#include <bits/stdc++.h> n using namespace std; n const int N = 1003; n int n, k; n bitset<N * 3> A, dp, dpt; n int main() { n   scanf( %d%d , &n, &k); n   for (int a; k; k--) scanf( %d , &a), A[a] = 1; n   dp[1500] = 1; n   for (int __ = 1; __ <= 1009; __++) { n     dpt = 0; n     for (int i = 0; i < 3000; i++) n       if (dp[i] == 1) dpt |= A << (i - n); n     dp = dpt; n     if (dp[1500] == 1) return !printf( %d n , __); n   } n   return !printf( -1 n ); n } n


#include <bits/stdc++.h> n using namespace std; n long long n, fir; n int main() { n   scanf( %lld , &n); n   fir = n; n   for (int i = 2; 1ll * i * i <= n; i++) n     if (n % i == 0) { n       fir = i; n       break; n     } n   for (; n != 1 && n % fir == 0; n /= fir) n     ; n   printf( %lld n , n == 1 ? fir : 1); n } n


#include <bits/stdc++.h> n using namespace std; n map<long long, long long> m; n long long f(string s) { n   long long ff[27] = {0}, ans = 0, i, j; n   for (i = 0; i < s.size(); i++) { n     ff[s[i] -  a ]++; n   } n   for (i = 0; i < 26; i++) { n     if (ff[i] % 2) { n       ans |= (1LL << i); n     } n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, i, j; n   cin >> n; n   string s[n + 1]; n   vector<long long> v; n   for (i = 0; i < n; i++) { n     cin >> s[i]; n     v.push_back(f(s[i])); n   } n   for (i = 0; i < v.size(); i++) m[v[i]]++; n   long long ans = 0; n   for (auto i : m) { n     ans += (i.second * (i.second - 1)) / 2; n   } n   for (i = 0; i < 26; i++) { n     map<long long, long long> mm; n     for (j = 0; j < n; j++) n       if (v[j] & (1 << i)) mm[v[j] ^ (1LL << i)]++; n     for (auto j : mm) { n       ans += m[j.first] * j.second; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   int n, m, k; n   cin >> n >> m >> k; n   int result = n - m; n   if (k >= abs(result) && k != 0) { n     cout <<  ?  <<   n ; n   } else { n     if (result > 0) n       cout <<  + n ; n     else if (result < 0) n       cout <<  - n ; n     else if (result == 0) n       cout <<  0 n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n stack<char> st; n char s[100005]; n int main() { n   scanf( %s , s); n   int len = strlen(s); n   for (int i = 0; i < len; ++i) { n     if (st.empty() || st.top() != s[i]) n       st.push(s[i]); n     else n       st.pop(); n   } n   if (st.empty()) n     puts( Yes ); n   else n     puts( No ); n } n


#include <bits/stdc++.h> n using namespace std; n #define ll long long n int n,m; n char a[6][6]; n bool used[6][6]; n int ans; n void dfs(int x,int y) n { n     if(a[x][y]== * ) n     { n         ans++; n     } n     if(x==n&&y==m) n     { n         cout << ans; n         exit(0); n     } n     if(x+1<=n&&a[x+1][y]== * ) n     { n         dfs(x+1,y); n     } n     if(y+1<=m&&a[x][y+1]== * ) n     { n         dfs(x,y+1); n     } n     if(y+1<=m) n     { n         dfs(x,y+1); n     } n     if(x+1<=n) n     { n         dfs(x+1,y); n     } n } n int main() n { n     cin >> n >> m; n     for(int i = 1;i<=n;i++) n     { n         for(int j = 1;j<=m;j++) n         { n             cin >> a[i][j]; n         } n     } n     dfs(1,1); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   iostream::sync_with_stdio(0); n   int a, b, c, d; n   cin >> a >> b >> c >> d; n   for (int i = a; i <= 200; i++) { n     for (int j = b; j <= 200; j++) { n       for (int k = 1; k <= 200; k++) { n         if (a * 2 >= i && b * 2 >= j && c <= k && c * 2 >= k && i > d * 2 && n             j > d * 2 && d <= k && d * 2 >= k && i > j && j > k) { n           cout << i << endl << j << endl << k << endl; n           return 0; n         } n       } n     } n   } n   cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int visit[100005]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     char a[n][m]; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         if (i == 0 && j == 0) { n           a[i][j] =  W ; n         } else { n           a[i][j] =  B ; n         } n       } n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         cout << a[i][j]; n       } n       cout <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct Edge { n   int from, to; n   Edge(int f, int t) : from(f), to(t) {} n }; n vector<Edge> edges; n vector<int> G[100005]; n int h[100005]; n void add_edge(int from, int to) { n   edges.push_back(Edge(from, to)); n   int m = edges.size(); n   G[from].push_back(m - 1); n   return; n } n void bfs(int x) { n   queue<int> Q; n   Q.push(x); n   int cnt = 1, first = 1; n   h[x] = cnt; n   while (!Q.empty()) { n     int u = Q.front(); n     Q.pop(); n     if (h[u] == cnt && first) { n       cnt++; n       first = 0; n     } n     for (int i = 0; i < G[u].size(); i++) { n       Edge &e = edges[G[u][i]]; n       if (!h[e.to]) { n         h[e.to] = cnt; n         Q.push(e.to); n       } n     } n     first = 1; n   } n } n int main() { n   int n; n   while (scanf( %d , &n) != EOF) { n     for (int i = 0; i < n - 1; i++) { n       int u, v; n       scanf( %d %d , &u, &v); n       add_edge(u, v); n       add_edge(v, u); n     } n     memset(h, 0, sizeof(h)); n     bfs(1); n     double sum = 0.0; n     for (int i = 1; i <= n; i++) { n       if (h[i] != 0) sum += (double)1 / h[i]; n     } n     printf( %lf n , sum); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int pot(int x, int y) { n   if (y == 0) { n     return 1; n   } else { n     return x * pot(x, y - 1); n   } n } n int bin(int x, int y) { n   if ((x == 0 && y != 0) || (y == 0 && x != 0)) { n     return 1; n   } else { n     return bin(x, y - 1) + bin(x - 1, y); n   } n } n void strlwr(string& s) { n   for (int i = 0; (unsigned)i < s.size(); i++) { n     if (s[i] >=  A  && s[i] <=  Z ) { n       s[i] += 32; n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int a[26] = {}; n   int n; n   string s; n   cin >> s; n   n = s.size(); n   for (int i = 0; i < n; i++) { n     a[s[i] -  a ]++; n   } n   int k = 25; n   for (int i = 0; i < n; i++) { n     while (a[k] == 0 && k > 0) { n       k--; n     } n     if (s[i] -  a  < k) { n       a[s[i] -  a ]--; n     } n     if (s[i] -  a  == k) { n       a[s[i] -  a ]--; n       cout << s[i]; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i; n long n, m; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   map<string, int> mp; n   string s; n   while (n--) { n     cin >> s; n     mp[s]++; n     if (mp[s] > 1) { n       cout <<  YES  << endl; n     } else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int ans[52]; n   memset(ans, 0, sizeof(ans)); n   int flag = 0; n   for (int i = 0; i < n; ++i) { n     int arr[52]; n     memset(arr, 0, sizeof(arr)); n     for (int j = 0; j < n; ++j) { n       int k; n       cin >> k; n       arr[k]++; n     } n     for (int j = 0; j < n; ++j) { n       if (arr[j] == n - j) { n         ans[i] = j; n         if (j == n - 1) { n           ans[i] += flag; n           flag++; n         } n         break; n       } n     } n   } n   for (int i = 0; i < n; ++i) { n     if (ans[i] == 0) ans[i] = n; n     cout << ans[i] <<    ; n   } n } n


#include <bits/stdc++.h> n int const MOD = 998244353; n int main() { n   std::ios::sync_with_stdio(0); n   std::cin.tie(0); n   int n, nopt; n   std::cin >> n >> nopt; n   std::vector<int> h; n   h.reserve(n + 1); n   h.resize(n); n   for (int& hi : h) std::cin >> hi; n   h.push_back(h[0]); n   std::vector<int> f{1}; n   f.reserve(n * 2 + 1); n   std::vector<int> g; n   g.reserve(n * 2 + 1); n   for (int i = 0; i < n; ++i) { n     if (h[i] == h[i + 1]) { n       for (auto& fi : f) fi = int(fi * (int64_t)nopt % MOD); n       f.insert(begin(f), 0); n       f.push_back(0); n     } else { n       g.assign(begin(f), end(f)); n       g.push_back(0); n       g.push_back(0); n       assert(nopt - 2 >= 0); n       std::transform(begin(f), end(f), ++begin(g), ++begin(g), n                      [nopt](int fi, int gi) { n                        return int((gi + fi * int64_t(nopt - 2)) % MOD); n                      }); n       std::transform(begin(f), end(f), ++ ++begin(g), ++ ++begin(g), n                      [](int fi, int gi) { n                        return gi + fi >= MOD ? gi + fi - MOD : gi + fi; n                      }); n       std::swap(f, g); n     } n   } n   std::cout << std::accumulate(begin(f) + n + 1, end(f), 0LL) % MOD <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 100; n int arr[maxn]; n int main() { n   int T; n   cin >> T; n   while (T--) { n     int n; n     cin >> n; n     for (int i = 0; i < n; ++i) cin >> arr[i]; n     for (int i = 0; i < n; ++i) { n       if (i % 2) { n         if (arr[i] > 0) arr[i] = -arr[i]; n       } else { n         if (arr[i] < 0) arr[i] = -arr[i]; n       } n     } n     for (int i = 0; i < n; ++i) cout << arr[i] <<    ; n     cout << endl; n   } n   return 0; n } n


/* https://codeforces.com/blog/entry/87523 */ n #include <stdio.h> n #include <stdlib.h> n #include <string.h> n  n #define N 100000 n  n int *ej[N], eo[N]; n  n void append(int i, int j) { n  int o = eo[i]++; n  n  if (o >= 2 && (o & o - 1) == 0) n   ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]); n  ej[i][o] = j; n } n  n int main() { n  static int dd[N], ll[N + 1], qu[N], *qq[N], kk[N], dp[N + 1], dq[N + 1]; n  static char ans[N + 1]; n  int n, x, y, h, i, d, d_, k, s, cnt; n  n  scanf( %d%d , &n, &x); n  for (i = 0; i < n; i++) n   ej[i] = (int *) malloc(2 * sizeof *ej[i]); n  for (i = 1; i < n; i++) { n   int p; n  n   scanf( %d , &p), p--; n   append(p, i); n  } n  for (i = 1; i < n; i++) n   dd[i] = n; n  cnt = 0, qu[cnt++] = 0; n  for (d = 0; d < n && cnt; d++) { n   qq[d] = (int *) malloc(cnt * sizeof *qq[d]), memcpy(qq[d], qu, (kk[d] = cnt) * sizeof *qu); n   cnt = 0; n   for (h = 0; h < kk[d]; h++) { n    int o; n  n    i = qq[d][h]; n    for (o = eo[i]; o--; ) { n     int j = ej[i][o]; n  n     qu[cnt++] = j; n    } n   } n  } n  d_ = d; n  for (d = 0; d < d_; d++) n   ll[kk[d]]++; n  dp[0] = -1; n  for (k = 1; k <= n; k++) { n   if (ll[k] == 0) n    continue; n   for (s = 0; s <= n; s++) n    dq[s] = dp[s] ? 0 : (s >= k && dq[s - k] < ll[k] ? dq[s - k] : ll[k]) + 1; n   for (s = 0; s <= n; s++) n    if (!dp[s] && dq[s] <= ll[k]) n     dp[s] = k; n  } n  if (dp[x]) { n   printf( %d n , d_); n   memset(ll, 0, (n + 1) * sizeof *ll); n   for (k = n, s = x; k >= 1; k--) n    while (dp[s] == k) n     s -= k, ll[k]++; n   for (d = 0; d < d_; d++) n    if (ll[kk[d]]) { n     ll[kk[d]]--; n     for (h = 0; h < kk[d]; h++) n      ans[qq[d][h]] =  a ; n    } else n     for (h = 0; h < kk[d]; h++) n      ans[qq[d][h]] =  b ; n  } else { n   printf( %d n , d_ + 1); n   y = n - x; n   for (d = 0; d < d_; d++) n    if (x >= kk[d]) n     for (h = 0; h < kk[d]; h++) n      ans[qq[d][h]] =  a , x--; n    else if (y >= kk[d]) n     for (h = 0; h < kk[d]; h++) n      ans[qq[d][h]] =  b , y--; n    else { n     for (h = 0; h < kk[d]; h++) { n      i = qq[d][h]; n      if (eo[i]) n       ans[i] =  a , x--; n     } n     for (h = 0; h < kk[d]; h++) { n      i = qq[d][h]; n      if (!eo[i]) { n       if (x > 0) n        ans[i] =  a , x--; n       else n        ans[i] =  b , y--; n      } n     } n    } n  } n  printf( %s n , ans); n  return 0; n } n


#include <bits/stdc++.h> n #ifdef ALGO n #include  el_psy_congroo.hpp  n #else n #define DUMP(...) 1145141919810 n #define CHECK(...) (__VA_ARGS__) n #endif n  n struct Dsu { n   std::vector<int> dsu; n  n   explicit Dsu(int size) : dsu(size) { n     std::iota(dsu.begin(), dsu.end(), 0); n   } n  n   int find(int x) { n     return dsu[x] == x ? x : dsu[x] = find(dsu[x]); n   } n }; n  n using LL = long long; n  n LL binom2(int x) { n   if (x < 2) return 0; n   return x * 1LL * (x - 1) / 2; n } n  n struct Solver { n   int n; n   std::vector<std::vector<int>> edges; n   std::vector<int> sz; n   std::vector<int> parent; n  n   Solver(int n, std::vector<std::vector<int>> edges) : n(n), edges(edges), sz(n), parent(n, -1) {} n  n   void dfs(int u, int fa) { n     parent[u] = fa; n     sz[u] = 1; n     for (int v : edges[u]) if (v != fa) { n       dfs(v, u); n       sz[u] += sz[v]; n     } n   } n  n   void solve() { n     dfs(0, -1); n     std::vector<LL> result(n + 1); n     for (int v : edges[0]) result[0] += binom2(sz[v]); n     std::set<int> eds; n     Dsu dsu(n); n     std::vector<bool> mark(n); n     mark[0] = true; n     std::set<int> r1; n     for (int u = 1; u < n; ++u) { n       if (!mark[u]) { n         eds.emplace(u); n         for (int v = u; ; v = dsu.find(v)) { n           mark[v] = true; n           int w = parent[v]; n           if (w == 0) break; n           if (eds.count(w)) { n             eds.erase(w); n           } n           dsu.dsu[v] = w; n         } n       } n       r1.emplace(dsu.find(u)); n       if (r1.size() != eds.size()) { n         break; n       } n       if (eds.size() == 2) { n         LL val = 1; n         for (int v : eds) n           val *= sz[v]; n         result[u + 1] += val; n       } else if (eds.size() == 1) { n         LL val = sz[*eds.begin()]; n         val *= n - sz[dsu.find(u)]; n         result[u + 1] += val; n       } n       if (u > 1) result[u] -= result[u + 1]; n     } n     result[1] = binom2(n) - std::accumulate(result.begin(), result.end(), 0LL); n     for (int i = 0; i <= n; ++i) n       printf( %lld%c , result[i],    n [i == n]); n   } n }; n  n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(nullptr); n   std::istream& reader = std::cin; n  n   int cas; n   reader >> cas; n   while (cas--) { n     int n; n     reader >> n; n     std::vector<std::vector<int>> edges(n); n     for (int i = 0; i < n - 1; ++i) { n       int x, y; n       reader >> x >> y; n       edges[x].emplace_back(y); n       edges[y].emplace_back(x); n     } n     Solver(n, edges).solve(); n   } n } n  n


#include <bits/stdc++.h> n using namespace std; n const long long maxm = 1e+18; n vector<long long> prime; n long long power(long long x, long long y) { n   long long res = 1; n   x = x % 1000000007; n   while (y > 0) { n     if (y & 1) res = (res * x) % 1000000007; n     y = y >> 1; n     x = (x * x) % 1000000007; n   } n   return res; n } n void primeFactors(long long n) { n   prime.clear(); n   while (n % 2 == 0) { n     prime.push_back(2); n     n = n / 2; n   } n   for (int i = 3; i <= sqrt(n); i = i + 2) { n     while (n % i == 0) { n       prime.push_back(i); n       n = n / i; n     } n   } n   if (n > 2) prime.push_back(n); n } n long long getRes(long long n, long long p) { n   long long res = 1; n   long long x[101]; n   long long i = 1; n   long long j = 0; n   long long z = p; n   while (true) { n     if (z > n) break; n     x[j++] = n / z; n     if (maxm / z < p) break; n     z *= p; n     i++; n   } n   for (int i = 0; i < j - 1; i++) { n     x[i] -= x[i + 1]; n   } n   long long mul = 1; n   for (int i = 0; i < j; i++) { n     long long val = power(power(p, mul), x[i]); n     res = (res * (val) % 1000000007) % 1000000007; n     mul += 1; n   } n   return res; n } n int main() { n   long long x, n; n   cin >> x >> n; n   primeFactors(x); n   vector<long long>::iterator ip; n   ip = std::unique(prime.begin(), prime.end()); n   prime.resize(std::distance(prime.begin(), ip)); n   long long ans = 1; n   for (int i = 0; i < prime.size(); i++) { n     long long res = getRes(n, prime[i]); n     ans = (ans * res) % 1000000007; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n const int N = 3e5 + 5; n long long a[N]; n int main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   string s; n   cin >> s; n   string open =  ([{< ; n   string close =  )]}> ; n   map<char, char> closeMp; n   for (int i = 0; i < 4; i++) closeMp[close[i]] = open[i]; n   stack<char> st; n   int ans = 0; n   for (auto i : s) { n     if (closeMp.count(i) == 0) { n       st.push(i); n     } else { n       if (st.empty()) n         return cout <<  Impossible , 0; n       else { n         if (st.top() != closeMp[i]) ans++; n         st.pop(); n       } n     } n   } n   if (st.empty()) n     cout << ans; n   else n     cout <<  Impossible ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long find_smallest_number_with_cumulative_sum_greater_or_equal_than_sum( n     long long sum) { n   long long lower = 0, upper = (long long)15E8, mid; n   while (lower < upper) { n     mid = (lower + upper) / 2; n     if (mid * (mid + 1) / 2 >= sum) n       upper = mid; n     else n       lower = mid + 1; n   } n   return lower; n } n long long find_answer(long long n, long long H) { n   long long lower = H - 1, upper = (long long)15E8, mid; n   while (lower < upper) { n     mid = (lower + upper) / 2; n     long long current_sum = mid * (mid + 1) / 2 - H * (H - 1) / 2; n     long long remaining_sum = n - current_sum; n     if (find_smallest_number_with_cumulative_sum_greater_or_equal_than_sum( n             remaining_sum) <= mid + 1) n       upper = mid; n     else n       lower = mid + 1; n   } n   long long current_sum = lower * (lower + 1) / 2 - H * (H - 1) / 2; n   long long remaining_sum = n - current_sum; n   long long total_blocks_till_now = lower - (H - 1); n   return total_blocks_till_now + n          find_smallest_number_with_cumulative_sum_greater_or_equal_than_sum( n              remaining_sum); n } n int main() { n   long long n, H; n   cin >> n >> H; n   cout << find_answer(n, H) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int A, int B) { n   if (B == 0) n     return A; n   else n     return gcd(B, A % B); n } n long long int mod_exponentiation(long long int base, long long int exponent, n                                  int modulus) { n   long long int result = 1; n   while (exponent > 0) { n     if (exponent % 2 == 1) result = (result * base) % modulus; n     exponent = exponent >> 1; n     base = (base * base) % modulus; n   } n   return result; n } n int fermat(long long int n, long long int m) { n   return mod_exponentiation(n, m - 2, m); n } n struct node { n   int a; n   int cnt; n }; n struct Compare { n   bool operator()(node &a, node &b) { return a.cnt > b.cnt; } n }; n inline int toInt(string s) { n   int v; n   istringstream sin(s); n   sin >> v; n   return v; n } n template <class T> n inline string toString(T x) { n   ostringstream sout; n   sout << x; n   return sout.str(); n } n template <class T> n inline T sqr(T x) { n   return x * x; n } n int main() { n   int n; n   cin >> n; n   int a[8]; n   for (int i = 0; i < 7; i++) { n     cin >> a[i + 1]; n   } n   int sum = 0; n   for (int i = 1; i <= 7;) { n     sum += a[i]; n     if (sum >= n) { n       cout << i; n       return 0; n     } n     i++; n     if (i > 7) { n       i %= 7; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200006; n vector<vector<int> > edges(N); n vector<int> color; n bool bipartite; n vector<pair<int, int> > e; n int n, m; n void dfs(int node, int c) { n   color[node] = c; n   for (auto to : edges[node]) { n     if (color[to] == -1) { n       dfs(to, c ^ 1); n     } else { n       if (color[to] == color[node]) { n         bipartite = false; n       } n     } n   } n   return; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     x--; n     y--; n     edges[x].push_back(y); n     edges[y].push_back(x); n     e.push_back(make_pair(x, y)); n   } n   bipartite = true; n   color = vector<int>(n, -1); n   dfs(0, 0); n   if (!bipartite) { n     cout <<  NO n ; n     return 0; n   } n   cout <<  YES n ; n   for (int i = 0; i < m; i++) { n     cout << (color[e[i].first] < color[e[i].second]); n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ask(string q, int x) { n   cout << q <<     << x << endl; n   int ret; n   cin >> ret; n   return ret; n } n int getclosestnode(vector<vector<int>> &adj, set<int> &me, int node) { n   bool visited[1001]; n   memset(visited, 0, sizeof visited); n   queue<int> q; n   q.push(node); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     if (me.count(u) != 0) n       return u; n     else n       for (auto x : adj[u]) n         if (!visited[x]) { n           q.push(x); n           visited[x] = 1; n         } n   } n   return -1; n } n void solve() { n   int n; n   vector<vector<int>> adj(1001); n   cin >> n; n   for (int i = 0; i < (int)(n - 1); i++) { n     int a, b; n     cin >> a >> b; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   set<int> me, li; n   int k; n   cin >> k; n   for (int i = 0; i < (int)(k); i++) { n     int a; n     cin >> a; n     me.insert(a); n   } n   cin >> k; n   for (int i = 0; i < (int)(k); i++) { n     int a; n     cin >> a; n     li.insert(a); n   } n   int node = ask( B , *li.begin()); n   if (me.count(node) != 0) n     cout <<  C   << node << endl; n   else { n     int closest = getclosestnode(adj, me, node); n     int liclose = ask( A , closest); n     if (li.count(liclose) != 0) { n       cout <<  C   << closest << endl; n     } else n       cout <<  C   << -1 << endl; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int tc; n   cin >> tc; n   for (int i = 0; i < (int)(tc); i++) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct arc_t { n   int u, v, c; n   arc_t(int _u, int _v, int _c) : u(_u), v(_v), c(_c) {} n   bool operator<(const arc_t& rhs) const { return c < rhs.c; } n }; n int pa[2001]; n void set_init(int n) { n   for (int i = 1; i <= n; i++) pa[i] = i; n } n int set_find(int x) { return pa[x] == x ? x : pa[x] = set_find(pa[x]); } n int set_union(int x, int y) { n   x = set_find(x); n   y = set_find(y); n   if (x == y) { n     return -1; n   } n   pa[y] = x; n   return 0; n } n int f[2001][2001]; n vector<pair<int, int> > G[2001]; n long long d[2001][2001]; n int root; n vector<bool> mark; n int dfs(int u) { n   mark[u] = true; n   for (vector<pair<int, int> >::iterator i = G[u].begin(); i != G[u].end(); n        i++) { n     int v = i->first; n     if (!mark[v]) { n       d[root][v] = d[root][u] + i->second; n       dfs(v); n     } n   } n } n int getd(int _r) { n   root = _r; n   mark.clear(); n   mark.resize(2001, false); n   d[_r][_r] = 0; n   dfs(_r); n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) scanf( %d , &f[i][j]); n   vector<arc_t> arc; n   arc.reserve(n * n / 2 + 1); n   for (int i = 1; i <= n; i++) { n     if (f[i][i]) { n       puts( NO ); n       return 0; n     } n     for (int j = i + 1; j <= n; j++) { n       if (!f[i][j] || f[i][j] != f[j][i]) { n         puts( NO ); n         return 0; n       } n       arc.push_back(arc_t(i, j, f[i][j])); n     } n   } n   sort(arc.begin(), arc.end()); n   set_init(n); n   for (vector<arc_t>::iterator it = arc.begin(); it != arc.end(); it++) { n     if (!set_union(it->u, it->v)) { n       G[it->u].push_back(make_pair(it->v, it->c)); n       G[it->v].push_back(make_pair(it->u, it->c)); n     } n   } n   for (int i = 1; i <= n; i++) { n     getd(i); n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       if (d[i][j] != f[i][j]) { n         puts( NO ); n         return 0; n       } n   puts( YES ); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n #pragma GCC optimize(3,  Ofast ,  inline ) n using namespace std; n const long long mod = 1e9 + 7; n const long long M = 1e8 + 5; n const long long N = 6e5 + 5; n char s[N]; n bool check() { n   map<char, long long> mp; n   long long len = strlen(s + 1); n   long long l = 1; n   while (s[l] ==  a ) l++; n   if (l == 1) return 0; n   long long pos = l; n   while (s[l] ==  b ) l++; n   if (l == pos) return 0; n   while (s[l] ==  c ) l++; n   if (l != len + 1) return 0; n   for (register long long i = 1; i <= len; i++) mp[s[i]]++; n   if (mp[ c ] == mp[ a ] || mp[ c ] == mp[ b ]) return 1; n   return 0; n } n inline void solve() { n   scanf( %s , s + 1); n   puts(check() ?  YES  :  NO ); n } n signed main() { n   long long T = 1; n   for (long long index = 1; index <= T; index++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxx = 1e2 + 10; n int a[maxx], b[maxx]; n int n; n inline bool check(int m) { n   int max1 = 0, max2 = 0; n   for (int i = 1; i <= n; i++) { n     if (a[i] && !b[i]) n       max1 += m; n     else if (a[i] && b[i]) n       max1 += 1, max2 += 1; n     else if (!a[i] && b[i]) n       max2 += 1; n     else n       ; n   } n   return max1 > max2; n } n int main() { n   while (cin >> n && n) { n     for (int i = 1; i <= n; i++) cin >> a[i]; n     for (int i = 1; i <= n; i++) cin >> b[i]; n     int l = 1, r = 1e7, mid; n     int ans = -1; n     while (l <= r) { n       mid = l + r >> 1; n       if (check(mid)) { n         ans = mid; n         r = mid - 1; n       } else n         l = mid + 1; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string s, ans; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   cin.ignore(numeric_limits<streamsize>::max(),   n ); n   cin >> s; n   bool flag = true; n   int cnt = 0, max_cnt = 0; n   for (int i = 0; i < n - 1; ++i) { n     string sub = s.substr(i, 2); n     cnt = 0; n     for (int j = 0; j < n - 1; ++j) { n       flag = true; n       for (int k = 0; k < 2; ++k) { n         if (sub[k] != s[j + k]) flag = false; n       } n       if (flag) ++cnt; n       if (cnt > max_cnt) { n         max_cnt = cnt; n         ans = sub; n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = (int)1e9 + 7; n const int FFTMOD = 1007681537; n const int INF = (int)1e9; n const long long LINF = (long long)1e18; n const long double PI = acos((long double)-1); n const long double EPS = 1e-9; n inline long long gcd(long long a, long long b) { n   long long r; n   while (b) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n inline long long fpow(long long n, long long k, int p = MOD) { n   long long r = 1; n   for (; k; k >>= 1) { n     if (k & 1) r = r * n % p; n     n = n * n % p; n   } n   return r; n } n template <class T> n inline int chkmin(T& a, const T& val) { n   return val < a ? a = val, 1 : 0; n } n template <class T> n inline int chkmax(T& a, const T& val) { n   return a < val ? a = val, 1 : 0; n } n inline long long isqrt(long long k) { n   long long r = sqrt(k) + 1; n   while (r * r > k) r--; n   return r; n } n inline long long icbrt(long long k) { n   long long r = cbrt(k) + 1; n   while (r * r * r > k) r--; n   return r; n } n inline void addmod(int& a, int val, int p = MOD) { n   if ((a = (a + val)) >= p) a -= p; n } n inline void submod(int& a, int val, int p = MOD) { n   if ((a = (a - val)) < 0) a += p; n } n inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; } n inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } n inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; } n inline int sign(long double x, long double y) { return sign(x - y); } n const int maxn = 2e5 + 5; n int n; n vector<int> adj[maxn]; n int par[maxn]; n int size[maxn]; n int f[maxn]; n void dfs(int u, int p) { n   size[u] = 1; n   par[u] = p; n   for (int v : adj[u]) { n     if (v != p) { n       dfs(v, u); n       size[u] += size[v]; n     } n   } n } n void chemthan() { n   cin >> n; n   for (int i = (0); i < (n); ++i) { n     int u; n     cin >> u; n     u--; n     if (u != -1) { n       adj[u].push_back(i); n       adj[i].push_back(u); n     } n   } n   if (!(n & 1)) { n     cout <<  NO n ; n     return; n   } n   dfs(0, -1); n   for (int u = (0); u < (n); ++u) { n     int tot = 0; n     for (int v : adj[u]) { n       if (v != par[u]) { n         if (!(size[v] & 1)) { n           f[u]++; n         } n         tot += size[v]; n       } n     } n     tot = n - tot - 1; n     if (!(tot & 1) && tot) { n       f[u]++; n     } n   } n   static int deg[maxn]; n   static int rem[maxn]; n   for (int u = (0); u < (n); ++u) deg[u] = int((adj[u]).size()); n   set<int> st; n   for (int u = (0); u < (n); ++u) { n     if (!f[u] && !(deg[u] & 1)) { n       st.insert(u); n     } n   } n   vector<int> res; n   while (int((st).size())) { n     int u = *st.begin(); n     st.erase(u); n     if (deg[u] & 1) { n       continue; n     } n     res.push_back(u); n     rem[u] = 1; n     for (int v : adj[u]) { n       deg[v]--; n       f[v]--; n       if (!f[v] && !rem[v] && !(deg[v] & 1)) { n         st.insert(v); n       } n     } n   } n   if (int((res).size()) != n) { n     cout <<  NO n ; n     return; n   } n   cout <<  YES n ; n   for (int u : res) { n     cout << u + 1 <<   n ; n   } n } n int main(int argc, char* argv[]) { n   ios_base::sync_with_stdio(0), cin.tie(0); n   if (argc > 1) { n     assert(freopen(argv[1],  r , stdin)); n   } n   if (argc > 2) { n     assert(freopen(argv[2],  wb , stdout)); n   } n   chemthan(); n   cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000010; n int n, k; n int C[MAXN]; n void load() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) scanf( %d , C + i); n } n bool A[MAXN]; n int previ[MAXN]; n int nexti[MAXN]; n int last[MAXN]; n void sito() { n   int x = 2; n   for (int i = 0; i < MAXN; i++) A[i] = true; n   while (x * x <= MAXN) { n     int y = MAXN - 1; n     while (y != x) { n       y = previ[y]; n       long long z = (long long)x * y; n       if (z >= MAXN) continue; n       last[z] = x; n       nexti[previ[z]] = nexti[z]; n       previ[nexti[z]] = previ[z]; n       A[z] = false; n     } n     x = nexti[x]; n   } n } n int CFactors[MAXN]; n bool solve() { n   for (int i = 1; i < MAXN; i++) { n     previ[i] = i - 1; n     nexti[i] = i + 1; n   } n   sito(); n   for (int i = 0; i < MAXN; i++) n     if (A[i]) last[i] = i; n   for (int i = 0; i < n; i++) { n     int c = C[i]; n     while (c > 1) { n       int l = last[c]; n       int br = 0; n       while (c % l == 0) { n         br++; n         c /= l; n       } n       CFactors[l] = max(CFactors[l], br); n     } n   } n   while (k > 1) { n     int l = last[k]; n     int br = 0; n     while (k % l == 0) { n       br++; n       k /= l; n     } n     if (br > CFactors[l]) return false; n   } n   return true; n } n int main() { n   load(); n   if (solve()) n     printf( Yes n ); n   else n     printf( No n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   int n; n   cin >> n; n   if (n == 1 || n == 4 || n == 6 || n == 8 || n == 9 || n == 10 || n == 13 || n       n == 15) n     cout <<  1  << endl; n   else n     cout <<  0  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p[100]; n long long u, v; n int MOD; n void addmod(int &x, int y) { x = (x + y) % MOD; } n int dfs(long long minx, long long maxx, long long left, long long right, n         long long state, int step) { n   if (left <= minx && maxx <= right) { n     int ret = 0; n     long long r = (v >= state) ? ((v - state) >> step) : -1; n     long long l = (u - 1 >= state) ? ((u - 1 - state) >> step) : -1; n     if (r < 0LL) return 0; n     long long a = l + r + 1, b = r - l; n     if (a & 1) n       b >>= 1; n     else n       a >>= 1; n     ret = a % MOD * (b % MOD) % MOD; n     ret = (long long)ret * p[step] % MOD; n     addmod(ret, (r - l) % MOD * (state % MOD) % MOD); n     addmod(ret, (r - l) % MOD); n     return ret; n   } n   long long mid = (minx + maxx) / 2; n   int ret = 0; n   if (left <= mid) addmod(ret, dfs(minx, mid, left, right, state, step + 1)); n   if (right > mid) n     addmod(ret, n            dfs(mid + 1, maxx, left, right, state | (1LL << step), step + 1)); n   return ret; n } n int main() { n   long long n, l, r; n   int m; n   scanf( %I64d%d%d , &n, &m, &MOD); n   p[0] = 1 % MOD; n   for (int i = 1; i <= 90; ++i) { n     p[i] = (p[i - 1] * 2) % MOD; n   } n   for (int i = 0; i < m; ++i) { n     scanf( %I64d%I64d%I64d%I64d , &l, &r, &u, &v); n     u = max(0LL, u - 1); n     v = min(n - 1, v - 1); n     if (u > v) n       puts( 0 ); n     else n       printf( %d n , dfs(0, n - 1, l - 1, r - 1, 0, 0)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const long long MAX = 105; n long long n, m, x, y, z, k; n struct Matrix { n   long long row, col; n   long long m[MAX][MAX]; n }; n Matrix Multiply(Matrix A, Matrix B) { n   Matrix ans; n   ans.row = A.row; n   ans.col = B.col; n   for (long long i = 1; i <= A.row; i++) { n     for (long long j = 1; j <= B.col; j++) { n       ans.m[i][j] = 0; n       for (long long k = 1; k <= A.col; k++) { n         ans.m[i][j] += (A.m[i][k] * B.m[k][j]) % mod; n         if (ans.m[i][j] >= mod) ans.m[i][j] -= mod; n       } n     } n   } n   return ans; n } n Matrix Power(Matrix mat, long long p) { n   Matrix res; n   Matrix ans; n   ans.row = res.row = mat.row; n   ans.col = res.col = mat.col; n   long long n = ans.row; n   for (long long i = 1; i <= n; i++) { n     for (long long j = 1; j <= n; j++) { n       ans.m[i][j] = 0; n       res.m[i][j] = mat.m[i][j]; n     } n     ans.m[i][i] = 1; n   } n   while (p) { n     if (p % 2 == 1) ans = Multiply(ans, res); n     res = Multiply(res, res); n     p = p / 2; n   } n   return ans; n } n Matrix power(Matrix mat, long long p) { n   if (p == 1) return mat; n   if (p & 1) return Multiply(mat, power(mat, p - 1)); n   Matrix re = power(mat, (p / 2)); n   return Multiply(re, re); n } n Matrix mat; n long long ara[MAX]; n int main() { n   cin >> n >> k; n   for (long long i = 1; i <= n; i++) { n     scanf( %lld , &ara[i]); n   } n   if (k == 1) { n     cout << n << endl; n     return 0; n   } n   mat.row = mat.col = n; n   for (long long i = 1; i <= n; i++) { n     for (long long j = 1; j <= n; j++) { n       long long val = ara[i] ^ ara[j]; n       if (__builtin_popcountll(val) % 3 == 0) n         mat.m[i][j] = 1; n       else n         mat.m[i][j] = 0; n     } n   } n   mat = power(mat, k - 1); n   long long ans = 0; n   for (long long i = 1; i <= n; i++) { n     for (long long j = 1; j <= n; j++) { n       ans = (ans + mat.m[i][j]); n       if (ans >= mod) ans -= mod; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T abs(T x) { n   return x > 0 ? x : (-x); n } n template <class T> n T sqr(T x) { n   return x * x; n } n const int maxn = 1000 * 1000 * 2; n const int BUBEN = 40; n long long fib[BUBEN]; n int a[maxn]; n int n; n long long X, Y; n long long P; n struct M { n   long long a[2][2]; n   M() { memset(a, 0, sizeof(a)); } n   long long* operator[](int x) { return a[x]; } n   M operator*(M m) { n     M res; n     for (int i = 0; i < 2; ++i) n       for (int j = 0; j < 2; ++j) n         for (int k = 0; k < 2; ++k) n           res[i][j] = (res[i][j] + a[i][k] * m[k][j]) % P; n     return res; n   } n }; n M pw(M x, long long y) { n   M res; n   res[0][0] = res[1][1] = 1; n   while (y) { n     if (y % 2LL == 1LL) n       res = res * x, --y; n     else n       x = x * x, y /= 2LL; n   } n   return res; n } n const double alpha = (1. + sqrt(5.)) * 0.5; n bool cmp(pair<long long, long long> p, pair<long long, long long> q) { n   if (X >= BUBEN - 2) n     return p.first * alpha + p.second > q.first * alpha + q.second; n   return p.first * fib[X + 1] + p.second * fib[X] > n          q.first * fib[X + 1] + q.second * fib[X]; n } n int main() { n   fib[0] = 0; n   fib[1] = 1; n   for (int i = 2; i < BUBEN; ++i) fib[i] = fib[i - 1] + fib[i - 2]; n   cin >> n >> X >> Y >> P; n   long long sum = 0; n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n     sum += a[i]; n     sum %= P; n   } n   sort(a, a + n); n   if (0) { n     vector<int> v; n     for (int i = 0; i < n; ++i) v.push_back(a[i]); n     for (int i = 0; i < X; ++i) { n       vector<int> w; n       w.push_back(v[0]); n       for (int j = 1; j < ((int)(v).size()); ++j) n         w.push_back(v[j - 1] + v[j]), w.push_back(v[j]); n       v = w; n     } n     sort((v).begin(), (v).end()); n     for (int i = 0; i < Y; ++i) { n       vector<int> w; n       w.push_back(v[0]); n       for (int j = 1; j < ((int)(v).size()); ++j) n         w.push_back(v[j - 1] + v[j]), w.push_back(v[j]); n       v = w; n     } n     long long res = 0; n     for (int i = 0; i < ((int)(v).size()); ++i) res += v[i]; n     res %= P; n     cerr << res <<   n ; n   } n   if (n == 1) { n     cout << (a[0] % P) <<   n ; n     return 0; n   } n   long long l1 = a[0], r1 = a[n - 1]; n   long long l2 = a[0]; n   pair<long long, long long> _r2(-1, -1); n   for (int i = 0; i < n - 1; ++i) { n     long long x = a[i], y = a[i + 1]; n     if (x < y) swap(x, y); n     pair<long long, long long> cur(x, y); n     if (cmp(cur, _r2)) _r2 = cur; n   } n   M mf; n   mf[0][0] = mf[0][1] = mf[1][0] = 1; n   M F = pw(mf, X); n   long long r2 = F[0][0] * (_r2.first % P) + F[0][1] * (_r2.second % P); n   r2 %= P; n   M m1; n   m1[0][0] = 3; n   m1[0][1] = (P - 1) % P; n   m1[1][1] = 1; n   M m2 = pw(m1, X); n   long long T1 = l1 + r1; n   long long T2 = l2 + r2; n   T1 %= P; n   T2 %= P; n   long long s0 = m2[0][0] * sum + m2[0][1] * (T1); n   s0 %= P; n   M m3 = pw(m1, Y); n   long long res = m3[0][0] * s0 + m3[0][1] * (T2); n   res %= P; n   res += P; n   res %= P; n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int f[123]; n int l[123]; n int t[123][123]; n int h[123][123]; n int main() { n   int n, m, H; n   cin >> n >> m >> H; n   for (int i = 0; i < m; i++) scanf( %d , f + i); n   for (int i = 0; i < n; i++) scanf( %d , l + i); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) scanf( %d , &t[i][j]); n   for (int j = 0; j < m; j++) { n     for (int i = 0; i < n; i++) n       if (t[i][j] && l[i] >= f[j]) { n         h[i][j] = f[j]; n       } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) n       if (t[i][j] && f[j] >= l[i]) { n         h[i][j] = max(h[i][j], l[i]); n       } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) printf( %d  , h[i][j]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, i, j, a[100100], p = 1; n   scanf( %lld , &n); n   for (i = 0; i < n; i++) scanf( %lld , &a[i]); n   sort(a, a + n); n   for (i = 0; i < n; i++) { n     if (a[i] >= p) p++; n   } n   printf( %lld n , p); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string toString(int n) { n   ostringstream ost; n   ost << n; n   ost.flush(); n   return ost.str(); n } n int toInt(string s) { n   int r = 0; n   istringstream sin(s); n   sin >> r; n   return r; n } n int main() { n   int n; n   cin >> n; n   int arr[100]; n   map<int, int> mp; n   vector<int> vp; n   for (int i = 0; i < n; i++) cin >> arr[i], mp[arr[i]]++, vp.push_back(arr[i]); n   sort(arr, arr + n); n   { n     sort((vp).begin(), (vp).end()); n     (vp).erase(unique((vp).begin(), (vp).end()), vp.end()); n   }; n   int ans = 0; n   for (int i = 0; i < vp.size(); i++) { n     ans += mp[vp[i]] / 2; n   } n   cout << (ans / 2) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t; n int main() { n   cin >> t; n   while (t--) { n     int n, nrp = 0, nri = 0; n     cin >> n; n     while (n--) { n       int x; n       cin >> x; n       if (x % 2) n         nri++; n       else n         nrp++; n     } n     if (nrp == 0) n       if (nri % 2) n         cout <<  YES n ; n       else n         cout <<  NO n ; n     else if (nri) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, parent[100002]; n long long pl[100002], ans, dp[100002][22][5]; n vector<long long> gr[100002]; n long long ast[65]; n void dfs(long long v) { n   for (long long i = 0; i <= 20; i++) { n     long long x = ((pl[v] >> i) & 1); n     dp[v][i][x]++; n   } n   long long klir[22][5]; n   for (long long i = 0; i <= 20; i++) { n     klir[i][0] = 0; n     klir[i][1] = 0; n   } n   for (long long i = 0; i < gr[v].size(); i++) { n     if (gr[v][i] == parent[v]) continue; n     parent[gr[v][i]] = v; n     dfs(gr[v][i]); n     for (long long j = 0; j <= 20; j++) { n       klir[j][0] += dp[gr[v][i]][j][0]; n       klir[j][1] += dp[gr[v][i]][j][1]; n     } n   } n   for (long long i = 0; i < gr[v].size(); i++) { n     if (gr[v][i] == parent[v]) continue; n     for (long long j = 0; j <= 20; j++) { n       long long x = ((pl[v] >> j) & 1); n       dp[v][j][x] += dp[gr[v][i]][j][0]; n       dp[v][j][x ^ 1] += dp[gr[v][i]][j][1]; n       klir[j][0] -= dp[gr[v][i]][j][0]; n       klir[j][1] -= dp[gr[v][i]][j][1]; n       if (x == 1) { n         ans += (ast[j]) * dp[gr[v][i]][j][0] * klir[j][0]; n         ans += (ast[j]) * dp[gr[v][i]][j][1] * klir[j][1]; n       } else { n         ans += (ast[j]) * dp[gr[v][i]][j][0] * klir[j][1]; n         ans += (ast[j]) * dp[gr[v][i]][j][1] * klir[j][0]; n       } n     } n   } n   for (long long i = 0; i <= 20; i++) ans += dp[v][i][1] * (ast[i]); n } n int main() { n   cin >> n; n   ast[0] = 1; n   for (long long i = 1; i < 64; i++) ast[i] = 2 * ast[i - 1]; n   for (long long i = 1; i <= n; i++) scanf( %lld , &pl[i]); n   for (long long i = 1; i < n; i++) { n     long long k, l; n     scanf( %lld%lld , &k, &l); n     gr[k].push_back(l); n     gr[l].push_back(k); n   } n   dfs(1); n   cout << ans << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n inline int read(void) { n   int x = 0; n   char c = getchar(); n   while (c >  9  || c <  0 ) c = getchar(); n   while (c >=  0  && c <=  9 ) x = x * 10 + (c -  0 ), c = getchar(); n   return x; n } n const int N = 150010, M = 300010; n int n, m, c; n int loc[N], p[N]; n struct xint { n   double max_left, max_right, sum, res; n   xint() {} n   xint(double A) : max_left(A), max_right(A), sum(A), res(A) {} n   inline void print(void) { n     printf( %.2lf %.2lf %.2lf %.2lf n , sum, max_left, max_right, res); n     puts(  ); n   } n } tr[N * 5]; n xint update(xint lc, xint rc) { n   xint k; n   k.sum = lc.sum + rc.sum; n   k.max_left = max(lc.max_left, lc.sum + rc.max_left); n   k.max_right = max(rc.max_right, lc.max_right + rc.sum); n   k.res = max(lc.res, rc.res); n   k.res = max(k.res, lc.max_right + rc.max_left); n   return k; n } n void build(int k, int l, int r) { n   if (l == r) { n     double P = (double)p[l] / 100.0; n     double tmp = (double)(loc[l + 1] - loc[l]) / 2 - P * c; n     tr[k] = xint(tmp); n     return; n   } n   int mid = (l + r) >> 1; n   int lc = k << 1, rc = k << 1 | 1; n   build(lc, l, mid); n   build(rc, mid + 1, r); n   tr[k] = update(tr[lc], tr[rc]); n } n xint query(int k, int l, int r, int x, int y) { n   if (x <= l && r <= y) return tr[k]; n   if (l > r) return 0; n   int mid = (l + r) >> 1; n   int lc = k << 1, rc = k << 1 | 1; n   if (y <= mid) return query(lc, l, mid, x, y); n   if (x > mid) return query(rc, mid + 1, r, x, y); n   xint tmp1 = query(lc, l, mid, x, y); n   xint tmp2 = query(rc, mid + 1, r, x, y); n   return update(tmp1, tmp2); n } n int main(void) { n   n = read(), m = read(), c = read(); n   for (int i = 1; i <= n; ++i) loc[i] = read(); n   for (int i = 1; i < n; ++i) p[i] = read(); n   build(1, 1, n - 1); n   double ans = 0; n   for (int i = 1; i <= m; ++i) { n     int l = read(), r = read(); n     xint tmp = query(1, 1, n - 1, l, r - 1); n     ans += max(tmp.res, 0.0); n   } n   printf( %.8lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse4 ) n using namespace std; n static const int INF = 0x3f3f3f3f; n static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; n template <typename T, typename U> n static void amin(T &x, U y) { n   if (y < x) x = y; n } n template <typename T, typename U> n static void amax(T &x, U y) { n   if (x < y) x = y; n } n inline uint32_t ifzero(int num) { return (num - 1) >> 31; } n inline int ifnotzero(int num) { return ~((num - 1) >> 31); } n int main() { n   int Q; n   while (~scanf( %d , &Q)) { n     vector<uint32_t> pos(100000), neg(100000); n     for (int ii = 0; ii < Q; ++ii) { n       int ty; n       scanf( %d , &ty); n       if (ty == 1) { n         int L; n         int R; n         int k; n         scanf( %d%d%d , &L, &R, &k), --L, --R; n         uint32_t *data = k > 0 ? pos.data() : neg.data(); n         uint32_t b = abs(k) - 1; n         for (int(x) = (int)(L); (x) < (int)(R); ++(x)) { n           auto a = data[x] - 1; n           data[x] = (a < b ? a : b) + 1; n         } n       } else if (ty == 2) { n         int L; n         int R; n         scanf( %d%d , &L, &R), --L, --R; n         long long ans = 0; n         for (int(x) = (int)(L); (x) < (int)(R); ++(x)) { n           ans += (pos[x] + neg[x]) & ifnotzero(pos[x]) & ifnotzero(neg[x]); n         } n         printf( %lld n , ans); n       } else n         abort(); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n vector<pair<int, int> > V; n int main(int argc, const char *argv[]) { n   cin >> N >> M; n   for (int i = 0, x, y; i < M; i++) { n     cin >> x >> y; n     V.push_back(pair<int, int>(x, y)); n   } n   sort(V.begin(), V.end()); n   vector<pair<int, int> > currI; n   currI.push_back(pair<int, int>(1, 1)); n   int currRow = 0; n   for (int i = 0; i < V.size();) { n     pair<int, int> p = V[i]; n     vector<pair<int, int> > newI; n     if (p.first > currRow + 1 && currI.size()) { n       int left = currI[0].first; n       currI.clear(); n       currI.push_back(pair<int, int>(left, N)); n     } n     currRow = p.first; n     vector<pair<int, int> > temp; n     int last = 0; n     while (i < V.size() && V[i].first == p.first) { n       temp.push_back(pair<int, int>(last + 1, V[i].second - 1)); n       last = V[i].second; n       i++; n     } n     temp.push_back(pair<int, int>(last + 1, N)); n     int j = 0; n     for (auto x : temp) { n       while (j < currI.size() && currI[j].second < x.first) j++; n       if (j < currI.size()) { n         int x1 = max(x.first, currI[j].first), x2 = x.second; n         if (x2 >= x1) { n           newI.push_back(pair<int, int>(x1, x2)); n         } n       } n     } n     currI = newI; n   } n   bool poss = false; n   if (currI.size() > 0) { n     pair<int, int> l = currI[currI.size() - 1]; n     poss = (currRow < N && l.second <= N); n     poss = poss || (currRow == N && l.second == N); n   } n   if (poss) { n     cout << 2 * (N - 1) << endl; n   } else { n     cout << -1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int a[n]; n     for (int i = 0; i < n; i++) cin >> a[i]; n     for (int i = n - 1; i >= 0; i--) cout << a[i] <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char a[1000]; n   cin >> a; n   int n = strlen(a), i, up = 1; n   for (i = 1; i < n; i++) n     if (a[i] >=  a  && a[i] <=  z ) up = 0; n   if (up) { n     for (i = 1; i < n; i++) a[i] = a[i] +  a  -  A ; n     if (a[0] >=  A  && a[0] <=  Z ) n       a[0] = a[0] +  a  -  A ; n     else n       a[0] = a[0] +  A  -  a ; n   } n   cout << a; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n inline T1 max(T1 a, T2 b) { n   return a < b ? b : a; n } n template <typename T1, typename T2> n inline T1 min(T1 a, T2 b) { n   return a < b ? a : b; n } n const char lf =   n ; n namespace ae86 { n const int bufl = 1 << 15; n char buf[bufl], *s = buf, *t = buf; n inline int fetch() { n   if (s == t) { n     t = (s = buf) + fread(buf, 1, bufl, stdin); n     if (s == t) return EOF; n   } n   return *s++; n } n inline int ty() { n   int a = 0; n   int b = 1, c = fetch(); n   while (!isdigit(c)) b ^= c ==  - , c = fetch(); n   while (isdigit(c)) a = a * 10 + c - 48, c = fetch(); n   return b ? a : -a; n } n }  // namespace ae86 n using ae86::ty; n const int _ = 500007, __ = _ << 1, inf = 0x3f3f3f3f; n struct cxk { n   int v, len; n   cxk(int v_ = inf, int len_ = 0) { v = v_, len = len_; } n   int f(int x) { return min(x + len, v); } n   friend cxk operator+(cxk a, cxk b) { n     return cxk(min(a.v + b.len, b.v), a.len + b.len); n   } n }; n struct sgt { n   static const int _t = __ << 2; n   cxk t[_t]; n   int mx[_t]; n   void up(int x) { n     t[x] = t[(x << 1)] + t[(x << 1 | 1)]; n     mx[x] = max(mx[(x << 1)], mx[(x << 1 | 1)]); n   } n   void plant(int x, int l, int r) { n     t[x] = cxk(), mx[x] = -inf; n     if (l == r) return; n     plant((x << 1), l, ((l + r) >> 1)), n         plant((x << 1 | 1), ((l + r) >> 1) + 1, r), up(x); n   } n   void change(int x, int l, int r, int tar, int dlt) { n     if (l == r) { n       t[x].len++, t[x].v = dlt, mx[x] = max(mx[x], dlt); n       return; n     } n     if (tar <= ((l + r) >> 1)) n       change((x << 1), l, ((l + r) >> 1), tar, dlt); n     else n       change((x << 1 | 1), ((l + r) >> 1) + 1, r, tar, dlt); n     up(x); n   } n   int findlen(int x, int l, int r, int tl, int tr) { n     if (tl <= l && r <= tr) return t[x].len; n     if (tr <= ((l + r) >> 1)) n       return findlen((x << 1), l, ((l + r) >> 1), tl, tr); n     if (tl > ((l + r) >> 1)) n       return findlen((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr); n     return findlen((x << 1), l, ((l + r) >> 1), tl, tr) + n            findlen((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr); n   } n   int findmx(int x, int l, int r, int tl, int tr) { n     if (tl <= l && r <= tr) return mx[x]; n     if (tr <= ((l + r) >> 1)) n       return findmx((x << 1), l, ((l + r) >> 1), tl, tr); n     if (tl > ((l + r) >> 1)) n       return findmx((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr); n     return max(findmx((x << 1), l, ((l + r) >> 1), tl, tr), n                findmx((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr)); n   } n   cxk findcxk(int x, int l, int r, int tl, int tr) { n     if (tl <= l && r <= tr) return t[x]; n     if (tr <= ((l + r) >> 1)) n       return findcxk((x << 1), l, ((l + r) >> 1), tl, tr); n     if (tl > ((l + r) >> 1)) n       return findcxk((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr); n     return findcxk((x << 1), l, ((l + r) >> 1), tl, tr) + n            findcxk((x << 1 | 1), ((l + r) >> 1) + 1, r, tl, tr); n   } n } t; n int n, val[_], rk[_] = {0}; n pair<int, int> temp[_]; n int able(int x) { return t.findmx(1, 1, n, 1, x) <= -t.findlen(1, 1, n, 1, x); } n int main() { n   ios::sync_with_stdio(0), cout.tie(nullptr); n   n = ty(); n   for (int i = 1; i <= n; i++) val[i] = ty(), temp[i] = make_pair(val[i], i); n   sort(temp + 1, temp + n + 1); n   for (int i = 1; i <= n; i++) rk[temp[i].second] = i; n   t.plant(1, 1, n); n   for (int i = 1; i <= n; i++) { n     t.change(1, 1, n, rk[i], temp[rk[i]].first); n     int l = 1, r = n, ans = -1; n     while (r >= l) { n       int mid = (l + r) >> 1; n       if (able(mid)) n         ans = mid, l = mid + 1; n       else n         r = mid - 1; n     } n     if (ans < 0) n       cout << t.findcxk(1, 1, n, 1, n).f(0) << lf; n     else { n       int ps = t.findlen(1, 1, n, 1, ans); n       if (ans >= n) n         cout << -ps << lf; n       else n         cout << t.findcxk(1, 1, n, ans + 1, n).f(-ps) << lf; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 102400; n long long n, ans, c00, c01, c10, c11; n string a, b; n int main() { n   cin >> n >> a >> b; n   for (int i = 0; i < n; i++) { n     if (a[i] ==  0  && b[i] ==  0 ) n       c00++; n     else if (a[i] ==  0  && b[i] ==  1 ) n       c01++; n     else if (a[i] ==  1  && b[i] ==  0 ) n       c10++; n     else if (a[i] ==  1  && b[i] ==  1 ) n       c11++; n   } n   for (int i = 0; i < n; i++) { n     if (a[i] ==  0  && b[i] ==  0 ) n       ans += (c10 + c11); n     else if (a[i] ==  0  && b[i] ==  1 ) n       ans += c10; n     else if (a[i] ==  1  && b[i] ==  0 ) n       ans += (c00 + c01); n     else if (a[i] ==  1  && b[i] ==  1 ) n       ans += c00; n   } n   cout << ans / 2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n char s[5010]; n int mat[5010][5010]; n int dp[5010][5010]; n int n; n void findAllPalindromes() { n   for (int i = 0; i < n; i++) { n     for (int j = 0; i - j >= 0 && i + j < n; j++) { n       if (s[i - j] == s[i + j]) n         mat[i - j][i + j] = 1; n       else n         break; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; i - j >= 0 && i + j + 1 < n; j++) { n       if (s[i - j] == s[i + j + 1]) n         mat[i - j][i + j + 1] = 1; n       else n         break; n     } n   } n } n void filldp() { n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) { n       dp[i][j] = n           dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1] + mat[i - 1][j - 1]; n     } n } n inline int sum(int l, int r) { n   int ans = dp[n][r]; n   if (l > 0) ans -= dp[l - 1][r]; n   return ans; n } n int main() { n   scanf(  %s , s); n   n = strlen(s); n   findAllPalindromes(); n   filldp(); n   int q; n   scanf(  %d , &q); n   while (q--) { n     int l, r; n     scanf( %d %d , &l, &r); n     printf( %d n , sum(l, r)); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n void read(long long &x) { n   char ch = getchar(); n   x = 0; n   while (!isdigit(ch)) ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); n } n const long long N = 105, mod = 1e9 + 9; n long long n, now, m, sz[N], f[N][N], p[N], in[N], res[N]; n long long cnt, h[N], to[N * N], nxt[N * N], c[N], inv[N]; n void add(long long u, long long v) { n   to[++cnt] = v, nxt[cnt] = h[u], h[u] = cnt, ++c[v]; n } n queue<long long> q; n long long vis[N], used[N]; n void topo() { n   for (long long i = 1; i <= n; ++i) n     if (c[i] <= 1) vis[i] = 1, q.push(i); n   while (!q.empty()) { n     long long t = q.front(); n     q.pop(); n     for (long long i = h[t], v; i; i = nxt[i]) { n       if ((--c[v = to[i]]) <= 1 && !vis[v]) vis[v] = 1, q.push(v); n     } n   } n } n long long C(long long x, long long y) { n   return p[x] * in[y] % mod * in[x - y] % mod; n } n void dp(long long u) { n   used[u] = sz[u] = f[u][0] = 1; n   for (long long i = h[u], v; i; i = nxt[i]) { n     if (used[v = to[i]] || !vis[v]) continue; n     dp(v); n     for (long long x = sz[u] - 1; x >= 0; --x) n       for (long long y = 1; y <= sz[v]; ++y) n         ((f[u][x + y] += f[u][x] * f[v][y] % mod * C(x + y, x) % mod) >= mod && n          (f[u][x + y] -= mod)); n     sz[u] += sz[v]; n   } n   f[u][sz[u]] = f[u][sz[u] - 1]; n } n long long Pow(long long x, long long y) { n   long long tmp = 1; n   while (y) { n     if (y & 1) tmp = tmp * x % mod; n     x = x * x % mod, y >>= 1; n   } n   return tmp; n } n vector<long long> st; n void find(long long u, long long la) { n   st.push_back(u); n   for (long long i = h[u], v; i; i = nxt[i]) n     if ((v = to[i]) != la) find(v, u); n } n long long tmp[N]; n void work(long long u, long long la) { n   memset(f[u], 0, sizeof(f[u])); n   sz[u] = f[u][0] = 1; n   for (long long i = h[u], v; i; i = nxt[i]) { n     if ((v = to[i]) == la) continue; n     work(v, u); n     for (long long x = sz[u] - 1; x >= 0; --x) n       for (long long y = 1; y <= sz[v]; ++y) n         ((f[u][x + y] += f[u][x] * f[v][y] % mod * C(x + y, y) % mod) >= mod && n          (f[u][x + y] -= mod)); n     sz[u] += sz[v]; n   } n   f[u][sz[u]] = f[u][sz[u] - 1]; n } n void merge(long long *a, long long tot) { n   for (long long i = now; i >= 0; --i) n     for (long long j = 1; j <= tot; ++j) n       ((res[i + j] += res[i] * a[j] % mod * C(i + j, i) % mod) >= mod && n        (res[i + j] -= mod)); n   now += tot; n } n signed main() { n   read(n), read(m); n   for (long long i = 1, u, v; i <= m; ++i) n     read(u), read(v), add(u, v), add(v, u); n   topo(); n   p[0] = res[0] = 1; n   for (long long i = 1; i <= n; ++i) p[i] = p[i - 1] * i % mod; n   in[n] = Pow(p[n], mod - 2); n   for (long long i = n - 1; i >= 0; --i) in[i] = in[i + 1] * (i + 1) % mod; n   for (long long i = 1; i <= n; ++i) inv[i] = Pow(i, mod - 2); n   for (long long i = 1; i <= n; ++i) { n     if (vis[i]) continue; n     for (long long j = h[i], v; j; j = nxt[j]) n       if (vis[v = to[j]] && !used[v]) dp(v), merge(f[v], sz[v]); n   } n   for (long long i = 1; i <= n; ++i) n     if (vis[i] && !used[i]) { n       st.clear(), find(i, i); n       long long tot = st.size(); n       memset(tmp, 0, sizeof(tmp)); n       for (long long j = 0; j < tot; ++j) { n         work(st[j], st[j]), used[st[j]] = 1; n         for (long long k = 0; k <= tot; ++k) n           ((tmp[k] += f[st[j]][k]) >= mod && (tmp[k] -= mod)); n       } n       for (long long j = 0; j < tot; ++j) tmp[j] = tmp[j] * inv[tot - j] % mod; n       merge(tmp, tot); n     } n   for (long long i = 0; i <= n; ++i) printf( %lld n , res[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int id, v; n } tree[4 * 100005]; n int in[100005]; n void build(int nod, int s, int e) { n   if (s == e) { n     tree[nod].id = s; n     tree[nod].v = in[s]; n     return; n   } n   int mid = (s + e) / 2, l = 2 * nod, r = l + 1; n   build(l, s, mid); n   build(r, mid + 1, e); n   if (tree[l].v > tree[r].v) { n     tree[nod].v = tree[l].v; n     tree[nod].id = tree[l].id; n   } else { n     tree[nod].v = tree[r].v; n     tree[nod].id = tree[r].id; n   } n } n pair<int, int> query(int nod, int s, int e, int i, int j) { n   if (s > j || e < i) return {-1, -1}; n   if (s >= i && e <= j) return {tree[nod].v, tree[nod].id}; n   int mid = (s + e) / 2, l = 2 * nod, r = l + 1; n   pair<int, int> a = query(l, s, mid, i, j); n   pair<int, int> b = query(r, mid + 1, e, i, j); n   if (a.first > b.first) n     return a; n   else n     return b; n } n long long save[100005]; n long long ans[100005]; n int main() { n   int n, i; n   scanf( %d , &n); n   for (i = 1; i < n; i++) { n     scanf( %d , &in[i]); n   } n   build(1, 1, n); n   save[n - 1] = 1; n   ans[n - 1] = 1; n   pair<int, int> a = query(1, 1, n, 6, 8); n   for (i = n - 2; i >= 1; i--) { n     pair<int, int> pp = query(1, 1, n, i + 1, in[i]); n     save[i] = pp.second - i + save[pp.second] + n - in[i]; n     ans[i] = ans[i + 1] + save[i]; n   } n   printf( %I64d n , ans[1]); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void checkmin(T &a, const T &b) { n   if (b < a) a = b; n } n template <class T> n inline void checkmax(T &a, const T &b) { n   if (b > a) a = b; n } n const int maxn = 1e3 + 10; n const int inf = 1e9 + 10; n const long long mod = 1e9 + 7; n int dp[maxn][maxn][4], g[maxn]; n int n, k; n long long fac[maxn], c[maxn][maxn]; n int main() { n   scanf( %d%d , &n, &k); n   dp[0][0][2] = 1; n   for (int i = 0; i < n; i++) n     for (int j = 0; j <= n; j++) n       for (int mask = 0; mask < 4; mask++) { n         if (dp[i][j][mask] == 0) continue; n         int mask2 = (mask & 1) << 1; n         dp[i + 1][j][mask2] += dp[i][j][mask]; n         dp[i + 1][j][mask2] %= mod; n         if (!((mask >> 1) & 1)) n           dp[i + 1][j + 1][mask2] += dp[i][j][mask], n               dp[i + 1][j + 1][mask2] %= mod; n         if (i == n - 1) continue; n         mask2 |= 1; n         dp[i + 1][j + 1][mask2] += dp[i][j][mask]; n         dp[i + 1][j + 1][mask2] %= mod; n       } n   fac[0] = 1; n   for (long long i = 1; i < maxn; i++) fac[i] = fac[i - 1] * i % mod; n   for (int i = k; i <= n; i++) { n     long long now = 0; n     for (int mask = 0; mask < 4; mask++) now += dp[n][i][mask], now %= mod; n     g[i] = now * fac[n - i] % mod; n   } n   c[0][0] = 1; n   for (int i = 1; i < maxn; i++) { n     c[i][0] = 1; n     for (int j = 1; j <= i; j++) n       c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod; n   } n   long long ans = 0; n   for (int i = k; i <= n; i++) { n     if ((i - k) & 1) n       ans -= c[i][k] * g[i] % mod, ans += mod; n     else n       ans += c[i][k] * g[i] % mod; n     ans %= mod; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxint = -1u >> 1; n template <class T> n bool get_max(T& a, const T& b) { n   return b > a ? a = b, 1 : 0; n } n template <class T> n bool get_min(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n const int maxn = 1000000 + 5; n int n, m, r1, r2, sv[maxn]; n void output() { n   for (int i = n; i >= 0; i--) { n     for (int j = 0; j < sv[i]; j++) { n       printf( 7 ); n     } n     if (i) printf( 4 ); n   } n   printf(  n ); n } n int main() { n   scanf( %d%d%d%d , &n, &m, &r1, &r2); n   memset(sv, 0, sizeof(sv)); n   for (int i = 1; i < n; i++) { n     if (r1 && r2) { n       if (!m) { n         printf( -1 n ); n         return 0; n       } else { n         r1--; n         r2--; n         sv[i]++; n         m--; n       } n     } n   } n   if (r1) { n     if (!m) { n       printf( -1 n ); n       return 0; n     } else { n       r1--; n       sv[0]++; n       m--; n     } n   } n   if (r2) { n     if (!m) { n       printf( -1 n ); n       return 0; n     } else { n       r2--; n       sv[n]++; n       m--; n     } n   } n   if (r1 + r2 != 0) { n     printf( -1 n ); n     return 0; n   } n   if (sv[0]) { n     sv[0] += m; n   } else { n     sv[1] += m; n   } n   output(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n long long a[maxn], b[maxn]; n int main() { n   int n, m; n   cin >> n >> m; n   int t; n   long long sum_n = 0, sum_m = 0; n   long long cnt_n = 0, cnt_m = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < m; i++) { n     cin >> b[i]; n   } n   sum_n = accumulate(a, a + n, 0LL); n   sum_m = accumulate(b, b + m, 0LL); n   sort(a, a + n); n   sort(b, b + m); n   for (int i = 0; i < n; i++) { n     if (a[i] < sum_m && i < n - 1) { n       cnt_n += a[i]; n     } else { n       cnt_n += sum_m; n     } n   } n   for (int i = 0; i < m; i++) { n     if (b[i] < sum_n && i < m - 1) { n       cnt_m += b[i]; n     } else { n       cnt_m += sum_n; n     } n   } n   printf( %lld n , min(cnt_n, cnt_m)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 2.0 * acos(0.0); n const double EPS = 1e-6; n int a[455]; n int b[455]; n vector<int> G[455]; n int boss[455]; n void init() { n   for (int i = 1; i < 455; i++) boss[i] = i; n } n int find_boss(int x) { n   return boss[x] = (boss[x] == x ? x : find_boss(boss[x])); n } n bool unite(int x, int y) { n   int bx = find_boss(x); n   int by = find_boss(y); n   if (bx == by) return false; n   boss[bx] = by; n   return true; n } n vector<pair<pair<int, int>, int> > res; n int pour(int from, int to, int d) { n   int flow = min(d, max(a[to] - b[to], 0)); n   a[to] -= flow; n   int pos = ((int)(res).size()); n   for (int i = 0; flow < d && i < ((int)(G[to]).size()); i++) { n     int v = G[to][i]; n     if (v == from) continue; n     flow += pour(to, v, d - flow); n   } n   if (from != -1) { n     int po = min(a[to], flow); n     if (po > 0) n       res.insert(res.begin() + pos, make_pair(make_pair(to, from), po)); n     if (po < flow) res.push_back(make_pair(make_pair(to, from), flow - po)); n   } n   return flow; n } n int main() { n   int n, v, e; n   scanf( %d %d %d , &n, &v, &e); n   for (int i = 1; i <= n; i++) scanf( %d , a + i); n   for (int i = 1; i <= n; i++) scanf( %d , b + i); n   init(); n   while (e--) { n     int x, y; n     scanf( %d %d , &x, &y); n     if (unite(x, y)) { n       G[x].push_back(y); n       G[y].push_back(x); n     } n   } n   for (int i = 1; i <= n; i++) n     if (a[i] < b[i]) a[i] += pour(-1, i, b[i] - a[i]); n   for (int i = 1; i <= n; i++) n     if (a[i] != b[i]) return puts( NO ), 0; n   printf( %d n , ((int)(res).size())); n   for (__typeof((res).begin()) itr = (res).begin(); itr != (res).end(); itr++) n     printf( %d %d %d n , itr->first.first, itr->first.second, itr->second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double t0; n double error(long long t1, long long t2, long long x1, long long x2) { n   double c = (t1 * x1 + t2 * x2) / double(x1 + x2); n   if (c >= t0) return c - t0; n   return 1e9; n } n int main() { n   long long t1, t2, x1, x2; n   cin >> t1 >> t2 >> x1 >> x2 >> t0; n   double ER = 1e8; n   long long a1 = -1, a2 = -1; n   for (int y1 = 0; y1 <= x1; y1++) { n     long long mi = (t0 != t2) ? (t1 * y1 - t0 * y1) / (t0 - t2) : 1000000000; n     for (long long y2 = min(max(mi - 10, 0LL), x2); n          y2 <= max(min(mi + 10, x2), 0LL); ++y2) { n       if (y1 == 0 && y2 == 0) continue; n       double calc = error(t1, t2, y1, y2); n       if (ER > calc) { n         ER = calc; n         a1 = y1; n         a2 = y2; n       } else if (ER == calc) { n         if (a1 + a2 < y1 + y2) a1 = y1, a2 = y2; n       } n     } n   } n   cout << a1 <<     << a2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n ll A[19], cnt, dp[19][4][3][2][2][504][2]; n const int p3[]{1, 3, 9}; n ll dfs(int pos, int level2, int level3, int level5, int level7, int sum, n        bool limit) { n   ll ans = 0; n   if (dp[pos][level2][level3][level5][level7][sum][limit] != -1) n     return dp[pos][level2][level3][level5][level7][sum][limit]; n   for (int v = 0; v <= (limit ? A[pos] : 9); ++v) { n     int l2 = level2, l3 = level3, l5 = level5, l7 = level7; n     int cur = (sum * 10 + v) % 504; n     if (v == 2) l2 = max(l2, 1); n     if (v == 3) l3 = max(l3, 1); n     if (v == 4) l2 = max(l2, 2); n     if (v == 5) l5 = 1; n     if (v == 6) l2 = max(l2, 1), l3 = max(l3, 1); n     if (v == 7) l7 = 1; n     if (v == 8) l2 = 3; n     if (v == 9) l3 = 2; n     if (pos == cnt - 1) n       ans += cur % (1 << l2) == 0 && cur % p3[l3] == 0 && n              cur % (l7 ? 7 : 1) == 0 && (!l5 || v == 5 || v == 0); n     else n       ans += dfs(pos + 1, l2, l3, l5, l7, cur, limit && v == A[pos]); n   } n   if (!limit) dp[pos][level2][level3][level5][level7][sum][limit] = ans; n   return ans; n } n ll f(ll x) { n   if (x == 0) return 1; n   cnt = 0; n   while (x) A[cnt++] = x % 10, x /= 10; n   reverse(A, A + cnt); n   memset(dp, -1, sizeof(dp)); n   return dfs(0, 0, 0, 0, 0, 0, true); n } n int main() { n   ios::sync_with_stdio(false); n   int t; n   cin >> t; n   while (t--) { n     ll x, y; n     cin >> x >> y; n     ll l = f(x - 1), r = f(y); n     cout << r - l <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1100; n char str[N]; n int G[N][N]; n int sum_r[N], sum_c[N]; n int n, m; n bool vis[N][N]; n bool no() { n   int r0 = n, c0 = m; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       sum_r[i] += G[i][j]; n     } n     if (sum_r[i]) r0--; n   } n   for (int j = 1; j <= m; j++) { n     for (int i = 1; i <= n; i++) { n       sum_c[j] += G[i][j]; n     } n     if (sum_c[j]) c0--; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (G[i][j]) { n         int k = j; n         while (k <= m && G[i][k]) k++; n         if (k - j != sum_r[i]) return true; n         break; n       } n     } n   } n   for (int j = 1; j <= m; j++) { n     for (int i = 1; i <= n; i++) { n       if (G[i][j]) { n         int k = i; n         while (k <= n && G[k][j]) k++; n         if (k - i != sum_c[j]) return true; n         break; n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     if (sum_r[i] == 0) { n       if (c0 == 0) return true; n     } n   } n   for (int j = 1; j <= m; j++) { n     if (sum_c[j] == 0) { n       if (r0 == 0) return true; n     } n   } n   return false; n } n vector<pair<int, int> > dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; n void dfs(int x, int y) { n   vis[x][y] = 1; n   for (auto [dx, dy] : dir) { n     int nx = x + dx, ny = y + dy; n     if (vis[nx][ny]) continue; n     if (G[nx][ny] && 0 < nx && nx <= n && 0 < ny && ny <= m) dfs(nx, ny); n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %s , str + 1); n     for (int j = 1; j <= m; j++) { n       G[i][j] = str[j] ==  #  ? 1 : 0; n     } n   } n   if (no()) { n     puts( -1 ); n     return 0; n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (G[i][j] && !vis[i][j]) { n         dfs(i, j); n         ans++; n       } n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   stack<int> q; n   string str; n   cin >> str; n   int open = 0, count = 0, rcount = 0; n   for (int i = 0; i < str.length(); ++i) { n     if (str[i] ==  ( ) n       open++; n     else if (str[i] ==  ) ) { n       if (open != 0) n         open--; n       else n         count--; n     } n     if (str[i] ==  # ) { n       count += open - 1; n       open = 0; n       rcount++; n     } n     if (count < 0) { n       cout << -1; n       return 0; n     } n   } n   if (open > 0) { n     cout << -1; n     return 0; n   } n   for (int i = 0; i < rcount - 1; i++) cout <<  1  ; n   cout << count + 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:102400000,102400000 ) n const int MOD = 1e9 + 7; n const int N = 1e5 + 7; n int n, m, x, L, R; n long long pre[N][6]; n long long sum[N << 2][6]; n int laz[N << 2]; n inline void pushup(int rt) { n   for (int i = int(0); i <= int(5); ++i) n     sum[rt][i] = sum[rt << 1][i] + sum[rt << 1 | 1][i], sum[rt][i] %= MOD; n } n inline void pushdown(int rt, int l, int r) { n   if (laz[rt] != -1) { n     int m = (l + r) >> 1; n     for (int i = int(0); i <= int(5); ++i) { n       sum[rt << 1][i] = n           ((pre[m][i] - pre[l - 1][i]) % MOD + MOD) % MOD * laz[rt] % MOD; n       sum[rt << 1 | 1][i] = n           ((pre[r][i] - pre[m][i]) % MOD + MOD) % MOD * laz[rt] % MOD; n     } n     laz[rt << 1] = laz[rt << 1 | 1] = laz[rt]; n     laz[rt] = -1; n   } n } n void build(int rt, int l, int r) { n   laz[rt] = -1; n   if (l == r) { n     scanf( %d , &x); n     sum[rt][0] = (long long)x; n     for (int i = int(1); i <= int(5); ++i) n       sum[rt][i] = sum[rt][i - 1] * l % MOD; n     return; n   } n   int m = (l + r) >> 1; n   build(rt << 1, l, m); n   build(rt << 1 | 1, m + 1, r); n   pushup(rt); n } n void setv(int rt, int l, int r) { n   if (L <= l && r <= R) { n     laz[rt] = x; n     for (int i = int(0); i <= int(5); ++i) { n       sum[rt][i] = ((pre[r][i] - pre[l - 1][i]) % MOD + MOD) % MOD * x % MOD; n     } n     return; n   } n   pushdown(rt, l, r); n   int m = (l + r) >> 1; n   if (L <= m) setv(rt << 1, l, m); n   if (R > m) setv(rt << 1 | 1, m + 1, r); n   pushup(rt); n } n long long query(int d, int rt, int l, int r) { n   if (L <= l && r <= R) { n     return sum[rt][d]; n   } n   pushdown(rt, l, r); n   int m = (l + r) >> 1; n   long long ret = 0; n   if (L <= m) ret += query(d, rt << 1, l, m); n   if (R > m) ret += query(d, rt << 1 | 1, m + 1, r); n   ret %= MOD; n   pushup(rt); n   return ret; n } n long long solve() { n   long long ret; n   long long u = (long long)L - 1; n   if (x == 0) ret = query(0, 1, 1, n); n   if (x == 1) { n     ret = query(1, 1, 1, n) - u * query(0, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n     return ret; n   } n   if (x == 2) { n     ret = query(2, 1, 1, n) - 2LL * u * query(1, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n     ret = ret + (long long)u * u % MOD * query(0, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n   } n   if (x == 3) { n     ret = query(3, 1, 1, n) - 3LL * u * query(2, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n     ret = ret + 3LL * u * u % MOD * query(1, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n     ret = ret - u * u % MOD * u % MOD * query(0, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n   } n   if (x == 4) { n     ret = query(4, 1, 1, n) - 4LL * u * query(3, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n     ret = ret + 6LL * u * u % MOD * query(2, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n     ret = ret - 4LL * u * u % MOD * u % MOD * query(1, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n     ret = ret + u * u % MOD * u % MOD * u % MOD * query(0, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n   } n   if (x == 5) { n     ret = query(5, 1, 1, n) - 5LL * u * query(4, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n     ret = ret + 10LL * u * u % MOD * query(3, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n     ret = ret - 10LL * u * u % MOD * u % MOD * query(2, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n     ret = ret + 5LL * u * u % MOD * u % MOD * u % MOD * query(1, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n     ret = ret - n           u * u % MOD * u % MOD * u % MOD * u % MOD * query(0, 1, 1, n) % MOD; n     ret = (ret % MOD + MOD) % MOD; n   } n   return ret; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = int(1); i <= int(n); ++i) { n     long long t = 1; n     for (int j = int(0); j <= int(5); ++j) { n       pre[i][j] = pre[i - 1][j] + t, pre[i][j] %= MOD; n       t = t * i % MOD; n     } n   } n   build(1, 1, n); n   char s[5]; n   for (int i = int(1); i <= int(m); ++i) { n     scanf( %s%d%d%d , s, &L, &R, &x); n     if (s[0] ==  = ) { n       setv(1, 1, n); n     } else { n       printf( %I64d n , solve()); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int N = int(2.1e5); n vector<pair<int, int>> g[N]; n int n, q; n ll res = 0; n class dsu { n  public: n   using T = int; n   vector<int> p; n   vector<ll> sz; n   int n; n   dsu(int _n) : n(_n) { n     p.resize(n); n     sz.resize(n); n     iota(p.begin(), p.end(), 0); n     fill(sz.begin(), sz.end(), 1); n   } n   inline T get(T x) { return (x == p[x] ? x : (p[x] = get(p[x]))); } n   inline bool unite(T x, T y) { n     T px = get(x); n     T py = get(y); n     if (px != py) { n       if (sz[px] < sz[py]) { n         swap(px, py); n       } n       p[py] = px; n       res -= (sz[px] * (sz[px] - 1)) / 2; n       res -= (sz[py] * (sz[py] - 1)) / 2; n       sz[px] += sz[py]; n       res += (sz[px] * (sz[px] - 1)) / 2; n       return true; n     } n     return false; n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n >> q; n   vector<pair<int, pair<int, int>>> ed(n - 1); n   for (int i = 0; i < n - 1; ++i) { n     int u, v, w; n     cin >> u >> v >> w; n     u--, v--; n     ed[i] = {w, {u, v}}; n   } n   sort(ed.begin(), ed.end()); n   vector<pair<int, int>> qr(q); n   for (int i = 0; i < q; ++i) { n     int x; n     cin >> x; n     qr[i] = {x, i}; n   } n   sort(qr.begin(), qr.end()); n   vector<ll> ans(q); n   int j = 0; n   dsu d(n + 1); n   for (int i = 0; i < q; ++i) { n     while (j < n - 1 && ed[j].first <= qr[i].first) { n       d.unite(ed[j].second.first, ed[j].second.second); n       j++; n     } n     ans[qr[i].second] = res; n   } n   for (ll x : ans) { n     cout << x <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   k = min(k, 26); n   string s =  ab ; n   for (int i = 0; i < k - 2; i++) { n     s += char(99 + i); n   } n   string s1 =   ; n   for (int i = 0; i < n / k; i++) { n     s1 += s; n   } n   for (int i = 0; i < n % k; i++) { n     s1 = s1 + s[i]; n   } n   cout << s1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef struct node { n   struct node* b[3]; n   int flag[3]; n } node; n node* root; n vector<int> ans; n int bit[32], bit_n[32]; n void calc(int u) { n   memset(bit_n, 0, sizeof(bit_n)); n   memset(bit, 0, sizeof(bit)); n   int j = 0, num; n   for (num = u; num > 0; num = num / 2) bit_n[j++] = num % 2; n   for (int i = 0; i < 32; i++) bit[i] = bit_n[31 - i]; n } n void insert(int u) { n   node* head; n   head = root; n   calc(u); n   for (int i = 0; i < 32; i++) { n     if (head->b[bit[i]] == NULL) { n       node* temp; n       temp = (node*)malloc(sizeof(node)); n       for (int j = 0; j < 3; j++) temp->b[j] = NULL, temp->flag[j] = 0; n       head->b[bit[i]] = temp; n     } n     head->flag[bit[i]]++; n     head = head->b[bit[i]]; n   } n   return; n } n void del(int u) { n   node* head; n   head = root; n   calc(u); n   for (int i = 0; i < 32; i++) { n     head->flag[bit[i]]--; n     head = head->b[bit[i]]; n   } n   return; n } n void search(int u) { n   calc(u); n   node* head; n   head = root; n   for (int i = 0; i < 32; i++) { n     if (bit[i] == 1) { n       if (head->flag[0]) n         ans.push_back(1), head = head->b[0]; n       else n         ans.push_back(0), head = head->b[1]; n     } else { n       if (head->flag[1]) n         ans.push_back(1), head = head->b[1]; n       else n         ans.push_back(0), head = head->b[0]; n     } n   } n } n int main() { n   root = (node*)malloc(sizeof(node)); n   for (int i = 0; i < 3; i++) root->b[i] = NULL, root->flag[i] = 0; n   int n; n   cin >> n; n   insert(0); n   char a; n   int num; n   for (int i = 0; i < n; i++) { n     int calc = 0; n     cin >> a >> num; n     if (a ==  + ) n       insert(num); n     else if (a ==  - ) n       del(num); n     else { n       ans.clear(); n       search(num); n       for (int i = 0; i < ans.size(); i++) calc += (pow(2, 31 - i) * ans[i]); n       cout << calc <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = -1; n   for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ; n   return x * f; n } n int n, k, a[201010]; n long long f[201010][2]; n long long power(long long x, long long p) { n   long long res = 1; n   while (p) { n     if (p & 1) res = res * x % 998244353; n     x = x * x % 998244353; n     p >>= 1; n   } n   return res; n } n long long dp(int l, int r, int len) { n   if (len == 0) { n     if (l == r && l != 0 && r != 0) return 0; n     return 1; n   } n   if (r == 0) { n     return (l == 0 ? k : (k - 1)) * power(k - 1, len - 1) % 998244353; n   } n   for (int i = 0; i <= len; i++) f[i][0] = f[i][1] = 0; n   if (l == 0) n     f[0][0] = k - 1, f[0][1] = 1, len--; n   else if (l == r) n     f[0][1] = 1; n   else n     f[0][0] = 1; n   for (int i = 1; i <= len; i++) { n     f[i][0] = n         (f[i][0] + f[i - 1][0] * (k - 2) + f[i - 1][1] * (k - 1)) % 998244353; n     f[i][1] = f[i - 1][0]; n   } n   return f[len][0]; n } n int main() { n   n = read(), k = read(); n   long long ans = 1; n   for (int i = 1; i <= n; i++) a[i] = read(); n   int lst = -1; n   for (int i = 1; i <= n + 2; i += 2) n     if (a[i] != -1) n       ans = ans * dp(a[lst], a[i], (i - lst) / 2 - 1) % 998244353, lst = i; n   lst = 0; n   for (int i = 2; i <= n + 2; i += 2) n     if (a[i] != -1) n       ans = ans * dp(a[lst], a[i], (i - lst) / 2 - 1) % 998244353, lst = i; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e6 + 10; n const long long mod = 1e9 + 7; n struct Dsu { n   long long fa[N << 1], d[N << 1]; n   struct Tmp { n     long long x, y, add; n   }; n   stack<Tmp> s; n   long long find(long long x) { n     while (x != fa[x]) x = fa[x]; n     return x; n   } n   void init(long long n) { n     while (!s.empty()) s.pop(); n     for (long long i = 1; i <= n; i++) fa[i] = i, d[i] = 0; n   } n   void merge(long long x, long long y) { n     long long xx = find(x); n     long long yy = find(y); n     if (xx == yy) return; n     if (d[xx] > d[yy]) swap(xx, yy); n     s.push((Tmp){xx, yy, d[xx] == d[yy]}); n     fa[xx] = yy; n     d[yy] += (d[xx] == d[yy]); n   } n   void ret(long long o) { n     while (s.size() > o) { n       Tmp x = s.top(); n       fa[x.x] = x.x; n       d[x.y] -= x.add; n       s.pop(); n     } n   } n } t; n long long read() { n   long long x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) x = (x << 1) + (x << 3) + c -  0 , c = getchar(); n   return x * f; n } n long long c[N]; n map<pair<long long, long long>, vector<pair<long long, long long>>> mp; n int main() { n   long long n = read(), m = read(), k = read(); n   for (long long i = 1; i <= n; i++) c[i] = read(); n   vector<pair<long long, long long>> e(m + 1); n   t.init(2 * n); n   for (long long i = 1; i <= m; i++) e[i].first = read(), e[i].second = read(); n   vector<long long> z(k + 1); n   for (long long i = 1; i <= m; i++) { n     long long u = e[i].first, v = e[i].second; n     if (c[u] == c[v]) { n       long long x = t.find(u); n       long long y = t.find(v); n       if (x == y) { n         z[c[u]] = 1; n       } else { n         t.merge(u, v + n); n         t.merge(u + n, v); n       } n     } else { n       pair<long long, long long> tmp = {min(c[u], c[v]), max(c[v], c[u])}; n       mp[tmp].push_back({u, v}); n     } n   } n   long long res = 1ll * k * (k - 1) / 2; n   long long gg = 0; n   for (long long i = 1; i <= k; i++) n     if (z[i] == 1) gg++; n   res -= (gg) * (gg - 1) / 2 + gg * (k - gg); n   for (auto now : mp) { n     if (z[now.first.first] || z[now.first.second]) continue; n     auto tmp = now.second; n     long long o = t.s.size(); n     for (pair<long long, long long> qwq : tmp) { n       long long u = qwq.first; n       long long v = qwq.second; n       long long x = t.find(u); n       long long y = t.find(v); n       if (x == y) { n         res -= 1; n         break; n       } else { n         t.merge(u, v + n); n         t.merge(u + n, v); n       } n     } n     t.ret(o); n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n #pragma GCC target( avx2 ) n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n const long long int inf = 1e18; n const long long int ninf = -1e18; n const long long int mod = 1000000007; n const long long int MOD = 998244353; n template <typename T> n bool asc(pair<T, T> &a, pair<T, T> &b) { n   if (a.first == b.first) { n     return a.second < b.second; n   } n   return a.first < b.first; n } n template <typename T> n bool desc(pair<T, T> &a, pair<T, T> &b) { n   if (a.first == b.first) { n     return a.second > b.second; n   } n   return a.first > b.first; n } n template <typename T> n T power(T a, T b) { n   if (b == 0) return 1; n   if (b == 1) n     return a; n   else { n     T res = (power(a, b / 2)); n     if (b % 2) { n       return (res * res * a); n     } else { n       return res * res; n     } n   } n } n template <typename T> n T power(T a, T b, T modulo) { n   if (b == 0) return 1; n   if (b == 1) n     return a; n   else { n     T res = (power(a, b / 2, modulo) % modulo); n     if (b % 2) { n       return ((((res % modulo) * (res % modulo)) % modulo) * (a % modulo)) % n              modulo; n     } else { n       return ((res % modulo) * (res % modulo)) % modulo; n     } n   } n } n template <typename T> n T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <typename T> n T lcm(T p, T q) { n   return (p * q) / gcd<T>(p, q); n } n template <typename T> n void primefactorise(T n, vector<T> &vec) { n   while (n % 2 == 0) { n     vec.emplace_back(2); n     n = n / 2; n   } n   for (int i = 3; i <= sqrt(n); i = i + 2) { n     while (n % i == 0) { n       vec.emplace_back(i); n       n = n / i; n     } n   } n   if (n > 2) { n     vec.emplace_back(n); n   } n } n template <typename T> n void all_factor(T n, vector<T> &vec) { n   for (auto i = 1; i <= sqrt(n); ++i) { n     if (n % i == 0) { n       vec.emplace_back(i); n       if (i != (n / i)) { n         vec.emplace_back(n / i); n       } n     } n   } n } n long long mulmod(long long a, long long b, long long c) { n   if (b == 0) { n     return 0; n   } n   long long s = mulmod(a, b / 2, c); n   if (b % 2 == 1) { n     long long p = (a % c + 2 * (s % c)) % c; n     return p; n   } else { n     long long p = (2 * (s % c)) % c; n     return p; n   } n } n long long mod_inv(long long a) { n   return (power<long long>(a, mod - 2, mod)) % mod; n } n void factorial(long long n, vector<long long int> fact) { n   fact.resize(n + 1, 1); n   fact[0] = 1; n   fact[1] = 1; n   for (int i = 2; i <= n; ++i) { n     fact[i] = ((fact[i - 1] % mod) * (i % mod)) % mod; n   } n } n int main() { n   std::chrono::time_point<std::chrono::high_resolution_clock> start_timer, n       end_timer; n   start_timer = std::chrono::high_resolution_clock::now(); n   bool show_time = false; n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   long long n; n   cin >> n; n   if (n == 1) { n     cout << ((1)) <<   n ; n     ; n   } else if (n == 2) { n     cout << ((2)) <<   n ; n     ; n   } else if (n == 3) { n     cout << ((6)) <<   n ; n     ; n   } else if (n % 2) { n     cout << (((n * (n - 1) * (n - 2)))) <<   n ; n     ; n   } else n     cout << (((max((((n - 3) * (n - 1) * (n - 2))) / n                        (gcd<long long>(n - 1, n - 2) * n                         gcd<long long>(n - 1, n - 3) * n                         gcd<long long>(n - 3, n - 2)), n                    (((n) * (n - 1) * (n - 3))) / n                        (gcd<long long>(n - 1, n - 3) * n                         gcd<long long>(n, n - 3) * gcd<long long>(n, n - 1)))))) n          <<   n ; n   ; n   end_timer = std::chrono::high_resolution_clock::now(); n   long long elapsed_time = n       std::chrono::duration_cast<std::chrono::milliseconds>(end_timer - n                                                             start_timer) n           .count(); n   if (show_time) { n     cout <<   nElapsed Time:   << elapsed_time <<  ms n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, ed[26][26] = {}, pos[26][26] = {}; n   static char s[200100], t[200100]; n   scanf( %d%s%s , &n, s, t); n   int ans = 0; n   for (int i = 0; i < (n); ++i) { n     ans += s[i] != t[i]; n     ed[s[i] -  a ][t[i] -  a ] += 1; n     pos[s[i] -  a ][t[i] -  a ] = i + 1; n   } n   for (int i = 0; i < (26); ++i) { n     for (int j = 0; j < (i); ++j) { n       if (ed[j][i] && ed[i][j]) { n         printf( %d n%d %d n , ans - 2, pos[j][i], pos[i][j]); n         return 0; n       } n     } n   } n   for (int i = 0; i < (26); ++i) { n     for (int j = 0; j < (26); ++j) { n       if (j == i) continue; n       if (!ed[i][j]) continue; n       for (int k = 0; k < (26); ++k) { n         if (k != j && ed[j][k]) { n           printf( %d n%d %d n , ans - 1, pos[i][j], pos[j][k]); n           return 0; n         } n       } n     } n   } n   printf( %d n%d %d n , ans, -1, -1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int readInt() { n   int a; n   scanf( %d , &a); n   return a; n } n long long readLong() { n   long long a; n   scanf( %lld , &a); n   return a; n } n void readString(char *s) { scanf(  %s , s); } n const int N = 100005; n char s[N]; n vector<pair<int, int>> comp; n int f[26]; n int dp[N]; n void solve() { n   int n = readInt(); n   int m = readInt(); n   readString(s + 1); n   int last = 1; n   for (int i = (1); i <= (n); ++i) { n     if (s[i] != s[i + 1]) { n       comp.emplace_back(s[i] -  a , i - last + 1); n       last = i + 1; n     } n     f[s[i] -  a ]++; n   } n   long long ans = (int)(comp).size() * (n * 1ll * m - n); n   dp[1] = 1; n   for (int i = (2); i <= (n); ++i) { n     if (s[i] != s[i - 1] && s[i] == s[i - 2]) n       dp[i] = 1 + dp[i - 1]; n     else if (s[i] != s[i - 1]) n       dp[i] = 2; n     else n       dp[i] = 1; n     ans -= dp[i] - 1; n   } n   printf( %lld , ans); n } n int main() { n   int t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, a, d; n   long long t, v; n   double prev = 0; n   scanf( %I64d%I64d%I64d , &n, &a, &d); n   for (int i = 1; i <= n; i++) { n     scanf( %I64d%I64d , &t, &v); n     double tt = sqrt((2 * d) / (a * 1.0)); n     if (tt * a > v) { n       tt = v / (a * 1.0) + (d - v * v / (2 * a * 1.0)) / v; n     } n     tt += t; n     if (tt < prev) tt = prev; n     printf( %.8lf n , tt); n     prev = tt; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long double x1, x2, y, y2, r1, r2, ab, s = 0, al, be; n const long double pi = acos(-1); n void inp() { n   cin >> x1 >> y >> r1; n   cin >> x2 >> y2 >> r2; n   ab = sqrt((x1 - x2) * (x1 - x2) + (y - y2) * (y - y2)); n } n void out() { n   if (ab >= (r1 + r2)) { n     cout << fixed << setprecision(20) << s; n   } else if (ab <= abs(r1 - r2)) { n     if (r1 < r2) { n       cout << fixed << setprecision(20) << r1 * r1 * pi; n     } else { n       cout << fixed << setprecision(20) << r2 * r2 * pi; n     } n   } else { n     al = 2.0 * acos((ab * ab - r1 * r1 + r2 * r2) / (2.0 * ab * r2)); n     be = 2.0 * acos((ab * ab - r2 * r2 + r1 * r1) / (2.0 * ab * r1)); n     s = be * r1 * r1 - r1 * r1 * sin(be) + al * r2 * r2 - r2 * r2 * sin(al); n     s = s / 2.0; n     cout << fixed << setprecision(20) << s; n   } n } n int main() { n   inp(); n   out(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[2][100100]; n int visit[100100]; n int v[100100]; n int main() { n   int i, j; n   int n, m; n   while (scanf( %d %d , &n, &m) != EOF) { n     memset(dp, 0, sizeof(dp)); n     for (i = 1; i <= n; i++) { n       scanf( %d , &v[i]); n       if (v[i] < 0) { n         dp[0][-v[i]]++; n         dp[0][0]++; n       } else { n         dp[1][v[i]]++; n         dp[1][0]++; n       } n     } n     memset(visit, 0, sizeof(visit)); n     int flag = 0; n     for (i = 1; i <= n; i++) { n       if (dp[1][i] + dp[0][0] - dp[0][i] == m) { n         visit[i] += 1; n         flag++; n       } n     } n     for (i = 1; i <= n; i++) { n       int now = v[i]; n       if (now < 0) now = 0 - now; n       if (v[i] > 0) { n         if (visit[v[i]] != 1) n           printf( Lie n ); n         else if (flag == 1) n           printf( Truth n ); n         else n           printf( Not defined n ); n       } else { n         if (visit[-v[i]] == 0) n           printf( Truth n ); n         else if (flag == 1) n           printf( Lie n ); n         else n           printf( Not defined n ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   if (n <= m && n <= k) { n     cout <<  Yes ; n   } else { n     cout <<  No ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 4; n int n, q, A[N], P[N], R[N], res[N], S[N * 2]; n map<int, int> M; n vector<int> Q[N]; n inline void Add(int le, int ri, int val) { n   le--; n   ri--; n   for (le += n, ri += n; le < ri; le >>= 1, ri >>= 1) { n     if (le & 1) S[le++] ^= val; n     if (ri & 1) S[--ri] ^= val; n   } n } n inline int Get(int i) { n   int ret = 0; n   for (i--, i += n; i; i >>= 1) ret ^= S[i]; n   return (ret); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &A[i]), P[i] = (P[i - 1] ^ A[i]); n   scanf( %d , &q); n   for (int i = 1, l; i <= q; i++) n     scanf( %d%d , &l, &R[i]), Q[l].push_back(i), res[i] = (P[R[i]] ^ P[l - 1]); n   for (int i = 1; i <= n; i++) M[A[i]] = n + 1; n   for (int i = n; i; i--) { n     Add(i, M[A[i]], A[i]); n     for (int &id : Q[i]) res[id] ^= Get(R[id]); n     M[A[i]] = i; n   } n   for (int i = 1; i <= q; i++) printf( %d n , res[i]); n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, l, x, y; n   set<long long> Set; n   while (cin >> n >> l >> x >> y) { n     for (int i = 1; i <= n; ++i) { n       long long t; n       scanf( %I64d , &t); n       Set.insert(t); n     } n     bool checkx = 0; n     bool checky = 0; n     for (set<long long>::iterator it = Set.begin(); it != Set.end(); it++) { n       if (Set.find(*it + x) != Set.end()) { n         checkx = 1; n       } n       if (Set.find(*it + y) != Set.end()) { n         checky = 1; n       } n       if (checkx && checky) { n         break; n       } n     } n     if (checkx && checky) { n       cout << 0 << endl; n       break; n     } n     if (checkx) { n       cout << 1 << endl; n       cout << y << endl; n       break; n     } n     if (checky) { n       cout << 1 << endl; n       cout << x << endl; n       break; n     } n     bool find = 0; n     long long ans = 0; n     for (set<long long>::iterator it = Set.begin(); it != Set.end(); it++) { n       if ((*it + x <= l) && Set.find(*it + x + y) != Set.end()) { n         find = 1; n         ans = *it + x; n         break; n       } n       if ((*it + x <= l) && Set.find(*it + x - y) != Set.end()) { n         find = 1; n         ans = *it + x; n         break; n       } n       if ((*it - x >= 0) && Set.find(*it - x + y) != Set.end()) { n         find = 1; n         ans = *it - x; n         break; n       } n       if ((*it - x >= 0) && Set.find(*it - x - y) != Set.end()) { n         find = 1; n         ans = *it - x; n         break; n       } n     } n     if (find) { n       cout << 1 << endl; n       cout << ans << endl; n       break; n     } n     cout << 2 << endl; n     cout << x <<     << y << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     cin >> N; n     printf( %d n , (N > 2 ? N - 2 : 0)); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n constexpr long long MOD = 1000000007LL; n template <class T> n inline bool chmax(T &a, T b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n template <class T> n inline bool chmin(T &a, T b) { n   if (a > b) { n     a = b; n     return true; n   } n   return false; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int N, M, K, S; n   cin >> N >> M >> K >> S; n   vector<pair<long long, long long> > A(N), B(N), C, D; n   for (int i = 0; i < (N); ++i) cin >> A[i].first; n   for (int i = 0; i < (N); ++i) cin >> B[i].first; n   for (int i = 0; i < (M); ++i) { n     int com, c; n     cin >> com >> c; n     if (com == 1) n       C.emplace_back(c, i); n     else n       D.emplace_back(c, i); n   } n   for (int i = 0; i < (N); ++i) A[i].second = B[i].second = i; n   sort((C).begin(), (C).end()); n   sort((D).begin(), (D).end()); n   int P = C.size(); n   int Q = D.size(); n   vector<long long> E(P + 1), F(Q + 1); n   for (int i = 0; i < (P); ++i) { n     E[i + 1] = E[i] + C[i].first; n   } n   for (int i = 0; i < (Q); ++i) { n     F[i + 1] = F[i] + D[i].first; n   } n   vector<pair<long long, long long> > G(N), H(N); n   pair<long long, long long> p = {1e9, 1e9}, q = {1e9, 1e9}; n   for (int i = 0; i < (N); ++i) { n     chmin(p, A[i]); n     chmin(q, B[i]); n     G[i] = p; n     H[i] = q; n   } n   int ng = -1; n   int ok = N; n   while (ok - ng > 1) { n     int mid = (ng + ok) / 2; n     long long r = G[mid].first; n     long long s = H[mid].first; n     bool check = false; n     for (int i = 0; i <= K; ++i) { n       if (i > P || K - i > Q) continue; n       if (E[i] * r + F[K - i] * s <= S) check = true; n     } n     if (check) n       ok = mid; n     else n       ng = mid; n   } n   if (ok == N) n     cout << -1 <<   n ; n   else { n     cout << ok + 1 <<   n ; n     long long r = G[ok].first; n     long long s = H[ok].first; n     for (int i = 0; i <= K; ++i) { n       if (i > P || K - i > Q) continue; n       if (E[i] * r + F[K - i] * s <= S) { n         for (int j = 0; j < (i); ++j) { n           cout << C[j].second + 1 <<     << G[ok].second + 1 <<   n ; n         } n         for (int j = 0; j < (K - i); ++j) { n           cout << D[j].second + 1 <<     << H[ok].second + 1 <<   n ; n         } n         return 0; n       } n     } n   } n } n