#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > g[110]; n int seen[110][110]; n int c[110]; n int ans; n void dfs(int s, int end, int color) { n   if (s == end && c[color] == 0) { n     c[color] = 1; n     ans++; n     return; n   } n   for (int i = 0; i < (int)g[s].size(); i++) { n     if ((color == 0 || color == g[s][i].second) && n         seen[s][g[s][i].first] == 0 && seen[g[s][i].first][s] == 0) { n       seen[s][g[s][i].first] = 1; n       seen[g[s][i].first][s] = 1; n       dfs(g[s][i].first, end, g[s][i].second); n       seen[s][g[s][i].first] = 0; n       seen[g[s][i].first][s] = 0; n     } n   } n } n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   int temp1, temp2, temp3; n   for (int i = 0; i < m; i++) { n     scanf( %d %d %d , &temp1, &temp2, &temp3); n     g[temp1].push_back(pair<int, int>(temp2, temp3)); n     g[temp2].push_back(pair<int, int>(temp1, temp3)); n   } n   int q; n   scanf( %d , &q); n   for (int i = 0; i < q; i++) { n     scanf( %d %d , &temp1, &temp2); n     dfs(temp1, temp2, 0); n     printf( %d n , ans); n     ans = 0; n     for (int i = 0; i < 110; i++) n       for (int j = 0; j < 110; j++) seen[i][j] = 0; n     for (int i = 0; i < 110; i++) c[i] = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int n, t, m = 0; n   cin >> n; n   vector<int> s; n   for (int i = 0; i < n; i++) { n     cin >> t; n     s.push_back(t); n   } n   sort(s.begin(), s.end()); n   while (true) { n     t = -1; n     for (int i = 0; i < n; i++) { n       if (s[i] != -1 && s[i] >= t + 1) { n         s[i] = -1; n         t++; n       } n     } n     if (t == -1) break; n     m++; n   } n   cout << m << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[20][20], ans[20]; n int n, m; n bool isValid() { n   for (int i = 2; i <= n; i++) { n     int c = 0; n     for (int j = 1; j <= m; j++) c += (ans[j] != a[i][j]); n     if (c > 1) return false; n   } n   return true; n } n void fun() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> (a[i] + 1); n   for (int i = 1; i <= m; i++) ans[i] = a[1][i]; n   ans[m + 1] =   0 ; n   if (isValid()) n     cout << (ans + 1) <<   n ; n   else { n     bool isGood = false; n     for (int i = 1; i <= m && !isGood; i++) { n       for (char c =  a ; c <=  z  && !isGood; c++) { n         if (c != a[1][i]) { n           ans[i] = c; n           if (isValid()) { n             cout << (ans + 1) <<   n ; n             isGood = true; n           } n         } n       } n       ans[i] = a[1][i]; n     } n     if (!isGood) cout <<  -1 n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     fun(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool umin(T& a, T b) { n   if (a > b) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n bool umax(T& a, T b) { n   if (a < b) { n     a = b; n     return 1; n   } n   return 0; n } n int main() { n   int n, x = 500; n   scanf( %d , &n); n   for (int i = 0; i < 26 and (n or !i); i++) { n     while (x * (x - 1) / 2 > n) x--; n     n -= x * (x - 1) / 2; n     for (int j = 0; j < x; j++) printf( %c , char(i + 97)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[100005]; n int n, k, cnt[20]; n bool a[20][20], mark[1 << 17], tmp[1 << 17]; n inline void work(int x, int y) { n   memset(tmp, 0, sizeof(tmp)); n   for (int i = 1, j, t; i <= n;) { n     while (i <= n && s[i] -  a  != x) i++; n     j = i + 1; n     t = 0; n     while (j <= n && s[j] -  a  != x && s[j] -  a  != y) { n       t |= 1 << s[j] -  a ; n       j++; n     } n     if (j > n) break; n     if (s[j] -  a  == y) tmp[t] = 1; n     if (s[j] -  a  == x) n       i = j; n     else n       i = j + 1; n   } n   for (int i = 1; i < 1 << k; i++) { n     if (!tmp[i]) continue; n     mark[i] = 1; n     for (int j = 0; j < k; j++) n       if (j != x && j != y) tmp[i | 1 << j] = 1; n   } n } n bool f[1 << 17]; n int main() { n   cin >> n >> k; n   scanf( %s , s); n   for (int i = 0; i < n; i++) cnt[s[i] -  a ]++; n   for (int i = 0; i < k; i++) n     for (int j = 0; j < k; j++) { n       cin >> a[i][j]; n       if (!a[i][j]) work(i, j); n     } n   f[0] = 1; n   for (int i = 0; i < 1 << k; i++) { n     if (!f[i]) continue; n     for (int j = 0; j < k; j++) n       if (!mark[i | 1 << j]) f[i | 1 << j] = 1; n   } n   int ans = 0; n   for (int i = 0; i < 1 << k; i++) { n     if (!f[i]) continue; n     int t = 0; n     for (int j = 0; j < k; j++) n       if (i & 1 << j) t += cnt[j]; n     ans = max(ans, t); n   } n   cout << n - ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e6 + 10; n const long long inf = 1e15; n const int mod = 1e6; n void faster() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n const long long N = 3000 * 200; n int mark[N]; n int main() { n   faster(); n   int n; n   cin >> n; n   int t = 0; n   vector<int> v[n]; n   for (int i = 1; i <= n * n; i++) { n     v[(i + t) % n].push_back(i); n     if (i % n == 0) t++; n   } n   for (int i = 0; i < n; i++) { n     for (auto c : v[i]) cout << c <<    ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100000 + 5; n const long long mod = 99999997; n long long a[maxn], k, n; n void dfs(long long l, long long r) { n   if (l + 1 >= r || !k) return; n   long long mid = (l + r) / 2; n   k -= 2; n   swap(a[mid - 1], a[mid]); n   dfs(l, mid); n   dfs(mid, r); n } n int main() { n   cin >> n >> k; n   if (k > 2 * n - 1 || k % 2 == 0) { n     cout <<  -1  << endl; n     return 0; n   } n   for (int i = 0; i < n; i++) { n     a[i] = i + 1; n   } n   k--; n   dfs(0ll, n); n   for (int i = 0; i < n; i++) cout << a[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void smax(T &x, T y) { n   x = max((x), (y)); n } n template <class T> n inline void smin(T &x, T y) { n   x = min((x), (y)); n } n inline void scanInt(int &x) { n   register char c = getchar(); n   x = 0; n   bool neg = false; n   while (c < 48 || c > 57) { n     if (c ==  - ) neg = true; n     c = getchar(); n   } n   for (; c > 47 && c < 58; c = getchar()) { n     x = (x << 1) + (x << 3) + c - 48; n   } n   if (neg) x *= -1; n } n int n, m; n string origin; n string s; n bool place_char_start(int inx) { n   if (inx >= 2) { n     for (char i = s[inx] + 1; i <  a  + m; i++) n       if (i != s[inx - 1] && i != s[inx - 2] && i != s[inx]) { n         s[inx] = i; n         return true; n       } n     return false; n   } else if (inx == 1) { n     for (char i = s[inx] + 1; i <  a  + m; i++) n       if (i != s[inx - 1] && i != s[inx]) { n         s[inx] = i; n         return true; n       } n     return false; n   } else if (inx == 0) { n     s[0] = s[0] + 1; n     if (s[0] >=  a  + m) return false; n     return true; n   } n   return false; n } n bool place_char(int inx) { n   if (inx >= 2) { n     for (char i =  a ; i <  a  + m; i++) n       if (i != s[inx - 1] && i != s[inx - 2]) { n         s[inx] = i; n         return true; n       } n     return false; n   } else if (inx == 1) { n     for (char i =  a ; i <  a  + m; i++) n       if (i != s[inx - 1]) { n         s[inx] = i; n         return true; n       } n   } else if (inx == 0) { n     s[0] =  a ; n     return true; n   } n   return false; n } n int main(int argc, const char *argv[]) { n   scanInt(n); n   scanInt(m); n   cin >> s; n   origin = s; n   for (int i = (int)s.size() - 1; i >= 0; i--) { n     s = origin; n     bool ok = true; n     ok &= place_char_start(i); n     for (int j = i + 1; ok && j < s.size(); j++) { n       if (place_char(j) == false) ok = false; n     } n     if (ok) { n       cout << s; n       return 0; n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct event { n   int x[3], id; n   event() { x[0] = x[1] = x[2] = id = 0; } n   event(int xx, int yy, int zz, int idd) { n     x[0] = xx; n     x[1] = yy; n     x[2] = zz; n     id = idd; n   } n }; n int vc = 0; n bool operator<(const event &a, const event &b) { n   if (a.x[vc] == b.x[vc]) return a.id < b.id; n   return a.x[vc] < b.x[vc]; n } n int ans[100005], ans_id[100005]; n event G[3][200005]; n void cdq(int L, int R, int now) { n   if (L >= R) return; n   vc = now; n   if (now == 2) { n     int last = -1, last_id = -1; n     for (int i = L; i <= R; ++i) { n       if (G[now][i].id > 0) { n         if (last_id != -1) { n           int &tmp = ans[G[now][i].id]; n           if (tmp == -1 || tmp < last) { n             tmp = last; n             ans_id[G[now][i].id] = last_id; n           } n         } n       } else { n         last = G[now][i].x[2]; n         last_id = -G[now][i].id; n       } n     } n     return; n   } n   int mid = (L + R) / 2, cnt = 0; n   cdq(L, mid, now); n   for (int i = L; i <= mid; ++i) n     if (G[now][i].id < 0) G[now + 1][++cnt] = G[now][i]; n   for (int i = mid + 1; i <= R; ++i) n     if (G[now][i].id > 0) G[now + 1][++cnt] = G[now][i]; n   vc = now + 1; n   sort(G[now + 1] + 1, G[now + 1] + cnt + 1); n   cdq(1, cnt, now + 1); n   cdq(mid + 1, R, now); n } n int main() { n   int n, m, i, j, k, l, cnt = 0; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; ++i) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     G[0][++cnt] = event(x, -y, -z, -i); n   } n   for (i = 1; i <= m; ++i) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     G[0][++cnt] = event(x, -y, -z, i); n   } n   memset(ans, -1, sizeof(ans)); n   memset(ans_id, -1, sizeof(ans)); n   vc = 0; n   sort(G[0] + 1, G[0] + 1 + cnt); n   cdq(1, cnt, 0); n   for (i = 1; i <= m; ++i) printf( %d%c , ans_id[i],    n [i == m]); n } n


#include <bits/stdc++.h> n using namespace std; n vector<multiset<int> > G; n vector<int> d; n void dfs(int u, vector<int> &ans) { n   while (!G[u].empty()) { n     int v = *G[u].begin(); n     G[u].erase(G[u].begin()); n     G[v].erase(G[v].find(u)); n     dfs(v, ans); n   } n   ans.push_back(u); n } n int main() { n   int n, m; n   cin >> n >> m; n   G.resize(n); n   d.resize(n, 0); n   for (int i = 0; i < m; i++) { n     int u, v; n     scanf( %d %d , &u, &v); n     u--; n     v--; n     G[u].insert(v); n     G[v].insert(u); n     d[u]++; n     d[v]++; n   } n   vector<int> odd; n   for (int i = 0; i < n; i++) { n     if (d[i] & 1) odd.push_back(i); n   } n   int add = 0; n   for (int i = 0; i < (int)odd.size() - 1; i += 2) { n     int u = odd[i], v = odd[i + 1]; n     G[u].insert(v); n     G[v].insert(u); n     add++; n   } n   if (odd.size() & 1) { n     int u = odd[odd.size() - 1]; n     G[u].insert(u); n     G[u].insert(u); n     add++; n   } n   if ((m + add) % 2) { n     G[0].insert(0); n     G[0].insert(0); n     add++; n   } n   vector<int> ans; n   dfs(0, ans); n   cout << m + add << endl; n   for (int i = 0; i < (int)ans.size() - 1; i++) { n     if (i & 1) n       printf( %d %d n , ans[i] + 1, ans[i + 1] + 1); n     else n       printf( %d %d n , ans[i + 1] + 1, ans[i] + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int arr[30] = {0}; n   unsigned long long sum = 0; n   long long int a, b, n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int j = 0; n     cin >> a; n     while (a != 0) { n       b = a % 10; n       arr[j] += b; n       arr[j + 1] += b; n       a /= 10; n       j += 2; n     } n   } n   for (unsigned long long int i = 0, ten = 1; i < 30; i++, ten = ten * 10) { n     if (!arr[i]) continue; n     arr[i] *= n; n     unsigned long long x = n         ((arr[i] % 998244353) * (ten % 998244353)) % 998244353; n     sum = (sum + x) % 998244353; n   } n   cout << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n int main() { n   int n; n   cin >> n; n   long long int x = 2; n   double d; n   long long int p; n   for (long long int i = 1; i <= n; i++) { n     long long int B = i * (i + 1) * (i + 1) - x / i; n     cout << B <<   n ; n     x = i * (i + 1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n string grid[8]; n int get_weight(char c) { n   switch (c) { n     case  q : n       return 9; n     case  r : n       return 5; n     case  b : n     case  n : n       return 3; n     case  p : n       return 1; n     default: n       return 0; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   for (int i = 0; i < 8; ++i) cin >> grid[i]; n   int black = 0, white = 0; n   for (int i = 0; i < 8; ++i) n     for (int j = 0; j < 8; ++j) { n       bool play1 = isupper(grid[i][j]); n       int score = get_weight(tolower(grid[i][j])); n       if (play1) n         black += score; n       else n         white += score; n     } n   if (black == white) n     cout <<  Draw ; n   else if (black > white) n     cout <<  White ; n   else n     cout <<  Black ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n char s[21][100100]; n int n, m, ans = 1e9, all, inv, a[100100], bit[1100000], w[1100000], f[1100000]; n int power(int a, int k) { n   int ret = 1; n   while (k) { n     if (k & 1) ret = 1ll * ret * a % mod; n     a = 1ll * a * a % mod; n     k >>= 1; n   } n   return ret; n } n void FWT(int *a, int t) { n   int pre, cur = 0; n   static int f[2][1100000]; n   for (int i = 0; i <= all; i++) f[0][i] = a[i]; n   for (int i = 0; i <= n - 1; i++) { n     pre = cur, cur ^= 1; n     for (int s = 0; s <= all; s++) n       if (!(s >> i & 1)) { n         int l = f[pre][s], r = f[pre][s | (1 << i)]; n         f[cur][s] = (l + r) % mod; n         f[cur][s | (1 << i)] = (l + mod - r) % mod; n       } n   } n   if (t) n     for (int i = 0; i <= all; i++) f[cur][i] = 1ll * f[cur][i] * inv % mod; n   for (int i = 0; i <= all; i++) a[i] = f[cur][i]; n } n int main() { n   scanf( %d%d , &n, &m); n   all = (1 << n) - 1; n   inv = power(power(2, mod - 2), n); n   for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1); n   for (int i = 1; i <= m; i++) n     for (int j = 1; j <= n; j++) a[i] = (a[i] << 1) + s[j][i] -  0 ; n   for (int i = 1; i <= all; i++) bit[i] = bit[i >> 1] + (i & 1); n   for (int i = 1; i <= m; i++) f[a[i]]++; n   for (int i = 0; i <= all; i++) w[i] = min(bit[i], n - bit[i]); n   FWT(f, 0); n   FWT(w, 0); n   for (int i = 0; i <= all; i++) f[i] = 1ll * f[i] * w[i] % mod; n   FWT(f, 1); n   for (int i = 0; i <= all; i++) ans = min(ans, f[i]); n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int lim = 1e5 + 5; n int main(int argc, char const *argv[]) { n   int n; n   cin >> n; n   std::vector<int> v(n); n   for (int i = 0; i < n; ++i) { n     cin >> v[i]; n   } n   int mn = INT_MAX, ind1, ind2; n   for (int i = 0; i < n - 1; ++i) { n     int dif = abs(v[i] - v[i + 1]); n     if (mn > dif) { n       mn = dif; n       ind1 = i + 1; n       ind2 = i + 2; n     } n   } n   int dif = abs(v[0] - v[n - 1]); n   if (mn > dif) { n     mn = dif; n     ind1 = 1; n     ind2 = n; n   } n   cout << ind1 <<     << ind2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long ll; n #define endl   n  n const int DIM = 1E5+7; n int A[DIM]; n int cnt[2][DIM]; n int solve() { n     int n; n     cin>>n; n     for(int i = 1;i<=n;++i){ n         cin>>A[i]; n         ++cnt[i%2][A[i]]; n     } n     sort(A+1,A+1+n); n     int flag = 0; n     for(int i = 1;i<=n;++i){ n         cnt[i%2][A[i]]--; n     } n     for(int i = 1;i<=n;++i){ n         if (cnt[0][A[i]] || cnt[1][A[i]]) n             flag = 1; n         cnt[0][A[i]] = cnt[1][A[i]] = 0; n     } n     if (flag) n         cout<< NO n ; n     else cout<< YES n ; n  n     return 1; n } n int main() { n     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); n  n     int t; n     cin>>t; n     while(t--) n         assert(solve()); n }


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n string s, t; n int lenX, lenY; n long long dp[5009][5009]; n inline long long go(int x, int y) { n   if (x < 0 || y < 0) return 0LL; n   long long &ret = dp[x][y]; n   if (ret != -1) return ret; n   ret = 0; n   if (y > 0) ret = go(x, y - 1); n   if (ret >= MOD) ret -= MOD; n   if (s[x] == t[y]) { n     ret++; n     if (x > 0 && y > 0) ret = (ret + go(x - 1, y - 1)) % MOD; n   } n   return ret; n } n int main() { n   memset(dp, -1, sizeof(dp)); n   cin >> s >> t; n   lenX = (int)s.length(); n   lenY = (int)t.length(); n   long long ans = 0; n   for (int i = 0; i < lenX; ++i) { n     ans += go(i, lenY - 1); n     if (ans >= MOD) ans -= MOD; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   const int MAXOPER = 1e5 + 123; n   const int MAXN = 1e5 + 123; n   vector<long long> V; n   long long sz = 0; n   static long long sz_after[MAXOPER]; n   static int oper_tip[MAXOPER]; n   static int oper_l[MAXOPER]; n   static int oper_c[MAXOPER]; n   static int oper_x[MAXOPER]; n   int n_oper; n   scanf( %d , &n_oper); n   for (int i_oper = 0; i_oper < (n_oper); ++i_oper) { n     int tip; n     scanf( %d , &tip); n     oper_tip[i_oper] = tip; n     if (tip == 1) { n       int x; n       scanf( %d , &x); n       oper_x[i_oper] = x; n       if ((int)V.size() < MAXN) V.push_back(x); n       ++sz; n     } else { n       int l, c; n       scanf( %d %d , &l, &c); n       oper_l[i_oper] = l; n       oper_c[i_oper] = c; n       for (int i = 0; i < (c); ++i) { n         if ((int)V.size() >= MAXN) break; n         for (int j = 0; j < (l); ++j) { n           if ((int)V.size() >= MAXN) break; n           V.push_back(V[j]); n         } n       } n       sz += l * c; n     } n     sz_after[i_oper] = sz; n   } n   int n_q; n   scanf( %d , &n_q); n   for (int i_q = 0; i_q < (n_q); ++i_q) { n     long long idx; n     cin >> idx; n     --idx; n     int o_idx = upper_bound(sz_after, sz_after + n_oper, idx) - sz_after; n     long long sol; n     if (oper_tip[o_idx] == 1) n       sol = oper_x[o_idx]; n     else { n       sol = V[(idx - sz_after[o_idx - 1]) % oper_l[o_idx]]; n     } n     cout << sol; n     if (i_q + 1 < n_q) n       cout <<    ; n     else n       cout << endl; 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     int n, m, count = 0; n     cin >> n >> m; n     string arr[n]; n     for (int i = 0; i < n; i++) { n       cin >> arr[i]; n     } n     for (int i = 0; i < (m - 1); i++) { n       if (arr[n - 1][i] !=  R ) count++; n     } n     for (int i = 0; i < (n - 1); i++) { n       if (arr[i][m - 1] !=  D ) count++; n     } n     cout << count << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n template <typename T> n using V = std::vector<T>; n struct debugger { n   template <typename T> n   debugger &operator,(const T &v) { n     cerr << v <<    ; n     return *this; n   } n } dbg; n using namespace std; n const double pi = acos(-1); n struct SegmentTree { n   int n; n   int size; n   vector<pair<double, double> > dat; n   vector<double> lazy; n   int real_size; n   SegmentTree(int n_) { n     real_size = n_; n     n = 1; n     size = n_; n     while (n < n_) n *= 2; n     dat = vector<pair<double, double> >(2 * n - 1); n     lazy = vector<double>(2 * n - 1); n     init(0, 0, n); n   } n   void init(int k, int l, int r) { n     if (r - l == 1) { n       if (l < real_size) { n         dat[k] = make_pair(1.0, 0.0); n       } n     } else { n       int m = (l + r) / 2; n       init((k * 2 + 1), l, m); n       init((k * 2 + 2), m, r); n       dat[k] = combine(dat[(k * 2 + 1)], dat[(k * 2 + 2)]); n     } n   } n   void update(int a, int b, const double &d) { update(a, b + 1, 0, 0, n, d); } n   void propagate(int k, int l, int r) { n     double t = lazy[k]; n     double x = dat[k].first * cos(t) + dat[k].second * sin(t); n     double y = -dat[k].first * sin(t) + dat[k].second * cos(t); n     dat[k] = make_pair(x, y); n     if ((k * 2 + 2) < lazy.size()) { n       lazy[(k * 2 + 1)] += lazy[k]; n       lazy[(k * 2 + 2)] += lazy[k]; n     } n     lazy[k] = 0.0; n   } n   void update(int a, int b, int k, int l, int r, const double &d) { n     propagate(k, l, r); n     if (r <= a || b <= l) return; n     if (a <= l && r <= b) { n       lazy[k] = d; n       propagate(k, l, r); n     } else { n       int m = (l + r) / 2; n       update(a, b, (k * 2 + 1), l, m, d); n       update(a, b, (k * 2 + 2), m, r, d); n       dat[k] = combine(dat[(k * 2 + 1)], dat[(k * 2 + 2)]); n     } n   } n   void update(int a, int b, int k, int l, int r, int z) { n     propagate(k, l, r); n     if (r <= a || b <= l) return; n     if (a <= l && r <= b) { n       double len = n           sqrt(dat[k].first * dat[k].first + dat[k].second * dat[k].second); n       dat[k].first *= (len + z) / len; n       dat[k].second *= (len + z) / len; n     } else { n       int m = (l + r) / 2; n       update(a, b, (k * 2 + 1), l, m, z); n       update(a, b, (k * 2 + 2), m, r, z); n       dat[k] = combine(dat[(k * 2 + 1)], dat[(k * 2 + 2)]); n     } n   } n   void update(int a, int z) { update(a, a + 1, 0, 0, n, z); } n   pair<double, double> query(int a, int b) { return query(a, b + 1, 0, 0, n); } n   pair<double, double> query(int a, int b, int k, int l, int r) { n     if (r <= a || b <= l) return make_pair(0.0, 0.0); n     propagate(k, l, r); n     if (a <= l && r <= b) { n       return dat[k]; n     } else { n       pair<double, double> vl = query(a, b, (k * 2 + 1), l, (l + r) / 2); n       pair<double, double> vr = query(a, b, (k * 2 + 2), (l + r) / 2, r); n       return combine(vl, vr); n     } n   } n   pair<double, double> combine(pair<double, double> vl, n                                pair<double, double> vr) { n     return make_pair(vl.first + vr.first, vl.second + vr.second); n   } n }; n int main() { n   int N, M; n   scanf( %d , &N), scanf( %d , &M); n   SegmentTree st(N + 1); n   for (int i = 0; i < (M); i++) { n     int x; n     scanf( %d , &x); n     if (x == 2) { n       int y, z; n       scanf( %d , &y), scanf( %d , &z); n       st.update(y, N, z * 1.0 / 360 * 2 * pi); n     } else { n       int y, z; n       scanf( %d , &y), scanf( %d , &z); n       st.update(y, z); n     } n     auto ans = st.query(1, N); n     printf( %.10f %.10f n , ans.first, ans.second); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int z[150005]; n long long tir[150005]; n int find(int a) { n   if (a != z[a]) { n     z[a] = find(z[a]); n   } n   return z[a]; n } n void mix(int a, int b) { z[find(a)] = find(b); } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     z[i] = i; n     tir[i] = 0; n   } n   for (int j = 0; j < m; j++) { n     int a, b; n     scanf( %d%d , &a, &b); n     mix(a, b); n   } n   for (int i = 1; i <= n; i++) { n     tir[find(i)]++; n   } n   long long sum = 0; n   for (int i = 1; i <= n; i++) { n     sum += ((tir[i] * (tir[i] - 1)) / 2); n   } n   if (sum == m) n     puts( YES ); n   else n     puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using vi = vector<long long>; n template <typename T> n std::istream& operator>>(std::istream& input, std::pair<T, T>& data) { n   input >> data.first >> data.second; n   return input; n } n template <typename T> n std::istream& operator>>(std::istream& input, std::vector<T>& data) { n   for (T& first : data) input >> first; n   return input; n } n template <typename T> n std::ostream& operator<<(std::ostream& output, const pair<T, T>& data) { n   output <<  (  << data.first <<  ,  << data.second <<  ) ; n   return output; n } n template <typename T> n std::ostream& operator<<(std::ostream& output, const std::vector<T>& data) { n   for (const T& first : data) output << first <<    ; n   return output; n } n std::ostream& operator<<(std::ostream& output, const __int128& first) { n   __int128 n = first; n   if (n == 0) { n     output <<  0 ; n     return output; n   } n   if (n < 0) { n     n = -n; n     output <<  - ; n   } n   string s; n   while (n) { n     s +=  0  + (n % 10); n     n /= 10; n   } n   reverse(s.begin(), s.end()); n   cout << s; n   return output; n } n long long div_up(long long a, long long b) { n   return a / b + ((a ^ b) > 0 && a % b); n } n long long div_down(long long a, long long b) { n   return a / b - ((a ^ b) < 0 && a % b); n } n long long math_mod(long long a, long long b) { return a - b * div_down(a, b); } n template <class T> n using V = vector<T>; n template <class T> n bool ckmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool ckmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n long long gcd(long long a, long long b) { n   while (b) { n     tie(a, b) = make_pair(b, a % b); n   } n   return a; n } n long long Bit(long long mask, long long bit) { return (mask >> bit) & 1; } n template <long long MOD, long long RT> n struct mint { n   static const long long mod = MOD; n   static constexpr mint rt() { return RT; } n   long long v; n   explicit operator long long() const { return v; } n   mint() { v = 0; } n   mint(long long _v) { n     v = (long long)((-MOD < _v && _v < MOD) ? _v : _v % MOD); n     if (v < 0) v += MOD; n   } n   friend bool operator==(const mint& a, const mint& b) { return a.v == b.v; } n   friend bool operator!=(const mint& a, const mint& b) { return !(a == b); } n   friend bool operator<(const mint& a, const mint& b) { return a.v < b.v; } n   friend string ts(mint a) { return to_string(a.v); } n   mint& operator+=(const mint& m) { n     if ((v += m.v) >= MOD) v -= MOD; n     return *this; n   } n   mint& operator-=(const mint& m) { n     if ((v -= m.v) < 0) v += MOD; n     return *this; n   } n   mint& operator*=(const mint& m) { n     v = (long long)((long long)v * m.v % MOD); n     return *this; n   } n   mint& operator/=(const mint& m) { return (*this) *= inv(m); } n   friend mint pow(mint a, long long p) { n     mint ans = 1; n     assert(p >= 0); n     for (; p; p /= 2, a *= a) n       if (p & 1) ans *= a; n     return ans; n   } n   mint& operator^=(const long long& p) { return (*this) = pow(this, p); } n   friend mint inv(const mint& a) { n     assert(a.v != 0); n     return pow(a, MOD - 2); n   } n   mint operator-() const { return mint(-v); } n   mint& operator++() { return *this += 1; } n   mint& operator--() { return *this -= 1; } n   friend mint operator+(mint a, const mint& b) { return a += b; } n   friend mint operator-(mint a, const mint& b) { return a -= b; } n   friend mint operator*(mint a, const mint& b) { return a *= b; } n   friend mint operator/(mint a, const mint& b) { return a /= b; } n   friend mint operator^(mint a, const long long p) { return pow(a, p); } n }; n const long long MOD = 1e9 + 7; n typedef mint<MOD, 5> mi; n std::ostream& operator<<(std::ostream& o, const mi& a) { n   cout << a.v; n   return o; n } n vector<vector<mi> > scmb; n void genComb(long long SZ) { n   scmb.assign(SZ, vector<mi>(SZ)); n   scmb[0][0] = 1; n   for (long long i = (1); i < (SZ); ++i) n     for (long long j = (0); j < (i + 1); ++j) n       scmb[i][j] = scmb[i - 1][j] + (j ? scmb[i - 1][j - 1] : 0); n } n vector<mi> invs, fac, ifac; n void genFac(long long SZ) { n   invs.resize(SZ), fac.resize(SZ), ifac.resize(SZ); n   invs[1] = fac[0] = ifac[0] = 1; n   for (long long i = (2); i < (SZ); ++i) n     invs[i] = mi(-(long long)MOD / i * (long long)invs[MOD % i]); n   for (long long i = (1); i < (SZ); ++i) { n     fac[i] = fac[i - 1] * i; n     ifac[i] = ifac[i - 1] * invs[i]; n   } n } n mi comb(long long a, long long b) { n   if (a < b || b < 0) return 0; n   assert(a < fac.size()); n   return fac[a] * ifac[b] * ifac[a - b]; n } n const long long N = 507; n long long link[N]; n const long long K = 1 << 16; n void ANDConvolution(mi v[K]) { n   for (long long step = K; step > 1; step /= 2) { n     for (long long start = 0; start < K; start += step) { n       for (long long w = 0; w < step / 2; w++) { n         v[start + w] += v[start + w + step / 2]; n       } n     } n   } n } n void inverseANDConvolution(mi v[K]) { n   for (long long step = K; step > 1; step /= 2) { n     for (long long start = 0; start < K; start += step) { n       for (long long w = 0; w < step / 2; w++) { n         v[start + w] -= v[start + w + step / 2]; n       } n     } n   } n } n void ORConvolution(mi v[K]) { n   for (long long step = K; step > 1; step /= 2) { n     for (long long start = 0; start < K; start += step) { n       for (long long w = 0; w < step / 2; w++) { n         v[start + step / 2 + w] += v[start + w]; n       } n     } n   } n } n void inverseORConvolution(mi v[K]) { n   for (long long step = K; step > 1; step /= 2) { n     for (long long start = 0; start < K; start += step) { n       for (long long w = 0; w < step / 2; w++) { n         v[start + step / 2 + w] -= v[start + w]; n       } n     } n   } n } n mi dp[N][1 << 16]; n string s; n mi A[K], B[K], C[K]; n long long ptr = 0; n long long solve(long long l, long long r) { n   long long v = ptr; n   ptr++; n   if (l == r) { n     long long who = -1, add = -1; n     if (s[l] ==  a ) { n       who = 0; n       add = 1; n     } else if (s[l] ==  A ) { n       who = 0; n       add = 0; n     } else if (s[l] ==  b ) { n       who = 1; n       add = 1; n     } else if (s[l] ==  B ) { n       who = 1; n       add = 0; n     } else if (s[l] ==  c ) { n       who = 2; n       add = 1; n     } else if (s[l] ==  C ) { n       who = 2; n       add = 0; n     } else if (s[l] ==  d ) { n       who = 3; n       add = 1; n     } else if (s[l] ==  D ) { n       who = 3; n       add = 0; n     } else { n       assert(s[l] ==  ? ); n     } n     if (who != -1) { n       long long foo = 0; n       for (long long mask = (0); mask < (16); ++mask) { n         if (Bit(mask, who) ^ add) { n           foo ^= 1 << mask; n         } n       } n       dp[v][foo] += 1; n     } else { n       for (long long who = (0); who < (4); ++who) { n         for (long long add = (0); add < (2); ++add) { n           long long foo = 0; n           for (long long mask = (0); mask < (16); ++mask) { n             if (Bit(mask, who) ^ add) { n               foo ^= 1 << mask; n             } n           } n           dp[v][foo] += 1; n         } n       } n     } n     return v; n   } n   long long L = solve(l + 1, link[l] - 1); n   long long nextb = link[l] + 2; n   long long R = solve(nextb + 1, link[nextb] - 1); n   if (s[nextb - 1] !=  & ) { n     for (long long i = (0); i < (K); ++i) { n       A[i] = dp[L][i]; n       B[i] = dp[R][i]; n     } n     ORConvolution(A); n     ORConvolution(B); n     for (long long i = 0; i < K; i++) { n       C[i] = A[i] * B[i]; n     } n     inverseORConvolution(C); n     for (long long i = (0); i < (K); ++i) { n       dp[v][i] += C[i]; n     } n   } n   if (s[nextb - 1] !=  | ) { n     for (long long i = (0); i < (K); ++i) { n       A[i] = dp[L][i]; n       B[i] = dp[R][i]; n     } n     ANDConvolution(A); n     ANDConvolution(B); n     for (long long i = 0; i < K; i++) { n       C[i] = A[i] * B[i]; n     } n     inverseANDConvolution(C); n     for (long long i = (0); i < (K); ++i) { n       dp[v][i] += C[i]; n     } n   } n   return v; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> s; n   long long len = s.size(); n   vi sk; n   for (long long i = (0); i < (len); ++i) { n     if (s[i] ==  ( ) { n       sk.push_back(i); n     } else if (s[i] ==  ) ) { n       assert(sk.size()); n       link[sk.back()] = i; n       link[i] = sk.back(); n       sk.pop_back(); n     } n   } n   long long root = solve(0, len - 1); n   long long q; n   cin >> q; n   long long want = 0; n   long long know = 0; n   for (long long _ = (0); _ < (q); ++_) { n     long long bit = 0; n     for (long long i = (0); i < (4); ++i) { n       long long first; n       cin >> first; n       if (first) { n         bit ^= 1 << i; n       } n     } n     know ^= 1 << bit; n     long long res; n     cin >> res; n     if (res) { n       want ^= 1 << bit; n     } n   } n   mi ans = 0; n   for (long long mask = (0); mask < (1 << 16); ++mask) { n     bool ok = 1; n     for (long long bit = (0); bit < (16); ++bit) { n       if (Bit(know, bit)) { n         ok &= Bit(want, bit) == Bit(mask, bit); n       } n     } n     if (ok) { n       ans += dp[root][mask]; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, t; n   cin >> n >> t; n   string s; n   cin >> s; n   while (t--) { n     for (long long j = 1; j < n; j++) { n       if (s[j - 1] ==  B  && s[j] ==  G ) { n         swap(s[j - 1], s[j]); n         j++; n       } n     } n   } n   cout << s << endl; n   ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n void print(int base) { n   if (base == 4) cout <<  4 * 3 = 12 n12 * 2 = 24 n24 * 1 = 24  << endl; n   if (base == 5) n     cout <<  5 * 4 = 20 n3 + 2 = 5 n5 - 1 = 4 n20 + 4 = 24  << endl; n   if (base == 6) n     cout <<  4 * 3 = 12 n12 * 2 = 24 n5 + 1 = 6 n6 - 6 = 0 n24 + 0 = 24  n          << endl; n   if (base == 7) n     cout <<  5 * 3 = 15 n15 + 7 = 22 n2 - 1 = 1 n22 * 1 = 22 n6 - 4 = 2 n22 +   n              2 = 24  n          << endl; n } n void solve(int n, int base) { n   print(base); n   if (n == base) return; n   cout << base + 1 <<   +   << base + 4 <<   =   << 2 * base + 5 <<   n ; n   cout << base + 2 <<   +   << base + 3 <<   =   << 2 * base + 5 <<   n ; n   long long sm1 = 2 * base + 5, sm2 = 2 * base + 5, cs = 0; n   for (int i = base + 5; i <= n; i += 2) { n     if (cs) { n       cout << sm1 <<   +   << i <<   =   << sm1 + i <<   n ; n       cout << sm2 <<   +   << i + 1 <<   =   << sm2 + i + 1 <<   n ; n       cs = 0; n       sm1 += i; n       sm2 += i + 1; n     } else { n       cout << sm1 <<   +   << i + 1 <<   =   << sm1 + i + 1 <<   n ; n       cout << sm2 <<   +   << i <<   =   << sm2 + i <<   n ; n       cs = 1; n       sm1 += i + 1; n       sm2 += i; n     } n   } n   cout << sm1 <<   -   << sm2 <<   =   n        <<  0 n ; n   cout <<  24 + 0 = 24 n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int n; n   cin >> n; n   if (n < 4) return puts( NO ), 0; n   cout <<  YES  << endl; n   for (int i = 4; i <= 7; ++i) { n     if ((((n - i) / 2) % 2 == 0) && (n - i) % 2 == 0) solve(n, i); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int arr[105]; n int main() { n   int n; n   cin >> n; n   int pos = 0; n   int neg = 0; n   int z = 0; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     if (arr[i] > 0) n       pos++; n     else if (arr[i] < 0) n       neg++; n     else n       z++; n   } n   int pas = 0; n   if (n % 2 == 0) n     pas = n / 2; n   else n     pas = (n / 2) + 1; n   int maxi = pos; n   if (neg > pos) maxi = neg; n   if (maxi >= pas && maxi == pos) { n     cout << 1 << endl; n   } else if (maxi >= pas && maxi == neg) { n     cout << -1 << endl; n   } else { n     cout << 0 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[500][500]; n int d[500][500]; n long long int ans[500]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       int num; n       cin >> num; n       a[i][j] = num; n       d[i][j] = num; n     } n   } n   int b[n]; n   for (int i = 0; i < n; i++) { n     cin >> b[i]; n     b[i]--; n   } n   reverse(b, b + n); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       for (int s = 0; s < n; s++) { n         d[j][s] = min(d[j][s], d[j][b[i]] + d[b[i]][s]); n       } n     } n     for (int j = 0; j <= i; j++) { n       for (int s = 0; s <= i; s++) { n         ans[i] += d[b[j]][b[s]]; n       } n     } n   } n   reverse(ans, ans + n); n   for (int i = 0; i < n; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n int ma[maxn]; n int en[maxn]; n int add = 0; n int main() { n   std::ios::sync_with_stdio(false); n   int n, d; n   cin >> n >> d; n   int sum = 0; n   int mx = -40000000; n   int op = 0; n   for (int i = 0; i < n; i++) { n     int in; n     cin >> in; n     if (in != 0) { n       sum += in; n       mx = max(mx, sum); n       if (sum > d) { n         cout <<  -1  << endl; n         return 0; n       } n     } else { n       if (sum >= 0) continue; n       ma[op] = mx; n       en[op++] = sum; n       sum = 0; n       mx = -400000000; n     } n   } n   int cnt = 0; n   for (int i = 0; i < op; i++) { n     if (min(add, d - ma[i]) < abs(en[i])) { n       cnt++; n       add = d; n     } else { n       add = min(add, d - ma[i]) - abs(en[i]); n     } n   } n   cout << cnt << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<vector<int> > field; n   int x, y; n   cin >> x >> y; n   field.resize(x); n   for (int i = 0; i < x; ++i) field[i].resize(y); n   for (int i = 0; i < x; ++i) n     for (int j = 0; j < y; ++j) field[i][j] = 0; n   int x0, y0; n   cin >> x0 >> y0; n   x0 -= 1; n   y0 -= 1; n   field[x0][y0] = 1; n   int count = x * y - 1; n   string s; n   cin >> s; n   cout <<  1  ; n   for (unsigned int i = 0; i < s.size() - 1; ++i) { n     if (s[i] ==  U  && x0 != 0) { n       x0 -= 1; n       if (field[x0][y0] != 1) { n         field[x0][y0] = 1; n         --count; n         cout <<  1  ; n       } else n         cout <<  0  ; n     } else if (s[i] ==  D  && x0 != x - 1) { n       x0 += 1; n       if (field[x0][y0] != 1) { n         field[x0][y0] = 1; n         --count; n         cout <<  1  ; n       } else n         cout <<  0  ; n     } else if (s[i] ==  L  && y0 != 0) { n       y0 -= 1; n       if (field[x0][y0] != 1) { n         field[x0][y0] = 1; n         --count; n         cout <<  1  ; n       } else n         cout <<  0  ; n     } else if (s[i] ==  R  && y0 != y - 1) { n       y0 += 1; n       if (field[x0][y0] != 1) { n         field[x0][y0] = 1; n         --count; n         cout <<  1  ; n       } else n         cout <<  0  ; n     } else n       cout <<  0  ; n   } n   cout << count; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a[+100500 * 2], ans; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     scanf( %I64d , &a[i]); n   } n   for (int i = 1; i <= n; i++) { n     ans += abs(a[i] - a[i - 1]); n   } n   printf( %I64d , ans); n   return 0; n   ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> v(n); n   for (int i = 0; i < n; i++) cin >> v[i]; n   string str; n   getline(cin, str); n   bool isok = true; n   for (int i = 0; i < n; i++) { n     getline(cin, str); n     int x = 0; n     for (int j = 0; j < str.length(); j++) { n       if (str[j] ==  a  || str[j] ==  e  || str[j] ==  i  || str[j] ==  o  || n           str[j] ==  u  || str[j] ==  y ) n         x++; n     } n     if (x != v[i]) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long a, b; n   cin >> a >> b; n   vector<string> A; n   for (long long i = 0; i < a; i++) { n     string res =   ; n     for (long long j = 0; j < b; j++) { n       if (i % 4 == 0 || i % 4 == 2) { n         res +=  # ; n       } else if (i % 4 == 1 || i % 4 == 3) { n         res +=  . ; n       } n     } n     if (i % 4 == 1) n       res[res.length() - 1] =  # ; n     else if (i % 4 == 3) n       res[0] =  # ; n     A.push_back(res); n   } n   for (auto i : A) { n     cout << i <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long tt(1); n   while (tt--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long pow(long long a, long long b) { n   if (b == 0) { n     return 1; n   } n   if (b % 2 == 0) { n     return pow((a % 1000000007) * (a % 1000000007), b / 2) % 1000000007; n   } else { n     return (a % 1000000007) * n            (pow((a % 1000000007) * (a % 1000000007), (b - 1) / 2) % 1000000007); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int i, j, k, n; n   cin >> n >> k; n   double x[n], y[n]; n   for (i = 0; i < n; i++) { n     cin >> x[i] >> y[i]; n   } n   double ans = 0.000000000; n   for (i = 1; i < n; i++) { n     ans += sqrt((x[i] - x[i - 1]) * (x[i] - x[i - 1]) + n                 (y[i] - y[i - 1]) * (y[i] - y[i - 1])); n   } n   double f = (ans * double(k)) / (50.0000000000); n   cout << fixed << setprecision(10) << f <<   n ; n } n


#include <bits/stdc++.h> n const long long P = 1000000007; n long long N, oldA, oldB, oldC, oldD = 1, newA, newB, newC, newD; n int main() { n   std::cin >> N; n   for (int i = 1; i <= N; ++i) { n     newA = (oldB + oldC + oldD) % P; n     newB = (oldA + oldC + oldD) % P; n     newC = (oldA + oldB + oldD) % P; n     newD = (oldA + oldB + oldC) % P; n     oldA = newA; n     oldB = newB; n     oldC = newC; n     oldD = newD; n   } n   std::cout << newD; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n long long a[N][26]; n int b[N]; n long long ans[28]; n char s[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     cin >> (s + 1); n     for (int i = 0; i <= n; i++) { n       for (int j = 0; j <= 26; j++) { n         a[i][j] = 0; n       } n     } n     for (int i = 0; i < 26; i++) ans[i] = 0; n     for (int i = 0; i < m; i++) cin >> b[i]; n     for (int i = 1; i <= n; i++) { n       int d = s[i] -  a ; n       a[i][d]++; n     } n     for (int i = 0; i < 26; i++) { n       for (int j = 2; j <= n; j++) { n         a[j][i] = a[j - 1][i] + a[j][i]; n       } n     } n     for (int i = 0; i < m; i++) { n       int k = b[i]; n       for (int j = 0; j < 26; j++) { n         ans[j] += a[k][j]; n       } n     } n     for (int i = 0; i < 26; i++) { n       ans[i] += a[n][i]; n     } n     for (int i = 0; i < 26; i++) { n       if (i) cout <<    ; n       cout << ans[i]; n     } n     cout << endl; n   } n   return 0; n } n


#pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimization ( O3 ) n #pragma GCC optimization ( unroll-loops ) n  n #include<bits/stdc++.h> n using namespace std; n  n #define pb push_back n #define mp make_pair n #define F first n #define S second n #define lb lower_bound n #define ub upper_bound n #define sz(x) (int)(x).size() n #define all(x) x.begin(), x.end() n  n typedef long long ll; n typedef long double ld; n typedef complex<ld> cd; n typedef pair<int, int> pii; n typedef pair<ll,ll> pll; n typedef pair<ld,ld> pld; n typedef vector<int> vi; n typedef vector<ld> vd; n typedef vector<ll> vl; n typedef vector<pii> vpi; n typedef vector<pll> vpl; n  n #define FOR(i, a, b) for (int i=a; i<(b); i++) n #define F0R(i, a) for (int i=0; i<(a); i++) n #define FORd(i,a,b) for (int i = (b)-1; i >= a; i--) n #define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) n #define trav(a,x) for (auto& a : x) n  n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n   n ll powmod(ll a,ll b) {ll res=1; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;} n ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} n int n,d; n  n void solve() { n     int n; string a,b; n     cin >> n >> a >> b; n     if(a==b) { cout << b <<   n ; return ; } n     if(a[0] ==  0 ) { F0R(i,n) cout <<  1 ; cout<<  n ; return; } n     if(b.back() ==  1  || a == b) { cout << b <<   n ; return ; }  n     {        n         int l = n-1; n         while(a[l] ==  1 ) --l; n         a[l]= 1 ; FOR(i,l+1,n) a[i]= 0 ; n     } n     if(a != b) b[n-1] =  1 ; n     { cout << b <<   n ; return ; } n } n  n  n int main(){ n     ios_base::sync_with_stdio(false); cin.tie(NULL);  n      #ifndef ONLINE_JUDGE n         freopen( input.txt , r ,stdin); n         freopen( output.txt , w ,stdout); n     #endif  n     int t=1,Tc=1; n     while(t--){ n         //cout <<  Case # <<Tc<< :  ; Tc++; n         solve(); n     } n   return 0; n }


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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