#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   using namespace std;   template <typename T1, typename T2>   void ckmin(T1 &a, T2 b) {     if (a > b) a = b;   }   template <typename T1, typename T2>   void ckmax(T1 &a, T2 b) {     if (a < b) a = b;   }   template <typename T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   int read() {     int x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = 10 * x + ch -  0 , ch = getchar();     return f ? -x : x;   }   const int mod = 1000000007;   const int N = 2005;   struct fuck {     int x, y, b;   } a[N];   int sum[N][N];   int n, m, R, t = 1000;   int fac[N], ifac[N];   int qpow(int a, int b = mod - 2) {     int res = 1;     while (b > 0) {       if (b & 1) res = 1ll * res * a % mod;       a = 1ll * a * a % mod;       b >>= 1;     }     return res;   }   void init(int n) {     fac[0] = ifac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;     ifac[n] = qpow(fac[n], mod - 2);     for (int i = n - 1; i >= 1; i--) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod;   }   int C(int n, int m) {     if (n < m || n < 0)       return 0;     else       return 1ll * fac[n] * ifac[n - m] % mod * ifac[m] % mod;   }   int calc1(int xd1, int yd1, int xd2, int yd2) {     return sum[xd2][yd2] - sum[xd1 - 1][yd2] - sum[xd2][yd1 - 1] +            sum[xd1 - 1][yd1 - 1];   }   int main() {     init(2000);     n = read(), m = read(), R = read();     for (int i = 1; i <= n; i++) {       a[i].x = read(), a[i].y = read(), a[i].b = read();       sum[a[i].x][a[i].y]++;     }     for (int i = 1; i <= t; i++) {       for (int j = 1; j <= t; j++) {         sum[i][j] += sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1];       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       int xd1 = max(1, a[i].x - R), yd1 = max(1, a[i].y - R);       int xd2 = min(t, a[i].x + R), yd2 = min(t, a[i].y + R);       int in_dot = calc1(xd1, yd1, xd2, yd2);       ans = (ans + 1ll * (C(n, m) - C(n - in_dot, m) + mod) * a[i].b % mod *                        a[i].b % mod) %             mod;     }     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         int xd1 = max(1, a[i].x - R), yd1 = max(1, a[i].y - R);         int xd2 = min(t, a[i].x + R), yd2 = min(t, a[i].y + R);         int in_dot = calc1(xd1, yd1, xd2, yd2);         int kase = C(n, m);         kase = (kase - C(n - in_dot, m) + mod) % mod;         int x3 = max(1, a[j].x - R), y3 = max(1, a[j].y - R);         int x4 = min(t, a[j].x + R), y4 = min(t, a[j].y + R);         int in_dot2 = calc1(x3, y3, x4, y4);         kase = (kase - C(n - in_dot2, m) + mod) % mod;         int x5 = max(xd1, x3), y5 = max(yd1, y3);         int x6 = min(xd2, x4), y6 = min(yd2, y4);         int in_dot3 = 0;         if (x5 <= x6 && y5 <= y6) {           in_dot3 = calc1(x5, y5, x6, y6);         }         int in = in_dot + in_dot2 - in_dot3;         kase = (kase + C(n - in, m)) % mod;         ans = (ans + 1ll * 2 * a[i].b % mod * a[j].b % mod * kase % mod) % mod;       }     }     printf( %lld n , (ans % mod + mod) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int solve(string second, char cur) {     if (second.size() == 1) {       return !(second[0] == cur);     }     int n = second.size();     int check = 0;     for (int i = 0; i < n / 2; i++) {       check += (second[i] == cur);     }     int check2 = 0;     for (int i = n / 2; i < n; i++) {       check2 += (second[i] == cur);     }     int a = solve(second.substr(n / 2, n / 2), cur + 1) + n / 2 - check;     int b = solve(second.substr(0, n / 2), cur + 1) + n / 2 - check2;     return min(a, b);   }   int main() {     std::ios::sync_with_stdio(false);     int T;     cin >> T;     int n;     string second;     while (T--) {       cin >> n;       cin >> second;       cout << solve(second,  a ) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long INF = 0x7FFFFFFFFFFFFFFF;   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long ask(vector<long long>& v) {     cout <<  ?   << (long long int)(v).size() <<    ;     for (long long i = 0; i < (long long int)(v).size(); ++i) cout << v[i] <<    ;     cout <<   n  << flush;     long long res;     cin >> res;     return res;   }   vector<long long> comp(vector<long long>& st, long long n) {     vector<bool> pres(n + 1, 0);     for (long long i = 0; i < (long long int)(st).size(); ++i) pres[st[i]] = 1;     vector<long long> res;     for (long long i = 1; i < n + 1; ++i) {       if (!pres[i]) res.push_back(i);     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long T;     cin >> T;     while (T--) {       long long n, k;       cin >> n >> k;       vector<vector<long long> > st(k);       for (long long i = 0; i < k; ++i) {         long long c;         cin >> c;         st[i].resize(c);         for (long long j = 0; j < c; ++j) cin >> st[i][j];       }       vector<long long> a(n);       iota((a).begin(), (a).end(), 1);       long long mx = ask(a);       long long l = 0, r = k - 1;       while (l < r) {         long long md = (l + r) / 2;         a.clear();         for (long long i = 0; i < md + 1; ++i) {           for (long long j = 0; j < (long long int)(st[i]).size(); ++j)             a.push_back(st[i][j]);         }         long long m = ask(a);         if (m == mx)           r = md;         else           l = md + 1;       }       vector<long long> ans(k, mx);       vector<long long> c = comp(st[l], n);       long long m = ask(c);       ans[l] = m;       cout <<  !  ;       for (long long i = 0; i < k; ++i) cout << ans[i] <<    ;       cout <<   n  << flush;       string strl;       cin >> strl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool smin(T &a, const T &b) {     return b < a ? a = b, 1 : 0;   }   template <typename T>   inline bool smax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const long long N = (long long)1e6 + 10;   long long n, ar[N], m, bl[N], br[N], pre[N], fen[N], res[N];   vector<long long> qs[N];   map<long long, long long> last;   long long get_xor(long long l, long long r) {     if (!l) return pre[r];     return pre[r] ^ pre[l - 1];   }   void add(long long i, long long val) {     for (; i < N; i += (i & -i)) fen[i] ^= val;   }   long long get(long long i) {     long long ret = 0;     for (; i; i ^= (i & -i)) ret ^= fen[i];     return ret;   }   void add(long long l, long long r, long long val) {     add(r, val);     if (l > 1) add(l - 1, val);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 1; i <= n; ++i) {       cin >> ar[i];       if (i) pre[i] = pre[i - 1];       pre[i] ^= ar[i];     }     cin >> m;     for (long long j = 0; j < m; ++j) {       cin >> bl[j] >> br[j];       qs[br[j]].push_back(j);     }     for (long long j = 1; j <= n; ++j) last[ar[j]] = -1;     for (long long i = 1; i <= n; ++i) {       long long x = ar[i];       if (last[x] == -1)         add(1, i, x);       else         add(last[x] + 1, i, x);       last[x] = i;       for (long long p : qs[i]) {         res[p] = get_xor(bl[p], i);         res[p] ^= get(i);         res[p] ^= get(bl[p] - 1);       }     }     for (long long j = 0; j < m; ++j) cout << res[j] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   const int CS = 22;   int cmax[N][CS], cmin[N][CS], ans[N];   int lt[CS];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &cmax[i][0]);       cmax[i][0] *= 100;     }     for (int i = 1; i <= n; i++) scanf( %d , &cmin[i][0]);     int cs = 1;     for (int g = 1; g < n; g <<= 1, cs++) {       int gg = g << 1;       for (int i = 1; i <= n; i++) {         if (i + gg - 1 > n)           cmax[i][cs] = cmin[i][cs] = 0;         else {           cmax[i][cs] = max(cmax[i][cs - 1], cmax[i + g][cs - 1]);           cmin[i][cs] = min(cmin[i][cs - 1], cmin[i + g][cs - 1]);         }       }     }     lt[0] = 1;     for (int i = 1; i < cs; i++) lt[i] = lt[i - 1] << 1;     for (int i = 1; i <= n; i++) {       ans[i] = 0;       int tmax = 0, tmin = 10000000;       int mid = i;       for (int j = cs - 1; j >= 0; j--) {         if (cmax[mid][j] > 0) {           int tmax2 = max(tmax, cmax[mid][j]);           int tmin2 = min(tmin, cmin[mid][j]);           ans[i] = max(ans[i], min(tmax2, tmin2));           if (tmax2 <= tmin2) {             tmax = tmax2;             tmin = tmin2;             if (tmax == tmin) break;             mid += lt[j];             if (mid > n) break;           }         }       }     }     sort(ans + 1, ans + n + 1);     double p = 1.0;     double res = 0;     for (int i = 1; i <= n - k + 1; i++) {       if (p < 1e-20) break;       double pp = k * 1.0 / (n - i + 1);       res += p * pp * ans[i];       p *= (1 - pp);     }     printf( %.12f , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(string s) {     for (int i = 0; i < s.size() / 2; i++)       if (s[i] != s[s.size() - 1 - i]) return 0;     return 1;   }   int main() {     int jopa;     string s;     cin >> s;     int p = 0;     char a = s[0];     for (int i = 0; i < s.size(); i++)       if (s[i] == a) p++;     if (p >= s.size() - 1) {       cout <<  Impossible ;       return 0;     }     int n = s.size();     s = s + s;     for (int i = 1; i < n; i++) {       if (i + n - 1 >= s.size()) break;       if (check(s.substr(i, n)) && s.substr(i, n) != s.substr(0, n)) {         cout << 1;         return 0;       }     }     cout << 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int main() {     string s;     cin >> s;     int k = 0, c = 0;     for (int i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  b )         c++;       else {         k += c;         c *= 2;         k %= MOD;         c %= MOD;       }     }     cout << k <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n;     cin >> n;     long long nu[n];     for (long long i = 0; i < n; ++i) {       char a;       cin >> a;       nu[i] = a -  0 ;     }     long long f[10];     for (long long i = 0; i < 9; ++i) cin >> f[i + 1];     for (long long i = 0; i < n; ++i) {       if (f[nu[i]] > nu[i]) {         long long dab = i;         for (dab = i; dab < n && f[nu[dab]] >= nu[dab]; ++dab) {           nu[dab] = f[nu[dab]];         }         break;       }     }     for (long long i = 0; i < n; ++i) {       cout << nu[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const maxn = 100100;   long long a[maxn];   set<long long> s;   int main() {     int n, k;     long long x1, x2, x3, x4;     while (~scanf( %d%d , &n, &k)) {       for (int i = 0; i < n; ++i) {         scanf( %I64d.%I64d.%I64d.%I64d , &x1, &x2, &x3, &x4);         a[i] = (x1 << 24) | (x2 << 16) | (x3 << 8) | x4;       }       long long ret = -1;       for (int i = 31; i >= 0; --i) {         long long t = (1LL << 32) - (1LL << i);         s.clear();         for (int j = 0; j < n; ++j) {           s.insert(t & a[j]);         }         if (s.size() == k) {           ret = t;           break;         }       }       if (ret == -1)         puts( -1 );       else {         printf( %I64d.%I64d.%I64d.%I64d n , ret >> 24, (ret >> 16) & 255,                (ret >> 8) & 255, ret & 255);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> vec(n, 0);     for (long long i = 0; i < n; i++) cin >> vec[i];     long long mn = 10e9 + 1, mx = -1, count = 0;     for (long long i = 1; i < n; i++) {       if (vec[i] == -1 && vec[i - 1] != -1) {         mn = min(mn, vec[i - 1]);         mx = max(mx, vec[i - 1]);       }     }     for (long long i = 0; i < n - 1; i++) {       if (vec[i] == -1 && vec[i + 1] != -1) {         mn = min(mn, vec[i + 1]);         mx = max(mx, vec[i + 1]);       }     }     if (mx == -1) {       cout << 0 <<     << 0 << endl;     } else {       long long k = (mx + mn) / 2;       for (long long i = 0; i < n; i++) {         if (vec[i] == -1) {           vec[i] = k;         }       }       long long dif = 0;       for (long long i = 1; i < n; i++) {         dif = max(dif, abs(vec[i] - vec[i - 1]));       }       cout << dif <<     << k << endl;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t-- > 0) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   #define ll long long   #define f(i, n) for (i = 0; i < n; ++i)   #define all(n) n.begin(), n.end()   #define P long(1e9 + 7)   #define fastio                               ios_base::sync_with_stdio(false);        cin.tie(NULL)      using namespace std;      ll solve(vector<vector<ll>>& dp, vector<ll>& s, int l, int r)   {       if (l == r)           return dp[l][r] = 0;          if (dp[l][r] == -1) {           ll val = s[r] - s[l];           val += min(solve(dp, s, l + 1, r), solve(dp, s, l, r - 1));           return dp[l][r] = val;       }          return dp[l][r];   }      int main()   {       int n, i, j, k, l, m;       cin >> n;       vector<ll> s(n, 0);       vector<vector<ll>> dp(n, vector<ll>(n, -1));       f(i, n) cin >> s[i];       sort(all(s));          cout << solve(dp, s, 0, n - 1);   }


#include <bits/stdc++.h>   template <typename T>   void rd(T& x) {     long long f = 0, c;     while ((c = getchar()) < 48 || 57 < c) f ^= !(c ^ 45);     x = (c & 15);     while (47 < (c = getchar()) && c < 58) x = x * 10 + (c & 15);     if (f) x = -x;   }   template <typename T>   inline void pt(T x) {     if (x < 0) x = -x, putchar( - );     if (x > 9) pt(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void pt(T x, long long c) {     pt(x), putchar(c);   }   template <typename T>   inline T max(const T& x, const T& y) {     return x < y ? y : x;   }   template <typename T>   inline T min(const T& x, const T& y) {     return x < y ? x : y;   }   const long long N = 2005, P = 1000000007;   long long n, m, f[2][N][N], sum[N][N];   char s[N][N];   long long getsum(long long a, long long b, long long c, long long d) {     if (a > c || b > d) return 0;     return sum[c][d] - sum[c][b - 1] - sum[a - 1][d] + sum[a - 1][b - 1];   }   long long getf0(long long a, long long b, long long c, long long d) {     if (a > c || b > d) return 0;     return f[0][c][d] - f[0][c][b - 1] - f[0][a - 1][d] + f[0][a - 1][b - 1];   }   long long getf1(long long a, long long b, long long c, long long d) {     if (a > c || b > d) return 0;     return f[1][c][d] - f[1][c][b - 1] - f[1][a - 1][d] + f[1][a - 1][b - 1];   }   signed main() {     rd(n), rd(m);     for (long long i = (1); i <= (n); ++i) scanf( %s , s[i] + 1);     if (s[n][m] ==  R ) {       puts( 0 );       return 0;     }     if (n == 1 && m == 1) {       puts( 1 );       return 0;     }     for (long long i = (1); i <= (n); ++i)       for (long long j = (1); j <= (m); ++j)         sum[i][j] =             sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + (s[i][j] ==  R );     f[0][1][1] = 1;     f[1][1][1] = 1;     for (long long i = (1); i <= (n); ++i)       for (long long j = (1); j <= (m); ++j) {         long long l = 1, r = i, ans = i;         while (l <= r) {           long long mid = (l + r) >> 1;           if (getsum(mid + 1, j, n, j) <= n - i)             ans = mid, r = mid - 1;           else             l = mid + 1;         }         (f[1][i][j] += getf0(ans, j, i - 1, j)) %= P;         l = 1, r = j, ans = j;         while (l <= r) {           long long mid = (l + r) >> 1;           if (getsum(i, mid + 1, i, m) <= m - j)             ans = mid, r = mid - 1;           else             l = mid + 1;         }         (f[0][i][j] += getf1(i, ans, i, j - 1)) %= P;         (f[0][i][j] += f[0][i][j - 1] + f[0][i - 1][j] - f[0][i - 1][j - 1]) %= P;         (f[1][i][j] += f[1][i][j - 1] + f[1][i - 1][j] - f[1][i - 1][j - 1]) %= P;       }     pt(((getf0(n, m, n, m) + getf1(n, m, n, m)) % P + P) % P,   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string arr[55], arr2[55];   vector<pair<int, int> > hasil;   int i, j, n, t, tc, r, x, y, k, c;   void tuker_lr(int x, int y) {     arr[x][y] =  U ;     arr[x + 1][y] =  D ;     arr[x][y + 1] =  U ;     arr[x + 1][y + 1] =  D ;   }   void tuker_ud(int x, int y) {     arr[x][y] =  L ;     arr[x][y + 1] =  R ;     arr[x + 1][y] =  L ;     arr[x + 1][y + 1] =  R ;   }   void l_u_ganjil(int x, int y) {     if (arr[x + 1][y] ==  L ) {       tuker_lr(x, y);       hasil.push_back(make_pair(x, y));     } else if (arr[x + 1][y + 1] ==  U ) {       tuker_ud(x + 1, y);       hasil.push_back(make_pair(x + 1, y));       tuker_lr(x, y);       hasil.push_back(make_pair(x, y));     } else {       l_u_ganjil(x + 1, y + 1);       tuker_ud(x + 1, y);       hasil.push_back(make_pair(x + 1, y));       tuker_lr(x, y);       hasil.push_back(make_pair(x, y));     }   }   void u_d_ganjil(int x, int y) {     if (arr[x][y + 1] ==  U ) {       tuker_ud(x, y);       hasil.push_back(make_pair(x, y));     } else if (arr[x][y + 1] ==  L ) {       l_u_ganjil(x, y + 1);       tuker_ud(x, y);       hasil.push_back(make_pair(x, y));     } else {       u_d_ganjil(x - 1, y + 1);       l_u_ganjil(x, y + 1);       tuker_ud(x, y);       hasil.push_back(make_pair(x, y));     }   }   int main() {     scanf( %d %d , &r, &c);     for (i = 0; i < r; i++) cin >> arr[i];     for (i = 0; i < r; i++) cin >> arr2[i];     if (c % 2 == 1) {       for (j = 0; j < c; j++)         for (i = 0; i < r; i++)           if (arr[i][j] ==  L ) l_u_ganjil(i, j);     } else {       for (j = 0; j < c; j++)         for (i = 0; i < r; i++)           if (arr[i][j] ==  U ) u_d_ganjil(i, j);     }     for (j = 0; j < c; j++) {       for (i = 0; i < r; i++) {         if (arr[i][j] == arr2[i][j])           continue;         else if (arr[i][j] ==  U )           u_d_ganjil(i, j);         else           l_u_ganjil(i, j);       }     }     printf( %d n , hasil.size());     for (i = 0; i < hasil.size(); i++)       printf( %d %d n , hasil[i].first + 1, hasil[i].second + 1);   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a = 0, b = 0;     int t;     for (int i = 0; i < 3; ++i) {       cin >> t;       a += t;     }     a = (a + 4) / 5;     for (int i = 0; i < 3; ++i) {       cin >> t;       b += t;     }     b = (b + 9) / 10;     cin >> n;     if (a + b > n)       printf( NO );     else       printf( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct name {     int l, r;   } bl[200001];   bool cmp(name n, name m) {     if (n.r == m.r) return n.l < m.l;     return n.r < m.r;   }   int main() {     int n, x, w, ans = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x, &w);       bl[i].l = x - w;       bl[i].r = x + w;     }     sort(bl + 1, bl + n + 1, cmp);     int cnt = -2e9;     for (int i = 1; i <= n; i++) {       if (cnt <= bl[i].l) {         ans++;         cnt = bl[i].r;       }     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 1e5 + 5;   long long qpow(long long a, long long b, long long r) {     long long ans = 1, buff = a % r;     while (b) {       if (b & 1) ans = (ans * buff) % r;       buff = (buff * buff) % r;       b >>= 1;     }     return ans;   }   long long f_inv(long long a, long long p) { return qpow(a, p - 2, p); }   string s;   long long k, ans = 0;   int main() {     ios::sync_with_stdio(false);     cin >> s >> k;     if (s[0] ==  -  || s[0] ==  + ) s.erase(s.begin());     long long len = s.length();     for (long long i = 0; i < len; i++) {       if (s[i] ==  0  || s[i] ==  5 ) {         ans += qpow(2, i, mod);         ans %= mod;       }     }     long long x = qpow(2, len, mod);     long long y = qpow(x, k, mod);     x--, y--;     ans = ans * (y * f_inv(x, mod) % mod) % mod;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 1e9;   const long long N = (1 << 20);   long long mod_expo(long long a, long long b, long long c) {     long long ans = 1;     while (b) {       if (b & (long long)1) ans = (ans * a) % c;       a = (a * a) % c;       b = b >> 1;     }     return ans;   }   long long inverse(long long n) { return mod_expo(n, mod - 2, mod); }   int n;   int total;   int a[N];   long long f[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     total = 1 << 20;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       a[x]++;     }     n = 20;     for (int i = 0; i < total; i++) f[i] = a[i];     for (int i = 0; i < n; i++) {       for (int mask = total - 1; mask >= 0; mask--) {         if ((mask & (1 << i)) == 0) f[mask] += f[mask ^ (1 << i)];       }     }     long long ans = 0;     for (int i = 0; i < total; i++) {       int bits = __builtin_popcount(i);       if (bits % 2)         ans -= mod_expo(2, f[i], mod);       else         ans += mod_expo(2, f[i], mod);       ans %= mod;       ans += mod;       ans %= mod;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   vector<string> vec_splitter(string s) {     s +=  , ;     vector<string> res;     while (!s.empty()) {       res.push_back(s.substr(0, s.find( , )));       s = s.substr(s.find( , ) + 1);     }     return res;   }   void debug_out(vector<string> __attribute__((unused)) args,                  __attribute__((unused)) long long int idx,                  __attribute__((unused)) long long int LINE_NUM) {     cout <<   n ;   }   template <typename Head, typename... Tail>   void debug_out(vector<string> args, long long int idx, long long int LINE_NUM,                  Head H, Tail... T) {     if (idx > 0)       cout <<  ,  ;     else       cout <<  Line(  << LINE_NUM <<  )  ;     stringstream ss;     ss << H;     cout << args[idx] <<   =   << ss.str();     debug_out(args, idx + 1, LINE_NUM, T...);   }   const long long int mod = 1000000007;   const long long int inf = 1e18;   const long long int N = 2e5 + 5;   long long int dp[N][5];   string s;   long long int n;   string abc =  abc ;   long long int go(long long int idx, long long int pos) {     if (pos > 3LL) {       return 0;     }     if (idx == n) {       return (pos == 3LL);     }     long long int &ans = dp[idx][pos];     if (ans != -1) return ans;     ans = 0;     if (s[idx] !=  ? ) {       if (s[idx] == abc[pos]) {         ans += go(idx + 1, pos + 1);         ans %= mod;       }       ans += go(idx + 1, pos);       ans %= mod;     } else {       for (char x =  a ; x <=  c ; x++) {         if (x == abc[pos]) {           ans += go(idx + 1, pos + 1);           ans %= mod;         }         ans += go(idx + 1, pos);         ans %= mod;       }     }     return ans;   }   void HyperBeast() {     memset(dp, -1, sizeof(dp));     cin >> n >> s;     cout << go(0, 0);   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int T = 1;     for (long long int ti = 1; ti <= T; ti++) {       HyperBeast();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int num[100010];   int num1[100010];   int a[100010];   int main() {     int n;     cin >> n;     int flag = 0;     for (int i = 1; i <= n; i++) {       cin >> num[i];       num1[i] = num[i];     }     sort(num + 1, num + n + 1);     sort(num1 + 1, num1 + n + 1);     int tim = 0;     for (int i = 1; i < n; i++) {       int t = num[i + 1] - num[i];       if (t == 0) tim++;     }     if (tim >= 2) flag = 1;     for (int i = 1; i < n; i++) {       if (num1[i] == num1[i + 1]) {         num1[i]--;         break;       }     }     sort(num1 + 1, num1 + n + 1);     for (int i = 1; i < n; i++) {       if (num1[i] == num1[i + 1] || num1[i] == -1) {         flag = 1;         break;       }     }     if (flag == 1)       cout <<  cslnb  << endl;     else {       long long sum = 0;       for (int i = 1; i <= n; i++) sum += num[i];       long long s = n * (n - 1) / 2;       if ((sum - s) % 2 == 0)         cout <<  cslnb  << endl;       else         cout <<  sjfnb  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     map<int, int> nrs;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       nrs[x]++;     }     int max_times = nrs.begin()->second;     for (auto it : nrs) max_times = max(it.second, max_times);     if (max_times > (n + 1) / 2)       cout <<  NO  << endl;     else       cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct s {     long long col, colf, flag;   } node[100010 << 2];   void build(int l, int r, int tr) {     node[tr].col = node[tr].colf = node[tr].flag = 0;     if (l == r) {       node[tr].col = l;       return;     }     int mid = (l + r) >> 1;     build(l, mid, tr << 1);     build(mid + 1, r, tr << 1 | 1);   }   long long ABS(long long x) {     if (x < 0) return -x;     return x;   }   void pushdown(int tr, int m) {     if (node[tr].flag) {       node[tr << 1].flag += node[tr].flag;       node[tr << 1 | 1].flag += node[tr].flag;       node[tr << 1].colf += node[tr].flag * (m - (m >> 1));       node[tr << 1 | 1].colf += node[tr].flag * (m >> 1);       node[tr].flag = 0;     }     if (node[tr].col) {       node[tr << 1].col = node[tr << 1 | 1].col = node[tr].col;     }   }   void pushup(int tr) {     node[tr].colf = node[tr << 1].colf + node[tr << 1 | 1].colf;     if (node[tr << 1].col == node[tr << 1 | 1].col)       node[tr].col = node[tr << 1].col;     else       node[tr].col = 0;   }   void update(int L, int R, long long val, int l, int r, int tr) {     if (L <= l && r <= R) {       if (node[tr].col) {         node[tr].colf += (r - l + 1) * ABS(node[tr].col - val);         node[tr].flag += ABS(node[tr].col - val);         node[tr].col = val;         return;       }     }     pushdown(tr, r - l + 1);     int mid = (l + r) >> 1;     if (L <= mid) update(L, R, val, l, mid, tr << 1);     if (R > mid) update(L, R, val, mid + 1, r, tr << 1 | 1);     pushup(tr);   }   long long query(int L, int R, int l, int r, int tr) {     if (L <= l && r <= R) {       return node[tr].colf;     }     pushdown(tr, r - l + 1);     long long a, b;     a = 0;     b = 0;     int mid = (l + r) >> 1;     if (L <= mid) {       a = query(L, R, l, mid, tr << 1);     }     if (R > mid) {       b = query(L, R, mid + 1, r, tr << 1 | 1);     }     return (a + b);   }   int main() {     int n, m;     while (scanf( %d%d , &n, &m) != EOF) {       build(1, n, 1);       while (m--) {         int op;         scanf( %d , &op);         if (op == 1) {           int a, b;           long long c;           scanf( %d%d%lld , &a, &b, &c);           update(a, b, c, 1, n, 1);         } else {           int a, b;           scanf( %d%d , &a, &b);           printf( %lld n , query(a, b, 1, n, 1));         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  { ;     string sep;     for (const auto &x : v) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     os <<  { ;     string sep;     for (const auto &x : v) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename T, size_t size>   ostream &operator<<(ostream &os, const array<T, size> &arr) {     os <<  { ;     string sep;     for (const auto &x : arr) os << sep << x, sep =  ,  ;     return os <<  } ;   }   template <typename A, typename B>   ostream &operator<<(ostream &os, const pair<A, B> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename A, typename B>   ostream &operator<<(ostream &os, const map<A, B> &v) {     os <<  { ;     string sep;     for (const auto &x : v) os << sep << x, sep =  ,  ;     return os <<  } ;   }   void dbg_out() { cerr << endl; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr <<     << H;     dbg_out(T...);   }   mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());   long long rand(long long a, long long b) {     return uniform_int_distribution<long long>(a, b)(mt_rng);   }   template <long long D, typename T>   struct vec : public vector<vec<D - 1, T>> {     static_assert(D >= 1,  Dimensions invalid );     template <typename... Args>     vec(long long n = 0, Args... args)         : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {}   };   template <typename T>   struct vec<1, T> : public vector<T> {     vec(long long n = 0, const T &val = T()) : vector<T>(n, val) {}   };   template <class T>   bool cmin(T &a, const T &b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool cmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const long long N = 2e5 + 5, inf = 1e18;   struct Point {     long long x, y;     Point operator-(Point p) { return {x - p.x, y - p.y}; }     long long dist() { return x * x + y * y; }   };   bool by_x(Point &a, Point &b) { return a.x < b.x; }   bool by_y(Point &a, Point &b) { return a.y < b.y; }   long long n, ans = 1e18;   long long a[N], pref[N];   Point pt[N];   long long solve(long long L, long long R) {     if (L == R) return 1e18;     long long M = (L + R) / 2;     sort(pt + L, pt + R + 1, by_x);     long long d = min(solve(L, M), solve(M + 1, R));     long long midx = pt[L + (R - L + 1) / 2].x;     vector<Point> v;     for (long long i = L; i <= R; i++) {       if (Point{pt[i].x - midx, 0}.dist() < d) {         v.push_back(pt[i]);       }     }     sort(v.begin(), v.end(), by_y);     for (long long i = 0; i < v.size(); i++) {       for (long long j = i + 1; j < v.size(); j++) {         if (Point{0, v[i].y - v[j].y}.dist() > d) break;         d = min(d, (v[i] - v[j]).dist());       }     }     return d;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long sum = 0;     for (long long i = 1, u; i <= n; i++) {       cin >> u;       sum += u;       pt[i].x = i;       pt[i].y = sum;     }     cout << solve(1, n) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long double pi = 3.14159265358979323;   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     vector<int> a(100000, 0);     vector<int> ans;     for (int i = 0; i < (int)n + m; ++i) {       if (a[i] < k) {         for (int j = 0; j < (int)k - a[i]; ++j) ans.push_back(i);         int t = a[i];         for (int j = i; j < n + i; ++j) a[j] += k - t;       } else if (a[i + 1] == 0) {         for (int j = i; j < n + i; ++j) a[j]++;         ans.push_back(i);       }     }     printf( %d n , ans.size());     for (int i = 0; i < (int)ans.size(); ++i) {       printf( %d  , ans[i] + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   vector<long long> adj[1000000];   vector<bool> visited(1000000, 0);   vector<long long> color(1000000, 0);   long long n, k, x = 0;   void DFSUtil(long long u) {     visited[u] = true;     x++;     for (long long i = 0; i < adj[u].size(); i++) {       if (visited[adj[u][i]] == false) {         DFSUtil(adj[u][i]);       }     }   }   long long M = 1e9 + 7;   long long DFS(long long n) {     long long c = 0;     for (long long u = 1; u <= n; u++) {       if (visited[u] == false) {         x = 0;         DFSUtil(u);         long long g = 1;         for (long long i = 0; i < k; i++) {           g *= x;           g %= M;         }         c += g;         c %= M;       }     }     return c;   }   void aE(long long u, long long v) { adj[u].push_back(v); }   vector<long long> v(1000000, 0);   vector<long long> segTree(1000000, 0);   void build(long long low, long long high, long long pos) {     if (low == high) {       segTree[pos] = v[low];       return;     }     long long mid = (low + high) / 2;     build(low, mid, pos * 2);     build(mid + 1, high, pos * 2 + 1);     segTree[pos] = segTree[pos * 2] + segTree[pos * 2 + 1];   }   long long querry(long long low, long long high, long long l, long long r,                    long long pos) {     if (l <= low && r >= high)       return segTree[pos];     else if (r < low || l > high)       return 0;     long long mid = (low + high) / 2;     return querry(low, mid, l, r, 2 * pos) +            querry(mid + 1, high, l, r, 2 * pos + 1);   }   void update(long long low, long long high, long long index, long long val,               long long pos) {     if (low == high) {       v[index] = val;       segTree[pos] = val;     } else {       long long mid = (low + high) / 2;       if (low <= index && index <= mid)         update(low, mid, index, val, 2 * pos);       else         update(mid + 1, high, index, val, 2 * pos + 1);       segTree[pos] = segTree[2 * pos] + segTree[2 * pos + 1];     }   }   long long mes(string s1, string s2) {     long long count = 0;     for (long long i = 0; i < min(s1.size(), s2.size()); i++) {       if (s1[i] != s2[i])         break;       else         count++;     }     return count;   }   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     vector<pair<long long, long long> > point(n);     for (long long i = 0; i < n; i++) cin >> point[i].first >> point[i].second;     vector<pair<long double, long double> > nonvert;     vector<long long> vert;     map<long long, long long> vertm;     map<pair<long double, long double>, long long> nonvertm;     for (long long i = 0; i < n - 1; i++) {       for (long long j = i + 1; j < n; j++) {         long long x1, x2, y1, y2;         x1 = point[i].first;         x2 = point[j].first;         y1 = point[i].second;         y2 = point[j].second;         if (x1 == x2) {           if (vertm[x1] == 0) {             vert.push_back(x1);             vertm[x1] = 1;           }         } else {           long double m, c;           m = (long double)(y2 - y1) / (long double)(x2 - x1);           c = (long double)(x2 * y1 - x1 * y2) / (long double)(x2 - x1);           if (nonvertm[make_pair(m, c)] == 0) {             nonvert.push_back(make_pair(m, c));             nonvertm[make_pair(m, c)] = 1;           }         }       }     }     sort((nonvert).begin(), (nonvert).end());     vector<long long> same;     long double last = nonvert[0].first;     for (long long i = 0; i < nonvert.size(); i++) {       long long count = 0, j = i;       while (1) {         if (nonvert[j].first == last) {           count++;           j++;         } else {           if (count > 1) same.push_back(count);           count = 0;           last = nonvert[j].first;           i = j - 1;           break;         }       }     }     long long u = vert.size() + nonvert.size();     long long m = u * (u - 1) / 2;     for (long long i = 0; i < same.size(); i++)       m -= (same[i] * (same[i] - 1) / 2);     if (vert.size() > 1) m -= (vert.size()) * (vert.size() - 1) / 2;     cout << m << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   struct node {     int num, cnt;     node *l, *r, *p, *path;   };   typedef node *pnode;   const int N = 100003;   node tr[N + 1];   pnode tmp[100002];   const pnode pNull = tr + N;   inline void upd(pnode v) {     if (v == pNull) return;     v->cnt = 1 + v->l->cnt + v->r->cnt;     v->l->p = v;     v->r->p = v;   }   pnode fnd(pnode v, int cnt) {     if (v == pNull) return pNull;     if (v->l->cnt >= cnt)       return fnd(v->l, cnt);     else if (v->l->cnt + 1 == cnt)       return v;     else       return fnd(v->r, cnt - v->l->cnt - 1);   }   inline bool is_left_son(pnode v1, pnode v2) { return v1->l == v2; }   void rotate(pnode v) {     if (v->p == pNull) return;     pnode f = v->p;     if (is_left_son(f, v)) {       pnode tmp = v->r;       v->r = f;       f->l = tmp;       v->p = f->p;       if (is_left_son(v->p, f))         v->p->l = v;       else         v->p->r = v;       f->p = v;       upd(f);       upd(v);     } else {       pnode tmp = v->l;       v->l = f;       f->r = tmp;       v->p = f->p;       if (is_left_son(v->p, f))         v->p->l = v;       else         v->p->r = v;       f->p = v;       upd(f);       upd(v);     }     v->path = f->path;   }   void splay(pnode v) {     while (v->p != pNull) {       if (v->p->p == pNull) {         rotate(v);         break;       }       if (is_left_son(v->p, v) == is_left_son(v->p->p, v->p)) {         rotate(v->p);         rotate(v);       } else {         rotate(v);         rotate(v);       }     }   }   pnode merge(pnode l, pnode r) {     if (l == pNull && r == pNull) return pNull;     if (l == pNull) return r;     if (r == pNull) return l;     pnode q = fnd(r, 1);     splay(q);     q->l = l;     upd(q);     return q;   }   pnode getRoot(pnode v, int &cnt) {     splay(v);     cnt = v->l->cnt + 1;     return v;   }   pnode expose(pnode v) {     splay(v);     if (v->r != pNull) {       v->r->path = v;       v->r->p = pNull;       v->r = pNull;       upd(v);     }     int tmp = 0;     while (v->path != pNull) {       pnode f = v->path;       splay(f);       if (f->r != pNull) {         f->r->path = f;         f->r->p = pNull;         f->r = pNull;         upd(f);       }       pnode old = f->path;       v = merge(f, v);       v->path = old;     }     return v;   }   pnode makeRoot(pnode v) {     pnode root = expose(v);     splay(v);     return v;   }   int a, b, c, d, i, j, n, m, k;   int mas[100004];   int main() {     scanf( %d%d , &n, &m);     for (int _n((n)-1), i(0); i <= _n; i++) {       scanf( %d , &mas[i]);       pnode q = &tr[k++];       q->l = q->r = q->p = pNull;       q->cnt = 1;       q->num = i;       if (i + mas[i] < n) {         q->path = &tr[i + mas[i]];       } else {         q->path = &tr[n];       }     }     pnode q = &tr[k++];     q->l = q->r = q->p = q->path = pNull;     q->cnt = 1;     q->num = n;     for (int _n((m)-1), i(0); i <= _n; i++) {       scanf( %d , &a);       if (a == 0) {         scanf( %d%d , &a, &b);         --a;         pnode link = pNull;         if (a + mas[a] < n)           link = tr + a + mas[a];         else           link = tr + n;         pnode root = makeRoot(link);         c = 0;         pnode pa = expose(tr + a);         expose(link);         tr[a].path = pNull;         mas[a] = b;         if (a + mas[a] < n)           link = tr + a + mas[a];         else           link = tr + n;         tr[a].path = link;       } else {         scanf( %d , &a);         --a;         makeRoot(tr + n);         pnode root = expose(tr + a);         pnode p = fnd(root, 2);         printf( %d %d n , p->num + 1, root->cnt - 1);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     long long sz, ans, x, y;     string s, str =   ;     cin >> n >> x >> y >> s;     str += s[0];     for (i = 1; i < n; i++)       if (s[i - 1] != s[i]) str += s[i];     sz = (long long)str.size();     if (str[0] ==  0 )       sz = (sz >> 1LL) + (sz & 1);     else       sz = sz >> 1LL;     ans = min((sz - 1) * x + y, sz * y);     cout << max(0LL, ans) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double dist(long double x1, long double y1, long double x2,                    long double y2) {     long double D = ((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1));     return sqrt(D);   }   int main() {     const int inf = 1e9;     int n;     cin >> n;     vector<pair<int, pair<pair<int, int>, long double>>> v;     for (int i = 0; i < n; i++) {       int x, y, t;       long double p;       cin >> x >> y >> t >> p;       v.push_back({t, {{x, y}, p}});     }     sort(v.begin(), v.end());     long double ans = 0.0;     vector<long double> dp(n + 1, 0.0);     for (int i = 1; i <= n; i++) dp[i] = v[i - 1].second.second;     dp[0] = 0;     for (int i = 0; i < n; i++) {       for (int j = i - 1; j >= 0; j--) {         long double x1 = (v[i].second.first.first),                     x2 = (v[j].second.first.first);         long double y1 = v[i].second.first.second, y2 = v[j].second.first.second;         if (dist(x1, y1, x2, y2) <= (long double)(v[i].first - v[j].first)) {           dp[i + 1] = max(dp[i + 1], dp[j + 1] + v[i].second.second);         }       }       ans = max(ans, dp[i + 1]);     }     cout << setprecision(14) << ans <<   n ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( fast-math )   #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native )   using namespace std;   int a, b, c, d, e, f, p = 1000000007, base = 157, mi = 1e9, id = 0, q, pos;   int ind[300000], ans[300000], si[300000], si2[300000];   pair<int, int> reb_price[300000];   string s, s2;   vector<int> vec[300000];   vector<pair<int, int>> rebra[300000];   vector<int> order;   void dfs() {     for (auto v : order) {       int ma = 0, ma2 = 0;       si[v] = 1;       for (auto i : rebra[v]) {         if (i.second == 0) {           continue;         }         b += (si[i.first] + i.second - 1) / id;         si[i.first] = (si[i.first] + i.second - 1) % id;         if (si[i.first] > ma) {           ma2 = ma;           ma = si[i.first];         } else if (si[i.first] > ma2) {           ma2 = si[i.first];         }       }       si[v] = ma + 1;       if (si[v] + ma2 >= id) {         si[v] = 0;         b++;       }     }   }   pair<int, int> dfs2(int v, int pred, int pred2) {     if (rebra[v].size() == 1 && v != 1) {       rebra[v][0] = {pred2, 0};       order.push_back(v);       return {v, 1};     }     if (rebra[v].size() == 2 && v != 1) {       if (rebra[v][0].first == pred) {         auto pa = dfs2(rebra[v][1].first, v, pred2);         return {pa.first, pa.second + 1};       } else {         auto pa = dfs2(rebra[v][0].first, v, pred2);         return {pa.first, pa.second + 1};       }     }     int j = 0;     for (auto i : rebra[v]) {       if (i.first == pred) {         rebra[v][j] = {pred2, 0};         j++;         continue;       }       rebra[v][j] = dfs2(i.first, v, v);       j++;     }     order.push_back(v);     return {v, 1};   }   int readint() {     int n = 0;     char c;     do {       c = fgetc(stdin);     } while (!(c ==  -  ||  0  <= c && c <=  9 ));     int sign = 1;     if (c ==  - ) {       sign = -1;       c = fgetc(stdin);     }     do {       n = n * 10 + (c -  0 );       c = fgetc(stdin);     } while ( 0  <= c && c <=  9 );     return n * sign;   }   signed main() {     cin.tie(NULL);     cout.tie(NULL);     ios_base::sync_with_stdio(false);     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();     a = readint();     for (int i = 0; i < a - 1; i++) {       b = readint();       c = readint();       rebra[b].push_back({c, 1});       rebra[c].push_back({b, 1});     }     dfs2(1, -1, -1);     for (int i = 0; i < a; i = i) {       if (i == 0 || i < 500) {         b = 0;         id = i + 1;         dfs();         cout << b <<   n ;         ;         i++;       } else {         b = 0;         id = i + 1;         dfs();         c = b;         int l = i + 1, r = a / max(b, 1) + 1;         b = 0;         while (r - l > 1) {           int res = (r + l) / 2;           b = 0;           id = res;           dfs();           if (b == c) {             l = res;           } else {             r = res;           }         }         for (int j = i; j < l; j++) {           cout << c <<   n ;           ;         }         i = l;       }     }     cin >> a;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( popcnt )   using namespace std;   constexpr int siz = 1 << 9 | 1, INF = 0x7f7f7f7f;   constexpr int fx[4][2] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};   int n, m, sx, sy, cnt;   long long val[9], sum[siz];   int f[21][21][siz];   char c[21][21];   pair<int, int> t[9];   queue<tuple<int, int, int> > q;   inline bool check(char c) { return c ==  .  || c ==  S ; }   inline bool check(int first, int second, int xi, int yi, int k) {     if (xi == t[k].first && yi < t[k].second) return first < xi;     if (first == t[k].first && second < t[k].second) return first > xi;     return false;   }   long long bfs();   signed main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> c[i][j];         if (c[i][j] ==  S ) {           sx = i;           sy = j;         }         if (isdigit(c[i][j])) {           cnt++;           t[c[i][j] -  0 ] = make_pair(i, j);         }       }     for (int i = 1; i <= cnt; i++) scanf( %lld , &val[i]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (c[i][j] ==  B ) {           val[++cnt] = -INF;           t[cnt] = make_pair(i, j);         }     for (int i = 1; i < (1 << cnt); i++)       for (int j = 0; j < cnt; j++)         if ((i >> j) & 1) sum[i] += val[j + 1];     printf( %lld n , bfs());     return 0;   }   long long bfs() {     long long res(0);     q.push(make_tuple(sx, sy, 0));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         for (int k = 0; k < (1 << cnt); k++) f[i][j][k] = -1;     f[sx][sy][0] = 0;     while (!q.empty()) {       int first, second, s;       tie(first, second, s) = q.front();       q.pop();       if (first == sx && second == sy)         res = max(res, sum[s] - f[first][second][s]);       for (int i = 0; i < 4; i++) {         const int xi = first + fx[i][0];         const int yi = second + fx[i][1];         if (xi > 0 && xi <= n && yi > 0 && yi <= m && check(c[xi][yi])) {           int si = s;           for (int j = 0; j < cnt; j++)             if (check(first, second, xi, yi, j + 1)) si ^= (1 << j);           if (f[xi][yi][si] == -1) {             f[xi][yi][si] = f[first][second][s] + 1;             q.push(make_tuple(xi, yi, si));           }         }       }     }     return res;   }


#include <bits/stdc++.h>   using namespace std;   int n, V, offset;   int d[1005];   int u[1000005], v[1000005], cnt = 0;   inline void print(int u, int v) {     ::u[++cnt] = u + offset;     ::v[cnt] = v + offset;   }   int main() {     int i, j;     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d , d + i);     V = d[n] + 1;     for (offset = 1;; ++offset) {       if (!d[1]) {         offset = V - d[n];         for (i = 1; i < n; ++i) d[i] = d[i + 1];         d[n--] = 0;       }       if (n <= 1) {         for (i = 0; i < d[1]; ++i)           for (j = i + 1; j <= d[1]; ++j) print(i, j);         break;       }       for (i = 1; i <= d[n]; ++i) print(0, i);       for (i = 1; i <= n; ++i) --d[i];       if (!d[1]) {         d[n--] = 0;         if (n <= 1) break;       }     }     printf( %d n , cnt);     for (i = 1; i <= cnt; ++i) printf( %d %d n , u[i], v[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void boost() {     ios_base::sync_with_stdio();     cin.tie(0);   }   const long long MAX = 1e5 + 111;   const long long mod = 1e9 + 7;   map<string, int> maap;   vector<int> g[MAX];   int main() {     boost();     int n;     bool ans = false;     cin >> n;     string a[n + 1];     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       if (a[i][0] ==  O  && a[i][1] ==  O ) {         a[i].erase(0, 2);         a[i].insert(0,  ++ );         ans = true;         break;       }       if (a[i][3] ==  O  && a[i][4] ==  O ) {         a[i].erase(3, 4);         a[i].insert(3,  ++ );         ans = true;         break;       }     }     if (ans == true) {       cout <<  YES n ;       for (int i = 1; i <= n; i++) {         cout << a[i] <<   n ;       }     } else {       cout <<  NO ;     }     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class S>   ostream& operator<<(ostream& os, const pair<T, S>& v) {     return os <<  (  << v.first <<  ,   << v.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& v) {     os <<  [ ;     for (int i = int(0); i <= int((static_cast<int>((v).size())) - 1); ++i) {       if (i) os <<  ,  ;       os << v[i];     }     return os <<  ] ;   }   template <class T>   bool setmax(T& _a, T _b) {     if (_b > _a) {       _a = _b;       return true;     }     return false;   }   template <class T>   bool setmin(T& _a, T _b) {     if (_b < _a) {       _a = _b;       return true;     }     return false;   }   template <class T>   T gcd(T _a, T _b) {     return _b == 0 ? _a : gcd(_b, _a % _b);   }   struct Node {     vector<Node*> ys;     int h = -1;   };   int main() {     int n, k;     cin >> n >> k;     vector<string> ss(n);     for (int i = int(0); i <= int((n)-1); ++i) cin >> ss[i];     sort((ss).begin(), (ss).end());     vector<int> height(n - 1);     for (int i = int(0); i <= int((n - 1) - 1); ++i) {       int j = 0;       while (j < static_cast<int>((ss[i]).size()) &&              j < static_cast<int>((ss[i + 1]).size()) &&              ss[i][j] == ss[i + 1][j]) {         ++j;       }       height[i] = j;     }     const function<Node*(int, int)> build = [&](int l, int r) {       Node* x = new Node();       if (l + 1 == r) return x;       int h = *min_element(height.begin() + l, height.begin() + r - 1);       x->h = h;       int i = l;       for (int j = int(l); j <= int((r)-1); ++j) {         if (j == r - 1 || height[j] == h) {           x->ys.push_back(build(i, j + 1));           i = j + 1;         }       }       return x;     };     Node* root = build(0, n);     const function<vector<int>(Node*)> solve = [&](Node* x) {       if (x->h < 0) return vector<int>{0, 0};       vector<int> ans{0};       for (Node* y : x->ys) {         vector<int> tmp = solve(y);         vector<int> r(static_cast<int>((ans).size()) +                       static_cast<int>((tmp).size()) - 1);         for (int i = int(0); i <= int((static_cast<int>((ans).size())) - 1); ++i)           for (int j = int(0); j <= int((static_cast<int>((tmp).size())) - 1);                ++j) {             setmax(r[i + j], ans[i] + tmp[j] + i * j * x->h);           }         ans = r;       }       if (static_cast<int>((ans).size()) > k + 1) ans.resize(k + 1);       return ans;     };     vector<int> ans = solve(root);     if (k < static_cast<int>((ans).size())) {       cout << ans[k] << endl;     } else {       cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long power(long long a, long long b, long long p) {     if (a == 0) return 0;     long long res = 1;     a %= p;     while (b > 0) {       if (b & 1) res = (res * a) % p;       b >>= 1;       a = (a * a) % p;     }     return res;   }   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     string t =   ;     for (long long i = 0; i < s.size(); i++) {       if (i + 1 < s.size()) {         if (s[i] ==  U  && s[i + 1] ==  R ) {           t +=  D ;           i = i + 1;         } else if (s[i] ==  R  && s[i + 1] ==  U ) {           t +=  D ;           i = i + 1;         } else {           t += s[i];         }       } else {         t += s[i];       }     }     cout << t.size() <<   n ;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000010;   struct Trie {     int next[maxn][26], fail[maxn];     int depth[maxn];     vector<int> sons[maxn];     int _dp[maxn][2];     int root, L;     int newnode() {       for (int i = 0; i < 26; i++) next[L][i] = -1;       return L++;     }     void init() {       L = 0;       root = newnode();       depth[root] = 0;     }     void insert(char buf[]) {       int len = strlen(buf);       int now = root;       for (int i = 0; i < len; i++) {         if (next[now][buf[i] -  a ] == -1) next[now][buf[i] -  a ] = newnode();         now = next[now][buf[i] -  a ];         depth[now] = i + 1;       }     }     void build() {       queue<int> Q;       fail[root] = root;       for (int i = 0; i < 26; i++)         if (next[root][i] == -1)           next[root][i] = root;         else {           fail[next[root][i]] = root;           Q.push(next[root][i]);         }       while (!Q.empty()) {         int now = Q.front();         Q.pop();         for (int i = 0; i < 26; i++)           if (next[now][i] == -1)             next[now][i] = next[fail[now]][i];           else {             fail[next[now][i]] = next[fail[now]][i];             Q.push(next[now][i]);           }       }     }     void build_edge() {       for (int i = 0; i < L; i++) sons[i].clear();       for (int i = 1; i < L; i++) {         int j = fail[i];         sons[j].push_back(i);       }     }     int dp(int u) {       _dp[u][0] = 0, _dp[u][1] = 1;       for (int i = 0; i < sons[u].size(); i++) {         int v = sons[u][i];         dp(v);         _dp[u][0] += max(_dp[v][0], _dp[v][1]);         _dp[u][1] +=             (depth[v] - depth[u] == 1) ? _dp[v][0] : max(_dp[v][0], _dp[v][1]);       }       return _dp[u][0];     }   };   char buf[maxn];   Trie ac;   int main() {     int T;     int n;     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       ac.init();       for (int i = 0; i < n; i++) {         scanf( %s , buf);         ac.insert(buf);       }       ac.build();       ac.build_edge();       printf( %d n , ac.dp(0));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 20;   const int MOD = (int)1e9 + 7;   const int dx[] = {0, -1, 0, 1, 0};   const int dy[] = {0, 0, 1, 0, -1};   struct Matrix {     long long mat[N][N];   };   bool blocked[N][N];   int m, n, q;   int size;   Matrix operator*(const Matrix a, const Matrix b) {     Matrix c;     for (int i = 0; i < size; ++i)       for (int j = 0; j < size; ++j) {         c.mat[i][j] = 0;         for (int k = 0; k < size; ++k)           c.mat[i][j] = (c.mat[i][j] + a.mat[i][k] * b.mat[k][j]) % MOD;       }     return c;   }   Matrix power(Matrix a, int p) {     Matrix ans;     memset(ans.mat, 0, sizeof(ans.mat));     for (int i = 0; i < size; ++i) ans.mat[i][i] = 1;     for (; p; p >>= 1) {       if (p & 1) ans = ans * a;       a = a * a;     }     return ans;   }   int getIndex(int x, int y) { return x * n + y; }   void update(Matrix &a) {     for (int i = 0; i < m; ++i)       for (int j = 0; j < n; ++j) {         int cur = getIndex(i, j);         for (int k = 0; k < size; ++k) a.mat[cur][k] = 0;         if (blocked[i][j]) continue;         for (int d = 0; d < 5; ++d) {           int x = i + dx[d], y = j + dy[d];           if (x < 0 || y < 0 || x >= m || y >= n || blocked[x][y]) continue;           a.mat[cur][getIndex(x, y)] = 1;         }       }   }   void multiply(Matrix gap, long long ans[]) {     int newAns[N];     for (int i = 0; i < size; ++i) {       newAns[i] = 0;       for (int j = 0; j < size; ++j)         newAns[i] = (newAns[i] + ans[j] * gap.mat[i][j]) % MOD;     }     for (int i = 0; i < size; ++i) ans[i] = newAns[i];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> m >> n >> q;     size = m * n;     Matrix a;     update(a);     long long ans[N];     memset(ans, 0, sizeof(ans));     ans[0] = 1;     int lastT = 1;     while (q--) {       int type, x, y, t;       cin >> type >> x >> y >> t;       --x;       --y;       Matrix gap = power(a, t - lastT - 1);       multiply(gap, ans);       multiply(a, ans);       if (type != 1) {         blocked[x][y] ^= 1;         update(a);       }       if (type == 1) cout << ans[getIndex(x, y)] <<   n ;       lastT = t;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 110;   int a[MAXN];   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     int n, i;     while (scanf( %d , &n) == 1) {       scanf( %d , &a[0]);       int temp = a[0];       int mmax = a[0];       for (i = 1; i < n; i++) {         scanf( %d , &a[i]);         temp = gcd(temp, a[i]);         mmax = max(a[i], mmax);       }       int ans = mmax / temp - n;       if (ans & 1)         printf( Alice n );       else         printf( Bob n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int MAXX = 2e6 + 10;   long long f(long long n) {     long long ret = n;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         while (n % i == 0) n /= i;         ret -= ret / i;       }     }     if (n > 1) ret -= ret / n;     return ret;   }   long long g(long long n) { return n; }   long long F(long long n, long long k) {     if (k == 1) return f(g(n));     if (n == 1) return 1ll;     if (k & 1)       return F(f(n), k - 1);     else       return F(g(n), k - 1);   }   int main() {     long long n, k;     scanf( %lld %lld , &n, &k);     long long ans = F(n, k);     printf( %lld , ans % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     pair<int, int> a[105];     for (int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i + 1;     }     sort(a, a + n);     for (int i = 0; i < n / 2; i++)       cout << a[i].second <<     << a[n - i - 1].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<string> checkWorks(vector<vector<bool>> arr) {     vector<int> row = vector<int>(n, 2);     vector<int> col = vector<int>(m, 2);     row[0] = 0;     for (int j = 0; j < m; j++) {       col[j] = arr[0][j];     }     bool works = true;     for (int i = 1; i < n; i++) {       for (int j = 0; j < m; j++) {         bool shouldBe = arr[i][j] ^ col[j];         if (row[i] == 2) {           row[i] = shouldBe;         } else {           if (row[i] != shouldBe) {             works = false;             break;           }         }       }       if (!works) break;     }     if (works) {       string a;       for (int i = 0; i < n; i++) {         if (row[i])           a.push_back( 1 );         else           a.push_back( 0 );       }       string b;       for (int j = 0; j < m; j++) {         if (col[j])           b.push_back( 1 );         else           b.push_back( 0 );       }       vector<string> ans;       ans.push_back(a);       ans.push_back(b);       return ans;     }     row[0] = 1;     for (int j = 0; j < m; j++) {       col[j] = !arr[0][j];     }     works = true;     for (int i = 1; i < n; i++) {       for (int j = 0; j < m; j++) {         bool shouldBe = arr[i][j] ^ col[j];         if (row[i] == 2) {           row[i] = shouldBe;         } else {           if (row[i] != shouldBe) {             works = false;             break;           }         }       }       if (!works) break;     }     if (works) {       string a;       for (int i = 0; i < n; i++) {         if (row[i])           a.push_back( 1 );         else           a.push_back( 0 );       }       string b;       for (int j = 0; j < m; j++) {         if (col[j])           b.push_back( 1 );         else           b.push_back( 0 );       }       vector<string> ans;       ans.push_back(a);       ans.push_back(b);       return ans;     }     return vector<string>();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     vector<vector<bool>> arr = vector<vector<bool>>(n, vector<bool>(m));     vector<vector<bool>> arrCopy = vector<vector<bool>>(n, vector<bool>(m));     int x;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> x;         if (x) {           arr[i][j] = false;         } else {           arr[i][j] = true;         }         arrCopy[i][j] = arr[i][j];       }     }     vector<string> maybe = checkWorks(arr);     if (maybe.size() > 0) {       cout <<  YES  << endl;       cout << maybe[0] << endl;       cout << maybe[1] << endl;       return 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         arrCopy[i][j] = !arr[i][j];         maybe = checkWorks(arrCopy);         if (maybe.size() > 0) {           cout <<  YES  << endl;           cout << maybe[0] << endl;           cout << maybe[1] << endl;           return 0;         }       }     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[100001];   int pmid;   int pfromside;   char sideequal[50001];   int leftplenty, rightplenty;   int ln[100001] = {0}, rn[100001] = {0};   int wn1[100001] = {0}, wn2[100001] = {0};   int possible(int l, int r) {     int includemid;     int left = l - 1;     int right = n - r;     int width = r - l + 1;     if (n & 1)       includemid = (l <= (n / 2 + 1) && r >= (n / 2 + 1));     else       includemid = (l <= (n / 2) && r > (n / 2));     if (includemid) {       if (left < right)         return (left <= pfromside) && (right <= rightplenty);       else         return (right <= pfromside) && (left <= leftplenty);     } else {       int side;       if (left < right)         side = left;       else         side = right;       return (side <= pfromside) && ((n - side - side - width - width) <= pmid) &&              (sideequal[side + width]);     }   }   int findminr(int l) {     int no, yes;     if (!possible(l, n)) return 0;     yes = n;     if (possible(l, l)) return l;     no = l;     while (no != yes - 1) {       int newmid = (yes + no) / 2;       if (possible(l, newmid))         yes = newmid;       else         no = newmid;     }     return yes;   }   int main() {     int i;     int minr;     long long total = 0;     int lj, rj;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     for (i = 1; i <= n / 2; i++) {       if (a[i] != a[n - i + 1]) break;     }     pfromside = i - 1;     pmid = n & 1;     lj = n / 2;     rj = n / 2 + 1 + (n & 1);     for (i = 0; i < n / 2; i++) {       if (a[lj] != a[rj]) break;       lj--;       rj++;     }     pmid += i * 2;     int wasequal, diffn = 0;     lj = 1;     rj = n;     sideequal[0] = 1;     for (i = 1; i <= n / 2; i++) {       wasequal = (ln[a[lj]] == rn[a[lj]]);       ln[a[lj]]++;       if (ln[a[lj]] == rn[a[lj]])         diffn--;       else if (wasequal)         diffn++;       wasequal = (ln[a[rj]] == rn[a[rj]]);       rn[a[rj]]++;       if (ln[a[rj]] == rn[a[rj]])         diffn--;       else if (wasequal)         diffn++;       if (diffn == 0)         sideequal[i] = 1;       else         sideequal[i] = 0;       lj++;       rj--;     }     int odds = 0;     for (i = 1; i <= n; i++) {       wn1[a[i]]++;       wn2[a[i]]++;       if (wn1[a[i]] & 1)         odds++;       else         odds--;     }     if (odds > 1) {       cout << 0;       return 0;     }     lj = 1;     for (i = 0; i < n / 2; i++) {       wn1[a[lj]] -= 2;       if (wn1[a[lj]] < 0) break;       lj++;     }     leftplenty = i;     rj = n;     for (i = 0; i < n / 2; i++) {       wn2[a[rj]] -= 2;       if (wn2[a[rj]] < 0) break;       rj--;     }     rightplenty = i;     for (i = 1; i <= n; i++) {       minr = findminr(i);       if (minr) total = total + (long long)(n - minr + 1);     }     cout << total;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[1003];   int main() {     long long n, s;     cin >> n >> s;     long long miner = 0x3f3f3f3f3f3f3f3f;     long long sumer = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];       sumer += a[i];       miner = min(miner, a[i]);     }     if (sumer < s) {       cout <<  -1  << endl;       return 0;     }     sumer = 0;     for (long long i = 0; i < n; i++) {       sumer += a[i] - miner;       a[i] = miner;     }     if (sumer >= s) {       cout << miner << endl;     } else {       long long need = s - sumer;       miner -= need / n;       if (need % n != 0) {         miner--;       }       cout << miner << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T BMOD(T p, T e, T m) {     T ret = 1;     while (e) {       if (e & 1) ret = (ret * p) % m;       p = (p * p) % m;       e >>= 1;     }     return (T)ret;   }   template <typename T>   inline T POW(T B, T P) {     if (P == 0) return 1;     if (P & 1)       return B * POW(B, P - 1);     else       return SQR(POW(B, P / 2));   }   template <typename T>   inline T ModInv(T b, T m) {     return BMOD(b, m - 2, m);   }   template <typename T>   inline T ABS(T a) {     if (a < 0)       return -a;     else       return a;   }   template <typename T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <typename T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};   int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};   int n, x, trck[200005], arr[100005];   int main() {     scanf( %d%d , &n, &x);     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]);       trck[arr[i]]++;     }     long long int res = 0;     for (int i = 1; i <= 100000; i++) {       int nm = i ^ x;       if (trck[nm] && trck[i]) {         long long int cnt = (long long int)trck[nm] * trck[i];         if (x == 0) cnt = (long long int)trck[nm] * (trck[i] - 1);         res += cnt;       }     }     res /= 2;     printf( %lld , res), puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T sqr(const T& a) {     return a * a;   }   template <typename T>   inline int sign(const T& a) {     return a < 0 ? -1 : a > 0;   }   void task();   int main() {     task();     return 0;   }   char dp[21][1 << 5][161050 + 10];   char par[21][1 << 5][161050 + 10];   int n, m;   int an[6], am[21];   vector<int> mask_by_cnt[6];   vector<int> to_11[161050 + 10];   int pw[11];   inline int to_number(vector<int>& v) {     return v[0] + v[1] * 11 + v[2] * 11 * 11 + v[3] * 11 * 11 * 11 +            v[4] * 11 * 11 * 11 * 11;   }   void task() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> an[i];     for (int i = 0; i < m; ++i) cin >> am[i];     pw[0] = 1;     for (int i = 1; i < 11; ++i) pw[i] = pw[i - 1] * 11;     for (int mask = 0; mask < (1 << n); ++mask) {       vector<int> v;       for (int j = 0; j < n; ++j) v.push_back((mask & (1 << j)) > 0);       v.push_back(17);       int cnt = 0;       for (int i = v.size() - 2; i >= 0; --i)         cnt += v[i] == 1 && v[i] != v[i + 1];       mask_by_cnt[cnt].push_back(mask);     }     for (int a = 0; a <= 10; ++a)       for (int b = 0; b <= 10; ++b)         for (int c = 0; c <= 10; ++c)           for (int d = 0; d <= 10; ++d)             for (int e = 0; e <= 10; ++e) {               int number = e + d * 11 + c * 11 * 11 + b * 11 * 11 * 11 +                            a * 11 * 11 * 11 * 11;               to_11[number] = {e, d, c, b, a};             }     int limit_number = 1;     for (int i = 0; i < n; ++i) limit_number *= 11;     dp[0][0][0] = 1;     par[0][0][0] = -1;     for (int i = 0; i < m; ++i)       for (int prev_mask : mask_by_cnt[i - 1 >= 0 ? am[i - 1] : 0])         for (int number = 0; number < limit_number; ++number)           if (dp[i][prev_mask][number])             for (int cur_mask : mask_by_cnt[am[i]]) {               int nb = number;               int ok = 1;               for (int j = 0; j < n; ++j)                 if ((prev_mask & (1 << j)) == 0 && (cur_mask & (1 << j)) > 0) {                   nb += pw[j];                   if (to_11[number][j] == an[j]) {                     ok = 0;                     break;                   }                 }               dp[i + 1][cur_mask][nb] = 1;               par[i + 1][cur_mask][nb] = prev_mask;             }     vector<int> v = {an[0], an[1], an[2], an[3], an[4]};     int number = to_number(v);     for (int mask = 0; mask < (1 << n); ++mask) {       if (dp[m][mask][number]) {         (void(1));         ;         vector<string> ans(n, string(m, 0));         int cur_mask = mask;         for (int i = m; i > 0; --i) {           for (int j = 0; j < n; ++j)             ans[j][i - 1] = (cur_mask & (1 << j)) > 0 ?  *  :  . ;           int prev_mask = par[i][cur_mask][number];           for (int j = 0; j < n; ++j)             if ((prev_mask & (1 << j)) == 0 && (cur_mask & (1 << j)) > 0) {               number -= pw[j];             }           cur_mask = prev_mask;         }         for (int i = 0; i < n; ++i) cout << ans[i] <<   n ;         return;       }     }     (void(1));     ;   }


#include <bits/stdc++.h>   using namespace std;   void magic() {     int n;     cin >> n;     int arr[n];     for (int i = 0; i < n; ++i) {       cin >> arr[i];     }     sort(arr, arr + n);     cout << min(arr[n - 1] - arr[1], arr[n - 2] - arr[0]) << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     magic();   }


#include <bits/stdc++.h>   using namespace std;   long long int is_prime[1000500];   int main() {     for (long long int i = 0; i < ((long long int)(1000500)); ++i)       if (2 <= i) is_prime[i] = true;     for (long long int i = 2; i * i < 1000500; i++) {       if (!is_prime[i]) continue;       for (long long int j = i * i; j < 1000500; j += i) is_prime[j] = false;     }     long long int a, b, k;     cin >> a >> b >> k;     queue<long long int> q;     long long int res = -1;     q.push(a - 1);     for (long long int pos = a; pos <= b; pos++) {       if (is_prime[pos]) q.push(pos);       while (k < ((long long int)(q).size())) q.pop();       if (((long long int)(q).size()) == k) res = max(res, pos - q.front() + 1);     }     if (q.front() == a - 1)       cout << -1 << endl;     else       cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long volume[100001][2];   vector<long long> sell, buy;   int main() {     long long n, s;     cin >> n >> s;     for (long long i = 0; i < n; i++) {       char a;       long long b, c, d;       cin >> a >> b >> c;       if (a ==  B )         d = 1;       else         d = 0;       if (volume[b][d] == 0) {         if (d == 0)           sell.push_back(b);         else           buy.push_back(b);       }       volume[b][d] += c;     }     sort(buy.begin(), buy.end());     sort(sell.begin(), sell.end());     for (long long i = 0; i < s; i++) {       if (s - i - 1 < sell.size() && s - i - 1 >= 0)         cout <<  S   << sell[s - i - 1] <<     << volume[sell[s - i - 1]][0]              << endl;     }     for (long long i = 0; i < s; i++) {       if (buy.size() - i - 1 >= 0)         cout <<  B   << buy[buy.size() - i - 1] <<                  << volume[buy[buy.size() - i - 1]][1] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long p[2007], hs[2007];   string q, w;   vector<int> k, st, st1, st2;   long long hashing(long long z, long long x) {     return (hs[x + 1] - hs[z]) * p[q.size() - x + 1];   }   void kmp_process() {     int g, h;     g = 0, h = -1, k[0] = -1;     while (g < w.length()) {       while (h >= 0 && w[g] != w[h]) h = k[h];       g++, h++;       k[g] = h;     }   }   void kmp_matching() {     int g, h;     g = h = 0;     while (g < q.length()) {       while (h >= 0 && q[g] != w[h]) h = k[h];       g++, h++;       if (h == w.length()) st.push_back(g - h), h = k[h];     }   }   int main() {     int g, h, f;     string a, s, as;     vector<long long> sst;     cin >> q >> a >> s;     w = a;     k.assign(2003, 0);     kmp_process();     kmp_matching();     st1 = st;     st.clear(), k.clear();     w = s;     k.assign(2003, 0);     kmp_process();     kmp_matching();     st2 = st;     st.clear();     for (g = 0; g < st2.size(); g++) st2[g] += (s.length() - 1);     p[0] = 1;     for (g = 1; g <= 2003; g++) {       p[g] = (p[g - 1] * 31);     }     for (g = 1; g <= q.length(); g++) {       hs[g] = hs[g - 1] + q[g - 1] * p[g];     }     long long xx = max(a.length(), s.length());     for (g = 0; g < st1.size(); g++) {       h = lower_bound(st2.begin(), st2.end(), st1[g]) - st2.begin();       for (; h < st2.size(); h++)         if (st2[h] - st1[g] + 1 >= xx) {           long long m = hashing(st1[g], st2[h]);           sst.push_back(m);         }     }     sort(sst.begin(), sst.end());     sst.erase(unique(sst.begin(), sst.end()), sst.end());     printf( %d n , sst.size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct vect {     int h, p1, p2;   };   struct point {     int p1, p2;   };   int n, mod, nr, t;   long long solf;   int viz[200005];   point poz[200005];   map<int, vect> h;   vector<int> aib[200005];   void precalc() {     int i, j, x;     for (i = 0; i < n; i++)       if (!viz[i]) {         x = 1;         j = i;         nr++;         do {           viz[j] = nr;           poz[j].p1 = x;           x++;           j = (j + mod) % n;         } while (!viz[j]);         j = i;         do {           poz[j].p2 = poz[j].p1 + x - 1;           j = (j + mod) % n;         } while (!poz[j].p2);         for (j = 0; j <= 2 * x; j++) aib[nr].push_back(0);       }   }   void update(int ind, int poz, int val) {     while (poz < aib[ind].size()) {       aib[ind][poz] += val;       poz += poz & -poz;     }   }   int query(int ind, int poz) {     int sol = 0;     while (poz > 0) {       sol += aib[ind][poz];       poz -= poz & -poz;     }     return sol;   }   int find(int x) {     int st = poz[x].p1, dr = poz[x].p2, m, sol = dr - 1;     int nr = st - query(viz[x], st);     while (st <= dr) {       m = (st + dr) >> 1;       if (m - query(viz[x], m) > nr) {         sol = m;         dr = m - 1;       } else         st = m + 1;     }     solf += sol - poz[x].p1;     sol = ((1LL * (sol - poz[x].p1) * mod) % n + x) % n;     return sol;   }   int main() {     scanf( %d %d %d n , &n, &mod, &t);     precalc();     vect x;     char ch;     int id, hash, y, z;     while (t--) {       scanf( %c , &ch);       if (ch ==  - ) {         scanf( %d n , &id);         x = h[id];         update(x.h, x.p1, -1);         update(x.h, x.p2, -1);         h[id] = (vect){0, 0, 0};       } else {         scanf( %d %d n , &id, &hash);         x.h = viz[hash];         x.p1 = poz[hash].p1;         x.p2 = poz[hash].p2;         y = query(x.h, x.p1);         z = query(x.h, x.p1 - 1);         if (y != z) hash = find(hash);         x.h = viz[hash];         x.p1 = poz[hash].p1;         x.p2 = poz[hash].p2;         h[id] = x;         update(x.h, x.p1, 1);         update(x.h, x.p2, 1);       }     }     printf( %I64d n , solf);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans = 0;   string searchS;   map<string, int> mp;   set<string> st;   void getans(string s, int idx) {     if (idx == searchS.size()) {       if (!st.count(s)) {         ans += mp[s];         st.insert(s);       }       return;     }     if (searchS[idx] ==  ? ) {       for (int i = 0; i < 5; i++) getans(s + char(i +  a ), idx + 1);       getans(s, idx + 1);     } else       getans(s + searchS[idx], idx + 1);   }   void lets_hope_its_right() {     int n, m;     cin >> n >> m;     while (n--) {       string s;       cin >> s;       mp[s]++;     }     while (m--) {       string s;       cin >> s;       ans = 0;       searchS = s;       st.clear();       getans(  , 0);       cout << ans <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt = 1;     while (tt--) lets_hope_its_right();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3050;   int a[N];   int b[N];   long long dp[N][N];   int main() {     int n, m, i, j;     long long ans = 0, minPre;     scanf( %d , &n);     set<int> S;     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       a[i] -= i;       S.insert(a[i]);     }     m = 0;     for (set<int>::iterator iter = S.begin(); iter != S.end(); iter++) {       b[++m] = *iter;     }     for (j = 1; j <= m; j++) {       dp[1][j] = abs(a[1] - b[j]);     }     for (i = 2; i <= n; i++) {       minPre = dp[i - 1][1];       for (j = 1; j <= m; j++) {         minPre = min(minPre, dp[i - 1][j]);         dp[i][j] = minPre + abs(a[i] - b[j]);       }     }     ans = 1e18;     for (j = 1; j <= m; j++) {       ans = min(ans, dp[n][j]);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 150 + 10;   void remax(int& x, int y) {     if (x < y) {       x = y;     }   }   int n;   char s[MAXN];   int a[MAXN];   bool read() {     if (scanf( %d n , &n) < 1) {       return 0;     }     for (int i = 0; i < (int)n; ++i) {       scanf( %d , &a[i + 1]);     }     scanf(  n );     scanf( %s n , s);     assert((int)strlen(s) == n);     return 1;   }   int dp[MAXN][MAXN];   int dp_pal[MAXN][MAXN][MAXN];   int dp_full[MAXN][MAXN];   int solve() {     memset(dp, 0, sizeof dp);     memset(dp_full, -1, sizeof dp_full);     memset(dp_pal, -1, sizeof dp_pal);     for (int len = 1; len <= n; ++len) {       for (int l = 0; l < (int)n - len + 1; ++l) {         int r = l + len - 1;         assert(r < n);         {           for (int m = l; m < r; ++m) {             if (dp_full[l][m] != -1 && dp_full[m + 1][r] != -1) {               remax(dp_full[l][r], dp_full[l][m] + dp_full[m + 1][r]);             }           }           if (s[l] == s[r]) {             if (len <= 2) {               remax(dp_full[l][r], a[len]);             } else {               remax(dp_full[l][r], dp_pal[l + 1][r - 1][2]);             }           }         }         {           for (int m = l; m < r; ++m) {             remax(dp[l][r], dp[l][m] + dp[m + 1][r]);           }           remax(dp[l][r], dp_full[l][r]);         }         {           for (int out = 2; out <= n - len; out += 2) {             if (dp_full[l][r] != -1 && a[out] != -1) {               remax(dp_pal[l][r][out], dp_full[l][r] + a[out]);             }             for (int m = l; m < r; ++m) {               if (dp_pal[l][m][out] != -1 && dp_full[m + 1][r] != -1) {                 remax(dp_pal[l][r][out], dp_pal[l][m][out] + dp_full[m + 1][r]);               }             }             for (int m = l + 1; m <= r; ++m) {               if (dp_full[l][m - 1] != -1 && dp_pal[m][r][out] != -1) {                 remax(dp_pal[l][r][out], dp_full[l][m - 1] + dp_pal[m][r][out]);               }             }             if (s[l] == s[r]) {               if (len <= 2) {                 remax(dp_pal[l][r][out], a[out + len]);               } else {                 remax(dp_pal[l][r][out], dp_pal[l + 1][r - 1][out + 2]);               }             }           }         }       }     }     return dp[0][n - 1];   }   int main() {     while (read()) {       printf( %d n , solve());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long int q;     cin >> q;     while (q--) {       long long int l1, r1, l2, r2;       cin >> l1 >> r1 >> l2 >> r2;       cout << l1 <<     << ((l1 != l2) ? l2 : r2) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 3e5 + 10;   class SegmentTree {    public:     long long addv[N * 4];     int ql, qr, qx;     void set(int l, int r, int x = 0) { ql = l, qr = r, qx = x; }     void add(int l, int r, int o = 1) {       if (ql <= l && r <= qr) {         addv[o] += qx;         return;       }       int mid = (l + r) >> 1;       if (ql <= mid) add(l, mid, o << 1);       if (mid < qr) add(mid + 1, r, o << 1 | 1);     }     long long query(int l, int r, int o = 1) {       long long ret = addv[o];       if (l == r) {         return ret;       }       int mid = (l + r) >> 1;       if (ql <= mid) ret += query(l, mid, o << 1);       if (mid < qr) ret += query(mid + 1, r, o << 1 | 1);       return ret;     }   } st;   vector<int> v[N];   vector<pair<int, int>> qr[N];   int depth[N];   int h = 0;   long long ans[N];   void dfs(int x, int fa = 0) {     depth[x] = depth[fa] + 1;     h = max(h, depth[x]);     for (auto &y : v[x]) {       if (y == fa) continue;       dfs(y, x);     }   }   void solve(int x, int fa = 0) {     int l = depth[x];     for (auto &p : qr[x]) {       int r;       int val;       tie(r, val) = p;       st.set(l, r, val);       st.add(1, h);     }     st.set(l, l);     ans[x] = st.query(1, h);     for (auto &y : v[x]) {       if (y == fa) continue;       solve(y, x);     }     for (auto &p : qr[x]) {       int r;       int val;       tie(r, val) = p;       st.set(l, r, -val);       st.add(1, h);     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1);     int q;     scanf( %d , &q);     while (q--) {       int x, d, val;       scanf( %d%d%d , &x, &d, &val);       d = min(h, depth[x] + d);       qr[x].push_back({d, val});     }     solve(1);     for (int i = 1; i <= n; i++) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 7;   const long long inf = 0x3f3f3f3f;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       double pi = 3.1415926535897932384626433832795028841971, n;       cin >> n;       printf( %.10lf n , 1 / tan(pi / (n * 2)));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, n, x, j, c = 0;     cin >> n >> x;     if (n >= x) {       for (i = 2; i <= n; i++) {         if (x % i == 0 && (x / i) <= n) c++;       }       cout << c + 1 << endl;     } else {       for (i = 2; i <= n; i++) {         if (x % i == 0 && (x / i) <= n) c++;       }       cout << c << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     scanf( %d , &N);     int P;     scanf( %d , &P);     vector<int> As, Bs;     long long SA = 0, SB = 0;     for (decltype(N) _i = 0, _n = (N); _i < _n; _i++) {       int A;       scanf( %d , &A);       int B;       scanf( %d , &B);       As.push_back(A);       Bs.push_back(B);       SA += A;       SB += B;     }     auto check = [&](double t) {       double tmp = 0.0;       for (decltype(N) i = 0, _n = (N); i < _n; i++) {         tmp += max(As[i] * t - Bs[i], 0.0) / P;       }       return tmp <= t;     };     if (SA <= P) {       printf( -1 n );     } else {       double l = 0.0, r = SB * 2.0;       int cnt = 0;       while (1e-10 < (r - l) and cnt < 1000) {         cnt++;         double c = (l + r) / 2;         if (check(c)) {           l = c;         } else {           r = c;         }       }       printf( %f , l);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 9e18;   const long long N = 2e5 + 5;   const long long M = 1e9 + 7;   bool chk(vector<long long> a, long long x, long long y) {     long long A = 0, B = 0;     for (long long i = 2; i < a.size(); i++)       if (a[i] > a[i - 1] && a[i] > a[i + 1])         A++;       else if (a[i] < a[i - 1] && a[i] < a[i + 1])         B++;     if (A == x && B == y) return 1;     return 0;   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0);     long long tests;     cin >> tests;     while (tests--) {       vector<long long> a;       long long n, x, y;       bool ok = 0;       cin >> n >> x >> y;       if (abs(x - y) > 1 || x + y > n - 2) {         cout <<  -1 n ;         continue;       }       if (x >= y) {         long long l = 1;         long long r = n;         while (l <= r) {           a.push_back(l++);           if (l > r) break;           a.push_back(r--);         }         long long idx = 1 + 2 * y;         if (x > y) idx++;         sort(a.begin() + idx, a.begin() + n);         if (x > y) reverse(a.begin() + idx, a.begin() + n);       } else {         long long l = 1;         long long r = n;         while (l <= r) {           a.push_back(r--);           if (l > r) break;           a.push_back(l++);         }         long long idx = 2 * y;         sort(a.begin() + idx, a.begin() + n);       }       for (auto h : a) cout << h <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int q;     std::cin >> q;     while (q--) {       int n;       std::cin >> n;       std::cout << ((n + 6) / 7) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 10, mod = 11092019;   int n, m[2], leaf[N][2], dep[N][2], p[16][2][N], pre[N][2], dist[N][N][2],       dp[N][2];   vector<int> adj[N][2];   void predfs(int u, int pa, int lst, bool st) {     p[0][st][u] = pa;     dep[u][st] = dep[pa][st] + 1;     pre[u][st] = lst;     lst = (adj[u][st].size() > 1 ? u : lst);     for (int v : adj[u][st]) {       predfs(v, u, lst, st);     }   }   pair<int, int> lca(int u, int v, bool st) {     int dis = 0;     if (dep[u][st] > dep[v][st]) swap(u, v);     for (int j = 15; j >= 0; j--) {       if (dep[v][st] - (1 << j) >= dep[u][st]) {         dis += (1 << j);         v = p[j][st][v];       }     }     if (u == v) return {u, dis};     dis += 2;     for (int j = 15; j >= 0; j--) {       if (p[j][st][u] != p[j][st][v]) {         u = p[j][st][u];         v = p[j][st][v];         dis += (2 << j);       }     }     return {p[0][st][u], dis};   }   int main() {     scanf( %d , &n);     for (int s = 0; s < 2; s++) {       scanf( %d , &m[s]);       for (int i = 2; i <= m[s]; i++) {         int x;         scanf( %d , &x);         adj[x][s].push_back(i);       }       for (int i = 1; i <= n; i++) {         int x;         scanf( %d , &x);         leaf[i][s] = x;       }     }     predfs(1, 1, 1, 0);     predfs(1, 1, 1, 1);     for (int j = 1; j < 16; j++) {       for (int st = 0; st < 2; st++) {         for (int i = 1; i <= m[st]; i++)           p[j][st][i] = p[j - 1][st][p[j - 1][st][i]];       }     }     for (int st = 0; st < 2; st++) {       for (int i = 1; i <= n; i++) {         int dis = 0;         vector<int> sum(m[st] + 1, 0);         for (int j = i; j <= n; j++) {           int v = leaf[j][st];           int u = pre[v][st];           dis += dep[v][st] - dep[u][st];           sum[u]++;           while (sum[u] == adj[u][st].size()) {             dis += dep[u][st] - dep[pre[u][st]][st];             u = pre[u][st];             sum[u]++;           }           dist[i][j][st] = dis;         }       }     }     for (int i = 1; i <= n; i++) {       for (int st = 0; st < 2; st++) {         for (int j = i; j >= 1; j--)           dp[i][st] = max(dp[i][st], dp[j - 1][1 - st] + dist[j][i][st]);       }     }     printf( %d n , max(dp[n][0], dp[n][1]));     return 0;   }


#include <bits/stdc++.h>   int n, k, a[100001], is[100001], i, j, sum, ans;   int main() {     scanf( %d %d , &n, &k);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < n; i++) scanf( %d , &is[i]);     for (i = 0; i < k; i++) sum += a[i];     for (i = k; i < n; i++)       if (is[i]) sum += a[i];     ans = sum;     for (i = 0; i < n - k + 1; i++) {       if (is[i] == 0) sum -= a[i];       if (is[i + k] == 0) sum += a[i + k];       if (ans < sum) ans = sum;     }     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int N, M, ans, S, T, C;   pair<int, int> ap;   struct edge {     int u, v, w, i;     bool operator<(const edge &o) const { return w < o.w; }   } tmp[30300];   vector<edge> e;   vector<pair<int, int>> adj[1100];   int id[1100], lo[1100], tp[1100], ep[1100];   bool art[1100];   struct uf {     int p[1100];     void init() {       for (int i = (1); i < (N + 1); i++) p[i] = i;     }     int g(int i) { return p[i] == i ? i : p[i] = g(p[i]); }     bool c(int i, int j) { return g(i) == g(j); }     void m(int i, int j) { p[g(i)] = g(j); }   } a, b, c;   void clr() {     for (int i = (1); i < (N + 1); i++) {       adj[i].clear();       id[i] = 0, lo[i] = 0, art[i] = 0;       tp[i] = 0, ep[i] = 0;     }     C = 0;   }   void go(int i, int p) {     id[i] = ++C;     lo[i] = id[i];     for (auto j : adj[i]) {       if (j.first == p)         p = -1;       else if (!id[j.first]) {         tp[j.first] = i;         ep[j.first] = j.second;         go(j.first, i);         lo[i] = min(lo[i], lo[j.first]);       } else         lo[i] = min(lo[i], id[j.first]);     }     if (lo[i] == id[i]) art[i] = 1;   }   int main() {     scanf( %d %d %d %d , &N, &M, &S, &T);     a.init(), b.init(), c.init(), ans = 2e9 + 7, ap = {-1, -1};     for (int i = (0); i < (M); i++) {       scanf( %d %d %d , &tmp[i].u, &tmp[i].v, &tmp[i].w);       tmp[i].i = i + 1;     }     sort(tmp, tmp + M);     for (int i = (0); i < (M); i++) {       if (!a.c(tmp[i].u, tmp[i].v)) {         a.m(tmp[i].u, tmp[i].v);         e.push_back(tmp[i]), e.back().i = i;       } else if (!b.c(tmp[i].u, tmp[i].v)) {         b.m(tmp[i].u, tmp[i].v);         e.push_back(tmp[i]), e.back().i = i;       } else if (!c.c(tmp[i].u, tmp[i].v)) {         c.m(tmp[i].u, tmp[i].v);         e.push_back(tmp[i]), e.back().i = i;       }     }     if (!a.c(S, T)) return puts( 0 n0 ), 0;     clr();     for (int i = (0); i < ((int)e.size()); i++) {       adj[e[i].u].push_back({e[i].v, e[i].i}),           adj[e[i].v].push_back({e[i].u, e[i].i});     }     go(S, -1);     int x = T;     while (x != S) {       if (art[x]) {         if (tmp[ep[x]].w < ans) {           ans = tmp[ep[x]].w;           ap = {tmp[ep[x]].i, -1};         }       }       x = tp[x];     }     for (int rem = (0); rem < ((int)e.size()); rem++) {       int extra = 0, rid = -1;       clr();       for (int i = (0); i < ((int)e.size()); i++) {         if (i != rem) {           adj[e[i].u].push_back({e[i].v, e[i].i}),               adj[e[i].v].push_back({e[i].u, e[i].i});         } else           extra = e[i].w, rid = tmp[e[i].i].i;       }       go(S, -1);       if (!id[T]) continue;       x = T;       while (x != S) {         if (art[x]) {           if (tmp[ep[x]].w + extra < ans) {             ans = tmp[ep[x]].w + extra;             ap = {tmp[ep[x]].i, rid};           }         }         x = tp[x];       }     }     if (ans == 2e9 + 7)       puts( -1 );     else {       printf( %d n , ans);       if (ap.second == -1) {         printf( 1 n%d n , ap.first);       } else {         printf( 2 n%d %d n , ap.first, ap.second);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int N = 1e6 + 100;   int n, m, q;   struct Qu {     int op, x;   } qu[N];   struct Edge {     int u, v, w;     bool operator<(const Edge& t) const { return w < t.w; }   } edge[N];   struct Max {     int val, pos;     Max() {}     Max(int val, int pos) : val(val), pos(pos) {}     static Max inf() { return Max(-0x3f3f3f3f, 0); }     bool operator<(const Max& t) const { return val < t.val; }   };   struct Node {     int l, r;     Max mmax;   } tree[N << 2];   int a[N], f[N], val[N], dp[N][25], L[N], R[N], id[N], tot;   vector<int> node[N];   void pushup(int k) {     tree[k].mmax = max(tree[k << 1].mmax, tree[k << 1 | 1].mmax);   }   void build(int k, int l, int r) {     tree[k].l = l;     tree[k].r = r;     if (l == r) {       tree[k].mmax.val = a[id[l]];       tree[k].mmax.pos = l;       return;     }     int mid = l + r >> 1;     build(k << 1, l, mid);     build(k << 1 | 1, mid + 1, r);     pushup(k);   }   void update(int k, int pos) {     if (tree[k].l == tree[k].r) {       tree[k].mmax.val = 0;       return;     }     int mid = tree[k].l + tree[k].r >> 1;     if (pos <= mid)       update(k << 1, pos);     else       update(k << 1 | 1, pos);     pushup(k);   }   Max query(int k, int l, int r) {     if (tree[k].l > r || tree[k].r < l) return Max::inf();     if (tree[k].l >= l && tree[k].r <= r) return tree[k].mmax;     return max(query(k << 1, l, r), query(k << 1 | 1, l, r));   }   void dfs(int u, int fa) {     dp[u][0] = fa;     for (int i = 1; i <= 20; i++) dp[u][i] = dp[dp[u][i - 1]][i - 1];     L[u] = ++tot;     id[tot] = u;     for (auto v : node[u]) dfs(v, u);     R[u] = tot;   }   int get_pos(int u, int up) {     for (int i = 20; i >= 0; i--)       if (dp[u][i] != 0 && val[dp[u][i]] <= up) u = dp[u][i];     return u;   }   int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }   int Ex_Kruskal() {     for (int i = 1; i <= n << 1; i++) f[i] = i;     int index = n;     sort(edge + 1, edge + 1 + m);     for (int i = 1; i <= m; i++) {       int xx = find(edge[i].u), yy = find(edge[i].v);       if (xx != yy) {         f[xx] = f[yy] = ++index;         val[index] = edge[i].w;         node[index].push_back(xx);         node[index].push_back(yy);       }     }     int last = 1;     for (int i = 1; i <= n; i++) {       int xx = find(last), yy = find(i);       if (xx != yy) {         f[xx] = f[yy] = ++index;         val[index] = inf;         node[index].push_back(xx);         node[index].push_back(yy);         last = index;       }     }     return index;   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &edge[i].u, &edge[i].v);       edge[i].w = 0;     }     int val = inf;     for (int i = 1; i <= q; i++) {       scanf( %d%d , &qu[i].op, &qu[i].x);       if (qu[i].op == 2) edge[qu[i].x].w = --val;     }     int root = Ex_Kruskal();     dfs(root, 0);     build(1, 1, root);     val = inf - 1;     for (int i = 1; i <= q; i++) {       if (qu[i].op == 1) {         int x = get_pos(qu[i].x, val);         Max ans = query(1, L[x], R[x]);         printf( %d n , ans.val);         update(1, ans.pos);       } else         val--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long part[4001];   unsigned long long pmod(unsigned long long n, int exp) {     unsigned long long x = 1, y = n;     while (exp > 0) {       if (1 == (exp % 2)) {         x = x * y;         if (x > 1000000007) x = x % 1000000007;       }       y = y * y;       if (y > 1000000007) y = y % 1000000007;       exp /= 2;     }     return x;   }   unsigned long long inv(unsigned long long x) { return pmod(x, 1000000007 - 2); }   unsigned long long Rfact[4001];   unsigned long long Ifact[4001];   unsigned long long fact(int x) {     if (!Rfact[x]) {       unsigned long long ret = 1;       for (int i = x; i >= 2; i--) {         ret = (ret * i) % 1000000007;       }       Rfact[x] = ret;     }     return Rfact[x];   }   unsigned long long inv_fact(int x) {     if (!Ifact[x]) {       Ifact[x] = inv(fact(x));     }     return Ifact[x];   }   unsigned long long com(int n, int r) {     unsigned long long ret = fact(n);     ret = (ret * inv_fact(n - r)) % 1000000007;     ret = (ret * inv_fact(r)) % 1000000007;     return ret;   }   int main() {     part[0] = part[1] = 1;     for (int i = 2; i <= 4000; i++) {       for (int j = 0; j < i; j++) {         unsigned long long tadd = (com(i - 1, j) * part[j]) % 1000000007;         part[i] = (part[i] + tadd) % 1000000007;       }     }     int n;     cin >> n;     unsigned long long ret = 0;     for (int i = 1; i <= n; i++) {       unsigned long long tadd = (com(n, i) * part[n - i]) % 1000000007;       ret = (ret + tadd) % 1000000007;     }     cout << ret << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int sz[100005];   long long pw[100005];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       sz[a]++;       sz[b]++;     }     int lf = 0;     for (int i = 1; i <= n; i++)       if (sz[i] == 1) lf++;     pw[0] = 1LL;     for (int i = 1; i <= 100000; i++) pw[i] = (pw[i - 1] * 2) % 1000000007;     long long res = lf * pw[n - lf + 1] + (n - lf) * pw[n - lf];     res %= 1000000007;     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     long long ss4 = 0, ss7 = 0, swap = 0;     string s, t;     cin >> s >> t;     for (long long i = 0; i < s.length(); i++) {       if (s[i] != t[i] && s[i] ==  4 ) {         if (ss7)           ss7--, swap++;         else           ss4++;       } else if (s[i] != t[i] && s[i] ==  7 )         if (ss4)           ss4--, swap++;         else           ss7++;     }     cout << swap + ss7 + ss4 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     set<int> ase;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       if (ase.size() >= x) {         ase.insert(x);       } else {         cout << i << endl;         return 0;       }     }     cout << -1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, half;   long long k, ans = 0, a[25][25];   map<long long, int> mp[20][20];   void calcf(int x, int y, long long val, int cnt) {     val ^= a[x][y];     if (cnt == half) {       mp[x][y][val]++;       return;     }     if (x + 1 < n) calcf(x + 1, y, val, cnt + 1);     if (y + 1 < m) calcf(x, y + 1, val, cnt + 1);   }   void calcb(int x, int y, long long val, int cnt) {     if (cnt == n + m - 2 - half) {       if (mp[x][y].count(val ^ k)) ans += mp[x][y][val ^ k];       return;     }     val ^= a[x][y];     if (x > 0) calcb(x - 1, y, val, cnt + 1);     if (y > 0) calcb(x, y - 1, val, cnt + 1);   }   int main() {     int i, j;     cin >> n >> m >> k;     half = (n + m - 2) / 2;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) cin >> a[i][j];     calcf(0, 0, 0, 0);     calcb(n - 1, m - 1, 0, 0);     cout << ans;   }