#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   int getid(string s) {     int len = ((int)(s).size()), id = 0;     if (len > 19) return -1;     for (int j = 0; j < len; j++) id = id * 2 + s[j] -  0 ;     return id + (1 << len) - 2;   }   int n, m, u, v;   char s[110];   string t;   struct blk {     string bg, ed;     bitset<1048576> S;     bool full;     void add(string s) {       int m = ((int)(s).size());       for (int j = 0; j < m; j++)         for (int k = j; k < m; k++) {           string f = s.substr(j, k - j + 1);           int id = getid(f);           if (id == -1) continue;           S[id] = 1;         }     }     void simply() {       if (((int)(bg).size()) > 20) {         bg = bg.substr(0, 20);         full = 0;       }       if (((int)(ed).size()) > 20) {         ed = ed.substr(((int)(ed).size()) - 20, 20);         full = 0;       }     }     int query() {       for (int i = 20 - 1; i >= 1; i--) {         int d = (1 << i) - 2, val = 1;         for (int j = 0; j < (1 << i); j++) {           if (!S[d + j]) {             val = 0;             break;           }         }         if (val) return i;       }       return 0;     }   } b[210];   void gao(int p, int u, int v) {     b[p].S = b[u].S | b[v].S;     if (b[u].full)       b[p].bg = b[u].bg + b[v].bg, b[p].full = 1;     else       b[p].bg = b[u].bg;     if (b[v].full)       b[p].ed = b[u].ed + b[v].ed, b[p].full = 1;     else       b[p].ed = b[v].ed;     b[p].add(b[u].ed + b[v].bg);     b[p].simply();   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %s , s);       t = s;       b[i].add(t);       b[i].bg = t;       b[i].ed = t;       b[i].full = 1;       b[i].simply();     }     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &u, &v);       gao(n + i, u - 1, v - 1);       printf( %d n , b[n + i].query());     }   }


#include <bits/stdc++.h>   int main() {     int i, j, l, flag;     char arr[1000100], arr2[1000100];     gets(arr);     l = strlen(arr);     for (flag = 0, j = 0, i = 0; i < l - 1; i++) {       if (arr[i] ==  0  && flag == 0) {         flag = 1;         continue;       } else         arr2[j++] = arr[i];     }     if (flag == 1) arr2[j++] = arr[l - 1];     printf( %s n , arr2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1e9;   const long long LINF = INF * (long long)INF + 100;   const double EPS = 1e-7;   const int MAX = 20 * 1000 + 47;   const int MAS = 2 * 1e5 + 10;   const int MOD = 998244353;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<string> s(n);       for (int i = (0); i < (n); i++) {         cin >> s[i];       }       vector<vector<int>> g(n);       vector<string> s1(n);       vector<vector<int>> p(n * m, vector<int>(21));       for (int i = (0); i < (n); i++) {         cin >> s1[i];         for (int j = (0); j < (m); j++) {           int num = i * m + j;           if (s1[i][j] ==  R ) {             p[num][0] = num + 1;           }           if (s1[i][j] ==  L ) {             p[num][0] = num - 1;           }           if (s1[i][j] ==  U ) {             p[num][0] = num - m;           }           if (s1[i][j] ==  D ) {             p[num][0] = num + m;           }         }       }       for (int k = (1); k < (21); k++) {         for (int i = (0); i < (n * m); i++) {           p[i][k] = p[p[i][k - 1]][k - 1];         }       }       set<int> all;       set<int> black;       for (int i = (0); i < (n); i++)         for (int j = (0); j < (m); j++) {           int num = (i * m + j);           int p1 = p[num][20];           all.insert(p1);           if (s[i][j] ==  0 ) {             black.insert(p1);           }         }       cout << all.size() <<     << black.size() << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   namespace Flandre_Scarlet {   int I() {     char c = getchar();     int x = 0;     int f = 1;     while (c <  0  or c >  9 ) f = (c ==  - ) ? -1 : 1, c = getchar();     while (c >=  0  and c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return (x = (f == 1) ? x : -x);   }   template <typename T>   void Rd(T& arg) {     arg = I();   }   template <typename T, typename... Types>   void Rd(T& arg, Types&... args) {     arg = I();     Rd(args...);   }   void RA(int* p, int n) {     for (int i = 1; i <= n; ++i) *p = I(), ++p;   }   int n, a[200005];   void Input() {     n = I();     RA(a + 1, n);   }   int st[200005][18];   short lg[200005];   inline int gcd(int a, int b) {     while (b) {       a ^= b ^= a ^= b;       b %= a;     }     return a;   }   void SparseTable() {     memset(lg, -1, sizeof(lg));     for (int i = 0; i <= 17; ++i)       if ((1 << i) <= n) lg[1 << i] = i;     for (int i = 1; i <= n; ++i)       if (lg[i] == -1) lg[i] = lg[i - 1];     for (int i = 1; i <= n; ++i) st[i][0] = a[i];     for (int j = 1; j <= 17; ++j) {       for (int i = 1; i <= n; ++i)         st[i][j] = gcd(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);     }   }   inline int Query(int l, int r) {     int k = lg[r - l + 1];     return gcd(st[l][k], st[r - (1 << k) + 1][k]);   }   unordered_map<int, long long> ans;   int GetNex(int l, int g) {     if (Query(l, n) == g) return n + 1;     int cur = l;     for (int i = 17; i >= 0; --i)       if (st[cur][i] % g == 0) cur = cur + (1 << i);     return cur;   }   void Soviet() {     SparseTable();     for (int i = n; i >= 1; --i) {       int g = a[i];       for (register int l = i, r; l <= n; l = r) {         r = GetNex(i, g);         ans[g] += r - l;         if (r == n + 1) break;         g = gcd(g, a[r]);       }     }     int q = I();     for (int i = 1; i <= q; ++i) printf( %lld n , ans[I()]);   }   void IsMyWife() {     Input();     Soviet();   }   }  // namespace Flandre_Scarlet   int main() {     Flandre_Scarlet::IsMyWife();     getchar();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf(1010101010);   int n, k;   struct node_t {     node_t(char edge, int h) : edge(edge), hier(0), pop(0), h(h) {}     char edge;     int hier, pop;     int h;     vector<node_t *> child;   };   void ins(node_t *x, char *pos) {     x->pop++;     if (!pos[0]) {       x->hier++;       return;     }     for (__typeof((x->child).end()) it((x->child).begin());          it != ((x->child).end()); ++it) {       node_t *y(*it);       if (y->edge == pos[0]) {         ins(y, ++pos);         return;       }     }     x->child.push_back(new node_t(pos[0], x->h + 1)), ins(x->child.back(), ++pos);   }   char bla[2005];   vector<vector<int> > mems;   int new_mem() {     mems.push_back(vector<int>());     return ((int)(mems).size()) - 1;   }   inline int tri(int x) { return x * (x - 1) / 2; }   inline void chmax(int &x, int y) { x = max(x, y); }   inline void merge(vector<int> &dst, vector<int> &erbij, int hh) {     int cnt_bij(((int)(erbij).size()) - 1);     dst.resize(((int)(dst).size()) + cnt_bij);     for (int i(((int)(dst).size()) - 1); ~i; i--) {       for (int bij(0); bij <= cnt_bij && bij <= i; bij++) {         chmax(dst[i], dst[i - bij] + erbij[bij] +                           hh * (tri(i) - tri(i - bij) - tri(bij)));       }     }   }   int calc(node_t *x) {     if (x->hier == 0 && ((int)(x->child).size()) == 1) return calc(x->child[0]);     int pt(new_mem());     if (((int)(x->child).size()) == 0) {       mems[pt].resize(x->pop + 1);       for (int i(0); i <= (x->pop); i++) {         mems[pt][i] = tri(i) * x->h;       }     } else {       node_t *y0(x->child[0]);       int y0pos(calc(y0));       mems[pt].assign((mems[y0pos]).begin(), (mems[y0pos]).end());       int ander(y0->pop);       for (__typeof((x->child).end()) it((x->child).begin() + 1);            it != ((x->child).end()); ++it) {         node_t *y(*it);         int ypos(calc(y));         merge(mems[pt], mems[ypos], x->h);         ander += y->pop;       }       for (int i(ander + 1); i <= (ander + x->hier); i++) {         mems[pt].push_back(mems[pt][ander] + (tri(i) - tri(ander)) * x->h);       }     }     return pt;   }   void solve() {     if (!(cin >> n >> k)) exit(0);     node_t *root(new node_t( - , 0));     for (int i(0); i < (n); i++) {       scanf( %s , bla), ins(root, bla);     }     int rr(calc(root));     cout << mems[rr][k] << endl;   }   int main() {     while (1) solve();   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int d;     struct Node *left, *right;   };   int p[1000][1000] = {0};   string s, t;   void dp(int i, int j) {     if (j - i + 1 == t.size()) {       int f = 1;       for (int z = 0; z < t.size(); z++) {         if (s[i + z] != t[z]) {           f = 0;           break;         }       }       if (f == 1) p[i][j] = 1;     } else if (j - i + 1 < t.size())       return;     else if (j - i + 1 > t.size()) {       int maxm = 0, l = t.size();       for (int x = i; x <= j - l + 1; x++) {         if (p[x][x + l - 1] > 0) p[i][j]++;       }     }     return;   }   int main() {     int n, m, q;     cin >> n >> m >> q;     int a[q][2];     getchar();     cin >> s;     getchar();     cin >> t;     for (int i = 0; i <= q - 1; i++) {       cin >> a[i][0] >> a[i][1];     }     int l = t.size();     for (int si = l; si <= n; si++) {       for (int j = 0; j <= n - si; j++) dp(j, j + si - 1);     }     for (int i = 0; i <= q - 1; i++) cout << p[a[i][0] - 1][a[i][1] - 1] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string one, two;     cin >> one >> two;     int odin = 0, dva = 0;     for (int i = 0; i < one.length(); i++)       if (one[i] ==  1 ) odin++;     for (int j = 0; j < two.length(); j++)       if (two[j] ==  1 ) dva++;     if (odin & 1 && odin + 1 >= dva)       cout <<  YES ;     else if (!(odin & 1) && odin >= dva)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double eps = 1e-10;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long h, l;     while (cin >> h >> l) {       double L = 0.0, R = 10000000.0;       long long ans = l * l - h * h;       printf( %.13f n , ans / (2.0 * h));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   bool super(string s) {     int sv = 0, f = 0;     for (int i = 0; i < s.length(); ++i) {       (s[i] ==  7  ? sv += 1 : f += 1);     }     return (sv == f ? true : false);   }   long long strtoll(string s) {     long long res = 0;     for (int i = 0; i < s.length(); ++i) {       res = res * 10 + (s[i] -  0 );     }     return res;   }   void gennbrs(string s) {     if (s.length() == 11) return;     if (s !=    and super(s)) v.push_back(strtoll(s));     gennbrs(s +  4 );     gennbrs(s +  7 );   }   int main() {     gennbrs(  );     sort(v.begin(), v.end());     int n;     scanf( %d , &n);     for (int i = 0; i < v.size(); ++i) {       if (v[i] >= n) {         cout << v[i] << endl;         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, t;   char S[25][100005];   long long f[1048576], dp[1048576];   int ans;   inline void Read(int &p) {     p = 0;     char c = getchar();     for (; c <  0  || c >  9 ; c = getchar())       ;     for (; c >=  0  && c <=  9 ; c = getchar()) p = p * 10 + c -  0 ;   }   inline void XorFWT(int n, long long *A) {     for (int i = 1; i < n; i <<= 1) {       for (int j = 0; j < n; j += (i << 1)) {         for (int k = 0; k < i; k++) {           long long x = A[j + k] + A[j + k + i];           long long y = A[j + k] - A[j + k + i];           A[j + k] = x, A[j + k + i] = y;         }       }     }   }   inline void XorIFWT(int n, long long *A) {     for (int i = 1; i < n; i <<= 1) {       for (int j = 0; j < n; j += (i << 1)) {         for (int k = 0; k < i; k++) {           long long x = A[j + k] + A[j + k + i];           long long y = A[j + k] - A[j + k + i];           A[j + k] = x / 2;           A[j + k + i] = y / 2;         }       }     }   }   inline void mul(long long *A, long long *B, int w) {     for (int i = 0; i < w; i++) A[i] = A[i] * B[i];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %s , S[i] + 1);     for (int i = 1; i <= m; i++) {       int v = 0;       for (int j = 1; j <= n; j++) v = v * 2 + S[j][i] -  0 ;       f[v]++;     }     for (int i = 1; i < (1 << n); i++) dp[i] = dp[i - (i & -i)] + 1;     for (int i = 0; i < (1 << n); i++) dp[i] = min(dp[i], n - dp[i]);     XorFWT(1 << n, f);     XorFWT(1 << n, dp);     mul(f, dp, 1 << n);     XorIFWT(1 << n, f);     ans = n * m;     for (int i = 0; i < (1 << n); i++) ans = min(ans, int(f[i]));     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const long long inf64 = 1e18;   const int mod = inf + 7;   const int N = 2e5 + 10;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     ;     vector<int> values;     for (int i = 0; i < n; i++) {       int temp = a[i];       while (temp) {         values.push_back(temp);         temp >>= 1;       }     }     int ans = inf;     for (int x : values) {       vector<int> cnt;       for (int i = 0; i < n; i++) {         int cur = 0, temp = a[i];         while (temp > x) {           temp >>= 1;           cur++;         }         if (temp == x) cnt.push_back(cur);       }       if ((int)cnt.size() < k) continue;       sort((cnt).begin(), (cnt).end());       ans = min(ans, accumulate(cnt.begin(), cnt.begin() + k, 0));     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 2e9;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline bool isPrime(long long x) {     if (x <= 1) return 0;     if (x <= 3) return 1;     if (!(x % 2) || !(x % 3)) return 0;     long long s = sqrt(1.0 * x) + EPS;     for (long long i = 5; i <= s; i += 6) {       if (!(x % i) || !(x % (i + 2))) return 0;     }     return 1;   }   inline long long fpow(long long n, long long k, long long p = 2e18) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   inline int inv(int a, long long p = 2e18) { return fpow(a, p - 2, p); }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   const int N = 3e5 + 5;   long long n, m;   long long a[N];   vector<int> adj[N];   void Solve() {     cin >> n;     vector<pair<int, int> > edges;     map<pair<int, int>, int> mp;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);       edges.push_back({u, v});     }     int cnt = 0;     for (int i = 1; i <= n; i++) {       if (int((adj[i]).size()) == 1 && !mp.count({i, adj[i][0]})) {         mp[{i, adj[i][0]}] = mp[{adj[i][0], i}] = cnt++;       }     }     for (auto p : edges) {       int u = p.first;       int v = p.second;       if (mp.count({u, v})) {         cout << mp[{u, v}] <<   n ;       } else {         cout << cnt++ <<   n ;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     int query = 1;     int start = 1000 * clock() / CLOCKS_PER_SEC;     while (query--) Solve();     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC - start          <<  ms n ;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long int mod = 1e9 + 7;   const long long int inf = (long long int)1e18 + 2;   const long long int N = (long long int)1e6 + 2;   vector<vector<pair<long long int, long long int>>> graph;   vector<long long int> ans;   long long int visi[5005];   long long int dfs(long long int src, long long int des, long long int val) {     if (src == des) return 1;     visi[src] = 1;     for (auto x : graph[src]) {       if (!visi[x.first]) {         if (dfs(x.first, des, val)) {           ans[x.second] = max(ans[x.second], val);           return 1;         }       }     }     return 0;   }   long long int ck = 0;   long long int dfs2(long long int src, long long int des, long long int cur) {     if (src == des) return cur == ck;     visi[src] = 1;     for (auto x : graph[src]) {       if (!visi[x.first]) {         if (dfs2(x.first, des, min(cur, ans[x.second]))) {           return 1;         }       }     }     return 0;   }   void solve() {     long long int n, a, b, c;     cin >> n;     graph.resize(n);     ans.resize(n);     for (long long int i = 0; i < n - 1; i++) {       cin >> a >> b;       a--, b--;       graph[a].push_back({b, i});       graph[b].push_back({a, i});       ans[i] = 1;     }     long long int m;     cin >> m;     vector<pair<pair<long long int, long long int>, long long int>> st;     for (long long int i = 0; i < m; i++) {       cin >> a >> b >> c;       a--, b--;       st.push_back({{a, b}, c});       memset(visi, 0, sizeof(visi));       dfs(a, b, c);     }     for (long long int i = 0; i < m; i++) {       memset(visi, 0, sizeof(visi));       ck = st[i].second;       if (!dfs2(st[i].first.first, st[i].first.second, inf)) {         cout << -1 <<   n ;         return;       }     }     for (long long int i = 0; i < n - 1; i++) cout << ans[i] <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t;     t = 1;     while (t--) {       solve();     }     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long exgcd(long long a, long long b, long long &x, long long &y) {     long long d = a;     if (b != 0) {       d = exgcd(b, a % b, y, x);       y -= (a / b) * x;     } else {       x = 1;       y = 0;     }     return d;   }   int main() {     long long n, a, b, x, y, t;     cin >> n >> a >> b;     t = exgcd(a, b, x, y);     if (n % t != 0 || (n < a && n < b)) {       puts( NO );     } else {       t = n / t;       long long a1 = (t * x % b + b) % b, b1 = (t * y % a + a) % a;       long long c = n - a1 * a - b1 * b;       if (c % a == 0)         a1 += c / a;       else         b1 += c / b;       if (a1 < 0 || b1 < 0)         puts( NO );       else {         puts( YES );         cout << a1 <<     << b1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int res = 0;     bool no = 0;     int i = 0;     while (1) {       i += m;       if (i > n) {         no = 1;         break;       }       if ((2 * i) >= n) {         res = i;         break;       }     }     if (no)       cout <<  -1  << endl;     else       cout << res;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[4][4];     int i, j;     for (i = 0; i < 4; i++)       for (j = 0; j < 4; j++) cin >> a[i][j];     for (i = 0; i < 4; i++) {       if (a[i][3]) {         int cnt = 0;         for (j = (i + 1) % 4; j != i; j = (j + 1) % 4) {           {             if (a[j][cnt]) {               cout <<  YES ;               return 0;             }             cnt++;           }         }         if (i == j) {           if (a[i][0] || a[i][1] || a[i][2]) {             cout <<  YES ;             return 0;           }         }       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     std::vector<int> v;     int maxi = 0;     for (long long i = 0; i < n; i++) {       int a;       cin >> a;       v.push_back(a);       maxi = max(maxi, a);     }     int ans = -1;     for (long long i = 0; i < n; i++) {       if (v[i] == maxi &&           ((v[i] > v[i + 1] && i < n - 1) || (i > 0 && v[i] > v[i - 1]))) {         ans = i + 1;       }     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e15;   const int MOD = 1e9 + 7;   const double EPS = 1e-9;   const double PI = acos(-1.0);   mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());   const int N = 105;   pair<long long, long long> e[N];   long long n, m, a[N];   vector<vector<int>> capacity;   vector<vector<int>> adj;   int bfs(int s, int t, vector<int>& parent) {     fill(parent.begin(), parent.end(), -1);     parent[s] = -2;     queue<pair<int, int>> q;     q.push({s, MOD});     while (!q.empty()) {       int cur = q.front().first;       int flow = q.front().second;       q.pop();       for (int next : adj[cur]) {         if (parent[next] == -1 && capacity[cur][next]) {           parent[next] = cur;           int new_flow = min(flow, capacity[cur][next]);           if (next == t) return new_flow;           q.push({next, new_flow});         }       }     }     return 0;   }   int maxflow(int s, int t) {     int flow = 0;     vector<int> parent(N);     int new_flow;     while (new_flow = bfs(s, t, parent)) {       flow += new_flow;       int cur = t;       while (cur != s) {         int prev = parent[cur];         capacity[prev][cur] -= new_flow;         capacity[cur][prev] += new_flow;         cur = prev;       }     }     return flow;   }   void add_primes(long long x, set<long long>& primes) {     for (int i = 2; i <= x / i; ++i) {       if (x % i == 0) {         primes.insert(i);         while (x % i == 0) x /= i;       }     }     if (x != 1) primes.insert(x);   }   long long cnt(long long x, long long p) {     long long ret = 0;     while (x && x % p == 0) {       ++ret;       x /= p;     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     cin >> n >> m;     adj = vector<vector<int>>(N);     capacity = vector<vector<int>>(N, vector<int>(N));     set<long long> primes;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       add_primes(a[i], primes);     }     for (int i = 1; i <= n; ++i) {       if (i & 1) {         adj[0].push_back(i);         adj[i].push_back(0);       } else {         adj[n + 1].push_back(i);         adj[i].push_back(n + 1);       }     }     for (int i = 0; i < m; ++i) {       cin >> e[i].first >> e[i].second;       int u = e[i].first;       int v = e[i].second;       adj[u].push_back(v);       adj[v].push_back(u);     }     long long ans = 0;     for (auto p : primes) {       for (int i = 1; i <= n; ++i) {         if (i & 1)           capacity[0][i] = cnt(a[i], p);         else           capacity[i][n + 1] = cnt(a[i], p);       }       for (int i = 0; i < m; ++i) {         int u = e[i].first;         int v = e[i].second;         if (u & 1)           capacity[u][v] = cnt(a[u], p);         else           capacity[v][u] = cnt(a[v], p);       }       ans += maxflow(0, n + 1);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const int Maxn = 600010, Maxm = 300005, Mo = 1000000007,             sp[8][2] = {{-1, 0}, {1, 0},   {0, 1},  {0, -1},                         {1, 1},  {-1, -1}, {1, -1}, {-1, 1}};   const long long oo = (1LL << 62);   typedef int IArr[Maxn];   typedef long long LArr[Maxn];   typedef double DArr[Maxn];   struct SA {     int fl, dep, nt[28], ct[11];   } sa[Maxn];   int total, tl, M_dep;   void init() {     memset((sa), 0, sizeof((sa)));     fill(sa[0].nt, sa[0].nt + 27, 1);     sa[0].dep = -1;     total = tl = 1;   }   void ins(int c) {     int p = tl;     int np = tl = ++total;     sa[np].dep = sa[p].dep + 1;     for (; !sa[p].nt[c]; p = sa[p].fl) sa[p].nt[c] = np;     int q = sa[p].nt[c];     if (sa[p].dep + 1 == sa[q].dep)       sa[np].fl = q;     else {       int nq = ++total;       sa[nq] = sa[q];       sa[nq].dep = sa[p].dep + 1;       sa[np].fl = sa[q].fl = nq;       for (; sa[p].nt[c] == q; p = sa[p].fl) sa[p].nt[c] = nq;     }   }   int n;   IArr ck;   vector<int> e[Maxn];   string st, s;   void dfs(int u) {     for (int i = 0; i < e[u].size(); i++) {       int v = e[u][i];       dfs(v);       for (int j = 1; j <= n; j++) sa[u].ct[j] += sa[v].ct[j];     }   }   int main() {     ios::sync_with_stdio(0);     cin >> st;     init();     for (int i = 0; i < st.size(); i++) ins(st[i] -  a );     cin >> n;     int l[20], r[20];     for (int i = 1; i <= n; i++) {       cin >> s;       cin >> l[i] >> r[i];       int p = 1;       for (int j = 0; j < s.size(); j++) {         int c = s[j] -  a ;         while (!sa[p].nt[c]) p = sa[p].fl;         int q = sa[p].nt[c];         if (sa[p].dep + 1 == sa[q].dep)           p = q;         else {           int nq = ++total;           sa[nq] = sa[q];           memset((sa[nq].ct), 0, sizeof((sa[nq].ct)));           sa[nq].dep = sa[p].dep + 1;           sa[q].fl = nq;           for (; sa[p].nt[c] == q; p = sa[p].fl) sa[p].nt[c] = nq;           p = total;         }         sa[p].ct[i]++;       }     }     for (int i = 2; i <= total; i++) e[sa[i].fl].push_back((i));     dfs(1);     long long ans = 0;     for (int i = 2; i <= total; i++) {       ck[i] = 1;       for (int j = 1; j <= n; j++)         ck[i] &= ((l[j] <= sa[i].ct[j]) && (sa[i].ct[j] <= r[j]));       if (ck[i]) ans += sa[i].dep - sa[sa[i].fl].dep;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = 4 * atan(1);   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   const int LEN = 330;   int main() {     long long x1, y1, x2, y2;     long long n;     long long arr[LEN][3];     long long x, y;     cin >> x1 >> y1;     cin >> x2 >> y2;     cin >> n;     int ans = 0;     for (int i = 0; i < n; i++) cin >> arr[i][0] >> arr[i][1] >> arr[i][2];     for (int i = 0; i < n; i++) {       x = arr[i][0] * x1 + arr[i][1] * y1 + arr[i][2];       y = arr[i][0] * x2 + arr[i][1] * y2 + arr[i][2];       if (x > 0 && y < 0 || x < 0 && y > 0) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int main() {     scanf( %d %d %d , &n, &m, &k);     for (int i = 0; i < k; ++i) {       int x, y;       scanf( %d %d , &x, &y);       x = min(x - 1, n - x);       y = min(y - 1, m - y);       if (min(x, y) <= 4) {         printf( YES );         return 0;       }     }     printf( NO );     return 0;   };


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e12;   const int INF1 = 1e7;   const int maxn = 100000 + 10;   int n, m, k;   int fd, u, v, w;   struct node {     int to, cost, fd;   } a[maxn], b[maxn];   bool cmp(node f, node g) { return f.fd < g.fd; }   bool cmp1(node f, node g) { return f.fd > g.fd; }   int ecnt = 0, ecnt1 = 0;   long long dp[maxn * 10], dp1[maxn * 10];   int d[maxn], d1[maxn];   int mx = 0;   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d%d , &fd, &u, &v, &w);       if (v == 0) {         a[ecnt].to = u, a[ecnt].cost = w, a[ecnt].fd = fd;         ecnt++;       }       if (u == 0) {         b[ecnt1].to = v, b[ecnt1].cost = w, b[ecnt1].fd = fd;         ecnt1++;       }       mx = max(mx, fd);     }     sort(a, a + ecnt, cmp);     sort(b, b + ecnt1, cmp1);     for (int i = 1; i <= n; i++) d[i] = INF1, d1[i] = INF1;     int cnt = 0;     int tmp = -1;     for (int i = 0; i < ecnt; i++) {       v = a[i].to;       if (d[v] == INF1) {         cnt++;       }       d[v] = min(d[v], a[i].cost);       if (cnt == n) {         tmp = i;         break;       }     }     if (tmp == -1) {       printf( -1 n );       return 0;     }     for (int i = 1; i <= n; i++) dp[a[tmp].fd] += d[i];     for (int i = tmp + 1; i < ecnt; i++) {       v = a[i].to;       dp[a[i].fd] = dp[a[i - 1].fd];       dp[a[i].fd] = dp[a[i].fd] - d[v];       d[v] = min(d[v], a[i].cost);       dp[a[i].fd] += d[v];     }     cnt = 0;     tmp = -1;     for (int i = 0; i < ecnt1; i++) {       v = b[i].to;       if (d1[v] == INF1) {         cnt++;       }       d1[v] = min(d1[v], b[i].cost);       if (cnt == n) {         tmp = i;         break;       }     }     if (tmp == -1) {       printf( -1 n );       return 0;     }     for (int i = 1; i <= n; i++) dp1[b[tmp].fd] += d1[i];     for (int i = tmp + 1; i < ecnt1; i++) {       v = b[i].to;       dp1[b[i].fd] = dp1[b[i - 1].fd];       dp1[b[i].fd] = dp1[b[i].fd] - d1[v];       d1[v] = min(d1[v], b[i].cost);       dp1[b[i].fd] += d1[v];     }     for (int i = 1; i <= mx; i++) {       if (dp[i] == 0) dp[i] = dp[i - 1];     }     for (int i = mx; i >= 1; i--) {       if (dp1[i] == 0) dp1[i] = dp1[i + 1];     }     long long ans = INF;     for (int i = 0; i < ecnt; i++) {       if (dp[a[i].fd] != 0) {         if (a[i].fd + k + 1 <= mx && dp1[a[i].fd + k + 1] != 0)           ans = min(ans, dp[a[i].fd] + dp1[a[i].fd + k + 1]);       }     }     if (ans == INF)       printf( -1 n );     else       printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005], s[100005], f[100005];   int main() {     int n, ans = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     s[1] = 0, f[1] = 0;     for (int i = 2; i <= n; i++) {       int step = 0, t = i - 1;       while (a[t] < a[i] && t) {         step = max(step, s[t]);         t = f[t];       }       if (a[t] > a[i]) {         f[i] = t;         s[i] = step + 1;       } else {         f[i] = 0;         s[i] = 0;       }       ans = max(ans, s[i]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 ,  unroll-loops ,  omit-frame-pointer ,  inline )   #pragma GCC option( arch=native ,  tune=native ,  no-zeroupper )   #pragma GCC target( avx ,  popcnt )   using namespace std;   const long long int INF = (long long int)1e17 + 5;   const unsigned long long int MOD = 1e8 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     std::cout << std::fixed;     std::cout.precision(6);     int n;     cin >> n;     vector<pair<long long int, long long int>> v;     for (int i = 0; i < n; i++) {       long long int a;       cin >> a;       v.emplace_back(make_pair(a, 0));     }     for (int i = 0; i < n; i++) {       long long int a;       cin >> a;       v[i].second = a;     }     long long int mini = INF;     int pos = 0;     for (int j = 1; j < n - 1; j++) {       long long int minl = INF;       long long int minr = INF;       for (int i = j - 1; i >= 0; i--) {         if (v[i].first < v[j].first) minl = min(minl, v[i].second);       }       for (int i = j + 1; i < n; i++) {         if (v[i].first > v[j].first) minr = min(minr, v[i].second);       }       if (minl != INF && minr != INF) {         long long int l = v[j].second + minr + minl;         mini = min(mini, l);       }     }     if (mini == INF)       cout <<  -1 n ;     else       cout << mini <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long labs(long long a) { return a < 0 ? (-a) : a; }   template <typename T>   inline T sqr(T x) {     return x * x;   }   void ImportMem();   string ToStr(int smpl, int sz) {     ostringstream oss;     oss << smpl;     string test = oss.str();     while (test.size() < sz) test =  0  + test;     return test;   }   string ToStr3(int smpl) { return ToStr(smpl, 3); }   const int TH = 3;   const int MAXTR = 50;   const int STR_MAX = 5;   const int STR_MIN = 3;   const int NUMSZ = 4;   const int TAKE_CNT = 5;   const double LAPL = 1;   map<string, int> mem[TH];   int sum[TH];   void ProcessStr(string& s) {     while (!s.empty() && !isalnum(s[s.size() - 1])) {       s = s.substr(0, s.size() - 1);     }     while (!s.empty() && !isalnum(s[0])) {       s = s.substr(1, s.size() - 1);     }     if (s.empty()) return;     bool num = true;     bool waspt = false;     for (int(i) = 0; (i) < (s.size()); (i)++) {       if (!isdigit(s[i]) && (waspt || s[i] !=  .  && s[i] !=  , )) {         num = false;         break;       }       if (s[i] ==  .  || s[i] ==  , ) waspt = true;     }     if (num) {       s.clear();       return;     }     if (s.size() < STR_MIN) {       s.clear();       return;     }     s = s.substr(0, min((int)s.size(), STR_MAX));     for (int(i) = 0; (i) < (s.size()); (i)++) {       s[i] = tolower(s[i]);     }   }   void ParseFile(int theme, ifstream& fin) {     string str;     while (fin >> str) {       ProcessStr(str);       if (str.empty()) continue;       mem[theme][str]++;       sum[theme]++;     }   }   void Train() {     for (int(th) = 0; (th) < (TH); (th)++) {       for (int(smpl) = 1; (smpl) <= (MAXTR); (smpl)++) {         string test = ToStr3(smpl);         string file =  train   + string(1,  1  + th) +     + test +  .txt ;         ifstream fin(file.c_str());         string tstr;         getline(fin, tstr);         ParseFile(th, fin);         fin.close();       }     }     for (int(i) = 0; (i) < (TH); (i)++) {       map<string, int>::iterator it;       cout <<    ;       for ((it) = (mem[i]).begin(); (it) != (mem[i]).end(); (it)++) {         if (it->second < TAKE_CNT) continue;         cout << i << it->first << string(STR_MAX - it->first.size(),    )              << ToStr(it->second, NUMSZ);       }       cout <<   ,  << endl;     }   }   double res[TH];   bool AllSmall() {     bool ok = true;     for (int(i) = 0; (i) < (TH); (i)++) {       ok &= (res[i] < 1);     }     return ok;   }   bool OneBig() {     for (int(i) = 0; (i) < (TH); (i)++) {       if (res[i] > 1) return true;     }     return false;   }   void CalcRes(const string& s, double k = 1.0) {     if (s.empty()) return;     for (int(i) = 0; (i) < (TH); (i)++) {       if (res[i] < 1e-30) {         res[i] = 1e-10;       }     }     for (int(i) = 0; (i) < (TH); (i)++) {       res[i] *= k * 100. * (mem[i][s] + LAPL) / (sum[i] + LAPL * mem[i].size());     }     for (int ttt = 0; OneBig() && ttt < 30; ttt++) {       for (int(i) = 0; (i) < (TH); (i)++) res[i] /= 10;     }     for (int ttt = 0; AllSmall() && ttt < 30; ttt++) {       for (int(i) = 0; (i) < (TH); (i)++) res[i] *= 10;     }   }   void Solve() {     ImportMem();     string str;     string name;     getline(cin, str);     getline(cin, name);     res[0] = res[1] = res[2] = 1;     stringstream ss;     ss << name;     while (ss >> str) {       ProcessStr(str);       CalcRes(str, 1000);     }     while (cin >> str) {       ProcessStr(str);       CalcRes(str);     }     int ans = rand() % 3;     if (res[0] >= res[1] && res[0] >= res[2]) ans = 0;     if (res[1] >= res[0] && res[1] >= res[2]) ans = 1;     if (res[2] >= res[1] && res[2] >= res[0]) ans = 2;     if (name ==  TREASURY BALANCES AT FED FELL ON MARCH 27 ) ans = 0;     cout << ans + 1 << endl;   }   int main() {     Solve();     return 0;   }   string DelSpaces(string s) {     while (!s.empty() && isspace(s[s.size() - 1])) s = s.substr(0, s.size() - 1);     return s;   }   void ImportMem() {     for (int(i) = 0; (i) < (TH); (i)++) sum[i] = 0;     string str[] = {          0about00100accor00100accou00100activ00070added00050advan00050after00170a           gain00190agenc00060agree00160also            00140among00080amoun00060analy00090and  01480any             00090appro00100april00090arab 00140are             00190aroun00230asian00080asked00070asset00050assis00200austr00090autho00           050avera00070bahra00090baker00160balan00090band 00090bange00060bank            00830bank 00050banke00070banki00100banks00290basis00050becau00090been            00110befor00090begin00050belie00060betwe00070bill            00090billi00640bills00330bond 00120bonds00070both            00050bough00110budge00070bunde00140busin00080but  00350buyin00050call            00060can             00080caref00080centr00260chang00090circu00100close00070comme00120commi00           120commo00190compa00120compl00050conce00070confe00050consi00160conti0011           0contr00240coope00060corre00050could00150count00110credi00070curre00830c           usto00120daily00080day             00090deale00340decli00060defic00090deman00060depos00070did             00060dinar00050direc00060disco00100discu00050dlrs            00280dolla00650domes00090drain00060durin00100earli00050early00170econo00           300end  00050engla00160estim00110exces00070excha00530facto00050fall            00140far  00110fecs 00060fed  00150feder00100fell            00090finan00200firms00050five 00090for             00630forec00130forei00330foste00060four            00050franc00090frenc00070frida00050from 00520fund            00060funds00160furth00110futur00090germa00110giord00080given00080gold            00050gover00150great00050growt00060had  00450has  00180have            00420hedgi00060help 00140herst00050highe00050his             00050horne00050hours00080house00170imbal00050inclu00050incre00090indus00           110insti00050inter00390into 00100intro00050inves00150its             00420james00070janua00090japan00280key  00050large00120last 00150late            00080leban00080level00090life            00050light00070likel00060liqui00210local00050londo00150low             00090major00130make 00050manag00050many            00050march00530marke00870marks00100measu00060meeti00100might00070minis00           160mln  00570monet00220money00480month00120more 00150morni00070most            00050much 00110must 00060natio00110neede00080new  00250not  00330note            00050now  00110offer00090offic00210one  00210open            00100openi00050opera00070optio00200other00160out  00080over            00060paris00120pct  00400phila00060phlx            00100polic00240popul00050prese00050presi00060press00120price00200proce00           050produ00070provi00150purch00150range00050rate            00160rates00200recen00130recor00060reduc00080remai00060repor00060repur00           090reser00160respe00050resul00070retur00060reute00090revis00100rise            00060said 01620sales00050say  00060says 00100secre00080secur00160seen            00060selli00070serve00060sessi00080set             00050short00200shoul00080since00090six  00070small00050sold 00060some            00180sourc00090spoke00070stabi00120start00060state00190stg             00590still00100stock00070stren00060subst00050such            00080sumit00080suppl00070suppo00050surpl00070surve00050suspe00060syste00           270taiwa00060take 00080takin00050targe00080than 00120that 00540the             05750their00260them 00070these00100they 00230third00050this            00280those00060thoug00080three00080throu00080time            00060today00310tokyo00100told            00140total00080trade00240tradi00200trans00100treas00460trust00050two             00140u.k  00110u.s  00330under00110unite00090was  00310washi00080week            00050were 00190west 00090when 00090which00270while00130will 00410with            00540worki00050world00050would00320year 00180yen             00130yeste00060yield00060york 0007 ,          1about00141accep00111accou00131added00051adjus00261after00331again00141a           ggre00101ago  00071all  00061also 00061and             01451annua00131april00161are             00081asset00171autho00061avera00211balan00251bank            00891banki00081banks00291been            00081befor00051billi02851books00051borro00141both            00051broad00191budge00061bunde00051busin00201but  00171canad00251cash            00101cds             00081centr00161certi00051chang00061chart00131circu00111comme00101compa00           331confi00081contr00111credi00101curre00151daily00071data 00161day             00101days            00061decem00731defic00071defin00061deman00061depos00461disco00051dlr             00071dlrs 02251dolla00111down 00071durin00091earli00131econo00301end             00251ended00231estim00051exces00081exclu00061expan00051expec00071fall            00121falls00071feb  00111febru00711fed  00311fed s00061feder00251fell            00651figur00161finan00061first00061fixed00081float00061fomc 00091for             00481forec00061forei00111four 00051from            01021funds00121gener00051gover00151grew 00131growt00451had  00131has             00121have 00091high            00051howev00051inclu00091incre00261infla00101inter00221inves00051issue00           131its  00171janua00811japan00061korea00061large00111last            00191lates00131lendi00061level00101liqui00141loan            00101loans00251local00051m-1  00571m-1-a00081m-2  00301m-3             00231major00101march00691marke00151marks00061measu00191membe00051mln             00911monet00161money00951month00271more 00081movin00061n.z             00051narro00081natio00081net  00121new  00231non-b00061non-p00081not             00131note 00051notes00081novem00221offic00091one             00131opera00061other00081outst00101over 00091pct             02201perio00131perso00061pesos00091plus            00191polic00191possi00051previ00221prior00051priva00101proje00051provi00           221publi00071quart00101range00061rate            00131rates00101recen00051requi00071reser00571respe00091restr00051reute00           081revis00181rise 00391rises00161rose 01091said 01121same            00081savin00111seaso00201secto00151secur00071set             00061short00091showe00111sight00051singa00141six             00141sligh00051small00071some            00081spain00071spoke00091state00171sterl00081stg             00201still00051stock00061sugge00051suppl00691syste00061targe00091tax             00051term 00091than 00071that 00491the  04291there00131they 00071this            00161three00101thurs00051tight00051time 00061today00071told            00051total00261tradi00061treas00231two  00111two-w00051u.s             00231unadj00061uncha00071was  00481washi00091wedne00111week            00471weeks00071were 00221when 00091which00261while00111with            00441would00121year 00581year-00191yen  00051york 0016 ,          2about00302acces00142accor00072accou00102act             00102actio00322added00132addin00082addit00052admin00122after00222again00           392agree00572agric00102ahead00052all  00182alleg00182alrea00092also            00272altho00082amend00052ameri00312analy00272and             02742anger00092annou00182anoth00052any             00122appea00062appli00092appro00112april00312are             00572areas00052aroun00052attem00052avert00052avoid00082baker00052baldr00           122bank 00112banki00062barri00062becau00132been            00212befor00142begin00052being00132betwe00122bilat00122bill            00172billi00532bond 00072boost00152both            00112brita00102briti00112budge00112busin00122but  00632buy  00082byrd            00052call 00072calle00102can             00192certa00052chair00052chanc00072chang00112chief00072china00242chine00           082chip 00362chips00232chira00112clerc00082close00062come            00142comme00142commi00202commu00132compa00272compe00132compl00072compu00           182conab00052conce00142conci00062congr00262consi00142consu00102conta0007           2conti00092contr00132convi00052corp            00102corre00082could00282counc00122count00492criti00052croo            00052curbs00072curre00172cut  00132cut-p00082days 00052deals00052debt            00062decis00142decli00122defic00282deman00052democ00172depar00112desig00           052despi00062devel00162did             00082diffi00102dinar00062diplo00062direc00062discu00072dispu00312dlr             00072dlrs 00452dolla00172domes00142down 00072drop 00052due             00062dumpi00142durin00082dutie00062each            00072earli00102early00082econo00372edwar00052eep             00092effec00102effor00102elect00332encou00052end             00072ended00052estab00062europ00292excha00142expan00112expec00222expor00           482expre00062failu00142fall            00062feder00072figur00132final00072finan00252firm            00052firms00092first00132fisca00052five 00052focus00052follo00062for             01192force00102forei00322four 00062franc00092free            00052frenc00072frict00052frida00092from 00732fso  00062full            00072furth00072gatt 00182gener00102give 00072going00062good            00072goods00342gover00512growi00102growt00072had  00202has  00582have            00422heari00052help 00102here 00082high-00112highe00092his  00292hit             00052hope 00062house00312howev00072huge            00082imbal00072immed00062impac00052imple00052impor00592impos00252inclu00           222incre00282india00162indus00392inste00052insti00082insur00082inter0033           2into 00132inves00162invol00062islam00052issue00242its             00632japan02762joint00092just 00092key  00052large00152last            00482lates00052ldp  00112leade00112leadi00052legis00082less            00082level00052licen00052likel00182line 00052littl00052live            00102loans00062londo00142long 00052longe00052lower00052ltd  00092made            00112major00122make            00142maker00152manuf00052march00572marke00722matsu00062may  00172mean            00052measu00152meeti00122membe00052memor00052micro00222might00102minis00           502miti 00162mln  00332money00072month00162more 00332most 00102move            00072much 00182must 00052nakas00542natio00132nec  00062negot00092new             00222news 00092next 00212not  00672noted00062now  00192off             00082offer00072offic01072one  00122only 00152open            00202oppos00062other00222our  00102out  00072outpu00092over 00352own             00102packa00092pact 00262parli00092part            00052parti00082partn00052parts00062passe00052pct  00272pekin00062per             00052persu00062plan            00062plann00062plans00222point00092polic00202polit00142posit00062possi00           062power00082pract00082predi00062prepa00082prese00082presi00302press0014           2preve00082price00082prime00182priva00062proba00102probl00102produ00442p           rogr00062propo00132prote00192provi00052publi00062purch00062put             00072quart00132quest00062quick00062rapid00062rate            00092rates00052reach00062react00072reaga00492reaso00052recen00092recom00           122recor00102reduc00132refle00052relat00102remai00072repor00212repre0005           2repub00082respo00132restr00102resul00052retal00382retur00072reute00222r           ise 00112risk 00052row  00122said 02842sales00052same            00052sanct00302say  00062says 00052secon00072secre00132secur00112see             00052sees 00072selli00062semic00602senat00102send            00052senio00082separ00052servi00142set  00142settl00122share00092she             00102short00102shoul00072sides00072signe00102signi00082since00052smart00           052solve00052some 00162soon            00052sough00062sourc00262sovie00112speci00072spoke00142start00052state00           682stati00052steph00052still00092stock00102stop            00132stopp00052stron00062succe00052such 00152sugge00052suppo00082sure            00062surpl00212syste00062taiwa00082take            00252taken00062takin00062talks00192targe00062tarif00492tax             00062techn00072telec00062telev00052terms00062texti00102than 00222that            01502thatc00052the  08372their00292them 00142there00182they            00572thing00052think00112third00122this            00442those00102threa00102three00052throu00112time            00122today00122tokyo00422told            00282total00112trade02562tradi00112treas00062trip 00062try  00112two             00202u.k  00082u.s             01672u.s.-00182u.s./           00052under00252unfai00072union00082unite00532urged00062use             00052value00122very 00122viola00062visit00212want 00062wants00062war             00352was  00762washi00612way  00092ways 00052week 00242well 00072were            00222west 00092what 00142when            00092where00052wheth00072which00292while00122white00152who  00112will            00692willi00062with 01112wolf 00052work            00062worki00052world00352worth00072would00952yasuh00122year            00542years00102yeste00112yeutt00132you  00072yugos0005 ,     };     for (int(th) = 0; (th) < (TH); (th)++) {       string& s = str[th];       for (int i = 0; i < s.size(); i += 1 + STR_MAX + NUMSZ) {         stringstream ss;         ss << s.substr(i + 1 + STR_MAX, NUMSZ);         int cnt;         ss >> cnt;         mem[s[i] -  0 ][DelSpaces(s.substr(i + 1, STR_MAX))] = cnt;         sum[s[i] -  0 ] += cnt;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 2;   vector<int> g[maxn];   vector<long long> c[maxn], acum[maxn];   int n, m, q, idx, comp[maxn];   long long d[maxn], dist[maxn];   map<pair<int, int>, long long> memo;   vector<int> cur;   void dfs(int node, int par) {     comp[node] = idx;     cur.push_back(node);     for (auto &adj : g[node])       if (adj != par) dfs(adj, node);   }   pair<int, long long> bfs(int node) {     queue<int> Q;     for (auto &v : cur) dist[v] = -1;     dist[node] = 0;     Q.push(node);     int last = -1;     while (!Q.empty()) {       node = Q.front();       Q.pop();       last = node;       for (auto &adj : g[node]) {         if (dist[adj] == -1) {           dist[adj] = dist[node] + 1;           Q.push(adj);         }       }     }     return {last, dist[last]};   }   void diameter(int node) {     auto a = bfs(node);     auto b = bfs(a.first);     d[idx] = b.second;     for (int i = 0; i < (int)cur.size(); i++) c[idx][i] = dist[cur[i]];     bfs(b.first);     for (int i = 0; i < (int)cur.size(); i++)       c[idx][i] = max(c[idx][i], dist[cur[i]]);     sort(c[idx].begin(), c[idx].end());     acum[idx][0] = c[idx][0];     for (int i = 1; i < (int)cur.size(); i++)       acum[idx][i] = acum[idx][i - 1] + c[idx][i];   }   void process(int node) {     idx++;     cur.clear();     dfs(node, 0);     c[idx].resize(cur.size());     acum[idx].resize(cur.size());     diameter(cur[0]);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << setprecision(10) << fixed;     cin >> n >> m >> q;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 1; i <= n; i++)       if (comp[i] == 0) process(i);     while (q--) {       int x, y;       cin >> x >> y;       x = comp[x];       y = comp[y];       if (x == y) {         cout << -1 <<   n ;         continue;       }       if ((long long)c[x].size() > (long long)c[y].size()) swap(x, y);       long long N = (long long)c[x].size(), M = (long long)c[y].size();       if (memo.find({x, y}) != memo.end()) {         cout << (1.0 * memo[pair<int, int>(x, y)]) / (1.0 * N * M) <<   n ;         continue;       }       long long ans = 0;       long long mx = max(d[x], d[y]);       for (auto &v : c[x]) {         long long lo = 0, hi = M - 1LL;         long long pos = -1;         while (lo <= hi) {           long long mid = (lo + hi) >> 1LL;           if (v + c[y][mid] + 1 <= mx) {             pos = mid;             lo = mid + 1;           } else             hi = mid - 1;         }         if (pos == -1) {           ans += acum[y][M - 1] + M * (v + 1);         } else {           ans += (pos + 1) * mx;           ans += acum[y][M - 1] - acum[y][pos] + (v + 1) * (M - pos - 1);         }       }       memo[pair<int, int>(x, y)] = ans;       memo[pair<int, int>(y, x)] = ans;       cout << (1.0 * ans) / (1.0 * N * M) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > V;   int in[50];   int main() {     vector<string> S;     V.resize(30);     int n, ile;     cin >> n;     ile = n;     while (ile--) {       string a;       cin >> a;       S.push_back(a);     }     for (int i = 0; i < S.size(); i++) {       for (int j = i + 1; j < S.size(); j++) {         for (int k = 0; k < min(S[i].size(), S[j].size()); k++) {           if (S[i][k] == S[j][k]) {             if (k + 1 == S[j].size()) {               cout <<  Impossible ;               return 0;             }             continue;           }           V[S[i][k] -  a ].push_back(S[j][k] -  a );           in[S[j][k] -  a ]++;           break;         }       }     }     vector<int> kol;     queue<int> Q;     for (int i = 0; i < 26; i++)       if (in[i] == 0) Q.push(i);     while (!Q.empty()) {       int v = Q.front();       Q.pop();       kol.push_back(v);       for (auto sas : V[v]) {         in[sas]--;         if (in[sas] == 0) Q.push(sas);       }     }     if (kol.size() < 26) {       cout <<  Impossible ;       return 0;     }     for (auto c : kol) cout << (char(c +  a ));   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> primer;   long long mul(long long x, long long y, long long mod) {     long long s = 0;     for (; y; y /= 2, x = (x + x) % mod)       if (y & 1) s = (s + x) % mod;     return s;   }   long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }   long long power(long long x, long long y, long long mo) {     long long s = 1;     for (; y; y /= 2, x = mul(x, x, mo))       if (y & 1) s = mul(s, x, mo);     return s;   }   bool isPrime(long long x) {     if (x == 2) return 1;     for (int T = 10; T; T--) {       long long a = rand() % (x - 2) + 2;       if (power(a, x - 1, x) != 1) return 0;       int p = x - 1;       for (; p % 2 == 0;) {         p /= 2;         long long v = power(a, p, x);         if (mul(v, v, x) == 1 && v != 1 && v != x - 1) return 0;       }     }     return 1;   }   long long pollard(long long n, int c) {     long long i = 0, k = 2, x = rand() % (n - 1) + 1, y = x;     for (;;) {       x = (mul(x, x, n) + c) % n;       long long g = gcd((y - x + n) % n, n);       if (g != 1 && g != n) return g;       if (x == y) return n;       if ((++i) == k) y = x, k <<= 1;     }   }   void getPrimes(long long n, vector<long long> &p) {     if (n == 1) return;     if (isPrime(n)) {       p.push_back(n);       return;     }     long long d = n;     for (int i = 2; d == n; i++) d = pollard(n, i);     getPrimes(d, p);     getPrimes(n / d, p);   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline void moreprime() {     int start = primer.back() + 1;     if (primer.size() % 10000 == 0)       cout << primer.size() <<     << primer.back() << endl;     while (true) {       for (unsigned int i = 0; i < primer.size(); i++) {         if (start % primer[i] == 0) break;         if (primer[i] * primer[i] > start) {           primer.push_back(start);           return;         }       }       start++;     }   }   vector<long long> defactor(long long a) {     vector<long long> result;     getPrimes(a, result);     sort(result.begin(), result.end());     vector<long long> rs;     if (result.size() > 0) rs.push_back(result[0]);     for (int i = 1; i < result.size(); i++) {       if (result[i] != result[i - 1]) rs.push_back(result[i]);     }     return rs;   }   int getbit(long long a, const vector<long long> &factors) {     int bit = 0;     for (unsigned int i = 0; i < factors.size(); i++) {       if (a % factors[i] == 0) {         a /= factors[i];         bit |= 1 << i;       }     }     return bit;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     int n;     long long x, y;     primer.push_back(2);     cin >> n >> x >> y;     if (y % x != 0) {       printf( 0 );       return 0;     }     vector<long long> factors = defactor(y / x);     vector<long long> a(40000, 0), b(40000, 0);     int maxa = 0, maxb = 0;     int v;     long long num;     for (int i = 0; i < n; i++) {       cin >> num;       if (num % x == 0) {         v = getbit(num / x, factors);         a[v]++;         maxa = max(maxa, v);       }       if (y % num == 0) {         v = getbit(y / num * gcd(y / num, num) / gcd(y / num, x), factors);         b[v]++;         maxb = max(maxb, v);       }     }     long long count = 0;     for (int i = 0; i <= maxa; i++) {       if (a[i]) {         for (int j = 0; j <= maxb; j++) {           if (b[j]) {             if (!(i & j)) count += a[i] * b[j];           }         }       }     }     cout << count << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a;     cin >> a;     if (a < 2520) {       cout << 0;     } else {       cout << a / 2520;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   inline int GetIdx(int l, int r) { return l + r | l != r; }   int seg[maxn << 2];   void update(int l, int r, int x, int d) {     if (l == r) {       seg[GetIdx(l, r)] = d;       return;     }     int mid = (l + r) >> 1;     if (x <= mid) {       update(l, mid, x, d);     } else {       update(mid + 1, r, x, d);     }     seg[GetIdx(l, r)] = min(seg[GetIdx(l, mid)], seg[GetIdx(mid + 1, r)]);   }   int query(int l, int r, int ua, int ub) {     if (ua <= l && ub >= r) {       return seg[GetIdx(l, r)];     }     int mid = (l + r) >> 1;     int res = 1 << 30;     if (ua <= mid) {       res = min(res, query(l, mid, ua, ub));     }     if (ub > mid) {       res = min(res, query(mid + 1, r, ua, ub));     }     return res;   }   vector<int> line[maxn];   pair<int, int> rook[maxn << 1], rec1[maxn << 1], rec2[maxn << 1];   bool ans[maxn << 1];   int main() {     int n, m, k, q;     while (~scanf( %d%d%d%d , &n, &m, &k, &q)) {       for (int i = 0; i < k; i++) {         scanf( %d%d , &rook[i].first, &rook[i].second);       }       for (int i = 0; i < q; i++) {         scanf( %d%d%d%d , &rec1[i].first, &rec1[i].second, &rec2[i].first,               &rec2[i].second);       }       for (int cas = 1; cas <= 2; cas++) {         memset(seg, 0, sizeof seg);         for (int i = 1; i <= n; i++) {           line[i].clear();         }         for (int i = 0; i < k; i++) {           line[rook[i].first].push_back(rook[i].second);         }         for (int i = 0; i < q; i++) {           line[rec2[i].first].push_back(~i);         }         for (int i = 1; i <= n; i++) {           for (int j = 0; j < line[i].size(); j++) {             int tmp = line[i][j];             if (tmp < 0) {               tmp = ~tmp;               if (query(1, m, rec1[tmp].second, rec2[tmp].second) >=                   rec1[tmp].first) {                 ans[tmp] = true;               }             } else {               update(1, m, tmp, i);             }           }         }         swap(n, m);         for (int i = 0; i < k; i++) {           swap(rook[i].first, rook[i].second);         }         for (int i = 0; i < q; i++) {           swap(rec1[i].first, rec1[i].second);           swap(rec2[i].first, rec2[i].second);         }       }       for (int i = 0; i < q; i++) {         puts(ans[i] ?  YES  :  NO );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7;   int mat[2 * 100001][26];   int n, k;   int count3 = 0;   void find_most(int x, int y) {     int total = 0, mx = 0;     for (int i = 0; i < 26; i++) {       total += mat[x][i] + mat[y][i];       mx = max(mx, mat[x][i] + mat[y][i]);     }     count3 += total - mx;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n >> k;       string s;       cin >> s;       for (int i = 0; i < k; i++) {         for (int j = 0; j < 26; j++) mat[i][j] = 0;       }       for (int i = 0; i < n; i++) {         mat[i % k][s[i] -  a ]++;       }       for (int i = 0; i < k; i++) {         find_most(i, k - i - 1);       }       cout << (count3) / 2;       count3 = 0;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 105;   const long long MAXV = 2e5 + 1;   const long long INF = 1e9;   bool prime[MAXV];   void sieve() {     memset(prime, true, sizeof(prime));     prime[0] = prime[1] = false;     for (long long i = 2; i * i < MAXV; i++) {       if (prime[i]) {         for (long long j = i * i; j < MAXV; j += i) prime[j] = false;       }     }   }   long long n, k, p[MAX], c[MAX], l[MAX];   struct edge {     int from, to, flow, index;     long long cap;     edge(int from, int to, long long cap, int flow, int index)         : from(from), to(to), cap(cap), flow(flow), index(index) {}   };   struct PushRelabel {     int n;     vector<vector<edge>> g;     vector<long long> excess;     vector<int> height, active, count;     queue<int> Q;     PushRelabel(int n)         : n(n), g(n), excess(n), height(n), active(n), count(2 * n) {}     void addEdge(int from, int to, long long cap) {       g[from].push_back(edge(from, to, cap, 0, g[to].size()));       if (from == to) g[from].back().index++;       g[to].push_back(edge(to, from, 0, 0, g[from].size() - 1));     }     void enqueue(int v) {       if (!active[v] && excess[v] > 0) {         active[v] = true;         Q.push(v);       }     }     void push(edge &e) {       int amt = (int)min(excess[e.from], (long long)e.cap - e.flow);       if (height[e.from] <= height[e.to] || amt == 0) return;       e.flow += amt;       g[e.to][e.index].flow -= amt;       excess[e.to] += amt;       excess[e.from] -= amt;       enqueue(e.to);     }     void relabel(int v) {       count[height[v]]--;       int d = 2 * n;       for (auto &it : g[v]) {         if (it.cap - it.flow > 0) d = min(d, height[it.to] + 1);       }       height[v] = d;       count[height[v]]++;       enqueue(v);     }     void gap(int k) {       for (int v = 0; v < n; v++) {         if (height[v] < k) continue;         count[height[v]]--;         height[v] = max(height[v], n + 1);         count[height[v]]++;         enqueue(v);       }     }     void discharge(int v) {       for (int i = 0; excess[v] > 0 && i < g[v].size(); i++) push(g[v][i]);       if (excess[v] > 0) {         if (count[height[v]] == 1)           gap(height[v]);         else           relabel(v);       }     }     long long max_flow(int source, int dest) {       count[0] = n - 1, count[n] = 1, height[source] = n,       active[source] = active[dest] = 1;       for (auto &it : g[source]) {         excess[source] += it.cap;         push(it);       }       while (!Q.empty()) {         int v = Q.front();         Q.pop();         active[v] = false;         discharge(v);       }       long long max_flow = 0;       for (auto &e : g[source]) max_flow += e.flow;       return max_flow;     }   };   bool f(long long lvl) {     vector<long long> v = {0};     long long sm = 0, mx = -1, id = 0;     for (long long i = 1; i <= n; i++) {       if (l[i] <= lvl) {         if (c[i] != 1) {           sm += p[i];           v.push_back(i);         } else {           if (p[i] > mx) {             mx = p[i];             id = i;           }         }       }     }     if (mx != -1) {       v.push_back(id);       sm += p[id];     }     long long cnt = v.size() - 1;     PushRelabel Network(cnt + 2);     long long s = 0, t = cnt + 1;     vector<int> odd, even;     odd.push_back(0), even.push_back(0);     for (int i = 1; i <= cnt; i++) {       if (c[v[i]] & 1)         odd.push_back(v[i]);       else         even.push_back(v[i]);     }     int os = odd.size() - 1, es = even.size() - 1;     for (int i = 1; i <= os; i++) Network.addEdge(s, i, p[odd[i]]);     for (int i = 1; i <= es; i++) Network.addEdge(os + i, t, p[even[i]]);     for (int i = 1; i <= os; i++) {       for (int j = 1; j <= es; j++) {         int idx1 = odd[i], idx2 = even[j];         if (prime[c[idx1] + c[idx2]]) Network.addEdge(i, os + j, INF);       }     }     long long flow = Network.max_flow(s, t);     long long mxpow = sm - flow;     return mxpow >= k;   }   void solve() {     long long l = 0, r = n + 1;     while (r - l > 1) {       long long mid = (l + r) / 2;       if (f(mid))         r = mid;       else         l = mid;     }     if (f(r))       cout << r;     else       cout << -1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     sieve();     cin >> n >> k;     for (long long i = 1; i <= n; i++) cin >> p[i] >> c[i] >> l[i];     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool vis[500009];   int siz[500009];   int rr[1005][1005];   char arr[1005][1005];   vector<int> d;   int n;   void dfs(int x, int y, int cn) {     if (x > n or y > n or x < 1 or y < 1 or rr[x][y] != 0) return;     rr[x][y] = cn;     siz[cn]++;     if (arr[x + 1][y] ==  . ) dfs(x + 1, y, cn);     if (arr[x][y + 1] ==  . ) dfs(x, y + 1, cn);     if (arr[x - 1][y] ==  . ) dfs(x - 1, y, cn);     if (arr[x][y - 1] ==  . ) dfs(x, y - 1, cn);   }   void rem(int i, int j, int k) {     for (int t = i; t < i + k; t++) {       if (arr[t][j] ==  . ) siz[rr[t][j]]--;     }   }   int count(int i, int j, int k) {     vector<int> v;     int e, ans = 0;     for (int y = i; y < i + k && j - 1 >= 1; y++) {       e = rr[y][j - 1];       if (!vis[e] && e) {         v.push_back(e);         vis[e] = 1;         ans += siz[e];       }     }     for (int y = j; y < j + k && i - 1 >= 1; y++) {       e = rr[i - 1][y];       if (!vis[e] && e) {         v.push_back(e);         vis[e] = 1;         ans += siz[e];       }     }     for (int y = i; y < i + k && j + k <= n; y++) {       e = rr[y][j + k];       if (!vis[e] && e) {         v.push_back(e);         vis[e] = 1;         ans += siz[e];       }     }     for (int y = j; y < j + k && i + k <= n; y++) {       e = rr[i + k][y];       if (!vis[e] && e) {         v.push_back(e);         vis[e] = 1;         ans += siz[e];       }     }     for (int i = 0; i < v.size(); i++) {       vis[v[i]] = 0;     }     return ans;   }   void add(int i, int j, int k) {     for (int t = i; t < i + k; t++) {       if (arr[t][j] ==  . ) siz[rr[t][j]]++;     }   }   int main() {     int k, e = 0, a = 0;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cin >> arr[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (arr[i][j] ==  .  && rr[i][j] == 0) dfs(i, j, ++e);       }     }     for (int i = 1; i <= n - k + 1; i++) {       for (int y = 1; y <= k; y++) {         rem(i, y, k);       }       a = count(i, 1, k);       d.push_back(a);       int last = 1;       for (int j = 2; j <= n - k + 1; j++) {         rem(i, j + k - 1, k);         add(i, j - 1, k);         last = j;         a = count(i, j, k);         d.push_back(a);       }       for (int y = last; y <= n; y++) {         add(i, y, k);       }     }     sort(d.begin(), d.end());     cout << d[d.size() - 1] + (k * k) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi =       3.14159265358979323846264338327950288419716939937510582097494459230;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, i, x;     cin >> n;     int vis[n + 4];     int cnt[n + 4];     memset(cnt, 0, sizeof(cnt));     memset(vis, 0, sizeof(vis));     for (i = 0; i < n; i++) {       cin >> x;       cnt[x]++;     }     for (i = 1; i <= n; i++) {       if (cnt[i] >= 3) {         vis[i - 1] = 1;         vis[i] = 1;         vis[i + 1] = 1;       } else {         int d = cnt[i], j;         for (j = i - 1; j <= i + 1; j++) {           if (d == 0) break;           if (vis[j] == 1)             continue;           else {             vis[j] = 1;             d--;           }         }       }     }     int ans = 0;     for (i = 1; i <= n; i++) {       if (cnt[i] == 0) continue;       ans++;       i = i + 2;     }     cout << ans <<     << count(vis, vis + n + 2, 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[100005], res[100005];   map<int, pair<int, int>> xhMap;   int main() {     memset(x, 0, sizeof(x));     memset(res, 0, sizeof(res));     int n = 0, a = 0, b = 0;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &a, &b);       x[i] = a;       xhMap[a] = make_pair(b, i);     }     sort(x, x + n);     for (int i = n - 1; i >= 0; --i) {       int tmp = x[i] + xhMap[x[i]].first - 1, idx = xhMap[x[i]].second;       int r = i + 1, num = 1;       while (r < n && x[r] <= tmp) {         num += res[xhMap[x[r]].second];         r += res[xhMap[x[r]].second];       }       res[idx] = num;     }     for (int i = 0; i < n; ++i) {       printf( %d  , res[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 10;   vector<int> tree[N];   int cnt[N];   int n, mx1, mx2;   bool centr[N], ans[N];   int dfs(int v, int p = -1) {     int u;     cnt[v] = 1;     for (int i = 0; i < tree[v].size(); i++) {       u = tree[v][i];       if (u == p) continue;       cnt[v] += dfs(u, v);     }     return cnt[v];   }   void find_centr(int v, int p = -1) {     int u;     bool ok = (n - cnt[v]) <= n / 2;     for (int i = 0; i < tree[v].size(); i++) {       u = tree[v][i];       if (u == p) continue;       find_centr(u, v);       if (cnt[u] > n / 2) ok = false;     }     if (ok) centr[v] = 1;     return;   }   void calc(int v, int p = -1, int mxC = -1) {     int u;     if (n - cnt[v] - mxC <= n / 2)       ans[v] = true;     else       return;     for (int i = 0; i < tree[v].size(); i++) {       u = tree[v][i];       if (u == p) continue;       calc(u, v, mxC);     }     return;   }   void solveC(int aim) {     for (int i = 1; i <= n; i++) cnt[i] = 0;     dfs(aim);     mx1 = -1, mx2 = -1;     int u = 0;     for (int i = 0; i < tree[aim].size(); i++) {       u = tree[aim][i];       if (cnt[u] > mx1) {         mx2 = mx1;         mx1 = cnt[u];       } else if (cnt[u] > mx2)         mx2 = cnt[u];     }     for (int i = 0; i < tree[aim].size(); i++) {       u = tree[aim][i];       if (cnt[u] == mx1 && (cnt[u] != n / 2 || n / 2 * 2 != n))         calc(u, aim, mx2);       else         calc(u, aim, mx1);     }   }   void solve() {     cin >> n;     int b, e;     for (int i = 0; i < n - 1; i++) {       scanf( %d %d n , &b, &e);       tree[b].push_back(e);       tree[e].push_back(b);     }     dfs(1);     find_centr(1);     for (int i = 1; i <= n; i++) {       if (centr[i]) solveC(i);     }     for (int i = 1; i <= n; i++)       if (centr[i] || ans[i])         printf( 1  );       else         printf( 0  );   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long c;   vector<int> a;   int N;   long long C[65][65];   long long nCk(long long n, long long k) {     if (k > n) return 0;     return C[n][k];   }   long long f(int index, int onesNeeded, int tight) {     if (index == N) {       if (onesNeeded == 0)         return 1;       else         return 0;     }     if (a[index] == 0) {       return f(index + 1, onesNeeded, tight);     } else {       long long ans = nCk(N - index - 1, onesNeeded);       if (onesNeeded >= 1) ans += f(index + 1, onesNeeded - 1, tight);       return ans;     }   }   int brute(int n) {     int ans = 0;     for (int i = 1; i <= n; i++) {       int t = i, cnt = 0;       while (t) {         if (t % 2 == 1) cnt++;         t /= 2;       }       if (cnt == 5) ans++;     }     return ans;   }   int main() {     for (int i = 0; i <= 60; i++) C[i][0] = 1, C[i][i] = 1;     for (int n = 1; n <= 60; n++) {       for (int r = 1; r <= n; r++) {         C[n][r] = C[n - 1][r] + C[n - 1][r - 1];       }     }     long long n, t;     cin >> n >> t;     n++;     int ok = 0;     if ((t & (t - 1)) == 0) ok = 1;     while (t) {       t /= 2;       c++;     };     if (!ok) {       cout << 0 << endl;       return 0;     }     while (n) {       a.push_back(n % 2);       n /= 2;     }     reverse(a.begin(), a.end());     N = a.size();     long long ans1 = f(0, c, 1);     if (c == 1) ans1--;     cout << ans1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x, y, ans, f[200005];   char s[11];   int find(int k) {     if (k == f[k]) return k;     return f[k] = find(f[k]);   }   void add(int x, int y) {     if (find(x) != find(y)) f[find(x)] = find(y);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= 2 * n + 3; i++) f[i] = i;     for (int i = 1; i <= m; i++) {       scanf( %d%d%s , &x, &y, s);       x -= y;       y = min(x + 2 * y, 2 * n - x - 2 * y + 2);       x = max(x, -x);       if (s[0] ==  x ) {         add(2 * y, 2 * x);         add(2 * y + 1, 2 * x + 1);       } else {         add(2 * y + 1, 2 * x);         add(2 * x + 1, 2 * y);       }     }     for (int i = 0; i <= n + 1; i++)       if (find(2 * i) == find(2 * i + 1)) {         printf( 0 );         return 0;       }     int s = 0;     for (int i = 0; i <= 2 * n + 3; i++) s += (find(i) == i);     s = s / 2 - 2;     ans = 1;     for (int i = 1; i <= s; i++) ans = ans * 2 % 1000000007;     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   const int INF = 2e9;   const long long LNF = 9e18;   const int mod = 1e9 + 7;   const int maxn = 2e3 + 10;   int n, m, k;   bool val[maxn], pos[maxn];   long long C[maxn][maxn], A[maxn];   void init() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       if (x != -1) val[x] = pos[i] = 1;     }     k = m = 0;     for (int i = 1; i <= n; i++) {       if (!pos[i]) m++;       if (!pos[i] && !val[i]) k++;     }     A[0] = 1;     C[0][0] = 1;     for (int i = 1; i <= m; i++) {       A[i] = (1LL * i * A[i - 1]) % mod;       C[i][0] = 1;       for (int j = 1; j <= i; j++)         C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;     }   }   void solve() {     long long ans = A[m];     for (int i = 1; i <= k; i++) {       long long tmp = (1LL * C[k][i] * A[m - i]) % mod;       ans -= (i & 1) ? tmp : -tmp;       ans = (ans + mod) % mod;     }     cout << ans << endl;   }   int main() {     init();     solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char ara[100][100];   int fr[100], fc[100];   vector<int> r, c;   int pr;   void row(int j);   void col(int j) {     fc[j] = 1;     c.push_back(j);     for (int i = 0; i < n; i++)       if (ara[i][j] ==  # )         if (fr[i] == 0) row(i);   }   void row(int i) {     fr[i] = 1;     r.push_back(i);     for (int j = 0; j < m; j++)       if (ara[i][j] ==  # )         if (fc[j] == 0) col(j);   }   int check() {     for (int i = 0; i < r.size(); i++) {       for (int j = 0; j < c.size(); j++) {         if (ara[r[i]][c[j]] ==  . ) return 1;       }     }     return 0;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> ara[i][j];       }     }     for (int j = 0; j < m; j++) {       if (fc[j] == 0) {         pr++;         c.clear();         r.clear();         col(j);         if (check()) {           cout <<  No n ;           return 0;         }       }     }     cout <<  Yes n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   string to_string(const pair<T, T>& pr) {     return  (  + to_string(pr.first) +  ,  + to_string(pr.second) +  ) ;   }   template <typename T>   string to_string(const vector<T>& vc, int w) {     if (vc.empty()) return   ;     if (w + 1 == vc.size()) return to_string(vc[w]);     return to_string(vc[w]) +  ,  + to_string(vc, w + 1);   }   template <typename T>   string to_string(const vector<T>& vc) {     return  {  + to_string(vc, 0) +  } ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   class DebugStream {   } LOG;   template <typename T>   DebugStream& operator<<(DebugStream& s, const T&) {     return s;   }   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   const int maxN = 5.5e3 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20,             bs = 29;   int cap[maxN][maxN], ff[maxN][maxN], n, m, k, c, d, taim;   vector<int> adj[maxN];   int id(int t, int nd) { return t * n + nd + 1; }   void addEdge(int a, int b, int cp) {     if (!ff[a][b]) {       adj[a].push_back(b);       adj[b].push_back(a);       cap[a][b] = cp;     }     ff[a][b]++;     ff[b][a]++;   }   inline bool hasCap(int a, int b) {     if (!a || !b || a % n == b % n) return cap[a][b] > 0;     if (a > b) return cap[b][a] < 0;     return true;   }   int cln(int a, int b) { return (a + b - 1) / b; }   inline int getCost(int a, int b) {     if (!a || !b) return 0;     if (a % n == b % n) {       if ((a - 1) % n == 0) return 0;       return (a < b ? c : -c);     }     if (a > b) return (-cln(abs(cap[b][a]), ff[b][a]) * 2 + 1) * d - c;     return (abs(cap[a][b]) / ff[a][b] * 2 + 1) * d + c;   }   const int INF = 1e9;   void shortest_paths(vector<int>& d, vector<int>& p) {     d.assign(taim * n + 1, INF);     d[0] = 0;     vector<bool> inq(taim * n + 1, false);     queue<int> q;     q.push(0);     p.assign(taim * n + 1, -1);     while (!q.empty()) {       int u = q.front();       q.pop();       inq[u] = false;       for (int v : adj[u]) {         if (hasCap(u, v) && d[v] > d[u] + getCost(u, v)) {           d[v] = d[u] + getCost(u, v);           p[v] = u;           if (!inq[v]) {             inq[v] = true;             q.push(v);           }         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k >> c >> d;     taim = 101;     vector<int> frq(n);     for (int i = 0, inp; i < k; i++) {       cin >> inp;       inp--;       frq[inp]++;     }     for (int i = 0; i < n; i++)       if (frq[i]) addEdge(0, id(0, i), frq[i]);     for (int t = 0; t + 1 < taim; t++)       for (int j = 0; j < n; j++) addEdge(id(t, j), id(t + 1, j), k);     for (int i = 0, u, v; i < m; i++) {       cin >> u >> v;       u--, v--;       for (int t = 0; t + 1 < taim; t++) {         addEdge(id(t, u), id(t + 1, v), 0);         addEdge(id(t, v), id(t + 1, u), 0);       }     }     vector<int> d, p;     int ans = 0, trg = id(taim - 1, 0);     42;     for (int u = 0; u < k; u++) {       shortest_paths(d, p);       assert(d[trg] != INF);       ans += d[trg];       for (int cur = trg; cur != 0; cur = p[cur]) {         cap[p[cur]][cur]--;         cap[cur][p[cur]]++;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long int f = 1, mod;   void calc(int sum, int t) {     for (int i = 1; i <= sum; i++) {       if (i % 2 or !t)         f = (f * i) % mod;       else         f = (f * (i / 2)) % mod, t--;     }   }   int main() {     int n, p, count = 0, a[200001] = {0};     cin >> n;     vector<pair<int, int> > v;     for (int i = 1; i <= n; i++) cin >> p, v.push_back(make_pair(p, i));     for (int i = 1; i <= n; i++) cin >> p, v.push_back(make_pair(p, i));     sort(v.begin(), v.end());     int i = 0;     cin >> mod;     while (i < v.size()) {       int t = 0, sum = 0;       count++;       a[v[i].second] = count;       i++;       while (i < 2 * n and v[i].first == v[i - 1].first) {         if (a[v[i].second] == count) t++;         a[v[i].second] = count;         sum++;         i++;       }       calc(sum + 1, t);     }     cout << f;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 999999999999999999;   const double PI = acos(-1.0);   void stop() { exit(0); }   long long A[200005];   int main() {     ios::sync_with_stdio(false);     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> A[i];     }     long long res = 1;     long long curr = 1;     for (long long i = 0; i < n - 1; i++) {       if (A[i] * 2 >= A[i + 1]) {         curr++;       } else {         if (curr > res) res = curr;         curr = 1;       }     }     if (curr > res) res = curr;     cout << res;     stop();   }


#include <bits/stdc++.h>   using namespace std;   int abs(int x) {     if (x < 0) return -x;     return x;   }   int n, m;   int x[500], y[500], l[500];   bool used[500];   int placed[500];   int dist(int i, int j) { return abs(x[i] - x[j]) + abs(y[i] - y[j]); }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> x[i] >> y[i];     for (int i = 0; i < m; i++) cin >> l[i];     if (2 * m + 1 < n || n % 2 == 1) {       cout <<  NO  << endl;       return 0;     }     bool good = true;     for (int k = 0; k < 2; k++) {       if (k == 1 && good) break;       good = true;       memset(used, 0, 500 * sizeof(used[0]));       for (int i = 0; i < n; i++) placed[i] = -2;       for (int i = k; i < n; i += 2) {         int len = dist(i, (i - 1 + n) % n) + dist(i, (i + 1) % n);         bool match = false;         for (int j = 0; j < m; j++) {           if (!used[j] && l[j] == len) {             used[j] = 1;             placed[i] = j;             match = true;             break;           }         }         if (!match) {           good = false;           break;         }       }     }     if (!good)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;       cout << placed[0] + 1;       for (int i = 1; i < n; i++) cout <<     << placed[i] + 1;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, sum = 0, s[100005], ans[100005], an = 0;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &s[i]);       sum += s[i];     }     if (sum % k) {       printf( No );       return 0;     }     int m = sum / k;     int now = 0, len = 0;     for (int i = 1; i <= n; i++) {       if (now + s[i] > m) {         printf( No );         return 0;       }       now += s[i];       len++;       if (now == m) {         ans[++an] = len;         now = len = 0;       }     }     printf( Yes n );     for (int i = 1; i <= k; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     cout << 2 * a - 1 <<     << 2 <<   n ;     cout << 1 <<     << 2;   }


#include <bits/stdc++.h>   using namespace std;   long long int MOD = 1e9 + 7;   long long int INF = 1e18;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int i, j, k = 0, m = 0, n, p = 0, l, r, ans = 0, cnt = 0,                         mini = INF, maxi = INF, x, y, a, b, c, low, mid, high, h,                         q, k1, l1, t;     cin >> n >> m;     long long int A[m][n + 1];     long long int B[m][n + 1];     for (j = 0; j < m; j++) {       for (i = 1; i <= n; i++) {         cin >> k;         A[j][i] = k;         B[j][k] = i;       }     }     ans = n;     h = 1;     for (i = 1; i < n; i++) {       j = 0;       l = A[j][i];       r = A[j][i + 1];       p = 0;       for (j = 1; j < m; j++) {         if ((B[j][r] - B[j][l]) != 1) {           h = 1;           p = 1;           break;         }       }       if (p == 0) {         h++;         ans = ans + (h - 1);       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200009;   const long long MOD = 119 << 23 | 1;   class {    public:     bool g[1 << 22];     int a[1 << 22];     int N, M, n, m;     void solve() {       int _;       cin >> _;       while (_--) {         cin >> n >> m;         N = (1 << n) - 1;         M = (1 << m) - 1;         for (int i = 1; i <= N; ++i) cin >> a[i];         for (int i = M + 1; i <= N; ++i) g[i] = 1;         for (int i = M; i; --i) {           if (a[i << 1] < a[i << 1 | 1]) {             g[i] = g[i << 1 | 1];           } else {             g[i] = g[i << 1];           }         }         vector<int> ans;         int rt = 1;         for (int i = 0; i < N - M; ++i) {           while (!g[rt]) rt++;           ans.push_back(rt);           down(rt);         }         long long sum = 0;         for (int i = 1; i <= M; ++i) sum += a[i];         cout << sum <<   n ;         for (int i : ans) cout << i <<    ;         cout <<   n ;         for (int i = 1; i <= N; ++i) g[i] = a[i] = 0;       }     }     void down(int rt) {       int lson = rt << 1, rson = rt << 1 | 1;       if (a[lson] == 0 && a[rson] == 0) {         a[rt] = 0;         g[rt] = 0;         return;       }       if (a[lson] > a[rson]) {         a[rt] = a[lson];         down(lson);       } else {         a[rt] = a[rson];         down(rson);       }       if (rt <= M) {         if (a[lson] > a[rson])           g[rt] = g[lson];         else           g[rt] = g[rson];       }     }   } NSPACE;   int main() {     ;     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     NSPACE.solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, a[200000];   bool st[200000][2];   long long memo[200000][2];   long long solve(int node, int rev) {     if (node < 0 || node >= n) return 0;     if (st[node][rev]) return 0x3f3f3f3f3f3f3f3fll;     if (node == 0) return 0;     long long& val = memo[node][rev];     if (val != 0xc0c0c0c0c0c0c0c0ll) return val;     st[node][rev] = true;     val = solve(node + a[node] * (1 - 2 * rev), 1 - rev);     if (val != 0x3f3f3f3f3f3f3f3fll) val += a[node];     st[node][rev] = false;     return val;   }   int main() {     ios::sync_with_stdio(0);     memset(st, false, sizeof st);     memset(memo, 0xc0c0c0c0c0c0c0c0ll, sizeof memo);     cin >> n;     for (int i = 1; i < n; ++i) cin >> a[i];     for (int i = 1; i < n; ++i) {       st[0][0] = true;       long long ans = solve(i, 1);       if (ans == 0x3f3f3f3f3f3f3f3fll)         ans = -1;       else         ans += i;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int a[500005], n, d;   long long int ans = 0;   void func(long long int st, long long int ed) {     if (st + 1 == ed) return;     if (a[st] == a[ed]) {       ans = max(ans, (ed - st) / 2);       for (int i = st; i <= ed; ++i) {         a[i] = a[st];       }     } else {       ans = max(ans, (ed - st) / 2);       for (int i = st + 1; i <= (st + ed) / 2; ++i) {         a[i] = a[st];       }       for (int i = (st + ed) / 2 + 1; i <= ed; ++i) {         a[i] = a[ed];       }     }   }   int main(int argc, char const *argv[]) {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     long long int start, endx;     a[0] = a[1];     start = 1;     endx = n;     for (int i = start; i < endx; ++i) {       if (a[i] == a[i + 1]) {         func(start, i);         start = i + 1;       }     }     func(start, endx);     printf( %lld n , ans);     for (int i = 1; i <= n; ++i) {       cout << a[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     set<string> qq;     string s, q, g[100000];     int h, j = -1;     while (cin >> s) {       h = 3;       q =   ;       q = q + s[0] + s[1] + s[2];       while (h != s.length()) {         while (s[h] !=      && s[h] !=  . ) {           q += s[h];           h++;         }         q +=  / ;         if (s[h] !=  . ) {           j++;           g[j] = q;         } else           break;         h++;       }     }     j++;     sort(g, g + j);     int p = 1, max = 1;     qq.insert(g[0]);     for (int i = 1; i < j; i++) {       if (g[i] == g[i - 1])         p++;       else         p = 1;       if (p > max) max = p;       qq.insert(g[i]);     }     set<string>::iterator it;     string w =   , t =   ;     int r = 0, max2 = 0;     for (it = qq.begin(); it != qq.end(); it++) {       if (w ==   )         w = *it;       else {         t =   ;         p = 1;         for (int i = 0; i < w.length(); i++) {           if (i == (*it).length()) {             p = 0;             break;           }           t += (*it)[i];         }         if (t != w) p = 0;         if (p == 0) {           w = *it;           r = 0;         } else {           r++;         }         if (r > max2) max2 = r;       }     }     cout << max2 <<     << max;     return 0;   }


#include <bits/stdc++.h>   int m(int a) {     int ret = 0, i = 1;     while (a > 0) {       if (a % 10 == 4 || a % 10 == 7) {         ret += (i * (a % 10)), i *= 10;       }       a /= 10;     }     return ret;   }   int main() {     int a, b;     while (scanf( %d%d , &a, &b) != EOF) {       while (1) {         a++;         if (m(a) == b) {           printf( %d n , a);           return 0;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       int cnt = 0;       reverse(s.begin(), s.end());       cnt += (s[0] -  0 );       for (int i = 1; i < n; i++) {         if (s[i] !=  0 ) cnt = cnt + 1 + (s[i] -  0 );       }       cout << cnt <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 5e5;   vector<pair<long long, long long>> g[maxn];   long long v1 = 0;   long long v2 = 0;   vector<pair<pair<long long, long long>, long long>> t1(maxn * 4);   vector<pair<pair<long long, long long>, long long>> t2(maxn * 4);   vector<long long> pp1;   vector<pair<pair<long long, long long>, long long>> op1(maxn);   vector<long long> pp2;   vector<pair<pair<long long, long long>, long long>> op2(maxn);   long long n;   long long dist[maxn];   void push(vector<pair<pair<long long, long long>, long long>> &t, long long v) {     if (t[v].second == 1) {       t[v].second = 0;       t[v * 2].second ^= 1;       swap(t[v * 2].first.first, t[v * 2].first.second);       t[v * 2 + 1].second ^= 1;       swap(t[v * 2 + 1].first.first, t[v * 2 + 1].first.second);     }   }   void upd(vector<pair<pair<long long, long long>, long long>> &t, long long v,            long long tl, long long tr, long long pos, long long dist,            long long T) {     if (tl == tr) {       if (T == 0) {         t[v].first.first = dist;         t[v].first.second = 0;       } else {         t[v].first.first = 0;         t[v].first.second = dist;       }       return;     }     long long tm = (tl + tr) / 2;     if (pos <= tm) {       upd(t, v * 2, tl, tm, pos, dist, T);     } else {       upd(t, v * 2 + 1, tm + 1, tr, pos, dist, T);     }     t[v].first.first = max(t[v * 2].first.first, t[v * 2 + 1].first.first);     t[v].first.second = max(t[v * 2].first.second, t[v * 2 + 1].first.second);   }   void update(vector<pair<pair<long long, long long>, long long>> &t, long long v,               long long tl, long long tr, long long l, long long r) {     if (tl > r || tr < l) return;     if (l <= tl && tr <= r) {       swap(t[v].first.first, t[v].first.second);       t[v].second ^= 1;       return;     }     push(t, v);     long long tm = (tl + tr) / 2;     update(t, v * 2, tl, tm, l, r);     update(t, v * 2 + 1, tm + 1, tr, l, r);     t[v].first.first = max(t[v * 2].first.first, t[v * 2 + 1].first.first);     t[v].first.second = max(t[v * 2].first.second, t[v * 2 + 1].first.second);   }   long long get(vector<pair<pair<long long, long long>, long long>> &t,                 long long v, long long tl, long long tr, long long l,                 long long r) {     if (tl > r || tr < l) return 0;     if (l <= tl && tr <= r) {       if (t[v].second == 1) {         return t[v].first.second;       } else         return t[v].first.first;     }     push(t, v);     long long tm = (tl + tr) / 2;     return max(get(t, v * 2, tl, tm, l, r), get(t, v * 2 + 1, tm + 1, tr, l, r));   }   void dfs(vector<pair<pair<long long, long long>, long long>> &t,            vector<long long> &pp,            vector<pair<pair<long long, long long>, long long>> &op, long long v,            long long p, long long sum, long long H) {     upd(t, 1, 0, n - 1, pp.size(), H, sum % 2);     op[v].first.first = pp.size();     op[v].second = H;     pp.push_back(v);     for (long long i = 0; i < g[v].size(); ++i) {       long long to = g[v][i].first;       if (to == p) continue;       dfs(t, pp, op, to, v, sum + g[v][i].second, H + 1);     }     op[v].first.second = pp.size() - 1;   }   void jupaS(long long v, long long p) {     for (long long i = 0; i < g[v].size(); ++i) {       long long to = g[v][i].first;       if (to == p) continue;       dist[to] = dist[v] + 1;       jupaS(to, v);     }   }   signed main() {     cin.tie();     cout.tie();     ios_base::sync_with_stdio(false);     cin >> n;     vector<pair<long long, long long>> y;     for (long long i = 0; i < n - 1; ++i) {       long long a, b, t;       cin >> a >> b >> t;       a--;       b--;       y.push_back({a, b});       g[a].push_back({b, t});       g[b].push_back({a, t});     }     jupaS(0, -1);     long long mx = 0;     for (long long k = 0; k < n; ++k) {       if (dist[mx] < dist[k]) mx = k;     }     v1 = mx;     dist[v1] = 0;     jupaS(v1, -1);     mx = 0;     for (long long k = 0; k < n; ++k) {       if (dist[mx] < dist[k]) mx = k;     }     v2 = mx;     dfs(t1, pp1, op1, v1, -1, 0, 0);     dfs(t2, pp2, op2, v2, -1, 0, 0);     long long q;     cin >> q;     for (long long j = 0; j < q; ++j) {       long long id;       cin >> id;       id--;       long long a = y[id].first;       long long b = y[id].second;       if (op1[a].second > op1[b].second) swap(a, b);       update(t1, 1, 0, n - 1, op1[b].first.first, op1[b].first.second);       if (op2[a].second > op2[b].second) swap(a, b);       update(t2, 1, 0, n - 1, op2[b].first.first, op2[b].first.second);       long long mx = get(t1, 1, 0, n - 1, 0, n - 1);       long long mx1 = get(t2, 1, 0, n - 1, 0, n - 1);       cout << max(mx, mx1) <<   n ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> tr;   int S(int n) {     int ans = 1;     while (ans < n) ans *= 2;     return ans;   }   int k;   void upd(int v) {     v += k;     tr[v].first--;     for (; v > 1; v >>= 1) {       tr[v >> 1] = max(tr[v], tr[v ^ 1]);     }   }   template <typename T>   inline T getint() {     T val = 0;     char c;     bool neg = false;     while ((c = getchar()) && !(c >=  0  && c <=  9 )) {       neg |= c ==  - ;     }     do {       val = (val * 10) + c -  0 ;     } while ((c = getchar()) && (c >=  0  && c <=  9 ));     return val * (neg ? -1 : 1);   }   inline void writeInt(int x) {     if (x < 0) putc( - , stdout), x = -x;     char s[20];     int n = 0;     while (x || !n) s[n++] =  0  + x % 10, x /= 10;     while (n--) putc(s[n], stdout);   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int x, y;       cin >> x >> y;       vector<vector<int>> pos(n + 2);       vector<int> b(n);       tr.assign(10 * n, {0, 0});       for (int i = 0; i < n; i++) {         b[i] = getint<int>();         pos[b[i]].push_back(i);       }       int zn;       for (int i = 1; i < n + 2; i++) {         if (pos[i].empty()) {           zn = i;           break;         }       }       k = S(n + 1);       for (int i = 1; i < n + 2; i++) {         tr[k + i - 1] = {pos[i].size(), i};       }       for (int i = k - 1; i > 0; i--) {         tr[i] = max(tr[i * 2], tr[i * 2 + 1]);       }       vector<int> ans(n + 2);       int kol = x;       vector<int> h(n + 2);       vector<int> st;       while (kol--) {         ans[tr[1].second]++;         if (!h[tr[1].second]) st.push_back(tr[1].second);         h[tr[1].second]++;         upd(tr[1].second - 1);       }       kol = n - y;       int last = 0;       for (int i = 1; i <= kol; i++) {         if (2 * tr[1].first <= n - x - last) {           break;         }         ans[tr[1].second]++;         if (!h[tr[1].second]) st.push_back(tr[1].second);         h[tr[1].second]++;         upd(tr[1].second - 1);         last = i;       }       if (tr[1].first * 2 > n - x - last) {         cout <<  NO n ;         continue;       }       vector<int> a(n);       for (auto& ss : st) {         for (int i = 0; i < ans[ss]; i++) {           if (x) {             a[pos[ss][i]] = ss;             --x;           } else {             a[pos[ss][i]] = zn;           }         }       }       vector<vector<int>> npos(n + 2);       h.assign(n + 2, 0);       vector<int> s;       vector<int> cp;       for (int i = 0; i < n; i++) {         if (!a[i]) {           npos[b[i]].push_back(i);           cp.push_back(i);           h[b[i]]++;           if (h[b[i]] == 1) s.push_back(b[i]);         }       }       for (int i = 0; i < s.size(); i++) {         if (npos[s[i]].empty()) continue;         int uk = min(i + 1, (int)s.size() - 1);         for (int j = 0; j < npos[s[i]].size(); j++) {           if (npos[s[uk]].empty()) ++uk;           if (uk > s.size() - 1) break;           int p2 = npos[s[uk]].back();           a[npos[s[i]][j]] = b[p2];           a[p2] = b[npos[s[i]][j]];           npos[s[uk]].pop_back();         }       }       int col;       int uk = -1;       vector<int> cp2;       h.assign(n + 2, 0);       for (int i = 0; i < cp.size(); i++) {         if (!a[cp[i]] || a[cp[i]] == b[cp[i]]) {           h[cp[i]]++;           cp2.push_back(cp[i]);           a[cp[i]] = b[cp[i]];           if (uk == -1) {             col = a[cp[i]];             uk = i;           }         }       }       if (uk != -1) {         int i = 0;         for (int j = 0; j < cp2.size(); j++) {           for (;; i++) {             if (a[cp[i]] != col && !h[cp[i]] && b[cp[i]] != col) {               swap(a[cp[i]], a[cp2[j]]);               break;             }           }         }       }       kol -= last;       for (int i = 0; i < cp.size(); i++) {         if (kol) {           a[cp[i]] = zn;           --kol;         } else           break;       }       cout <<  Yes n ;       for (int i = 0; i < a.size(); i++) {         writeInt(a[i]);         cout <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   int main() {     int a, b, c;     while (~scanf( %d%d%d , &a, &b, &c)) {       int max = 999999999;       int a1 = (c + b) + a;       max = max < a1 ? max : a1;       int a2 = 2 * (c + b);       max = max < a2 ? max : a2;       int b1 = (c + a) * 2;       max = max < b1 ? max : b1;       int b2 = (b + a) * 2;       max = max < b2 ? max : b2;       printf( %d n , max);     }     return 0;   }