#include <bits/stdc++.h>   using namespace std;   const int p[] = {1, 2, 2, 1};   const int q[] = {1, 1, 2, 2};   const int N = 500005;   int n, m;   int a[N], b[N];   long long ans;   void check(int& a, int b) {     if (!a)       a = b;     else if (a != b)       ans = 0;   }   int F(int a, int b) { return (b & 1) ? a : 3 - a; }   int main() {     scanf( %d%d n , &n, &m);     ans = 1;     char ch;     int k;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         scanf( %c , &ch);         if (ch ==  . ) continue;         k = ch -  1 ;         check(a[j], F(p[k], i));         check(b[i], F(q[k], j));       }       scanf(  n );     }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         (ans *= ((i == 1 && !a[j]) + 1) * ((j == 1 && !b[i]) + 1)) %= 1000003;     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   int n, m, en, q[maxn], depth[maxn], f[maxn][20], dist[maxn];   struct edge {     int e;     edge *next;   } * v[maxn], ed[maxn << 1];   void add_edge(int s, int e) {     en++;     ed[en].next = v[s];     v[s] = ed + en;     v[s]->e = e;   }   void bfs(int root) {     int front = 1, tail = 1;     q[1] = root;     depth[1] = 1;     for (; front <= tail;) {       int now = q[front++];       for (edge *e = v[now]; e; e = e->next)         if (!depth[e->e]) {           depth[e->e] = depth[now] + 1;           f[e->e][0] = now;           int p = now, x = 0;           while (f[p][x]) {             f[e->e][x + 1] = f[p][x];             p = f[p][x];             x++;           }           q[++tail] = e->e;         }     }   }   int get_lca(int p1, int p2) {     if (depth[p1] < depth[p2]) swap(p1, p2);     int delta = depth[p1] - depth[p2], x = 0;     while (delta) {       if (delta & 1) p1 = f[p1][x];       delta >>= 1;       x++;     }     x = 0;     while (p1 != p2) {       if (!x || f[p1][x] != f[p2][x]) {         p1 = f[p1][x];         p2 = f[p2][x];         x++;       } else         x--;     }     return p1;   }   int main() {     scanf( %d%d , &n, &m);     for (int a = 1; a < n; a++) {       int s, e;       scanf( %d%d , &s, &e);       add_edge(s, e);       add_edge(e, s);     }     int size = (int)sqrt(n);     bfs(1);     int cnt = 1;     q[1] = 1;     memset(dist, 0x3f, sizeof(dist));     dist[1] = 0;     int opt, p;     for (int a = 1; a <= m; a++) {       scanf( %d%d , &opt, &p);       if (opt == 1) {         q[++cnt] = p;         dist[p] = 0;       } else {         int ans = dist[p];         for (int b = 1; b <= cnt; b++)           ans = min(ans, depth[p] + depth[q[b]] - 2 * depth[get_lca(p, q[b])]);         printf( %d n , ans);       }       if (cnt >= size) {         for (int front = 1, tail = cnt + 1; front != tail;) {           int now = q[front++];           if (front == maxn) front = 0;           for (edge *e = v[now]; e; e = e->next)             if (dist[e->e] > dist[now] + 1) {               dist[e->e] = dist[now] + 1;               q[tail++] = e->e;               if (tail == maxn) tail = 0;             }         }         cnt = 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ty {     int d[4][11], a;   } t[400005], ans;   int n, m, q, x, y, a[11][100005], co[42], col, fa1, fa2, fa[42];   int find(int x) {     if (x == fa[x]) return x;     return fa[x] = find(fa[x]);   }   ty update(ty x, ty y) {     ty z;     for (int i = 1; i <= n; i++) {       fa[x.d[3][i]] = x.d[3][i];       fa[x.d[2][i]] = x.d[2][i];       fa[y.d[2][i] + 20] = y.d[2][i] + 20;       fa[y.d[3][i] + 20] = y.d[3][i] + 20;     }     z.a = x.a + y.a;     int col = 0;     memset(co, 0, sizeof(co));     for (int i = 1; i <= n; i++)       if (x.d[1][i] == y.d[0][i]) {         fa1 = find(x.d[3][i]);         fa2 = find(y.d[2][i] + 20);         if (fa1 != fa2) {           z.a--;           fa[fa2] = fa1;         }       }     for (int i = 1; i <= n; i++) {       z.d[0][i] = x.d[0][i];       z.d[1][i] = y.d[1][i];       fa1 = find(x.d[2][i]);       if (!co[fa1]) co[fa1] = ++col;       z.d[2][i] = co[fa1];       fa1 = find(y.d[3][i] + 20);       if (!co[fa1]) co[fa1] = ++col;       z.d[3][i] = co[fa1];     }     return z;   }   void build(int o, int l, int r) {     if (l == r) {       t[o].a = 0;       int col = 0;       for (int i = 1; i <= n; i++) {         t[o].d[0][i] = t[o].d[1][i] = a[i][l];         if (a[i][l] != a[i - 1][l]) {           t[o].a++;           col++;         }         t[o].d[2][i] = t[o].d[3][i] = col;       }       return;     }     int mid = (l + r) >> 1;     build(o * 2, l, mid);     build(o * 2 + 1, mid + 1, r);     t[o] = update(t[o * 2], t[o * 2 + 1]);   }   ty find(int o, int l, int r, int L, int R) {     if (l == L && r == R) return t[o];     int mid = (l + r) >> 1;     if (R <= mid)       return find(o * 2, l, mid, L, R);     else if (L > mid)       return find(o * 2 + 1, mid + 1, r, L, R);     else       return update(find(o * 2, l, mid, L, mid),                     find(o * 2 + 1, mid + 1, r, mid + 1, R));   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++)       for (int r = 1; r <= m; r++) scanf( %d , &a[i][r]);     build(1, 1, m);     for (int i = 1; i <= q; i++) {       scanf( %d%d , &x, &y);       ans = find(1, 1, m, x, y);       printf( %d n , ans.a);     }   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   string best;   void LongestPalindromicPrefix(string str) {     string temp = str +  ? ;     reverse(str.begin(), str.end());     temp += str;     int n = temp.length();     int lps[n];     fill(lps, lps + n, 0);     for (int i = 1; i < n; i++) {       int len = lps[i - 1];       while (len > 0 && temp[len] != temp[i]) {         len = lps[len - 1];       }       if (temp[i] == temp[len]) {         len++;       }       lps[i] = len;     }     if (best.length() < lps[n - 1]) {       best = temp.substr(0, lps[n - 1]);     }   }   int solve() {     int n, i, j;     best.erase();     string s;     cin >> s;     n = s.length();     i = 0, j = n - 1;     string temp;     long long ans = 0;     while (s[i] == s[j] && i <= j) {       temp.push_back(s[i]);       i++;       j--;       ans++;       if (i != j) {         ans++;       }       if (i >= j) {         break;       }     }     int k;     string res;     for (k = i; k <= j; k++) {       res.push_back(s[k]);     }     if (res.length() == 0) {       cout << s <<   n ;       return 0;     }     cout << temp;     LongestPalindromicPrefix(res);     reverse(res.begin(), res.end());     LongestPalindromicPrefix(res);     cout << best;     reverse(temp.begin(), temp.end());     cout << temp <<   n ;     return 0;   }   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;   long double l[200006];   int main() {     l[1] = 0;     l[0] = 0;     for (int i = 2; i < 200005; i++) {       l[i] = log(i) + l[i - 1];     }     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     if (k >= m) {       printf( 1.00000 n );     } else if (k + n < m) {       printf( 0.00000 n );     } else {       long double ans = l[n] + l[m] - l[n + k + 1] - l[m - k - 1];       ans = exp(ans);       double tmp = 1.0 - ans;       printf( %.10f n , tmp);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> adj[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     bool flag = true;     int test_case = 1, tc;     if (!flag) cin >> test_case;     tc = test_case;     while (tc--) {       int i, j, n, m, sum = 0, ans = 0, cnt = 0, flag = 0;       int maxi = -1e9, mini = 1e9;       string s;       cin >> s;       cin >> n;       m = s.size();       int pre[26][m + 2];       memset(pre, 0, sizeof(pre));       for (i = 0; i < m; i++) pre[s[i] -  a ][i] = 1;       for (i = 0; i < 26; i++) {         for (j = 1; j < m; j++) {           pre[i][j] += pre[i][j - 1];         }       }       while (n--) {         int l, r;         cin >> l >> r;         cnt = 0;         if (r == l) {           cout <<  Yes n ;           continue;         } else if (l == 1) {           for (i = 0; i < 26; i++) {             if (pre[i][r - 1] > 0) cnt++;           }         } else {           for (i = 0; i < 26; i++) {             if (pre[i][r - 1] - pre[i][l - 2] > 0) cnt++;           }         }         if (cnt > 2 or s[l - 1] != s[r - 1])           cout <<  Yes n ;         else           cout <<  No n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100001];   int main() {     ios::sync_with_stdio(0);     int n, mn = 1e9;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       mn = min(mn, a[i]);     }     int last = -1;     int ans = n + 1e1;     for (int i = 1; i <= n; ++i) {       if (a[i] == mn) {         if (last != -1) {           ans = min(ans, i - last);         }         last = i;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int hr, mt;     int h, d, c, n;     scanf( %d%d , &hr, &mt);     scanf( %d%d%d%d , &h, &d, &c, &n);     int p = h + max((1200 - (hr * 60 + mt)) * d, 0), t;     if (p % n != 0)       t = p / n + 1;     else       t = p / n;     double ans = t * c * 0.8;     if (h % n != 0)       t = h / n + 1;     else       t = h / n;     ans = min(ans, t * c * 1.0);     printf( %.3f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, clr[300001][3] = {{0}};   vector<long long> v[300001];   void dfs(long long node, long long parent) {     for (auto x : v[node]) {       if (x == parent) continue;       dfs(x, node);       clr[node][1] += clr[x][1];       clr[node][2] += clr[x][2];     }   }   signed main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cin >> n;     long long r = 0, b = 0;     for (long long i = 1; i < n + 1; i++) {       long long c;       cin >> c;       if (c == 1) r++;       if (c == 2) b++;       clr[i][c]++;     }     for (long long i = 1; i < n; i++) {       long long x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1, 1);     long long ans = 0;     if (b == 0 || r == 0) return cout << n - 1 <<   n , 0;     for (long long i = 1; i < n + 1; i++) {       if ((clr[i][2] == 0 && clr[i][1] == r) ||           (clr[i][1] == 0 && clr[i][2] == b))         ans++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > ans;   int main() {     int n;     scanf( %d , &n);     int a[n + 1], b[n + 1];     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= n; ++i) {       scanf( %d , &b[i]);     }     for (int i = 1; i <= n; ++i) {       if (a[i] != b[i]) {         for (int j = i + 1; j <= n; ++j) {           if (a[i] == b[j]) {             for (int k = j; k > i; k--) {               int sw = b[k];               b[k] = b[k - 1];               b[k - 1] = sw;               ans.push_back(make_pair(k - 1, k));             }             break;           }         }       }     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) {       printf( %d %d n , ans[i].first, ans[i].second);     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T x, T y) {     while (y > 0) {       x %= y;       swap(x, y);     }     return x;   }   template <class _T>   inline _T sqr(const _T& x) {     return x * x;   }   template <class _T>   inline string tostr(const _T& a) {     ostringstream os(  );     os << a;     return os.str();   }   const long double PI = 3.1415926535897932384626433832795L;   template <typename T>   inline void input(T& a) {     static int c;     a = 0;     while (!isdigit(c = getchar()) && c !=  - ) {     }     char neg = 0;     if (c ==  - ) {       neg = 1;       c = getchar();     }     while (isdigit(c)) {       a = 10 * a + c -  0 ;       c = getchar();     }     if (neg) a = -a;   }   template <typename T = int>   inline T nxt() {     T res;     input(res);     return res;   }   void solve() {}   void imp() {     puts( IMPOSSIBLE );     exit(0);   }   const int N = 1000010;   vector<int> q[N][2];   int g[N][2];   int r[N];   int maleft[N];   int miright[N];   int n;   int dfs(int v, int le, int ri) {     if (r[v] >= ri) {       imp();     }     if (v >= ri) {       imp();     }     if (le >= ri) {       imp();     }     if (maleft[v] > v) {       g[v][0] = v + 1;       int ret = dfs(v + 1, maleft[v], min(ri, miright[v]));       le = max(le, r[v]);       if (ret < le) {         g[v][1] = ret + 1;         return dfs(ret + 1, le, ri);       } else {         return ret;       }     } else {       le = max(le, r[v]);       if (v < le) {         g[v][1] = v + 1;         return dfs(v + 1, le, ri);       }     }     return v;   }   void print(int v) {     if (v >= n) {       return;     }     if (g[v][0]) {       print(g[v][0]);     }     printf( %d  , v + 1);     if (g[v][1]) {       print(g[v][1]);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int c;     n = nxt();     c = nxt();     char s[10];     for (int i = 0; i < c; ++i) {       int a = nxt() - 1;       int b = nxt() - 1;       if (b <= a) {         imp();       }       scanf( %s , s);       if (s[0] ==  L ) {         q[a][0].push_back(b);       } else {         q[a][1].push_back(b);       }     }     for (int i = 0; i < n; ++i) {       r[i] = i;       maleft[i] = i;       miright[i] = INT_MAX;     }     for (int i = n - 2; i >= 0; --i) {       for (int x : q[i][0]) {         r[i] = max(r[i], r[x]);       }       for (int x : q[i][1]) {         r[i] = max(r[i], r[x]);       }       for (int x : q[i][0]) {         maleft[i] = max(maleft[i], r[x]);       }       for (int x : q[i][1]) {         miright[i] = min(miright[i], x);       }       if (miright[i] <= maleft[i]) {         imp();       }     }     int val = dfs(0, n - 1, n);     assert(val == n - 1);     print(0);     puts(  );     return 0;   };


#include <bits/stdc++.h>   template <typename T>   std::istream& operator>>(std::istream& input, std::vector<T>& v) {     for (T& a : v) input >> a;     return input;   }   void answer(int v) { std::cout << v <<   n ; }   void solve(const std::vector<size_t>& id) {     int z = 0;     std::unordered_map<size_t, size_t> x;     for (const size_t a : id) {       if (a == 0) continue;       const size_t c = ++x[a];       if (c > 2) return answer(-1);       z += (c == 2);     }     answer(z);   }   int main() {     size_t n;     std::cin >> n;     std::vector<size_t> id(n);     std::cin >> id;     solve(id);     return 0;   }


#include <bits/stdc++.h>   std::pair<int, int> a[111111];   int main() {     int i, n, m, max = 0;     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) scanf( %d%d , &a[i].first, &a[i].second);     max = std::max(a[0].second + a[0].first - 1,                    a[m - 1].second - a[m - 1].first + n);     for (i = 1; i < m; i++) {       if (std::abs(a[i].second - a[i - 1].second) > a[i].first - a[i - 1].first) {         puts( IMPOSSIBLE );         return 0;       }       max = std::max(max, std::max(a[i].second, a[i - 1].second) +                               (a[i].first - a[i - 1].first -                                std::abs(a[i].second - a[i - 1].second)) /                                   2);     }     printf( %d , max);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, m, pos[N], ans[N];   vector<int> g[N];   map<int, int> tot;   struct data {     int a, i;   } a[N];   bool cmp(data u, data v) { return u.a > v.a; }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i].a), a[i].i = i;       ++tot[a[i].a];     }     sort(a + 1, a + 1 + n, cmp);     for (int i = 1; i <= n; ++i) pos[a[i].i] = i;     for (int i = 1, x, y; i <= m; ++i) {       scanf( %d%d , &x, &y);       x = pos[x], y = pos[y];       g[x].push_back(y);       g[y].push_back(x);     }     int cnt = n;     a[0].a = -1;     for (int i = 1; i <= n; ++i) {       int s = g[i].size();       if (a[i].a != a[i - 1].a) cnt -= tot[a[i].a];       ans[a[i].i] = cnt;       for (int j = 0; j < s; ++j)         if (g[i][j] > i && a[g[i][j]].a != a[i].a) --ans[a[i].i];     }     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, aid = 1, did = 1, atk[105], def[105], c[105];   char s[10];   int main() {     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       scanf( %s , s);       if (s[0] ==  A )         scanf( %lld , &atk[aid++]);       else         scanf( %lld , &def[did++]);     }     for (long long i = 1; i <= m; i++) {       scanf( %lld , &c[i]);     }     sort(atk + 1, atk + aid);     sort(c + 1, c + m + 1, greater<long long>());     long long indx = 1, sum = 0, off = 0;     for (long long i = 1; i <= m; i++) {       if (i >= aid) break;       if (c[i] < atk[i]) {         off = 1;         break;       }       sum += (c[i] - atk[i]);       indx = i + 1;     }     multiset<long long> cel;     bool flag = 1;     if (off == 1 || indx > m) {       goto p;       return 0;     }     for (long long i = indx; i <= m; i++) cel.insert(c[i]);     for (long long i = 1; i < did; i++) {       auto it = cel.upper_bound(def[i]);       if (it == cel.end()) {         goto p;       }       cel.erase(it);     }     while (!cel.empty()) {       auto it = cel.begin();       sum += *it;       cel.erase(it);     }   p:     long long sum2 = 0, cnt = 0;     multiset<long long> cel2;     for (long long i = 1; i <= m; i++) cel2.insert(c[i]);     for (long long i = 1; i < did; i++) {       auto it = cel2.upper_bound(def[i]);       if (it == cel2.end()) continue;       cnt++;       cel2.erase(it);     }     for (long long i = 1; i < aid; i++) {       auto it = cel2.upper_bound(atk[i]);       if (it == cel2.end()) continue;       cnt++;       sum2 += (*it - atk[i]);       cel2.erase(it);     }     while (!cel2.empty() && cnt == n) {       auto it = cel2.begin();       sum2 += *it;       cel2.erase(it);     }     cout << max(sum, sum2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 2020;   const int MOD = 1e9 + 7;   const long long INF = 1061109567;   const long double EPS = 1e-9;   const long double PI = acos(-1);   const int MXX = 2e5 + 5;   long long F[MXX + 5], iF[MXX + 5];   long long qpow(long long b, long long e) {     if (!e) return 1LL;     if (e & 1) return (qpow(b, e - 1) * b) % MOD;     long long aux = qpow(b, e / 2);     return (aux * aux) % MOD;   }   long long invmod(long long n) { return qpow(n, MOD - 2); }   long long ways(int p, int q) {     if (p == 0 || q == 0) return 1;     long long ans = ((F[p + q] % MOD) * (iF[p] % MOD)) % MOD;     ans = ((ans % MOD) * (iF[q] % MOD)) % MOD;     return ans;   }   long long ways(int p, int q, int u, int v) { return ways(u - p, v - q) % MOD; }   pair<int, int> pt[MX];   long long dp[MX];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     iF[0] = F[0] = iF[1] = F[1] = 1LL;     for (int i = (2); i < (MXX); i++) {       F[i] = ((F[i - 1] % MOD) * (i % MOD)) % MOD;       iF[i] = ((iF[i - 1] % MOD) * (invmod(i) % MOD)) % MOD;     }     int h, w;     cin >> h >> w;     int n;     cin >> n;     n++;     pt[0].first = pt[0].second = 1;     for (int i = (1); i < (n); i++) {       cin >> pt[i].first >> pt[i].second;     }     sort(pt, pt + n);     for (int i = (n - 1); i >= (0); i--) {       dp[i] = ways(pt[i].first, pt[i].second, h, w);       for (int j = (i + 1); j < (n); j++) {         if (pt[j].second < pt[i].second) continue;         long long v =             ways(pt[i].first, pt[i].second, pt[j].first, pt[j].second) % MOD;         v = (v * dp[j]) % MOD;         dp[i] = (dp[i] + MOD - v) % MOD;       }     }     cout << dp[0];   }


#include<bits/stdc++.h>   using namespace std;   #define M 500000   typedef long long ll;   typedef unsigned long long ull;   inline ll read() {    char ch;    ll f = 1, res = 0;    while ((ch = getchar()) <  0  || ch >  9 )     if (ch ==  - ) f = -1;    while (ch >=  0  && ch <=  9 ) {     res = (res << 1) + (res << 3) + (ch ^ 48);     ch = getchar();    }    return f * res;   }   inline void pt(ll u,ll mod) {    printf( %lld , u);    if (mod == 1)     putchar(   );    else if (mod == 2)     putchar(  n );   }   ll mod=1e9+7;   ll arr[M];   ll p[M];   int main() {    //freopen( ../in ,  r , stdin);    //freopen( ../out ,  w , stdout);    p[1]=1;    p[0]=1;    for(ll i=2;i<M;i++)     p[i]=p[i-1]*i%mod;    ll q = read();    while (q--) {     ll n = read();     ll k = pow(2, 40) + 0.1 - 1;     for (ll i = 0; i < n; i++) {      ll t = read();      arr[i] = t;      k &= t;     }     ll cnt = 0;     for (ll i = 0; i < n; i++) {      if (arr[i] == k)       cnt++;     }     ll ans = cnt * (cnt - 1) % mod;     pt(ans * p[n - 2] % mod, 2);    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[1 << 16], *S, *T;     if (S == T) {       T = (S = buf) + fread(buf, 1, 1 << 16, stdin);       if (T == S) return EOF;     }     return *S++;   }   inline long long read() {     long long x = 0, f = 1;     char ch = gc();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = gc();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = gc();     return x * f;   }   int m, k, n, a[1000010], dp[1000010], ans = 0;   long long l;   pair<int, int> c[1000010];   int main() {     m = read();     l = read();     k = read();     n = m * k;     for (int i = 0; i < m; ++i) a[i] = read();     for (int i = 0; i < n; ++i) c[i].first = a[i % m], c[i].second = i;     sort(c, c + n);     long long tot = l / m;     int yu = l % m;     ans = l % 1000000007;     for (int i = 0; i < n; ++i) {       int id = c[i].second;       if (id / m + 1 == 1) {         dp[id / m + 1]++;         continue;       }       dp[id / m + 1] += dp[id / m + 1 - 1], dp[id / m + 1] %= 1000000007;       if (id >= l) continue;       long long cnt = tot - (id / m + 1) + 1;       if (id % m <= yu - 1) cnt++;       ans += cnt % 1000000007 * dp[id / m + 1 - 1] % 1000000007;       ans %= 1000000007;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long sq(long long x) { return x * x; }   long double ptos(pair<long long, long long> A, pair<long long, long long> B,                    pair<long long, long long> C) {     long long area = abs((B.first - A.first) * (C.second - A.second) -                          (B.second - A.second) * (C.first - A.first));     long long llen = sq(B.first - C.first) + sq(B.second - C.second);     return 1.0l * area / sqrtl(llen);   }   int main() {     int n;     scanf( %d , &n);     vector<pair<long long, long long> > p(n);     for (int i = 0; i < n; ++i) {       int first, second;       scanf( %d %d , &first, &second);       p[i].first = first, p[i].second = second;     }     p.push_back(p[0]);     long double dans = 1e18l;     for (int i = 0; i < n; ++i) {       dans = min(dans, ptos(p[i], p[(i - 1 + n) % n], p[i + 1]));       for (int j = 0; j < n; ++j) {         if (i != j) {           dans = min(dans, sqrtl(sq(p[i].first - p[j].first) +                                  sq(p[i].second - p[j].second)));         }         if (i != j && i != (j + 1) % n) {           dans = min(dans, ptos(p[i], p[j], p[j + 1]));         }       }     }     printf( %.10lf n , (double)(dans / 2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100005;   vector<vector<long long> > adj(N), w(N);   long long out[N], col[N], res[N], cnt;   queue<long long> q;   void dfs(long long v, long long p) {     for (auto &u : adj[v]) {       if (u == p) continue;       dfs(u, v);     }     for (auto &u : adj[v]) {       if (u == p) continue;       if (col[u] != col[v] && !res[u] && !res[v]) {         res[u] = res[v] = ++cnt;         q.push(v);         q.push(u);       }     }     return;   }   void bfs() {     q.push(1);     col[1] = 1;     while (!q.empty()) {       long long v = q.front();       q.pop();       for (auto &u : adj[v]) {         if (!col[u]) {           col[u] = col[v] % 2 + 1;           q.push(u);         }       }     }     cnt = 0;     dfs(1, 0);     while (!q.empty()) {       long long v = q.front();       q.pop();       for (auto &u : adj[v]) {         if (!res[u]) {           res[u] = res[v];           q.push(u);         }       }     }     return;   }   int main() {     long long n, i, j, v, u, ans;     cin >> n;     for (i = 0; i < n - 1; i++) {       cin >> v >> u;       adj[v].push_back(u);       adj[u].push_back(v);     }     bfs();     for (i = 1; i <= n; i++) w[res[i]].push_back(i);     ans = 0;     for (i = 1; i <= cnt; i++) {       ans += (w[i].size() - 1) * 2;       for (j = 0; j < w[i].size(); j++)         out[w[i][j]] = w[i][(j + 1) % w[i].size()];     }     cout << ans <<   n ;     for (i = 1; i <= n; i++) cout << out[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x;     int y;   };   struct vec {     int x;     int y;   };   point r_array[12], b_array[12];   int root[12]{}, ocupied[12]{};   int r, b;   double cross(point a, point b, point c) {     vec v1 = {c.x - a.x, c.y - a.y};     vec v2 = {b.x - a.x, b.y - a.y};     return (v1.x * v2.y - v1.y * v2.x);   }   bool r_check(int r1_index, int b1_index, int r2_index, int b2_index) {     point r1_cor = r_array[r1_index];     point r2_cor = r_array[r2_index];     point b1_cor = b_array[b1_index];     point b2_cor = b_array[b2_index];     double kq_r1 = cross(r1_cor, r2_cor, b2_cor);     double kq_b1 = cross(b1_cor, r2_cor, b2_cor);     double kq_r2 = cross(r2_cor, r1_cor, b1_cor);     double kq_b2 = cross(b2_cor, r1_cor, b1_cor);     if (kq_r1 * kq_b1 > 0) return 0;     if (kq_r2 * kq_b2 > 0) return 0;     return 1;   }   bool check() {     bool kq = 1;     for (int i = 1; i < r; i++)       for (int j = i + 1; j <= r; j++) {         kq = min(kq, r_check(i, root[i], j, root[j]));         if (kq == 0) return 0;       }     return kq;   }   bool sinh(int r_pos) {     if (r_pos > r) {       return check();     }     for (int i = 1; i <= b; i++) {       if (ocupied[i]) continue;       ocupied[i] = 1;       root[r_pos] = i;       bool kq = sinh(r_pos + 1);       ocupied[i] = 0;       if (kq) return kq;     }   }   int main() {     cin >> r >> b;     for (int i = 1; i <= r; i++) cin >> r_array[i].x >> r_array[i].y;     for (int i = 1; i <= b; i++) cin >> b_array[i].x >> b_array[i].y;     if (r != b) {       cout <<  No ;       return 0;     }     bool kq = sinh(1);     if (kq)       puts( Yes );     else       puts( No );   }


#include <bits/stdc++.h>   using namespace std;   using DO = double;   using LL = long long;   using VI = vector<LL>;   const int N = 5e5 + 10;   int head[N], nxt[N << 1], to[N << 1];   LL wei[N << 1];   int E;   void init(int n) {     for (int i = 1; i <= n; i++) {       head[i] = -1;     }     E = 0;   }   void add(int u, int v, int w) {     nxt[E] = head[u];     to[E] = v;     wei[E] = w;     head[u] = E++;     nxt[E] = head[v];     to[E] = u;     wei[E] = w;     head[v] = E++;   }   LL dp[N][2];   int n, k;   void dfs(int u, int fa = 0) {     dp[u][0] = dp[u][1] = 0;     VI vec;     for (int e = head[u], v; ~e; e = nxt[e]) {       v = to[e];       if (v == fa) continue;       dfs(v, u);       dp[u][0] += dp[v][0];       dp[u][1] += dp[v][0];       if (dp[v][0] < dp[v][1] + wei[e]) {         vec.push_back(dp[v][1] + wei[e] - dp[v][0]);       }     }     sort(vec.begin(), vec.end());     reverse(vec.begin(), vec.end());     for (int i = 0; i < min((int)vec.size(), k); i++) {       dp[u][0] += vec[i];     }     for (int i = 0; i < min((int)vec.size(), k - 1); i++) {       dp[u][1] += vec[i];     }   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %d %d , &n, &k);       init(n);       for (int i = 1, u, v, w; i < n; i++) {         scanf( %d %d %d , &u, &v, &w);         add(u, v, w);       }       dfs(1);       printf( %I64d n , max(dp[1][0], dp[1][1]));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   const int M = 205;   const int MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   struct node {     int l, r, id;   } p[N << 1];   bool cmp(node a, node b) { return a.r < b.r; }   int sum[N << 4];   void update(int p, int L, int R, int pos) {     if (L == R) {       sum[pos]++;       return;     }     int mid = (L + R) >> 1;     if (p <= mid)       update(p, L, mid, pos << 1);     else       update(p, mid + 1, R, pos << 1 | 1);     sum[pos] = sum[pos << 1] + sum[pos << 1 | 1];   }   int query(int k, int L, int R, int pos) {     if (L == R) return L;     int mid = (L + R) >> 1;     if (k <= sum[pos << 1])       return query(k, L, mid, pos << 1);     else       return query(k - sum[pos << 1], mid + 1, R, pos << 1 | 1);   }   int n, k, x[N << 1];   vector<int> Ans;   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++)       scanf( %d%d , &p[i].l, &p[i].r), p[i].id = i + 1, x[i * 2] = p[i].l,                                        x[i * 2 + 1] = p[i].r;     sort(p, p + n, cmp);     sort(x, x + 2 * n);     int m = unique(x, x + 2 * n) - x;     for (int i = 0; i < n; i++) {       p[i].l = lower_bound(x, x + m, p[i].l) - x;       p[i].r = lower_bound(x, x + m, p[i].r) - x;     }     int ans = 0, st, ed;     for (int i = n - 1; i >= 0; i--) {       update(p[i].l, 0, m - 1, 1);       if (sum[1] < k) continue;       int pos = query(k, 0, m - 1, 1);       int len = x[p[i].r] - x[pos] + 1;       if (len > ans) ans = len, st = pos, ed = p[i].r;     }     if (!ans) {       puts( 0 );       for (int i = 1; i <= k; i++) printf( %d  , i);     } else {       printf( %d n , ans);       for (int i = 0; i < n; i++)         if (p[i].l <= st && ed <= p[i].r) Ans.push_back(p[i].id);       sort(Ans.begin(), Ans.end());       for (int i = 0; i < k; i++) printf( %d  , Ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   struct node {     int x, y;     bool operator<(const node &_) const {       return x < _.x || (x == _.x && y < _.y);     }   } A[2005];   int h, w, n;   long long dp[2005], jie[200005 << 1], inv[200005 << 1];   long long Pow(long long x) {     int n = mod - 2;     long long res = 1;     while (n) {       if (n & 1) res = res * x % mod;       x = x * x % mod;       n >>= 1;     }     return res;   }   void Init() {     jie[0] = inv[0] = 1;     for (int i = 1; i < 200005; i++) {       jie[i] = 1LL * jie[i - 1] * i % mod;       inv[i] = Pow(jie[i]);     }   }   long long C(int a, int b) {     return 1LL * jie[a] * inv[b] % mod * inv[a - b] % mod;   }   int main() {     Init();     scanf( %d%d%d , &h, &w, &n);     for (int i = 1; i <= n; i++) scanf( %d%d , &A[i].x, &A[i].y);     sort(A + 1, A + n + 1);     A[n + 1].x = h, A[n + 1].y = w;     for (int i = 1; i <= n + 1; i++) {       dp[i] = C(A[i].x + A[i].y - 2, A[i].x - 1);       for (int j = 1; j < i; j++) {         if (A[i].y < A[j].y) continue;         dp[i] = ((dp[i] -                   C(A[i].x - A[j].x + A[i].y - A[j].y, A[i].x - A[j].x) * dp[j]) %                      mod +                  mod) %                 mod;       }     }     cout << dp[n + 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<vector<int> > adj;   vector<bool> top;   vector<int> branched;   vector<bool> visited;   vector<bool> fertile;   int root = -1;   void fail() {     cout <<  No  << endl;     exit(0);   }   void dfsFindRoot(int u) {     if (root != -1) return;     visited[u] = true;     bool leaf = true;     for (int child : adj[u]) {       if (visited[child]) continue;       leaf = false;     }     if (!leaf) {       branched[u] = 0;       for (int child : adj[u]) {         if (visited[child]) continue;         dfsFindRoot(child);         branched[u] += branched[child];       }       if (root != -1) return;       if (branched[u] >= 3) {         root = u;       }     }   }   void dfs(int u) {     visited[u] = true;     bool leaf = true;     for (int child : adj[u]) {       if (visited[child]) continue;       leaf = false;     }     if (!leaf) {       branched[u] = 0;       int numTops = 0;       for (int child : adj[u]) {         if (visited[child]) continue;         dfs(child);         if (fertile[child]) top[u] = true;         branched[u] += branched[child];         if (top[child]) {           numTops++;           top[u] = true;         }       }       if (u != root && numTops > 1)         fail();       else if (numTops > 2)         fail();       if (branched[u] >= 3) {         top[u] = true;       } else if (branched[u] == 2)         fertile[u] = true;     }   }   int main() {     int m;     cin >> n;     adj = vector<vector<int> >(n, vector<int>(0));     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     if (n <= 4) {       cout <<  YES  << endl;       return 0;     }     top = vector<bool>(n, false);     branched = vector<int>(n, 1);     visited = vector<bool>(n, false);     dfsFindRoot(0);     if (root == -1) {       cout <<  Yes  << endl;       return 0;     }     top = vector<bool>(n, false);     branched = vector<int>(n, 1);     visited = vector<bool>(n, false);     fertile = vector<bool>(n, false);     dfs(root);     cout <<  Yes  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, ans = 0, a, b, t = 1;     cin >> n >> x;     while (n--) {       cin >> a >> b;       while (t <= a) t = t + x;       t = t - x;       ans = ans + b - t + 1;       t = b + 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6 + 10;   long long bit[maxn];   void update(long long idx, long long v) {     while (idx <= maxn) {       bit[idx] += v;       idx += idx & -idx;     }   }   long long query(long long idx) {     long long ans = 0;     while (idx > 0) {       ans += bit[idx];       idx -= idx & -idx;     }     return ans;   }   long long inter(long long l, long long r) { return query(r) - query(l - 1); }   void solve() {     long long n, m;     cin >> n >> m;     memset(bit, 0, sizeof bit);     vector<pair<long long, pair<long long, long long> > > hor(n), vert(m);     vector<pair<long long, pair<long long, long long> > > ord;     long long ans = 1;     for (long long i = 0; i < n; i++) {       cin >> hor[i].first >> hor[i].second.first >> hor[i].second.second;       if ((hor[i].second.first + hor[i].second.second) == 1e6) ans++;     }     for (long long i = 0; i < m; i++) {       cin >> vert[i].first >> vert[i].second.first >> vert[i].second.second;       if ((vert[i].second.first + vert[i].second.second) == 1e6) ans++;     }     for (long long i = 0; i < m; i++) {       vert[i].first++;       vert[i].second.first++;       vert[i].second.second++;     }     for (long long i = 0; i < n; i++) {       hor[i].first++;       hor[i].second.first++;       hor[i].second.second++;     }     for (long long i = 0; i < (long long)vert.size(); i++) {       ord.push_back({vert[i].first, {1, i}});     }     for (long long i = 0; i < (long long)hor.size(); i++) {       ord.push_back({hor[i].second.first, {0, i}});       ord.push_back({hor[i].second.second, {2, i}});     }     sort(ord.begin(), ord.end());     for (long long i = 0; i < (long long)ord.size(); i++) {       long long x = ord[i].first;       long long tipo = ord[i].second.first;       long long ind = ord[i].second.second;       if (tipo == 1) {         long long y1 = vert[ind].second.first;         long long y2 = vert[ind].second.second;         ans += inter(y1, y2);       } else {         long long y = hor[ind].first;         if (tipo == 2)           update(y, -1);         else           update(y, 1);       }     }     cout << ans << endl;   }   int32_t main() {     cin.tie(0);     ios::sync_with_stdio(0);     long long tc = 1;     while (tc--) solve();   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > v, a;   vector<pair<double, int> > ans;   int n, sum, del, sx, sy, x, y, Nx, Ny;   set<int> u;   int cmp(pair<int, int> a, pair<int, int> b) {     return ((a.first) * (a.first)) + ((a.second) * (a.second)) <            ((b.first) * (b.first)) + ((b.second) * (b.second));   }   int main() {     v.clear();     u.clear();     for (int i = 0; i <= 200; i++)       for (int j = i; j <= 200; j++)         if (i + j)           if (!u.count(((i) * (i)) + ((j) * (j))))             v.push_back(make_pair(i, j)), u.insert(((i) * (i)) + ((j) * (j)));     sort(v.begin(), v.end(), cmp);     cin >> n;     sum = 0;     for (int i = 0; i < n; i++) sum += (v[i].first + v[i].second) & 1;     a.clear();     del = n;     if (sum & 1) {       sum += (v[n].first + v[n].second) & 1;       for (int i = n - 1; i >= 0; i--)         if (!((sum - ((v[i].first + v[i].second) & 1)) & 1)) {           del = i;           break;         }     }     for (int i = 0; i <= n; i++)       if (del != i) a.push_back(v[i]);     sx = sy = 0;     for (int i = n - 1; i >= 0; i--) {       x = a[i].first, y = a[i].second;       for (int s = 0; s < 8; s++) {         Nx = x, Ny = y;         if (s & 1) swap(Nx, Ny);         if (s & 2) Nx *= -1;         if (s & 4) Ny *= -1;         if (((sx + a[i].first) * (sx + a[i].first)) +                 ((sy + a[i].second) * (sy + a[i].second)) >             ((sx + Nx) * (sx + Nx)) + ((sy + Ny) * (sy + Ny)))           a[i] = make_pair(Nx, Ny);       }       sx += a[i].first, sy += a[i].second;     }     for (int i = 0; i < n; i++)       ans.push_back(make_pair(atan2(a[i].second, a[i].first), i));     sort(ans.begin(), ans.end());     cout <<  YES  << endl;     sx = 0, sy = 0;     for (int i = 0; i < n; i++) {       cout << sx <<     << sy << endl;       int id = ans[i].second;       sx += a[id].first, sy += a[id].second;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ax, ay, bx, by, cx, cy;   void check(long long axx, long long ayy) {     if (cx == 0 && cy == 0) {       if (axx == bx && ayy == by) {         cout <<  YES ;         exit(0);       } else         return;     }     if ((cx * (by - ayy) - cy * (bx - axx)) % (cx * cx + cy * cy) != 0 ||         (cx * (bx - axx) + cy * (by - ayy)) % (cx * cx + cy * cy) != 0)       return;     cout <<  YES ;     exit(0);   }   int main() {     cin >> ax >> ay >> bx >> by >> cx >> cy;     check(ax, ay);     check(ay, -ax);     check(-ax, -ay);     check(-ay, ax);     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int A[2];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     long long ans = 0;     cin >> n;     while (cin >> n) {       ++A[n];       if (!n) ans += A[1];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1};   int dy[9] = {0, 1, 0, -1, 1, -1, 1, -1};   struct edge {     int st, ed;     char col;     edge() {       this->st = 0;       this->ed = 0;       this->col = 0;     }     edge(int st, int ed, char col) {       this->st = st;       this->ed = ed;       this->col = col;     }   };   long long n, m;   long long a[2000001], b[2000001];   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     for (int test_case = 0; test_case < t; ++test_case) {       cin >> n >> m;       string input;       cin >> input;       string s2 =   ;       for (int i = 0; i < n; ++i) {         a[i] = 1000000000;       }       for (int i = 0; i < n; ++i) {         if (a[i % m] == 1000000000) a[i % m] = (long long)input[i] -  0 ;         s2 += input[i % m];       }       bool flg = 0;       if (s2 < input) flg = 1;       if (flg) {         int i;         for (i = 0; i < n; ++i) {           if (a[i] == 1000000000) break;         }         i--;         while (a[i] == 9) {           a[i] = 0;           i--;         }         a[i]++;       }       cout << n <<   n ;       for (int i = 0; i < n; ++i) {         cout << a[i % m];       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }   }   int fr[100005], to[100005 << 1], ne[100005 << 1], x[100005];   int a[100005], b[100005], l, r;   int n, m;   int flag;   int c, d, e;   inline void dfs(int w) {     for (int u = fr[w]; u; u = ne[u])       if (!x[to[u]]) {         x[to[u]] = 3 - x[w];         dfs(to[u]);       } else if (x[w] == x[to[u]])         flag = 1;   }   int main() {     read(n);     read(m);     for (int i = 1; i <= m; ++i) {       read(c);       read(d);       to[++e] = d;       ne[e] = fr[c];       fr[c] = e;       to[++e] = c;       ne[e] = fr[d];       fr[d] = e;     }     flag = 0;     for (int i = 1; i <= n; ++i)       if (!x[i]) {         x[i] = 1;         dfs(i);       }     if (flag)       printf( -1 n );     else {       for (int i = 1; i <= n; ++i)         if (x[i] == 1)           a[++l] = i;         else           b[++r] = i;       printf( %d n , l);       for (int i = 1; i <= l; ++i) printf( %d%c , a[i], i < l ?     :   n );       printf( %d n , r);       for (int i = 1; i <= r; ++i) printf( %d%c , b[i], i < r ?     :   n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long mod(long long n, long long m) {     long long ret = n % m;     if (ret < 0) ret += m;     return ret;   }   long long gcd(long long a, long long b) {     return (b == 0LL ? a : gcd(b, a % b));   }   long long exp(long long a, long long b, long long m) {     if (b == 0LL) return 1LL;     if (b == 1LL) return mod(a, m);     long long k = mod(exp(a, b / 2, m), m);     if (b & 1LL) {       return mod(a * mod(k * k, m), m);     } else       return mod(k * k, m);   }   void print(int i) {     for (int j = 0; j < 3; j++) {       cout << !!(i & (1 << j));     }     cout <<  - ;   }   int v[5][5];   int OK[10][10];   int n, m;   bool ok(int a, int b) {     if (OK[a][b] != -1) return OK[a][b];     for (int i = 0; i < n; i++) {       for (int j = 0; j < 2; j++) {         int c = (j == 0 ? a : b);         if ((c & (1 << i))) {           v[i][j] = 1;         } else           v[i][j] = 0;       }     }     for (int i = 0; i < n - 1; i++) {       int tot = v[i][0] + v[i][1] + v[i + 1][0] + v[i + 1][1];       if (tot % 2 == 0) return OK[a][b] = 0;     }     return OK[a][b] = 1;   }   const int N = 1e6 + 10;   vector<vector<char> > mat;   int C[N][(1 << 3)];   int cost(int id, int msk) {     if (C[id][msk] != -1) return C[id][msk];     int c = 0;     for (int j = 0; j < n; j++) {       int sla = (msk & (1 << j)) > 0;       if ((sla) != (mat[j][id] -  0 )) c++;     }     return C[id][msk] = c;   }   const int inf = 1e8;   int dp[N][(1 << 3)];   int solve(int j, int msk) {     if (j == m) return 0;     int& x = dp[j][msk];     if (x != -1) return x;     x = inf;     for (int m = 0; m < (1 << n); m++) {       if (ok(m, msk)) x = min(x, solve(j + 1, m) + cost(j, m));     }     return x;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     memset(C, -1, sizeof(C));     memset(OK, -1, sizeof(OK));     memset(dp, -1, sizeof(dp));     cin >> n >> m;     mat.resize(n, vector<char>(m));     for (int i = 0; i < (n); ++i)       for (int j = 0; j < (m); ++j) cin >> mat[i][j];     if (n == 1) {       cout << 0 <<   n ;     } else if (n <= 3) {       int res = 1e9;       for (int i = 0; i < (1 << n); i++) {         res = min(res, solve(1, i) + cost(0, i));       }       cout << res <<   n ;     } else {       cout << -1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, ans, ini, fin, med, idx;   bool t[40];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (long long i = 0; i < m; i++) {       cout <<  1 n ;       cout.flush();       cin >> ans;       if (!ans) return 0;       if (ans == 1) t[i] = true;     }     ini = 1;     fin = n;     while (ini != fin) {       med = (ini + fin) / 2;       cout << med <<   n ;       cout.flush();       cin >> ans;       if (!ans) return 0;       if (t[idx]) {         if (ans == 1) {           ini = med + 1;         } else {           fin = med - 1;         }       } else {         if (ans == 1) {           fin = med - 1;         } else {           ini = med + 1;         }       }       idx++;       idx %= m;     }     cout << ini <<   n ;     cout.flush();     cin >> ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5001;   long long n, m, a[N + 1], b[N + 1], type[N], l[N], r[N], x[N];   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; i++) a[i] = 1e9;     for (int j = 1; j <= m; j++) {       cin >> type[j] >> l[j] >> r[j] >> x[j];       if (type[j] == 1)         for (int i = l[j]; i <= r[j]; i++) b[i] += x[j];       else {         bool ok = false;         for (int i = l[j]; i <= r[j]; i++) {           if (a[i] >= x[j] - b[i]) ok = true;           a[i] = min(a[i], x[j] - b[i]);         }         if (!ok) {           cout <<  NO ;           return 0;         }       }     }     for (int i = 1; i <= n; i++) b[i] = a[i];     bool ok = true;     for (int i = 1; i <= m; i++) {       if (type[i] == 1)         for (int j = l[i]; j <= r[i]; j++) a[j] += x[i];       else {         long long mx = a[l[i]];         for (int j = l[i] + 1; j <= r[i]; j++) mx = max(mx, a[j]);         if (mx != x[i]) {           ok = false;           break;         }       }     }     if (!ok)       cout <<  NO ;     else {       cout <<  YES  << endl;       for (int i = 1; i <= n; i++) cout << b[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mat[105][105];   int n, m, res;   void solve(int p) {     if (p % 2) return;     for (int i = 0, j = p - 1; i < p / 2; i++, j--)       for (int k = 0; k < m; k++)         if (mat[i][k] != mat[j][k]) return;     res = res / 2;     solve(p / 2);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &mat[i][j]);     res = n;     solve(n);     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ans, m;   queue<int> q;   int main() {     cin >> n;     int *a = new int[n + 1];     int *j = new int[n + 1];     memset(a, 0, sizeof(int) * (n + 1));     for (int i = 1; i <= n; i++) {       cin >> j[i];       a[j[i]]++;       if (a[j[i]] > 1) ans++;     }     cout << ans << endl;     for (int i = 1; i <= n; i++) {       if (a[i] == 0) q.push(i);     }     for (int i = 1; i <= n; i++) {       if (q.empty()) {         cout << j[i] <<    ;       } else {         if (a[j[i]] > 1) {           if (j[i] < q.front()) {             cout << j[i] <<    ;             a[j[i]] = 0;           } else {             a[j[i]]--;             m = q.front();             cout << m <<    ;             q.pop();           }         } else if (a[j[i]] == 1) {           cout << j[i] <<    ;         } else {           m = q.front();           cout << m <<    ;           q.pop();         }       }     }     delete[] a;     delete[] j;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300000 + 5;   int a[maxn];   int main() {     int n;     cin >> n;     int mn = 0x3f3f3f3f;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       mn = min(a[i], mn);     }     int ans = 0x3f3f3f3f;     for (int i = 1; i <= n; i++) {       if (i != 1) ans = min(min(a[i], a[1]) / abs(1 - i), ans);       if (i != n) ans = min(min(a[i], a[n]) / abs(n - i), ans);     }     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   bool check(long long x, long long y, long long p, long long q, long long t) {     return p * t >= x && q * t - p * t >= y - x;   }   int main() {     long long t;     cin >> t;     while (t--) {       long long x, y, p, q, m;       cin >> x >> y >> p >> q;       long long l = -1;       long long r = (long long)1e9;       if (!check(x, y, p, q, r)) {         printf( -1 n );         continue;       }       while (r - l > 1) {         m = l + (r - l) / 2;         if (check(x, y, p, q, m))           r = m;         else           l = m;       }       printf( %lld n , r * q - y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   const int INF = 0x3f3f3f3f;   const int iinf = 1 << 30;   const long long linf = 2e18;   const int mod = 1000000007;   const double eps = 1e-7;   void douout(double x) { printf( %lf n , x + 0.0000000001); }   template <class T>   void print(T a) {     cout << a << endl;     exit(0);   }   template <class T>   void chmin(T &a, T b) {     if (a > b) a = b;   }   template <class T>   void chmax(T &a, T b) {     if (a < b) a = b;   }   void add(int &a, int b) { a = a + b < mod ? a + b : a + b - mod; }   void sub(int &a, int b) { a = (a - b + mod) % mod; }   void mul(int &a, int b) { a = (long long)a * b % mod; }   int addv(int a, int b) { return (a += b) >= mod ? a -= mod : a; }   int subv(int a, int b) { return (a -= b) < 0 ? a += mod : a; }   int mulv(int a, int b) { return (long long)a * b % mod; }   int read() {     int f = 1, x = 0;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int pw(int a, int b) {     int s = 1;     for (; b; b >>= 1, a = (long long)a * a % mod)       if (b & 1) s = (long long)s * a % mod;     return s;   }   int n, ans;   int val[N] = {1}, ans1[N], ans2[N], ans3[N], p[N];   void dfs(int x) {     if (val[x] == n && x == ans) {       printf( %d n , ans);       for (int i = (0); i <= (ans - 1); i++)         if (~ans2[i])           printf( lea e%cx, [e%cx + %d*e%cx] n , ans1[i] +  a , ans2[i] +  a ,                  p[i], ans3[i] +  a );         else           printf( lea e%cx, [%d*e%cx] n , ans1[i] +  a , p[i], ans3[i] +  a );       exit(0);     }     if (x == ans) return;     for (int i = (0); i <= (x); i++)       for (int j = (-1); j <= (x); j++)         for (int k = 1; k < 9; k <<= 1) {           if (j + 1)             val[x + 1] = val[i] * k + val[j];           else             val[x + 1] = val[i] * k;           ans1[x] = x + 1;           ans2[x] = j;           ans3[x] = i;           p[x] = k;           dfs(x + 1);         }   }   signed main() {     scanf( %d , &n);     for (ans = 0; ans <= n; ans++) dfs(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000;   const double eps = 1e-9;   long long INF = 1e9;   const int OO = 0x3f3f3f3f;   int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};   int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};   bool comp(pair<int, int> a, pair<int, int> b) {     if (a.first < b.first)       return true;     else if (a.first > b.first)       return false;     else       return a.first < b.first;   }   void read(string str, int node) {     stringstream ss;     int number;     ss << str;     while (ss >> number) cout << number << endl;   }   long long fp(long long b, long long p) {     if (p == 0) return 1;     if (p % 2 == 0) return fp((b * b) % INF, p / 2);     return (fp(b, p - 1) * b) % INF;   }   unsigned long long read_binary(string s) {     unsigned long long x = 0, tmp = 1;     for (int i = s.size() - 1; i >= 0; i--) {       x = (x + tmp * (s[i] -  0 )) % INF;       tmp = (tmp * 2) % INF;     }     return x;   }   long long com(long long x, long long y) {     long long sum = 1;     for (int i = 1; i <= y; i++) {       sum *= x;       x--;       sum /= i;     }     return sum;   }   long long gcd(long long n1, long long n2) {     if (n2 != 0)       return gcd(n2, n1 % n2);     else       return n1;   }   int setBit(int num, int idx, int val = 1) {     return (val) ? (num | (1 << idx)) : (num & ~(1 << idx));   }   int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }   int cntBit(int num) {     int ret = 0;     while (num) {       if (num % 2) ret++;       num /= 2;     }     return ret;   }   bool sum[1500];   void sieve() {     sum[0] = sum[1] = 1;     for (int i = 2; i * i < 1002; i++) {       if (!sum[i]) {         for (int j = 2 * i; j < 1002; j += i) {           sum[j] = 1;         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     long long n;     cin >> n;     string s = to_string(n);     long long mi = INF;     for (int i = 0; i < (1 << s.size()); ++i) {       int cnt = 0;       string k;       for (int j = 0; j < s.size(); j++) {         if (i & (1 << j)) {           k += s[j];           cnt++;         }       }       if (k[0] ==  0 ) continue;       long long val;       istringstream ss(k);       ss >> val;       double d = sqrt(val);       int ii = sqrt(val);       if (d == ii) {         mi = min(mi, (long long)s.size() - cnt);       }     }     if (mi == INF)       cout << -1 << endl;     else       cout << mi << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long xorsum(long long n, long long k) {     if (k == 1) return n;     int msb = (int)log2((double)n);     if ((1ll << msb) > n) msb--;     return (2ll << msb) - 1;   }   int main() {     long long n, k;     cin >> n >> k;     cout << xorsum(n, k) << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   void manupulate(string &str) {     for (long long int i = 0; i < str.size(); ++i) str[i] -= 48;   }   bool isprime(long long int n) {     if (n <= 1) return false;     for (long long int i = 2; i * i <= n; ++i)       if (n % i == 0) return false;     return true;   }   long long int expo(long long int a, long long int n) {     if (n == 0) return 1;     if (n == 1) return a;     long long int tmp = expo(a, n / 2);     tmp = (tmp * tmp) % (long)(1e9 + 7);     if (n & 1) tmp = (tmp * a) % (long)(1e9 + 7);     return tmp;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) {       string str;       cin >> str;       set<array<long long int, 4> > s;       long long int ans = 0;       long long int x = 0, y = 0;       for (long long int i = 0; i < str.size(); ++i) {         long long int x1 = x, y1 = y;         if (str[i] ==  N )           ++y1;         else if (str[i] ==  E )           ++x1;         else if (str[i] ==  S )           --y1;         else           --x1;         array<long long int, 4> tmp = {x, y, x1, y1};         array<long long int, 4> tmp2 = {x1, y1, x, y};         if (s.find(tmp) != s.end() || s.find(tmp2) != s.end())           ++ans;         else {           s.insert(tmp);           s.insert(tmp2);           ans += 5;         }         x = x1, y = y1;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int x = 0, f = 1;     register char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = 0;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + (ch ^  0 );       ch = getchar();     }     return f ? x : -x;   }   const int mod = 998244353;   int n, l[55], r[55], inv[105], b[105], t, f[55][105], s[55][105];   inline void inc(int& x, int y) { x = x + y < mod ? x + y : x + y - mod; }   inline int power(int b, int n) {     int ans = 1;     for (; n; n >>= 1, b = 1ll * b * b % mod)       if (n & 1) ans = 1ll * ans * b % mod;     return ans;   }   int main() {     n = read();     for (int i = (1), _ed = (n); i <= _ed; ++i)       l[i] = read(), r[i] = read(), b[++t] = l[i], b[++t] = ++r[i];     inv[0] = inv[1] = 1;     for (int i = (2), _ed = (n + n); i <= _ed; ++i)       inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;     sort(b + 1, b + t + 1), t = unique(b + 1, b + t + 1) - b - 1;     for (int i = (1), _ed = (n); i <= _ed; ++i)       l[i] = lower_bound(b + 1, b + t + 1, l[i]) - b,       r[i] = lower_bound(b + 1, b + t + 1, r[i]) - b;     f[0][t] = s[0][t] = 1;     for (int i = (1), _ed = (n + 1); i <= _ed; ++i)       for (int j = (t - 1), _ed = (1); j >= _ed; --j) {         s[i - 1][j] = (s[i - 1][j + 1] + f[i - 1][j]) % mod;         if (l[i] > j || r[i] <= j) continue;         int L = b[j + 1] - b[j], C = 1, cnt = 0;         for (int k = (i - 1), _ed = (0); k >= _ed; --k) {           ++cnt;           C = 1ll * C * (L + cnt - 1) % mod * inv[cnt] % mod;           inc(f[i][j], 1ll * s[k][j + 1] * C % mod);           if (l[k] > j || r[k] <= j) break;         }       }     int ans = s[n][1];     for (int i = (1), _ed = (n); i <= _ed; ++i)       ans = 1ll * ans * power(b[r[i]] - b[l[i]], mod - 2) % mod;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   enum { N = 201 };   int n;   int where[N][N];   int cnt[N] = {};   int what[N];   int set[N][N];   int sn[N] = {};   int eq(int i, int j) {     int k;     for (k = 0; k < n - 1; ++k) {       if (where[i][k] != where[j][k]) return 0;     }     return 1;   }   int main(void) {     scanf( %d , &n);     int i, j, k, x;     if (n == 2) {       scanf( %d %d , &k, &x);       printf( 1 %d n%d  , x, k - 1);       for (i = 0; i < k - 1; ++i) {         scanf( %d , &x);         printf( %d  , x);       }       printf(  n );       return 0;     }     int nn = n * (n - 1) / 2;     for (i = 0; i < nn; ++i) {       scanf( %d , &k);       for (j = 0; j < k; ++j) {         scanf( %d , &x);         where[x][cnt[x]] = i;         ++cnt[x];       }     }     for (i = 1; i < N; ++i) {       if (cnt[i] == 0) continue;       what[i] = i;       for (j = 1; j < i; ++j) {         if (cnt[j] == 0) continue;         if (eq(j, i)) {           what[i] = j;           break;         }       }       set[what[i]][sn[what[i]]] = i;       ++sn[what[i]];     }     for (i = 1; i < N; ++i) {       if (sn[i] == 0) continue;       printf( %d  , sn[i]);       for (j = 0; j < sn[i]; ++j) {         printf( %d  , set[i][j]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 42;   int n, m;   char s[N];   long long dp[N][N][2], nex[N];   void kmp_init() {     int j = 0;     nex[1] = 0;     nex[0] = -1;     for (int i = 1; i < n; i++) {       while (j >= 0 && s[i + 1] != s[j + 1]) j = nex[j];       if (j == -1 || s[i + 1] == s[j + 1]) j++;       nex[i + 1] = j;     }   }   int getNex(int pos, int val) {     if (pos == 0) return val == s[1] -  0  ? 1 : 0;     if (s[pos + 1] ==  0  + val) return pos + 1;     return getNex(nex[pos], val);   }   long long dfs(int pre, int now, int matched_len, int isok) {     if (now == m + 1) {       return matched_len == pre && isok;     }     if (dp[now][matched_len][isok] != -1) return dp[now][matched_len][isok];     long long ans = 0;     ans += dfs(pre, now + 1, getNex(matched_len, 0),                isok | (getNex(matched_len, 0) == n));     ans += dfs(pre, now + 1, getNex(matched_len, 1),                isok | (getNex(matched_len, 1) == n));     return dp[now][matched_len][isok] = ans;   }   int main() {     scanf( %d %s , &m, s + 1);     n = strlen(s + 1);     kmp_init();     long long ans = 0;     for (int i = 0; i <= n; i++) {       memset(dp, -1, sizeof(dp));       ans += dfs(i, 1, i, 0);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;   const int INF = INT_MAX;   const long long LINF = LLONG_MAX;   const int MOD = 1000000000 + 7;   const double EPS = 1e-9;   const double PI = acos(-1);   const int di[]{0, -1, 0, 1, -1, -1, 1, 1};   const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     long long n, m;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     cin >> m;     vector<long long> q(m);     for (int i = 0; i < m; ++i) {       cin >> q[i];     }     vector<long long> sum(n + 1, 0);     for (int i = 0; i < n; ++i) {       sum[i + 1] = sum[i] + a[i];     }     sort((a).begin(), (a).end(), greater<long long>());     for (int i = 0; i < m; ++i) {       long long ans = sum[n] - a[q[i] - 1];       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e18 + 7;   const long long N = 2e6 + 5;   int main() {     long long i, j, k, l = 0;     long long n, m, t;     cin >> n;     for (long long i = 0; i < n; i++) cin >> k, l += k;     if (l % n)       cout << n - 1 << endl;     else       cout << n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int num[100005];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &num[i]);     }     sort(num, num + n);     if (n < k) {       printf( %d n , num[n - 1]);       return 0;     } else {       vector<int> ans;       for (int i = 0; i < n - k; i++) {         ans.push_back(num[i] + num[2 * n - 2 * k - 1 - i]);       }       for (int i = 2 * n - 2 * k; i < n; i++) ans.push_back(num[i]);       sort(ans.begin(), ans.end());       printf( %d n , ans[ans.size() - 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int m5 = 100042;   int main(void) {     string s, ans =   ;     getline(cin, s);     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  . ) {         if (i == 0) {           ans +=  ... ;         } else {           ans +=   ... ;         }         i += 2;       } else if (s[i] ==  , ) {         ans +=  ,  ;       } else {         ans += s[i];       }     }     while (true) {       int pos = ans.find(    );       if (pos == string::npos) {         break;       }       ans.erase(ans.begin() + pos, ans.begin() + pos + 1);     }     if (ans[ans.size() - 1] ==    ) {       ans.erase(ans.begin() + ans.size() - 1);     }     string ans2 =   ;     for (int i = 0; i < ans.size(); i++) {       if (ans[i] ==     && isdigit(ans[i - 1]) && ans[i + 1] ==  , ) {         continue;       } else if (ans[i] ==     && isdigit(ans[i + 1]) && ans[i - 1] ==  . ) {         continue;       } else if (ans[i] ==     && ans[i + 1] ==  ,  && ans[i - 1] ==  . ) {         continue;       } else {         ans2 += ans[i];       }     }     cout << ans2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int minn(int, int, int);   int main() {     int x1, x2, x3;     cin >> x1 >> x2 >> x3;     int d1 = abs(x2 - x1) + abs(x3 - x1);     int d2 = abs(x1 - x2) + abs(x3 - x2);     int d3 = abs(x3 - x1) + abs(x3 - x2);     cout << minn(d1, d2, d3) << endl;     return 0;   }   int minn(int a, int b, int c) {     int m = a;     if (b < m) m = b;     if (c < m) m = c;     return m;   }


#include <bits/stdc++.h>   using namespace std;   long long sqr(long long x) { return x * x; }   int mysqrt(long long x) {     int l = 0, r = 1e9 + 1;     while (r - l > 1) {       int m = (l + r) / 2;       if (m * (long long)m <= x)         l = m;       else         r = m;     }     return l;   }   mt19937 rnd(1227);   mt19937_64 rndll(12365);   long long AR = 19, BR = 13, CR = 23, XR = 228, YR = 322, MODR = 1e9 + 993;   long long myrand() {     long long ZR = (XR * AR + YR * BR + CR) % MODR;     XR = YR;     YR = ZR;     return ZR;   }   int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }   int gcdex(int a, int b, int &x, int &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     int x1, y1;     int ret = gcdex(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return ret;   }   const int Mod = 1e9 + 7;   int Bpow(int x, int y) {     int ret = 1;     int w = x;     while (y) {       if (y & 1) ret = (ret * (long long)w) % Mod;       w = (w * (long long)w) % Mod;       y >>= 1;     }     return ret;   }   int Bdiv(int x) {     int a, b;     gcdex(x, Mod, a, b);     if (a < 0) a += Mod;     return a;   }   int Bdiv(int x, int y) { return (x * (long long)Bpow(y, Mod - 2)) % Mod; }   void setmin(int &x, int y) { x = min(x, y); }   void setmax(int &x, int y) { x = max(x, y); }   void setmin(long long &x, long long y) { x = min(x, y); }   void setmax(long long &x, long long y) { x = max(x, y); }   const long long llinf = 2e18 + 100;   const double eps = 1e-9;   const int maxn = 1e5 + 100, maxw = 1e6 + 100, inf = 2e9 + 100, sq = 300,             mod = 1e9 + 7, LG = 17;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int w = 1;     for (int i = 2; i <= n; i++)       if (i + (n + i - 1) / i < w + (n + w - 1) / w) w = i;     for (int i = n; i > 0; i -= w) {       for (int j = max(1, i - w + 1); j <= i; j++) cout << j <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     scanf( %d%d , &m, &n);     int t[m][n];     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) scanf( %d , &t[i][j]);     }     int latest[m];     fill(latest, latest + m, 0);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         latest[j] += t[j][i];         if (j != m - 1) latest[j + 1] = max(latest[j], latest[j + 1]);       }     }     for (int i = 0; i < m; i++) {       printf( %d , latest[i]);       if (i != m - 1) putchar(   );     }     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     map<int, vector<int>> mp;     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       mp[a].push_back(i);     }     vector<pair<int, int>> ans;     int cnt = 0;     for (auto ele : mp) {       int a = ele.first;       vector<int> pos = ele.second;       if (pos.size() == 1) {         ans.push_back({a, 0});       } else {         int diff = pos[1] - pos[0];         bool can = true;         for (int i = 2; i <= pos.size() - 1; i++) {           if (pos[i] - pos[i - 1] != diff) {             can = false;             break;           }         }         if (can) {           ans.push_back({a, diff});         }       }     }     cout << ans.size() << endl;     for (auto& ele : ans) {       cout << ele.first <<     << ele.second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, w, nm;   char ls[1000][10][10];   int _d[1000][1000];   int used[1000], res[1000], sz = 0, c = 0;   int main() {     cin >> n >> m >> k >> w;     nm = n * m;     c = nm;     for (int i = 0; i < k; i++)       for (int y = 0; y < n; y++)         for (int x = 0; x < m; x++) cin >> ls[i][y][x];     for (int a = 0; a < k; a++)       for (int b = 0; b < k; b++) {         int res = 0;         for (int i = 0; i < n; i++)           for (int j = 0; j < m; j++)             if (ls[a][i][j] != ls[b][i][j]) res++;         _d[a][b] = res;       }     res[0] = 0;     used[0] = 1;     sz = 1;     stringstream ss;     ss <<  1 0  << endl;     while (sz < k) {       int mini = -1, minval = -1, minj = -1, type = 0;       for (int j = 0; j < sz; j++) {         for (int i = 0; i < k; i++) {           if (used[i]) continue;           int a = _d[res[j]][i] * w, t = min(a, nm);           if (t < minval || mini < 0) {             mini = i;             minval = t;             minj = -1;             if (a < nm) {               minj = res[j];               type = 1;             }           }         }       }       res[sz++] = mini;       used[mini] = 1;       ss << mini + 1 <<     << minj + 1 << endl;       c += minval;     }     cout << c << endl << ss.str();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 15e4 + 5;   int n, b[N];   long long a[N];   int prev(int x) {     int y = x - 1;     if (y == 0) y = n;     return y;   }   int nxt(int x) { return x % n + 1; }   int main() {     scanf( %d , &n);     bool f = true;     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     for (int i = 2; i <= n; i++)       if (b[i] != b[i - 1]) f = false;     if (f) {       if (b[1] != 0) return !printf( NO );       puts( YES );       for (int i = 1; i <= n; i++) printf( %d  , 3122002);       return 0;     }     int pos;     for (int i = 1; i <= n; i++) {       if (b[i] > b[prev(i)]) {         pos = i;         break;       }     }     a[pos] = b[pos];     for (int i = pos - 1; i >= 1; i--) {       int k = max(1LL, (b[prev(i)] - b[i] + a[nxt(i)]) / a[nxt(i)]);       a[i] = 1LL * a[nxt(i)] * k + b[i];     }     for (int i = n; i > pos; i--) {       int k = max(1LL, (b[prev(i)] - b[i] + a[nxt(i)]) / a[nxt(i)]);       a[i] = 1LL * a[nxt(i)] * k + b[i];     }     puts( YES );     for (int i = 1; i <= n; i++) printf( %lld  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string str;   int main() {     long long int i, j, t, n;     cin >> t;     while (t--) {       cin >> str;       int ar[4];       for (i = 0; i < 4; i++) {         ar[i] = 0;       }       int l = str.length();       int count = 0;       int mn = l + 1;       for (i = 0, j = 0; i <= j && j < l; j++) {         ar[str[j] -  1 ]++;         if (ar[str[j] -  1 ] == 1) {           count++;         }         if (count == 3) {           if (j - i + 1 < mn) {             mn = j - i + 1;           }           while (i <= j && count == 3) {             ar[str[i] -  1 ]--;             if (ar[str[i] -  1 ] == 0) {               count--;             }             i++;             if (count == 3 && j - i + 1 < mn) {               mn = j - i + 1;             }           }         }       }       if (mn > l) {         cout << 0 <<   n ;       } else {         cout << mn <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, c[6][223456], child[223456];   double ans[223456], res = 0.0;   vector<pair<int, double> > ke[223456];   pair<pair<int, int>, double> way[223456];   int dad[223456];   void dfs1(int u, int par) {     child[u] = 1;     dad[u] = par;     for (int i = 0; i < ke[u].size(); i++) {       int v = ke[u][i].first;       if (v == par) continue;       dfs1(v, u);       child[u] += child[v];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     int u, v;     double w;     for (int i = 1; i < n; i++) {       cin >> u >> v >> w;       ke[u].push_back(make_pair(v, w));       ke[v].push_back(make_pair(u, w));       way[i] = make_pair(make_pair(u, v), w);     }     dfs1(1, 0);     res = 0;     for (int i = 1; i < n; i++) {       int u1 = way[i].first.first;       int u2 = way[i].first.second;       if (dad[u2] == u1) swap(u1, u2);       double we = way[i].second;       res += we * (child[u1] * (n - child[u1]));     }     int q;     cin >> q;     while (q--) {       cin >> u >> w;       int u1 = way[u].first.first;       int u2 = way[u].first.second;       if (dad[u2] == u1) swap(u1, u2);       double we = way[u].second;       res -= (we - w) * double(child[u1] * (n - child[u1]));       way[u].second = w;       cout << fixed << setprecision(8) << res / double(n * (n - 1) / 6.0) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   void query(int x) {     cout <<  ? ;     for (int i = 1; i <= k + 1; ++i)       if (i != x) cout <<     << i;     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     int x, y, px, py;     query(k + 1);     cin >> px >> x;     query(px);     cin >> py >> y;     int m = 1;     if (y > x) {       for (int i = 1; i <= k; ++i) {         if (i != px) {           query(i);           int pa, a;           cin >> pa >> a;           if (a > x) ++m;         }       }     } else {       for (int i = 1; i <= k; ++i) {         if (i != px) {           query(i);           int pa, a;           cin >> pa >> a;           if (a > y) ++m;         }       }     }     cout <<  !   << m << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265358979323846;   void solve() {     long long n, m, a, b, k, x, y, queries;     string s;     cin >> n >> s;     s =  G  + s;     long long i = 1;     while (i <= n) {       if (s[i] ==  8 ) break;       i++;     }     if (i + 10 <= n)       cout <<  YES ;     else       cout <<  NO ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       solve();       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   inline long long read() {     char c;     long long x;     for (c = getchar(); !isdigit(c); c = getchar())       ;     for (x = 0; isdigit(c); c = getchar()) {       x = x * 10 + c -  0 ;     }     return x;   }   const int N = 2e5 + 5;   int n, q, d[N], f[N];   long long a[N], b[N], c[N], s[N];   std::multiset<long long> set[N], all;   void modify(int u, int sgn, int flag) {     int v = f[u];     if (!set[v].empty()) {       if (flag || sgn < 0) {         all.erase(all.find(*set[v].begin() + c[v]));         all.erase(all.find(*set[v].rbegin() + c[v]));       }     }     if (sgn == 1) {       set[v].insert(b[u] + s[u]);     }     if (sgn == -1) {       set[v].erase(set[v].find(b[u] + s[u]));     }     if (!set[v].empty()) {       if (flag || sgn > 0) {         assert(!set[v].empty());         all.insert(*set[v].begin() + c[v]);         all.insert(*set[v].rbegin() + c[v]);       }     }   }   int main() {     n = read();     q = read();     for (int u = 1; u <= n; u++) {       a[u] = read();       d[u] = 1;     }     for (int u = 1; u <= n; u++) {       f[u] = read();       d[f[u]]++;     }     for (int u = 1; u <= n; u++) {       c[u] = a[u] / (d[u] + 1);       b[u] = a[u] - c[u] * d[u];       s[f[u]] += c[u];     }     for (int u = 1; u <= n; u++) {       modify(u, 1, 1);     }     for (int i = 0; i < q; i++) {       int opt = read();       if (opt == 1) {         int u = read(), v = read();         modify(u, -1, 0);         modify(f[u], -1, 0);         modify(f[f[u]], -1, 0);         d[f[u]]--;         s[f[u]] -= c[u];         s[f[f[u]]] -= c[f[u]];         c[f[u]] = a[f[u]] / (d[f[u]] + 1);         b[f[u]] = a[f[u]] - c[f[u]] * d[f[u]];         s[f[f[u]]] += c[f[u]];         modify(u, 2, 0);         modify(f[u], 1, 0);         modify(f[f[u]], 1, 0);         f[u] = v;         modify(u, -2, 0);         modify(f[u], -1, 0);         modify(f[f[u]], -1, 0);         d[f[u]]++;         s[f[u]] += c[u];         s[f[f[u]]] -= c[f[u]];         c[f[u]] = a[f[u]] / (d[f[u]] + 1);         b[f[u]] = a[f[u]] - c[f[u]] * d[f[u]];         s[f[f[u]]] += c[f[u]];         modify(u, 1, 0);         modify(f[u], 1, 0);         modify(f[f[u]], 1, 0);       } else if (opt == 2) {         int u = read();         printf( %lld n , b[u] + c[f[u]] + s[u]);       } else {         printf( %lld %lld n , *all.begin(), *all.rbegin());       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000000 )   using namespace std;   int n, l[30], m[30], w[30];   int tw[30], P1, P2;   map<pair<long long, long long>, pair<long long, long long> > mp;   long long best = -(1ll << 58), msk1, msk2;   void rec(int p, int msk, long long L, long long M, long long W) {     if (p == P1) {       pair<long long, long long> tmp = make_pair(L - M, L - W);       if (mp.find(tmp) == mp.end())         mp[tmp] = make_pair(L, msk);       else if (mp[tmp].first < L) {         mp[tmp] = make_pair(L, msk);       }       return;     }     rec(p + 1, msk * 3, L, M + m[p], W + w[p]);     rec(p + 1, msk * 3 + 1, L + l[p], M, W + w[p]);     rec(p + 1, msk * 3 + 2, L + l[p], M + m[p], W);   }   void rec2(int p, int msk, long long L, long long M, long long W) {     if (p == n) {       pair<long long, long long> tmp = make_pair(-(L - M), -(L - W));       if (mp.find(tmp) == mp.end()) return;       pair<long long, long long> tmp2 = mp[tmp];       long long sum = L + tmp2.first;       if (sum < best) return;       best = sum;       msk1 = tmp2.second;       msk2 = msk;       return;     }     rec2(p + 1, msk * 3, L, M + m[p], W + w[p]);     rec2(p + 1, msk * 3 + 1, L + l[p], M, W + w[p]);     rec2(p + 1, msk * 3 + 2, L + l[p], M + m[p], W);   }   void print(int x, int msk) {     if (x == 0) return;     print(x - 1, msk / 3);     if (msk % 3 == 0)       printf( MW n );     else if (msk % 3 == 1)       printf( LW n );     else       printf( LM n );   }   int main() {     for (int i = 0; i < 30; i++) tw[i] = 1 << i;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d %d , &l[i], &m[i], &w[i]);     }     P1 = n / 2, P2 = n - P1;     rec(0, 0, 0, 0, 0);     rec2(P1, 0, 0, 0, 0);     if (best == -(1ll << 58))       printf( Impossible n );     else {       print(P1, msk1);       print(P2, msk2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0)->sync_with_stdio(0);     long long n, r1, r2, r3, d;     cin >> n >> r1 >> r2 >> r3 >> d;     long long a[n];     for (int i = 0; i < n; i++) cin >> a[i];     long long adv[n + 1], ret[n + 1];     adv[0] = ret[n] = 0;     ret[n - 1] = min(         {a[n - 1] * r1 + r3, a[n - 1] * r1 + 2 * r1 + 2 * d, r2 + r1 + 2 * d});     for (int i = 1; i <= n; i++) {       adv[i] = adv[i - 1] + a[i - 1] * r1 + r3 + d;       if (i - 2 >= 0)         adv[i] = min(adv[i], adv[i - 2] + min(a[i - 2] * r1 + r1, r2) +                                  min(a[i - 1] * r1 + r1, r2) + 2 * r1 + 4 * d);     }     adv[n] -= d;     for (int i = n - 2; i >= 0; i--) {       ret[i] = ret[i + 1] + min(a[i] * r1 + 2 * r1, r2 + r1) + 2 * d;     }     long long sol = LLONG_MAX;     for (int i = 0; i <= n; i++) sol = min(sol, adv[i] + ret[i]);     cout << sol <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int t;     cin >> t;     for (int _ = 0; _ < (t); ++_) {       int n;       cin >> n;       if (n < 4) {         cout << -1 <<   n ;         continue;       }       deque<int> p{3, 1, 4};       vector<int> nums{2};       for (int i = 5; i <= n; ++i) {         nums.push_back(i);       }       for (int i = 0; i < (((int)(nums).size())); ++i) {         if (abs(p.front() - nums[i]) >= 2 && abs(p.front() - nums[i]) <= 4) {           p.push_front(nums[i]);         } else {           p.push_back(nums[i]);         }       }       for (int i = 0; i < (((int)(p).size())); ++i) {         if (i) {           cout <<    ;         }         cout << p[i];       }       cout <<   n ;     }   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int c = 102;   int kezd[c][c], veg[c][c], dp[c][c], n, m, sum;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       int db;       cin >> db;       for (int j = 1; j <= db; j++) {         int a, b;         cin >> a >> b;         for (int k = a; k <= b; k++) kezd[i][k] = a, veg[i][k] = b;       }     }     for (int j = 0; j < m; j++)       for (int i = 1; i + j <= m; i++) {         int maxi = 0;         for (int k = i; k <= i + j; k++) {           int cnt = 0;           for (int l = 1; l <= n; l++)             cnt += (i <= kezd[l][k] && veg[l][k] <= i + j);           maxi = max(maxi, cnt * cnt + dp[i][k - 1] + dp[k + 1][i + j]);         }         dp[i][i + j] = maxi;       }     cout << dp[1][m] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long t;     cin >> t;     while (t--) {       long long n, l, r;       cin >> n >> l >> r;       vector<long long> lol = {0};       for (long long i = n - 1; i >= 1; i--) {         lol.push_back(lol.back() + 2 * i);       }       for (long long x = l; x <= r; x++) {         if (x == n * (n - 1) + 1) {           cout << 1 <<    ;         } else {           long long block =               (long long)(lower_bound(lol.begin(), lol.end(), x) - lol.begin());           if (x % 2 == 1) {             cout << block <<    ;           } else {             long long h = x - lol[block - 1];             cout << h / 2 + block <<    ;           }         }       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t != 0) {       int n;       cin >> n;       long long m = (n - 1) / 2;       long long sum = m * (m + 1) * (2 * m + 1) / 6;       long long raspuns = 8 * sum;       cout << raspuns <<   n ;       t--;     }   }


#include <bits/stdc++.h>   using namespace std;   void ensure(bool b) {     if (!b) {       cout << 0 << endl;       exit(0);     }   }   void solve() {     int n;     cin >> n;     vector<vector<int>> g(n);     vector<int> e(2 * n - 2);     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       g[x].emplace_back(i << 1);       e[i << 1] = y;       g[y].emplace_back(i << 1 | 1);       e[i << 1 | 1] = x;     }     vector<int> dep(n), pa(n, -1);     function<void(int, int)> dfs = [&](int u, int p) {       for (int i : g[u])         if ((i ^ p) != 1) {           int v = e[i];           dep[v] = dep[u] + 1;           pa[v] = i;           dfs(v, i);         }     };     dfs(0, -1);     auto get_path = [&](int u, int v) {       vector<int> left, right;       while (u != v) {         if (dep[u] > dep[v]) {           left.push_back(pa[u] ^ 1);           u = e[pa[u] ^ 1];         } else {           right.push_back(pa[v]);           v = e[pa[v] ^ 1];         }       }       reverse(right.begin(), right.end());       for (auto& x : right) {         left.push_back(x);       }       return left;     };     int total_diff = 0;     const int HEAD = -2, TAIL = -3;     vector<int> S(n, -1), T(n, -1), pre(2 * n - 2, -1), nxt(2 * n - 2, -1);     auto limit_path = [&](int u, int v) {       auto p = get_path(u, v);       int len = p.size();       total_diff += len;       ensure(total_diff <= 2 * n - 2);       int i;       i = p[0];       ensure(S[u] == -1 && pre[i] == -1);       pre[i] = HEAD;       S[u] = i;       i = p.back() ^ 1;       ensure(T[v] == -1 && nxt[i] == -1);       nxt[i] = TAIL;       T[v] = i;       for (int _ = 0, j; _ + 1 < len; _++) {         i = p[_], j = p[_ + 1];         u = e[i];         i ^= 1;         ensure(nxt[i] == -1 && pre[j] == -1);         nxt[i] = j;         pre[j] = i;       }     };     for (int v = 0; v < n; v++) {       int u;       cin >> u;       u--;       if (u == -1) continue;       ensure(u != v);       limit_path(u, v);     }     long long res = 1;     const long long MOD = 1e9 + 7;     vector<bool> trk(2 * n - 2, false);     for (int u = 0; u < n; u++) {       int cnt = 0;       int vis = 0;       if (S[u] != -1) {         int i = S[u];         trk[i] = true;         vis++;         while (nxt[i] >= 0) {           i = nxt[i];           ensure(!trk[i]);           trk[i] = true;           vis++;         }         if (T[u] == i) {           ensure(vis == g[u].size());         }         cnt++;       }       for (int i : g[u])         if (pre[i] == -1) {           trk[i] = true;           vis++;           while (nxt[i] >= 0) {             i = nxt[i];             ensure(!trk[i]);             trk[i] = true;             vis++;           }           cnt++;         }       ensure(vis == g[u].size());       if (S[u] != -1) cnt--;       if (T[u] != -1) cnt--;       for (int i = 1; i <= cnt; i++) {         (res *= i) %= MOD;       }     }     cout << res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k;     cin >> n >> k;     long long a[n];     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     std::map<long long, long long> m;     for (int i = 0; i < n; ++i) {       m[a[i]]++;     }     long long l = 1, r = n / k, mid;     multiset<long long> ans, s;     multiset<long long>::iterator it;     map<long long, long long> m1;     while (l <= r) {       mid = l + (r - l) / 2;       long long c = 0;       m1 = m;       s.clear();       for (int i = 0; i < n; ++i) {         if (m1[a[i]] >= mid) {           s.insert(a[i]);           c++;           m1[a[i]] -= mid;         }         if (c == k) {           break;         }       }       if (c >= k) {         ans = s;         l = mid + 1;       } else {         r = mid - 1;       }     }     for (it = ans.begin(); it != ans.end(); it++) {       cout << *it <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast ,  unroll-loops ,  omit-frame-pointer ,  inline )   #pragma GCC option( arch=native ,  tune=native ,  no-zero-upper )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   using namespace std;   int n, q, fa[66666], aa[66666], kh[66666], a[66666], p[66666], fp[66666],       siz[66666], ck, pa[66666];   vector<int> edge[66666];   int dd[66666];   void dfs(int u) {     siz[u] = 1;     p[++ck] = u;     fp[u] = ck;     pa[ck] = fp[fa[u]];     dd[ck] = dd[pa[ck]] + 1;     for (auto v : edge[u]) {       dfs(v);       siz[u] += siz[v];     }   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) {       scanf( %d , aa + i);     }     for (int i = 2; i <= n; ++i) {       scanf( %d , fa + i);       edge[fa[i]].push_back(i);     }     dfs(1);     for (int i = 1; i <= n; ++i) {       a[fp[i]] = aa[i];       kh[i] = -50001;     }     for (int i = 1; i <= q; ++i) {       int x;       scanf( %d , &x);       int y = siz[x];       x = fp[x];       int pp = i + 1, *jj = kh + x, *diao = dd + x, *aa = a + x;       int ans = 0, cnt = 0;       for (int j = 0; j < y; ++j) {         if (jj[j] + aa[j] < pp) {           jj[j] = i;           ans += diao[j];           cnt++;         }       }       ans = ans - cnt * dd[x];       printf( %d %d n , ans, cnt);     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:256000000 )   using namespace std;   int main() {     int n;     scanf( %d , &(n));     vector<int> v1(n), v2(n), v3(n);     if (!(n % 2)) {       printf( -1 n );       return 0;     }     for (int i = (0), endi = (n); i < endi; ++i) v1[i] = i;     for (int i = (0), endi = (n); i < endi; ++i) v2[i] = (i + 1) % n;     for (int i = (0), endi = (n); i < endi; ++i) v3[i] = (v1[i] + v2[i]) % n;     for (int i = (0), endi = ((v1).size()); i < endi; ++i) {       printf( %d  , (v1[i]));     };     printf(  n );     for (int i = (0), endi = ((v2).size()); i < endi; ++i) {       printf( %d  , (v2[i]));     };     printf(  n );     for (int i = (0), endi = ((v3).size()); i < endi; ++i) {       printf( %d  , (v3[i]));     };     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int n, t, x, y, a = 0, b = 0, suma = 0, sumb = 0;     cin >> n;     while (n--) {       cin >> t >> x >> y;       if (t == 1) {         a++;         suma += x;       } else {         b++;         sumb += x;       }     }     if (suma >= 5 * a)       cout <<  LIVE ;     else       cout <<  DEAD ;     cout << endl;     if (sumb >= 5 * b)       cout <<  LIVE ;     else       cout <<  DEAD ;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e15;   struct Edge {     int t, w;   } e[100010 << 1];   queue<int> g[100010];   long long d[100010], f[100010];   int i, j, k, n, m, q, x, h[100010];   struct _ {     int x;     _(int x) : x(x) {}     bool operator<(const _& a) const { return d[x] > d[a.x]; }   };   priority_queue<_> Q;   vector<int> V[100010];   int done[100010 << 2];   inline void Dij() {     for (i = 2; i <= n; i++) d[i] = INF;     Q.push(1);     while (!Q.empty()) {       x = Q.top().x;       Q.pop();       for (int j : V[x])         if (d[e[j].t] > d[x] + e[j].w) {           d[e[j].t] = d[x] + e[j].w;           Q.push(e[j].t);         }     }   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &x, &e[i].t, &e[i].w);       V[x].push_back(i);     }     Dij();     for (int i = 1; i <= q; ++i) {       scanf( %d%d , &x, &k);       if (x == 1)         printf( %lld n , d[k] >= INF ? -1 : d[k]);       else {         for (int i = 1; i <= k; ++i) scanf( %d , &x), e[x].w++;         for (int i = 2; i <= n; ++i) f[i] = INF;         g[m = 0].push(1);         k = min(k, n - 1);         for (int i = 0; i <= m; ++i)           while (!g[i].empty()) {             x = g[i].front();             g[i].pop();             if (i > f[x]) continue;             for (int j : V[x]) {               long long y = f[x] + d[x] + e[j].w - d[e[j].t];               if (f[e[j].t] > y) {                 f[e[j].t] = y;                 if (y <= k) {                   g[y].push(e[j].t);                   if (y > m) m = y;                 }               }             }           }         for (int i = 2; i <= n; ++i) d[i] = min(INF, d[i] + f[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const int xx[4] = {1, -1, 0, 0};   const int yy[4] = {0, 0, 1, -1};   int inline in() {     int x = 0, c;     for (; (unsigned)((c = getchar()) -  0 ) >= 10;) {       if (c ==  - ) return -in();       if (!~c) throw ~0;     }     do {       x = (x << 3) + (x << 1) + (c -  0 );     } while ((unsigned)((c = getchar()) -  0 ) < 10);     return x;   }   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     int n, t;     string buf;     cin >> n >> t >> buf;     int i = buf.find( . ) + 1;     while (i < n && buf[i] <  5 ) i++;     if (i == n) {       cout << buf << endl;       return 0;     }     while (t-- && buf[i] >=  5 ) {       i--;       bool flag = (buf[i] ==  . );       if (flag) i--;       buf[i]++;       if (flag) break;     }     int len = i + 1;     for (; i >= 1 && buf[i] ==  9  + 1; i--) {       buf[i] =  0 ;       buf[i - 1]++;     }     if (buf[0] ==  9  + 1) {       buf[0] =  0 ;       buf =  1  + buf;       len++;     }     buf.resize(len);     cout << buf << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, e = 0, o = 0, k, p, j;     long long int arr[100005];     vector<long long int> v[100005], od, ev;     cin >> n >> k >> p;     for (i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] % 2 == 0) {         ev.push_back(arr[i]);         e++;       } else {         od.push_back(arr[i]);         o++;       }     }     if (o < (k - p)) {       cout <<  NO n ;       return 0;     }     o = o - k + p;     if (o % 2 == 1) {       cout <<  NO n ;       return 0;     }     if ((e + (o) / 2) < p) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     int j1 = 0, j2 = k - p;     for (i = 0; i < od.size(); i++) {       j1++;       if (j1 <= k - p) {         v[j1].push_back(od[i]);       } else {         j2++;         if (j2 > k) {           j2 = k;         }         v[j2].push_back(od[i]);         i++;         v[j2].push_back(od[i]);       }     }     for (i = 0; i < ev.size(); i++) {       j2++;       if (j2 <= k) {         v[j2].push_back(ev[i]);       } else {         v[k].push_back(ev[i]);       }     }     for (i = 1; i <= k; i++) {       cout << v[i].size() <<    ;       for (j = 0; j < v[i].size(); j++) {         cout << v[i][j] <<    ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   template <class T_T>   T_T gcd(T_T a, T_T b) {     return b ? gcd(b, a % b) : a;   }   template <class T_T>   T_T f_max(T_T a, T_T b) {     return a > b ? a : b;   }   using namespace std;   const int N = 100000;   int a[105][105], r[105], c[105], cnt_r[105], cnt_c[105], ans;   int main() {     int n, m, i, j;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);         r[i] += a[i][j];         c[j] += a[i][j];       }     queue<int> q;     for (i = 1; i <= n; i++)       if (r[i] < 0) q.push(i);     for (i = 1; i <= m; i++)       if (c[i] < 0) q.push(i + n);     while (!q.empty()) {       int v = q.front();       q.pop();       if (v <= n) {         if (r[v] >= 0) continue;         cnt_r[v]++;         r[v] = -r[v];         for (i = 1; i <= m; i++) {           c[i] -= 2 * a[v][i];           a[v][i] = -a[v][i];           if (c[i] < 0) q.push(i + n);         }       } else {         v -= n;         if (c[v] >= 0) continue;         cnt_c[v]++;         c[v] = -c[v];         for (i = 1; i <= n; i++) {           r[i] -= 2 * a[i][v];           a[i][v] = -a[i][v];           if (r[i] < 0) q.push(i);         }       }     }     for (i = 1, ans = 0; i <= n; i++)       if (cnt_r[i] & 1) ans++;     printf( %d  , ans);     for (i = 1; i <= n; i++)       if (cnt_r[i] & 1) printf( %d  , i);     puts(  );     for (i = 1, ans = 0; i <= m; i++)       if (cnt_c[i] & 1) ans++;     printf( %d  , ans);     for (i = 1; i <= m; i++)       if (cnt_c[i] & 1) printf( %d  , i);     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, m, a = 0, b = 0, c = 0, d, h, p, x, y, z, i = 0, j = 0,                         k = 0, l, r, rem, time = 0, ans = 0, mini = 1e18 + 1,                         maxi = 0, count = 0, sum = 0, sign = 0, xx, yy, zz;     cin >> n;     if (n >= 22 || n <= 10)       cout <<  0             <<   n ;     else if (n > 10 && n < 20 || n == 21)       cout <<  4             <<   n ;     else if (n == 20)       cout <<  15             <<   n ;   }   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     fast();     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> r;     for (int i = 0; i < n; i++) {       int tmp;       cin >> tmp;       r.push_back(tmp);     }     int m_lng = 0;     for (int i = 0; i < n; i++) {       int cnt = 1;       int lng = 0;       int sum = 0;       for (int j = i; j < n; j++) {         sum += r[j];         if (sum > 100 * cnt) lng = cnt;         cnt++;       }       if (m_lng < lng) m_lng = lng;     }     cout << m_lng;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fact[500005];   void criba() {     for (int i = 2; i * i < 500005; i++)       if (fact[i] == 0)         for (int j = i * i; j < 500005; j += i) fact[j] = i;     for (int i = 2; i < 500005; i++)       if (fact[i] == 0) fact[i] = i;   }   bool vis[500005];   int F[500005], a[500005];   int mask[1 << 9], primes[9];   vector<pair<int, int> > G[500005];   int main() {     int n, q;     criba();     while (cin >> n >> q) {       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);         int num = a[i], top = 0;         while (num > 1) {           int f = fact[num];           while (num % f == 0) num /= f;           primes[top++] = f;         }         mask[0] = 1;         for (int j = 1, l; j < (1 << top); j++) {           l = 31 - __builtin_clz(j & -j);           mask[j] = mask[j ^ (1 << l)] * primes[l];           if (__builtin_popcount(j) % 2 == 0)             G[i].push_back(make_pair(mask[j], 0));           else             G[i].push_back(make_pair(mask[j], 1));         }       }       long long pos, cur = 0, last = 0;       long long ans, val, id;       for (int i = 0; i < q; i++) {         scanf( %d , &pos);         pos--;         ans = cur;         if (vis[pos]) {           for (int j = 0; j < G[pos].size(); j++) {             val = G[pos][j].first;             id = G[pos][j].second;             if (id)               ans -= F[val];             else               ans += F[val];             F[val]--;           }           cur--;         } else {           for (int j = 0; j < G[pos].size(); j++) {             val = G[pos][j].first;             id = G[pos][j].second;             if (id)               ans -= F[val];             else               ans += F[val];             F[val]++;           }           cur++;         }         if (vis[pos] && a[pos] == 1) ans--;         if (vis[pos])           ans = last - ans;         else           ans = last + ans;         vis[pos] = 1 - vis[pos];         printf( %I64d n , ans);         last = ans;       }     }   }


#include <bits/stdc++.h>   int main() {     int n, m, a[1003], b[1003], i, j, count = 0, k = 0, flag = 0;     scanf( %d %d , &n, &m);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (i = 0; i < m; i++) {       scanf( %d , &b[i]);     }     for (i = 0; i < m; i++) {       for (j = k; j < n; j++) {         if (b[i] >= a[j]) {           count++;           flag = 1;           break;         }       }       if (flag == 1) {         k = j + 1;       } else if (flag == 0) {         break;       }       flag = 0;     }     printf( %d n , count);   }