#include <bits/stdc++.h> n using namespace std; n const long double pi = 3.1415926535897932384626433832795l; n template <typename T> n inline auto sqr(T x) -> decltype(x * x) { n   return x * x; n } n template <typename T1, typename T2> n inline bool umx(T1& a, T2 b) { n   if (a < b) { n     a = b; n     return 1; n   } n   return 0; n } n template <typename T1, typename T2> n inline bool umn(T1& a, T2 b) { n   if (b < a) { n     a = b; n     return 1; n   } n   return 0; n } n const int N = 2000; n struct Input { n   int n; n   string s[N]; n   bool read() { n     if (!(cin >> n)) { n       return 0; n     } n     getline(cin, s[0]); n     for (int i = int(0); i < int(n); ++i) { n       getline(cin, s[i]); n     } n     return 1; n   } n   void init(const Input& input) { *this = input; } n }; n struct Data : Input { n   vector<int> ans[N]; n   void write() { n     for (int i = int(0); i < int(n); ++i) { n       printf( %d , ((int)(ans[i]).size())); n       for (int j = int(0); j < int(((int)(ans[i]).size())); ++j) { n         printf(  %d , ans[i][j]); n       } n       puts(  ); n     } n   } n   virtual void solve() {} n   virtual void clear() { *this = Data(); } n }; n struct Solution : Data { n   static const int L = (N + 63) >> 6; n   unsigned long long m[N][L]; n   unsigned long long u[N][L]; n   bool need[N]; n   int pos[N]; n   void solve() { n     memset(m, 0, sizeof m); n     for (int i = int(0); i < int(n); ++i) { n       vector<unsigned long long> q((((int)(s[i]).size()) + 8) / 9, 0); n       for (int j = int(((int)(s[i]).size())) - 1; j >= int(0); --j) { n         (q[((int)(q).size()) - 1 - j / 9] *= 10) += n             s[i][((int)(s[i]).size()) - 1 - j] -  0 ; n       } n       for (int k = int(0); k < int(L * 2); ++k) { n         unsigned long long r = 0; n         for (int j = int(0); j < int(((int)(q).size())); ++j) { n           q[j] += r * 1000000000; n           r = q[j] & ((1ull << 32) - 1); n           q[j] >>= 32; n         } n         m[i][k >> 1] |= r << (32 * (k & 1)); n       } n     } n     memset(u, 0, sizeof u); n     for (int i = int(0); i < int(n); ++i) { n       u[i][i >> 6] |= 1ull << (i & 63); n       for (int j = int(0); j < int(i); ++j) n         if (need[j]) { n           if (m[i][pos[j] >> 6] & (1ull << (pos[j] & 63))) { n             for (int k = int(0); k < int(L); ++k) { n               m[i][k] ^= m[j][k]; n             } n             for (int k = int(0); k < int((i + 63) >> 6); ++k) { n               u[i][k] ^= u[j][k]; n             } n           } n         } n       need[i] = 0; n       for (int j = int(0); j < int(N); ++j) { n         if (m[i][j >> 6] & (1ull << (j & 63))) { n           need[i] = 1; n           pos[i] = j; n           break; n         } n       } n       if (!need[i]) { n         for (int j = int(0); j < int(i); ++j) { n           if (u[i][j >> 6] & (1ull << (j & 63))) { n             ans[i].push_back(j); n           } n         } n       } n     } n   } n   void clear() { *this = Solution(); } n }; n Solution sol; n int main() { n   cout.setf(ios::showpoint | ios::fixed); n   cout.precision(20); n   sol.read(); n   sol.solve(); n   sol.write(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char spots[9][9]; n   for (int i = 0; i < 9; i++) { n     for (int j = 0; j < 3; j++) { n       string input; n       cin >> input; n       for (int k = 0; k < input.size(); k++) { n         spots[i][j * 3 + k] = input[k]; n       } n     } n   } n   int first, second; n   cin >> first >> second; n   first--; n   second--; n   int targetedFirst = first % 3; n   int targetedSecond = second % 3; n   bool changed = false; n   for (int i = targetedFirst * 3; i < targetedFirst * 3 + 3; i++) { n     for (int j = targetedSecond * 3; j < targetedSecond * 3 + 3; j++) { n       if (spots[i][j] ==  . ) { n         changed = true; n         spots[i][j] =  ! ; n       } n     } n   } n   if (changed == false) { n     for (int i = 0; i < 9; i++) { n       for (int j = 0; j < 9; j++) { n         if (spots[i][j] ==  . ) { n           spots[i][j] =  ! ; n         } n       } n     } n   } n   for (int i = 0; i < 9; i++) { n     for (int j = 0; j < 9; j++) { n       cout << spots[i][j]; n       if (j % 3 == 2) { n         cout <<    ; n       } n     } n     if (i % 3 == 2 && i != 8) { n       cout << endl; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[1000005]; n int n, m, k; n int main() { n   scanf( %d%d%d , &n, &m, &k); n   memset(arr, 0, sizeof arr); n   for (int i = 0; i < m; ++i) { n     int number; n     scanf( %d , &number); n     arr[number] = 1; n   } n   bool flg = 0; n   int where = 1; n   if (arr[where] == 1) flg = 1; n   while (k--) { n     int num1, num2; n     scanf( %d%d , &num1, &num2); n     if (num1 == where && !flg) { n       where = num2; n       if (arr[where] == 1) flg = 1; n     } else if (num2 == where && !flg) { n       where = num1; n       if (arr[where] == 1) flg = 1; n     } n   } n   printf( %d , where); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct debugger { n   static void call(const char* it) {} n   template <typename T, typename... aT> n   static void call(const char* it, T a, aT... rest) { n     string b; n     for (; *it && *it !=  , ; ++it) n       if (*it !=    ) b += *it; n     cerr << b <<  =  << a <<    ; n     call(++it, rest...); n   } n }; n int dr[] = {0, 1, 1, -1, 0, -1, -1, 1}; n int dc[] = {1, 0, 1, 1, -1, 0, -1, -1}; n char field[4][4]; n int dt = 0; n int tour(int r, int c, char c1, char c2, int d) { n   if (r < 0 || r > 3 || c < 0 || c > 3) return 0; n   if (field[r][c] == c2) { n     dt++; n     if (dt > 1) return 0; n   } else if (field[r][c] != c1) n     return 0; n   int ans = 1; n   ans += tour(r + dr[d], c + dc[d], c1, c2, d); n   return ans; n } n int main() { n   { n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n     cout.tie(NULL); n   }; n   for (int i = 0; i < 4; i++) n     for (int j = 0; j < 4; j++) cin >> field[i][j]; n   int y = 0; n   for (int i = 0; i < 4; i++) { n     for (int j = 0; j < 4; j++) { n       for (int k = 0; k < 4; k++) { n         if (tour(i, j,  x ,  . , k) == 3) { n           y = 1; n           break; n         } n         dt = 0; n       } n       if (y) break; n     } n     if (y) break; n   } n   if (y) n     cout <<  YES n ; n   else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[105]; n int main() { n   int ans = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 2; i <= n - 1; i++) { n     if (a[i] == 0 && a[i - 1] == 1 && a[i + 1] == 1) { n       ans++; n       a[i + 1] = 0; n     } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n long long a[10010]; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n   sort(a + 1, a + 1 + n); n   long long sum = 0; n   for (int i = 1; i <= k; i++) sum += a[i]; n   printf( %lld n , sum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void err() { cout << endl; } n template <class T, class... Ts> n void err(const T &arg, const Ts &...args) { n   cout << arg <<    ; n   err(args...); n } n using ll = long long; n using db = double; n const int N = 1e5 + 10; n int n, m, q; n int deg[N]; n vector<vector<int>> G; n ll f(ll x) { return 1ll * (deg[x] - G[x].size()) * G[x].size(); } n void RUN() { n   while (cin >> n >> m) { n     G.clear(); n     G.resize(n + 1); n     memset(deg, 0, sizeof deg); n     for (int i = 1, u, v; i <= m; ++i) { n       cin >> u >> v; n       if (u > v) { n         swap(u, v); n       } n       deg[u]++, deg[v]++; n       G[u].push_back(v); n     } n     ll res = 0; n     for (int i = 1; i <= n; ++i) { n       res += f(i); n     } n     cout << res <<   n ; n     cin >> q; n     while (q--) { n       int u; n       cin >> u; n       res -= f(u); n       for (auto &v : G[u]) { n         res -= f(v); n         G[v].push_back(u); n         res += f(v); n       } n       G[u].clear(); n       res += f(u); n       cout << res <<   n ; n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr), cout.tie(nullptr); n   RUN(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 5; n int t, n, h, m, a[maxn], x; n int sum; n int main() { n   ios::sync_with_stdio(0); n   cin >> n >> h >> m; n   for (int i = 1; i <= n; ++i) a[i] = h; n   for (int i = 0; i < m; ++i) { n     int l, r, w; n     cin >> l >> r >> w; n     for (int i = l; i <= r; ++i) { n       a[i] = min(a[i], w); n     } n   } n   long long ac = 0; n   for (int i = 1; i <= n; ++i) { n     ac += a[i] * a[i]; n   } n   cout << ac << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool check(long long int n, long long int k) { n   long long int sum = k; n   long long int A[k]; n   fill(A, A + k, 1); n   for (long long int i = k - 1; i >= 0; --i) { n     while (sum + A[i] <= n) { n       sum += A[i]; n       A[i] *= 2; n     } n   } n   if (sum != n) { n     return 0; n   } n   return 1; n } n int main() { n   ios_base ::sync_with_stdio(false), cin.tie(NULL); n   long long int a, b; n   cin >> a >> b; n   for (long long int i = 0; i < 33; i++) { n     long long int x = a - i * (b); n     if (check(x, i)) return cout << i <<   n , 0; n   } n   cout << -1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n char arr[2 * 1000 + 5]; n int cum[2 * 1000 + 5]; n void read_input() { n   cin >> n; n   cum[0] = 0, k = 0; n   for (int i = 1; i <= n; i++) { n     cin >> arr[i]; n     arr[i + n] = arr[i]; n     cum[i] = cum[i - 1]; n     if (arr[i] ==  T ) n       cum[i] += 1; n     else n       k++; n   } n   for (int i = n + 1; i < n + k; i++) { n     cum[i] = cum[i - 1]; n     if (arr[i] ==  T ) cum[i] += 1; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cerr.tie(0); n   read_input(); n   int min_swaps = INT_MAX; n   for (int i = k; i < n + k; i++) { n     min_swaps = min(min_swaps, cum[i] - cum[i - k]); n   } n   cout << min_swaps <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<pair<long long, long long> > s1; n long long a[212345], ans[212345]; n long long b[212345]; n signed main() { n   std::ios::sync_with_stdio(false); n   long long n, m; n   cin >> n >> m; n   for (long long i = 1; i <= n; i++) cin >> a[i]; n   for (long long i = 1; i <= m; i++) { n     long long b2; n     cin >> b[i] >> b2; n     pair<long long, long long> now = make_pair(b2, i); n     s1.insert(now); n     while (*s1.begin() != now) s1.erase(s1.begin()); n   } n   s1.insert(make_pair(0, 0)); n   set<pair<long long, long long> >::iterator t = s1.end(); n   t--; n   for (long long i = (*t).first + 1; i <= n; i++) ans[i] = a[i]; n   sort(a + 1, a + (*t).first + 1); n   long long l = 0, r = (*t).first + 1; n   while (t != s1.begin()) { n     set<pair<long long, long long> >::iterator tl = t; n     tl--; n     for (long long i = (*t).first; i > (*tl).first; i--) { n       if (b[(*t).second] == 1) n         ans[i] = a[--r]; n       else n         ans[i] = a[++l]; n     } n     t--; n   } n   for (long long i = 1; i <= n; i++) cout << ans[i] <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:256000000 ) n template <typename T> n int size(T& a) { n   return (int)a.size(); n } n template <typename T> n T sqr(T a) { n   return a * a; n } n int main() { n   int a, b, mod; n   cin >> a >> b >> mod; n   int ta = a, tb = b; n   a %= mod; n   b %= mod; n   a += mod; n   b += mod; n   a = min(a, ta); n   b = min(b, tb); n   int r = 1; n   for (int i = (0); i < (9); ++i) r = (r * 10) % mod; n   for (int i = 0; i <= a; ++i) { n     int c = (long long)r * i % mod; n     int z = (mod - c); n     if (z >= mod) z -= mod; n     if (z <= b) { n       continue; n     } n     printf( 1  ); n     printf( %0*d , 9, i); n     return 0; n   } n   printf( 2 ); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using PII = pair<int, int>; n const int mod = 998244353; n const int inf = 1 << 30; n const int maxn = 100000 + 5; n int n, k, alive[maxn]; n int query(int x) { n   cout <<  ?   << x << endl; n   string s; n   cin >> s; n   if (s ==  Y ) { n     alive[x] = false; n     return true; n   } else { n     return false; n   } n } n void reset() { cout <<  R  << endl; } n int main() { n   cin >> n >> k; n   fill(alive + 1, alive + 1 + n, true); n   int B = max(k / 2, 1), Bcnt = n / B; n   for (int i = 1; i <= Bcnt; i++) { n     for (int j = 0; j < i && i + j < Bcnt; j++) { n       for (int k = j; k < Bcnt; k += i) { n         for (int p = 1; p <= B; p++) { n           query(k * B + p); n         } n       } n       reset(); n     } n   } n   cout <<  !   << count(alive + 1, alive + 1 + n, true) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     int nLund0 = 0; n     int nRund0 = 0; n     int n00 = 0; n     int nL = 0; n     int nR = 0; n     auto zaehle = [&](char c1, char c2) -> void { n       if ((c1 ==  >  && c2 ==  - ) || (c2 ==  >  && c1 ==  - )) nRund0++; n       if ((c1 ==  <  && c2 ==  - ) || (c2 ==  <  && c1 ==  - )) nLund0++; n       if (c1 ==  >  && c2 ==  > ) nR++; n       if (c1 ==  <  && c2 ==  < ) nL++; n       if (c1 ==  -  && c2 ==  - ) n00++; n     }; n     cin >> n; n     char c1 = 0, c2 = 0; n     char c0; n     for (int i = 0; i < n; ++i) { n       if (i > 0) c1 = c2; n       cin >> c2; n       if (i == 0) { n         c0 = c2; n         continue; n       } n       zaehle(c1, c2); n     } n     zaehle(c2, c0); n     cout << nRund0 + nLund0 + n00 + nL * ((nLund0 + nL + n00) == n ? 1 : 0) + n                 nR * ((nRund0 + nR + n00) == n ? 1 : 0) n          << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e5, INF = 1e9; n const double PI = 3.141592653589793238462643383279502884197, eps = 1e-9; n int sum; n void getstring(int st, int ed, int n, bool val) { n   string s; n   sum = 0; n   cout <<  ?  ; n   for (int i = 0; i < st; i++) cout << 0; n   for (int i = st; i < ed; i++) n     cout << (i % 2 ? !val : val), n         sum += ((val && i % 2 == 0) || (!val && i % 2)); n   for (int i = ed; i < n; i++) cout << 0; n   cout << endl; n } n bool check(int cnt, int total, bool x) { n   return (cnt != total + sum && x) || (cnt != total - sum && !x); n } n int main() { n   int n, total, cnt, st, ed, md; n   bool val, x; n   string s1, s2; n   cin >> n; n   cout <<  ?  ; n   for (int i = 0; i < n; i++) cout << 0; n   cout << endl; n   cin >> total; n   cout <<  ?  ; n   for (int i = 1; i < n; i++) cout << 0; n   cout << 1 << endl; n   cin >> cnt; n   x = (cnt == total - 1); n   getstring(0, n, n, 0); n   cin >> cnt; n   val = !check(cnt, total, !x); n   st = 0, ed = n - 1; n   while (st < ed) { n     md = (st + ed) / 2; n     getstring(st, md + 1, n, val); n     cin >> cnt; n     if (check(cnt, total, !x)) n       ed = md; n     else n       st = md + 1; n   } n   if (x) n     cout <<  !   << st + 1 <<     << n; n   else n     cout <<  !   << n <<     << st + 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   if (n & 1) { n     cout << 0; n   } else { n     int res = n / 4; n     if (n % 4 == 0) { n       res--; n     } n     cout << res; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 4e5 + 5, M = 205, INF = 1e9, MOD2 = 1e9 + 7; n int n, k, y, x[N], mem[N][3], freq[N]; n int cur = 0, last = -1; n vector<int> vec; n int solve(int idx, int rem) { n   if (!rem) return 0; n   if (idx > cur) return 0; n   int& ret = mem[idx][rem]; n   if (~ret) return ret; n   ret = 0; n   ret = solve(idx + 1, rem); n   int last = n       upper_bound(vec.begin(), vec.end(), vec[idx] + k) - vec.begin() - 1; n   int c2 = freq[last]; n   if (idx) c2 -= freq[idx - 1]; n   ret = max(ret, solve(last + 1, rem - 1) + c2); n   return ret; n } n void runtestcase() { n   cin >> n >> k; n   vec.clear(); n   for (int i = 0; i < n; ++i) { n     cin >> x[i]; n     vec.push_back(x[i]); n     mem[i][2] = mem[i][1] = -1; n     freq[i] = 0; n   } n   freq[n] = 0; n   sort(vec.begin(), vec.end()); n   cur = -1, last = -1; n   for (int i = 0; i < n; ++i) { n     if (last != vec[i]) last = vec[i], ++cur; n     freq[cur]++; n   } n   for (int i = 1; i <= cur; ++i) freq[i] += freq[i - 1]; n   for (int i = 0; i < n; ++i) cin >> y; n   vec.erase(unique(vec.begin(), vec.end()), vec.end()); n   cout << solve(0, 2); n } n int main() { n   cout << fixed << setprecision(12), ios::sync_with_stdio(false), n       cin.tie(nullptr), cout.tie(nullptr); n   int t = 1, tt = 1; n   cin >> t; n   while (t) { n     runtestcase(); n     cout <<   n ; n     --t, ++tt; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T gcd(T a, T b) { n   T r; n   while (b != 0) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n template <class T> n T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n template <class T> n int getbit(T s, int i) { n   return (s >> i) & 1; n } n template <class T> n T onbit(T s, int i) { n   return s | (T(1) << i); n } n template <class T> n T offbit(T s, int i) { n   return s & (~(T(1) << i)); n } n const double PI = 2 * acos(0.0); n const double eps = 1e-9; n const int infi = 1e9; n const long long Linfi = (long long)1e18; n const long long MOD = 1000000007; n const int c1 = 11; n const int c2 = 13; n int n, m, dx, dy; n int a[100005], b[100005]; n map<int, int> M; n long long power(int a, int p, int M) { n   if (p == 0) return 1; n   if (p == 1) return a % M; n   long long ans = power(a, p / 2, M); n   ans = (ans * ans) % M; n   if (p % 2 == 1) ans = (ans * a) % M; n   return ans; n } n int phiEuler(int n) { n   int res = n; n   for (int i = 2; i * i <= n; i++) { n     if (n % i == 0) res -= res / i; n     while (n % i == 0) n /= i; n   } n   if (n > 1) res -= res / n; n   return res; n } n void solve() { n   int phi = phiEuler(n); n   for (int i = 1; i <= m; i++) { n     long long inver = power(dx, phi - 1, n); n     long long k = inver * (n - a[i]); n     k %= n; n     long long tmp = (b[i] + k * dy) % n; n     M[tmp]++; n   } n   int maxx = 0, val = -1; n   for (typeof(M.begin()) i = M.begin(); i != M.end(); i++) { n     if (i->second > maxx) { n       maxx = i->second; n       val = i->first; n     } n   } n   cout << 0 <<     << val << endl; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m >> dx >> dy; n   for (int i = 1; i <= m; i++) { n     cin >> a[i] >> b[i]; n   } n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long a, b; n   cin >> a >> b; n   long long count = 0; n   while (b >= a) { n     ostringstream str1; n     str1 << a; n     string str2 = str1.str(); n     for (long long i = 0; i < str2.length(); i++) { n       if (str2[i] ==  2  || str2[i] ==  3  || str2[i] ==  5 ) { n         count += 5; n       } else if (str2[i] ==  0  || str2[i] ==  6  || str2[i] ==  9 ) { n         count += 6; n       } else if (str2[i] ==  1 ) { n         count += 2; n       } else if (str2[i] ==  4 ) { n         count += 4; n       } else if (str2[i] ==  7 ) { n         count += 3; n       } else if (str2[i] ==  8 ) { n         count += 7; n       } n     } n     a++; n   } n   cout << count << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   cin >> n; n   set<long long int> s; n   long long int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] > 0) { n       s.insert(a[i]); n     } n   } n   long long int len1 = s.size(); n   cout << len1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Q { n   int r1, r2, c1, c2, idx; n }; n int n, m, k, q; n Q qs[200001]; n vector<int> qAtRow[100001]; n vector<int> qAtCol[100001]; n vector<int> atCol[100001]; n vector<int> atRow[100001]; n bool must[200000]; n bool res[200000]; n int v[100001]; n int Z = 400001; n int seg[400001]; n int at, val; n void update(int n, int s, int e) { n   if (at < s || at > e) return; n   if (s == e) { n     if (seg[n] == (1 << 29)) n       seg[n] = val; n     else n       seg[n] = val; n     return; n   } n   update(n * 2, s, (s + e) / 2); n   update(n * 2 + 1, (s + e) / 2 + 1, e); n   seg[n] = max(seg[n * 2], seg[n * 2 + 1]); n } n int l, r; n int get(int n, int s, int e) { n   if (l > e || r < s) return -1; n   if (s >= l && e <= r) return seg[n]; n   return max(get(n * 2, s, (s + e) / 2), get(n * 2 + 1, (s + e) / 2 + 1, e)); n } n int main() { n   scanf( %d%d%d%d , &n, &m, &k, &q); n   for (int i = 0; i < k; ++i) { n     int r, c; n     scanf( %d%d , &r, &c); n     atCol[c].push_back(r); n     atRow[r].push_back(c); n   } n   for (int i = 0; i < q; ++i) { n     Q &t = qs[i]; n     scanf( %d%d%d%d , &t.r1, &t.c1, &t.r2, &t.c2); n     t.idx = i; n     qAtCol[t.c1].push_back(i); n     qAtRow[t.r1].push_back(i); n   } n   for (int i = 0; i < Z; ++i) seg[i] = 1 << 29; n   for (int i = n; i > 0; --i) { n     for (int j = 0; j < atRow[i].size(); ++j) { n       at = atRow[i][j]; n       val = i; n       update(1, 1, m); n     } n     for (int j = 0; j < qAtRow[i].size(); ++j) { n       Q &t = qs[qAtRow[i][j]]; n       l = t.c1; n       r = t.c2; n       int a = get(1, 1, m); n       if (a <= 0 || a > t.r2) must[t.idx] = true; n     } n   } n   for (int i = 0; i < Z; ++i) seg[i] = 1 << 29; n   for (int i = m; i > 0; --i) { n     for (int j = 0; j < atCol[i].size(); ++j) { n       at = atCol[i][j]; n       val = i; n       update(1, 1, n); n     } n     for (int j = 0; j < qAtCol[i].size(); ++j) { n       Q &t = qs[qAtCol[i][j]]; n       l = t.r1; n       r = t.r2; n       int a = get(1, 1, n); n       if (must[t.idx] && (a <= 0 || a > t.c2)) res[t.idx] = true; n     } n   } n   for (int i = 0; i < q; ++i) n     if (res[i]) n       puts( NO ); n     else n       puts( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long int> glen(100001); n long long int M = 1000000007; n long long int n1, n2 = 0, sum = 0; n long long int gcd(long long int a, long long int b) { n   return (b == 0) ? a : gcd(b, a % b); n } n long long int lcm(long long int a, long long int b) { n   long long int g = gcd(a, b); n   long long int l = (a * b) / g; n   return l; n } n long long int po(long long int a, long long int b) { n   if (b == 0) return 1; n   long long int temp = po(a, b / 2); n   long long int z = ((temp % M) * (temp % M)) % M; n   if (b % 2) n     return ((z % M) * (a % M)) % M; n   else n     return z; n } n bool fun1(char c) { n   if (c ==  1  || c ==  2 ) return true; n   return false; n } n bool fun3(char c) { n   if (c ==  1  || c ==  2 ) return false; n   return true; n } n long long int fun(long long int dp[], long long int n, long long int left) { n   if (dp[n] != 0) return dp[n]; n   if (n == left) return 1; n   long long int ans = 0; n   long long int limit = n - left; n   for (long long int i = 1; i < limit + 1; i++) { n     ans += fun(dp, n - i, left - 1); n   } n   return ans; n } n bool compare(pair<double, long long int> p1, pair<double, long long int> p2) { n   if (p1.first != p2.first) { n     return p1.first > p2.first; n   } n   return p1.second < p2.second; n } n struct HASH { n   size_t operator()(const pair<double, long long int>& x) const { n     return hash<long long>()(((long long)x.first) ^ n                              (((long long)x.second) << 32)); n   } n }; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t = 1; n   long long int cs = 1; n   while (t--) { n     long long int n, k, m; n     cin >> n >> k >> m; n     long long int ans = 0; n     long long int a[n]; n     for (long long int i = 0; i < n; i++) cin >> a[i]; n     long long int b; n     map<long long int, vector<long long int>> mp; n     for (long long int i = 0; i < n; i++) { n       b = a[i] % m; n       mp[b].push_back(a[i]); n     } n     long long int f = 0; n     for (auto i : mp) { n       if (mp[i.first].size() >= k) { n         f = 1; n         cout <<  Yes n ; n         long long int s = 0; n         for (auto j : mp[i.first]) { n           cout << j <<    ; n           s++; n           if (s == k) break; n         } n         break; n       } n     } n     if (f == 0) cout <<  No n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using pii = pair<int, int>; n const int maxn = 2e5 + 100; n const int mod = 998244353; n mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); n ll fact[maxn], inv[maxn]; n ll pwr(ll a, ll pw) { n   ll ret = 1; n   while (pw > 0) { n     if (pw & 1) ret = ret * a % mod; n     a = a * a % mod; n     pw >>= 1; n   } n   return ret; n } n ll modinv(ll a) { return pwr(a, mod - 2); } n ll choose(ll N, ll K) { return fact[N] * inv[K] % mod * inv[N - K] % mod; } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0); n   fact[0] = inv[0] = 1; n   for (ll i = 1; i < maxn; i++) { n     fact[i] = fact[i - 1] * i % mod; n     inv[i] = modinv(fact[i]); n   } n   int n, k; n   cin >> n >> k; n   vector<int> v(n); n   for (int i = 0; i < n; i++) cin >> v[i]; n   int cnt = 0; n   for (int i = 0; i < n; i++) n     if (v[i] != v[(i + 1) % n]) ++cnt; n   ll same = 0; n   for (int c = 0; c * 2 <= cnt; c++) n     same = (same + choose(cnt, c) * choose(cnt - c, c) % mod * n                        pwr(k - 2, cnt - 2 * c)) % n            mod; n   same = same * pwr(k, n - cnt) % mod; n   ll ans = ((pwr(k, n) - same + mod) % mod) * modinv(2) % mod; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n; n   scanf( %d , &n); n   while (n--) { n     int tenth = 10; n     int F = 0; n     char input[15]; n     char A[15] = { n         0, n     }; n     scanf( %s , input); n     for (int i = 4; i < strlen(input); i++) A[i - 4] = input[i]; n     for (int i = 1; i < strlen(A); i++) { n       F += tenth; n       tenth *= 10; n     } n     int year = atoi(A); n     while (year < 1989 + F) year += tenth; n     printf( %d n , year); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)3e5 + 1; n int n, m, a[N][10], p1 = 1, p2 = 1; n int ok[(1 << 8) + 1]; n bool check(int x) { n   memset(ok, 0, sizeof(ok)); n   for (int i = 1; i <= n; ++i) { n     int mask = 0; n     for (int j = 0; j < m; ++j) { n       if (a[i][j] >= x) mask |= (1 << j); n     } n     for (int j = 0; j < (1 << m); ++j) { n       if (ok[j] && (mask | j) == (1 << m) - 1) { n         p1 = ok[j]; n         p2 = i; n         return true; n       } n     } n     ok[mask] = i; n   } n   return false; n } n void solve() { n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j < m; ++j) cin >> a[i][j]; n   } n   int l = 0, r = (int)1e9; n   while (l <= r) { n     int mid = (l + r) / 2; n     if (check(mid)) { n       l = mid + 1; n     } else n       r = mid - 1; n   } n   cout << p1 <<     << p2; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int num[102]; n   int a, i, sum = 0, flag = 1; n   scanf( %d , &a); n   for (i = 0; i < a; i++) { n     scanf( %d , &num[i]); n   } n   if (a < 3) { n     printf( -1 n ); n   } else { n     for (i = a - 1; i >= 0; i--) { n       if (i == a - 1 && i % 2 && num[i]) { n         flag = 0; n         break; n       } n       if (num[i] > 0) { n         if (i % 2) { n           sum += num[i]; n           num[i / 2] -= num[i]; n           num[i] = 0; n         } else { n           sum += num[i]; n           if (i) { n             num[i - 1] -= num[i]; n             num[i / 2 - 1] -= num[i]; n           } n           num[i] = 0; n         } n       } n     } n     if (flag) { n       printf( %d n , sum); n     } else { n       printf( -1 n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #define F(i,j,k) for(int i=(j);i<=(k);++i) n #define D(i,j,k) for(int i=(j);i>=(k);--i) n #define rep(it,s) for(__typeof(s.begin()) it=s.begin();it!=s.end();++it) n #define Rep(a,s) for(auto a:s) n #define PB push_back n #define MP make_pair n #define FF first n #define SS second n typedef long long ll; n typedef unsigned long long ull; n using namespace std; n ll quick_pow(ll x,ll y,ll Mod){ n     ll res=1; n     while(y){ n         if(y&1)res=res*x%Mod; n         x=x*x%Mod,y>>=1; n     } n     return res; n } n ll inv(ll x,ll Mod){return quick_pow(x,Mod-2,Mod);} n namespace IO{ n     template <class T> n     inline void read(T &x){ n         x=0;int f=1;char ch=getchar(); n         while(ch< 0 ||ch> 9 ){if(ch== - )f=-1;ch=getchar();} n         while(ch<= 9 &&ch>= 0 )x=x*10+ch- 0 ,ch=getchar(); n         x*=f; n     } n }; n using namespace IO; n const int N=100005; n vector<int>ans,vec0,vec1; n bool calc(int x,int y){ n  if(x==0||x==2)return 0;//没间隔  n  if(x>1&&y==0)return 0; n  if(x%2==0&&y<=1)return 0; n  if(x%2==0){ n   ans.PB(2); n   x-=3; n  } n  while(x>1){ n   ans.PB(1); n   x-=2; n  } n  return 1; n } n void solve(int x){ n  int flag=1; n  ans.clear(); n  //Rep(y,vec0){ n  for(int i=0;i<vec0.size();i++){ n   int y=vec0[i]; n   flag&=calc(y-x,x); n   if(i+1!=vec0.size())ans.PB(vec1[i]+x); n  } n  if(flag){ n   cout<<ans.size()<<  n ; n   Rep(y,ans)cout<<y<<   ; n   exit(0); n  } n } n char s[N]; n int cnt0,cnt1; n int main(){ n     #ifndef ONLINE_JUDGE n         freopen( in.txt , r ,stdin); n         //freopen( out.txt , w ,stdout); n     #endif n     scanf( %s n ,s+1); n  int n=strlen(s+1); n  //if(s[1]== # )vec0.PB(1); n  F(i,1,n){ n   if(s[i]== _ ){ n    if(cnt1)vec1.PB(cnt1); n    cnt1=0,cnt0++; n   } n   else{ n    if(!vec0.size())vec0.PB(cnt0+1); n    else if(cnt0)vec0.PB(cnt0); n    cnt0=0,cnt1++; n   } n  } n  vec0.PB(cnt0+1); n  if(cnt1)vec1.PB(cnt1); n  //Rep(y,vec0)cout<<y<<   ;cout<<endl; n  //Rep(y,vec1)cout<<y<<   ;cout<<endl; n  if(!vec1.size()){ n   cout<<0<<  n n ; n   return 0; n  } n  int mink=1e9; n  Rep(y,vec0)mink=min(mink,y); n  F(i,0,min(mink,3)){ n   solve(i); n  } n  cout<<-1; n     return 0; n }


#include <bits/stdc++.h> n const long long INF32 = 1e9; n const long long INF64 = 1e17; n const int RANGE = 1e6 + 5; n using namespace std; n template <class T> n void read(T &Val) { n   T tmp = 0; n   char ch = getchar(); n   int flag = 1; n   while (!(ch >=  0  && ch <=  9 )) { n     if (ch ==  - ) flag = -1; n     ch = getchar(); n   } n   while ((ch >=  0  && ch <=  9 )) { n     tmp = tmp * 10 + ch -  0 ; n     ch = getchar(); n   } n   Val = flag * tmp; n } n int q, cnt; n int n, m; n char data[300][300]; n int bigX[] = {0, 1, -1, 0, 1, -1, 1, -1}, bigY[] = {1, 0, 0, -1, 1, -1, -1, 1}; n void check(int x, int y) { n   if (x < 0 or y < 0 or x >= m or y >= n or data[y][x] !=  1 ) return; n   data[y][x] =  2 ; n   cnt++; n   for (int i = 0; i < 8; i++) check(x + bigX[i], y + bigY[i]); n } n int tell_square(int y, int x, int d) { n   int yy = y + d, xx = x + d; n   if (yy >= n or xx >= m) return 0; n   for (int i = x; i <= xx; i++) { n     if (data[y][i] !=  2  or data[yy][i] !=  2 ) return 0; n   } n   for (int i = y; i <= yy; i++) { n     if (data[i][x] !=  2  or data[i][xx] !=  2 ) return 0; n   } n   return 1; n } n int tell_rombus(int y, int x, int d) { n   int yy = y + d * 2, lxx = x - d, rxx = x + d; n   if (yy >= n or rxx >= m or lxx < 0) return 0; n   for (int i = 0; i <= d; i++) { n     if (data[y + i][x + i] !=  2  or data[y + i + d][x + i - d] !=  2 ) { n       return 0; n     } n   } n   for (int i = 0; i <= d; i++) { n     if (data[y + i][x - i] !=  2  or data[y + i + d][x - i + d] !=  2 ) { n       return 0; n     } n   } n   return 1; n } n int main() { n   read(q); n   while (q--) { n     read(n), read(m); n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) cin >> data[i][j]; n     } n     int ans = 0; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         if (data[i][j] ==  0  or data[i][j] ==  2 ) continue; n         cnt = 0; n         check(j, i); n         if ((cnt % 4) != 0 or cnt / 4 > 250) continue; n         ans = ans + tell_rombus(i, j, cnt / 4) + tell_square(i, j, cnt / 4); n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   string s; n   while (t--) { n     cin >> s; n     vector<int> E, O; n     int io = 0, ie = 0, prev = -1; n     for (int i = 0; i < s.size(); ++i) { n       if ((s[i] - 48) % 2 == 0) { n         if (io < O.size() && ie < E.size() && prev == 1) { n           while (io < O.size() && ie < E.size()) { n             if (O[io] < E[ie]) n               cout << O[io++]; n             else n               cout << E[ie++]; n           } n         } n         E.push_back(s[i] - 48); n         prev = 0; n       } else { n         if (io < O.size() && ie < E.size() && prev == 0) { n           while (io < O.size() && ie < E.size()) { n             if (O[io] < E[ie]) n               cout << O[io++]; n             else n               cout << E[ie++]; n           } n         } n         O.push_back(s[i] - 48); n         prev = 1; n       } n     } n     if (io < O.size() && ie < E.size()) { n       while (io < O.size() && ie < E.size()) { n         if (O[io] < E[ie]) n           cout << O[io++]; n         else n           cout << E[ie++]; n       } n     } n     while (io < O.size()) cout << O[io++]; n     while (ie < E.size()) cout << E[ie++]; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using uint = unsigned int; n using ll = long long; n using ull = unsigned long long; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n template <typename T1, typename T2> n ostream &operator<<(ostream &out, const pair<T1, T2> &item) { n   out <<  (  << item.first <<  ,   << item.second <<  ) ; n   return out; n } n template <typename T> n ostream &operator<<(ostream &out, const vector<T> &v) { n   for (const auto &item : v) out << item <<    ; n   return out; n } n const double EPS = 1e-9; n int v[10]; n int a[10][5]; n vector<vector<int>> permutations; n double dist(const pair<pii, int> &a, const pair<pii, int> &b) { n   return sqrt(1.0 * (a.first.first - b.first.first) * n                   (a.first.first - b.first.first) + n               1.0 * (a.first.second - b.first.second) * n                   (a.first.second - b.first.second) + n               1.0 * (a.second - b.second) * (a.second - b.second)); n } n void check() { n   vector<pair<pii, int>> b; n   for (int i = 0; i < 8; ++i) { n     const auto &p = permutations[v[i]]; n     b.push_back({{a[i][p[0]], a[i][p[1]]}, a[i][p[2]]}); n   } n   for (int i = 0; i < 8; ++i) n     for (int j = i + 1; j < 8; ++j) n       if (b[i] == b[j]) return; n   auto c1 = *min_element(b.begin(), b.end()); n   auto c2 = *max_element(b.begin(), b.end()); n   double aux = dist(c1, c2) / sqrt(3.0); n   if (abs(aux - round(aux)) > EPS) return; n   int d = round(aux); n   vector<int> v1, v2; n   for (int i = 0; i < 8; ++i) { n     if (abs(dist(c1, b[i]) - d) < EPS) v1.push_back(i); n     if (abs(dist(c2, b[i]) - d) < EPS) v2.push_back(i); n   } n   if (v1.size() != 3 || v2.size() != 3) return; n   cout <<  YES n ; n   for (int i = 0; i < 8; ++i) n     cout << b[i].first.first <<     << b[i].first.second <<     << b[i].second n          <<   n ; n   exit(0); n } n void bkt(int k) { n   if (k == 8) { n     check(); n     return; n   } n   for (int i = 0; i < permutations.size(); ++i) { n     v[k] = i; n     bkt(k + 1); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   vector<int> p = {0, 1, 2}; n   do { n     permutations.push_back(p); n   } while (next_permutation(p.begin(), p.end())); n   for (int i = 0; i < 8; ++i) n     for (int j = 0; j < 3; ++j) cin >> a[i][j]; n   bkt(1); n   cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 10; n int du[maxn]; n set<int> g[maxn]; n int b1[maxn], b2[maxn], ans[maxn], vis[maxn]; n int main() { n   int n, m, k; n   scanf( %d%d%d , &n, &m, &k); n   set<pair<int, int> > s; n   for (int i = 0; i < m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     b1[i] = x, b2[i] = y; n     du[x]++, du[y]++; n     g[x].insert(y); n     g[y].insert(x); n   } n   for (int i = 1; i <= n; i++) s.insert(make_pair(du[i], i)); n   for (int i = m - 1; i >= 0; i--) { n     while (s.size() >= 1) { n       pair<int, int> itt = (*s.begin()); n       if (itt.first >= k) break; n       for (set<int>::iterator it = g[itt.second].begin(); n            it != g[itt.second].end(); it++) { n         int u = *it; n         if (vis[u] == 1) continue; n         s.erase(make_pair(du[u], u)); n         du[u]--; n         s.insert(make_pair(du[u], u)); n         g[u].erase(itt.second); n       } n       s.erase(itt); n       vis[itt.second] = 1; n     } n     ans[i] = s.size(); n     if (vis[b1[i]] == 0 && vis[b2[i]] == 0) { n       s.erase(make_pair(du[b1[i]], b1[i])); n       du[b1[i]]--; n       s.insert(make_pair(du[b1[i]], b1[i])); n       g[b1[i]].erase(b2[i]); n       s.erase(make_pair(du[b2[i]], b2[i])); n       du[b2[i]]--; n       s.insert(make_pair(du[b2[i]], b2[i])); n       g[b2[i]].erase(b1[i]); n     } n   } n   for (int i = 0; i < m; i++) printf( %d n , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t = 0; n   cin >> t; n   long long a = 0, b = 0; n   for (int i = 0; i < t; i++) { n     cin >> a >> b; n     long long dif = abs(a - b); n     long long res = dif / 5; n     dif = dif % 5; n     res += dif / 2; n     dif %= 2; n     res += dif; n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int lala = 2e9 + 1; n int max(int a, int b) { return a > b ? a : b; } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   pair<int, int> arr[100005]; n   int dp[3][100005]; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second; n   arr[n].first = lala, arr[n].second = 0; n   dp[0][0] = 0; n   dp[1][0] = 1; n   dp[2][0] = arr[0].first + arr[0].second < arr[1].first ? 1 : 0; n   for (int i = 1; i < n; i++) { n     dp[0][i] = max(dp[0][i - 1], max(dp[1][i - 1], dp[2][i - 1])); n     if (arr[i].first - arr[i].second > arr[i - 1].first) { n       if (arr[i].first - arr[i].second > arr[i - 1].first + arr[i - 1].second) { n         dp[1][i] = dp[0][i] + 1; n       } else { n         dp[1][i] = dp[1][i - 1] + 1; n       } n     } else { n       dp[1][i] = dp[0][i]; n     } n     if (arr[i].first + arr[i].second < arr[i + 1].first) { n       dp[2][i] = dp[0][i] + 1; n     } else { n       dp[2][i] = dp[0][i]; n     } n   } n   cout << max(dp[0][n - 1], max(dp[1][n - 1], dp[2][n - 1])) << endl; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:102400000,102400000 ) n using namespace std; n double eps = 1e-10; n const int maxn = 30005; n char s[105][105]; n int num[105][105], ans[105]; n int main() { n   ios::sync_with_stdio; n   cin.tie(0); n   double a, b, c, d; n   cin >> a >> b >> c >> d; n   double l = 0, r = 1e9 + 7; n   for (int i = 1; i <= 100; i++) { n     double mid = (l + r) / 2.0; n     double maxia = max(max((a + mid) * (d + mid), (a + mid) * (d - mid)), n                        max((a - mid) * (d + mid), (a - mid) * (d - mid))); n     double minia = min(min((a + mid) * (d + mid), (a + mid) * (d - mid)), n                        min((a - mid) * (d + mid), (a - mid) * (d - mid))); n     double maxib = max(max((b + mid) * (c + mid), (b + mid) * (c - mid)), n                        max((b - mid) * (c + mid), (b - mid) * (c - mid))); n     double minib = min(min((b + mid) * (c + mid), (b + mid) * (c - mid)), n                        min((b - mid) * (c + mid), (b - mid) * (c - mid))); n     if (maxia >= minib && maxia <= maxib || minia >= minib && minia <= maxib || n         maxib >= minia && maxib <= maxia || minib >= minia && minib <= maxia) n       r = mid; n     else n       l = mid; n   } n   printf( %.10lf n , l); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<long long, long long> mp[15]; n long long k, a[200010]; n int n, l[200010], r[200010]; n long long ans = 0; n int itos(long long x) { n   int now = 0; n   while (x) { n     now++; n     x /= 10; n   } n   return now; n } n void add(int p) { n   long long now = a[p]; n   for (int i = 1; i <= 10; i++) { n     now *= 10; n     now %= k; n     mp[i][now]++; n     if (i == l[p]) r[p] = now; n   } n } n void sub(long long x) { n   long long now = x; n   for (int i = 1; i <= 10; i++) { n     now *= 10; n     now %= k; n     mp[i][now]--; n   } n } n int cal(int p) { n   int anss = 0; n   if (a[p] % k == 0) n     anss = mp[l[p]][0] - (r[p] == 0); n   else n     anss = mp[l[p]][k - (a[p] % k)] - (r[p] == k - (a[p] % k)); n   return anss; n } n int main() { n   cin.tie(0), cout.sync_with_stdio(false); n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     l[i] = itos(a[i]); n     add(i); n   } n   for (int i = 0; i < n; i++) ans += cal(i); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( unroll-loops ,  omit-frame-pointer ,  inline ) n #pragma GCC option( arch=native ,  tune=native ,  no-zero-upper ) n #pragma GCC target(   n      sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) n #pragma GCC optimize( Ofast ) n using namespace std; n const long double pi = acos(-1); n const long long int M = 1e9 + 7, N = 1e7 + 5, INF = 1e18; n void solve() { n   long long int x, y, z, a, b, c, f1, f2, f3, f4, f5, f6, s = 0; n   cin >> x >> y >> z >> a >> b >> c >> f1 >> f2 >> f3 >> f4 >> f5 >> f6; n   if (y < 0) s += f1; n   if (y > b) s += f2; n   if (z > c) s += f4; n   if (z < 0) s += f3; n   if (x > a) s += f6; n   if (x < 0) s += f5; n   cout << s <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007, MAX = 100003; n const long long INF = 1LL << 60; n int par[MAX]; n long long mini[MAX], cost[MAX]; n void init(int n) { n   for (int i = 0; i < n; i++) { n     par[i] = i; n     mini[i] = cost[i]; n   } n } n int root(int a) { n   if (par[a] == a) n     return a; n   else n     return par[a] = root(par[a]); n } n void unite(int a, int b) { n   if (root(a) != root(b)) { n     mini[root(a)] = min(mini[root(a)], mini[root(b)]); n     par[root(b)] = root(a); n   } n } n bool check(int a, int b) { return root(a) == root(b); } n int main() { n   int N, M; n   cin >> N >> M; n   for (int i = 0; i < N; i++) { n     scanf( %lld , &cost[i]); n   } n   init(N); n   for (int i = 0; i < M; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     a--; n     b--; n     unite(a, b); n   } n   set<pair<int, int>> SE; n   for (int i = 0; i < N; i++) { n     SE.insert({root(i), mini[root(i)]}); n   } n   long long ans = 0; n   for (auto it = SE.begin(); it != SE.end(); it++) { n     ans += (*it).second; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int k, a[1001], i, j, poz, submisii_interesante, f[1001]; n double ecran, fully_tested, n, timp = 1; n struct coada { n   int x, y, z; n }; n vector<coada> v; n int main() { n   cin >> n >> k; n   for (i = 1; i <= n; ++i) { n     cin >> a[i]; n     if (k) { n       v.push_back({0, a[i], i}); n       k--; n       poz = i + 1; n     } n   } n   while (!v.empty()) { n     if (timp > 0 && double(timp) == int(timp)) { n       for (size_t i = 0; i < v.size(); ++i) { n         v[i].x++; n         if (v[i].x == v[i].y) { n           fully_tested++; n           ecran = round((100 * fully_tested) / n); n           v.erase(v.begin() + i, v.begin() + i + 1); n           if (poz <= n) { n             v.push_back({-1, a[poz], poz}); n             poz++; n           } n           i--; n         } n       } n     } n     if (double(timp - 0.5) == int(timp - 0.5)) { n       for (size_t i = 0; i < v.size(); ++i) { n         if (v[i].x + 1 == ecran && ecran) { n           f[v[i].z]++; n           if (f[v[i].z] == 1) { n             submisii_interesante++; n           } n         } n       } n     } n     timp = timp + 0.5; n   } n   cout << submisii_interesante; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC target( avx2 ) n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unroll-loops ) n const int tam = 100010; n const int MOD = 1000000007; n const int MOD1 = 998244353; n const double DINF = 1e100; n const double EPS = 1e-9; n const double PI = acos(-1); n void solve() { n   int n; n   cin >> n; n   vector<int> ar(n); n   bool bo = true; n   for (int i = 0; i < n; i++) { n     cin >> ar[i]; n     bo &= ar[i] & 1 ^ i; n   } n   if (!bo) { n     cout << -1 <<   n ; n     return; n   } n   int a, b; n   vector<int> res; n   for (int i = n; i > 1; i -= 2) { n     for (int j = 0; j < i; j++) { n       if (ar[j] == i) a = j + 1; n       if (ar[j] == i - 1) b = j + 1; n     } n     if (a == i && b == i - 1) { n       continue; n     } n     if (a != 1) { n       res.push_back(a); n       reverse(ar.begin(), ar.begin() + a); n       for (int j = 0; j < i; j++) n         if (ar[j] == i - 1) b = j + 1; n     } n     if (b != 2) { n       res.push_back(b - 1); n       reverse(ar.begin(), ar.begin() + b - 1); n       res.push_back(b + 1); n       reverse(ar.begin(), ar.begin() + b + 1); n       res.push_back(3); n       reverse(ar.begin(), ar.begin() + 3); n     } n     res.push_back(i); n     reverse(ar.begin(), ar.begin() + i); n   } n   cout << res.size() <<   n ; n   for (int x : res) cout << x <<    ; n   if (res.size()) cout <<   n ; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mv = pow(10, 5) + 1; n void pfn() { n   char x[mv], y[mv]; n   cin >> x >> y; n   int ly = strlen(y) - 1, i; n   i = ly; n   while (i >= 0 && y[i] !=  1 ) i--; n   int lx = strlen(x) - 1 - ly + i; n   i = lx; n   while (i >= 0 && x[i] !=  1 ) i--; n   cout << lx - i <<   n ; n } n int main() { n   int t; n   cin >> t; n   while (t--) pfn(); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n using namespace std; n long long int mod = 1000000007; n long long int maxn = 200001; n long long int binpow(long long int a, long long int b, long long int mod) { n   long long int res = 1; n   while (b > 0) { n     if (b % 2) { n       res = (res * a) % mod; n       b--; n     } n     a = (a * a) % mod; n     b /= 2; n   } n   return res % mod; n } n long long int binpow(long long int a, long long int b) { n   long long int res = 1; n   while (b > 0) { n     if (b % 2) { n       res = (res * a); n       b--; n     } n     a = (a * a); n     b /= 2; n   } n   return res; n } n bool isPrime(long long int n) { n   if (n == 1) return false; n   for (long long int i = 2; i * i <= n; i++) { n     if (n % i == 0) return false; n   } n   return true; n } n long long int mulmod(long long int a, long long int b) { n   return ((a % mod) * (b % mod)) % mod; n } n long long int addmod(long long int a, long long int b) { n   return (((a % mod) + (b % mod)) + mod) % mod; n } n void solve(); n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long int t = 2; n   cin >> t; n   for (long long int tt = 1; tt <= t; tt++) { n     solve(); n   } n } n void solve() { n   long long int n; n   cin >> n; n   string s1, s2; n   cin >> s1 >> s2; n   vector<long long int> oper; n   bool zero; n   if (s1[0] ==  0 ) n     zero = true; n   else n     zero = false; n   for (long long int i = 0; i < n - 1; i++) { n     if (s1[i] != s1[i + 1]) { n       oper.push_back(i + 1); n       zero = !zero; n     } n   } n   if (!zero) oper.push_back(n); n   s1 = string(n,  0 ); n   zero = true; n   for (long long int i = n - 1; i >= 0; i--) { n     if (s2[i] ==  1  and zero == true) { n       oper.push_back(i + 1); n       zero = false; n     } n     if (s2[i] ==  0  and zero == false) { n       oper.push_back(i + 1); n       zero = true; n     } n   } n   cout << oper.size() <<    ; n   for (long long int i = 0; i < oper.size(); i++) cout << oper[i] <<    ; n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int wh, a, b, c, cst; n   node(int WH, int A, int B, int C, int CST) { n     wh = WH; n     a = A; n     b = B; n     c = C; n     cst = CST; n   } n   bool operator<(const node &t) const { return cst < t.cst; } n }; n vector<node> v1, v2; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int a, b, c, d; n     cin >> a >> b >> c >> d; n     v1.push_back(node(i + 1, a, b, c, d)); n   } n   for (int i = 0; i < n; i++) { n     bool b = true; n     for (int j = 0; j < n; j++) n       if (v1[i].a < v1[j].a && v1[i].b < v1[j].b && v1[i].c < v1[j].c) n         b = false; n     if (b) v2.push_back(v1[i]); n   } n   sort(v2.begin(), v2.end()); n   cout << v2[0].wh << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD(1000000009); n const int INF((1 << 30) - 1); n const int MAXN(100005); n int a[MAXN], na = 0; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int x; n     scanf( %d , &x); n     int low = 0, high = na - 1, mid, pos = na; n     while (low <= high) { n       mid = (low + high) / 2; n       if (a[mid] > x) n         pos = mid, high = mid - 1; n       else n         low = mid + 1; n     } n     a[pos] = x; n     if (pos == na) na++; n   } n   printf( %d , na); n } n


#include <bits/stdc++.h> n using namespace std; n long long v[100005]; n long long st[400005]; n void init(int idx, int a, int b) { n   if (a == b) { n     st[idx] = v[a]; n   } else { n     int m = (a + b) / 2; n     init(idx * 2 + 1, a, m); n     init(idx * 2 + 2, m + 1, b); n     st[idx] = max(st[idx * 2 + 1], st[idx * 2 + 2]); n   } n } n long long query(int idx, int a, int b, int i, int j) { n   if (i > b || j < a) n     return -1; n   else if (j >= b && i <= a) n     return st[idx]; n   int m = (a + b) / 2; n   long long x0 = query(idx * 2 + 1, a, m, i, j); n   long long x1 = query(idx * 2 + 2, m + 1, b, i, j); n   return max(x0, x1); n } n int main() { n   int n; n   int qry; n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   char c; n   int x, y; n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> v[i]; n   init(0, 0, n - 1); n   for (int i = 0; i < n; ++i) { n     long long mn = query(0, 0, n - 1, i + 1, n - 1); n     if (v[i] > mn) n       cout << 0 <<    ; n     else n       cout << mn - v[i] + 1 <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n  n int main() { n     ios::sync_with_stdio(0); n     int t; n     cin >> t; n     for (int tc=1; tc<=t; tc++) { n         int n, x; n         cin >> n >> x; n         vector<int> v(n); n         for (int i=0; i<n; i++) { n             cin >> v[i]; n         } n         vector<int> ans; n         int sum = 0; n         bool ok = true; n         for (int i=0; i<n; i++) { n             int val = v[i]; n             if (sum + val == x) { n                 if (i == n-1) { n                     ok = false; n                     break; n                 } n                 swap(v[i], v[n-1]); n                 val = v[i]; n             } n             ans.push_back(val); n             sum += val; n         } n         if (!ok) { n             cout <<  NO n ; n             continue; n         } n         cout <<  YES n ; n         for (int i=0; i<n; i++) { n             cout << ans[i] <<    n [i+1==n]; n         } n     } n } n


#include <bits/stdc++.h> n using namespace std; n int n, i, j, k, m; n char ss[111], c; n bool a[111]; n string s[111], t; n bool eq(string a, string b) { n   for (int i = 0; i < a.length(); i++) n     if (a[i] <=  Z ) a[i] = a[i] -  A  +  a ; n   for (int i = 0; i < b.length(); i++) n     if (b[i] <=  Z ) b[i] = b[i] -  A  +  a ; n   return a == b; n } n int main() { n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %s , ss); n     s[i] = ss; n   } n   scanf( %s , ss); n   t = ss; n   m = t.length(); n   scanf( %s , ss); n   c = ss[0]; n   for (i = 0; i < m; i++) n     for (j = 0; j < n; j++) n       if (i + s[j].length() <= m && eq(s[j], t.substr(i, s[j].length()))) n         for (k = 0; k < s[j].length(); k++) a[i + k] = true; n   for (i = 0; i < m; i++) n     if (a[i]) { n       if (c ==  a ) { n         if (t[i] == c) n           t[i] =  b ; n         else if (t[i] ==  A ) n           t[i] =  B ; n         else if (t[i] <=  Z ) n           t[i] =  A ; n         else n           t[i] =  a ; n       } else if (t[i] == c) n         t[i] =  a ; n       else if (t[i] == c -  a  +  A ) n         t[i] =  A ; n       else if (t[i] <=  Z ) n         t[i] = c -  a  +  A ; n       else n         t[i] = c; n     } n   puts(t.c_str()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-12; n const int INF = 999999999; n const int kMod = 1000000007; n const int kMaxN = 100010; n char a[kMaxN], b[kMaxN]; n int p10[kMaxN], p2[kMaxN], seq[kMaxN]; n int F[kMaxN], S[kMaxN]; n int P10(int n) { n   int &res = p10[n]; n   if (res != -1) return res; n   return res = (n == 0) ? 1 : ((long long)P10(n - 1) * 10) % kMod; n } n int P2(int n) { n   int &res = p2[n]; n   if (res != -1) return res; n   return res = (n == 0) ? 1 : ((long long)P2(n - 1) * 2) % kMod; n } n int ComSeq(int n) { n   int &res = seq[n]; n   if (res != -1) return res; n   if (n == 0) return res = 0; n   return res = ((long long)ComSeq(n - 1) * 10 + 1) % kMod; n } n int ComS(int n) { n   int &res = S[n]; n   if (res != -1) return res; n   if (n == 0) return res = 0; n   res = ((long long)ComS(n - 1) * 20) % kMod; n   res = (res + (long long)P2(n - 1) * 11) % kMod; n   return res; n } n int ComG(int n) { n   int res = ((long long)ComS(n) * 2) % kMod; n   res = (res - (long long)ComSeq(n) * 11) % kMod; n   return res; n } n int ComF(int n) { n   int &res = F[n]; n   if (res != -1) return res; n   res = 0; n   if (n == 0) return res; n   int p = ((long long)P10(n - 1) * 4) % kMod; n   int w1 = (p + (long long)ComSeq(n - 1) * 7) % kMod; n   res = (res + (((long long)p * p) % kMod) * (P2(n - 1) - 1)) % kMod; n   res = (res + p * (long long)ComG(n - 1)) % kMod; n   res = (res + ComF(n - 1)) % kMod; n   p = ((long long)P10(n - 1) * 7) % kMod; n   int w2 = (p + (long long)ComSeq(n - 1) * 4) % kMod; n   res = (res + (((long long)p * p) % kMod) * (P2(n - 1) - 1)) % kMod; n   res = (res + p * (long long)ComG(n - 1)) % kMod; n   res = (res + ComF(n - 1)) % kMod; n   res = (res + (long long)w1 * w2) % kMod; n   return res; n } n int Solve(const char a[]) { n   int n = strlen(a); n   int res = 0; n   int prefix = 0; n   for (int i = n - 1; i >= 0; --i) { n     int d = a[n - 1 - i] -  0 ; n     int next_prefix = (prefix + (long long)P10(i) * d) % kMod; n     if (d == 7) { n       int p = (prefix + (long long)P10(i) * 4) % kMod; n       if (i > 0) { n         res = (res + (((long long)p * p) % kMod) * (P2(i) - 1)) % kMod; n         res = (res + (long long)p * ComG(i)) % kMod; n         res = (res + ComF(i)) % kMod; n       } n       int w1 = (p + (long long)ComSeq(i) * 7) % kMod; n       int w2 = (next_prefix + (long long)ComSeq(i) * 4) % kMod; n       res = (res + (long long)w1 * w2) % kMod; n     } n     prefix = next_prefix; n   } n   return res; n } n int main() { n   scanf( %s , a); n   scanf( %s , b); n   memset(p10, -1, sizeof(p10)); n   memset(p2, -1, sizeof(p2)); n   memset(seq, -1, sizeof(seq)); n   memset(F, -1, sizeof(F)); n   memset(S, -1, sizeof(S)); n   int res = Solve(b); n   res = (res - Solve(a)) % kMod; n   if (res < 0) res += kMod; n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, i, j, r = 1; n   cin >> n; n   int a[n][n]; n   for (i = 0; i < n; i++) { n     for (j = 0; j < n; j++) { n       if (i % 2 == 0) { n         a[i][j] = r; n         r++; n       } else { n         a[i][n - j - 1] = r; n         r++; n       } n     } n   } n   for (i = 0; i < n; i++) { n     for (j = 0; j < n; j++) { n       cout << a[j][i] <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void Int(T &n) { n   n = 0; n   int f = 1; n   int ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = -1; n   for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch -  0 ; n   n = n * f; n } n template <typename T> n T gcd(T a, T b) { n   return !b ? a : gcd(b, a % b); n } n template <typename T> n inline void umin(T &a, T b) { n   a = a < b ? a : b; n } n template <typename T> n inline void umax(T &a, T b) { n   a = a > b ? a : b; n } n template <typename T, typename W> n inline void Int(T &x, W &y) { n   Int(x), Int(y); n } n template <typename T, typename W, typename Q> n inline void Int(T &x, W &y, Q &z) { n   Int(x, y), Int(z); n } n const int N = 1e5 + 7; n const int inf = 1e9 + 7; n int dp[N]; n int lev[N]; n vector<int> g[N]; n vector<pair<int, int>> edges; n int dfs(int u, int p = -1) { n   dp[u] = 0; n   for (int v : g[u]) { n     if (lev[v] == 0) { n       lev[v] = lev[u] + 1; n       edges.push_back({u, v}); n       dp[u] += dfs(v, u); n     } else if (lev[u] > lev[v] && v != p) { n       ++dp[u]; n       --dp[v]; n       edges.push_back({u, v}); n     } n   } n   if (p != -1 && dp[u] == 0) { n     printf( 0 n ); n     exit(0); n   } n   return dp[u]; n } n int solve() { n   int n, m; n   Int(n, m); n   for (int i = 1; i <= m; ++i) { n     int u, v; n     Int(u, v); n     g[u].push_back(v); n     g[v].push_back(u); n   } n   for (int i = 1; i <= n; ++i) { n     if (!lev[i]) { n       lev[i] = 1; n       dfs(i); n     } n   } n   for (auto [u, v] : edges) { n     printf( %d %d n , u, v); n   } n   return 0; n } n int main() { n   int tests = 1, CaseNo = 0; n   while (tests--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[10000], i, t, n, j, x; n int main() { n   cin >> t; n   while (t--) { n     cin >> n; n     for (int i = 1; i <= n; i++) { n       cin >> x; n       if (x <= 2048) a[x]++; n     } n     j = 1; n     while (j < 2048) { n       a[j * 2] += a[j] / 2; n       a[j] = 0; n       j *= 2; n     } n     if (a[2048] > 0) { n       cout <<  YES  << endl; n     } else n       cout <<  NO  << endl; n     a[2048] = 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int n; n   cin >> n; n   int r, c; n   int diff = 1000000; n   for (int a = 1; a * a <= n; a++) n     for (int b = a; a * b <= n; b++) n       if (a * b == n && b - a < diff) r = a, c = b; n   cout << r <<     << c; n } n


#include <bits/stdc++.h> n const long long oo = 1e16; n using namespace std; n const int N = 1000005; n long long n, dp[N]; n long long num(long long n) { n   if (n == 0) return 0; n   if (dp[n] != -1) return dp[n]; n   string s = to_string(n); n   long long res = oo; n   for (int i = 0; i < s.size(); i++) n     if (s[i] !=  0 ) res = min(res, 1 + num(n - (s[i] -  0 ))); n   return dp[n] = res; n } n int main() { n   cin >> n; n   memset(dp, -1, sizeof(dp)); n   cout << num(n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, m; n   cin >> n >> m; n   long long start = 0, end = 6 * (n + m); n   while (start <= end) { n     long long mid = (start + end) / 2; n     long long val1 = (mid / 2) - (mid / 6); n     long long val2 = (mid / 3) - (mid / 6); n     if ((mid / 6) >= (max(n - val1, 0LL) + max(m - val2, 0LL))) { n       end = mid - 1; n     } else { n       start = mid + 1; n     } n   } n   cout << start << endl; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t; n   t = 1; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     string s; n     cin >> s; n     int flag = 1; n     int st; n     char c = s[0]; n     for (int i = 1; i < n; i++) { n       if (s[i] == c) n         continue; n       else { n         st = i; n         flag = 0; n         break; n       } n     } n     if (flag == 1) { n       cout << (n + 2) / 3 << endl; n       continue; n     } n     int ans = 0; n     int m = 1; n     c = s[st]; n     int val = (st + 1) % n; n     for (int i = val; i != st; i = ((i + 1) % n)) { n       if (s[i] == c) { n         m++; n       } else { n         if (m >= 3) ans += (m) / 3; n         c = s[i]; n         m = 1; n       } n     } n     if (m >= 3) ans += (m / 3); n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace Solve { n const int MAXN = 3005; n inline int mymin(int a, int b) { return a < b ? a : b; } n inline int mymax(int a, int b) { return a > b ? a : b; } n int Log[MAXN], maxid[MAXN][20]; n void getLog() { n   Log[1] = 0; n   for (int i = 2; i <= 3000; i++) { n     if (i & 1) n       Log[i] = Log[i - 1]; n     else n       Log[i] = Log[i >> 1] + 1; n   } n   return; n } n void getST(int *A, int n) { n   for (int i = 1; i <= n; i++) maxid[i][0] = i; n   for (int k = 1; k <= 12; k++) { n     for (int i = 1; i + (1 << k) - 1 <= n; i++) { n       int f = i + (1 << (k - 1)); n       if (A[maxid[i][k - 1]] > A[maxid[f][k - 1]]) n         maxid[i][k] = maxid[i][k - 1]; n       else n         maxid[i][k] = maxid[f][k - 1]; n     } n   } n   return; n } n struct Data { n   int id, val; n   Data(int a = 0, int b = 0) : id(a), val(b) {} n   bool operator<(const Data &B) const { return val > B.val; } n } A[MAXN]; n int N, D[MAXN], awd[MAXN]; n int Qmaxid(int l, int r) { n   if (l > r) return 0; n   int k = Log[r - l + 1]; n   int f = r - (1 << k) + 1; n   if (D[maxid[l][k]] > D[maxid[f][k]]) return maxid[l][k]; n   return maxid[f][k]; n } n void work() { n   scanf( %d , &N); n   for (int i = 1; i <= N; i++) scanf( %d , &A[i].val), A[i].id = i; n   sort(A + 1, A + N + 1); n   A[0].val = 0; n   for (int i = 1; i <= N; i++) D[i] = A[i - 1].val - A[i].val; n   D[N + 1] = A[N].val; n   getLog(); n   getST(D, N + 1); n   int mxi = -1, mxj = -1, mxk = -1, ansi = -1, ansj = -1, ansk = -1; n   for (int i = 1; i < N; i++) { n     if (A[i].val - A[i + 1].val < mxi) continue; n     for (int j = i + 1; j < N; j++) { n       if (i > 2 * (j - i)) continue; n       if (j - i > 2 * i) break; n       if (A[i].val - A[i + 1].val == mxi && A[j].val - A[j + 1].val < mxj) n         continue; n       int milen = mymin(i, j - i); n       int mxlen = mymax(i, j - i); n       int low = j + ((mxlen + 1) >> 1) + 1, upp = j + (milen << 1) + 1; n       if (low > N + 1) continue; n       if (upp > N + 1) upp = N + 1; n       int mxid = Qmaxid(low, upp); n       if (A[i].val - A[i + 1].val == mxi && A[j].val - A[j + 1].val == mxj && n           D[mxid] < mxk) n         continue; n       mxi = A[i].val - A[i + 1].val; n       mxj = A[j].val - A[j + 1].val; n       mxk = D[mxid]; n       ansi = i, ansj = j, ansk = mxid - 1; n     } n   } n   for (int i = 1; i <= ansi; i++) awd[A[i].id] = 1; n   for (int i = ansi + 1; i <= ansj; i++) awd[A[i].id] = 2; n   for (int i = ansj + 1; i <= ansk; i++) awd[A[i].id] = 3; n   for (int i = ansk + 1; i <= N; i++) awd[A[i].id] = -1; n   for (int i = 1; i <= N; i++) printf( %d  , awd[i]); n   printf(  n ); n   return; n } n }  // namespace Solve n int main() { n   Solve::work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005, K = 105, P = 998244353; n using ll = long long; n ll dp[N][K], sum[N], cnt[N][K]; n inline bool cmp(int a, int b) { return a == -1 || b == -1 || a == b; } n int n, kk, len, a[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> kk >> len; n   if (len == 1) { n     puts( 0 ); n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     for (int j = 1; j <= kk; j++) cnt[i][j] = cnt[i - 1][j] + cmp(a[i], j); n   } n   sum[0] = 1; n   if (a[1] == -1) { n     for (int i = 1; i <= kk; i++) dp[1][i] = 1; n     sum[1] = kk; n   } else n     sum[1] = 1, dp[1][a[1]] = 1; n   for (int i = 2; i <= n; i++) n     for (int j = 1; j <= kk; j++) n       if (cmp(a[i], j)) { n         dp[i][j] = sum[i - 1]; n         if (i >= len && cnt[i][j] - cnt[i - len][j] == len) { n           dp[i][j] = ((dp[i][j] - sum[i - len] + dp[i - len][j]) % P + P) % P; n         } n         sum[i] = (sum[i] + dp[i][j]) % P; n       } n   cout << sum[n] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 1000 + 5; n const int mod = 1000 * 1000 * 1000 + 7; n int a[65], b[65]; n int main() { n   ios_base::sync_with_stdio(false); n   long long l, r; n   cin >> l >> r; n   for (int i = 0; l > 0; l /= 2, i++) a[i] = l % 2; n   for (int i = 0; r > 0; r /= 2, i++) b[i] = r % 2; n   int i; n   for (i = 60; i >= 0 && a[i] == b[i]; i--) n     ; n   if (i == -1) n     cout << 0 << endl; n   else n     cout << (1ll << (i + 1)) - 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct seg { n   vector<int> id; n   map<pair<int, int>, int> st; n   int getid(int l, int r) { n     int L = lower_bound(id.begin(), id.end(), l) - id.begin(); n     int R = upper_bound(id.begin(), id.end(), r) - id.begin() - 1; n     if (L > R) return -1; n     return st[make_pair(L, R)]; n   } n } tr[20000]; n vector<pair<int, int> > res; n int cur; n int merge(int x, int y) { n   if (x == -1 || y == -1) n     return max(x, y); n   else { n     res.emplace_back(x, y); n     cur++; n     return cur; n   } n } n int blk, tot, Tid = 0; n int n, q, a[5000], Id[5000], l[5000], r[5000]; n int solve(int l, int r, vector<int> id) { n   Tid++; n   int k; n   tr[k = Tid].id = id; n   if (l == r) { n     tr[Tid].st[pair<int, int>(0, 0)] = id[0]; n     return Tid; n   } n   int mid = (l + r) >> 1; n   vector<int> lid, rid; n   for (auto x : id) n     if (a[x] <= mid) n       lid.push_back(x); n     else n       rid.push_back(x); n   int ls = solve(l, mid, lid), rs = solve(mid + 1, r, rid); n   for (int i = 0; i < id.size(); i++) n     for (int j = i; j < id.size(); j++) n       tr[k].st[pair<int, int>(i, j)] = n           merge(tr[ls].getid(id[i], id[j]), tr[rs].getid(id[i], id[j])); n   return k; n } n int main() { n   scanf( %d%d , &n, &q); n   blk = sqrt(q); n   cur = n; n   for (int i = 1; i <= (tot = n / blk); i++) n     l[i] = r[i - 1] + 1, r[i] = i * blk; n   if (tot * blk != n) l[++tot] = r[tot - 1] + 1, r[tot] = n; n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= tot; i++) { n     vector<int> id; n     for (int j = 1; j <= n; j++) n       if (l[i] <= a[j] && a[j] <= r[i]) id.push_back(j); n     Id[i] = solve(l[i], r[i], id); n   } n   vector<int> ans; n   for (int l, r; q--;) { n     scanf( %d%d , &l, &r); n     int rest = -1; n     for (int i = 1; i <= tot; i++) rest = merge(rest, tr[Id[i]].getid(l, r)); n     ans.push_back(rest); n   } n   printf( %d n , cur); n   for (auto x : res) printf( %d %d n , x.first, x.second); n   for (int x : ans) printf( %d  , x); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int a[n], b[n]; n     for (int i = 0; i < n; i++) cin >> a[i]; n     for (int i = 0; i < n; i++) cin >> b[i]; n     sort(a, a + n); n     sort(b, b + n); n     for (int i = 0; i < n; i++) cout << a[i] <<    ; n     cout << endl; n     for (int i = 0; i < n; i++) cout << b[i] <<    ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> tst[100005]; n int rep[100005]; n int idx[100005]; n int arr[100005]; n pair<int, int> sw[1000000]; n int ns; n int num, id; n int islucky(int x) { n   for (; x > 0; x /= 10) n     if (x % 10 != 4 and x % 10 != 7) return 0; n   return 1; n } n int main() { n   int i, j; n   int a, b, c, d; n   int n; n   ns = 0; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d , &arr[i]); n     tst[i] = pair<int, int>(arr[i], i); n   } n   sort(tst, tst + n); n   for (i = 0; i < n; i++) { n     rep[i] = tst[i].first; n     idx[i] = tst[i].second; n     arr[tst[i].second] = i; n   } n   num = -1; n   for (i = 0; i < n; i++) { n     if (islucky(rep[i])) { n       num = i; n       id = idx[i]; n       break; n     } n   } n   if (num == -1) { n     for (i = 0; i < n - 1; i++) n       if (arr[i] > arr[i + 1]) { n         printf( -1 n ); n         return 0; n       } n   } n   for (i = 0; i < n; i++) { n     if (i == num or i == arr[i]) continue; n     a = i; n     b = id; n     c = idx[i]; n     d = arr[i]; n     if (a != b) sw[ns++] = pair<int, int>(a, b); n     if (a != c) sw[ns++] = pair<int, int>(a, c); n     idx[num] = id = c; n     idx[i] = a; n     idx[arr[i]] = b; n     swap(arr[a], arr[b]); n     swap(arr[a], arr[c]); n   } n   printf( %d n , ns); n   for (i = 0; i < ns; i++) printf( %d %d n , sw[i].first + 1, sw[i].second + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, k; n   cin >> n >> k; n   vector<pair<int, int> > v; n   string a; n   cin >> a; n   int balance_max = 0; n   int balance_min = 0; n   v.push_back(pair<int, int>(0, 0)); n   for (int i = 0; i < n - 1; i++) { n     if (a[i] ==  W ) { n       balance_min++; n       if (balance_max < k - 1) balance_max++; n     } else if (a[i] ==  L ) { n       balance_max--; n       if (balance_min > 1 - k) balance_min--; n     } else if (a[i] ==  ? ) { n       if (balance_max < k - 1) balance_max++; n       if (balance_min > 1 - k) balance_min--; n     } n     v.push_back(pair<int, int>(balance_min, balance_max)); n     if (balance_max < balance_min) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   if (a[n - 1] ==  W ) { n     balance_min++; n     balance_max++; n   } else if (a[n - 1] ==  L ) { n     balance_min--; n     balance_max--; n   } else if (a[n - 1] ==  ? ) { n     balance_min--; n     balance_max++; n   } n   v.push_back(pair<int, int>(balance_min, balance_max)); n   int pos = k; n   string solve =   ; n   if (balance_max == k) { n     pos = k; n   } else if (balance_min == -k) { n     pos = -k; n   } else { n     cout <<  NO  << endl; n     return 0; n   } n   for (int i = n - 1; i >= 0; i--) { n     if (a[i] ==  L ) { n       pos++; n       solve +=  L ; n     } else if (a[i] ==  W ) { n       pos--; n       solve +=  W ; n     } else if (a[i] ==  D ) { n       solve +=  D ; n     } else if (a[i] ==  ? ) { n       if (v[i].second < pos) { n         pos--; n         solve +=  W ; n       } else if (v[i].first > pos) { n         pos++; n         solve +=  L ; n       } else n         solve +=  D ; n     } n   } n   reverse(solve.begin(), solve.end()); n   cout << solve << endl; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(3,  Ofast ,  inline ) n using namespace std; n mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); n const long long maxn = (long long)1e6 + 5; n const long long mod = 998244353; n const long long inf = 0x3f3f3f3f; n long long T = 1; n struct edge { n   long long u, v, colu, colv; n   bool operator<(const edge &b) const { n     if (colu != b.colu) return colu < b.colu; n     return colv < b.colv; n   }; n } v[maxn]; n long long tot = 0; n struct node { n   long long u, v, fa, siz; n }; n stack<node> s; n long long pre[maxn]; n long long find(long long x) { n   while (x != pre[x]) x = pre[x]; n   return pre[x]; n } n long long siz[maxn]; n void unite(long long u, long long v) { n   u = find(u), v = find(v); n   if (siz[u] > siz[v]) swap(u, v); n   s.push({u, v, pre[u], siz[u]}); n   if (u != v) { n     pre[u] = v; n     siz[v] += siz[u]; n     siz[u] = 0; n   } n } n void restore() { n   node now = s.top(); n   s.pop(); n   if (now.u != now.v) { n     pre[now.u] = now.fa; n     siz[now.u] = now.siz; n     siz[now.v] -= now.siz; n   } n } n long long col[maxn]; n bool no[maxn]; n void solve() { n   long long n, m, k; n   cin >> n >> m >> k; n   long long cnt = k; n   for (long long i = 1; i <= n; ++i) cin >> col[i]; n   for (long long i = 1; i <= 2 * n; ++i) pre[i] = i, siz[i] = 1; n   for (long long i = 1; i <= m; ++i) { n     long long x, y; n     cin >> x >> y; n     if (col[x] != col[y]) { n       v[++tot] = edge({x, y, col[x], col[y]}); n       if (col[x] > col[y]) swap(v[tot].colu, v[tot].colv); n       continue; n     } n     if (no[col[x]]) continue; n     if (find(x) == find(y)) { n       --cnt; n       no[col[x]] = true; n       continue; n     } n     unite(x, y + n); n     unite(y, x + n); n   } n   long long ans = (cnt - 1) * cnt / 2; n   bool flag = false; n   sort(v + 1, v + tot + 1); n   long long last = s.size(); n   for (long long i = 1; i <= tot; ++i) { n     edge now = v[i]; n     if (no[now.colu] || no[now.colv]) continue; n     if (now.colu != v[i - 1].colu || now.colv != v[i - 1].colv) { n       while (s.size() != last) restore(); n       flag = false; n     } n     if (flag) continue; n     if (find(now.u) == find(now.v)) { n       --ans; n       flag = true; n       continue; n     } n     unite(now.u, now.v + n); n     unite(now.v, now.u + n); n   } n   cout << ans; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   while (T--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1000000000; n const long long longinf = 1000000000000000000; n const double PI = 3.141592653589793; n const long long mod = 1000000007; n long long d[100][2]; n void solve() { n   int n; n   cin >> n; n   vector<long long> v(n); n   for (int i = 0; i < n; ++i) { n     cin >> v[i]; n   } n   vector<long long> sm(n + 1, 0); n   for (int i = n - 1; i >= 0; --i) { n     sm[i] = sm[i + 1] + v[i]; n   } n   d[n][0] = 0; n   d[n][1] = 0; n   for (int i = n - 1; i >= 0; --i) { n     for (int h = 0; h <= 1; ++h) { n       d[i][h] = max(d[i + 1][h], v[i] + sm[i + 1] - d[i + 1][h ^ 1]); n     } n   } n   cout << sm[0] - d[0][0] <<     << d[0][0] << endl; n } n int main() { n   cout.precision(20); n   cin.tie(0); n   iostream::sync_with_stdio(false); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mx=2e5+10; n const int INF=0x3f3f3f; n long long tes[mx][2][2]; n bool flg[mx][2][2]; n int hd[mx],nx[mx*2],t[mx*2],vl[mx*2]; n int sum; n  n struct Node n { n     int x,y,z; n     long long jud; n     bool operator < (const Node &nd) const n     { n         return jud>nd.jud; n     } n }; n  n void add(int x,int y,int z) n { n     t[++sum]=y; n     nx[sum]=hd[x]; n     vl[sum]=z; n     hd[x]=sum; n } n  n void chg() n { n     priority_queue<Node> q; n     q.push({1,0,0,0}); n     memset(tes,0x3f,sizeof(tes)); n     tes[1][0][0]=0; n     while(!q.empty()) n     { n         Node upp=q.top(); n         q.pop(); n         int x=upp.x,y=upp.y,z=upp.z; n         if(flg[x][y][z]) n             continue; n         flg[x][y][z]=1; n         for(int i=hd[x];i;i=nx[i]) n         { n             int a=vl[i],b=t[i]; n             if(tes[b][y][z]>tes[x][y][z]+a) n             { n                 tes[b][y][z]=tes[x][y][z]+a; n                 q.push({b,y,z,tes[b][y][z]}); n             } n             if(!y) n             { n                 if(tes[b][y^1][z]>tes[x][y][z]) n                 { n                     tes[b][y^1][z]=tes[x][y][z]; n                     q.push({b,y^1,z,tes[b][y^1][z]}); n                 } n             } n             if(!z) n             { n                 if(tes[b][y][z^1]>tes[x][y][z]+a*2) n                 { n                     tes[b][y][z^1]=tes[x][y][z]+a*2; n                     q.push({b,y,z^1,tes[b][y][z^1]}); n                 } n             } n             if(!y&&!z) n             { n                 if(tes[b][y^1][z^1]>tes[x][y][z]+a) n                 { n                     tes[b][y^1][z^1]=tes[x][y][z]+a; n                     q.push({b,y^1,z^1,tes[b][y^1][z^1]}); n                 } n             } n         } n     } n } n  n int main() n { n     int n,m; n     scanf( %d %d ,&n,&m); n     for(int i=1;i<=m;i++) n     { n         int x,y,z; n         scanf( %d %d %d ,&x,&y,&z); n         add(x,y,z); n         add(y,x,z); n     } n     chg(); n     for(int i=2;i<=n;i++) n         cout<<tes[i][1][1]<<   ; n } n  n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 2e5 + 5; n pair<long long, long long> a[MAXN]; n long long s; n long long n; n bool check(long long x) { n   long long sum = 0, cnt = 0; n   vector<long long> nums; n   for (long long i = 0; i < n; i++) { n     if (a[i].first >= x) { n       sum += a[i].first; n       cnt++; n     } else { n       if (a[i].second < x) { n         sum += a[i].first; n       } else { n         nums.push_back(a[i].first); n       } n     } n   } n   long long left = max((long long)0, (n + 1) / 2 - cnt); n   if (left > nums.size()) return 0; n   for (long long i = 0; i < nums.size() - left; i++) { n     sum += nums[i]; n   } n   for (long long i = nums.size() - left; i < nums.size(); i++) { n     sum += x; n   } n   return (sum <= s); n } n int main() { n   long long q; n   cin >> q; n   while (q--) { n     cin >> n >> s; n     for (long long i = 0; i < n; i++) { n       cin >> a[i].first >> a[i].second; n     } n     sort(a, a + n); n     long long l = 1, r = 1e9 + 100; n     while (l + 1 < r) { n       long long m = (l + r) >> 1; n       if (check(m)) { n         l = m; n       } else { n         r = m; n       } n     } n     cout << l <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, res, tmp, m; n vector<int> v; n bool check(int val) { n   int m = n - val; n   return m % (2 * k + 1) <= k; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> k; n   int i = min(n, k + 1); n   while (!check(i)) i--; n   while (i <= n) { n     if (i <= n) v.push_back(i); n     i += 2 * k + 1; n   } n   if (v[v.size() - 1] + k < n) v.push_back(n); n   cout << v.size() <<   n ; n   for (int i = 0; i < v.size(); i++) cout << v[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 300 + 5; n int n, m, p; n int grid[MAX][MAX]; n int dp[MAX][MAX]; n vector<pair<int, int> > pos[MAX * MAX]; n vector<int> col[MAX]; n int main() { n   scanf( %d %d %d , &n, &m, &p); n   for (int i = int(0); i < int(n); i++) { n     for (int j = int(0); j < int(m); j++) { n       scanf( %d , &grid[i][j]); n       if (grid[i][j] == 1) { n         dp[i][j] = i + j; n       } else { n         dp[i][j] = 1 << 30; n       } n       pos[grid[i][j]].emplace_back(i, j); n     } n   } n   bool visited[MAX]; n   for (int i = int(1); i < int(p); i++) { n     memset(visited, false, sizeof visited); n     for (int c = int(0); c < int(m); c++) { n       col[c].clear(); n     } n     for (auto &each : pos[i + 1]) { n       col[each.second].push_back(each.first); n     } n     for (auto &each : pos[i]) { n       visited[each.first] = true; n     } n     for (int r = int(0); r < int(n); r++) { n       if (visited[r]) { n         int best = 1 << 30; n         for (int c = int(0); c < int(m); c++) { n           best++; n           if (grid[r][c] == i) { n             best = min(best, dp[r][c]); n           } n           for (auto &each : col[c]) { n             dp[each][c] = min(dp[each][c], best + abs(each - r)); n           } n         } n         best = 1 << 30; n         for (int c = int(m - 1); c >= int(0); c--) { n           best++; n           if (grid[r][c] == i) { n             best = min(best, dp[r][c]); n           } n           for (auto &each : col[c]) { n             dp[each][c] = min(dp[each][c], best + abs(each - r)); n           } n         } n       } n     } n   } n   printf( %d n , dp[pos[p][0].first][pos[p][0].second]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long ll; n typedef vector<int> vi; n typedef vector<int> vll; n typedef pair<int, int> pii; n #define F first n #define S second n #define PB push_back n #define MP make_pair n #define ALL(v) v.begin(), v.end() n #define rALL(v) v.rbegin(), v.rend() n #define INF 1000000007LL n #define MOD 998244353LL n  n const int LIM = 2e5 + 5; n  n void solve() n { n     int n, x, f, res = 0; n     cin >> n; n     for(int i = 0; i < n; i++) n     { n         cin >> x; n         f = 0; n         for(int j = 1; j * j <= x; j++) n             if(j * j == x) n             { n                 f = 1; n                 break; n             } n         if(f == 0) n             res = 1; n     } n  n     if(res) n         cout <<  YES n ; n     else n         cout <<  NO n ; n      n } n  n int main() n { n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n  n     int t = 1; n     cin >> t; n     while (t--) n     { n         solve(); n     } n  n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a, b; n   int n; n   cin >> n; n   cin >> a >> b; n   int ans = 0; n   for (int i = 0; i < n - 1; i++) { n     if (a[i] != b[i]) { n       ans++; n       if (a[i + 1] != b[i + 1] && a[i] != a[i + 1]) { n         swap(a[i], a[i + 1]); n       } else n         a[i] = b[i]; n     } n   } n   if (a[n - 1] != b[n - 1]) ans++; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef int matrix[140][140]; n const int modp = 12345; n int k, N, mod[30], base[30], cnt[30], num[30][30]; n int legal[140], ans; n long long n; n matrix a, b; n void mul(matrix a, matrix b) { n   matrix c; n   for (int i = 0; i < N; i++) n     for (int j = 0; j < N; j++) c[i][j] = 0; n   for (int i = 0; i < N; i++) n     for (int j = 0; j < N; j++) n       for (int k = 0; k < N; k++) n         c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % modp; n   for (int i = 0; i < N; i++) n     for (int j = 0; j < N; j++) a[i][j] = c[i][j]; n } n int gcd(int x, int y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n int main() { n   cin >> n >> k; n   for (int i = 0; i < 26; i++) mod[i] = 1; n   for (int i = 1; i <= k; i++) { n     char type[4]; n     int p, x; n     scanf( %s , type); n     p = type[0] -  A ; n     scanf( %d , &x); n     mod[p] *= x / gcd(x, mod[p]); n     cnt[p]++; n     num[p][cnt[p]] = x; n   } n   base[0] = 1; n   for (int i = 0; i < 26; i++) base[i + 1] = base[i] * mod[i]; n   N = base[26]; n   for (int i = 0; i < N; i++) { n     legal[i] = 1; n     for (int j = 0; j < 26; j++) n       if (cnt[j]) { n         int res = 0, zt; n         zt = i + base[j]; n         if ((i / base[j] + 1) % mod[j] == 0) zt -= base[j + 1]; n         b[i][zt]++; n         for (int k = 1; k <= cnt[j]; k++) n           if ((i / base[j]) % num[j][k] == 0) res = 1; n         legal[i] &= res; n       } n   } n   a[0][0] = 1; n   for (; n; n >>= 1) { n     if (n & 1) mul(a, b); n     mul(b, b); n   } n   for (int i = 0; i < N; i++) n     if (legal[i]) ans = (ans + a[0][i]) % modp; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cout.precision(30); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   vector<pair<long long, long long>> ps(n); n   for (int i = 0; i < n; i++) { n     cin >> ps[i].first >> ps[i].second; n   } n   sort(ps.begin(), ps.end(), n        [&](pair<long long, long long> a, pair<long long, long long> b) { n          return make_pair(a.second, a.first) < make_pair(b.second, b.first); n        }); n   vector<long long> hadv(n, 0), hadh(n, 0); n   vector<pair<long long, long long>> v, h; n   vector<pair<pair<long long, long long>, pair<long long, long long>>> verts; n   long long cury = ps[0].second; n   for (int i = 1; i < n; i++) { n     if (cury != ps[i].second) { n       cury = ps[i].second; n     } else { n       hadv[i - 1] = 1; n       hadv[i] = 1; n       verts.push_back({ps[i - 1], ps[i]}); n     } n   } n   for (int i = 0; i < n; i++) { n     if (!hadv[i]) v.push_back(ps[i]), v.push_back(ps[i]); n   } n   sort(ps.begin(), ps.end()); n   vector<pair<pair<long long, long long>, pair<long long, long long>>> hors; n   long long curx = ps[0].first; n   for (int i = 1; i < n; i++) { n     if (curx != ps[i].first) { n       curx = ps[i].first; n     } else { n       hadh[i - 1] = 1; n       hadh[i] = 1; n       hors.push_back({ps[i - 1], ps[i]}); n     } n   } n   for (int i = 0; i < n; i++) { n     if (!hadh[i]) h.push_back(ps[i]), h.push_back(ps[i]); n   } n   swap(hors, verts); n   swap(h, v); n   auto inter = [&](pair<long long, long long> a, pair<long long, long long> b, n                    pair<long long, long long> c, pair<long long, long long> d) { n     if (c.first < a.first && a.first < d.first) { n       if (a.second < c.second && c.second < b.second) return true; n     } n     return false; n   }; n   vector<vector<long long>> g(verts.size()); n   for (int i = 0; i < verts.size(); i++) { n     for (int j = 0; j < hors.size(); j++) { n       if (inter(verts[i].first, verts[i].second, hors[j].first, hors[j].second)) n         g[i].push_back(j); n     } n   } n   vector<long long> to(hors.size(), -1); n   vector<long long> used(verts.size(), 0); n   vector<long long> from(verts.size(), -1); n   function<bool(int)> dfs = [&](int v) { n     if (used[v]) return false; n     used[v] = 1; n     for (int u : g[v]) { n       if (to[u] == -1 || dfs(to[u])) { n         to[u] = v; n         from[v] = u; n         return true; n       } n     } n     return false; n   }; n   for (int i = 0; i < verts.size(); i++) { n     used.assign(verts.size(), 0); n     dfs(i); n   } n   used.assign(verts.size(), 0); n   vector<long long> used1(hors.size(), 0); n   function<void(int)> dfs1 = [&](int v) { n     if (used[v]) return; n     used[v] = 1; n     for (int u : g[v]) { n       if (!used1[u]) { n         used1[u] = 1; n         dfs1(to[u]); n       } n     } n   }; n   vector<long long> free(verts.size(), 1); n   for (int i : to) n     if (i != -1) free[i] = 0; n   for (int i = 0; i < verts.size(); i++) n     if (free[i]) dfs1(i); n   for (int i = 0; i < verts.size(); i++) { n     auto a = verts[i].first, b = verts[i].second; n     if (i == 0 || verts[i - 1].second != verts[i].first) { n       if (i > 0) v.push_back(verts[i - 1].second); n       v.push_back(a); n     } n     if (!used[i]) v.push_back(a), v.push_back(b); n   } n   if (!verts.empty()) v.push_back(verts.back().second); n   for (int i = 0; i < hors.size(); i++) { n     auto a = hors[i].first, b = hors[i].second; n     if (i == 0 || hors[i - 1].second != hors[i].first) { n       if (i > 0) h.push_back(hors[i - 1].second); n       h.push_back(a); n     } n     if (used1[i]) h.push_back(a), h.push_back(b); n   } n   if (!hors.empty()) h.push_back(hors.back().second); n   cout << h.size() / 2 << endl; n   for (int i = 0; i < h.size(); i++) n     cout << h[i].first <<     << h[i].second << ((i % 2) ?   n  :    ); n   cout << v.size() / 2 << endl; n   for (int i = 0; i < v.size(); i++) n     cout << v[i].first <<     << v[i].second << ((i % 2) ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, k; n   cin >> n >> k; n   while (k > 0) { n     if (n % 10 != 0 && k >= n % 10) { n       k -= n % 10; n       n -= n % 10; n     } else if (n % 10 != 0 && k < n % 10) { n       n -= k; n       k -= k; n     } else if (n % 10 == 0) { n       n = n / 10; n       k--; n     } n   } n   cout << n << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T in() { n   char ch; n   T n = 0; n   bool ng = false; n   while (1) { n     ch = getchar(); n     if (ch ==  - ) { n       ng = true; n       ch = getchar(); n       break; n     } n     if (ch >=  0  && ch <=  9 ) break; n   } n   while (1) { n     n = n * 10 + (ch -  0 ); n     ch = getchar(); n     if (ch <  0  || ch >  9 ) break; n   } n   return (ng ? -n : n); n } n template <typename T> n inline T Dist(T x1, T y1, T x2, T y2) { n   return sqrt((x1 - x2 * x1 - x2) + (y1 - y2 * y1 - y2)); n } n template <typename T> n inline T POW(T B, T P) { n   if (P == 0) return 1; n   if (P & 1) n     return B * POW(B, P - 1); n   else n     return (POW(B, P / 2) * POW(B, P / 2)); n } n template <typename T> n inline T ABS(T a) { n   if (a < 0) n     return -a; n   else n     return a; n } n template <typename T> n inline T Gcd(T a, T b) { n   if (a < 0) return Gcd(-a, b); n   if (b < 0) return Gcd(a, -b); n   return (b == 0) ? a : Gcd(b, a % b); n } n template <typename T> n inline T Lcm(T a, T b) { n   if (a < 0) return Lcm(-a, b); n   if (b < 0) return Lcm(a, -b); n   return a * (b / Gcd(a, b)); n } n long long Bigmod(long long base, long long power, long long MOD) { n   long long ret = 1; n   while (power) { n     if (power & 1) ret = (ret * base) % MOD; n     base = (base * base) % MOD; n     power >>= 1; n   } n   return ret; n } n long long ModInverse(long long number, long long MOD) { n   return Bigmod(number, MOD - 2, MOD); n } n int Set(int N, int pos) { return N = N | (1 << pos); } n int Reset(int N, int pos) { return N = N & ~(1 << pos); } n bool Chkbit(int N, int pos) { return (bool)(N & (1 << pos)); } n bool isVowel(char ch) { n   ch = toupper(ch); n   if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E ) n     return true; n   return false; n } n bool isConst(char ch) { n   if (isalpha(ch) && !isVowel(ch)) return true; n   return false; n } n int toInt(string s) { n   int sm; n   stringstream ss(s); n   ss >> sm; n   return sm; n } n long long int toLlint(string s) { n   long long int sm; n   stringstream ss(s); n   ss >> sm; n   return sm; n } n struct z { n   long long int lft, rgt; n   z() {} n   z(long long int _, long long int __) { lft = _, rgt = __; } n }; n int h, q; n z Solve(long long int lev, long long int l, long long int r) { n   long long int now = l, now1 = r; n   for (int i = lev + 1; i <= h; i++) { n     now *= 2LL; n     now1 *= 2LL; n     now1 += 1LL; n   } n   return z(now, now1); n } n vector<z> A, B; n bool cmp(z a, z b) { return ((a.rgt - a.lft) > (b.rgt - b.lft)); } n bool cmp1(z a, z b) { return (a.lft < b.lft); } n vector<z> C; n int main() { n   h = in<int>(), q = in<int>(); n   for (int i = 0; i < q; i++) { n     long long int a, l, r, id; n     a = in<long long int>(), l = in<long long int>(), r = in<long long int>(), n     id = in<long long int>(); n     if (id) n       A.push_back(Solve(a, l, r)); n     else n       B.push_back(Solve(a, l, r)); n   } n   sort(B.begin(), B.end(), cmp1); n   long long int lf, rg; n   if (A.size() == 0) { n     z tp = Solve(1, 1, 1); n     lf = tp.lft, rg = tp.rgt; n   } else { n     z tp = Solve(1, 1, 1); n     lf = tp.lft, rg = tp.rgt; n     for (int i = 0; i < A.size(); i++) { n       long long int l = A[i].lft, r = A[i].rgt; n       if (lf > r || rg < l) { n         printf( Game cheated! n ); n         return 0; n       } n       lf = max(lf, l); n       rg = min(rg, r); n     } n   } n   if (B.size() == 0) { n     if (lf == rg) { n       cout << lf << endl; n     } else n       printf( Data not sufficient! n ); n     return 0; n   } n   for (int i = 0; i < B.size(); i++) { n     long long int lf1 = B[i].lft, rg1 = B[i].rgt; n     if (rg1 < lf || lf1 > rg) n       continue; n     else { n       C.push_back(z(max(lf, lf1), min(rg, rg1))); n     } n   } n   if (C.size() == 0) { n     if (lf == rg) { n       cout << lf << endl; n     } else n       printf( Data not sufficient! n ); n     return 0; n   } n   sort(C.begin(), C.end(), cmp1); n   long long int ans = -1; n   if (C[0].lft - 1 == lf) { n     ans = lf; n   } else if (lf + 1 < C[0].lft) { n     printf( Data not sufficient! n ); n     return 0; n   } n   long long int Rgt = C[0].rgt; n   for (int i = 1; i < C.size(); i++) { n     long long int lf1 = C[i].lft, rg1 = C[i].rgt; n     if (Rgt + 1 < C[i].lft) { n       long long int dff = C[i].lft - Rgt - 1; n       if (dff == 1) { n         if (ans == -1) { n           ans = Rgt + 1; n         } else { n           printf( Data not sufficient! n ); n           return 0; n         } n       } else { n         printf( Data not sufficient! n ); n         return 0; n       } n     } n     Rgt = max(Rgt, C[i].rgt); n   } n   if (rg >= Rgt + 1) { n     if (rg == Rgt + 1) { n       if (ans == -1) { n         ans = rg; n       } else { n         printf( Data not sufficient! n ); n         return 0; n       } n     } else { n       printf( Data not sufficient! n ); n       return 0; n     } n   } n   if (ans == -1) { n     printf( Game cheated! n ); n     return 0; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n double eps = 1e-10; n using namespace std; n long long m, h1, a1, x_1, y_1, h2, a2, x_2, y_2, len1, len2, l1, l2, i1 = -1, n                                                                      i2 = -1; n int idx1[1000006], idx2[1000006], cycle1[1000006], cycle2[1000006]; n bool check(long long x) { n   if (x < l2) { n     if (cycle2[x] == a2) n       return 1; n     else n       return 0; n   } n   x -= l2; n   x %= len2; n   return (cycle2[x + l2] == a2); n } n int main() { n   cin >> m >> h1 >> a1 >> x_1 >> y_1 >> h2 >> a2 >> x_2 >> y_2; n   for (int i = 0; i <= 1000000; i++) idx1[i] = idx2[i] = -1; n   idx1[h1] = 0, idx2[h2] = 0; n   cycle1[0] = h1, cycle2[0] = h2; n   for (int i = 1; i <= m + 1; i++) { n     int height = (x_1 * cycle1[i - 1] + y_1) % m; n     if (idx1[height] != -1) { n       len1 = i - idx1[height]; n       l1 = idx1[height]; n       break; n     } else { n       cycle1[i] = height; n       idx1[height] = i; n     } n   } n   for (int i = 1; i <= m + 1; i++) { n     int height = (x_2 * cycle2[i - 1] + y_2) % m; n     if (idx2[height] != -1) { n       len2 = i - idx2[height]; n       l2 = idx2[height]; n       break; n     } else { n       cycle2[i] = height; n       idx2[height] = i; n     } n   } n   for (int i = 0; i < l1; i++) { n     if (cycle1[i] == a1) { n       if (check(i)) { n         cout << i << endl; n       } else { n         puts( -1 ); n       } n       return 0; n     } n   } n   for (int i = l1; i < len1 + l1; i++) { n     if (cycle1[i] == a1) { n       i1 = i - l1; n       break; n     } n   } n   if (i1 == -1) { n     puts( -1 ); n     return 0; n   } n   for (int k1 = 0; k1 < 1000002; k1++) { n     long long t = l1 + (long long)k1 * len1 + i1; n     if (check(t)) { n       cout << t << endl; n       return 0; n     } n   } n   puts( -1 ); n } n


#include <bits/stdc++.h> n using namespace std; n bool debug = true; n template <typename T1, typename T2> n ostream& operator<<(ostream& os, pair<T1, T2> ptt) { n   os << ptt.first <<  ,  << ptt.second; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, vector<T> vt) { n   os <<  { ; n   for (int i = 0; i < vt.size(); i++) { n     os << vt[i] <<    ; n   } n   os <<  } ; n   return os; n } n int n, k; n int a[200005]; n int main(int argc, char* argv[]) { n   int t; n   cin >> t; n   while (t--) { n     cin >> n >> k; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     int mx = 0; n     for (int i = 0; i < n - k; i++) { n       if (a[i + k] - a[i] < a[mx + k] - a[mx]) { n         mx = i; n       } n     } n     cout << (a[mx + k] + a[mx]) / 2 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n long long n, k, m; n long long dp[1010][110][2], pw[1010], PW[1010]; n long long Solve(long long p, long long r, int f) { n   if (p <= 0) return f; n   if (~dp[p][r][f]) return dp[p][r][f]; n   if (f) return (9LL * PW[p - 1]) % m; n   long long res = 0; n   for (int i = ((p == 1) ? 1 : 0); i <= (9); ++i) { n     long long nr = (r + (long long)i * pw[n - p]) % k; n     res = (res + Solve(p - 1, nr, f || (!nr && i))) % m; n   } n   return dp[p][r][f] = res; n } n int main() { n   scanf( %I64d%I64d%I64d , &n, &k, &m); n   pw[0] = PW[0] = 1; n   for (int i = 1; i <= (n); ++i) n     pw[i] = (pw[i - 1] * 10) % k, PW[i] = (PW[i - 1] * 10) % m; n   memset(dp, -1, sizeof(dp)); n   printf( %I64d n , Solve(n, 0, 0)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, c, d, e, i, j, ii, jj, zx, xc, p[10009], ji, F[10009], G[10009]; n pair<int, int> k[10009]; n vector<int> v; n vector<int>::iterator it; n int ask(int q, int w) { n   int qw = 0; n   cout <<  ?   << q <<     << w << endl; n   cin >> qw; n   return qw; n } n int fun(int q) { n   int qw = 0; n   if (q != k[0].first) { n     qw = ask(q, k[0].first); n   } else { n     qw = ask(q, k[0].second); n   } n   for (j = 1; j <= ji; j++) { n     if (q != k[j].first) { n       e = ask(q, k[j].first); n     } else { n       e = ask(q, k[j].second); n     } n     qw &= e; n   } n   return qw; n } n void answer() { n   cout <<  ! ; n   for (j = 1; j <= a; j++) { n     cout <<     << p[j]; n   } n   exit(0); n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> a; n   for (j = 0;; j++) { n     if ((1 << j) >= a) break; n     ji = j; n   } n   while (1) { n     for (j = 0; j <= ji; j++) { n       if (k[j].first == 0) break; n     } n     if (j == ji + 1) break; n     c = rand() % a + 1; n     d = rand() % a + 1; n     if (c == d) continue; n     e = ask(c, d); n     for (jj = 0; jj <= ji; jj++) { n       if ((e & (1 << jj)) == 0) { n         k[jj].first = c; n         k[jj].second = d; n       } n     } n   } n   for (i = 1; i <= a; i++) { n     c = rand() % (a - i + 1) + 1; n     G[i] = c; n     v.push_back(i); n   } n   for (i = 1; i <= a; i++) { n     F[i] = v[G[i] - 1]; n     it = v.begin() + (G[i] - 1); n     v.erase(it); n   } n   p[F[1]] = fun(F[1]); n   c = F[1]; n   for (i = 2; i <= a; i++) { n     e = ask(c, F[i]); n     if (p[c] == e) { n       c = F[i]; n       p[c] = fun(c); n     } n   } n   p[c] = 0; n   for (i = 1; i <= a; i++) { n     if (i == c) continue; n     p[i] = ask(i, c); n   } n   answer(); n   return 0; n } n