#include <bits/stdc++.h> n using namespace std; n const int N = 160; n const int mod = 1e9 + 7; n int n, m, f[N][N][2][2], ans; n void inc(int& a, int b) { n   if (a += b, a >= mod) a -= mod; n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= m; ++i) n     for (int j = i; j <= m; ++j) { n       f[i][j][1][1] = 1; n     } n   for (int h = 1; h <= n; ++h) { n     int tot = 0; n     for (int i = 1; i <= m; ++i) n       for (int j = 1; j <= m; ++j) n         for (int kl = 0; kl <= 1; ++kl) n           for (int kr = 0; kr <= 1; ++kr) { n             inc(tot, f[i][j][kl][kr]); n           } n     inc(ans, (long long)tot * (n + 1 - h) % mod); n     if (h == n) break; n     for (int j = 1; j <= m; ++j) n       for (int i = 1; i < j; ++i) n         for (int kr = 0; kr <= 1; ++kr) { n           inc(f[i + 1][j][0][kr], (f[i][j][0][kr] + f[i][j][1][kr]) % mod); n         } n     for (int i = 1; i <= m; ++i) n       for (int j = m; j > i; --j) n         for (int kl = 0; kl <= 1; ++kl) { n           inc(f[i][j - 1][kl][0], (f[i][j][kl][0] + f[i][j][kl][1]) % mod); n         } n     for (int j = 2; j <= m; ++j) n       for (int i = j; i > 1; --i) n         for (int kr = 0; kr <= 1; ++kr) { n           inc(f[i - 1][j][1][kr], f[i][j][1][kr]); n         } n     for (int i = 1; i <= m - 1; ++i) n       for (int j = i; j < m; ++j) n         for (int kl = 0; kl <= 1; ++kl) { n           inc(f[i][j + 1][kl][1], f[i][j][kl][1]); n         } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 1e5 + 5; n char a[MAX_N]; n int main() { n   int N; n   cin >> N; n   scanf( %s , a + 1); n   int cnt = 0; n   for (int i = 1; i <= N; i++) { n     if (a[i] ==  S  && a[i] >= 2 && a[i - 1] ==  G ) { n       cnt++; n     } n   } n   if (a[N] ==  G ) cnt++; n   int len = 0, prelen = (cnt >= 2), ans = 0; n   for (int i = 1; i <= N; i++) { n     if (a[i] ==  G ) { n       len++; n       ans = max(ans, len + prelen); n     } n     if (a[i] ==  S ) { n       if (2 <= i && i <= N - 1 && a[i - 1] ==  G  && a[i + 1] ==  G ) { n         if (cnt == 2) { n           prelen = len; n         } else if (cnt >= 3) { n           prelen = len + 1; n         } n       } else { n         prelen = (cnt >= 2); n       } n       len = 0; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1e-10; n const long double INF = (int)1e9 + 34; n const int N = (int)1e6 + 34; n void ret(int x) { n   cout << x; n   exit(0); n } n int n, k; n int a[N]; n int b[N], len; n bool u[N]; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) scanf( %d , a + i); n   srand(3431); n   sort(a, a + n); n   a[n] = 100000000; n   int lst = a[0]; n   b[len++] = a[0]; n   for (int i = 1; i < n; i++) n     if (a[i + 1] - lst >= k) { n       b[len++] = lst = a[i]; n     } n   int mn = a[0]; n   for (int i = 0; i < n; i++) mn = min(mn, a[i]); n   vector<int> v; n   for (int i = 0; i < 30; i++) v.push_back(a[abs((rand() << 16) ^ rand()) % n]); n   for (int i = 1; i <= 1000000; i++) n     for (int j = 0; !u[i] && j < (int)v.size(); j++) n       if (v[j] % i > k) u[i] = true; n   int l1 = -1; n   int pr; n   bool fail; n   for (int d = mn; d >= 0; d--) { n     if (u[d]) continue; n     fail = false; n     for (int i = 0; !fail && i < len; i++) n       if (b[i] % d > k) fail = true; n     if (!fail) { n       pr = d; n       break; n     } n     l1 = d; n   } n   for (int d = pr; d >= 0; d--) { n     if (u[d]) continue; n     fail = false; n     for (int i = n - 1; !fail && i >= 0; i--) n       if (a[i] % d > k) fail = true; n     if (!fail) { n       pr = d; n       break; n     } n     l1 = d; n   } n   cout << pr; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   long long n, cnt1 = 0, cnt2 = 0, l, r; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> l >> r; n     cnt1 += l; n     cnt2 += r; n   } n   cout << min(cnt1, n - cnt1) + min(cnt2, n - cnt2); n } n


#include <bits/stdc++.h> n using namespace std; n long long int Mmax(long long int a, long long int b) { n   if (a > b) return a; n   return b; n } n long long int Mmin(long long int a, long long int b) { n   if (a < b) return a; n   return b; n } n long long int nod(long long int a, long long int b) { n   while (a && b) { n     if (a > b) n       a %= b; n     else n       b %= a; n   } n   return Mmax(a, b); n } n long long int nok(long long int a, long long int b) { n   return a * b / nod(a, b); n } n bool IsPrime(long long int x) { n   if (x < 2) return false; n   long long int X = sqrt(x), i; n   for (i = 2; i <= X; i++) n     if (x % i == 0) return false; n   return true; n } n void hanoi(int n, int A, int C, int B) { n   if (n == 1) { n     cout << n <<     << A <<     << C << endl; n   } else { n     hanoi(n - 1, A, B, C); n     cout << n <<     << A <<     << C << endl; n     hanoi(n - 1, B, C, A); n   } n } n string pr2(string a, int d) { n   if (d == 0) return  0 ; n   string b; n   long long int sz = a.size(), i, prenos = 0; n   for (i = 0; i < sz; i++) { n     b[i] = a[i]; n   } n   for (i = sz - 1; i > -1; i--) { n     a[i] = ((b[i] -  0 ) * d + prenos) % 10 +  0 ; n     prenos = ((b[i] -  0 ) * d + prenos) / 10; n   } n   if (prenos) a = char(prenos +  0 ) + a; n   return a; n } n string sum(string a, string b) { n   bool carry = false; n   long long int i, sz1, sz2, maxsz, minsz; n   string c, d; n   sz1 = a.size(); n   sz2 = b.size(); n   maxsz = max(sz1, sz2); n   minsz = min(sz1, sz2); n   while (sz1 < maxsz) { n     sz1++; n     a =  0  + a; n   } n   while (sz2 < maxsz) { n     sz2++; n     b =  0  + b; n   } n   for (i = maxsz - 1; i > -1; i--) { n     d = char((a[i] + b[i] - 96 + carry) % 10 + 48) + d; n     if (a[i] + b[i] - 96 + carry > 9) n       carry = true; n     else n       carry = false; n   } n   if (carry == true) d = char( 1 ) + d; n   return d; n } n string pr(string a, string b) { n   string res =  0 , p, p2; n   int sz = a.size(), x = 0; n   for (sz = a.size(); sz > 0; sz--, x++) { n     int d = a[sz - 1] -  0 ; n     a = a.erase(sz - 1, 1); n     p2 = pr2(b, d); n     p2 += p; n     res = sum(res, p2); n     p +=  0 ; n   } n   return res; n } n bool vesokosna(long long int x) { n   return (x % 4 == 0 && x % 100 || x % 400 == 0); n } n long long int reverse(long long int x) { n   long long int mirror = 0; n   while (x) { n     mirror = mirror * 10 + x % 10; n     x /= 10; n   } n   return mirror; n } n long long int ost(string x, long long int k) { n   long long int num = 0, i, sz = x.size(); n   for (i = 0; i < sz; i++) { n     num = num * 10; n     num += x[i] -  0 ; n     num %= k; n   } n   return num; n } n bool can[128][128]; n vector<string> ans; n int main() { n   char last; n   int k, i, j, sz2 = 1; n   cin >> k; n   string q; n   cin >> q; n   int sz = q.size(); n   if (sz < k) { n     cout <<  NO n ; n     return 0; n   } n   string help; n   help += q[0]; n   ans.push_back(help); n   last = q[0]; n   for (i = 1; i < sz; i++) { n     if (sz2 == k) break; n     bool can = true; n     ; n     for (j = 0; j < sz2; j++) n       if (q[i] == ans[j][0]) can = false; n     if (can) { n       string help; n       help += q[i]; n       last = q[i]; n       ans.push_back(help); n       sz2++; n     } else n       ans.back() += q[i]; n   } n   if (sz2 == k) { n     cout <<  YES n ; n     for (; i < sz; i++) { n       ans.back() += q[i]; n     } n     for (i = 0; i < sz2; i++) cout << ans[i] << endl; n     return 0; n   } n   cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <ostream& out = cout, class... T> n void prints(T&&...) {} n template <ostream& out = cout, class... T> n void printe(T&&...) {} n template <ostream& out = cout, class... T> n void printw(T&&...) {} n template <ostream& out = cout, class... T> n void printew(T&&...) {} n template <ostream& out = cout, class... T> n void printb(T&&...) {} n template <ostream& out = cout, class... T> n void printd(T&&...) {} n template <ostream& out = cout, class... T> n void printde(T&&...){}; n template <class T> n istream& operator>>(istream& in, vector<T>& v) { n   for (auto& e : v) { n     in >> e; n   } n   return in; n } n int main() { n   int n; n   cin >> n; n   vector<char> s(n); n   cin >> s; n   int k = 0; n   bool pr; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  1 ) { n       k++; n       pr = true; n     } else { n       break; n     } n   } n   if (k == n) { n     cout <<  YES ; n     return 0; n   } n   int l = 0; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  0 ) { n       l++; n       pr = false; n     } else { n       break; n     } n   } n   if (l == n) { n     cout <<  YES ; n     return 0; n   } n   int m; n   m = max(l, k); n   for (int i = 0; i < n; i = i + m) { n     if (s[i] ==  1  && pr) { n       for (int j = 0; j < m; j++) { n         if (s[j + i] !=  1 ) { n           cout <<  NO ; n           return 0; n         } n       } n       pr = false; n       continue; n     } n     if (s[i] ==  0  && !pr) { n       for (int j = 0; j < m; j++) { n         if (s[j + i] !=  0 ) { n           cout <<  NO ; n           return 0; n         } n       } n       pr = true; n       continue; n     } n     cout <<  NO ; n     return 0; n   } n   cout <<  YES ; n } n


#include <bits/stdc++.h> n using namespace std; n const int nax = 505; n int n; n char grid[nax][nax]; n int cc[nax][nax]; n int cc_size[nax * nax]; n int when_added[nax * nax]; n const int dx[4] = {-1, 1, 0, 0}; n const int dy[4] = {0, 0, -1, 1}; n const char EMPTY =  . ; n bool inside(int x, int y) { return 0 <= min(x, y) && max(x, y) < n; } n void dfs(int x, int y, int which_cc) { n   cc[x][y] = which_cc; n   ++cc_size[which_cc]; n   for (int i = 0; i < 4; ++i) { n     int x2 = x + dx[i]; n     int y2 = y + dy[i]; n     if (inside(x2, y2) && grid[x2][y2] == EMPTY && cc[x2][y2] == 0) n       dfs(x2, y2, which_cc); n   } n } n void add(int x, int y, int& answer, int current_time) { n   if (inside(x, y) && grid[x][y] == EMPTY) { n     int id = cc[x][y]; n     if (when_added[id] != current_time) { n       when_added[id] = current_time; n       answer += cc_size[id]; n     } n   } n } n int main() { n   int k; n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; ++i) scanf( %s , grid[i]); n   int how_many_cc = 0; n   for (int x = 0; x < n; ++x) n     for (int y = 0; y < n; ++y) n       if (grid[x][y] == EMPTY && cc[x][y] == 0) dfs(x, y, ++how_many_cc); n   int cur_time = 1; n   int best_answer = 0; n   for (int y_low = 0; y_low + k <= n; ++y_low) { n     for (int x = 0; x < k; ++x) n       for (int y = y_low; y < y_low + k; ++y) --cc_size[cc[x][y]]; n     for (int x_low = 0; x_low + k <= n; ++x_low) { n       int answer = k * k; n       for (int x = x_low; x < x_low + k; ++x) { n         add(x, y_low - 1, answer, cur_time); n         add(x, y_low + k, answer, cur_time); n       } n       for (int y = y_low; y < y_low + k; ++y) { n         add(x_low - 1, y, answer, cur_time); n         add(x_low + k, y, answer, cur_time); n       } n       ++cur_time; n       best_answer = max(best_answer, answer); n       if (x_low + k != n) { n         for (int y = y_low; y < y_low + k; ++y) { n           ++cc_size[cc[x_low][y]]; n           --cc_size[cc[x_low + k][y]]; n         } n       } n     } n     for (int x = n - k; x < n; ++x) n       for (int y = y_low; y < y_low + k; ++y) ++cc_size[cc[x][y]]; n   } n   printf( %d , best_answer); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1000000000; n const int maxn = 100010; n int a[maxn]; n int max(int a, int b) { return a > b ? a : b; } n int min(int a, int b) { return a > b ? b : a; } n int main() { n   int n, l, r, i, j; n   string s; n   while (cin >> n) { n     for (i = 0; i < n; i++) cin >> a[i]; n     cin >> s; n     l = -inf, r = inf; n     for (i = 4; i < n; i++) { n       if (s[i] ==  1 ) { n         int maxi = -inf; n         for (j = i; j >= i - 4; j--) { n           maxi = max(maxi, a[j]); n         } n         int cnt = 0; n         for (j = i; j >= i - 4; j--) { n           if (s[j] ==  0 ) cnt++; n         } n         if (cnt == 4) { n           l = max(l, maxi + 1); n         } n       } else if (s[i] ==  0 ) { n         int mina = inf; n         for (j = i; j >= i - 4; j--) { n           mina = min(mina, a[j]); n         } n         int cnt = 0; n         for (j = i; j >= i - 4; j--) { n           if (s[j] ==  1 ) cnt++; n         } n         if (cnt == 4) { n           r = min(r, mina - 1); n         } n       } n     } n     cout << l <<     << r << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long i, j, k, n, v[200010], m, a, b, x, y, h, w, l, p, ans, numitor, aux, n     mini, sum, poz; n string s1, s2, second; n char c; n map<long long, long long> mip; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> x; n   for (long long i = 1; i <= n; i++) { n     cin >> v[i]; n     if (v[i] < x) n       v[i] = -1; n     else if (v[i] > x) n       v[i] = 1; n     else { n       v[i] = 0; n       poz = i; n     } n   } n   mip[0] = 1; n   sum = 0; n   for (long long i = 1; i <= n; i++) { n     sum += v[i]; n     if (i >= poz) { n       if (mip.find(sum) != mip.end()) ans += mip[sum]; n       if (mip.find(sum - 1) != mip.end()) ans += mip[sum - 1]; n     } else { n       mip[sum] += 1; n       v[i] = sum; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n int n, ex, ey, sx[N], sy[N]; n char s[N]; n inline bool check(int m) { n   for (int i = 1; i + m - 1 <= n; i++) { n     int decx = sx[n] - sx[i + m - 1] + sx[i - 1]; n     int decy = sy[n] - sy[i + m - 1] + sy[i - 1]; n     int nedx = ex - decx; n     int nedy = ey - decy; n     if (abs(nedx) + abs(nedy) <= m && !(m - abs(nedx) - abs(nedy) & 1)) n       return 1; n   } n   return 0; n } n int main() { n   scanf( %d%s%d%d , &n, s + 1, &ex, &ey); n   for (int i = 1; i <= n; i++) { n     sx[i] = sx[i - 1] + (s[i] ==  L  ? -1 : (s[i] ==  R  ? 1 : 0)); n     sy[i] = sy[i - 1] + (s[i] ==  D  ? -1 : (s[i] ==  U  ? 1 : 0)); n   } n   int l = 0, r = n, mid, 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   } n   printf( %d n , ans); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e6 + 5; n int tree[4 * MAXN], n, m, a[MAXN], size = 0, less1[MAXN]; n vector<int> del, nums; n void initialize(int l, int r, int node) { n   tree[node] = r - l + 1; n   if (r == l) return; n   int mid = (l + r) / 2; n   initialize(l, mid, 2 * node); n   initialize(mid + 1, r, 2 * node + 1); n } n int elim(int node) { n   while (node >= 1) { n     tree[node]--; n     node /= 2; n   } n } n void find(int l, int r, int sum, int node) { n   if (l == r) { n     nums[l] = -2; n     elim(node); n     return; n   } n   int mid = (l + r) / 2; n   if (tree[2 * node] >= sum) n     find(l, mid, sum, 2 * node); n   else n     find(mid + 1, r, sum - tree[2 * node], 2 * node + 1); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> m; n   for (int i = 0; i < m; ++i) { n     cin >> a[i]; n   } n   for (int i = 0; i < MAXN; ++i) less1[i] = 0; n   for (int i = 0; i < m - 1; ++i) n     for (int k = a[i]; k < a[i + 1]; ++k) less1[k] = i + 1; n   for (int i = a[m - 1]; i < MAXN; ++i) less1[i] = m; n   for (int i = 0; i < n; ++i) { n     int x; n     cin >> x; n     if (x == -1) { n       del.push_back(less1[size]); n       size -= less1[size]; n     } else { n       nums.push_back(x); n       size++; n     } n   } n   if (nums.size() == 0) { n     cout <<  Poor stack!  << endl; n     return 0; n   } n   initialize(0, nums.size() - 1, 1); n   for (int i = 0; i < del.size(); ++i) n     for (int j = del[i] - 1; j >= 0; --j) find(0, nums.size() - 1, a[j], 1); n   int ct = 0; n   for (int i = 0; i < nums.size(); ++i) { n     if (nums[i] != -2) { n       cout << nums[i]; n       ++ct; n     } n   } n   if (ct == 0) cout <<  Poor stack! ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long INFF = 0x3f3f3f3f3f3f3f3f; n const double pi = acos(-1.0); n const double eps = 1e-9; n const long long mod = 1e9 + 7; n int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch< 0  | ch>  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n void Out(int aa) { n   if (aa > 9) Out(aa / 10); n   putchar(aa % 10 +  0 ); n } n int n, t; n int f[55], s[55], p[55]; n double dp[55][5005]; n bool check(double mid) { n   for (int i = n; i >= 1; i--) { n     for (int j = t + 1; j <= 5000; j++) dp[i + 1][j] = mid; n     for (int j = 0; j <= t; j++) { n       double t1 = (dp[i + 1][j + f[i]] + f[i]) * p[i] / 100; n       double t2 = (dp[i + 1][j + s[i]] + s[i]) * (100 - p[i]) / 100; n       dp[i][j] = min(mid, t1 + t2); n     } n   } n   return dp[1][0] < mid; n } n int main() { n   n = read(), t = read(); n   for (int i = 1; i <= n; i++) f[i] = read(), s[i] = read(), p[i] = read(); n   double l = 0, r = 1e12; n   for (int i = 0; i < 100; i++) { n     double mid = (l + r) / 2; n     if (check(mid)) n       r = mid; n     else n       l = mid; n   } n   printf( %.10f n , l); n   return 0; n } n


#include <iostream> n #include <vector> n #include <algorithm> n  n using namespace std; n  n #define int long long n  n void solve() { n     int n; n     vector<long long> vect; n     cin >> n; n     for (int i = 0; i < n; i++) { n         long long x; n         cin >> x; n         vect.push_back(x); n     } n     sort(vect.begin(), vect.end()); n     long long res = 0; n     long long now = 0; n     for (int i = n - 2; i >= 0; i--) { n         res -= now - (n - i - 2) * vect[i]; n         now += vect[i + 1]; n     } n     cout << res <<   n ; n } n  n signed main() n { n     ios_base::sync_with_stdio(false); n     cin.tie(nullptr); n     int t; n     cin >> t; n     for (int i = 0; i < t; i++) n         solve(); n     return 0; n } n


n // Problem : B. Tree Array n // Contest : Codeforces - Codeforces Round #728 (Div. 1) n // URL : https://codeforces.com/contest/1540/problem/B n // Memory Limit : 256 MB n // Time Limit : 2000 ms n // Powered by CP Editor (https://github.com/cpeditor/cpeditor) n  n #include <bits/stdc++.h> n  n using namespace std; n  n int N; n long long pas[205][205]; n const long long MOD = 1e9+7; n long long cache[205][205]; n vector<int> graph[205]; n int par[205]; n bool vis[205]; n  n long long add(long long a, long long b){ n  return (a + b) % MOD; n } n  n long long mult(long long a, long long b){ n  return a * b % MOD; n } n  n long long qikpow(long long b, long long e){ n  if(!e){ n   return 1; n  } n  long long ret = qikpow(b, e / 2); n  ret = mult(ret, ret); n  if(e & 1){ n   ret = mult(ret, b); n  } n  return ret; n } n  n long long sub(long long a, long long b){ n  return ((a - b) % MOD + MOD ) % MOD; n } n  n long long divd(long long a, long long b){ n  return mult(a, qikpow(b, MOD - 2)); n } n  n void dfs1(int n){ n  for(int e : graph[n]){ n   if(e != par[n]){ n    par[e] = n; n    dfs1(e); n   } n  } n } n  n int dfs2(int n, int p){ n  int sz = 1; n  for(int e : graph[n]){ n   if(!vis[e] && p != e){ n    sz += dfs2(e, n); n   } n  } n  return sz; n } n  n int main(){ n  ios::sync_with_stdio(0); n  cin.tie(0); n  cout.tie(0); n  cin >> N; n  for(int i = 0; i <= N; i++){ n   pas[i][0] = 1; n   for(int j = 1; j <= i; j++){ n    pas[i][j] = add(pas[i-1][j], pas[i-1][j-1]); n   } n  }  n  for(int i = 1; i < N; i++){ n   int a, b; n   cin >> a >> b; n   graph[a].emplace_back(b); n   graph[b].emplace_back(a); n  } n  long long ans = 0; n  for(int n = 1; n <= N; n++){ n   fill(par, par+1+N, 0); n   dfs1(n); n   vis[n] = 1; n   for(int k = n+1; k <= N; k++){ n    int cur = k, len = 0; n    while(cur != n){ n     vis[cur] = 1; n     len++; n     cur = par[cur]; n    } n    cur = k; n    for(int t = len; t; t--){ n     int s = dfs2(cur, 0); n     //cout << s <<   n ; n     long long tot = divd(s, N); n     if(t == len){ n      ans = add(ans, tot); n     } n     else{ n      /* n      long long p = 1;//qikpow(divd(1, 2), len);      n      cout << p <<     << pas[len - 1][len - t] <<   n ; n      p = mult(p, divd(pas[len - 1][len - t], pas[len][len-t])); n      cout << n <<     << k <<     << cur <<   n ; n      cout << p <<     << tot <<   n ; n      ans = add(ans, mult(p, tot)); n      */ n      //cout << n <<     << k <<     << cur <<   n ; n      //cout << tot <<   n ; n      if(!cache[len][t]){ n       for(int c = 0; c < t; c++){ n        cache[len][t] = add(cache[len][t], mult(pas[c+len-t-1][len-t-1], qikpow(divd(1, 2), c+len-t))); n        //cout << mult(mult(pas[c+len-t-1][len-t-1], qikpow(divd(1, 2), c+len-t)), tot) <<   n ; n       }   n      } n      ans = add(mult(tot, cache[len][t]), ans); n       n     } n     cur = par[cur]; n    } n    cur = k; n    while(cur != n){ n     vis[cur] = 0; n     cur = par[cur]; n    } n   } n   vis[n] = 0; n  } n  cout << ans; n }


#include <bits/stdc++.h> n using namespace std; n int read() { n   int a = 0; n   char c = getchar(); n   bool f = 0; n   while (!isdigit(c)) { n     f = c ==  - ; n     c = getchar(); n   } n   while (isdigit(c)) { n     a = a * 10 + c - 48; n     c = getchar(); n   } n   return f ? -a : a; n } n const int _ = 1e5 + 11; n vector<int> nxt[_][2]; n int N, C[_], ans; n long long num; n void addEd(int a, int b, int c) { nxt[a][c].push_back(b); } n int deg[_], dst[_], seq[_], cseq; n unsigned long long arr[_][50]; n void build(int fir) { n   memset(deg, 0, sizeof(deg)); n   cseq = 0; n   for (int i = 1; i <= N + 8; ++i) { n     for (auto t : nxt[i][0]) deg[t] += dst[t] == dst[i]; n     for (auto t : nxt[i][1]) deg[t] += dst[t] == dst[i] + 1; n   } n   queue<int> q; n   q.push(fir); n   while (!q.empty()) { n     int t = q.front(); n     q.pop(); n     seq[++cseq] = t; n     for (int l = 0; l < 2; ++l) n       for (auto p : nxt[t][l]) n         if (dst[p] == dst[t] + l && !--deg[p]) q.push(p); n   } n } n void solve(int size, vector<int> node, int fir, int mx) { n   memset(arr, 0, sizeof(arr)); n   for (int i = 0; i < node.size(); ++i) n     arr[node[i]][i >> 6] |= 1ull << (i & 63); n   for (int i = 1; i <= cseq; ++i) { n     int t = seq[i]; n     for (int l = 0; l < 2; ++l) n       for (auto p : nxt[t][l]) n         if (dst[p] == dst[t] + l) n           for (int r = 0; r < 50; ++r) arr[p][r] |= arr[t][r]; n   } n   long long cnt = 0; n   int val = node.size(); n   for (int i = 1; i <= N && val == node.size(); ++i) n     if (dst[i] == mx) { n       int num = 0; n       for (int j = 0; j < 50; ++j) { n         num += __builtin_popcountll(arr[i][j]); n       } n       val = min(val, num); n     } n   if (val == node.size()) --mx; n   for (int i = 1; i <= N; ++i) n     if (dst[i] > mx) n       cnt += node.size(); n     else if (dst[i] == mx) { n       int num = 0; n       for (int j = 0; j < 50; ++j) { n         num += __builtin_popcountll(arr[i][j]); n       } n       cnt += node.size() - num; n     } n   if (ans < mx) { n     ans = mx; n     num = 0; n   } n   if (ans == mx) num += cnt; n } n int main() { n   ios::sync_with_stdio(0); n   cin >> N; n   for (int i = 1; i <= N; ++i) { n     char c; n     cin >> c; n     C[i] = c -  a  + 1; n     addEd(i, N + C[i], 0); n     addEd(N + C[i], i, 1); n   } n   for (int i = 2; i <= N; ++i) { n     addEd(i - 1, i, 1); n     addEd(i, i - 1, 1); n   } n   for (int i = 1; i <= 8; ++i) { n     memset(dst, 0x3f, sizeof(dst)); n     dst[N + i] = 0; n     deque<int> q; n     q.push_back(N + i); n     int mx = 0; n     while (!q.empty()) { n       int t = q.front(); n       q.pop_front(); n       if (t <= N) mx = max(mx, dst[t]); n       for (auto r : nxt[t][0]) n         if (dst[r] > dst[t]) { n           dst[r] = dst[t]; n           q.push_front(r); n         } n       for (auto r : nxt[t][1]) n         if (dst[r] > dst[t] + 1) { n           dst[r] = dst[t] + 1; n           q.push_back(r); n         } n     } n     vector<int> node; n     build(N + i); n     for (int j = 1; j <= N; ++j) n       if (C[j] == i) { n         node.push_back(j); n         if (node.size() == 64 * 50) { n           solve(64 * 50, node, N + i, mx); n           node.clear(); n         } n       } n     if (node.size()) solve(node.size(), node, N + i, mx); n   } n   cout << ans <<     << num / 2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int64_t ans, n, k, m, r[100005]; n char s[100005], t[100005]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int64_t tt; n   cin >> tt; n   while (tt--) { n     cin >> n; n     cin >> s; n     cin >> t; n     vector<int> ans; n     m = n - 1; n     int i = 0, j = n - 1; n     while (i < j) { n       r[m--] = i; n       i++; n       r[m--] = j; n       j--; n     } n     if (i == j) r[m] = i; n     m = 0; n     for (int i = n - 1; i >= 0; i--) { n       if ((s[r[i]] -  0  + m) % 2 == t[i] -  0 ) ans.push_back(1); n       ans.push_back(i + 1); n       m++; n     } n     cout << (int)ans.size() <<    ; n     for (auto i : ans) cout << i <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> a; n int k, t, n, mx; n string s; n int main() { n   cin >> n >> k; n   cin >> s; n   for (int i = 0; i < s.size(); i++) n     if (s[i] ==  . ) a.push_back(i); n   for (int i = 0; i < a.size() - 1; i++) mx = max(mx, a[i + 1] - a[i]); n   if (mx > k) n     cout <<  NO ; n   else n     cout <<  YES ; n } n


#include <bits/stdc++.h> n using namespace std; n int w; n long long n, k; n pair<long long, long long> o = {0, 0}; n pair<long long, long long> csop(long long kezd, long long kim) { n   long long sum = 0, kov = kezd + k; n   if (kezd <= kim && kim <= kov) { n     kov++; n   } n   sum = (kov - kezd) * (kov - kezd - 1) / 2; n   if (log(k) + log(kezd) < 42.0) { n     sum += kezd * (kov - kezd); n   } else { n     sum = 2e18; n   } n   if (kezd <= kim && kim < kov) { n     sum -= kim; n   } n   return {sum, kov}; n } n pair<long long, long long> calc(long long ert) { n   if (ert <= k * (k + 1) / 2) { n     return {1, k * (k + 1) / 2}; n   } n   long long kis = ert / k - k / 2; n   auto s = calc(kis); n   long long fi = s.first, se = s.second; n   long long s2 = kis, kor = 0, ert2 = 0; n   s2 -= (fi - 1) * (k + 1), kor += fi - 1, ert2 = (fi - 1) * (k + 1); n   long long ss = (s2 + k - 2) / k; n   kor += ss, ert2 += ss * k; n   ert2++, kor++; n   if (ert2 >= se) { n     ert2++; n   } n   auto cs = csop(ert2, se); n   if (cs.first < ert) { n     ert2 = cs.second, kor++; n     cs = csop(ert2, se); n   } n   return {kor, cs.first}; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> w; n   while (w--) { n     cin >> n >> k; n     if (n <= k) { n       cout << n <<   n ; n       continue; n     } n     if (k == 2 && n <= 5) { n       cout << n <<   n ; n       continue; n     } n     auto s = calc(n); n     if (s.second == n) { n       cout << s.first * (k + 1) <<   n ; n     } else { n       long long fi = s.first, ans = fi * (k + 1); n       n -= fi * (k + 1) - 1; n       ans += (k + 1) * (n / k) + n % k; n       if (n % k == 0) { n         ans--; n       } n       cout << ans <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cl[5000010], cr[5000010], ld[5000010], sl = 1; n bool yz[5000010]; n void pushd(int x) { n   if (cl[x] == 0) { n     cl[x] = ++sl; n     yz[cl[x]] = 1; n   } n   if (cr[x] == 0) { n     cr[x] = ++sl; n     yz[cr[x]] = 1; n   } n   yz[x] = 0; n   if (ld[x] == 0) return; n   ld[cl[x]] = ld[cr[x]] = ld[x]; n   ld[x] = 0; n } n vector<int> cf[50010], ve[5000010]; n void addqj(int i, long long l, long long r, long long L, long long R, int x) { n   if (R <= l || r <= L) return; n   if (L <= l && r <= R) { n     ld[i] = x; n     cf[x].push_back(i); n     return; n   } n   long long m = (l + r) >> 1; n   pushd(i); n   addqj(cl[i], l, m, L, R, x); n   addqj(cr[i], m, r, L, R, x); n } n void link(int x, int y) { n   if (yz[x] && yz[y]) { n     if (ld[x] < ld[y]) n       ve[x].push_back(y); n     else n       ve[y].push_back(x); n     return; n   } n   link(yz[x] ? x : cl[x], yz[y] ? y : cl[y]); n   link(yz[x] ? x : cr[x], yz[y] ? y : cr[y]); n } n int find(int i, long long l, long long r, long long x) { n   if (yz[i]) return i; n   long long m = (l + r) >> 1; n   return x < m ? find(cl[i], l, m, x) : find(cr[i], m, r, x); n } n int lx[50010], fa[5000010], ans[50010]; n long long A[50010], B[50010]; n int getv(int x) { return x == fa[x] ? x : fa[x] = getv(fa[x]); } n void merge(int x, int y) { n   x = getv(x); n   y = getv(y); n   if (x != y) fa[x] = y; n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   ld[1] = m + 1; n   yz[1] = 1; n   for (int i = 1; i <= m; i++) { n     char zf[10]; n     scanf( %s%lld%lld , zf, &A[i], &B[i]); n     lx[i] = zf[0] ==  b  ? 0 : 1; n     if (lx[i] == 0) addqj(1, 0, (1ll << n), A[i], B[i] + 1, i); n   } n   for (int i = 1; i <= sl; i++) { n     fa[i] = i; n     if (!yz[i]) link(cl[i], cr[i]); n   } n   for (int i = 1; i <= sl; i++) { n     if (ld[i] != m + 1) continue; n     for (int j = 0; j < ve[i].size(); j++) merge(i, ve[i][j]); n   } n   for (int i = m; i >= 1; i--) { n     if (lx[i]) n       ans[i] = (getv(find(1, 0, (1ll << n), A[i])) == n                 getv(find(1, 0, (1ll << n), B[i]))); n     else { n       for (int x = 0; x < cf[i].size(); x++) { n         int u = cf[i][x]; n         for (int y = 0; y < ve[u].size(); y++) merge(u, ve[u][y]); n       } n     } n   } n   for (int i = 1; i <= m; i++) { n     if (lx[i]) printf( %d n , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 15; n long long Get_Num(int num[], int b, int n) { n   long long number = 0; n   long long in = 1; n   for (int i = n - 1; i >= 0; i--) { n     number += num[i] * in; n     in = in * b; n   } n   return number; n } n int main() { n   int x[N], y[N]; n   int b; n   int n; n   long long X, Y; n   cin >> n >> b; n   for (int i = 0; i < n; i++) { n     cin >> x[i]; n   } n   X = Get_Num(x, b, n); n   cin >> n >> b; n   for (int i = 0; i < n; i++) { n     cin >> y[i]; n   } n   Y = Get_Num(y, b, n); n   if (X == Y) { n     printf( = n ); n   } else if (X > Y) { n     printf( > n ); n   } else { n     printf( < n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long n, m; n     cin >> n >> m; n     long sum = 0; n     if (n == 1 || n == 2) { n       if (n == 1) n         cout << 0 << endl; n       else n         cout << m << endl; n     } else { n       cout << 2 * m << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n long long n, m; n int k; n int mpow(int a, long long b) { n   int c = 1; n   for (; b; b >>= 1, a = 1ll * a * a % mod) n     if (b & 1) c = 1ll * c * a % mod; n   return c; n } n int main() { n   scanf( %lld%lld%d , &n, &m, &k); n   if ((n + m) & 1) n     if (k == -1) { n       printf( 0 n ); n       return 0; n     } n   int tmp = mpow(2, n - 1); n   printf( %d n , mpow(tmp, m - 1)); n } n


#include <bits/stdc++.h> n using namespace std; n int tt(char p) { n   int s; n   if (p ==  > ) n     s = 8; n   else if (p ==  < ) n     s = 9; n   else if (p ==  + ) n     s = 10; n   else if (p ==  - ) n     s = 11; n   else if (p ==  . ) n     s = 12; n   else if (p ==  , ) n     s = 13; n   else if (p ==  [ ) n     s = 14; n   else n     s = 15; n   return s; n } n int main() { n   string x; n   int t = 0; n   int q = x.length() - 1; n   cin >> x; n   for (int i = 0; i < x.length(); ++i) { n     t = (t * 16 + tt(x[i])) % 1000003; n   } n   cout << t; n   return 0; n } n


#include <bits/stdc++.h> n template <typename T> n inline T MIN(T a, T b) { n   return a < b ? a : b; n } n template <typename T> n inline T MAX(T a, T b) { n   return a > b ? a : b; n } n using namespace std; n void reop() { freopen( input.txt ,  r , stdin); } n int a[100001] = {0}; n int ans = 0, curans = 0; n bool test(int div, int n, int start) { n   int prev = start; n   for (int i = 2; i < n; ++i) { n     if (a[i] == prev + div) n       prev = a[i]; n     else if (a[i] + 1 == prev + div) { n       prev = a[i] + 1; n       curans++; n     } else if (a[i] - 1 == prev + div) { n       prev = a[i] - 1; n       curans++; n     } else n       return false; n   } n   ans = MIN(ans, curans); n   return true; n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   if (n == 1 || n == 2) { n     cout << 0; n     return 0; n   } n   ans = 1000000007; n   for (int i = -1; i <= 1; ++i) { n     for (int j = -1; j <= 1; ++j) { n       curans = 0; n       int div = a[1] + j - (a[0] + i); n       if (j) curans++; n       if (i) curans++; n       test(div, n, a[1] + j); n     } n   } n   cout << (ans == 1000000007 ? -1 : ans); n   return 0; n } n


#include<bits/stdc++.h> n #define int long long n #define pii pair<int,int> n #define F first n #define S second n #define pi acos(-1.0) n #define pb push_back n #define sf(x) scanf( %lld ,&x) n #define pf(x) printf( %lld ,&x) n using namespace std; n const int mod=1e9+7; n int a1[2000],ar[2000],ff[2000] ; n map<int,int>mp,mk ; n int bigmod(int a , int b) n { n     if(b==0) return 1 ; n     int x = bigmod(a,b/2) ; n     x=((x%mod)*(x%mod))%mod ; n     if(b%2) x=((x%mod)*(a%mod))%mod ; n     return x ; n } n int ncr(int a , int b) n { n     int p=(ff[a-b]*ff[b])%mod ; n     p=(ff[a]*bigmod(p,mod-2)) ; p%=mod ; n     return p ; n } n int32_t main() n { n     ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ; n     ff[0]=1 ; ff[1]=1 ; n     for(int i = 2 ; i <= 1000 ; i++) ff[i]=(ff[i-1]*i)%mod ; n     int t ; cin>>t ; n     while(t--) n     { n         int n,k,mx=0 ; cin>>n>>k ; mp.clear() ; mk.clear() ; n         set<int>st ; n         for(int i = 1 ; i <= n ; i++){cin>>ar[i] ; mp[ar[i]]++ ; a1[i]=ar[i] ; } n         sort(a1+1,a1+n+1) ; reverse(a1+1,a1+n+1) ; n        // for(int i = 1 ; i <= n ; i++) cout<<a1[i]<<    ; cout<<endl ; n         for(int i = 1 ; i <= k ; i++) {mx+=a1[i] ; st.insert(a1[i]) ; mk[a1[i]]++ ;} n         int ans=1 ; n         for(int x : st) n         { n             int p=mp[x],q=mk[x] ; n           //  cout<<x<<   <<p<<   <<q<<endl ; n             ans*=ncr(p,q); ans%=mod ; n         } n         cout<<ans<<endl ; n     } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 2, M = 1e9 + 7; n int tt = 1, n, k; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> tt; n   while (tt--) { n     cin >> n; n     if (n == 1) { n       cout <<  a n ; n       continue; n     } n     string second =   , ans =   ; n     for (int i = 0; i < n / 2 - 1; i++) second +=  a ; n     ans +=  a  + second +  b  + second; n     if (n & 1) ans +=  c ; n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 7; n const long long inf = 1e17 + 7; n pair<long long, long long> a[maxn]; n pair<long long, long long> A[maxn]; n pair<pair<long long, long long>, pair<long long, long long> > S[maxn]; n int pos; n inline long long elf(pair<long long, long long> z, long long x) { n   return z.first * x + z.second; n } n inline long long earl(pair<long long, long long> z, long long v) { n   long long a = z.first, b = z.second; n   long long x = (v - b) / a; n   if (a * x >= v - b) return x; n   return x + 1; n } n inline long double intx(pair<long long, long long> l1, n                         pair<long long, long long> l2) { n   long long a1 = l1.first, a2 = l2.first, b1 = l1.second, b2 = l2.second; n   return (long double)(b2 - b1) / (long double)(a1 - a2); n } n void ins(long long a, long long b) { n   while (pos >= 2 && intx(S[pos].first, S[pos - 1].first) >= n                          intx(make_pair(a, b), S[pos].first)) n     pos--; n   S[pos].second.second = ceil(intx(S[pos].first, make_pair(a, b))) - 1; n   pos++; n   S[pos] = n       make_pair(make_pair(a, b), n                 make_pair(ceil(intx(S[pos - 1].first, make_pair(a, b))), inf)); n } n int main() { n   int n; n   long long s; n   scanf( %d %lld , &n, &s); n   for (int i = 1; i <= n; i++) { n     scanf( %lld %lld , &a[i].first, &a[i].second); n   } n   sort(a + 1, a + n + 1); n   a[0].first = -1; n   long long cur = -1; n   long long best = inf; n   int idx = 0; n   for (int i = n; i >= 0; i--) { n     if (a[i].first != cur) { n       if (cur > 0) { n         idx++; n         A[idx] = make_pair(cur, best); n       } n       cur = a[i].first; n       best = inf; n     } n     best = min(best, a[i].second); n   } n   n = idx; n   for (int i = 1; i <= n; i++) a[i] = A[i]; n   best = inf; n   idx = 0; n   for (int i = 1; i <= n; i++) { n     if (a[i].second >= best) continue; n     idx++; n     A[idx] = a[i]; n     best = min(best, a[i].second); n   } n   n = idx; n   reverse(A + 1, A + n + 1); n   long long ans = inf; n   pos = 1; n   S[pos] = make_pair(make_pair(A[1].first, 0), make_pair(0, inf)); n   int fp = 1; n   for (int i = 2; i <= n; i++) { n     while (fp < pos && elf(S[fp].first, S[fp].second.second) < A[i].second) n       fp++; n     long long cx = earl(S[fp].first, A[i].second); n     long long fcx = elf(S[fp].first, cx); n     ins(A[i].first, fcx - A[i].second - A[i].first * cx); n     fp = min(fp, pos); n   } n   for (int i = 1; i <= pos; i++) { n     ans = min(ans, earl(S[i].first, s)); n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 3; n const long long int M = 1000000007; n void solve() { n   string s; n   cin >> s; n   int n = s.length(); n   for (int i = 0; i < n - 1; ++i) { n     s +=  0 ; n   } n   long long int ans = 0; n   for (int i = 0; i < 2 * (n - 1) + 1; ++i) { n     ans += ans + s[i] -  0 ; n     ans %= M; n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   solve(), cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct like { n   int id; n   int change = 0; n }; n int main() { n   int n, s, max = 0, idmax = 0, count = 0, k = 0; n   cin >> n; n   like *A = new like[n]; n   for (int i = 0; i < n; i++) { n     cin >> s; n     k = 1; n     for (int j = 0; j < count; j++) { n       if (A[j].id == s) { n         A[j].change++; n         k = 0; n         if (A[j].change > max) { n           max = A[j].change; n           idmax = A[j].id; n         } n       } n     } n     if (k == 1) { n       A[count].id = s; n       A[count].change++; n       if (A[count].change > max) { n         max = A[count].change; n         idmax = A[count].id; n       } n       count++; n     } n   } n   cout << idmax << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int H[100000][5], V[100000][5]; n long long dp[32]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 1; i < m; ++i) n     for (int j = 0; j < n; ++j) cin >> H[i][j]; n   for (int i = 0; i < m; ++i) n     for (int j = 0; j < n; ++j) cin >> V[i][j]; n   for (int i = 1; i < (1 << n); ++i) dp[i] = 1e18; n   const int sz = 1 << n; n   for (int i = 1; i < m; ++i) { n     for (int j = 0; j < sz; ++j) { n       for (int k = 0; k < n; ++k) { n         if (!(j & (1 << k))) { n           auto &t = dp[j | (1 << k)]; n           const auto &nt = dp[j] + H[i][k]; n           if (nt < t) t = nt; n         } n       } n       for (int k = 0; k < n; ++k) { n         if ((((j >> k)) ^ ((j >> ((k + 1) % n)))) & 1) dp[j] += V[i][k]; n       } n     } n   } n   cout << dp[sz - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int arr[100000], arr1[100000], arr2[100000]; n int main() { n   int n, flag = 0; n   cin >> n; n   multiset<long long int> m; n   multiset<long long int>::iterator it; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     m.insert(arr[i]); n     if (i == 0) n       arr1[i] = arr[i]; n     else n       arr1[i] = arr1[i - 1] + arr[i]; n   } n   for (int i = n - 1; i >= 0; i--) { n     if (i == n - 1) n       arr2[n - 1 - i] = arr[i]; n     else n       arr2[n - 1 - i] = arr2[n - 2 - i] + arr[i]; n   } n   if (arr1[n - 1] % 2 != 0) n     cout <<  NO ; n   else { n     long long int sum = arr1[n - 1] / 2; n     it = m.find(arr[0]); n     m.erase(it); n     if (arr1[0] == sum || arr2[0] == sum) flag = 1; n     if (!flag) { n       for (int i = 1; i < n - 1; i++) { n         if (m.find(sum - arr1[i - 1]) != m.end()) { n           flag = 1; n           break; n         } n         if (!flag) { n           int low = i + 1, high = n - 1; n           while (low < high) { n             int mid = low + (high - low + 1) / 2; n             if (arr1[mid] - arr1[i] + arr1[i - 1] > sum) n               high = mid - 1; n             else n               low = mid; n           } n           if (arr1[low] - arr1[i] + arr1[i - 1] == sum) { n             flag = 1; n             break; n           } n         } n         it = m.find(arr[i]); n         m.erase(it); n       } n     } n     m.clear(); n     if (!flag) { n       for (int i = 0; i < n; i++) m.insert(arr[i]); n       it = m.find(arr[n - 1]); n       m.erase(it); n       for (int i = 1; i < n - 1; i++) { n         if (m.find(sum - arr2[i - 1]) != m.end()) { n           flag = 1; n           break; n         } n         int low = i + 1, high = n - 1; n         while (low < high) { n           int mid = low + (high - low + 1) / 2; n           if (arr2[mid] - arr2[i] + arr2[i - 1] > sum) n             high = mid - 1; n           else n             low = mid; n         } n         if (arr2[low] - arr2[i] + arr2[i - 1] == sum) { n           flag = 1; n           cout << i << endl; n           break; n         } n         it = m.find(arr[n - 1 - i]); n         m.erase(it); n       } n     } n     if (flag) n       cout <<  YES ; n     else n       cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll MOD = 1e9 + 7; n void dfs(int node, vector<vector<pair<int, int>>>& adj, vector<bool>& vu, n          ll& cnt) { n   for (auto& p : adj[node]) { n     if (!vu[p.first] and p.second == 0) { n       vu[p.first] = true; n       ++cnt; n       dfs(p.first, adj, vu, cnt); n     } n   } n } n ll getPow(ll a, ll p) { n   ll ret = 1, cp = a; n   while (p) { n     if (p & 1) ret = (ret * cp) % MOD; n     p >>= 1; n     cp = (cp * cp) % MOD; n   } n   return ret; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n, k, a, b, c; n   cin >> n >> k; n   vector<vector<pair<int, int>>> adj(n + 1); n   for (int i = 1; i < n; ++i) { n     cin >> a >> b >> c; n     adj[a].emplace_back(b, c); n     adj[b].emplace_back(a, c); n   } n   vector<bool> vu(n + 1); n   ll ans = getPow(n, k); n   for (int i = 1; i <= n; ++i) { n     if (!vu[i]) { n       ll tmp = 1; n       vu[i] = true; n       dfs(i, adj, vu, tmp); n       ans = (ans - getPow(tmp, k)) % MOD; n     } n   } n   cout << (ans + MOD) % MOD; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, v[5000]; n char a[5000][5050]; n bool dfs(int x, int from) { n   v[x] = 1; n   for (int y = 0; y < n; y++) n     if (a[x][y] ==  1 ) { n       if (!v[y]) { n         if (dfs(y, x)) return true; n       } else { n         if (a[y][from] ==  1 ) { n           printf( %d %d %d n , y + 1, from + 1, x + 1); n           return true; n         } n       } n     } n   return false; n } n int main() { n   scanf( %d , &n); n   gets(a[0]); n   for (int i = 0; i < n; i++) gets(a[i]); n   for (int i = 0; i < n; i++) n     if (!v[i]) n       if (dfs(i, -1)) return 0; n   puts( -1 ); n } n


#include <bits/stdc++.h> n const double EPS = 0.0000000001; n const long long mod1 = 998244353; n const long long mod2 = 1000000007; n const long long mod3 = 1000000009; n const long long mod4 = 998244353; n const long long inf = 10000000000000000; n using namespace std; n signed main() { n   cin.tie(0); n   cout.tie(0); n   std::ios_base::sync_with_stdio(0); n   long long n, a; n   cin >> n >> a; n   long long matrix[a][n]; n   for (long long i = 0; i < a; i++) { n     for (long long z = 0; z < n; z++) { n       char c; n       cin >> c; n       matrix[i][z] = (c -  0 ); n     } n   } n   bool used[a]; n   for (long long i = 0; i < a; i++) { n     bool p = 0; n     for (long long z = 0; z < n; z++) { n       if (!matrix[i][z]) p = 1; n     } n     used[i] = p; n   } n   long long c = 0; n   long long x = 1; n   long long maxi = -1; n   for (long long i = 0; i < a; i++) { n     if (used[i]) { n       c++; n       continue; n     } n     maxi = max(maxi, c); n     c = 0; n   } n   maxi = max(maxi, c); n   cout << maxi; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> x[1024], y[1024]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     for (int i = 0; i < n; i++) { n       cin >> x[i].first >> x[i].second; n       y[i].first = x[i].first; n       y[i].second = x[i].second; n     } n     sort(x, x + n, [](const pair<int, int>& a, const pair<int, int>& b) { n       return a.first < b.first || (a.first == b.first && a.second < b.second); n     }); n     sort(y, y + n, [](const pair<int, int>& a, const pair<int, int>& b) { n       return a.second < b.second || (a.second == b.second && a.first < b.first); n     }); n     string ans =   ; n     int r = 0, c = 0; n     for (int i = 0; i < n; i++) { n       if (x[i] != y[i]) { n         cout <<  NO  << endl; n         ans =   ; n         break; n       } else { n         ans += string(x[i].first - r,  R ); n         ans += string(x[i].second - c,  U ); n         r = x[i].first; n         c = x[i].second; n       } n     } n     if (!ans.empty()) { n       cout <<  YES  << endl << ans << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[123456]; n int main() { n   scanf( %s , s); n   stack<pair<int, int> > st; n   int best = 0, rr = -1; n   int sqb = 0; n   for (int i = 0; s[i]; ++i) { n     if (s[i] ==  (  || s[i] ==  [ ) { n       st.push(make_pair(i, sqb)); n       sqb = 0; n     } else if (s[i] ==  ) ) { n       if (st.size() > 0 && s[st.top().first] ==  ( ) { n         sqb += st.top().second; n         if (best < sqb) { n           best = sqb; n           rr = i; n         } n         st.pop(); n       } else { n         stack<pair<int, int> >().swap(st); n         sqb = 0; n       } n     } else if (s[i] ==  ] ) { n       if (st.size() > 0 && s[st.top().first] ==  [ ) { n         sqb += st.top().second + 1; n         if (best < sqb) { n           best = sqb; n           rr = i; n         } n         st.pop(); n       } else { n         stack<pair<int, int> >().swap(st); n         sqb = 0; n       } n     } n   } n   s[rr + 1] = 0; n   int ll = rr; n   stack<int> out; n   for (int i = rr; i >= 0; --i) { n     if (s[i] ==  )  || s[i] ==  ] ) { n       out.push(i); n     } else if (s[i] ==  ( ) { n       if (out.size() > 0 && s[out.top()] ==  ) ) { n         ll = i; n         out.pop(); n       } else n         break; n     } else if (s[i] ==  [ ) { n       if (out.size() > 0 && s[out.top()] ==  ] ) { n         ll = i; n         out.pop(); n       } else n         break; n     } n   } n   while (out.size() > 0) { n     ll = out.top() + 1; n     out.pop(); n   } n   printf( %d n , best); n   puts(s + ll); n   return 0; n } n


#include <bits/stdc++.h> n template <int MOD_> n struct modnum { n   static constexpr int MOD = MOD_; n   static_assert(MOD_ > 0,  MOD must be positive ); n  n  private: n   using ll = long long; n   int v; n   static int minv(int a, int m) { n     a %= m; n     assert(a); n     return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a); n   } n  n  public: n   modnum() : v(0) {} n   modnum(ll v_) : v(int(v_ % MOD)) { n     if (v < 0) v += MOD; n   } n   explicit operator int() const { return v; } n   friend std::ostream& operator<<(std::ostream& out, const modnum& n) { n     return out << int(n); n   } n   friend std::istream& operator>>(std::istream& in, modnum& n) { n     ll v_; n     in >> v_; n     n = modnum(v_); n     return in; n   } n   friend bool operator==(const modnum& a, const modnum& b) { n     return a.v == b.v; n   } n   friend bool operator!=(const modnum& a, const modnum& b) { n     return a.v != b.v; n   } n   modnum inv() const { n     modnum res; n     res.v = minv(v, MOD); n     return res; n   } n   friend modnum inv(const modnum& m) { return m.inv(); } n   modnum neg() const { n     modnum res; n     res.v = v ? MOD - v : 0; n     return res; n   } n   friend modnum neg(const modnum& m) { return m.neg(); } n   modnum operator-() const { return neg(); } n   modnum operator+() const { return modnum(*this); } n   modnum& operator++() { n     v++; n     if (v == MOD) v = 0; n     return *this; n   } n   modnum& operator--() { n     if (v == 0) v = MOD; n     v--; n     return *this; n   } n   modnum& operator+=(const modnum& o) { n     v += o.v; n     if (v >= MOD) v -= MOD; n     return *this; n   } n   modnum& operator-=(const modnum& o) { n     v -= o.v; n     if (v < 0) v += MOD; n     return *this; n   } n   modnum& operator*=(const modnum& o) { n     v = int(ll(v) * ll(o.v) % MOD); n     return *this; n   } n   modnum& operator/=(const modnum& o) { return *this *= o.inv(); } n   friend modnum operator++(modnum& a, int) { n     modnum r = a; n     ++a; n     return r; n   } n   friend modnum operator--(modnum& a, int) { n     modnum r = a; n     --a; n     return r; n   } n   friend modnum operator+(const modnum& a, const modnum& b) { n     return modnum(a) += b; n   } n   friend modnum operator-(const modnum& a, const modnum& b) { n     return modnum(a) -= b; n   } n   friend modnum operator*(const modnum& a, const modnum& b) { n     return modnum(a) *= b; n   } n   friend modnum operator/(const modnum& a, const modnum& b) { n     return modnum(a) /= b; n   } n }; n int main() { n   using namespace std; n   ios_base::sync_with_stdio(false), cin.tie(nullptr); n   using num = modnum<int(1e9) + 7>; n   int Q; n   cin >> Q; n   string A; n   cin >> A; n   vector<num> dp(int(A.size()) + 1, num(1)); n   Q--; n   while (Q--) { n     string B; n     cin >> B; n     vector<num> ndp(int(B.size()) + 1, num(0)); n     int Asize = int(A.size()); n     int Bsize = int(B.size()); n     int L = max(Asize + 1, Bsize + 1); n     A.resize(L + 1,  $ ); n     B.resize(L + 1,  % ); n     dp.resize(L + 1, num(0)); n     ndp.resize(L, num(0)); n     vector<array<array<num, 2>, 2>> pref_dp(L); n     pref_dp[0][0][0]++; n     for (int i = 0; i < L; i++) { n       for (int z : {0, 1}) { n         pref_dp[i][1][z] += dp[i] * pref_dp[i][0][z]; n       } n       if (i + 1 == L) break; n       for (int z : {0, 1}) { n         pref_dp[i + 1][z][1] += pref_dp[i][z][1]; n         if (A[i + z] == B[i]) { n           pref_dp[i + 1][z][0] += pref_dp[i][z][0]; n         } else if (A[i + z] < B[i]) { n           pref_dp[i + 1][z][1] += pref_dp[i][z][0]; n         } n       } n     } n     bool suff_less = true; n     num ways_suff = num(0); n     num ways_suff_less = num(0); n     for (int i = L - 1; i >= 0; i--) { n       ways_suff += dp[i + 1]; n       if (suff_less) { n         ways_suff_less += dp[i + 1]; n       } n       if (A[i] < B[i + 1]) { n         ways_suff_less = ways_suff; n       } else if (A[i] > B[i + 1]) { n         ways_suff_less = 0; n       } n       if (A[i + 1] != B[i + 1]) { n         suff_less = A[i + 1] < B[i + 1]; n       } n       ndp[i] += ways_suff_less * pref_dp[i][0][0]; n       ndp[i] += suff_less * pref_dp[i][1][0]; n       ndp[i] += ways_suff * pref_dp[i][0][1]; n       ndp[i] += pref_dp[i][1][1]; n     } n     A.resize(Asize); n     B.resize(Bsize); n     dp.resize(Asize + 1); n     ndp.resize(Bsize + 1); n     A = std::move(B); n     dp = std::move(ndp); n   } n   num ans = accumulate(dp.begin(), dp.end(), num(0)); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[] = {0, 0, 1, -1}; n int dy[] = {-1, 1, 0, 0}; n template <class T> n T power(T N, T P) { n   return (P == 0) ? 1 : N * power(N, P - 1); n } n template <class T> n T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n struct debugger { n   template <typename T> n   debugger& operator,(const T& v) { n     cerr << v <<    ; n     return *this; n   } n } dbg; n void make_unique(vector<int>& a) { n   sort(a.begin(), a.end()); n   a.erase(unique(a.begin(), a.end()), a.end()); n } n int on(int n, int pos) { return n = n | (1 << pos); } n void off(int& n, int pos) { n = n & ~(1 << pos); } n bool check(int n, int pos) { return (bool)(n & (1 << pos)); } n const int N = 1e5 + 10; n const int M = 64; n int id, cnt[M * N], a[N * M][5]; n int new_node() { n   for (int i = 0; i < 3; i++) { n     a[id][i] = -1; n   } n   cnt[id] = 0; n   return id++; n } n vector<int> bit(70); n void make(long long int x) { n   bit.clear(); n   int i = 0; n   while (x) { n     bit.push_back(x % 2); n     x /= 2LL; n     i++; n   } n   while (i < M - 1) { n     bit.push_back(0LL); n     i++; n   } n   reverse(bit.begin(), bit.end()); n } n void add(long long int x) { n   make(x); n   int cur = 0, typ; n   for (int i = 0; i < M; i++) { n     typ = bit[i]; n     if (a[cur][typ] == -1) { n       a[cur][typ] = new_node(); n     } n     cur = a[cur][typ]; n     ++cnt[cur]; n   } n } n void del(long long int x) { n   make(x); n   int cur = 0, typ; n   for (int i = 0; i < M; i++) { n     typ = bit[i]; n     cur = a[cur][typ]; n     --cnt[cur]; n   } n } n long long int query(long long int x) { n   make(x); n   int cur = 0, typ; n   long long int ans = 0LL; n   for (int i = 0; i < M; i++) { n     typ = bit[i]; n     if (cnt[a[cur][!typ]] > 0) { n       ans += (1LL << (M - i - 2)); n       cur = a[cur][!typ]; n     } else { n       if (a[cur][typ] == -1) return ans; n       cur = a[cur][typ]; n     } n   } n   return ans; n } n long long int arr[N]; n int main() { n   int n; n   while (scanf( %d , &n) != EOF) { n     id = 0; n     new_node(); n     for (__typeof(n) i = 1; i <= n; i++) { n       scanf( %lld , &arr[i]); n     } n     long long int xr = 0LL; n     for (int i = n; i >= 1; i--) { n       xr ^= arr[i]; n       add(xr); n     } n     long long int mx = 0LL; n     long long int nw = 0LL; n     mx = max(mx, query(nw)); n     for (int i = 1; i <= n; i++) { n       nw ^= arr[i]; n       mx = max(mx, query(nw)); n       del(xr); n       xr ^= arr[i]; n     } n     printf( %lld n , mx); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q = 1, i, j; n   while (q--) { n     int n, r; n     cin >> r >> n; n     vector<int> t(n + 1), x(n + 1), y(n + 1); n     t[0] = 0, x[0] = 1, y[0] = 1; n     for (i = 1; i < (n + 1); i++) { n       cin >> t[i] >> x[i] >> y[i]; n     } n     vector<int> dp(n + 1, INT_MIN), pref(n + 1, INT_MIN); n     dp[0] = 0; n     for (i = 1; i < (n + 1); i++) { n       dp[i] = 1 + pref[max(i - 2 * r, 0)]; n       for (j = max(0, i - 2 * r + 1); j < (i); j++) { n         if (t[i] - t[j] >= abs(x[i] - x[j]) + abs(y[i] - y[j])) { n           dp[i] = max(dp[i], dp[j] + 1); n         } n       } n       pref[i] = max({dp[i], pref[i - 1], 0}); n     } n     cout << pref[n] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   int n, m, a; n   cin >> n >> m; n   int l = 1, mx = 0; n   for (int i = 0; i < n; i++) { n     cin >> a; n     if ((a + m - 1) / m >= mx) { n       mx = (a + m - 1) / m; n       l = i + 1; n     } n   } n   cout << l << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long const M = 2000 + 10, M2 = 1e7 + 10, mod = 1e9 + 7, inf = 1e9 + 10, n                 sq = 450; n long long a[M][M], ro[M], col[M], all[M]; n int32_t main() { n   long long n, ans = 0; n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     string x; n     cin >> x; n     for (long long j = 0; j < x.size(); j++) { n       a[i][j + 1] = x[j] -  0 ; n     } n   } n   for (long long i = 1; i <= n; i++) { n     for (long long j = n; j > i; j--) { n       long long good = col[j] xor ro[i]; n       long long need = good xor a[i][j]; n       ro[i] = ro[i] xor need; n       all[i] = all[i] xor need; n       col[j] = col[j] xor need; n       all[j] = all[j] xor need; n       ans += need; n     } n   } n   for (long long i = 1; i <= n; i++) col[i] = 0, ro[i] = 0; n   for (long long i = n; i >= 1; i--) { n     for (long long j = 1; j < i; j++) { n       long long good = col[j] xor ro[i]; n       long long need = good xor a[i][j]; n       ro[i] = ro[i] xor need; n       all[i] = all[i] = all[i] xor need; n       col[j] = col[j] xor need; n       all[j] = all[j] xor need; n       ans += need; n     } n   } n   for (long long i = 1; i <= n; i++) { n     ans += all[i] xor a[i][i]; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, m; n   cin >> n >> m; n   long long a[n], b[m]; n   for (long long i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   for (long long i = 0; i < m; ++i) { n     cin >> b[i]; n   } n   long long ans = INF; n   for (long long i = 0; i < n; ++i) { n     long long res = -INF; n     for (long long j = 0; j < n; ++j) { n       if (i != j) { n         for (long long k = 0; k < m; ++k) { n           res = max(res, a[j] * b[k]); n         } n       } n     } n     ans = min(ans, res); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int n, x[maxn], y[maxn]; n int solve(set<pair<int, int> >& a, set<pair<int, int> >& b) { n   set<pair<int, int> >::iterator itl = a.begin(), itd = b.begin(), it1; n   set<pair<int, int> >::reverse_iterator itr = a.rbegin(), itu = b.rbegin(), n                                          it2; n   set<pair<int, int> > f, s; n   bool chk = false; n   for (int i = 0; i < a.size() - 1; ++i) { n     if (next(itl)->first > itl->first + 1) { n       chk = true; n       for (it1 = a.begin(); it1 != next(itl); ++it1) { n         f.insert({x[it1->second], it1->second}); n       } n     } else if (next(itd)->first > itd->first + 1) { n       chk = true; n       for (it1 = b.begin(); it1 != next(itd); ++it1) { n         f.insert({x[it1->second], it1->second}); n       } n     } else if (next(itr)->first + 1 < itr->first) { n       chk = true; n       for (it2 = a.rbegin(); it2 != next(itr); ++it2) { n         f.insert({x[it2->second], it2->second}); n       } n     } else if (next(itu)->first + 1 < itu->first) { n       chk = true; n       for (it2 = b.rbegin(); it2 != next(itu); it2++) { n         f.insert({x[it2->second], it2->second}); n       } n     } n     if (chk) { n       for (auto u : f) { n         s.insert({y[u.second], u.second}); n         b.erase({y[u.second], u.second}); n         a.erase(u); n       } n       return solve(a, b) + solve(f, s); n     } n     itl++; n     itr++; n     itd++; n     itu++; n   } n   return 1; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   set<pair<int, int> > xs, ys; n   for (int i = 0; i < n; ++i) { n     cin >> x[i] >> y[i]; n     xs.insert({x[i], i}); n     ys.insert({y[i], i}); n   } n   cout << solve(xs, ys); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int t = 1, i, j, n; n   long long int p, q, temp, arr[90]; n   for (j = 0; j < t; j++) { n     scanf( %lld %lld , &p, &q); n     scanf( %d , &n); n     for (i = 0; i < n; i++) scanf( %lld , &arr[i]); n     for (i = 0; i < n; i++) { n       if (p / q < arr[i]) { n         printf( NO n ); n         break; n       } n       p = p - (q * arr[i]); n       if (p == 0 && i != n - 1) { n         printf( NO n ); n         break; n       } n       if (i != n - 1) { n         temp = p; n         p = q; n         q = temp; n       } n     } n     if (p == 0 && i == n) n       printf( YES n ); n     else if (i == n) n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int bits = 1000; n bitset<bits> node[4 * 100060]; n long long int leftOver[4 * 100060]; n int n; n int treeSize[100060]; n vector<int> adj[100060]; n int dfsOrder[100060]; n int o = 1; n void dfs(int curr = 1, int par = -1) { n   treeSize[curr] = 1; n   dfsOrder[curr] = o++; n   for (int nxt : adj[curr]) { n     if (nxt != par) { n       dfs(nxt, curr); n       treeSize[curr] += treeSize[nxt]; n     } n   } n } n int m; n bitset<bits> rotate(std::bitset<bits> b, unsigned k) { n   b = b << (k) | b >> (m - (k)); n   b = b | (b >> m); n   return b; n } n void build(int pos, int bit, int id = 1, int l = 1, int r = n) { n   if (l == r) { n     node[id][bit] = 1; n     return; n   } n   int mid = (l + r) >> 1; n   if (pos <= mid) n     build(pos, bit, id << 1, l, mid); n   else n     build(pos, bit, (id << 1) + 1, mid + 1, r); n   node[id] = node[id << 1] | node[(id << 1) + 1]; n } n void push(int id) { n   if (leftOver[id] > 0) { n     leftOver[id << 1] = (leftOver[id] + leftOver[id << 1]) % m; n     leftOver[(id << 1) + 1] = (leftOver[id] + leftOver[(id << 1) + 1]) % m; n     leftOver[id] = 0; n   } n } n void add(int val, int L, int R, int id = 1, int l = 1, int r = n) { n   if (L <= l && r <= R) { n     leftOver[id] = (leftOver[id] + val) % m; n     return; n   } n   push(id); n   int mid = (l + r) >> 1; n   if (L <= mid) add(val, L, R, id << 1, l, mid); n   if (R > mid) add(val, L, R, (id << 1) + 1, mid + 1, r); n   node[id] = rotate(node[id << 1], leftOver[id << 1]) | n              rotate(node[(id << 1) + 1], leftOver[(id << 1) + 1]); n } n bitset<bits> ans; n void query(int qL, int qR, int id = 1, int l = 1, int r = n) { n   if (qL <= l && qR >= r) { n     ans = ans | rotate(node[id], leftOver[id]); n     return; n   } n   push(id); n   int mid = (l + r) >> 1; n   if (qL <= mid) query(qL, qR, id << 1, l, mid); n   if (qR > mid) query(qL, qR, (id << 1) + 1, mid + 1, r); n   node[id] = rotate(node[id << 1], leftOver[id << 1]) | n              rotate(node[(id << 1) + 1], leftOver[(id << 1) + 1]); n } n vector<int> primes; n vector<int> sieve(int limit) { n   vector<int> primes; n   bool in[limit + 1]; n   memset(in, true, sizeof(in)); n   for (int i = 2; i <= limit; i++) { n     if (in[i]) { n       primes.push_back(i); n       for (int j = i; j <= limit; j += i) in[j] = false; n     } n   } n   return primes; n } n int a[100060]; n int aTemp[100060]; n int addBrute(int l, int r, int x) { n   for (int i = l; i < r + 1; i++) a[i] = (a[i] + x) % m; n } n bitset<bits> findBrute(int l, int r) { n   bitset<bits> temp = 0; n   for (int i = l; i < r + 1; i++) temp[a[i] % m] = 1; n   return temp; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int q; n   cin >> n >> m; n   primes = sieve(m); n   for (int i = 0; i < n; i++) cin >> a[i + 1]; n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     cin >> x >> y; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   dfs(); n   for (int i = 0; i < n; i++) { n     build(dfsOrder[i + 1], a[i + 1] % m); n   } n   for (int i = 1; i < n + 1; i++) { n     aTemp[dfsOrder[i]] = a[i]; n   } n   for (int i = 1; i < n + 1; i++) { n     a[i] = aTemp[i]; n   } n   cin >> q; n   for (int i = 0; i < q; i++) { n     int t, v; n     cin >> t >> v; n     if (t == 1) { n       int x; n       cin >> x; n       add(x % m, dfsOrder[v], dfsOrder[v] + treeSize[v] - 1); n     } else { n       ans = 0; n       query(dfsOrder[v], dfsOrder[v] + treeSize[v] - 1); n       int k = 0; n       for (int j = 0; j < primes.size(); j++) { n         if (primes[j] < m) { n           if (ans[primes[j]]) { n             k++; n           } n         } n       } n       cout << k <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n struct seg { n   vector<int> t; n   int n; n   seg(int n = 0) : t(2 * n), n(n) {} n   int query(int l, int r) { n     int ans = 0; n     for (l += n, r += n; l < r; l >>= 1, r >>= 1) { n       if (l & 1) ans += t[l++]; n       if (r & 1) ans += t[--r]; n     } n     return ans; n   } n   void update(int p, int v) { n     for (t[p += n] += v; p > 1; p >>= 1) { n       t[p >> 1] = t[p] + t[p ^ 1]; n     } n   } n }; n seg s[4][11][10]; n void modify(int p, int c, int m) { n   for (int i = 1; i <= 10; i++) { n     s[c][i][p % i].update(p, m); n   } n } n void convert(string& s) { n   for (char& c : s) { n     switch (c) { n       case  A : n         c = 0; n         break; n       case  T : n         c = 1; n         break; n       case  C : n         c = 2; n         break; n       case  G : n         c = 3; n         break; n     } n   } n } n int main() { n   string k; n   cin >> k; n   convert(k); n   for (int i = 0; i < 4; i++) { n     for (int j = 1; j <= 10; j++) { n       for (int l = 0; l < j; l++) { n         s[i][j][l] = seg(k.size()); n       } n     } n   } n   for (int i = 0; i < k.size(); i++) { n     modify(i, k[i], 1); n   } n   int q; n   cin >> q; n   while (q--) { n     int op; n     cin >> op; n     if (op == 1) { n       int x; n       string c; n       cin >> x >> c; n       convert(c); n       x--; n       modify(x, k[x], -1); n       k[x] = c[0]; n       modify(x, k[x], 1); n     } else { n       int l, r; n       cin >> l >> r; n       l--; n       string e; n       cin >> e; n       convert(e); n       int a = 0; n       for (int i = l; i < l + e.size(); i++) { n         a += s[e[i - l]][e.size()][i % e.size()].query(l, r); n       } n       cout << a <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1}; n const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, n           d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1}; n void DBG() { cout <<  ]  << endl; } n template <class H, class... T> n void DBG(H h, T... t) { n   cout << to_string(h); n   if (sizeof...(t)) cout <<  ,  ; n   DBG(t...); n } n template <class T> n bool umin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool umax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n int n; n vector<pair<long long, long long>> cards[(long long)(200002)], n     need[(long long)(200002)]; n vector<array<long long, 3>> valid[(long long)(200002)]; n void prepare() { n   for (int i = (1), _c = (n); i <= _c; ++i) { n     vector<int> cnt(4, 0); n     sort((cards[i]).begin(), (cards[i]).end(), n          [](pair<long long, long long> a, pair<long long, long long> b) { n            return a.first < b.first || n                   (a.first == b.first && a.second > b.second); n          }); n     for (auto j : cards[i]) { n       if (j.first == 1 && cnt[j.first] >= 3) continue; n       if (j.first == 2 && cnt[j.first] >= 1) continue; n       if (j.first == 3 && cnt[j.first] >= 1) continue; n       need[i].push_back(j); n       ++cnt[j.first]; n     } n   } n   for (int i = (1), _c = (n); i <= _c; ++i) { n     for (int j = (0), _c = ((1ll << (((int)((need[i]).size())))) - 1); j <= _c; n          ++j) { n       long long cost = 0, ma = 0, dame = 0; n       for (int k = (0), _c = (((int)((need[i]).size())) - 1); k <= _c; ++k) { n         if ((((j) >> (k)) & 1ll)) { n           cost += need[i][k].first; n           dame += need[i][k].second; n           umax(ma, need[i][k].second); n         } n       } n       if (cost <= 3) { n         int bonus = __builtin_popcountll(j); n         valid[i].push_back({bonus, dame, ma}); n       } n     } n   } n } n long long dp[(long long)(200002)][11]; n void test_case() { n   cin >> n; n   for (int i = (1), _c = (n); i <= _c; ++i) { n     int k; n     cin >> k; n     cards[i].assign(k, {0, 0}); n     for (int j = (0), _c = (k - 1); j <= _c; ++j) n       cin >> cards[i][j].first >> cards[i][j].second; n   } n   prepare(); n   for (auto i : valid[1]) umax(dp[1][i[0]], i[1]); n   for (int i = (1), _c = (n - 1); i <= _c; ++i) n     for (int j = (0), _c = (10); j <= _c; ++j) n       if (dp[i][j] || j == 0) { n         for (auto k : valid[i + 1]) { n           int nxtNum = j + k[0]; n           if (nxtNum < 10) n             umax(dp[i + 1][nxtNum], dp[i][j] + k[1]); n           else n             umax(dp[i + 1][nxtNum % 10], dp[i][j] + k[1] + k[2]); n         } n       } n   long long ans = 0; n   for (int i = (0), _c = (10); i <= _c; ++i) umax(ans, dp[n][i]); n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   auto time = clock(); n   int test = 1; n   while (test--) { n     test_case(); n   } n   cerr <<  [It took   << fixed << setprecision(3) n        << double(clock() - time) / CLOCKS_PER_SEC <<  s]  n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Get(int &T) { n   char C; n   bool F = 0; n   for (; C = getchar(), C <  0  || C >  9 ;) n     if (C ==  - ) F = 1; n   for (T = C -  0 ; C = getchar(), C >=  0  && C <=  9 ; T = T * 10 + C -  0 ) n     ; n   F && (T = -T); n } n int N; n void Init() { Get(N); } n int T[55][55]; n void Mul(int A[][55], int B[][55], int N, int K, int M) { n   for (int i = 1; i <= N; i++) n     for (int j = 1; j <= M; j++) { n       T[i][j] = 0; n       for (int k = 1; k <= K; k++) (T[i][j] ^= (A[i][k] & B[k][j])); n     } n   for (int i = 1; i <= N; i++) n     for (int j = 1; j <= M; j++) A[i][j] = T[i][j]; n } n int A[55][55]; n int B[55][55]; n int T2[55][55]; n void Pow(int X[][55], long long P) { n   for (int i = 1; i <= N; i++) n     for (int j = 1; j <= N; j++) T2[i][j] = (i == j); n   for (; P; P >>= 1) { n     if (P & 1) Mul(T2, X, N, N, N); n     Mul(X, X, N, N, N); n   } n   for (int i = 1; i <= N; i++) n     for (int j = 1; j <= N; j++) X[i][j] = T2[i][j]; n } n long long Factor[100005]; n int FactorTop; n bool I() { n   for (int i = 1; i <= N; i++) n     for (int j = 1; j <= N; j++) n       if (B[i][j] != (i == j)) return 0; n   return 1; n } n bool Check() { n   for (int i = 1; i <= N; i++) n     for (int j = 1; j <= N; j++) B[i][j] = A[i][j]; n   Pow(B, (1ll << N) - 1); n   int Ans = I(); n   if (Ans == 0) return 0; n   for (int k = 1; k <= FactorTop; k++) { n     for (int i = 1; i <= N; i++) n       for (int j = 1; j <= N; j++) B[i][j] = A[i][j]; n     Pow(B, ((1ll << N) - 1) / Factor[k]); n     int Ans = I(); n     if (Ans == 1) return 0; n   } n   return 1; n } n void Debug() { n   FactorTop = 0; n   long long X = 1ll << N; n   X--; n   Factor[0] = 1; n   for (long long i = 2; i * i <= X; i++) { n     for (;; X /= i) { n       if (X % i != 0) break; n       Factor[++FactorTop] = i; n     } n   } n   if (X > 1) Factor[++FactorTop] = X; n   for (int i = 1; i < N; i++) A[i + 1][i] = 1; n   for (;;) { n     for (int i = 1; i <= N; i++) A[i][N] = rand() & 1; n     int Ans = Check(); n     if (Ans) break; n   } n } n void Work() { Debug(); } n void Output() { n   for (int i = N; i >= 1; i--) printf( %d  , A[i][N]); n   puts(  ); n   for (int i = N; i >= 1; i--) printf( %d  , 1); n   puts(  ); n } n int main() { n   srand(time(0)); n   Init(); n   Work(); n   Output(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t; n long long n; n long long tmp; n long long gcd(long long a, long long b) { n   long long temp; n   if (a < b) { n     temp = a; n     a = b; n     b = temp; n   } n   while (b != 0) { n     temp = a % b; n     a = b; n     b = temp; n   } n   return a; n } n long long lcm(long long a, long long b) { n   long long temp_lcm; n   temp_lcm = a * b / gcd(a, b); n   return temp_lcm; n } n int main() { n   cin >> t; n   while (t--) { n     cin >> n; n     if (n % 2 == 0) { n       long long a, b; n       tmp = n / 2; n       while (tmp--) { n         cin >> a >> b; n         cout << b <<     << -a <<    ; n       } n       cout << endl; n     } else { n       long long a, b, c; n       tmp = (n - 2) / 2; n       while (tmp--) { n         cin >> a >> b; n         cout << b <<     << -a <<    ; n       } n       cin >> a >> b >> c; n       tmp = lcm(a, b); n       tmp = lcm(tmp, c); n       cout << tmp / a <<     << tmp / b <<     << -2 * tmp / c; n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int max = 0, min = 0; n   int a[m], b[m]; n   for (int i = 0; i < m; i++) { n     cin >> a[i]; n     b[i] = a[i]; n   } n   sort(a, a + m, greater<int>()); n   for (int i = 0; i < n; i++) { n     if (a[0] != 0) { n       max = max + a[0]; n       a[0] = a[0] - 1; n       sort(a, a + m, greater<int>()); n     } else { n       break; n     } n   } n   sort(b, b + m); n   int i = 0, k = 0; n   while (i != n) { n     if (b[k] != 0) { n       min = min + b[k]; n       b[k] = b[k] - 1; n     } else { n       k++; n       min = min + b[k]; n       b[k] = b[k] - 1; n     } n     i++; n   } n   cout << max <<     << min; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isPrime[1000005] = {false}; n vector<long long int> SPF(1000005); n long long int fastPower(long long int a, long long int b) { n   if (b == 0) return 1; n   long long int prod = 1; n   while (b > 0) { n     if (b & 1) prod = prod * a; n     b = b >> 1; n     a = a * a; n   } n   return prod; n } n void sieve() { n   int i; n   for (i = 2; i < 1000005; ++i) isPrime[i] = 1; n   for (i = 2; i * i < 1000005; ++i) { n     if (isPrime[i]) { n       for (int j = i * i; j < 1000005; j += i) isPrime[j] = 0; n     } n   } n } n void printa(bool f) { n   if (f) n     cout <<  YES ; n   else n     cout <<  NO ; n   cout <<   n ; n } n bool flip(bool f) { n   if (f) return 0; n   return 1; n } n void solve() { n   long long int i, n; n   cin >> n; n   vector<long long int> a(n); n   for (i = 0; i < n; ++i) cin >> a[i]; n   sort(a.begin(), a.end()); n   long long int s = 0, m = a[n - 1]; n   for (i = 0; i < n - 1; ++i) s += a[i]; n   cout << abs(m - s) + 1 <<   n ; n } n int main() { n   int tc = 1; n   while (tc--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int m, n, p, count = 0; n   cin >> m >> n; n   if (m % n == 0) n     cout << m / n; n   else { n     count = count + (m / n); n     m = m % n; n     for (;;) { n       if (m > n) { n         if (m % n == 0) { n           count += m / n; n           break; n         } n         m = m - n; n         count++; n       } else if (n > m) { n         if (n % m == 0) { n           count += n / m; n           break; n         } n         n = n - m; n         count++; n       } n     } n     cout << count; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 5; n const int MAXM = 20; n int n, m; n int a[MAXN], b[MAXM]; n int num[MAXM]; n char ans[MAXN][MAXM]; n set<int> states[MAXM]; n int getState(int mask, int num[MAXM]) { n   int res = mask; n   for (int i = 0; i < n; ++i) { n     res = res * MAXN + num[i]; n   } n   return res; n } n bool dfs(int j, int lastState = 0) { n   if (j == m) { n     for (int i = 0; i < n; ++i) { n       if (num[i] != a[i]) { n         return false; n       } n     } n     return true; n   } n   if (j) { n     if (states[j].find(lastState) != states[j].end()) { n       return false; n     } n     states[j].insert(lastState); n   } n   int origin[MAXM]; n   memcpy(origin, num, sizeof(num)); n   for (int k = 0; k < (1 << n); ++k) { n     int cnt = 0; n     for (int i = 0; i < n; ++i) { n       if (k & (1 << i)) { n         ans[i][j] =  * ; n         if (i == 0 || ans[i - 1][j] ==  . ) { n           ++cnt; n         } n       } else { n         ans[i][j] =  . ; n       } n     } n     if (cnt != b[j]) { n       continue; n     } n     for (int i = 0; i < n; ++i) { n       if (ans[i][j] ==  * ) { n         if (j == 0 || ans[i][j - 1] ==  . ) { n           ++num[i]; n         } n       } n     } n     bool valid = true; n     for (int i = 0; i < n; ++i) { n       if (num[i] > a[i]) { n         valid = false; n         break; n       } n       if (ans[i][j] ==  * ) { n         if (a[i] - num[i] > (m - j - 1) / 2) { n           valid = false; n           break; n         } n       } else { n         if (a[i] - num[i] > (m - j) / 2) { n           valid = false; n           break; n         } n       } n     } n     if (valid) { n       if (dfs(j + 1, getState(k, num))) { n         return true; n       } n     } n     memcpy(num, origin, sizeof(origin)); n   } n   return false; n } n int main() { n   while (cin >> n >> m) { 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     for (int i = 0; i < n; ++i) { n       states[i].clear(); n     } n     memset(num, 0, sizeof(num)); n     dfs(0); n     for (int i = 0; i < n; ++i) { n       for (int j = 0; j < m; ++j) { n         cout << ans[i][j]; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100500; n const int INF = 2 * (1e9); n int n, m; n vector<pair<int, int> > edge[N]; n vector<pair<int, int> > delay[N]; n int dist[N]; n int main() { n   cin.sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int from, to, len; n     cin >> from >> to >> len; n     from--; n     to--; n     edge[from].push_back(make_pair(to, len)); n     edge[to].push_back(make_pair(from, len)); n   } n   for (int i = 0; i < n; i++) { n     int num; n     cin >> num; n     int cur; n     for (int j = 0; j < num; j++) { n       cin >> cur; n       if (j == 0 or delay[i].back().second != cur) n         delay[i].push_back(make_pair(cur, cur + 1)); n       else n         delay[i].back().second++; n     } n   } n   for (int i = 0; i < n; i++) dist[i] = INF; n   dist[0] = 0; n   if (delay[0].size() >= 1 and delay[0][0].first == 0) n     dist[0] = delay[0][0].second; n   set<pair<int, int> > dijkstra; n   dijkstra.insert(make_pair(dist[0], 0)); n   for (int i = 0; i < n; i++) { n     if (dijkstra.empty()) break; n     pair<int, int> now = *dijkstra.begin(); n     dijkstra.erase(now); n     for (const pair<int, int> &next : edge[now.second]) { n       int arrival = next.first; n       int tm = next.second + now.first; n       int idx = lower_bound(delay[arrival].begin(), delay[arrival].end(), n                             make_pair(tm, INF)) - n                 delay[arrival].begin(); n       if (idx > 0 and arrival != n - 1) { n         idx--; n         if (delay[arrival][idx].first <= tm and tm < delay[arrival][idx].second) n           tm = delay[arrival][idx].second; n       } n       if (dist[arrival] > tm) { n         dijkstra.erase(make_pair(dist[arrival], arrival)); n         dist[arrival] = tm; n         dijkstra.insert(make_pair(dist[arrival], arrival)); n       } n     } n   } n   if (dist[n - 1] == INF) dist[n - 1] = -1; n   cout << dist[n - 1] << endl; n   return 0; n } n


#include <cstdio> n #include <vector> n #include <cstring> n #include <algorithm> n const int Maxn=200000; n const int Inf=0x3f3f3f3f; n int n; n int a[Maxn+5]; n std::vector<int> v_lis[Maxn+5]; n struct Segment_Tree{ n  struct Segment_Node{ n   int minn,maxn; n   int lazy; n  }seg[Maxn<<2|5]; n  void update_tag(int root,int a){ n   seg[root].lazy+=a; n   seg[root].minn+=a,seg[root].maxn+=a; n  } n  void push_up(int root){ n   seg[root].minn=std::min(seg[root<<1].minn,seg[root<<1|1].minn); n   seg[root].maxn=std::max(seg[root<<1].maxn,seg[root<<1|1].maxn); n  } n  void push_down(int root){ n   if(seg[root].lazy==0){ n    return; n   } n   update_tag(root<<1,seg[root].lazy); n   update_tag(root<<1|1,seg[root].lazy); n   seg[root].lazy=0; n  } n  void update(int l,int r,int v,int root=1,int left=0,int right=n){ n   if(l>right||r<left){ n    return; n   } n   if(l<=left&&r>=right){ n    update_tag(root,v); n    return; n   } n   push_down(root); n   int mid=(left+right)>>1; n   update(l,r,v,root<<1,left,mid); n   update(l,r,v,root<<1|1,mid+1,right); n   push_up(root); n  } n  int query_min(int l,int r,int root=1,int left=0,int right=n){ n   if(l>right||r<left){ n    return Inf; n   } n   if(l<=left&&r>=right){ n    return seg[root].minn; n   } n   push_down(root); n   int mid=(left+right)>>1; n   return std::min(query_min(l,r,root<<1,left,mid),query_min(l,r,root<<1|1,mid+1,right)); n  } n  int query_max(int l,int r,int root=1,int left=0,int right=n){ n   if(l>right||r<left){ n    return -Inf; n   } n   if(l<=left&&r>=right){ n    return seg[root].maxn; n   } n   push_down(root); n   int mid=(left+right)>>1; n   return std::max(query_max(l,r,root<<1,left,mid),query_max(l,r,root<<1|1,mid+1,right)); n  } n }seg_1,seg_2; n int ans[Maxn+5]; n int main(){ n  scanf( %d ,&n); n  for(int i=1;i<=n;i++){ n   scanf( %d ,&a[i]); n   v_lis[a[i]].push_back(i); n  } n  for(int i=1;i<=n;i++){ n   seg_1.update(i>>1,(n-1)>>1,1); n   seg_2.update((i+1)>>1,n>>1,1); n  } n  for(int i=1;i<=n;i++){ n   for(int j=0;j<(int)v_lis[i].size();j++){ n    int pos=v_lis[i][j]; n    int pos_1_max=seg_1.query_max(pos>>1,(n-1)>>1); n    int pos_1_min=seg_1.query_min(0,(pos>>1)-1); n    int pos_2_max=seg_2.query_max((pos+1)>>1,n>>1); n    int pos_2_min=seg_2.query_min(0,(pos-1)>>1); n    ans[pos]=std::max(std::max((pos_2_max-pos_2_min)>>1,(pos_1_max-pos_1_min)>>1),  n    std::max((pos_2_max-pos_1_min-1)>>1,(pos_1_max-pos_2_min-1)>>1)); n   } n   for(int j=0;j<(int)v_lis[i].size();j++){ n    seg_1.update(v_lis[i][j]>>1,(n-1)>>1,-2); n    seg_2.update((v_lis[i][j]+1)>>1,n>>1,-2); n   } n   for(int j=0;j<(int)v_lis[i].size();j++){ n    int pos=v_lis[i][j]; n    int pos_1_min=seg_1.query_min(pos>>1,(n-1)>>1); n    int pos_1_max=seg_1.query_max(0,(pos>>1)-1); n    int pos_2_min=seg_2.query_min((pos+1)>>1,n>>1); n    int pos_2_max=seg_2.query_max(0,(pos-1)>>1); n    ans[pos]=std::max(ans[pos],std::max( n    std::max((pos_2_max-pos_2_min)>>1,(pos_1_max-pos_1_min)>>1)-1,  n    std::max((pos_2_max-pos_1_min-1)>>1,(pos_1_max-pos_2_min-1)>>1))); n   } n  } n  for(int i=1;i<=n;i++){ n   printf( %d  ,ans[i]); n  } n  puts(  );; n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> V[100005]; n int main() { n   int N, M, K, ans = 1; n   scanf( %d%d%d , &N, &M, &K); n   for (int i = 1; i <= N; ++i) { n     int c; n     scanf( %d , &c); n     V[c].push_back(i); n   } n   for (int c = 1; c <= M; ++c) { n     int L = V[c].size(), rem = 0, st = 0; n     for (int j = 1; j < L; ++j) { n       rem += V[c][j] - V[c][j - 1] - 1; n       while (rem > K) { n         rem -= V[c][st + 1] - V[c][st] - 1; n         ++st; n       } n       ans = max(ans, j - st + 1); n     } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n int main() { n   string s; n   cin >> s; n   string h = s.substr(0, 2); n   int hour = atoi(h.c_str()); n   string m = s.substr(3, 2); n   int minute = atoi(m.c_str()); n   long long time = 60 * hour + minute; n   long long add; n   cin >> add; n   long long sum = time + add; n   long long n = sum % (24 * 60); n   cout << setfill( 0 ) << setw(2) << right << (n / 60); n   cout <<  : ; n   cout << setfill( 0 ) << setw(2) << right << (n % 60) << endl; n   ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[7]; n int b[7]; n int main() { n   string s; n   int k; n   cin >> s >> k; n   int kol = 0; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  0 ) { n       kol++; n     } n   } n   if (kol < k) { n     cout << s.length() - 1; n   } else { n     kol = 0; n     int res = 0; n     for (int i = s.length() - 1; i >= 0; i--) { n       if (s[i] ==  0 ) { n         kol++; n       } else { n         res++; n       } n       if (kol == k) { n         cout << res; n         return 0; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s1[5010], s2[5010], str[5010]; n int num[30]; n int len1, len2; n int dfs(int k, int m) { n   if (!s1[k]) return m; n   for (int i = 0; i < 26; i++) n     if (num[i] && (m || (i >= s2[k] -  a ))) { n       str[k] = i +  a ; n       num[i]--; n       if (dfs(k + 1, m || (i > s2[k] -  a ))) return 1; n       num[i]++; n     } n   return 0; n } n int main() { n   while (EOF != scanf( %s %s , s1, s2)) { n     memset(num, 0, sizeof(num)); n     len1 = strlen(s1), len2 = strlen(s2); n     for (int i = 0; i < len1; i++) num[s1[i] -  a ]++; n     if (!dfs(0, 0)) n       printf( -1 n ); n     else { n       printf( %s n , str); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Rectangle { n   int x1; n   int x2; n   int y1; n   int y2; n   Rectangle() {} n   Rectangle(int a, int b, int c, int d) { n     x1 = a; n     y1 = b; n     x2 = c; n     y2 = d; n     if (x1 > x2) { n       swap(x1, x2); n     } n     if (y1 > y2) { n       swap(y1, y2); n     } n   } n   bool operator<(Rectangle r) const { n     if (x1 != r.x1) { n       return x1 < r.x1; n     } else if (x2 != r.x2) { n       return x2 < r.x2; n     } else if (y1 != r.y1) { n       return y1 < r.y1; n     } else { n       return y2 < r.y2; n     } n   } n }; n int Area(Rectangle r) { return (r.x2 - r.x1) * (r.y2 - r.y1); } n set<Rectangle> rec; n set<Rectangle> lines; n int main() { n   int W, H, N; n   scanf( %d , &W); n   ; n   scanf( %d , &H); n   ; n   scanf( %d , &N); n   ; n   rec.insert(Rectangle(0, 0, W, H)); n   for (int(n) = 0; n < (int)N; n++) { n     int a, b, c, d; n     scanf( %d , &a); n     ; n     scanf( %d , &b); n     ; n     scanf( %d , &c); n     ; n     scanf( %d , &d); n     ; n     lines.insert(Rectangle(a, b, c, d)); n   } n   for (int(n) = 0; n < (int)N; n++) { n     for (__typeof(rec).begin() t = rec.begin(); t != rec.end(); t++) { n       Rectangle r = *t; n       for (__typeof(lines).begin() it = lines.begin(); it != lines.end(); n            it++) { n         if (it->x1 == it->x2) { n           if (r.x1 < it->x1 && it->x2 < r.x2 && r.y1 == it->y1 && n               r.y2 == it->y2) { n             lines.erase(lines.find(*it)); n             rec.erase(*t); n             rec.insert(Rectangle(r.x1, r.y1, it->x2, r.y2)); n             rec.insert(Rectangle(it->x2, r.y1, r.x2, r.y2)); n             goto end; n           } n         } else if (it->y1 == it->y2) { n           if (r.y1 < it->y1 && it->y2 < r.y2 && r.x1 == it->x1 && n               r.x2 == it->x2) { n             lines.erase(lines.find(*it)); n             rec.erase(*t); n             rec.insert(Rectangle(r.x1, r.y1, r.x2, it->y1)); n             rec.insert(Rectangle(r.x1, it->y1, r.x2, r.y2)); n             goto end; n           } n         } n       } n     } n   end: n     int sol = 42; n   } n   vector<int> res; n   for (__typeof(rec).begin() it = rec.begin(); it != rec.end(); it++) { n     res.push_back(Area(*it)); n   } n   sort(res.begin(), res.end()); n   for (__typeof(res).begin() it = res.begin(); it != res.end(); it++) { n     printf(  %d , *it); n   } n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e3 + 10; n long long q, x, v, u, w, ans; n map<long long, long long> len; n int main() { n   cin >> q; n   for (int i = 1; i <= q; i++) { n     cin >> x >> v >> u; n     if (x == 1) { n       cin >> w; n       while (v != u) { n         if (v > u) { n           len[v] += w; n           v = v / 2; n         } else { n           len[u] += w; n           u = u / 2; n         } n       } n     } else { n       ans = 0; n       while (v != u) { n         if (v > u) { n           ans += len[v]; n           v = v / 2; n         } else { n           ans += len[u]; n           u = u / 2; n         } n       } n       cout << ans <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1000000000000000000ll; n long long x[6], y[6]; n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; n   if (n == 1) { n     cout << -1 << endl; n     return 0; n   } n   if (n == 2) { n     if (x[0] == x[1] || y[0] == y[1]) { n       cout << -1 << endl; n       return 0; n     } n     long long s = (abs(x[0] - x[1]) * abs(y[0] - y[1])); n     cout << s << endl; n     return 0; n   } n   long long X = 0, Y = 0; n   for (int i = 1; i < n; i++) { n     X = max(X, abs(x[0] - x[i])); n     Y = max(Y, abs(y[0] - y[i])); n   } n   cout << X * Y << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3f; n const int MOD = (int)1e9 + 7; n const int N = (int)3e5 + 7; n char read_char() { n   char c; n   for (;;) { n     c = getchar(); n     if (c >=  A  && c <=  Z ) return c; n   } n } n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= MOD; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % MOD; n     a = a * a % MOD; n   } n   return res; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long add(long long a, long long b) { n   a = ((a + b) % MOD + MOD) % MOD; n   return a; n } n long long mul(long long a, long long b) { return a * b % MOD; } n int n, p, cnt[N], tmp[N]; n pair<int, int> a[N]; n void Init() { n   memset(cnt, 0, sizeof(cnt)); n   for (int i = (0); i < (n); ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     if (u > v) swap(u, v); n     a[i].first = u, a[i].second = v; n     cnt[u]++; n     cnt[v]++; n   } n   for (int i = (1); i < (n + 1); ++i) tmp[i] = cnt[i]; n   sort(tmp + 1, tmp + n + 1); n   sort(a, a + n); n } n int Solve() { n   long long ans = 0; n   for (int i = n, j = 1; j < i; i--) { n     while (tmp[j] + tmp[i] < p && j < i) j++; n     ans += i - j; n   } n   for (int i = 0, j; i < n; i = j) { n     j = i + 1; n     while (j < n && a[i] == a[j]) j++; n     int u = a[i].first, v = a[i].second; n     if (cnt[u] + cnt[v] >= p && cnt[u] + cnt[v] - (j - i) < p) { n       ans--; n     } n   } n   return !printf( %lld n , ans); n } n int main() { n   while (~scanf( %d%d , &n, &p)) { n     Init(); n     Solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<long long, long long> s; n long long n, b[500005], c[500005]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     long long x; n     cin >> x; n     s[x]++; n   } n   long long m, mx1 = 0, mx2 = 0, index = 1; n   cin >> m; n   for (int i = 0; i < m; i++) { n     cin >> b[i]; n   } n   for (int i = 0; i < m; i++) { n     cin >> c[i]; n   } n   for (int i = 0; i < m; i++) { n     if (s[b[i]] > mx1) { n       mx1 = s[b[i]]; n       index = i + 1; n     } n   } n   for (int i = 0; i < m; i++) { n     if (s[b[i]] == mx1) { n       if (s[c[i]] > mx2) { n         index = i + 1; n         mx2 = s[c[i]]; n       } n     } n   } n   cout << index << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 1010; n const double EPS = 0.0000001; n struct Point { n   int x, y; n   Point() {} n   Point(int a, int b) : x(a), y(b) {} n }; n int n; n long long k; n Point centers[MAX_N]; n int radii[MAX_N]; n double GetDist(int x1, int y1, int x2, int y2) { n   return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); n } n void AddEvents(vector<pair<double, int> > &events, double ang1, double ang2) { n   for (int i = 0; i < 3; ++i) { n     events.push_back(make_pair(ang1 + i * 2 * M_PI + EPS, 1)); n     events.push_back(make_pair(ang2 + i * 2 * M_PI - EPS, -1)); n   } n } n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; ++i) { n     int x, y; n     cin >> x >> y >> radii[i]; n     centers[i] = Point(x, y); n   } n   int best = 0; n   for (int i = 1; i <= n; ++i) { n     vector<pair<double, int> > events; n     int cnt = 0; n     for (int j = 1; j <= n; ++j) { n       if (i != j) { n         double ang = n             atan2(centers[j].y - centers[i].y, centers[j].x - centers[i].x); n         double d = n             GetDist(centers[i].x, centers[i].y, centers[j].x, centers[j].y); n         double u1 = asin((radii[i] - radii[j]) / d); n         double u2 = asin((radii[i] + radii[j]) / d); n         AddEvents(events, ang + u1 - M_PI / 2, ang + u2 - M_PI / 2); n         AddEvents(events, ang - u2 + M_PI / 2, ang - u1 + M_PI / 2); n       } n     } n     sort(events.begin(), events.end()); n     for (size_t j = 0; j < events.size(); ++j) { n       cnt += events[j].second; n       if (cnt < 0) { n         cnt = 0; n       } n       best = max(best, cnt); n     } n   } n   long long sol = k * (k + 1) / 2 + (k + 1) * best + (n - best); n   cout << sol << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long calc(const long long &x, const long long &pow, const long long &pp) { n   long long res = 1, tmp = (x % pp); n   long long cur = pow; n   while (cur > 0) { n     if (cur % 2 == 0) { n       tmp = (tmp * tmp) % pp; n       cur = cur / 2; n     } else { n       res = (res * tmp) % pp; n       cur = cur - 1; n     } n   } n   return res; n } n int obr() { n   long long k, l, r, p; n   cin >> k >> l >> r >> p; n   long long ans; n   if (p == 2) { n     cout << (1 - (k % 2)) << endl; n     return 0; n   } n   if (k == 1) n     ans = 2 % p; n   else { n     long long st_l = calc(2, l, p - 1), st_r = calc(2, r + 1, p - 1); n     long long rev_2 = (p + 1) / 2; n     long long ch = (calc(k, st_r, p) + p - 1) % p; n     long long zn = (calc(k, st_l, p) + p - 1) % p; n     if (k % p == 0) zn = ch = p - 1; n     if (zn == 0) { n       ch = calc(2, r - l + 1, p); n     } else { n       zn = calc(zn, p - 2, p); n       ch = (ch * zn) % p; n     } n     if (k % 2) { n       long long to_div = calc(rev_2, r - l, p); n       ch = (ch * to_div) % p; n     } n     ans = ch; n   } n   cout << ans << endl; n   return 0; n } n int main() { n   ios_base::sync_with_stdio(false); n   int t; n   cin >> t; n   for (int i = 1; i <= t; ++i) obr(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int x[500010], y[500010]; n bitset<2010 * 2> A[2010]; n void Work() { n   for (int i = 1; i <= n; i++) { n     int t = i; n     for (int j = i + 1; j <= n; j++) n       if (A[j][i]) t = j; n     swap(A[i], A[t]); n     for (int j = 1; j <= n; j++) n       if (A[j][i] && j != i) A[j] ^= A[i]; n   } n   for (int i = 1; i <= m; i++) n     if (A[y[i]][x[i] + n]) n       puts( NO ); n     else n       puts( YES ); n } n void Init() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d , &x[i], &y[i]); n     A[x[i]][y[i]] = 1; n   } n   for (int i = 1; i <= n; i++) A[i][i + n] = 1; n } n int main() { n   Init(); n   Work(); n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 60; n int n, P, A[MAXN]; n const int mod = 1000000007; n void reduce(int& x) { x += x >> 31 & mod; } n int mul(int a, int b) { return (long long)a * b % mod; } n int pow(int a, int b, int res = 1) { n   for (; b; b >>= 1, a = mul(a, a)) n     if (b & 1) res = mul(res, a); n   return res; n } n int dp[MAXN][MAXN][MAXN]; n int main() { n   std::ios_base::sync_with_stdio(false), std::cin.tie(0); n   std::cin >> n >> P; n   for (int i = 1; i <= n; ++i) std::cin >> A[i]; n   dp[0][0][0] = 1; n   for (int i = 1; i <= n; ++i) n     for (int j = 0; j <= i; ++j) n       for (int k = 0; k <= i; ++k) n         if (dp[i - 1][j][k]) { n           if (A[i] == 0 || A[i] == -1) { n             int t = pow(2, i - 1 - (!!k), dp[i - 1][j][k]); n             reduce(dp[i][j + 1][k] += t - mod); n             if (k) reduce(dp[i][j][k] += t - mod); n           } n           if (A[i] == 1 || A[i] == -1) { n             int t = pow(2, i - 1 - (!!j), dp[i - 1][j][k]); n             reduce(dp[i][j][k + 1] += t - mod); n             if (j) reduce(dp[i][j][k] += t - mod); n           } n         } n   int ans = 0; n   for (int i = 0; i <= n; ++i) n     for (int j = 0; j <= n; ++j) n       if ((i + j & 1) == P) reduce(ans += dp[n][i][j] - mod); n   std::cout << ans << std::endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char s[200001], t1[200001]; n   long long n, x, y, t, con = 0; n   cin >> n >> x >> y; n   getchar(); n   gets(s); n   t = n - x; n   for (long long i = t; s[i] !=   0 ; i++) { n     if (i == n - 1 - y && s[i] !=  1 ) con++; n     if (i != n - 1 - y && s[i] !=  0 ) con++; n   } n   cout << con << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k, r; n   cin >> k >> r; n   int n = 1; n   while (true) { n     if ((k * n - r) % 10 == 0 || (k * n) % 10 == 0) { n       cout << n <<   n ; n       return 0; n     } n     n++; n   } n } n