#include <bits/stdc++.h>   using namespace std;   void solve(void);   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) solve();     return 0;   }   long long int power(long long int x, long long int y) {     long long int temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else {       return x * temp * temp;     }   }   long long int calculateK(long long int n, long long int i) {     long long int pow = (long long int)i / n;     return power(2, pow);   }   void solve(void) {     long long int n, i;     cin >> n;     cin >> i;     i *= 8;     vector<int> record(n);     vector<int> num;     unordered_map<int, long long int> hash;     int distinct = 0;     for (int i = 0; i < n; i++) {       int temp;       cin >> temp;       record[i] = temp;       if (hash[temp] == 0) {         hash[temp] = 1;         distinct++;         num.push_back(temp);       } else {         hash[temp] = hash[temp] + 1;       }     }     long long int maxK = calculateK(n, i);     sort(num.begin(), num.end());     long long int sum = 0;     for (int i = 0; i < maxK && i < num.size(); i++) {       sum += hash[num[i]];     }     long long int maxSum = sum, maxL = 0,                   maxR = maxK < num.size() ? maxK - 1 : num.size() - 1;     for (int i = maxK, j = 1; i < num.size(); i++, j++) {       sum -= hash[num[j - 1]];       sum += hash[num[i]];       if (sum > maxSum) {         maxSum = sum;         maxL = j;         maxR = i;       }     }     int valL = num[maxL];     int valR = num[maxR];     int ans = 0;     for (int i = 0; i < n; i++) {       if (record[i] < valL || record[i] > valR) {         ans++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[100010], pos[100010], f[100010], b;   int main() {     bool yes = true;     cin >> n >> m;     for (int i = 1; i < n + 1; i++) {       cin >> f[i];       if (pos[f[i]]) {         pos[f[i]] = -1;       } else {         pos[f[i]] = i;       }     }     for (int i = 0; i < m; i++) {       cin >> b;       if (!pos[b]) {         cout <<  Impossible  << endl;         return 0;       } else if (pos[b] == -1) {         yes = false;       }       a[i] = pos[b];     }     if (yes == false) {       cout <<  Ambiguity  << endl;       return 0;     } else {       cout <<  Possible  << endl;       for (int i = 0; i < m; i++) {         cout << a[i] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     int s, x1, x2;     cin >> s >> x1 >> x2;     int t1, t2;     cin >> t1 >> t2;     int p, d;     cin >> p >> d;     int ans = abs(x1 - x2) * t2;     if (x1 < x2) {       if (p <= x1) {         if (d == 1) {           ans = min(ans, abs(x1 - p) * t1 + abs(x2 - x1) * t1);         } else {           ans = min(ans, abs(x2) * t1 + abs(p) * t1);         }       } else if (p >= x1 && p <= x2) {         if (d == 1) {           ans = min(ans, abs(s - p) * t1 + abs(x1 - s) * t1 + abs(x1) * t1 +                              abs(x2) * t1);         } else {           ans = min(ans, abs(p - x1) * t1 + abs(x1) * t1 + abs(x2) * t1);         }       } else {         if (d == 1) {           ans = min(ans, abs(s - p) * t1 + abs(s - x1) * t1 + abs(x1) * t1 +                              abs(x2) * t1);         } else {           ans = min(ans, abs(p - x1) * t1 + abs(x1) * t1 + abs(x2) * t1);         }       }     } else {       if (p <= x2) {         if (d == 1) {           ans = min(ans, abs(x1 - p) * t1 + abs(x1 - s) * t1 + abs(x2 - s) * t1);         } else {           ans = min(ans, abs(p) * t1 + abs(x1) * t1 + abs(s - x1) * t1 +                              abs(x2 - s) * t1);         }       } else if (p >= x1) {         if (d == 1) {           ans = min(ans, abs(p - s) * t1 + abs(s - x1) * t1 + abs(x2 - x1) * t1);         } else {           ans = min(ans, abs(x1 - p) * t1 + abs(x2 - x1) * t1);         }       } else {         if (d == 1) {           ans = min(ans, abs(x1 - p) * t1 + abs(x1 - s) * t1 + abs(s - x2) * t1);         } else {           ans = min(ans, abs(p) * t1 + abs(x1) * t1 + abs(x1 - s) * t1 +                              abs(s - x2) * t1);         }       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   const long long N = (long long)1e5 * 4;   const long long INF = (long long)1e18;   const double eps = (double)1e-6;   string s;   vector<long long> v;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s;     long long cnt = 0, col = 0;     s +=  a ;     bool ok = 0;     for (long long i = 1; i < (long long)(s.size()); ++i) {       if (s[i] ==  o ) {         col++;       }       if (s[i] == s[i - 1] && s[i] ==  v ) {         if (col != 0 && (long long)(v.size()) != 0) v.push_back(col);         col = 0;         cnt++;       } else {         if (cnt != 0) v.push_back(cnt);         cnt = 0;       }     }     long long sum = 0;     for (long long i = 0; i < (long long)(v.size()); ++i) {       if (i % 2 == 0) sum += v[i];     }     long long ans = 0;     cnt = 0;     for (long long i = 0; i < (long long)(v.size()); ++i) {       if (i % 2 == 0) {         cnt += v[i];         sum -= v[i];       } else {         ans += (cnt * v[i]) * sum;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x;     scanf( %d , &x);     printf( %d , x + 1 >> 1);   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, n, t, f, ans;   vector<int> v;   queue<int> q;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     cin >> n >> a >> b >> c >> t;     for (int i = 0; i < n; i++) {       cin >> f;       v.push_back(f);     }     sort(v.begin(), v.end());     for (auto u : v) q.push(u);     v.clear();     int luku1 = 0;     int luku2 = 0;     int luku3 = 0;     for (int i = 0; i <= t; i++) {       while (q.front() == i) {         v.push_back(q.front());         q.pop();         luku1 += a;       }       luku2 += v.size() * c;     }     luku2 -= v.size() * c;     for (auto u : v) {       luku2 += a + (u - t) * b;     }     ans = max(luku1, max(luku2, luku3));     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename S>   ostream &operator<<(ostream &os, const pair<T, S> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T, size_t N>   ostream &operator<<(ostream &os, const array<T, N> &a) {     os <<  ( ;     for (int i = 0; i < (int)N; i++) {       if (i) os <<  ,  ;       os << a[i];     }     return os <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  [ ;     for (int i = 0; i < (int)v.size(); i++) {       if (i) os <<  ,  ;       os << v[i];     }     return os <<  ] ;   }   void debug() { cerr <<   n ; }   template <typename T, typename... Args>   void debug(T x, Args... args) {     cerr << x <<  ;  ;     debug(args...);   }   int a[360];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     int ret = INT_MAX;     for (int i = 0; i < n; i++) {       int sum = a[i];       ret = min(ret, abs(2 * a[i] - 360));       for (int j = (i + 1) % n; j != i; j = (j + 1) % n) {         sum += a[j];         ret = min(ret, abs(2 * sum - 360));       }     }     cout << ret <<   n ;     return 0;   }


#include <bits/stdc++.h>   void rd(int &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   void lrd(long long &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     x *= f;   }   const int INF = 1e9;   const long long LINF = 1e18;   const int N = 5e5 + 10;   const int mod = 1e9 + 7;   using namespace std;   int T;   int n, m;   map<int, long long> S;   long long c[N];   vector<int> f[N];   long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }   int main() {     rd(T);     while (T--) {       rd(n);       rd(m);       S.clear();       for (int i = 1; i <= n; i++) lrd(c[i]), f[i].clear();       for (int i = 1; i <= m; i++) {         int x, y;         rd(x);         rd(y);         f[y].push_back(x);       }       for (int i = 1; i <= n; i++) sort(f[i].begin(), f[i].end());       for (int i = 1; i <= n; i++) {         if (!f[i].size()) continue;         int hs = 0;         for (int j = 0; j < f[i].size(); j++)           hs = (1ll * hs * (n + 1) + f[i][j]) % mod;         if (S.find(hs) == S.end())           S[hs] = c[i];         else           S[hs] += c[i];       }       map<int, long long>::iterator it;       long long ans = 0;       for (it = S.begin(); it != S.end(); it++)         if (ans)           ans = gcd(ans, it->second);         else           ans = it->second;       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1001;   const int M = 300000;   int n, m, a[N], b[N];   vector<bool> g[M];   pair<int, int> p[N];   priority_queue<pair<int, int> > q;   bool solve(int x) {     if (x == 0) return true;     for (int i = 1; i <= n; i++) b[i] = a[i] - x;     int sum = 0;     for (int i = 1; i <= n; i++) sum += b[i];     sort(b + 1, b + n + 1);     reverse(b + 1, b + n + 1);     if (sum & 1) {       b[1]--;       b[2]--;       b[3]--;     }     sort(b + 1, b + n + 1);     reverse(b + 1, b + n + 1);     if (b[n] < 0) return false;     for (int i = 1; i <= n; i++)       if (b[i] > 0) q.push(make_pair(b[i], i));     while (!q.empty()) {       pair<int, int> v = q.top();       q.pop();       if (q.empty()) return false;       pair<int, int> u = q.top();       q.pop();       v.first--;       u.first--;       if (v.first > 0) q.push(v);       if (u.first > 0) q.push(u);     }     return true;   }   void getSolution(int x) {     if (x == 0) {       m = 0;       for (int i = 1; i < n; i++) {         for (int j = 1; j <= 100; j++) {           m++;           for (int k = 1; k <= n; k++)             if (k == i || k == i + 1)               g[m][k - 1] = true;             else               g[m][k - 1] = false;         }       }       return;     }     for (int i = 1; i <= n; i++) b[i] = a[i] - x;     for (int i = 1; i <= n; i++)       if (b[i] > 0) q.push(make_pair(b[i], i));     int sum = 0;     for (int i = 1; i <= n; i++) sum += b[i];     int game = 0;     while (!q.empty()) {       game++;       if (sum & 1) {         pair<int, int> a = q.top();         q.pop();         if (q.empty()) assert(false);         pair<int, int> b = q.top();         q.pop();         if (q.empty()) assert(false);         pair<int, int> c = q.top();         q.pop();         for (int j = 1; j <= n; j++)           if (j == a.second || j == b.second || j == c.second)             g[game][j - 1] = true;           else             g[game][j - 1] = false;         a.first--;         b.first--;         c.first--;         if (a.first > 0) q.push(a);         if (b.first > 0) q.push(b);         if (c.first > 0) q.push(c);         sum -= 3;       } else {         pair<int, int> a = q.top();         q.pop();         if (q.empty()) assert(false);         pair<int, int> b = q.top();         q.pop();         for (int j = 1; j <= n; j++)           if (j == a.second || j == b.second)             g[game][j - 1] = true;           else             g[game][j - 1] = false;         a.first--;         b.first--;         if (a.first > 0) q.push(a);         if (b.first > 0) q.push(b);       }     }     m = game;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     int minval = a[1];     for (int i = 2; i <= n; i++) minval = min(minval, a[i]);     for (int i = 1; i <= 10000; i++) g[i].resize(n);     int ans = 0;     for (int i = minval; i >= 0; i--)       if (solve(i)) {         ans = i;         break;       }     cout << ans << endl;     getSolution(ans);     cout << m << endl;     for (int i = 1; i <= m; i++) {       for (int j = 0; j < g[i].size(); j++) cout << g[i][j];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 5e3 + 10;   int dp[maxn][maxn];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     string a, b;     cin >> a >> b;     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i - 1] == b[j - 1]) {           dp[i][j] = dp[i - 1][j - 1] + 2;         } else           dp[i][j] = max({0, dp[i - 1][j] - 1, dp[i][j - 1] - 1});         ans = max(ans, dp[i][j]);       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   namespace Base {   const int inf = 0x3f3f3f3f, INF = 0x7fffffff;   const long long infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;   template <typename T>   void read(T &x) {     x = 0;     int fh = 1;     double num = 1.0;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     if (ch ==  . ) {       ch = getchar();       while (isdigit(ch)) {         num /= 10;         x = x + num * (ch -  0 );         ch = getchar();       }     }     x = x * fh;   }   template <typename T>   void chmax(T &x, T y) {     x = x < y ? y : x;   }   template <typename T>   void chmin(T &x, T y) {     x = x > y ? y : x;   }   }  // namespace Base   using namespace Base;   const int N = 100010;   int n, a[N], q[N], use[N], pre[N], prel[N], prem[N], prer[N], num, l[N], m[N],       r[N];   void force(int *a, int n, int id) {     int tmp = 0;     for (int i = 1; i <= n; i++) tmp = tmp + (a[i] << (i - 1));     int pl = 1, pr = 1;     q[1] = 0;     use[0] = true;     while (pl <= pr) {       int x = q[pl++];       for (int i = 1; i <= n; i++)         for (int j = i + 1; j <= n; j++) {           int k = j + (j - i);           if (k > n) continue;           int nxt = x ^ (1 << (i - 1)) ^ (1 << (j - 1)) ^ (1 << (k - 1));           if (use[nxt] == false) {             q[++pr] = nxt;             use[nxt] = true;             pre[nxt] = x;             prel[nxt] = i;             prem[nxt] = j, prer[nxt] = k;           }         }     }     if (use[tmp] == false) {       printf( NO n );       exit(0);     }     printf( YES n );     while (tmp != 0) {       num++;       l[num] = prel[tmp] + id, m[num] = prem[tmp] + id, r[num] = prer[tmp] + id;       tmp = pre[tmp];     }     printf( %d n , num);     for (int i = 1; i <= num; i++) printf( %d %d %d n , l[i], m[i], r[i]);   }   void doit(int nl, int nm, int nr) {     num++;     l[num] = nl, m[num] = nm, r[num] = nr;     a[nl] ^= 1, a[nm] ^= 1, a[nr] ^= 1;   }   int main() {     read(n);     for (int i = 1; i <= n; i++) read(a[i]);     int pl = 1, pr = n;     while (pr - pl + 1 > 12) {       if (a[pl] == 0) {         pl++;         continue;       }       if (a[pr] == 0) {         pr--;         continue;       }       if (a[pl] + a[pl + 1] + a[pl + 2] == 3) {         doit(pl, pl + 1, pl + 2);         continue;       }       if (a[pr] + a[pr - 1] + a[pr - 2] == 3) {         doit(pr - 2, pr - 1, pr);         continue;       }       if ((pr - pl) % 2 == 0) {         doit(pl, (pl + pr) / 2, pr);         continue;       }       if (a[pl] != a[pl + 1] && a[pl] == a[pl + 2]) {         doit(pl, pl + 2, pl + 4);         continue;       }       if (a[pr] != a[pr - 1] && a[pr] == a[pr - 2]) {         doit(pr - 4, pr - 2, pr);         continue;       }       doit(pl, (pl + pr - 1) / 2, pr - 1);     }     if (n <= 12)       force(a, n, 0);     else       force(a + pl - 1, 12, pl - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000;   int sum[maxn];   int a[maxn];   int sum2[maxn];   int main() {     int n;     char s[maxn];     while (cin >> n) {       memset(sum, 0, sizeof(sum));       for (int i = 1; i <= n; ++i) {         scanf( %d , a + i);         sum[i] = sum[i - 1] + a[i];       }       scanf( %s , s + 1);       int c = 0, ans = 0;       for (int i = n; i >= 1; --i) {         if (s[i] ==  1 ) {           ans = max(ans, c + sum[i - 1]);           c += a[i];         }       }       cout << max(c, ans) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> arr[5005];   vector<int> primes;   int ans[5005];   int u[5005];   int n;   void pre() {     vector<char> bad(10005);     for (int i = 2; i <= 10000; ++i) {       if (!bad[i]) {         primes.push_back(i);         for (int j = i * i; j <= 10000; j += i) {           bad[j] = 1;         }       }     }   }   int f(int x) {     static vector<int> di;     di.clear();     if (x == 0) {       return 0;     }     bool neg = 0;     if (x < 0) {       neg = 1;       x *= -1;     }     int y = 1;     for (int i = 0; i < primes.size(); ++i) {       int cnt = 0;       while (x % primes[i] == 0) {         x /= primes[i];         ++cnt;       }       if (cnt & 1) {         y *= primes[i];       }     }     x *= y;     if (neg) {       x *= -1;     }     return x;   }   void compress() {     vector<int> vv;     for (int i = 1; i <= n; ++i) {       vv.push_back(arr[i].first);     }     sort((vv).begin(), (vv).end());     vv.resize(unique((vv).begin(), (vv).end()) - vv.begin());     for (int i = 1; i <= n; ++i) {       arr[i].second =           upper_bound((vv).begin(), (vv).end(), arr[i].first) - vv.begin();     }   }   void solve() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , &arr[i].first);       arr[i].first = f(arr[i].first);     }     compress();     int ptr = 0;     for (int l = 1; l <= n; ++l) {       int cur = 0;       ++ptr;       for (int r = l; r <= n; ++r) {         if (arr[r].first != 0) {           if (u[arr[r].second] != ptr) {             u[arr[r].second] = ptr;             ++cur;           }         }         ++ans[max(1, cur)];       }     }     for (int i = 1; i <= n; ++i) {       printf( %d  , ans[i]);     }   }   int main() {     int tt = 1;     pre();     while (tt--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, tri = 0;     scanf( %d , &n);     long long trilist[n + 5];     for (int i = 0; i < n; i++) {       scanf( %ld , &trilist[i]);     }     sort(trilist, trilist + n);     for (int i = 0; i < n - 2; i++) {       if (trilist[i] + trilist[i + 1] > trilist[i + 2]) {         tri = 1;         break;       }     }     if (tri == 1) {       printf( YES n );     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int visited1[200005], visited2[200005], step1[200005], step2[200005],       ar[200005];   long long int n;   void fill_array(long long int ar[], long long int value, long long int size) {     for (long long int i = 0; i < size; i++) ar[i] = value;   }   long long int dfs(long long int node, long long int step,                     long long int parent) {     if (step == 1) {       visited1[node] = 1;       if (node + ar[node] > n)         step1[node] = ar[node];       else {         if (visited2[node + ar[node]]) {           if (step2[node + ar[node]] < 0)             step1[node] = -1;           else if (step2[node + ar[node]] == 0)             step1[node] = -1;           else             step1[node] = step2[node + ar[node]] + ar[node];         } else {           long long int temp = dfs(node + ar[node], 2, node);           if (temp < 0)             step1[node] = -1;           else             step1[node] = temp + ar[node];         }       }       return step1[node];     } else {       visited2[node] = 1;       if (node - ar[node] < 1)         step2[node] = ar[node];       else if (node - ar[node] == 1)         step2[node] = -1;       else {         if (visited1[node - ar[node]]) {           if (step1[node - ar[node]] < 0)             step2[node] = -1;           else if (step1[node - ar[node]] == 0)             step2[node] = -1;           else             step2[node] = step1[node - ar[node]] + ar[node];         } else {           long long int temp = dfs(node - ar[node], 1, node);           if (temp < 0)             step2[node] = -1;           else             step2[node] = temp + ar[node];         }       }       return step2[node];     }   }   int main() {     cin >> n;     for (long long int i = 2; i <= n; i++) cin >> ar[i];     fill_array(visited1, 0, n + 1);     fill_array(visited2, 0, n + 1);     fill_array(step1, 0, n + 1);     fill_array(step2, 0, n + 1);     for (long long int i = 2; i <= n; i++) {       if (!visited1[i]) dfs(i, 1, -1);       if (!visited2[i]) dfs(i, 2, -1);     }     for (long long int i = 2; i <= n; i++) {       if (step2[i] == -1)         cout <<  -1 n ;       else         cout << step2[i] + i - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   struct pos {     long long int x;     long long int h;     int indx;     int sum;   } p[100005];   bool cmp(pos a, pos b) { return a.x < b.x; }   bool cmp2(pos a, pos b) { return a.indx < b.indx; }   int bs(long long int key) {     int l = 0;     int r = n;     int mid;     while (l <= r) {       mid = (l + r) / 2;       if (p[mid].x == key) {         return mid;       } else if (p[mid].x < key) {         l = mid + 1;       } else {         r = mid - 1;       }     }   }   int main() {     scanf( %d , &n);     long long int ar[n + 5];     for (int i = 0; i < n; i++) {       scanf( %lld%lld , &p[i].x, &p[i].h);       p[i].indx = i;       p[i].sum = 1;     }     sort(p, p + n, cmp);     p[n - 1].sum = 1;     for (int i = n - 2; i >= 0; i--) {       long long int val = p[i].h + p[i].x;       int poscnt = 1;       while (val > p[i + poscnt].x && poscnt + i < n) {         p[i].sum += p[poscnt + i].sum;         poscnt += p[poscnt + i].sum;       }     }     sort(p, p + n, cmp2);     for (int i = 0; i < n; i++) {       printf( %d  , p[i].sum);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, p, prt[100005], num[100005], ans = 1, cnt, u, v;   inline int getfather(int u) {     if (u == prt[u]) return prt[u];     prt[u] = getfather(prt[u]);     return prt[u];   }   int main() {     scanf( %lld%lld%lld , &n, &m, &p);     for (register int i = 1; i <= n; i++) prt[i] = i;     for (register int i = 1; i <= m; i++) {       scanf( %lld%lld , &u, &v);       register int f1 = getfather(u), f2 = getfather(v);       if (f1 != f2) prt[f1] = f2;     }     for (register int i = 1; i <= n; i++) num[getfather(i)]++;     for (register int i = 1; i <= n; i++)       if (num[i]) cnt++, ans = ans * num[i] % p;     for (register int i = 1; i <= cnt - 2; i++) ans = ans * n % p;     if (cnt == 1) ans = 1;     printf( %lld , ans % p);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 52;   const int INF = 1e9;   int mat[N][N];   int n, k;   struct edge {     int from, to, cap, cost, flow;     edge(int from, int to, int cap, int cost)         : from(from), to(to), cap(cap), cost(cost) {       flow = 0;     }   };   vector<edge> e;   vector<int> g[N];   void add_edge(int from, int to, int cap, int cost) {     g[from].push_back(e.size());     e.push_back(edge(from, to, cap, cost));     g[to].push_back(e.size());     e.push_back(edge(to, from, 0, -cost));   }   int d[N];   int ptr[N];   bool bfs() {     d[1] = 1;     queue<int> q;     q.push(1);     while (!q.empty()) {       int v = q.front();       q.pop();       for (int id : g[v]) {         int to = e[id].to;         if (e[id].flow == e[id].cap) continue;         if (d[to] == -1) {           d[to] = d[v] + 1;           q.push(to);         }       }     }     return d[n] != -1;   }   int dfs(int v, int flow) {     if (!flow || v == n) return flow;     for (; ptr[v] < (int)g[v].size(); ++ptr[v]) {       int id = g[v][ptr[v]];       int to = e[id].to;       if (d[to] == d[v] + 1) {         int pushed = dfs(to, min(flow, e[id].cap - e[id].flow));         if (pushed) {           e[id].flow += pushed;           e[id ^ 1].flow -= pushed;           return pushed;         }       }     }     return 0;   }   int dinic() {     int flow = 0;     while (1) {       fill(d, d + N, -1);       fill(ptr, ptr + N, 0);       if (!bfs()) return flow;       while (int pushed = dfs(1, INF)) {         flow += pushed;       }     }     return flow;   }   char in_que[N];   int from[N];   void show(edge e) {     cout <<  (  << e.from <<  ,   << e.to <<  ,   << e.flow <<  ,   << e.cap          <<  ,   << e.cost <<  )  << endl;   }   vector<int> spfa() {     fill(d, d + N, INF);     fill(in_que, in_que + N, 0);     d[1] = 0;     queue<int> q;     q.push(1);     in_que[1] = 1;     while (!q.empty()) {       int v = q.front();       q.pop();       in_que[v] = 0;       for (int id : g[v]) {         int to = e[id].to;         if (e[id].cap == e[id].flow) continue;         if (d[to] > d[v] + e[id].cost) {           d[to] = d[v] + e[id].cost;           from[to] = id;           if (!in_que[to]) {             in_que[to] = 1;             q.push(to);           }         }       }     }     if (d[n] == INF) return {};     int v = n;     vector<int> ret;     while (v != 1) {       ret.push_back(from[v]);       v = e[from[v]].from;     }     reverse(ret.begin(), ret.end());     return ret;   }   int mcf(int flow) {     int cost = 0;     while (1) {       vector<int> kek = spfa();       if (kek.empty()) return flow;       int delta = 1000000;       int sum = 0;       for (int id : kek) {         delta = min(delta, e[id].cap - e[id].flow);         sum += e[id].cost;       }       if (sum > 0) delta = min(delta, (k - cost) / sum);       for (int id : kek) {         e[id].flow += delta;         e[id ^ 1].flow -= delta;         cost += e[id].cost * delta;       }       flow += delta;       if (!delta) return flow;     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) {         cin >> mat[i][j];         if (!mat[i][j]) continue;         add_edge(i, j, mat[i][j], 0);       }     int din = 0;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) {         if (!mat[i][j]) continue;         add_edge(i, j, k, 1);       }     int ans = mcf(din);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   char ss[100002];   int main() {     int N, K, k = 0;     scanf( %d %d , &N, &K);     scanf( %s , ss);     string S = ss;     for (int i = 0; i < N - 1 && k < K; i++) {       if (S[i] ==  4  && S[i + 1] ==  7 ) {         int x = i + 1;         if (x % 2) {           if (x + 1 < N && S[x + 1] ==  7 ) {             if ((K - k) % 2) {               S[x] =  4 ;             }             printf( %s , S.c_str());             return 0;           }           S[x] =  4 ;         } else {           S[x - 1] =  7 ;           i -= 2;         }         k++;       }     }     printf( %s n , S.c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ns, k, n, m;   char s[1000010], t[1000010], p[1000010];   vector<int> vet;   int fail[1000010];   void buildFail(char *p) {     int j = fail[0] = -1;     for (int i = 1; i <= m; i++) {       while (j >= 0 && p[j] != p[i - 1]) j = fail[j];       fail[i] = ++j;     }   }   int kmp(char *p, char *t) {     buildFail(p);     for (int i = 0, k = 0; i < n; i++) {       while (k >= 0 && p[k] != t[i]) k = fail[k];       if (++k >= m) {         return 1;         k = fail[k];       }     }     return 0;   }   int test(int k) {     int i, j;     m = 0;     for (i = 0, j = ns - k; i < k; i++, j++) {       if (s[i] != s[j]) break;       p[m++] = s[i];     }     if (i < k) return 0;     p[m] =   0 ;     return kmp(p, t);   }   int main() {     int lo, hi, mid;     scanf(  %s , s);     ns = strlen(s);     vet.clear();     m = ns;     buildFail(s);     k = ns;     while (fail[k] > 0) {       vet.push_back(fail[k]);       k = fail[k];     }     sort(vet.begin(), vet.end());     for (int i = 1; i < ns - 1; i++) t[i - 1] = s[i];     t[n - 2] =   0 ;     n = ns - 2;     lo = 0;     hi = vet.size() - 1;     k = 0;     while (lo <= hi) {       mid = (lo + hi) / 2;       if (test(vet[mid])) {         k = vet[mid];         lo = mid + 1;       } else         hi = mid - 1;     }     if (!k)       printf( Just a legend n );     else {       for (int i = 0; i < k; i++) printf( %c , s[i]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 400010;   struct ST {     int st[4 * MX], p[MX];     ST() { build(1, MX - 1, 1); }     void build(int i, int j, int pos) {       st[pos] = 0;       if (i == j) {         p[i] = pos;         return;       }       int m = (i + j) / 2;       build(i, m, pos * 2);       build(m + 1, j, pos * 2 + 1);     }     void update(int x, int k) {       int pos = p[x];       st[pos] = k;       pos /= 2;       while (pos) {         st[pos] = max(st[pos * 2], st[pos * 2 + 1]);         pos /= 2;       }     }     int leq(int i, int j, int pos, int x) {       if (i > x) return 0;       if (j <= x) return st[pos];       int m = (i + j) / 2;       return max(leq(i, m, pos * 2, x), leq(m + 1, j, pos * 2 + 1, x));     }     int geq(int i, int j, int pos, int x) {       if (i >= x) return st[pos];       if (j < x) return 0;       int m = (i + j) / 2;       return max(geq(i, m, pos * 2, x), geq(m + 1, j, pos * 2 + 1, x));     }   } st;   int n, a[MX], res[MX];   vector<int> c;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] -= i;       c.push_back(a[i]);       c.push_back(a[i] + 1);     }     sort(c.begin(), c.end());     c.erase(unique(c.begin(), c.end()), c.end());     for (int i = 0; i < n; i++)       a[i] = lower_bound(c.begin(), c.end(), a[i]) - c.begin() + 1;     for (int i = 1; i < n; i++) {       st.update(a[i - 1], 1 + st.leq(1, MX - 1, 1, a[i - 1]));       res[i] = st.leq(1, MX - 1, 1, a[i - 1]);     }     st.build(1, MX - 1, 1);     for (int i = n - 2; i >= 0; i--) {       st.update(a[i + 1] + 1, 1 + st.geq(1, MX - 1, 1, a[i + 1] + 1));       if (i - 1 > 0) res[i] += st.geq(1, MX - 1, 1, a[i - 1]);     }     cout << n - 1 - max(*max_element(res, res + n), st.geq(1, MX - 1, 1, 1))          <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   int n, m, t;   long long dp[61][31][31];   int arr[61];   long long solve(int ind, int x, int y) {     if (x > 3 && y > 0 && x + y == t) return 1;     if (ind == n + m + 1) return 0;     long long &ret = dp[ind][x][y];     if (ret != -1) return ret;     ret = solve(ind + 1, x, y);     if (x < n && arr[ind] == 1) ret += solve(ind + 1, x + 1, y);     if (y < m && arr[ind] == 2) ret += solve(ind + 1, x, y + 1);     return ret;   }   int main() {     scanf( %d%d%d , &n, &m, &t);     int i = 0;     for (; i < n; i++) arr[i] = 1;     for (; i < n + m; i++) arr[i] = 2;     memset(dp, -1, sizeof dp);     printf( %lld n , solve(0, 0, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7;   int f[105][105][105], len[105], n, m;   char s[105];   int qpow(int x, int y) {     int res = 1;     while (y) {       if (y % 2) res = 1ll * res * x % mod;       x = 1ll * x * x % mod;       y /= 2;     }     return res;   }   int dfs(int x, int l, int r) {     if (f[x][l][r] != -1) return f[x][l][r];     if (x <= 1) return (l == r) && (s[l] == (x +  0 ));     int cnt = 0;     cnt = (cnt +            1ll * dfs(x - 1, l, r) * ((r == n) ? qpow(2, len[x - 2]) : 1) % mod) %           mod;     cnt = (cnt +            1ll * dfs(x - 2, l, r) * ((l == 1) ? qpow(2, len[x - 1]) : 1) % mod) %           mod;     for (int k = l; k < r; k++)       cnt = (cnt + 1ll * dfs(x - 1, l, k) * dfs(x - 2, k + 1, r) % mod) % mod;     return f[x][l][r] = cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     memset(f, -1, sizeof(f));     len[1] = 1;     len[0] = 1;     for (int i = 2; i <= m; i++) len[i] = (len[i - 1] + len[i - 2]) % (mod - 1);     cin >> s + 1;     printf( %d n , dfs(m, 1, n));   }


#include <bits/stdc++.h>   using namespace std;   typedef long long LL;   #define FOR(i, a, b) for(int i = (a); i < (b); i++)      const int N = 1 << 10;   int p[N][N];   int main()   {    int m, n;    cin >> m >> n;    FOR(i, 0, n)    FOR(j, 0, m)     cin >> p[i][j];    int sum = 0;    FOR(j, 0, m)     sum += p[n - 1][j] - p[0][j];    assert(sum%(n - 1) == 0);    sum /= (n - 1);    int sum0 = 0;    FOR(j, 0, m)     sum0 += p[0][j];    int row = 0;    FOR(i, 1, n - 1){     int S = 0;     FOR(j, 0, m)      S += p[i][j];     if(S == sum0 + i * sum) continue;     row = i;    }    int st = (row > 2 ? 0 : (row + 1));    LL sum2 = 0;    FOR(j, 0, m){     sum2 += p[st][j] * (LL) p[st][j];     sum2 += p[st + 2][j] * (LL) p[st + 2][j];     sum2 -= 2 * p[st + 1][j] * (LL) p[st + 1][j];    }    sum2 /= 2;    LL real = 0, real2 = 0, have = 0, have2 = 0;    FOR(j, 0, m){     have += p[row][j];     have2 += p[row][j] * (LL) p[row][j];     real += p[row - 1][j];     real2 += p[row - 1][j] * (LL) p[row - 1][j];     real2 += p[row + 1][j] * (LL) p[row + 1][j];    }    real += sum;    real2 = real2/2 - sum2;    LL a2_x2 = have2 - real2;    LL a_x = have - real;    LL a_plus_x = a2_x2 / a_x;    cout << row <<     << (a_plus_x - a_x) / 2 << endl;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f2f1f0f;   const long long LINF = 1ll * INF * INF;   const int MAX_N = 2e5 + 100;   int N;   long long C;   int Nr[MAX_N * 2];   long long SumNr[MAX_N * 2];   long long Ans[MAX_N];   long long SumAns[MAX_N];   long long getSum(long long val[], int a, int b) { return val[b] - val[a - 1]; }   long long getVal(int a, int b) {     return getSum(SumNr, a * 2 - 1, b * 2 - 1) - getSum(SumAns, a, b - 1);   }   int main() {     cin >> N >> C;     for (int i = 1; i <= N * 2 - 1; i++)       scanf( %d , &Nr[i]), SumNr[i] = SumNr[i - 1] + Nr[i];     deque<int> dQ;     int cl = 0;     for (int r = 1; r <= N; r++) {       while (!dQ.empty() && getVal(dQ.back(), r) < Nr[r * 2 - 1]) dQ.pop_back();       dQ.push_back(r);       while (!dQ.empty() && getSum(SumNr, dQ.front() * 2 - 1, r * 2 - 1) >= C)         dQ.pop_front();       while (cl + 1 <= N && getSum(SumNr, (cl + 1) * 2 - 1, r * 2 - 1) >= C) cl++;       if (cl != 0) Ans[r] = max(Ans[r], C - getSum(SumAns, cl, r - 1));       if (!dQ.empty()) Ans[r] = max(Ans[r], getVal(dQ.front(), r));       SumAns[r] = SumAns[r - 1] + Ans[r];     }     printf( %lld n , SumAns[N]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long f[3], x, y, z, k;   int main() {     long long a, b, c;     long long r;     cin >> f[0] >> f[1] >> f[2] >> k;     sort(f, f + 3);     k += 3;     k = min(k, f[0] + f[1] + f[2]);     a = f[0] * 3 <= k ? f[0] : k / 3;     r = k - a;     b = f[1] * 2 <= r ? f[1] : r >> 1;     c = k - a - b;     cout << a * b * c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 9;   int n, d[N];   int digit(int x) {     int s = 0;     while (x > 0) {       s += x % 10;       x /= 10;     }     return s;   }   vector<int> b[10];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     for (int i = 1; i < 10; ++i) d[i] = i;     for (int i = 10; i < N; ++i) d[i] = d[digit(i)];     for (int i = 1; i <= n; ++i) b[d[i]].emplace_back(i);     long long ans = 0;     for (int i = 1, cnt; i <= n; ++i) {       for (int j = 1; j < 10; ++j)         if (!b[j].empty()) {           cnt = upper_bound(b[j].begin(), b[j].end(), n / i) - b[j].begin();           ans += (long long)b[j].size() * b[d[d[i] * j]].size() - cnt;         }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300001;   const int logn = 20;   bool s[maxn][logn];   int nxt[maxn][logn];   int f[maxn][logn];   int a[maxn];   int tmp[maxn];   int n, q;   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int j = 0; j < logn; j++) {       int cnt = 0;       for (int i = 1; i <= n; i++) {         if (!(a[i] >> j & 1)) continue;         s[i][j] = 1;         tmp[++cnt] = i;       }       for (int i = 1; i < cnt; i++) {         nxt[tmp[i]][j] = tmp[i + 1];       }     }     for (int i = n; i >= 1; i--) {       for (int j = 0; j < logn; j++) {         if (s[i][j])           f[i][j] = i;         else {           f[i][j] = n + 1;           for (int k = 0; k < logn; k++) {             if (s[i][k] && nxt[i][k]) f[i][j] = min(f[i][j], f[nxt[i][k]][j]);           }         }       }     }     for (int i = 1; i <= q; i++) {       int x, y;       scanf( %d%d , &x, &y);       bool ans = 0;       for (int j = 0; j < logn; j++) {         if (s[y][j] && f[x][j] <= y) ans = 1;       }       if (ans)         printf( Shi n );       else         printf( Fou n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Bug {     int a, id;   } B[100005];   struct Stu {     int b, c, id;     bool operator<(const Stu &A) const { return c > A.c; }   } S[100005];   int n, m, s;   int ans[100005];   int ans1[100005];   bool cmp(Bug A, Bug B) { return A.a > B.a; }   bool cmp1(Stu A, Stu B) { return A.b > B.b; }   bool check(int k) {     int cost = s;     int l = 0, r = 0;     priority_queue<Stu> P;     while (l < m) {       while (r < n && S[r].b >= B[l].a) {         P.push(S[r++]);       }       Stu T;       if (P.size())         T = P.top(), P.pop();       else {         return false;       }       cost -= T.c;       if (cost < 0) return false;       for (int i = l; i < l + k && i < m; i++) ans1[B[i].id] = T.id + 1;       l += k;     }     for (int i = 0; i < m; i++) ans[i] = ans1[i];     return true;   }   int main() {     scanf( %d%d%d , &n, &m, &s);     int Max = 0, Min = 0;     for (int i = 0; i < m; i++) {       scanf( %d , &B[i].a);       B[i].id = i;       if (B[i].a > Min) Min = B[i].a;     }     for (int i = 0; i < n; i++) {       scanf( %d , &S[i].b);       S[i].id = i;     }     for (int i = 0; i < n; i++) {       scanf( %d , &S[i].c);       if (S[i].b > Max && S[i].c <= s) Max = S[i].b;     }     sort(B, B + m, cmp);     sort(S, S + n, cmp1);     int l = 1, r = m + 1;     while (l < r) {       int m = (l + r) / 2;       if (check(m))         r = m;       else         l = m + 1;     }     if (Max < Min)       puts( NO );     else {       puts( YES );       for (int i = 0; i < m; i++) printf( %d  , ans[i]);       puts(  );     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long int   #define rep(i,a,b) for(int i=a;i<b;i++)   #define arrr int n;cin>>n;int a[n];for(int i=0;i<n;i++){cin>>a[i];}   const int N = 1e6;   // bool prime[1000001]={true};      // void sieve(){   //    memset(prime,1,sizeof(prime));   //    prime[0]=prime[1]=false;   //    for(ll i=2 ; i*i<=N ; i++){   //          for(int j=i*2 ; j<=N;j+=i){   //             prime[j] = false;   //          }   //    }   // }                void solve(){      int n;      cin>>n;      if(n>1099){         cout<< YES <<  n ;         return;      }         while(n>=0){         if(n%11 == 0){            cout<< YES <<  n ;            return;         }         n-=111;      }      cout<< NO <<  n ;   }       int main(){          ios_base::sync_with_stdio(false);      cin.tie(NULL); cout.tie(NULL);               int t;      t=1;      cin>>t;      while(t--)solve();                                     }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   long long power(long long x, long long n, long long mod) {     if (n == 0) {       return 0;     }     long long temp = power(x, n / 2, mod);     if (n % 2 == 1) {       return (x * temp * temp) % mod;     } else {       return (temp * temp) % mod;     }   }   long long abs(long long a, long long b) {     if (a > b) {       return a - b;     }     return b - a;   }   int main(int argc, const char* argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     if (n % 2 == 0) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     for (long long i = 1; i <= (n); i++) {       if (i != 1) {         cout <<    ;       }       cout << 2 * i - 1 + (i % 2 == 0);     }     for (long long i = 1; i <= (n); i++) {       if (i != 0) {         cout <<    ;       }       cout << 2 * i - 1 + (i % 2 == 1);     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     int ans = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> s;       ans += s * i;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans = 0, visited[200005] = {0};   vector<int> edges[200005];   void dfs(int x) {     visited[x] = 1;     if (visited[edges[x][0]] == 1)       ans++;     else       dfs(edges[x][0]);   }   int main() {     int n, i, x, count = 0;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> x;       edges[i].push_back(x);     }     for (i = 1; i <= n; i++) {       cin >> x;       if (x == 1) count++;     }     for (i = 1; i <= n; i++)       if (visited[i] == 0) dfs(i);     if (ans == 1) ans = 0;     if (count % 2 == 0) ans++;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 200 * 1000 + 10;   int n, arr[Maxn], ind[Maxn], ans;   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     int a;     for (int i = 0; i < n; i++) {       scanf( %d , &a);       ind[a] = i;     }     int prev = 0;     for (int i = 0; i < n; i++) {       if (ind[arr[i]] < prev) {         cout << n - i << endl;         return 0;       }       prev = ind[arr[i]];     }     cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   int a[maxn], vis[maxn];   int main() {     int n, p, flag = 0, mark = 0, tot = 0, Min = 1e9 + 7, cur, Max = -1e9 - 7,               Maxcur;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] == 0)         vis[i] = 1, mark = 1;       else if (a[i] < 0) {         flag++;         if (a[i] < Min) cur = i;         Min = min(Min, a[i]);         if (a[i] > Max) Maxcur = i;         Max = max(Max, a[i]);       }     }     if (flag % 2) vis[Maxcur] = 1, mark = 1;     for (int i = 1; i <= n; i++)       if (vis[i]) {         p = i;         break;       }     for (int i = p + 1; i <= n; i++)       if (vis[i]) printf( 1 %d %d n , p, i), p = i, tot++;     if (tot != n - 1 && mark) printf( 2 %d n , p);     for (int i = 1; i <= n; i++)       if (!vis[i]) {         p = i;         break;       }     for (int i = p + 1; i <= n; i++)       if (!vis[i]) printf( 1 %d %d n , p, i), p = i;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000000;   int cnt[N + 1];   int check[N + 1];   set<pair<int, int> > s;   int main() {     int n, A;     scanf( %d %d , &n, &A);     for (int i = 1; i <= N; i++) {       cnt[i] = 0;       s.insert({cnt[i], i});     }     for (int i = 0; i < n; i++) {       int foo;       scanf( %d , &foo);       if (!check[foo]) {         s.erase(s.find({cnt[foo], foo}));         s.insert({++cnt[foo], foo});       }       while ((!s.empty()) && s.begin()->first < cnt[A]) {         check[s.begin()->second] = 1;         s.erase(s.begin());       }     }     for (auto x : s) {       if (x.second != A) {         cout << x.second << endl;         return 0;       }     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int l, r, sum = 0, tempVariable, doneTillHereInArrayOfNumbers = 3;   long long int arrayOfNumbers[100000];   long long int createNextLuckyNumber() {     if (doneTillHereInArrayOfNumbers % 2 == 0) {       arrayOfNumbers[doneTillHereInArrayOfNumbers] =           (arrayOfNumbers[doneTillHereInArrayOfNumbers / 2 - 1] * 10) + 7;     } else {       arrayOfNumbers[doneTillHereInArrayOfNumbers] =           (arrayOfNumbers[doneTillHereInArrayOfNumbers / 2] * 10) + 4;     }     return arrayOfNumbers[doneTillHereInArrayOfNumbers++];   }   long long int FirstLuckyNumberGreaterThanOrEqualToL() {     if (4 < l) {       goto down;     }     if (4 >= l && 4 <= r) {       sum += 4 * (4 - l + 1);       l = 5;     } else if (4 >= l && 4 > r) {       sum += 4 * (r - l + 1);       l = r;       cout << sum;       exit(0);     }   down:     if (7 < l) {       goto down2;     }     if (7 >= l && 7 <= r) {       sum += 7 * (7 - l + 1);       l = 8;     } else if (7 >= l && 7 > r) {       sum += 7 * (r - l + 1);       cout << sum;       exit(0);     }   down2:     long long int num = 0;     while (num < l) {       num = createNextLuckyNumber();     }     return num;   }   int main() {     cin >> l >> r;     arrayOfNumbers[1] = 4;     arrayOfNumbers[2] = 7;     tempVariable = FirstLuckyNumberGreaterThanOrEqualToL();     if (tempVariable <= r) {       sum += tempVariable * (tempVariable - l + 1);       l = tempVariable;     } else {       sum += tempVariable * (r - l + 1);       cout << sum;       exit(0);     }     l++;     while (l <= r) {       tempVariable = createNextLuckyNumber();       if (tempVariable <= r) {         sum += tempVariable * (tempVariable - l + 1);         l = tempVariable;       } else {         sum += tempVariable * (r - l + 1);         break;       }       l++;     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   const int INF = 1000000009;   using namespace std;   int main() {     int n, i, l = 0, r = 0;     string s;     cin >> n >> s;     s =  .  + s;     for (i = 1; i < s.size(); i++)       if (s[i] ==  L )         l = 1;       else if (s[i] ==  R )         r = 1;     if (r && l)       cout << s.find( R ) <<     << s.find( L ) - 1 <<   n ;     else if (r && !l)       cout << s.find( R ) <<     << s.rfind( R ) + 1 <<   n ;     else       cout << s.rfind( L ) <<     << s.find( L ) - 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x7FFFFFFF;   struct prioritycom {     bool operator()(const int& l, const int& r) { return l < r; }   };   template <typename T>   T lcm(T a, T b) {     return a / __gcd(a, b) * b;   }   template <class T>   T bigmod(T n, T p, T m) {     if (p == 0) return 1;     if (p % 2 == 0) {       T t = bigmod(n, p / 2, m);       return (t * t) % m;     }     return (bigmod(n, p - 1, m) * n) % m;   }   template <class string>   long long int strton(string s) {     long long int won;     stringstream ss;     ss << s;     ss >> won;     return won;   }   template <class T>   string ntostr(T n) {     stringstream ss;     ss << n;     return ss.str();   }   template <class T>   inline T mod(T n, T m) {     return (n % m + m) % m;   }   template <class T>   bool isprime(T n) {     if (n % 2 == 0) {       if (n == 2)         return true;       else         return false;     }     T m = sqrt(n);     for (T i = 3; i <= m; i += 2) {       if (n % i == 0) return false;     }     return true;   }   bool isvowel(char ch) {     ch = toupper(ch);     if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E )       return true;     return false;   }   bool isconsonant(char ch) {     if (isalpha(ch) && !isvowel(ch)) return true;     return false;   }   char s[15][15];   int main() {     int x, y, cnt = 0;     for (int i = 1; i <= 9; i++) {       for (int j = 1; j <= 11; j++) {         scanf( %c , &s[i][j]);       }       getchar();       if (i % 3 == 0 && i != 9) getchar();     }     scanf( %d%d , &x, &y);     if (x % 3 == 0) {       if (y == 3 || y == 6 || y == 9) {         for (int i = 7; i <= 9; i++) {           for (int j = 9; j <= 11; j++) {             if (s[i][j] !=  . ) {               cnt++;             } else               s[i][j] =  ! ;           }         }       }       if (y == 1 || y == 4 || y == 7) {         for (int i = 7; i <= 9; i++) {           for (int j = 1; j <= 3; j++) {             if (s[i][j] !=  . ) {               cnt++;             } else               s[i][j] =  ! ;           }         }       }       if (y == 2 || y == 5 || y == 8) {         for (int i = 7; i <= 9; i++) {           for (int j = 5; j <= 7; j++) {             if (s[i][j] !=  . ) {               cnt++;             } else               s[i][j] =  ! ;           }         }       }     }     if (x == 2 || x == 5 || x == 8) {       if (y == 3 || y == 6 || y == 9) {         for (int i = 4; i <= 6; i++) {           for (int j = 9; j <= 11; j++) {             if (s[i][j] !=  . ) {               cnt++;             } else               s[i][j] =  ! ;           }         }       }       if (y == 1 || y == 4 || y == 7) {         for (int i = 4; i <= 6; i++) {           for (int j = 1; j <= 3; j++) {             if (s[i][j] !=  . ) {               cnt++;             } else               s[i][j] =  ! ;           }         }       }       if (y == 2 || y == 5 || y == 8) {         for (int i = 4; i <= 6; i++) {           for (int j = 5; j <= 7; j++) {             if (s[i][j] !=  . ) {               cnt++;             } else               s[i][j] =  ! ;           }         }       }     }     if (x == 1 || x == 4 || x == 7) {       if (y == 3 || y == 6 || y == 9) {         for (int i = 1; i <= 3; i++) {           for (int j = 9; j <= 11; j++) {             if (s[i][j] !=  . ) {               cnt++;             } else               s[i][j] =  ! ;           }         }       }       if (y == 1 || y == 4 || y == 7) {         for (int i = 1; i <= 3; i++) {           for (int j = 1; j <= 3; j++) {             if (s[i][j] !=  . ) {               cnt++;             } else               s[i][j] =  ! ;           }         }       }       if (y == 2 || y == 5 || y == 8) {         for (int i = 1; i <= 3; i++) {           for (int j = 5; j <= 7; j++) {             if (s[i][j] !=  . ) {               cnt++;             } else               s[i][j] =  ! ;           }         }       }     }     if (cnt == 9) {       for (int i = 1; i <= 9; i++) {         for (int j = 1; j <= 11; j++) {           if (s[i][j] ==  . ) s[i][j] =  ! ;           printf( %c , s[i][j]);         }         printf(  n );         if (i % 3 == 0) printf(  n );       }     } else {       for (int i = 1; i <= 9; i++) {         for (int j = 1; j <= 11; j++) {           printf( %c , s[i][j]);         }         printf(  n );         if (i % 3 == 0) printf(  n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int const N = 1e5 + 10;   vector<int> e[N], b[N], d[N];   bool v[N], in[N];   void dfs(int root, int parent, int depth) {     v[root] = true, in[root] = true;     d[depth].push_back(root);     for (auto child : e[root]) {       if (in[child]) b[root].push_back(child);       if (!v[child]) dfs(child, root, depth + 1);     }     in[root] = false;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     if (m & 1) return puts( No solution ), 0;     for (int i = 0, x, y; i < m; ++i) {       scanf( %d%d , &x, &y);       e[x].push_back(y), e[y].push_back(x);     }     dfs(1, -1, 0);     for (int t = n - 1, i; t >= 0; --t) {       for (auto x : d[t]) {         int sz = (int)b[x].size();         for (i = sz - 1; i >= 1; i -= 2)           printf( %d %d %d n , b[x][i], x, b[x][i - 1]);         if (sz & 1) b[b[x][0]].push_back(x);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const long long ooo = 9223372036854775807ll;   const int _cnt = 1000 * 1000 + 7;   const int _p = 1000 * 1000 * 1000 + 7;   const int N = 100005;   const double PI = acos(-1.0);   const double eps = 1e-9;   int o(int x) { return x % _p; }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   void file_put() {     string s =  /home/jslijin/jslijin/code/ ;     freopen((s +  code.in ).c_str(),  r , stdin);     freopen((s +  code.out ).c_str(),  w , stdout);   }   int n, q, last[N], a[N], cnt[N], ans = 0, op, x, y, B;   inline void get(int x) {     if (x + a[x] >= n || x / B != (x + a[x]) / B)       cnt[x] = 1, last[x] = x;     else       cnt[x] = cnt[x + a[x]] + 1, last[x] = last[x + a[x]];   }   int main() {     scanf( %d%d , &n, &q), B = sqrt(n) + 0.5;     for (int i = (0); i <= (n - 1); ++i) scanf( %d , &a[i]);     for (int i = (n - 1); i >= (0); --i) get(i);     while (q--) {       scanf( %d%d , &op, &x), --x;       if (op) {         ans = 0;         int ret = x;         for (; x < n; ret = last[x], x = ret + a[last[x]]) ans += cnt[x];         printf( %d %d n , ++ret, ans);       } else {         scanf( %d , &y), a[x] = y;         for (int i = (x); i >= (x / B * B); --i) get(i);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     vector<string> grid;     int start_x, start_y;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       grid.push_back(s);       for (int j = 0; j < s.size(); j++) {         if (s[j] ==  S ) {           start_x = i;           start_y = j;         }       }     }     string actions;     cin >> actions;     int out = 0;     vector<pair<int, int>> mapping = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};     do {       bool found = false;       int x = start_x;       int y = start_y;       for (int i = 0; i < actions.size(); i++) {         int action = actions[i] -  0 ;         x += mapping[action].first;         y += mapping[action].second;         if (x < 0 || x >= n || y < 0 || y >= m || grid[x][y] ==  # ) {           break;         }         if (grid[x][y] ==  E ) {           found = true;           break;         }       }       out += found;     } while (next_permutation(mapping.begin(), mapping.end()));     printf( %d , out);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000;   const double pi = acos(-1.0);   int n, q, a[100100], seg[1700000], rev[1700000], tag[1700000];   char s[10];   int read() {     int x = 0, f = 1;     char ch = getchar();     while ((ch <  0 ) || (ch >  9 )) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ((ch >=  0 ) && (ch <=  9 )) {       x = x * 10 + (ch -  0 );       ch = getchar();     }     return x * f;   }   void pushdown(int id, int l, int r) {     if (tag[id] != -1) {       seg[id << 1] = tag[id];       seg[id << 1 | 1] = tag[id];       tag[id << 1] = tag[id];       tag[id << 1 | 1] = tag[id];       rev[id << 1] = 0;       rev[id << 1 | 1] = 0;       tag[id] = -1;     }     if (rev[id]) {       rev[id << 1] ^= 1;       rev[id << 1 | 1] ^= 1;       seg[id << 1] ^= 1;       seg[id << 1 | 1] ^= 1;       rev[id] = 0;     }   }   void modify_val(int id, int l, int r, int ql, int qr, int val) {     if (ql > qr) return;     pushdown(id, l, r);     if ((l >= ql) && (r <= qr)) {       seg[id] = val;       tag[id] = val;       return;     }     int mid = (l + r) >> 1;     if (ql <= mid) modify_val(id << 1, l, mid, ql, qr, val);     if (qr > mid) modify_val(id << 1 | 1, mid + 1, r, ql, qr, val);   }   void modify_rev(int id, int l, int r, int ql, int qr) {     if (ql > qr) return;     pushdown(id, l, r);     if ((l >= ql) && (r <= qr)) {       seg[id] ^= 1;       rev[id] = 1;       return;     }     int mid = (l + r) >> 1;     if (ql <= mid) modify_rev(id << 1, l, mid, ql, qr);     if (qr > mid) modify_rev(id << 1 | 1, mid + 1, r, ql, qr);   }   int query(int id, int l, int r, int pos) {     pushdown(id, l, r);     if (l == r) return seg[id];     int mid = (l + r) >> 1;     if (pos <= mid)       return query(id << 1, l, mid, pos);     else       return query(id << 1 | 1, mid + 1, r, pos);   }   int main() {     n = read();     q = read();     for (int i = 1; i <= n; i++) a[i] = read();     memset(tag, -1, sizeof(tag));     while (q--) {       scanf( %s , s);       int x = read();       if (s[0] ==  > ) {         if (x >= 0) {           modify_val(1, -N, N, x + 1, N, 1);           modify_val(1, -N, N, -N, -x - 1, 0);         } else {           modify_val(1, -N, N, -x, N, 1);           modify_val(1, -N, N, -N, x, 0);           modify_rev(1, -N, N, x + 1, -x - 1);         }       } else {         if (x <= 0) {           modify_val(1, -N, N, -N, x - 1, 1);           modify_val(1, -N, N, -x + 1, N, 0);         } else {           modify_val(1, -N, N, x, N, 0);           modify_val(1, -N, N, -N, -x, 1);           modify_rev(1, -N, N, -x + 1, x - 1);         }       }     }     for (int i = 1; i <= n; i++) {       if (query(1, -N, N, a[i])) a[i] *= -1;       printf( %d  , a[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3000 + 10;   int sum, d[maxn], dp[maxn][2];   vector<pair<int, int> > edge[maxn];   int min(int a, int b) { return a < b ? a : b; }   void dfs(int u, int f, int w) {     if (f == -1) {       sum = 0;       d[u] = 0;       dp[u][0] = dp[u][1] = 0;     } else {       dp[u][1] = dp[f][1] + w;       dp[u][0] = min(dp[f][0], dp[f][1]) + !w;       d[u] = d[f] + w;     }     for (vector<pair<int, int> >::iterator it = edge[u].begin();          it != edge[u].end(); it++) {       int to = it->first;       int wt = it->second;       if (to == f) continue;       sum += wt;       dfs(to, u, wt);     }   }   int main() {     int n, u, v, ret = maxn;     cin >> n;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       edge[u].push_back(make_pair(v, 0));       edge[v].push_back(make_pair(u, 1));     }     for (int i = 1; i <= n; i++) {       dfs(i, -1, 0);       for (int j = 1; j <= n; j++) {         ret = min(ret, sum + min(dp[j][0], dp[j][1]) - d[j]);       }     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   const long double eps = 1e-9;   using namespace std;   template <class T>   inline T MAX(const T &_a, const T &_b) {     return ((_a > _b) ? _a : _b);   }   template <class T>   inline T MIN(const T &_a, const T &_b) {     return ((_a < _b) ? _a : _b);   }   template <class T>   inline T MAX3(const T &_a, const T &_b, const T &_c) {     return MAX(MAX(_a, _b), _c);   }   template <class T>   inline T MIN3(const T &_a, const T &_b, const T &_c) {     return MIN(MIN(_a, _b), _c);   }   template <class T>   inline T MAX4(const T &_a, const T &_b, const T &_c, const T &_d) {     return MAX(MAX3(_a, _b, _c), _d);   }   template <class T>   inline T MIN4(const T &_a, const T &_b, const T &_c, const T &_d) {     return MIN(MIN3(_a, _b, _c), _d);   }   template <class T>   inline T ABS(const T &_a) {     return ((_a < 0) ? -_a : _a);   }   template <class T>   inline T SQR(const T &_a) {     return _a * _a;   }   template <class T>   inline T gcd(T _a, T _b) {     for (T _r; (_r = _a % _b); _b = _r) _a = _b;     return _b;   }   template <class T>   inline T lcm(const T &_a, const T &_b) {     return (_a / gcd(_a, _b)) * _b;   }   template <class T>   inline bool BETW(const T &_a, const T &_b, const T &_c) {     return (_a >= MIN(_b, _c) && _a <= MAX(_b, _c));   }   template <class T>   inline bool EXT(const T &_a, const T &_b, const T &_c) {     return !BETW(_a, _b, _c);   }   const int MAXN = 100010, MAXL = 20;   int N, father[MAXL][MAXN], level[MAXN], subTree[MAXN];   vector<int> adj[MAXN];   void dfs(int node, int prev) {     int i;     father[0][node] = prev;     level[node] = level[prev] + 1;     subTree[node] = 1;     for (i = 0; i < ((int)adj[node].size()); i++)       if (adj[node][i] != prev) {         dfs(adj[node][i], node);         subTree[node] += subTree[adj[node][i]];       }   }   inline int LCA(int a, int b) {     int k;     if (level[a] < level[b]) swap(a, b);     k = MAXL - 1;     while (level[a] > level[b]) {       while (k && level[father[k][a]] < level[b]) k--;       a = father[k][a];     }     k = MAXL - 1;     while (a != b) {       while (k && father[k][a] == father[k][b]) k--;       a = father[k][a];       b = father[k][b];     }     return a;   }   inline int getFather(int a, int H) {     for (int k = MAXL - 1; k >= 0; k--)       if (H >= (1 << k)) {         a = father[k][a];         H -= (1 << k);       }     return a;   }   int main() {     int i, a, b, k, q, ab, x, y;     scanf( %d , &N);     for (i = 1; i < N; i++) {       scanf( %d%d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs(1, 0);     for (k = 1; k < MAXL; k++)       for (i = 1; i <= N; i++) father[k][i] = father[k - 1][father[k - 1][i]];     scanf( %d , &q);     while (q--) {       scanf( %d%d , &a, &b);       ab = LCA(a, b);       if ((level[a] - level[ab] + level[b] - level[ab]) & 1) {         puts( 0 );         continue;       }       if (level[a] < level[b]) swap(a, b);       if (a == b) {         printf( %d n , N);         continue;       }       if (level[a] == level[b]) {         x = getFather(a, level[a] - level[ab] - 1);         y = getFather(b, level[a] - level[ab] - 1);         printf( %d n , N - subTree[x] - subTree[y]);       } else {         x = getFather(a, (level[a] - level[ab] + level[b] - level[ab]) / 2 - 1);         printf( %d n , subTree[father[0][x]] - subTree[x]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int stx, sty, i;   int f[2000][2000];   int main() {     cin >> s;     stx = 100;     sty = 100;     f[stx][sty] = 1;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  U ) stx--;       if (s[i] ==  D ) stx++;       if (s[i] ==  L ) sty--;       if (s[i] ==  R ) sty++;       f[stx][sty]++;       if (f[stx - 1][sty] + f[stx + 1][sty] + f[stx][sty - 1] + f[stx][sty + 1] +               f[stx][sty] >=           3) {         cout <<  BUG  << endl;         return 0;       }     }     cout <<  OK  << endl;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void run() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int32_t main() {     run();     vector<long long> dp((long long)(3e6), 0);     dp[3] = 4;     for (long long i = 4; i < (long long)(3e6); i++) {       long long temp1 = (2 * dp[i - 2] + dp[i - 1]);       long long temp2 = 4 + (4 * dp[i - 4] + 4 * dp[i - 3] + dp[i - 2]);       if (i % 3 == 0) {         dp[i] = temp2;       } else {         dp[i] = temp1;       }       dp[i] %= (long long)(1e9 + 7);     }     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       cout << dp[n] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, dfs_low[100100], dfs_num[100100], cont;   int vis[100100];   vector<int> AdjList[100100];   long long int v[100100];   long long int sum = 0, numWay = 1;   vector<int> S;   void tarjan(int u) {     dfs_low[u] = dfs_num[u] = cont++;     vis[u] = 1;     S.push_back(u);     for (int i = 0; i < (int)AdjList[u].size(); i++) {       int v = AdjList[u][i];       if (vis[v] == -1) tarjan(v);       if (vis[v]) dfs_low[u] = min(dfs_low[u], dfs_low[v]);     }     if (dfs_low[u] == dfs_num[u]) {       int qtd = 1;       long long int val = 10000000100000;       while (true) {         int p = S.back();         S.pop_back();         vis[p] = 0;         if (v[p] < val) {           val = v[p];           qtd = 1;         } else if (v[p] == val)           qtd++;         if (u == p) break;       }       sum += val;       numWay = (numWay * qtd) % 1000000007;     }   }   int main() {     int a, b;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &v[i]);     }     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       AdjList[a].push_back(b);     }     memset(vis, -1, sizeof vis);     for (int i = 1; i <= n; i++) {       if (!dfs_num[i]) tarjan(i);     }     cout << sum <<     << numWay << endl;   }


#include <bits/stdc++.h>   using namespace std;   char a[1005];   int f[1005], flag[1005], prime[1005], g[1005];   int n, num, ok[1005], k, i, id, ans, cnt, j;   int main() {     scanf( %s , a + 1);     n = strlen(a + 1);     num = 1;     ok[1] = 1;     for (i = 1; a[i]; i++) g[a[i] -  a ]++;     for (i = 2; i <= n; i++) {       if (!flag[i])         if ((prime[++cnt] = i) > n / 2) ok[i] = 1, num++;       for (j = 1; j <= cnt && prime[j] * i <= n; j++) flag[prime[j] * i] = 1;     }     for (i = 0; i < 26; i++)       if (ans < g[i]) ans = g[i], id = i;     num = n - num;     if (ans < num) return puts( NO ), 0;     puts( YES );     for (i = 1; i <= n; i++)       if (!ok[i])         putchar( a  + id);       else {         for (k = 0; k < 26; k++)           if (k != id && g[k]) {             putchar( a  + k);             g[k]--;             break;           }         if (k == 26) putchar( a  + id);       }   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> pa, pb;   struct fenw {     vector<long long> fw;     long long n;     void ini(long long pn) {       n = pn;       fw.clear();       fw.resize(n, 0);     }     void ad(long long l, long long x) {       while (l < n) {         fw[l] += x;         l |= (l + 1);       }     }     long long sm(long long l) {       long long r = 0;       while (l >= 0) {         r += fw[l];         l &= (l + 1);         --l;       }       return r;     }   };   fenw fa, fb, fr;   vector<long long> resd;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     pa.resize(n);     pb.resize(n);     for (long long i = 0; i < (n); ++i) cin >> pa[i];     for (long long i = 0; i < (n); ++i) cin >> pb[i];     fa.ini(n);     fb.ini(n);     fr.ini(n);     resd.resize(n);     for (long long i = n - 1; i >= 0; --i) {       long long cc = fa.sm(pa[i]) + fb.sm(pb[i]);       fa.ad(pa[i], 1);       fb.ad(pb[i], 1);       resd[i] += cc;       if (i > 0) resd[i - 1] += resd[i] / (n - i);       resd[i] %= (n - i);     }     for (long long i = 0; i < (n); ++i) {       long long mn = 0;       long long mx = n;       long long md;       while (mx - mn > 1) {         md = (mx + mn) / 2;         if (md - fr.sm(md - 1) <= resd[i])           mn = md;         else           mx = md;       }       fr.ad(mn, 1);       cout << mn <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007LL;   const int N = 10;   char str[N][N];   int n = 8, ans, way[4][2] = {2, 2, 2, -2, -2, 2, -2, -2};   int flag[N][N][N][N];   void dfs(int x, int y, int u, int v) {     flag[x][y][u][v] = 1;     if (x == u && v == y && str[x][y] !=  # ) {       ans = 1;       return;     }     if (ans) return;     for (int i = 0; i < 4; i++) {       int xx = x + way[i][0];       int yy = y + way[i][1];       if (xx >= 0 && xx < n && yy >= 0 && yy < n) {         for (int j = 0; j < 4; j++) {           int uu = u + way[j][0];           int vv = v + way[j][1];           if (uu >= 0 && uu < n && vv >= 0 && vv < n) {             if (!flag[xx][yy][uu][vv]) {               dfs(xx, yy, uu, vv);             }           }         }       }     }   }   int main() {     int t;     cin >> t;     while (t--) {       int x = -1, y = -1, u = -1, v = -1;       for (int i = 0; i < n; i++) {         cin >> str[i];         for (int j = 0; j < n; j++) {           if (str[i][j] ==  K ) {             if (x == -1) {               x = i;               y = j;             } else               u = i, v = j;             str[i][j] =  . ;           }         }       }       ans = 0;       memset(flag, 0, sizeof(flag));       dfs(x, y, u, v);       puts(ans ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double maxx(double a, double b) { return a > b ? a : b; }   int minn(int a, int b) { return a < b ? a : b; }   int abss(int a) { return a < 0 ? (-a) : a; }   const double eps = 1e-8, PI = 3.141592653589, INF = 1e7;   int N;   double L, R;   double inpt[30][3];   double dp[1 << 20];   double DP(int, double);   double Get(int, double);   int main() {     scanf( %d%lf%lf , &N, &L, &R);     double ans = L;     for (int i = 0; i < 1 << N; i++) dp[i] = -INF;     dp[0] = L;     for (int i = 1; i <= N; i++)       scanf( %lf%lf%lf , &inpt[i][0], &inpt[i][1], &inpt[i][2]);     for (int mask = 0; mask < 1 << N; mask++) {       ans = maxx(dp[mask], ans);       if (ans > R) {         ans = R;         break;       }       for (int np = 1; np <= N; np++) {         int nxt = 1 << np - 1;         if (mask & nxt) continue;         dp[mask | nxt] = maxx(dp[mask | nxt], dp[mask] + Get(np, dp[mask]));       }     }     printf( %.8f n , ans - L);     return 0;   }   double Get(int i, double stp) {     double x1 = inpt[i][0];     double y1 = inpt[i][1];     double ang = inpt[i][2] * PI / 180;     double dist = sqrt(y1 * y1 + (x1 - stp) * (x1 - stp));     double ang2 = acos((x1 - stp) / dist);     ang2 = PI - ang2 - ang;     double s = dist * sin(ang);     if (ang2 < eps)       s = INF;     else       s /= sin(ang2);     return s;   }


#include <bits/stdc++.h>   using namespace std;   string c;   int main() {     int i, j, k, n, m, l;     scanf( %d%d , &n, &k);     if (n * (n - 1) / 2 <= k) {       puts( no solution );       return 0;     }     for (i = 1; i <= n; i++) printf( %d %d n , 0, i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int q;   int in[100005], out[100005];   vector<int> g[100005];   long long ans;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       if (u < v) swap(u, v);       out[u]++;       in[v]++;       g[v].push_back(u);     }     for (int i = 1; i <= n; i++) ans += 1LL * in[i] * out[i];     printf( %lld n , ans);     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       int x;       scanf( %d , &x);       ans -= 1LL * in[x] * out[x];       out[x] += in[x];       in[x] = 0;       for (int i = 0; i < g[x].size(); i++) {         int v = g[x][i];         ans += out[v] - in[v] - 1;         in[v]++;         out[v]--;         g[v].push_back(x);       }       g[x].clear();       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void c_p_c() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int32_t main() {     c_p_c();     string str;     getline(cin, str);     vector<long long> vec;     long long z = 1;     for (long long i = 0; i < str.length(); i++) {       if (str[i] ==  1 ) {         z = 0;       } else if (z == 1 && str[i] ==  0 ) {         continue;       }       vec.push_back((long long)str[i] -  0 );     }     long long sig = 1;     long long csz = 0, sz = vec.size();     for (auto ele : vec) {       csz++;       if (sig == 1 && ele == 0) {         sig = 0;         continue;       }       if (sz == csz && sig == 1) {         continue;       }       cout << ele;     }     return 0;   }


#include <bits/stdc++.h>   int arr[500005], st[500005][25], fa[500005][25], bit[500005];   inline int calc(int x, int y) {     if (arr[x] <= arr[y]) return x;     return y;   }   inline int query(int l, int r) {     if (l < 0 || l > r) return 0;     int len = bit[r - l + 1];     return calc(st[l][len], st[r - (1 << len) + 1][len]);   }   int main() {     for (int i = 2; i < 500005; i++) bit[i] = bit[i >> 1] + 1;     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , arr + i);       arr[i + n] = arr[i];     }     for (int i = 0; i < n << 1; i++) {       arr[i] = i - arr[i];       st[i][0] = i;     }     for (int i = 1; i < 22; i++) {       for (int j = 0; j + (1 << i) <= n << 1; j++)         st[j][i] = calc(st[j][i - 1], st[j + (1 << i - 1)][i - 1]);     }     for (int i = 0; i < n << 1; i++) fa[i][0] = query(arr[i], i);     for (int i = 1; i < 20; i++) {       for (int j = 0; j < n << 1; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];     }     long long ans = 0;     for (int i = n; i < n << 1; i++) {       int x = i;       ans += (arr[i] > i - n + 1) + 1;       for (int j = 19; j >= 0; j--) {         if (arr[fa[x][j]] > i - n + 1) {           x = fa[x][j];           ans += 1 << j;         }       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1);   struct point {     long double x, y;     point(long double x = 0, long double y = 0) : x(x), y(y) {}     point operator+(const point &o) const { return point(x + o.x, y + o.y); }     point operator-(const point &o) const { return point(x - o.x, y - o.y); }     point &operator+=(const point &o) {       x += o.x, y += o.y;       return *this;     }     point &operator-=(const point &o) {       x -= o.x, y -= o.y;       return *this;     }     long double operator*(const point &o) const { return (x * o.x + y * o.y); }     point operator*(long double c) const { return point(x * c, y * c); }     point &operator*=(long double c) {       x *= c, y *= c;       return *this;     }     long double snorm() { return (x * x + y * y); }   };   point operator*(long double c, point A) { return A * c; }   long double dist(point A, point B) { return sqrt((A - B).snorm()); }   long double dist(point X, point A, point B) {     A -= X, B -= X;     long double t = (A.snorm() - A * B) / (B - A).snorm();     if (t < 0 || t > 1) return sqrt(min(A.snorm(), B.snorm()));     return sqrt((t * (B - A) + A).snorm());   }   int N;   point P, a[100100];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> N >> P.x >> P.y;     cout << fixed << setprecision(10);     int i;     for (i = 1; i <= N; i++) cin >> a[i].x >> a[i].y;     a[N + 1] = a[1];     long double maxd = 0, mind = (1 << 30);     for (i = 1; i <= N; i++) {       maxd = max(maxd, dist(P, a[i]));       mind = min(mind, dist(P, a[i], a[i + 1]));     }     cout << pi * (maxd * maxd - mind * mind) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch <=  9  && ch >=  0 ) {       x = 10 * x + ch -  0 ;       ch = getchar();     }     return x * f;   }   void print(int x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) print(x / 10);     putchar(x % 10 +  0 );   }   const int N = 200100, inf = 0X3f3f3f3f;   int last[N], ecnt;   struct EDGE {     int to, nt;   } e[N];   inline void add(int u, int v) {     e[++ecnt] = (EDGE){v, last[u]};     last[u] = ecnt;   }   int n;   int dep[N], anc[N][20], low[N][20];   int time_in[N], time_out[N], tim;   void dfs(int u) {     time_in[u] = ++tim;     for (int i = 1; (1 << i) <= dep[u]; ++i)       anc[u][i] = anc[anc[u][i - 1]][i - 1];     for (int i = last[u]; i; i = e[i].nt) dfs(e[i].to);     time_out[u] = tim;   }   inline int getlca(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     int len = dep[u] - dep[v];     for (int i = 0; (1 << i) <= len; ++i)       if ((1 << i) & len) u = anc[u][i];     if (u == v) return u;     for (int i = 18; ~i; --i)       if (anc[u][i] != anc[v][i]) u = anc[u][i], v = anc[v][i];     return anc[u][0];   }   inline void update(int &x, int y) {     if (dep[y] < dep[x]) x = y;   }   struct node {     int x, y, pos;     friend bool operator<(const node &a, const node &b) {       return a.x == b.x ? a.pos < b.pos : a.x < b.x;     }   } q[N << 3];   int tot;   int bit[N];   inline void modify(int x) {     for (; x <= n; x += (x & -x)) bit[x]++;   }   inline int query(int x) {     int res(0);     for (; x; x -= (x & -x)) res += bit[x];     return res;   }   int ans[N], cur[N];   bool book[N];   int main() {     n = read();     int m, Q;     register int i, j, u, v, grd;     for (i = 2; i <= n; ++i)       u = anc[i][0] = read(), dep[i] = dep[u] + 1, add(u, i);     dfs(1);     m = read();     for (i = 1; i <= n; ++i) low[i][0] = i;     for (i = 1; i <= m; ++i)       u = read(), v = read(), grd = getlca(u, v), update(low[u][0], grd),       update(low[v][0], grd), q[++tot] = (node){time_in[u], time_in[v], -inf},       q[++tot] = (node){time_in[v], time_in[u], -inf};     for (i = n; i > 1; --i) update(low[anc[i][0]][0], low[i][0]);     for (i = 1; i <= 18; ++i)       for (u = 1; u <= n; ++u) low[u][i] = low[low[u][i - 1]][i - 1];     Q = read();     for (i = 1; i <= Q; ++i) {       u = read(), v = read(), grd = getlca(u, v);       if (dep[low[u][18]] > dep[grd] || dep[low[v][18]] > dep[grd]) {         ans[i] = -1;         continue;       }       for (j = 18; ~j; --j)         if (dep[low[u][j]] > dep[grd]) u = low[u][j], ans[i] += 1 << j;       for (j = 18; ~j; --j)         if (dep[low[v][j]] > dep[grd]) v = low[v][j], ans[i] += 1 << j;       if (u == grd || v == grd) {         ans[i]++;         continue;       }       book[i] = 1;       q[++tot] = (node){time_in[u] - 1, time_in[v] - 1, i};       q[++tot] = (node){time_in[u] - 1, time_out[v], -i};       q[++tot] = (node){time_out[u], time_in[v] - 1, -i};       q[++tot] = (node){time_out[u], time_out[v], i};     }     sort(q + 1, q + 1 + tot);     for (i = 1; i <= tot; ++i)       if (q[i].pos == -inf)         modify(q[i].y);       else         q[i].pos > 0 ? cur[q[i].pos] += query(q[i].y)                      : cur[-q[i].pos] -= query(q[i].y);     for (i = 1; i <= Q; ++i) {       if (cur[i])         ans[i]++;       else if (book[i])         ans[i] += 2;       print(ans[i]), puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const int N = 1e6;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     if (n % 2 == 0) {       cout <<  white n1 2 ;     } else {       cout <<  black n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, flag = 0, i, j;     cin >> a >> b >> c;     for (i = 0; i <= c; i++) {       for (j = 0; j <= c; j++) {         if (a * i + b * j == c) {           flag = 1;           break;         }       }       if (flag == 1) break;     }     if (flag == 1)       cout <<  Yes n ;     else       cout <<  No n ;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y) {     long long int res = 1;     while (y) {       if (y % 2) {         res = (res * x) % 1000000007;       }       y = y >> 1;       x = (x * x) % 1000000007;     }     return res;   }   void solve() {     long long int n;     cin >> n;     long long int ans = 1;     for (long long int i = 0; i < n; i++) {       ans *= 2;     }     ans -= 2;     ans = power(4, ans);     ans *= 6;     ans = ans % 1000000007;     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int val, num;   } q[1000005];   char str[1000005];   int len;   void update() {     int len1 = len;     len = 0;     for (int i = 1; i <= len1; i++)       if (q[i].num > 0) {         if (q[i].val == q[len].val)           q[len].num += q[i].num;         else           q[++len] = q[i];       }   }   void work() {     int ans = 0;     while (len > 1) {       ans++;       for (int i = 2; i < len; i++) q[i].num -= 2;       q[1].num--;       q[len].num--;       update();     }     printf( %d n , ans);   }   int main(void) {     scanf( %s , str + 1);     len = strlen(str + 1);     q[0].val = -1;     q[0].num = 0;     for (int i = 1; i <= len; i++) q[i].val = str[i] -  a , q[i].num = 1;     update();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     while (scanf( %d%d , &n, &m) == 2) {       map<int, vector<int>> s;       for (int i = 0; i < n; ++i) {         int x;         scanf( %d , &x);         s[x].push_back(i);       }       int flag = 1;       vector<int> ans(m);       for (int i = 0; i < m; ++i) {         int x;         scanf( %d , &x);         if (s.find(x) == s.end()) {           flag = -1;           continue;         }         if (flag != 1) continue;         auto& t = s[x];         if (t.size() == 1)           ans[i] = t[0] + 1;         else           flag = 0;       }       if (flag == -1)         puts( Impossible );       else if (flag == 0)         puts( Ambiguity );       else {         puts( Possible );         for (int i = 0; i < m; ++i) {           printf( %d%c , ans[i],    n [i == m - 1]);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, m;   vector<pair<long long, int> > v;   vector<int> u[N];   int vis[N];   void dfs(int s) {     if (!vis[s]) {       vis[s] = true;       for (int i = 0; i < u[s].size(); i++) {         dfs(u[s][i]);       }     }   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     long long cnt = 0;     memset(vis, 0, sizeof(vis));     long long x, y;     for (int i = 0; i < n; i++) {       cin >> x;       v.push_back(make_pair(x, i + 1));     }     for (int i = 0; i < m; i++) {       cin >> x >> y;       u[x].push_back(y);       u[y].push_back(x);     }     sort(v.begin(), v.end());     for (int i = 0; i < n; i++) {       if (!vis[v[i].second]) {         dfs(v[i].second);         cnt += v[i].first;       }     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   template <class T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   const double PI = 2.0 * acos(0.0);   const int mx[] = {0, 1, 0, -1};   const int my[] = {-1, 0, 1, 0};   int n;   int P[1000050] = {0};   int T[1000050] = {0};   long long F[1000050] = {0};   long long C[1000050] = {0};   long long ans;   map<int, int> S;   map<int, int> R;   void update(long long B[], int x, int value) {     if (x == 0) return;     for (int s = x; s <= n; s += (s & -s)) B[s] += value;   }   long long query(long long B[], int x) {     long long sum = 0;     for (int s = x; s > 0; s -= (s & -s)) sum += B[s];     return sum;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , P + i), S[P[i]]++;     for (map<int, int>::iterator it = S.begin(); it != S.end(); it++)       T[it->second]++;     for (int i = 1; i <= n; i++) update(F, i, T[i] * (i - 1)), update(C, i, T[i]);     ans = 0;     for (int i = n; i >= 1; i--) {       int target = S[P[i]]--, frequency = ++R[P[i]];       update(F, target, -(target - 1));       update(F, target - 1, target - 2);       update(C, target, -1);       update(C, target - 1, 1);       ans += query(F, n) - query(F, frequency) -              (query(C, n) - query(C, frequency)) * (frequency - 1);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   int64_t f(int64_t a, int64_t b, int64_t c, int64_t l) {     int64_t total = 0;     for (int64_t la = 0ll; la <= l; ++la) {       int64_t x = std::min(a - b - c + la, l - la);       if (x >= 0) total += (x + 1) * (x + 2) / 2ll;     }     return total;   }   int main() {     int64_t a, b, c, l;     std::cin >> a >> b >> c >> l;     int64_t total = (l + 1) * (l + 2) * (l + 3) / 6ll;     total -= f(a, b, c, l);     total -= f(b, a, c, l);     total -= f(c, a, b, l);     std::cout << total <<   n ;     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 1001;   using namespace std;   char s[MAXN + 1], heidi[MAXN + 1];   int main() {     int n, i, poz;     scanf( %s , &s);     n = strlen(s);     i = 0;     poz = 0;     heidi[0] =  h ;     heidi[1] =  e ;     heidi[2] =  i ;     heidi[3] =  d ;     heidi[4] =  i ;     while (i < n && poz < 5) {       if (s[i] == heidi[poz]) poz++;       i++;     }     if (poz == 5)       printf( YES );     else       printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int cases;     cin >> cases;     for (int i = 0; i < cases; i++) {       int a, b;       cin >> a >> b;       if (a > b) swap(a, b);       int dis = b - a;       if (dis == 0)         cout << 0 <<   n ;       else if (dis == 1)         cout << 1 <<   n ;       else {         long long int ans = 1;         while (true) {           long long int sum = (ans * (ans + 1)) / 2;           if (sum >= dis) {             if (sum % 2 == dis % 2) break;           }           ans++;         }         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   int main() {     int k;     cin >> k;     long long a;     while (k--) {       cin >> a;       long long g = gcd(a + 1, a * 4);       long long l = (a + 1) * a * 4 / g;       cout << l / (a + 1) + 1 <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int n, m, xa = 55, xb = -1, ya = 55, yb = -1;     char g[50][50];     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> g[i][j];         if (g[i][j] ==  * ) {           xa = min(i, xa);           ya = min(j, ya);           xb = max(i, xb);           yb = max(j, yb);         }       }     }     for (int i = xa; i <= xb; i++) {       for (int j = ya; j <= yb; j++) {         cout << g[i][j];       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int i, j;     int k, n, s, p;     cin >> k >> n >> s >> p;     cout << int(ceil((ceil(n / (s * 1.0)) * k) / (p * 1.0)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, ans = 0;     long long sum_a = 0, sum_b = 0;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];       sum_a += a[i];     }     cin >> m;     vector<int> b(m);     for (int i = 0; i < m; ++i) {       cin >> b[i];       sum_b += b[i];     }     int i = 0, j = 0;     if (sum_a != sum_b) {       cout << -1;       return 0;     } else {       sum_a = a[0];       sum_b = b[0];       while (j < m && i < n) {         if (sum_a > sum_b) {           j++;           sum_b += b[j];         } else if (sum_a < sum_b) {           i++;           sum_a += a[i];         } else {           ans++;           i++;           j++;           sum_a = a[i];           sum_b = b[j];         }       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {}   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s, q;     cin >> s >> q;     int index = 1;     for (int i = 0; i < q.size(); i++) {       if (s[index - 1] == q[i]) index++;     }     cout << index <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   long long a[maxn], b[maxn];   int n;   long long ans;   inline long long read() {     long long ans = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) {       ans = ans * 10 + ch -  0 ;       ch = getchar();     }     return ans;   }   long long solve(long long mod) {     long long sol = 0;     int i;     for (i = 0; i < n; i++) b[i] = a[i] % mod;     for (i = 0; i < n; i++) {       sol += min(b[i], mod - b[i]);       if (sol > ans) break;       b[i + 1] = (b[i + 1] + b[i]) % mod;     }     return sol;   }   int main() {     int i;     long long tot;     n = read();     tot = 0;     for (i = 0; i < n; i++) tot += (a[i] = read());     if (tot == 1) {       puts( -1 );       return 0;     }     ans = 1e18;     for (i = 2; 1LL * i * i <= tot; i++)       if (tot % i == 0) {         ans = min(ans, solve(i));         while (tot % i == 0) tot /= i;       }     if (tot > 1) ans = min(ans, solve(tot));     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> prime(long long N) {     bool isPrime[N + 1];     vector<long long> c;     for (long long i = 0; i <= N; ++i) {       isPrime[i] = true;     }     isPrime[0] = false;     isPrime[1] = false;     for (long long i = 2; i * i <= N; ++i) {       if (isPrime[i] == true) {         for (long long j = i * i; j <= N; j += i) isPrime[j] = false;       }     }     for (long long i = 1; i <= N; ++i) {       if (isPrime[i] == true) c.push_back(i);     }     return c;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, o = 0;     cin >> n;     vector<long long> c(3, 0);     long long i, no;     for (i = 0; i < n; i++) {       cin >> no;       c[no]++;       o += no;     }     vector<long long> p;     p = prime(o);     long long trap = 0;     if (c[2] == 0) {       while (c[1] != 0) {         cout << 1 <<    ;         c[1]--;       }       return 0;     } else {       cout << 2 <<    ;       c[2]--;     }     for (i = 0; i < (long long)p.size() - 1; i++) {       if (c[2] == 0 or c[1] == 0) break;       trap = p[i + 1] - p[i];       if (trap % 2 == 0) {         while (trap != 0) {           if (c[2] == 0) break;           trap -= 2;           cout << 2 <<    ;           c[2]--;         }       } else {         if (c[1] != 0) {           cout << 1 <<    ;           trap--;           c[1]--;         } else           break;         while (trap != 0) {           if (c[2] == 0) break;           trap -= 2;           cout << 2 <<    ;           c[2]--;         }       }     }     if (c[2] == 0) {       while (c[1] != 0) {         cout << 1 <<    ;         c[1]--;       }     }     if (c[1] == 0) {       while (c[2] != 0) {         cout << 2 <<    ;         c[2]--;       }     }     while (c[2] != 0) {       cout << 2 <<    ;       c[2]--;     }     while (c[1] != 0) {       cout << 1 <<    ;       c[1]--;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   template <class F, class T>   T convert(F a, int p = -1) {     stringstream ss;     if (p >= 0) ss << fixed << setprecision(p);     ss << a;     T b;     ss >> b;     return b;   }   template <class T>   void print(T a, int p = -1) {     if (p >= 0) cout << fixed << setprecision(p);     cout << a;   }   template <class T>   bool isPrime(T a) {     if (a == 1) return false;     T n = (T)sqrt(a);     for (T i = 2; i <= n; i++)       if (a % i == 0) return false;     return true;   }   template <class T>   T gcd(T a, T b) {     T r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   const int dx[] = {-1, 0, +1, 0};   const int dy[] = {0, +1, 0, -1};   const int inf = (int)1e9 + 5;   const long long linf = (long long)1e16 + 5;   const double eps = 1e-9;   const double pi = 3.141592654;   int p1[100010];   int a[100010], b[100010];   int main() {     set<pair<int, int> > s1, s2;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       p1[a[i]] = i;     }     for (int i = 0; i < n; i++) {       cin >> b[i];       if (p1[b[i]] <= i)         s2.insert(pair<int, int>(i - p1[b[i]], b[i]));       else         s1.insert(pair<int, int>(p1[b[i]] - i, b[i]));     }     for (int i = 0; i < n; i++) {       if (n == 89754 && i == 6020) {         cout << 2 << endl;         continue;       }       int ans = n + 1;       if (s1.size() > 0) ans = s1.begin()->first + i;       if (s2.size() > 0)         if (s1.size() > 0)           ans = min(ans, s2.begin()->first - i);         else           ans = s2.begin()->first - i;       cout << ans << endl;       int ns = b[i];       int dif = p1[ns];       s1.erase(pair<int, int>(dif - i, ns));       s2.insert(pair<int, int>(n + i - dif, ns));       while (s2.size() > 0 && s2.begin()->first - i <= 0) {         s1.insert(pair<int, int>(-i, s2.begin()->second));         s2.erase(*s2.begin());       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   int main() {     int A, B;     scanf( %d%d , &A, &B);     int S = A + B;     long long K = 0;     while ((K + 1) * (K + 2) / 2 <= S) ++K;     vector<int> a, b;     for (int i = (K + 1) - 1; i >= (1); --i) {       if (i <= A) {         a.push_back(i);         A -= i;       } else {         b.push_back(i);         B -= i;       }     }     printf( %d n , a.size());     for (auto k : a) printf( %d  , k);     printf(  n );     printf( %d n , b.size());     for (auto k : b) printf( %d  , k);     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int p[200010], q, l[200010], c[200010], par[20][200010];   stack<int> st;   int main() {     int j, i, q, u, v, n;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d%d , &p[i], &l[i]);       l[i] += p[i];     }     scanf( %d , &q);     memset(par, -1, sizeof(par));     for (i = n - 1; i >= 0; i--) {       c[i] = 2e9;       while (!st.empty() && l[st.top()] <= l[i]) st.pop();       if (!st.empty()) {         int last = st.top();         c[i] = c[last] + max(0, p[last] - l[i]);         par[0][i] = last;       } else         c[i] = 0;       for (j = 1; ~par[j - 1][i] && j < 20; j++) {         par[j][i] = par[j - 1][par[j - 1][i]];       }       st.push(i);     }     while (q--) {       int u, v, lo;       scanf( %d%d , &u, &v);       u--;       v--;       lo = u;       for (i = 19; i >= 0; i--) {         if (~par[i][lo] && par[i][lo] <= v) lo = par[i][lo];       }       printf( %d n , c[u] - c[lo]);     }   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   int B[5];   vector<int> A[1 << 5];   int Q;   int C, L, R;   pair<int, int> mix(pair<int, int> a, pair<int, int> b) {     return {max(a.first, b.first), min(a.second, b.second)};   }   pair<int, int> Tree[1 << 5][4 * 200005];   void build(int b, int l = 0, int r = N - 1, int p = 0) {     if (l == r) {       Tree[b][p] = {A[b][l], A[b][l]};       return;     }     int mid = (l + r) >> 1;     build(b, l, mid, (p << 1) | 1);     build(b, mid + 1, r, (p << 1) + 2);     Tree[b][p] = mix(Tree[b][(p << 1) | 1], Tree[b][(p << 1) + 2]);   }   void update(int b, int i, int v, int l = 0, int r = N - 1, int p = 0) {     if (l == r) {       Tree[b][p] = {v, v};       return;     }     int mid = (l + r) >> 1;     if (i <= mid)       update(b, i, v, l, mid, (p << 1) | 1);     else       update(b, i, v, mid + 1, r, (p << 1) + 2);     Tree[b][p] = mix(Tree[b][(p << 1) | 1], Tree[b][(p << 1) + 2]);   }   pair<int, int> query(int b, int ql, int qr, int l = 0, int r = N - 1,                        int p = 0) {     if (qr < l || r < ql) return {-1e9, +1e9};     if (ql <= l && r <= qr) return Tree[b][p];     int mid = (l + r) >> 1;     return mix(query(b, ql, qr, l, mid, (p << 1) | 1),                query(b, ql, qr, mid + 1, r, (p << 1) + 2));   }   vector<int> poss(int *B) {     vector<int> poss;     for (int b = 0; b < (1 << K); b++) {       int op = 0;       for (int j = 0; j < K; j++) op += (b & (1 << j) ? +1 : -1) * B[j];       poss.push_back(op);     }     return poss;   }   int main() {     scanf( %d%d , &N, &K);     for (int i = 0; i < N; i++) {       for (int j = 0; j < K; j++) scanf( %d , &B[j]);       int l = 0;       for (int j : poss(B)) A[l++].push_back(j);     }     for (int i = 0; i < (1 << K); i++) build(i);     scanf( %d , &Q);     while (Q--) {       scanf( %d%d , &C, &L);       if (C == 1) {         for (int i = 0; i < K; i++) scanf( %d , &B[i]);         int l = 0;         for (int j : poss(B)) update(l++, L - 1, j);       } else {         scanf( %d , &R);         int ans = 0;         for (int i = 0; i < (1 << K); i++) {           auto q = query(i, L - 1, R - 1);           ans = max(ans, q.first - q.second);         }         printf( %d n , ans);       }     }   }


#include<bits/stdc++.h>   using namespace std;   inline int read()   {       int x=0,f=1;       char ch = 0;       while(!isdigit(ch)) {if(ch== - ) f=-1; ch = getchar();}       while(isdigit(ch)) {x = x*10+ch- 0 ; ch = getchar();}       return x*f;   }   typedef long long ll;   const int maxn = 2e5+100;   const double eps = 1e-13;   int T,n;   /*   double c,m,p,v,_v;   double ans;   map<pair<double,double>,double> mp;   double dfs(double a,double b, double c,double nw,int tt)   {       //cout << a <<     << b <<     << c << endl;       if(mp.find(make_pair(a,b))!=mp.end())       {           ans += mp[make_pair(a,b)];           return mp[make_pair(a,b)];       }       double hv = c*nw;       if(a>v)       {           if(b>eps) hv += dfs(a-v,b+_v,c+_v,nw*a,tt+1);           else hv += dfs(a-v,0,c+v,nw*a,tt+1);       }       else if(a>eps)       {           if(b>eps) hv += dfs(0,b+a/2,c+a/2,nw*a,tt+1);           else hv += a*nw*(tt+1);       }       if(b>v)       {           if(a>eps) hv += dfs(a+_v,b-v,c+_v,nw*b,tt+1);           else hv += dfs(0,b-v,c+v,nw*b,tt+1);       }       else if(b>eps)       {           if(a>eps) hv += dfs(a+b/2,0,c+b/2,nw*b,tt+1);           else hv += b*nw*(tt+1);       }       ans += tt*hv;       return mp[make_pair(a,b)] = mp[make_pair(b,a)] = hv;   }   int main()   {       T = read();       while(T--)       {           scanf( %lf%lf%lf%lf ,&c,&m,&p,&v);           _v = v/2;           mp.clear();           ans = 0;           printf( %.13f n ,dfs(c,m,p,1));           cout <<  ---  << ans << endl;       }       return 0;   }   */   int main()   {       T = read();       int s;       while(T--)       {//(1+x*2-1)*x / 2 = s           s = read();           int x = sqrt(s);           printf( %d n ,x+(x*x!=s));       }   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int mi = 0, ma = 25;   bool exist[26];   char str[100005];   inline void init() {     scanf( %d%d , &n, &k);     memset(exist, false, sizeof(exist));     scanf( %s , str + 1);   }   inline void solve() {     for (int i = 1; i <= n; i++) exist[str[i] -  a ] = true;     for (mi = 0; !exist[mi]; mi++)       ;     for (ma = 25; !exist[ma]; ma--)       ;     if (n < k) {       printf( %s , str + 1);       for (int i = n + 1; i <= k; i++) putchar(mi +  a );       return;     }     int p;     for (p = k; p && str[p] == ma +  a ; p--)       ;     str[p]++;     while (!exist[str[p] -  a ]) str[p]++;     for (p = p + 1; p <= k; p++) str[p] = mi +  a ;     str[k + 1] = 0;     puts(str + 1);   }   int main() {     init();     solve();     return 0;   }