#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& os, const array<T, 2>& a) {     for (T e : a) {       os << e <<    ;     };     return os;   }   inline void lol(const function<void(int)>& fun, const array<int, 2>& f,                   const array<int, 2>& s) {     if (f == s) {       return;     }     for (int i = 0; i < 2; ++i) {       for (int j = 0; j < 2; ++j) {         if (f[i] == s[j]) {           fun(f[i]);         }       }     }   }   inline int common(const array<int, 2>& f, const array<int, 2>& s) {     for (int i = 0; i < 2; ++i) {       for (int j = 0; j < 2; ++j) {         if (f[i] == s[j]) {           return f[i];         }       }     }   }   bool ok(const vector<array<int, 2>>& a, const array<int, 2>& f) {     unordered_set<int> s;     for (auto& p : a) {       lol([&](int x) { s.emplace(x); }, p, f);     }     return s.size() == 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<array<int, 2>> first(n), second(m);     for (int i = 0; i < n; ++i) {       cin >> first[i][0] >> first[i][1];       if (first[i][0] > first[i][1]) {         swap(first[i][0], first[i][1]);       }     }     for (int i = 0; i < m; ++i) {       cin >> second[i][0] >> second[i][1];       if (second[i][0] > second[i][1]) {         swap(second[i][0], second[i][1]);       }     }     unordered_set<int> candidates;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         lol([&](int x) { candidates.emplace(x); }, first[i], second[j]);       }     }     if (candidates.size() == 1) {       cout << *candidates.begin() <<   n ;       return 0;     }     bool they_know = true;     for (auto& f : first) {       vector<array<int, 2>> v;       for (auto& s : second) {         lol([&](int x) { v.emplace_back(s); }, f, s);       }       if (v.empty()) {         continue;       }       int chosen = common(f, v.front());       for (int i = 1; i < v.size(); ++i) {         if (chosen != common(f, v[i])) {           they_know = false;           break;         }       }       for (int i = 0; i < v.size(); ++i) {         if (!ok(first, v[i])) {           they_know = false;           break;         }       }       if (!they_know) {         break;       }     }     if (they_know) {       cout <<  0 n ;     } else {       cout <<  -1 n ;     }     return 0;   }


#include <bits/stdc++.h>   int n, m, k;   std::set<int> r;   std::set<std::pair<int, int> > e;   std::string getAnswer(bool b) {     if (b != 0)       return  possible ;     else       return  impossible ;   }   bool check(int x, int y) {     if (x > y) std::swap(x, y);     return e.find(std::make_pair(x, y)) == e.end();   }   void dfs(int x) {     std::vector<int> s;     for (auto now : r) {       if (check(x, now)) {         s.push_back(now);       }     }     for (auto now : s) {       r.erase(now);     }     for (auto now : s) {       dfs(now);     }   }   int main() {     std::cin >> n >> m >> k;     for (int i = 1; i <= m; i++) {       int x, y;       static int deg = 0;       std::cin >> x >> y;       if (x > y) std::swap(x, y);       e.insert(std::make_pair(x, y));       if (x == 1 && ++deg > n - k - 1) {         return puts(getAnswer(false).c_str()), 0;       }     }     for (int i = 2; i <= n; i++) {       r.insert(i);     }     int nBlock = 0;     for (int i = 2; i <= n; i++) {       if (check(1, i) && r.find(i) != r.end()) {         nBlock++;         r.erase(i);         dfs(i);       }     }     std::cout << getAnswer(nBlock <= k && r.empty()) << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tt = 1;     while (tt--) {       long long n;       cin >> n;       long long arr[n + 1];       for (long long i = 0; i < n; i++) cin >> arr[i];       arr[n] = arr[n - 1];       long long mx = -1;       long long ans = INT_MAX;       for (long long i = 0; i < n; i++) {         mx = max(arr[i], arr[i + 1]);         ans = min(ans, mx);       }       cout << min({ans, arr[0], arr[n]});       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   int N;   char A[2020];   char B[2020];   long long D[2020][4040];   long long E[2020][4040];   int main() {     int tc;     scanf( %d , &tc);     while (tc--) {       scanf( %d , &N);       scanf( %s , A + 1);       scanf( %s , B + 1);       for (int i = 0; i <= N + 1; i++)         for (int j = 0; j <= N + N; j++) D[i][j] = E[i][j] = 0;       D[0][N] = 1;       for (int i = 1; i <= N; i++) {         for (int j = 0; j <= N + N; j++) {           for (int k = 0; k < 2; k++) {             if (A[i] !=  ?  && A[i] != k +  0 ) continue;             for (int l = 0; l < 2; l++) {               if (B[i] !=  ?  && B[i] != l +  0 ) continue;               int tj = (i & 1 ? j + l - k : j - l + k);               if (tj < 0 || tj > N + N) continue;               D[i][tj] = (D[i][tj] + D[i - 1][j]) % MOD;             }           }         }       }       E[N + 1][N] = 1;       for (int i = N; i >= 1; i--) {         for (int j = 0; j <= N + N; j++) {           for (int k = 0; k < 2; k++) {             if (A[i] !=  ?  && A[i] != k +  0 ) continue;             for (int l = 0; l < 2; l++) {               if (B[i] !=  ?  && B[i] != l +  0 ) continue;               int tj = (~i & 1 ? j + l - k : j - l + k);               if (tj < 0 || tj > N + N) continue;               E[i][tj] = (E[i][tj] + E[i + 1][j]) % MOD;             }           }         }       }       long long ans = 0;       for (int i = 1; i < N; i++) {         for (int j = 0; j <= N + N; j++) {           ans = (ans + abs(j - N) * D[i][j] % MOD * E[i + 1][j]) % MOD;         }       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct st {     int x, p;   };   bool myfun(st a, st b) { return a.x < b.x; }   int main() {     int i, sum = 0, c = 0, n, k;     st a[110];     cin >> n >> k;     for (i = 0; i < n; ++i) {       a[i].p = i + 1;       cin >> a[i].x;     }     sort(a, a + n, myfun);     for (i = 0; i < n; ++i) {       sum += a[i].x;       if (sum > k) break;       c++;     }     cout << c <<   n ;     for (i = 0; i < c; ++i) cout << a[i].p <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr long long maxn = 2e5 + 5, inf = 0x3f3f3f3f;   vector<long long> e[maxn];   long long n, m, k, c[maxn], ans;   void dfs(long long u, long long fa) {     for (auto v : e[u]) {       if (v == fa) continue;       dfs(v, u);       c[u] += c[v];       ans += min(c[v], k - c[v]);     }   }   signed main() {     cin >> n >> k;     k *= 2;     for (long long i = 1; i <= k; i++) {       long long x;       cin >> x;       c[x] = 1;     }     for (long long i = 1; i < n; i++) {       long long u, v;       cin >> u >> v;       e[u].push_back(v);       e[v].push_back(u);     }     dfs(1, 1);     cout << ans;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   long long seg[5000000];   long long scn[5000000];   void update(long long pos, long long x, long long l = 0, long long r = 300000,               long long ind = 1) {     if (l == r && l == pos)       seg[ind] = x, scn[ind] = x > 0;     else if (l > pos || r < pos)       return;     else if (l != r) {       update(pos, x, l, (l + r) / 2, ind * 2);       update(pos, x, (l + r) / 2 + 1, r, ind * 2 + 1);       seg[ind] = seg[ind * 2] + seg[ind * 2 + 1];       scn[ind] = scn[ind * 2] + scn[ind * 2 + 1];     }   }   long long query(long long light, long long l = 0, long long r = 300000,                   long long ind = 1) {     if (l == r || scn[ind] == light) return seg[ind];     if (scn[ind * 2] >= light)       return query(light, l, (l + r) / 2, ind * 2);     else       return seg[ind * 2] +              query(light - scn[ind * 2], (l + r) / 2 + 1, r, ind * 2 + 1);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     pair<long long, long long> a[n];     set<long long> all;     for (long long i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;       if (a[i].second > 0) {         all.insert(-a[i].second);       }     }     map<long long, long long> mapper;     long long cnt = 1;     for (auto v : all) {       mapper[-v] = cnt++;     }     cnt = 0;     set<long long> light;     for (long long i = 0; i < n; i++) {       if (a[i].first && a[i].second > 0)         light.insert(a[i].second);       else if (a[i].first && a[i].second < 0)         light.erase(-a[i].second);       if (a[i].second > 0)         update(mapper[a[i].second], a[i].second), cnt++;       else if (a[i].second < 0)         update(mapper[-a[i].second], 0), cnt--;       long long ans = seg[1];       if (light.size()) update(mapper[(*light.begin())], 0);       if (cnt == (long long)light.size())         ans += query((long long)light.size() - 1);       else         ans += query(light.size());       if (light.size()) update(mapper[(*light.begin())], (*light.begin()));       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void sol() {     long long int n, k;     cin >> n >> k;     if (n == k)       cout << -1 <<   n ;     else {       long long int ar[n];       for (long long int i = 0; i < k; i++) {         ar[n - 1 - i] = n - i;       }       ar[n - 1 - k] = 1;       for (long long int i = 2; i <= n - k; i++) cout << i <<    ;       for (long long int i = n - 1 - k; i < n; i++) cout << ar[i] <<    ;     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t = 1;     while (t--) {       sol();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7;   bool prime[1000001] = {true};   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     vector<int> arr(m);     if (m == 0) {       cout <<  YES ;       return 0;     }     for (int i = 0; i < m; i++) {       cin >> arr[i];     }     sort(arr.begin(), arr.end());     if (arr[0] == 1 || arr[m - 1] == n) {       cout <<  NO ;       return 0;     } else {       for (int i = 0; i < m - 1; i++) {         if (i < m - 2 && arr[i] + 1 == arr[i + 1] &&             arr[i + 1] + 1 == arr[i + 2]) {           cout <<  NO ;           return 0;         }       }       cout <<  YES ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ar[100010], flag = 1, cnt = 1;     char s[100010];     scanf( %d , &n);     getchar();     for (int i = 1; i <= n; i++) scanf( %c , &s[i]);     for (int i = 1; i <= n; i++) scanf( %d , &ar[i]);     for (int i = 1; i <= n; i++) {       if (s[cnt] ==  > )         cnt += ar[cnt];       else         cnt -= ar[cnt];       if (cnt > n || cnt < 1) {         printf( FINITE n );         flag = 0;         break;       }     }     if (flag) printf( INFINITE n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long qsm(long long a, int b) {     a %= mod;     long long ret = 1;     while (b) {       if (b & 1) ret = ret * a % mod;       b >>= 1;       a = a * a % mod;     }     return ret;   }   long long a[220000], b[220000], f[220000];   int main() {     long long n;     scanf( %lld , &n);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]), b[i] = a[i];     if (n == 1) {       printf( %lld n , a[0]);       return 0;     }     if (n & 1) {       n--;       int o = 0;       for (int i = 0; i < n; i++) {         if (!o)           b[i] = (a[i] + a[i + 1]) % mod;         else           b[i] = (a[i] - a[i + 1]) % mod;         o ^= 1;       }     }     f[0] = 1;     long long m = n / 2 - 1;     for (int i = 1; i <= m; i++) f[i] = f[i - 1] * i % mod;     long long ans1 = 0, ans2 = 0;     for (int i = 0; i <= m; i++) {       ans1 = (ans1 + f[m] * qsm(f[i] * f[m - i], mod - 2) % mod * b[i * 2]) % mod;       ans2 = (ans2 + f[m] * qsm(f[i] * f[m - i], mod - 2) % mod * b[i * 2 + 1]) %              mod;     }     long long ans;     if ((n * (n - 1) / 2) & 1)       ans = ((ans1 + ans2) % mod + mod) % mod;     else       ans = ((ans1 - ans2) % mod + mod) % mod;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   using vvi = vector<vi>;   using ii = pair<int, int>;   using vii = vector<ii>;   using l = long long;   using vl = vector<l>;   using vvl = vector<vl>;   using ll = pair<l, l>;   using vll = vector<ll>;   using vvll = vector<vll>;   using lu = unsigned long long;   using vb = vector<bool>;   using vvb = vector<vb>;   using vd = vector<double>;   using vvd = vector<vd>;   const int INF = numeric_limits<int>::max();   const double EPS = 1e-10;   const l e5 = 100000, e6 = 1000000, e7 = 10000000, e9 = 1000000000;   struct node;   struct edge;   using pnode = shared_ptr<node>;   using graph = vector<pnode>;   struct node {     bool visited = false;     vector<pnode> adjusted;     char letter =  x ;     l same = 0;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     l n, m;     while (cin >> n >> m) {       graph g(n);       for (auto &u : g) {         u = make_shared<node>();       }       for (l i = 0; i < m; i++) {         l a, b;         cin >> a >> b;         a--;         b--;         g[a]->adjusted.push_back(g[b]);         g[b]->adjusted.push_back(g[a]);       }       bool ok = true;       for (auto u : g) {         if (u->adjusted.size() == n - 1) {           u->letter =  b ;           u->visited = true;         }       }       char x =  a ;       for (auto u : g) {         if (u->visited) continue;         if (x ==  x ) {           ok = false;           break;         }         queue<pnode> q;         q.emplace(u);         l marked = 0;         u->visited = true;         u->letter = x;         marked++;         while (!q.empty()) {           auto v = q.front();           q.pop();           for (auto r : v->adjusted) {             if (!r->visited || r->letter == v->letter) v->same++;             if (r->visited) continue;             r->visited = true;             r->letter = x;             marked++;             q.emplace(r);           }         }         for (auto v : g) {           if (v->letter != x) continue;           if (v->same != marked - 1) ok = false;         }         if (!ok) break;         if (x ==  a ) {           x =  c ;         } else {           x =  x ;         }       }       if (ok) {         cout <<  Yes  << endl;         for (auto u : g) cout << u->letter;         cout << endl;       } else {         cout <<  No  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 1;     cin >> n;     vector<vector<int>> graph(n + 1);     vector<bool> visit(n + 1);     vector<int> color(n + 1);     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);     }     queue<pair<int, int>> q;     color[1] = 1;     visit[1] = 1;     int curC = 2;     for (auto i : graph[1]) {       visit[i] = 1;       color[i] = curC;       ans = max(ans, color[i]);       curC++;       q.push({1, i});     }     while (!q.empty()) {       int kakek = q.front().first, bapak = q.front().second;       q.pop();       curC = 1;       for (auto i : graph[bapak]) {         if (!visit[i]) {           visit[i] = 1;           while (curC == color[bapak] || curC == color[kakek]) curC++;           color[i] = curC;           ans = max(ans, color[i]);           curC++;           q.push({bapak, i});         }       }     }     cout << ans <<   n ;     for (int i = 1; i <= n; i++) cout << color[i] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int a[105][105];   int main() {     int n, m, q;     cin >> n >> m >> q;     vector<pair<pair<int, int>, pair<int, int> > > t(q);     for (int i = 0; i < q; ++i) {       cin >> t[i].first.first >> t[i].first.second;       if (t[i].first.first == 3) cin >> t[i].second.first >> t[i].second.second;     }     while (q > 0) {       --q;       if (t[q].first.first == 1) {         int r = t[q].first.second;         --r;         int x = a[r][m - 1];         for (int j = m - 1; j > 0; --j) a[r][j] = a[r][j - 1];         a[r][0] = x;       } else if (t[q].first.first == 2) {         int r = t[q].first.second;         --r;         int x = a[n - 1][r];         for (int i = n - 1; i > 0; --i) a[i][r] = a[i - 1][r];         a[0][r] = x;       } else {         int x, y, v;         x = t[q].first.second, y = t[q].second.first, v = t[q].second.second;         --x, --y;         a[x][y] = v;       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) cout << a[i][j] <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAX = 103;   long long dp[MAX][MAX][MAX];   long long tmp[MAX][MAX];   long long ncr[MAX][MAX];   long long res[MAX];   int sub[MAX];   vector<int> adj[MAX];   int modulo(int a, int b, int c) {     long long res = 1;     for (int i = 0; i < b; i++) {       res *= a;       res %= c;     }     return res % c;   }   void merge(int a, int b) {     memset(tmp, 0, sizeof tmp);     for (int i = 0; i < sub[b]; i++) {       for (int j = 1; j <= sub[b]; j++) {         for (int k = 0; k < sub[a]; k++) {           for (int l = 1; l <= sub[a]; l++) {             long long x = dp[b][i][j];             long long y = dp[a][k][l];             tmp[i + k + 1][j + l] += ((x * y) % MOD);             tmp[i + k + 1][j + l] %= MOD;             tmp[i + k][j] += ((((x * y) % MOD) * 1ll * l) % MOD);             tmp[i + k][j] %= MOD;           }         }       }     }     for (int i = 0; i < (sub[a] + sub[b]); i++) {       for (int j = 1; j <= (sub[a] + sub[b]); j++) {         dp[b][i][j] = tmp[i][j];       }     }   }   void dfs(int s, int p) {     dp[s][0][1] = 1;     sub[s] = 1;     for (int i = 0; i < adj[s].size(); i++) {       int u = adj[s][i];       if (u != p) {         dfs(u, s);         merge(u, s);         sub[s] += sub[u];       }     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int a, b;       scanf( %d %d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs(1, 0);     for (int i = 0; i < n - 1; i++) {       for (int j = 1; j <= n; j++) {         dp[1][i][j] = (dp[1][i][j] * 1ll * j) % MOD;         dp[1][i][j] = (dp[1][i][j] * 1ll * modulo(n, n - i - 2, MOD)) % MOD;         res[i] += dp[1][i][j];         res[i] %= MOD;       }     }     res[n - 1] = 1;     ncr[0][0] = 1;     ncr[1][0] = 1;     ncr[1][1] = 1;     for (int i = 2; i <= n; i++) {       ncr[i][0] = 1;       for (int j = 1; j <= i; j++) {         ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 1][j]) % MOD;       }     }     for (int i = n - 2; i >= 0; i--) {       for (int j = i + 1; j < n; j++) {         res[i] -= ((ncr[j][i] * res[j]) % MOD);         res[i] += MOD;         res[i] %= MOD;       }     }     for (int i = 0; i < n; i++) {       printf( %lld n , res[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   int xp, yp, xc, yc;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> xp >> yp >> xc >> yc;     vector<pair<int, int>> store;     while (xc != 0 || yc != 0) {       store.push_back({xc, yc});       xc--;       yc--;       xc = max(0, xc);       yc = max(0, yc);     }     store.push_back({xc, yc});     for (int i = 0; i < store.size(); i++) {       pair<int, int> h = store[i];       int z = max(0, xp - h.first) + max(0, yp - h.second);       if (z <= i) {         cout <<  Polycarp ;         return 0;       }     }     cout <<  Vasiliy ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int A(int n, int k) {     if (n < k) {       return 0;     }     long long int res = 1;     for (int i = n; i > n - k; --i) res *= i;     return res;   }   int fact(int n) {     int res = 1;     for (int i = 2; i <= n; ++i) res *= i;     return res;   }   int main() {     long long int n, m;     cin >> n >> m;     --n;     --m;     int dn = 0, dm = 0;     int lastn = 0, lastm = 0;     vector<int> dign, digm;     if (n == 0) {       dn = 1;       dign.push_back(0);     }     if (m == 0) {       dm = 1;       digm.push_back(0);     }     while (n) {       dn++;       lastn = n % 7;       dign.push_back(lastn);       n /= 7;     }     while (m) {       dm++;       lastm = m % 7;       digm.push_back(lastm);       m /= 7;     }     reverse(dign.begin(), dign.end());     reverse(digm.begin(), digm.end());     if (dn + dm > 7) {       cout << 0 << endl;       return 0;     }     long long int ans = 0;     int mask = 0;     for (; mask < (1 << 7); ++mask) {       vector<int> digits;       for (int i = 0; i < 7; ++i) {         if (mask & (1 << i)) {           digits.push_back(i);         }       }       if (digits.size() != dn + dm) continue;       for (int i = 0; i < fact(dn + dm); ++i) {         bool flag = 1;         int j = 0;         while (j < dn && digits[j] == dign[j]) ++j;         if (j < dn && digits[j] > dign[j]) flag = 0;         j = dn;         while (j < dn + dm && digits[j] == digm[j - dn]) ++j;         if (j < dn + dm && digits[j] > digm[j - dn]) flag = 0;         if (flag) {           ++ans;         }         next_permutation(digits.begin(), digits.end());       }     }     cout << ans << endl;     return 0;   }


#include<bits/stdc++.h>   #define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)   #define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)   #define ll long long   #define pii pair<int, int>   #define db double   #define x first   #define y second   #define ull unsigned long long   #define sz(a) ((int) (a).size())   #define vi vector<int>   using namespace std;   const int N = 5e6 + 7;   int n, a[N], b[N], now[N];   char s[N];   void Main() {    cin >> n >> (s + 1);    int cnt = 0, cnt0 = 0, cnt1 = 0;    L(i, 1, n) if(s[i] ==  1 ) cnt ++;    cnt /= 2;    L(i, 1, n) if(s[i] ==  1 ) {     if(cnt) now[i] = 1, --cnt;     else now[i] = -1;    }    L(i, 1, n) {     if(s[i] ==  0 ) {      if(cnt0 < cnt1) a[i] = 1, b[i] = -1, cnt0 ++, cnt1 --;      else a[i] = -1, b[i] = 1, cnt0 --, cnt1 ++;     }     else {      cnt0 += now[i], cnt1 += now[i];      a[i] = b[i] = now[i];     }     if(cnt0 < 0 || cnt1 < 0) {      cout <<  NO n ;      return;     }     }    if(cnt0 || cnt1) {     cout <<  NO n ;     return;    }    cout <<  YES n ;    L(i, 1, n) cout << (a[i] == 1 ?  (  :  ) );    cout <<   n ;    L(i, 1, n) cout << (b[i] == 1 ?  (  :  ) );    cout <<   n ;   }   int main() {    ios::sync_with_stdio(false);    cin.tie(0); cout.tie(0);    int T;    cin >> T;    while(T--) Main();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void read(_T &dig) {     int flg;     char c;     flg = dig = 0;     while (c = getchar(), !isdigit(c))       if (c ==  - ) flg = 1;     while (isdigit(c)) dig = dig * 10 + c -  0 , c = getchar();     if (flg) dig = -dig;   }   template <typename _T, typename... Args>   inline void read(_T &x, Args &...args) {     read(x);     read(args...);   }   const int N = 505, M = 1e5 + 5;   int n, f[N][N], a[N];   int head[M], nxt[M], tot, ver[M], v[N], in[N];   queue<int> q;   void add(int u, int v) { nxt[++tot] = head[u], head[u] = tot, ver[tot] = v; }   int main() {     read(n);     for (int i = (1); i <= (n); ++i) read(a[i]), f[i][i] = a[i];     for (int k = 2; k <= n; ++k)       for (int i = 1; i + k - 1 <= n; ++i)         for (int j = i; j < i + k - 1; ++j)           if (f[i][j] && f[i][j] == f[j + 1][i + k - 1]) {             f[i][i + k - 1] = f[i][j] + 1;             break;           }     for (int i = 1; i <= n; ++i)       for (int j = i; j <= n; ++j)         if (f[i][j]) add(i, j + 1);     memset(v, 0x3f, sizeof(v));     v[1] = 0, q.push(1);     int x, y;     while (q.size()) {       x = q.front(), q.pop(), in[x] = 0;       for (int i = head[x]; i; i = nxt[i]) {         if (v[y = ver[i]] > v[x] + 1) {           v[y] = v[x] + 1;           if (!in[y]) q.push(y), in[y] = 1;         }       }     }     printf( %d n , v[n + 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0, ways = 0;     int c[100];     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> c[i];       sum = sum + c[i];     }     for (int i = 0; i < n; ++i) {       if ((sum - c[i]) % 2 == 0) ways++;     }     cout << ways << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int a[n];     long long int f[100005];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     int x = a[n - 1] - a[0];     long long int y = 1;     int i = 1;     while (a[i] == a[0] && i < n - 1) {       y++;       i++;     }     i = n - 2;     long long int z = 1;     while (a[i] == a[n - 1] && i > 0) {       z++;       i--;     }     if (a[n - 1] == a[0]) {       cout << x <<     << (n * (n - 1)) / 2;       exit(0);     }     cout << x <<     << z * y << endl;   }


#include <bits/stdc++.h>   using namespace std;   using pqboro = priority_queue<long long, vector<long long>, less<long long>>;   using pqchoto =       priority_queue<long long, vector<long long>, greater<long long>>;   template <typename T>   string toString(T Number) {     stringstream ss;     ss << Number;     return ss.str();   }   template <typename T>   long long toll(T str) {     stringstream ss;     ss << str;     long long num;     ss >> num;     return num;   }   const int N = 2e5 + 7;   const int M = 1e9 + 7;   const long long inf = 0x7f7f7f7f7f7f7f7f;   void run_for_testcase() {     long long n, m, i, j, k, x;     cin >> n >> k;     string s;     cin >> s;     vector<long long> a;     long long tot = 0;     long long cnt = 0;     i = 0;     for (i = 0; i < n; i++) {       if (s[i] ==  W ) {         break;       }     }     for (; i < n; i++) {       if (s[i] ==  L ) {         ++cnt;         j = i + 1;         for (; j < n; j++) {           if (s[j] ==  W ) {             a.emplace_back(cnt);             cnt = 0;             break;           }           ++cnt;         }         i = j - 1;       } else {         ++tot;         j = i + 1;         for (; j < n; j++) {           if (s[j] ==  L ) {             break;           }           tot += 2;         }         i = j - 1;       }     }     if (tot == 0) {       cout << max(0LL, 2 * k - 1) << endl;       return;     }     sort(a.begin(), a.end());     for (i = 0; i < a.size(); i++) {       if (a[i] <= k) {         k -= a[i];         tot += (1 + (a[i] * 2));       } else {         tot += (k * 2);         cout << tot << endl;         return;       }     }     if (k > 0) {       if (s.front() ==  L ) {         cnt = 0;         for (i = 0; i < n; i++) {           if (s[i] ==  L ) {             ++cnt;           } else             break;         }         if (k > cnt) {           tot += (cnt * 2);           k -= cnt;         } else {           tot += (k * 2);           cout << tot << endl;           return;         }       }     }     if (k > 0) {       if (s.back() ==  L ) {         cnt = 0;         for (i = n - 1; i >= 0; i--) {           if (s[i] ==  L )             ++cnt;           else             break;         }         tot += (min(k, cnt) * 2);       }     }     cout << tot << endl;   }   int main() {     int tc;     cin >> tc;     while (tc--) run_for_testcase();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     string st;     cin >> st;     bool ev = false, od = false;     for (int i = 0; i < n; i++) {       if (st[i] % 2 == 1 and i % 2 == 0)         od = true;       else if (st[i] % 2 == 0 and i % 2 == 1)         ev = true;     }     if (n & 1) {       if (od) {         cout <<  1 n ;       } else         cout <<  2 n ;     } else {       if (ev)         cout <<  2 n ;       else         cout <<  1 n ;     }   }   int main() {     int tc;     cin >> tc;     while (tc--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 305;   const int inf = 0x3f3f3f3f;   const double eps = 1e-5;   int n, c;   int dp[605][N][N], a[N][N];   int max(int a, int b, int c, int d) { return max(max(a, b), max(c, d)); }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]);     memset(dp, -inf, sizeof(dp));     dp[0][1][1] = a[1][1];     int l = (n - 1) * 2;     for (int i = 1; i <= l; i++) {       for (int j = 1; j <= n; j++) {         for (int k = 1; k <= n; k++) {           if (k == j)             c = a[j][i + 2 - j];           else             c = a[j][i + 2 - j] + a[k][i + 2 - k];           dp[i][j][k] = max(dp[i - 1][j - 1][k - 1], dp[i - 1][j][k - 1],                             dp[i - 1][j - 1][k], dp[i - 1][j][k]) +                         c;         }       }     }     printf( %d n , dp[l][n][n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const int inf = 2012345678;   const int N = 2e5 + 10;   string s, ans, tmp;   bool ch() {     int i = 0;     while (s[i] == tmp[i] && i < tmp.length()) ++i;     return i == tmp.length();   }   int main() {     int n, k;     cin >> n >> k >> s;     ans = s, --k;     int ps = 1;     while (k--) {       while (true) {         if (ps == ans.length()) {           ans += s, ps = ans.length();           break;         }         tmp = ans.substr(ps);         if (ch()) {           for (int i = tmp.length(); i < (int)(s.length()); ++i) ans += s[i];           ++ps;           break;         } else           ++ps;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   char d[8][8];   int i, j, sch, k, m;   int main() {     k = 0;     m = 0;     for (i = 0; i < 8; i++) {       sch = 0;       for (j = 0; j < 8; j++) {         cin >> d[i][j];         if (d[i][j] ==  B ) sch++;       }       if (sch == 8)         k++;       else if (sch > m)         m = sch;     }     cout << k + m;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, nn = 0, range;     int a, b, c, d, pos, neg, ok = 1, finddd = 0;     int ara[200], ara2[200];     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d %d , &ara[i], &ara2[i]);       if (ara2[i] == m || ara[i] == m) {         finddd = 1;       }     }     if (n == 1 && ara[0] == 1) {       finddd = 0;     }     for (int i = 1; i < n; i++) {       for (int j = 0; j < i; j++) {         if (ara[i] <= ara2[j]) {           pos = 1;         }       }       if (pos == 1) {         ok = 1;       } else {         ok = 0;         break;       }       pos = 0;       neg = 0;     }     if (ok == 1 && finddd == 1) {       printf( YES n );     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   char s[8][10];   int i;   vector<int> p;   int cnt() {     int v[8];     int i, j;     for (i = 0; i < n; i++) {       v[i] = 0;       for (j = 0; j < k; j++) v[i] = v[i] * 10 + (int)(s[i][p[j]] -  0 );     }     int minv = v[0];     int maxv = v[0];     for (i = 0; i < n; i++) {       if (v[i] > maxv) maxv = v[i];       if (v[i] < minv) minv = v[i];     }     return maxv - minv;   }   int main() {     scanf( %d %d , &n, &k);     for (i = 0; i < n; i++) scanf( %s , s[i]);     for (i = 0; i < k; i++) p.push_back(i);     int sol = cnt();     while (next_permutation(p.begin(), p.end())) {       int res = cnt();       if (res < sol) sol = res;     }     printf( %d n , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long t, n, h, i, j, x, y, z, k, e, m;     string s;     cin >> n >> m;     x = 0;     for (i = 1; i <= n; i++) {       y = i / 5;       z = (i + m) / 5;       x += (z - y);     }     cout << x;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool read(T &x) {     int c = getchar();     int sgn = 1;     while (~c && c< 0  | c>  9 ) {       if (c ==  - ) sgn = -1;       c = getchar();     }     for (x = 0; ~c &&  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;     x *= sgn;     return ~c;   }   const long long N = 100005;   const long long MOD = 1e9 + 7;   long long dp[N][2];   string str;   long long n;   long long solve(long long pos, long long c) {     if (pos >= n) return 0;     if (dp[pos][c] != -1) return dp[pos][c];     long long x = n;     if (c == 1) {       x = solve(pos + 1, 1) + (str[pos] >  Z );       x = min(x, solve(pos + 1, 0) + (str[pos] <  a ));     } else {       x = min(x, solve(pos + 1, 0) + (str[pos] <  a ));     }     return dp[pos][c] = x;   }   int main() {     memset(dp, -1, sizeof(dp));     cin >> str;     n = str.size();     cout << solve(0, 1) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, u, v, a, b, A, B, C;     A = B = C = 0;     cin >> a >> b;     for (i = 1; i <= 6; i++) {       u = abs(i - a);       v = abs(i - b);       if (u < v)         A++;       else if (u == v)         B++;       else         C++;     }     cout << A <<     << B <<     << C;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int n = 10000000;   bitset<n> b;   vector<int> v;   void sieve() {     b.set();     b[0] = 0;     b[1] = 0;     for (long long i = 2; i <= n; i++) {       if (b[i]) {         v.push_back(i);         for (long long j = i * i; j <= n; j = j + i) {           b[j] = 0;         }       }     }   }   bool large_prime(long long no) {     if (no <= n) {       if (b[no]) {         return true;       } else {         return false;       }     }     for (long long i = 0; v[i] * (long long)v[i] <= no; i++) {       if (no % v[i] == 0) {         return false;       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     sieve();     long long a, b;     while (t--) {       cin >> a >> b;       if (a - b == 1) {         long long ans = (a - b) * (a + b);         if (large_prime(ans)) {           cout <<  YES                 <<   n ;         } else {           cout <<  NO                 <<   n ;         }       } else {         cout <<  NO               <<   n ;       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   void checkmin(int &x, int y) {     if (x > y) x = y;   }   void checkmax(int &x, int y) {     if (x < y) x = y;   }   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return x * f;   }   const int N = 20;   const int M = (1 << 20);   int n;   long long a[N], sum[M];   int dp[M], vis[M], sz[M];   signed main() {     n = read();     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);       if (!a[i]) n--, i--;     }     int full = (1 << n) - 1;     for (int i = 0; i <= full; i++)       for (int j = 0; j < n; j++)         if (i >> j & 1) sum[i] += a[j], sz[i]++;     for (int mask1 = 1; mask1 <= full; mask1++) {       for (int mask2 = (mask1 - 1) & mask1; (mask2 << 1) >= mask1;            mask2 = mask1 & (mask2 - 1)) {         int mask3 = mask1 ^ mask2;         long long tmp = abs(sum[mask2] - sum[mask3]);         if (tmp < sz[mask1] && (sz[mask1] - tmp) & 1) {           vis[mask1] = 1;           break;         }       }     }     for (int i = 1; i <= full; i++)       if (vis[i]) {         int rest = full ^ i;         checkmax(dp[i], 1);         for (int j = rest; j; j = rest & (j - 1))           checkmax(dp[i | j], dp[j] + dp[i]);       }     int mx = 0;     for (int mask = 1; mask <= full; mask++) checkmax(mx, dp[mask]);     printf( %d n , n - mx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long p = 1000000007;   char s[100005];   long long w[100005];   long long te[100005] = {1};   void build() {     for (int i = 1; i <= 100000; i++) {       te[i] = (te[i - 1] * 10) % p;     }   }   long long quick_mod(long long a, long long b) {     long long ans = 1;     a %= p;     while (b) {       if (b & 1) {         ans = ans * a % p;         b--;       }       b >>= 1;       a = a * a % p;     }     return ans;   }   long long C(long long n, long long m) {     if (m > n) return 0;     long long ans = 1;     for (int i = 1; i <= m; i++) {       long long a = (n + i - m) % p;       long long b = i % p;       ans = ans * (a * quick_mod(b, p - 2) % p) % p;     }     return ans;   }   int main() {     build();     long long n, k;     scanf( %I64d%I64d , &n, &k);     scanf( %s , s);     long long ans = 0;     w[n - 1] = C(n - 1, k);     long long t = w[n - 1];     for (int i = n - 1; i >= 1; i--) {       t = t * ((i - k) * quick_mod(i, p - 2) % p) % p;       w[i - 1] = (w[i] + (te[n - i - 1] * t) % p * 9) % p;     }     for (int i = 0; i < n; i++) ans = (ans + w[i] * (s[i] -  0 )) % p;     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MAX = 1e6 + 5;   const int N = 2e5 + 5;   const long long int mod = 1e9 + 7;   const long long int mx = 1e16;   bool comp(const int a, const int b) { return a > b; }   const double PI = 2 * acos(0.0);   long long int fac[N];   void pre() {     fac[0] = 1LL;     for (long long int i = 1; i < N; i++) {       fac[i] = 1LL * i * fac[i - 1];       if (fac[i] >= mod) fac[i] %= mod;     }   }   long long int power(long long int a, long long int b) {     long long int x = 1;     while (b) {       if (b & 1) {         x *= a;         if (x >= mod) x %= mod;       }       a *= a;       if (a >= mod) a %= mod;       b >>= 1;     }     return x;   }   long long int inv(long long int k) { return power(k, mod - 2); }   string strngtoint(int n) {     ostringstream str1;     str1 << n;     string ans = str1.str();     return ans;   }   bool fun(long long int z, long long int x, long long int y, long long int p,            long long int q) {     if (p * z >= x && q * z - p * z >= y - x)       return true;     else       return false;   }   int main() {     long long t;     scanf( %lld n , &t);     while (t--) {       long long int x, y, p, q;       scanf( %lld %lld %lld %lld , &x, &y, &p, &q);       long long int low = -1, high = 1e9, mid;       if (!fun(high, x, y, p, q)) {         cout << -1 << endl;         continue;       }       while (high - low > 1) {         mid = (low + high) / 2;         if (fun(mid, x, y, p, q)) {           high = mid;         } else {           low = mid;         }       }       cout << high * q - y << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int main() {     char s1[15], s2[15], s3[15];     int p[15];     scanf( %s%s , s1, s2);     int len = strlen(s1);     int pos = 0;     for (int i = 0; i < len; i++) {       if (s1[i] ==  + )         pos++;       else         pos--;     }     int cnt = 0;     for (int i = 0; i < len; i++)       if (s2[i] ==  ? ) p[cnt++] = i;     int m = 1 << cnt, ans = 0;     for (int i = 0; i < m; i++) {       int k = i, u = 0;       strcpy(s3, s2);       for (int j = 0; j < cnt; j++) {         if (k & 1)           s3[p[u]] =  + ;         else           s3[p[u]] =  - ;         k >>= 1;         u++;       }       int w = 0;       for (int j = 0; j < len; j++) {         if (s3[j] ==  + )           w++;         else           w--;       }       if (w == pos) ans++;     }     printf( %.12f n , ans * 1.0 / m);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   string s;   int main() {     cin >> s;     int len = s.size();     int index7[20], index2[20], index5[20], index0[20];     int sum7 = 0, sum0 = 0, sum5 = 0, sum2 = 0;     for (int i = 0; i < len; i++) {       if (s[i] ==  5 ) {         index5[sum5] = i;         sum5++;       }       if (s[i] ==  0 ) {         index0[sum0] = i;         sum0++;       }       if (s[i] ==  7 ) {         index7[sum7] = i;         sum7++;       }       if (s[i] ==  2 ) {         index2[sum2] = i;         sum2++;       }     }     int res = 1000;     bool flag = false;     if (sum0 >= 2) {       flag = true;       int temp = (len - 1 - index0[sum0 - 1]) + (len - 2 - index0[sum0 - 2]);       res = min(res, temp);     }     if (sum0 > 0 && sum5 > 0) {       flag = true;       int temp = 0;       if (index0[sum0 - 1] < index5[sum5 - 1]) {         temp = ((index5[sum5 - 1] <= len - 1) ? len - 1 - index5[sum5 - 1] : 0) +                ((index0[sum0 - 1] <= len - 2) ? len - 2 - index0[sum0 - 1] : 0);         temp++;       } else {         temp = ((index5[sum5 - 1] <= len - 2) ? len - 2 - index5[sum5 - 1] : 0) +                ((index0[sum0 - 1] <= len - 1) ? len - 1 - index0[sum0 - 1] : 0);       }       if (index5[sum5 - 1] == 0) {         int i = 1;         while (s[i] ==  0  && i < index0[sum0 - 1]) i++;         temp += i - 1;       }       res = min(res, temp);     }     if (sum5 > 0 && sum2 > 0) {       flag = true;       int temp = 0;       if (index5[sum5 - 1] < index2[sum2 - 1]) {         temp = ((index2[sum2 - 1] <= len - 1) ? len - 1 - index2[sum2 - 1] : 0) +                ((index5[sum5 - 1] <= len - 2) ? len - 2 - index5[sum5 - 1] : 0);         temp++;       } else {         temp = ((index2[sum2 - 1] <= len - 2) ? len - 2 - index2[sum2 - 1] : 0) +                ((index5[sum5 - 1] <= len - 1) ? len - 1 - index5[sum5 - 1] : 0);       }       if (index5[sum5 - 1] == 0 || index2[sum2 - 1] == 0) {         int i = 1;         while (s[i] ==  0 ) i++;         temp += i - 1;       }       res = min(res, temp);     }     if (sum7 > 0 && sum5 > 0) {       flag = true;       int temp = 0;       if (index5[sum5 - 1] < index7[sum7 - 1]) {         temp = ((index7[sum7 - 1] <= len - 1) ? len - 1 - index7[sum7 - 1] : 0) +                ((index5[sum5 - 1] <= len - 2) ? len - 2 - index5[sum5 - 1] : 0);         temp++;       } else {         temp = ((index7[sum7 - 1] <= len - 2) ? len - 2 - index7[sum7 - 1] : 0) +                ((index5[sum5 - 1] <= len - 1) ? len - 1 - index5[sum5 - 1] : 0);       }       if (index5[sum5 - 1] == 0 || index7[sum7 - 1] == 0) {         int i = 1;         while (s[i] ==  0 ) i++;         temp += i - 1;       }       res = min(res, temp);     }     if (!flag)       cout << -1 << endl;     else       cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, cnt, ans, tot;   unordered_map<long long, int> id;   int op[400010], d[400010], fa[400010], rk[400010], lg[400010], hs[400010];   struct node {     int u, v;     long long h;     void bb() {       if (u > v) swap(u, v);       h = (long long)u << 30 | v;     }   } e[400010], g[400010];   int getfa(int x) { return fa[x] == x ? x : getfa(fa[x]); }   void uni(int x, int y, int z) {     x = getfa(x), y = getfa(y);     if (rk[x] <= rk[y]) {       fa[x] = y;       lg[++tot] = x;       hs[tot] = z;       if (rk[x] == rk[y]) rk[y]++;     } else {       fa[y] = x;       lg[++tot] = y;       hs[tot] = z;     }   }   void del(int x) {     int i;     for (i = tot; hs[i] != x; i--) {       fa[lg[i]] = lg[i];     }     fa[lg[i]] = lg[i];     int u = tot;     tot = i - 1;     for (i++; i <= u; i++) uni(g[hs[i]].u, g[hs[i]].v, hs[i]);   }   void solve(int be, int en) {     for (int i = 1; i <= n; i++) fa[i] = i, rk[i] = 0;     tot = 0;     vector<int> v(cnt + 3), vv(cnt + 3);     for (int i = 1; i < be; i++)       if (op[i] == 1) v[d[i]] ^= 1;     for (int i = be; i <= en; i++)       if (op[i] == 1) vv[d[i]] = vv[d[i + m]] = 1;     for (int i = 1; i <= cnt; i++)       if (v[i] && !vv[i]) uni(g[i].u, g[i].v, i);     for (int i = 1; i <= cnt; i++)       if (v[i] && vv[i]) uni(g[i].u, g[i].v, i);     for (int i = be; i <= en; i++) {       if (ans) e[i] = e[i + m], d[i] = d[i + m];       if (op[i] == 1) {         v[d[i]] ^= 1;         if (v[d[i]])           uni(e[i].u, e[i].v, d[i]);         else           del(d[i]);       } else {         int x = getfa(e[i].u), y = getfa(e[i].v);         if (x != y)           putchar( 0 ), ans = 0;         else           putchar( 1 ), ans = 1;       }     }   }   int main(int argc, char const *argv[]) {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d , &op[i]);       scanf( %d%d , &e[i].u, &e[i].v);       e[i].bb();       op[i + m] = op[i];       e[i + m] = {e[i].u % n + 1, e[i].v % n + 1};       e[i + m].bb();     }     for (int i = 1, tot = m * 2; i <= tot; i++) {       long long t = e[i].h;       if (!id[t]) id[t] = ++cnt, g[cnt] = e[i];       d[i] = id[t];     }     int B = sqrt(m);     for (int i = 1; i <= m; i += B) solve(i, min(i + B - 1, m));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int x;   int dfs(int xx, int yy, int cc) {     if (cc == 0) {       if (xx == 1 || yy == 1) {         int tt = xx * yy;         if (tt % 2 == 0)           return tt / 2;         else           return tt / 2 + 1;       } else         return ((xx + yy) * 2 - 4) / 2;     }     if (xx <= 2 || yy <= 2) {       if (cc >= 1) return 0;       int k = xx * yy;       if (k % 2 == 0) return k / 2;       return k / 2 + 1;     }     int g = dfs(xx - 2, yy - 2, cc - 1);     return g;   }   int main() {     while (cin >> n >> m >> x) {       int t = dfs(n, m, x - 1);       cout << t << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1 << 28;   const long long LINF = 1ll << 61;   const long long mod = 1e9 + 7;   long long kissme(long long x, long long t) {     long long ans = 1;     while (t > 0) {       if (t & 1) ans = ans * x % mod;       x = x * x % mod;       t >>= 1;     }     return ans;   }   struct number {     int x, y;     number(int _x = 0, int _y = 0) {       x = _x;       y = _y;     }     number operator+(number t) {       return number((x + t.x) % mod, (y + t.y) % mod);     }     number operator-(number t) {       return number((x - t.x + mod) % mod, (y - t.y + mod) % mod);     }     number operator*(number t) {       return number((1ll * x * t.x + 1ll * y * t.y * 5) % mod,                     (1ll * x * t.y + 1ll * y * t.x) % mod);     }     number operator*(int t) {       return number((1ll * x * t) % mod, (1ll * y * t) % mod);     }     bool operator!=(number t) { return x != t.x || y != t.y; }     number inv() {       long long t = (1ll * x * x % mod - 5ll * y * y % mod + mod) % mod;       t = kissme(t, mod - 2);       return number(x * t % mod, (-y * t % mod + mod) % mod);     }     void operator=(int t) {       x = t;       y = 0;     }     number operator^(long long t) {       number ret(1, 0), b = (*this);       while (t > 0) {         if (t & 1) ret = ret * b;         b = b * b;         t >>= 1;       }       return ret;     }     void out() { cout << x <<  ,  << y << endl; }   };   number sigma(number x, long long l, long long r) {     if (x.x == 1 && x.y == 0)       return (r - l + 1) % mod;     else       return ((x ^ l) - (x ^ (r + 1))) * (number(1, 0) - x).inv();   }   long long k, l, r;   long long dp[211];   long long f[211], revf[211];   long long C(long long x, long long y) {     if (x < y)       return 0;     else       return f[x] * revf[y] % mod * revf[x - y] % mod;   }   number A, B, pa[211], pb[211];   int sign(long long n) { return n & 1 ? mod - 1 : 1; }   long long solve(long long l, long long r) {     number c = 1, bs = number(0, kissme(5, mod - 2));     number sum;     for (int i = 1; i <= k; i++) {       c = c * bs;       number tsum;       for (int j = 0; j <= i; j++) {         tsum = tsum + sigma(pa[j] * pb[i - j], l, r) * C(i, j) * sign(i - j);       }       tsum = tsum * c;       sum = sum + tsum * dp[i];     }     return sum.x;   }   int main() {     f[0] = 1;     for (int i = 1; i <= 205; i++) f[i] = f[i - 1] * i % mod;     revf[205] = kissme(f[205], mod - 2);     for (int i = 204; i >= 0; i--) revf[i] = revf[i + 1] * (i + 1) % mod;     number A = number(1, 1) * kissme(2, mod - 2), B = number(1, 0) - A;     pa[0] = 1;     pb[0] = 1;     for (int i = 1; i <= 205; i++) pa[i] = pa[i - 1] * A, pb[i] = pb[i - 1] * B;     cin >> k >> l >> r;     l += 2;     r += 2;     dp[1] = 1;     long long fac = 1;     for (int i = 1; i < k; i++) {       fac = fac * (i + 1) % mod;       for (int j = i; j >= 0; j--) {         dp[j + 1] = (dp[j + 1] + dp[j]) % mod;         dp[j] = dp[j] * (-i + mod) % mod;       }     }     cout << solve(l, r) % mod * kissme(fac, mod - 2) % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     vector<int> cnt(200002, 0);     for (int i = 0; i < n; i++) {       cnt[a[i]]++;     }     int mx = 0;     int res = 0;     for (int i = 0; i < 200002; i++) {       if (cnt[i] > mx) {         mx = cnt[i];         res = i;       }     }     int ind = 0;     for (int i = 0; i < n; i++) {       if (a[i] == res) {         ind = i;         break;       }     }     cout << n - mx <<   n ;     int ind1 = ind;     while (ind1 > 0) {       if (a[ind1 - 1] < res) {         cout <<  1   << ind1 <<     << ind1 + 1 <<   n ;       }       if (a[ind1 - 1] > res) {         cout <<  2   << ind1 <<     << ind1 + 1 <<   n ;       }       ind1--;     }     ind1 = ind;     while (ind1 < n - 1) {       if (a[ind1 + 1] < res) {         cout <<  1   << ind1 + 2 <<     << ind1 + 1 <<   n ;       }       if (a[ind1 + 1] > res) {         cout <<  2   << ind1 + 2 <<     << ind1 + 1 <<   n ;       }       ind1++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     istream& in = cin;     int n;     in >> n;     vector<string> v;     for (int i = 0; i < n; i++) {       string str;       in >> str;       v.push_back(str);     }     set<char> use;     map<char, set<char> > use2;     for (int i = 0; i < n; i++) {       char p, c;       for (int j = 0; j < v[i].length(); j++) {         c = v[i][j];         use.insert(c);         if (j != 0) {           use2[p].insert(c);         }         p = c;       }     }     if (use.size() != 26) {       for (char ch =  a ; ch <=  z ; ch++) {         if (use.find(ch) == use.end()) {           cout << ch << endl;           break;         }       }     } else {       bool find = false;       for (char c1 =  a ; c1 <=  z  && !find; c1++) {         set<char> s = use2[c1];         for (char c2 =  a ; c2 <=  z  && !find; c2++) {           if (s.find(c2) == s.end()) {             cout << c1 << c2 << endl;             find = true;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     bool f = 0;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = 1;     for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);     if (f) x = -x;   }   template <typename F>   inline void write(F x, char ed =   n ) {     static short st[30];     short tp = 0;     if (x < 0) putchar( - ), x = -x;     do st[++tp] = x % 10, x /= 10;     while (x);     while (tp) putchar( 0  | st[tp--]);     putchar(ed);   }   template <typename T>   inline void Mx(T &x, T y) {     x < y && (x = y);   }   template <typename T>   inline void Mn(T &x, T y) {     x > y && (x = y);   }   const int N = 500050;   int c[N], col[N], f[N], fl;   struct node {     int x, y;     bool operator<(const node &i) const {       return c[x] == c[i.x] ? c[y] < c[i.y] : c[x] < c[i.x];     }   } ed[N];   int ne[N << 1], to[N << 1], h[N], tot, m, n, k;   inline void add(int x, int y) { ne[++tot] = h[x], to[h[x] = tot] = y; }   void dfs(int x, int &f2, int &f1) {     if (col[x] == 1) {       if (!f1) f1 = x;       f[x] = f1;     }     if (col[x] == 2) {       if (!f2) f2 = x;       f[x] = f2;     }     for (int i = h[x]; i; i = ne[i]) {       int y = to[i];       if (fl) return;       if (col[y]) {         if (col[y] != 3 - col[x]) {           fl = 1;           return;         }       } else         col[y] = 3 - col[x], dfs(y, f2, f1);     }   }   vector<int> v[N];   int vis[N], cnt;   void check(int x, int tim) {     vis[x] = tim;     for (auto y : v[x]) {       if (fl) return;       if (vis[y] == tim) {         if (col[y] != 3 - col[x]) {           fl = 1;           return;         }         continue;       }       col[y] = 3 - col[x];       check(y, tim);     }   }   int ban[N];   int main() {     read(n), read(m), read(k);     for (int i = 1; i <= n; i++) read(c[i]);     for (int i = 1, x, y; i <= m; i++) {       read(x), read(y);       if (c[x] == c[y])         add(x, y), add(y, x);       else {         if (c[x] > c[y]) swap(x, y);         ed[++cnt] = (node){x, y};       }     }     long long ans = k;     for (int i = 1; i <= n; i++) f[i] = i;     for (int i = 1; i <= n; i++) {       if (!col[i] && !ban[c[i]]) {         int f1 = 0, f2 = 0;         col[i] = 1;         fl = 0;         dfs(i, f2, f1);         if (fl) ban[c[i]] = 1, ans--;         if (f1 && f2) {           v[f1].push_back(f2), v[f2].push_back(f1);         }       }     }     sort(ed + 1, ed + cnt + 1);     ans = ans * (ans - 1) / 2;     int tim = 0;     for (int l = 1, r = 1; l <= cnt; l = r + 1, r = l) {       while (r <= cnt && c[ed[r + 1].x] == c[ed[l].x] &&              c[ed[r + 1].y] == c[ed[l].y])         r++;       if (ban[c[ed[l].x]] || ban[c[ed[l].y]]) continue;       for (int i = l; i <= r; i++) {         int x = ed[i].x, y = ed[i].y;         v[f[x]].push_back(f[y]), v[f[y]].push_back(f[x]);       }       tim++;       for (int i = l; i <= r; i++) {         int x = f[ed[i].x];         fl = 0;         if (vis[x] != tim) col[x] = 1, check(x, tim);         if (fl) break;       }       if (fl) ans--;       for (int i = l; i <= r; i++) {         int x = ed[i].x, y = ed[i].y;         v[f[x]].pop_back(), v[f[y]].pop_back();       }     }     write(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int f = 1, x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) f = (ch ==  - ) ? -1 : 1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return f * x;   }   const int N = 500 + 5;   const int P = 1e9 + 7;   int n, m, len;   inline int add(int a, int b) {     a += b;     return a >= P ? a - P : a;   }   inline int mul(int a, int b) { return (unsigned long long)a * b % P; }   char s[N][N];   int dp[2][N][N];   int dx1[] = {0, 1}, dy1[] = {1, 0};   int dx2[] = {0, -1}, dy2[] = {-1, 0};   bool ok(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; }   void solve_odd() {     int u = 0, v = 1;     dp[u][0][n - 1] = 1;     len = (len + 1) >> 1;     for (int i = (0); i < (len - 1); ++i) {       u ^= 1, v ^= 1, memset(dp[u], 0, sizeof(dp[u]));       for (int j = (0); j < (n); ++j)         for (int k = (0); k < (n); ++k) {           int x1 = j, y1 = i - j;           int x2 = k, y2 = m - 1 - (i - (n - 1 - x2));           if (ok(x1, y1) && ok(x2, y2)) {             for (int p = (0); p < (2); ++p)               for (int q = (0); q < (2); ++q) {                 int tx1 = x1 + dx1[p], ty1 = y1 + dy1[p];                 int tx2 = x2 + dx2[q], ty2 = y2 + dy2[q];                 if (ok(tx1, ty1) && ok(tx2, ty2) && s[tx1][ty1] == s[tx2][ty2]) {                   dp[u][tx1][tx2] = add(dp[u][tx1][tx2], dp[v][x1][x2]);                 }               }           }         }     }     int ans = 0;     for (int i = (0); i < (n); ++i) ans = add(ans, dp[u][i][i]);     cout << ans << endl;   }   void solve_even() {     int u = 0, v = 1;     dp[u][0][n - 1] = 1;     len = (len) >> 1;     for (int i = (0); i < (len - 1); ++i) {       u ^= 1, v ^= 1, memset(dp[u], 0, sizeof(dp[u]));       for (int j = (0); j < (n); ++j)         for (int k = (0); k < (n); ++k) {           int x1 = j, y1 = i - j;           int x2 = k, y2 = m - 1 - (i - (n - 1 - x2));           if (ok(x1, y1) && ok(x2, y2)) {             for (int p = (0); p < (2); ++p)               for (int q = (0); q < (2); ++q) {                 int tx1 = x1 + dx1[p], ty1 = y1 + dy1[p];                 int tx2 = x2 + dx2[q], ty2 = y2 + dy2[q];                 if (ok(tx1, ty1) && ok(tx2, ty2) && s[tx1][ty1] == s[tx2][ty2]) {                   dp[u][tx1][tx2] = add(dp[u][tx1][tx2], dp[v][x1][x2]);                 }               }           }         }     }     int ans = 0;     for (int i = (0); i < (n); ++i)       ans = add(ans, add(dp[u][i][i], dp[u][i][i + 1]));     cout << ans << endl;   }   int main() {     n = read(), m = read();     for (int i = (0); i < (n); ++i) scanf( %s , s[i]);     if (s[0][0] != s[n - 1][m - 1]) {       puts( 0 );       return 0;     }     len = n + m - 1;     if (len & 1)       solve_odd();     else       solve_even();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int gotcha() {     int a = 0, b = 1, c = getchar();     while (!isdigit(c)) b ^= c ==  - , c = getchar();     while (isdigit(c)) a = a * 10 + c - 48, c = getchar();     return b ? a : -a;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     map<int, int> mp;     int n;     scanf( %d , &n);     int b, i, index = 0, j;     for (i = 1; i <= n; i++) {       scanf( %d , &b);       mp[b] = i;     }     for (i = 0; i < n; i++) {       b = gotcha();       if (mp[b] - index > 0) {         printf( %d  , mp[b] - index);         index = mp[b];       } else         printf( 0  );     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int maxn = 1e5 + 5;   vector<int> a[maxn];   vector<int> ans[maxn];   int n, m, cas = 0;   void change2(int t) {     ans[t].resize(m + 1);     ans[t + 1].resize(m + 1);     for (int i = 1; i <= m; ++i) {       if (i & 1)         ans[t][i] = a[t][i];       else         ans[t + 1][i] = a[t][i];     }     ans[t][2] = a[t + 1][m];     ans[t + 1][1] = a[t + 1][m - 1];     for (int i = 3; i <= m; ++i) {       if (i & 1)         ans[t + 1][i] = a[t + 1][i - 2];       else         ans[t][i] = a[t + 1][i - 2];     }   }   void change3(int t) {     ans[t].resize(m + 1);     ans[t + 1].resize(m + 1);     ans[t + 2].resize(m + 1);     for (int i = 1; i <= m; ++i) {       if (i & 1)         ans[t][i] = a[t][i];       else         ans[t + 2][i] = a[t][i];     }     ans[t][2] = a[t + 1][m];     ans[t + 1][1] = a[t + 1][m - 1];     for (int i = 3; i <= m; ++i) {       if (i & 1)         ans[t + 1][i] = a[t + 1][i - 2];       else         ans[t][i] = a[t + 1][i - 2];     }     for (int i = 1; i <= m; ++i) {       if (i & 1)         ans[t + 2][i] = a[t + 2][i];       else         ans[t + 1][i] = a[t + 2][i];     }   }   void change1(int t) {     ans[t].push_back(123);     for (int i = 1; i <= m; ++i) {       if ((i & 1) == cas) ans[t].push_back(a[t][i]);     }     for (int i = 1; i <= m; ++i) {       if ((i & 1) == (cas ^ 1)) ans[t].push_back(a[t][i]);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int i, j, k;     cin >> n >> m;     if (n == 3 && m == 3) {       cout <<  YES  << endl;       cout <<  1 8 3  << endl;       cout <<  9 2 4  << endl;       cout <<  5 7 6  << endl;       return 0;     }     if (n == 1 && m == 1) {       cout <<  YES  << endl;       cout <<  1  << endl;       return 0;     }     if (n <= 2 && m <= 2) {       cout <<  NO  << endl;       return 0;     }     if ((n == 1 && m <= 3) || (m == 1 && n == 3) ||         (n + m == 5 && n != 1 && m != 1)) {       cout <<  NO  << endl;       return 0;     }     if (n <= m) {       for (int i = 1; i <= n; ++i) {         a[i].push_back(123);         for (int j = 1; j <= m; ++j) a[i].push_back((i - 1) * m + j);       }       if (n != 1) {         if (n % 2 == 0) {           for (int i = 1; i <= n; i += 2) change2(i);         } else {           for (int i = 1; i <= n - 3; i += 2) change2(i);           change3(n - 2);         }       } else         change1(1);       cout <<  YES  << endl;       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= m; ++j) cout << ans[i][j] <<    ;         cout << endl;       }     } else {       int cnt = 1;       swap(m, n);       for (int i = 1; i <= n; ++i) a[i].push_back(23);       for (int i = 1; i <= m; ++i)         for (int j = 1; j <= n; ++j) a[j].push_back(cnt++);       if (n != 1) {         if (n % 2 == 0) {           for (int i = 1; i <= n; i += 2) change2(i);         } else {           for (int i = 1; i <= n - 3; i += 2) change2(i);           change3(n - 2);         }       } else         change1(1);       cout <<  YES  << endl;       for (int i = 1; i <= m; ++i) {         for (int j = 1; j <= n; ++j) cout << ans[j][i] <<    ;         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k, u = 0, ans1 = 0, ans2 = 0;     cin >> n >> m >> k;     bool a[n][m];     long long sum[n + 2][m];     memset(sum, 0, sizeof(sum));     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         cin >> a[i][j];         sum[i][j] = (i ? sum[i - 1][j] : 0) + a[i][j];         if (i >= k) sum[i][j] -= a[u][j];         if (sum[i][j] > sum[n][j]) {           sum[n][j] = sum[i][j];           sum[n + 1][j] = i - k + 1;         }       }       u += (i >= k);     }     for (long long j = 0; j < m; j++) {       ans1 += sum[n][j];       for (long long i = 0; i < sum[n + 1][j]; i++) ans2 += a[i][j];     }     cout << ans1 <<     << ans2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ii {     string zl;     int x, id;   } zl[1000005];   bool cmp1(ii a, ii b) {     if (a.x < b.x) return 1;     if (a.x > b.x) return 0;     return a.zl < b.zl;   }   bool cmp2(ii a, ii b) { return a.id < b.id; }   int n, cnt, zhi[1000005], sz[1000005], i;   long long sum[1000005][5], ans;   map<int, int> mp;   void update(int id, int le, int ri, int pos) {     sz[id]++;     if (le == pos && ri == pos) {       sum[id][1] += zhi[pos];       return;     }     if (pos > (le + ri) / 2)       update(id * 2 + 1, (le + ri) / 2 + 1, ri, pos);     else       update(id * 2, le, (le + ri) / 2, pos);     int i;     for (i = 0; i < 5; i++) {       sum[id][i] =           sum[id * 2][i] + sum[id * 2 + 1][((i - sz[id * 2] % 5) + 5) % 5];     }   }   void erase(int id, int le, int ri, int pos) {     sz[id]--;     if (le == pos && ri == pos) {       sum[id][1] -= zhi[pos];       return;     }     if (pos > (le + ri) / 2)       erase(id * 2 + 1, (le + ri) / 2 + 1, ri, pos);     else       erase(id * 2, le, (le + ri) / 2, pos);     int i;     for (i = 0; i < 5; i++) {       sum[id][i] =           sum[id * 2][i] + sum[id * 2 + 1][((i - sz[id * 2] % 5) + 5) % 5];     }   }   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (i = 1; i <= n; i++) {       cin >> zl[i].zl;       if (zl[i].zl[0] ==  s )         zl[i].x = 0;       else         cin >> zl[i].x;       zl[i].id = i;     }     sort(zl + 1, zl + n + 1, cmp1);     cnt = 1;     for (i = 1; i <= n; i++) {       if (zl[i].zl[0] ==  a ) {         if (!mp[zl[i].x]) mp[zl[i].x] = cnt++;         zhi[mp[zl[i].x]] = zl[i].x;         zl[i].x = mp[zl[i].x];       } else if (zl[i].zl[0] ==  d ) {         zl[i].x = mp[zl[i].x];       }     }     sort(zl + 1, zl + n + 1, cmp2);     for (i = 1; i <= n; i++) {       if (zl[i].zl ==  add ) update(1, 1, cnt, zl[i].x);       if (zl[i].zl ==  del ) erase(1, 1, cnt, zl[i].x);       if (zl[i].zl ==  sum ) cout << sum[1][3] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int primes[10001];   int p[10001];   int numbers[10001];   int cnt;   void sieve() {     for (int a = 2; a <= 10000; ++a)       if (primes[a] == 0)         for (int b = 2; b * a <= 10000; b++) primes[a * b] = 1;     int c = 0;     for (int a = 2; a <= 10001; ++a)       if (primes[a] == 0) {         p[c] = a;         c++;       }     cnt = 0;     for (int a = 1; a < c; ++a) {       if (primes[p[a] + p[a - 1] + 1] == 0) {         numbers[cnt] = p[a] + p[a - 1] + 1;         cnt++;       }     }   }   int main() {     sieve();     int n, k;     cin >> n >> k;     if (lower_bound(numbers, numbers + cnt, n) - numbers >= k - 1)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, m;     int i = 0, tmp;     int P, Q;     cin >> n >> m;     i = n;     cin >> P;     while (i--) {       cin >> tmp;     }     cin >> Q;     i = m;     while (i--) {       cin >> tmp;     }     int sm = 1, sn = 1;     if (P < 0) sn = -1;     if (Q < 0) sm = -1;     if (m == n) {       if (sm * sn < 0) cout <<  - ;       P = (P < 0) ? -P : P;       Q = (Q < 0) ? -Q : Q;       int a = P, b = Q;       while (b) {         if (a > b)           a -= b;         else           b -= a;       }       P /= a;       Q /= a;       if (m >= 0) cout << P <<  /  << Q << endl;     } else {       if (n < m)         cout <<  0/1  << endl;       else {         if (sm * sn < 0) cout <<  - ;         cout <<  Infinity  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int A = 1e7 + 10;   const int B = 1e6 + 10;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   inline int read() {     char c = getchar();     int x = 0, f = 1;     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);     return x * f;   }   struct node {     int v, nxt, w, kkk;   } e[B];   int cnt, in[B], id[B], cg[B], k = 0, n, m, head[B];   void modify(int u, int v, int w, int kkk) {     e[++cnt].nxt = head[u];     e[cnt].w = w;     e[cnt].v = v;     e[cnt].kkk = kkk;     head[u] = cnt;   }   queue<int> q;   bool check(int mid) {     int kc = 0;     memset(in, 0, sizeof(in));     memset(id, 0, sizeof(id));     for (int i = 1; i <= n; i++) {       for (int j = head[i]; j; j = e[j].nxt) {         int v = e[j].v, w = e[j].w;         if (w <= mid) continue;         ++in[v];       }     }     for (int i = 1; i <= n; i++) {       if (!in[i]) {         q.push(i);       }     }     int js = 0;     while (!q.empty()) {       int now = q.front();       id[now] = ++kc;       js++;       q.pop();       for (int i = head[now]; i; i = e[i].nxt) {         int v = e[i].v, w = e[i].w;         if (w <= mid) continue;         --in[v];         if (!in[v]) q.push(v);       }     }     if (js != n) return 0;     k = 0;     for (int i = 1; i <= n; i++) {       for (int j = head[i]; j; j = e[j].nxt) {         if (e[j].w > mid) continue;         int v = e[j].v;         if (id[v] < id[i]) {           cg[++k] = e[j].kkk;         }       }     }     return 1;   }   int main() {     n = read(), m = read();     int r = 0;     for (int i = 1; i <= m; i++) {       int u = read(), v = read(), w = read();       modify(u, v, w, i);       r = max(r, w);     }     int l = 0, ans = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid)) {         r = mid - 1;         ans = mid;       } else         l = mid + 1;     }     sort(cg + 1, cg + k + 1);     printf( %d %d n , ans, k);     for (int i = 1; i <= k; i++) printf( %d  , cg[i]);   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007LL;   long long large = 2000000000000000000LL;   bitset<20011> vis;   vector<int> primes;   void sieve(long long n) {     vis.set();     vis[0] = 0;     vis[1] = 0;     for (long long i = 2; i <= n; i++) {       if (vis[i]) primes.push_back((int)i);       for (int j = 0; j < (int)primes.size() && i * primes[j] <= n; j++) {         vis[i * primes[j]] = 0;         if (i % primes[j] == 0) break;       }     }   }   int main() {     int n;     unsigned int a, b, c, d;     cin >> n >> a >> b >> c >> d;     sieve(20010);     unsigned int ans = 0;     int sq = 20000;     int p = 2;     while (p < n + 1) {       int l = p;       int r = min(l + sq, n + 1);       int sz = r - l;       vector<bool> vis(sz, true);       for (int i = 0; i < (int)primes.size(); i++) {         int x = primes[i];         int y = l;         y = max(y, 2 * x);         y = ((y - 1) / x + 1) * x;         while (y < r) {           vis[y - l] = false;           y += x;         }       }       for (int i = 0; i < sz; i++) {         if (vis[i]) {           unsigned int x = i + l;           if (x < 2) continue;           unsigned int temp = a * x * x * x + b * x * x + c * x + d;           unsigned int d = x;           while (n / d) {             ans += temp * (n / d);             if (n / x < d) break;             d *= x;           }         }       }       p += sq;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n;   int a[N];   int f[N];   int sumf[N];   long long sum;   long long best;   vector<int> freq;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       f[a[i]]++;       sum += a[i];     }     if (f[1]) {       printf( %lld n , sum);       return 0;     }     for (int i = 2; i < N; i++) {       if (f[i]) freq.push_back(i);       sumf[i] = f[i] + sumf[i - 1];     }     for (int i = 0; i < freq.size(); i++) {       int leading = freq[i];       long long total = 0;       for (int j = leading; j < N; j += leading) {         total += 1ll * (sumf[min(j + leading - 1, N - 1)] - sumf[j - 1]) * j;       }       best = max(best, total);     }     printf( %lld n , best);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   struct par {     ll l;     ll r;   };   int n;   ll s;   par mas[200100];   bool cmp(par a, par b) { return (a.l < b.l); }   bool good(ll m) {     vector<par> grp1;     vector<par> grp2;     vector<par> grp3;     for (int i = 0; i < n; i++) {       if (mas[i].r < m)         grp1.push_back(mas[i]);       else if (m <= mas[i].l)         grp2.push_back(mas[i]);       else         grp3.push_back(mas[i]);     }     int rem = max(0, (n + 1) / 2 - (int)grp2.size());     if (rem > grp3.size()) return false;     ll sum = 0;     for (auto el : grp1) sum += el.l;     for (auto el : grp2) sum += el.l;     if (grp3.size() > 0) sort(grp3.begin(), grp3.end(), cmp);     for (int i = 1; i <= rem; i++) sum += m;     for (int i = 0; i < grp3.size() - rem; i++) sum += grp3[i].l;     return (sum <= s);   }   ll bin_s() {     ll l = 1, r = 1e9;     ll m;     while (l < r) {       m = (l + r + 1) / 2;       if (good(m))         l = m;       else         r = m - 1;     }     return l;   }   void solve() {     cin >> n >> s;     for (int i = 0; i < n; i++) {       cin >> mas[i].l >> mas[i].r;     }     ll med = bin_s();     cout << med <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, siz = 1e6 + 5;   long long t, n, m, k, a[siz], dp[5002][5002], dp2[5002];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> t;     while (t--) {       cin >> n;       string s;       cin >> s;       s =  0  + s;       for (long long i = 1; i <= n + 1; i++)         for (long long j = i + 1; j <= n + 1; j++) dp[i][j] = 0;       for (long long i = n; i >= 1; i--) {         for (long long j = i - 1; j >= 1; j--) {           if (s[i] == s[j]) {             dp[j][i] = 1 + dp[j + 1][i + 1];           }         }       }       long long ans = 0;       for (long long i = 1; i <= n; i++) {         dp2[i] = n - i + 1;         for (long long j = 1; j < i; j++) {           if (s[i] > s[j])             dp2[i] = max(dp2[j] + n - i + 1, dp2[i]);           else if (s[i] == s[j]) {             if (s[i + dp[j][i]] > s[j + dp[j][i]]) {               dp2[i] = max(dp2[i], dp2[j] + n - (i + dp[j][i]) + 1);             }           }         }         ans = max(ans, dp2[i]);       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   double mod(double a, double b) {     long long int val = a / b;     return a - val * b;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     double a, b, m, vx, vy, vz;     cin >> a >> b >> m >> vx >> vy >> vz;     double sx, sy, sz, t, x0, y0;     t = -m / vy;     sx = abs(vx * t);     sz = vz * t;     long long int val;     if (sx > (3 * a) / 2) {       sx -= (3 * a) / 2;       val = sx / (a);       if (val % 2 == 0)         x0 = mod(sx, a);       else         x0 = a - mod(sx, a);     } else if (sx <= a / 2)       x0 = a / 2 + sx;     else       x0 = a - (sx - a / 2);     if (vx < 0) x0 = a - x0;     val = sz / (b);     if (val % 2 == 0)       y0 = mod(sz, b);     else       y0 = b - mod(sz, b);     cout << fixed << setprecision(10) << x0 <<     << y0;   }


#include <bits/stdc++.h>   using namespace std;   char F1[2000000];   char F2[2000000];   void computeLPSArray(string pat, int M, int* lps);   void KMPSearch(string pat, string txt, vector<int>& st, vector<int>& end) {     int M = pat.size();     int N = txt.size();     int lps[M];     computeLPSArray(pat, M, lps);     int i = 0;     int j = 0;     while (i < N) {       if (pat[j] == txt[i]) {         j++;         i++;       }       if (j == M) {         end.push_back(i - 1);         st.push_back(i - M);         j = lps[j - 1];       } else if (i < N && pat[j] != txt[i]) {         if (j != 0)           j = lps[j - 1];         else           i = i + 1;       }     }   }   void computeLPSArray(string pat, int M, int* lps) {     int len = 0;     lps[0] = 0;     int i = 1;     while (i < M) {       if (pat[i] == pat[len]) {         len++;         lps[i] = len;         i++;       } else {         if (len != 0) {           len = lps[len - 1];         } else {           lps[i] = 0;           i++;         }       }     }   }   long long int Stoi(string s) {     long long int ans = 0;     for (int i = 0; i < s.size(); i++) ans = ans * 10 + s[i] -  0 ;     return ans;   }   string itos(long long int num) {     if (num == 0) return  0 ;     string ans =   ;     while (num) {       int digit = num % 10;       char ch =  0  + digit;       ans = ch + ans;       num = num / 10;     }     return ans;   }   long long int numBefore(int i, string& s) {     int indx = i - 1;     while (s[indx] >=  0  && s[indx] <=  9  && indx >= 0) indx--;     indx++;     int len = i - indx;     long long int num = Stoi(s.substr(indx, len));     return num;   }   int charAfter(int i, string& s) {     if (i == s.size() - 1) return -1;     int indx = i + 1;     while (s[indx] >=  0  && s[indx] <=  9  && indx >= 0) indx++;     return indx;   }   int main() {     int m, n;     cin >> n >> m;     long long int prevFreq = 0;     char prevCh =  Q ;     string Final =   ;     int ptr1 = 0, ptr2 = 0;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       int size = s.size();       int indx = size - 2;       ;       string num1 = s.substr(0, indx);       long long int frq = Stoi(num1);       char Chr = s[indx + 1];       if (Chr == prevCh)         prevFreq += frq;       else {         if (prevCh !=  Q ) {           string s1 = itos(prevFreq) + prevCh;           for (int i = 0; i < s1.size(); i++) {             F1[ptr1] = s1[i];             ptr1++;           }         }         prevFreq = frq;         prevCh = Chr;       }     }     string s1 = itos(prevFreq) + prevCh;     for (int i = 0; i < s1.size(); i++) {       F1[ptr1] = s1[i];       ptr1++;     }     F1[ptr1] = 0;     Final = F1;     prevFreq = 0;     prevCh =  Q ;     string Final2 =   ;     for (int i = 0; i < m; i++) {       string s;       cin >> s;       int indx = s.find( - );       string num1 = s.substr(0, indx);       long long int frq = Stoi(num1);       char Chr = s[indx + 1];       if (Chr == prevCh)         prevFreq += frq;       else {         if (prevCh !=  Q ) {           string s2 = itos(prevFreq) + prevCh;           for (int i = 0; i < s2.size(); i++) {             F2[ptr2] = s2[i];             ptr2++;           }         }         prevFreq = frq;         prevCh = Chr;       }     }     string s2 = itos(prevFreq) + prevCh;     for (int i = 0; i < s2.size(); i++) {       F2[ptr2] = s2[i];       ptr2++;     }     Final2 = F2;     vector<int> st, end;     int indx = 0;     int indx2 = Final2.size() - 2;     while (Final2[indx] >=  0  && Final2[indx] <=  9 ) indx++;     while (indx2 >= 0 && Final2[indx2] >=  0  && Final2[indx2] <=  9 ) indx2--;     long long int ans = 0;     if (indx2 >= 0) {       string toSrch = Final2.substr(indx, indx2 - indx + 1);       KMPSearch(toSrch, Final, st, end);       for (int i = 0; i < st.size(); i++) {         long long int Aval = numBefore(st[i], Final);         long long int Req = numBefore(indx, Final2);         int i2 = charAfter(end[i], Final);         int i3 = charAfter(indx2, Final2);         if (i2 >= 0 && i3 >= 0 && Final2[i3] == Final[i2]) {           long long int Aval2 = numBefore(i2, Final);           long long int Req2 = numBefore(i3, Final2);           if (Aval >= Req && Aval2 >= Req2) ans++;         }       }     } else {       char ch = Final2[Final2.size() - 1];       for (int i = 0; i < Final.size(); i++) {         if (Final[i] == ch) {           long long int Aval = numBefore(i, Final);           long long int Req = numBefore(Final2.size() - 1, Final2);           if (Aval >= Req) ans = ans + (Aval - Req + 1);         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void Fast() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   inline int RD() {     int i;     cin >> i;     return i;   }   inline float RF() {     float i;     cin >> i;     return i;   }   inline double RDO() {     double i;     cin >> i;     return i;   }   inline string RS() {     string i;     cin >> i;     return i;   }   inline long long Rll() {     long long i;     cin >> i;     return i;   }   inline bool super(long long n) {     int x4 = 0, x7 = 0;     while (n != 0) {       int x = n % 10;       if (x == 7)         x7++;       else         x4++;       n /= 10;     }     return (x4 == x7) ? true : false;   }   int A1[1000];   int arr[200004];   int main() {     Fast();     int n = RD(), k = RD();     string t = RS();     int x = 0;     for (int i = 1; i < t.size(); i++) {       if (t.substr(i) == t.substr(0, t.size() - i)) {         x = n - i;         break;       }     }     cout << t;     for (int i = 0; i < k - 1; i++) cout << t.substr(x);   }


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


#include <bits/stdc++.h>   using namespace std;   double t, k, d, start = 0, sum = 0;   int main() {     scanf( %lf%lf%lf , &k, &d, &t);     if ((long long)k % (long long)d == 0)       printf( %.1f n , t);     else if (k >= t)       printf( %.1f n , t);     else {       if (k > d) {         long long a = k / d;         d *= a + 1;       }       long long x = (long long)t / (k + (d - k) / 2);       start = (double)x * d;       sum = (double)x * (k + (d - k) / 2);       sum = t - sum;       if (sum > k)         start += k + (sum - k) * 2;       else         start += sum;       printf( %.9f n , start);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, i, dx, dy, y;   int main() {     scanf( %d %d , &N, &M);     if ((N == 5 || N == 6) && M == 3) {       printf( -1 n );       return 0;     }     dx = 9;     dy = 5;     y = 0;     for (i = 0; i < M; i++) {       printf( %d %d n , dx * i, y);       y += dy * (i + 1);     }     y = 0;     for (i = 0; i < N - M; i++) {       printf( %d %d n , 10000000 - dx * i, y);       y += dy * (i + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pos[11], neg[11], n, x, zero;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       if (x == 0) zero++;       if (x > 0) pos[x]++;       if (x < 0) neg[abs(x)]++;     }     long long cnt = 0;     cnt += zero * (zero - 1) / 2;     for (int i = 1; i <= 10; i++) cnt += (pos[i] * neg[i]);     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(const pair<int, pair<int, int>> a, const pair<int, pair<int, int>> b) {     if (a.first == b.first) {       return a.second.first > b.second.first;     } else {       return a.first < b.first;     }   }   int main() {     ios_base::sync_with_stdio(false);     int n, k;     cin >> n >> k;     vector<int> be(n);     vector<int> en(n);     for (int i = 0; i < n; i++) {       cin >> be[i] >> en[i];     }     int L = 0;     int R = 1e9 + 1e9 + 5;     while (R - L > 1) {       int mid = L + (R - L) / 2;       vector<pair<int, pair<int, int>>> even;       for (int i = 0; i < n; i++) {         long long nooow = (long long)en[i] - mid + 1;         if (be[i] <= nooow) {           even.push_back({be[i], {1, 0}});           even.push_back({nooow, {-1, 0}});         }       }       sort(even.begin(), even.end(), cmp);       int bal = 0;       bool good = false;       for (int i = 0; i < even.size(); i++) {         bal += even[i].second.first;         if (bal >= k) {           good = true;         }       }       if (good) {         L = mid;       } else {         R = mid;       }     }     vector<pair<int, pair<int, int>>> even;     for (int i = 0; i < n; i++) {       long long nooow = (long long)en[i] - L + 1;       if (be[i] <= nooow) {         even.push_back({be[i], {1, i}});         even.push_back({nooow, {-1, i}});       }     }     sort(even.begin(), even.end(), cmp);     vector<int> ans;     ans.push_back(1);     int ind = 0;     for (int i = 1; i < even.size(); i++) {       if (even[i].second.first == 1) {         ans.push_back(ans[i - 1] + 1);       } else {         ans.push_back(ans[i - 1] - 1);       }       if (ans[i] == k) {         ind = i;         break;       }     }     if (L == 0) {       cout << 0 << endl;       for (int i = 0; i < k; i++) {         cout << i + 1 <<    ;       }     } else {       cout << L << endl;       set<int> answer;       for (int i = 0; i <= ind; i++) {         if (even[i].second.first == 1) {           answer.insert(even[i].second.second);         } else {           answer.erase(even[i].second.second);         }       }       for (set<int>::iterator it = answer.begin(); it != answer.end(); it++) {         cout << *it + 1 <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int id;     int u, v, w;   } edges[100005];   int n, m;   int d[100005], cost[100005];   bool path[100005];   vector<Edge> G[100005], ans;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       edges[i].u = u, edges[i].v = v, edges[i].w = w, edges[i].id = i;       G[u].push_back(edges[i]);       G[v].push_back(edges[i]);     }     d[1] = 0;     cost[1] = 0;     queue<int> que;     que.push(1);     while (!que.empty()) {       int u = que.front();       que.pop();       for (size_t i = 0; i < G[u].size(); i++) {         Edge e = G[u][i];         int v = e.u;         if (v == u) v = e.v;         if (v != 1 && d[v] == 0) {           d[v] = d[u] + 1;           que.push(v);         }         if (d[v] == d[u] + 1) cost[v] = max(cost[v], cost[u] + e.w);       }     }     int u = n;     while (d[u] != 0) {       for (size_t i = 0; i < G[u].size(); i++) {         Edge e = G[u][i];         int v = e.u;         if (v == u) v = e.v;         if (d[v] != d[u] - 1) continue;         if ((e.w == 1 && cost[v] == cost[u] - 1) ||             (e.w == 0 && cost[v] == cost[u])) {           path[e.id] = true;           u = v;           break;         }       }     }     for (int ind = 0; ind < m; ind++) {       if (path[ind] && edges[ind].w == 0) {         ans.push_back(edges[ind]);       } else if (!path[ind] && edges[ind].w == 1) {         ans.push_back(edges[ind]);       }     }     cout << ans.size() << endl;     for (vector<Edge>::iterator it = ans.begin(); it != ans.end(); ++it) {       cout << it->u <<     << it->v <<     << (it->w ^ 1) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9, MOD = INF + 7;   long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); }   long long power(long long a, long long b) {     return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1));   }   long long mod(long long a) { return (a % MOD + MOD) % MOD; }   const long long N = 1e6 + 20;   vector<long long> g[N];   long long mark[N];   vector<pair<long long, pair<long long, long long> > > ans;   bool dfs(long long v, long long par = 0) {     mark[v] = 1;     long long tmp = 0;     for (long long u : g[v]) {       if (u == par || mark[u] == 2) continue;       if (mark[u] == 0 && dfs(u, v)) continue;       if (tmp == 0)         tmp = u;       else         ans.push_back(make_pair(v, make_pair(u, tmp))), tmp = 0;     }     mark[v] = 2;     if (tmp != 0 && par != 0) ans.push_back(make_pair(v, make_pair(tmp, par)));     return tmp;   }   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     for (long long i = 1; i <= n; i++)       if (mark[i] == 0) dfs(i);     cout << ans.size() <<   n ;     for (auto p : ans)       cout << p.second.first <<     << p.first <<     << p.second.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     long n, m;     scanf( %ld %ld , &n, &m);     std::vector<long> a(n + 2, 0);     a[n + 1] = m;     for (long p = 1; p <= n; p++) {       scanf( %ld , &a[p]);     }     long orig(0), off(0), mx(0);     for (long p = n; p >= 0; p--) {       if (p % 2) {         off += a[p + 1] - a[p];       } else {         orig += a[p + 1] - a[p];       }       mx = (mx > off - orig) ? mx : (off - orig);     }     printf( %ld n , orig + (mx > 0) * (mx - 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int k = (n + 1) / 2;     vector<int> A(k);     for (int& a : A) scanf( %d , &a);     int x;     scanf( %d , &x);     A.resize(n, x);     long long sum = accumulate(begin(A), begin(A) + k, 0LL);     long long min_sum = sum;     int res = -1;     for (long long i = k, s = 1LL * x * (n - k); i < n; ++i, s -= x) {       if (min_sum + s > 0) {         res = n + k - i;         break;       }       sum += A[i] - A[i - k];       min_sum = min(min_sum, sum);     }     if (res == -1 && min_sum > 0) res = k;     printf( %d n , res);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void smn(T &a, const T &b) {     if (b < a) a = b;   }   template <class T>   inline void smx(T &a, const T &b) {     if (b > a) a = b;   }   template <class T>   inline T rev(const T &a) {     T _ = a;     reverse(_.begin(), _.end());     return _;   }   const double eps = 1e-9;   const long double leps = 1e-14;   const int MN = 5000 + 100, MOD = 1000 * 1000 * 1000 + 7;   vector<int> dis;   int n;   int dt[MN][MN];   pair<int, int> point[MN];   int mk = 1, now;   int mark[MN];   int v[MN];   int d(pair<int, int> a, pair<int, int> b) {     return abs(a.first - b.first) + abs(a.second - b.second);   }   void dfs(int a) {     mark[a] = mk;     for (int i = 0; i < n; i++)       if (dt[a][i] > now && mark[i] != mk) v[i] = 1 - v[a], dfs(i);   }   bool av(int a) {     now = a;     for (int i = 0; i < n; i++)       if (mark[i] != mk) v[i] = 0, dfs(i);     mk++;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (dt[i][j] > now && v[i] == v[j]) return 0;     return 1;   }   int main(int argc, char *argv[]) {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> point[i].first >> point[i].second;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) dt[i][j] = d(point[i], point[j]);     int s = 0, e = 10000;     int res = 10000;     while (s <= e) {       int m = (s + e) / 2;       if (av(m))         smn(res, m), e = m - 1;       else         s = m + 1;     }     now = res;     cout << now <<   n ;     int rn = 1;     for (int i = 0; i < n; i++)       if (mark[i] != mk) dfs(i), rn = (2LL * rn) % MOD;     cout << rn <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long t, a, b, x, y, n, z, z2;     cin >> t;     while (t--) {       cin >> a >> b >> x >> y >> n;       if (abs(a - x) + abs(b - y) < n) {         n = abs(a - x) + abs(b - y);       }       long long a2 = a, b2 = b, x2 = x, y2 = y, n2 = n;       if (n2 > abs(a2 - x2)) {         n2 -= abs(a2 - x2);         a2 = x2;         b2 -= n2;       } else {         a2 -= n2;       }       if (n > abs(b - y)) {         n -= abs(b - y);         b = y;         a -= n;       } else {         b -= n;       }       cout << min(a2 * b2, a * b) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long M = 1e9 + 7;   void solve() {     long long n, r;     cin >> n >> r;     long long ans = 0;     if (r >= n) ans++;     r = min(r, n - 1);     if (r % 2)       ans += r * ((r + 1) / 2);     else       ans += (r / 2) * (r + 1);     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   void read() { scanf( %d%d , &n, &q); }   void solve() {     int p0 = 0, p1 = 0, l = 0;     while (q--) {       int t;       scanf( %d , &t);       if (t == 1) {         int x;         scanf( %d , &x);         p1 = (p1 + x) % n;         p0 = (p0 + x) % n;         l ^= ((x % 2) + 2) % 2;       } else {         if (!l) {           p0 = (p0 + 1) % n;           p1 = (p1 - 1) % n;         } else {           p0 = (p0 - 1) % n;           p1 = (p1 + 1) % n;         }         l ^= 1;       }     }     if (l == 1) swap(p0, p1);     for (int i = 0; i < n; i++) {       int x;       x = (i - p0 + n) % n;       printf( %d  , x + 1);       swap(p0, p1);     }   }   int main() {     read();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool o[30];   int main() {     int m, n, i, x, mid;     cin >> m >> n;     for (i = 0; i < n; i++) {       cout << m << endl;       cin >> x;       if (!x) return printf( %d n , m), 0;       o[i] = x == -1;     }     i = -1;     int l = 1, r = m - 1;     while (l <= r) {       mid = (l + r) >> 1;       cout << mid << endl;       cin >> x;       if (!x) return printf( %d n , mid), 0;       if ((x == -1) ^ o[(++i) %= n])         l = mid + 1;       else         r = mid - 1;     }     return printf( %d n , l), 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int ans, h, r;     double tmp;     scanf( %d%d , &r, &h);     ans = h / r * 2;     tmp = h % r;     if (r / 2.0 - tmp > 1e-8)       ans++;     else if (sqrt(3) / 2 * r - tmp > 1e-8)       ans += 2;     else       ans += 3;     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 5;   vector<long long> adj[N];   vector<pair<long long, long long> > lol[N];   long long x[N], y[N], z[N], vis[N], tin[N], low[N], bridge[N], comp[N],       artificat[N], depth[N], par[N], path[N], timer, cur;   void dfs1(long long node, long long prvId) {     vis[node] = 1;     tin[node] = low[node] = ++timer;     for (auto &id : adj[node]) {       if (id == prvId) continue;       long long v = x[id] ^ y[id] ^ node;       if (!vis[v])         dfs1(v, id), low[node] = min(low[node], low[v]);       else         low[node] = min(low[node], tin[v]);       if (low[v] > tin[node]) bridge[id] = 1;     }   }   void dfs2(long long node) {     comp[node] = cur;     vis[node] = 1;     for (auto &id : adj[node]) {       if (bridge[id]) continue;       if (z[id]) artificat[cur] = 1;       long long v = x[id] ^ y[id] ^ node;       if (!vis[v]) dfs2(v);     }   }   void dfs3(long long node, long long pr) {     depth[node] = depth[pr] + 1;     par[node] = pr;     for (auto &ele : lol[node])       if (ele.first != pr) path[ele.first] = ele.second, dfs3(ele.first, node);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= m; i++) {       cin >> x[i] >> y[i] >> z[i];       adj[x[i]].push_back(i);       adj[y[i]].push_back(i);     }     dfs1(1, 0);     for (long long i = 1; i <= n; i++) vis[i] = 0;     for (long long i = 1; i <= n; i++)       if (!vis[i]) cur++, dfs2(i);     for (long long i = 1; i <= m; i++) {       if (bridge[i]) {         lol[comp[x[i]]].push_back({comp[y[i]], z[i]});         lol[comp[y[i]]].push_back({comp[x[i]], z[i]});       }     }     dfs3(1, 0);     long long s, t;     cin >> s >> t;     s = comp[s], t = comp[t];     while (s != t) {       if (depth[s] < depth[t]) swap(s, t);       if (artificat[s] || path[s]) return cout <<  YES , 0;       s = par[s];     }     cout << (artificat[s] ?  YES  :  NO );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500000;   const int M = 70;   const int C = 300;   const int MOD = 1e9 + 7;   struct Point {     int x[5];     Point() {       for (int i = 0; i < 5; i++) x[i] = 0;     }   };   int n;   Point a[N];   vector<int> res;   Point diff(const Point &a, const Point &b) {     Point res = Point();     for (int i = 0; i < 5; i++) res.x[i] = a.x[i] - b.x[i];     return res;   }   bool check(const Point &a, const Point &b) {     int val = 0;     for (int i = 0; i < 5; i++) val += a.x[i] * b.x[i];     return (val > 0);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < 5; j++) scanf( %d , &a[i].x[j]);     }     int ans = 0;     if (n <= C) {       for (int i = 0; i < n; i++) {         bool flag = true;         for (int j = 0; j < n; j++) {           for (int k = j + 1; k < n; k++) {             if (j == i || k == i) continue;             if (check(diff(a[j], a[i]), diff(a[k], a[i]))) {               flag = false;               break;             }           }         }         if (flag) {           ans++;           res.push_back(i + 1);         }       }     }     cout << ans << endl;     for (int i = 0; i < res.size(); i++) cout << res[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> eg[400005];   long long dep[400005];   int dfn[400005], sz[400005];   int a[400005];   int p[400005], w[400005];   int dfcnt = 0;   int fa[400005][20];   void dfs(int a) {     sz[a] = 1, dfn[a] = ++dfcnt;     for (auto v : eg[a]) {       if (v == p[a]) continue;       fa[v][0] = a;       for (int i = 1; i < 20; i++) fa[v][i] = fa[fa[v][i - 1]][i - 1];       dep[v] = dep[a] + w[v];       dfs(v);       sz[a] += sz[v];     }   }   long long ud[400005];   vector<int> qs[400005];   int d[400005];   int lb(int x) { return x & -x; }   void upd(int pl, int x) {     while (pl < 400005) d[pl] += x, pl += lb(pl);   }   int q(int pl) {     int ans = 0;     while (pl) ans += d[pl], pl -= lb(pl);     return ans;   }   int ans[400005];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 2; i <= n; i++) {       scanf( %d%d , &p[i], &w[i]);       eg[p[i]].push_back(i);     }     dfs(1);     dep[0] = -1e18;     for (int i = 1; i <= n; i++) {       int v = i;       for (int j = 19; j >= 0; j--) {         int t = fa[v][j];         if (dep[t] >= dep[i] - a[i]) v = t;       }       if (p[v]) upd(dfn[p[v]], -1);       upd(dfn[i], 1);     }     for (int i = 1; i <= n; i++) ans[i] = q(dfn[i] + sz[i] - 1) - q(dfn[i] - 1);     for (int i = 1; i <= n; i++) printf( %d  , ans[i] - 1);     return 0;   }


#include <bits/stdc++.h>   int n, k, a, b;   int ask(int x, int y) {     if (x == n) return 1;     fflush(stdout);     printf( 1 %d %d n , x, y);     fflush(stdout);     char s[5];     scanf( %s , s);     fflush(stdout);     return s[0] ==  T ;   }   int xxx(int l, int r) {     int mid, res = 0;     while (l <= r) {       mid = (l + r) >> 1;       if (ask(mid, mid + 1))         res = mid, r = mid - 1;       else         l = mid + 1;     }     return res;   }   int main() {     scanf( %d%d , &n, &k);     fflush(stdout);     a = xxx(1, n);     b = xxx(1, a - 1);     if (!b) b = xxx(a + 1, n);     fflush(stdout);     printf( 2 %d %d , a, b);     fflush(stdout);   }


#include <bits/stdc++.h>   int main() {     int n;     int x, y;     int k;     int l;     scanf( %d , &n);     for (x = 4; 2 * x < n; x++) {       y = n - x;       k = 0;       l = 0;       for (int i = 2; i < x; i++) {         if (x % i == 0) k = 1;       }       for (int j = 2; j < y; j++) {         if (y % j == 0) l = 1;       }       if (k && l) {         printf( %d %d , x, y);         break;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   using ii = pair<int, int>;   using ll = long long;   const int N = 2005;   const int mod = 1e9 + 7;   ll a[2005], b[2005];   ll lena[2005], lenb[2005];   int n, m;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     ll x;     cin >> x;     fill(lena, lena + n + 1, 1e9);     fill(lenb, lenb + m + 1, 1e9);     for (int i = 0; i < n; i++) {       ll cur = 0;       for (int j = i; j < n; j++) {         cur += a[j];         lena[j - i + 1] = min(lena[j - i + 1], cur);       }     }     for (int i = 0; i < m; i++) {       ll cur = 0;       for (int j = i; j < m; j++) {         cur += b[j];         lenb[j - i + 1] = min(lenb[j - i + 1], cur);       }     }     int out = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (lena[i] * lenb[j] <= x) out = max(out, i * j);     cout << out <<   n ;     return 0;   }