#include <bits/stdc++.h>   using namespace std;   const int modulo = 1e9 + 7;   const int max_n = 111;   const int max_k = max_n * max_n;   int bin_pow(int base, long long pw) {     if (pw == 0) return 1;     if (pw & 1) return (1LL * base * bin_pow(base, pw - 1)) % modulo;     return bin_pow((1LL * base * base) % modulo, pw >> 1);   }   int a[max_n][max_k], C[max_n][max_n], d[max_n][max_n];   int n, k;   long long m;   int main() {     ios_base::sync_with_stdio(false);     C[0][0] = 1;     for (int i = 1; i < max_n; ++i) {       C[0][i] = 0;       C[i][0] = 1;     }     for (int i = 1; i < max_n; ++i)       for (int j = 1; j < max_n; ++j)         C[i][j] = (0LL + C[i][j] + C[i - 1][j] + C[i - 1][j - 1]) % modulo;     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= n; ++j) {         long long pw = 1 + (m - i) / n;         d[i][j] = bin_pow(C[n][j], pw);       }     a[0][0] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= min(k, i * n); ++j)         for (int t = 0; t <= min(j, n); ++t)           if (a[i - 1][j - t] != 0)             a[i][j] = (a[i][j] + 1LL * a[i - 1][j - t] * d[i][t]) % modulo;     cout << a[n][k] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cube[8][3];   long long len[28];   long long dist(int a, int b) {     long long ret = 0;     for (int i = 0; i < 3; i++)       ret += (long long)(cube[a][i] - cube[b][i]) * (cube[a][i] - cube[b][i]);     return ret;   }   bool check() {     int idx = 0;     for (int i = 0; i < 8; i++)       for (int j = i + 1; j < 8; j++) len[idx++] = dist(i, j);     sort(len, len + 28);     for (int i = 1; i < 12; i++)       if (len[i] != len[i - 1] || len[i] == 0) return false;     for (int i = 13; i < 24; i++)       if (len[i] != len[i - 1]) return false;     for (int i = 25; i < 28; i++)       if (len[i] != len[i - 1]) return false;     if (len[0] * 2 != len[12] || len[0] * 3 != len[24]) return false;     return true;   }   bool go(int idx) {     if (idx == 8) return check();     do {       if (go(idx + 1)) return true;     } while (next_permutation(cube[idx], cube[idx] + 3));     return false;   }   int main() {     for (int i = 0; i < 8; i++) cin >> cube[i][0] >> cube[i][1] >> cube[i][2];     for (int i = 0; i < 8; i++) sort(cube[i], cube[i] + 3);     if (go(1)) {       cout <<  YES n ;       for (int i = 0; i < 8; i++)         cout << cube[i][0] <<     << cube[i][1] <<     << cube[i][2] <<   n ;       return 0;     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     cin >> n;     bool t[2 * n], s[2 * n];     char tmp;     for (i = 0; i < 2 * n; i++) {       cin >> tmp;       t[i] = (tmp ==  1 );     }     for (i = 0; i < 2 * n; i++) {       cin >> tmp;       s[i] = (tmp ==  1 );     }     int t_sum = 0, s_sum = 0, and_sum = 0, t_sum1 = 0, s_sum1 = 0;     for (i = 0; i < 2 * n; i++) {       t_sum += int(t[i]);       s_sum += int(s[i]);       and_sum += int(t[i] & s[i]);       t_sum1 += int(!t[i] & s[i]);       s_sum1 += int(t[i] & !s[i]);     }     if (t_sum > s_sum) {       if (and_sum % 2 == 0)         t_sum -= min(t_sum - s_sum, s_sum1) / 2;       else         t_sum -= min(t_sum - s_sum, s_sum1) / 2 + min(t_sum - s_sum, s_sum1) % 2;     } else if (t_sum < s_sum) {       if (and_sum % 2 == 0)         s_sum -= min(s_sum - t_sum, t_sum1) / 2 + min(s_sum - t_sum, t_sum1) % 2;       else         s_sum -= min(s_sum - t_sum, t_sum1) / 2;     }     t_sum -= and_sum / 2;     s_sum -= and_sum / 2 + and_sum % 2;     if (t_sum == s_sum)       cout <<  Draw ;     else if (t_sum > s_sum)       cout <<  First ;     else       cout <<  Second ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   int v[N], ans[N];   int main() {     cin.tie(0), ios_base::sync_with_stdio(false);     int n, k, s = 0;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> v[i], s += v[i], ans[i % k] += v[i];     int tans = 0;     for (int i = 0; i < k; i++) tans = max(tans, abs(s - ans[i]));     cout << tans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const long long int MXN = 1e18;   struct node {     double x, y;   } p, p1, p2, p3, p4;   double ji(node a, node b, node c) {     return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);   }   bool jug(node a) {     if ((ji(p1, p2, a) * ji(p3, p4, a) >= 0) &&         (ji(p2, p3, a) * ji(p4, p1, a) >= 0))       return true;     return false;   }   int main() {     int n, d, m;     cin >> n >> d >> m;     p1.x = 0, p1.y = d;     p2.x = d, p2.y = 0;     p3.x = n, p3.y = n - d;     p4.x = n - d, p4.y = n;     int ans = 0;     double a, b;     for (int i = 0; i < m; i++) {       cin >> p.x >> p.y;       if (jug(p)) {         cout <<  YES  << endl;       } else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct pl {     int num, t1, t2, h1, h2;   };   vector<pl> h[(1 << 16) + 5];   int n, k, su;   int s[22], sum[(1 << 16) + 5], si[(1 << 16) + 5];   bitset<200000000> fl, ft;   int work(int a) {     if (a % k == 0) return work(a / k);     return a;   }   int change(int a, int b) { return a * 2001 + b; }   void find(int a, int b) {     int c = b;     for (int i = 0; i < h[a].size(); i++) {       if (h[a][i].num == c) {         b = i;         break;       }     }     if (h[a][b].t1 != -1) find(h[a][b].t1, h[a][b].h1);     if (h[a][b].t2 != -1) find(h[a][b].t2, h[a][b].h2);     if (h[a][b].t1 != -1) printf( %d %d n , h[a][b].h1, h[a][b].h2);   }   bool dfs(int a, int b) {     if (si[a] < b) return 0;     if (fl[change(a, b)] == 1) return 0;     if (ft[change(a, b)] == 1) return 1;     for (int i = 0; i < h[a].size(); i++) {       if (h[a][i].num == b) {         ft[change(a, b)] = 1;         return 1;       }     }     if (sum[a] == 1) {       fl[change(a, b)] = 1;       return 0;     }     int tmp = a;     pl ti;     ti.num = b;     while (tmp != 0) {       if (sum[tmp] * 2 <= sum[a]) {         for (int i = b; i <= si[a]; i *= k) {           for (int j = 1; j < i; j++) {             if (dfs(tmp, j) && dfs((a ^ tmp), i - j)) {               ti.t1 = tmp;               ti.t2 = (a ^ tmp);               ti.h1 = j;               ti.h2 = i - j;               h[a].push_back(ti);               ft[change(a, b)] = 1;               return 1;             }           }         }       }       tmp = (a & (tmp - 1));     }     fl[change(a, b)] = 1;     return 0;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &s[i]);       su += s[i];       pl tmp;       tmp.t1 = tmp.t2 = -1;       tmp.num = s[i];       h[1 << (i - 1)].push_back(tmp);     }     for (int i = 1; i < (1 << n); i++) {       int tmp = i, ti = 1;       while (tmp != 0) {         if (tmp & 1) si[i] += s[ti];         sum[i] += (tmp & 1), tmp = (tmp >> 1);         ti++;       }     }     if (k >= 50) {       int an = change((1 << n) - 1, 1);       for (int i = 1; i < (1 << n); i++) {         for (int j = 0; j < h[i].size(); j++) {           int tmp = (((1 << n) - 1) ^ i), ti = tmp;           while (tmp != 0) {             for (int k = 0; k < h[tmp].size(); k++) {               int tip = change((i | tmp), work(h[i][j].num + h[tmp][k].num));               if (fl[tip] == 1) continue;               fl[tip] = 1;               pl tp;               tp.num = work(h[i][j].num + h[tmp][k].num);               tp.t1 = i;               tp.t2 = tmp;               tp.h1 = h[i][j].num;               tp.h2 = h[tmp][k].num;               h[i | tmp].push_back(tp);               if (fl[an] == 1) break;             }             if (fl[an] == 1) break;             tmp = (ti & (tmp - 1));           }           if (fl[an] == 1) break;         }         if (fl[an] == 1) break;       }     } else       dfs((1 << n) - 1, 1);     for (int i = 0; i < h[(1 << n) - 1].size(); i++) {       if (h[(1 << n) - 1][i].num == 1) {         puts( YES );         find((1 << n) - 1, 1);         return 0;       }     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int a, b, c;       cin >> a >> b >> c;       int totmake = (a + b + c) / 3;       if (a == 0 || b == 0 || totmake == 0) {         cout << 0 << endl;       } else if (a <= b && a <= totmake) {         cout << a << endl;       } else if (b <= a && b <= totmake) {         cout << b << endl;       } else {         cout << totmake << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     map<char, char> m;     bool ans = true;     vector<pair<char, char>> v;     int count = 0;     for (int i = 0; i < s.size(); i++) {       if (m.find(s[i]) != m.end()) {         if (m[s[i]] != t[i]) {           ans = false;           break;         } else {           continue;         }       } else {         if (m.find(t[i]) != m.end()) {           ans = false;           break;         } else {           m[s[i]] = t[i];           m[t[i]] = s[i];           if (s[i] != t[i]) {             v.push_back({s[i], t[i]});             count++;           }         }       }     }     if (ans) {       cout << count << endl;       for (int i = 0; i < count; i++)         cout << v[i].first <<     << v[i].second << endl;     } else       cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, s1, s2;     long long a, b, c = 0;     cin >> s;     b = stoi(s);     while (b > 0) {       s1 = s;       sort(s1.begin(), s1.end());       int d = stoi(s1) % 10;       b = b - d;       c++;       s = to_string(b);     }     cout << c <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a0, a1, a2, b0, b1, b2, n;     cin >> a0 >> a1 >> a2;     int cnt = (a0 + a1 + a2) / 5;     if ((a0 + a1 + a2) % 5) cnt++;     cin >> b0 >> b1 >> b2;     cnt += ((b0 + b1 + b2) / 10);     if ((b0 + b1 + b2) % 10) cnt++;     cin >> n;     if (cnt <= n)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x, y;   string tt(long long a) {     string ans =   ;     while (a != 0) ans += (a % 10) +  0 , a /= 10;     int p = ans.length();     for (int i = 0; i * 2 < p; ++i) swap(ans[i], ans[p - i - 1]);     return ans;   }   int main() {     cin >> x >> y;     string s;     while (x != 1 || y != 1) {       if (x < y) {         s += tt((y - 1) / x) +  B ;         y = (y - 1) % x + 1;       } else if (x > y) {         s += tt((x - 1) / y) +  A ;         x = (x - 1) % y + 1;       } else {         cout <<  Impossible n ;         return 0;       }     }     cout << s <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double Cnk(int n, int k) {     double result = 1;     for (int i = 1; i <= k; ++i) {       result *= n - k + i;       result /= i;     }     return result;   }   double Power(int n, int power) {     double result = 1;     for (int i = 0; i < power; ++i) {       result *= n;     }     return result;   }   int main() {     int n, m;     cin >> n >> m;     vector<int> a(m);     for (int i = 0; i < m; ++i) {       cin >> a[i];     }     vector<vector<vector<double> > > p(n + 1);     for (int i = 0; i <= n; ++i) {       p[i].resize(m + 1);       for (int j = 0; j <= m; ++j) {         p[i][j].assign(n + 1, 0);       }     }     for (int j = 0; j <= m; ++j) {       p[0][j][0] = 1;       for (int i = 1; i <= n; ++i) {         p[0][j][i] = 0;         p[i][j][0] = 0;       }     }     for (int i = 0; i <= n; ++i) {       for (int k = 0; k <= n; ++k) {         if (k == (i + a[0] - 1) / a[0]) {           p[i][1][k] = 1;         } else {           p[i][1][k] = 0;         }       }     }     for (int j = 2; j <= m; ++j) {       for (int i = 1; i <= n; ++i) {         for (int k = 1; k <= n; ++k) {           p[i][j][k] = 0;           for (int h = a[j - 1] * k - a[j - 1] + 1;                (h <= i) && (h < a[j - 1] * (k + 1) - a[j - 1] + 1); ++h) {             double sum = 0;             for (int l = 0; l <= k; ++l) {               sum += p[i - h][j - 1][l];             }             p[i][j][k] += Cnk(i, h) * Power(j - 1, i - h) * sum;           }           for (int h = 0; (h <= i) && (h < k * a[j - 1] - a[j - 1] + 1); ++h) {             p[i][j][k] += Cnk(i, h) * Power(j - 1, i - h) * p[i - h][j - 1][k];           }           p[i][j][k] /= Power(j, i);         }       }     }     double E = 0;     for (int i = 0; i <= n; ++i) {       E += i * p[n][m][i];     }     printf( %.10lf , E);     getchar();     getchar();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ull = unsigned long long;   int main() {     int t;     cin >> t;     while (t--) {       ull n, k, x;       cin >> n >> k >> x;       cin.ignore();       string arr;       getline(cin, arr);       vector<pair<ull, ull>> values;       for (int i = arr.size(); i-- > 0;) {         if (arr[i] ==  a ) {           if (i == arr.size() - 1 || arr[i + 1] !=  a )             values.emplace_back(0, 1);           else             values.back().second++;           continue;         }         if (i == arr.size() - 1)           values.emplace_back(1, k);         else if (arr[i + 1] ==  * )           values.back().second += k;         else           values.emplace_back(1, k);       }       x--;       for (int i = values.size(); i-- > 0;) {         if (values[i].first == 0) {           for (int j = 0; j < values[i].second; j++) cout <<  a ;           continue;         }         ull weight = 1;         for (int j = 0; j < values.size(); j++) {           if (j == i) break;           if (!values[j].first) continue;           ull temp = weight * (values[j].second + 1);           if (temp < weight) {             weight = 0;             break;           }           weight = temp;         }         if (!weight) continue;         int total_b = x / weight;         for (int j = 0; j < total_b; j++) cout <<  b ;         x -= total_b * weight;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   const int MM = 998244353;   template <typename T, typename U>   static inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static inline void amax(T &x, U y) {     if (x < y) x = y;   }   int _runtimeTerror_() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     sort(a.begin(), a.end());     string s;     cin >> s;     vector<int> ans(n + 1);     vector<char> dir(n);     dir[0] = s[0];     ans[0] = 0;     char heavy = s[0];     for (int i = 1; i < n; ++i) {       if (s[i] == heavy) {         if (i & 1) {           dir[i] =  L  ^  R  ^ heavy;           ans[i] += 0;           ++ans[0];           --ans[i];         } else {           dir[i] = heavy;           ans[i] += 0;           ++ans[0];           --ans[i];         }       } else {         ans[i] += i;         dir[i] = s[i];         ans[i + 1] -= i;       }       heavy = s[i];     }     for (int i = 1; i < n; ++i) {       ans[i] += ans[i - 1];     }     for (int i = 0; i < n; ++i) {       cout << a[ans[i]] <<     << dir[i] <<   n ;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) _runtimeTerror_();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, i, j, k, l, m, b, t, sum, sum1, flag, max1, min1;     cin >> n >> m;     long long a[n + 1];     for (i = 1; i <= n; i++) {       cin >> a[i];     }     sum = 0;     long long pre[100009];     pre[1] = a[1];     for (i = 2; i <= n; i++) {       pre[i] = pre[i - 1] + a[i];     }     max1 = INT_MIN;     for (i = 1; i <= n; i++) {       k = pre[i];       l = pre[n] - pre[i];       k = k % m;       l = l % m;       max1 = max(k + l, max1);     }     cout << max1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   template <class T>   void out(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) out(x / 10);     putchar(x % 10 +  0 );   }   long long dp[2005];   struct node {     int x, y;   } a[2005];   bool cmp(node a, node b) {     if (a.x == b.x) return a.y < b.y;     return a.x < b.x;   }   long long fact[200010], inv[200010];   inline long long MOD(long long x) {     while (x < 0) x += mod;     return x % mod;   }   long long binpow(long long a, int k) {     if (k == 0) return 1;     long long ans = binpow(a, k / 2);     ans = 1ll * ans * ans % mod;     if (k % 2) ans = 1ll * ans * a % mod;     return ans;   }   long long C(long long n, long long k) {     if (k > n) return 0;     long long ans = fact[n] * 1ll * inv[k] % mod;     ans = 1ll * ans * inv[n - k] % mod;     return ans % mod;   }   void pre() {     fact[0] = inv[0] = 1;     for (int i = 1; i < 200010; i++) {       fact[i] = 1ll * i * fact[i - 1] % mod;       inv[i] = binpow(fact[i], mod - 2);     }   }   int main() {     pre();     int h, w, n;     scanf( %d%d%d , &h, &w, &n);     for (int i = 0; i < n; i++) scanf( %d%d , &a[i].x, &a[i].y);     sort(a, a + n, cmp);     long long ans = C(h + w - 2, h - 1);     for (int i = 0; i < n; i++) {       dp[i] = C(a[i].x + a[i].y - 2, a[i].y - 1);       for (int j = 0; j < i; j++)         if (a[j].x <= a[i].x && a[j].y <= a[i].y) {           dp[i] = (dp[i] -                    dp[j] * C(a[i].x - a[j].x + a[i].y - a[j].y, a[i].x - a[j].x) +                    mod) %                   mod;         }       ans = (ans - dp[i] * C(h - a[i].x + w - a[i].y, h - a[i].x) + mod) % mod;     }     out((ans + mod) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> adj[101];   int vis[101][101];   int id;   bool dfs(const int &idx, int cur, int to) {     if (cur == to) return true;     bool ret = false;     for (int i = 0; i < (int)adj[idx][cur].size(); i++) {       if (vis[idx][adj[idx][cur][i]] == id) continue;       vis[idx][adj[idx][cur][i]] = id;       ret |= dfs(idx, adj[idx][cur][i], to);     }     return ret;   }   int main() {     int n, m, q;     scanf( %d%d , &n, &m);     for (int i = 0; i < 101; i++) adj[i].resize(n);     for (int i = 0, u, v, c; i < m; i++) {       scanf( %d%d%d , &u, &v, &c);       adj[c - 1][u - 1].push_back(v - 1);       adj[c - 1][v - 1].push_back(u - 1);     }     int u, v;     scanf( %d , &q);     while (q--) {       id++;       scanf( %d%d , &u, &v);       int ans = 0;       for (int i = 0; i < m; i++) ans += dfs(i, u - 1, v - 1);       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1e5 + 7;   int H, ans;   int cnt[10007][444], a[Maxn], flag[Maxn];   int mark[Maxn];   vector<int> luck;   void lucky(int p) {     if (p > 10000) return;     luck.push_back(p);     mark[p] = true;     p *= 10;     lucky(p + 4);     lucky(p + 7);   }   void add(int l, int r, int d) {     int p1 = l / H;     int p2 = r / H;     for (int i = p1 + 1; i < p2; i++) flag[i] += d;     if (p1 == p2) {       for (int i = l; i <= r; i++) cnt[a[i]][p1]--, a[i] += d, cnt[a[i]][p1]++;       return;     }     int L = p2 * H;     int R = p1 * H + H - 1;     for (int i = L; i <= r; i++) cnt[a[i]][p2]--, a[i] += d, cnt[a[i]][p2]++;     for (int i = l; i <= R; i++) cnt[a[i]][p1]--, a[i] += d, cnt[a[i]][p1]++;   }   void Find(int l, int r) {     int p1 = l / H;     int p2 = r / H;     for (int i = p1 + 1; i < p2; i++)       for (int j = 0; j < luck.size(); j++)         if (luck[j] - flag[i] > 0) ans += cnt[luck[j] - flag[i]][i];     if (p1 == p2) {       for (int i = l; i <= r; i++) ans += mark[a[i] + flag[p1]];       return;     }     int L = p2 * H;     int R = p1 * H + H - 1;     for (int i = L; i <= r; i++) ans += mark[a[i] + flag[p2]];     for (int i = l; i <= R; i++) ans += mark[a[i] + flag[p1]];   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     H = sqrt(n);     for (int i = 0; i < n; i++) scanf( %d , a + i), cnt[a[i]][i / H]++;     lucky(4);     lucky(7);     for (int i = 0; i < q; i++) {       char s[10];       scanf( %s  , s);       int l, r, x;       if (s[0] ==  c ) {         ans = 0;         scanf( %d%d , &l, &r);         l--, r--;         Find(l, r);         printf( %d  , ans);       } else {         scanf( %d%d%d , &l, &r, &x);         l--, r--;         add(l, r, x);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   char img[2007][2007];   int c[2007], r[2007];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) scanf( %s , img[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) img[i][j] -=  0 ;     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = n - 1; j > i; --j)         if (c[j] ^ r[i] ^ img[i][j]) {           ++ans;           c[j] ^= 1, r[i] ^= 1;         }     for (int i = 0; i < n; i++) img[i][i] ^= c[i] ^ r[i];     memset(c, 0, sizeof(c)), memset(r, 0, sizeof(r));     for (int i = n - 1; i >= 0; --i)       for (int j = 0; j < i + 1; j++)         if (c[j] ^ r[i] ^ img[i][j]) {           ++ans;           c[j] ^= 1, r[i] ^= 1;         }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int maxn = 1e6 + 3000;   const long long mod = 1e9 + 7;   long long k, p;   int f[maxn];   bool vis[maxn];   long long cnt[maxn];   long long qpow(long long x, long long p) {     long long ans = 1;     while (p) {       if (p & 1) ans = ans * x % mod;       x = x * x % mod;       p >>= 1;     }     return ans;   }   int main() {     cin >> p >> k;     if (k == 0) {       cout << qpow(p, p - 1) << endl;       return 0;     }     if (k == 1) {       cout << qpow(p, p) << endl;       return 0;     }     for (int i = 1; i < p; i++) {       f[i] = i * k % p;     }     long long ans = 1;     for (int i = 1; i < p; i++) {       int c = 0;       if (vis[i]) continue;       int x = i;       while (!vis[x]) {         vis[x] = 1;         x = f[x];         c++;       }       cnt[c]++;     }     for (int i = 2; i < maxn; i++) {       if (cnt[i]) {         ans = ans * qpow(i * cnt[i] + 1, cnt[i]) % mod;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void reset(int& n, int first) { n = n & ~(1 << first); }   bool check(int n, int first) { return (bool)(n & (1 << first)); }   const int mx = 55;   long long inf = 1e18;   unsigned long long f[mx], v;   int a[mx];   int main() {     f[0] = f[1] = 1;     int i, j, k, n;     for (i = 2; i < mx; i++) f[i] = f[i - 1] + f[i - 2];     while (cin >> n >> v) {       int cur = n;       for (i = 1; i <= n; i++) a[i] = i;       for (i = 1; i <= n; i++) {         if (v > f[cur - 1]) {           swap(a[i], a[i + 1]);           i++;           cur -= 2;           v -= f[cur + 1];         } else           cur--;       }       for (i = 1; i <= n; i++) printf( %d  , a[i]);       puts(  );     }   }


#include <bits/stdc++.h>   using ll = long long;   int main() {     std::ios_base::sync_with_stdio(0);     std::cin.tie(0);     std::string s;     std::cin >> s;     int n = s.length();     std::vector<std::set<int>> adj(26);     for (int i = 0; i < n; ++i) {       int d = s[i] -  a ;       adj[d].insert(i);     }     int q;     std::cin >> q;     while (q--) {       int op;       std::cin >> op;       if (op == 1) {         int pos;         char c;         std::cin >> pos >> c;         --pos;         int d = s[pos] -  a ;         s[pos] = c;         adj[d].erase(pos);         adj[c -  a ].insert(pos);       } else {         int l, r;         std::cin >> l >> r;         --l, --r;         int ans = 0;         for (int i = 0; i < 26; ++i) {           if (adj[i].empty()) {             continue;           }           auto it = adj[i].lower_bound(l);           if (it == adj[i].end()) {             continue;           }           int index = *it;           if (index <= r) {             ++ans;           }         }         std::cout << ans <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, i = 0, j = 0;     cin >> a >> b >> c >> d;     while (a != 0) {       a = a - 1;       i++;     }     while (b != 0) {       b = b - 1;       j++;     }     if (j >= i)       cout <<  Second ;     else       cout <<  First ;   }


#include <bits/stdc++.h>   using namespace std;   using INT = long long;   int n;   int a[200010];   vector<int> B[200010];   void add(int u, int val) {     for (; u <= n; u += u & -u) B[u].push_back(val);   }   int calc(int u, int val) {     int ans = 0;     for (; u; u -= u & -u) {       int id = lower_bound(B[u].begin(), B[u].end(), val) - B[u].begin();       ans += B[u].size() - id;     }     return ans;   }   int calc(int l, int r, int val) {     if (l > r) return 0;     return calc(r, val) - calc(l - 1, val);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) add(i, min(a[i], n));     for (int i = 1; i <= n; i++) sort(B[i].begin(), B[i].end());     INT ans = 0;     for (int i = 1; i < n; i++) {       ans += calc(i + 1, min(n, a[i]), i);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   bool a[maxn];   int main() {     int n, k;     while (~scanf( %d%d , &n, &k)) {       int p = (n - k) / 2 + 1;       int t = n / p;       while (t--) {         for (int i = 0; i < p; i++) {           if (i == p - 1)             printf( 0 );           else             printf( 1 );         }       }       for (int i = 0; i < n % p; i++) printf( 1 );       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int o = 0;       int z = 0;       for (int i = 0; i < n; i++) {         int y;         cin >> y;         if (y == 1)           o++;         else           z++;       }       if (z == o) {         cout << n / 2 <<   n ;         for (int i = 1; i <= n / 2; i++) cout <<  0  ;       } else if (z > o) {         cout << n / 2 <<   n ;         for (int i = 1; i <= n / 2; i++) cout <<  0  ;       } else {         int y = n / 2;         if (y % 2 == 0) {           cout << y <<   n ;           for (int i = 0; i < y; i++) cout <<  1  ;         } else {           cout << (y + 1) <<   n ;           for (int i = 0; i < y + 1; i++)             cout <<  1                   <<    ;         }       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, x, i, w[100005], sum;   int main() {     cin >> n >> x;     for (i = 1; i <= n; i++) {       cin >> w[i];       sum = sum + w[i];     }     if (sum + n - 1 == x)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, A, B, a[200006];   long long ask(int l, int r) {     long long ans;     int mid = (l + r) / 2,         num = upper_bound(a + 1, a + k + 1, r) - lower_bound(a + 1, a + k + 1, l);     if (num == 0)       return A;     else       ans = 1LL * B * num * (r - l + 1);     return r - l ? min(ans, ask(l, mid) + ask(mid + 1, r)) : ans;   }   int main() {     scanf( %d%d%d%d , &n, &k, &A, &B);     for (int i = 1; i <= k; i++) scanf( %d , &a[i]);     sort(a + 1, a + k + 1);     printf( %lld n , ask(1, 1 << n));   }


#include <bits/stdc++.h>   const int M = 1e5 + 5;   int len;   long long lsh[M * 3];   int n, m, k, p, t[M], v[M], nxt[M], pre[M];   long long CB[M * 3];   long long now, val[M], ans[M];   struct Query {     int L, R, p, id;     inline bool operator<(const Query& it) const {       return p == it.p ? p & 1 ? R < it.R : R > it.R : L < it.L;     }   } q[M];   inline void Add(const int& id, const int& to) {     now += CB[to];     ++CB[v[id]];   }   inline void Del(const int& id, const int& to) {     --CB[v[id]];     now -= CB[to];   }   signed main() {     register int i, L = 1, R = 0;     scanf( %d%d , &n, &k);     lsh[++len] = 0;     lsh[++len] = k;     lsh[++len] = -k;     for (i = 1; i <= n; ++i) scanf( %d , t + i);     for (i = 1; i <= n; ++i) {       scanf( %lld , val + i);       if (t[i] == 1)         val[i] = val[i - 1] + val[i];       else         val[i] = val[i - 1] - val[i];       lsh[++len] = val[i];       lsh[++len] = val[i] - k;       lsh[++len] = val[i] + k;     }     std::sort(lsh + 1, lsh + len + 1);     len = std::unique(lsh + 1, lsh + len + 1) - lsh - 1;     for (i = 0; i <= n; ++i) {       v[i] = std::lower_bound(lsh + 1, lsh + len + 1, val[i]) - lsh;       pre[i] = std::lower_bound(lsh + 1, lsh + len + 1, val[i] - k) - lsh;       nxt[i] = std::lower_bound(lsh + 1, lsh + len + 1, val[i] + k) - lsh;     }     scanf( %d , &m);     p = ceil(n / sqrt(m * 2.0 / 3));     for (i = 1; i <= m; ++i) {       scanf( %d%d , &q[i].L, &q[i].R);       --q[i].L;       q[i].id = i;       q[i].p = q[i].L / p;     }     std::sort(q + 1, q + m + 1);     for (i = 1; i <= m; ++i) {       const int &QL = q[i].L, &QR = q[i].R;       while (R < QR) ++R, Add(R, pre[R]);       while (L > QL) --L, Add(L, nxt[L]);       while (L < QL) Del(L, nxt[L]), ++L;       while (R > QR) Del(R, pre[R]), --R;       ans[q[i].id] = now;     }     for (i = 1; i <= m; ++i) printf( %lld n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int n, m, d[200], g[200][200], dp[200][200], ans[200];   int cnt, st[200], ed[200];   bool flag[200];   void dfs1(int u) {     flag[u] = true;     st[u] = ++cnt;     for (int i = 1; i <= n; i++)       if (g[u][i] == 1 && !flag[i]) dfs1(i);     ed[u] = ++cnt;   }   void dfs2(int u) {     flag[u] = true;     for (int i = 1; i <= n; i++)       if (i ^ u) dp[u][i] = d[g[u][i]];     dp[u][u] = m;     for (int i = 1; i <= n; i++)       if (g[u][i] == 1 && !flag[i]) {         dfs2(i);         for (int j = 1; j <= n; j++)           if (st[i] <= st[j] && ed[j] <= ed[i])             dp[u][j] += dp[i][j];           else             dp[u][j] += min(dp[i][j], dp[i][dp[i][0]]);       }     dp[u][0] = u;     for (int i = 1; i <= n; i++)       if (st[u] <= st[i] && ed[i] <= ed[u] && dp[u][i] < dp[u][dp[u][0]])         dp[u][0] = i;   }   void dfs3(int u) {     flag[u] = true;     for (int i = 1; i <= n; i++)       if (g[u][i] == 1 && !flag[i]) {         if (st[i] <= st[ans[u]] && ed[ans[u]] <= ed[i])           ans[i] = ans[u];         else if (dp[i][ans[u]] < dp[i][dp[i][0]])           ans[i] = ans[u];         else           ans[i] = dp[i][0];         dfs3(i);       }   }   void solve() {     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);     memset(flag, false, sizeof(flag));     cnt = 0;     dfs1(1);     memset(flag, false, sizeof(flag));     dfs2(1);     ans[1] = dp[1][0];     memset(flag, false, sizeof(flag));     dfs3(1);     printf( %d n , dp[1][dp[1][0]]);     for (int i = 1; i <= n; i++) printf( %d%c , ans[i], i < n ?     :   n );   }   int main() {     int u, v;     while (scanf( %d%d , &n, &m) == 2) {       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) g[i][j] = 1000000000;       for (int i = 1; i < n; i++) scanf( %d , d + i);       for (int i = 1; i < n; i++) {         scanf( %d%d , &u, &v);         g[u][v] = g[v][u] = 1;       }       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMax = 101000;   int N;   vector<pair<int, int> > A, B, C, D;   bool cmp1(pair<int, int> a, pair<int, int> b) {     if (a.first < b.first) return 1;     if (a.first > b.first) return 0;     if (a.second < b.second) return 1;     return 0;   }   bool cmp2(pair<int, int> a, pair<int, int> b) {     if (a.first < b.first) return 1;     if (a.first > b.first) return 0;     if (a.second > b.second) return 1;     return 0;   }   bool cmp3(pair<int, int> a, pair<int, int> b) {     if (a.first > b.first) return 1;     if (a.first < b.first) return 0;     if (a.second > b.second) return 1;     return 0;   }   bool cmp4(pair<int, int> a, pair<int, int> b) {     if (a.first > b.first) return 1;     if (a.first < b.first) return 0;     if (a.second < b.second) return 1;     return 0;   }   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       int first, second;       scanf( %d%d , &first, &second);       if (first >= 0 && second >= 0)         A.push_back(make_pair(first, second));       else if (first >= 0 && second <= 0)         B.push_back(make_pair(first, second));       else if (first <= 0 && second <= 0)         C.push_back(make_pair(first, second));       else         D.push_back(make_pair(first, second));     }     int ret = 0;     for (int i = 0; i < A.size(); i++) {       if (A[i].first) ret += 2;       if (A[i].second) ret += 2;       ret += 2;     }     for (int i = 0; i < B.size(); i++) {       if (B[i].first) ret += 2;       if (B[i].second) ret += 2;       ret += 2;     }     for (int i = 0; i < C.size(); i++) {       if (C[i].first) ret += 2;       if (C[i].second) ret += 2;       ret += 2;     }     for (int i = 0; i < D.size(); i++) {       if (D[i].first) ret += 2;       if (D[i].second) ret += 2;       ret += 2;     }     printf( %d n , ret);     sort(A.begin(), A.end(), cmp1);     for (int i = 0; i < A.size(); i++) {       if (A[i].first) printf( 1 %d R n , A[i].first);       if (A[i].second) printf( 1 %d U n , A[i].second);       printf( 2 n );       if (A[i].second) printf( 1 %d D n , A[i].second);       if (A[i].first) printf( 1 %d L n , A[i].first);       printf( 3 n );     }     sort(B.begin(), B.end(), cmp2);     for (int i = 0; i < B.size(); i++) {       if (B[i].first) printf( 1 %d R n , B[i].first);       if (B[i].second) printf( 1 %d D n , -B[i].second);       printf( 2 n );       if (B[i].second) printf( 1 %d U n , -B[i].second);       if (B[i].first) printf( 1 %d L n , B[i].first);       printf( 3 n );     }     sort(C.begin(), C.end(), cmp3);     for (int i = 0; i < C.size(); i++) {       if (C[i].first) printf( 1 %d L n , -C[i].first);       if (C[i].second) printf( 1 %d D n , -C[i].second);       printf( 2 n );       if (C[i].second) printf( 1 %d U n , -C[i].second);       if (C[i].first) printf( 1 %d R n , -C[i].first);       printf( 3 n );     }     sort(D.begin(), D.end(), cmp4);     for (int i = 0; i < D.size(); i++) {       if (D[i].first) printf( 1 %d L n , -D[i].first);       if (D[i].second) printf( 1 %d U n , D[i].second);       printf( 2 n );       if (D[i].second) printf( 1 %d D n , D[i].second);       if (D[i].first) printf( 1 %d R n , -D[i].first);       printf( 3 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     char a[110];     cin >> n >> a;     for (int i = 2; i <= n; i++) {       if (n % i == 0) reverse(a, a + i);     }     cout << a << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k, minn = 10000, a[1000], temp = 0;     cin >> n >> m >> k;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (a[i] <= k && a[i] != 0) {         temp = abs(i + 1 - m) * 10;         if (temp < minn) minn = temp;       }     }     cout << minn;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gi() {     int a;     scanf( %d , &a);     return a;   }   long long gli() {     long long a;     scanf( %I64d , &a);     return a;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     if (b == 0) return a;     if (a > b) return gcd(a % b, b);     return gcd(b % a, a);   }   int pr[1000000];   int main() {     unordered_map<long long, vector<pair<long long, long long> > > m;     unordered_map<long long, vector<pair<long long, long long> > >::iterator it;     int n = gi();     for (int i = 0; i < n; i++) {       long long x = gli();       long long y = gli();       long long c = gli();       m[x].push_back(make_pair(y, c));     }     vector<pair<long long, long long> > main;     int L = 0;     long long gg = 0;     int first = 1;     for (it = m.begin(); it != m.end(); it++) {       vector<pair<long long, long long> > &v = it->second;       sort(v.begin(), v.end());       if (first) {         first = 0;         L = v.size();         long long g = 0;         for (int i = 0; i < L; i++) g = gcd(g, v[i].second);         for (int i = 0; i < L; i++)           main.push_back(make_pair(v[i].first, v[i].second / g));       } else {         if (int(v.size()) != L || v[0].first != main[0].first ||             v[0].second % main[0].second != 0) {           printf( 0 n );           return 0;         }         long long f = v[0].second / main[0].second;         for (int i = 1; i < L; i++)           if (v[i].first != main[i].first || v[i].second % main[i].second != 0 ||               v[i].second / main[i].second != f) {             printf( 0 n );             return 0;           }       }       gg = gcd(gg, v[0].second);     }     m.clear();     long long g = 0;     for (int i = 0; i < L; i++) g = gcd(g, main[i].second);     g *= gg / main[0].second;     memset(pr, -1, sizeof(pr));     long long r = 1;     long long c = 1;     while (g % 2 == 0) {       c++;       g /= 2;     }     r *= c;     for (int i = 3; i < 1000000; i += 2)       if (pr[i]) {         for (int j = i * 3; j < 1000000; j += i * 2) pr[i] = 0;         long long c = 1;         while (g % i == 0) {           c++;           g /= i;         }         r *= c;       }     if (g > 1LL) r *= 2;     cout << r << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 55;   const unsigned long long M = 1000000009LL;   const int K = 3;   const int LIT = 2500;   const int INF = 1 << 30;   const double eps = 1e-6;   const unsigned long long MOD = 1000000007LL;   const int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   unsigned long long n, m;   unsigned long long pw2[N] = {0};   void init() {     pw2[0] = 1;     for (int i = 1; i < N; i++) {       pw2[i] = pw2[i - 1] * 2;     }   }   int getCP(int n, int m) {     if (n == 3 && m == 1) return -1;     if (n == 3 && m == 2) return -2;     unsigned long long tot = pw2[n - 2];     unsigned long long mid = pw2[n - 3];     if (m > mid) {       return getCP(n, m - mid) - 1;     } else {       return getCP(n - 1, m);     }   }   vector<unsigned long long> getP(unsigned long long n, unsigned long long m) {     vector<unsigned long long> ans;     if (n == 1) {       ans.push_back(1);       return ans;     }     if (n == 2) {       if (m == 1) {         ans.push_back(1);         ans.push_back(2);       }       if (m == 2) {         ans.push_back(2);         ans.push_back(1);       }       return ans;     }     unsigned long long tot = pw2[n - 1];     unsigned long long mid = pw2[n - 2];     if (m > mid) {       ans = getP(n, tot + 1 - m);       reverse(ans.begin(), ans.end());       return ans;     }     vector<unsigned long long> pre = getP(n - 1, (m + 1) / 2);     int cp = n + getCP(n, m);     for (int i = 0; i < cp; i++) {       ans.push_back(pre[i]);     }     ans.push_back(n);     for (int i = cp; i < n - 1; i++) {       ans.push_back(pre[i]);     }     return ans;   }   void solve() {     vector<unsigned long long> ans = getP(n, m);     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     cout << endl;   }   int main() {     int T;     while (cin >> n >> m) {       init();       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int th[100080], bl[100080];   int main() {     int i, j, n, k, mx = 0, sum, fl, fval;     scanf( %d %d , &n, &k);     for (i = 0; i < n; i++) {       scanf( %d , &th[i]);     }     for (i = 0; i < n; i++) {       scanf( %d , &bl[i]);     }     j = 0;     i = 0;     sum = 0;     fl = 0;     fval = th[0];     while (j < n) {       while (i < k && j < n) {         if (bl[j] == 0) sum += th[j];         i++;         j++;       }       if (i == k && j <= n) {         if (sum > mx) mx = sum;         fl++;         if (bl[fl - 1] == 0) sum -= fval;         fval = th[fl];         i--;       }     }     for (i = 0; i < n; i++) {       if (bl[i] == 1) mx += th[i];     }     printf( %d , mx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long Solve(long long n, long long k) {     long long low = 1;     long long high = ((long long)1 << n) - 1;     long long mid = low + (high - low) / 2;     if (mid == k)       return n;     else if (mid < k)       return Solve(n - 1, k - mid);     else       return Solve(n - 1, k);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, k;     cin >> n >> k;     cout << Solve(n, k) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= 2 * n / 3; i++) printf( %d %d n , i, 1);     for (int i = 1; i <= n - 2 * n / 3; i++) printf( %d %d n , i * 2, 4);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200;   long long n, num[N], tmp;   int main() {     cin >> n;     for (int i = 0, v; i < n; i++) cin >> v, num[v]++;     for (int i = 1; i <= 100; i++) {       for (int j = 1; j < i; j++)         tmp = max(0ll, min(num[0] - num[j], num[i])), num[j] += tmp,         num[i] -= tmp;       tmp = num[i] - num[0];       int k = tmp % (i + 1);       tmp = tmp / (i + 1);       if (tmp > 0 || k > 0)         for (int j = 0; j <= i; j++) {           num[j] += tmp, num[i] -= tmp;           if (j < k) num[j]++, num[i]--;         }     }     cout << num[0] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     cin >> n;     cout << n / 2 - !(n % 2) - (n % 4 == 2) <<     << n / 2 + 1 + (n % 4 == 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   bool doubleEquals(double a, double b) { return abs(a - b) < eps; }   bool db_less(double a, double b) { return a < b - eps; }   bool db_equal(double a, double b) { return abs(a - b) < eps; }   bool db_less_equal(double a, double b) { return a < b + eps; }   struct Point {     double x, y;     Point() {}     Point(double x, double y) : x(x), y(y) {}     Point operator-(Point p) { return Point(x - p.x, y - p.y); }     Point operator+(Point p) { return Point(x + p.x, y + p.y); }     Point operator/(double e) { return Point(x / e, y / e); }     Point operator*(double e) { return Point(x * e, y * e); }     bool operator<(const Point &p) const {       return x < p.x || (x == p.x && y < p.y);     }     bool operator==(Point p) {       return doubleEquals(x, p.x) && doubleEquals(y, p.y);     }   };   ostream &operator<<(ostream &os, Point p) {     return os <<  (  << p.x <<  ,  << p.y <<  ) ;   }   double cross(Point O, Point A, Point B) {     return (A - O).x * (B - O).y - (A - O).y * (B - O).x;   }   double dot(Point A, Point B) { return A.x * B.x + A.y * B.y; }   double dist(Point A, Point B) { return sqrtl(dot(A - B, A - B)); }   double distLine(Point A, Point B, Point P) {     return abs(cross(A, B, P) / dist(A, B));   }   double angle(Point O, Point A, Point B) {     return acos(dot(A - O, B - O) / (dist(O, A) * dist(O, B)));   }   vector<Point> convexHull(vector<Point> &points) {     vector<Point> hull(points.size() + 1);     int k = 0;     sort(points.begin(), points.end());     for (int i = 0; i < points.size(); i++) {       while (k >= 2 && (cross(hull[k - 2], hull[k - 1], points[i]) + eps > 0))         k--;       hull[k++] = points[i];     }     for (int i = points.size() - 2, t = k + 1; i >= 0; i--) {       while (k >= t && cross(hull[k - 2], hull[k - 1], points[i]) + eps > 0) k--;       hull[k++] = points[i];     }     k--;     hull.resize(k);     return hull;   }   bool pnpoly(Point p, vector<Point> &points) {     bool c = 0;     for (int i = 0, j = points.size() - 1; i < points.size(); j = i++) {       if (((points[i].y > p.y) != (points[j].y > p.y)) &&           (p.x < (double)(points[j].x - points[i].x) * (p.y - points[i].y) /                          (points[j].y - points[i].y) +                      points[i].x))         c = !c;     }     return c;   }   struct Line {     double A, B, C;     Line(double A, double B, double C) : A(A), B(B), C(C){};     Line(Point p1, Point p2) {       A = p1.y - p2.y;       B = p2.x - p1.x;       C = p1.x * p2.y - p1.y * p2.x;     }     bool parallel(Line l) { return doubleEquals(B * l.A - A * l.B, 0); }     bool equals(Line l) {       if (!parallel(l)) return false;       return parallel(l) && doubleEquals(distLine(l), 0);     }     Point inter(Line l) {       assert(!parallel(l));       Point ret;       ret.x = (l.C * B - C * l.B) / (l.B * A - B * l.A);       ret.y = (l.C * A - C * l.A) / (B * l.A - l.B * A);       return ret;     }     double distLine(Line l) {       if (l.A == 0) return distPoint({0, -l.C / l.B});       return distPoint({-l.C / l.A, 0});     }     double distPoint(Point p) {       return abs(A * p.x + B * p.y + C) / sqrt(A * A + B * B);     }     Line getPerpendicular(Point p) {       Line l(B, -A, 0);       l.C = -l.A * p.x - l.B * p.y;       return l;     }   };   bool pointInSegment(pair<Point, Point> s, Point p) {     if (doubleEquals(cross(s.first, s.second, p), 0)) {       double xa = min(s.first.x, s.second.x), xb = max(s.first.x, s.second.x);       double ya = min(s.first.y, s.second.y), yb = max(s.first.y, s.second.y);       return p.x + eps > xa && p.x - eps < xb && p.y + eps > ya && p.y - eps < yb;     }     return false;   }   bool segmentInter(pair<Point, Point> A, pair<Point, Point> B) {     Line la(A.first, A.second), lb(B.first, B.second);     if (la.parallel(lb) && !la.equals(lb)) return false;     if (la.equals(lb)) {       if (max(A.first.x, A.second.x) + eps < min(B.first.x, B.second.x))         return false;       if (min(A.first.x, A.second.x) - eps > max(B.first.x, B.second.x))         return false;       if (max(A.first.y, A.second.y) + eps < min(B.first.y, B.second.y))         return false;       if (min(A.first.y, A.second.y) - eps > max(B.first.y, B.second.y))         return false;       return true;     }     Point i = la.inter(lb);     return pointInSegment(A, i) && pointInSegment(B, i);   }   double distSegmentToPoint(pair<Point, Point> s, Point P) {     if (dot(s.first - s.second, P - s.second) < 0) return dist(s.second, P);     if (dot(s.second - s.first, P - s.first) < 0) return dist(s.first, P);     return distLine(s.first, s.second, P);   }   double distSegmentToSegment(pair<Point, Point> sa, pair<Point, Point> sb) {     if (sa.first == sa.second && sb.first == sb.second)       return dist(sa.first, sb.first);     if (sa.first == sa.second) return distSegmentToPoint(sb, sa.first);     if (sb.first == sb.second) return distSegmentToPoint(sa, sb.first);     if (segmentInter(sa, sb)) return 0;     return min(         {distSegmentToPoint(sa, sb.first), distSegmentToPoint(sa, sb.second),          distSegmentToPoint(sb, sa.first), distSegmentToPoint(sb, sa.second)});   }   double polygonArea(vector<Point> &points) {     double area = 0;     for (int i = 0; i < points.size(); i++)       area += cross({0, 0}, points[i], points[(i + 1) % points.size()]);     return abs(area) / 2.0;   }   Point rotate(Point O, Point p, double rad) {     p = p - O;     double x = p.x * cos(rad) + p.y * -sin(rad);     double y = p.x * sin(rad) + p.y * cos(rad);     return Point(x, y) + O;   }   bool insideTriangle(Point A, Point B, Point C, Point p) {     return abs(cross(p, A, B)) + abs(cross(p, B, C)) + abs(cross(p, C, A)) ==            abs(cross(p, A, B) + cross(p, B, C) + cross(p, C, A));   }   pair<Point, Point> centerCircle(Point a, Point b, double r) {     Point c = (a + b) / 2;     double d = dist(a, b);     Point v = (b - a) / d;     swap(v.x, v.y);     v.x *= -1;     assert(d < 2 * r + eps);     double q;     if (doubleEquals(r * r, (d / 2) * (d / 2)))       q = 0;     else       q = sqrt(r * r - (d / 2) * (d / 2));     return {c + (v * q), c - (v * q)};   }   double getAxisAngle(Point c, Point p) {     double ang = atan2((p - c).y, (p - c).x);     if (ang < 0) ang += 2 * acos(-1);     return ang;   }   struct Circle {     Point p;     double r;     Circle(Point p, double r) : p(p), r(r) {}     bool touch(Circle other) {       double d = dist(p, other.p);       return d < r + other.r + eps;     }     bool inside(Circle other) {       double d = dist(p, other.p);       return d + r < other.r - eps;     }     bool cover(Point point) { return dist(point, p) < r + eps; }     bool equal(Circle other) {       double d = dist(p, other.p);       return doubleEquals(d, 0) && doubleEquals(r, other.r);     }   };   pair<Point, Point> circleIntersection(Circle c1, Circle c2) {     assert(c1.touch(c2));     assert(!c1.inside(c2) && !c2.inside(c1));     assert(!c1.equal(c2));     double d = dist(c1.p, c2.p);     double a = (c1.r * c1.r - c2.r * c2.r + d * d) / (2 * d);     double h = sqrtl(c1.r * c1.r - a * a);     Point u = (c2.p - c1.p) / d;     Point pu = Point(-u.y, u.x);     u = u * a;     pu = pu * h;     return {u + pu + c1.p, u - pu + c1.p};   }   int main() {     vector<Point> A;     vector<Point> B;     for (int i = 0; i < 4; i++) {       int a, b;       scanf( %d %d , &a, &b);       A.push_back({1. * a, 1. * b});     }     for (int i = 0; i < 4; i++) {       int a, b;       scanf( %d %d , &a, &b);       B.push_back({1. * a, 1. * b});     }     for (int i = 0; i < 4; i++) {       int a = i;       int b = (i + 1) % 4;       for (int j = 0; j < 4; j++) {         int c = j;         int d = (j + 1) % 4;         if (segmentInter({A[a], A[b]}, {B[c], B[d]})) {           printf( YES );           return 0;         }       }     }     for (int i = 0; i < 4; i++) {       vector<Point> v;       v.push_back(B[0]);       v.push_back(B[1]);       v.push_back(B[2]);       v.push_back(B[3]);       if (pnpoly(A[i], v)) {         printf( YES );         return 0;       }     }     for (int i = 0; i < 4; i++) {       vector<Point> v;       v.push_back(A[0]);       v.push_back(A[1]);       v.push_back(A[2]);       v.push_back(A[3]);       if (pnpoly(B[i], v)) {         printf( YES );         return 0;       }     }     printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     a[0] = 1;     a[1] = 5;     a[2] = 13;     a[3] = 25;     for (int i = 4; i < n; i++) {       a[i] = a[i - 1] + 4 * (i);     }     cout << a[n - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   class Matrix {    public:     long long m[4][4];     Matrix(){};     Matrix(long long k[4][4]) {       for (int i = 0; i < 4; i++)         for (int j = 0; j < 4; j++) m[i][j] = k[i][j];     }   };   Matrix operator*(const Matrix &a, const Matrix &b) {     Matrix t;     for (int i = 0; i < 4; i++) {       for (int j = 0; j < 4; j++) {         t.m[i][j] = 0;         for (int c = 0; c < 4; c++) {           t.m[i][j] += (b.m[i][c]) * (a.m[c][j]);           t.m[i][j] %= MOD;         }       }     }     return t;   }   Matrix pow(Matrix m, int p) {     if (p == 1) return m;     Matrix ret = pow(m, p / 2);     if (p & 1) {       return (ret * ret) * m;     } else       return (ret * ret);   }   int main() {     int n;     long long arr[4][4];     scanf( %d , &n);     for (int i = 0; i < 4; i++)       for (int j = 0; j < 4; j++)         if (i == j)           arr[i][j] = 0;         else           arr[i][j] = 1;     Matrix g(arr);     Matrix ret = pow(g, n);     cout << ret.m[3][3] % MOD << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, deg[N], fa[N];   int root = 0;   vector<pair<pair<int, int>, int> > ans;   struct edge {     int to, val;     edge() {}     edge(int to, int val) : to(to), val(val) {}   };   vector<edge> G[N];   vector<int> leaf[N];   void add_edge(int x, int y, int z) { G[x].push_back(edge(y, z)); }   void init() {     scanf( %d , &n);     int x, y, z;     if (n == 2) {       scanf( %d%d%d , &x, &y, &z);       printf( YES n1 n1 2 %d n , z);       exit(0);     }     for (int i = 1; i < n; ++i) {       scanf( %d%d%d , &x, &y, &z);       add_edge(x, y, z);       add_edge(y, x, z);       ++deg[x], ++deg[y];     }   }   void pre(int x, int f) {     fa[x] = f;     for (int i = 0; i < (int)G[x].size(); ++i) {       int to = G[x][i].to, w = G[x][i].val;       if (to == f) continue;       pre(to, x);       leaf[x].push_back(leaf[to][0]);     }     if (G[x].size() == 1) {       leaf[x].push_back(x);     }   }   void add_to_root(int x, int val) {     if (leaf[x].size() >= 2) {       int f1 = leaf[x][0], f2 = leaf[x][1];       ans.push_back(make_pair(make_pair(root, f1), val / 2));       ans.push_back(make_pair(make_pair(root, f2), val / 2));       ans.push_back(make_pair(make_pair(f1, f2), -val / 2));     } else {       ans.push_back(make_pair(make_pair(root, x), val));     }   }   void dfs(int x, int f) {     for (int i = 0; i < (int)G[x].size(); ++i) {       int to = G[x][i].to, w = G[x][i].val;       if (to == f) continue;       dfs(to, x);       add_to_root(to, w);       if (x != root) add_to_root(x, -w);     }   }   void solve() {     int flag = 1;     for (int i = 1; i <= n; ++i) {       if (deg[i] == 2) {         puts( NO );         return;       }     }     puts( YES );     for (int i = 1; i <= n; ++i) {       if (G[i].size() == 1) {         root = i;         break;       }     }     pre(root, 0);     dfs(root, 0);     printf( %d n , ans.size());     for (int i = 0; i < (int)ans.size(); ++i) {       printf( %d %d %d n , ans[i].first.first, ans[i].first.second,              ans[i].second);     }   }   int main() {     init();     solve();     return 0;   }


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


#include <iostream>   #include <sstream>   #include <cstdio>   #include <cmath>   #include <cstring>   #include <cctype>   #include <string>   #include <vector>   #include <set>   #include <unordered_set>   #include <map>   #include <unordered_map>   #include <queue>   #include <stack>   #include <algorithm>   #include <functional>   #include <climits>   #include <iterator>   #include <numeric>   #include <memory>      #define IOS  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)      using namespace std;   typedef long long int ll;   typedef pair<int,int> pii;   typedef vector<int> vi;      int main()   {       IOS;       int t, n;       cin>>t;       while(t--) {           cin>>n;           vector<int> p(n), maxP(n);           cin>>p[0];           maxP[0]=p[0];           for(int i=1; i<n; i++) {               cin>>p[i];               maxP[i]=max(maxP[i-1], p[i]);           }           int r=n-1, l=n-1;           while(l>=0) {               while(l>=0 && maxP[r]!=p[l]) {                   l--;               }               for(int i=l; i<=r; i++) {                   cout<<p[i]<<   ;               }               l--;               r=l;           }           cout<<  n ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     long long p1 = 0;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       a[i] = x;       p1 = max(p1, x);     }     long long m;     cin >> m;     vector<pair<long long, long long> > b(m);     long long p2 = 0;     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       b[i].first = x;       b[i].second = y;       p2 = max(p2, x);     }     if (p2 < p1) {       cout << -1 <<   n ;       return;     }     sort(b.begin(), b.end());     for (long long i = m - 2; i >= 0; i--) {       b[i].second = max(b[i].second, b[i + 1].second);     }     long long mx = 0;     long long cnt = -1;     long long ans = 0;     long long q = -1;     for (long long i = 0; i < n; i++) {       mx = max(mx, a[i]);       long long j = lower_bound(b.begin(), b.end(), make_pair(mx, q)) - b.begin();       if (b[j].second < i - cnt) {         ans++;         mx = 0;         i--;         cnt = i;       }     }     ans++;     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long TESTS = 1;     cin >> TESTS;     while (TESTS--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (1 << 30) - 1;   const long long linf = (1ll << 62) - 1;   const int N = 1e6;   int n;   int p[N];   int division[2][N];   int dln[2];   bool u[N];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , &p[i]);       p[i]--;     }     int index1 = -1, index2 = -1;     for (int i = 0; i < n; i++) {       if (p[i] == i) index1 = i;       if (p[p[i]] == i) index2 = i;     }     if (index1 != -1) {       puts( YES );       for (int i = 0; i < n; i++)         if (index1 != i) printf( %d %d n , index1 + 1, i + 1);       return 0;     }     if (index2 != -1) {       bool flag = true;       dln[0] = dln[1] = 0;       fill_n(u, n, 0);       u[index2] = u[p[index2]] = 1;       for (int i = 0; i < n; i++)         if (!u[i]) {           u[i] = 1;           division[0][dln[0]++] = i;           int curI = p[i], step = 1;           while (curI != i) {             u[curI] = 1;             division[step][dln[step]++] = curI;             step ^= 1;             curI = p[curI];           }           if (step == 1) {             flag = false;             break;           }         }       if (!flag) {         puts( NO );         return 0;       }       puts( YES );       printf( %d %d n , index2 + 1, p[index2] + 1);       for (int i = 0; i < dln[0]; i++)         printf( %d %d n , index2 + 1, division[0][i] + 1);       for (int i = 0; i < dln[1]; i++)         printf( %d %d n , p[index2] + 1, division[1][i] + 1);       return 0;     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, h;     cin >> n;     int a[n];     cin >> a[0];     h = a[0];     for (int i = 1; i < n; i++) {       cin >> a[i];       h = h + abs(a[i] - a[i - 1]) + 1;     }     cout << h + n;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5000 + 7;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int mod = 998244353;   const double eps = 1e-8;   const double PI = acos(-1);   template <class T, class S>   inline void add(T& a, S b) {     a += b;     if (a >= mod) a -= mod;   }   template <class T, class S>   inline void sub(T& a, S b) {     a -= b;     if (a < 0) a += mod;   }   template <class T, class S>   inline bool chkmax(T& a, S b) {     return a < b ? a = b, true : false;   }   template <class T, class S>   inline bool chkmin(T& a, S b) {     return a > b ? a = b, true : false;   }   int n, k, v, sum, now1, now2, a[N];   bool dp[N][N];   bool f[N][N];   vector<int> vc[2];   int main() {     scanf( %d%d%d , &n, &k, &v);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     if (sum < v) return puts( NO ), 0;     dp[0][0] = true;     for (int i = 0; i < n; i++) {       for (int j = 0; j < k; j++) {         if (!dp[i][j]) continue;         dp[i + 1][(j + a[i + 1]) % k] = true;         f[i + 1][(j + a[i + 1]) % k] = true;         dp[i + 1][j] = true;         f[i + 1][j] = false;       }     }     if (!dp[n][v % k]) return puts( NO ), 0;     int tmp = v % k;     for (int i = n; i >= 1; i--) {       if (f[i][tmp]) {         vc[0].push_back(i);         tmp = ((tmp - a[i]) % k + k) % k;       } else {         vc[1].push_back(i);       }     }     sort((vc[0]).begin(), (vc[0]).end());     sort((vc[1]).begin(), (vc[1]).end());     for (auto& t : vc[0]) now1 += a[t];     now2 = sum - now1;     puts( YES );     for (int i = 1; i < ((int)vc[0].size()); i++)       printf( 100000 %d %d n , vc[0][i], vc[0][0]);     for (int i = 1; i < ((int)vc[1].size()); i++)       printf( 100000 %d %d n , vc[1][i], vc[1][0]);     if (!((int)vc[1].size())) vc[1].push_back(vc[0].back());     if (!((int)vc[0].size())) vc[0].push_back(vc[1].back());     if (now1 < v) printf( %d %d %d n , (v - now1) / k, vc[1][0], vc[0][0]);     if (now1 > v) printf( %d %d %d n , (now1 - v) / k, vc[0][0], vc[1][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     getline(cin, s);     int n, flag = 0;     n = s.length();     for (int i = n; i >= 0; i--) {       if ((s[i] >=  a  && s[i] <=  z ) || (s[i] >=  A  && s[i] <=  Z )) {         if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  ||             s[i] ==  u  || s[i] ==  y  || s[i] ==  A  || s[i] ==  E  ||             s[i] ==  I  || s[i] ==  O  || s[i] ==  U  || s[i] ==  Y ) {           flag = 1;         }         break;       }     }     if (flag) {       cout <<  YES n ;     } else {       cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> arr;   pair<int, long long> doit(long long n) {     if (n <= 7) return make_pair(n, n);     vector<long long>::iterator ite = upper_bound(arr.begin(), arr.end(), n);     int ind = (ite - arr.begin());     ind--;     pair<int, long long> te1 = doit(n - arr[ind]);     pair<int, long long> te2 = doit(arr[ind] - 1 - arr[ind - 1]);     if (te1.first > te2.first)       return make_pair(te1.first + 1, te1.second + arr[ind]);     if (te1.first < te2.first)       return make_pair(te2.first + 1, te2.second + arr[ind - 1]);     if (te1.second + arr[ind] > te2.second + arr[ind - 1])       return make_pair(te1.first + 1, te1.second + arr[ind]);     return make_pair(te2.first + 1, te2.second + arr[ind - 1]);   }   int main() {     for (long long i = 0; i <= 100001; i++) {       arr.push_back(i * i * i);     }     long long m;     cin >> m;     pair<int, long long> temp = doit(m);     cout << temp.first <<     << temp.second;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double xp, yp, vp;   double x, y, v, r;   const double pi = acos(-1);   double cal(double x0, double y0, double x1, double y1) {     double ji = x0 * x1 + y0 * y1;     double L0 = sqrt(x0 * x0 + y0 * y0);     double L1 = sqrt(x1 * x1 + y1 * y1);     double cosA = ji / L0 / L1;     double A = acos(cosA);     double s = L1 * L0 * sin(A) / (double)2;     double l = sqrt((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1));     double dis = s * (double)2 / l;     if (dis >= r || (L0 * L0 + l * l - L1 * L1) < 0 ||         (L1 * L1 + l * l - L0 * L0) < 0)       return l;     double a0 = acos(r / L0);     double a1 = acos(r / L1);     double Lsum = r * (A - a0 - a1) + L0 * sin(a0) + L1 * sin(a1);     return Lsum;   }   bool s(double t) {     double R = sqrt(xp * xp + yp * yp);     double a = acos(xp / R);     if (yp < 0) a = -a + 2 * pi;     a = a + t * vp / R;     double x0 = R * cos(a);     double y0 = R * sin(a);     double t0 = cal(x0, y0, x, y) / v;     if (t0 <= t)       return true;     else       return false;   }   int main() {     cin >> xp >> yp >> vp;     cin >> x >> y >> v >> r;     double l = 0, r = 1e4, mid;     while (r - l > 1e-9) {       mid = (r + l) / (double)2;       if (s(mid))         r = mid;       else         l = mid;     }     printf( %.10lf , mid);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     int t, i, n, j, e;     char grid[8][8];     map<int, bool> black, white;     for (i = 0; i < 8; i++) {       cin >> grid[i];     }     int min = INT_MAX;     int flag = 0;     for (i = 0; i < 8; i++) {       for (j = 0; j < 8; j++) {         if (grid[i][j] ==  W ) {           int x = i;           int y = j;           int f = 1;           while (x >= 0) {             if (grid[x][j] ==  B ) {               f = 0;               break;             }             x--;           }           if (f == 1) {             if (min >= i) {               min = i;               flag = 0;             }           }         }         if (grid[i][j] ==  B ) {           int x = i;           int y = j;           int f = 1;           while (x < 8) {             if (grid[x][j] ==  W ) {               f = 0;               break;             }             x++;           }           if (f == 1) {             if (min > (7 - i)) {               min = 7 - i;               flag = 1;             }           }         }       }     }     if (flag == 0)       cout <<  A ;     else       cout <<  B ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void coder_RB6() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   bool comp(long long int a, long long int b) { return (a > b); }   int32_t main() {     coder_RB6();     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       vector<long long int> a;       for (long long int i = 0; i < n; i++) {         long long int x;         cin >> x;         a.push_back(x);       }       long long int flag = 0;       long long int index;       for (long long int i = 1; i < n - 1; i++) {         if (a[i] > a[i - 1] && a[i] > a[i + 1]) {           flag = 1;           index = i;           break;         }       }       if (flag == 1) {         cout <<  YES  << endl;         cout << index <<     << index + 1 <<     << index + 2 << endl;       } else {         cout <<  NO  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, f, t;   const int N = 1e3 + 5;   vector<int> adj[N];   int col[N], vis[N], row[N];   int dj[N][N];   int mn = -1e9, id = 1;   void dfs(int u, int ret) {     if (u == n + 1) {       ret = 0;       for (int i = 1; i <= 6; i++) {         for (int j = i; j <= 6; j++) {           dj[i][j] = 0;         }       }       for (int i = 1; i <= n; i++) {         for (auto j : adj[i]) {           int c = col[i];           int k = col[j];           if (!dj[c][k] && c <= k) {             ret++;             dj[c][k] = 1;           }         }       }       mn = max(mn, ret);       return;     }     for (int i = 1; i <= 6; i++) {       if (!col[u]) {         col[u] = i;         dfs(u + 1, 0);         col[u] = 0;       }     }   }   int main() {     cin >> n >> m;     while (m--) {       cin >> f >> t;       adj[f].push_back(t);       adj[t].push_back(f);     }     dfs(1, 1);     cout << mn <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int dot[510];   inline long double max(long double a, long double b) { return a > b ? a : b; }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , dot + i);     }     double ans = 0.0;     for (int i = 1; i <= m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       if (z > 0) {         ans = max(ans, (long double)(dot[x] + dot[y]) / z);       }     }     cout << setiosflags(ios::fixed) << setprecision(10) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const long long int BOUND = 1.5e6;   const long long int SQ_BOUND = BOUND * BOUND;   vector<complex<long long int> > arr;   long long int s[N];   inline long long int norm_sq(const complex<long long int> &z) {     return (z * conj(z)).real();   }   long long int greedy(long long int sgn) {     complex<long long int> o{0, 0};     reverse((arr).begin(), (arr).end());     o = (s[0] = sgn) * arr[0];     for (int i = 1; i < (int)arr.size(); ++i) {       complex<long long int> po = o + arr[i];       complex<long long int> ne = o - arr[i];       if (norm_sq(po) <= norm_sq(ne)) {         s[i] = 1;         o = po;       } else {         s[i] = -1;         o = ne;       }     }     reverse((arr).begin(), (arr).end());     return norm_sq(o);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     srand(time(NULL));     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       int x, y;       cin >> x >> y;       arr.emplace_back(x, y);     }     long long int cur, sgn = 1;     do {       cur = greedy(sgn);       if (!~sgn) random_shuffle((arr).begin(), (arr).end());       sgn = -sgn;     } while (cur > SQ_BOUND);     for (int i = n - 1; i >= 0; --i) cout << s[i] <<    n [i + 1 == n];     return 0;   }


//  Say:He is the Most Merciful,We have believed in him and upon him we have relied  [67:29]       //#pragma GCC optimize ( Ofast )   //#pragma GCC target ( avx2 )   //#pragma GCC optimize( unroll-loops )       #include<bits/stdc++.h>   using namespace std;                                                           /*   #include <ext/pb_ds/assoc_container.hpp>   #include <ext/pb_ds/tree_policy.hpp>   using namespace __gnu_pbds;   template<typename T>   using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;    */       typedef long long ll;   typedef long double ld;   typedef pair<ll,ll> pll;   typedef pair<int,int> pii;   typedef vector<ll> vll;   typedef vector<int> vii;   typedef map<int,int> mpi;   typedef map<ll,ll> mpl;   typedef unordered_map<int,int> umpi;   typedef unordered_map<ll,ll> umpl;       #define ump unordered_map   #define mod 1000000007   #define inf 1000000000000000006   #define infi 2000000009   #define ff first   #define ss second   #define pb push_back   #define all(v) v.begin(), v.end()   #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)   #define endl   n    #define pi acos(-1.0)   #define dec(n) fixed << setprecision(n)   #define N 300005   //#define int long long      inline void IO(string name) { // Usaco        freopen((name +  .in ).c_str(),  r , stdin);        freopen((name +  .out ).c_str(),  w , stdout);   }      ll n,a[N],t[N],k,d[N];   vector<pii> v;   void solve(){    cin >> n >> k;    for(int i=0;i<k;i++) cin >> a[i];    for(int i=0;i<k;i++) cin >> t[i];    priority_queue<pii> pq;    for(int i=1;i<=n;i++) d[i]=infi;    for(int i=0;i<k;i++){     pq.push({-t[i],a[i]});     d[a[i]]=t[i];    }    //int cc=0;    while(!pq.empty()){     //cc++;     int u=pq.top().ss,c=-pq.top().ff;     pq.pop();     if(u-1!=0 && d[u-1]>c+1){      d[u-1]=c+1;      pq.push({-d[u-1],u-1});     }     if(u+1!=n+1 && d[u+1]>c+1){      d[u+1]=c+1;      pq.push({-d[u+1],u+1});     }    }    for(int i=1;i<=n;i++) cout << d[i] <<    ;    cout << endl;    //cout << cc << endl;       }      signed main(){       fastio;       //srand(chrono::steady_clock::now().time_since_epoch().count());       int T=1,cs=0;       cin >> T;       while(T--){           //cout <<  Case   << ++cs <<  :  <<     ;         solve();       }    }


#include <bits/stdc++.h>   using namespace std;   int num[100 + 5][100 + 5], ans[100 + 5][100 + 5];   int row[100 + 5], col[100 + 5];   int main() {     int n, m;     while (scanf( %d%d , &m, &n) != EOF) {       int i, j, k;       int ii, jj, kk;       memset(row, 0, sizeof(row));       memset(col, 0, sizeof(col));       for (i = 0; i < m; i++) {         for (j = 0; j < n; j++) {           scanf( %d , &num[i][j]);           row[i] += num[i][j];           col[j] += num[i][j];         }       }       for (i = 0; i < m; i++) {         for (j = 0; j < n; j++) {           ans[i][j] = 1;         }       }       for (i = 0; i < m; i++) {         for (j = 0; j < n; j++) {           if (num[i][j] == 0) {             for (ii = 0; ii < m; ii++) ans[ii][j] = 0;             for (jj = 0; jj < n; jj++) ans[i][jj] = 0;           }         }       }       bool ok = true;       for (i = 0; i < m; i++) {         for (j = 0; j < n; j++) {           int tp = 0;           for (ii = 0; ii < m; ii++) tp |= ans[ii][j];           for (jj = 0; jj < n; jj++) tp |= ans[i][jj];           if (tp != num[i][j]) {             ok = false;             break;           }         }         if (!ok) break;       }       if (ok) {         printf( YES n );         for (i = 0; i < m; i++) {           for (j = 0; j < n; j++) {             if (j) printf(   );             printf( %d , ans[i][j]);           }           printf(  n );         }       } else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 501;   int n, m, a[N];   bool dp[2][N][N];   vector<int> sol;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     dp[0][0][0] = dp[0][a[0]][0] = dp[0][a[0]][a[0]] = true;     int at = 0;     for (int i = 1; i < n; ++i) {       at ^= 1;       for (int j = 0; j <= m; ++j)         for (int k = 0; k <= m; ++k) {           dp[at][j][k] = dp[at ^ 1][j][k];           if (a[i] <= j) dp[at][j][k] |= dp[at ^ 1][j - a[i]][k];           if (a[i] <= j && a[i] <= k && k <= j)             dp[at][j][k] |= dp[at ^ 1][j - a[i]][k - a[i]];         }     }     for (int i = 0; i <= m; ++i)       if (dp[at][m][i]) sol.push_back(i);     printf( %d n , (int)sol.size());     for (int i = 0; i < (int)sol.size(); ++i)       printf( %s%d , i ?     :   , sol[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   template <typename T>   inline void read(T& x) {     T res = 0, flag = 1;     char ch;     ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) flag = -1;       ch = getchar();     }     while (isdigit(ch)) {       res = res * 10 + ch - 48;       ch = getchar();     }     x = res * flag;   }   const int N = 300000 + 1;   int n, m, a[N], f[N];   inline bool check(int x) {     for (int i = 1; i <= n; ++i) {       f[i] = a[i];       if (f[i] >= f[i - 1]) {         if (f[i] + x >= m)           if ((f[i] + x) % m >= f[i - 1]) f[i] = f[i - 1];       } else {         if (f[i] + x >= f[i - 1])           f[i] = f[i - 1];         else           return 0;       }     }     return 1;   }   int main() {     read(n), read(m);     for (int i = 1; i <= n; ++i) read(a[i]);     int l = 0, r = m;     while (l < r) {       int mid = l + r >> 1;       if (check(mid))         r = mid;       else         l = mid + 1;     }     printf( %d n , l);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, a;       vector<int> v;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a;         v.push_back(a);       }       reverse(v.begin(), v.end());       for (int i = 0; i < n; i++) {         cout << v[i] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   #pragma gcc optimize(o3)   using namespace std;   long long qpow(long long x, long long y) {     return y ? (y & 1 ? x * qpow(x, y - 1) % 1000000007                       : qpow(x * x % 1000000007, y / 2))              : 1;   }   template <typename T>   inline void read(T& x) {     x = 0;     char c;     int sign = 1;     do {       c = getchar();       if (c ==  - ) sign = -1;     } while (!isdigit(c));     do {       x = x * 10 + c -  0 ;       c = getchar();     } while (isdigit(c));     x *= sign;   }   long long a, b, x, y, k;   long long gcd(long long p, long long q) {     if (q == 0) return p;     return gcd(q, p % q);   }   int main() {     read(a), read(b), read(x), read(y);     k = gcd(x, y);     x /= k, y /= k;     printf( %I64d n , min(a / x, b / y));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = (long long)(2e5 + 1);   bool bipartite = true;   vector<long long> colour;   vector<long long> adj[N];   vector<long long> visited;   void dfs(long long node, long long par, long long col) {     visited[node] = 1;     colour[node] = col;     for (auto it : adj[node]) {       if (!visited[it])         dfs(it, node, !col);       else if (it != par and colour[it] == colour[node])         bipartite = false;     }   }   signed main() {     long long n, m;     cin >> n >> m;     vector<pair<long long, long long>> edges;     colour = vector<long long>(n, -1);     visited = vector<long long>(n, 0);     for (long long i = 0; i < m; i++) {       long long u, v;       cin >> u >> v;       u--, v--;       adj[v].push_back(u);       adj[u].push_back(v);       edges.push_back({u, v});     }     dfs(0, -1, 0);     if (!bipartite) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     for (long long i = 0; i < m; i++) {       long long ele1 = edges[i].first;       long long ele2 = edges[i].second;       cout << (colour[ele1] < colour[ele2]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buf[10000001], *ptr = buf - 1;   inline int read() {     int x = 0, c = *++ptr;     while (c < 48) c = *++ptr;     while (c > 47) x = x * 10 + c -  0 , c = *++ptr;     return x;   }   const int MAXN = 500005;   const int MOD = 1000000007;   int s[MAXN], a[MAXN], b[MAXN];   int c[MAXN], cnt[MAXN];   int n;   inline int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }   inline void modify(int i, int t) {     while (i <= n) s[i] = add(s[i], t), i += i & -i;   }   inline int query(int i) {     int res = 0;     while (i) res = add(res, s[i]), i -= i & -i;     return res;   }   int main(int argc, char const *argv[]) {     fread(buf, 1, sizeof(buf), stdin)[buf] = 0;     int x, ans = 0;     n = read();     for (int i = 1; i <= n; ++i) b[i] = c[i] = a[i] = read();     sort(b + 1, b + 1 + n);     for (int i = 1; i <= n; ++i) {       x = lower_bound(b + 1, b + 1 + n, a[i]) - b;       modify(x, i);       cnt[i] = (cnt[i] + (long long)query(x - 1) * (n - i + 1)) % MOD;     }     memset(s, 0, sizeof(s));     reverse(a + 1, a + 1 + n);     for (int i = 1; i <= n; ++i) {       x = lower_bound(b + 1, b + 1 + n, a[i]) - b;       modify(x, i);       cnt[n - i + 1] =           (cnt[n - i + 1] + (long long)query(x - 1) * (n - i + 1)) % MOD;     }     for (int i = 1; i <= n; ++i)       ans = (ans + (cnt[i] + (long long)i * (n - i + 1)) % MOD * c[i]) % MOD;     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 1e5;   int m, n;   long long sum[MaxN + 5], a[MaxN + 5];   long long Gcd(long long x, long long y) {     if (y == 0)       return x;     else       return Gcd(y, x % y);   }   void pdo() {     long long ans = 0;     for (int i = 1; i <= n; i++) {       long long t1 = a[i] * (i - 1) - sum[i - 1];       long long t2 = sum[n] - sum[i] - a[i] * (n - i);       ans += a[i] + t1 + t2;     }     long long t = Gcd(ans, (long long)n);     printf( %I64d %I64d n , ans / t, n / t);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];     pdo();   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4 )   using namespace std;   using ll = long long;   using ld = long double;   using itn = int;   using dd = double;   mt19937 gen(41);   const dd eps = 1e-7;   const ll MAXN = 2097152;   const ll INF = 1e9;   const dd pi = acos(dd(-1));   ll gcd(ll a, ll b) {     a = abs(a);     b = abs(b);     while (b) {       a %= b;       swap(a, b);     }     return a;   }   ll binpow(ll a, ll n, ll binpow_mod = 1e9 + 7) {     ll res = 1;     while (n) {       if (n & 1) res *= a;       a *= a;       n >>= 1;       a %= binpow_mod;       res %= binpow_mod;     }     return res;   }   struct Point {     ll x, y;     bool z;     void scan() { cin >> x >> y; }     Point(ll X = 0, ll Y = 0, bool Z = 0) {       x = X;       y = Y;       z = Z;     }     ll operator*(Point &a) { return x * a.y - y * a.x; }     bool operator==(Point &a) { return x == a.x && y == a.y; }   };   ll n, m, k;   deque<ll> a;   ll solve() {     vector<ll> b((n + m - 1) / m, 0), c((n + m - 1) / m, -1e10);     ll now = 0;     for (int i = 0; i < n; i++) {       now += a[i];       c[i / m] = max(c[i / m], now);       if (i % m == m - 1) {         b[i / m] = now;         now = 0;       }     }     ll ans = c[0] - k, sum = 0, min_sum = 0;     for (int r = 0; r < b.size(); ++r) {       sum += c[r] - k;       ans = max(ans, sum - min_sum);       sum = sum - c[r] + b[r];       min_sum = min(min_sum, sum);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout << fixed << setprecision(20);     cin >> n >> m >> k;     a.resize(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     ll res = 0;     for (int k = 0; k < min(n, m); k++) {       res = max(res, solve());       a.pop_front();       n = a.size();     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define ll long long int   ll mod=1e9+7;   ll mul(ll a,ll b)   {       return ((a%mod)*(b%mod))%mod;   }   ll add(ll a,ll b)   {       return ((a%mod)+(b%mod))%mod;   }   ll sub(ll a,ll b)   {       return ((a%mod)-(b%mod)+mod)%mod;   }   ll po(ll a, ll b)   {       if(b==0)       {           return 1;       }       ll t=po(a,b/2);       if(b%2)       {           return mul(t,mul(t,a));       }       else       {           return mul(t,t);       }   }   ll  a[200005];   ll mseg[1000000];   ll maseg[1000000];   void mupd(ll s, ll e, ll i)   {    if(s==e)    {     mseg[i]=a[s];     return;    }    ll mi=s+(e-s)/2;    mupd(s,mi,2*i+1);    mupd(mi+1,e,2*i+2);    mseg[i]=min(mseg[2*i+1],mseg[2*i+2]);    return;   }   void maupd(ll s, ll e, ll i)   {    if(s==e)    {     maseg[i]=a[s];     return;    }    ll mi=s+(e-s)/2;    maupd(s,mi,2*i+1);    maupd(mi+1,e,2*i+2);    maseg[i]=max(maseg[2*i+1],maseg[2*i+2]);    return;   }   ll mir(ll s, ll e, ll i,ll chs, ll che)   {    if(s>che || e<chs)    {     return 1e18;    }    if(s<=chs && e>=che)    {     return mseg[i];    }    ll mi=chs+(che-chs)/2;    return min(mir(s,e,2*i+1,chs,mi),mir(s,e,2*i+2,mi+1,che));   }   ll mar(ll s, ll e, ll i,ll chs, ll che)   {    if(s>che || e<chs)    {     return -1e18;    }    if(s<=chs && e>=che)    {     return maseg[i];    }    ll mi=chs+(che-chs)/2;    return max(mar(s,e,2*i+1,chs,mi),mar(s,e,2*i+2,mi+1,che));   }   int main()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);       ll t;       cin>>t;       while(t--)       {        ll n,q;        cin>>n>>q;        a[0]=0;        string s;        cin>>s;        for(ll i=0;i<n;i++)        {         if(s[i]== - )         {          a[i+1]=a[i]-1;         }         else         {          a[i+1]=a[i]+1;         }         //cout<<a[i+1]<<   ;        }        //cout<<  n ;        mupd(0,n,0);        maupd(0,n,0);        while(q--)        {         ll l,r;         cin>>l>>r;         ll u1=mir(0,l-1,0,0,n);         ll u2=mar(0,l-1,0,0,n);;         ll s1=0,s2=0;         //cout<<u1<<   <<u2<<  n ;         if(r+1<=n)         {          s1=mir(r+1,n,0,0,n);          s2=mar(r+1,n,0,0,n);;                    s1=s1-a[r];          s2=s2-a[r];         }         //cout<<u1<<   <<u2<<   <<s1<<   <<s2<<  n ;         ll mi=min((ll)0,u1);         ll ma=max((ll)0,u2);         mi=min(a[l-1]+s1,mi);         ma=max(a[l-1]+s2,ma);         cout<<ma-mi+1<<  n ;        }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int dp[50][50];   int m, n;   int main() {     for (int x = 0; x < 36; x++) {       dp[0][x] = 1;     }     for (int x = 1; x < 36; x++)       for (int y = 1; y < 36; y++)         for (int z = 0; z < x; z++) {           dp[x][y] += dp[z][y - 1] * dp[x - z - 1][y - 1];         }     cin >> m >> n;     cout << dp[m][35] - dp[m][n - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void print(T t) {     cout << t << endl;   }   long long n = 0, t = 0;   long long small = -1e18, big = 1e18;   const long long mod = 1e9 + 7;   map<long long, long long> occ;   map<pair<long long, long long>, long long> occP;   void print2dVec(vector<vector<long long>> v) {     for (int i = 0; i < v.size(); ++i) {       cout << i <<   :  ;       for (int j = 0; j < v[i].size(); ++j) {         cout << v[i][j] <<    ;       }       print(  );     }   }   void printSet(set<int> s) {     for (auto itr = s.begin(); itr != s.end(); ++itr) {       cout << *itr <<    ;     }   }   long long factorial(int n) {     long long ans = 1;     for (int i = 1; i <= n; ++i) {       ans *= i;     }     return ans;   }   long long findGCD(long long a, long long b) {     long long ans = 1;     for (int i = 1; i <= min(a, b); ++i) {       if (a % i == 0 && b % i == 0) {         ans = i;       }     }     return ans;   }   long long findLCM(long long a, long long b) {     for (long long i = min(a, b); i <= a * b; ++i) {       if (i % a == 0 && i % b == 0) {         return i;       }     }     return -1;   }   bool isPrime(int num) {     if (num <= 1) return false;     if (num <= 3) return true;     int range = sqrt(num);     if (num % 2 == 0 || num % 3 == 0) return false;     for (int i = 5; i <= range; i += 6)       if (num % i == 0 || num % (i + 2) == 0) return false;     return true;   }   vector<long long> primeFactors(long long x) {     vector<long long> fac;     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) {         while (x % i == 0) {           fac.push_back(i);           x /= i;         }       }     }     return fac;   }   bool sortVec(const vector<long long>& v1, const vector<long long>& v2) {     return v1[0] < v2[0];   }   bool check(long long val) { return false; }   long long binsearch(long long low, long long high) {     while (low < high) {       long long mid = (low + high) / 2;       if (check(mid)) {         high = mid;       } else {         low = mid + 1;       }     }     return low;   }   unordered_map<long long, long long> d;   long long rib(long long n, long long a, long long b, long long c) {     if (n == 0) return 0;     if (n < 0) return small;     if (d.count(n))       return d[n];     else {       d[n] = 1 + max(rib(n - a, a, b, c),                      max(rib(n - b, a, b, c), rib(n - c, a, b, c)));       return d[n];     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed;     cout << setprecision(10);     ;     long long n, a, b, c;     cin >> n >> a >> b >> c;     cout << rib(n, a, b, c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b;     cin >> n >> a >> b;     int rem = b % n;     int sum = a + rem;     if (sum <= 0)       cout << n + sum;     else if (sum > n)       cout << sum - n;     else       cout << sum;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100030;   const long long MODD = 1000000009;   int ctr[128];   void do_case() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) ctr[s[i]]++;     sort(ctr, ctr + 128);     reverse(ctr, ctr + 128);     long long ans = 0;     for (int i = 0; i < 128; i++) {       long long v = min(k, ctr[i]);       ans += v * v;       k -= v;     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     do_case();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<long long> > g;   vector<bool> used;   void dfs(long long v, long long &h, long long &e) {     used[v] = true;     h++;     e += g[v].size();     for (int i = 0; i < g[v].size(); ++i) {       if (!used[g[v][i]]) dfs(g[v][i], h, e);     }   }   int main() {     long long n, m;     cin >> n >> m;     g.resize(n);     used.resize(n);     for (int i = 0; i < m; ++i) {       long long u, v;       cin >> u >> v;       g[u - 1].push_back(v - 1);       g[v - 1].push_back(u - 1);     }     for (int i = 0; i < n; ++i) {       if (!used[i]) {         long long h = 0, e = 0;         dfs(i, h, e);         if (h * (h - 1) != e) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<int> res;     for (int i = n + 1;; i++) {       if (res.size() == n) {         break;       }       res.push_back(i);     }     for (auto x : res) {       cout << x <<    ;     }   }   int main() {     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 99999999;   struct seg_tree {     int seg[3 * 1000009], lazy[3 * 1000009];     void construct_segtree(int start, int end, int pos) {       lazy[pos] = -inf;       if (end == start + 1)         seg[pos] = 0;       else {         int mid = (start + end) / 2;         construct_segtree(start, mid, 2 * pos + 1);         construct_segtree(mid, end, 2 * pos + 2);         int t1 = seg[2 * pos + 1];         int t2 = seg[2 * pos + 2];         seg[pos] = t1 + t2;       }     }     int get_query(int ql, int qh, int low, int high, int pos) {       if (lazy[pos] != -inf) {         seg[pos] += lazy[pos];         if (high != low + 1) {           add_lazy(2 * pos + 1, lazy[pos]);           add_lazy(2 * pos + 2, lazy[pos]);         }         lazy[pos] = -inf;       }       if (qh <= low || ql >= high) return 0;       if (low >= ql && high <= qh) return seg[pos];       int mid = (low + high) / 2;       return get_query(ql, qh, low, mid, 2 * pos + 1) +              get_query(ql, qh, mid, high, 2 * pos + 2);     }     void update(int ql, int qh, int low, int high, int val, int pos) {       int mid = (high + low) / 2;       if (lazy[pos] != -inf) {         seg[pos] += lazy[pos];         if (high != low + 1) {           add_lazy(2 * pos + 1, lazy[pos]);           add_lazy(2 * pos + 2, lazy[pos]);         }         lazy[pos] = -inf;       }       if (qh <= low || ql >= high) return;       if (low >= ql && high <= qh) {         seg[pos] += val;         if (high != low + 1) {           add_lazy(2 * pos + 1, val);           add_lazy(2 * pos + 2, val);         }         return;       }       update(ql, qh, low, mid, val, 2 * pos + 1);       update(ql, qh, mid, high, val, 2 * pos + 2);       seg[pos] = seg[2 * pos + 1] + seg[2 * pos + 2];       return;     }       private:     void add_lazy(int place, int val) {       if (lazy[place] == -inf)         lazy[place] = val;       else         lazy[place] += val;     }   };   struct Query {     int first, second, indx;   };   int bin_search(int first, int second);   void pre_process();   void fn();   int comp(Query x, Query y);   int comp2(Query x, Query y);   seg_tree tree;   char input[1000009];   int arr[1000009], ans[1000009], n_q = 0;   Query q[1000009], open[1000009], close_here[1000009];   int my_stack[1000009];   int ten = 0;   int main() {     scanf( %s , input);     scanf( %d , &n_q);     for (int i = 0; i < n_q; i++) scanf( %d %d , &q[i].first, &q[i].second);     for (int i = 0; i < min(10, (int)strlen(input)); i++)       if (input[i] ==  ) ) ten++;     pre_process();     fn();     for (int i = 0; i < n_q; i++) printf( %d n , ans[i]);     return 0;   }   void fn() {     int closed = 0;     int y = strlen(input);     for (int i = 0; i <= max((int)y, 0) && closed < n_q; i++) {       while (closed < n_q && close_here[closed].second <= i) {         int k = close_here[closed].indx;         int indx = close_here[closed].indx;         ans[open[indx].indx] = tree.get_query(indx, indx + 1, 0, n_q, 0);         closed++;       }       if (n_q == closed) return;       if (i < y && input[i] ==  ) ) {         if (arr[i] != -1) {           int x = arr[i];           int indx = bin_search(x + 1, -inf);           if (indx != -1) tree.update(0, indx + 1, 0, n_q, 2, 0);         }       }     }   }   int bin_search(int first, int second) {     int s = 0, b = n_q, ret = -1;     while (b >= s) {       int mid = (b + s) / 2;       if (open[mid].first < first)         s = mid + 1, ret = max(ret, mid);       else         b = mid - 1;     }     return ret;   }   void pre_process() {     memset(arr, -1, sizeof(arr));     int stack_indx = 0;     for (int i = 0; i < strlen(input); i++) {       if (input[i] ==  ( )         my_stack[stack_indx++] = i;       else {         if (stack_indx) {           int x = my_stack[stack_indx - 1];           stack_indx--;           arr[i] = x;           arr[x] = i;         }       }     }     for (int i = 0; i < n_q; i++) q[i].first--;     for (int i = 0; i < n_q; i++) {       open[i].first = q[i].first;       open[i].second = q[i].second;       open[i].indx = i;     }     sort(open, open + n_q, comp);     for (int i = 0; i < n_q; i++) {       int k = open[i].indx;       q[k].indx = i;     }     for (int i = 0; i < n_q; i++) close_here[i] = q[i];     sort(close_here, close_here + n_q, comp2);     int prev = 0;     tree.construct_segtree(0, n_q, 0);   }   int comp(Query x, Query y) {     if (x.first == y.first) return x.second < y.second;     return x.first < y.first;   }   int comp2(Query x, Query y) {     if (x.second == y.second) return x.first < y.first;     return x.second < y.second;   }


#include <bits/stdc++.h>   using namespace std;   long long labs(long long a) { return a < 0 ? (-a) : a; }   long long max(long long a, long long b) { return a > b ? a : b; }   long long min(long long a, long long b) { return a < b ? a : b; }   int main() {     int n;     cin >> n;     int h = 1;     vector<vector<int> > ans;     for (int i = 0; ans.size() + (h - 1) <= n; i++) {       ans.push_back(vector<int>());       for (int(k) = 0; (k) < ((int)ans.size() - 1); (k)++) {         ans[i].push_back(h);         ans[k].push_back(h++);       }     }     cout << ans.size() << endl;     for (int(i) = 0; (i) < (ans.size()); (i)++) {       for (int(j) = 0; (j) < (ans[i].size()); (j)++) {         cout << ans[i][j] <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     float dist, h, w, t;     cin >> dist;     cin >> h;     cin >> w;     t = dist / (h + w);     printf( %.12lf n , t * h);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int infinity = 1e9;   int N, M;   int A[509][509];   int P[509][509];   int squaresum(int cx, int cy, int k) {     int ax = cx - k / 2;     int ay = cy - k / 2;     int bx = cx + k / 2;     int by = cy + k / 2;     return P[bx][by] - P[ax - 1][by] - P[bx][ay - 1] + P[ax - 1][ay - 1];   }   bool goodk(int i, int j, int k) {     k /= 2;     return ((i - k >= 1) && (i + k <= N) && (j - k >= 1) && (j + k <= M));   }   int main() {     scanf( %d %d  , &N, &M);     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++) scanf( %d , &A[i][j]);     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++)         P[i][j] = P[i - 1][j] + P[i][j - 1] - P[i - 1][j - 1] + A[i][j];     int ans = -infinity;     for (int i = 2; i <= N - 1; i++)       for (int j = 2; j <= M - 1; j++) {         int spiral = A[i][j];         for (int k = 3; goodk(i, j, k); k += 2) {           spiral = squaresum(i, j, k) - spiral - A[i - k / 2 + 1][j - k / 2];           ans = max(ans, spiral);         }       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int cnt[maxn], num[maxn], t[maxn], r[maxn], last[maxn];   char ans[maxn];   int main() {     int T, m, k;     scanf( %d , &T);     while (T--) {       scanf( %d%d , &m, &k);       for (int i = 1; i <= k; i++) {         scanf( %d , &num[i]);         ans[i] =  N ;         cnt[i] = 0;         last[i] = 0;       }       int unknown = 0;       bool flag = 0;       for (int i = 1; i <= m - 1; i++) {         scanf( %d%d , &t[i], &r[i]);         last[t[i]] = i;       }       for (int i = 1; i <= m - 1; i++) {         if (r[i] == 0) {           if (t[i])             cnt[t[i]]++;           else             unknown++;         } else {           if (flag == 0) {             int tmp = 0x3fffffff;             for (int j = 1; j <= k; j++) {               if (last[j] < i && cnt[j] + unknown >= num[j]) {                 tmp = min(tmp, num[j] - cnt[j]);                 ans[j] =  Y ;               }             }             unknown -= tmp;             flag = 1;           }           if (t[i])             cnt[t[i]]++;           else             unknown++;         }         if (t[i] != 0 && cnt[t[i]] == num[t[i]]) {           flag = 1;         }       }       for (int i = 1; i <= k; i++) {         if (num[i] - cnt[i] - unknown <= 0) {           ans[i] =  Y ;         }       }       ans[k + 1] = 0;       printf( %s n , ans + 1);     }     return 0;   }