#include <bits/stdc++.h> n using namespace std; n int n, a, b; n vector<pair<int, int> > x[255][4005]; n int main() { n   scanf( %d n , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d %d n , &a, &b); n     x[a / 4000][b / 250].push_back(make_pair(a, i + 1)); n   } n   for (int i = 0; i < 252; i++) { n     for (int j = 0; j < 4002; j++) n       if (!x[i][j].empty()) { n         sort(x[i][j].begin(), x[i][j].end()); n         for (size_t k = 0; k < x[i][j].size(); k++) n           printf( %d  , x[i][j][k].second); n       } n     i++; n     for (int j = 4001; j >= 0; j--) n       if (!x[i][j].empty()) { n         sort(x[i][j].begin(), x[i][j].end()); n         for (size_t k = 0; k < x[i][j].size(); k++) n           printf( %d  , x[i][j][k].second); n       } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k; n   cin >> k; n   vector<vector<int> > v = {{1}}; n   for (int i = 0; i < k; i++) { n     int current = v.size(); n     for (int j = 0; j < current; j++) { n       vector<int> vnew(2 * current); n       for (int l = 0; l < current; l++) { n         vnew[l] = v[j][l]; n         vnew[current + l] = v[j][l]; n         v[j].push_back(-v[j][l]); n       } n       v.push_back(vnew); n     } n   } n   for (int i = 0; i < v.size(); i++) { n     for (int j = 0; j < v[i].size(); j++) { n       cout << ((v[i][j] == 1) ?  +  :  * ); n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   cout << --n / 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace IO { n template <typename t> n inline void read(t& x) { n   x = 0; n   bool f = 1; n   char ch; n   for (ch = getchar(); ch <  0  ||  9  < ch; ch = getchar()) n     if (ch ==  - ) f ^= 1; n   for (;  0  <= ch && ch <=  9 ; ch = getchar()) n     x = (x << 3) + (x << 1) + (ch ^ 48); n   x = f ? x : -x; n } n }  // namespace IO n const int MAXN = 50 + 10; n const int CHAR_RANGE = 26 + 10; n int n, len[2], f[MAXN][MAXN]; n bool can[2][MAXN][MAXN][CHAR_RANGE]; n char str[2][MAXN], tmp[10]; n vector<int> trans[CHAR_RANGE], rtrans[CHAR_RANGE * CHAR_RANGE + 100]; n void calc(int _) { n   for (int i = (1), iend = (len[_]); i <= iend; ++i) n     can[_][i][i][str[_][i] -  a ] = true; n   for (int l = (2), lend = (len[_]); l <= lend; ++l) { n     for (int i = (1), iend = (len[_] - l + 1); i <= iend; ++i) { n       int j = i + l - 1; n       for (int k = (i), kend = (j - 1); k <= kend; ++k) n         for (int ch1 = (0), ch1end = (25); ch1 <= ch1end; ++ch1) n           if (can[_][i][k][ch1]) n             for (int ch2 = (0), ch2end = (25); ch2 <= ch2end; ++ch2) { n               if (can[_][k + 1][j][ch2]) { n                 for (int x : rtrans[26 * ch1 + ch2]) can[_][i][j][x] = true; n               } n             } n     } n   } n } n int main() { n   scanf( %s , str[0] + 1), scanf( %s , str[1] + 1); n   len[0] = strlen(str[0] + 1), len[1] = strlen(str[1] + 1); n   IO::read(n); n   for (int i = (1), iend = (n); i <= iend; ++i) { n     scanf( %s , tmp + 1); n     rtrans[26 * (tmp[4] -  a ) + tmp[5] -  a ].push_back(tmp[1] -  a ); n   } n   memset(f, -1, sizeof f); n   f[0][0] = 0; n   calc(0), calc(1); n   for (int i = (1), iend = (len[0]); i <= iend; ++i) n     for (int j = (1), jend = (len[1]); j <= jend; ++j) { n       f[i][j] = 1e9; n       for (int i2 = (0), i2end = (i - 1); i2 <= i2end; ++i2) n         for (int j2 = (0), j2end = (j - 1); j2 <= j2end; ++j2) n           if (f[i2][j2] != -1) n             for (int ch1 = (0), ch1end = (25); ch1 <= ch1end; ++ch1) { n               if (can[0][i2 + 1][i][ch1] && can[1][j2 + 1][j][ch1]) { n                 f[i][j] = min(f[i2][j2] + 1, f[i][j]); n               } n             } n       if (f[i][j] == 1e9) f[i][j] = -1; n     } n   printf( %d n , f[len[0]][len[1]]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char **argv) { n   int n, h; n   cin >> n >> h; n   bool flag; n   for (int k = 0; k < n; k++) { n     flag = false; n     for (int j = 0; j < n; j++) { n       if (flag) cout <<    ; n       flag = true; n       if (j == k) n         cout << h; n       else n         cout <<  0 ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, p, q, ans = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> p; n     cin >> q; n     if (q - p >= 2) ans++; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct vals { n   bool vd; n   char val[1010]; n   bool cur; n   int idx[2]; n   string nome, op; n } s[5020]; n bool valdef(bool k, int vv, int curidx) { n   if (s[curidx].idx[vv] == -1) return k; n   return s[s[curidx].idx[vv]].cur; n } n bool value(string op, bool k, int curidx) { n   if (op ==  XOR ) { n     return valdef(k, 0, curidx) ^ valdef(k, 1, curidx); n   } else if (op ==  OR ) { n     return valdef(k, 0, curidx) | valdef(k, 1, curidx); n   } else if (op ==  AND ) { n     return valdef(k, 0, curidx) & valdef(k, 1, curidx); n   } n } n int main() { n   int n, m; n   char c; n   char aux1[12], aux2[1010], aux3[5], aux4[12]; n   map<string, int> mpi; n   cin >> n >> m; n   for (int i = 0; i < (n); ++i) { n     scanf( %s := %s%c , aux1, aux2, &c); n     mpi[string(aux1)] = i; n     if (c ==    ) { n       scanf( %s %s , aux3, aux4); n       if (string(aux2) !=  ? ) n         s[i].idx[0] = mpi[string(aux2)]; n       else n         s[i].idx[0] = -1; n       s[i].op = string(aux3); n       if (string(aux4) !=  ? ) n         s[i].idx[1] = mpi[string(aux4)]; n       else n         s[i].idx[1] = -1; n       s[i].vd = false; n     } else if (c ==   n  or c ==   r ) { n       strcpy(s[i].val, aux2); n       s[i].vd = true; n     } else n       cout <<  erro  << endl; n   } n   string sauxmax =   ; n   string sauxmin =   ; n   for (int i = 0; i < (m); ++i) { n     vector<int> vsoma(2, 0); n     for (int k = 0; k < (2); ++k) { n       for (int j = 0; j < (n); ++j) { n         bool baux; n         if (s[j].vd) { n           baux = s[j].val[i] -  0 ; n           s[j].cur = baux; n         } else { n           baux = value(s[j].op, k, j); n           s[j].cur = baux; n         } n         vsoma[k] += baux; n       } n     } n     if (vsoma[1] > vsoma[0]) n       sauxmax +=  1 , sauxmin +=  0 ; n     else if (vsoma[1] == vsoma[0]) n       sauxmax +=  0 , sauxmin +=  0 ; n     else if (vsoma[1] < vsoma[0]) n       sauxmax +=  0 , sauxmin +=  1 ; n   } n   cout << sauxmin << endl << sauxmax << endl; n } n


#include <bits/stdc++.h> n using namespace std; n string A[8]; n int dx[9] = {-1, -1, -1, 0, 1, 1, 1, 0, 0}; n int dy[9] = {-1, 0, 1, 1, 1, 0, -1, -1, 0}; n bool dfs(int x, int y, int tour) { n   if (x == 0 && y == 7) return 1; n   if (tour > 8) return true; n   for (int k = 0; k <= 8; k++) { n     int nx = x + dx[k], ny = y + dy[k]; n     if (nx < 0 || ny < 0 || nx > 7 || ny > 7) continue; n     if (nx - tour >= 0 && A[nx - tour][ny] ==  S ) continue; n     if (nx - tour - 1 >= 0 && A[nx - tour - 1][ny] ==  S ) continue; n     if (dfs(nx, ny, tour + 1)) return 1; n   } n   return 0; n } n int main() { n   vector<pair<int, int> > S; n   for (int i = 0; i < 8; i++) { n     cin >> A[i]; n   } n   if (dfs(7, 0, 0)) n     cout <<  WIN  << endl; n   else n     cout <<  LOSE  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void io() { n   freopen( input.txt ,  r , stdin); n   freopen( output.txt ,  w , stdout); n } n const int N = 2e5 + 9; n const long long MOD = 1e9 + 7; n const int INF = 1e9; n int dx[5] = {0, -1, 1, 0, 0}; n int dy[5] = {0, 0, 0, -1, 1}; n char dc[5] = { 0 ,  U ,  D ,  L ,  R }; n int main() { n   int test; n   test = 1; n   while (test--) { n     int x, y; n     cin >> x >> y; n     int ans = 0; n     while (x > 0 && y > 0) { n       if (x > y) swap(x, y); n       if (x < 100) x++; n       y -= 2; n       if (y < 0) break; n       ans++; n     } n     cout << ans; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int n, m, d[N], a[N]; n bool flag[N]; n bool check(int x) { n   memset(flag, 0, sizeof(flag)); n   int cur = x - 1; n   for (int i = x; i >= 1; i--) { n     cur = min(cur, i - 1); n     if (d[i] && !flag[d[i]] && a[d[i]] <= cur) { n       flag[d[i]] = 1; n       cur -= a[d[i]] + 1; n     } n   } n   for (int i = 1; i <= m; i++) { n     if (!flag[i]) return 0; n   } n   return 1; n } n int main() { n   int ans = -1; n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , d + i); n   for (int i = 1; i <= m; i++) scanf( %d , a + i); n   int l = 1, r = n, mid; n   while (l <= r) { n     mid = (l + r) >> 1; n     if (check(mid)) n       r = mid - 1, ans = mid; n     else n       l = mid + 1; n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, size_t N> n struct ma : array<T, N> { n   T &operator[](size_t n) { return (*static_cast<array<T, N> *>(this))[n]; } n }; n template <class T> n string to_str(const T &a) { n   ostringstream os; n   os << a; n   return os.str(); n } n template <> n string to_str<long double>(const long double &a) { n   ostringstream os; n   os.precision(10); n   os.setf(ios::fixed); n   os << a; n   return os.str(); n } n template <class T> n T from_str(const string &s) { n   istringstream is; n   T val; n   is >> val; n   return val; n } n int cond = (long long)0; n void solve() { n   int n, m; n   scanf( %d%d , &n, &m); n   vector<int> co(n); n   for (auto i = (0); i < (n); ++i) scanf( %d , &co[i]); n   long long ret = 0; n   for (auto i = (0); i < (m); ++i) { n     int a, b; n     scanf( %d%d , &a, &b); n     a--; n     b--; n     ret += min(co[a], co[b]); n   } n   cout << ret << endl; n } n void brute() {} n void gen(int i, int n, int k) {} n int main(int argc, char **argv) { n   ios::sync_with_stdio(false); n   vector<string> args; n   int nr_test = -1; n   int t = 1; n   for (auto i = (1); i <= (argc - 1); ++i) args.push_back(argv[i]); n   for (auto &it : (args)) n     if (it ==  q ) cond = 10000000; n   for (auto &it : (args)) n     if (it ==  all ) t = 1000; n   for (auto &it : (args)) n     if (atoi(it.c_str()) > 0) nr_test = atoi(it.c_str()); n   for (auto &it : (args)) n     if (it ==  b ) { n       brute(); n       return 0; n     } n   for (auto &it : (args)) n     if (it ==  g  && args.size() >= 4) { n       gen(atoi(args[1].c_str()), atoi(args[2].c_str()), atoi(args[3].c_str())); n       return 0; n     } n   for (auto i = (1); i <= (t); ++i) { n     if (nr_test == -1 || i <= nr_test) solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, dx4[4] = {-1, 0, 1, 0}; n int dy8[8] = {0, -1, -1, -1, 0, 1, 1, 1}, dy4[4] = {0, -1, 0, 1}; n inline void open(string name) { n   freopen((name +  .in ).c_str(),  r , stdin); n   freopen((name +  .out ).c_str(),  w , stdout); n } n inline void close() { n   fclose(stdin); n   fclose(stdout); n } n inline int io() { n   register char c; n   while (1) { n     c = getchar_unlocked(); n     if (c !=   n  && c !=    ) break; n   } n   int res = 0, sign = 1; n   if (c ==  - ) n     sign = -1; n   else n     res = c -  0 ; n   while (1) { n     c = getchar_unlocked(); n     if (c ==     || c ==   n  || c == EOF) break; n     res = (res << 3) + (res << 1) + c -  0 ; n   } n   return res * sign; n } n const int N = 100005; n struct Bullet { n   int x; n   int y; n   int idx; n   Bullet() {} n   bool operator<(Bullet other) const { n     if (x == other.x) { n       if (y == other.y) n         return idx < other.idx; n       else n         return y < other.y; n     } else n       return x < other.x; n   } n }; n Bullet origin[N], arr[N]; n struct Node { n   vector<pair<int, int> > bullet_list; n   vector<int> RMQ; n   Node() { n     bullet_list.clear(); n     RMQ.clear(); n   } n   void Build() { n     RMQ.resize(4 * bullet_list.size()); n     Build(1, 0, bullet_list.size() - 1); n   } n   void Build(int id, int l, int r) { n     if (l == r) n       RMQ[id] = bullet_list[l].second; n     else { n       int chld = id << 1, m = (l + r) >> 1; n       Build(chld, l, m); n       Build(chld + 1, m + 1, r); n       RMQ[id] = min(RMQ[chld], RMQ[chld + 1]); n     } n   } n   int Query(int ya, int yb) { n     int st = n         lower_bound(bullet_list.begin(), bullet_list.end(), make_pair(ya, 0)) - n         bullet_list.begin(); n     int en = upper_bound(bullet_list.begin(), bullet_list.end(), n                          make_pair(yb, 1000000000)) - n              bullet_list.begin(); n     en--; n     if (st > en) n       return 1000000000; n     else n       return Query(1, 0, bullet_list.size() - 1, st, en); n   } n   int Query(int id, int l, int r, int x, int y) { n     if (x <= l && r <= y) n       return RMQ[id]; n     else { n       int chld = (id << 1), m = (l + r) >> 1; n       int res = 1000000000; n       if (x <= m) res = min(res, Query(chld, l, m, x, y)); n       if (y > m) res = min(res, Query(chld + 1, m + 1, r, x, y)); n       return res; n     } n   } n   void Del(int id) { n     int ya = origin[id].y; n     int st = n         lower_bound(bullet_list.begin(), bullet_list.end(), make_pair(ya, id)) - n         bullet_list.begin(); n     Del(1, 0, bullet_list.size() - 1, st); n   } n   void Del(int id, int l, int r, int x) { n     if (l == r) { n       RMQ[id] = 1000000000; n     } else { n       int chld = id << 1, m = (l + r) >> 1; n       if (x <= m) n         Del(chld, l, m, x); n       else n         Del(chld + 1, m + 1, r, x); n       RMQ[id] = min(RMQ[chld], RMQ[chld + 1]); n     } n   } n }; n Node rtree[4 * N]; n vector<int> X; n int n, q; n int ans[N]; n void BuildRangeTree(int id, int l, int r) { n   if (l == r) { n     rtree[id].bullet_list.push_back(make_pair(arr[l].y, arr[l].idx)); n   } else { n     int chld = id << 1, m = (l + r) >> 1; n     BuildRangeTree(chld, l, m); n     BuildRangeTree(chld + 1, m + 1, r); n     int i = 0, j = 0; n     while (i < rtree[chld].bullet_list.size() && n            j < rtree[chld + 1].bullet_list.size()) { n       if (rtree[chld].bullet_list[i] < rtree[chld + 1].bullet_list[j]) n         rtree[id].bullet_list.push_back(rtree[chld].bullet_list[i++]); n       else n         rtree[id].bullet_list.push_back(rtree[chld + 1].bullet_list[j++]); n     } n     while (i < rtree[chld].bullet_list.size()) n       rtree[id].bullet_list.push_back(rtree[chld].bullet_list[i++]); n     while (j < rtree[chld + 1].bullet_list.size()) n       rtree[id].bullet_list.push_back(rtree[chld + 1].bullet_list[j++]); n   } n   rtree[id].Build(); n } n void UpdateRangeTree(int pos) { n   int idpos = lower_bound(arr, arr + q, origin[pos]) - arr; n   int id = 1, l = 0, r = q - 1; n   while (1) { n     rtree[id].Del(pos); n     if (l == r) break; n     int chld = id << 1, m = (l + r) >> 1; n     if (idpos <= m) n       r = m, id = chld; n     else n       l = m + 1, id = chld + 1; n   } n } n int QueryRangeTree(int id, int l, int r, int x, int y, int ya, int yb) { n   int res = 1000000000; n   if (x <= l && r <= y) n     res = rtree[id].Query(ya, yb); n   else { n     int chld = (id << 1), m = (l + r) >> 1; n     res = 1000000000; n     if (x <= m) res = min(res, QueryRangeTree(chld, l, m, x, y, ya, yb)); n     if (y > m) res = min(res, QueryRangeTree(chld + 1, m + 1, r, x, y, ya, yb)); n   } n   return res; n } n struct Target { n   int xa; n   int ya; n   int xb; n   int yb; n   int z; n   int idx; n   Target() {} n   bool operator<(Target other) const { n     if (z == other.z) return idx < other.idx; n     return z < other.z; n   } n }; n Target arr2[N]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d %d %d %d %d , &arr2[i].xa, &arr2[i].xb, &arr2[i].ya, &arr2[i].yb, n           &arr2[i].z); n     arr2[i].idx = i; n   } n   sort(arr2, arr2 + n); n   scanf( %d , &q); n   for (int i = 0; i < q; i++) { n     scanf( %d %d , &origin[i].x, &origin[i].y); n     origin[i].idx = i; n     X.push_back(origin[i].x); n     arr[i] = origin[i]; n   } n   sort(arr, arr + q); n   sort(X.begin(), X.end()); n   BuildRangeTree(1, 0, q - 1); n   memset(ans, -1, sizeof ans); n   for (int i = 0; i < n; i++) { n     int x1 = lower_bound(X.begin(), X.end(), arr2[i].xa) - X.begin(); n     int x2 = upper_bound(X.begin(), X.end(), arr2[i].xb) - X.begin(); n     x2--; n     if (x1 <= x2) { n       int res = QueryRangeTree(1, 0, q - 1, x1, x2, arr2[i].ya, arr2[i].yb); n       if (res != 1000000000) { n         ans[res] = arr2[i].idx; n         UpdateRangeTree(res); n       } n     } n   } n   for (int i = 0; i < q; i++) printf( %d n , ans[i] + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string str; n   char tmp =  z ; n   cin >> str; n   for (int i = 0; i < str.length(); i++) { n     if (str[i] <= tmp) { n       tmp = str[i]; n       cout <<  Mike  << endl; n     } else { n       cout <<  Ann  << endl; n     } 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(0); n   cout.tie(0); n   long long int n, m, a, b; n   cin >> n >> m >> a >> b; n   long long int res, ans; n   res = n / m; n   if (n % m) res++; n   res = (res * m - n) * a; n   ans = (n % m) * b; n   cout << min(res, ans) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1e9 + 7; n long long min(long long a, long long b) { return (a < b) ? a : b; } n long long max(long long a, long long b) { return (a > b) ? a : b; } n long long fp(long long a, long long b) { n   if (b == 0) return 1; n   long long x = fp(a, b / 2); n   x = (x * x) % mod; n   if (b & 1) x = (x * a) % mod; n   return x; n } n const long long N = 2e5 + 5; n long long a[N]; n long long n; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n; n   long long cnt[60] = {0}; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i]; n     for (long long b = 0; b < 20; b++) { n       if ((a[i] >> b) & 1) { n         cnt[b]++; n       } n     } n   } n   long long ans = 0; n   for (long long i = 1; i <= n; i++) { n     long long x = 0; n     for (long long b = 0; b < 20; b++) { n       if (cnt[b]) { n         cnt[b]--; n         x |= (1ll << b); n       } n     } n     ans += x * x; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, x; n vector<pair<int, int> > leti[26]; n vector<pair<int, int> > shift; n vector<int> dis[26]; n int main() { n   cin >> n >> m >> x; n   int d = x * x; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       char t; n       cin >> t; n       if (t ==  S ) n         shift.push_back(pair<int, int>(i, j)); n       else n         leti[t -  a ].push_back(pair<int, int>(i, j)); n     } n   } n   for (int i = 0; i < 26; i++) { n     for (int j = 0; j < leti[i].size(); j++) { n       int mn = 0x7fffffff; n       for (int k = 0; k < shift.size(); k++) { n         int dx = shift[k].first - leti[i][j].first; n         int dy = shift[k].second - leti[i][j].second; n         mn = min(mn, dx * dx + dy * dy); n       } n       dis[i].push_back(mn); n     } n   } n   int q; n   cin >> q; n   int cnt = 0; n   for (int i = 0; i < q; i++) { n     char t; n     cin >> t; n     if (((t -  a ) >= 0) && leti[t -  a ].empty()) { n       cout << -1 << endl; n       return 0; n     } n     if (((t -  a ) < 0) && leti[t -  A ].empty()) { n       cout << -1 << endl; n       return 0; n     } n     if (((t -  a ) < 0) && shift.empty()) { n       cout << -1 << endl; n       return 0; n     } n     if ((t -  a ) < 0) { n       int flag = true; n       for (int j = 0; j < leti[t -  A ].size(); j++) { n         if (dis[t -  A ][j] <= d) { n           flag = false; n           break; n         } n       } n       if (flag) n         cnt++; n       else n         flag = true; n     } n   } n   cout << cnt << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int Maxn3 = 1e3 + 10; n const long long int Maxn4 = 1e4 + 10; n const long long int Maxn5 = 1e5 + 10; n const long long int Maxn6 = 1e6 + 10; n const long long int Maxn7 = 1e7 + 10; n const long long int Maxn8 = 1e8 + 10; n const long long int Maxn9 = 1e9 + 10; n const long long int Maxn18 = 1e18 + 10; n const long long int Mod1 = 1e7 + 7; n const long long int Mod2 = 1e9 + 7; n const long long int LLMax = LLONG_MAX; n const long long int LLMin = LLONG_MIN; n const long long int INTMax = INT_MAX; n const long long int INTMin = INT_MIN; n long long int mn = LLMax, mx = LLMin; n bool prime(int x) { n   for (int i = 2; i * i <= x; i++) n     if (x % i == 0) return 0; n   return 1; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   int n; n   cin >> n; n   if (prime(n) == 1) n     return cout <<  1 n  << n, 0; n   else { n     cout <<  3 n3  ; n     n -= 3; n     for (int i = 3; i < n; i += 2) n       if (prime(n - i) and prime(i)) return cout << i <<     << n - i, 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n FILE *in = stdin, *out = stdout; n using namespace std; n #pragma comment(linker,  /stack:36777216 ) n int n; n char a[300005]; n int D[300005]; n void input() { n   fscanf(in,  %d , &n); n   fscanf(in,  %s , &a[1]); n } n bool isSame(int x) { n   if (x & 1) return false; n   for (int i = (1); i <= (x / 2); i++) { n     if (a[i] != a[i + x / 2]) return false; n   } n   return true; n } n void pro() { n   int ans = n; n   for (int i = (1); i <= (n); i++) { n     if (isSame(i)) ans = min(ans, i / 2 + 1 + (n - i)); n   } n   fprintf(out,  %d , ans); n } n int main() { n   input(); n   pro(); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 110, M = 10010; n int n; n long double x; n int c[N], all; n long double binom[N][N]; n long double f[N][M]; n int main() { n   cin >> n >> x; n   for (int i = 1; i <= n; i++) scanf( %d , &c[i]), all += c[i]; n   f[0][0] = 1; n   for (int i = 0; i <= n; i++) { n     binom[i][0] = binom[i][i] = 1; n     for (int j = 1; j < i; j++) n       binom[i][j] = binom[i - 1][j] + binom[i - 1][j - 1]; n   } n   f[0][0] = 1; n   for (int id = 1; id <= n; id++) { n     for (int i = id; i; i--) { n       for (int j = all; j >= c[id]; j--) { n         f[i][j] += f[i - 1][j - c[id]]; n       } n     } n   } n   long double ans = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= all; j++) { n       long double v = f[i][j]; n       v /= binom[n][i]; n       v *= min(x / 2 + x / 2 * n / i, (long double)j / (long double)i); n       ans += v; n     } n   } n   printf( %.15Lf n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n long long k, l, g = 0, h = 0; n int a, b, p[3][3], q[3][3], t, u, v, c; n vector<pair<int, int> > s; n bool con; n int gg(int a, int b) { n   if (a == b + 1 || a == b - 2) return 1; n   return 0; n } n void sim(int x, int t, int u) { n   while (x > 0) { n     g += gg(t, u); n     h += gg(u, t); n     v = t; n     t = p[t][u]; n     u = q[v][u]; n     x--; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> k >> a >> b; n   a--, b--; n   for (int i = 0; i < (3); i++) n     for (int j = 0; j < (3); j++) cin >> p[i][j]; n   for (int i = 0; i < (3); i++) n     for (int j = 0; j < (3); j++) cin >> q[i][j]; n   for (int i = 0; i < (3); i++) n     for (int j = 0; j < (3); j++) q[i][j]--, p[i][j]--; n   s.push_back({a, b}); n   t = p[a][b], u = q[a][b]; n   while (true) { n     con = false; n     for (int i = 0; i < (s.size()); i++) { n       if (s[i].first == t && s[i].second == u) con = true; n     } n     if (con) n       break; n     else { n       s.push_back({t, u}); n       v = t; n       t = p[t][u]; n       u = q[v][u]; n     } n     con = false; n   } n   for (int i = 0; i < (s.size()); i++) { n     if (s[i].first == t && s[i].second == u) c = s.size() - i; n   } n   if (k < 10000) { n     sim(k, a, b); n   } else { n     l = (k - s.size() + c) / c; n     sim(c, t, u); n     g *= l; n     h *= l; n     sim(s.size() - c, a, b); n     sim((k - s.size() + c) % c, t, u); n   } n   cout << g <<     << h << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e3 + 3; n const int inf = 1e8; n int n, m; n char str[N][N]; n int sx, sy; n int tx, ty; n struct data { n   int up; n   int down; n   int rgt; n   int lft; n   data() { n     up = 0; n     down = 0; n     rgt = 0; n     lft = 0; n   } n   void rotate() { n     int _up = lft; n     int _rgt = up; n     int _down = rgt; n     int _lft = down; n     up = _up; n     rgt = _rgt; n     down = _down; n     lft = _lft; n   } n }; n data mat[N][N]; n queue<int> qx; n queue<int> qy; n queue<int> qr; n int dist[N][N][4]; n inline void relax(int nx, int ny, int nr, int ndist) { n   if (dist[nx][ny][nr] > ndist) { n     dist[nx][ny][nr] = ndist; n     qx.push(nx); n     qy.push(ny); n     qr.push(nr); n   } n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; ++i) { n     scanf( %s , str[i] + 1); n   } n   for (int i = 0; i <= m + 1; ++i) { n     str[0][i] =  * ; n     str[n + 1][i] =  * ; n   } n   for (int i = 0; i <= n + 1; ++i) { n     str[i][0] =  * ; n     str[i][m + 1] =  * ; n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       if (str[i][j] ==  + ) { n         mat[i][j].up = 1; n         mat[i][j].lft = 1; n         mat[i][j].rgt = 1; n         mat[i][j].down = 1; n       } n       if (str[i][j] ==  - ) { n         mat[i][j].up = 0; n         mat[i][j].lft = 1; n         mat[i][j].rgt = 1; n         mat[i][j].down = 0; n       } n       if (str[i][j] ==  | ) { n         mat[i][j].up = 1; n         mat[i][j].lft = 0; n         mat[i][j].rgt = 0; n         mat[i][j].down = 1; n       } n       if (str[i][j] ==  ^ ) { n         mat[i][j].up = 1; n         mat[i][j].lft = 0; n         mat[i][j].rgt = 0; n         mat[i][j].down = 0; n       } n       if (str[i][j] ==  > ) { n         mat[i][j].up = 0; n         mat[i][j].lft = 0; n         mat[i][j].rgt = 1; n         mat[i][j].down = 0; n       } n       if (str[i][j] ==  < ) { n         mat[i][j].up = 0; n         mat[i][j].lft = 1; n         mat[i][j].rgt = 0; n         mat[i][j].down = 0; n       } n       if (str[i][j] ==  v ) { n         mat[i][j].up = 0; n         mat[i][j].lft = 0; n         mat[i][j].rgt = 0; n         mat[i][j].down = 1; n       } n       if (str[i][j] ==  L ) { n         mat[i][j].up = 1; n         mat[i][j].lft = 0; n         mat[i][j].rgt = 1; n         mat[i][j].down = 1; n       } n       if (str[i][j] ==  R ) { n         mat[i][j].up = 1; n         mat[i][j].lft = 1; n         mat[i][j].rgt = 0; n         mat[i][j].down = 1; n       } n       if (str[i][j] ==  U ) { n         mat[i][j].up = 0; n         mat[i][j].lft = 1; n         mat[i][j].rgt = 1; n         mat[i][j].down = 1; n       } n       if (str[i][j] ==  D ) { n         mat[i][j].up = 1; n         mat[i][j].lft = 1; n         mat[i][j].rgt = 1; n         mat[i][j].down = 0; n       } n       if (str[i][j] ==  * ) { n         mat[i][j].up = 0; n         mat[i][j].lft = 0; n         mat[i][j].rgt = 0; n         mat[i][j].down = 0; n       } n     } n   } n   scanf( %d %d , &sx, &sy); n   scanf( %d %d , &tx, &ty); n   for (int i = 0; i <= n + 1; ++i) { n     for (int j = 0; j <= m + 1; ++j) { n       for (int k = 0; k < 4; ++k) { n         dist[i][j][k] = inf; n       } n     } n   } n   relax(sx, sy, 0, 0); n   while (!qx.empty()) { n     int x = qx.front(); n     int y = qy.front(); n     int r = qr.front(); n     int d = dist[x][y][r]; n     qx.pop(); n     qy.pop(); n     qr.pop(); n     relax(x, y, (r + 1) % 4, d + 1); n     data tmp = mat[x][y]; n     data tmprgt = mat[x][y + 1]; n     data tmpdown = mat[x + 1][y]; n     data tmplft = mat[x][y - 1]; n     data tmpup = mat[x - 1][y]; n     for (int i = 0; i < r; ++i) { n       tmp.rotate(); n       tmprgt.rotate(); n       tmpdown.rotate(); n       tmplft.rotate(); n       tmpup.rotate(); n     } n     if (tmp.rgt && tmprgt.lft) { n       relax(x, y + 1, r, d + 1); n     } n     if (tmp.lft && tmplft.rgt) { n       relax(x, y - 1, r, d + 1); n     } n     if (tmp.up && tmpup.down) { n       relax(x - 1, y, r, d + 1); n     } n     if (tmp.down && tmpdown.up) { n       relax(x + 1, y, r, d + 1); n     } n   } n   int ans = inf; n   for (int i = 0; i < 4; ++i) { n     ans = min(ans, dist[tx][ty][i]); n   } n   if (ans >= inf) { n     ans = -1; n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n bool sortbysecdesc(const pair<long long, long long> &a, n                    const pair<long long, long long> &b) { n   if (a.first == b.first) n     return a.second > b.second; n   else n     return 0; n } n const long long N = 100010; n bool prime[N]; n void SieveOfEratosthenes() { n   long long n = N - 3; n   memset(prime, true, sizeof(prime)); n   for (long long p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       for (long long i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n } n long long i, j; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   SieveOfEratosthenes(); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     if (n == 1 || n == 2 || n == 3 || n == 5 || n == 7 || n == 11) { n       cout <<  -1  <<   n ; n     } else if (n % 4 == 0) { n       cout << n / 4 <<   n ; n     } else if (n == 6) { n       cout << 1 <<   n ; n     } else { n       long long temp = n / 4; n       long long x = n - temp * 4; n       if (x == 1) { n         cout << 1 + (n - 9) / 4 <<   n ; n       } else if (x == 2) { n         cout << 1 + (n - 6) / 4 <<   n ; n       } else if (x == 3) { n         cout << 2 + (n - 15) / 4 <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fastpower(long long power, long long base) { n   if (power == 0) return (1 % 1000000007); n   long long sum; n   sum = fastpower(power / 2, base) % 1000000007; n   sum = ((sum % 1000000007) * (sum % 1000000007)) % 1000000007; n   if (power & 1) sum = ((sum % 1000000007) * (base % 1000000007)) % 1000000007; n   return (sum % 1000000007); n } n int main() { n   ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0), n       cout.tie(0); n   ; n   string s; n   long long k, sum = 0; n   cin >> s >> k; n   long long rn = n       (fastpower((long long)s.size() * k, 2) - 1 + 1000000007) % 1000000007; n   long long r = n       (fastpower((long long)s.size(), 2) - 1 + 1000000007) % 1000000007; n   long long d = fastpower(1000000007 - 2, r); n   for (int i = 0; i < (int)s.size(); ++i) { n     if (s[i] ==  0  || s[i] ==  5 ) { n       long long a = fastpower(i, 2); n       sum = (sum % 1000000007 + a * rn % 1000000007 * d % 1000000007) % n             1000000007; n     } n   } n   cout << sum <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx ) n #pragma GCC target( avx,tune=native ) n using namespace std; n class CodeHash { n  public: n   string precise(double number, int prec) { n     stringstream ss; n     ss << fixed << setprecision(prec) << number; n     return ss.str(); n   } n }; n class ScanReader { n  private: n   FILE *stream; n   char buffer[1 << 11]; n   bool is_digit[1 << 8]; n   int index, total; n   int scan() { n     if (index >= total) { n       index = 0; n       total = fread(buffer, 1, 1 << 11, stream); n       if (total <= 0) return -1; n     } n     return buffer[index++]; n   } n   bool iswhitespace(int n) { n     if (n ==     || n ==   n  || n ==   t  || n ==   r  || n == -1) return true; n     return false; n   } n  n  public: n   ScanReader(FILE *stream) { n     this->stream = stream; n     index = total = 0; n     for (int i = 0; i < 1 << 8; i++) is_digit[i] = isdigit(i); n   } n   int scanInt() { n     int integer = 0, temp = scan(); n     while (iswhitespace(temp)) temp = scan(); n     int neg = 1; n     if (temp ==  - ) neg *= -1, temp = scan(); n     while (!iswhitespace(temp)) n       if (is_digit[temp]) integer *= 10, integer += (temp -  0 ), temp = scan(); n     return neg * integer; n   } n   long long scanLong() { n     long long integer = 0; n     int temp = scan(); n     while (iswhitespace(temp)) temp = scan(); n     int neg = 1; n     if (temp ==  - ) neg *= -1, temp = scan(); n     while (!iswhitespace(temp)) n       if (is_digit[temp]) integer *= 10, integer += (temp -  0 ), temp = scan(); n     return neg * integer; n   } n   string scanString() { n     string ss =   ; n     int temp = scan(); n     while (iswhitespace(temp)) temp = scan(); n     while (!iswhitespace(temp)) ss += temp, temp = scan(); n     return ss; n   } n   double scanDouble() { n     int c = scan(); n     while (iswhitespace(c)) c = scan(); n     int sgn = 1; n     if (c ==  - ) sgn = -1, c = scan(); n     double res = 0; n     while (!iswhitespace(c) && c !=  . ) { n       if (c ==  e  || c ==  E ) return res * pow(10, scanInt()); n       res *= 10; n       res += c -  0 ; n       c = scan(); n     } n     if (c ==  . ) { n       c = scan(); n       double m = 1; n       while (!iswhitespace(c)) { n         if (c ==  e  || c ==  E ) { n           return res * pow(10, scanInt()); n         } n         m /= 10; n         res += (c -  0 ) * m; n         c = scan(); n       } n     } n     return res * sgn; n   } n }; n class PrintWriter { n  private: n   FILE *stream; n   static const int BUFFER_SIZE = (1 << 11) - 1; n   static const int MAX_OUT_SIZE = 23; n   int size; n   char buffer[BUFFER_SIZE]; n   void write(long long v) { n     if (v < 0) buffer[size++] =  - , v *= -1; n     if (v < 10) n       buffer[size++] = v + 48; n     else { n       write(v / 10); n       buffer[size++] = v % 10 + 48; n     } n   } n  n  public: n   PrintWriter(FILE *stream) { n     this->size = 0; n     this->stream = stream; n   } n   void close() { n     if (size) fwrite(buffer, 1, size, stream); n   } n   void println(long long s) { n     if ((size ^ BUFFER_SIZE) < MAX_OUT_SIZE) { n       fwrite(buffer, 1, size, stream); n       size = 0; n     } n     write(s); n     buffer[size++] =   n ; n   } n   void print(long long s) { n     if ((size ^ BUFFER_SIZE) < MAX_OUT_SIZE) { n       fwrite(buffer, 1, size, stream); n       size = 0; n     } n     write(s); n     buffer[size++] =    ; n   } n   void println(string s) { n     if ((size ^ BUFFER_SIZE) < MAX_OUT_SIZE) { n       fwrite(buffer, 1, size, stream); n       size = 0; n     } n     for (int i = 0; i < s.length(); i++) { n       buffer[size++] = s[i]; n       if ((size ^ BUFFER_SIZE) < MAX_OUT_SIZE) { n         fwrite(buffer, 1, size, stream); n         size = 0; n       } n     } n     buffer[size++] =   n ; n   } n   void print(string s) { n     if ((size ^ BUFFER_SIZE) < MAX_OUT_SIZE) { n       fwrite(buffer, 1, size, stream); n       size = 0; n     } n     for (int i = 0; i < s.length(); i++) { n       buffer[size++] = s[i]; n       if ((size ^ BUFFER_SIZE) < MAX_OUT_SIZE) { n         fwrite(buffer, 1, size, stream); n         size = 0; n       } n     } n     buffer[size++] =    ; n   } n }; n FILE *fi = stdin; n FILE *fo = stdout; n ScanReader *in = new ScanReader(fi); n PrintWriter *out = new PrintWriter(fo); n CodeHash *ch = new CodeHash(); n int main() { n   multiset<int> mt; n   multiset<int> mt1; n   multiset<int> mt2; n   int n = in->scanInt(); n   long long ans = 1; n   long long mod = 1000000007; n   while (n--) { n     string s = in->scanString(); n     int tt = in->scanInt(); n     if (s.length() == 3) { n       if (!mt.empty() && *mt.begin() < tt) n         mt.insert(tt); n       else if (!mt1.empty() && *mt1.rbegin() > tt) n         mt1.insert(tt); n       else n         mt2.insert(tt); n     } else { n       if ((!mt.empty() && *mt.begin() < tt) || n           (!mt1.empty() && *mt1.rbegin() > tt)) { n         out->println(0); n         out->close(); n         return 0; n       } n       if ((!mt.empty() && *mt.begin() == tt)) mt.erase(mt.begin()); n       if ((!mt1.empty() && *mt1.rbegin() == tt)) mt1.erase(--mt1.end()); n       while (!mt2.empty()) { n         int tl = *mt2.begin(); n         mt2.erase(mt2.begin()); n         if (tl < tt) { n           mt1.insert(tl); n         } else if (tl > tt) { n           mt.insert(tl); n         } else { n           ans = (ans * 2) % mod; n         } n       } n     } n   } n   out->println((ans * (mt2.size() + 1)) % mod); n   out->close(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int getn() { n   int h; n   scanf( %d , &h); n   return h; n } n template <class T, class U> n ostream& operator<<(ostream& out, const pair<T, U>& par) { n   cout <<  [  << par.first <<  ;  << par.second <<  ] ; n   return out; n } n vector<vector<int> > mini; n int n; n int nacitaj(int i, int j) { n   mini[i][j] = getn(); n   i = (i != n - 1 ? i + 1 : 0); n   j = (i != 0 ? j : j + 1); n   return (j != n ? nacitaj(i, j) : 1); n } n int floydwardshal(int i, int j, int l) { n   mini[i][j] = min(mini[i][j], mini[i][l] + mini[l][j]); n   i = (i != n - 1 ? i + 1 : 0); n   j = (i != 0 ? j : j + 1); n   j = (j >= n ? 0 : j); n   l = (i == 0 && j == 0 ? l + 1 : l); n   return (l != n ? floydwardshal(i, j, l) : 0); n } n int maxi(int i, int j) { n   int mx = mini[i][j]; n   i = (i != n - 1 ? i + 1 : 0); n   j = (i != 0 ? j : j + 1); n   return (j != n ? max(maxi(i, j), mx) : mx); n } n int main() { n   n = getn(); n   mini.resize(n, vector<int>(n, 0)); n   nacitaj(0, 0); n   floydwardshal(0, 0, 0); n   cout << maxi(0, 0) << endl; n } n


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


#include <bits/stdc++.h> n int main() { n   int sum = 0, a, n, m, i; n   scanf( %d %d , &n, &m); n   for (i = 1; i <= n; i++) { n     sum = sum + i; n     if (m > sum && i == n) { n       i = 0; n     } n     a = m - sum; n     if (a < i + 1) { n       printf( %d , a); n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2000000 + 10; n int a[N], b[N]; n int n, m; n int main() { n   int x, y; n   scanf( %d%d , &n, &m); n   { n     for (int i = 0; i < m; i++) { n       scanf( %d%d , &x, &y); n       x--; n       y--; n       a[x]++; n       a[y]++; n     } n     for (int i = 0; i < n; i++) b[i] = n - 1 - a[i]; n     long long total = 0; n     for (int i = 0; i < n; i++) total += (long long)a[i] * b[i]; n     total /= 2; n     cout << (long long)n * (n - 1) / 2 * (n - 2) / 3 - total << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mult(long long a, long long b, long long p = 1000000007) { n   return ((a % p) * (b % p)) % p; n } n long long add(long long a, long long b, long long p = 1000000007) { n   return (a % p + b % p) % p; n } n long long sub(long long a, long long b, long long p = 1000000007) { n   return (a % p - b % p + p) % p; n } n long long fpow(long long n, long long k, long long p = 1000000007) { n   long long r = 1; n   for (; k; k >>= 1) { n     if (k & 1) r = mult(r, n, p); n     n = mult(n, n, p); n   } n   return r; n } n long long inv(long long a, long long p = 1000000007) { n   return fpow(a, p - 2, p); n } n map<long long, vector<long long> > m; n int main() { n   long long n, k; n   cin >> n >> k; n   long long a[n], c[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     m[a[i]].push_back(i); n   } n   bool f = 1; n   long long mx = 1; n   long long it = 1; n   for (auto i : m) { n     if (i.second.size() > k) f = 0; n     for (auto j : i.second) { n       c[j] = it; n       mx = max(mx, it); n       ++it; n       if (it > k) { n         it = 1; n         mx = k; n       } n     } n   } n   if (f && mx == k) { n     cout <<  YES n ; n     for (int i = 0; i < n; i++) cout << c[i] <<    ; n   } else n     cout <<  NO n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2 * 100 * 1000; n long double l[N]; n long double Maks(long double dod, int n) { n   int i; n   long double as, mi, w; n   mi = 0; n   w = -10000000000000; n   as = 0; n   for (i = 1; i <= n; ++i) { n     as += (l[i] - dod); n     w = max(w, as - mi); n     mi = min(mi, as); n   } n   return w; n } n long double Minim(long double dod, int n) { n   int i; n   long double as, ma, w; n   ma = 0; n   w = 10000000000000; n   as = 0; n   for (i = 1; i <= n; ++i) { n     as += (l[i] - dod); n     w = min(w, as - ma); n     ma = max(ma, as); n   } n   return w; n } n long double TS(long double p, long double k, int n) { n   int i; n   long double s1, s2, w1, w2; n   for (i = 1; i <= 100; ++i) { n     s1 = p + ((k - p) / 3); n     s2 = k - ((k - p) / 3); n     w1 = max(abs(Maks(s1, n)), abs(Minim(s1, n))); n     w2 = max(abs(Maks(s2, n)), abs(Minim(s2, n))); n     if (w1 < w2) n       k = s2; n     else n       p = s1; n   } n   return p; n } n void WczytajLiczby(int &n) { n   int i; n   cin >> n; n   for (i = 1; i <= n; ++i) cin >> l[i]; n } n void Weakness() { n   int n; n   long double w; n   WczytajLiczby(n); n   w = TS(-10000, 10000, n); n   w = max(abs(Minim(w, n)), abs(Maks(w, n))); n   cout << fixed << setprecision(10) << w <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   Weakness(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005], lg[100005]; n int rmq[100005][20]; n struct trie { n   struct node { n     node *edge[2]; n     vector<int> ps[2]; n     node() { n       for (int i = 0; i < 2; i++) edge[i] = 0; n       ps[0].clear(); n       ps[1].clear(); n     } n   } * root; n   trie() { root = new node(); } n   void insert(int v, int p) { n     node *t = root; n     for (int po = 29; po >= 0; po--) { n       int x = (bool)(v & (1 << po)); n       if (!t->edge[x]) t->edge[x] = new node(); n       t->ps[x].push_back(p); n       t = t->edge[x]; n     } n   } n   void remove(int v) { n     node *t = root; n     for (int po = 29; po >= 0; po--) { n       int x = (bool)(v & (1 << po)); n       t->ps[x].pop_back(); n       t = t->edge[x]; n     } n   } n   long long query(int v, int last) { n     node *t = root; n     int res = 0; n     for (int po = 29; po >= 0; po--) { n       int x = (bool)(v & (1 << po)); n       x = !x; n       if (!t->ps[x].empty() && t->ps[x].back() > last) { n         res += (1 << po); n         t = t->edge[x]; n       } else n         t = t->edge[!x]; n     } n     return res; n   } n }; n int q(int l, int r) { n   if (l > r) swap(l, r); n   int po = lg[r - l + 1]; n   return max(rmq[l][po], rmq[r - (1 << po) + 1][po]); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   lg[0] = -1; n   for (int i = 1; i < 100005; i++) lg[i] = lg[i - 1] + !(i & (i - 1)); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) rmq[i][0] = a[i]; n   for (int i = 1; i <= lg[n]; i++) n     for (int j = 0; j + (1 << i) <= n; j++) n       rmq[j][i] = max(rmq[j][i - 1], rmq[j + (1 << (i - 1))][i - 1]); n   long long res = 0; n   trie t; n   t.insert(a[0], 0); n   stack<pair<long long, long long> > ms; n   ms.push(pair<long long, long long>(a[0], 0)); n   for (int i = 1; i < n; i++) { n     int p1 = -1; n     for (int po = (1 << 17); po; po >>= 1) n       if (p1 + po < i && q(p1 + po, i) > a[i]) p1 += po; n     int p2 = -1; n     if (p1 > 0) n       for (int po = (1 << 17); po; po >>= 1) n         if (p2 + po <= p1 - 1 && q(p2 + po, p1 - 1) > a[i]) p2 += po; n     res = max(res, t.query(a[i], p2)); n     while (!ms.empty() && ms.top().second > p1) { n       t.remove(ms.top().first); n       ms.pop(); n     } n     t.insert(a[i], i); n     ms.push(pair<long long, long long>(a[i], i)); n   } n   cout << (res) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, g[20][20], r, c, k, ans = 0, x, y; n bool chk(int a, int b, int c, int d) { n   int cnt = 0; n   for (int i = a; i <= a + c; i++) { n     for (int j = b; j <= b + d; j++) { n       cnt += g[i][j]; n       if (cnt >= k) return 1; n     } n   } n   return 0; n } n int main() { n   scanf( %d%d%d%d , &r, &c, &n, &k); n   for (int i = 0; i < n; i++) { n     scanf( %d%d , &x, &y); n     g[x][y] = 1; n   } n   for (int i = 1; i <= r; i++) { n     for (int j = 1; j <= c; j++) { n       for (int e = 0; e + i <= r; e++) { n         for (int f = 0; f + j <= c; f++) { n           ans += chk(i, j, e, f); n         } n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void printVec(vector<int> v2, string s =   ) { n   cout << s; n   for (int i = 0; i < (int)v2.size(); ++i) cout << v2[i] <<    ; n   cout <<   n ; n } n bool isOdd(int a) { return (a % 2 == 1); } n void initMem(int n, int mem[]) { n   for (int i = 0; i < n; i++) mem[i] = -1; n } n bool lucky(long long n) { n   n = abs(n); n   while (n) { n     if (n % 10 == 8) { n       return true; n     } n     n /= 10; n   } n   return false; n } n int main() { n   int k; n   int d; n   cin >> k >> d; n   string s =   ; n   s += ( 0  + d); n   for (int i = 1; i < k; i++) s +=  0 ; n   if (d == 0) { n     if (k == 1) n       cout << 0; n     else n       cout <<  No solution ; n     return 0; n   } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long a, b; n   cin >> a >> b; n   long long ans = abs(a - b) / 5; n   a = abs(a - b) % 5; n   if (a == 4) cout << ans + 2; n   if (a == 3) cout << ans + 2; n   if (a == 2) cout << ans + 1; n   if (a == 1) cout << ans + 1; n   if (a == 0) cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.precision(20); n   long long t = 1; n   cin >> t; n   while (t--) { n     solve(); n     cout <<   n ; n   } n   cin.get(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int gizzly; n   cin >> gizzly; n   priority_queue<int> scoreList; n   for (int i = 1; i < n; i++) { n     int x; n     cin >> x; n     scoreList.push(x); n   } n   int candy = 0; n   while (gizzly <= scoreList.top()) { n     int opponent = scoreList.top(); n     scoreList.pop(); n     opponent -= 1; n     gizzly += 1; n     candy += 1; n     scoreList.push(opponent); n   } n   cout << candy << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, a[((int)1001 * 1000)], maxi, mini; n vector<int> v; n int jaghool; n bitset<((int)1001 * 1000)> dp, mark; n int main() { n   scanf( %d%d , &n, &k); n   int k2 = k; n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= n; i++) n     if (!mark[i]) { n       int x = a[i], p = 1; n       while (x != i) p++, mark[x] = 1, x = a[x]; n       v.push_back(p); n       maxi += min(k2, p / 2) * 2, k2 -= min(k2, p / 2); n       if (p % 2) jaghool++; n     } n   maxi += min(k2, jaghool); n   dp[0] = 1; n   sort(v.begin(), v.end()); n   v.push_back(-1); n   vector<int> v2; n   for (int i = 0, cnt = 1; i < v.size(); i++) { n     if (v[i] != v[i + 1]) { n       int x = v[i]; n       while (cnt) { n         dp |= (dp << v[i]); n         for (int j = 0; j < ((int)20); j++) { n           if ((1 << j) <= cnt && cnt < (1 << (j + 1))) { n             cnt -= (1 << j); n             break; n           } n           dp |= (dp << (v[i] << j)); n         } n       } n       cnt = 1; n     } else n       cnt++; n   } n   cout << k + 1 - dp[k] <<     << maxi <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Q, cnt = 1; n int par[400010][21], nxt[400010][21], len[400010]; n long long w[400010], sum[400010][21]; n long long mx[400010][21]; n int find_first_bigger(int u, int W) { n   if (mx[u][0] >= W) return u; n   for (int i = 18; i >= 0; i--) n     if (mx[u][i + 1] >= W && mx[u][i] < W) u = par[u][i]; n   return mx[u][0] >= W ? u : 0; n } n void add(int R, int W) { n   int u = ++cnt; n   w[u] = W; n   int fb = find_first_bigger(R, W); n   len[u] = len[fb] + 1; n   nxt[u][0] = fb; n   sum[u][0] = W; n   par[u][0] = R; n   mx[u][0] = w[u]; n   for (int i = 1; i < 21; i++) { n     nxt[u][i] = nxt[nxt[u][i - 1]][i - 1]; n     sum[u][i] = sum[nxt[u][i - 1]][i - 1] + sum[u][i - 1]; n     par[u][i] = par[par[u][i - 1]][i - 1]; n     mx[u][i] = max(mx[par[u][i - 1]][i - 1], mx[u][i - 1]); n   } n } n long long getsum(long long u, long long k) { n   if (!k) return 0; n   long long ret = 0; n   for (int i = 0; k; i++, k >>= 1) n     if (k & 1) { n       ret += sum[u][i]; n       u = nxt[u][i]; n     } n   return ret; n } n long long query(long long u, long long x) { n   long long lo = 1, hi = len[u]; n   while (lo < hi) { n     long long mid = (lo + hi) >> 1; n     long long s = getsum(u, mid); n     if (s > x) n       hi = mid; n     else n       lo = mid + 1; n   } n   if (getsum(u, lo) <= x) n     return lo; n   else if (getsum(u, lo - 1) > x) n     return 0; n   return lo - 1; n } n int main() { n   for (int i = 0; i < 400010; i++) n     for (int j = 0; j < 21; j++) mx[i][j] = -4e18; n   for (int i = 0; i < 21; i++) mx[1][0] = 0; n   len[1] = 1; n   scanf( %d , &Q); n   long long last = 0; n   while (Q--) { n     long long tt, p, q; n     scanf( %lld%lld%lld , &tt, &p, &q); n     if (tt == 1) { n       long long R = p ^ last, W = q ^ last; n       add(R, W); n     } else { n       long long R = p ^ last, X = q ^ last; n       printf( %lld n , last = query(R, X)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> vec; n   set<int> st; n   for (int i = 0; i < int(n); ++i) { n     int a; n     cin >> a; n     st.insert(i); n     vec.push_back(a); n   } n   queue<int> tok; n   int ans = 0; n   int killed = 0; n   for (int i = n - 1; i > 0; i--) { n     if (vec[i] < vec[i - 1]) { n       st.erase(i); n       ++killed; n       tok.push(i - 1); n     } n   } n   if (killed) ans++; n   queue<int> qtok; n   while (killed) { n     killed = 0; n     while (!tok.empty()) { n       int tp = tok.front(); n       tok.pop(); n       auto it = st.find(tp); n       if (it == st.end()) continue; n       auto itn = st.find(tp); n       itn++; n       if (itn == st.end()) continue; n       if (vec[*it] > vec[*itn]) { n         qtok.push(*it); n         ++killed; n         st.erase(itn); n       } n     } n     while (!qtok.empty()) { n       tok.push(qtok.front()); n       qtok.pop(); n     } n     if (killed) ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double pie = 3.14159265358979; n const long long mod = 1e9 + 7; n string vow =  aeiou ; n void solve(int test_case) { n   string f, m, s; n   cin >> f >> m >> s; n   map<string, string> beat; n   beat[ rock ] =  scissors ; n   beat[ scissors ] =  paper ; n   beat[ paper ] =  rock ; n   if (beat[f] == m && beat[f] == s) n     cout <<  F ; n   else if (beat[m] == f && beat[m] == s) n     cout <<  M ; n   else if (beat[s] == f && beat[s] == m) n     cout <<  S ; n   else n     cout <<  ? ; n   cout <<   n ; n } n int main() { n   int t = 1; n   for (int i = 0; i < t; i++) solve(i); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n, ls[310]; n int dp[110][310][310]; n pair<int, int> p[110]; n int L[110], R[110], x[110]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &p[i].first, &p[i].second); n     ls[i * 3 - 2] = p[i].first - p[i].second; n     ls[i * 3 - 1] = p[i].first; n     ls[i * 3] = p[i].first + p[i].second; n   } n   sort(p + 1, p + n + 1); n   sort(ls + 1, ls + n * 3 + 1); n   int ex = unique(ls + 1, ls + n * 3 + 1) - ls; n   for (int i = 1; i <= n; i++) { n     L[i] = lower_bound(ls + 1, ls + ex, p[i].first - p[i].second) - ls; n     x[i] = lower_bound(ls + 1, ls + ex, p[i].first) - ls; n     R[i] = lower_bound(ls + 1, ls + ex, p[i].first + p[i].second) - ls; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j < ex; j++) { n       for (int k = j; k < ex; k++) { n         dp[i][j][max(k, R[i])] = max( n             dp[i][j][max(k, R[i])], dp[i - 1][j][k] + max(0, ls[R[i]] - ls[k])); n         if (L[i] <= j) n           dp[i][0][max(k, x[i])] = n               max(dp[i][0][max(k, x[i])], n                   dp[i - 1][j][k] + max(0, ls[x[i]] - ls[k])); n       } n     } n     for (int k = 1; k < ex; k++) { n       if (k >= x[i]) n         dp[i][0][max(k, R[i])] = max( n             dp[i][0][max(k, R[i])], dp[i - 1][0][k] + max(0, ls[R[i]] - ls[k])); n       else n         dp[i][0][R[i]] = n             max(dp[i][0][R[i]], dp[i - 1][0][k] + ls[R[i]] - ls[x[i]]); n       for (int j = k; j < x[i]; j++) n         dp[i][j][R[i]] = n             max(dp[i][j][R[i]], dp[i - 1][0][k] + ls[R[i]] - ls[j]); n       if (k >= L[i]) n         dp[i][0][max(k, x[i])] = max( n             dp[i][0][max(k, x[i])], dp[i - 1][0][k] + max(0, ls[x[i]] - ls[k])); n       else n         dp[i][0][x[i]] = n             max(dp[i][0][x[i]], dp[i - 1][0][k] + ls[x[i]] - ls[L[i]]); n       for (int j = k; j < L[i]; j++) n         dp[i][j][x[i]] = n             max(dp[i][j][x[i]], dp[i - 1][0][k] + ls[x[i]] - ls[j]); n     } n   } n   int ans = 0; n   for (int i = 1; i < ex; i++) ans = max(ans, dp[n][0][i]); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ; n   return x * f; n } n const int MAXN = 200010; n const int INF = 1e9; n const int Mod = 998244353LL; n int mx; n int N; n int tms = 0; n pair<int, int> sta[MAXN * 10 + 1]; n int top; n int Node[MAXN << 1], Next[MAXN << 1], Root[MAXN + 1], cnt; n int deg[MAXN + 1]; n inline void insert(int u, int v) { n   Node[++cnt] = v; n   Next[cnt] = Root[u]; n   Root[u] = cnt; n   return; n } n inline void solve(int k, int Fa, int val) { n   if (k != 1) --deg[k]; n   int last = deg[k]; n   sta[++top] = make_pair(k, tms); n   bool flag = 0; n   if (tms == mx && val != -1) { n     tms = max(val - last, 0); n     if (tms + last != val) flag = 1; n     sta[++top] = make_pair(k, tms); n   } n   for (int x = Root[k]; x; x = Next[x]) { n     int v = Node[x]; n     if (v == Fa) continue; n     ++tms; n     --last; n     solve(v, k, ((tms == val && flag) ? tms : tms - 1)); n     ++tms; n     sta[++top] = make_pair(k, tms); n     if (tms == mx && val != -1) { n       tms = max(val - last, 0); n       if (tms + last != val) flag = 1; n       sta[++top] = make_pair(k, tms); n     } n   } n   if (val != -1 && tms > val) { n     sta[++top] = make_pair(k, val); n     tms = val; n   } n   return; n } n int main() { n   N = read(); n   for (int i = 1; i < N; i++) { n     int u = read(), v = read(); n     insert(u, v); n     insert(v, u); n     ++deg[u]; n     ++deg[v]; n   } n   mx = 0; n   for (int i = 1; i <= N; i++) mx = max(mx, deg[i]); n   solve(1, 0, -1); n   printf( %d n , top); n   for (int i = 1; i <= top; i++) printf( %d %d n , sta[i].first, sta[i].second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 600000; n const int MOD = (int)1e9 + 7; n int n, m, k, u, v, g[N]; n long long c[N], w[N]; n set<long long> s; n vector<pair<long long, pair<int, int> > > e; n int find(int cur) { return cur == g[cur] ? g[cur] : g[cur] = find(g[cur]); } n int main() { n   scanf( %d %d %d , &n, &m, &k); n   w[0] = 1; n   for (int i = 1; i <= n; i++) { n     w[i] = 2LL * w[i - 1] % MOD; n   } n   for (int i = 0; i < n; i++) { n     scanf( %lld , &c[i]); n   } n   for (int i = 0; i < m; i++) { n     scanf( %d %d , &u, &v); n     u--; n     v--; n     s.insert(c[u] ^ c[v]); n     e.push_back({c[u] ^ c[v], make_pair(u, v)}); n   } n   long long ans = (((1LL << k) - s.size()) % MOD) * w[n] % MOD; n   sort(e.begin(), e.end()); n   for (int i = 0; i < e.size();) { n     int j = i; n     while (j < e.size() && e[i].first == e[j].first) { n       j++; n     } n     for (int p = i; p < j; p++) { n       int u = e[p].second.first; n       int v = e[p].second.second; n       g[u] = u; n       g[v] = v; n     } n     int c = n; n     for (int p = i; p < j; p++) { n       int u = e[p].second.first; n       int v = e[p].second.second; n       u = find(u); n       v = find(v); n       if (u != v) { n         c--; n         g[v] = u; n       } n     } n     ans += w[c]; n     ans %= MOD; n     i = j; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, lamps[2002], sol = 0, cs; n   memset(lamps, 0, sizeof(lamps)); n   cin >> n >> m; n   string s[2002]; n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n   } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       if (s[i][j] ==  1 ) lamps[j]++; n   for (int i = 0; i < n; i++) { n     cs = 1; n     for (int j = 0; j < m; j++) { n       if (s[i][j] ==  1  && lamps[j] < 2) { n         cs = 0; n         break; n       } n     } n     if (cs == 1) { n       sol = 1; n       break; n     } n   } n   if (sol) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 200000 + 100; n const int M = 30; n vector<int> G[MAXN]; n int deep[MAXN], fa[MAXN][M]; n void DFS(int cur, int pre) { n   fa[cur][0] = pre; n   for (int i = 1; i < 20; ++i) fa[cur][i] = fa[fa[cur][i - 1]][i - 1]; n   for (int i = 0; i < G[cur].size(); i++) { n     int to = G[cur][i]; n     if (to == pre) continue; n     deep[to] = deep[cur] + 1; n     DFS(to, cur); n   } n } n int LCA(int v, int u) { n   if (deep[v] > deep[u]) swap(v, u); n   for (int i = 0; i < 20; ++i) n     if (deep[u] - deep[v] >> i & 1) u = fa[u][i]; n   for (int i = 19; i >= 0; --i) n     if (fa[v][i] != fa[u][i]) v = fa[v][i], u = fa[u][i]; n   return v == u ? v : fa[v][0]; n } n int cal(int s, int t, int f) { n   int ans = 0, sf = LCA(s, f) == f, tf = LCA(t, f) == f; n   if (sf != tf) n     return 1; n   else if (sf) n     ans = deep[LCA(s, t)] - deep[f]; n   else if (LCA(s, f) != LCA(t, f)) n     ans = deep[f] - max(deep[LCA(f, s)], deep[LCA(f, t)]); n   else n     ans = deep[LCA(s, t)] + deep[f] - 2 * deep[LCA(s, f)]; n   return ans + 1; n } n int main() { n   int n, q; n   scanf( %d%d , &n, &q); n   for (int i = 2; i <= n; ++i) { n     int x; n     scanf( %d , &x); n     G[i].push_back(x); n     G[x].push_back(i); n   } n   DFS(1, 0); n   while (q--) { n     int a, b, c; n     scanf( %d%d%d , &a, &b, &c); n     printf( %d n , max(cal(a, b, c), max(cal(b, c, a), cal(c, a, b)))); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool check(int i, int n, set<pair<int, int> >& st) { n   for (auto it : st) { n     pair<int, int> t(it.first + i, it.second + i); n     if (t.first > n) t.first %= n; n     if (t.second > n) t.second %= n; n     if (t.first > t.second) swap(t.first, t.second); n     if (!st.count(t)) return false; n   } n   return true; n } n int main() { n   int n, m, a, b; n   while (cin >> n >> m) { n     set<pair<int, int> > st; n     for (int i = 1; i <= m; i++) { n       cin >> a >> b; n       st.insert(make_pair(min(a, b), max(a, b))); n     } n     bool flg = false; n     for (int i = 1; i * i <= n; i++) { n       if (n % i == 0) { n         if (check(i, n, st)) { n           flg = true; n           break; n         } else if (i != 1 && check(n / i, n, st)) { n           flg = true; n           break; n         } n       } n     } n     cout << (flg ?  Yes  :  No ) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, k, l, n, m, s, an, K, X; n const int N = 5100; n int a[1100000], g[1100000]; n long long f[N][N]; n int main() { n   scanf( %d%d , &n, &K); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   sort(&a[1], &a[n + 1]); n   int v1 = n / K + 1; n   int v2 = n / K; n   if (n % K == 0) v1--; n   int ss = n % K; n   if (!ss) ss = K; n   ss = K - ss; n   memset(f, 120, sizeof(f)); n   f[0][0] = 0; n   for (int i = 0; i <= K; i++) n     for (int j = 0; j <= ss; j++) { n       int now = j * v2 + (i - j) * v1; n       f[i + 1][j] = min(f[i + 1][j], f[i][j] + a[now + v1] - a[now + 1]); n       f[i + 1][j + 1] = n           min(f[i + 1][j + 1], f[i][j] + a[now + v2] - a[now + 1]); n     } n   printf( %I64d n , f[K][ss]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fun(long long a[], long long remain, long long total, long long n, n          long long m) { n   vector<long long> ans; n   long long i, j; n   for (i = 0; i < n && total > 0; i++) { n     if (a[i] % m == remain) { n       ans.push_back(a[i]); n       total--; n     } n   } n   sort(ans.begin(), ans.end()); n   for (i = 0; i < ans.size(); i++) cout << ans[i] <<    ; n } n int main() { n   long long t, n, i, j, k, m; n   t = 1; n   while (t--) { n     cin >> n >> k >> m; n     map<long long, long long> x; n     long long a[n], flag = 0; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n       x[a[i] % m]++; n     } n     for (auto itr = x.begin(); itr != x.end(); itr++) { n       if (itr->second >= k) { n         flag = 1; n         cout <<  Yes  << endl; n         fun(a, itr->first, k, n, m); n         break; n       } n     } n     if (flag == 0) cout <<  No  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool isprime(long long int n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long int i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n int main() { n   int t; n   cin >> t; n   string y =  YES n , z =  NO n ; n   while (t--) { n     long long int a, b, i, j; n     cin >> a >> b; n     if (a - b != 1) n       cout << z; n     else { n       if (isprime(a + b)) n         cout << y; n       else n         cout << z; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   long long ans = 0; n   for (int i = (0); i < (n); ++i) { n     long long t, T, x, cost; n     cin >> t >> T >> x >> cost; n     if (t >= T) { n       ans += cost + m * x; n       continue; n     } n     long long aux1 = cost; n     if (m > (T - t)) aux1 += m * x; n     long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1; n     aux2 *= cost; n     ans += min(aux1, aux2); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int n = 0; n   while (s.at(n) !=  . ) n++; n   if (s.at(n - 1) ==  9 ) n     cout <<  GOTO Vasilisa. ; n   else { n     if (s.at(n + 1) < 53) n       cout << s.substr(0, n); n     else { n       cout << s.substr(0, n - 1); n       cout << (char)(s.at(n - 1) + 1); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   while (scanf( %I64d , &n) != EOF) { n     long long x, y, l, h, mid; n     l = 0, h = 1e18 + 7; n     while (l < h - 1) { n       mid = (l + h) >> 1; n       if (n / (3 * mid) >= mid + 1) n         l = mid; n       else n         h = mid; n     } n     x = 2 * l; n     y = 0; n     long long ret = n - 3 * l * (l + 1); n     l++; n     if (ret >= 1) { n       x++; n       y += 2; n       if (ret <= l) { n         x -= ret - 1; n         y += 2 * (ret - 1); n       } else { n         x -= l - 1; n         y += 2 * (l - 1); n         if (ret <= 2 * l) { n           x -= 2 * (ret - l); n         } else { n           x -= 2 * l; n           if (ret <= 3 * l) { n             x -= ret - 2 * l; n             y -= 2 * (ret - 2 * l); n           } else { n             x -= l; n             y -= 2 * l; n             if (ret <= 4 * l) { n               x += ret - 3 * l; n               y -= 2 * (ret - 3 * l); n             } else { n               x += l; n               y -= 2 * l; n               if (ret <= 5 * l) { n                 x += 2 * (ret - 4 * l); n               } else { n                 x += 2 * l; n                 x += ret - 5 * l; n                 y += 2 * (ret - 5 * l); n               } n             } n           } n         } n       } n     } n     printf( %I64d %I64d n , x, y); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 4e5 + 10; n int n, a[M], b[M], ans, cnt; n int f(int x, int i) { n   return n - (x >> i) - (lower_bound(b, b + n, (1 << (i + 1)) - x) - b); n } n int32_t main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , a + i); n   for (int i = 0; i < 28; i++) { n     for (int j = 0; j < n; j++) b[j] = (a[j] & ((1 << (i + 1)) - 1)); n     sort(b, b + n); n     cnt = 0; n     for (int j = 0; j < n; j++) cnt += f(b[j], i); n     ans += (((cnt >> 1) & 1) << (i + 1)); n   } n   if (n % 2 == 0) n     for (int i = 0; i < n; i++) ans ^= a[i]; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double PI = acos(-1); n const long long MOD = 1000000007; n const long long FMOD = 998244353; n long long cnt1, cnt2, x, y; n bool isSafe(long long mid) { n   long long div1 = mid / x; n   long long div2 = mid / y; n   long long div3 = mid / (x * y); n   long long no = mid - (div1 + div2 - div3); n   long long p = div1 - div3; n   long long q = div2 - div3; n   long long ans1 = cnt1 - q; n   long long ans2 = cnt2 - p; n   if (ans1 < 0) ans1 = 0; n   if (ans2 < 0) ans2 = 0; n   return (ans1 + ans2) <= no; n } n signed main() { n   cin >> cnt1 >> cnt2 >> x >> y; n   long long beg = 0, end = 1e10; n   long long ans = 0; n   while (beg <= end) { n     long long mid = (beg + end) / 2; n     if (isSafe(mid)) { n       ans = mid; n       end = mid - 1; n     } else { n       beg = mid + 1; n     } n   } n   cout << ans; n } n


/*/ Author: Aniruddh Lawande /*/ n #include<bits/stdc++.h> n using namespace std; n  n /*/---------------------------Defines----------------------/*/ n   n #define ll long long n #define F first n #define S second n #define pb push_back n #define endl   n  n #define all(v) (v).begin(),(v).end() n  n typedef pair<ll,ll> pii; n /*/-----------------------Modular Arithmetic---------------/*/ n   n const long long INF = 1ll << 32;  n const int mod=1e9+7; n inline int add(int x,int y){ n     x+=y; n     if (x>=mod) return x-mod; n     return x; n } n inline int sub(int x,int y){ n     x-=y; n     if (x<0) return x+mod; n     return x; n } n inline int mul(int x,int y){ n     return (x*1ll*y)%mod; n } n inline int power(int x,int y){ n     int ans=1; n     while(y){ n         if (y&1) ans=mul(ans,x); n         x=mul(x,x); n         y>>=1; n     } n     return ans; n } n inline int inv(int x){ n     return power(x,mod-2); n } n  n const ll FACTORIAL_SIZE = 1.1e6; n ll fact[FACTORIAL_SIZE], ifact[FACTORIAL_SIZE]; n void gen_factorial(ll n) { n  fact[0] = fact[1] = ifact[0] = ifact[1] = 1; n    n  for (ll i = 2; i <= n; i++) { n   fact[i] = (i * fact[i - 1]) % mod; n  } n  ifact[n] = inv(fact[n]); n  for (ll i = n - 1; i >= 2; i--) { n   ifact[i] = ((i + 1) * ifact[i + 1]) % mod; n  } n } n  n  n ll nck(ll n, ll k) { n  ll den = (ifact[k] * ifact[n - k]) % mod; n  return (den * fact[n]) % mod; n } n  n /*/-----------------------------Code begins----------------------------------/*/ n const int N=2e5+5; n  n void solve() n { n     ll d,k; n     cin>>d>>k; n     ll x=0,y=0; n     ll i=0; n     while(x*x+y*y<=d*d) n     { n         if(i%2==0) n         { n             if((x+k)*(x+k)+y*y<=d*d) x+=k; n             else break; n         } n         else n         { n             if(x*x+(y+k)*(y+k)<=d*d) y+=k; n             else break; n         } n         i++; n     } n     if(i%2!=0) n     { n         cout<< Ashish <<endl; n     } n     else n     { n         cout<< Utkarsh <<endl; n     } n      n } n  n  n  n int main() n { n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n     cout.tie(NULL); n  int tc=1; n  cin>>tc; n     int i=1; n  while(tc--) n  { n         //cout<< CASE # <<i<< :  ; n   solve(); n         i++; n  } n  return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int N = 2e5L + 11, M = N * 2; n int a[M], b[M], c[M]; n int back[M]; n struct SegTree { n   ll flag[N * 8]; n   ll val[N * 4]; n   void push(int x) { n     val[x] += flag[x]; n     flag[2 * x] += flag[x]; n     flag[2 * x + 1] += flag[x]; n     flag[x] = 0; n   } n   void change(int l, int r, int ql, int qr, int c, int x = 1) { n     push(x); n     if (ql == l && qr == r) { n       flag[x] = c; n       push(x); n     } else { n       if (qr <= (l + r) / 2) { n         change(l, (l + r) / 2, ql, qr, c, 2 * x); n         push(2 * x + 1); n       } else if (ql >= (l + r) / 2) { n         push(2 * x); n         change((l + r) / 2, r, ql, qr, c, 2 * x + 1); n       } else { n         change(l, (l + r) / 2, ql, (l + r) / 2, c, 2 * x); n         change((l + r) / 2, r, (l + r) / 2, qr, c, 2 * x + 1); n       } n       val[x] = min(val[2 * x], val[2 * x + 1]); n     } n   } n   ll query(int l, int r, int ql, int qr, int x = 1) { n     push(x); n     if (ql == l && qr == r) return val[x]; n     if (qr <= (l + r) / 2) n       return query(l, (l + r) / 2, ql, qr, 2 * x); n     else if (ql >= (l + r) / 2) n       return query((l + r) / 2, r, ql, qr, 2 * x + 1); n     else n       return min(query(l, (l + r) / 2, ql, (l + r) / 2, 2 * x), n                  query((l + r) / 2, r, (l + r) / 2, qr, 2 * x + 1)); n   } n } st; n vector<int> e[N]; n int cnt = 0; n int in[N], out[N], id[N]; n void dfs(int x) { n   id[x] = ++cnt; n   in[x] = cnt; n   for (int i : e[x]) dfs(i); n   out[x] = cnt; n } n int n; n ll query(int x) { return st.query(1, n + 1, id[x], id[x] + 1) - back[x]; } n int main() { n   int q; n   cin >> n >> q; n   for (int i = 1; i <= 2 * n - 2; i++) { n     scanf( %d%d%d , a + i, b + i, c + i); n     if (i <= n - 1) n       e[a[i]].push_back(b[i]); n     else n       back[a[i]] = c[i]; n   } n   dfs(1); n   for (int i = 1; i <= n - 1; i++) n     st.change(1, n + 1, in[b[i]], out[b[i]] + 1, c[i]); n   for (int i = 2; i <= n; i++) st.change(1, n + 1, id[i], id[i] + 1, back[i]); n   while (q--) { n     int t, u, v; n     scanf( %d%d%d , &t, &u, &v); n     if (t == 1) { n       int i = u, w = v; n       if (i <= n - 1) { n         st.change(1, n + 1, in[b[i]], out[b[i]] + 1, w - c[i]); n         c[i] = w; n       } else { n         st.change(1, n + 1, id[a[i]], id[a[i]] + 1, w - c[i]); n         back[a[i]] = w; n         c[i] = w; n       } n     } else { n       ll ans = st.query(1, n + 1, in[u], out[u] + 1) - query(u) + query(v); n       if (id[v] >= in[u] && id[v] <= out[u]) n         ans = min(ans, query(v) - query(u)); n       printf( %lld n , ans); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e17 + 7; n const long long maxn = 5e5 + 700; n const int mod = 998244353; n const int up = 1e9; n template <typename T> n inline void read(T &a) { n   char c = getchar(); n   T x = 0, f = 1; n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = (x << 1) + (x << 3) + c -  0 ; n     c = getchar(); n   } n   a = f * x; n } n long long n, m, p; n int num[maxn], b[maxn]; n struct Dinic { n   long long cnt = 2; n   struct Edge { n     int e, next; n     long long w; n   }; n   int _S, _T, N; n   int head[maxn], d[maxn], cur[maxn]; n   Edge edge[maxn]; n   void _inint(int s, int t, int n) { n     memset(head, 0, sizeof(head)); n     cnt = 2; n     _S = s, _T = t, N = n; n   } n   void addedge(int u, int v, long long w) { n     edge[cnt] = Edge{v, head[u], w}; n     head[u] = cnt++; n   } n   void Add(int u, int v, long long w) { n     addedge(u, v, w); n     addedge(v, u, 0); n   } n   bool bfs() { n     for (int k = 0; k <= N; k++) d[k] = 0; n     queue<int> q; n     q.push(_S); n     d[_S] = 1; n     while (!q.empty()) { n       int u = q.front(); n       q.pop(); n       for (int i = head[u]; i; i = edge[i].next) { n         int e = edge[i].e; n         if (edge[i].w <= 0 || d[e]) continue; n         d[e] = d[u] + 1; n         q.push(e); n       } n     } n     for (int k = 0; k <= N; k++) cur[k] = head[k]; n     return (d[_T] != 0); n   } n   long long dfs(int u, long long flow) { n     if (u == _T) return flow; n     for (int &i = cur[u]; i; i = edge[i].next) { n       int e = edge[i].e; n       if (d[e] != d[u] + 1 || edge[i].w <= 0) continue; n       long long temp = dfs(e, min(flow, edge[i].w)); n       if (temp <= 0) continue; n       edge[i].w -= temp; n       edge[i ^ 1].w += temp; n       return temp; n     } n     return 0; n   } n   long long MaxFlow() { n     long long maxflow = 0, delta = 0; n     while (bfs()) { n       while (delta = dfs(_S, INF)) maxflow += delta; n     } n     return maxflow; n   } n   vector<int> v[maxn]; n   int col[maxn]; n   vector<vector<int>> res; n   void dfs(int u, vector<int> &a) { n     col[u] = 1; n     a.push_back(u); n     for (int e : v[u]) { n       if (col[e]) continue; n       dfs(e, a); n     } n   } n   void AC() { n     long long temp = MaxFlow(); n     if (temp == N - 1) { n       for (int i = 1; i <= n; i++) { n         if (!(num[i] & 1)) continue; n         for (int k = head[i]; k; k = edge[k].next) { n           int e = edge[k].e; n           if (edge[k ^ 1].w) { n             v[e].push_back(i); n             v[i].push_back(e); n           } n         } n       } n       for (int i = 1; i <= n; i++) { n         if (!col[i]) { n           vector<int> temp; n           dfs(i, temp); n           res.push_back(temp); n         } n       } n       printf( %d n , res.size()); n       for (auto x : res) { n         printf( %d  , x.size()); n         for (int y : x) printf( %d  , y); n         printf(  n ); n       } n     } else n       printf( Impossible n ); n   } n } g; n int judge(int x) { n   for (int i = 2; i * i <= x; i++) n     if (x % i == 0) return 0; n   return 1; n } n int main() { n   read(n); n   g._inint(0, n + 1, n + 1); n   for (int i = 1; i <= n; i++) { n     read(num[i]); n     if (num[i] & 1) n       g.Add(0, i, 2); n     else n       g.Add(i, n + 1, 2); n   } n   for (int i = 1; i <= n; i++) { n     for (int k = i + 1; k <= n; k++) { n       if (judge(num[i] + num[k])) { n         if (num[i] & 1) n           g.Add(i, k, 1); n         else n           g.Add(k, i, 1); n       } n     } n   } n   g.AC(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 30, Mod = 1e9 + 7; n const long long SQ = 330; n map<long long, vector<long long> > mp; n pair<long long, long long> E[N]; n long long p[N], sz[N], M[N], cnt[N]; n vector<long long> G[N]; n long long r[N], ans[N]; n void DFS(long long v, long long R) { n   cnt[v] = sz[v]; n   M[v] = 1; n   r[v] = R; n   for (auto u : G[v]) { n     if (!M[u]) { n       DFS(u, R); n       cnt[v] += cnt[u]; n     } n   } n } n long long get(long long x) { return (p[x] ? p[x] = get(p[x]) : x); } n void add(long long x, long long y) { n   x = get(x); n   y = get(y); n   if (x == y) return; n   if (rand() % 2) swap(x, y); n   p[x] = y; n   sz[y] += sz[x]; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   long long n; n   cin >> n; n   fill(sz, sz + N, 1); n   for (int i = 1; i < n; i++) { n     long long v, u, w; n     cin >> v >> u >> w; n     mp[w].push_back(i); n     E[i] = {v, u}; n   } n   for (auto R : mp) { n     vector<long long> V = R.second; n     set<long long> second; n     for (auto x : V) { n       second.insert(get(E[x].first)); n       second.insert(get(E[x].second)); n     } n     for (auto x : second) G[x].clear(), M[x] = false, cnt[x] = 0; n     for (auto x : V) { n       G[get(E[x].first)].push_back(get(E[x].second)); n       G[get(E[x].second)].push_back(get(E[x].first)); n     } n     for (auto u : second) n       if (!M[u]) DFS(u, u); n     for (auto x : V) { n       long long v = E[x].first, u = E[x].second; n       v = get(v); n       u = get(u); n       if (cnt[v] > cnt[u]) swap(v, u); n       ans[x] = cnt[v] * (cnt[r[v]] - cnt[v]); n     } n     for (auto x : V) add(E[x].first, E[x].second); n   } n   long long mx = 0; n   for (int i = 1; i < n; i++) mx = max(mx, ans[i]); n   long long C = 0; n   for (int i = 1; i < n; i++) n     if (ans[i] == mx) C++; n   cout << 2 * mx <<     << C <<   n ; n   for (int i = 1; i < n; i++) n     if (ans[i] == mx) cout << i <<    ; n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, l = 0, r = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     bool a, b; n     cin >> a >> b; n     l += a; n     r += b; n   } n   int left = 2 * l > n ? (n - l) : l; n   int right = 2 * r > n ? (n - r) : r; n   int count = left + right; n   cout << count; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll MOD = 1e9 + 7; n class SegTree { n  private: n   const ll NEUT = 0; n   vector<ll> seg, tag; n   int h = 1; n   ll len(int i) { return h >> (31 - __builtin_clz(i)); } n   void apply(int i, ll v) { n     seg[i] = (seg[i] + v * len(i)) % MOD; n     if (i < h) tag[i] = (tag[i] + v) % MOD; n   } n   void push(int i) { n     if (tag[i] == 0) return; n     apply(2 * i, tag[i]); n     apply(2 * i + 1, tag[i]); n     tag[i] = 0; n   } n   ll combine(ll a, ll b) { return (a + b) % MOD; } n   ll recGet(int a, int b, int i, int ia, int ib) { n     if (ib <= a || b <= ia) return NEUT; n     if (a <= ia && ib <= b) return seg[i]; n     push(i); n     int im = (ia + ib) >> 1; n     return combine(recGet(a, b, 2 * i, ia, im), n                    recGet(a, b, 2 * i + 1, im, ib)); n   } n   void recApply(int a, int b, ll v, int i, int ia, int ib) { n     if (ib <= a || b <= ia) return; n     if (a <= ia && ib <= b) n       apply(i, v); n     else { n       push(i); n       int im = (ia + ib) >> 1; n       recApply(a, b, v, 2 * i, ia, im); n       recApply(a, b, v, 2 * i + 1, im, ib); n       seg[i] = combine(seg[2 * i], seg[2 * i + 1]); n     } n   } n  n  public: n   SegTree(int n) { n     while (h < n) h *= 2; n     seg.resize(2 * h, NEUT); n     tag.resize(h, 0); n   } n   ll rangeSum(int a, int b) { return recGet(a, b + 1, 1, 0, h); } n   void rangeAdd(int a, int b, ll v) { recApply(a, b + 1, v, 1, 0, h); } n }; n class HLD { n  private: n   vector<int> par, siz, cmp, ind; n   void dfs1(int i, vector<vector<int>>& g) { n     for (auto& t : g[i]) { n       if (t == par[i]) continue; n       par[t] = i; n       dfs1(t, g); n       siz[i] -= siz[t]; n       if (siz[t] > siz[g[i][0]]) swap(t, g[i][0]); n     } n     siz[i] *= -1; n   } n   void dfs2(int i, int& x, const vector<vector<int>>& g) { n     ind[i] = x; n     ++x; n     for (auto t : g[i]) { n       if (t == par[i]) continue; n       cmp[t] = (x == ind[i] + 1 ? cmp[i] : t); n       dfs2(t, x, g); n     } n   } n  n  public: n   HLD(vector<vector<int>> g, int r = 0) n       : par(g.size(), -1), siz(g.size(), -1), cmp(g.size(), r), ind(g.size()) { n     dfs1(r, g); n     int x = 0; n     dfs2(r, x, g); n   } n   const vector<pair<int, int>>& path(int a, int b) const { n     static vector<pair<int, int>> res; n     res.clear(); n     for (;; b = par[cmp[b]]) { n       if (ind[b] < ind[a]) swap(a, b); n       if (ind[cmp[b]] <= ind[a]) { n         res.push_back({ind[a], ind[b]}); n         return res; n       } n       res.push_back({ind[cmp[b]], ind[b]}); n     } n   } n   pair<int, int> subtree(int i) const { return {ind[i], ind[i] + siz[i] - 1}; } n   int lca(int a, int b) const { n     for (;; b = par[cmp[b]]) { n       if (ind[b] < ind[a]) swap(a, b); n       if (ind[cmp[b]] <= ind[a]) return a; n     } n   } n   bool deeper(int a, int b) { return siz[a] < siz[b]; } n }; n ll modPow(ll a, ll b) { n   if (b & 1) return a * modPow(a, b - 1) % MOD; n   if (b == 0) return 1; n   return modPow(a * a % MOD, b / 2); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   ll colc = 1; n   vector<ll> weight(n); n   vector<pair<int, int>> evs; n   for (int i = 0; i < n; ++i) { n     int a, b; n     cin >> a >> b; n     evs.push_back({a, i + 1}); n     evs.push_back({b + 1, -(i + 1)}); n     colc = (colc * (b - a + 1)) % MOD; n     weight[i] = modPow(b - a + 1, MOD - 2); n   } n   sort(evs.begin(), evs.end()); n   vector<vector<int>> g(n); n   for (int i = 0; i < n - 1; ++i) { n     int a, b; n     cin >> a >> b; n     --a; n     --b; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   HLD hld(g); n   ll cur = 0; n   ll res = 0; n   SegTree above(n), below(n); n   int c = 0; n   for (int j = 0; j < evs.size(); ++j) { n     int nc = evs[j].first; n     res = (res + cur * (nc - c)) % MOD; n     c = nc; n     int i = abs(evs[j].second) - 1; n     ll v = (evs[j].second < 0 ? MOD - 1 : 1) * weight[i] % MOD; n     vector<pair<int, int>> path = hld.path(i, 0); n     int pi = n - 1; n     for (auto pr : path) { n       cur = (cur + v * below.rangeSum(pr.second + 1, pi)) % MOD; n       above.rangeAdd(pr.second + 1, pi, v); n       cur = (cur + v * above.rangeSum(pr.first, pr.second)) % MOD; n       below.rangeAdd(pr.first, pr.second, v); n       pi = pr.first - 1; n     } n   } n   res = (res * colc) % MOD; n   if (res < 0) res += MOD; n   cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7, NMAX = 100010; n int N, M; n int color[NMAX]; n vector<int> Left[NMAX], Right[NMAX]; n void DFS(int node, int current_color) { n   if (color[node] && color[node] != current_color) { n     cout <<  0 n ; n     exit(0); n   } n   if (color[node] == 0) { n     color[node] = current_color; n     for (int i = 0; i < int(Left[node].size()); ++i) n       DFS(Left[node][i], current_color); n     for (int i = 0; i < int(Right[node].size()); ++i) n       DFS(Right[node][i], 3 - current_color); n   } n } n int FastExponentiation(int exponent) { n   int base = 2, ret = 1; n   while (exponent) { n     if (exponent & 1) ret = (int64_t(ret) * base) % MOD; n     base = (int64_t(base) * base) % MOD; n     exponent >>= 1; n   } n   return ret; n } n int main() { n   ios_base::sync_with_stdio(false); n   int i, x, y, c; n   cin >> N >> M; n   while (M--) { n     cin >> x >> y >> c; n     c == 1 ? (Left[x].push_back(y), Left[y].push_back(x)) n            : (Right[x].push_back(y), Right[y].push_back(x)); n   } n   int components = 0; n   for (i = 1; i <= N; ++i) { n     if (color[i]) continue; n     DFS(i, 1); n     ++components; n   } n   cout << FastExponentiation(components - 1) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int current = 0; n   int i = 1, i2 = 2; n   int ans = 0; n   while (current + i <= n) { n     current += i; n     ans++; n     i += i2; n     i2++; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int n = 0, m = 0; n char** values; n bool** values1; n void PrintArray() { n   cout <<  Values n ; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cout << values[i][j] <<    ; n     } n     cout << endl; n   } n   cout <<  Values1 n ; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cout << values1[i][j] <<    ; n     } n     cout << endl; n   } n } n void Check(int i, int j) { n   char valueToCheck = values[i][j]; n   if (i == n - 1) goto second; n   for (int i1 = i + 1; i1 < n; i1++) { n     if (valueToCheck == values[i1][j]) { n       values1[i][j] = true; n       values1[i1][j] = true; n     } n   } n second: n   if (j == m - 1) return; n   for (int j1 = j + 1; j1 < m; j1++) { n     if (valueToCheck == values[i][j1]) { n       values1[i][j] = true; n       values1[i][j1] = true; n     } n   } n } n void ConstructString() { n   string result =   ; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (values1[i][j] != true) result += values[i][j]; n     } n   } n   cout << result; n } n int main() { n   string str, temp; n   cin >> n >> m; n   values = new char*[n + 1]; n   values1 = new bool*[n + 1]; n   for (int i = 0; i < n; i++) { n     values[i] = new char[m + 1]; n     values1[i] = new bool[m + 1]; n     memset(values1[i], 0, m + 1); n     cin >> values[i]; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (values[i][j] ==  * ) continue; n       Check(i, j); n     } n   } n   ConstructString(); n   for (int i = 0; i < n; ++i) { n     delete[] values[i]; n     delete[] values1[i]; n   } n   delete[] values; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Imx = 2147483647; n const long long Lbig = 2e18; n const int mod = 1e9 + 7; n struct fastio { n   char s[100000]; n   int it, len; n   fastio() { it = len = 0; } n   inline char get() { n     if (it < len) return s[it++]; n     it = 0; n     len = fread(s, 1, 100000, stdin); n     if (len == 0) n       return EOF; n     else n       return s[it++]; n   } n   bool notend() { n     char c = get(); n     while (c ==     || c ==   n ) c = get(); n     if (it > 0) it--; n     return c != EOF; n   } n } _buff; n inline long long getnum() { n   long long r = 0; n   bool ng = 0; n   char c; n   c = _buff.get(); n   while (c !=  -  && (c <  0  || c >  9 )) c = _buff.get(); n   if (c ==  - ) ng = 1, c = _buff.get(); n   while (c >=  0  && c <=  9 ) r = r * 10 + c -  0 , c = _buff.get(); n   return ng ? -r : r; n } n template <class T> n inline void putnum(T x) { n   if (x < 0) putchar( - ), x = -x; n   register short a[20] = {}, sz = 0; n   while (x) a[sz++] = x % 10, x /= 10; n   if (sz == 0) putchar( 0 ); n   for (int i = sz - 1; i >= 0; i--) putchar( 0  + a[i]); n } n inline char getreal() { n   char c = _buff.get(); n   while (c <= 32) c = _buff.get(); n   return c; n } n long long qpow(long long x, long long k) { n   return k == 0 ? 1 n                 : 1ll * qpow(1ll * x * x % mod, k >> 1) * (k & 1 ? x : 1) % mod; n } n char s[100111]; n bitset<100005> ch[26], A, all; n char t[100111]; n int main() { n   scanf( %s , s); n   int n = strlen(s); n   for (int i = 0; i < n; i++) ch[s[i] -  a ][i] = 1, all[i] = 1; n   int q; n   scanf( %d , &q); n   while (q--) { n     int op, x; n     scanf( %d%d , &op, &x); n     x--; n     if (op == 1) { n       char c = getchar(); n       while (c <  a  || c >  z ) c = getchar(); n       ch[s[x] -  a ][x] = 0; n       s[x] = c; n       ch[s[x] -  a ][x] = 1; n     } else { n       int y; n       scanf( %d , &y); n       y--; n       scanf( %s , t); n       int l = strlen(t); n       A = (all >> (n - (y - x + 1) + l - 1)) << x; n       for (int i = 0; i < l; i++) A = (A & ch[t[i] -  a ]) << 1; n       printf( %d n , A.count()); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int dig(long long int n) { n   long long int r = 0; n   while (n) { n     ++r; n     n = n / 10; n   } n   return (r - 1); n } n long long int func(long long int n) { n   if (n <= 9) return (n + 1); n   long long int lt = dig(n); n   lt = pow(10, lt); n   long long int ret = lt - 1; n   long long int mul = ret / 10; n   long long int mid = (n % lt) / 10; n   lt = n / lt; n   long long int rt = n % 10; n   if (rt >= lt) { n     return (lt * (mul + 1) + func(ret)); n   } else { n     return (lt * (mul + 1) + func(ret)); n   } n } n long long int fun(long long int n) { n   if (n <= 9) return (n + 1); n   long long int lt = dig(n); n   lt = pow(10, lt); n   long long int ret = lt - 1; n   long long int mul = ret / 10; n   long long int mid = (n % lt) / 10; n   lt = n / lt; n   long long int rt = n % 10; n   if (rt >= lt) { n     return ((mid + 1) + (lt - 1) * (mul + 1) + func(ret)); n   } else { n     return (mid + (lt - 1) * (mul + 1) + func(ret)); n   } n } n int main() { n   long long int l, r; n   cin >> l >> r; n   cout << fun(r) - fun(l - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int a, b, c; n   cin >> a >> b >> c; n   cout << a * b + (a + b - 1) * (c - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double inf = 1e14; n const double pi = acos(-1); n const double eps = 1e-10; n const int maxn = 25010; n int n, x[maxn], y[maxn], dx[maxn], dy[maxn], s[maxn]; n double ans = inf, ddx[maxn], ddy[maxn], K[maxn], B[maxn]; n inline double solve(int a, int b) { n   double b1, k1, b2, k2; n   k1 = K[a]; n   b1 = B[a]; n   k2 = K[b]; n   b2 = B[b]; n   if (k1 == k2) { n     double kk = n         sqrt((x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b])); n     double X, Y, XX, YY, t; n     t = kk / double(s[a] + s[b]); n     X = (double)x[a] + (double)ddx[a] * t * s[a]; n     Y = (double)y[a] + (double)ddy[a] * t * s[a]; n     XX = (double)x[b] + (double)ddx[b] * t * s[b]; n     YY = (double)y[b] + (double)ddy[b] * t * s[b]; n     if (abs(X - XX) <= eps && abs(Y - YY) <= eps) return t; n     if (s[a] == s[b]) return inf; n     t = kk / double(s[a]); n     X = (double)x[a] + (double)ddx[a] * t * s[a]; n     Y = (double)y[a] + (double)ddy[a] * t * s[a]; n     if (abs(X - x[b]) <= eps && abs(Y - y[b]) <= eps) return t; n     t = kk / double(s[b]); n     X = (double)x[b] + (double)ddx[b] * t * s[b]; n     Y = (double)y[b] + (double)ddy[b] * t * s[b]; n     if (abs(X - x[a]) <= eps && abs(Y - y[a]) <= eps) return t; n     return inf; n   } n   double X = (b2 - b1) / (k1 - k2), Y; n   Y = k1 * X + b1; n   if ((Y - y[a]) * dy[a] < 0) return inf; n   if ((Y - y[b]) * dy[b] < 0) return inf; n   if ((X - x[a]) * dx[a] < 0) return inf; n   if ((X - x[b]) * dx[b] < 0) return inf; n   double now1 = sqrt((X - x[a]) * (X - x[a]) + (Y - y[a]) * (Y - y[a])) / s[a]; n   double now2 = sqrt((X - x[b]) * (X - x[b]) + (Y - y[b]) * (Y - y[b])) / s[b]; n   return max(now1, now2); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d%d%d%d%d , &x[i], &y[i], &dx[i], &dy[i], &s[i]); n     double v = sqrt(dx[i] * dx[i] + dy[i] * dy[i]); n     ddx[i] = dx[i] / v; n     ddy[i] = dy[i] / v; n     K[i] = (double)dy[i] / dx[i]; n     B[i] = y[i] - (double)dy[i] / dx[i] * x[i]; n   } n   for (int i = 1; i <= n; ++i) n     for (int j = i + 1; j <= n; ++j) { n       ans = min(ans, solve(i, j)); n     } n   if (ans > 1e12) n     printf( No show :( n ); n   else n     printf( %.15f n , ans); n   return 0; n } n


#include<iostream> n typedef long long ll; n using namespace std; n  n const int maxn =1e5+5; n int n,q; n ll sum[maxn]; n string s; n  n int main() { n     cin>>n>>q; n     cin>>s; n     s =  # +s; n     for(int i=1;i<=n;i++) sum[i] = sum[i-1]+s[i]- a +1; n     while (q--) { n         int l,r; n         cin>>l>>r; n         cout<<sum[r]-sum[l-1]<<endl; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int n, a[100010]; n int la, ra; n void update(int i, int delta) { n   for (; i < n; i = i | (i + 1)) { n     a[i] += delta; n   } n } n int get(int fr, int to) { n   int res = 0; n   for (int i = to; i >= 0; i = (i & (i + 1)) - 1) { n     res += a[i]; n   } n   for (int i = fr - 1; i >= 0; i = (i & (i + 1)) - 1) { n     res -= a[i]; n   } n   return res; n } n int main(void) { n   int q; n   scanf( %d%d , &n, &q); n   for (int i = 0; i < n; ++i) { n     update(i, 1); n   } n   int la = 0; n   int ra = n; n   for (int i = 0; i < q; ++i) { n     int t; n     scanf( %d , &t); n     if (t == 1) { n       int p, len, mid; n       scanf( %d , &p); n       if (la < ra) { n         len = ra - la; n         mid = la + p; n       } else { n         len = la - ra; n         mid = la - p; n       } n       if (p > len / 2) { n         swap(la, ra); n         p = len - p; n       } n       if (la < ra) { n         for (int i = 0; i < p; ++i) { n           update(mid + i, get(mid - 1 - i, mid - 1 - i)); n         } n       } else { n         for (int i = 0; i < p; ++i) { n           update(mid - 1 - i, get(mid + i, mid + i)); n         } n       } n       la = mid; n     } else { n       int l, r; n       scanf( %d%d , &l, &r); n       if (la < ra) { n         l += la; n         r += la; n       } else { n         l = la - l; n         r = la - r; n         swap(l, r); n       } n       printf( %d n , get(l, r - 1)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const short maxn = 5000 + 5; n const int mod = 1000000000 + 7; n int n; n short x[maxn], y[maxn]; n short d[maxn][maxn]; n short md; n char col[maxn]; n void dfs(int x) { n   for (int i = 0, _n = (int)(n); i < _n; i++) n     if (d[x][i] > md) { n       if (col[x] == col[i]) throw 0; n       if (col[i]) continue; n       col[i] = 3 - col[x]; n       dfs(i); n     } n } n int cnt() { n   memset(col, 0, sizeof col); n   int r = 1; n   for (int i = 0, _n = (int)(n); i < _n; i++) n     if (col[i] == 0) { n       col[i] = 1; n       try { n         dfs(i); n       } catch (...) { n         return 0; n       } n       (r += r) >= mod ? r -= mod : 0; n     } n   return r; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 0, _n = (int)(n); i < _n; i++) cin >> x[i] >> y[i]; n   for (int i = 0, _n = (int)(n); i < _n; i++) n     for (int j = (int)(i + 1), _n = (int)(n); j < _n; j++) n       d[i][j] = d[j][i] = abs(x[i] - x[j]) + abs(y[i] - y[j]); n   short lo = -1, hi = 10000; n   while (lo + 1 < hi) { n     md = (lo + hi) / 2; n     if (cnt() != 0) n       hi = md; n     else n       lo = md; n   } n   md = hi; n   cout << hi << endl << cnt() << endl; n   { n     int _; n     cin >> _; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, A, B; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   while (n--) { n     cin >> A >> B; n     cout << A * (long long)log10(B + 1) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int u, v; n   long long g, s; n   bool operator<(const edge &cmp) const { return s < cmp.s; } n } e[50005], a[50005]; n int n, m, cnt, p[205], tam; n long long gt, st; n bool cmpG(edge a, edge b) { return a.g < b.g; } n int find(int x) { n   if (p[x] == x) return x; n   return p[x] = find(p[x]); n } n bool link(int &a, int &b) { n   if (find(a) == find(b)) return false; n   p[find(a)] = find(b); n   return true; n } n long long kruskal() { n   long long res = 0; n   cnt = 0; n   for (int i = 1; i <= n; ++i) p[i] = i; n   sort(a, a + tam); n   for (int i = 0; i < tam; ++i) { n     if (link(a[i].u, a[i].v)) { n       res = a[i].s; n       a[cnt++] = a[i]; n     } n   } n   tam = cnt; n   return res; n } n int main() { n   scanf( %d%d , &n, &m); n   scanf( %I64d%I64d , &gt, &st); n   long long res = 1ll << 62, sil; n   cnt = tam = 0; n   for (int i = 0; i < m; ++i) { n     scanf( %d%d%I64d%I64d , &e[i].u, &e[i].v, &e[i].g, &e[i].s); n     e[i].g *= gt; n     e[i].s *= st; n   } n   sort(e, e + m, cmpG); n   for (int i = 0; i < m; ++i) { n     a[tam++] = e[i]; n     sil = kruskal(); n     if (cnt == n - 1) { n       sil += e[i].g; n       if (sil < res) res = sil; n     } n   } n   if (res < 1ll << 62) n     printf( %I64d n , res); n   else n     printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 2e5 + 10; n using namespace std; n long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return f * x; n } n int n, q; n long long a[MAXN]; n typedef struct node { n   long long maxx; n   long long sum; n } node; n node d[MAXN << 2]; n void up(int x) { n   d[x].sum = d[x << 1].sum + d[x << 1 | 1].sum; n   d[x].maxx = max(d[x << 1].maxx, d[x << 1 | 1].maxx); n } n void built(int rt, int l, int r) { n   if (l == r) { n     d[rt].maxx = d[rt].sum = a[l]; n     return; n   } n   int mid = (l + r) >> 1; n   built(rt << 1, l, mid); n   built(rt << 1 | 1, mid + 1, r); n   up(rt); n } n void update(int rt, int l, int r, int t, long long vul) { n   if (l == r) { n     d[rt].maxx = d[rt].sum = vul; n     return; n   } n   int mid = (l + r) >> 1; n   if (t <= mid) n     update(rt << 1, l, mid, t, vul); n   else n     update(rt << 1 | 1, mid + 1, r, t, vul); n   up(rt); n } n bool flag; n int pos1; n void querty2(int rt, int l, int r, long long vul) { n   if (l == r) { n     pos1 = l; n     return; n   } n   int mid = (l + r) >> 1; n   if (d[rt << 1].maxx >= vul) n     querty2(rt << 1, l, mid, vul); n   else n     querty2(rt << 1 | 1, mid + 1, r, vul); n } n void querty(int rt, int l, int r, int ql, int qr, long long vul) { n   if (flag) return; n   if (ql <= l && r <= qr) { n     if (d[rt].maxx >= vul) { n       flag = 1; n       querty2(rt, l, r, vul); n     } n     return; n   } n   int mid = (l + r) >> 1; n   if (ql <= mid) querty(rt << 1, l, mid, ql, qr, vul); n   if (qr > mid) querty(rt << 1 | 1, mid + 1, r, ql, qr, vul); n } n long long ans; n void querty1(int rt, int l, int r, int ql, int qr) { n   if (ql <= l && r <= qr) { n     ans += d[rt].sum; n     return; n   } n   int mid = (l + r) >> 1; n   if (ql <= mid) querty1(rt << 1, l, mid, ql, qr); n   if (qr > mid) querty1(rt << 1 | 1, mid + 1, r, ql, qr); n } n int main() { n   n = read(); n   q = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   a[n + 1] = 1e18; n   int pos, ans1; n   long long vul, key, pre; n   n++; n   built(1, 1, n); n   for (int i = 1; i <= q; i++) { n     pos = read(); n     vul = read(); n     a[pos] = vul; n     update(1, 1, n, pos, vul); n     ans1 = -1; n     key = 0; n     if (!a[1]) { n       printf( 1 n ); n       continue; n     } n     if (a[1] == a[2]) { n       printf( 2 n ); n       continue; n     } n     key = a[1] + a[2]; n     pre = 3; n     while (1) { n       if (pre > n) break; n       flag = 0; n       querty(1, 1, n, pre, n, key); n       ans = 0; n       querty1(1, 1, n, 1, pos1 - 1); n       if (ans == a[pos1]) { n         ans1 = pos1; n         break; n       } n       key = ans + a[pos1]; n       pre = pos1 + 1; n     } n     printf( %d n , ans1); n   } n   return 0; n } n