#include <bits/stdc++.h>   using namespace std;   long long powmod(long long p, long long n) {     if (n == 0) return 1;     if (n % 2 == 1) return (p * powmod(p, n - 1)) % 1000000007;     long long z = powmod(p, n / 2);     return (z * z) % 1000000007;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long x, n;     cin >> x >> n;     set<long long> P;     for (long long i = 2; i < 100000 && x > 1; ++i) {       while (x % i == 0) {         P.insert(i);         x /= i;       }     }     if (x > 1) P.insert(x);     long long ans = 1;     for (long long p : P) {       long long a = 0;       long long b = n;       while (b) {         b /= p;         a += b;         a %= (1000000007 - 1);       }       ans *= powmod(p, a);       ans %= 1000000007;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, n, m;   long long a[1 << 20], b[1 << 20];   int g[21][100001];   void FWT(long long *P, int opt) {     for (int i = 2; i <= N; i <<= 1)       for (int p = i >> 1, j = 0; j < N; j += i)         for (int k = j; k < j + p; ++k) {           long long x = P[k], y = P[k + p];           P[k] = x + y;           P[k + p] = x - y;           if (opt == -1) P[k] /= 2, P[k + p] /= 2;         }   }   int main() {     cin >> n >> m;     N = 1 << n;     char ch[100001];     for (int i = 1; i <= n; ++i) {       scanf( %s , ch + 1);       for (int j = 1; j <= m; ++j) g[i][j] = ch[j] - 48;     }     for (int i = 1; i <= m; ++i) {       int x = 0;       for (int j = 1; j <= n; ++j) x = (x << 1) | g[j][i];       a[x]++;     }     for (int i = 0; i < N; ++i) b[i] = b[i >> 1] + (i & 1);     for (int i = 0; i < N; ++i) b[i] = min(b[i], n - b[i]);     FWT(a, 1);     FWT(b, 1);     for (int i = 0; i < N; ++i) a[i] *= b[i];     FWT(a, -1);     long long ans = n * m;     for (int i = 0; i < N; ++i) ans = min(ans, a[i]);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-6;   inline long long lgput(long long a, long long b, long long mod) {     long long ret = 1;     while (b) {       if (b & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return (ret % mod);   }   inline long long inv(long long x, long long MOD) {     return lgput(x, MOD - 2, MOD);   }   inline bool exist(double nr) { return (nr < -eps) || (nr > eps); }   long long big_rand() { return rand() * RAND_MAX + rand(); }   map<int, int> gr[100100];   map<int, int> vec[100100];   vector<int> ap[100100];   int dad[100100];   int superdad(int a) {     if (dad[a] != a) {       dad[a] = superdad(dad[a]);     }     return dad[a];   }   void bag(int a, int b) {     for (auto &x : ap[dad[a]]) {       vec[x][dad[b]] = 1;       ap[dad[b]].push_back(x);     }     ap[dad[a]].clear();     dad[dad[a]] = dad[b];   }   void unite(int a, int b) {     superdad(a);     superdad(b);     if (dad[a] == dad[b]) {       return;     }     if (ap[dad[a]].size() < ap[dad[b]].size()) {       bag(a, b);     } else {       bag(b, a);     }   }   void edge(int x, int y, int val) {     if (gr[x][val]) {       unite(y, gr[x][val]);     }     if (gr[y][val]) {       unite(x, gr[y][val]);     }     gr[x][val] = y;     gr[y][val] = x;     superdad(x);     superdad(y);     vec[y][dad[x]] = 1;     vec[x][dad[y]] = 1;     ap[dad[x]].push_back(y);     ap[dad[y]].push_back(x);   }   bool verif(int x, int y) {     superdad(x);     superdad(y);     if (dad[x] == dad[y]) {       return 1;     }     if (vec[y][dad[x]]) {       return 1;     }     return 0;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cout << setprecision(10) << fixed;     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     srand(time(nullptr));     int n, m, c, q;     cin >> n >> m >> c >> q;     for (int i = 1; i <= n; i++) {       dad[i] = i;     }     for (int i = 1; i <= m; i++) {       int x, y, val;       cin >> x >> y >> val;       edge(x, y, val);     }     while (q--) {       char ch;       cin >> ch;       if (ch ==  + ) {         int x, y, val;         cin >> x >> y >> val;         edge(x, y, val);       } else {         int x, y;         cin >> x >> y;         if (verif(x, y)) {           cout <<  Yes  <<   n ;         } else {           cout <<  No  <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   pair<pair<int, int>, int> a[100100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       a[i].first.first = x;     }     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       a[i].first.second = x;       a[i].second = i;     }     sort(a + 1, a + n + 1);     reverse(a + 1, a + n + 1);     cout << (n / 2) + 1 << endl;     cout << a[1].second <<    ;     for (int i = 2; i <= n; i += 2) {       if (i == n)         cout << a[i].second;       else {         int x = a[i].second;         if (a[i + 1].first.second > a[i].first.second) x = a[i + 1].second;         cout << x <<    ;       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long i, x;     vector<long long> v;     for (i = 0; i < n; i++) {       cin >> x;       v.push_back(x);     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       long long sum = 0;       for (long long j = i; j < n; j++) {         sum += v[j];         if (sum > 100 * (j - i + 1)) ans = max(ans, j - i + 1);       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 5;   const long long mod = 998244353;   set<long long> pre, cur;   string s, mn, mx;   long long zmin[2 * N];   long long zmax[2 * N];   long long dmin[N];   long long dmax[N];   long long dp[N];   long long n;   void init() {     long long n, m, l, r;     string str;     n = s.size();     m = mn.size();     l = r = 0;     str = mn +  #  + s;     for (long long i = 1; i <= n + m; i++) {       long long &x = zmin[i];       if (i <= r) x = min(zmin[i - l], r - i);       while (i + x <= n + m && str[x] == str[i + x]) x++;       if (i + x >= r) {         l = i;         r = i + x;       }       if (i > m) dmin[i - m] = i - m + x;     }     n = s.size();     m = mx.size();     l = r = 0;     str = mx +  #  + s;     for (long long i = 1; i <= n + m; i++) {       long long &x = zmax[i];       if (i <= r) x = min(zmax[i - l], r - i);       while (i + x <= n + m && str[x] == str[i + x]) x++;       if (i + x >= r) {         l = i;         r = i + x;       }       if (i > m) dmax[i - m] = i - m + x;     }   }   bool ok(long long l, long long r) {     if (r - l + 1 > mx.size()) return false;     if (r - l + 1 == mx.size()) {       long long mid = dmax[l];       if (mid <= r && s[mid] > mx[mid - l]) return false;     }     if (r - l + 1 < mn.size()) return false;     if (r - l + 1 == mn.size()) {       long long mid = dmin[l];       if (mid <= r && s[mid] < mn[mid - l]) return false;     }     return true;   }   void add(long long &a, long long b) {     a += b;     if (a >= mod) a -= mod;   }   void sub(long long &a, long long b) {     a -= b;     if (a < 0) a += mod;   }   void solve() {     long long sum = 0;     dp[0] = 1;     for (long long i = 1; i <= n; i++) {       dp[i] = 0;       while (pre.size()) {         long long pos = *pre.begin();         if (ok(pos, i)) {           cur.insert(pos);           pre.erase(pos);           add(sum, dp[pos - 1]);         } else           break;       }       while (cur.size()) {         long long pos = *cur.begin();         if (!ok(pos, i)) {           cur.erase(pos);           sub(sum, dp[pos - 1]);         } else           break;       }       dp[i] = sum;       if (ok(i, i)) {         add(dp[i], dp[i - 1]);         if (s[i] !=  0 ) {           cur.insert(i);           add(sum, dp[i - 1]);         }       } else if (s[i] !=  0 )         pre.insert(i);     }     cout << dp[n] <<   n ;   }   void brute() {     dp[0] = 1;     for (long long i = 1; i <= n; i++) {       dp[i] = 0;       for (long long j = 0; j < i; j++) {         if (ok(j + 1, i) && !(j + 1 != i && s[j + 1] ==  0 )) add(dp[i], dp[j]);       }     }     cout << dp[n] <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> s >> mn >> mx;     init();     n = s.size();     s =     + s;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int modularPower(long long int x, unsigned long long int y,                              long long int mod) {     long long int res = 1;     x %= mod;     while (y > 0) {       if (y & 1) res = (res * x) % mod;       y >>= 1;       x = (x * x) % mod;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cerr.tie(NULL);     cout.tie(NULL);     ;     int height;     cin >> height;     vector<int> v(height + 5);     vector<int> sum(height + 5);     int posOfChange = 0;     for (int i = 0; i <= height; ++i) {       int foo;       cin >> foo;       v[i] = foo;     }     while (posOfChange < height and            (v[posOfChange] == 1 or v[posOfChange + 1] == 1))       posOfChange++;     if (posOfChange == height) {       cout <<  perfect ;       return 0;     }     sum[0] = 1;     for (int i = 1; i < v.size(); ++i) {       sum[i] = sum[i - 1] + v[i - 1];     }     cout <<  ambiguous           <<   n ;     cout << 0 <<    ;     for (int i = 1; i <= height; ++i) {       for (int j = 0; j < v[i]; ++j) {         cout << sum[i - 1] <<    ;       }     }     cout <<   n  << 0 <<    ;     for (int i = 1; i <= height; ++i) {       if (i == posOfChange + 1) {         cout << sum[i - 1] + 1 <<    ;         for (int j = 1; j < v[i]; ++j) {           cout << sum[i - 1] <<    ;         }       } else {         for (int j = 0; j < v[i]; ++j) {           cout << sum[i - 1] <<    ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long infLL = 0x3f3f3f3f3f3f3f3fLL;   const int maxn = 5000 + 5;   const int mod = 1000000007;   int n, m;   int s[maxn];   int f[maxn], h[maxn];   map<pair<int, int>, int> cows;   int l[maxn], r[maxn];   int pre[maxn], suf[maxn];   int cnt[maxn][4];   void sweep() {     for (int i = (1); i <= (n); ++i) {       auto it = cows.find(pair<int, int>(s[i], ++pre[s[i]]));       if (it != cows.end()) l[it->second] = i;     }     for (int i = n; i >= 1; --i) {       auto it = cows.find(pair<int, int>(s[i], ++suf[s[i]]));       if (it != cows.end()) r[it->second] = i;     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = (1); i <= (n); ++i) scanf( %d , &s[i]);     for (int i = 0; i < (m); ++i) {       scanf( %d%d , &f[i], &h[i]);       cows[pair<int, int>(f[i], h[i])] = i;       l[i] = inf, r[i] = -inf;     }     sweep();     int X = 0, Y = 1;     for (int i = 0; i < (m); ++i)       if (r[i] > 0) ++cnt[f[i]][2];     for (int t = (1); t <= (n); ++t)       if (cnt[t][2]) ++X, Y = (long long)Y * cnt[t][2] % mod;     for (int i = 0; i < (m); ++i)       if (l[i] <= n) {         int x = 1, y = 1;         memset(cnt, 0, sizeof(cnt));         for (int j = 0; j < (m); ++j)           if (j != i) {             int mask = 0;             if (f[j] != f[i] && l[j] < l[i]) mask |= 1;             if (r[j] > l[i]) mask |= 2;             ++cnt[f[j]][mask];           }         for (int t = (1); t <= (n); ++t) {           int c = ((cnt[t][1] + cnt[t][3]) * (cnt[t][2] + cnt[t][3]) - cnt[t][3]);           if (c) {             x += 2, y = (long long)y * c % mod;             continue;           }           c = cnt[t][1] + cnt[t][2] + cnt[t][3] * 2;           if (c) ++x, y = (long long)y * c % mod;         }         if (x > X)           X = x, Y = y;         else if (x == X)           Y = (Y + y) % mod;       }     printf( %d %d n , X, Y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a[n + 1][3];     map<long long, long long> m;     for (long long i = 1; i <= n; i++) {       cin >> a[i][0] >> a[i][1] >> a[i][2];     }     vector<pair<double, pair<long long, long long> > > v;     for (long long i = 1; i < n; i++) {       for (long long j = i + 1; j <= n; j++) {         double d =             sqrt(pow(abs(a[i][0] - a[j][0]), 2) + pow(abs(a[i][1] - a[j][1]), 2) +                  pow(abs(a[i][2] - a[j][2]), 2));         v.push_back({d, {i, j}});       }     }     sort(v.begin(), v.end());     long long c = 0;     for (long long i = 0; i < v.size(); i++) {       if (m[(v[i].second).second] == 0 && m[(v[i].second).first] == 0) {         cout << (v[i].second).second <<     << (v[i].second).first << endl;         m[(v[i].second).second]++;         m[(v[i].second).first]++;         c++;       }       if (c == n / 2) break;     }   }


#include <bits/stdc++.h>   const int maxn = 5e5 + 5;   using namespace std;   char s[maxn];   int main() {     scanf( %s , s);     int k = strlen(s);     char y = s[0];     for (int i = 0; i < k; i++) {       if (s[i] > y) {         cout <<  Ann  << endl;       } else {         y = s[i];         cout <<  Mike  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   bool es[100001];   string ans;   void wk() {     int i;     cin >> n;     cin >> s;     for (i = 0; i <= n; i++) es[i] = false;     int fstone = n;     for (i = 0; i < n; i++)       if (s[i] ==  1 ) {         fstone = i;         break;       }     bool zero = false;     for (i = n - 1; i >= 0; i--) {       if (s[i] ==  0  && zero && fstone < i) es[i] = true;       if (s[i] ==  1  && zero) es[i] = true;       if (s[i] ==  0 ) zero = true;     }     ans =   ;     for (i = 0; i < n; i++)       if (!es[i]) ans += s[i];     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     int i;     cin >> t;     for (i = 1; i <= t; i++) wk();     return 0;   }


#include <bits/stdc++.h>   const char nl =   n ;   const int mod = (int)1e9 + 7;   int main() {     std::cin.tie(0)->std::ios::sync_with_stdio(0);     std::cin.exceptions(std::cin.failbit);     int t;     std::cin >> t;     while (t--) {       int n;       std::string s;       std::cin >> n >> s;       int l = -1, r = -1;       for (int i = 0; i < n - 1; i++) {         if ((s[i] ==  a  && s[i + 1] ==  b ) ||             (s[i] ==  b  && s[i + 1] ==  a )) {           l = i + 1;           r = i + 2;           break;         }       }       std::cout << l <<     << r << nl;     }   }


#include <bits/stdc++.h>   using namespace std;   const bool DEBUG = false;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     bool puede = true;     int N, M;     cin >> N >> M;     unordered_set<int> conj;     vector<string> cad(N);     vector<int> index(M);     for (int i = 0; i < N; i++) {       cin >> cad[i];       conj.insert(i);     }     for (int i = 0; i < M; i++) {       cin >> index[i];       index[i]--;       conj.erase(index[i]);     }     for (int i = 0; i < M - 1; i++) {       if (cad[index[i]].size() != cad[index[i + 1]].size()) puede = false;     }     if (!puede) {       cout <<  No n ;       return 0;     }     bool band;     string patron =   ;     int sz = cad[index[0]].size();     if (DEBUG) {       cout << cad[index[0]] << endl;       cout <<  SZ:   << sz << endl;     }     for (int i = 0; i < sz; i++) {       band = true;       for (int j = 0; j < M - 1; j++) {         if (cad[index[j]][i] != cad[index[j + 1]][i]) {           patron +=  ? ;           band = false;         }         if (!band) break;       }       if (band) patron += cad[index[0]][i];     }     for (auto &it : conj) {       band = true;       if (cad[it].size() != patron.size()) continue;       for (int i = 0; i < patron.size(); i++) {         if (patron[i] ==  ? ) continue;         if (patron[i] == cad[it][i]) continue;         band = false;         break;       }       if (band) {         cout <<  No n ;         return 0;       }     }     cout <<  Yes n  << patron <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<string> v(n);       for (int i = 0; i < n; i++) {         cin >> v[i];       }       int a[26] = {0};       for (auto s : v) {         for (auto i : s) {           a[i -  a ]++;         }       }       int f = 0;       for (int i = 0; i < 26; i++) {         if (a[i] % n) {           f = 1;           break;         }       }       if (f) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> V[100005];   long long n;   map<long long, long long> DP[100005];   long long concatHash(long long x, long long y) {     return (x * 100005 + y) % 1000000007;   }   void answer(long long x) {     cout << x;     exit(0);   }   void fail() {     cout << -1;     exit(0);   }   void prec(long long x, long long f) {     if (V[x].size() == 1 && f) {       DP[x][f] = 1;       return;     }     unordered_set<long long> S;     for (auto i : V[x]) {       if (i != f) {         prec(i, x);         if (DP[i][x] == -1) DP[x][f] = -1;         S.insert(DP[i][x]);       }     }     if (DP[x][f] == -1) return;     if (S.size() == 1) {       long long chash = *(S.begin());       DP[x][f] = concatHash(chash, V[x].size());     } else       DP[x][f] = -1;   }   void DFS(long long x, long long f, long long phash) {     if (V[x].size() == 1 && f) {       if (phash != -1) {         answer(x);       }       return;     }     unordered_map<long long, long long> S;     for (auto i : V[x])       if (i != f) S[DP[i][x]]++;     if (f) S[phash]++;     if (S.size() == 0) {       assert(false);       return;     }     if (S.size() == 1 && S.begin()->first != -1) {       answer(x);     }     if (S.size() == 1 && S.begin()->first == -1) {       if (S.begin()->second != 1) return;       for (auto i : V[x]) {         if (DP[i][x] == -1) {           if (f)             DFS(i, x, concatHash(phash, V[x].size()));           else             DFS(i, x, V[x].size());           return;         }       }     }     if (S.size() >= 3) {       return;     }     auto it = S.begin();     auto a = make_pair(it->first, it->second);     it++;     auto b = make_pair(it->first, it->second);     for (auto i : V[x]) {       if (i != f && (DP[i][x] == a.first && a.second == 1 && b.first != -1)) {         DFS(i, x, concatHash(b.first, V[x].size()));       }       if (i != f && (DP[i][x] == b.first && b.second == 1 && a.first != -1)) {         DFS(i, x, concatHash(a.first, V[x].size()));       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     if (n == 1) {       answer(1);     }     for (long long i = 1; i < n; i++) {       long long x, y;       cin >> x >> y;       V[x].push_back(y);       V[y].push_back(x);     }     prec(1, 0);     DFS(1, 0, -1);     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   const double pi = acos(-1.0);   const long long mod = 1e9 + 7;   int n, k;   int a[MAXN], b[MAXN], z[MAXN], f[MAXN];   void solve() {     scanf( %d %d , &n, &k);     int t = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       if (a[i] < k)         b[i] = 0;       else if (a[i] == k) {         b[i] = 1;         t = 1;       } else         b[i] = 2;     }     int flag = 0, last = -10;     for (int i = 1; i <= n; i++) {       int cnt = 0;       for (int j = 0; j < 3; j++)         if (b[i + j] >= 1) cnt++;       if (cnt > 1) flag = 1;     }     if ((flag && t) || (n == 1 && a[1] == k))       puts( yes );     else       puts( no );     for (int i = 1; i <= n; i++) b[i] = 0;   }   int main() {     int T = 1;     scanf( %d , &T);     while (T--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000000000 + 7;   const double esp = 1e-13;   struct node {     int x, y;     bool operator<(const node &op) const {       return op.x > x || (op.x == x && op.y > y);     }   } a[2000 + 10];   int h, w, n;   long long res[2000 + 10], gt[200000 + 10], rev[200000 + 10];   long long power(long long a, long long n) {     long long ans = 1;     while (n) {       if (n % 2) ans = ans * a % INF;       a = a * a % INF;       n /= 2;     }     return ans;   }   long long C(int n, int k) { return gt[n] * rev[k] % INF * rev[n - k] % INF; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cin >> h >> w >> n;     for (long long i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;     a[++n] = {h, w};     sort(a + 1, a + n + 1);     gt[0] = 1;     rev[0] = power(1, INF - 2);     for (long long i = 1; i <= 200000; i++) {       gt[i] = gt[i - 1] * i % INF;       rev[i] = power(gt[i], INF - 2);     }     for (long long i = 1; i <= n; i++) {       res[i] = C(a[i].x + a[i].y - 2, a[i].x - 1);       for (long long j = 1; j <= i - 1; j++)         if (a[i].x >= a[j].x && a[i].y >= a[j].y) {           res[i] -= res[j] *                     C(a[i].x - a[j].x + a[i].y - a[j].y, a[i].x - a[j].x) % INF;           if (res[i] < 0) res[i] += INF;         }     }     cout << res[n];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     pair<int, int> p[100000];     int n, ans = 0, a, k, c = 0, i;     scanf( %d %d , &n, &k);     for (i = 0; i < n; i++) scanf( %d , &a), p[i] = make_pair(a, i);     sort(p, p + n);     for (i = 0; i < n; i++) {       if ((p[i].first + ans) <= k) c++, ans += p[i].first;     }     printf( %d n , c);     for (i = 0; i < c; i++) printf( %d  , p[i].second + 1);   }


#include <bits/stdc++.h>   using namespace std;   using Long = long long;   constexpr Long MOD = 998244353;   template <typename T>   using V = vector<T>;   template <typename T>   using Vv = V<V<T>>;   using Vb = V<bool>;   using Vvb = V<Vb>;   using Vi = V<int>;   using Vvi = V<Vi>;   using Vl = V<Long>;   using Vvl = V<Vl>;   using Vd = V<double>;   using Vvd = V<Vd>;   using Vs = V<string>;   template <typename First, typename Second>   istream& operator>>(istream& is, pair<First, Second>& v);   template <typename T>   istream& operator>>(istream& is, vector<T>& v) {     for (auto& x : v) {       is >> x;     }     return is;   }   template <typename First, typename Second>   istream& operator>>(istream& is, pair<First, Second>& v) {     is >> v.first >> v.second;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (const auto& x : v) {       os << x <<    ;     }     return os;   }   void solve() {     Vvi divisors(100001);     for (int d = 1; d <= 100000; ++d) {       for (int k = 1; d * k <= 100000; ++k) {         divisors[d * k].push_back(d);       }     }     int bitcount[] = {0, 1, 1, 2, 1, 2, 2, 3};     int t;     cin >> t;     for (int i = 0; i < t; ++i) {       int num[3];       Vi* d[3];       int n[3];       for (int j = 0; j < 3; ++j) {         cin >> num[j];         d[j] = &divisors[num[j]];         n[j] = d[j]->size();       }       int p[3] = {};       int counts[1 << 3] = {};       while (p[0] < n[0] || p[1] < n[1] || p[2] < n[2]) {         int v[3];         for (int j = 0; j < 3; ++j) {           v[j] = p[j] < n[j] ? (*d[j])[p[j]] : 100001;         }         int m = min({v[0], v[1], v[2]});         int set = 0;         for (int j = 0; j < 3; ++j) {           if (v[j] == m) {             set |= 1 << j;             p[j]++;           }         }         counts[set]++;       }       Long ans = 0;       for (int x = 1; x < (1 << 3); ++x) {         for (int y = x; y < (1 << 3); ++y) {           for (int z = y; z < (1 << 3); ++z) {             if ((x | y | z) == (1 << 3) - 1) {               Long r = 0;               if (x != y && y != z && x != z) {                 ans += (Long)counts[x] * counts[y] * counts[z];               } else if (x == y && y == z) {                 int c = counts[x];                 r = c * (c + 1LL) * (c + 2LL) / (2 * 3);               } else if (x == y) {                 if (bitcount[x] > 1) {                   int c = counts[x];                   r = (c * (c + 1LL) / 2) * counts[z];                 }               } else if (x == z) {                 if (bitcount[x] > 1) {                   int c = counts[x];                   r = (c * (c + 1LL) / 2) * counts[y];                 }               } else if (y == z) {                 if (bitcount[y] > 1) {                   int c = counts[y];                   r = (c * (c + 1LL) / 2) * counts[x];                 }               } else {                 throw exception{};               }               ans += r;             }           }         }       }       cout << ans <<   n ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cout.precision(10);     cout << fixed;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (1 << 20) + 1000;   const int INF = 1000000000;   const int Mod = 1000000007;   void update(int tree[], int k, int v) {     while (k < N) {       tree[k] += v;       k += k & (-k);     }   }   int get(int tree[], int k) {     int ret = 0;     while (k) {       ret += tree[k];       k -= k & (-k);     }     return ret;   }   int a[N], n, tot, r[N], mp[N], tree[N];   long long dp[30], sum[30], f[30];   bool cmpr(int i, int j) { return a[i] < a[j]; }   int Hash() {     for (int i = 0; i < tot; i++) r[i] = i;     sort(r, r + tot, cmpr);     int K = 1;     mp[1] = a[r[0]];     for (int i = 0; i < tot; i++) {       if (mp[K] != a[r[i]]) mp[++K] = a[r[i]];       a[r[i]] = K;     }     return K;   }   int main() {     scanf( %d , &n);     tot = 1 << n;     for (int i = 0; i < tot; i++) scanf( %d , &a[i]);     int fuck = Hash();     for (int i = 1; i <= n; i++) {       dp[i] += dp[i - 1];       sum[i] += sum[i - 1];       int len = 1 << (i - 1);       for (int j = tot / len - 2; j >= 0; j -= 2) {         for (int k = 0; k < len; k++) update(tree, a[(j + 1) * len + k], 1);         for (int k = 0; k < len; k++) {           int tmp = get(tree, a[j * len + k] - 1);           sum[i] += tmp;           dp[i] += tmp;         }         for (int k = 0; k < len; k++) update(tree, a[(j + 1) * len + k], -1);         for (int k = 0; k < len; k++) update(tree, a[j * len + k], 1);         for (int k = 0; k < len; k++) {           sum[i] += get(tree, a[(j + 1) * len + k] - 1);         }         for (int k = 0; k < len; k++) update(tree, a[j * len + k], -1);       }     }     int m;     scanf( %d , &m);     while (m--) {       int x;       scanf( %d , &x);       long long t1 = dp[x], t2 = sum[x] - dp[x];       f[0] = 0;       for (int i = 1; i < x; i++) {         f[i] = dp[i];         dp[i] = sum[i] - dp[i];       }       for (int i = x; i <= n; i++) {         dp[i] = dp[i] - t1 + t2;       }       printf( %I64d n , dp[n]);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   vector<long long int> edges[500010];   long long int c[500010], cc[500010], color[500010], bip[500010];   long long int dfs(long long int u, long long int co, long long int j) {     color[u] = co;     cc[u] = j;     for (auto v : edges[u]) {       if (c[v] != c[u]) continue;       if (color[v] == color[u]) return false;       if (color[v] != 0) continue;       if (!dfs(v, 3 - co, j)) return false;     }     return true;   }   map<pair<long long int, long long int>,       vector<pair<long long int, long long int>>>       es;   map<long long int, vector<pair<long long int, long long int>>> gr;   map<long long int, long long int> flip;   long long int dfs2(long long int u, long long int f) {     flip[u] = f;     for (auto e : gr[u]) {       long long int v = e.first;       if (e.second == 0) {         if (flip.count(v) && flip[v] != flip[u]) return false;         if (flip.count(v) == 0) {           if (!dfs2(v, f)) return false;         }       }       if (e.second == 1) {         if (flip.count(v) && flip[v] == flip[u]) return false;         if (flip.count(v) == 0) {           if (!dfs2(v, !f)) return false;         }       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, k;     cin >> n >> m >> k;     for (long long int i = 1; i <= n; ++i) cin >> c[i];     for (long long int i = 0; i < m; ++i) {       long long int a, b;       cin >> a >> b;       edges[a].push_back(b);       edges[b].push_back(a);       if (c[a] != c[b]) {         long long int mi = min(c[a], c[b]);         long long int ma = max(c[a], c[b]);         es[{mi, ma}].push_back({a, b});       }     }     for (long long int i = 1; i <= k; ++i) bip[i] = 1;     for (long long int i = 1; i <= n; ++i) {       if (!color[i]) {         if (!dfs(i, 1, i)) bip[c[i]] = 0;       }     }     long long int nb = accumulate(bip, bip + k + 1, 0ll);     set<pair<long long int, long long int>> bad;     for (auto pp : es) {       long long int c1 = pp.first.first;       long long int c2 = pp.first.second;       if ((!bip[c1]) || (!bip[c2])) continue;       gr.clear();       flip.clear();       set<long long int> rc;       for (auto e : pp.second) {         if (color[e.first] == color[e.second])           gr[cc[e.first]].push_back({cc[e.second], 1});         if (color[e.first] != color[e.second])           gr[cc[e.first]].push_back({cc[e.second], 0});         if (color[e.first] == color[e.second])           gr[cc[e.second]].push_back({cc[e.first], 1});         if (color[e.first] != color[e.second])           gr[cc[e.second]].push_back({cc[e.first], 0});         rc.insert(cc[e.first]);         rc.insert(cc[e.second]);       }       for (auto i : rc) {         if (!flip.count(i)) {           if (!dfs2(i, 0)) bad.insert(pp.first);         }       }     }     cout << nb * (nb - 1) / 2 - bad.size() << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 2, M = 6e5 + 2, O = 1.2e6 + 2;   long long len1[M], len2[M], v[N], g[N][4], ans[M];   long long lx, ly;   int lj[M], nxt[M], fir[N], f[N], qlj[O], qnxt[O], qfir[N], xw[O][3];   int flj[M], fnxt[M], ffir[N];   int n, q, i, x, y, c, bs, qs, fs;   bool ed[N];   inline void read(int &x) {     c = getchar();     while ((c < 48) || (c > 57)) c = getchar();     x = c ^ 48;     c = getchar();     while ((c >= 48) && (c <= 57)) {       x = x * 10 + (c ^ 48);       c = getchar();     }   }   inline void read(long long &x) {     c = getchar();     while ((c < 48) || (c > 57)) c = getchar();     x = c ^ 48;     c = getchar();     while ((c >= 48) && (c <= 57)) {       x = x * 10 + (c ^ 48);       c = getchar();     }   }   inline void add() {     lj[++bs] = y;     len1[bs] = lx;     len2[bs] = ly;     nxt[bs] = fir[x];     fir[x] = bs;     lj[++bs] = x;     len1[bs] = lx;     len2[bs] = ly;     nxt[bs] = fir[y];     fir[y] = bs;   }   inline void fadd(int x, int y) {     flj[++fs] = y;     fnxt[fs] = ffir[x];     ffir[x] = fs;   }   inline void qadd(int x, int y, int i) {     qlj[++qs] = i;     qnxt[qs] = qfir[x];     qfir[x] = qs;   }   void dfs1(int x) {     ed[x] = 1;     for (int i = fir[x]; i; i = nxt[i])       if (!ed[lj[i]]) {         dfs1(lj[i]);         v[x] = min(v[x], v[lj[i]] + len1[i] + len2[i]);       }     ed[x] = 0;   }   void dfs2(int x) {     ed[x] = 1;     for (int i = fir[x]; i; i = nxt[i])       if (!ed[lj[i]]) {         v[lj[i]] = min(v[lj[i]], v[x] + len1[i] + len2[i]);         dfs2(lj[i]);       }     ed[x] = 0;   }   void dfs3(int x) {     ed[x] = 1;     for (int i = fir[x]; i; i = nxt[i])       if (!ed[lj[i]]) {         g[lj[i]][0] = min(len2[i], v[x] + v[lj[i]] + len1[i]);         g[lj[i]][1] = min(len2[i] + v[lj[i]], len1[i] + v[x]);         g[lj[i]][2] = min(len1[i] + v[lj[i]], len2[i] + v[x]);         g[lj[i]][3] = min(len1[i], v[x] + v[lj[i]] + len2[i]);         dfs3(lj[i]);       }     ed[x] = 0;   }   void getf(register int x) {     if (f[f[x]] == f[x]) return;     getf(f[x]);     g[0][0] = min(g[x][0] + g[f[x]][0], g[x][2] + g[f[x]][1]);     g[0][1] = min(g[x][1] + g[f[x]][0], g[x][3] + g[f[x]][1]);     g[0][2] = min(g[x][0] + g[f[x]][2], g[x][2] + g[f[x]][3]);     g[0][3] = min(g[x][1] + g[f[x]][2], g[x][3] + g[f[x]][3]);     memcpy(g[x], g[0], 32);     f[x] = f[f[x]];   }   void dfs4(int x) {     ed[x] = 1;     int i;     for (i = qfir[x]; i; i = qnxt[i])       if (ed[y = xw[qlj[i]][2]]) {         getf(y);         fadd(f[y], qlj[i]);       }     for (i = fir[x]; i; i = nxt[i])       if (!ed[lj[i]]) {         dfs4(lj[i]);         f[lj[i]] = x;       }     for (i = ffir[x]; i; i = fnxt[i]) {       y = flj[i];       if (y > q)         c = y - q;       else         c = y;       if (xw[y][2] != x) {         qs = xw[y][0] >> 1 & 1;         bs = xw[y][0] & 1;         getf(xw[y][1]);         getf(xw[y][2]);         ans[c] = min(g[xw[y][1]][bs] + g[xw[y][2]][qs],                      g[xw[y][1]][bs | 2] + g[xw[y][2]][qs | 2]);       } else {         getf(xw[y][1]);         ans[c] = g[xw[y][1]][xw[y][0]];       }     }   }   int main() {     read(n);     for (i = 1; i <= n; i++) read(v[i]);     for (i = 1; i < n; i++) {       read(x);       read(y);       read(lx);       read(ly);       add();       f[i] = i;     }     dfs1(1);     dfs2(1);     dfs3(1);     read(q);     for (i = 1; i <= q; i++) {       read(x);       read(y);       if (x + 1 >> 1 == y + 1 >> 1) {         if (x != y) ans[i] = v[x + 1 >> 1];         continue;       }       xw[i][0] = (x & 1) | (y & 1) << 1;       xw[i + q][0] = (y & 1) | (x & 1) << 1;       qadd(xw[i][1] = xw[i + q][2] = x = x + 1 >> 1,            xw[i][2] = xw[i + q][1] = y = y + 1 >> 1, i);       qadd(y, x, i + q);     }     dfs4(1);     for (i = 1; i <= q; i++) printf( %lld n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   string winner;   int score;   int calc(int Suc, int Fal, int A, int B, int C, int D, int E) {     int ret = A + B + C + D + E;     ret += Suc * 100;     ret -= Fal * 50;     return ret;   }   int main() {     int n;     while (cin >> n) {       score = -100000000;       for (int i = 1; i <= n; i++) {         string name;         int Suc, Fal, A, B, C, D, E;         cin >> name >> Suc >> Fal >> A >> B >> C >> D >> E;         int s = calc(Suc, Fal, A, B, C, D, E);         if (s > score) winner = name, score = s;       }       cout << winner << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }   int main() {     int n;     scanf( %d , &n);     if (n % 2)       printf( %d %d n , n / 2, n / 2 + 1);     else {       for (int a = n / 2 - 1; a; a--) {         if (gcd(a, n - a) == 1) {           printf( %d %d n , a, n - a);           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int r, c;     scanf( %d %d , &r, &c);     bool banR[1000] = {false};     bool banC[1000] = {false};     char map[100][100];     for (int i = 0; i < r; i++) {       scanf( %s , map[i]);     }     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         if (map[i][j] ==  S ) {           banR[i] = true;           banC[j] = true;         }       }     }     int minus = 0;     int ans = 0;     for (int i = 0; i < r; i++) {       if (banR[i] == false) {         ans += c;         minus++;       }     }     for (int i = 0; i < c; i++) {       if (banC[i] == false && minus <= r) {         ans += (r - minus);       }     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[10];   int n, ans, m, tmp;   vector<int> v2;   void recur(int now) {     if (now == n) {       int vis[7][7];       memset(vis, 0, sizeof(vis));       int ans2 = 0;       for (int e = 1; e <= n; e++) {         for (int p = 0; p < v[e].size(); p++) {           int next = v[e][p];           int f = v2[e - 1], s = v2[next - 1];           if (f > s) swap(f, s);           if (vis[f][s] == 0) {             vis[f][s] = 1;             ans2++;           }         }       }       ans = max(ans, ans2);     } else {       for (int p = 1; p <= min(n, 6); p++) {         v2.push_back(p);         recur(now + 1);         v2.pop_back();       }     }   }   int main(void) {     scanf( %d%d , &n, &m);     for (int e = 0; e < m; e++) {       int a, b;       scanf( %d%d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     recur(0);     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s1, s2;     cin >> s1 >> s2;     int ans = 0;     int start = 0;     int end = n - 1;     while (s1[start] == s2[start]) start++;     while (s1[end] == s2[end]) end--;     if (s1.substr(start, end - start) == s2.substr(start + 1, end - start)) ans++;     if (s2.substr(start, end - start) == s1.substr(start + 1, end - start)) ans++;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t1, t2, x1, x2, t0, y1, y2;     cin >> t1 >> t2 >> x1 >> x2 >> t0;     if (t1 == t2)       cout << x1 <<     << x2 << endl;     else if (t1 == t0)       cout << x1 <<     << 0 << endl;     else if (t2 == t0)       cout << 0 <<     << x2 << endl;     else {       y1 = 0;       y2 = x2;       long double min_diff = t2 - t0;       for (long long i = 1; i <= x1; i++) {         long long j = ((t0 - t1) * i + (t2 - t0 - 1)) / (t2 - t0);         if (j > x2) continue;         long double temp = (t1 * i + t2 * j + 0.0) / (i + j + 0.0);         long double diff = temp - t0;         if (min_diff > diff) {           min_diff = diff;           y1 = i;           y2 = j;         } else if (min_diff == diff && i + j > y1 + y2) {           y1 = i;           y2 = j;         }       }       cout << y1 <<     << y2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void sortLU(long long a[], long long n, long long b[]) {     long long i, j;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (a[i] < a[j]) {           swap(a[i], a[j]);           swap(b[i], b[j]);         }       }     }   }   int main() {     long long p;     cin >> p;     long long a, s = 0, i;     for (i = 0; i < p; i++) {       cin >> a;       s += a;     }     long long n;     cin >> n;     long long x[n], y[n];     for (i = 0; i < n; i++) {       cin >> x[i] >> y[i];     }     for (i = 0; i < n; i++) {       if (s <= max(x[i], y[i])) {         if (s <= min(x[i], y[i])) {           cout << min(x[i], y[i]) << endl;           return 0;         } else {           cout << s << endl;           return 0;         }       }     }     cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   inline void add(int &a, int b, int md = MOD) {     a += b;     if (a >= md) {       a -= md;     }   }   inline int mul(int a, int b, int md = MOD) { return (long long)a * b % md; }   inline int power(int a, int b, int md = MOD) {     int res = 1;     while (b > 0) {       if (b & 1) {         res = mul(res, a, md);       }       a = mul(a, a, md);       b >>= 1;     }     return res;   }   inline int inv(int x) { return power(x, MOD - 2); }   struct node {     int value;     int len;   };   node seq(int n7, int n6, int k) {     int p10k = power(10, k);     int t = mul(p10k, 10);     int e = n6 - power(10, k, MOD - 1) + 1;     if (e < 0) {       e += MOD - 1;     }     int it1 = inv(t - 1);     int sum = mul(power(t, e) + MOD - 1, it1);     int z = mul(p10k, sum);     int res = z;     int cnt = n7 - p10k + 1;     if (cnt < 0) {       cnt += MOD;     }     add(res, mul(sum - cnt + MOD, it1));     return {res, mul(e, k + 1, MOD - 1)};   }   node concat(node a, node b) {     int value = mul(a.value, power(10, b.len));     add(value, b.value);     return {value, (a.len + b.len) % (MOD - 1)};   }   node multi(node a, int b) {     if (b == 1) {       return a;     }     if (b % 2 == 1) {       return concat(multi(a, b - 1), a);     }     node z = multi(a, b / 2);     return concat(z, z);   }   const int N = 100010;   node prec[N];   node big_seq(int n7, int n6, int k) {     node res = seq(n7, n6, k - 1);     for (int i = k - 2; i >= 0; i--) {       res = concat(prec[i], res);     }     return res;   }   char s[N];   int pos;   node solve_exp() {     int start = pos;     int v7 = 0;     int v6 = 0;     while ( 0  <= s[pos] && s[pos] <=  9 ) {       v7 = mul(v7, 10);       add(v7, s[pos] -  0 );       v6 = mul(v6, 10, MOD - 1);       add(v6, s[pos] -  0 , MOD - 1);       pos++;     }     int len_v = pos - start;     if (s[pos] ==  + ) {       pos++;       return concat({v7, len_v}, solve_exp());     }     if (s[pos] ==  - ) {       pos++;       int start2 = pos, w7 = 0, w6 = 0;       while ( 0  <= s[pos] && s[pos] <=  9 ) {         w7 = mul(w7, 10);         add(w7, s[pos] -  0 );         w6 = mul(w6, 10, MOD - 1);         add(w6, s[pos] -  0 , MOD - 1);         pos++;       }       int len_w = pos - start2;       add(v7, MOD - 1);       add(v6, (MOD - 1) - 1, MOD - 1);       node v = big_seq(v7, v6, len_v);       node w = big_seq(w7, w6, len_w);       int diff = w.len - v.len;       if (diff < 0) {         diff += MOD - 1;       }       int real_value = w.value;       add(real_value, MOD - mul(v.value, power(10, diff)));       int real_len = w.len;       add(real_len, (MOD - 1) - v.len, MOD - 1);       if (s[pos] ==  + ) {         pos++;         return concat({real_value, real_len}, solve_exp());       }       return {real_value, real_len};     }     if (s[pos] ==  ( ) {       int finish = pos;       pos++;       node z = solve_exp();       node res = {0, 0};       for (int i = start; i < finish; i++) {         res = multi(res, 10);         if (s[i] !=  0 ) {           res = concat(res, multi(z, s[i] -  0 ));         }       }       pos++;       if (s[pos] ==  + ) {         pos++;         return concat(res, solve_exp());       }       return res;     }     return {v7, len_v};   }   int main() {     int v7 = 0;     int v6 = 0;     for (int k = 0; k < N; k++) {       v7 = mul(v7, 10);       add(v7, 9);       v6 = mul(v6, 10, MOD - 1);       add(v6, 9, MOD - 1);       prec[k] = seq(v7, v6, k);     }     scanf( %s , s);     pos = 0;     node res = solve_exp();     printf( %d n , res.value);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e7 + 10;   const long long MOD = (long long)(1e9) + (long long)(7);   const long double INF = 1e17;   long long dp[505][505][12];   long long edge[505][505][4];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     vector<long long> v(n);     map<long long, long long> cnt;     for (auto &it : v) {       cin >> it;       cnt[it]++;     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     if (n < 4)       cout << 0;     else {       for (int i = 0; i < n; i++) {         if (cnt[v[i]] % 2 == 1) {           cnt[v[i]]--;           cnt[v[i] - 1]++;         }       }       long long ans = 0;       bool form = true;       long long store = 0;       for (long long i = 0; i < n; i++) {         long long l = v[i];         while (cnt[l] >= 2) {           if (form == true) {             form = false;             store = l;             cnt[l] -= 2;           } else {             form = true;             ans += store * l;             store = 0;             cnt[l] -= 2;           }         }       }       cout << ans;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using vi = vector<int>;   const int N = 3e5 + 3;   const int mod = 1e9 + 7;   int n;   ll a[N];   template <class T>   struct FT {     vector<T> tree;     int sz;     FT(int n) { sz = n, tree.resize(n + 1); }     T get(int i) {       if (i <= 0 || i > sz) return T(0);       T sum = T(0);       for (; i; i -= (i & -i)) sum += tree[i];       return sum;     }     void upd(int i, T val) {       for (; i <= sz; i += (i & -i)) tree[i] += val;     }     void init(T *arr, int n) {       sz = n;       for (int i = 1; i <= n; i++) upd(i, arr[i - 1]);     }   };   ll ans[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     FT<ll> tree1(N);     FT<ll> tree2(N);     ll sum = 0;     for (int i = 0; i < n; i++) {       ans[i] = 1ll * i * a[i] + sum;       ans[i] -= tree1.get(a[i]);       sum += a[i];       int mul = a[i];       while (mul < N) {         tree1.upd(mul, 1ll * a[i]);         mul += a[i];       }       mul = (300000 / a[i]) * a[i];       ll cnt = 0;       while (mul != 0) {         ll cur = i - tree2.get(mul - 1);         ll how_many = cur - cnt;         ans[i] -= 1ll * mul * how_many;         cnt = cur;         mul -= a[i];       }       tree2.upd(a[i], 1ll);     }     for (int i = 0; i < n; i++) {       printf( %lld  , ans[i]);       ans[i + 1] += ans[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double a, v;     cin >> a >> v;     double l, d, w;     cin >> l >> d >> w;     w = min(w, v);     double s = w / a;     double t = a * s * s / 2;     double thead = 0;     double vhead = 0;     if (t < d) {       double t1 = v / a;       double t2 = (v - w) / a;       double dd = t1 * v / 2 + t2 * (v + w) / 2;       if (dd < d) {         double t3 = (d - dd) / v;         thead = t1 + t2 + t3;         vhead = w;       } else {         double vv = sqrt((2 * a * d + w * w) / 2);         thead = vv / a + (vv - w) / a;         vhead = w;       }     } else {       thead = sqrt(2 * d / a);       vhead = a * thead;     }     double ttail = 0;     double tt = (-vhead + sqrt(vhead * vhead + 2 * a * (l - d))) / a;     if (vhead + tt * a < v) {       ttail = tt;     } else {       double t1 = (v - vhead) / a;       double rest = (l - d) - (vhead + v) * t1 / 2;       double t2 = rest / v;       ttail = t1 + t2;     }     cout << setiosflags(ios::fixed) << setprecision(12);     cout << thead + ttail << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug = 1;   long long MOD = 1e9 + 7;   const int N = 2e5 + 10;   map<int, vector<int>> mpe, mps;   int nonred[N];   int n;   set<int> st;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       int l, r;       scanf( %d%d , &l, &r);       mpe[l].push_back(i + 1);       mps[r + 1].push_back(i + 1);       st.insert(l);       st.insert(r + 1);     }     set<int> at;     for (auto &tempo : st) {       for (auto &it : mpe[tempo]) {         at.insert(it);       }       for (auto &it : mps[tempo]) {         if (!nonred[it]) {           cout << it << endl;           return 0;         }         at.erase(it);       }       if (at.size() == 1) {         nonred[*at.begin()] = 1;       }     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, a = 0, b = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t;       if (t == 25)         a++;       else if (t == 50) {         b++;         a--;         if (a < 0 || b < 0) {           cout <<  NO  << endl;           return 0;         }       } else if (t == 100) {         if (b - 1 < 0) {           a -= 3;         } else {           b--;           a--;         }         if (a < 0) {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long key = 31;   const int MB = 1e5 + 5;   int n, m;   string s;   unsigned long long p[100008];   unsigned long long h[100008];   vector<int> v[100005];   vector<int> vv[100005];   int a[100005];   map<unsigned long long, int> pos;   string b[100005];   inline void build(int len) {     unsigned long long cur = 0;     for (int i = 0; i < v[len].size(); ++i) {       cur = 0;       for (int j = 0; j < len; ++j)         cur = (cur + (b[v[len][i]][j] -  a  + 1) * p[j + 1]);       cur = (cur * p[MB - 1]);       pos[cur] = v[len][i];     }     for (int i = 1; i <= n - len + 1; ++i) {       cur = h[i + len - 1] - h[i - 1];       cur *= p[MB - i];       if (pos.count(cur)) vv[pos[cur]].push_back(i);     }     pos.clear();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s;     n = s.size();     p[0] = 1;     for (int i = 1; i <= MB; ++i) p[i] = p[i - 1] * key;     for (int i = 1; i <= n; ++i) h[i] = h[i - 1] + (s[i - 1] -  a  + 1) * p[i];     cin >> m;     for (int i = 1; i <= m; ++i) {       cin >> a[i];       cin >> b[i];       v[b[i].size()].push_back(i);     }     for (int i = 1; i <= n; ++i)       if (v[i].size() > 0) {         build(i);       }     for (int i = 1; i <= m; ++i) {       if (vv[i].size() < a[i]) {         cout << -1 <<   n ;         continue;       }       int cur = n;       int z;       for (int j = a[i]; j <= vv[i].size(); ++j) {         z = vv[i][j - 1] - vv[i][j - a[i]] + b[i].size();         if (z < cur) cur = z;       }       cout << cur <<   n ;     }   }


#include <bits/stdc++.h>   long long dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};   long long dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};   using namespace std;   class pa3 {    public:     long long x;     long long y, z;     pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {}     bool operator<(const pa3 &p) const {       if (x != p.x) return x < p.x;       if (y != p.y) return y < p.y;       return z < p.z;     }     bool operator>(const pa3 &p) const {       if (x != p.x) return x > p.x;       if (y != p.y) return y > p.y;       return z > p.z;     }     bool operator==(const pa3 &p) const {       return x == p.x && y == p.y && z == p.z;     }     bool operator!=(const pa3 &p) const {       return !(x == p.x && y == p.y && z == p.z);     }   };   class pa4 {    public:     long long x;     long long y, z, w;     pa4(long long x = 0, long long y = 0, long long z = 0, long long w = 0)         : x(x), y(y), z(z), w(w) {}     bool operator<(const pa4 &p) const {       if (x != p.x) return x < p.x;       if (y != p.y) return y < p.y;       if (z != p.z) return z < p.z;       return w < p.w;     }     bool operator>(const pa4 &p) const {       if (x != p.x) return x > p.x;       if (y != p.y) return y > p.y;       if (z != p.z) return z > p.z;       return w > p.w;     }     bool operator==(const pa4 &p) const {       return x == p.x && y == p.y && z == p.z && w == p.w;     }   };   class pa2 {    public:     long long x, y;     pa2(long long x = 0, long long y = 0) : x(x), y(y) {}     pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); }     pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); }     bool operator<(const pa2 &p) const { return y != p.y ? y < p.y : x < p.x; }     bool operator>(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; }     bool operator==(const pa2 &p) const {       return abs(x - p.x) == 0 && abs(y - p.y) == 0;     }     bool operator!=(const pa2 &p) const {       return !(abs(x - p.x) == 0 && abs(y - p.y) == 0);     }   };   string itos(long long i) {     ostringstream s;     s << i;     return s.str();   }   long long gcd(long long v, long long b) {     if (v > b) return gcd(b, v);     if (v == b) return b;     if (b % v == 0) return v;     return gcd(v, b % v);   }   long long mod;   long long extgcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long d = extgcd(b, a % b, y, x);     y -= a / b * x;     return d;   }   pair<long long, long long> operator+(const pair<long long, long long> &l,                                        const pair<long long, long long> &r) {     return {l.first + r.first, l.second + r.second};   }   pair<long long, long long> operator-(const pair<long long, long long> &l,                                        const pair<long long, long long> &r) {     return {l.first - r.first, l.second - r.second};   }   long long pr[1000010];   long long inv[1000010];   long long beki(long long wa, long long rr, long long warukazu) {     if (rr == 0) return 1 % warukazu;     if (rr == 1) return wa % warukazu;     wa %= warukazu;     if (rr % 2 == 1)       return ((long long)beki(wa, rr - 1, warukazu) * (long long)wa) % warukazu;     long long zx = beki(wa, rr / 2, warukazu);     return (zx * zx) % warukazu;   }   long long comb(long long nn, long long rr) {     if (rr < 0 || rr > nn || nn < 0) return 0;     long long r = pr[nn] * inv[rr];     r %= mod;     r *= inv[nn - rr];     r %= mod;     return r;   }   void gya(long long ert) {     pr[0] = 1;     for (long long i = 1; i <= ert; i++) {       pr[i] = (pr[i - 1] * i) % mod;     }     inv[ert] = beki(pr[ert], mod - 2, mod);     for (long long i = ert - 1; i >= 0; i--) {       inv[i] = inv[i + 1] * (i + 1) % mod;     }   }   long long sita[1010];   long long oya[1010];   vector<long long> G[1010], H1[1010], H2[1010];   long long dfs1(long long r, long long p) {     oya[r] = p;     sita[r] = 1;     for (auto v : G[r])       if (v != p) {         sita[r] += dfs1(v, r);       }     return sita[r];   }   long long dep[1011];   void dfs2(long long r, long long p, long long d = 1) {     oya[r] = p;     dep[r] = d;     for (auto v : G[r])       if (v != p) {         dfs2(v, r, d + 1);         H1[r].push_back(v);       }   }   void dfs3(long long r, long long p, long long d = 1) {     oya[r] = p;     dep[r] = d;     for (auto v : G[r])       if (v != p) {         dfs3(v, r, d + 1);         H2[r].push_back(v);       }   }   long long dp[1010][1010];   long long mae[1010][1011];   long long wei[1010];   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long n;     cin >> n;     for (long long i = 0; i < n - 1; i++) {       long long y, yy;       cin >> y >> yy;       G[y].push_back(yy);       G[yy].push_back(y);     }     if (n == 1) {       return 0;     }     if (n == 2) {       cout <<  1 2 1  << endl;       return 0;     }     dfs1(1, 1);     long long root = -1;     for (long long i = 2; i <= n; i++) {       long long wa = n - 1;       bool ok = true;       for (auto v : G[i])         if (v != oya[i]) {           if (!(sita[v] <= n / 2)) ok = 0;           wa -= sita[v];         }       if (!ok) continue;       if (wa <= n / 2) root = i;     }     if (root == -1) root = 1;     dfs1(root, root);     vector<pair<long long, long long> > ve;     for (auto v : G[root]) ve.push_back({v, sita[v]});     long long m = ve.size();     dp[0][0] = 1;     mae[0][0] = -1;     for (long long i = 0; i < m; i++) {       for (long long j = 0; j <= n; j++)         if (dp[i][j]) {           dp[i + 1][j] = 1;           mae[i + 1][j] = mae[i][j];           dp[i + 1][j + ve[i].second] = 1;           mae[i + 1][j + ve[i].second] = i;         }     }     vector<long long> V1, V2;     for (long long j = n / 2; j >= 0; j--)       if (dp[m][j]) {         long long imaval = j;         long long imaind = m;         while (1) {           V1.push_back(ve[mae[imaind][imaval]].first);           long long ee = imaval;           imaval -= ve[mae[imaind][imaval]].second;           imaind = mae[imaind][ee];           if (mae[imaind][imaval] == -1) break;         }         break;       }     for (auto v : ve) {       bool bo = 0;       for (auto w : V1)         if (v.first == w) {           bo = 1;           break;         }       if (!bo) V2.push_back(v.first);     }     for (auto v : V1) dfs2(v, root), H1[root].push_back(v);     for (auto v : V2) dfs3(v, root), H2[root].push_back(v);     long long h1 = 0, h2 = 0;     for (long long i = 1; i <= n; i++) h1 += H1[i].size();     for (long long i = 1; i <= n; i++) h2 += H2[i].size();     assert(h1 + h2 == n - 1);     ve.clear();     for (long long i = 1; i <= n; i++)       for (auto v : H1[i]) ve.push_back({dep[v], v});     sort(ve.begin(), ve.end());     for (long long i = 0; i < ve.size(); i++) {       wei[ve[i].second] = (i + 1) * (h2 + 1);     }     ve.clear();     for (long long i = 1; i <= n; i++)       for (auto v : H2[i]) ve.push_back({dep[v], v});     sort(ve.begin(), ve.end());     for (long long i = 0; i < ve.size(); i++) {       wei[ve[i].second] = i + 1;     }     for (long long i = 1; i <= n; i++)       if (i != root) {         cout << i <<     << oya[i] <<     << wei[i] - wei[oya[i]] << endl;       }     for (long long i = 1; i <= n; i++)       if (i != root) {       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:16777216 )   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:16777216 )   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   const int inf = 2e9;   const long long linf = 5000000000000000000;   const long double LDINF = 2e18;   template <typename T>   void print(vector<T>& a) {     for (int i = 0; i < a.size(); i++) cout << a[i] <<    ;     cout <<   n ;   }   template <typename T>   void print(deque<T>& a) {     for (int i = 0; i < a.size(); i++) cout << a[i] <<    ;     cout <<   n ;   }   template <typename T>   void print(vector<vector<T>>& a) {     for (int i = 0; i < a.size(); i++) {       for (int j = 0; j < a[i].size(); j++) cout << a[i][j] <<    ;       cout <<   n ;     }   }   template <typename T>   void input(vector<T>& a) {     for (int i = 0; i < a.size(); i++) cin >> a[i];   }   template <typename T>   void input(deque<T>& a) {     for (int i = 0; i < a.size(); i++) cin >> a[i];   }   template <typename T>   void input(vector<vector<T>>& a) {     for (int i = 0; i < a.size(); i++)       for (int j = 0; j < a[i].size(); j++) cin >> a[i][j];   }   long long mod = 998244353;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   vector<int> p, rang;   void CreateSet(int v) {     p[v] = v;     rang[v] = 1;   }   int FindSet(int v) {     if (p[v] == v) return v;     return p[v] = FindSet(p[v]);   }   vector<pair<int, int>> ans;   void UnionSet(int a, int b) {     a = FindSet(a);     b = FindSet(b);     if (a == b) return;     if (rang[a] < rang[b]) swap(a, b);     p[b] = a;     if (rang[a] == rang[b]) rang[a]++;     ans.push_back({a, b});   }   void solve() {     long long n, d;     cin >> n;     long long a = 0, b = 0;     for (int i = 0; i < n; i++) {       cin >> d;       a |= d;     }     for (int i = 0; i < n; i++) {       cin >> d;       b |= d;     }     cout << a + b;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tst = 1;     while (tst--) solve();   }


#include <bits/stdc++.h>   struct Data {     std::vector<int> nums;     std::string str;   };   struct Interval {     int start;     int end;     std::string* data;   };   bool compareIntervals(const Interval& a, const Interval& b) {     if (a.start < b.start) return true;     if (a.start > b.start) return false;     return a.end < b.end;   }   int main() {     std::cin.tie(0);     std::ios_base::sync_with_stdio(0);     int numSteps;     std::cin >> numSteps;     size_t finalLength = 0;     std::vector<Data> steps(numSteps);     int numIntervals = 0;     for (int i = 0; i < steps.size(); ++i) {       std::cin >> steps[i].str;       int occurrences;       std::cin >> occurrences;       steps[i].nums.resize(occurrences);       numIntervals += occurrences;       for (int k = 0; k < occurrences; ++k) std::cin >> steps[i].nums[k];       finalLength =           std::max(finalLength, steps[i].nums.back() - 1 + steps[i].str.size());     }     std::vector<Interval> intervals(numIntervals);     int intervalsIdx = 0;     for (int i = 0; i < steps.size(); ++i) {       for (int j = 0; j < steps[i].nums.size(); ++j) {         Interval& curr = intervals[intervalsIdx];         curr.start = steps[i].nums[j] - 1;         curr.end = curr.start + steps[i].str.size();         curr.data = &steps[i].str;         ++intervalsIdx;       }     }     std::sort(intervals.begin(), intervals.end(), compareIntervals);     std::string out(finalLength,  a );     int doneIdx = 0;     for (int i = 0; i < intervals.size(); ++i) {       for (int idx = std::max(doneIdx, intervals[i].start);            idx < intervals[i].end; ++idx) {         out[idx] = (*intervals[i].data)[idx - intervals[i].start];       }       doneIdx = std::max(doneIdx, intervals[i].end);     }     std::cout << out <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<bool> isprime(1005, true);   vector<long long> spf(1005, 0);   vector<long long> prime;   void sieve() {     isprime[0] = isprime[1] = false;     for (long long i = 2; i < 1005; i++) {       if (isprime[i]) {         for (long long j = 2 * i; j < 1005; j += i) {           isprime[j] = false;           if (spf[j] == 0) {             spf[j] = i;           }         }         prime.push_back(i);       }     }   }   long long power(long long k, long long n, long long m = 1000000007) {     long long res = 1;     while (n) {       if (n % 2 != 0) {         res = (res * k) % m;       }       k = (k * k) % m;       n = n / 2;     }     return (res);   }   void READ(vector<long long> &v, long long n) {     long long a;     for (long long i = 0; i < n; i = i + 1) {       cin >> a;       v.push_back(a);     }   }   void PRINT(vector<long long> &v, long long a = 0) {     for (long long i = a; i < v.size(); i = i + 1) {       cout << v[i] <<    ;     }     cout <<   n ;   }   long long n, m, k;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     std::cout.unsetf(std::ios::floatfield);     std::cout.precision(12);     long long a, b, c, d, e, x, i, j, t, y, w, z, x1, y1, z1, f;     string str, str1, str2, str4;     cin >> n >> a >> b;     if (a * b >= 6 * n) {       cout << a * b <<   n  << a <<     << b;       exit(0);     }     x = y = 1e18;     d = 0;     for (j = 0;; j++) {       c = 0;       for (i = min(a, b); i * i <= 6 * n + j; i++) {         if ((6 * n + j) % i == 0) {           if (i >= a && (6 * n + j) / i >= b) {             x = i;             y = (6 * n + j) / i;             c = 1;             break;           }           if (i >= b && (6 * n + j) / i >= a &&               i - b + (6 * n + j) / i - a < x - a + y - b) {             y = i;             x = (6 * n + j) / i;             c = 1;             break;           }         }       }       if (c) {         break;       }     }     cout << x * y <<   n  << x <<     << y;   }


#include <bits/stdc++.h>   const double pi = 3.1415926535897932384626433832795;   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   using namespace std;   void ifd() {}   void tme() {}   int n, k, h;   vector<pair<int, pair<int, int> > > l;   vector<int> answer;   bool can(double time) {     int cnt = 0;     int pos = 0;     while (pos < n && cnt < k) {       if (((double)l[pos].second.first * time) >= ((double)(cnt + 1) * h)) {         pos++;         cnt++;       } else {         pos++;       }     }     return cnt == k;   }   double bs() {     double low = 0, high = 1e10, mid;     for (int i = (0); i < (200); ++i) {       mid = (low + high) / 2;       if (can(mid))         high = mid;       else         low = mid;     }     return high;   }   int main() {     ifd();     cin >> n >> k >> h;     l.resize(n);     for (int i = (0); i < (n); ++i) {       cin >> l[i].first;     }     for (int i = (0); i < (n); ++i) {       cin >> l[i].second.first;       l[i].second.second = i + 1;     }     sort(l.begin(), l.end());     double time = bs();     int cnt = 0;     int pos = 0;     while (pos < n && cnt < k) {       if (((double)l[pos].second.first * time) >= ((double)(cnt + 1) * h)) {         answer.push_back(l[pos].second.second);         pos++;         cnt++;       } else {         pos++;       }     }     for (int i = (0); i < (k - 1); ++i) cout << answer[i] <<    ;     cout << answer[k - 1] << endl;     tme();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 110;   const int INF = 1e9;   int _w;   int n, a[MAXN], b[MAXN];   namespace MCMF {   const int MAXV = 1000000;   const int MAXE = 1000000;   struct Edge {     int u, v, c, f, w;     Edge() {}     Edge(int u, int v, int c, int f, int w) : u(u), v(v), c(c), f(f), w(w) {}   };   int n, m, s, t;   int head[MAXV], nxt[MAXE << 1];   Edge edge[MAXE << 1];   void init(int nn) {     n = nn, m = 0;     for (int i = 1; i <= n; ++i) head[i] = -1;   }   void adde(int u, int v, int c, int w) {     edge[m] = Edge(u, v, c, 0, w);     nxt[m] = head[u], head[u] = m++;     edge[m] = Edge(v, u, 0, 0, -w);     nxt[m] = head[v], head[v] = m++;   }   queue<int> q;   int inq[MAXV], dis[MAXV], res[MAXV], pre[MAXV];   bool spfa() {     for (int i = 1; i <= n; ++i) inq[i] = 0, dis[i] = -INF;     q.push(s), inq[s] = 1, dis[s] = 0, res[s] = INF;     while (!q.empty()) {       int u = q.front();       q.pop();       inq[u] = 0;       for (int i = head[u]; ~i; i = nxt[i]) {         Edge &e = edge[i];         if (e.c > e.f && dis[e.v] < dis[u] + e.w) {           dis[e.v] = dis[u] + e.w;           res[e.v] = min(res[u], e.c - e.f);           pre[e.v] = i;           if (!inq[e.v]) {             inq[e.v] = 1;             q.push(e.v);           }         }       }     }     return dis[t] != -INF;   }   void augment() {     int u = t, f = res[t];     while (u != s) {       int i = pre[u];       edge[i].f += f;       edge[i ^ 1].f -= f;       u = edge[i].u;     }   }   int solve(int ss, int tt) {     s = ss, t = tt;     int ans = 0, flow = 0;     while (spfa()) {       augment();       ans += dis[t] * res[t];       flow += res[t];     }     return ans;   }   }  // namespace MCMF   int id1[27], id2[27][MAXN], id3[MAXN], s, t, nid;   void solve() {     for (int i = 1; i <= 26; ++i) id1[i] = ++nid;     for (int i = 1; i <= 26; ++i)       for (int j = 1; j <= n / 2; ++j) id2[i][j] = id2[i][n - j + 1] = ++nid;     for (int i = 1; i <= n; ++i) id3[i] = ++nid;     s = ++nid, t = ++nid;     MCMF::init(nid);     for (int i = 1; i <= n; ++i) MCMF::adde(s, id1[a[i]], 1, 0);     for (int i = 1; i <= 26; ++i)       for (int j = 1; j <= n / 2; ++j) MCMF::adde(id1[i], id2[i][j], 1, 0);     for (int i = 1; i <= 26; ++i)       for (int j = 1; j <= n; ++j)         MCMF::adde(id2[i][j], id3[j], 1, a[j] == i ? b[j] : 0);     for (int i = 1; i <= n; ++i) MCMF::adde(id3[i], t, 1, 0);     printf( %d n , MCMF::solve(s, t));   }   int main() {     _w = scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       char c;       _w = scanf(  %c , &c);       a[i] = c -  a  + 1;     }     for (int i = 1; i <= n; ++i) _w = scanf( %d , b + i);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef int *arrint;   const int maxn = 2e3 + 55;   int main() {     int h1, h2, a, b, i, j, k;     scanf( %d , &h1), scanf( %d , &h2);     scanf( %d , &a), scanf( %d , &b);     k = 0;     i = h1;     j = 1;     while (i < h2) {       if (j == 1) {         i = i + a * 8;         j = 0;         if (a <= b && i < h2) {           k = -1;           break;         }       } else {         i = i + a * 12;       }       if (i >= h2) {         break;       } else {         k++;         i -= b * 12;       }     }     printf( %d , k), printf( %c ,   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     long long n = s.length();     reverse(s.begin(), s.end());     set<string> ans;     vector<bool> dp2(n + 1, 0), dp3(n + 1, 0);     dp2[1] = 1;     dp3[2] = 1;     for (long long i = 3; i < n - 5; ++i) {       dp2[i] = dp3[i - 2] ||                (dp2[i - 2] && !(s[i] == s[i - 2] && s[i - 1] == s[i - 3]));       dp3[i] = dp3[i] || dp2[i - 3];       if (i - 5 >= 0)         dp3[i] =             dp3[i] || (dp3[i - 3] && !(s[i] == s[i - 3] && s[i - 1] == s[i - 4] &&                                        s[i - 2] == s[i - 5]));     }     for (long long i = 0; i < n - 5; ++i) {       if (dp2[i]) {         string temp = s.substr(i - 1, 2);         reverse(temp.begin(), temp.end());         ans.insert(temp);       }       if (dp3[i]) {         string temp = s.substr(i - 2, 3);         reverse(temp.begin(), temp.end());         ans.insert(temp);       }     }     cout << ans.size() <<   n ;     for (string i : ans) cout << i <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using ll = long long;   using namespace std;   const int N = 1e6 + 10;   const int Mod = 0;   ll a[N], sum[N], p[N];   int n, m, T, q;   int Read();   void update(ll x) {     vector<ll> v;     x--;     int cnt = 0;     if (n <= 14) {       for (int i = 1; i <= 14; i++) v.push_back(i);     } else {       for (int i = 1; i <= 14; i++) v.push_back(n - 14 + i);     }     for (int i = min(13, n - 1); i >= 0; i--) {       int j = x / p[i];       a[++cnt] = v[j];       x %= p[i];       v.erase(v.begin() + j);     }     int st = max(n - 13, 1);     for (int i = st, xx = 1; i <= n; i++, xx++) {       sum[i] = sum[i - 1] + a[xx];     }   }   int main() {     n = Read(), q = Read();     for (int i = 1; i <= n; ++i) {       a[i] = i;       sum[i] = sum[i - 1] + i;     }     p[0] = 1;     for (int i = 1; i <= 14; i++) p[i] = p[i - 1] * i;     ll now = 1;     for (int i = 1; i <= q; i++) {       int opt;       opt = Read();       if (opt == 1) {         int x = Read(), y = Read();         printf( %lld n , sum[y] - sum[x - 1]);       } else {         int x = Read();         now += x;         update(now);       }     }     return 0;   }   int Read() {     int val = 0, opt = 1;     char ch;     while (!isdigit(ch = getchar()))       if (ch ==  - ) opt = -1;     while (isdigit(ch)) (val *= 10) += ch -  0 , ch = getchar();     return val * opt;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     long long n, k;     cin >> n >> k;     string s;     long long lo = 1, hi = n;     while (1) {       long long mid = lo + hi >> 1;       if (hi - lo <= 50) {         long long guess = rng() % (hi - lo + 1) + lo;         cout << guess <<     << guess << endl;         cin >> s;         if (s ==  Yes ) exit(0);         lo = max(1ll, lo - k), hi = min(n, hi + k);         continue;       }       cout << lo <<     << mid << endl;       cin >> s;       if (s ==  Yes )         lo = max(lo - k, 1ll), hi = min(mid + k, n);       else         lo = max(mid - k, 1ll), hi = min(hi + k, n);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 50;   char s[N], t[N];   int n, a[N], b[N], c[N];   int main(void) {     scanf( %d , &n);     scanf( %s , s);     scanf( %s , t);     for (int i = 0; i < n; i++) {       a[i] = s[i] -  a ;       b[i] = t[i] -  a ;     }     for (int i = 0; i < n; i++) {       c[i] += (a[i] + b[i]) / 2;       if ((a[i] + b[i]) % 2) {         c[i + 1] += 13;       }     }     for (int i = n - 1; i >= 0; i--) {       c[i - 1] += c[i] / 26;       c[i] %= 26;     }     for (int i = 0; i < n; i++) {       printf( %c , (char)( a  + c[i]));     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j;     int dif;     int n, m;     bool ans = true;     char flag[100][101];     cin >> n >> m;     for (i = 0; i < n; i++) cin >> flag[i];     for (i = 0; i < n; i++) {       dif = flag[i][0];       for (j = 1; j < m; j++)         if (flag[i][j] != dif) ans = false;     }     for (i = 1; i < n - 1; i++)       for (j = 0; j < m; j++)         if (flag[i][j] == flag[i - 1][j] || flag[i][j] == flag[i + 1][j]) {           ans = false;           break;         }     if (ans)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long MOD = 1e9 + 7;   const int INF = 1e9;   const unsigned long long INF64 = 9e18;   const long double EPS = 1e-9;   const long double PI = 3.14159265358979310000;   const unsigned long long MD = 535355424;   const unsigned long long T = 25342;   const int N = 200001;   const int M = 501;   int n, k;   bool prov(unsigned long long v) {     unsigned long long s = 0, kk = 1;     while (v / kk > 0) {       s += v / kk;       kk *= k;     }     if (s >= n)       return 1;     else       return 0;   }   int main() {     cin >> n >> k;     if (k == 1) {       cout << 1 << endl;       return 0;     }     unsigned long long l, r, m;     l = 0;     r = INF64;     while (l + 1 < r) {       m = (l + r) / 2;       if (prov(m))         r = m;       else         l = m;     }     cout << r;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int arr[100010];   vector<int> v;   int main(void) {     int n, k, i, j, totalcnt;     scanf( %d %d , &n, &k);     for (i = 1; i <= n; i++) {       scanf( %d , &arr[i]);       v.push_back(arr[i]);       ;     }     if (k == 1) {       sort(v.begin(), v.end());       printf( 1 n );     } else {       int cnt = 0, sum = 0, mn = (1 << 29), indx, flag = 0;       totalcnt = 0;       for (i = 1; i <= n; i++) {         sum = 0;         cnt = 0;         for (j = i;; j += k) {           if (j > n) j %= n;           sum += arr[j];           totalcnt++;           cnt++;           if (cnt == (n / k)) {             break;           }         }         if (mn > sum) {           indx = i;           mn = sum;         }         if (totalcnt == n) break;       }       printf( %d n , indx);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int n;   int k;   map<int, int> mp;   int S;   long long res;   struct linetree {     map<int, int> rot;     int s[22 * N][2];     int v[22 * N];     int ct;     inline void ins(int p, int l, int r, int pos) {       v[p]++;       if (r - l == 1) {         return;       }       int mid = (l + r) / 2;       if (pos <= mid)         ins(s[p][0] = s[p][0] ? s[p][0] : ++ct, l, mid, pos);       else         ins(s[p][1] = s[p][1] ? s[p][1] : ++ct, mid, r, pos);     }     inline int qry(int p, int l, int r, int dl, int dr) {       if ((dl == l && dr == r) || p == 0) {         return v[p];       }       int mid = (l + r) / 2;       int res = 0;       if (dl < mid) res += qry(s[p][0], l, mid, dl, min(dr, mid));       if (mid < dr) res += qry(s[p][1], mid, r, max(dl, mid), dr);       return res;     }     inline void cins(int q, int x) {       if (rot.count(q) == 0) rot[q] = ++ct;       ins(rot[q], 0, S, x);     }     inline int cqr(int q, int dl, int dr) {       if (rot.count(q) == 0) return 0;       return qry(rot[q], 0, S, dl, dr);     }   } lt;   struct data {     int x;     int r;     int q;     friend bool operator<(data a, data b) { return a.r > b.r; }   } a[N];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d%d%d , &a[i].x, &a[i].r, &a[i].q);     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       mp[a[i].x] = 1;       mp[a[i].x + a[i].r] = 1;       mp[a[i].x - a[i].r] = 1;     }     map<int, int>::iterator it, it1;     for (it = mp.begin(), it1 = it, ++it1; it1 != mp.end(); ++it, ++it1)       it1->second += it->second;     S = mp.size();     for (int i = 1; i <= n; i++) {       for (int j = a[i].q - k; j <= a[i].q + k; j++)         res += lt.cqr(j, mp[a[i].x - a[i].r] - 1, mp[a[i].x + a[i].r]);       lt.cins(a[i].q, mp[a[i].x]);     }     printf( %I64d , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const int OO = INT_MAX, P = 10000;   int xd[] = {1, 0, -1, 0, -1, 1, 1, -1};   int yd[] = {0, -1, 0, 1, 1, 1, -1, -1};   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     long long int t;     cin >> t;     while (t--) {       long long int l, r;       cin >> l >> r;       if (l * 2 > r)         cout << -1 <<     << -1 <<   n ;       else         cout << l <<     << 2 * l <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> a(n + 1, 0), ans(n + 1, -1), visited(n + 1, 0);     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] > a[i - 1]) {         ans[i] = a[i - 1];         visited[a[i]] = 1;       }     }     int j = 1;     for (int i = 1; i <= n; i++) {       if (ans[i] == -1) {         while (j <= n && visited[j]) j++;         ans[i] = j;         visited[j] = 1;       }     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, a[1005], b[1005], c[1005], d[1005], ans, tot;   ;   char s[1005];   long long calc() {     long long cc = 0;     for (long long i = 1; i <= n; i++)       if (c[i]) {         ans += (c[i] - 1) * (m - c[i]) * 4;         for (long long j = i + 1; j <= n; j++)           if (!c[j] || c[j] < c[j - 1])             break;           else             cc += (c[i] - 1) * (m - c[j]) * 4;         for (long long j = i + 1; j <= n; j++)           if (!c[j] || c[j] > c[j - 1])             break;           else             cc += (c[j] - 1) * (m - c[i]) * 4;       }     return cc;   }   int main() {     scanf( %I64d%I64d , &n, &m);     for (long long i = 1; i <= n; i++) {       scanf( %s , s + 1);       for (long long j = 1; j <= m; j++)         if (s[j] ==  . )           tot++, a[i]++, b[j]++;         else           c[i] = j, d[j] = i;     }     long long o, ct, su;     o = ct = su = 0;     for (long long i = 1; i <= n; i++) o += su * a[i], ct += a[i], su += ct;     ans = o * 2;     o = ct = su = 0;     for (long long i = 1; i <= m; i++) o += su * b[i], ct += b[i], su += ct;     ans += o * 2;     ans += calc();     swap(n, m);     for (long long i = 1; i <= n; i++) c[i] = d[i];     ans += calc();     printf( %.16lf , ((double)ans) / tot / tot);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v;     int n, i, j, k, value;     cin >> n;     int x = n;     while (x--) {       cin >> value;       v.push_back(value);     }     for (i = 0; i < n; i++)       for (j = 0; j < n; j++) {         if (i == j) j++;         for (k = j + 1; k <= n - 1; k++) {           if (k == i) k++;           if (k == n) break;           if (v[i] == v[j] + v[k]) {             cout << i + 1 <<     << k + 1 <<     << j + 1;             return 0;           }         }       }     cout <<  -1 ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     int ans = 0;     int n = s.length();     for (int i = 0; i < n; i++) {       if (s[i] != s[n - i - 1]) {         ans = -1;         break;       }     }     if (ans != -1)       cout << 0 << endl;     else {       cout << 3 << endl;       cout <<  R   << 2 << endl;       cout <<  L   << s.length() << endl;       cout <<  L   << s.length() - 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   string second, pre, suf;   int main() {     ios::sync_with_stdio(false);     cin >> second;     int n = (int)second.size();     int l = 0;     int r = n - 1;     while (l + 1 < r - 1) {       if (second[l] == second[r]) {         pre += second[l];         suf += second[r];       } else {         if (second[l] == second[r - 1])           pre += second[l], suf += second[r - 1];         else if (second[l + 1] == second[r])           pre += second[l + 1], suf += second[r];         else           pre += second[l + 1], suf += second[r - 1];       }       l += 2;       r -= 2;     }     if (n % 4 != 0) {       pre += second[n / 2];     }     reverse(suf.begin(), suf.end());     pre = pre + suf;     cout << pre;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 1e6 + 42;   int k;   int f[6];   long long dp[MX];   long long eval(int val) {     long long ret = 0;     for (int dig = 0; dig < 6; dig++) {       int d = val % 10;       if (d % 3 == 0) ret = ret + 1LL * d / 3 * f[dig];       val = val / 10;     }     return ret;   }   void push(long long object, long long gain) {     if (object >= MX) return;     for (int i = MX - 1; i >= object; i--)       dp[i] = max(dp[i], dp[i - object] + gain);   }   void prec() {     for (int i = 0; i < MX; i++) dp[i] = -1e18;     dp[0] = 0;     for (int dig = 0; dig < 6; dig++) {       int mult = 1;       for (int t = 0; t < dig; t++) mult = mult * 10;       mult = mult * 3;       long long remain = 3 * (k - 1), object = mult, gain = f[dig];       while (remain) {         if (remain % 2 == 0) {           push(object, gain);           remain--;         }         if (remain % 2 == 1) {           push(object, gain);           remain--;         }         object = object * 2;         gain = gain * 2;         remain = remain / 2;       }     }   }   long long solve(int cur) {     long long ret = 0;     for (int i = 0; i <= cur; i++) ret = max(ret, dp[i] + eval(cur - i));     return ret;   }   int main() {     scanf( %i , &k);     for (int i = 0; i < 6; i++) scanf( %i , &f[i]);     prec();     int q;     scanf( %i , &q);     for (int i = 1; i <= q; i++) {       int val;       scanf( %i , &val);       printf( %lld n , solve(val));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int logx = 30;   const long long int N = 1e6 + 5;   const long long int INF = 1e18 + 5;   const long long int mod = 321555123;   const double PI = 3.14159265358979323846;   inline long long int mul(long long int a, long long int b) {     return (a * 1ll * b) % mod;   }   inline long long int sub(long long int a, long long int b) {     long long int c = a - b;     if (c < 0) c += mod;     return c;   }   inline long long int add(long long int a, long long int b) {     long long int c = a + b;     if (c > mod) c -= mod;     return c;   }   template <typename T>   T power(T x, T y, long long int m) {     T ans = 1;     while (y > 0) {       if (y & 1LL) ans = (ans * x) % m;       y >>= 1ll;       x = (x * x) % m;     }     return ans % m;   }   vector<long long int> bit[N];   long long int n, q, a[N], b[N];   void Update(long long int idx, long long int val) {     idx++;     while (idx <= n) {       bit[idx].push_back(val);       idx += (idx & -idx);     }   }   long long int Query(long long int idx, long long int val) {     long long int sum = 0;     idx++;     while (idx > 0) {       long long int lb =           lower_bound(bit[idx].begin(), bit[idx].end(), val) - bit[idx].begin();       sum += lb;       idx -= (idx & -idx);     }     return sum;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     cin >> n;     long long int sum = 0;     map<long long int, long long int> first;     for (long long int i = 0; i < n; i++) {       cin >> a[i];     }     for (long long int i = n - 1; i >= 0; i--) {       first[a[i]]++;       b[i] = first[a[i]];     }     for (long long int i = 0; i < n; i++) {       Update(i, b[i]);     }     for (long long int i = 1; i <= n + 1; i++) {       sort(bit[i].begin(), bit[i].end());     }     first.clear();     for (long long int i = 0; i < n; i++) {       long long int l = i + 1;       long long int r = n - 1;       first[a[i]]++;       sum += Query(r, first[a[i]]) - Query(l - 1, first[a[i]]);     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 50100;   int n, l[MAXN], p[MAXN], idx[MAXN];   double ev[MAXN], el[MAXN];   int idxCMP(int i, int j) {     return p[i] * l[i] * (100 - p[j]) > p[j] * l[j] * (100 - p[i]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> l[i] >> p[i];       idx[i] = i;     }     sort(idx, idx + n, idxCMP);     for (int i = 1; i <= n; i++) {       ev[i] =           ev[i - 1] + (el[i - 1] * (100 - p[idx[i - 1]]) / 100.0) + l[idx[i - 1]];       el[i] = el[i - 1] + l[idx[i - 1]] * p[idx[i - 1]] / 100.0;     }     cout << fixed << setprecision(10) << ev[n] << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct segtree {     vector<vector<int>> t;     vector<int> d;     int h, n, sz;     inline void build_node(const int& x) {       for (int j = 0; j < 26; ++j) {         t[x][j] = t[x << 1][j] + t[x << 1 | 1][j];       }     }     inline void build(int x) {       for (x /= 2; x > 0; x /= 2) {         build_node(x);       }     }     segtree(const string& s) {       sz = s.size();       h = sizeof(int) * 8 - __builtin_clz(sz);       n = 1 << h;       d = vector<int>(n << 1, 0);       t = vector<vector<int>>(n << 1, vector<int>(26, 0));       for (int i = 0; i < sz; ++i) {         ++t[i + n][s[i] -  a ];       }       for (int i = n - 1; i > 0; --i) {         build_node(i);       }     }     void apply(int x, int v) {       if (x < n) {         d[x] = v;       }     }     void fill_nodes(const vector<int>& ind, vector<int> char_count, int dir) {       for (const int& x : ind) {         for (int i = 0; i < 26; ++i) {           t[x][i] = 0;         }       }       int ch_type = (dir == 1 ? 0 : 25);       for (int i = (dir == 1 ? 0 : 0); i < ind.size(); ++i) {         int x = ind[i];         int my_sz = 1 << (h - (sizeof(int) * 8 - __builtin_clz(x)) + 1);         int have = 0;         for (; have < my_sz; (dir == 1 ? ++ch_type : --ch_type)) {           int take = min(my_sz - have, char_count[ch_type]);           t[x][ch_type] += take;           char_count[ch_type] -= take;           have += take;           if (have == my_sz) break;         }       }     }     void sort_nodes(const vector<int>& ind, int dir) {       vector<int> char_count(26, 0);       for (const int& x : ind) {         for (int i = 0; i < 26; ++i) {           char_count[i] += t[x][i];         }       }       fill_nodes(ind, char_count, dir);     }     void push_node(int x) {       if (d[x] != 0) {         fill_nodes(vector<int>({x << 1, x << 1 | 1}), t[x], d[x]);         apply(x << 1, d[x]);         apply(x << 1 | 1, d[x]);         d[x] = 0;       }     }     void push(int x) {       for (int s = h; s > 0; --s) {         int i = x >> s;         if (d[i] != 0) {           push_node(i);         }       }     }     void set(int l, int r, int dir) {       int l0 = l + n;       int r0 = r + n;       push(l0);       push(r0 - 1);       vector<int> front, back;       for (l += n, r += n; l < r; l /= 2, r /= 2) {         if (l % 2) {           front.push_back(l);           apply(l, dir);           ++l;         }         if (r % 2) {           --r;           back.push_back(r);           apply(r, dir);         }       }       reverse(back.begin(), back.end());       front.insert(front.end(), back.begin(), back.end());       sort_nodes(front, dir);       push(l0);       push(r0 - 1);       build(l0);       build(r0 - 1);     }     string to_string() {       for (int i = 1; i < n; ++i) {         push_node(i);       }       static char cstr[100010];       for (int i = 0; i < sz; ++i) {         for (int j = 0; j < 26; ++j) {           if (t[i + n][j] != 0) {             cstr[i] = j +  a ;           }         }       }       cstr[sz] = 0;       return string(cstr);     }   };   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int N, Q;     cin >> N >> Q;     string s;     cin >> s;     segtree st(s);     for (int qq = 0; qq < Q; ++qq) {       int i, j, k;       cin >> i >> j >> k;       st.set(i - 1, j, (k == 1 ? 1 : -1));     }     cout << st.to_string() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int id, k;   };   const int N = 2e5 + 10;   int a[N];   int C[N];   Node b[N];   int n;   int lowbit(int x) { return (x & -x); }   int sum(int x) {     int ret = 0;     while (x > 0) {       ret += C[x];       x -= lowbit(x);     }     return ret;   }   void add(int x, int d) {     while (x <= n) {       C[x] += d;       x += lowbit(x);     }   }   bool cmp(const Node& x, const Node& y) {     if (x.k == y.k) return x.id < y.id;     return x.k < y.k;   }   int main() {     long long tot;     int p;     scanf( %d , &n);     memset(C, 0, sizeof(C));     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     if (n == 1) {       printf( 0 n );       return 0;     }     for (int i = 2; i <= n; i++) {       b[i].k = min(a[i], i - 1);       b[i].id = i;     }     sort(b + 2, b + n + 1, cmp);     p = 2;     tot = 0;     for (int i = 1; i <= n; i++) {       if (a[i] > i) {         add(i + 1, 1);         add(min(a[i], n) + 1, -1);       }       while (p <= n && b[p].k == i) {         tot += sum(b[p].id);         p++;       }       if (p > n) break;     }     printf( %I64d n , tot);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<long long int, long long int> p[300002];   int see(long long int a, long long int b, long long int c) {     for (long long int i = 0; i < c; i++) {       if (p[i].first == a || p[i].first == b || p[i].second == a ||           p[i].second == b)         continue;       if (b == -1)         return see(a, p[i].first, c) || see(a, p[i].second, c);       else         return 0;     }     return 1;   }   int main() {     long long int n, m, i;     cin >> n >> m;     for (i = 0; i < m; i++) cin >> p[i].first >> p[i].second;     if (see(p[0].first, -1, m) || see(p[0].second, -1, m))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int num = 0;   int main() {     cin >> n;     int pre[n + 1];     pre[0] = 0;     vector<int> all;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       pre[i + 1] = pre[i] + a;     }     for (int i = 1; i <= n; i++) {       for (int k = 0; k < i; k++) {         all.push_back(pre[i] - pre[k]);       }     }     vector<pair<int, int>> op;     for (auto i : all) {       int cnt = 0;       vector<pair<int, int>> top;       for (int k = 0; k < n;) {         map<int, int> m;         m.insert(make_pair(pre[k], k));         bool findone = false;         while (!findone && k < n) {           int t = pre[k + 1] - i;           if (m.count(t)) {             findone = true;             cnt++;             top.push_back(make_pair(k + 1, m[t] + 1));           }           m.insert(make_pair(pre[k + 1], k + 1));           k++;         }       }       if (cnt > num) {         num = cnt;         op = top;       }     }     cout << num << endl;     for (auto v : op) cout << v.second <<     << v.first << endl;   }


#include <bits/stdc++.h>   int N, XL, XR, YL, YR, SX, SY, VX, VY;   long long LN, LD = 1, RN = 1000000000000LL, RD = 1;   inline bool cmp(long long a, long long b, long long c, long long d) {     return a * d < b * c;   }   void LIM(int v, int s, int l, int r) {     if (v == 0) {       if (s <= l || s >= r) {         puts( -1 );         exit(0);       }     } else {       l -= s;       r -= s;       if (v < 0) {         int tmp = l;         l = r;         r = tmp;         l = -l;         r = -r;         v = -v;       }       if (cmp(LN, LD, l, v)) {         LN = l;         LD = v;       }       if (cmp(r, v, RN, RD)) {         RN = r;         RD = v;       }     }   }   int main() {     for (scanf( %d%d%d%d%d , &N, &XL, &YL, &XR, &YR); N--;) {       scanf( %d%d%d%d , &SX, &SY, &VX, &VY);       LIM(VX, SX, XL, XR);       LIM(VY, SY, YL, YR);     }     if (cmp(LN, LD, RN, RD))       printf( %.12f n , (double)LN / LD);     else       puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long f[200200], sum[200200];   long long n;   void init() {     f[0] = 1LL;     for (int i = 1; i <= n; i++) f[i] = f[i - 1] * 10LL % 998244353;     return;   }   void solve() {     for (long long i = 1; i <= n; i++) {       long long ans = 0;       if (i == n)         ans = 10;       else if (i == n - 1)         ans = 180;       else {         ans += (10LL * 9LL * 9LL * (n - i - 1) * f[n - i - 2]) % 998244353;         ans += (10LL * 9LL * 2LL * f[n - i - 1]) % 998244353;         ans %= 998244353;       }       printf( %lld  , ans);       if (i != n) printf(   );     }     return;   }   int main() {     scanf( %lld , &n);     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T1>   void deb(T1 e) {     cout << e << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   template <class T>   T Abs(T x) {     return x > 0 ? x : -x;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   long long Pow(long long B, long long P) {     long long R = 1;     while (P > 0) {       if (P % 2 == 1) R = (R * B);       P /= 2;       B = (B * B);     }     return R;   }   long long BigMod(long long B, long long P, long long M) {     long long R = 1;     while (P > 0) {       if (P % 2 == 1) {         R = (R * B) % M;       }       P /= 2;       B = (B * B) % M;     }     return R;   }   long long n, m;   vector<pair<long long, long long> > v;   long long mod = 1000000007LL;   long long stree[4 * 200050];   map<long long, int> M;   set<long long> S;   void update(int node, int left, int right, int pos, long long val) {     if (pos < left || right < pos) return;     if (left == right) {       stree[node] = val;       return;     }     int mid = (left + right) / 2;     update(node * 2, left, mid, pos, val);     update(node * 2 + 1, mid + 1, right, pos, val);     stree[node] = stree[node * 2] % mod + stree[node * 2 + 1] % mod;     return;   }   long long query(int node, int left, int right, int srch_l, int srch_r) {     if (srch_l <= left && right <= srch_r) return stree[node];     if (right < srch_l || left > srch_r) return 0;     int mid = (left + right) / 2;     long long ret1 = query(node * 2, left, mid, srch_l, srch_r);     ret1 %= mod;     long long ret2 = query(node * 2 + 1, mid + 1, right, srch_l, srch_r);     ret2 %= mod;     long long ret = (ret1 + ret2) % mod;     return ret;   }   vector<int> adj[200050];   int main(void) {     long long a, b;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b, v.push_back(make_pair(a, b));       S.insert(a);       S.insert(b);     }     S.insert(0);     S.insert(n);     int track = 0;     for (__typeof((S).begin()) it = (S.begin()); it != (S).end(); ++it)       M[*it] = track++;     n = (int)M.size() - 1;     update(1, 0, n, 0, 1);     for (int i = 0; i < (int)v.size(); i++) {       long long right = v[i].second;       right = M[right];       adj[right].push_back(i);     }     for (int i = 1; i < (int)M.size(); i++) {       long long val = 0;       for (int j = 0; j < (int)adj[i].size(); j++) {         int indx = adj[i][j];         int left = v[indx].first;         int right = v[indx].second;         left = M[left];         right = M[right];         val += query(1, 0, n, left, right);         val %= mod;       }       update(1, 0, n, i, val);     }     deb(query(1, 0, n, n, n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int a[n * k], c = 0;       for (long long int i = 0; i < n * k; i++) {         cin >> a[i];       }       long long int m = (ceil)((double)n / 2);       for (long long int i = (m - 1) * k; i < n * k; i += n - m + 1) {         c += a[i];       }       cout << c << endl;     }     return 0;   }


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