#include <bits/stdc++.h> n using namespace std; n void read(int &x) { n   x = 0; n   int f = 1; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = -f; n   for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ; n   x *= f; n } n void print(int x) { n   if (x < 0) putchar( - ), x = -x; n   if (!x) return; n   print(x / 10), putchar(x % 10 + 48); n } n void write(int x) { n   if (!x) n     putchar( 0 ); n   else n     print(x); n   putchar(  n ); n } n const int maxn = 1e6 + 10; n const int inf = 1e9; n const double eps = 1e-8; n const int mod = 1e9 + 7; n int v[maxn]; n map<pair<int, int>, int> s; n int n, t, z[maxn], ans[maxn]; n int query(int x, int y) { n   if (x > y) swap(x, y); n   if (s[make_pair(x, y)]) return s[make_pair(x, y)]; n   printf( ? %d %d n , x, y); n   fflush(stdout); n   int a; n   read(a); n   assert(a != -1); n   return s[make_pair(x, y)] = a; n } n int get(int x) { n   int a = (1 << t) - 1; n   for (int i = 0; i < t; i++) n     if (x != z[i]) n       a &= query(z[i], x); n     else if ((a >> i) & 1) n       a ^= 1 << i; n   return a; n } n int main() { n   srand(time(0)); n   read(n); n   for (int i = 1; i < n; i <<= 1) t++; n   while (1) { n     int x = rand() % n + 1, y = rand() % n + 1, bo = 1; n     for (int i = 0; i < t; i++) n       if (!z[i]) bo = 0; n     if (bo) break; n     if (x == y) continue; n     int a = query(x, y); n     for (int i = 0; i < t; i++) n       if (!((a >> i) & 1)) z[i] = x; n   } n   int a = get(1), pre = 1; n   for (int i = 2; i <= n; i++) n     if (query(pre, i) == a) a = get(i), pre = i; n   for (int i = 1; i <= n; i++) n     if (i != pre) ans[i] = query(pre, i); n   printf( !  ); n   for (int i = 1; i <= n; i++) printf( %d  , ans[i]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios_base::sync_with_stdio(false); n   long long k, n, m, x = 10; n   int i = 1; n   cin >> k; n   k -= 9; n   if (k <= 0) { n     k = k + 9; n     cout << k; n     exit(0); n   } n   while (++i) { n     k -= 9 * i * x; n     if (k <= 0) { n       k += 9 * i * x; n       n = k / i; n       m = k % i; n       n = x + n; n       if (m == 0) n -= 1; n       ostringstream s; n       s << n; n       string s1 = s.str(); n       if (m == 0) n         cout << s1[i - 1]; n       else n         cout << s1[m - 1]; n       exit(0); n     } n     x = x * 10; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a, b, c, val; n vector<vector<long long>> F1; n vector<vector<long long>> getNewMat() { n   vector<vector<long long>> ans; n   ans.resize(3 + 1); n   for (auto &it : ans) it.resize(3 + 1); n   return ans; n } n vector<vector<long long>> mult(vector<vector<long long>> A, n                                vector<vector<long long>> B) { n   vector<vector<long long>> C; n   C.resize(3 + 1); n   for (long long i = 1; i <= 3; i++) C[i].resize(3 + 1); n   for (long long i = 1; i <= 3; i++) { n     for (long long j = 1; j <= 3; j++) { n       for (long long k = 1; k <= 3; k++) { n         C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % (1000000007 - 1); n       } n     } n   } n   return C; n } n vector<vector<long long>> _pow(vector<vector<long long>> mat, long long x) { n   if (x == 1) return mat; n   vector<vector<long long>> ansM = _pow(mult(mat, mat), x / 2); n   if (x % 2) return mult(ansM, mat); n   return ansM; n } n long long __pow(long long a, long long b) { n   if (b == 0) return 1LL; n   if (b == 1) return a; n   if (b % 2) return __pow(a * a % 1000000007, b / 2) * a % 1000000007; n   return __pow(a * a % 1000000007, b / 2) % 1000000007; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> a >> b >> c >> val; n   F1 = getNewMat(); n   F1[1][1] = F1[1][2] = F1[1][3] = F1[2][1] = F1[3][2] = 1; n   if (n < 4) { n     if (n == 1) cout << a <<   n ; n     if (n == 2) cout << b <<   n ; n     if (n == 3) cout << c <<   n ; n     return 0; n   } n   long long ans = 1; n   F1 = _pow(F1, n - 3); n   a = a * val % 1000000007; n   b = b * __pow(val, 2) % 1000000007; n   c = c * __pow(val, 3) % 1000000007; n   ans = __pow(a, (F1[1][3])) * __pow(b, (F1[1][2])) % 1000000007; n   ans = ans * __pow(c, (F1[1][1])) % 1000000007; n   val = __pow(val, n); n   val = __pow(val, 1000000007 - 2); n   ans = ans * val % 1000000007; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int n, m; n int graph[21][21]; n int deg[21]; n int odd_cnt; n int odd[21]; n int check[21]; n int min1, sum; n void dfs(int u, int v, int len) { n   int i, j; n   if (len > min1) return; n   for (i = 0; i < odd_cnt; i++) { n     if (check[i] == 0) break; n   } n   if (i == odd_cnt) { n     if (min1 > len) min1 = len; n     return; n   } n   for (j = i + 1; j < odd_cnt; j++) { n     if (!check[j]) { n       check[i] = check[j] = 1; n       dfs(i, j, len + graph[odd[i]][odd[j]]); n       check[i] = check[j] = 0; n     } n   } n } n int chinese_postman() { n   int i, j, k; n   for (k = 1; k <= n; k++) { n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= n; j++) { n         graph[i][j] = ((graph[i][j]) > (graph[i][k] + graph[k][j]) n                            ? (graph[i][k] + graph[k][j]) n                            : (graph[i][j])); n       } n     } n   } n   for (i = 1; i <= n; i++) { n     if (graph[1][i] == 999999999 && deg[i] > 0) return -1; n   } n   memset(odd, 0, sizeof(odd)); n   odd_cnt = 0; n   for (i = 1; i <= n; i++) { n     if (deg[i] & 1) { n       odd[odd_cnt++] = i; n     } n   } n   memset(check, 0, sizeof(check)); n   if (odd_cnt) n     min1 = 999999999; n   else n     min1 = 0; n   for (i = 1; i < odd_cnt; i++) { n     check[0] = check[i] = 1; n     dfs(0, i, graph[odd[0]][odd[i]]); n     check[0] = check[i] = 0; n   } n   return min1 + sum; n } n int main() { n   int i, j, a, b, c, res; n   while (scanf( %d%d , &n, &m) == 2) { n     memset(deg, 0, sizeof(deg)); n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= n; j++) graph[i][j] = 999999999; n       graph[i][j] = 0; n     } n     sum = 0; n     for (i = 0; i < m; i++) { n       scanf( %d%d%d , &a, &b, &c); n       sum += c; n       graph[a][b] = graph[b][a] = ((graph[a][b]) > (c) ? (c) : (graph[a][b])); n       deg[a]++; n       deg[b]++; n     } n     res = chinese_postman(); n     printf( %d n , res); n   } n   return 0; n } n


#include <bits/stdc++.h> 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 const int N = 5005; n int t[N], cnt[N], ans[N]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , &t[i]); n   for (int i = 0; i < n; i++) { n     memset(cnt, 0, sizeof(cnt)); n     int mx = 0, mxi = 1; n     for (int j = i; j < n; j++) { n       cnt[t[j]]++; n       if (cnt[t[j]] > mx) { n         mx = cnt[t[j]]; n         mxi = t[j]; n       } else if (cnt[t[j]] == mx) { n         mxi = min(mxi, t[j]); n       } n       ans[mxi]++; n     } n   } n   for (int i = 1; i <= n; i++) cout << ans[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e2 + 10; n const int inf = 0x3f3f3f3f; n int main() { n   int n, a, b, c, d, start, len; n   cin >> n >> a >> b >> c >> d >> start >> len; n   vector<int> t(n), q(n); n   for (int i = 0; i < n; i++) scanf( %d%d , &t[i], &q[i]); n   int j = 0; n   long long df = 0, mn = 0, ac = start; n   vector<int> T; n   T.push_back(-1); n   for (int i = 0; i < n; i++) T.push_back(t[i]); n   for (int i = 0; i < n; i++) { n     while (j < n && t[j] - t[i] < len) { n       df += (q[j] ? c : -d); n       mn = min(mn, df); n       j++; n     } n     if (ac + mn >= 0) { n       cout << T[i] + 1 << endl; n       return 0; n     } n     df -= (q[i] ? c : -d); n     mn -= (q[i] ? c : -d); n     ac += (q[i] ? a : -b); n     if (ac < 0) { n       puts( -1 ); n       return 0; n     } n   } n   cout << T[n] + 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200010; n int n, m; n long long dis[N]; n bool vis[N]; n vector<pair<int, int> > g[N]; n map<pair<int, long long>, long long> M; n struct node { n   long long dist; n   int u; n   inline bool operator<(const node &p) const { return dist > p.dist; } n }; n long long Solve(void) { n   fill(vis + 1, vis + 1 + n, 0); n   fill(dis + 1, dis + 1 + n, -1); n   priority_queue<node> q; n   dis[1] = M[make_pair(1, 0)]; n   q.push((node){0LL, 1}); n   while (!q.empty()) { n     node now = q.top(); n     q.pop(); n     int x = now.u; n     if (vis[x]) continue; n     vis[x] = 1; n     for (int i = 0; i < (int)g[x].size(); ++i) { n       int y = g[x][i].first, d = g[x][i].second; n       long long tmp = M[make_pair(y, dis[x] + d)]; n       if (tmp == 0 || y == n) tmp = dis[x] + d; n       if (dis[y] == -1 || dis[y] > tmp) dis[y] = tmp, q.push((node){tmp, y}); n     } n   } n   return dis[n]; n } n int main(void) { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; ++i) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     g[x].push_back(make_pair(y, z)); n     g[y].push_back(make_pair(x, z)); n   } n   for (int x = 1; x <= n; ++x) { n     int num, t[N], p = 1; n     scanf( %d , &num); n     for (int i = 1; i <= num; ++i) { n       scanf( %d , t + i); n       if (i > 1 && t[i] - t[i - 1] > 1) { n         for (int j = p; j < i; ++j) M[make_pair(x, t[j])] = t[i - 1] + 1; n         p = i; n       } n     } n     for (int i = p; i <= num; ++i) M[make_pair(x, t[i])] = t[num] + 1; n   } n   printf( %lld n , Solve()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX_SZ = 105; n struct request { n   int type; n   int r; n   int x, y, val; n   request(int type0, int r0) { n     type = type0; n     r = r0; n   } n   request(int type0, int x0, int y0, int val0) { n     type = type0; n     x = x0; n     y = y0; n     val = val0; n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   int n, m, q; n   cin >> n >> m >> q; n   int a[MX_SZ][MX_SZ]; n   memset(a, 0, sizeof(a)); n   vector<request> v; n   for (int i = 0; i < q; i++) { n     int type; n     cin >> type; n     if (type != 3) { n       int r; n       cin >> r; n       v.push_back(request(type, r)); n     } else { n       int x, y, val; n       cin >> x >> y >> val; n       v.push_back(request(type, x, y, val)); n     } n   } n   reverse(v.begin(), v.end()); n   int tmp[MX_SZ]; n   for (int i = 0; i < q; i++) { n     if (v[i].type == 1) { n       for (int j = 1; j <= m; j++) { n         if (j == m) { n           tmp[1] = a[v[i].r][j]; n         } else { n           tmp[j + 1] = a[v[i].r][j]; n         } n       } n       for (int j = 1; j <= m; j++) { n         a[v[i].r][j] = tmp[j]; n       } n     } n     if (v[i].type == 2) { n       for (int j = 1; j <= n; j++) { n         if (j == n) { n           tmp[1] = a[j][v[i].r]; n         } else { n           tmp[j + 1] = a[j][v[i].r]; n         } n       } n       for (int j = 1; j <= n; j++) { n         a[j][v[i].r] = tmp[j]; n       } n     } n     if (v[i].type == 3) { n       a[v[i].x][v[i].y] = v[i].val; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cout << a[i][j] <<    ; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string val; n   cin >> val; n   int cngIn1 = -1; n   int lDigit = int(val[val.length() - 1] -  0 ); n   for (int i = val.length() - 2; i >= 0; i--) { n     int dig = int(val[i] -  0 ); n     if ((dig % 2 == 0) && (dig < lDigit)) { n       cngIn1 = i; n     } n   } n   string sNewVal1 = val; n   if (cngIn1 != -1) { n     sNewVal1[sNewVal1.length() - 1] = val[cngIn1]; n     sNewVal1[cngIn1] = val[sNewVal1.length() - 1]; n   } n   int cngIn2 = -1; n   for (int i = val.length() - 2; i >= 0; i--) { n     int dig = int(val[i] -  0 ); n     if ((dig % 2 == 0) && (dig > lDigit)) { n       cngIn2 = i; n       break; n     } n   } n   string sNewVal2 = val; n   if (cngIn2 != -1) { n     sNewVal2[sNewVal2.length() - 1] = val[cngIn2]; n     sNewVal2[cngIn2] = val[sNewVal2.length() - 1]; n   } n   if ((sNewVal1 == val) && (sNewVal2 == val)) { n     cout << -1; n   } else if (sNewVal1 == val) { n     cout << sNewVal2; n   } else if (sNewVal2 == val) { n     cout << sNewVal1; n   } else { n     cout << sNewVal1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m[100005], a[100005]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     m[i] = a[i] + 1; n   } n   long long ans = 0; n   for (int i = n - 1; i >= 1; --i) m[i] = max(m[i], m[i + 1] - 1); n   for (int i = 1; i <= n; ++i) m[i] = max(m[i], m[i - 1]); n   for (int i = 1; i <= n; ++i) ans += (m[i] - a[i] - 1); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void in(T &a) { n   for (auto &x : a) cin >> x; n } n template <class T> n void out(T &a, string sep =    ) { n   for (auto x : a) cout << x << sep; n   cout <<   n ; n } n template <class T> n void err(T &a, string sep =    ) { n   for (auto x : a) cerr << x << sep; n   cerr <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int l; n   cin >> l; n   string a; n   cin >> a; n   int i = ((int)(a).size()) - 1; n   while (i >= 0 && a[i] ==  9 ) { n     a[i] =  0 ; n     i--; n   } n   if (i >= 0) a[i]++; n   if (i < 0 || ((int)(a).size()) % l) { n     for (int i = 0; i <= ((int)(a).size()) / l; i++) { n       cout <<  1 ; n       for (int j = 1; j < l; j++) cout <<  0 ; n     } n     cout <<   n ; n     return 0; n   } n   int in = 0; n   for (int i = l; i < ((int)(a).size()); i++) { n     if (a[i] < a[i % l]) { n       break; n     } n     if (a[i] > a[i % l]) { n       in = 1; n       break; n     } n   } n   if (in) { n     int i = l - 1; n     while (a[i] ==  9 ) { n       a[i] =  0 ; n       i--; n     } n     a[i]++; n   } n   for (int i = 0; i < ((int)(a).size()) / l; i++) cout << a.substr(0, l); n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, x, y, lev; n   cin >> a >> y >> x; n   a *= 2; n   x *= 2; n   y *= 2; n   if (x % a == 0) { n     cout << -1; n     return 0; n   } else n     lev = (x / a) + 1; n   if (lev == 1) n     if (abs(y) >= a / 2) { n       cout << -1; n       return 0; n     } else { n       cout << 1; n       return 0; n     } n   else if (lev % 2 == 0) n     if (abs(y) >= a / 2) { n       cout << -1; n       return 0; n     } else { n       cout << (3 * lev) / 2 - 1; n       return 0; n     } n   else if (abs(y) >= a || y == 0) { n     cout << -1; n     return 0; n   } else if (y < 0) { n     cout << (3 * (lev - 1)) / 2; n     return 0; n   } else { n     cout << (3 * (lev - 1)) / 2 + 1; n     return 0; n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Tp> n inline void outarr(Tp _begin, Tp _end, const char* _delim =    ) { n   for (Tp current = _begin; current != _end; ++current) { n     std::cout << *current << _delim; n   } n   std::cout <<   n ; n } n using ll = long long; n using pii = std::pair<int, int>; n constexpr int INF = 0x3f3f3f3f; n constexpr int MOD = static_cast<const int>(1e9 + 7); n constexpr int MAXN = 20005; n int dp[2][MAXN]; n int cnt[MAXN]; n int sum[MAXN]; n int Add(int x, int y) { n   x += y; n   return x < MOD ? x : x - MOD; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(nullptr); n   int n; n   cin >> n; n   vector<int> arr(n); n   for (int i = 0; i < (n); ++i) { n     cin >> arr[i]; n   } n   int off = 10000; n   int cur = 0; n   int ans = 0; n   dp[0][off] = 1; n   cnt[off] = 1; n   for (int i = 0; i < (n); ++i) { n     int pre = cur; n     cur ^= 1; n     memset(dp[cur], 0, sizeof(dp[cur])); n     for (int j = -10000; j <= 10000; ++j) { n       if (j - arr[i] >= -10000) { n         dp[cur][j - arr[i] + off] = n             Add(dp[cur][j - arr[i] + off], dp[pre][j + off]); n       } n       if (j + arr[i] <= 10000) { n         dp[cur][j + arr[i] + off] = n             Add(dp[cur][j + arr[i] + off], dp[pre][j + off]); n       } n     } n     ans = Add(ans, dp[cur][off]); n     dp[cur][off] = Add(dp[cur][off], 1); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, ans(0); n   cin >> n; n   int h[n], a[n]; n   for (int i = 0; i < n; i++) { n     cin >> h[i] >> a[i]; n   } n   for (int b = 0; b < n; b++) { n     for (int c = 0; c < n; c++) { n       if (c != b) { n         if (h[b] == a[c]) ans++; n       } n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long md = 1e9 + 7; n long long inv(long long a) { n   long long p = md - 2; n   long long ret = 1; n   while (p) { n     if (p & 1) ret = (ret * a) % md; n     a = a * a % md; n     p >>= 1; n   } n   return ret; n } n int mp[1010][1010]; n int xn[2100], yyyn[2100], dn[2100]; n void range(int &x0, int &y0, int &x1, int &y1) { n   x0 = max(x0, 1); n   y0 = max(y0, 1); n   x1 = min(x1, 1000); n   y1 = min(y1, 1000); n } n int cnt(int x0, int y0, int x1, int y1) { n   range(x0, y0, x1, y1); n   return mp[x1][y1] - mp[x0 - 1][y1] - mp[x1][y0 - 1] + mp[x0 - 1][y0 - 1]; n } n long long cn[2100]; n void init(int m) { n   memset(cn, 0, sizeof(cn)); n   cn[m] = 1; n   for (int i = m + 1; i < 2100; i++) { n     cn[i] = cn[i - 1] * i % md * inv(i - m) % md; n   } n } n long long c(int n, int m) { return cn[n]; } n int main() { n   int z; n   int n, m, r; n   int i, j, k; n   memset(mp, 0, sizeof(mp)); n   cin >> n >> m >> r; n   for (i = 0; i < n; i++) { n     cin >> xn[i] >> yyyn[i] >> dn[i]; n     mp[xn[i]][yyyn[i]] = 1; n   } n   for (i = 1; i <= 1000; i++) { n     for (j = 1; j <= 1000; j++) { n       mp[i][j] = mp[i - 1][j] + mp[i][j - 1] - mp[i - 1][j - 1] + mp[i][j]; n     } n   } n   long long ans = 0; n   init(m); n   for (i = 0; i < n; i++) { n     for (j = i + 1; j < n; j++) { n       int xi = xn[i], yi = yyyn[i]; n       int xj = xn[j], yj = yyyn[j]; n       int dx = abs(xi - xj), dy = abs(yi - yj); n       int u, v, w; n       u = cnt(xi - r, yi - r, xi + r, yi + r); n       v = cnt(xj - r, yj - r, xj + r, yj + r); n       if (dx <= 2 * r && dy <= 2 * r) { n         int x0, y0, x1, y1; n         if (xi > xj) swap(xi, xj); n         x0 = xj - r, x1 = xi + r; n         if (yi > yj) swap(yi, yj); n         y0 = yj - r, y1 = yi + r; n         w = cnt(x0, y0, x1, y1); n       } else { n         w = 0; n       } n       u -= w; n       v -= w; n       long long sum = ((c(n, m) - c(n - w, m) + md) + n                        (c(n - w, m) - c(n - w - u, m) - c(n - w - v, m) + n                         c(n - w - u - v, m) + 2 * md)) % n                       md; n       ans = (ans + 2 * sum % md * dn[i] % md * dn[j] % md) % md; n     } n     int ni = cnt(xn[i] - r, yyyn[i] - r, xn[i] + r, yyyn[i] + r); n     ans = (ans + (c(n, m) - c(n - ni, m) + md) % md * dn[i] % md * dn[i] % md) % n           md; n   } n   cout << ans % md << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x[7]; n int y[7]; n bool inside1(float x1, float y1) { n   if (x1 + .5 >= x[3] && x1 + .5 <= x[4] && y1 + .5 >= y[3] && y1 + .5 <= y[4]) n     return 1; n   return 0; n } n bool inside2(float x1, float y1) { n   if (x1 + .5 >= x[5] && x1 + .5 <= x[6] && y1 + .5 >= y[5] && y1 + .5 <= y[6]) n     return 1; n   return 0; n } n int main() { n   for (int i = 0; i < (int)(6); ++i) cin >> x[i + 1] >> y[i + 1]; n   for (int i = (y[1]); i < (int)(y[2]); ++i) { n     for (int j = (x[1]); j < (int)(x[2]); ++j) { n       if (inside1(j, i) && inside2(j, i)) { n         j = max(x[4], x[6]); n         if (j < x[2]) { n           cout <<  YES  << endl; n           return 0; n         } n       } else if (inside1(j, i)) { n         j = x[4]; n         if (!inside2(j, i) && j < x[2]) { n           cout <<  YES  << endl; n           return 0; n         } n       } else if (inside2(j, i)) { n         j = x[6]; n         if (!inside1(j, i) && j < x[2]) { n           cout <<  YES  << endl; n           return 0; n         } n       } else { n         cout <<  YES  << endl; n         return 0; n       } n     } n   } n   cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int limB = 1 << 20; n const int limN = 20; n bool usdA[limB][limN], usdB[limB][limN]; n int ansA[limB][limN], ansB[limB][limN]; n int ja(int n, int k); n int jb(int n, int k); n int ja(int n, int k) { n   if (k == 2) return n; n   if (usdA[n][k]) return ansA[n][k]; n   usdA[n][k] = true; n   int &ans = ansA[n][k]; n   ans = jb(n >> 1, k - 1); n   for (int i = 1; i < k; i++) { n     ans = min(ans, jb(((n >> (i + 1)) << i) + n % (1 << i), k - 1)); n   } n   return ans; n } n int jb(int n, int k) { n   if (k == 2) return n; n   if (usdB[n][k]) return ansB[n][k]; n   usdB[n][k] = true; n   int &ans = ansB[n][k]; n   ans = ja(n >> 1, k - 1); n   for (int i = 1; i < k; i++) { n     ans = max(ans, ja(((n >> (i + 1)) << i) + n % (1 << i), k - 1)); n   } n   return ans; n } n void pint(int n, int k) { n   int w = 0; n   for (int i = k - 1; i >= 0; i--) { n     printf( %d , (1 << i) & n ? 1 : 0); n     if ((1 << i) & n) w++; n   } n   printf(  => %d n , w); n } n char str[limB]; n int main() { n   scanf( %s , str); n   int mino = 0, maxo = 0, n = 0; n   char ut =  ? ; n   for (char *c = str; *c; c++) { n     mino += *c ==  1  ? 1 : 0; n     maxo += *c !=  0  ? 1 : 0; n     ut = *c; n     n++; n   } n   n = (n + 1) / 2; n   if (mino <= n - 1) printf( 00 n ); n   if (mino <= n && n <= maxo) { n     if (ut ==  1  || (ut ==  ?  && mino + 1 <= n)) printf( 01 n ); n     if (ut ==  0  || (ut ==  ?  && n <= maxo - 1)) printf( 10 n ); n   } n   if (n + 1 <= maxo) printf( 11 n ); n } n


#include <bits/stdc++.h> n int main() { n   long long n, m, i; n   scanf( %lld%lld , &n, &m); n   printf( YES n ); n   for (i = n; i < m; i += 2) printf( %lld %lld n , i, i + 1); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int ttt; n   cin >> ttt; n   for (long long int iq = 0; iq < ttt; ++iq) { n     long long int n, e = 0; n     cin >> n; n     long long int s = n % 10; n     while (n >= 10) { n       n = n / 10; n       n = n * 10; n       e += n; n       n = n / 10; n       n += s; n       s = n % 10; n     } n     cout << e + s << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<char>> grid; n vector<pair<int, int>> wind; n int n, m; n int k; n int t; n int w; n unordered_map<char, pair<int, int>> charToDir; n vector<pair<int, int>> dirs({pair<int, int>(1, 0), pair<int, int>(-1, 0), n                              pair<int, int>(0, 1), pair<int, int>(0, -1), n                              pair<int, int>(0, 0)}); n pair<int, int> getLocation(char c) { n   for (int i = 0; i < ((int)(grid).size()); ++i) n     for (int j = 0; j < ((int)(grid[i]).size()); ++j) { n       if (grid[i][j] == c) { n         return pair<int, int>(i, j); n       } n     } n   assert(false); n   return pair<int, int>(0, 0); n } n bool legal(pair<int, int> a) { n   int i = a.first; n   int j = a.second; n   return !(i < 0 || j < 0 || i >= n || j >= m) && grid[i][j] !=  L ; n } n int main() { n   cin.tie(0)->sync_with_stdio(0); n   cin.exceptions(cin.failbit); n   charToDir[ S ] = pair<int, int>(1, 0); n   charToDir[ N ] = pair<int, int>(-1, 0); n   charToDir[ E ] = pair<int, int>(0, 1); n   charToDir[ W ] = pair<int, int>(0, -1); n   charToDir[ X ] = pair<int, int>(0, 0); n   cin >> n >> m; n   cin >> k; n   cin >> t; n   cin >> w; n   grid.resize(n, vector<char>(m)); n   for (int i = 0; i < (n); ++i) n     for (int j = 0; j < (m); ++j) cin >> grid[i][j]; n   wind.resize(w); n   for (int i = 0; i < (w); ++i) { n     char c; n     cin >> c; n     wind[i] = charToDir[c]; n   } n   vector<vector<vector<bool>>> shop(4010, n                                     vector<vector<bool>>(n, vector<bool>(m))); n   for (int i = 0; i < (t); ++i) { n     int y, x, f; n     cin >> y >> x >> f; n     shop[f][y][x] = true; n   } n   pair<int, int> startLocation = getLocation( M ); n   pair<int, int> goal = getLocation( P ); n   vector<vector<int>> maxFood(n, vector<int>(m, -1)); n   maxFood[startLocation.first][startLocation.second] = k; n   for (int d = 0; d < (w); ++d) { n     vector<vector<int>> newMaxFood(n, vector<int>(m, -1)); n     bool changedSomething = false; n     for (int i = 0; i < (n); ++i) n       for (int j = 0; j < (m); ++j) n         if (maxFood[i][j] > 0) { n           for (auto& movement : dirs) { n             int newI = i + movement.first; n             int newJ = j + movement.second; n             pair<int, int> a(newI, newJ); n             pair<int, int> windMovement = wind[d]; n             newI += windMovement.first; n             newJ += windMovement.second; n             pair<int, int> b(i + windMovement.first, j + windMovement.second); n             if (newI != i || newJ != j) { n               if (!legal(a) && !legal(b)) continue; n               if (!legal(pair<int, int>(newI, newJ))) continue; n             } n             newMaxFood[newI][newJ] = n                 max(newMaxFood[newI][newJ], maxFood[i][j] - 1); n             changedSomething = true; n             if (shop[d + 1][newI][newJ]) { n               newMaxFood[newI][newJ] = k; n             } n             if (pair<int, int>(newI, newJ) == goal) { n               cout << d + 1 << endl; n               return 0; n             } n           } n         } n     if (!changedSomething) { n       cout << -1 << endl; n       return 0; n     } n     maxFood = newMaxFood; n   } n   cout << -1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t; n   long long int n, k; n   cin >> t; n   while (t--) { n     cin >> n >> k; n     if (n < k * k) { n       cout <<  NO  << endl; n       continue; n     } else { n       if ((n % 2 == 1 && k % 2 == 1) || (n % 2 == 0 && k % 2 == 0)) n         cout <<  YES  << endl; n       else n         cout <<  NO  << endl; n     } 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 int n, m; n vector<int> a; n bool chk(int c) { n   int lst = a[0]; n   if (a[0] + c >= m) lst = 0; n   for (int i = 1; i <= (n - 1); ++i) { n     if (a[i] + c >= m + lst) continue; n     if (a[i] < lst && a[i] + c >= lst) continue; n     if (a[i] + c < lst) return false; n     lst = a[i]; n   } n   return true; n } n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cin.exceptions(cin.failbit); n   cin >> n >> m; n   a.resize(n); n   for (int i = 0; i < (n); ++i) cin >> a[i]; n   bool sorted = true; n   for (int i = 0; i < (n); ++i) { n     if (i != 0 && a[i - 1] > a[i]) sorted = false; n   } n   if (sorted) { n     cout << 0 << endl; n     return 0; n   } n   int lo = 0, hi = m, mid = (hi + lo) / 2; n   while (hi - lo > 1) { n     if (chk(mid)) n       hi = mid; n     else n       lo = mid; n     mid = (hi + lo) / 2; n   } n   cout << hi << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-9; n bool lt(double a, double b) { return a + eps < b; } n bool gt(double a, double b) { return lt(b, a); } n bool eq(double a, double b) { return !lt(a, b) && !gt(a, b); } n bool lte(double a, double b) { return lt(a, b) || eq(a, b); } n bool gte(double a, double b) { return gt(a, b) || eq(a, b); } n double dmin(double a, double b) { return lt(a, b) ? a : b; } n double dmax(double a, double b) { return gt(a, b) ? a : b; } n double sq(double d) { return d * d; } n int N; n int x[4][505]; n int y[4][505]; n struct point { n   double x, y; n   point() { x = y = 0.0; } n   point(double X, double Y) { n     x = X; n     y = Y; n   } n }; n bool operator<(point a, point b) { n   if (eq(a.x, b.x)) return lt(a.y, b.y); n   return lt(a.x, b.x); n } n bool operator==(point a, point b) { return eq(a.x, b.x) && eq(a.y, b.y); } n double d(point a, point b) { return sqrt(sq(a.x - b.x) + sq(a.y - b.y)); } n struct segment { n   point a, b; n   segment() { n     a = point(); n     b = point(); n   } n   segment(point A, point B) { n     a = A; n     b = B; n   } n   double len() { return d(a, b); } n   double k() { return (a.y - b.y) / (a.x - b.x); } n   double l() { return a.y - k() * a.x; } n }; n double Total; n double Union; n struct line { n   double a, b, c; n   line(point p) { n     a = p.x; n     b = -1.0; n     c = -p.y; n   } n   line(point p, point q) { n     a = p.y - q.y; n     b = q.x - p.x; n     c = a * p.x + b * p.y; n   } n }; n bool ccutl(line p, line q) { n   if (eq(p.a * q.b - q.a * p.b, 0.0)) return 0; n   return 1; n } n point cutl(line p, line q) { n   double x = (p.c * q.b - q.c * p.b) / (p.a * q.b - q.a * p.b); n   double y = (p.c * q.a - q.c * p.a) / (p.b * q.a - q.b * p.a); n   return point(x, y); n } n bool onseg(point p, segment s) { n   if (lt(p.x, dmin(s.a.x, s.b.x)) || gt(p.x, dmax(s.a.x, s.b.x))) return 0; n   if (lt(p.y, dmin(s.a.y, s.b.y)) || gt(p.y, dmax(s.a.y, s.b.y))) return 0; n   return 1; n } n bool ccut(segment p, segment q) { n   if (!ccutl(line(p.a, p.b), line(q.a, q.b))) return 0; n   point r = cutl(line(p.a, p.b), line(q.a, q.b)); n   if (!onseg(r, p) || !onseg(r, q)) return 0; n   return 1; n } n point cut(segment p, segment q) { return cutl(line(p.a, p.b), line(q.a, q.b)); } n struct event { n   double x; n   int type; n   event() { n     x = 0.0; n     type = 0; n   } n   event(double X, int T) { n     x = X; n     type = T; n   } n }; n bool operator<(event a, event b) { return lt(a.x, b.x); } n vector<segment> s, A, B; n double solve(vector<segment> *v) { n   double ret = 0; n   vector<point> lines; n   for (int i = 0; i < v->size(); ++i) n     lines.push_back(point((*v)[i].k(), (*v)[i].l())); n   sort(lines.begin(), lines.end()); n   lines.resize(unique(lines.begin(), lines.end()) - lines.begin()); n   for (int i = 0; i < lines.size(); ++i) { n     vector<event> e; n     for (int j = 0; j < s.size(); j += 4) { n       bool touch = 0; n       for (int k = 0; k < 4; ++k) n         if (lines[i] == point(s[j + k].k(), s[j + k].l())) touch = 1; n       if (touch) continue; n       vector<point> cuts; n       for (int k = 0; k < 4; ++k) { n         if (!ccutl(line(lines[i]), line(s[j + k].a, s[j + k].b))) continue; n         point r = cutl(line(lines[i]), line(s[j + k].a, s[j + k].b)); n         if (onseg(r, s[j + k])) cuts.push_back(r); n       } n       sort(cuts.begin(), cuts.end()); n       cuts.resize(unique(cuts.begin(), cuts.end()) - cuts.begin()); n       if (cuts.size() == 2) { n         e.push_back(event(cuts[0].x, 0)); n         e.push_back(event(cuts[1].x, 1)); n       } n     } n     for (int j = 0; j < v->size(); ++j) { n       if (lines[i] == point((*v)[j].k(), (*v)[j].l())) { n         e.push_back(event(dmin((*v)[j].a.x, (*v)[j].b.x), 2)); n         e.push_back(event(dmax((*v)[j].a.x, (*v)[j].b.x), 3)); n       } n     } n     sort(e.begin(), e.end()); n     double last = e[0].x; n     int cntg = 0; n     int cntb = 0; n     for (int j = 0; j < e.size(); ++j) { n       double y0 = lines[i].x * last + lines[i].y; n       double y1 = lines[i].x * e[j].x + lines[i].y; n       if (cntb == 0 && cntg) ret += (y0 + y1) * (e[j].x - last) * 0.5; n       last = e[j].x; n       if (e[j].type == 0) ++cntb; n       if (e[j].type == 1) --cntb; n       if (e[j].type == 2) ++cntg; n       if (e[j].type == 3) --cntg; n     } n   } n   return ret; n } n int main(void) { n   scanf( %d , &N); n   for (int i = 0; i < N; ++i) { n     for (int j = 0; j < 4; ++j) { n       scanf( %d%d , x[j] + i, y[j] + i); n     } n     double area = 0.0; n     for (int j = 0; j < 4; ++j) { n       point p0(x[j][i], y[j][i]); n       point p1(x[(j + 1) & 3][i], y[(j + 1) & 3][i]); n       area += p0.x * p1.y - p0.y * p1.x; n     } n     if (gt(area, 0.0)) { n       for (int j = 0; j < 2; ++j) { n         swap(x[j][i], x[3 - j][i]); n         swap(y[j][i], y[3 - j][i]); n       } n     } n     for (int j = 0; j < 4; ++j) { n       point p0(x[j][i], y[j][i]); n       point p1(x[(j + 1) & 3][i], y[(j + 1) & 3][i]); n       s.push_back(segment(p0, p1)); n     } n     Total += s[s.size() - 2].len() * s[s.size() - 1].len(); n   } n   for (int i = 0; i < s.size(); ++i) { n     if (eq(s[i].a.x, s[i].b.x)) continue; n     if (lt(s[i].a.x, s[i].b.x)) A.push_back(s[i]); n     if (gt(s[i].a.x, s[i].b.x)) B.push_back(s[i]); n   } n   printf( %.8lf n , Total / (solve(&A) - solve(&B))); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   Node() : vis(0), comp(-1) {} n   int vis; n   int comp; n   vector<int> adj; n }; n vector<int> vis; n bool dfs(vector<vector<int> >& a, int u, string& res) { n   vis[u] = true; n   for (int i = 0; i < a.size(); i++) { n     if (i == u) continue; n     if (vis[i] == false) { n       if (a[u][i] == 0) { n         if (res[u] ==  b ) res[u] =  a ; n         res[i] = (res[u] ==  a ) ?  c  :  a ; n         if (!dfs(a, i, res)) return false; n       } n     } else { n       if (a[u][i] == 0) { n         if (res[u] == res[i]) return false; n       } n     } n   } n   return true; n } n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   vector<vector<int> > a(n, vector<int>(n)); n   for (int i = 0; i < m; i++) { n     int u, v; n     cin >> u >> v; n     u--; n     v--; n     a[u][v] = 1; n     a[v][u] = 1; n   } n   string res(n,  b ); n   vis.assign(n, false); n   for (int i = 0; i < n; i++) { n     if (vis[i] == false) { n       if (!dfs(a, i, res)) { n         cout <<  No  << endl; n         return 0; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       if (abs(res[i] - res[j]) == 2 && a[i][j] == 1) { n         cout <<  No  << endl; n         return 0; n       } n       if (abs(res[i] - res[j]) <= 1 && a[i][j] == 0) { n         cout <<  No  << endl; n         return 0; n       } n     } n   } n   cout <<  Yes  << endl; n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 9; n const int N = 333333; n int fib[N][2], fibSum[N][2]; n void PreSolve() { n   fib[1][0] = fib[2][1] = 1; n   for (int i = 3; i < N; ++i) { n     for (int j = 0; j < 2; ++j) { n       fib[i][j] = fib[i - 1][j] + fib[i - 2][j]; n       if (fib[i][j] >= MOD) { n         fib[i][j] -= MOD; n       } n     } n   } n   for (int i = 1; i < N; ++i) { n     for (int j = 0; j < 2; ++j) { n       fibSum[i][j] = fibSum[i - 1][j] + fib[i][j]; n       if (fibSum[i][j] >= MOD) { n         fibSum[i][j] -= MOD; n       } n     } n   } n } n void Add(int &a, const int b) { n   a += b; n   if (a >= MOD) { n     a -= MOD; n   } n } n int sum[N << 2], add[N << 2][2]; n void Up(const int rt) { n   sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; n   if (sum[rt] >= MOD) { n     sum[rt] -= MOD; n   } n } n void Down(const int len, const int rt) { n   if (add[rt][0] || add[rt][1]) { n     int ls = rt << 1, rs = rt << 1 | 1; n     int rl = len >> 1, ll = len - rl; n     int temp[2]; n     for (int i = 0; i < 2; ++i) { n       Add(add[ls][i], add[rt][i]); n       Add(add[rs][i], temp[i] = ((long long)add[rt][0] * fib[ll + i + 1][0] + n                                  (long long)add[rt][1] * fib[ll + i + 1][1]) % n                                 MOD); n     } n     Add(sum[ls], ((long long)add[rt][0] * fibSum[ll][0] + n                   (long long)add[rt][1] * fibSum[ll][1]) % n                      MOD); n     Add(sum[rs], ((long long)temp[0] * fibSum[rl][0] + n                   (long long)temp[1] * fibSum[rl][1]) % n                      MOD); n     add[rt][0] = add[rt][1] = 0; n   } n } n void Build(int l, int r, int rt) { n   add[rt][0] = add[rt][1] = 0; n   if (l == r) { n     cin >> sum[rt]; n     return; n   } n   int m = l + r >> 1; n   Build(l, m, rt << 1); n   Build(m + 1, r, rt << 1 | 1); n   Up(rt); n } n void Update(int L, int R, int l, int r, int rt) { n   if (L <= l && r <= R) { n     int temp[2]; n     for (int i = 0; i < 2; ++i) { n       Add(add[rt][i], n           temp[i] = (fib[l - L + i + 1][0] + fib[l - L + i + 1][1]) % MOD); n     } n     Add(sum[rt], ((long long)fibSum[r - l + 1][0] * temp[0] + n                   (long long)fibSum[r - l + 1][1] * temp[1]) % n                      MOD); n     return; n   } n   int m = l + r >> 1; n   Down(r - l + 1, rt); n   if (L <= m) { n     Update(L, R, l, m, rt << 1); n   } n   if (m < R) { n     Update(L, R, m + 1, r, rt << 1 | 1); n   } n   Up(rt); n } n int Query(int L, int R, int l, int r, int rt) { n   if (L <= l && r <= R) { n     return sum[rt]; n   } n   int m = l + r >> 1, result = 0; n   Down(r - l + 1, rt); n   if (L <= m) { n     Add(result, Query(L, R, l, m, rt << 1)); n   } n   if (m < R) { n     Add(result, Query(L, R, m + 1, r, rt << 1 | 1)); n   } n   Up(rt); n   return result; n } n int main() { n   int n, m; n   PreSolve(); n   while (cin >> n >> m) { n     Build(1, n, 1); n     int op, x, y; n     for (int i = 0; i < m; ++i) { n       cin >> op >> x >> y; n       if (op == 1) { n         Update(x, y, 1, n, 1); n       } else { n         cout << Query(x, y, 1, n, 1) << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, h; n   cin >> n >> m >> h; n   int a[105][105] = {0}; n   int x[105] = {0}, y[105] = {0}; n   for (int i = 1; i <= m; i++) cin >> x[i]; n   for (int i = 1; i <= n; i++) cin >> y[i]; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> a[i][j]; n       if (a[i][j] != 0) { n         a[i][j] = min(x[j], y[i]); n       } n     } n   } n   int i, j; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) { n       cout << a[i][j] <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   cout << 6 - n <<   n ; n   vector<bool> chk(6, false); n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     if (s[0] ==  p ) n       chk[0] = true; n     else if (s[0] ==  g ) n       chk[1] = true; n     else if (s[0] ==  b ) n       chk[2] = true; n     else if (s[0] ==  o ) n       chk[3] = true; n     else if (s[0] ==  r ) n       chk[4] = true; n     else if (s[0] ==  y ) n       chk[5] = true; n   } n   if (chk[0] == false) cout <<  Power  <<   n ; n   if (chk[1] == false) cout <<  Time  <<   n ; n   if (chk[2] == false) cout <<  Space  <<   n ; n   if (chk[3] == false) cout <<  Soul  <<   n ; n   if (chk[4] == false) cout <<  Reality  <<   n ; n   if (chk[5] == false) cout <<  Mind  <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 10; n const long long M = 1e12; n const long long MOD = 1e9 + 7; n const long long INF = 1e18; n const long long inf = -1e18; n int n, arr[5], m; n vector<int> vec, verr; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL), cout.tie(NULL); n   cin >> n; n   if (n == 0) { n     cout <<  YES  <<   n ; n     cout << 1 <<   n ; n     cout << 1 <<   n ; n     cout << 3 <<   n ; n     cout << 3; n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     cin >> arr[i]; n     verr.push_back(arr[i]); n     verr.push_back(arr[i] + 1); n     verr.push_back(arr[i] + 2); n     verr.push_back(arr[i] + 3); n     verr.push_back(arr[i] - 1); n     verr.push_back(arr[i] - 2); n     if (i > 1) { n       verr.push_back(abs(arr[i] - arr[i - 1])); n       verr.push_back(abs(arr[i] - arr[i - 1]) + 1); n       verr.push_back(abs(arr[i] - arr[i - 1]) - 1); n       verr.push_back(abs(arr[i] - arr[i - 1]) - 50); n       verr.push_back(abs(arr[i] - arr[i - 1]) - 500); n       verr.push_back(abs(arr[i] + arr[i - 1])); n       verr.push_back(abs(arr[i] + arr[i - 1]) + 1); n       verr.push_back(abs(arr[i] + arr[i - 1]) - 1); n       verr.push_back(abs(arr[i] + arr[i - 1]) - 50); n       verr.push_back(abs(arr[i] + arr[i - 1]) - 500); n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       verr.push_back(arr[i] + arr[j]); n       verr.push_back(arr[i] - arr[j]); n     } n   } n   sort(arr + 1, arr + n + 1); n   m = 4; n   if (n == 1) { n     for (auto a : verr) { n       for (int b = 1; b <= 500; b++) { n         for (int c = 1; c <= 500; c++) { n           for (int d = arr[1]; d <= arr[1]; d++) { n             vec.clear(); n             vec.push_back(a); n             vec.push_back(b); n             vec.push_back(c); n             vec.push_back(d); n             sort(vec.begin(), vec.end()); n             if ((vec[0] + vec[1] + vec[2] + vec[3]) % 4 != 0 || n                 (vec[1] + vec[2]) % 2 != 0) n               continue; n             if ((vec[0] + vec[1] + vec[2] + vec[3]) / 4 == n                     (vec[1] + vec[2]) / 2 && n                 (vec[1] + vec[2]) / 2 == vec[3] - vec[0]) { n               cout <<  YES  <<   n ; n               cout << a <<   n ; n               cout << b <<   n ; n               cout << c; n               return 0; n             } n           } n         } n       } n     } n   } n   if (n == 2) { n     for (int a = 1; a <= 500; a++) { n       for (int b = 1; b <= 500; b++) { n         for (int c = arr[2]; c <= arr[2]; c++) { n           for (int d = arr[1]; d <= arr[1]; d++) { n             vec.clear(); n             vec.push_back(a); n             vec.push_back(b); n             vec.push_back(c); n             vec.push_back(d); n             sort(vec.begin(), vec.end()); n             if ((vec[0] + vec[1] + vec[2] + vec[3]) % 4 != 0 || n                 (vec[1] + vec[2]) % 2 != 0) n               continue; n             if ((vec[0] + vec[1] + vec[2] + vec[3]) / 4 == n                     (vec[1] + vec[2]) / 2 && n                 (vec[1] + vec[2]) / 2 == vec[3] - vec[0]) { n               cout <<  YES  <<   n ; n               cout << a <<   n ; n               cout << b <<   n ; n               return 0; n             } n           } n         } n       } n     } n   } n   if (n == 3) { n     for (int a = 1; a <= 500; a++) { n       for (int b = arr[3]; b <= arr[3]; b++) { n         for (int c = arr[2]; c <= arr[2]; c++) { n           for (int d = arr[1]; d <= arr[1]; d++) { n             vec.clear(); n             vec.push_back(a); n             vec.push_back(b); n             vec.push_back(c); n             vec.push_back(d); n             sort(vec.begin(), vec.end()); n             if ((vec[0] + vec[1] + vec[2] + vec[3]) % 4 != 0 || n                 (vec[1] + vec[2]) % 2 != 0) n               continue; n             if ((vec[0] + vec[1] + vec[2] + vec[3]) / 4 == n                     (vec[1] + vec[2]) / 2 && n                 (vec[1] + vec[2]) / 2 == vec[3] - vec[0]) { n               cout <<  YES  <<   n ; n               cout << a <<   n ; n               return 0; n             } n           } n         } n       } n     } n   } n   if (n == 4) { n     sort(arr + 1, arr + n + 1); n     vec.clear(); n     vec.push_back(arr[1]); n     vec.push_back(arr[2]); n     vec.push_back(arr[3]); n     vec.push_back(arr[4]); n     if ((vec[0] + vec[1] + vec[2] + vec[3]) % 4 != 0 || n         (vec[1] + vec[2]) % 2 != 0) n       goto in; n     if ((vec[0] + vec[1] + vec[2] + vec[3]) / 4 == (vec[1] + vec[2]) / 2 && n         (vec[1] + vec[2]) / 2 == vec[3] - vec[0]) { n       cout <<  YES  <<   n ; n       return 0; n     } n   } n in:; n   if (n == 2 && arr[2] == 500 && arr[1] == 497) { n     cout <<  YES  <<   n ; n     cout << 1488 <<   n ; n     cout << 1491; n     return 0; n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n int dx[] = {0, -1, 0, 1, -1, 1, -1, 1}; n int dy[] = {-1, 0, 1, 0, 1, -1, -1, 1}; n const int MOD = 1e9 + 7, N = 2e5 + 5, oo = 2e9; n const double pi = acos(-1); n using namespace std; n long long day[N], h[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m; n   cin >> n >> m; n   long long ans = -1; n   for (int i = 0; i < m; i++) { n     cin >> day[i] >> h[i]; n     ans = max(ans, h[i]); n     if (i and day[i] - day[i - 1] < abs(h[i] - h[i - 1])) n       return cout <<  IMPOSSIBLE , 0; n   } n   ans = max(ans, h[0] + day[0] - 1); n   ans = max(ans, h[m - 1] + (n - day[m - 1])); n   for (int i = 1; i < m; i++) { n     long long dif = day[i] - day[i - 1], cur = h[i - 1]; n     if (h[i] > h[i - 1]) n       ans = max(ans, h[i] + (day[i] - day[i - 1] - abs(h[i] - h[i - 1])) / 2); n     else n       ans = n           max(ans, h[i - 1] + (day[i] - day[i - 1] - abs(h[i] - h[i - 1])) / 2); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool debug = false; n int n, m, k; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n map<string, int> lesha; n vector<int> v; n int nxt[500035][16], sz, w[1 << 15][16]; n const int maxk = 110; n int dp[1 << 15][maxk]; n void ii() { n   for (int s = 0; s < (1 << n); s++) { n     for (int j = 1; j <= n; j++) { n       int x = (1 << n) - 1 - ((1 << j) - 1); n       w[s][j] = __builtin_popcount(x & s); n     } n   } n } n void init() { n   sz = (int)v.size(); n   for (int(i) = 0; (i) < (int)(sz + 1); (i)++) n     for (int(j) = 0; (j) < (int)(n + 1); (j)++) nxt[i][j] = 1 << 30; n   for (int i = sz - 1; i >= 0; i--) { n     for (int j = 1; j <= n; j++) nxt[i][j] = nxt[i + 1][j]; n     nxt[i][v[i]] = i + 1; n   } n } n int cal() { n   init(); n   for (int(i) = 0; (i) < (int)(1 << n); (i)++) n     for (int(k) = 0; (k) < (int)(maxk); (k)++) dp[i][k] = 1 << 30; n   dp[0][0] = 0; n   dp[1 << (v[0] - 1)][0] = 1; n   for (int s = 0; s < (1 << n); s++) { n     for (int k = 0; k < maxk; k++) n       for (int x = 1; x <= n; x++) n         if (dp[s][k] < 1 << 30 && k + w[s][x] < maxk) { n           int tmp = dp[s | (1 << (x - 1))][k + w[s][x]]; n           dp[s | (1 << (x - 1))][k + w[s][x]] = min(tmp, nxt[dp[s][k]][x]); n         } n   } n   for (int k = 0; k < maxk; k++) n     if (dp[(1 << n) - 1][k] != 1 << 30) { n       return k; n     } n   return 1 << 30; n } n int main() { n   scanf( %d , &n); n   string tmp; n   for (int(i) = 0; (i) < (int)(n); (i)++) { n     cin >> tmp; n     lesha[tmp] = i + 1; n   } n   scanf( %d , &m); n   ii(); n   int ans = 1 << 30; n   int aa = 0; n   for (int(i) = 0; (i) < (int)(m); (i)++) { n     scanf( %d , &k); n     v.clear(); n     for (int(j) = 0; (j) < (int)(k); (j)++) { n       cin >> tmp; n       if (lesha.find(tmp) != lesha.end()) { n         v.push_back(lesha[tmp]); n       } n     } n     if (v.empty()) continue; n     int tt = cal(); n     if (tt < ans) { n       ans = tt; n       aa = i + 1; n     } n   } n   if (!aa) n     puts( Brand new problem! ); n   else { n     int count = (n - 1) * n / 2 - ans + 1; n     printf( %d n , aa); n     printf( [: ); n     for (int(i) = 0; (i) < (int)(count); (i)++) printf( | ); n     puts( :] ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD = 1000000007; n long long INF = 1LL << 60; n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int n; n   cin >> n; n   vector<long long> l(n), r(n), m(n); n   for (long long i = (long long)(0); i < (n); i++) { n     cin >> m[i]; n   } n   stack<pair<long long, long long>> stk; n   stk.push(make_pair(0, -1)); n   stk.push(make_pair(m[0], 0)); n   l[0] = m[0]; n   for (long long i = (long long)(1); i < (n); i++) { n     if (m[i] > stk.top().first) { n       l[i] = l[i - 1] + m[i]; n     } else { n       while (!stk.empty() && m[i] < stk.top().first) { n         stk.pop(); n       } n       int ind = stk.top().second; n       long long prv; n       if (ind == -1) { n         prv = 0; n       } else { n         prv = l[ind]; n       } n       l[i] = prv + (i - ind) * m[i]; n     } n     stk.push(make_pair(m[i], i)); n   } n   while (!stk.empty()) { n     stk.pop(); n   }; n   reverse(m.begin(), m.end()); n   ; n   stk.push(make_pair(0, -1)); n   stk.push(make_pair(m[0], 0)); n   r[0] = m[0]; n   for (long long i = (long long)(1); i < (n); i++) { n     if (m[i] > stk.top().first) { n       r[i] = r[i - 1] + m[i]; n     } else { n       while (!stk.empty() && m[i] < stk.top().first) { n         stk.pop(); n       } n       int ind = stk.top().second; n       long long prv; n       if (ind == -1) { n         prv = 0; n       } else { n         prv = r[ind]; n       } n       r[i] = prv + (i - ind) * m[i]; n     } n     stk.push(make_pair(m[i], i)); n   }; n   reverse(m.begin(), m.end()); n   ; n   ; n   reverse(r.begin(), r.end()); n   ; n   int ind = 0; n   long long out = 0; n   long long temp; n   for (long long i = (long long)(0); i < (n); i++) { n     temp = l[i] + r[i] - m[i]; n     if (temp > out) { n       ind = i; n       out = temp; n     } n   } n   vector<long long> outt(n); n   outt[ind] = m[ind]; n   long long big = m[ind]; n   for (int i = ind - 1; i >= 0; i--) { n     if (m[i] < big) { n       big = m[i]; n     } n     outt[i] = big; n   } n   big = m[ind]; n   for (int i = ind + 1; i < n; i++) { n     if (m[i] < big) { n       big = m[i]; n     } n     outt[i] = big; n   } n   for (long long i = (long long)(0); i < (n); i++) { n     cout << outt[i] <<    ; n   } n } n


#include <bits/stdc++.h> n const int N = 2e3 + 9; n using namespace std; n int n, dp[5][N], a[N], b[5] = {0, 1, 2, 1, 2}; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   for (int i = 1; i <= 4; i++) { n     for (int j = 1; j <= n; j++) { n       dp[i][j] = max(dp[i - 1][j], dp[i][j - 1] + (a[j] == b[i])); n     } n   } n   printf( %d n , dp[4][n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, k; n   cin >> n >> k; n   int hash[201] = {0}; n   vector<pair<int, int>> v; n   for (int i = 0; i < n; i++) { n     int l, r; n     cin >> l >> r; n     v.push_back(make_pair(l, r)); n     for (int j = l; j < r + 1; j++) hash[j]++; n   } n   vector<int> ans(n); n   for (int j = 0; j < 250; j++) { n     while (hash[j] > k) { n       int m = -1; n       for (int i = 0; i < n; i++) { n         if (!ans[i] && (j >= v[i].first && j <= v[i].second)) { n           if (m == -1 || v[i].second > v[m].second) m = i; n         } n       } n       if (m == -1) break; n       for (int i = v[m].first; i < v[m].second + 1; i++) hash[i]--; n       ans[m] = 1; n     } n   } n   cout << accumulate(ans.begin(), ans.end(), 0) << endl; n   for (int i = 0; i < n; i++) n     if (ans[i]) cout << i + 1 <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, m; n   cin >> n >> m; n   long long int kmin = 0; n   long long int kmax = 0; n   long long int left; n   kmax = ((n - m + 1) * (n - m)) / 2; n   long long int j = n / m; n   left = n % m; n   kmin = (m - left) * ((j) * (j - 1) / 2) + left * ((j) * (j + 1) / 2); n   cout << kmin <<     << kmax << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     int row[n * m + 1], col[n * m + 1]; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         int a; n         cin >> a; n         col[a] = j; n       } n     } n     for (int j = 0; j < m; j++) { n       for (int i = 0; i < n; i++) { n         int a; n         cin >> a; n         row[a] = i; n       } n     } n     int ans[n][m]; n     for (int i = 1; i < n * m + 1; i++) { n       ans[row[i]][col[i]] = i; n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         cout << ans[i][j] <<    ; n       } n       cout << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int t, tr, br, b, bl, tl; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> t >> tr >> br >> b >> bl >> tl; n   long long ans = 0; n   int k = min(tr, tl); n   ans += (2 * t + k) * ((long long)k); n   ans += 2 * (max(tr, tl) - k) * (t + k); n   int a = min(bl, br); n   ans += (2 * b + a) * ((long long)a); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[100100]; n int main() { n   long long n; n   int q; n   scanf( %I64d%d , &n, &q); n   int k = 0; n   long long tmp = n + 1; n   while (tmp % 2 == 0) tmp /= 2, k++; n   while (q--) { n     long long st; n     scanf( %I64d , &st); n     cin >> str; n     int L = strlen(str); n     for (int i = 0; i < L; i++) { n       int t = 0; n       while (st % 2 == 0) t++, st /= 2; n       if (str[i] ==  U ) { n         if (t == k - 1) { n           st = (1ll << t); n           continue; n         } n         if (st % 4 == 3) n           st = (st - 1) * (1ll << t); n         else n           st = (st + 1) * (1ll << t); n       } else { n         if (t == 0) continue; n         t--; n         st *= 2; n         if (str[i] ==  L ) n           st = (st - 1) * (1ll << t); n         else n           st = (st + 1) * (1ll << t); n       } n     } n     printf( %I64d n , st); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> divisors(long long n) { n   vector<long long> ans; n   for (long long i = 2; i <= sqrt(n); i++) { n     if (n % i == 0) { n       ans.push_back(i); n       if (n / i != i) ans.push_back(n / i); n     } n   } n   ans.push_back(1); n   return ans; n } n void precision_print(long double n, long long p) { n   cout << fixed << setprecision(p) << n <<   n ; n   return; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long x1, p1, x2, p2; n     cin >> x1 >> p1 >> x2 >> p2; n     string temp = to_string(x1); n     long long a = ((long long)(temp).size()); n     temp = to_string(x2); n     long long b = ((long long)(temp).size()); n     if (a + p1 > b + p2) { n       cout <<  >  <<   n ; n       continue; n     } n     if (a + p1 < b + p2) { n       cout <<  <  <<   n ; n       continue; n     } n     if (p1 < p2) n       x2 *= pow(10, p2 - p1); n     else n       x1 *= pow(10, p1 - p2); n     if (x1 > x2) n       cout <<  > n ; n     else if (x1 == x2) n       cout <<  = n ; n     else n       cout <<  < n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n long long num[200005], rig[200005], lef[200005]; n int main() { n   scanf( %d%d%d , &n, &m, &k); n   long long tmp = 0; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &num[i]); n   } n   int t = 1; n   while (m--) t *= k; n   for (int i = 1; i <= n; ++i) { n     rig[i] = rig[i - 1] | num[i]; n   } n   for (int i = n; i >= 1; --i) { n     lef[i] = lef[i + 1] | num[i]; n   } n   for (int i = 1; i <= n; ++i) n     tmp = max(tmp, num[i] * t | rig[i - 1] | lef[i + 1]); n   printf( %I64d , tmp); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000 + 2, maxm = 1000 * 1000 + 2; n int n, m, q, parent[maxn], r[maxn], b[maxn]; n pair<pair<long long, int>, pair<int, int> > v[maxm]; n bool chek = false; n int par(int x) { n   if (x == parent[x]) return x; n   int y = par(parent[x]); n   b[x] += b[parent[x]]; n   b[x] %= 2; n   return parent[x] = y; n } n void merge(int x, int y) { n   int second = x, e = y; n   x = par(x); n   y = par(y); n   if (x == y) { n     if (b[second] == b[e]) chek = true; n     return; n   } n   if (r[x] < r[y]) { n     swap(x, y); n     swap(second, e); n   } n   r[x] += r[y]; n   parent[y] = x; n   b[y] = (b[e] + 1 + b[second]) % 2; n } n int main() { n   ios::sync_with_stdio(false); n   int x, y, second, e; n   long long z; n   cin >> n >> m >> q; n   for (int i = 0; i < m; i++) { n     cin >> x >> y >> z; n     x--; n     y--; n     v[i] = make_pair(make_pair(z, i + 1), make_pair(x, y)); n   } n   sort(v, v + m); n   reverse(v, v + m); n   for (int t = 0; t < q; t++) { n     chek = false; n     cin >> second >> e; n     for (int i = 0; i < n; i++) { n       parent[i] = i; n       r[i] = 1; n       b[i] = 0; n     } n     for (int i = 0; i < m; i++) n       if (v[i].first.second >= second && v[i].first.second <= e) { n         x = v[i].second.first; n         y = v[i].second.second; n         z = v[i].first.first; n         merge(x, y); n         if (chek == true) { n           cout << z << endl; n           break; n         } n       } n     if (chek == false) cout << -1 << endl; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int a, b; n vector<int> res; n int main() { n   scanf( %d%d , &a, &b); n   while (true) { n     res.push_back(b); n     if (b == a) break; n     if (b < a) { n       printf( NO ); n       return 0; n     } n     if (b % 2 == 0) n       b /= 2; n     else if (b % 10 == 1) n       b /= 10; n     else { n       printf( NO ); n       return 0; n     } n   } n   printf( YES n%u n , res.size()); n   while (!res.empty()) printf( %d  , res.back()), res.pop_back(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   long long n, k; n   cin >> n >> k; n   multiset<pair<long long, long long>> s; n   vector<tuple<long long, long long, long long>> v; n   long long i; n   for (i = 0; i < n; i++) { n     long long a, b, p; n     cin >> a >> b >> p; n     s.insert({(a * a + b * b), i}); n     v.push_back(make_tuple(a, b, p)); n   } n   if (k >= 1e6) { n     cout << 0.00000000 <<   n ; n     return 0; n   } n   long long f = -1; n   double ans; n   for (pair<long long, long long> x : s) { n     pair<long long, long long> pp = x; n     long long y = pp.second; n     k += get<2>(v[y]); n     f++; n     if (k >= 1e6) { n       double aa = get<0>(v[y]); n       double bb = get<1>(v[y]); n       ans = sqrt(aa * aa + bb * bb); n       break; n     } n   } n   if (k < 1e6) { n     cout <<  -1 n ; n     return 0; n   } n   std::cout << std::fixed; n   std::cout << std::setprecision(10); n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int P = 998244353, N = 3e5; n int n, L, C, r[N], A[N], B[N]; n int g[N], g0[N], g1[N], g2[N]; n int f0[N], f1[N], f2[N]; n int q0[N], q1[N]; n int t1[N], t2[N], t3[N], t4[N]; n inline void Add(int &x, int y) { n   x += y; n   if (x >= P) x -= P; n } n inline int Mul(int x, int y) { return 1ll * x * y % P; } n inline int fpow(int x, int k) { n   int s = 1; n   for (; k; k >>= 1, x = Mul(x, x)) n     if (k & 1) s = Mul(s, x); n   return s; n } n inline void NTT_prepare(int len) { n   for (L = 1, C = 0; L < len; L <<= 1, ++C) n     ; n   for (int i = 0; i < L; ++i) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (C - 1)); n } n void NTT(int *A, int op) { n   for (int i = 0; i < L; ++i) n     if (i < r[i]) swap(A[i], A[r[i]]); n   for (int i = 1; i < L; i <<= 1) { n     int Wn = fpow(3, (P - 1) / (i << 1)); n     if (op == -1) Wn = fpow(Wn, P - 2); n     for (int j = 0; j < L; j += i << 1) { n       int w = 1; n       for (int k = 0; k < i; ++k, w = Mul(w, Wn)) { n         int p = A[j + k], q = Mul(w, A[j + i + k]); n         A[j + k] = (p + q) % P; n         A[j + i + k] = ((p - q) % P + P) % P; n       } n     } n   } n   if (op == -1) { n     int inv_L = fpow(L, P - 2); n     for (int i = 0; i < L; ++i) A[i] = Mul(A[i], inv_L); n   } n } n void Convolve(int *a, int *b, int *C) { n   for (int i = 0; i < L / 2; ++i) A[i] = a[i]; n   for (int i = 0; i < L / 2; ++i) B[i] = b[i]; n   for (int i = L / 2; i < L; ++i) A[i] = B[i] = 0; n   NTT(A, 1); n   NTT(B, 1); n   for (int i = 0; i < L; ++i) C[i] = Mul(A[i], B[i]); n   NTT(C, -1); n } n void Solve_1(int l, int r) { n   if (l == r) { n     Add(f0[l], g0[l]); n     Add(f1[l], g1[l]); n     return; n   } n   int mid = (l + r) / 2; n   Solve_1(l, mid); n   NTT_prepare(2 * (r - l + 1)); n   for (int i = 0; i < L; ++i) q0[i] = (i + l <= mid ? f0[i + l] : 0); n   for (int i = 0; i < L; ++i) q1[i] = (i + l <= mid ? f1[i + l] : 0); n   Convolve(g0, q0, t1); n   Convolve(g1, q0, t2); n   Convolve(g1, q1, t3); n   Convolve(g2, q1, t4); n   for (int i = 0; i < L / 2; ++i) { n     if (mid + 1 <= i + l + 1 && i + l + 1 <= r) { n       Add(f0[i + l + 1], t1[i]); n       Add(f1[i + l + 1], t2[i]); n     } n     if (mid + 1 <= i + l + 3 && i + l + 3 <= r) { n       Add(f0[i + l + 3], t3[i]); n       Add(f1[i + l + 3], t4[i]); n     } n   } n   Solve_1(mid + 1, r); n } n void Solve_2(int l, int r) { n   if (l == r) { n     Add(f2[l], g2[l]); n     Add(f2[l], l >= 1 ? t1[l - 1] : 0); n     return; n   } n   int mid = (l + r) / 2; n   Solve_2(l, mid); n   NTT_prepare(2 * (r - l + 1)); n   for (int i = 0; i < L; ++i) q0[i] = (i + l <= mid ? f2[i + l] : 0); n   Convolve(g2, q0, t2); n   for (int i = 0; i < L / 2; ++i) { n     if (mid + 1 - 3 <= i + l && i + l <= r - 3) { n       Add(f2[i + l + 3], t2[i]); n     } n   } n   Solve_2(mid + 1, r); n } n int main() { n   scanf( %d , &n); n   g[0] = 1; n   g[2] = 1; n   for (int i = 4; i <= n; i += 2) g[i] = (g[i - 2] + g[i - 4]) % P; n   for (int i = 0; i <= n; ++i) { n     g0[i] = Mul(g[i], Mul(i, i)); n     g1[i] = Mul(g[i], Mul(i + 1, i + 1)); n     g2[i] = Mul(g[i], Mul(i + 2, i + 2)); n   } n   Solve_1(0, n); n   NTT_prepare(2 * n); n   Convolve(g1, f1, t1); n   Solve_2(0, n); n   int ans = Mul(Mul((g[n - 1] + g[n - 3]) % P, Mul(n - 1, n - 1)), n); n   for (int i = 2; i <= n - 2; ++i) { n     Add(ans, Mul(Mul(Mul(g[i - 1], Mul(i - 1, i - 1)), f0[n - i - 1]), i)); n     Add(ans, n         Mul(Mul(Mul(g[i - 2], Mul(i - 1, i - 1)), f1[n - i - 2]), Mul(2, i))); n     if (3 <= i && i <= n - 3) n       Add(ans, Mul(Mul(Mul(g[i - 3], Mul(i - 1, i - 1)), f2[n - i - 3]), i)); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n template <class T, class U> n inline void add_self(T &a, U b) { n   a += b; n   if (a >= mod) a -= mod; n   if (a < 0) a += mod; n } n template <class T, class U> n inline void min_self(T &x, U y) { n   if (y < x) x = y; n } n template <class T, class U> n inline void max_self(T &x, U y) { n   if (y > x) x = y; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   cout << t; n   ; n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n template <class T, class U> n void print_m(const map<T, U> &m, int w = 3) { n   if (m.empty()) { n     cout <<  Empty  << endl; n     return; n   } n   for (auto x : m) cout <<  (  << x.first <<  :   << x.second <<  ),  << endl; n   cout << endl; n } n template <class T, class U> n void debp(const pair<T, U> &pr, bool end_line = 1) { n   cout <<  {  << pr.first <<     << pr.second <<  } ; n   cout << (end_line ?   n  :  ,  ); n } n template <class T> n void print_vp(const T &vp, int sep_line = 0) { n   if (vp.empty()) { n     cout <<  Empty  << endl; n     return; n   } n   if (!sep_line) cout <<  {  ; n   for (auto x : vp) debp(x, sep_line); n   if (!sep_line) cout <<  } n ; n   cout << endl; n } n template <typename T> n void print(const T &v, bool show_index = false) { n   int w = 2; n   if (show_index) { n     for (int i = 0; i < int((v).size()); i++) cout << setw(w) << i <<    ; n     cout << endl; n   } n   for (auto &el : v) cout << setw(w) << el <<    ; n   cout << endl; n } n template <typename T> n void print_vv(const T &vv) { n   if (int((vv).size()) == 0) { n     cout <<  Empty  << endl; n     return; n   } n   int w = 3; n   cout << setw(w) <<    ; n   for (int j = 0; j < int((*vv.begin()).size()); j++) n     cout << setw(w) << j <<    ; n   cout << endl; n   int i = 0; n   for (auto &v : vv) { n     cout << i++ <<   { ; n     for (auto &el : v) cout << setw(w) << el <<    ; n     cout <<  }, n ; n   } n   cout << endl; n } n int n, t; n const int nax = 200; n vector<double> glass(nax); n void dfs(int g, int l) { n   if (l > n) return; n   if (glass[g] > 1) { n     double half = (glass[g] - 1) / 2; n     glass[g] = 1; n     int c1 = (g + l); n     int c2 = (g + l + 1); n     glass[c1] += half; n     glass[c2] += half; n     if (glass[c1] > 1) dfs(c1, l + 1); n     if (glass[c2] > 1) dfs(c2, l + 1); n   } n } n void bfs() { n   set<int> q; n   if (glass[1] > 1) q.insert(1); n   int l = 1; n   while (!q.empty()) { n     if (l > 10) break; n     set<int> nq; n     for (auto top : q) { n       double half = (glass[top] - 1) / 2; n       glass[top] = 1; n       int c1 = (top + l); n       int c2 = (top + l + 1); n       glass[c1] += half; n       glass[c2] += half; n       if (glass[c1] > 1) nq.insert(c1); n       if (glass[c2] > 1) nq.insert(c2); n     } n     q = nq; n     ++l; n   } n } n int main() { n   while (cin >> n >> t) { n     glass.clear(); n     glass.resize(nax); n     for (int i = 0; i < int(t); i++) { n       glass[1] += 1; n       bfs(); n     } n     int ed = (n * (n + 1)) / 2; n     int cnt = 0; n     for (int i = int(1); i < int(ed + 1); i++) n       if (glass[i] >= 1) ++cnt; n     cout << cnt << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const char nl =   n ; n const int MAX_N = 100011; n const long long INF = (1 << 29) + 123; n const long long MOD = 1000000007; n const long double PI = 4 * atan((long double)1); n template <typename T> n bool ckmin(T& a, const T& b) { n   return a > b ? a = b, 1 : 0; n } n template <typename T> n bool ckmax(T& a, const T& b) { n   return b > a ? a = b, 1 : 0; n } n void dbg_out() { cerr << endl; } n template <typename Head, typename... Tail> n void dbg_out(Head H, Tail... T) { n   cerr << H <<    ; n   dbg_out(T...); n } n mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); n const int MX = 1 << 20; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   int m = n; n   vector<int> LOC[n + 1]; n   int A[n]; n   for (int i = 0; i < n; i++) { n     cin >> A[i]; n     LOC[A[i]].push_back(i); n   } n   int hi = 0, best = -1; n   for (int i = 1; i <= m; i++) n     if (ckmax(hi, (int)LOC[i].size())) best = i; n   bool done = 0; n   for (int i = 1; i <= m; i++) n     if (i != best && hi == (int)LOC[i].size()) done = 1; n   if (done) { n     cout << n << nl; n     return 0; n   } n   n += 2; n   int a[n]; n   for (int i = 0; i < n - 2; i++) a[i + 1] = A[i]; n   a[0] = a[n - 1] = best; n   vector<int> loc[n + 1]; n   for (int i = 0; i < n; i++) loc[a[i]].push_back(i); n   hi = (int)loc[best].size(); n   int idxBest[n]; n   for (int i = 0; i < n; i++) n     if (i == 0) n       idxBest[i] = 1; n     else n       idxBest[i] = idxBest[i - 1] + (a[i] == best); n   int ans = 0; n   int SQRTN = sqrt(n) - 100; n   for (int i = 1; i <= m; i++) { n     int SZ = (int)loc[i].size(); n     if (i == best || !SZ) continue; n     if (SZ > SQRTN) { n       int j = 0, k = 0; n       int sum = 0; n       int firstLoc[2 * n + 1]; n       for (int ii = 0; ii < 2 * n + 1; ii++) firstLoc[ii] = -1; n       firstLoc[sum + n] = 0; n       while (j != hi - 1 || k != SZ) { n         int curPos; n         if (k < SZ && loc[best][j] > loc[i][k]) { n           curPos = loc[i][k] + 1; n           ckmax(ans, curPos - 1 - firstLoc[sum + n]); n           sum++; n           k++; n         } else { n           curPos = loc[best][j] + 1; n           ckmax(ans, curPos - 1 - firstLoc[sum + n]); n           sum--; n           j++; n         } n         if (firstLoc[sum + n] == -1) firstLoc[sum + n] = curPos; n       } n       ckmax(ans, loc[best][j] - firstLoc[sum + n]); n     } else { n       int kkk = 0; n       for (int kk = 0; kk < SZ; kk++) { n         int j = max(0, idxBest[loc[i][kk]] - SZ - 2); n         int jEnd = min(hi, idxBest[loc[i][kk]] + SZ + 2); n         while (kkk < SZ && loc[best][j] > loc[i][kkk]) kkk++; n         int k = kkk; n         int PAD = 2 * SZ + 5; n         int firstLoc[2 * PAD + 1]; n         for (int ii = 0; ii < 2 * PAD + 1; ii++) firstLoc[ii] = -1; n         int sum = -1; n         if (j == 0) firstLoc[0 + PAD] = 0; n         firstLoc[sum + PAD] = loc[best][j] + 1; n         j++; n         while (j < jEnd) { n           int curPos; n           if (k < SZ && loc[i][k] < loc[best][j]) { n             curPos = loc[i][k] + 1; n             ckmax(ans, loc[i][k] - firstLoc[sum + PAD]); n             sum++; n             k++; n           } else { n             curPos = loc[best][j] + 1; n             ckmax(ans, loc[best][j] - firstLoc[sum + PAD]); n             sum--; n             j++; n           } n           if (firstLoc[sum + PAD] == -1) firstLoc[sum + PAD] = curPos; n         } n         if (j != hi) ckmax(ans, loc[best][j] - firstLoc[sum + PAD]); n       } n     } n   } n   cout << ans << nl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, k, cnt = 0; n   scanf( %d %d %d , &n, &m, &k); n   int p[n], s[n], c[k]; n   for (int i = 0; i < n; i++) scanf( %d , &p[i]); n   for (int i = 0; i < n; i++) scanf( %d , &s[i]); n   for (int i = 0; i < k; i++) scanf( %d , &c[i]); n   for (int i = 0; i < k; i++) { n     int po = p[c[i] - 1]; n     int so = s[c[i] - 1]; n     for (int j = 0; j < n; j++) { n       if (p[j] > po && s[j] == so) { n         cnt++; n         break; n       } n     } n   } n   printf( %d n , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n]; n   int mx = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     mx = max(a[i], mx); n   } n   int cnt = 0; n   int maxcnt = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] == mx) n       cnt++; n     else { n       maxcnt = max(cnt, maxcnt); n       cnt = 0; n     } n     if (i == n - 1) { n       maxcnt = max(cnt, maxcnt); n     } n   } n   cout << maxcnt; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n = 0; n   int max = 0; n   int cur = 0; n   cin >> n; n   string students[n]; n   for (int i = 0; i < n; ++i) { n     cin >> students[i]; n   } n   for (int i = 0; i < 7; ++i) { n     cur = 0; n     for (int j = 0; j < n; ++j) { n       if (students[j][i] ==  1 ) { n         cur++; n       } n     } n     if (cur > max) { n       max = cur; n     } n   } n   cout << max; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int rd(); n int gcd(int a, int b) { return a == 0 ? b : gcd(b % a, a); } n int J(int x) { n   int sum = 0; n   for (int i = 1; i * i <= x; ++i) { n     if (x % i == 0 && gcd(i, x / i) == 1) { n       sum += i; n       sum += x / i; n     } n   } n   return sum; n } n const int N = 1000007; n int n, cnt, pr[N], lp[N]; n void sieve() { n   for (int i = 2; i < N; ++i) { n     if (lp[i] == 0) { n       lp[i] = i; n       pr[cnt++] = i; n     } n     for (int j = 0; j < cnt && pr[j] <= lp[i] && pr[j] * i < N; ++j) { n       lp[i * pr[j]] = pr[j]; n     } n   } n } n long long getp(long long d) { n   --d; n   for (int i = 0; i < cnt && (long long)pr[i] * pr[i] <= d; ++i) { n     if (d % pr[i] == 0) { n       while (d % pr[i] == 0) d /= pr[i]; n       if (d == 1) return pr[i]; n       return -1; n     } n   } n   return d; n } n vector<pair<long long, long long> > mas; n long long ans; n bool used[N]; n void rec(int ptr, long long rem) { n   if (rem == 1) { n     ++ans; n     return; n   } n   if (ptr == (int)(mas).size()) return; n   if (rem % mas[ptr].first == 0 && !used[mas[ptr].second]) { n     used[mas[ptr].second] = true; n     rec(ptr + 1, rem / mas[ptr].first); n     used[mas[ptr].second] = false; n   } n   rec(ptr + 1, rem); n } n void solve() { n   sieve(); n   long long x; n   cin >> x; n   vector<long long> divs; n   for (int i = 1; (long long)i * i <= x; ++i) { n     if (x % i == 0) { n       if (i != 1) divs.push_back(i); n       if (i * i != x) divs.push_back(x / i); n     } n   } n   sort((divs).begin(), (divs).end()); n   vector<long long> pp; n   for (long long d : divs) { n     long long p = getp(d); n     if (p == -1 || p == 1) continue; n     mas.push_back(make_pair(d, p)); n     pp.push_back(p); n   } n   sort((mas).begin(), (mas).end()); n   reverse((mas).begin(), (mas).end()); n   sort((pp).begin(), (pp).end()); n   for (int i = 0; i < ((int)(mas).size()); ++i) n     mas[i].second = n         lower_bound((pp).begin(), (pp).end(), mas[i].second) - pp.begin(); n   rec(0, x); n   cout << ans << endl; n } n int rd() { return (((long long)rand() << 16) ^ rand()) % 1000000000; } n void testGen() { n   FILE *f = fopen( input.txt ,  w ); n   fclose(f); n } n int main() { n   cerr << fixed; n   cerr.precision(9); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200010; n const long long mod = 1000000007ll; n int n, cnt; n long long ans = 1; n int to[N], vis[N], dep[N]; n long long power(long long x, long long t) { n   long long ret = 1; n   for (; t; t >>= 1ll, x = x * x % mod) n     if (t & 1ll) ret = ret * x % mod; n   return ret; n } n void dfs(int u, int step, int d) { n   vis[u] = d; n   dep[u] = step; n   if (!vis[to[u]]) n     dfs(to[u], step + 1, d); n   else if (vis[to[u]] == vis[u]) { n     ans = ans * (power(2, dep[u] - dep[to[u]] + 1) - 2) % mod; n     cnt += dep[u] - dep[to[u]] + 1; n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &to[i]); n   for (int i = 1; i <= n; ++i) n     if (!vis[i]) dfs(i, 0, i); n   ans = ans * power(2, n - cnt) % mod; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2001; n const int INF = 1e9 + 1; n struct T { n   int u, f, w, num; n   T(int u, int f, int w, int num) : u(u), f(f), w(w), num(num){}; n   T(){}; n }; n vector<T> G[N]; n int n, m, s, t; n bool used[N]; n bool ist[N]; n int parent[N]; n pair<int, pair<int, int> > ans; n pair<int, int> mn; n int Time = 0; n int tin[N]; n int fin[N]; n void dfs(int v) { n   used[v] = true; n   for (int i = 0; i < G[v].size(); ++i) { n     int to = G[v][i].u; n     if (used[to] == false && G[v][i].f == 1) { n       parent[to] = v; n       dfs(to); n     } n   } n } n vector<int> getPath(int s, int t) { n   memset(used, false, sizeof(used)); n   vector<int> ans; n   dfs(s); n   if (used[t] == false) return ans; n   int v = t; n   while (v != s) { n     ans.push_back(v); n     v = parent[v]; n   } n   ans.push_back(v); n   return ans; n } n void DeleteEdge(int v, int u, int& num) { n   for (int i = 0; i < G[v].size(); ++i) { n     if (G[v][i].u == u) { n       G[v][i].f = 0; n       num = i; n       break; n     } n   } n   for (int i = 0; i < G[u].size(); ++i) { n     if (G[u][i].u == v) { n       G[u][i].f = 0; n       break; n     } n   } n } n void AddEdge(int v, int u) { n   for (int i = 0; i < G[v].size(); ++i) { n     if (G[v][i].u == u) { n       G[v][i].f = 1; n       break; n     } n   } n   for (int i = 0; i < G[u].size(); ++i) { n     if (G[u][i].u == v) { n       G[u][i].f = 1; n       break; n     } n   } n } n void update(int weight, pair<int, int> num) { n   if (ans.first == -1 || weight < ans.first) { n     ans.first = weight; n     ans.second = num; n   } n } n void findMinBridge(int v, int num) { n   if (v == t) ist[v] = true; n   used[v] = true; n   Time++; n   tin[v] = Time; n   fin[v] = Time; n   for (int i = 0; i < G[v].size(); ++i) { n     int to = G[v][i].u; n     if (G[v][i].num == num || G[v][i].f == 0) continue; n     if (used[to] == true) { n       fin[v] = min(fin[v], tin[to]); n     } else { n       findMinBridge(to, G[v][i].num); n       ist[v] |= ist[to]; n       fin[v] = min(fin[v], fin[to]); n       if (fin[to] > tin[v] && ist[to] == true) { n         if (mn.first > G[v][i].w) { n           mn.first = G[v][i].w; n           mn.second = G[v][i].num; n         } n       } n     } n   } n } n int main() { n   ans.first = -1; n   scanf( %d%d%d%d , &n, &m, &s, &t); n   s--; n   t--; n   for (int i = 0; i < m; ++i) { n     int u, v, w; n     scanf( %d%d%d , &u, &v, &w); n     u--; n     v--; n     G[u].push_back(T(v, 1, w, i)); n     G[v].push_back(T(u, 1, w, i)); n   } n   vector<int> path = getPath(s, t); n   if (path.size() == 0) { n     printf( 0 n0 n ); n     return 0; n   } n   for (int i = (int)path.size() - 1; i > 0; --i) { n     int num; n     DeleteEdge(path[i], path[i - 1], num); n     vector<int> tmp = getPath(s, t); n     if (tmp.size() == 0) { n       update(G[path[i]][num].w, make_pair(G[path[i]][num].num, -1)); n     } else { n       memset(used, false, sizeof(used)); n       memset(ist, false, sizeof(ist)); n       mn.first = INF; n       Time = 0; n       findMinBridge(s, -1); n       if (mn.first != INF) n         update(G[path[i]][num].w + mn.first, n                make_pair(G[path[i]][num].num, mn.second)); n     } n     AddEdge(path[i], path[i - 1]); n   } n   if (ans.first == -1) { n     printf( -1 n ); n     return 0; n   } n   printf( %d n , ans.first); n   if (ans.second.second == -1) { n     printf( 1 n%d , ans.second.first + 1); n   } else { n     printf( 2 n%d %d n , ans.second.first + 1, ans.second.second + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int flow; n   int next; n   int inv; n   int cap; n   int cost; n }; n const int N = 1100000; n vector<edge> v[N]; n int d[N]; n int phi[N]; n int from[N]; n bool vis[N]; n void add_edge(int x1, int x2, int x3, int x4) { n   edge x; n   x.next = x2; n   x.cost = x4; n   x.cap = x3; n   x.flow = 0; n   x.inv = v[x2].size(); n   v[x1].push_back(x); n   x.next = x1; n   x.cost = -x4; n   x.cap = 0; n   x.flow = 0; n   x.inv = v[x1].size() - 1; n   v[x2].push_back(x); n } n const int inf = (int)1e9; n void init() { n   for (int i = 0; i < N; i++) { n     phi[i] = 0; n     v[i].clear(); n   } n } n void bfs(int n) { n   for (int i = 0; i < n; i++) vis[i] = false; n   queue<int> q; n   q.push(0); n   vis[0] = true; n   while (!q.empty()) { n     int x = q.front(); n     q.pop(); n     for (int i = 0; i < v[x].size(); i++) n       if (!vis[v[x][i].next] && v[x][i].cap > v[x][i].flow) { n         vis[v[x][i].next] = true; n         from[v[x][i].next] = v[x][i].inv; n         q.push(v[x][i].next); n       } n   } n } n void dijkstra(int n) { n   for (int i = 0; i < n; i++) { n     d[i] = inf; n     vis[i] = false; n   } n   for (int i = 0; i < n; i++) vis[i] = false; n   set<pair<int, int> > q; n   d[0] = 0; n   for (int i = 1; i < n; i++) { n     d[i] = inf; n     q.insert(make_pair(d[i], i)); n   } n   q.insert(make_pair(0, 0)); n   while (!q.empty()) { n     int x = q.begin()->second; n     vis[x] = true; n     q.erase(q.begin()); n     if (d[x] == inf) break; n     for (int i = 0; i < v[x].size(); i++) n       if (!vis[v[x][i].next] && v[x][i].cap > v[x][i].flow) { n         int to = v[x][i].next; n         if (d[to] > d[x] + v[x][i].cost + phi[x] - phi[to]) { n           q.erase(make_pair(d[to], to)); n           d[to] = d[x] + v[x][i].cost + phi[x] - phi[to]; n           from[to] = v[x][i].inv; n           q.insert(make_pair(d[to], to)); n         } n       } n   } n } n int id[N]; n void fuckin_levit(int n) { n   for (int i = 0; i < n; i++) { n     d[i] = inf; n     id[i] = 0; n   } n   d[0] = 0; n   deque<int> q; n   q.push_back(0); n   while (!q.empty()) { n     int x = q.front(); n     q.pop_front(); n     vis[x] = true; n     if (d[x] == inf) break; n     id[x] = 1; n     for (int i = 0; i < v[x].size(); i++) n       if (v[x][i].cap - v[x][i].flow > 0) { n         int to = v[x][i].next; n         int len = v[x][i].cost; n         if (d[to] > d[x] + len) { n           d[to] = d[x] + len; n           if (id[to] == 0) n             q.push_front(to); n           else if (id[to] == 1) n             q.push_back(to); n           from[to] = v[x][i].inv; n           id[to] = 1; n         } n       } n   } n } n pair<int, int> maxflow(int n, int mode) { n   int res_flow = 0; n   int res_cost = 0; n   while (true) { n     if (mode == 1) dijkstra(n); n     if (mode == 0) bfs(n); n     if (mode == 2) fuckin_levit(n); n     if (!vis[n - 1]) break; n     if (d[n - 1] == inf) break; n     if (mode == 1) { n       for (int i = 0; i < n - 1; i++) phi[i] += vis[i] ? d[i] : d[n - 1]; n     } n     int x = n - 1; n     int dflow = inf; n     int dcost = 0; n     while (x != 0) { n       int a = v[x][from[x]].next; n       int b = v[x][from[x]].inv; n       dflow = min(dflow, v[a][b].cap - v[a][b].flow); n       dcost += v[a][b].cost; n       x = a; n     } n     x = n - 1; n     while (x != 0) { n       int a = v[x][from[x]].next; n       int b = v[x][from[x]].inv; n       v[a][b].flow += dflow; n       v[x][from[x]].flow -= dflow; n       x = a; n     } n     res_flow += dflow; n     res_cost += dflow * dcost; n   } n   return make_pair(res_flow, res_cost); n } n int a[100][100]; n vector<pair<int, int> > v1; n vector<pair<int, int> > v2; n int main() { n   cin.sync_with_stdio(false); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   init(); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       cin >> a[i][j]; n       if (((i + j) % 2) == 0) n         v1.push_back(make_pair(i, j)); n       else n         v2.push_back(make_pair(i, j)); n     } n   for (int i = 0; i < v2.size(); i++) n     add_edge(i + v1.size() + 1, n * m + 1, 1, 0); n   for (int i = 0; i < n * m / 2; i++) add_edge(0, i + 1, 1, 0); n   for (int i = 0; i < v1.size(); i++) n     for (int j = 0; j < v2.size(); j++) { n       int cost = 1; n       if (a[v1[i].first][v1[i].second] == a[v2[j].first][v2[j].second]) n         cost = 0; n       if ((abs(v1[i].first - v2[j].first) + abs(v1[i].second - v2[j].second)) == n           1) n         if (cost == 0) add_edge(i + 1, j + v1.size() + 1, 1, cost); n     } n   maxflow(n * m + 2, 0); n   for (int i = 0; i < v1.size(); i++) n     for (int j = 0; j < v2.size(); j++) { n       int cost = 1; n       if (a[v1[i].first][v1[i].second] == a[v2[j].first][v2[j].second]) n         cost = 0; n       if ((abs(v1[i].first - v2[j].first) + abs(v1[i].second - v2[j].second)) == n           1) n         if (cost == 1) add_edge(i + 1, j + v1.size() + 1, 1, cost); n     } n   pair<int, int> res = maxflow(n * m + 2, 2); n   cout << res.second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int get(int x) { n   int t = log2(x); n   if ((1 << t) < x) t++; n   return (1 << t) - x; n } n unordered_map<int, int> to, pos; n unordered_map<int, vector<pair<pair<int, int>, int> > > mp; n int a[200005]; n pair<pair<int, int>, int> num[200005]; n int len = 0; n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   int ans = 0, a1 = 0, a2 = 0; n   for (int i = 1; i <= n; i++) cin >> a[i], pos[a[i]] = i; n   sort(a + 1, a + n + 1, greater<int>()); n   for (int i = 1; i <= n; i++) { n     int x = a[i]; n     int cnt = 0; n     while (x) { n       int t = get(x); n       cnt++; n       mp[t].emplace_back(make_pair(make_pair(cnt, x), pos[a[i]])); n       to[x] = t; n       if (pos.count(t)) { n         if (cnt > ans) { n           ans = cnt; n           a1 = pos[a[i]]; n           a2 = pos[t]; n         } n       } n       x = t; n     } n   } n   for (auto u : mp) { n     len = 0; n     for (auto tu : u.second) { n       num[++len] = tu; n     } n     sort(num + 1, num + len + 1); n     pair<pair<int, int>, int> now = num[len]; n     while (len && num[len].first.second == now.first.second) len--; n     if (len) { n       pair<pair<int, int>, int> p2 = num[len]; n       if (now.first.first + p2.first.first > ans) { n         ans = now.first.first + p2.first.first; n         a1 = now.second; n         a2 = p2.second; n       } n     } n   } n   cout << a1 <<     << a2 <<     << ans; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n template <class T> n using vec = std::vector<T>; n bool __hack = std::ios::sync_with_stdio(false); n auto __hack1 = cin.tie(nullptr); n struct Input { n   Input(istream &in) : in(&in) {} n   template <class T> n   T next() const { n     T x; n     *in >> x; n     return x; n   } n   int ni() const { return next<int>(); } n   istream *in; n }; n Input in(cin); n class Output { n  private: n   ostream *out; n   template <typename T> n   void printSingle(const T &value) { n     *out << value; n   } n  n  public: n   Output(ostream &out) : out(&out) {} n   inline void setPrecision(int d) { *out << fixed << setprecision(d); } n   inline void print() {} n   template <typename T, typename... Ts> n   inline void print(const T &f, const Ts &...args) { n     printSingle(f); n     if (sizeof...(args) != 0) { n       *out <<    ; n       print(args...); n     } n   } n   template <typename... Ts> n   inline void println(const Ts &...args) { n     print(args...); n     (*out) <<   n ; n   } n   template <typename... Ts> n   inline void operator()(const Ts &...args) { n     println(args...); n   } n }; n Output out(cout); n namespace template_util { n constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; } n template <int N> n struct bytetype {}; n template <uint64_t N> n struct minimal_uint : bytetype<bytecount(N)> {}; n }  // namespace template_util n double EPS = 1e-10; n bool doubleEqual(double a, double b) { return fabs(a - b) < EPS; } n void solveOne() { n   auto n = in.ni(); n   auto len = in.ni(); n   vec<int> a(n + 2); n   a[0] = 0; n   a[n + 1] = len; n   for (int i = (1); i <= (n); ++i) a[i] = in.ni(); n   int i = 0, j = n + 1; n   double t = 0; n   int s1 = 1, s2 = 1; n   double x1 = 0, x2 = len; n   out.setPrecision(15); n   while (i + 1 < j) { n     double d1 = a[i + 1] - x1; n     double t1 = d1 / s1; n     double d2 = x2 - a[j - 1]; n     double t2 = d2 / s2; n     if (doubleEqual(t1, t2)) { n       t += t1; n       ++s1; n       ++s2; n       ++i; n       --j; n       x1 = a[i]; n       x2 = a[j]; n       if (i == j) { n         out(t); n         return; n       } n     } else if (t1 < t2) { n       t += t1; n       ++s1; n       ++i; n       x1 = a[i]; n       x2 -= t1 * s2; n     } else { n       t += t2; n       ++s2; n       --j; n       x2 = a[j]; n       x1 += t2 * s1; n     } n   } n   double d = x2 - x1; n   double s = s1 + s2; n   t += d / s; n   out(t); n } n void solve(istream &inStream, ostream &outStream) { n   in = Input(inStream); n   out = Output(outStream); n   auto tests = in.ni(); n   while (tests--) { n     solveOne(); n   } n } n int main() { n   solve(cin, cout); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC optimize( unroll-loops ) n #pragma comment(linker,  /STACK:2000000 ) n using namespace std; n template <int D, typename T> n struct Vec : public vector<Vec<D - 1, T>> { n   static_assert(D >= 1,  Vector dimension must be greater than zero! ); n   template <typename... Args> n   Vec(int n = 0, Args... args) n       : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {} n }; n template <typename T> n struct Vec<1, T> : public vector<T> { n   Vec(int n = 0, T val = T()) : vector<T>(n, val) {} n }; n using ll = long long; n using db = long double; n using ii = pair<int, int>; n const int N = 2e5 + 5, LG = 19, MOD = 998244353; n const int SQ = 320; n const long double EPS = 1e-7; n void printCase(int cs) { cout <<  Case #  << cs <<  :  ; } n int n; n vector<ii> arr; n int mx[3005][3005]; n void read() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     arr.push_back(ii(x, i)); n   } n   sort(arr.rbegin(), arr.rend()); n   arr.push_back(ii(0, n)); n } n int getVal(int i) { return arr[i].first - arr[i + 1].first; } n void initMax() { n   for (int i = 0; i < n; i++) { n     mx[i][i] = i; n     for (int j = i + 1; j < n; j++) { n       mx[i][j] = mx[i][j - 1]; n       if (getVal(j) > getVal(mx[i][j])) { n         mx[i][j] = j; n       } n     } n   } n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   read(); n   initMax(); n   vector<int> ans(6, INT_MIN); n   for (int i = 1; i < n; i++) n     for (int j = i; j < n; j++) n       if (i <= (j - i + 1) * 2 && i * 2 >= (j - i + 1)) { n         int mn = min(j - i + 1, i); n         int mx = max(j - i + 1, i); n         int r = mn * 2; n         int l = (mx + 1) / 2; n         if (j + l < n) { n           int k = ::mx[j + l][min(n - 1, j + r)]; n           vector<int> v({getVal(i - 1), getVal(j), getVal(k), i, j + 1, k + 1}); n           ans = max(ans, v); n         } n       } n   vector<int> out(n, -1); n   for (int i = 0; i < ans[3]; i++) out[arr[i].second] = 1; n   for (int i = ans[3]; i < ans[4]; i++) out[arr[i].second] = 2; n   for (int i = ans[4]; i < ans[5]; i++) out[arr[i].second] = 3; n   for (int i = 0; i < n; i++) cout << out[i] <<    n [i + 1 == n]; n   return 0; n } n


#include <bits/stdc++.h> n int max(int a, int b) { n   if (a > b) n     return a; n   else n     return b; n } n int main() { n   int n, m, p, r, x, y, c, i, j, zb, maxz; n   int max1, max2, max3, max4, minz; n   scanf( %d %d , &n, &m); n   scanf( %d , &c); n   for (i = 1; i <= c; i++) { n     scanf( %d %d , &x, &y); n     if (i == 1) max1 = x + y, max2 = x - y, max3 = -x + y, max4 = -x - y; n     if (i > 1 && x + y > max1) max1 = x + y; n     if (i > 1 && x - y > max2) max2 = x - y; n     if (i > 1 && -x + y > max3) max3 = -x + y; n     if (i > 1 && -x - y > max4) max4 = -x - y; n   } n   scanf( %d , &r); n   for (i = 1; i <= r; i++) { n     scanf( %d %d , &x, &y); n     maxz = max(max1 - (x + y), max2 - (x - y)); n     maxz = max(maxz, max3 - (-x + y)); n     maxz = max(maxz, max4 - (-x - y)); n     if (i == 1) minz = maxz, zb = 1; n     if (i > 1 && maxz < minz) minz = maxz, zb = i; n   } n   printf( %d n , minz); n   printf( %d n , zb); n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> g; n vector<vector<pair<long long, int> > > vec; n const int MAXN = 100010; n pair<long long, int> msum[MAXN][2]; n bool cmp2(pair<long long, int> a, pair<long long, int> b) { n   return b.first < a.first; n } n int main() { n   int n, c, s; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d %d , &c, &s); n     if (g.find(c) == g.end()) { n       g[c] = vec.size(); n       vec.push_back(vector<pair<long long, int> >()); n     } n     int id = g[c]; n     vec[id].push_back(make_pair(s, i + 1)); n   } n   int len = 0; n   for (int i = 0; i < vec.size(); ++i) { n     sort(vec[i].begin(), vec[i].end(), cmp2); n     len = max(len, (int)vec[i].size()); n     for (int j = 0; j < vec[i].size(); ++j) { n       if (j != 0) vec[i][j].first += vec[i][j - 1].first; n       if (vec[i][j].first >= msum[j][0].first) { n         msum[j][1] = msum[j][0]; n         msum[j][0].first = vec[i][j].first; n         msum[j][0].second = i; n       } else if (vec[i][j].first > msum[j][1].first) { n         msum[j][1].first = vec[i][j].first; n         msum[j][1].second = i; n       } n     } n   } n   long long ans = 0; n   int fc = -1, fl, sc, sl; n   for (int i = 0; i < len; ++i) { n     if (msum[i][0].first == 0) continue; n     if (msum[i][1].first != 0) { n       if (msum[i][0].first + msum[i][1].first > ans) { n         ans = msum[i][0].first + msum[i][1].first; n         fc = msum[i][0].second, fl = i + 1; n         sc = msum[i][1].second, sl = i + 1; n       } n     } n     if (i + 1 == len || msum[i + 1][0].first == 0) continue; n     if (msum[i + 1][0].second != msum[i][0].second) { n       if (msum[i][0].first + msum[i + 1][0].first > ans) { n         ans = msum[i][0].first + msum[i + 1][0].first; n         fc = msum[i][0].second, fl = i + 1; n         sc = msum[i + 1][0].second, sl = i + 2; n       } n     } else { n       if (msum[i][1].first != 0 && n           msum[i][1].first + msum[i + 1][0].first > ans) { n         ans = msum[i][1].first + msum[i + 1][0].first; n         fc = msum[i][1].second, fl = i + 1; n         sc = msum[i + 1][0].second, sl = i + 2; n       } n       if (msum[i + 1][1].first != 0 && n           msum[i][0].first + msum[i + 1][1].first > ans) { n         ans = msum[i][0].first + msum[i + 1][1].first; n         fc = msum[i][0].second, fl = i + 1; n         sc = msum[i + 1][1].second, sl = i + 2; n       } n     } n   } n   cout << ans << endl; n   if (fc != -1) { n     cout << fl + sl << endl; n     for (int i = 0; i < fl; ++i) { n       if (i) putchar(   ); n       printf( %d %d , vec[sc][i].second, vec[fc][i].second); n     } n     if (sl != fl) { n       printf(  %d , vec[sc][fl].second); n     } n     puts(  ); n   } else { n     cout << 0 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int c[N], ctr[N] = {0}; n vector<pair<int, int> > candidates, edges; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i < n; ++i) { n     int u, v; n     cin >> u >> v; n     edges.push_back({u, v}); n   } n   for (int i = 1; i <= n; ++i) cin >> c[i]; n   for (auto &i : edges) { n     if (c[i.first] != c[i.second]) candidates.push_back(i); n   } n   if (candidates.empty()) { n     cout <<  YES n1 ; n     return 0; n   } n   int m = candidates.size(); n   for (auto &i : candidates) { n     ctr[i.first]++; n     ctr[i.second]++; n   } n   for (int i = 1; i <= n; ++i) { n     if (ctr[i] == m) { n       cout <<  YES n  << i; n       return 0; n     } n   } n   cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n string s1, s2; n set<char> st; n vector<int> t[300]; n int bin_search(char k, int ind) { n   int l = 0, r = t[k].size() - 1, m; n   while (l < r) { n     m = (l + r) / 2; n     if (ind == t[k][m]) return t[k][m]; n     if (ind < t[k][m]) n       r = m; n     else n       l = m + 1; n   } n   if (l && t[k][l - 1] == ind) return t[k][l - 1]; n   return t[k][l]; n } n int main() { n   cin >> s1 >> s2; n   for (int i = 0; i < s1.size(); i++) t[s1[i]].push_back(i); n   for (int j = 0; j < s2.size(); j++) n     if (!t[s2[j]].size()) { n       cout <<  -1 ; n       return 0; n     } n   int ans = 1, j = 0; n   for (int i = 0; i < s2.size(); i++) { n     int p = bin_search(s2[i], j); n     if (p < j) { n       ans++; n       j = bin_search(s2[i], 0) + 1; n     } else { n       j = p + 1; n     } n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 300; n int main() { n   string s; n   int h; n   cin >> h; n   cin >> s; n   int ans = s.size(); n   for (int i = 1; s[i]; i++) { n     if ((s[i] ==  U  && s[i - 1] ==  R ) || (s[i] ==  R  && s[i - 1] ==  U )) { n       s[i] =  p ; n       --ans; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 300010; n vector<long long> arr[MAXN]; n vector<pair<long long, long long>> holdqs[MAXN]; n bool visited[MAXN]; n long long answer[MAXN]; n long long temp[MAXN]; n long long n; n void dfs(long long curr, long long par, long long level, long long ans) { n   for (auto x : holdqs[curr]) { n     long long lb = level; n     long long rb = level + 1 + x.first; n     temp[lb] += x.second; n     if (rb <= n) { n       temp[rb] -= x.second; n     } n   } n   ans += temp[level]; n   answer[curr] = ans; n   for (auto x : arr[curr]) { n     if (x != par) { n       dfs(x, curr, level + 1, ans); n     } n   } n   for (auto x : holdqs[curr]) { n     long long lb = level; n     long long rb = level + 1 + x.first; n     temp[lb] -= x.second; n     if (rb <= n) { n       temp[rb] += x.second; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   for (long long i = 1; i < n; i++) { n     long long x, y; n     cin >> x >> y; n     arr[x].push_back(y); n     arr[y].push_back(x); n   } n   long long q; n   cin >> q; n   while (q--) { n     long long v, d, x; n     cin >> v >> d >> x; n     holdqs[v].push_back(make_pair(d, x)); n   } n   dfs(1, 1, 1, 0); n   for (long long i = 1; i <= n; i++) { n     std::cout << answer[i] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n char a[25][25]; n int dp[40][1 << 20], n; n bool vis[40][1 << 20]; n int f(int xx, int st) { n   if (vis[xx][st]) return dp[xx][st]; n   int &res = dp[xx][st]; n   vis[xx][st] = true; n   if (xx == n * 2 - 2) { n     res = 0; n   } else { n     if (xx & 1) n       res = -0x3f3f3f3f; n     else n       res = 0x3f3f3f3f; n     int mask[30]; n     memset(mask, 0, sizeof(mask)); n     int cnt = 0; n     for (int j = 0; j <= xx + 1; ++j) { n       int x = xx + 1 - j; n       int y = j; n       if (x >= n || y >= n) continue; n       mask[a[x][y] -  a ] |= (1 << cnt); n       cnt++; n     } n     for (int i = 0; i < 26; ++i) { n       if (mask[i]) { n         int xt; n         if (xx + 1 < n) n           xt = (st | (st << 1)) & mask[i]; n         else n           xt = (st | (st >> 1)) & mask[i]; n         if (xt == 0) continue; n         int tmp = 0; n         if (i == 0) n           tmp = 1; n         else if (i == 1) n           tmp = -1; n         if (xx & 1) n           res = max(res, tmp + f(xx + 1, xt)); n         else n           res = min(res, tmp + f(xx + 1, xt)); n       } n     } n   } n   if (xx == 0) { n     if (a[0][0] ==  a ) n       res += 1; n     else if (a[0][0] ==  b ) n       res -= 1; n   } n   return res; n } n int main() { n   while (~scanf( %d , &n)) { n     for (int i = 0; i < n; ++i) scanf( %s , a[i]); n     memset(vis, 0, sizeof(vis)); n     int res = f(0, 1); n     if (res == 0) n       printf( DRAW n ); n     else if (res > 0) n       printf( FIRST n ); n     else n       printf( SECOND n ); n   } n   return 0; n } n