#include <bits/stdc++.h> n using namespace std; n const int p = 1e9 + 7, len = 1 << 16; n char ch[100012]; n int n, m, dp[502][100012], js, s[100012], tot, f[100012], val[100012]; n inline void fwt_or(int x[], int mde) { n   for (int i = 2; i <= len; i <<= 1) n     for (int j = 0, stp = i >> 1; j < len; j += i) n       for (int k = j; k < j + stp; k++) n         (x[k + stp] += 1ll * mde * x[k] % p) %= p; n } n inline void fwt_and(int x[], int mde) { n   for (int i = 2; i <= len; i <<= 1) n     for (int j = 0, stp = i >> 1; j < len; j += i) n       for (int k = j; k < j + stp; k++) n         (x[k] += 1ll * mde * x[k + stp] % p) %= p; n } n int solve(int l, int r) { n   int ret = ++js, mid; n   if (l == r) { n     if (ch[l] ==  ? ) { n       for (int i = 0; i < 4; i++) { n         int va = 0; n         for (int j = 0; j < 16; j++) n           if (j & (1 << i)) va |= 1 << j; n         dp[ret][va]++; n         va = 0; n         for (int j = 0; j < 16; j++) n           if (!(j & (1 << i))) va |= 1 << j; n         dp[ret][va]++; n       } n     } else if (ch[l] >=  A  && ch[l] <=  D ) { n       int va = 0; n       for (int j = 0; j < 16; j++) n         if (j & (1 << (ch[l] -  A ))) va |= 1 << j; n       dp[ret][va]++; n     } else { n       int va = 0; n       for (int j = 0; j < 16; j++) n         if (!(j & (1 << (ch[l] -  a )))) va |= 1 << j; n       dp[ret][va]++; n     } n     return ret; n   } n   tot = 0; n   for (int i = l; i <= r; i++) { n     if (ch[i] ==  ( ) n       s[++tot] = i; n     else if (ch[i] ==  ) ) n       tot--; n     else { n       if (!tot) { n         mid = i; n         break; n       } n     } n   } n   int ls = solve(l + 1, mid - 2), rs = solve(mid + 2, r - 1); n   if (ch[mid] ==  ? ) { n     fwt_or(dp[ls], 1); n     fwt_or(dp[rs], 1); n     for (int i = 0; i < len; i++) dp[ret][i] = 1ll * dp[ls][i] * dp[rs][i] % p; n     fwt_or(dp[ret], p - 1); n     fwt_or(dp[ls], p - 1); n     fwt_or(dp[rs], p - 1); n     fwt_and(dp[ls], 1); n     fwt_and(dp[rs], 1); n     for (int i = 0; i < len; i++) f[i] = 1ll * dp[ls][i] * dp[rs][i] % p; n     fwt_and(f, p - 1); n     fwt_and(dp[ls], p - 1); n     fwt_and(dp[rs], p - 1); n     for (int i = 0; i < len; i++) (dp[ret][i] += f[i]) %= p; n   } else if (ch[mid] ==  | ) { n     fwt_or(dp[ls], 1); n     fwt_or(dp[rs], 1); n     for (int i = 0; i < len; i++) dp[ret][i] = 1ll * dp[ls][i] * dp[rs][i] % p; n     fwt_or(dp[ret], p - 1); n     fwt_or(dp[ls], p - 1); n     fwt_or(dp[rs], p - 1); n   } else { n     fwt_and(dp[ls], 1); n     fwt_and(dp[rs], 1); n     for (int i = 0; i < len; i++) dp[ret][i] = 1ll * dp[ls][i] * dp[rs][i] % p; n     fwt_and(dp[ret], p - 1); n     fwt_and(dp[ls], p - 1); n     fwt_and(dp[rs], p - 1); n   } n   return ret; n } n int main() { n   scanf( %s , ch + 1); n   n = strlen(ch + 1); n   int rt = solve(1, n); n   memset(val, -1, sizeof(val)); n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) { n     int a, b, c, d, w; n     scanf( %d%d%d%d%d , &a, &b, &c, &d, &w); n     val[a | (b << 1) | (c << 2) | (d << 3)] = w; n   } n   int ans = 0; n   for (int i = 0; i < len; i++) { n     bool flag = true; n     for (int j = 0; j < 16; j++) n       if (val[j] != -1) { n         if (((i >> j) & 1) != val[j]) { n           flag = false; n           break; n         } n       } n     if (flag) ans = (ans + dp[rt][i]) % p; n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int func(int n) { n   int sum = 1; n   if (n == 3) return 4; n   if (n == 2) return 2; n   if (n == 1) return 1; n   if (n % 2 == 0) { n     sum += 2 * (n / 2 - 1) + 1 + func(n - 2); n   } else { n     sum += 2 * (n - 1) / 2 + func(n - 2); n   } n   return sum; n } n int main() { n   { n     int n; n     int r = 1; n     int i = 0; n     cin >> n; n     cout << func(n); n     return 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> s; n   long long n = s.size(); n   long long a = 0, b = 0; n   for (auto f : s) { n     a += (f ==  1 ); n     b += (f ==  0 ); n   } n   long long z = n - a - b; n   if (a < b + z) { n     cout <<  00  << endl; n   } n   if (n % 2 == 0 && s[n - 1] !=  0 ) { n     long long a1 = a, b1 = b; n     if (s[n - 1] ==  ? ) { n       a1++; n     } n     if (a1 <= n / 2 && b1 <= n / 2) { n       cout <<  01  << endl; n     } n   } else if (s[n - 1] !=  0 ) { n     long long a1 = a, b1 = b; n     if (s[n - 1] ==  ? ) { n       a1++; n     } n     if (a1 <= n / 2 + 1 && b1 <= n / 2) { n       cout <<  01  << endl; n     } n   } n   if (n % 2 == 0 && s[n - 1] !=  1 ) { n     long long a1 = a, b1 = b; n     if (s[n - 1] ==  ? ) { n       b1++; n     } n     if (a1 <= n / 2 && b1 <= n / 2) { n       cout <<  10  << endl; n     } n   } else if (s[n - 1] !=  1 ) { n     long long a1 = a, b1 = b; n     if (s[n - 1] ==  ? ) { n       b1++; n     } n     if (a1 <= n / 2 + 1 && b1 <= n / 2) { n       cout <<  10  << endl; n     } n   } n   if (a + z > b + 1) { n     cout <<  11  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e3 + 5; n int a[N], n; n int dp[N][N / 2][2][2]; n int solve(int idx, int lft, bool b4, bool b44) { n   if (lft < 0) return 1e9; n   if (idx == n) { n     if (lft) return 1e9; n     return 0; n   } n   int &ret = dp[idx][lft][b4][b44]; n   if (~ret) return ret; n   ret = solve(idx + 1, lft, 0, b4); n   if (!b4) { n     int x; n     int cost1 = 0, cost2 = 0; n     if (b44) { n       x = min(a[idx - 1], a[idx - 2] - 1); n     } else n       x = a[idx - 1]; n     if (idx) cost1 = max(0, x - (a[idx] - 1)); n     if (idx != n - 1) { n       cost2 = max(0, a[idx + 1] - (a[idx] - 1)); n     } n     ret = min(ret, solve(idx + 1, lft - 1, 1, 0) + cost1 + cost2); n   } n   return ret; n } n int main() { n   memset(dp, -1, sizeof dp); n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , a + i); n   for (int i = 1; i <= (n + 1) / 2; i++) { n     printf( %d  , solve(0, i, 0, 0)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int mod = 1e9 + 7; n const int sz = 1e5 + 10; n int main() { n   int n, x; n   set<int> ans, st, ha; n   while (cin >> n) { n     ans.clear(); n     st.clear(); n     for (int i = 0; i < n; i++) { n       ha.clear(); n       cin >> x; n       ha.insert(x); n       ans.insert(x); n       for (int xx : st) { n         ha.insert(x | xx); n         ans.insert(x | xx); n       } n       st = ha; n     } n     cout << ans.size() <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> arr(n + 1, -1); n   for (int i = 1; i <= n; i++) { n     int temp; n     cin >> temp; n     arr[i] = temp; n   } n   int ans = 0; n   vector<int> mini(n + 1, -1); n   vector<int> maxi(n + 1, -1); n   vector<int> equal(n + 1, -1); n   equal[1] = 1; n   mini[1] = 1; n   maxi[1] = 1; n   for (int i = 2; i <= n; i++) { n     if (arr[i] != arr[i - 1]) n       equal[i] = 1; n     else { n       equal[i] = equal[i - 1] + 1; n       mini[i] = mini[i - 1] + 1; n       maxi[i] = maxi[i - 1] + 1; n     } n     if (arr[i] > arr[i - 1]) { n       maxi[i] = max(mini[i - 1] + 1, equal[i - 1] + 1); n       mini[i] = 1; n     } n     if (arr[i] < arr[i - 1]) { n       mini[i] = max(maxi[i - 1] + 1, equal[i - 1] + 1); n       maxi[i] = 1; n     } n     int temp = max(mini[i], max(maxi[i], equal[i])); n     if (temp > ans) ans = temp; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 51123987; n string s; n int n; n long long d[50 + 10][50 + 10][150 + 10][3]; n int NEXT[150 + 10][5]; n inline int nex(int MIN, int c) { return NEXT[MIN][c]; } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> s; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= 3; ++j) { n       NEXT[i][j] = n + 1; n       for (int l = i - 1; l < s.size(); ++l) n         if (s[l] == char(j +  a  - 1)) { n           NEXT[i][j] = l + 1; n           break; n         } n     } n   { n     int ind = nex(1, 1); n     if (ind <= n) d[1][0][ind][1] = 1; n     ind = nex(1, 2); n     if (ind <= n) d[0][1][ind][1] = 1; n     ind = nex(1, 3); n     if (ind <= n) d[0][0][ind][1] = 1; n   } n   for (int i = 2; i <= n; ++i) { n     for (int j = 0; j <= 50; ++j) n       for (int l = 0; l <= 50; ++l) n         for (int k = 1; k <= n; ++k) { n           int ind = nex(k, 1); n           if (ind <= n) { n             d[j + 1][l][ind][0] += d[j][l][k][1]; n             if (d[j + 1][l][ind][0] > mod) d[j + 1][l][ind][0] -= mod; n           } n           ind = nex(k, 2); n           if (ind <= n) { n             d[j][l + 1][ind][0] += d[j][l][k][1]; n             if (d[j][l + 1][ind][0] > mod) d[j][l + 1][ind][0] -= mod; n           } n           ind = nex(k, 3); n           if (ind <= n) { n             d[j][l][ind][0] += d[j][l][k][1]; n             if (d[j][l][ind][0] > mod) d[j][l][ind][0] -= mod; n           } n         } n     for (int j = 0; j <= 50; ++j) n       for (int l = 0; l <= 50; ++l) n         for (int k = 1; k <= n; ++k) { n           d[j][l][k][1] = d[j][l][k][0]; n           d[j][l][k][0] = 0; n         } n   } n   long long ans = 0; n   for (int j = 0; j <= 50; ++j) n     for (int l = 0; l <= 50; ++l) n       for (int k = 1; k <= n; ++k) { n         int a = j; n         int b = l; n         int c = n - j - l; n         if (a >= 0 && b >= 0 && c >= 0) n           if (abs(a - b) <= 1 && abs(b - c) <= 1 && abs(a - c) <= 1) { n             ans += d[j][l][k][1]; n             ans %= mod; n           } n       } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int val, l, r; n } a[100010]; n int rt, n; n bool to[100010]; n map<int, bool> ma; n vector<int> v; n void dfs(int u, int maxx, int minn) { n   if (u == -1) return; n   if (a[u].val > maxx && a[u].val < minn) ma[a[u].val] = true; n   dfs(a[u].l, maxx, min(a[u].val, minn)); n   dfs(a[u].r, max(a[u].val, maxx), minn); n   return; n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     scanf( %d%d%d , &a[i].val, &a[i].l, &a[i].r); n     if (a[i].l != -1) to[a[i].l] = true; n     if (a[i].r != -1) to[a[i].r] = true; n   } n   for (int i = 1; i <= n; i++) n     if (to[i] == false) rt = i; n   dfs(rt, -1, 1e9 + 1); n   int ans = 0; n   for (int i = 1; i <= n; i++) n     if (ma[a[i].val] == false) ans++; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n struct node { n   int sig; n   int bz; n   char s[11]; n   int get() { n     int len = strlen(s); n     int x = 0; n     if (s[0] ==  0 ) return 0; n     for (int i = 0; i < len; i++) n       if (s[i] <  0  || s[i] >  9 ) n         return 0; n       else n         x = x * 10 + s[i] -  0 ; n     return x; n   } n } f[200000], g[200000], c[200000], d[200000]; n int a[200000 * 4], b[200000 * 4]; n int tot, m, calc, totc, totd; n int ans[200000][2]; n void ins(int* f, int l, int r, int s, int ll, int v) { n   if (l == r) { n     f[s] = v; n     return; n   } n   if ((l + r) / 2 >= ll) n     ins(f, l, (l + r) / 2, s + s, ll, v); n   else n     ins(f, (l + r) / 2 + 1, r, s + s + 1, ll, v); n   f[s] = min(f[s + s], f[s + s + 1]); n } n int get(int* f, int l, int r, int s) { n   if (l == r) { n     f[s] = 1; n     return l; n   } n   if (!f[s + s]) { n     int x = get(f, l, (l + r) / 2, s + s); n     f[s] = min(f[s + s], f[s + s + 1]); n     return x; n   } else { n     int x = get(f, (l + r) / 2 + 1, r, s + s + 1); n     f[s] = min(f[s + s], f[s + s + 1]); n     return x; n   } n } n void clear(int* f, int l, int r, int s, int ll) { n   if (l == r) { n     f[s] = 0; n     return; n   } n   if ((l + r) / 2 >= ll) n     clear(f, l, (l + r) / 2, s + s, ll); n   else n     clear(f, (l + r) / 2 + 1, r, s + s + 1, ll); n   f[s] = min(f[s + s], f[s + s + 1]); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf(  %s %d , f[i].s, &f[i].sig); n     f[i].bz = i; n     m += f[i].sig; n   } n   for (int i = 1; i <= n; i++) { n     int x = f[i].get(); n     if (x && x <= m) { n       ins(a, 1, m, 1, x, i); n       if (!f[i].sig) c[++totc] = f[i]; n     } else if (x && x <= n) { n       ins(b, 1, n - m, 1, x - m, i); n       if (f[i].sig) d[++totd] = f[i]; n     } else n       g[++tot] = f[i]; n   } n   int lc = 1, ld = 1, extra = n; n   int tot1 = tot; n   while (lc <= totc || ld <= totd) { n     if (!b[1] && lc <= totc) { n       ans[++calc][0] = c[lc].bz; n       ans[calc][1] = get(b, 1, n - m, 1) + m; n       clear(a, 1, m, 1, c[lc].get()); n       lc++; n     } else if (!a[1] && ld <= totd) { n       ans[++calc][0] = d[ld].bz; n       ans[calc][1] = get(a, 1, m, 1); n       clear(b, 1, n - m, 1, d[ld].get() - m); n       ld++; n     } else if (lc <= totc) { n       ans[++calc][0] = c[lc].bz; n       ans[calc][1] = ++extra; n       clear(a, 1, m, 1, c[lc].get()); n       g[++tot] = c[lc]; n       lc++; n     } else { n       ans[++calc][0] = d[ld].bz; n       ans[calc][1] = ++extra; n       clear(b, 1, n - m, 1, d[ld].get() - m); n       g[++tot] = d[ld]; n       ld++; n     } n   } n   for (int i = 1; i <= tot1; i++) n     if (g[i].sig) { n       ans[++calc][0] = g[i].bz; n       ans[calc][1] = get(a, 1, m, 1); n     } else { n       ans[++calc][0] = g[i].bz; n       ans[calc][1] = get(b, 1, n - m, 1) + m; n     } n   for (int i = tot; i > tot1; i--) n     if (g[i].sig) { n       ans[++calc][0] = -(extra); n       extra--; n       ans[calc][1] = get(a, 1, m, 1); n     } else { n       ans[++calc][0] = -(extra); n       extra--; n       ans[calc][1] = get(b, 1, n - m, 1) + m; n     } n   printf( %d n , calc); n   for (int i = 1; i <= calc; i++) n     if (ans[i][0] < 0) n       printf( move %d %d n , -ans[i][0], ans[i][1]); n     else n       printf( move %s %d n , f[ans[i][0]].s, ans[i][1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, k; n   cin >> n >> k; n   bool used[n]; n   for (int i = 0; i <= n - 1; i++) used[i] = false; n   int a = 0, b = n - 1; n   for (int i = 0; i <= k - 1; i++) { n     if (i & 1) n       used[b] = true; n     else n       used[a] = true; n     if (i & 1) n       cout << (1 + (b--)); n     else n       cout << (1 + (a++)); n     cout <<    ; n   } n   if (k & 1) { n     for (int i = 0; i <= n - 1; i++) { n       if (!used[i]) { n         cout << i + 1 <<    ; n       } n     } n   } else { n     for (int i = n - 1; i >= 0; --i) { n       if (!used[i]) { n         cout << i + 1 <<    ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[26]; n char s[100001]; n int gcd(int a, int b) { n   if (a % b == 0) { n     return b; n   } else { n     return gcd(b, a % b); n   } n } n int main() { n   int n, ans, sum = 0, c = 0, i, j, k, l; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     sum += a[i]; n     if (a[i] % 2 == 1) c++; n   } n   if (c >= 2) { n     ans = 0; n     for (i = 0, j = 0; i < n; i++) { n       while (a[i] > 0) { n         s[j++] =  a  + i; n         a[i]--; n       } n     } n   } else { n     ans = a[0]; n     for (i = 1; i < n; i++) ans = gcd(ans, a[i]); n     if (c == 1) { n       int p; n       for (i = 0; i < n; i++) { n         if (a[i] % 2 == 1) { n           p = i; n           a[i] -= ans; n         } n       } n       for (i = 0, l = 0; i < ans * 2; i++) { n         if (i % 2 == 0) { n           for (j = 0; j < n; j++) { n             for (k = 0; k < a[j] / ans / 2; k++) s[l++] =  a  + j; n           } n           s[l++] =  a  + p; n         } else { n           for (j = n - 1; j >= 0; j--) { n             for (k = 0; k < a[j] / ans / 2; k++) s[l++] =  a  + j; n           } n         } n       } n     } else { n       for (i = 0, l = 0; i < ans; i++) { n         if (i % 2 == 0) { n           for (j = 0; j < n; j++) { n             for (k = 0; k < a[j] / ans; k++) s[l++] =  a  + j; n           } n         } else { n           for (j = n - 1; j >= 0; j--) { n             for (k = 0; k < a[j] / ans; k++) s[l++] =  a  + j; n           } n         } n       } n     } n   } n   printf( %d n , ans); n   printf( %s n , s); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int d, n, a, s = 0, k; n   scanf( %d , &d); n   scanf( %d , &n); n   scanf( %d , &a); n   for (k = 1; k < n; k++) { n     s += d - a; n     scanf( %d , &a); n   } n   printf( %d n , s); n   return 0; n } n


#include <bits/stdc++.h> n int main(void) { n   int n, m; n   scanf( %d %d , &n, &m); n   long long a[1000 + 1]; n   long long t[1000 + 1 + 1][1000 + 1]; n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n   } n   for (int j = 0; j <= n; j++) t[n + 1][j] = 0; n   for (int i = n; i >= 1; i--) { n     for (int j = 0; j <= n; j++) { n       t[i][j] = n           std::min(t[i + 1][j] - a[i], (j > 0) ? t[i + 1][j - 1] : 1LL << 60LL); n       t[i][j] = std::max(t[i][j], 0LL); n     } n   } n   std::vector<std::pair<long long, int>> values; n   for (int j = 0; j <= n; j++) { n     if (j == 0 || t[1][j] != t[1][j - 1]) n       values.push_back(std::make_pair(t[1][j], j)); n   } n   std::sort(values.begin(), values.end()); n   for (int i = 0; i < m; i++) { n     long long b; n     scanf( %lld , &b); n     auto it = n         std::lower_bound(values.begin(), values.end(), std::make_pair(b, -1)); n     if (it == values.end() || it->first > b) it--; n     printf( %d n , it->second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18 + 7; n long long f[53], fac[53]; n long long add(long long a, long long b) { return min(INF, a + b); } n long long mul(long long a, long long b) { n   if (INF / a < b) return INF; n   return a * b; n } n const int N = 50; n long long g(int n) { n   if (n == 1) return 1; n   return fac[n - 2]; n } n void init() { n   fac[0] = 1; n   for (int i = 1; i <= N; i++) fac[i] = mul(fac[i - 1], i); n   f[0] = 1; n   for (int i = 1; i <= N; i++) n     for (int j = 1; j <= i; j++) f[i] = add(f[i], mul(f[i - j], g(j))); n   return; n } n int p[53]; n int q[53]; n bool vis[53]; n int find(int x) { n   while (q[x]) x = q[x]; n   return x; n } n void getq(int n, long long k) { n   if (n == 1) { n     q[1] = 1; n     return; n   } n   for (int i = 1; i <= n; i++) q[i] = vis[i] = 0; n   q[1] = n; n   vis[n] = 1; n   for (int i = 2; i < n; i++) { n     long long num = fac[n - i - 1]; n     for (int j = 1; j <= n; j++) n       if (j != i && !vis[j] && find(j) != i) { n         if (k <= num) { n           q[i] = j; n           vis[j] = true; n           break; n         } n         k -= num; n       } n   } n   for (int i = 1; i <= n; i++) n     if (!vis[i]) q[n] = i; n   return; n } n void getp(int n, long long k) { n   if (!n) return; n   int len = 0; n   for (int i = 1; i <= n; i++) { n     long long num = mul(g(i), f[n - i]); n     if (k <= num) { n       len = i; n       break; n     } n     k -= num; n   } n   long long num = f[n - len]; n   long long need = (k - 1) / num + 1; n   getp(n - len, k - (need - 1) * num); n   for (int i = n; i > len; i--) p[i] = p[i - len] + len; n   getq(len, need); n   for (int i = 1; i <= len; i++) p[i] = q[i]; n   return; n } n int main() { n   init(); n   int t; n   scanf( %d , &t); n   while (t--) { n     int n; n     long long k; n     scanf( %d %lld , &n, &k); n     if (f[n] < k) n       printf( -1 n ); n     else { n       getp(n, k); n       for (int i = 1; i <= n; i++) printf( %d  , p[i]); n       printf(  n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n bitset<100005> m[70], tmp, tmpp; n int f[100], ftop = 60; n int ans[100010]; n void swap(int x, int y) { n   tmp = m[x]; n   m[x] = m[y]; n   m[y] = tmp; n } n int main() { n   int i, j, k, d = 60; n   long long x, s = 0; n   scanf( %d , &n); n   for (i = 1; i <= n; ++i) { n     scanf( %I64d , &x); n     s ^= x; n     for (j = 0; j < 60; ++j) n       if (x & (1ll << j)) m[j][i] = 1; n   } n   for (i = 59; ~i; --i) n     if (!(s & (1ll << i))) { n       --d; n       tmpp = m[i]; n       for (j = i; j < d; ++j) m[j] = m[j + 1]; n       m[d] = tmpp; n     } n   for (i = 59; ~i; --i) { n     if (i >= d) m[i][0] = 1; n     for (j = 59; j >= ftop; --j) n       if (m[i][f[j]]) m[i] ^= m[j]; n     for (k = 1; k <= n && m[i][k] == 0; ++k) n       ; n     if (n < k) n       m[i][0] = 0; n     else { n       for (j = 59; j >= ftop; --j) n         if (m[j][k]) m[j] ^= m[i]; n       --ftop; n       f[ftop] = k; n       swap(ftop, i); n     } n   } n   for (i = 59; i >= ftop; --i) n     if (m[i][0]) ans[f[i]] = 1; n   for (i = 1; i <= n; ++i) printf( %d  , ans[i] ? 1 : 2); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int max_n = 300011, log_n = 32, max_m = 111, mod = 1000000007, n           inf = 1011111111; n const long double eps = 1e-7; n struct bor { n   stack<pair<int, int> > st; n   int t[max_n][27], res[max_n], sz[max_n], n; n   bor() { n     for (int i = 0; i < max_n; ++i) { n       for (int q = 0; q < 27; ++q) { n         t[i][q] = -1; n       } n     } n   } n   void add(int x, int y, char c) { t[x][c -  a ] = y; } n   int get_sz(int v) { n     int ans = 1; n     for (int i = 0; i < 26; ++i) { n       if (t[v][i] != -1) { n         ans += get_sz(t[v][i]); n       } n     } n     return sz[v] = ans; n   } n   int mrg(int v, int v1) { n     int ans = 1; n     for (int i = 0; i < 27; ++i) { n       if (t[v][i] != -1 && t[v1][i] != -1) { n         ans += mrg(t[v][i], t[v1][i]); n       } else if (t[v][i] != -1) { n         t[v1][i] = t[v][i]; n         st.push(make_pair(v1, i)); n       } n     } n     return ans; n   } n   void get(int v, int p) { n     int mx = 0, mxx = -1; n     for (int i = 0; i < 26; ++i) { n       if (t[v][i] != -1 && mx < sz[t[v][i]]) { n         mx = sz[t[v][i]]; n         mxx = i; n       } n     } n     if (mxx == -1) { n       return; n     } n     res[p]++; n     for (int i = 0; i < 26; ++i) { n       if (i == mxx) continue; n       if (t[v][i] != -1) { n         res[p] += mrg(t[v][i], t[v][mxx]); n       } n     } n     while (st.size()) { n       t[st.top().first][st.top().second] = -1; n       st.pop(); n     } n   } n   void get_all(int v, int p) { n     get(v, p); n     for (int i = 0; i < 26; ++i) { n       if (t[v][i] != -1) { n         get_all(t[v][i], p + 1); n       } n     } n   } n }; n bor br; n int n; n int main() { n   cin >> n; n   for (int i = 0; i < n - 1; ++i) { n     int a, b; n     char c; n     cin >> a >> b >> c; n     br.add(a - 1, b - 1, c); n   } n   br.get_sz(0); n   br.get_all(0, 0); n   int mx = 0, mxx = 0; n   for (int i = 0; i < n; ++i) { n     if (mx < br.res[i]) { n       mx = br.res[i]; n       mxx = i; n     } n   } n   cout << n - mx << endl << mxx + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double a, b, c, d; n   cin >> a >> b >> c >> d; n   double mx; n   mx = (a / b) * (1 / (1 - (1 - a / b) * (1 - c / d))); n   std::cout << std::setprecision(9) << mx <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void Read(T &x) { n   int f = 1; n   char t = getchar(); n   while (t <  0  || t >  9 ) { n     if (t ==  - ) f = -1; n     t = getchar(); n   } n   x = 0; n   while (t >=  0  && t <=  9 ) { n     x = x * 10 + t -  0 ; n     t = getchar(); n   } n   x *= f; n } n template <class T> n inline void chkmin(T &x, T y) { n   if (x > y) x = y; n } n template <class T> n inline void chkmax(T &x, T y) { n   if (x < y) x = y; n } n const int maxn = 200005; n const double inf = 2e18; n const double pi = acos(-1.0); n struct point { n   long double x, y; n   point() {} n   point(long double x, long double y) : x(x), y(y) {} n   void read() { cin >> x >> y; } n }; n point operator+(const point &a, const point &b) { n   return point(a.x + b.x, a.y + b.y); n } n point operator-(const point &a, const point &b) { n   return point(a.x - b.x, a.y - b.y); n } n point operator*(const point &a, long double v) { n   return point(a.x * v, a.y * v); n } n point operator/(const point &a, long double v) { n   return point(a.x / v, a.y / v); n } n long double operator^(const point &a, const point &b) { n   return a.x * b.y - a.y * b.x; n } n int n; n point P, g[maxn]; n long double dis(point &a, point &b) { n   return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); n } n long double maxr = -inf, minr = inf; n void calc(point &a, point &b) { n   long double A = dis(a, P), B = dis(b, P), C = dis(a, b); n   long double area = (a - P) ^ (b - P); n   long double Height = area * area / C; n   if (A < B) swap(A, B); n   if (A > B + C) return; n   chkmax(maxr, Height); n   chkmin(minr, Height); n } n void input() { n   Read(n); n   P.read(); n   for (register int i = 1; i <= n; i++) g[i].read(); n   g[0] = g[n]; n   for (register int i = 1; i <= n; i++) calc(g[i], g[i - 1]); n } n void solve() { n   for (register int i = 1; i <= n; i++) { n     chkmax(maxr, dis(g[i], P)); n     chkmin(minr, dis(g[i], P)); n   } n   printf( %.18lf n , (double)(maxr - minr) * pi); n } n int main() { n   input(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n long long power(long long a, long long b, long long md) { n   return (!b ? 1 n              : (b & 1 ? a * power(a * a % md, b / 2, md) % md n                       : power(a * a % md, b / 2, md) % md)); n } n const int xn = 1e3 + 10; n const int xm = 2e4 + 10; n const int sq = 300; n const int inf = 1e9 + 10; n const long long INF = 1e18 + 10; n const int mod = 1e6 + 7; n const int base = 257; n const int SIG = 26; n int n, k, tb[1 << 20], dp[xn][xm], ptr, a[xm], C[xm][SIG], ans = inf; n string S; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> S >> k, n = int(S.size()); n   if (k == 1) { n     ans = 0; n     for (int i = 0; i < n; ++i) ans += (S[i] ==  1 ); n     return cout << ans <<   n , 0; n   } n   for (int mask = 0; mask < (1 << k); ++mask) { n     bool flag = true; n     for (int i = 0; i < k; ++i) n       flag &= (!((mask & (1 << i))) | !(mask & (1 << (i + 1)))); n     flag &= !(mask & 1), flag &= !(mask & 2); n     if (flag) tb[mask] = ptr, a[ptr++] = mask; n   } n   for (int t = 0; t < ptr; ++t) { n     int mask = a[t] + 1; n     for (int i = 2; i < 10; ++i) { n       for (int bit = i; bit <= k; ++bit) n         if ((mask & (1 << (bit - i)))) C[t][i] += (1 << bit); n       bool flag = !(C[t][i] & (1 << k)); n       for (int j = 1; j < k; ++j) n         if (k % j == 0) flag |= (C[t][i] & (1 << j)); n       for (int b1 = 2; b1 < k; ++b1) n         for (int b2 = b1 + 1; b2 <= k; ++b2) n           if ((C[t][i] & (1 << b1)) && (C[t][i] & (1 << b2))) n             flag |= (k % (b2 - b1) == 0); n       C[t][i] = (C[t][i] & (C[t][i] ^ (1 << k))); n       if (!flag) C[t][i] = -1; n     } n   } n   for (int i = 0; i < xn; ++i) n     for (int j = 0; j < ptr; ++j) dp[i][j] = inf; n   dp[0][0] = 0; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < ptr; ++j) { n       int mask = a[j]; n       if (S[i] ==  1 ) n         dp[i + 1][0] = min(dp[i + 1][0], dp[i][j]); n       else { n         dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1); n         int x = C[j][S[i] -  0 ]; n         if (x != -1) dp[i + 1][tb[x]] = min(dp[i + 1][tb[x]], dp[i][j]); n       } n     } n   } n   for (int i = 0; i < ptr; ++i) ans = min(ans, dp[n][i]); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 109; n int a[MAX], n, k, t = 1e9, s; n int main() { n   cin >> n; n   for (int i = 0; i < 2 * n - 1; i++) { n     cin >> a[i], s += abs(a[i]), t = min(t, abs(a[i])); n     if (a[i] < 0) k++; n   } n   if (k % 2 && n % 2 == 0) s -= 2 * t; n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n int nor[200100 * 2], n, t, m, a[200100], b[200100], sola, solb, sol, pcta, pctb; n int main() { n   cin >> n; n   nor[++t] = 0; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     nor[++t] = a[i]; n   } n   cin >> m; n   for (int i = 1; i <= m; ++i) { n     cin >> b[i]; n     nor[++t] = b[i]; n   } n   sort(nor + 1, nor + t + 1); n   sort(a + 1, a + n + 1); n   sort(b + 1, b + m + 1); n   nor[++t] = max(a[n], b[n]) + 1; n   sol = -(1 << 30); n   for (int i = 1; i <= t; ++i) { n     int mij; n     int st = 1, dr = n; n     while (st <= dr) { n       mij = (st + dr) >> 1; n       if (a[mij] <= nor[i]) n         st = mij + 1; n       else n         dr = mij - 1; n     } n     pcta = (st - 1) * 2 + (n - (st - 1)) * 3; n     st = 1, dr = m; n     while (st <= dr) { n       mij = (st + dr) >> 1; n       if (b[mij] <= nor[i]) n         st = mij + 1; n       else n         dr = mij - 1; n     } n     pctb = (st - 1) * 2 + (m - (st - 1)) * 3; n     if (pcta - pctb > sol) { n       sol = pcta - pctb; n       sola = pcta; n       solb = pctb; n     } else if (pcta - pctb == sol && pcta > sola) { n       sola = pcta; n       solb = pctb; n     } n   } n   cout << sola <<  :  << solb; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n std::vector<int> Edge[510]; n std::vector<int> Current[510]; n int Right[510]; n int Left[510]; n int Vis[510]; n int N, M; n bool dfs(int idx) { n   if (Vis[idx]) return false; n   Vis[idx] = 1; n   for (int i = 0; i < Current[idx].size(); i++) { n     int v = Current[idx][i]; n     if (Left[v] == -1 || dfs(Left[v])) { n       Left[v] = idx; n       Right[idx] = v; n       return true; n     } n   } n   return false; n } n int bpm() { n   int Ans = 0; n   memset(Left, -1, sizeof(Left)); n   memset(Right, -1, sizeof(Right)); n   for (int i = 0; i < N; i++) { n     memset(Vis, false, sizeof(Vis)); n     Ans += dfs(i); n   } n   return Ans; n } n int main() { n   cin >> N >> M; n   int u, v; n   for (int i = 0; i < M; i++) { n     cin >> u >> v; n     u -= 1, v -= 1; n     Edge[u].push_back(v); n   } n   int Ans = 1e9; n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < N; j++) Current[j].clear(); n     int cnt = 0, other = 0; n     for (int j = 0; j < N; j++) { n       for (int k = 0; k < Edge[j].size(); k++) { n         if (j == i || Edge[j][k] == i) { n           cnt += 1; n           continue; n         } n         other += 1; n         Current[j].push_back(Edge[j][k]); n       } n     } n     int max_match = bpm(); n     Ans = min(Ans, 2 * N - 1 + other - cnt - 2 * max_match + N - 1); n   } n   cout << Ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(0); n   cin.sync_with_stdio(0); n   int n, t1, t2; n   double k; n   cin >> n >> t1 >> t2 >> k; n   k /= 100; n   k = 1 - k; n   double c[n + 1]; n   for (int i = 1; i <= n; i++) { n     int a, b; n     cin >> a >> b; n     int tema = a; n     int temb = b; n     a = max(a, temb); n     b = min(tema, b); n     if (t1 * k >= t2) { n       c[i] = t1 * a * k + t2 * b; n     } else { n       c[i] = t1 * b * k + t2 * a; n     } n   } n   int g[n + 1]; n   for (int i = 1; i <= n; i++) { n     g[i] = i; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = i; j <= n; j++) { n       if (c[j] > c[i] || (c[j] == c[i] && g[j] < g[i])) { n         double temb = c[i]; n         c[i] = c[j]; n         c[j] = temb; n         int temb2 = g[i]; n         g[i] = g[j]; n         g[j] = temb2; n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     cout << g[i] <<     << fixed << setprecision(2) << c[i] <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100 * 1000 + 10; n vector<int> u[N], v[N], v2[N]; n vector<pair<int, int> > q[N]; n int t, st[N], fi[N], di[N], g[N], par[N]; n int root(int u) { return (par[u] == u) ? u : par[u] = root(par[u]); } n void merge1(int x, int y) { n   int dx = root(x), dy = root(y); n   if (dx == dy) return; n   par[dy] = dx; n } n bool mark[N], ans[N]; n void dfs(int u) { n   mark[u] = true; n   st[u] = t++; n   for (int i = 0; i < v[u].size(); i++) { n     if (!mark[v[u][i]]) dfs(v[u][i]); n   } n   fi[u] = t++; n } n int main() { n   int n, m, p = 1, j = 1; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int a, b, c; n     cin >> a; n     u[i].push_back(a); n     if (a == 1) { n       cin >> b >> c; n       u[i].push_back(b); n       u[i].push_back(c); n       v[c].push_back(b); n       di[b]++; n     } n     if (a == 2) { n       cin >> b; n       u[i].push_back(b); n       u[i].push_back(p); n       p++; n     } n     if (a == 3) { n       cin >> b >> c; n       u[i].push_back(b); n       u[i].push_back(c); n       q[c].push_back({b, j++}); n     } n   } n   for (int i = 1; i <= n; i++) par[i] = i; n   for (int i = 1; i <= n; i++) { n     if (di[i] == 0) dfs(i); n   } n   for (int i = 1; i <= n; i++) { n   } n   for (int i = 0; i < m; i++) { n     int a = u[i][0], b = u[i][1], c = u[i][2]; n     if (u[i][0] == 1) merge1(b, c); n     if (u[i][0] == 2) { n       for (int i = 0; i < q[c].size(); i++) { n         int qu = q[c][i].first, kj = q[c][i].second; n         if (st[qu] <= st[b] && fi[qu] >= fi[b] && root(qu) == root(b)) n           ans[kj] = true; n         else n           ans[kj] = false; n       } n     } n   } n   for (int i = 1; i < j; i++) { n     if (ans[i]) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a; n   int b; n   cin >> a >> b; n   cout.precision(13); n   if (b > a) { n     cout << -1; n   } else if ((a % b == 0) && ((a / b) % 2 == 1)) { n     cout << b; n   } else { n     int k = a / b; n     if (k % 2 == 0) { n       k--; n     } n     int dist = a - k * b; n     double x1 = b; n     double x2 = (double)dist / (double)k + (double)b; n     double x = x1; n     double ang; n     double x_old; n     for (int i = 0; i < 50; i++) { n       ang = (x - b) / (k * x - a); n       x_old = x; n       if (ang > -1) { n         x = (x + x2) / 2.0; n         x1 = x_old; n       } else if (ang < -1) { n         x = (x + x1) / 2.0; n         x2 = x_old; n       } else { n         cout << x; n         return 0; n       } n     } n     cout << x; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n const long long maxn = 3e6; n const long long mod = 1e9 + 7; n const long double PI = acos((long double)-1); n long long pw(long long a, long long b, long long md = mod) { n   long long res = 1; n   while (b) { n     if (b & 1) { n       res = (a * res) % md; n     } n     a = (a * a) % md; n     b >>= 1; n   } n   return (res); n } n string s[4]; n bool hor(int x, int y) { n   if (x < 1 or x > 2) return (0); n   int cnt = 0; n   if (s[x][y] ==  o ) return (0); n   if (s[x][y] ==  . ) cnt++; n   if (s[x - 1][y] ==  o ) return (0); n   if (s[x - 1][y] ==  . ) cnt++; n   if (s[x + 1][y] ==  o ) return (0); n   if (s[x + 1][y] ==  . ) cnt++; n   return (cnt < 2); n } n bool ver(int x, int y) { n   if (y < 1 or y > 2) return (0); n   int cnt = 0; n   if (s[x][y] ==  o ) return (0); n   if (s[x][y] ==  . ) cnt++; n   if (s[x][y - 1] ==  o ) return (0); n   if (s[x][y - 1] ==  . ) cnt++; n   if (s[x][y + 1] ==  o ) return (0); n   if (s[x][y + 1] ==  . ) cnt++; n   return (cnt < 2); n } n bool dia(int x, int y) { n   int cnt = 0; n   if (x < 1 or x > 2) return (0); n   if (y < 1 or y > 2) return (0); n   if (s[x][y] ==  o ) return (0); n   if (s[x][y] ==  . ) cnt++; n   if (s[x - 1][y - 1] ==  o ) return (0); n   if (s[x - 1][y - 1] ==  . ) cnt++; n   if (s[x + 1][y + 1] ==  o ) return (0); n   if (s[x + 1][y + 1] ==  . ) cnt++; n   return (cnt < 2); n } n bool diag(int x, int y) { n   int cnt = 0; n   if (x < 1 or x > 2) return (0); n   if (y < 1 or y > 2) return (0); n   if (s[x][y] ==  o ) return (0); n   if (s[x][y] ==  . ) cnt++; n   if (s[x - 1][y + 1] ==  o ) return (0); n   if (s[x - 1][y + 1] ==  . ) cnt++; n   if (s[x + 1][y - 1] ==  o ) return (0); n   if (s[x + 1][y - 1] ==  . ) cnt++; n   return (cnt < 2); n } n bool chk(int x, int y) { n   if (ver(x, y)) return (1); n   if (hor(x, y)) return (1); n   if (dia(x, y)) return (1); n   if (diag(x, y)) return (1); n   return (0); n } n int32_t main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   for (int i = 0; i < 4; i++) cin >> s[i]; n   for (int i = 0; i < 4; i++) n     for (int j = 0; j < 4; j++) n       if (chk(i, j)) cout <<  YES , exit(0); n   cout <<  NO ; n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { puts( INTERCAL ); } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, sy, sx; n   cin >> n >> m >> sy >> sx; n   int up = sy; n   int down = sy + 1; n   int l = sx; n   int r = sx + 1; n   int k = 2; n   while (up >= 1) { n     while (l >= 1) { n       cout << up <<     << l << endl; n       l--; n     } n     while (r <= m) { n       cout << up <<     << r << endl; n       r++; n     } n     up--; n     if (k % 2 == 0) n       l = m; n     else n       r = 1; n     k++; n   } n   while (down <= n) { n     while (l >= 1) { n       cout << down <<     << l << endl; n       l--; n     } n     while (r <= m) { n       cout << down <<     << r << endl; n       r++; n     } n     down++; n     if (k % 2 == 0) n       l = m; n     else n       r = 1; n     k++; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<pair<int, int> > a_sent; n vector<pair<int, int> > b_sent; n set<pair<int, int> > a_possible; n set<pair<int, int> > b_possible; n int vis[10]; n bool certain(pair<int, int> a, vector<pair<int, int> > sent) { n   bool can_x = false; n   bool can_y = false; n   for (pair<int, int> b : sent) { n     if (0) { n       printf( has: [%d, %d], try: [%d, %d] n , a.first, a.second, b.first, n              b.second); n     } n     if (a.first == b.first && a.second == b.second) continue; n     if (a.first == b.second && a.second == b.first) continue; n     if (a.first != b.first && a.second != b.second && a.first != b.second && n         a.second != b.first) n       continue; n     if (a.first == b.first || a.first == b.second) can_x = true; n     if (a.second == b.first || a.second == b.second) can_y = true; n   } n   if (0) printf( can_x: %d, can_y: %d n , can_x, can_y); n   return (can_x && !can_y) || (can_y && !can_x); n } n int main() { n   cin >> n >> m; n   while (n--) { n     pair<int, int> pair; n     cin >> pair.first >> pair.second; n     if (pair.first < pair.second) swap(pair.first, pair.second); n     a_sent.push_back(pair); n   } n   while (m--) { n     pair<int, int> pair; n     cin >> pair.first >> pair.second; n     if (pair.first < pair.second) swap(pair.first, pair.second); n     b_sent.push_back(pair); n   } n   for (pair<int, int> a : a_sent) { n     for (pair<int, int> b : b_sent) { n       if (a.first == b.first && a.second == b.second) continue; n       if (a.first == b.second && a.second == b.first) continue; n       if (a.first != b.first && a.second != b.second && a.first != b.second && n           a.second != b.first) n         continue; n       if (a.first == b.first) vis[a.first]++; n       if (a.second == b.second) vis[a.second]++; n       if (a.first == b.second) vis[a.first]++; n       if (a.second == b.first) vis[a.second]++; n       a_possible.insert(a); n       b_possible.insert(b); n     } n   } n   int cnt = 0; n   for (int i = 1; i <= 9; ++i) { n     cnt += vis[i] >= 1; n     if (0) printf( vis[%d] = %d n , i, vis[i]); n   } n   if (0) cout << cnt << endl; n   if (cnt == 1) { n     for (int i = 1; i <= 9; ++i) { n       if (vis[i] >= 1) { n         cout << i << endl; n         return 0; n       } n     } n   } n   for (pair<int, int> a : a_possible) { n     if (!certain(a, b_sent)) { n       cout << -1 << endl; n       return 0; n     } n   } n   for (pair<int, int> b : b_possible) { n     if (!certain(b, a_sent)) { n       cout << -1 << endl; n       return 0; n     } n   } n   cout << 0 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, x, y, z, e, s, max1, max2, max3, max4; n   cin >> a >> b >> c; n   x = a + b * c; n   y = a * (b + c); n   z = a * b * c; n   e = (a + b) * c; n   s = a + b + c; n   max1 = (x + y + abs(x - y)) / 2; n   max2 = (max1 + z + abs(max1 - z)) / 2; n   max3 = (max2 + e + abs(max2 - e)) / 2; n   max4 = (max3 + s + abs(max3 - s)) / 2; n   cout << max4 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 10; n const int SZ = 2e5 + 10; n const int mod = 1e9 + 7; n long long read() { n   long long n = 0; n   char a = getchar(); n   bool flag = 0; n   while (a >  9  || a <  0 ) { n     if (a ==  - ) flag = 1; n     a = getchar(); n   } n   while (a <=  9  && a >=  0 ) { n     n = n * 10 + a -  0 , a = getchar(); n   } n   if (flag) n = -n; n   return n; n } n int a[SZ], b[SZ], p[SZ], pri[SZ], vis[SZ]; n int main() { n   int n = read(), x = read(); n   for (int i = 1, j = 0; i < (1 << n); i++) { n     if (i == x) n       continue; n     else { n       if (x < (1 << n)) { n         int ii = x ^ i; n         if (ii < i) a[++a[0]] = i; n       } else n         a[++a[0]] = i; n     } n   } n   for (int i = a[0]; i >= 2; i--) a[i] ^= a[i - 1]; n   printf( %d n , a[0]); n   for (int i = 1; i <= a[0]; i++) printf( %d  , a[i]); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 100; n long long f[N + 5][N + 5][N + 5]; n long long fac[N + 5], C[N + 5][N + 5]; n long long mod; n long long dfs(int n, int m, int k) { n   if (n == 0) return k == 0; n   if (m == 1) return k == 1 ? fac[n] : 0; n   if (n == 1) return k == 0; n   if (2 * k > n + 1) return 0; n   if (m > n) return k == 0 ? fac[n] : 0; n   if (f[n][m][k] != -1) return f[n][m][k]; n   long long ans = 0; n   for (int i = 0; i < n; i++) n     for (int j = 0; j <= k; j++) n       ans = (ans + C[n - 1][i] * dfs(i, m - 1, j) % mod * n                        dfs(n - i - 1, m - 1, k - j) % mod) % n             mod; n   return f[n][m][k] = ans; n } n int main() { n   memset(f, 0xff, sizeof(f)); n   int n, m, k; n   scanf( %d%d%d%lld , &n, &m, &k, &mod); n   for (int i = 0; i <= N; i++) C[i][0] = C[i][i] = 1; n   for (int i = 1; i <= N; i++) n     for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod; n   fac[0] = fac[1] = 1; n   for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % mod; n   printf( %lld , dfs(n, m, k)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3 + 5; n int P[N], I[N]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &P[i]); n   } n   int id = 1; n   for (int i = 1; i <= n; i++) { n     int cur = i; n     while (I[cur] != id) { n       I[cur] = id; n       cur = P[cur]; n     } n     id++; n     printf( %d  , cur); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18; n const long long maxu = 200005; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long i, j, k = 0, n, t = 1, m, l = 0; n   cin >> t; n   while (t--) { n     cin >> n; n     long long a[n]; n     long long b[n + 2]; n     long long cnt = 0; n     long long idx = -1; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n       if (a[i] != i + 1) { n         if (idx == -1) { n           idx = i; n         } n         b[i] = 0; n         cnt++; n       } else n         b[i] = 1; n     } n     if (cnt == 0) { n       cout << 0 <<   n ; n       continue; n     } n     if (cnt == n) { n       cout << 1 <<   n ; n       continue; n     } n     long long ans = 0; n     for (i = idx; i <= idx + cnt - 1; i++) { n       if (b[i] == 0) ans++; n     } n     if (ans == cnt) { n       cout << 1 <<   n ; n     } else n       cout << 2 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, k, op, val1, val2; n   while (cin >> x >> k) { n     int mini = 0, maxi = 0; n     maxi = x - 1; n     vector<int> T(4005); n     for (int i = 0; i < k; ++i) { n       cin >> op; n       if (op == 2) { n         cin >> val1; n         T[val1] = 1; n       } else { n         cin >> val1 >> val2; n         T[val1] = T[val2] = 1; n       } n       if (op == 2) n         maxi--; n       else n         maxi -= 2; n     } n     T[x] = 1; n     for (int i = 1; i <= x; ++i) n       if (T[i] == 0) { n         int ind; n         for (int j = i; j <= x; ++j) n           if (T[j] == 0) n             ind = j; n           else n             break; n         mini += ((ind - i + 1) - 1) / 2 + 1; n         i = ind; n       } n     cout << mini <<     << maxi << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void file() {} n using lli = long long int; n using pii = pair<int, int>; n using vi = vector<int>; n using vvi = vector<vi>; n void solve() { n   string s; n   cin >> s; n   string res =   ; n   int z = 0, ones = 0, two = s.size(); n   for (int i = 0; i < s.size(); i++) { n     int x = s[i] -  0 ; n     if (x == 1) ones++; n     if (x == 2 && two == s.size()) two = i; n     if (x == 0 && two == s.size()) z++; n   } n   res += string(z,  0 ); n   res += string(ones,  1 ); n   for (int i = two; i < s.size(); i++) { n     int x = s[i] -  0 ; n     if (x == 1) continue; n     res += s[i]; n   } n   cout << res << endl; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, i, ans, m, j, k; n   string s; n   cin >> n >> s; n   ans = 0; n   char ch; n   for (i = 25; i >= 0; i--) { n     ch = i +  a ; n     for (j = 1; j < (long long)s.size(); j++) { n       if (s[j] == ch and s[j - 1] + 1 == ch) { n         s.erase(s.begin() + j); n         ans++; n         j--; n       } n     } n     for (j = 0; j < (long long)s.size() - 1; j++) { n       if (s[j] == ch and s[j + 1] + 1 == ch) { n         s.erase(s.begin() + j); n         ans++; n         j -= 2; n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long ara[20], ara1[20]; n   for (long long i = 1; i <= 14; i++) { n     scanf( %I64d , &ara[i]); n   } n   long long maxi = 0; n   long long sum, c; n   for (long long i = 1; i <= 14; i++) { n     if (ara[i] == 0) { n       continue; n     } n     long long d = ara[i] / 14; n     long long e = ara[i] % 14; n     memset(ara1, 0, sizeof(ara1)); n     sum = 0, c = 0; n     if (d > 0) { n       for (long long j = i + 1;; j++) { n         if (j > 14) { n           j = j % 14; n           if (j == 0) { n             j = 14; n           } n         } n         if (i == j) { n           ara1[j] = d; n           break; n         } n         ara1[j] = ara[j] + d; n       } n     } n     for (long long j = i + 1;; j++) { n       if (j > 14) { n         j = j % 14; n         if (j == 0) { n           j = 14; n         } n       } n       if (d == 0) { n         ara1[j] = ara[j] + 1; n       } else { n         ara1[j] = ara1[j] + 1; n       } n       c++; n       if (c >= e) { n         break; n       } n     } n     for (int j = 1; j <= 14; j++) { n       if (ara1[j] % 2 == 0) { n         sum = sum + ara1[j]; n       } n     } n     if (sum > maxi) { n       maxi = sum; n     } n   } n   printf( %I64d n , maxi); n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> mp; n int main() { n   vector<int> v, v1; n   long long a, b, c, d, e; n   cin >> a >> b >> c; n   for (int i = 0; i < b; i++) { n     cin >> d; n     v.push_back(d); n   } n   for (int i = 0; i < c; i++) { n     cin >> e; n     v1.push_back(e); n   } n   for (int i = 1; i <= a; i++) { n     long long n = 0; n     for (int j = 0; j < v.size(); j++) { n       if (mp[v[j]] != 5 and i == v[j]) { n         cout << 1 <<    ; n         n++; n         mp[v[j]] = 5; n         break; n       } n     } n     if (n == 0) { n       for (int j = 0; j < v1.size(); j++) { n         if (mp[v1[j]] != 5 and i == v1[j]) { n           cout << 2 <<    ; n           mp[v1[j]] = 5; n           break; n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 2e9; n const long long INF = 4e17; n const int mod = 1e9 + 7; n const double eps = 1e-9; n const int N = 2e5 + 10; n long long n, arr[N], tree[N << 2], lazy[N << 2]; n void build(int node = 1, int L = 1, int R = n) { n   if (L == R) { n     tree[node] = arr[L]; n     lazy[node] = 0; n     return; n   } n   int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1; n   build(lc, L, mid), build(rc, mid + 1, R); n   tree[node] = tree[lc] + tree[rc]; n } n void set0(int l, int r, int node = 1, int L = 1, int R = n) { n   if (r < L || R < l || r < l) return; n   if (l <= L && R <= r) { n     tree[node] = 0; n     lazy[node] = 1; n     return; n   } n   int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1; n   if (lazy[node]) return; n   set0(l, r, lc, L, mid), set0(l, r, rc, mid + 1, R); n   tree[node] = tree[lc] + tree[rc]; n } n void upd(int pos, int v, int node = 1, int L = 1, int R = n) { n   if (L == R) { n     tree[node] += v; n     return; n   } n   int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1; n   if (pos <= mid) n     upd(pos, v, lc, L, mid); n   else n     upd(pos, v, rc, mid + 1, R); n   tree[node] = tree[lc] + tree[rc]; n } n long long getsum(int l, int r, int node = 1, int L = 1, int R = n) { n   if (r < L || R < l) return 0; n   if (l <= L && R <= r) return tree[node]; n   if (lazy[node]) return 0; n   int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1; n   return getsum(l, r, lc, L, mid) + getsum(l, r, rc, mid + 1, R); n } n long long getcap(int pos, int node = 1, int L = 1, int R = n) { n   if (L == R) return tree[node]; n   if (lazy[node]) return 0; n   int mid = (L + R) >> 1, lc = node << 1, rc = lc | 1; n   if (pos <= mid) return getcap(pos, lc, L, mid); n   return getcap(pos, rc, mid + 1, R); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &arr[i]); n   int m; n   scanf( %d , &m); n   build(); n   while (m--) { n     long long t, x, p, k; n     scanf( %lld , &t); n     if (t == 1) { n       scanf( %lld %lld , &p, &x); n       long long cap = getcap(p); n       if (cap > x) { n         if (!1) cout <<  no overflow decrease   << x <<   from cap n ; n         upd(p, -x); n         if (!1) cout <<  at   << p <<   now   << getcap(p) <<   n ; n       } else { n         long long got = 0; n         int lo = p, hi = n, pos = n + 1; n         while (lo <= hi) { n           int mid = (lo + hi) >> 1; n           got = getsum(p, mid); n           if (!1) n             cout <<  from   << p <<   ->   << mid <<   sum   << got <<   n ; n           if (got >= x) n             hi = mid - 1, pos = mid; n           else n             lo = mid + 1; n         } n         long long usedup = getsum(p, pos - 1); n         if (!1) n           cout <<  overflow ends at   << pos <<   and used up   << usedup n                <<   out of   << x <<   n ; n         upd(pos, usedup - x); n         if (!1) cout <<  set 0 to all in   << p <<   ->   << pos - 1 <<   n ; n         set0(p, pos - 1); n       } n     } else { n       scanf( %lld , &k); n       if (!1) cout <<  found   << getcap(k) <<   amount left n ; n       printf( %lld n , arr[k] - getcap(k)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string strA, strB, strAux; n char aux; n int main() { n   cin >> strA; n   cin >> strAux; n   aux = strAux[1]; n   strAux[1] = strAux[0]; n   strAux[0] = aux; n   strA += strAux; n   cin >> strB; n   cin >> strAux; n   aux = strAux[1]; n   strAux[1] = strAux[0]; n   strAux[0] = aux; n   strB += strAux; n   strA.erase(strA.find( X ), 1); n   strB.erase(strB.find( X ), 1); n   int posA = strA.find( A ); n   int posB = strB.find( A ); n   bool flag = true; n   for (int i = 0; i < 3; i++) { n     if (strA[posA] != strB[posB]) { n       flag = false; n       break; n     } n     posA++; n     if (posA == 3) { n       posA = 0; n     } n     posB++; n     if (posB == 3) { n       posB = 0; n     } n   } n   if (flag) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr static int MAXN = 1e6; n int main() { n   int k, a, b; n   cin >> k >> a >> b; n   if (a > b) swap(a, b); n   int x = a / k; n   int y = b / k; n   if (x == 0 && y == 0) { n     cout << -1 << endl; n     return 0; n   } n   if (x == 0 && b % k > 0) { n     cout << -1 << endl; n     return 0; n   } n   cout << x + y << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int t; n long long l, r; n inline void solve() { n   cin >> t; n   while (t--) { n     cin >> l >> r; n     long long ans = l; n     for (int i = 0; i <= 62; ++i) { n       if (ans + (1ll << i) <= r && (ans & (1ll << i)) == 0) { n         ans += (1ll << i); n       } n     } n     cout << ans << endl; n   } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   set<int> a; n   int n, t; n   cin >> n; n   while (n--) { n     cin >> t; n     a.insert(t); n   } n   cout << ((a.count(0) == 1) ? a.size() - 1 : a.size()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n long long a[1005]; n long long fac[1000005]; n long long ppow(long long a, long long b) { n   long long c = 1; n   while (b) { n     if (b & 1) c = c * a % 1000000007; n     a = a * a % 1000000007; n     b >>= 1; n   } n   return c; n } n long long work(long long m, long long i) { n   return ((fac[m] % 1000000007) * n           (ppow((fac[i] * fac[m - i]) % 1000000007, 1000000007 - 2) % n            1000000007)) % n          1000000007; n } n int main() { n   long long i, j, k; n   fac[0] = 1; n   for (int i = 1; i < 1000005; i++) { n     fac[i] = (fac[i - 1] * i) % 1000000007; n   } n   long long ans = 1, sum = 0; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     sum += a[i]; n   } n   for (int i = n; i >= 1; i--) { n     ans *= work(sum - 1, a[i] - 1); n     ans %= 1000000007; n     sum -= a[i]; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct city { n   int x, y, p; n   double dis; n } t[1010]; n int cmp(city a, city b) { return a.dis < b.dis; } n int main() { n   int s, n, i; n   while (scanf( %d%d , &n, &s) > 0) { n     for (i = 0; i < n; i++) { n       scanf( %d%d%d , &t[i].x, &t[i].y, &t[i].p); n       t[i].dis = sqrt(t[i].x * t[i].x + t[i].y * t[i].y); n     } n     sort(t, t + n, cmp); n     double ans; n     for (i = 0; i < n; i++) { n       s += t[i].p; n       if (s >= 1e6) { n         ans = t[i].dis; n         break; n       } n     } n     if (i == n) { n       printf( -1 n ); n       continue; n     } n     printf( %lf n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007LL; n int n, m; n int a[100005]; n int main() { n   unordered_map<int, long long> cnt1; n   unordered_map<int, long long> cnt2; n   cnt1.clear(); n   cnt2.clear(); n   cin >> n >> m; n   bool isone = false; n   for (int i = 1; i <= m; ++i) { n     cin >> a[i]; n     if (a[i] == 1) isone = true; n   } n   if (n == 1) { n     if (isone) n       cout << 0 << endl; n     else n       cout << 1 << endl; n     return 0; n   } n   for (int i = m; i >= 1; --i) { n     cnt1[a[i] - i] = cnt1[a[i] - i - 1] + 1; n     cnt2[a[i] + i] = cnt2[a[i] + i + 1] + 1; n   } n   long long tot = 0LL; n   for (int i = 1; i <= n; ++i) { n     long long rn = n         min((long long)(n - i), max((long long)m + 1 - cnt1[i], 0LL)); n     long long ln = n         min((long long)(i - 1), max((long long)m + 1 - cnt2[i], 0LL)); n     tot += ln + rn + 1; n   } n   cout << tot << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, x, y; n   cin >> n; n   cin >> x >> y; n   if (x + y <= n + 1) { n     cout <<  white ; n   } else { n     cout <<  black ; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n void rwFile() { n   freopen( INP.inp ,  r , stdin); n   freopen( OUT.out ,  w , stdout); n } n void solveB_MakeThemOdd() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int arr[n]; n     for (int i = 0; i < n; i++) cin >> arr[i]; n     sort(arr, arr + n, greater<int>()); n     map<int, int> M; n     for (int i = 0; i < n; i++) { n       while (arr[i] % 2 == 0) { n         if (M[arr[i]] == 1) break; n         if (M[arr[i]] == 0) M[arr[i]] = 1; n         arr[i] /= 2; n       } n     } n     int res = 0; n     for (auto i : M) res++; n     cout << res <<   n ; n   } n } n void solveC_EveryoneIsAWinner() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> res; n     int i = 1; n     while (i <= n) { n       int x = n / i; n       res.push_back(x); n       i = n / x + 1; n     } n     cout << res.size() + 1 <<   n ; n     cout <<  0  ; n     for (int j = res.size() - 1; j >= 0; j--) cout << res[j] <<    ; n     cout <<   n ; n   } n } n void solveA_TilePainting() { n   long long n; n   cin >> n; n   long long res = n; n   for (int i = 2; i <= 1e6 + 5; i++) { n     if (n % i == 0) { n       while (n % i == 0) n /= i; n       res = i; n       break; n     } n   } n   if (res == n) { n     cout << res; n     return; n   } n   if (n == 1) n     cout << res; n   else n     cout << 1; n } n void solveA_BearAndPoker() { n   int n; n   cin >> n; n   int arr[n]; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     while (arr[i] % 2 == 0) arr[i] /= 2; n     while (arr[i] % 3 == 0) arr[i] /= 3; n   } n   int able = 1; n   for (int i = 1; i < n; i++) { n     if (arr[i] != arr[i - 1]) { n       able = 0; n       break; n     } n   } n   if (able) n     cout <<  Yes ; n   else n     cout <<  No ; n } n void solveC_NewYearAndTheSphereTransmission() { n   long long n; n   cin >> n; n   vector<long long> res; n   for (int i = 1; i * i <= n; i++) { n     if (n % i == 0) { n       long long tmp = (n / i + 1) * (n + 2) / 2 - n - 1; n       res.push_back(tmp); n       if (i * i != n) { n         int j = n / i; n         tmp = (n / j + 1) * (n + 2) / 2 - n - 1; n         res.push_back(tmp); n       } n     } n   } n   sort(res.begin(), res.end()); n   for (long long i : res) cout << i <<    ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(nullptr); n   cout.tie(nullptr); n   solveC_NewYearAndTheSphereTransmission(); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename F, typename S> n ostream& operator<<(ostream& os, const pair<F, S>& p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <class T> n ostream& operator<<(ostream& os, vector<T> const& x) { n   os <<  {  ; n   for (auto& y : x) os << y <<    ; n   return os <<  } ; n } n template <class T> n ostream& operator<<(ostream& os, set<T> const& x) { n   os <<  {  ; n   for (auto& y : x) os << y <<    ; n   return os <<  } ; n } n template <typename T> n ostream& operator<<(ostream& os, const multiset<T>& v) { n   os <<  [ ; n   typename multiset<T>::const_iterator it; n   for (it = v.begin(); it != v.end(); it++) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   return os <<  ] ; n } n template <typename F, typename S> n ostream& operator<<(ostream& os, const map<F, S>& v) { n   os <<  [ ; n   typename map<F, S>::const_iterator it; n   for (it = v.begin(); it != v.end(); it++) { n     if (it != v.begin()) os <<  ,  ; n     os << it->first <<   =   << it->second; n   } n   return os <<  ] ; n } n string s[200]; n vector<pair<int, int> > ans; n void cng(int x1, int y1, int x2, int y2, int x3, int y3) { n   s[x1][y1] = s[x1][y1] ==  1  ?  0  :  1 ; n   s[x2][y2] = s[x2][y2] ==  1  ?  0  :  1 ; n   s[x3][y3] = s[x3][y3] ==  1  ?  0  :  1 ; n   ans.push_back({x1, y1}); n   ans.push_back({x2, y2}); n   ans.push_back({x3, y3}); n } n void _main_main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> s[i]; n   ans.clear(); n   for (int i = 0; i < n - 2; i++) { n     for (int j = 0; j < m - 1; j++) { n       if (s[i][j] ==  1 ) cng(i, j, i, j + 1, i + 1, j); n     } n     if (s[i][m - 1] ==  1 ) cng(i, m - 1, i + 1, m - 1, i + 1, m - 2); n   } n   for (int j = 0; j < m - 2; j++) { n     if (s[n - 2][j] ==  1 ) cng(n - 2, j, n - 2, j + 1, n - 1, j + 1); n     if (s[n - 1][j] ==  1 ) cng(n - 1, j, n - 2, j + 1, n - 1, j + 1); n   } n   int j = m - 2; n   while (1) { n     int cnt = 0; n     if (s[n - 2][j] ==  1 ) cnt++; n     if (s[n - 2][j + 1] ==  1 ) cnt++; n     if (s[n - 1][j] ==  1 ) cnt++; n     if (s[n - 1][j + 1] ==  1 ) cnt++; n     if (cnt == 0) n       break; n     else if (cnt == 1) { n       if (s[n - 2][j] ==  1 ) n         cng(n - 2, j, n - 2, j + 1, n - 1, j); n       else if (s[n - 2][j + 1] ==  1 ) n         cng(n - 2, j, n - 2, j + 1, n - 1, j); n       else if (s[n - 1][j] ==  1 ) n         cng(n - 2, j, n - 2, j + 1, n - 1, j); n       else if (s[n - 1][j + 1] ==  1 ) n         cng(n - 1, j + 1, n - 2, j + 1, n - 1, j); n     } else if (cnt == 2) { n       if (s[n - 2][j] ==  1 ) n         cng(n - 1, j + 1, n - 2, j + 1, n - 1, j); n       else if (s[n - 2][j + 1] ==  1 ) n         cng(n - 2, j, n - 1, j + 1, n - 1, j); n       else if (s[n - 1][j] ==  1 ) n         cng(n - 2, j, n - 2, j + 1, n - 1, j + 1); n       else if (s[n - 1][j + 1] ==  1 ) n         cng(n - 2, j, n - 2, j + 1, n - 1, j); n     } else if (cnt == 3) { n       if (s[n - 2][j] ==  0 ) n         cng(n - 1, j + 1, n - 2, j + 1, n - 1, j); n       else if (s[n - 2][j + 1] ==  0 ) n         cng(n - 2, j, n - 1, j + 1, n - 1, j); n       else if (s[n - 1][j] ==  0 ) n         cng(n - 2, j, n - 2, j + 1, n - 1, j + 1); n       else if (s[n - 1][j + 1] ==  0 ) n         cng(n - 2, j, n - 2, j + 1, n - 1, j); n     } else { n       cng(n - 2, j, n - 2, j + 1, n - 1, j); n     } n   } n   cout << ans.size() / 3 << endl; n   int cnt = 0; n   for (auto i : ans) { n     cnt++; n     cout << i.first + 1 <<     << i.second + 1 <<    ; n     if (cnt == 3) { n       cnt = 0; n       cout << endl; n     } n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int testCase = 1; n   cin >> testCase; n   for (int i = 0; i < testCase; i++) { n     _main_main(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int c[100001], l[100001], r[100001], vis[100001], a[100001]; n int f(int o, int ll, int rr) { n   if (!~o) return rr - ll + 1; n   int x = lower_bound(a + ll, a + rr + 1, c[o]) - a, y = x - 1; n   while (y < rr && a[y + 1] == c[o]) y++; n   return f(l[o], ll, x - 1) + f(r[o], y + 1, rr); n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) n     scanf( %d%d%d , c + i, l + i, r + i), vis[l[i]] = vis[r[i]] = 1, n                                           a[++a[0]] = c[i]; n   int o; n   for (int i = 1; i <= n; i++) n     if (!vis[i]) o = i; n   sort(a + 1, a + n + 1); n   printf( %d , f(o, 1, n)); n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> A[105]; n vector<int> ans; n int main() { n   int n, days; n   cin >> n >> days; n   for (int i = 0; i < n; i++) scanf( %d , &A[i].first), A[i].second = i; n   sort(A, A + n); n   for (int i = 0; i < n; i++) { n     if (days < A[i].first) break; n     ans.push_back(A[i].second + 1); n     days -= A[i].first; n   } n   sort(ans.begin(), ans.end()); n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) { n     if (i) printf(   ); n     printf( %d , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 200000; n int ans[MAX_N + 5]; n int main() { n   int tc; n   cin >> tc; n   while (tc--) { n     int n, i, j; n     string s; n     cin >> n >> s; n     int num = n, last = 0; n     for (i = 0; i < n; i++) { n       if (i == n - 1 || s[i] ==  > ) { n         for (j = i; j >= last; j--) ans[j] = num--; n         last = i + 1; n       } n     } n     for (i = 0; i < n; i++) cout << ans[i] << (i == n - 1 ?   n  :    ); n     num = 1, last = 0; n     for (i = 0; i < n; i++) { n       if (i == n - 1 || s[i] ==  < ) { n         for (j = i; j >= last; j--) ans[j] = num++; n         last = i + 1; n       } n     } n     for (i = 0; i < n; i++) cout << ans[i] << (i == n - 1 ?   n  :    ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int ar[50][50]; n int n; n int check(int r, int c) { n   int v = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (ar[r][i] + ar[j][c] == ar[r][c]) { n         return 1; n       } n     } n   } n   return 0; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) cin >> ar[i][j]; n   } n   int flag = 1; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (ar[i][j] != 1) { n         flag = flag && check(i, j); n       } n       if (!flag) { n         break; n       } n     } n     if (!flag) { n       break; n     } n   } n   if (flag) { n     cout <<  Yes  << endl; n   } else { n     cout <<  No  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int A[110]; n int main() { n   int n, k, x; n   cin >> n >> k >> x; n   for (int i = 0; i < n; i++) { n     cin >> A[i]; n   } n   int ans = 0; n   for (int i = 0; i < n - k; i++) { n     ans += A[i]; n   } n   ans += (k * x); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 5005; n long long n, m, dp[N]; n char s[N]; n inline long long read() { n   long long ret = 0, f = 0; n   char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) f = 1; n     c = getchar(); n   } n   while (isdigit(c)) { n     ret = ret * 10 + c - 48; n     c = getchar(); n   } n   if (f) return -ret; n   return ret; n } n long long lowbit(long long x) { return x & -x; } n signed main() { n   scanf( %s , s + 1); n   n = strlen(s + 1); n   m = log2(n); n   for (long long i = 0; i < (1 << m); i++) dp[i] = 1; n   for (long long i = 1; i <= n - (1 << m) + 1; i++) { n     char mi =  z ; n     for (long long j = 0; j < (1 << m); j++) n       if (dp[j]) mi = min(mi, s[i + j]); n     for (long long j = 0; j < (1 << m); j++) dp[j] &= (s[i + j] == mi); n     for (long long j = 0; j < (1 << m); j++) n       if (dp[j]) n         for (long long k = 0; k < m; k++) dp[j | (1 << k)] = 1; n     putchar(mi); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool comp(long long x, long long y) { n   if (x >= y) return true; n   return false; n } n bool compare(const pair<long long, long long> &i, n              const pair<long long, long long> &j) { n   return i.first <= j.first; n } n bool compare1(const pair<long long, long long> &i, n               const pair<long long, long long> &j) { n   return i.first > j.first; n } n string decitobinary(long long n, long long bit) { n   char c[bit]; n   memset(c,  0 , sizeof(c)); n   long long i = 0; n   while (n > 0) { n     c[i] = n % 2 + 48; n     n = n / 2; n     i++; n   } n   string s =   ; n   for (long long j = bit - 1; j >= 0; j--) s += c[j]; n   return s; n } n long long binarytodeci(string n) { n   string num = n; n   long long dec_value = 0; n   long long base = 1; n   long long len = num.length(); n   for (long long i = len - 1; i >= 0; i--) { n     if (num[i] ==  1 ) dec_value += base; n     base = base * 2; n   } n   return dec_value; n } n double intlog(double base, double x) { return (log(x) / log(base)); } n long long fact(long long n) { n   long long res = 1; n   for (long long i = 2; i <= n; i++) res = res * i; n   return res; n } n long long ncr(long long n, long long k) { n   long long res = 1; n   if (k > n - k) k = n - k; n   for (long long i = 0; i < k; ++i) { n     res *= (n - i); n     res /= (i + 1); n   } n   return res; n } n bool ispalindrome(string str, long long l, long long h) { n   while (h > l) { n     if (str[l++] != str[h--]) return 0; n   } n   return 1; n } n long long compute_hash(string s) { n   long long p = 31, hash = 0, po = 1; n   for (char c : s) { n     hash += (c -  a  + 1) * po % 1000000007; n     po = (po * p) % 1000000007; n   } n   return hash; n } n vector<vector<long long>> group_identical_strings(vector<string> const &s) { n   long long n = s.size(); n   vector<pair<long long, long long>> hashes(n); n   for (long long i = 0; i < n; i++) hashes[i] = {compute_hash(s[i]), i}; n   sort(hashes.begin(), hashes.end()); n   vector<vector<long long>> groups; n   for (long long i = 0; i < n; i++) { n     if (i == 0 || hashes[i].first != hashes[i - 1].first) groups.emplace_back(); n     groups.back().push_back(hashes[i].second); n   } n   return groups; n } n bool isarraysort(long long a[], long long i, long long j) { n   if (j == i) return 1; n   if (a[j] < a[j - 1]) return 0; n   return isarraysort(a, i, j - 1); n } n void sieve(long long n, long long prime[]) { n   for (long long i = 1; i <= n; i++) prime[i] = 1; n   for (long long p = 2; p * p <= n; p++) { n     if (prime[p] == 1) { n       for (long long i = p * p; i <= n; i += p) prime[i] = 0; n     } n   } n } n bool isprime(long long n) { n   for (long long i = 2; i * i <= n; i++) { n     if (n % i == 0) return 0; n   } n   return 1; n } n long long pow_mod(long long base, long long exp) { n   long long res = 1; n   while (exp > 0) { n     if (exp % 2 == 1) res = (res * base) % 1000000007; n     exp = exp >> 1; n     base = (base * base) % 1000000007; n   } n   return res; n } n const long long N = 1e6 + 3; n vector<vector<long long>> adj; n bool visited[N]; n long long depth[N] = {0}; n long long size[N] = {0}; n long long parent[N]; n void dfs(long long v) { n   visited[v] = true; n   for (long long u : adj[v]) { n     if (!visited[u]) { n       dfs(u); n     } n   } n } n long long time_in[N], time_out[N]; n long long dfs_timer = 0; n long long color[N]; n void dfs_time(long long v) { n   time_in[v] = ++dfs_timer; n   color[v] = 1; n   for (long long u : adj[v]) { n     if (color[u] == 0) { n       dfs_time(u); n     } n   } n   color[v] = 2; n   time_out[v] = ++dfs_timer; n } n long long count1[N]; n void numberOfNodes(long long s) { n   count1[s] = 1; n   for (long long u : adj[s]) { n     if (u == parent[s]) continue; n     numberOfNodes(u); n     count1[s] += count1[u]; n   } n } n long long call(long long a[], long long x, long long y) { n   long long mxi = x; n   long long mx = a[x]; n   for (long long i = x + 1; i <= y; i++) { n     if (a[i] > mx) { n       mx = a[i]; n       mxi = i; n     } n   } n   return mxi; n } n void solve(long long countu) { n   long long n; n   cin >> n; n   long long x[n], y[n]; n   long long cnt[100001] = {0}; n   for (long long i = 0; i < n; i++) { n     cin >> x[i] >> y[i]; n     cnt[x[i]]++; n   } n   for (long long i = 0; i < n; i++) n     cout << n - 1 + cnt[y[i]] <<     << n - 1 - cnt[y[i]] <<   n ; n } n int32_t main(void) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t = 1, countu = 1; n   while (t--) { n     solve(countu); n     countu++; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200005; n vector<int> sosedi[maxn]; n int parent[maxn], shagi[maxn], start[maxn], finish[maxn], n; n void dfs(int v, int predok) { n   parent[v] = predok; n   shagi[v] = shagi[predok] + 1; n   for (auto p : sosedi[v]) n     if (p != predok) dfs(p, v); n } n vector<int> circles; n int rt, lp, lq; n bool find_circle() { n   circles.clear(); n   static bool visit_vertex[maxn]; n   int p = 0; n   for (int i = 1; i <= n; i++) n     if (start[i] != finish[i] && shagi[i] > shagi[p]) p = i; n   if (!p) return 1; n   for (int u = p; visit_vertex[u] = 1, circles.push_back(u), n            start[parent[u]] != finish[parent[u]]; n        u = parent[u]) n     ; n   int q = 0; n   for (int i = 1; i <= n; i++) n     if (start[i] != finish[i] && !visit_vertex[i] && shagi[i] > shagi[q]) q = i; n   if (q) { n     reverse(circles.begin(), circles.end()); n     for (int u = q; visit_vertex[u] = 1, circles.push_back(u), n              start[parent[u]] != finish[parent[u]]; n          u = parent[u]) n       ; n   } else n     q = parent[circles.back()]; n   for (int i = 1; i <= n; i++) n     if (start[i] != finish[i] && !visit_vertex[i]) return 0; n   int u, v; n   for (u = p, v = q; u != v; u = parent[u]) n     if (shagi[u] < shagi[v]) swap(u, v); n   rt = u; n   if (circles.size() != shagi[p] + shagi[q] - 2 * shagi[rt]) return 0; n   lp = p, lq = q; n   return 1; n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> start[i]; n   } n   for (int i = 1; i <= n; i++) { n     cin >> finish[i]; n   } n   for (int i = 1, u, v; i < n; i++) { n     cin >> u >> v; n     sosedi[u].push_back(v), sosedi[v].push_back(u); n   } n   int pa = find(start + 1, start + n + 1, 0) - start, n       pb = find(finish + 1, finish + n + 1, 0) - finish; n   shagi[0] = -1; n   dfs(pb, 0); n   for (int u = pa; u != pb; u = parent[u]) swap(start[u], start[parent[u]]); n   long long ans = shagi[pa]; n   if (!find_circle()) { n     printf( -1 n ); n     return 0; n   } n   if (!circles.size()) { n     printf( 0 %d n , ans); n     return 0; n   } n   int gap = 0, len = circles.size(); n   for (int i = 0; i < len; i++) n     if (finish[circles[i]] == start[circles[0]]) gap = i; n   for (int i = 1; i < len; i++) n     if (finish[circles[(i + gap) % len]] != start[circles[i]]) { n       printf( -1 n ); n       return 0; n     } n   static bool visit_vertex[maxn]; n   for (int i = pa; i; i = parent[i]) visit_vertex[i] = 1; n   if (visit_vertex[circles[0]] || visit_vertex[circles.back()]) { n     int po = circles.size(); n     for (int i = 0; i < circles.size(); i++) n       if (!visit_vertex[circles[i]]) { n         po = i; n         break; n       } n     ans = ans - po + n           min(po + gap * 1ll * (len + 1), n               abs((len - gap) * 1ll * (len + 1) - po)); n   } else n     ans = (ans + min(gap, len - gap) * 1ll * (len + 1)); n   for (; !visit_vertex[rt]; rt = parent[rt]) ans += 2; n   if (lp > lq) swap(lq, lp); n   printf( %d %d %lld n , lp, lq, ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool home = 1; n signed realMain(); n signed main() { n   home = 0; n   if (home) { n     freopen( tony_stark ,  r , stdin); n   } else { n     ios::sync_with_stdio(0); n     cin.tie(0); n   } n   realMain(); n } n const int N = 100000 + 7; n int n, k; n long long sol[N]; n vector<int> co; n struct pt { n   int x, y; n } a[N]; n bool operator<(pt a, pt b) { return a.y < b.y; } n struct upd { n   int rw; n   int l, r; n   int sgn; n }; n bool operator<(upd a, upd b) { return a.rw < b.rw; } n int fnd(int x) { n   int l = 0, r = (int)co.size() - 1; n   while (l <= r) { n     int m = (l + r) / 2; n     if (co[m] == x) return m; n     if (co[m] < x) n       l = m + 1; n     else n       r = m - 1; n   } n   assert(0); n } n signed realMain() { n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y; n   sort(a + 1, a + n + 1); n   for (int i = 1; i <= n; i++) { n     int go = a[i].y - k + 1; n     if (!co.empty() && go <= co.back()) go = co.back() + 1; n     for (int j = go; j <= a[i].y; j++) co.push_back(j); n   } n   vector<upd> evs; n   for (int i = 1; i <= n; i++) { n     int lft = a[i].y - k + 1, rgh = a[i].y; n     int l = fnd(lft), r = fnd(rgh); n     evs.push_back({a[i].x - k + 1, l, r, +1}); n     evs.push_back({a[i].x + 1, l, r, -1}); n   } n   vector<int> cnt((int)co.size()), utime; n   swap(utime, co); n   sort(evs.begin(), evs.end()); n   int ret = 0; n   for (auto &it : evs) { n     int rw = it.rw; n     int l = it.l; n     int r = it.r; n     int sgn = it.sgn; n     for (int j = l; j <= r; j++) { n       sol[cnt[j]] += (rw - utime[j]); n       cnt[j] += sgn; n       utime[j] = rw; n     } n   } n   for (int j = 1; j <= n; j++) { n     cout << sol[j] <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n void pre() {} n void solve() {} n const long long mod = 998244353; n long long pw[1000009], a[1000009]; n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cin.exceptions(cin.failbit); n   pre(); n   pw[0] = 1; n   for (int i = 1; i <= (1000000); ++i) pw[i] = pw[i - 1] * 2 % mod; n   int n; n   cin >> n; n   for (int i = 0; i < (n); ++i) cin >> a[i + 1]; n   long long ans = a[n]; n   for (int i = 1; i <= (n - 1); ++i) { n     ans += 1ll * pw[n - i] * a[i] % mod; n     ans += 1ll * (n - i) * a[i] % mod * pw[n - 1 - i] % mod; n   } n   cout << ans % mod; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void read(T &x) { n   char c; n   bool nega = 0; n   while ((!isdigit(c = getchar())) && (c !=  - )) n     ; n   if (c ==  - ) { n     nega = 1; n     c = getchar(); n   } n   x = c - 48; n   while (isdigit(c = getchar())) x = x * 10 + c - 48; n   if (nega) x = -x; n } n template <typename T> n inline void writep(T x) { n   if (x > 9) writep(x / 10); n   putchar(x % 10 + 48); n } n template <typename T> n inline void write(T x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   writep(x); n   putchar(   ); n } n template <typename T> n inline void writeln(T x) { n   write(x); n   putchar(  n ); n } n template <typename R, typename D> n inline void Min(R &a, D b) { n   if (a > b) a = b; n } n template <typename D, typename R> n inline void Max(D &a, R b) { n   if (a < b) a = b; n } n const int N = 10005, M = 300005; n bool dd[10]; n int T, n; n int main() { n   ios_base::sync_with_stdio(NULL); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> T; n   while (T--) { n     cin >> n; n     if ((n / 2) & 1) { n       cout <<  NO n ; n       continue; n     } n     cout <<  YES n ; n     for (int i = 1; i <= n / 2; ++i) cout << i * 2 <<    ; n     for (int i = 1; i <= n / 2 - 1; ++i) cout << i * 2 - 1 <<    ; n     cout << n + n / 2 - 1; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool options(long a, long b) { return a > b; } n int main() { n   long n, i, *arr, *arrSort, *index; n   map<long, long> res; n   cin >> n; n   arr = new long[n]; n   arrSort = new long[n]; n   index = new long[n]; n   for (i = 0; i < n; i++) { n     cin >> arr[i]; n     arrSort[i] = arr[i]; n   } n   sort(arrSort, arrSort + n, options); n   for (i = 0; i < n; i++) { n     index[i] = i + 1; n   } n   for (i = 1; i < n; i++) { n     if (arrSort[i] == arrSort[i - 1]) { n       index[i] = index[i - 1]; n     } n   } n   for (i = 0; i < n; i++) { n     res[arrSort[i]] = index[i]; n   } n   for (i = 0; i < n; i++) { n     cout << res[arr[i]] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main(void) { n   unsigned int const max_skill_level = 100; n   unsigned int number_of_boys; n   unsigned int number_of_girls; n   unsigned int number_of_pairs = 0; n   std::vector<unsigned int> number_of_boys_with_each_skill_level( n       max_skill_level + 1, 0); n   std::vector<unsigned int> number_of_girls_with_each_skill_level( n       max_skill_level + 1, 0); n   std::ios_base::sync_with_stdio(false); n   std::cin >> number_of_boys; n   for (unsigned int i = 0; i < number_of_boys; ++i) { n     std::size_t skill_level; n     std::cin >> skill_level; n     ++number_of_boys_with_each_skill_level[skill_level]; n   } n   std::cin >> number_of_girls; n   for (unsigned int i = 0; i < number_of_girls; ++i) { n     std::size_t skill_level; n     std::cin >> skill_level; n     ++number_of_girls_with_each_skill_level[skill_level]; n   } n   for (std::size_t i = 0; i < max_skill_level; ++i) { n     unsigned int number_of_new_pairs; n     number_of_new_pairs = std::min(number_of_boys_with_each_skill_level[i], n                                    number_of_girls_with_each_skill_level[i]); n     number_of_boys_with_each_skill_level[i] -= number_of_new_pairs; n     number_of_girls_with_each_skill_level[i] -= number_of_new_pairs; n     number_of_pairs += number_of_new_pairs; n     number_of_new_pairs = n         std::min(number_of_boys_with_each_skill_level[i], n                  number_of_girls_with_each_skill_level[i + 1]); n     number_of_boys_with_each_skill_level[i] -= number_of_new_pairs; n     number_of_girls_with_each_skill_level[i + 1] -= number_of_new_pairs; n     number_of_pairs += number_of_new_pairs; n     number_of_new_pairs = std::min(number_of_boys_with_each_skill_level[i + 1], n                                    number_of_girls_with_each_skill_level[i]); n     number_of_boys_with_each_skill_level[i + 1] -= number_of_new_pairs; n     number_of_girls_with_each_skill_level[i] -= number_of_new_pairs; n     number_of_pairs += number_of_new_pairs; n   } n   number_of_pairs += std::min(number_of_boys_with_each_skill_level.back(), n                               number_of_girls_with_each_skill_level.back()); n   std::cout << number_of_pairs <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC target( avx2 ) n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n void pre() {} n void solve() { n   long long k, b, n; n   cin >> k >> b >> n; n   long long arr[n]; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   map<long long, long long> m; n   long long curr = 0; n   long long ans = 0; n   m[0]++; n   if (b == k - 1) { n     long long cur = 0; n     for (int i = 0; i < n; i++) { n       cur = 0; n       while (i < n && arr[i] == 0) { n         cur++; n         i++; n       } n       if (cur != 0) { n         i--; n       } n       ans -= (cur * (cur + 1)) / 2; n     } n   } n   if (b == 0) { n     long long cur = 0; n     for (int i = 0; i < n; i++) { n       cur = 0; n       while (i < n && arr[i] == 0) { n         cur++; n         i++; n       } n       if (cur != 0) { n         i--; n       } n       ans += (cur * (cur + 1)) / 2; n     } n     cout << ans <<   n ; n     return; n   } n   b %= (k - 1); n   for (int i = 0; i < n; i++) { n     curr += arr[i]; n     curr %= (k - 1); n     ans += m[(curr - b + k - 1) % (k - 1)]; n     m[curr]++; n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   pre(); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int n, adj[166][166]; n bool h[166]; n vector<char> V[166], r; n string a[105]; n void dfs(char x) { n   h[x] = true; n   for (typeof(V[x].begin()) it = V[x].begin(); it != V[x].end(); it++) n     if (!h[*it]) dfs(*it); n   r.push_back(x); n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n - 1; i++) { n     int q = 0; n     while (a[i][q] == a[i + 1][q]) q++; n     if (q >= a[i + 1].size() and q < a[i].size()) n       return puts( Impossible ) && 0; n     else if (q >= a[i].size()) n       continue; n     adj[a[i + 1][q]][a[i][q]] = 1; n     for (typeof(V[a[i][q]].begin()) it = V[a[i][q]].begin(); n          it != V[a[i][q]].end(); it++) n       adj[a[i + 1][q]][*it] = 1; n     V[a[i + 1][q]].push_back(a[i][q]); n   } n   for (int i =  a ; i <=  z ; i++) n     if (!h[i]) dfs(i); n   for (int i = 0; i <= r.size() - 1; i++) n     for (int j = 0; j <= i; j++) n       if (adj[r[j]][r[i]]) return puts( Impossible ) && 0; n   for (typeof(r.begin()) it = r.begin(); it != r.end(); it++) cout << *it; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300010; n int total[N]; n vector<pair<pair<int, int>, int> > e[N]; n int dir[N], from[N], to[N]; n int visit[N]; n int n, m; n int main() { n   scanf( %d%d , &n, &m); n   memset(total, 0, sizeof(total)); n   for (int i = 1; i <= m; i++) { n     int u, v, w; n     scanf( %d%d%d , &u, &v, &w); n     from[i] = u; n     to[i] = v; n     e[u].push_back(make_pair(make_pair(v, w), i)); n     e[v].push_back(make_pair(make_pair(u, w), i)); n     total[u] += w; n     total[v] += w; n     dir[i] = -1; n   } n   for (int i = 1; i <= n; i++) total[i] >>= 1; n   memset(visit, false, sizeof(visit)); n   queue<int> q; n   q.push(1); n   visit[1] = 1; n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int i = 0; i < e[u].size(); i++) { n       int id = e[u][i].second, v = e[u][i].first.first, n           w = e[u][i].first.second; n       if (dir[id] == -1) { n         if (u == from[id]) n           dir[id] = 0; n         else n           dir[id] = 1; n         total[v] -= w; n         if (total[v] == 0 && (!visit[v]) && v != n) { n           visit[v] = true; n           q.push(v); n         } n       } n     } n   } n   for (int i = 1; i <= m; i++) printf( %d n , dir[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read(void) n { n     int sum = 0, sign = 1; n     char ch = getchar(); n     while (ch >  9  || ch <  0 ) n     { n         if (ch ==  - ) n             sign = -1; n         ch = getchar(); n     } n     while (ch >=  0  && ch <=  9 ) n     { n         sum = sum * 10 + ch -  0 ; n         ch = getchar(); n     } n     return sum * sign; n } n const int maxn = 2e5 + 5; n typedef long long ll; n int main() n { n     int T = read(); n     for (int cas = 1; cas <= T; cas++) n     { n         string str; n         cin >> str; n         int bol = 0; n         for (int i = str.length() - 1; i >= 1; i--){ n             if (bol == 0 && str[i] ==  0  && str[i - 1] ==  0 ) n                 bol = 1; n             if (bol == 1 && str[i] ==  1  && str[i - 1] ==  1 ) n                 bol = 2; n         } n         if (bol == 2) n             cout <<  NO n ; n         else n             cout <<  YES n ; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int SZ = 104; n const double EPS = 1e-7; n int a, b, c; n void read() { cin >> a >> b >> c; } n void solve() { n   a -= a / b * b; n   for (int i = 0; i < 1e5; ++i) { n     a *= 10; n     if (c == a / b) { n       cout << i + 1; n       return; n     } n     a -= a / b * b; n   } n   cout << -1; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   read(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e5; n int a[maxn], b[maxn], c[maxn]; n int n, K, i, j, x, y, bl, la; n int main() { n   scanf( %d%d , &n, &K); n   x = K; n   for (i = 2; i <= x; i++) n     if (x % i == 0) { n       a[++la] = i; n       while (x % i == 0) { n         b[la]++; n         x /= i; n       } n     } n   for (i = 1; i <= n; i++) { n     scanf( %d , &x); n     for (j = 1; j <= la; j++) { n       y = 0; n       while (x % a[j] == 0) { n         y++; n         x /= a[j]; n       } n       c[j] = max(c[j], y); n     } n   } n   bl = 1; n   for (i = 1; i <= la; i++) n     if (c[i] < b[i]) { n       bl = 0; n       break; n     } n   if (bl) n     printf( Yes ); n   else n     printf( No ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char st[8][20] = { err ,       monday ,  tuesday ,   wednesday , n                    thursday ,  friday ,  saturday ,  sunday }; n int main() { n   char s1[20], s2[20]; n   scanf(  %s %s , s1, s2); n   int t1 = 0, t2 = 0; n   for (int i = 1; i <= 7; i++) n     if (strcmp(s1, st[i]) == 0) { n       t1 = i; n       break; n     } n   for (int i = 1; i <= 7; i++) n     if (strcmp(s2, st[i]) == 0) { n       t2 = i; n       break; n     } n   bool flag = false; n   if (t1 == t2) flag = true; n   int tmp = t1 + 2; n   if (tmp > 7) tmp -= 7; n   if (tmp == t2) flag = true; n   tmp = t1 + 3; n   if (tmp > 7) tmp -= 7; n   if (tmp == t2) flag = true; n   puts(flag ?  YES  :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long tc, n, x, cnt1, cnt2, i, max_; n   scanf( %lld , &tc); n   while (tc--) { n     scanf( %lld , &n); n     vector<long long> v; n     vector<long long> v1; n     for (i = 0; i < n; i++) { n       scanf( %lld , &x); n       v.push_back(x); n     } n     sort(v.begin(), v.end()); n     cnt1 = 0; n     v1.push_back(0); n     for (i = 0; i < n; i++) { n       cnt1++; n       if (cnt1 >= v[i]) v1.push_back(i + 1); n     } n     max_ = *max_element(v1.begin(), v1.end()); n     printf( %lld n , max_ + 1); n   } n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n #pragma comment(linker,  /STACK:336777216 ) n using namespace std; n int IT_MAX = 1 << 17; n long long MOD = 1000000007; n const int INF = 0x3f3f3f3f; n const long long LL_INF = 0x3f3f3f3f3f3f3f3f; n const double PI = acos(-1); n const double ERR = 1e-10; n set<pair<int, int> > Sx; n vector<int> conn[200050]; n bool pchk[200050]; n int lc = 1; n vector<int> Vl[200050]; n int r[200050]; n int sz[200050]; n int root(int x) { return (x == r[x]) ? x : (r[x] = root(r[x])); } n int main() { n   int N, M, i, j; n   scanf( %d %d , &N, &M); n   for (i = 1; i <= M; i++) { n     int t1, t2; n     scanf( %d %d , &t1, &t2); n     Sx.emplace(t1, t2); n     Sx.emplace(t2, t1); n     conn[t1].push_back(t2); n     conn[t2].push_back(t1); n   } n   int p = 1; n   for (i = 2; i <= N; i++) n     if (conn[i].size() < conn[p].size()) p = i; n   for (auto it : conn[p]) pchk[it] = true; n   for (i = 1; i <= N; i++) n     if (!pchk[i]) Vl[1].push_back(i); n   for (i = 1; i <= N; i++) { n     if (!pchk[i]) continue; n     lc++; n     Vl[lc].push_back(i); n   } n   for (i = 1; i <= lc; i++) r[i] = i; n   for (i = 1; i <= lc; i++) { n     for (j = i + 1; j <= lc; j++) { n       bool chk = false; n       for (auto it1 : Vl[i]) { n         for (auto it2 : Vl[j]) { n           if (Sx.count(pair<int, int>(it1, it2))) continue; n           chk = true; n           break; n         } n       } n       if (chk) r[root(i)] = root(j); n     } n   } n   int cnt = 0; n   for (i = 1; i <= lc; i++) sz[root(i)] += Vl[i].size(); n   vector<int> Va; n   for (i = 1; i <= lc; i++) n     if (r[i] == i) Va.push_back(sz[i]); n   sort((Va).begin(), (Va).end()); n   printf( %d n , (int)Va.size() - 1); n } n


#include <bits/stdc++.h> n using namespace std; n int h, w, k, Q; n int V; n int a[1005][1005]; n vector<int> G[1100005]; n short d[1100005]; n short dist[45][1000005]; n vector<int> vec[45]; n bool used[45]; n int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; n void bfs(int c, short dist[]) { n   queue<int> Q; n   for (int i = 0; i < h * w; i++) dist[i] = 30000; n   for (int i = 1; i <= k; i++) used[i] = false; n   for (int i = 0; i < vec[c].size(); i++) { n     Q.push(vec[c][i]); n     dist[vec[c][i]] = 0; n   } n   used[c] = true; n   int v, x, y; n   while (Q.size()) { n     v = Q.front(); n     Q.pop(); n     x = v % w, y = v / w, c = a[x][y]; n     if (!used[c]) { n       used[c] = true; n       for (int i = 0; i < vec[c].size(); i++) { n         if (dist[vec[c][i]] < 30000) continue; n         dist[vec[c][i]] = dist[v] + 1; n         Q.push(vec[c][i]); n       } n     } n     for (int i = 0; i < 4; i++) { n       int nx = x + dx[i], ny = y + dy[i], nv = ny * w + nx; n       if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue; n       if (dist[nv] < 30000) continue; n       dist[nv] = dist[v] + 1; n       Q.push(nv); n     } n   } n } n int main(void) { n   scanf( %d %d %d , &h, &w, &k); n   int p; n   for (int y = 0; y < h; y++) { n     for (int x = 0; x < w; x++) { n       scanf( %d , &p); n       a[x][y] = p; n     } n   } n   int n = h * w; n   for (int y = 0; y < h; y++) { n     for (int x = 0; x < w; x++) { n       vec[a[x][y]].push_back(y * w + x); n     } n   } n   for (int i = 1; i <= k; i++) { n     bfs(i, d); n     for (int j = 0; j < n; j++) dist[i][j] = d[j]; n   } n   scanf( %d , &Q); n   int sx, sy, tx, ty; n   for (int q = 0; q < Q; q++) { n     scanf( %d %d %d %d , &sy, &sx, &ty, &tx); n     sx--, sy--, tx--, ty--; n     int S = sy * w + sx, T = ty * w + tx; n     int ans = abs(sx - tx) + abs(sy - ty); n     for (int i = 1; i <= k; i++) { n       ans = min(ans, dist[i][S] + dist[i][T] + 1); n     } n     printf( %d n , ans); n   } n   flush(cout); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:102400000,102400000 ) n using namespace std; n const int maxn = 3010; n vector<int> g[maxn]; n int vis[maxn], dis[maxn][maxn]; n void bfs(int s) { n   memset(vis, 0, sizeof(vis)); n   queue<int> que; n   que.push(s); n   vis[s] = 1; n   while (!que.empty()) { n     int u = que.front(); n     que.pop(); n     for (int i = 0; i < g[u].size(); i++) { n       int v = g[u][i]; n       if (vis[v]) continue; n       vis[v] = 1; n       dis[s][v] = dis[s][u] + 1; n       que.push(v); n     } n   } n } n int main() { n   int n, m; n   while (~scanf( %d%d , &n, &m)) { n     for (int i = 0; i <= n; i++) g[i].clear(); n     for (int i = 0; i < m; i++) { n       int u, v; n       scanf( %d%d , &u, &v); n       g[u].push_back(v); n       g[v].push_back(u); n     } n     int s1, t1, d1, s2, t2, d2; n     scanf( %d%d%d%d%d%d , &s1, &t1, &d1, &s2, &t2, &d2); n     for (int i = 1; i <= n; i++) bfs(i); n     if (dis[s1][t1] > d1 || dis[s2][t2] > d2) { n       puts( -1 ); n       continue; n     } n     int ans = dis[s1][t1] + dis[s2][t2]; n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= n; j++) { n         if (dis[s1][i] + dis[i][j] + dis[j][t1] <= d1 && n             dis[s2][i] + dis[i][j] + dis[j][t2] <= d2) n           ans = min(ans, dis[s1][i] + dis[i][j] + dis[j][t1] + dis[s2][i] + n                              dis[j][t2]); n         if (dis[s1][i] + dis[i][j] + dis[j][t1] <= d1 && n             dis[t2][i] + dis[i][j] + dis[j][s2] <= d2) n           ans = min(ans, dis[s1][i] + dis[i][j] + dis[j][t1] + dis[t2][i] + n                              dis[j][s2]); n         if (dis[t1][i] + dis[i][j] + dis[j][s1] <= d1 && n             dis[s2][i] + dis[i][j] + dis[j][t2] <= d2) n           ans = min(ans, dis[t1][i] + dis[i][j] + dis[j][s1] + dis[s2][i] + n                              dis[j][t2]); n         if (dis[t1][i] + dis[i][j] + dis[j][s1] <= d1 && n             dis[t2][i] + dis[i][j] + dis[j][s2] <= d2) n           ans = min(ans, dis[t1][i] + dis[j][s1] + dis[t2][i] + dis[i][j] + n                              dis[j][s2]); n       } n     cout << m - ans << endl; n   } n   return 0; n } n


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