#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   char str[MAXN][MAXN];   bool used[MAXN][MAXN];   int n, m;   int Move[][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};   int pp[4];   void gao(int id, int dis[][MAXN]) {     queue<pair<int, int> > q;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (str[i][j] == ( 0  + id)) {           dis[i][j] = 0;           q.push(make_pair(i, j));         }       }     }     while (!q.empty()) {       pair<int, int> tmp = q.front();       q.pop();       char ss = str[tmp.first][tmp.second];       if (ss >=  1  && ss <=  3 ) {         if (pp[ss -  0 ] == -1) pp[ss -  0 ] = dis[tmp.first][tmp.second];       }       if (str[tmp.first][tmp.second] != ( 0  + id) &&           str[tmp.first][tmp.second] !=  . )         continue;       for (int i = 0; i < 4; i++) {         int x = tmp.first + Move[i][0];         int y = tmp.second + Move[i][1];         if (x < 0 || x >= n || y < 0 || y >= m) continue;         if (dis[x][y] != -1) continue;         if (str[x][y] ==  # ) continue;         dis[x][y] = dis[tmp.first][tmp.second] + 1;         q.push(make_pair(x, y));       }     }   }   int dp1[MAXN][MAXN], dp2[MAXN][MAXN], dp3[MAXN][MAXN];   void Update(int &a, int b) {     if (b == -1) return;     if (a == -1)       a = b;     else       a = min(a, b);   }   int main() {     while (scanf( %d%d , &n, &m) == 2) {       int ans = -1;       for (int i = 0; i < n; i++) scanf( %s , str[i]);       memset(pp, -1, sizeof(pp));       memset(dp1, -1, sizeof(dp1));       gao(1, dp1);       if (pp[1] != -1 && pp[2] != -1 && pp[3] != -1)         Update(ans, pp[1] + pp[2] + pp[3] - 2);       memset(pp, -1, sizeof(pp));       memset(dp2, -1, sizeof(dp2));       gao(2, dp2);       if (pp[1] != -1 && pp[2] != -1 && pp[3] != -1)         Update(ans, pp[1] + pp[2] + pp[3] - 2);       memset(pp, -1, sizeof(pp));       memset(dp3, -1, sizeof(dp3));       gao(3, dp3);       if (pp[1] != -1 && pp[2] != -1 && pp[3] != -1)         Update(ans, pp[1] + pp[2] + pp[3] - 2);       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) {           if (dp1[i][j] == -1) continue;           if (dp2[i][j] == -1) continue;           if (dp3[i][j] == -1) continue;           Update(ans, max(0, dp1[i][j] - 1) + max(0, dp2[i][j] - 1) +                           max(0, dp3[i][j] - 1) + (str[i][j] ==  . ));         }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     vector<long long> mult(32, 1);     for (int i = 0; i < 32; i++) mult[i] = (1 << i) + 1;     int t;     cin >> t;     while (t--) {       long long d, m, final = 1;       cin >> d >> m;       d++;       int x = logb(d);       for (int i = 0; i < x; i++) {         final *= (mult[i]) % m;         final %= m;       }       final *= (d - ((1 << (x))) + 1) % m;       cout << (final % m - 1 + m) % m << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sum;   int cV = 0;   void add(string n, int c) {     if (n.size() == 1) {       cV = c;       return;     }     sum = 0;     for (char e : n) {       int a = e -  0 ;       sum += a;     }     c++;     add(to_string(sum), c);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     string n;     cin >> n;     add(n, 0);     cout << cV <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream& operator<<(ostream& os, const pair<T1, T2>& v) {     os <<  (  << v.first <<     << v.second <<  ) ;     return os;   }   template <typename T, typename U = typename T::value_type,             typename = typename enable_if<!is_same<T, string>::value>::type>   ostream& operator<<(ostream& os, const T& v) {     os <<  [ ;     for (const auto& it : v) os << it <<    ;     if (!v.empty()) os <<   b ;     os <<  ] ;     return os;   }   int64_t binom2(int64_t N) {     if (N < 2) return 0;     return (N * (N - 1)) / 2;   }   struct Counter {     struct Node {       vector<int> y;       unique_ptr<Node> left, right;       Node(const vector<int>& p, int node_left, int node_right)           : y(p.begin() + node_left, p.begin() + node_right) {         sort((y).begin(), (y).end());         if (y.size() >= 2) {           int node_middle = (node_left + node_right) / 2;           left.reset(new Node(p, node_left, node_middle));           right.reset(new Node(p, node_middle, node_right));         }       }     };     unique_ptr<Node> root;     void init(const vector<int>& p) { root.reset(new Node(p, 0, p.size())); }     int go_count(const Node* node, int node_left, int node_right, int l, int r,                  int d, int u) {       if (node_left >= r || node_right <= l) return 0;       if (l <= node_left && node_right <= r)         return upper_bound((node->y).begin(), (node->y).end(), u) -                lower_bound((node->y).begin(), (node->y).end(), d);       int node_middle = (node_left + node_right) / 2;       return go_count(node->left.get(), node_left, node_middle, l, r, d, u) +              go_count(node->right.get(), node_middle, node_right, l, r, d, u);     }     int count(int l, int r, int d, int u) {       return go_count(root.get(), 0, root->y.size(), l, r + 1, d, u);     }   };   int N, Q;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     cin >> N >> Q;     vector<int> p(N);     for (int i = 0; i < (N); i++) {       cin >> p[i];       p[i]--;     }     Counter counter;     counter.init(p);     for (int i = 0; i < (Q); i++) {       int l, d, r, u;       cin >> l >> d >> r >> u;       l--, d--, r--, u--;       int64_t ans = binom2(N) - binom2(l) - binom2(N - r - 1);       ans -= binom2(counter.count(0, N - 1, u + 1, N - 1));       ans -= binom2(counter.count(0, N - 1, 0, d - 1));       ans += binom2(counter.count(0, l - 1, 0, d - 1));       ans += binom2(counter.count(0, l - 1, u + 1, N - 1));       ans += binom2(counter.count(r + 1, N - 1, 0, d - 1));       ans += binom2(counter.count(r + 1, N - 1, u + 1, N - 1));       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int INF = 2147483647;   int inf = -2147483648;   const double PI = acos(-1.0);   const double pi = 2 * asin(1.0);   int vis[1000009];   int vi[1000009];   int main() {     ios::sync_with_stdio(false);     int a, b, c, d;     cin >> a >> b >> c >> d;     for (int i = 0; i <= 100; i++) {       vis[b + a * i] = 1;     }     for (int i = 0; i <= 100; i++) {       vi[d + c * i] = 1;     }     for (int i = 0; i < 1000009; i++) {       if (vis[i] == 1 && vi[i] == 1) {         cout << i << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   clock_t start;   void Time(bool timeIt) {     if (!timeIt) return;     clock_t end = clock();     double elapsed_time =         ((long double)end - (long double)start) / (long double)CLOCKS_PER_SEC;     fprintf(stderr,  Time elapsed = %0.4lf n , elapsed_time);   }   const int SIZE = 200010;   const int ALPHABET = 26;   char a[SIZE], b[SIZE];   vector<pair<long long, long long> > ps[ALPHABET][2];   int main() {     start = clock();     int n;     scanf( %d %s %s , &n, a, b);     long long numerator = 0, denominator = 0;     for (long long i = 1; i <= n; ++i) {       denominator += 1ll * (n - i + 1) * (n - i + 1);     }     for (int i = 0; i < n; ++i) {       int ch = a[i] -  A ;       if (ps[ch][0].empty()) {         ps[ch][0].push_back(make_pair(i + 1, i));         ps[ch][1].push_back(make_pair(n - i, i));       } else {         ps[ch][0].push_back(make_pair(ps[ch][0].back().first + i + 1, i));         ps[ch][1].push_back(make_pair(ps[ch][1].back().first + n - i, i));       }     }     long double ans = 0;     for (int i = 0; i < n; ++i) {       int ch = b[i] -  A ;       int e = ps[ch][0].size(), s = -1;       while (e - s > 1) {         int m = (e + s) >> 1;         if (ps[ch][0][m].second <= i)           s = m;         else           e = m;       }       if (s != -1)         ans += (long double)(1ll * ps[ch][0][s].first * (n - i)) /                (long double)denominator;       e = ps[ch][1].size();       s = -1;       while (e - s > 1) {         int m = (e + s) >> 1;         if (ps[ch][1][m].second > i)           e = m;         else           s = m;       }       if (e != ps[ch][1].size()) {         long long sum =             (ps[ch][1].back().first - (s != -1 ? ps[ch][1][s].first : 0));         ans += (long double)(1ll * sum * (i + 1)) / (long double)denominator;       }     }     printf( %0.10Lf n , ans);     Time(true);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   #pragma GCC target( avx,avx2 )   using namespace std;   long long mod = 1e9 + 7;   const long long inf = 1e9;   int main() {     cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0);     int n, l, x, y;     cin >> n >> l >> x >> y;     vector<int> a(n);     set<int> ax, ay;     map<int, int> have;     bool havex = 0, havey = 0;     for (int i = 0; i < n; ++i) {       cin >> a[i];       have[a[i]] = 1;     }     for (int i = 0; i < n; ++i) {       if (a[i] + x < l && !have[a[i] + x]) ax.insert(a[i] + x);       if (a[i] + y < l && !have[a[i] + y]) ay.insert(a[i] + y);       if (a[i] - x > 0 && !have[a[i] - x]) ax.insert(a[i] - x);       if (a[i] - y > 0 && !have[a[i] - y]) ay.insert(a[i] - y);     }     for (int i = 0; i < n; ++i) {       if (have[a[i] - x] || have[a[i] + x]) havex = 1;       if (have[a[i] - y] || have[a[i] + y]) havey = 1;     }     vector<int> ans;     if (havex && havey) {       cout << 0;       exit(0);     }     if (havex) {       cout <<  1 n  << (*ay.begin());       exit(0);     }     if (havey) {       cout <<  1 n  << (*ax.begin());       exit(0);     }     for (int val : ax) {       if (ay.count(val)) {         cout <<  1 n  << val;         exit(0);       }     }     cout <<  2 n  << (*ax.begin()) <<     << (*ay.begin());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   int main() {     int n;     scanf( %d , &n);     long long sum = 0;     for (int i = 0; i < n; i++) {       int a;       scanf( %d , &a);       while (1) {         if (mp[a] == 0 || a == 0) {           mp[a] = 1;           sum += (long long)a;           break;         } else           a--;       }     }     printf( %I64d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, c, a, b;     cin >> a >> b >> c;     c -= 1;     while (c) {       c--;       i = a + b;       a = b;       b = i;     }     cout << b << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int p[100010];   bool used[100010];   int main() {     scanf( %d , &n);     memset(p, 0, sizeof(p));     memset(used, false, sizeof(used));     if (n == 1) {       printf( 1 n );       return 0;     }     if (n % 2 == 0) {       if (n % 4 != 0) {         printf( -1 n );         return 0;       }     } else {       if ((n - 1) % 4 != 0) {         printf( -1 n );         return 0;       }     }     if (n % 2 != 0) {       p[n / 2 + 1] = n / 2 + 1;       used[n / 2 + 1] = true;     }     for (int i = 1; i <= n / 2; i++) {       if (!p[i]) {         int num = 1;         while (used[num] || num == i) num++;         p[i] = num;         used[num] = true;         p[num] = n + 1 - i;         used[n + 1 - i] = true;         p[n + 1 - i] = n + 1 - num;         used[n + 1 - num] = true;         p[n + 1 - num] = i;         used[i] = true;       }     }     for (int i = 1; i <= n; i++) printf( %d  , p[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v;     for (int i = 1; i <= 20; ++i) {       int first = ((1 << i) - 1) * (1 << (i - 1));       if (first > 1e5) break;       v.push_back(first);     }     for (int i = v.size() - 1; i >= 0; --i) {       if (n % v[i] == 0) return cout << v[i], 0;     }     return 0;   }


#include <bits/stdc++.h>   int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};   int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};   using namespace std;   long long power(long long a, long long p, long long M) {     long long r = 1;     a = a % M;     while (p > 0) {       if (p % 2) r = (r * a) % M;       a = (a * a) % M;       p /= 2;     }     return r;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int n;   long long a[200000];   vector<long long> v[200000];   void solve() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     ;     for (int i = 0; i < n; i++) {       v[i].push_back(0);     }     for (int i = 0; i < n; i++) {       long long l = 0, r = n - 1;       while (l <= r) {         long long mid = (l + r) / 2;         if (v[mid][v[mid].size() - 1] < a[i]) {           r = mid - 1;         } else {           l = mid + 1;         }       }       v[l].push_back(a[i]);     }     for (int i = 0; i < n; i++) {       if (v[i].size() > 1) {         for (int j = 1; j < v[i].size(); j++) {           printf( %lld  , v[i][j]);         }         printf(  n );       } else {         break;       }     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[51][51], ans[51];   bool check(int j, int x) {     for (int i = 1; i <= n; i++)       if (a[j][i] > x || a[i][j] > x) return false;     ans[j] = x;     return true;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]);     for (int i = 1; i <= n; i++) {       int j = 1;       while (ans[j] || !check(j, i)) j++;     }     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     if (s.length() < 26) {       cout << -1 << endl;       return 0;     }     int j = -1;     for (int i = 0; i < s.length(); i++)       if (s[i] ==  a ) {         j = i + 1;         break;       }     if (j == -1) {       cout << -1 << endl;       return 0;     }     for (char c =  b ; c <=  z ; c++) {       bool f = 0;       for (int i = j; i < s.length(); i++) {         if (s[i] <= (char)(c - 1)) {           s[i] = c, j = i + 1, f = 1;           break;         }         if (s[i] == (char)(c)) {           j = i + 1, f = 1;           break;         }       }       if (f == 0) {         cout << -1 << endl;         return 0;       }     }     cout << s << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n;   long long a[maxn], l[maxn], r[maxn], lans[maxn], rans[maxn];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     for (int i = 1; i <= n; i++) {       l[i] = max(a[i], l[i - 1] + 1);       lans[i] = l[i] - a[i] + lans[i - 1];     }     for (int i = n; i >= 0; i--) {       r[i] = max(a[i], r[i + 1] + 1);       rans[i] = r[i] - a[i] + rans[i + 1];     }     long long ans = 1e18;     for (int i = 1; i <= n; i++)       ans =           min(ans, lans[i - 1] + rans[i + 1] + max(l[i], max(r[i], a[i])) - a[i]);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2005, INF = 2e9;   int n, m, k, p[N][N], rnk[N][N], le[N][N], ri[N][N];   bool used[N][N], iswap;   pair<int, pair<int, int> > ans;   int dsu_get(int x, int y) {     return p[x][y] == y ? y : p[x][y] = dsu_get(x, p[x][y]);   }   inline void dsu_unite(int x, int y1, int y2) {     int px = dsu_get(x, y1), py = dsu_get(x, y2);     if (px != py) {       if (rnk[x][px] < rnk[x][py]) {         swap(px, py);       }       if (rnk[x][px] == rnk[x][py]) {         rnk[x][px]++;       }       p[x][py] = px;       le[x][px] = min(le[x][px], le[x][py]);       ri[x][px] = max(ri[x][px], ri[x][py]);     }   }   inline void upd(pair<int, pair<int, int> > val) {     if (iswap) {       if (val.first < ans.first) {         ans = val;       } else if (val.first == ans.first) {         auto it1 = ans.second, it2 = val.second;         swap(it1.first, it1.second);         swap(it2.first, it2.second);         if (it1 > it2) {           ans = val;         }       }     } else {       ans = min(ans, val);     }   }   inline pair<int, int> getans(int x, int y) {     ans = make_pair(INF, make_pair(-1, -1));     for (int i = 0; i <= ans.first; i++) {       if (x - i >= 1) {         int py = dsu_get(x - i, y);         int ll = le[x - i][py], rr = ri[x - i][py];         if (used[x - i][ll]) {           ll--;         }         if (used[x - i][rr]) {           rr++;         }         if (ll >= 1) {           upd(make_pair(i + y - ll, make_pair(x - i, ll)));         }         if (rr <= m) {           upd(make_pair(i + rr - y, make_pair(x - i, rr)));         }       }       if (x + i <= n) {         int py = dsu_get(x + i, y);         int ll = le[x + i][py], rr = ri[x + i][py];         if (used[x + i][ll]) {           ll--;         }         if (used[x + i][rr]) {           rr++;         }         if (ll >= 1) {           upd(make_pair(i + y - ll, make_pair(x + i, ll)));         }         if (rr <= m) {           upd(make_pair(i + rr - y, make_pair(x + i, rr)));         }       }     }     return ans.second;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     if (n > m) {       iswap = true;       swap(n, m);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         le[i][j] = ri[i][j] = p[i][j] = j;       }     }     while (k--) {       int x, y;       cin >> x >> y;       if (iswap) {         swap(x, y);       }       auto it = getans(x, y);       used[it.first][it.second] = true;       if (it.second - 1 >= 1 && used[it.first][it.second - 1]) {         dsu_unite(it.first, it.second - 1, it.second);       }       if (it.second + 1 <= m && used[it.first][it.second + 1]) {         dsu_unite(it.first, it.second, it.second + 1);       }       if (iswap) {         swap(it.first, it.second);       }       cout << it.first <<     << it.second <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int P = 998244353;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<int> a(n), c(m, -1), d(m), bb(m);     map<int, int> b;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int j = 0; j < m; j++) {       int q;       cin >> q;       b.insert(make_pair(q, j));       bb[j] = q;     }     for (int k = 0; k < n; k++) {       if (b.find(a[k]) != b.end()) {         c[b.find(a[k])->second] = k;       }     }     if (c[0] == -1) {       cout << 0;       return 0;     }     for (int l = 1; l < m; l++) {       if ((c[l] < c[l - 1]) || (c[l - 1] == -1)) {         cout << 0;         return 0;       }     }     int s = 0, t = 0;     d[0] = c[0];     while (s <= c[t]) {       if (t >= 1) {         if (a[s] < bb[t - 1]) {           cout << 0;           return 0;         }       }       if (a[s] < bb[t]) d[t] = s;       if (s == c[t]) {         t++;         if (t >= m) break;         d[t] = c[t - 1];       }       s++;     }     if (d[0] < c[0]) {       cout << 0;       return 0;     }     for (int e = c[m - 1]; e < n; e++) {       if (a[e] < bb[m - 1]) {         cout << 0;         return 0;       };     }     if (m == 1) {       cout << 1;       return 0;     }     long long int sum = 1;     for (int w = 1; w < m; w++) {       sum = (sum * (c[w] - d[w])) % P;     }     cout << sum;   }


#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::deque;   using std::endl;   using std::map;   using std::max;   using std::min;   using std::multiset;   using std::pair;   using std::queue;   using std::set;   using std::sort;   using std::stack;   using std::string;   using std::vector;   int n, k, s, t;   int c[200005] = {       0,   };   int v[200005] = {       0,   };   int g[200005] = {       0,   };   bool isGood(int middle) {     int time = 0;     for (int i = 1; i <= k + 1; i++) {       int len = g[i] - g[i - 1];       if (len > middle) {         return false;       }       if (middle >= len * 2) {         time += len;       } else {         time += (len * 2 - middle) * 2 + (middle - len);       }     }     if (time <= t) return true;     return false;   }   int main() {     cin >> n >> k >> s >> t;     for (int i = 0; i < n; i++) {       scanf( %d%d , c + i, v + i);     }     g[0] = 0;     g[k + 1] = s;     for (int i = 1; i <= k; i++) {       scanf( %d , g + i);     }     sort(g, g + k + 2);     const int up = 2123456789;     int badBak = 0;     int goodBak = up;     while (badBak + 1 != goodBak) {       int middle = (int)((1LL * badBak + goodBak) / 2);       if (isGood(middle)) {         goodBak = middle;       } else {         badBak = middle;       }     }     if (goodBak == up) {       cout << -1;       return 0;     }     int cheap = up;     for (int i = 0; i < n; i++) {       if (v[i] >= goodBak && c[i] < cheap) {         cheap = c[i];       }     }     if (cheap == up) {       cout << -1;       return 0;     }     cout << cheap;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n, p, q, a;     cin >> t;     while (t--) {       cin >> n >> p >> q;       vector<long long int> player1, player2;       for (unsigned long long i = 0; i < p; i++) {         cin >> a;         player1.push_back(a);       }       for (unsigned long long i = 0; i < q; i++) {         cin >> a;         player2.push_back(a);       }       sort(player1.begin(), player1.end(), greater<long long int>());       sort(player2.begin(), player2.end(), greater<long long int>());       if (player1[0] > player2[0])         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   int N, M, Q;   vector<int> V[100002], W[100002];   int X[100002], Y[100002], T[100002], weight[100002];   int A[100002];   bool S[100002];   int xglob, yglob;   inline bool compare(const int& i1, const int& i2) {     return atan2(Y[i1] - yglob, X[i1] - xglob) <            atan2(Y[i2] - yglob, X[i2] - xglob);   }   void Dfs(int x) {     S[x] = true;     weight[x] = 1;     W[x].resize(V[x].size());     for (int i = 0; i < int(V[x].size()); ++i)       if (!S[V[x][i]]) {         T[V[x][i]] = x;         Dfs(V[x][i]);         weight[x] += weight[V[x][i]];         W[x][i] = -weight[V[x][i]];       }     for (int i = 0; i < int(V[x].size()); ++i)       if (V[x][i] == T[x]) W[x][i] = weight[x];     for (int i = 1; i < int(W[x].size()); ++i) W[x][i] += W[x][i - 1];   }   int main() {     cin >> N >> M;     for (int i = 1, nod1, nod2; i <= M; ++i) {       cin >> nod1 >> nod2;       V[nod1].push_back(nod2);       V[nod2].push_back(nod1);     }     int minx = -1;     for (int i = 1; i <= N; ++i) {       cin >> X[i] >> Y[i];       if (minx == -1 || X[i] < X[minx]) minx = i;     }     X[N + 1] = -0x3f3f3f3f, Y[N + 1] = -0x3f3f3f3f;     V[minx].push_back(N + 1);     V[N + 1].push_back(minx);     for (int i = 1; i <= N; ++i) {       xglob = X[i], yglob = Y[i];       sort(V[i].begin(), V[i].end(), compare);     }     Dfs(N + 1);     cin >> Q;     for (int i = 1; i <= Q; ++i) {       cin >> A[0];       long long area = 0;       for (int j = 1; j <= A[0]; ++j) {         cin >> A[j];         if (j >= 2)           area += 1LL * X[A[j - 1]] * Y[A[j]] - 1LL * X[A[j]] * Y[A[j - 1]];       }       area += 1LL * X[A[A[0]]] * Y[A[1]] - 1LL * X[A[1]] * Y[A[A[0]]];       if (area < 0) reverse(A + 1, A + A[0] + 1);       A[A[0] + 1] = A[1];       ++A[0];       A[A[0] + 1] = A[2];       ++A[0];       int result = 0;       for (int j = 2; j <= A[0] - 1; ++j) {         int step = 1 << 16, nod1, nod2;         for (nod1 = -1; step; step >>= 1)           if (nod1 + step < int(V[A[j]].size()) &&               atan2(Y[V[A[j]][nod1 + step]] - Y[A[j]],                     X[V[A[j]][nod1 + step]] - X[A[j]]) -                       atan2(Y[A[j - 1]] - Y[A[j]], X[A[j - 1]] - X[A[j]]) <                   eps)             nod1 += step;         step = 1 << 16;         for (nod2 = -1; step; step >>= 1)           if (nod2 + step < int(V[A[j]].size()) &&               atan2(Y[V[A[j]][nod2 + step]] - Y[A[j]],                     X[V[A[j]][nod2 + step]] - X[A[j]]) -                       atan2(Y[A[j + 1]] - Y[A[j]], X[A[j + 1]] - X[A[j]]) <                   eps)             nod2 += step;         if (nod1 < nod2)           result += W[A[j]][nod2 - 1] - W[A[j]][nod1];         else           result += W[A[j]][W[A[j]].size() - 1] -                     (W[A[j]][nod1] - (nod2 == 0 ? 0 : W[A[j]][nod2 - 1]));       }       cout << result <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int n;     cin >> n;     vector<long long int> a, d;     for (long long int i = 0; i < n; i++) {       long long int temp;       cin >> temp;       a.push_back(temp);     }     for (long long int i = 0; i < n; i++) {       long long int temp;       cin >> temp;       d.push_back(a[i] - temp);     }     sort(d.begin(), d.end());     long long int i = 0, j = n - 1, s = 0;     while (i != j) {       if (d[i] + d[j] > 0) {         j--;       } else {         i++;         s += n - j - 1;       }     }     s += (n - j - 1) * (n - j) / 2;     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string n;     cin >> n;     int ans = 0;     while (n.size() > 1) {       int k = 0;       for (int i = 0; i < n.size(); i++) {         k += n[i] - 48;       }       ans++;       stringstream ss;       ss << k;       string str = ss.str();       n = str;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T, a, b, c, i, count = 0;     cin >> T;     for (i = 0; i < T; i++) {       cin >> a >> b >> c;       if ((a + b + c) >= 2) {         count++;       }     }     cout << count <<   n ;     return 0;   }


#include <bits/stdc++.h>   namespace fft {   using namespace std;   const double PI = std::atan2(0, -1);   using dbl = double;   struct num {     dbl x, y;     num(dbl x_ = 0, dbl y_ = 0) : x(x_), y(y_) {}   };   inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }   inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }   inline num operator*(num a, num b) {     return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);   }   inline num conj(num a) { return num(a.x, -a.y); }   inline num inv(num a) {     dbl n = (a.x * a.x + a.y * a.y);     return num(a.x / n, -a.y / n);   }   using vn = vector<num>;   vector<int> rev({0, 1});   vn rt(2, num(1)), fa, fb;   inline void init(int n) {     if (n <= (int)(rt).size()) return;     rev.resize(n);     for (int i = 0; i < (n); ++i) rev[i] = (rev[i >> 1] | ((i & 1) * n)) >> 1;     rt.reserve(n);     for (int k = (int)(rt).size(); k < n; k *= 2) {       rt.resize(2 * k);       double a = PI / k;       num z(cos(a), sin(a));       for (int i = k / 2; i < (k); ++i)         rt[2 * i] = rt[i], rt[2 * i + 1] = rt[i] * z;     }   }   inline void fft(vector<num>& a, int n) {     init(n);     int s = __builtin_ctz((int)(rev).size() / n);     for (int i = 0; i < (n); ++i)       if (i < rev[i] >> s) swap(a[i], a[rev[i] >> s]);     for (int k = 1; k < n; k *= 2)       for (int i = 0; i < n; i += 2 * k)         for (int j = 0; j < (k); ++j) {           num t = rt[j + k] * a[i + j + k];           a[i + j + k] = a[i + j] - t;           a[i + j] = a[i + j] + t;         }   }   using vd = vector<double>;   vd multiply(const vd& a, const vd& b) {     int s = (int)(a).size() + (int)(b).size() - 1;     if (s <= 0) return {};     int L = s > 1 ? 32 - __builtin_clz(s - 1) : 0, n = 1 << L;     if ((int)(fa).size() < n) fa.resize(n);     if ((int)(fb).size() < n) fb.resize(n);     fill(fa.begin(), fa.begin() + n, 0);     for (int i = 0; i < ((int)(a).size()); ++i) fa[i].x = a[i];     for (int i = 0; i < ((int)(b).size()); ++i) fa[i].y = b[i];     fft(fa, n);     for (auto& x : fa) x = x * x;     for (int i = 0; i < (n); ++i) fb[i] = fa[(n - i) & (n - 1)] - conj(fa[i]);     fft(fb, n);     vd r(s);     for (int i = 0; i < (s); ++i) r[i] = fb[i].y / (4 * n);     return r;   }   }  // namespace fft   int main() {     using namespace std;     ios_base::sync_with_stdio(false), cin.tie(nullptr);     array<int, 2> N;     int Q;     cin >> N[0] >> N[1] >> Q;     array<vector<int>, 2> A;     for (int z = 0; z < 2; z++) {       A[z].resize(N[z]);       for (int& v : A[z]) cin >> v;     }     vector<int> queries(Q);     for (auto& q : queries) cin >> q;     const int X = int(1e5) + 100;     array<vector<double>, 2> mults;     for (int z = 0; z < 2; z++) {       mults[z].assign(X, 0);       for (int i = 0; i + 1 < N[z]; i++) {         mults[z][min(A[z][i], A[z][i + 1])]--;         mults[z][max(A[z][i], A[z][i + 1])]++;       }     }     vector<long long> ans(2 * X - 1);     vector<double> ans_double = fft::multiply(mults[0], mults[1]);     for (int i = 0; i < 2 * X - 1; i++) {       ans[i] = ((ans_double[i] > 0) - (ans_double[i] < 0)) *                (long long)(abs(ans_double[i]) + 0.5);     }     for (int a : {A[0].front(), A[0].back()}) {       for (int b : {A[1].front(), A[1].back()}) {         ans[a + b]++;       }     }     for (int i = 2 * X - 3; i >= 0; i--) {       ans[i] += ans[i + 1];     }     long long tot = ans[0];     for (auto& a : ans) {       a = 2 * a - tot;       a /= 4;     }     for (int q : queries) {       cout << ans[q] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:65777216 )   using namespace std;   const int N = 2222;   const int INF = 111111111;   const double eps = 1e-9;   const double pi = 3.14159265358979;   char s[N], u[N];   int n, m, ans = INF;   inline int check(int pos) {     int res = 0;     for (int i = 0; i < (m); i++) {       if (pos + i < 0 || pos + i >= n) continue;       if (s[pos + i] == u[i]) ++res;     }     return res;   }   int main() {     gets(s);     gets(u);     n = strlen(s);     m = strlen(u);     for (int i = -m; i <= m + n; i++) ans = min(ans, m - check(i));     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k = 0;     int ladder = 0;     string slogan;     cin >> k >> ladder;     cin >> slogan;     int h = k / 2;     if (ladder != 1 && ladder != k) {       if (ladder > h) {         while (ladder != k) {           cout <<  RIGHT  << endl;           ladder++;         }       } else if (ladder <= h) {         while (ladder != 1) {           cout <<  LEFT  << endl;           ladder--;         }       }     }     string toPrint = ladder == 1 ?  RIGHT  :  LEFT ;     if (toPrint ==  LEFT ) {       string reversed =   ;       for (int i = k - 1; i >= 0; i--) {         reversed += slogan.at(i);       }       slogan = reversed;     }     for (int i = 0; i < k; i++) {       if (i != 0) {         cout << toPrint << endl;       }       cout <<  PRINT   << slogan.at(i) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long v[3], l, ans, minusVal;   long long accSum(long long limit) {     return (limit + 1LL) * (limit + 2LL) / 2LL;   }   long long invalidCase(long long a, long long b, long long c) {     long long ret = 0LL;     for (long long i = 0LL; i <= l; i++) {       long long val = min(c - a - b + i, l - i);       if (val >= 0LL) ret += accSum(val);     }     return ret;   }   int main() {     scanf( %lld %lld %lld %lld , &v[0], &v[1], &v[2], &l);     ans = (l + 1LL) * (l + 2LL) * (l + 3LL) / 6LL;     ans -= invalidCase(v[2], v[1], v[0]);     ans -= invalidCase(v[0], v[2], v[1]);     ans -= invalidCase(v[0], v[1], v[2]);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000 * 1000 * 1000 + 7;   const long long MAXN = 100 * 1000 + 10;   long long t;   long long n, k;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     cin >> t;     while (t--) {       cin >> n >> k;       cout << k * 2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fin(string s, int i1) {     int mi = 999999999;     for (int d = 1; d <= 9; d++) {       for (int i = i1; i < i1 + 10; i++) {         if (i + 2 * d < s.length()) {           if (s[i] == s[i + d] && s[i] == s[i + 2 * d]) {             mi = min(mi, i + 2 * d);           }         }       }     }     return mi;   }   int main() {     string s;     cin >> s;     long long n = s.length();     long long ans = 0;     for (int i = 0; i < n; i++) {       int p = fin(s, i);       if (n > p) {         ans = ans + n - p;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e5 + 100;   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int modexp(long long int x, long long int n, long long int mod) {     long long int result = 1;     while (n > 0) {       if (n % 2 == 1) result = (result % mod * x % mod) % mod;       x = (x % mod * x % mod) % mod;     }     return result;   }   bool vis[N];   vector<long long int> adj[N];   long long int mx = 0;   void DFS(long long int s) {     vis[s] = true;     for (int i = 0; i < adj[s].size(); i++)       if (!vis[adj[s][i]]) DFS(adj[s][i]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int ans = n - (n % k);       long long int x = k / 2;       ans += min(x, n % k);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 9223372036854775807ll;   const int inf = 2147483647, nmax = 1000006;   struct thing {     long long a, b, c, i;     bool operator<(const thing &obj) const { return c < obj.c; }   } e[nmax], e2[nmax], apm[nmax];   struct thing2 {     long long a, b, c, i, st, dr, mid, ans;     bool operator<(const thing2 &obj) const { return mid < obj.mid; }   };   long long n, m, c[nmax], rng[nmax], v[nmax], ans[nmax];   vector<thing2> r;   long long find(long long x) {     if (x == c[x]) return x;     return c[x] = find(c[x]);   }   void unite(long long x, long long y) {     if (x == y) return;     if (rng[x] > rng[y])       c[y] = x;     else       c[x] = y;     if (rng[x] == rng[y]) ++rng[y];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       cin >> e[i].a >> e[i].b >> e[i].c;       e[i].i = i;       e2[i] = e[i];       ans[i] = -1;     }     sort(e2 + 1, e2 + m + 1);     for (int i = 1; i <= n; ++i) rng[i] = 1, c[i] = i;     int p = 0;     for (int i = 1; i <= m; ++i)       if (find(e2[i].a) != find(e2[i].b)) {         apm[++p] = e2[i];         unite(find(e2[i].a), find(e2[i].b));         v[p] = e2[i].c;       } else {         thing2 obj;         obj.a = e2[i].a;         obj.b = e2[i].b;         obj.c = e2[i].c;         obj.i = e2[i].i;         obj.st = 1;         obj.dr = n - 1;         r.push_back(obj);       }     sort(v + 1, v + n);     for (int t = 1; t <= 32; ++t) {       for (auto &x : r) x.mid = (x.st + x.dr) / 2;       sort(r.begin(), r.end());       for (int i = 1; i <= n; ++i) rng[i] = 1, c[i] = i;       unsigned p = 0;       for (int i = 1; i < n; ++i) {         unite(find(apm[i].a), find(apm[i].b));         while (p < r.size() && v[r[p].mid] <= apm[i].c) {           if (find(r[p].a) == find(r[p].b)) {             r[p].dr = r[p].mid - 1;             r[p].ans = v[r[p].mid];           } else             r[p].st = r[p].mid + 1;           ++p;         }       }     }     for (auto x : r) ans[x.i] = x.ans;     for (int i = 1; i <= m; ++i)       if (ans[i] != -1) cout << ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   struct compF {     bool operator()(const pair<T, T> &a, const pair<T, T> &b) {       return a.first < b.first;     }   };   template <typename T>   struct compS {     bool operator()(const pair<T, T> &a, const pair<T, T> &b) {       return a.second < b.second;     }   };   template <typename T>   void printMatrix(const string &txt, vector<vector<T>> &a) {     cout << txt;     for (int i = 0; i < a.size(); ++i) {       for (int j = 0; j < a[i].size(); ++j) cout << a[i][j] <<    ;       cout << endl;     }   }   template <typename T>   void printVector(const string &txt, vector<T> &a) {     cout << txt;     for (int i = 0; i < a.size(); ++i) cout << a[i] <<    ;     cout << endl;   }   template <typename T>   void readVector(int n, vector<T> &a) {     if (a.size() < n) a.resize(n);     for (int i = 0; i < n; ++i) cin >> a[i];   }   template <typename T1, typename T2>   bool exist(map<T1, T2> &m, T1 x) {     if (m.find(x) == m.end()) return false;     return true;   }   long long gcd(long long a, long long b) {     while (a != 0 && b != 0) {       if (b > a)         b %= a;       else         a %= b;     }     return a + b;   }   long long minFactor(long long x) {     for (long long i = 2; i * i <= x; ++i)       if (x % i == 0) return i;     return x;   }   long long allFactors(long long x, vector<long long> &prms,                        vector<long long> &prm_cnt) {     prms.clear();     prm_cnt.clear();     while (x > 1) {       long long t = minFactor(x);       prms.push_back(t);       int s = prms.size() - 1;       prm_cnt.push_back(0);       while (x % t == 0) {         x /= t;         ++prm_cnt[s];       }     }     return 0;   }   long long add(long long x, long long y) {     if (x >= 998244353) x %= 998244353;     if (y >= 998244353) y %= 998244353;     return (x + y) % 998244353;   }   long long mul(long long x, long long y) {     if (x >= 998244353) x %= 998244353;     if (y >= 998244353) y %= 998244353;     return (x * y) % 998244353;   }   long long pow_(long long x, long long y) {     if (y == 0) return 1ll;     if (y % 2 == 0) {       long long k = pow_(x, y / 2);       return (k * k) % 998244353;     } else {       return mul(x, pow_(x, y - 1));     }   }   long long n, m;   long long fact[2 * (int)(1e5) + 2], rfact[2 * (int)(1e5) + 2];   long long C(long long n, long long m) {     long long num = fact[n];     long long den = mul(rfact[m], rfact[n - m]);     return mul(num, den);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     fact[0] = fact[1] = rfact[0] = rfact[1] = 1ll;     for (long long i = 2; i <= 2 * (int)(1e5); ++i) {       fact[i] = mul(fact[i - 1], i);       rfact[i] = pow_(fact[i], 998244353 - 2);     }     cin >> n >> m;     if (n == 2) {       cout << 0 << endl;       return 0;     }     long long t = n - 1;     long long res = 0;     long long c = 0;     for (long long i = t; i <= m; ++i) {       long long cr = C(i - 1, t - 1);       c = add(c, cr);     }     long long t2 = pow_(2, t - 2);     res = mul(c, mul(max(t2, 1ll), t - 1));     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int isP(long int hj) {     long int op;     for (op = 2; op <= sqrt(hj); op++) {       if (hj % op == 0) return 0;     }     return 1;   }   void swap(long long int *p, long long int *q) {     long long int tmp = *p;     *p = *q;     *q = tmp;   }   void tog(int *p) {     if (*p == 1)       *p = 0;     else       *p = 1;   }   string fdi(int hi) {     switch (hi) {       case 0:         return  zero ;       case 1:         return  one ;       case 2:         return  two ;       case 3:         return  three ;       case 4:         return  four ;       case 5:         return  five ;       case 6:         return  six ;       case 7:         return  seven ;       case 8:         return  eight ;       case 9:         return  nine ;     }   }   string rdx(int hi) {     switch (hi) {       case 2:         return  twenty ;       case 3:         return  thirty ;       case 4:         return  forty ;       case 5:         return  fifty ;       case 6:         return  sixty ;       case 7:         return  seventy ;       case 8:         return  eighty ;       case 9:         return  ninety ;     }   }   long long int bd(long long int mk, long long int nk) {     long long int i;     for (i = min(mk, nk); i >= 1; i--) {       if (mk % i == 0 && nk % i == 0) return i;     }   }   int dsm(long long int pkk) {     if (pkk < 0) pkk *= -1;     while (pkk > 0) {       if (pkk % 10 == 8) return 1;       pkk /= 10;     }     return 0;   }   int main() {     long long int nk, l, nl, np, odI, evI, r, a1, a2, amt, maxu, y3, sx, sy, bsm,         fsm, bu, cp, bf, pr, res, lastm, c, r1, r2, x1, x2, y1, y2, maxN, m1, m2,         prev, prc, cost, ind, ans, g, p, inc, cap, sm, d, nxt, mn, t, up, a, b,         lc, la, e, preI, t2, brk, clbp, clb, et, jmp, u, l1, l2, sq, nd, maxi, li,         ri, tr, mp, og, lt1, lt2, n1, n2, c1, c2, minI, min1, p2, p3, ze, fst,         lst, min2, s, sm1, sm2, sm3, sr, sl, ln, rz, rn, car, eq, shr, ng, v,         curr, spl, fl, z, ev, od, m, ct, j, q, k, maxI, max1, max2, lt, md, f, n,         xP, xN, w, h, d2, d1, u1, u2, i, x, y;     cin >> n;     string st;     cin >> st;     a = 0;     b = 0;     if (st[0] ==  a )       a++;     else       b++;     ct = 0;     for (i = 1; i < n; i++) {       if (i % 2 != 0) {         if (st[i] ==  a )           a++;         else           b++;         if (a != b) {           ct++;           if (st[i] ==  a ) {             st[i] =  b ;             a--;             b++;           } else {             st[i] =  a ;             a++;             b--;           }         }       } else {         if (st[i] ==  a )           a++;         else           b++;       }     }     cout << ct << endl;     cout << st;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int q;   long long int input;   long long int lastSum[20];   long long int limit[20];   long long int targetSum(int digit, long long int target) {     long long int ret = lastSum[digit - 1] * target;     ret += target * (target + 1) * digit / 2;     return ret;   }   long long int targetSubSum(long long int target) {     if (target == 0) return 0;     int digit = 0;     long long int tmp = target, ret = 0, mul = 1;     while (tmp) digit++, tmp /= 10, mul *= 10;     ret += lastSum[digit - 1];     target -= (mul / 10) - 1;     ret += target * digit;     return ret;   }   int main() {     long long int mul = 9;     for (int digit = 1; digit < 10; digit++) {       lastSum[digit] = lastSum[digit - 1] + digit * mul;       limit[digit] = limit[digit - 1] + lastSum[digit - 1] * mul +                      digit * mul * (mul + 1) / 2;       mul *= 10;     }     scanf( %d , &q);     while (q) {       scanf( %lld , &input);       int digit = 1;       long long int low = 0, high = 9, answer = 1;       while (limit[digit] < input) digit++, high *= 10;       input -= limit[digit - 1];       while (low <= high) {         long long int mid = (low + high) / 2;         if (targetSum(digit, mid) <= input) {           answer = mid;           low = mid + 1;         } else           high = mid - 1;       }       long long int mul = 1;       for (int i = 1; i < digit; i++) mul *= 10;       input -= targetSum(digit, answer);       if (input == 0)         printf( %lld n , (answer + mul - 1) % 10);       else {         low = 0, high = answer + mul - 1, answer = 0;         while (low <= high) {           long long int mid = (low + high) / 2;           if (targetSubSum(mid) <= input) {             answer = mid;             low = mid + 1;           } else             high = mid - 1;         }         input -= targetSubSum(answer);         if (input == 0)           printf( %lld n , answer % 10);         else {           stack<int> s;           answer++;           while (answer) {             s.push(answer % 10);             answer /= 10;           }           for (int i = 1; i < input; i++) s.pop();           printf( %d n , s.top());         }       }       q--;     }   }


#include <bits/stdc++.h>   using namespace std;   long long BigMod(long long B, long long P, long long M) {     long long R = 1;     while (P > 0) {       if (P % 2 == 1) {         R = (R * B) % M;       }       P /= 2;       B = (B * B) % M;     }     return R;   }   template <class T1>   void deb(T1 e1) {     cout << e1 << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   const int MAX = 100060;   map<int, int> mpp;   int cnt[2][MAX];   int res[MAX];   int main() {     memset(cnt, (0), sizeof(cnt));     ;     vector<int> tmp, rval;     int v;     set<int> com;     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &v);       rval.push_back((v));       tmp.push_back((v));     }     sort(tmp.begin(), tmp.end());     for (int i = 0; i < n; i++) {       mpp[tmp[i]] = i + 1;     }     v = mpp[rval[0]];     com.insert(v);     for (int i = 1; i < n; i++) {       v = mpp[rval[i]];       auto it = com.lower_bound(v);       if (it != com.begin()) {         auto it1 = it;         it1--;         int u = (*it1);         if (cnt[0][u] != -1) {           res[i] = tmp[u - 1];           com.insert(v);           cnt[0][u]--;           continue;         }       }       if (it != com.end()) {         auto it1 = it;         int u = (*it1);         if (cnt[1][u] != -2) {           res[i] = tmp[u - 1];           com.insert(v);           cnt[1][u]--;           continue;         }       }     }     for (int i = 1; i < n; i++) {       if (i != 1) printf(   );       printf( %d , res[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     while (a != 0 && b != 0) {       if (a > b)         a %= b;       else         b = b % a;     }     return a + b;   }   int main() {     int k, l, m, n, d;     cin >> k >> l >> m >> n >> d;     int ans = 0;     for (int i = (1); i < (d + 1); i++)       if (i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0) ans++;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long rdtsc() {     long long tmp;     asm( rdtsc  :  =A (tmp));     return tmp;   }   inline int myrand() { return abs((rand() << 15) ^ rand()); }   inline int rnd(int x) { return myrand() % x; }   const long long INF = (long long)1e16 + 1;   const long double EPS = 1e-9;   struct SegmTree {     const static int maxn = (1 << 17);     int a[maxn * 2];     int n;     void build(int _n) {       for (n = 1; n < _n; n <<= 1)         ;       assert(n <= maxn);       for (int i = 1; i < 2 * n; ++i) a[i] = -1;     }     int get(int v) {       int res = -1;       for (v += n; v > 0; v >>= 1)         if (a[v] != -1) res = a[v];       return res;     }     void make(int v, int l, int r, int l0, int r0, int nval) {       if (l >= r0 || l0 >= r) return;       if (l0 <= l && r <= r0) {         a[v] = nval;         return;       }       if (a[v] != -1) a[2 * v] = a[2 * v + 1] = a[v], a[v] = -1;       int m = (l + r) / 2;       make(2 * v, l, m, l0, r0, nval);       make(2 * v + 1, m, r, l0, r0, nval);     }     void make(int l, int r, int nval) { make(1, 0, n, l, r, nval); }   } tree;   const int maxn = (int)1e5 + 10 + 1;   struct Vertex {     int x, y;     int g;     Vertex() {}     Vertex(int _x, int _y, int _g) : x(_x), y(_y), g(_g) {}   };   const int maxg = 4;   const int go[maxg + 1][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}, {0, 0}};   const char chgo[maxg] = { R ,  U ,  L ,  D };   int dir[maxn][2][2];   int dirg[maxn];   struct Event {     int type;     int x;     int l, r;     int id;     Event() {}     Event(int _type, int _x, int _y, int _id)         : type(_type), x(_x), l(_y), r(-1), id(_id) {       assert(type == 1);     }     Event(int _type, int _x, int _l, int _r, int _id)         : type(_type), x(_x), l(_l), r(_r), id(_id) {       assert(type == 2);     }     inline bool operator<(const Event &e) const {       if (x != e.x) return x < e.x;       return type > e.type;     }   };   Event evs[3 * maxn];   int n, b;   void rotate(int &x, int &y) {     int nx = b - y, ny = x;     x = nx, y = ny;   }   int gov[maxn * 2];   void fillGo(int cnt, Vertex *vs) {     for (int rot = 0; rot < maxg; ++rot) {       int m = 0;       for (int i = 0; i < cnt; ++i) {         if (vs[i].g != 2) continue;         evs[m++] = Event(1, vs[i].x, vs[i].y, i);       }       for (int i = 0; i < n; ++i) {         if (dir[i][0][0] == dir[i][1][0]) {           int l = dir[i][0][1], r = dir[i][1][1];           if (l > r) swap(l, r);           evs[m++] = Event(2, dir[i][0][0], l, r, i);         } else {           assert(dir[i][0][1] == dir[i][1][1]);           int x =               (dir[i][0][0] < dir[i][1][0]) ? dir[i][0][0] : (dir[i][1][0] + 1);           evs[m++] = Event(2, x, dir[i][0][1], dir[i][1][1], i);         }       }       sort(evs, evs + m);       tree.build(b + 1);       for (int i = 0; i < m; ++i) {         if (evs[i].type == 1) {           gov[evs[i].id] = tree.get(evs[i].l);         } else {           assert(evs[i].type == 2);           tree.make(evs[i].l, evs[i].r + 1, evs[i].id);         }       }       for (int i = 0; i < cnt; ++i) {         rotate(vs[i].x, vs[i].y);         vs[i].g += 1;         if (vs[i].g == 4) vs[i].g = 0;       }       for (int i = 0; i < n; ++i) {         for (int j = 0; j < 2; ++j) {           rotate(dir[i][j][0], dir[i][j][1]);         }       }     }   }   Vertex vs[maxn * 2 * 2];   int start[maxn][2];   int startDir[maxn];   long long startTime[maxn];   int mynext[maxn * 4];   int price[maxn * 4];   const int maxl = 50;   int pr[maxl][maxn * 4];   long long cs[maxl][maxn * 4];   int sign(int x) {     if (x < 0) return -1;     return !!x;   }   bool solve() {     if (scanf( %d%d , &n, &b) < 2) return 0;     int cnt = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < 2; ++j)         for (int k = 0; k < 2; ++k) scanf( %d , &dir[i][j][k]);       int dx = dir[i][1][0] - dir[i][0][0], dy = dir[i][1][1] - dir[i][0][1];       if (dx == 0) {         assert(dy != 0);         dy /= abs(dy);       } else {         assert(dy == 0);         dx /= abs(dx);       }       dirg[i] = -1;       for (int g = 0; g < maxg; ++g) {         if (go[g][0] == dx && go[g][1] == dy) dirg[i] = g;       }       assert(dirg[i] != -1);       vs[cnt++] = Vertex(dir[i][1][0], dir[i][1][1], dirg[i]);     }     int q;     scanf( %d , &q);     for (int iter = 0; iter < q; ++iter) {       char ch;       scanf(            %d%d %c             %lld ,           &start[iter][0], &start[iter][1], &ch, &startTime[iter]);       startDir[iter] = find(chgo, chgo + maxg, ch) - chgo;       assert(startDir[iter] != maxg);       vs[cnt++] = Vertex(start[iter][0], start[iter][1], startDir[iter]);     }     fillGo(cnt, vs);     int rcnt = cnt;     for (int i = 0; i < cnt; ++i) {       if (gov[i] == -1) {         mynext[i] = rcnt;         if (vs[i].g == 0) {           price[i] = b - vs[i].x;         } else {           if (vs[i].g == 1)             price[i] = b - vs[i].y;           else {             if (vs[i].g == 2)               price[i] = vs[i].x;             else {               assert(vs[i].g == 3);               price[i] = vs[i].y;             }           }         }         vs[rcnt] = Vertex(vs[i].x + go[vs[i].g][0] * price[i],                           vs[i].y + go[vs[i].g][1] * price[i], 4);         mynext[rcnt] = rcnt;         price[rcnt] = 1;         ++rcnt;         continue;       }       int crash = gov[i];       mynext[i] = crash;       price[i] = abs(vs[crash].x - vs[i].x) + abs(vs[crash].y - vs[i].y);     }     for (int i = 0; i < rcnt; ++i) {       pr[0][i] = mynext[i], cs[0][i] = price[i];     }     for (int it = 1; it < maxl; ++it) {       for (int v = 0; v < rcnt; ++v) {         pr[it][v] = pr[it - 1][pr[it - 1][v]];         cs[it][v] = cs[it - 1][v] + cs[it - 1][pr[it - 1][v]];         cs[it][v] = min(cs[it][v], INF);       }     }     for (int iter = 0; iter < q; ++iter) {       int v = iter + n;       long long left = startTime[iter];       for (int it = maxl - 1; it >= 0; --it) {         if (left >= cs[it][v]) {           left -= cs[it][v];           v = pr[it][v];         }       }       {         assert(left <= 3 * b + 5);         int x = vs[v].x, y = vs[v].y;         int nx = vs[pr[0][v]].x, ny = vs[pr[0][v]].y;         if (x != nx && y != ny) {           int dist1 = (vs[v].g & 1) ? (ny - y) : (nx - x);           x += go[vs[v].g][0] * min((int)left, abs(dist1));           y += go[vs[v].g][1] * min((int)left, abs(dist1));           left -= min((int)left, abs(dist1));         }         if (left > 0) {           if (nx != x) x += sign(nx - x) * (int)left;           if (ny != y) y += sign(ny - y) * (int)left;         }         printf( %d %d n , x, y);       }     }     return 1;   }   int main() {     srand(rdtsc());     while (1) {       if (!solve()) break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000 + 10;   const int INF = INT_MAX;   const double EXP = 0.0001;   void files() { freopen( output.txt ,  w , stdout); }   long long pow3(long long x) { return x * x * x; }   pair<int, long long> answer;   void solution(long long m, int step, long long cur) {     if (m == 0) {       answer = max(answer, make_pair(step, cur));       return;     }     long long x = 1;     while (pow3(x) <= m) x++;     x--;     solution(m - pow3(x), step + 1, cur + pow3(x));     if (x > 0) solution(pow3(x) - 1 - pow3(x - 1), step + 1, cur + pow3(x - 1));   }   int main() {     ios_base::sync_with_stdio(false);     long long m;     cin >> m;     solution(m, 0, 0);     cout << answer.first <<     << answer.second;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void ret(string s) {     cout << s;     exit(0);   }   int main() {     int n, m;     cin >> n >> m;     bool ok;     string s[100];     int xn = 200, xm = 0, yn = 200, ym = 0;     for (int i = 0; i < n; i++) {       cin >> s[i];       for (int j = 0; j < s[i].length(); j++)         if (s[i][j] ==  * ) {           xn = min(xn, j);           xm = max(xm, j);           yn = min(yn, i);           ym = max(yn, i);         }     }     for (int i = yn; i <= ym; i++) {       for (int j = xn; j <= xm; j++) cout << s[i][j];       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 2, M = 1e9 + 7, OO = 0x3f3f3f3f;   int n, m, u, v;   int ic[N];   int fc[N];   int adj[N][N];   pair<int, int> p[N];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> ic[i];     for (int i = 0; i < m; i++) {       cin >> u >> v;       u--;       v--;       fc[u] += ic[v];       fc[v] += ic[u];       adj[u][v] = 1;       adj[v][u] = 1;     }     for (int i = 0; i < n; ++i) p[i] = {ic[i], i};     sort(p, p + n);     int ans = 0;     int t;     int r = n;     while (r--) {       t = p[r].second;       ans += fc[t];       for (int i = 0; i < n; ++i) {         if (adj[t][i]) {           fc[i] -= ic[t];           adj[i][t] = 0;           adj[t][i] = 0;         }       }       fc[t] = OO;       sort(p, p + n);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   template <typename T>   void MACRO_VAR_Scan(T& t) {     std::cin >> t;   }   template <typename First, typename... Rest>   void MACRO_VAR_Scan(First& first, Rest&... rest) {     std::cin >> first;     MACRO_VAR_Scan(rest...);   }   template <typename T>   void MACRO_VEC_ROW_Init(int n, T& t) {     t.resize(n);   }   template <typename First, typename... Rest>   void MACRO_VEC_ROW_Init(int n, First& first, Rest&... rest) {     first.resize(n);     MACRO_VEC_ROW_Init(n, rest...);   }   template <typename T>   void MACRO_VEC_ROW_Scan(int p, T& t) {     std::cin >> t[p];   }   template <typename First, typename... Rest>   void MACRO_VEC_ROW_Scan(int p, First& first, Rest&... rest) {     std::cin >> first[p];     MACRO_VEC_ROW_Scan(p, rest...);   }   template <class T>   inline T CHMAX(T& a, const T b) {     return a = (a < b) ? b : a;   }   template <class T>   inline T CHMIN(T& a, const T b) {     return a = (a > b) ? b : a;   }   template <class T>   using V = std::vector<T>;   template <class T>   using VV = V<V<T>>;   template <typename S, typename T>   std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {     os <<  (  << p.first <<  ,   << p.second <<  ) ;     return os;   }   using ll = long long;   using ull = unsigned long long;   using ld = long double;   using PAIR = std::pair<ll, ll>;   using PAIRLL = std::pair<ll, ll>;   constexpr ll INFINT = 1 << 30;   constexpr ll INFINT_LIM = (1LL << 31) - 1;   constexpr ll INFLL = 1LL << 60;   constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);   constexpr double EPS = 1e-6;   constexpr ll MOD = 1000000007;   constexpr double PI = 3.141592653589793238462643383279;   template <class T, size_t N>   void FILL(T (&a)[N], const T& val) {     for (auto& x : a) x = val;   }   template <class ARY, size_t N, size_t M, class T>   void FILL(ARY (&a)[N][M], const T& val) {     for (auto& b : a) FILL(b, val);   }   template <class T>   void FILL(std::vector<T>& a, const T& val) {     for (auto& x : a) x = val;   }   template <class ARY, class T>   void FILL(std::vector<std::vector<ARY>>& a, const T& val) {     for (auto& b : a) FILL(b, val);   }   signed main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     ;     ll n, m;     MACRO_VAR_Scan(n, m);     ;     std::vector<ll> a, b;     MACRO_VEC_ROW_Init(m, a, b);     for (ll w_ = 0; w_ < m; ++w_) {       MACRO_VEC_ROW_Scan(w_, a, b);     };     std::vector<std::vector<ll>> g(n);     for (ll i = 0; i < ll(m); ++i) {       --a[i];       --b[i];       g[a[i]].emplace_back(b[i]);     }     std::vector<ll> min(n, INFLL);     for (ll i = 0; i < ll(n); ++i) {       for (ll x : g[i]) {         ll cost = x - i;         if (cost <= 0) cost += n;         CHMIN(min[i], cost);       }     }     for (ll i = 0; i < ll(n); ++i) {       ll ans = 0;       for (ll j = 0; j < ll(n); ++j) {         ll J = (i + j) % n;         if (g[J].empty()) continue;         ll len = g[J].size();         ll sum = (len - 1) * n + j + min[J];         CHMAX(ans, sum);       }       std::cout << (ans);       std::cout << (i + 1 == n ?   n  :    );       ;     }     return 0;   }


#include <bits/stdc++.h>   const int N = 1000005;   using namespace std;   int n, m, t = 0, tot = 0, cnt = 0, q[N];   int dl[N], dr[N], vis[N][27];   int edge[N], nxt[N], lst[N], pt[N], fail[N], val[N], nm[N], vvis[N];   string s;   struct nn {     int lx, rx, num;   } tr[N << 2];   void add(int x, int y) {     edge[++t] = y;     nxt[t] = lst[x];     lst[x] = t;   }   void insert(string s, int id) {     int len = s.length(), pos = 0;     for (int i = 0; i < len; i++) {       int c = s[i] -  a  + 1;       if (!vis[pos][c]) tot++, vis[pos][c] = tot;       pos = vis[pos][c];     }     pt[id] = pos;     val[pos] = 1;   }   void build_trie() {     int pos = 0, l = 0, r = 0;     for (int i = 1; i <= 26; i++)       if (vis[pos][i]) {         r++;         q[r] = vis[pos][i];         fail[vis[pos][i]] = pos;         add(pos, vis[pos][i]);       }     while (l < r) {       l++;       pos = q[l];       for (int i = 1; i <= 26; i++) {         if (vis[pos][i]) {           int f = fail[pos];           while (f && !vis[f][i]) f = fail[f];           fail[vis[pos][i]] = vis[f][i];           add(vis[f][i], vis[pos][i]);           r++;           q[r] = vis[pos][i];         } else           vis[pos][i] = vis[fail[pos]][i];       }     }   }   void build_tree(int x, int num) {     cnt++;     dl[x] = dr[x] = cnt;     nm[dl[x]] = num;     for (int r = lst[x]; r; r = nxt[r]) {       build_tree(edge[r], num + val[edge[r]]);       dr[x] = max(dr[x], dr[edge[r]]);     }   }   void chang(int x, int l, int r, int l1, int r1, int yh) {     if (l1 <= l && r <= r1) {       tr[x].num += yh;       return;     }     int mid = (l + r) >> 1;     if (l1 > mid)       chang(tr[x].rx, mid + 1, r, l1, r1, yh);     else if (r1 <= mid)       chang(tr[x].lx, l, mid, l1, r1, yh);     else {       chang(tr[x].lx, l, mid, l1, mid, yh);       chang(tr[x].rx, mid + 1, r, mid + 1, r1, yh);     }     return;   }   void build_segtree(int x, int l, int r) {     if (l == r) {       tr[x].num = nm[l];       return;     }     int mid = (l + r) >> 1;     tr[x].lx = x + 1;     tr[x].rx = (mid - l + 1) * 2 + x;     build_segtree(tr[x].lx, l, mid);     build_segtree(tr[x].rx, mid + 1, r);   }   int chk(int x, int l, int r, int goal) {     int res = 0;     if (l == r) return tr[x].num;     res += tr[x].num;     int mid = (l + r) >> 1;     if (goal > mid) return res + chk(tr[x].rx, mid + 1, r, goal);     return res + chk(tr[x].lx, l, mid, goal);   }   int search(string s) {     int len = s.length(), pos = 0, ans = 0;     for (int i = 1; i < len; i++) {       int c = s[i] -  a  + 1;       pos = vis[pos][c];       ans += chk(1, 1, cnt, dl[pos]);     }     return ans;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       cin >> s;       insert(s, i);     }     build_trie();     build_tree(0, 0);     build_segtree(1, 1, cnt);     for (int i = 1; i <= n; i++) {       cin >> s;       if (s[0] ==  -  || s[0] ==  + ) {         int yh = 0, len = s.length();         for (int i = 1; i < len; i++) {           yh = yh * 10 + s[i] -  0 ;         }         if (s[0] ==  - )           if (vvis[yh] == 0)             chang(1, 1, cnt, dl[pt[yh]], dr[pt[yh]], -1), vvis[yh] = 1;         if (s[0] ==  + )           if (vvis[yh] == 1)             chang(1, 1, cnt, dl[pt[yh]], dr[pt[yh]], 1), vvis[yh] = 0;       } else {         printf( %d n , search(s));       }     }   }


#pragma GCC optimize( Ofast,unroll-loops )   #pragma GCC target( avx,avx2,sse,sse2,ssse3,sse4,mmx,popcnt )   #include <bits/stdc++.h>   #define ar array      using namespace std;   using ll = long long;      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());      const int mxN = 2e5, mxM = 60;   int n, m, p;   vector<int> a[mxN];   using S = bitset<mxN>;   S a_inv[mxM];      ll ans = 0;      void solve(int start) {     int k = (int)a[start].size();        int best = 0;     int best_cnt = __builtin_popcountll(ans);        for (int s = 1; s < 1<<k; ++s) {       if (__builtin_popcount(s) <= best_cnt) continue;       S agree; agree.set();       for (int kk = 0; kk < k; ++kk) {         if (!(s & (1<<kk))) continue;         agree &= a_inv[a[start][kk]];       }       if ((int)agree.count()*2 >= n) best = s, best_cnt = __builtin_popcount(s);     }        if (best_cnt > __builtin_popcountll(ans)) {       ans = 0;       for (int kk = 0; kk < k; ++kk) {         if (!(best & (1<<kk))) continue;         ans |= (1LL<<a[start][kk]);       }     }   }      int main() {     cin.tie(0)->sync_with_stdio(0);        // since 50% need to agree, any random guy has at least 50% chance of being in the set     // need to only select a few people        cin >> n >> m >> p;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         char c; cin >> c;         if (c ==  1 ) a[i].push_back(j);       }     }        for (int i = 0; i < n; ++i)       for (int j : a[i])         a_inv[j].set(i);        uniform_int_distribution<int> random_i(0, n-1);        for (int rep = 0; rep < 10; ++rep) {       int i = random_i(rng);       solve(i);     }        for (int i = 0; i < m; ++i) {       cout << (ans&1);       ans /= 2;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const double eps = 1e-8;   const int mod = 1000000007;   const double pi = acos(-1.0);   inline void gn(long long& x) {     int sg = 1;     char c;     while (((c = getchar()) <  0  || c >  9 ) && c !=  - )       ;     c ==  -  ? (sg = -1, x = 0) : (x = c -  0 );     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;     x *= sg;   }   inline void gn(int& x) {     long long t;     gn(t);     x = t;   }   inline void gn(unsigned long long& x) {     long long t;     gn(t);     x = t;   }   long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }   long long powmod(long long a, long long x, long long mod) {     long long t = 1ll;     while (x) {       if (x & 1) t = t * a % mod;       a = a * a % mod;       x >>= 1;     }     return t;   }   const int maxn = 222222;   pair<int, int> pp[maxn];   map<int, int> need;   int fix[maxn];   map<int, vector<int> > hasid;   map<int, int> has;   int val[maxn];   int main() {     int n, m;     int totmatch = 0, totfix = 0;     memset((fix), 0, sizeof(fix));     gn(n);     gn(m);     for (int i = (1); i <= (n); i++) {       int x;       gn(x);       need[x]++;       val[i] = x;     }     for (int i = (1); i <= (m); i++) {       int vv;       gn(vv);       pp[i].first = vv;       pp[i].second = i;     }     sort(pp + 1, pp + 1 + m);     for (int i = (1); i <= (m); i++) {       int p = pp[i].first;       p = p * 2;       int tmp = -1;       while (true) {         if (p == 1) break;         p = (p + 1) / 2;         tmp++;         if (need.count(p) && has[p] < need[p]) break;       }       if (need.count(p) && has[p] < need[p]) {         totfix += tmp;         fix[pp[i].second] = tmp;         hasid[p].push_back(pp[i].second);         totmatch++;         has[p]++;       }     }     printf( %d %d n , totmatch, totfix);     for (int i = (1); i <= (m); i++) printf( %d  , fix[i]);     puts(  );     for (int i = (1); i <= (n); i++) {       if (!need.count(val[i]))         printf( 0  );       else {         if (hasid[val[i]].size() > 0) {           printf( %d  , hasid[val[i]].back());           hasid[val[i]].pop_back();         } else {           printf( %d  , 0);         }       }     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int h1, a1, c, h2, a2, h;     cin >> h1 >> a1 >> c >> h2 >> a2;     vector<string> v;     h = h1;     while (h2 > 0) {       if ((a1 >= h2) || h1 > a2) {         v.push_back( STRIKE );         h2 -= a1;       } else {         v.push_back( HEAL );         h1 += c;       }       h1 -= a2;     }     cout << v.size() << endl;     for (string s : v) cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( -Ofast,unroll-loops )   #pragma GCC target( avx2 )   std::mt19937 rnd(237);   using namespace std;   const int N = 2e5, mod = 1e9 + 7;   int n, m, type[N], cmp[N], cmp_p = 0;   vector<array<int, 2>> g1[N], g2[N];   long long dfs(int v) {     cmp[cmp_p++] = v;     long long ans = (type[v] ? 0 : 1);     for (auto &[u, c] : g1[v]) {       if (~type[u]) {         if (type[v] && type[u] != c) return -2e9;         if (!type[v] && type[u] == c) return -2e9;       } else {         type[u] = (type[v] ? c : 1 - c);         ans += dfs(u);       }     }     for (auto &[u, c] : g2[v]) {       if (~type[u]) {         if (type[u] == 1 && type[v] != c) return -2e9;         if (type[u] == 0 && type[v] == c) return -2e9;       } else {         type[u] = (type[v] == c ? 1 : 0);         ans += dfs(u);       }     }     return ans;   }   void solve() {     cin >> n >> m;     fill(type, type + n, -1);     cmp_p = 0;     for (int i = 0; i < n; ++i) {       g1[i].clear();       g2[i].clear();     }     for (int i = 0; i < m; ++i) {       int u, v;       string s;       cin >> u >> v >> s;       --u, --v;       if (s ==  crewmate ) {         g1[u].push_back({v, 1});         g2[v].push_back({u, 1});       } else {         g1[u].push_back({v, 0});         g2[v].push_back({u, 0});       }     }     long long ans = 0;     for (int i = 0; i < n; ++i) {       if (type[i] == -1) {         long long mx = -2e9;         type[i] = 1;         cmp_p = 0;         mx = max(mx, dfs(i));         for (int j = 0; j < cmp_p; ++j) {           type[cmp[j]] = -1;         }         type[i] = 0;         cmp_p = 0;         mx = max(mx, dfs(i));         ans += mx;       }     }     cout << (ans < 0 ? -1 : ans);   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt = 1;     cin >> tt;     while (tt--) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   int check(int num1, int num2);   using namespace std;   int main() {     int k, l, m, n, d;     cin >> k;     cin >> l;     cin >> m;     cin >> n;     cin >> d;     int total = 0;     for (int i = 1; i < d + 1; i++) {       if (check(i, k) || check(i, l) || check(i, m) || check(i, n)) {         total++;       }     }     cout << total << endl;     return 0;   }   int check(int num1, int num2) {     if (num1 % num2 == 0) {       return 1;     } else {       return 0;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > con[3];   vector<pair<long long, long long> > sum;   int main() {     for (long long i = 0; i < ((long long)3); i++) {       long long n;       cin >> n;       for (long long j = 0; j < ((long long)n); j++) {         long long x, y;         cin >> x >> y;         con[i].push_back(make_pair(x, y));       }     }     long long pos[3] = {1, 1, 1};     long long start[3] = {1, 1, 1};     for (long long i = 0; i < ((long long)3); i++)       for (long long j = 0; j < ((long long)((long long)con[i].size())); j++)         if (con[i][start[i]] < con[i][j]) pos[i] = start[i] = j;     long long sum_x = 0;     long long sum_y = 0;     bool f[3] = {true, true, true};     while (pos[0] != start[0] || pos[1] != start[1] || pos[2] != start[2] ||            f[0] || f[1] || f[2]) {       double ang[3] = {0, 0, 0};       long long next[3] = {(pos[0] + 1) % ((long long)con[0].size()),                            (pos[1] + 1) % ((long long)con[1].size()),                            (pos[2] + 1) % ((long long)con[2].size())};       for (long long i = 0; i < ((long long)3); i++) {         double xx = (con[i][next[i]].first) - (con[i][pos[i]].first);         double yy = (con[i][next[i]].second) - (con[i][pos[i]].second);         ang[i] = (yy == 0) ? (acos(-1) / 2.0) : acos(yy / hypot(xx, yy));         if (0 < xx) ang[i] = acos(-1) * 2.0 - ang[i];         if (ang[i] == 0) ang[i] = acos(-1) * 2.0;         if (pos[i] == start[i] && !f[i]) ang[i] = 365;       }       long long mini = 0;       for (long long i = 0; i < ((long long)3); i++)         if (ang[i] < ang[mini]) mini = i;       pos[mini] = next[mini];       f[mini] = false;       sum_x = sum_y = 0;       for (long long i = 0; i < ((long long)3); i++)         sum_x += (con[i][pos[i]].first);       for (long long i = 0; i < ((long long)3); i++)         sum_y += (con[i][pos[i]].second);       sum.push_back(make_pair(sum_x, sum_y));     }     vector<pair<long long, long long> > low, high;     long long mini = 0, maxi = 0;     long long mini_y[2], maxi_y[2];     for (long long i = 0; i < ((long long)((long long)sum.size())); i++)       if (sum[i] < sum[mini]) mini = i;     for (long long i = 0; i < ((long long)((long long)sum.size())); i++)       if (sum[maxi] < sum[i]) maxi = i;     for (int i = mini; i != maxi; i = (i + 1) % ((long long)sum.size()))       low.push_back(sum[i]);     for (int i = mini; i != maxi;          i = (i + ((long long)sum.size()) - 1) % ((long long)sum.size()))       high.push_back(sum[i]);     low.push_back(sum[maxi]);     high.push_back(sum[maxi]);     for (long long i = 0; i < ((long long)2); i++) mini_y[i] = sum[mini].second;     for (long long i = 0; i < ((long long)2); i++) maxi_y[i] = sum[maxi].second;     for (long long i = 0; i < ((long long)((long long)sum.size())); i++)       if (sum[i].first == sum[mini].first) {         mini_y[0] = min(mini_y[0], sum[i].second);         mini_y[1] = max(mini_y[1], sum[i].second);       }     for (long long i = 0; i < ((long long)((long long)sum.size())); i++)       if (sum[i].first == sum[maxi].first) {         maxi_y[0] = min(maxi_y[0], sum[i].second);         maxi_y[1] = max(maxi_y[1], sum[i].second);       }     sort(low.begin(), low.end());     sort(high.begin(), high.end());     long long n;     cin >> n;     for (long long i = 0; i < ((long long)n); i++) {       long long xx, yy;       cin >> xx >> yy;       xx *= 3;       yy *= 3;       if (xx == sum[maxi].first) {         if (maxi_y[0] <= yy && yy <= maxi_y[1])           cout <<  YES  << endl;         else           cout <<  NO  << endl;       } else if (xx == sum[mini].first) {         if (mini_y[0] <= yy && yy <= mini_y[1])           cout <<  YES  << endl;         else           cout <<  NO  << endl;       } else if (sum[mini].first < xx && xx < sum[maxi].first) {         vector<pair<long long, long long> >::iterator lp0 =             upper_bound(low.begin(), low.end(), make_pair(xx, yy));         vector<pair<long long, long long> >::iterator hp0 =             upper_bound(high.begin(), high.end(), make_pair(xx, yy));         vector<pair<long long, long long> >::iterator lp1 = lp0--;         vector<pair<long long, long long> >::iterator hp1 = hp0--;         long long ldx = lp1->first - lp0->first;         long long ldy = lp1->second - lp0->second;         long long hdx = hp1->first - hp0->first;         long long hdy = hp1->second - hp0->second;         if (ldx * lp0->second - ldy * lp0->first + ldy * xx <= ldx * yy &&             hdx * yy <= hdx * hp0->second - hdy * hp0->first + hdy * xx) {           cout <<  YES  << endl;         } else {           cout <<  NO  << endl;         }       } else {         cout <<  NO  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5050;   int n, b, c[MAXN], d[MAXN], fa[MAXN], sum[MAXN], f[MAXN][MAXN], g[MAXN][MAXN];   int buff[MAXN], bufg[MAXN];   int main() {     memset(f, 63, sizeof(f));     memset(g, 63, sizeof(g));     scanf( %d%d , &n, &b);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &c[i], &d[i]);       if (i > 1) scanf( %d , &fa[i]);       sum[i] = 1;       f[i][1] = c[i] - d[i];       g[i][0] = 0;       g[i][1] = c[i];       if (f[i][1] > b && g[i][1] > b) sum[i] = 0;     }     for (int i = n; i >= 2; i--) {       memcpy(buff, f[fa[i]], sizeof(buff));       memcpy(bufg, g[fa[i]], sizeof(bufg));       for (int j = 0; j <= sum[i]; j++)         for (int k = 0; k <= sum[fa[i]]; k++) {           f[fa[i]][j + k] = min(f[fa[i]][j + k], min(f[i][j], g[i][j]) + buff[k]);           g[fa[i]][j + k] = min(g[fa[i]][j + k], g[i][j] + bufg[k]);         }       sum[fa[i]] += sum[i];     }     for (int i = n; i; --i) {       if (f[1][i] <= b || g[1][i] <= b) {         printf( %d , i);         return 0;       }     }     printf( 0 );     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, q;     std::cin >> n >> q;     std::vector<std::pair<int, int>> a(q);     std::vector<int> cnt(n), k1(q), pr(n, -1);     std::vector<std::vector<int>> k2(q, std::vector<int>(q));     for (auto &i : a) {       std::cin >> i.first >> i.second;       --i.first;       --i.second;     }     for (auto i : a) {       for (int j = i.first; j <= i.second; ++j) {         ++cnt[j];       }     }     for (int i = 0; i < q; ++i) {       for (int j = a[i].first; j <= a[i].second; ++j) {         if (cnt[j] == 1) {           ++k1[i];         }       }     }     for (int i = 0; i < q; ++i) {       for (int j = a[i].first; j <= a[i].second; ++j) {         if (cnt[j] == 2) {           if (pr[j] == -1) {             pr[j] = i;           } else {             ++k2[pr[j]][i];           }         }       }     }     int max = 0, sum = 0;     for (int i = 0; i < n; ++i) {       if (cnt[i] > 0) ++sum;     }     for (int i = 0; i < q; ++i) {       for (int j = i + 1; j < q; ++j) {         max = std::max(max, sum - k1[i] - k1[j] - k2[i][j]);       }     }     std::cout << max;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp_x(const complex<double>& a, const complex<double>& b) {     return abs(a.real() - b.real()) < 1e-6 ? a.imag() < b.imag()                                            : a.real() < b.real();   }   bool cmp_y(const complex<double>& a, const complex<double>& b) {     return abs(a.imag() - b.imag()) < 1e-6 ? a.real() < b.real()                                            : a.imag() < b.imag();   }   double cross(complex<double> a, complex<double> b) {     return (conj(a) * b).imag();   }   vector<complex<double> > convex_hull(vector<complex<double> > ps) {     sort(ps.begin(), ps.end(), cmp_x);     int n = ps.size(), k = 0;     vector<complex<double> > qs(n * 2);     for (int i = 0; i < n; i++) {       while (k > 1 && cross(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0) k--;       qs[k++] = ps[i];     }     for (int i = n - 2, t = k; i >= 0; i--) {       while (k > t && cross(qs[k - 1] - qs[k - 2], ps[i] - qs[k - 1]) <= 0) k--;       qs[k++] = ps[i];     }     qs.resize(k - 1);     return qs;   }   int n;   int a[505][505];   bool vis[505][505];   bool used[505][505];   int di[] = {0, 0, 1, 1}, dj[] = {0, 1, 0, 1};   int dd[] = {-1, 0, 1, 0, -1};   vector<complex<double> > ps;   bool isvalid_point(int i, int j) {     return i >= 0 && i <= n && j >= 0 && j <= n;   }   bool isvalid_a(int i, int j) { return i >= 0 && i < n && j >= 0 && j < n; }   int main() {     cin.sync_with_stdio(false);     while (1) {       cin >> n;       if (n == 0) break;       memset(a, 0, sizeof(a));       memset(used, 0, sizeof(used));       memset(vis, 0, sizeof(vis));       ps.clear();       for (long long i = (long long)(0); i < (long long)(n); i++) {         string s;         cin >> s;         for (long long j = (long long)(0); j < (long long)(n); j++) {           a[i][j] = s[j] -  0 ;         }       }       queue<complex<double> > que;       for (long long i = (long long)(0); i < (long long)(n); i++)         for (long long j = (long long)(0); j < (long long)(n); j++) {           if (a[i][j] == 0) {             que.push(complex<double>(i, j));             vis[i][j] = true;           }         }       while (que.size()) {         complex<double> np = que.front();         que.pop();         int i = np.real(), j = np.imag();         for (long long dir = (long long)(0); dir < (long long)(4); dir++) {           int ni = i + di[dir], nj = j + dj[dir];           if (!isvalid_point(ni, nj)) continue;           if (used[ni][nj]) continue;           used[ni][nj] = true;           if (a[i][j] > 0) {             ps.push_back(complex<double>(ni, nj));           }         }         for (long long dir = (long long)(0); dir < (long long)(4); dir++) {           int ni = i + dd[dir], nj = j + dd[dir + 1];           if (!isvalid_a(ni, nj)) continue;           if (vis[ni][nj]) continue;           int cnt = 0;           for (long long ndir = (long long)(0); ndir < (long long)(4); ndir++) {             int nni = ni + di[ndir], nnj = nj + dj[ndir];             if (!isvalid_point(nni, nnj)) continue;             if (used[nni][nnj]) cnt++;           }           if (a[ni][nj] + cnt == 4) {             que.push(complex<double>(ni, nj));             vis[ni][nj] = true;           }         }       }       vector<complex<double> > res = convex_hull(ps);       reverse((res).begin(), (res).end());       vector<complex<double> > tmp(res.size());       for (long long i = (long long)(0); i < (long long)(res.size()); i++) {         tmp[i] = complex<double>((int)res[i].imag(), n - (int)res[i].real());       }       res = tmp;       int idx = 0;       for (long long i = (long long)(0); i < (long long)(res.size()); i++) {         if (cmp_x(res[i], res[idx])) idx = i;       }       printf( %d n , (int)res.size());       for (long long i = (long long)(0); i < (long long)(res.size()); i++) {         printf( %d %d n , (int)res[(idx + i) % res.size()].real(),                (int)res[(idx + i) % res.size()].imag());       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 500 * 1000 + 10;   int n, h[Maxn], ans;   vector<int> adj[Maxn], vec;   bool mark[Maxn];   void dfs(int v) {     mark[v] = true;     if ((int)adj[v].size() == 1) vec.push_back(h[v]);     for (int i = 0; i < (int)adj[v].size(); i++)       if (!mark[adj[v][i]]) {         h[adj[v][i]] = h[v] + 1;         dfs(adj[v][i]);       }     return;   }   int main() {     scanf( %d , &n);     int u, v;     for (int i = 0; i < n - 1; i++) {       scanf( %d%d , &u, &v);       u--;       v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     mark[0] = true;     for (int i = 0; i < (int)adj[0].size(); i++) {       dfs(adj[0][i]);       sort(vec.begin(), vec.end());       reverse(vec.begin(), vec.end());       int cnt = 1;       for (int j = 0; j < (int)vec.size(); j++) {         if (vec[j] + cnt > ans) ans = vec[j] + cnt;         cnt++;       }       vec.clear();     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   void solve() {     string p, h;     cin >> p >> h;     swap(p, h);     sort(h.begin(), h.end());     for (long long i = 0; i + h.size() - 1 < p.size(); ++i) {       string temp = p.substr(i, h.size());       sort(temp.begin(), temp.end());       if (temp == h) {         cout <<  YES n ;         return;       }     }     cout <<  NO n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   enum { UP, DOWN, LEFT, RIGHT };   const int MaxN = 1005;   const int MaxM = MaxN * MaxN;   const int oo = 0x3F3F3F3F;   char mp[MaxN][MaxN];   int dir[MaxM][4];   int d[MaxM][4];   int id[MaxN][MaxN], K;   int R, C, s, t;   struct Node {     int u, dir, d;     Node() {}     Node(int u, int dir, int d) : u(u), dir(dir), d(d) {}   };   void BFS() {     deque<Node> q;     Node u, v;     memset(d, 0x3F, sizeof(d));     q.push_back(Node(s, RIGHT, 0));     d[s][RIGHT] = 0;     while (!q.empty()) {       u = q.front();       q.pop_front();       if (d[u.u][u.dir] != u.d) continue;       for (int i = 0; i < 4; i++) {         if (dir[u.u][i]) {           v.u = dir[u.u][i];           v.dir = i;           v.d = u.d + (i != u.dir);           if (d[v.u][v.dir] > v.d) {             d[v.u][v.dir] = v.d;             if (i != u.dir)               q.push_back(v);             else               q.push_front(v);           }         }       }     }   }   int main() {     while (scanf( %d%d , &R, &C) == 2) {       for (int i = 0; i < R; i++) {         scanf( %s , mp[i]);         for (int j = 0; j < C; j++) {           if (mp[i][j] ==  # ) {             id[i][j] = ++K;           } else {             id[i][j] = 0;           }         }       }       s = ++K;       t = ++K;       fill(dir[s], dir[s] + 4, 0);       fill(dir[t], dir[t] + 4, 0);       for (int i = 0; i < R; i++) {         int last = i == 0 ? s : 0;         for (int j = 0; j < C; j++) {           if (mp[i][j] ==  # ) {             if (i == 0 && dir[s][RIGHT] == 0) dir[s][RIGHT] = id[i][j];             dir[id[i][j]][LEFT] = last;             last = id[i][j];           }         }         last = i == R - 1 ? t : 0;         for (int j = C - 1; j >= 0; j--) {           if (mp[i][j] ==  # ) {             if (i == R - 1 && dir[t][LEFT] == 0) dir[t][LEFT] = id[i][j];             dir[id[i][j]][RIGHT] = last;             last = id[i][j];           }         }       }       for (int j = 0; j < C; j++) {         int last = 0;         for (int i = 0; i < R; i++) {           if (mp[i][j] ==  # ) {             dir[id[i][j]][UP] = last;             last = id[i][j];           }         }         last = 0;         for (int i = R - 1; i >= 0; i--) {           if (mp[i][j] ==  # ) {             dir[id[i][j]][DOWN] = last;             last = id[i][j];           }         }       }       BFS();       if (d[t][RIGHT] == oo)         puts( -1 );       else         printf( %d n , d[t][RIGHT]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void PLAY() {     cout << fixed << setprecision(10);     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     deque<long long> x;     map<long long, long long> h;     for (int i = 0; i < n; i++) {       long long f;       cin >> f;       if (h[f] == 0) {         h[f] = 1;         x.push_back(f);         long long l = x.size();         if (l == k + 1) {           h[x.front()] = 0;           x.pop_front();         }       }     }     cout << x.size() << endl;     reverse(x.begin(), x.end());     long long l = x.size();     for (auto it : x) {       cout << it <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T;     cin >> T;     while (T--) {       int N;       cin >> N;       for (int i = 0; i < N; i++) cout <<  1  ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long n, m, ans = 0;   long long d[N], h[N];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (long long i = 1; i <= m; i++) cin >> d[i] >> h[i];     for (long long i = 2; i <= m; i++) {       long long maxdiff = abs(d[i] - d[i - 1]);       if (abs(h[i] - h[i - 1]) > maxdiff) {         cout <<  IMPOSSIBLE ;         return 0;       }     }     ans = max(h[1] + abs(d[1] - 1), h[m] + abs(n - d[m]));     for (long long i = 1; i <= m - 1; i++) {       long long extradays = d[i + 1] - d[i] - abs(h[i + 1] - h[i]);       long long maxh = max(h[i], h[i + 1]);       ans = max(ans, maxh + extradays / 2);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   bool vis1[100005], vis2[100005];   vector<int> e1[100005], e2[100005];   queue<int> q1, q2;   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       e1[x].push_back(y);       e2[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       if (a[i] == 1) {         vis1[i] = 1;         q1.push(i);       }     }     while (!q1.empty()) {       int now = q1.front();       q1.pop();       for (int i = 0; i < e1[now].size(); i++) {         int v = e1[now][i];         if (a[v] == 1 || vis1[v]) continue;         vis1[v] = 1;         q1.push(v);       }     }     for (int i = 1; i <= n; i++) {       if (a[i] == 2) {         vis2[i] = 1;         q2.push(i);       }     }     while (!q2.empty()) {       int now = q2.front();       q2.pop();       for (int i = 0; i < e2[now].size(); i++) {         int v = e2[now][i];         if (a[v] == 1) vis2[v] = 1;         if (a[v] == 1 || vis2[v]) continue;         vis2[v] = 1;         q2.push(v);       }     }     for (int i = 1; i <= n; i++)       if (vis1[i] && vis2[i])         printf( 1 n );       else         printf( 0 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int m;     cin >> m;     int i;     map<int, int> ipattern;     for (i = 1; i <= n; i++) {       int x;       cin >> x;       ipattern[i] = x;     }     int max = 0;     for (i = 1; i <= n; i++) {       if (ipattern[i] > max) {         max = ipattern[i];       }     }     int r = max % m;     int an = max / m;     if (r == 0)       an = an - 1;     else {       an = an;     }     int j;     if (an == 0) {       cout << n;     } else {       for (j = 1; j <= an; j++) {         for (i = 1; i <= n; i++) {           if ((ipattern[i] - m) <= 0) {             ipattern.erase(i);           } else {             ipattern[i] = ipattern[i] - m;           }         }       }       int y;       for (auto itr = ipattern.begin(); itr != ipattern.end(); ++itr) {         y = itr->first;       }       cout << y << endl;     }   }


#include <bits/stdc++.h>   int height;   std::vector<int> graph[1 + 127];   bool mark[1 + 127];   int answer;   void setup(void) {     scanf( %d , &height);     for (int i = 1; i <= 127; i++) {       graph[i].clear();       mark[i] = false;     }     answer = 0;   }   void ask(int v) {     if (!graph[v].empty()) {       return;     }     printf( ? %d n , v);     fflush(stdout);     int k;     scanf( %d , &k);     if (k == 0) exit(0);     for (int i = 0; i < k; i++) {       int u;       scanf( %d , &u);       graph[v].push_back(u);     }     if (k == 2) answer = v;   }   void guess(int v) {     printf( ! %d n , v);     fflush(stdout);   }   int find_leaf(int v, std::list<int>& path, bool prepend) {     ask(v);     mark[v] = true;     if (graph[v].size() == 1) return v;     for (auto u : graph[v]) {       if (!mark[u]) {         if (prepend)           path.push_front(u);         else           path.push_back(u);         return find_leaf(u, path, prepend);       }     };     throw -1;   }   int following(int v) {     for (auto u : graph[v])       if (!mark[u]) return u;     return v;   }   bool reachable(int v, int parent, int depth) {     ask(v);     if (depth == 0) return true;     if (answer) {       return true;     }     for (auto u : graph[v]) {       if (u != parent) return reachable(u, v, depth - 1);     }     return false;   }   bool within(int v, int parent, int depth) {     ask(v);     if (answer) {       return true;     }     if (depth > 0) {       for (auto u : graph[v]) {         if (u != parent && within(u, v, depth - 1)) return true;       }     }     return false;   }   int main(void) {     int t;     scanf( %d , &t);     while (t--) {       setup();       if (height == 0) break;       std::list<int> path;       path.push_front(1);       find_leaf(1, path, true);       find_leaf(1, path, false);       int altitude = path.size() / 2 + 1;       int par = *std::next(path.begin(), altitude - 1);       int v = following(par);       altitude++;       for (; altitude < height && altitude < 5 && !answer; altitude++) {         ask(v);         int u, w;         if (graph[v][0] == par) {           u = graph[v][1];           w = graph[v][2];         } else if (graph[v][1] == par) {           u = graph[v][0];           w = graph[v][2];         } else {           u = graph[v][0];           w = graph[v][1];         }         int next;         if (reachable(u, v, altitude)) {           next = u;         } else {           next = w;         }         par = v;         v = next;       };       if (!answer) {         if (altitude == height + 1) {           answer = par;         } else if (altitude == height) {           answer = v;         } else {           ask(v);           std::vector<int> candidates;           if (altitude == height - 1) {             ;             for (auto u : graph[v]) {               if (u != par) candidates.push_back(u);             }           } else if (altitude == height - 2) {             ;             for (auto u : graph[v]) {               if (u != par) {                 ask(u);                 candidates.push_back(u);                 for (auto w : graph[u]) {                   if (w != v) candidates.push_back(w);                 }               }             }           } else {             ;             throw -1;           }           for (int i = 0; i < (int)candidates.size() - 1; i++) {             ask(candidates[i]);           }           if (!answer) {             answer = candidates[candidates.size() - 1];           }         }       }       guess(answer);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int w, l;     cin >> w >> l;     int a[w];     long long sum[w];     sum[0] = 0;     for (int i = 1; i < w; i++) {       cin >> a[i];       sum[i] = sum[i - 1] + a[i];     }     long long mn = 100000000000000005;     for (int i = l; i < w; i++) {       mn = min(sum[i] - sum[i - l], mn);     }     cout << mn << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct InputReader {     char buf[1000001];     int p;     inline InputReader() { p = 1000001; }     inline void Flush() {       p = 0;       fread(buf, 1, 1000001, stdin);     }     inline char C() {       if (p >= 1000001) Flush();       return buf[p++];     }     inline char Readnum() {       char ch = C();       while (!isdigit(ch) && ch !=  - ) ch = C();       return ch;     }     inline void Readalpha(char &c) {       c = C();       while (!isalpha(c)) c = C();     }     int operator()() {       int ans = 0, fu = 1;       char ch = Readnum();       if (ch ==  - ) fu = -1, ch = C();       while (ch >=  0  && ch <=  9 ) {         ans = ans * 10 + ch -  0 ;         ch = C();       }       return ans * fu;     }     long long Readll() {       long long ans = 0LL, fu = 1LL;       char ch = Readnum();       if (ch ==  - ) fu = -1LL, ch = C();       while (ch >=  0  && ch <=  9 ) {         ans = ans * 10LL + ch -  0 ;         ch = C();       }       return ans * fu;     }     inline void Readstring(string &x) {       x.clear();       char ch = C();       while (!isdigit(ch) && !isalpha(ch) && ch !=  #  && ch !=  . ) ch = C();       while (isdigit(ch) || isalpha(ch) || ch ==  #  || ch ==  . ) {         x += ch;         ch = C();       }     }     inline void Readchstring(char s[]) {       int len = 0;       char ch = C();       while (!isdigit(ch) && !isalpha(ch)) ch = C();       while (isdigit(ch) || isalpha(ch)) {         s[len++] = ch;         ch = C();       }       s[len] =   0 ;     }     inline void Specialread(char &c) {       c = C();       while (!isdigit(c) && !isalpha(c) && c !=  #  && c !=  .  && c !=  =  &&              c !=  B )         c = C();     }   } In;   inline void Read(int &x) { x = In(); }   inline void Read(int &x, int &y) {     x = In();     y = In();   }   inline void Read(int &x1, int &x2, int &x3) {     x1 = In();     x2 = In();     x3 = In();   }   inline void Read(int &x1, int &x2, int &x3, int &x4) {     x1 = In();     x2 = In();     x3 = In();     x4 = In();   }   inline void Read(long long &x) { x = In.Readll(); }   inline void Read(long long &x, long long &y) {     x = In.Readll();     y = In.Readll();   }   inline void Read(long long &x1, long long &x2, long long &x3) {     x1 = In.Readll();     x2 = In.Readll();     x3 = In.Readll();   }   inline void Read(long long &x1, long long &x2, long long &x3, long long &x4) {     x1 = In.Readll();     x2 = In.Readll();     x3 = In.Readll();     x4 = In.Readll();   }   template <typename T>   void Read(T a[], int st, int ed) {     for (int(i) = (st); (i) <= (ed); ++(i)) Read(a[i]);   }   inline void FILEIO() {}   inline void FILEIO(string pname) {     freopen((pname +  .in ).c_str(),  r , stdin);     freopen((pname +  .out ).c_str(),  w , stdout);   }   inline void FILEIO_OICONTEST(string pname) {     freopen((pname +  .in ).c_str(),  r , stdin);     freopen((pname +  .out ).c_str(),  w , stdout);   }   void Printtime() {}   void END() {     Printtime();     exit(0);   }   template <typename T>   void END(T mes) {     cout << mes << endl;     END();   }   template <typename T>   void Print(T a[], int s, int t, char sp =    , char ed =   n ) {     if (s > t) return;     for (int i = s; i < t; i++) cout << a[i] << sp;     cout << a[t] << ed;     cout.flush();   }   template <typename T>   void Print(T a, int s = 0, int t = -1, char sp =    , char ed =   n ) {     if (t == -1) t = a.size() - 1;     for (int i = s; i <= t; i++) cout << a[i] << sp;     cout << ed;     cout.flush();   }   long long Pow(long long a, long long b, long long p = (1000000007LL)) {     long long ret = 1;     for (; b; a = a * a % p, b >>= 1LL)       if (b & 1LL) ret = ret * a % p;     return ret;   }   long long Inv(long long a, long long p = (1000000007LL)) {     return Pow(a, p - 2LL, p);   }   int n;   long long a[524288], va[524288];   long long lowerl[524288], lowerr[524288];   long long tree[524288];   inline void Add(int pos, long long x) {     assert(pos <= n + 1);     for (; pos <= n; pos += ((pos) & (-pos))) {       tree[pos] += x;       tree[pos] = (tree[pos]) >= (1000000007LL) ? ((tree[pos]) - (1000000007LL))                                                 : (tree[pos]);     }   }   inline long long Sum(int pos) {     long long ans = 0;     for (; pos; pos -= ((pos) & (-pos))) {       ans += tree[pos];       ans = (ans) >= (1000000007LL) ? ((ans) - (1000000007LL)) : (ans);     }     return ans;   }   void CalcLowerL() {     memset(tree, 0, sizeof(tree));     for (int(i) = 1; (i) <= (n); ++(i)) {       lowerl[i] = Sum(va[i] - 1);       Add(va[i], i);     }   }   void CalcLowerR() {     memset(tree, 0, sizeof(tree));     for (int(i) = (n); (i) >= 1; --(i)) {       lowerr[i] = Sum(va[i] - 1);       Add(va[i], n - i + 1);     }   }   int main() {     FILEIO();     Read(n);     vector<long long> d;     d.clear();     for (int(i) = 1; (i) <= (n); ++(i)) {       Read(a[i]);       d.push_back(a[i]);     }     sort(d.begin(), d.end());     d.resize(unique(d.begin(), d.end()) - d.begin());     for (int(i) = 1; (i) <= (n); ++(i)) {       va[i] = lower_bound(d.begin(), d.end(), a[i]) - d.begin() + 1;     }     CalcLowerL();     CalcLowerR();     long long ans = 0;     for (int(i) = 1; (i) <= (n); ++(i)) {       ans += 1LL * a[i] * i % (1000000007LL) * (n - i + 1) % (1000000007LL);       ans = (ans) >= (1000000007LL) ? ((ans) - (1000000007LL)) : (ans);     }     for (int(i) = 1; (i) <= (n); ++(i)) {       long long tans = (n - i + 1) * lowerl[i] + i * lowerr[i];       tans %= (1000000007LL);       tans = tans * a[i] % (1000000007LL);       ans += tans;       ans = (ans) >= (1000000007LL) ? ((ans) - (1000000007LL)) : (ans);     }     cout << ans << endl;     END();   }


#include <bits/stdc++.h>   int main() {     int g[6] = {0, 2, 3, 1, 2, 1}, i;     while (scanf( %d , &i) == 1) {       printf( %d n , g[i]);     }     return 0;   }