#include <bits/stdc++.h>   using namespace std;   long long int n;   set<long long int> nos;   long long powmod(long long x, long long y, long long m) {     long long res = 1LL;     while (y) {       if (y & 1) res = (res * x) % m;       x = (x * x) % m;       y /= 2;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     long long int ans = 1;     long long int buyt = 0;     long long int selt = INT64_MAX;     for (long long int i = 1; i <= n; i++) {       string s;       long long int val;       cin >> s >> val;       if (s ==  ADD )         nos.insert(val);       else {         nos.erase(val);         if (buyt < val && selt > val)           ans = (ans * 2) % 1000000007;         else if (buyt == val || selt == val)           ans = (ans * 1) % 1000000007;         else           ans = 0;         auto it = nos.upper_bound(val);         auto it1 = nos.lower_bound(val);         if (it != nos.end())           selt = *it;         else           selt = INT64_MAX;         if (it1 != nos.begin()) {           it1--;           buyt = *it1;         } else {           buyt = 0;         }       }     }     long long int m = 0;     for (auto it = nos.begin(); it != nos.end(); it++) {       long long int temp = *it;       if (temp > buyt && temp < selt) m++;     }     ans = (ans * (m + 1)) % 1000000007;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> cri[100100], notcri[100100];   int totalnot = 0;   int crinum[100100] = {}, notcrinum[100100] = {};   bool cand[100100];   int candnum = 0;   int claim[100100];   int main() {     int N, M;     scanf( %d%d , &N, &M);     for (int i = 1; i <= N; i++) {       scanf( %d , claim + i);       int num = claim[i];       if (num > 0) {         cri[num].push_back(i);         crinum[num]++;       } else {         notcri[-num].push_back(i);         notcrinum[-num]++;         totalnot++;       }     }     for (int c = 1; c <= N; c++) {       int lie = crinum[c] + totalnot - notcrinum[c];       if (lie != M) {         cand[c] = false;         continue;       }       cand[c] = true;       candnum++;     }     if (candnum == 1) {       int criminal;       for (int i = 1; i <= N; i++)         if (cand[i] == true) criminal = i;       for (int i = 1; i <= N; i++) {         if (claim[i] > 0 && claim[i] == criminal)           printf( Truth n );         else if (claim[i] > 0)           printf( Lie n );         if (claim[i] < 0 && claim[i] == -criminal)           printf( Lie n );         else if (claim[i] < 0)           printf( Truth n );       }     } else {       for (int i = 1; i <= N; i++) {         if (claim[i] > 0) {           if (cand[claim[i]] == false)             printf( Lie n );           else             printf( Not defined n );         } else {           if (cand[-claim[i]] == false)             printf( Truth n );           else             printf( Not defined n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1000000007;   const double pi = 3.141592653589793238463;   bool vow(char ch) {     return ch ==  a  || ch ==  e  || ch ==  i  || ch ==  o  || ch ==  u ;   }   bool isPrime(long long n) {     for (long long i = 2; i * i <= n; i++)       if (n % i == 0) return false;     return true;   }   long long fast_exp(long long x, long long n) {     long long ans = 1;     while (n) {       if (n & 1) {         ans *= x;         ans %= M;       }       n = n >> 1;       x = (x * x) % M;     }     return ans;   }   long long inverse(long long x) { return fast_exp(x, M - 2); }   long long comb(long long n, long long r) {     if (r == 0)       return 1;     else {       long long ans = n % M;       ans *= comb(n - 1, r - 1) % M;       ans %= M;       ans *= inverse(r) % M;       ans %= M;       return ans;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, m, k;     cin >> n >> m >> k;     cout << (comb(n - 1, 2 * k) % M * comb(m - 1, 2 * k) % M) % M;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   int l3, l4, l5;   double calc3(double r) {     double x = r / 2;     double y = r / 6 * sqrt(3);     double z = sqrt(r * r - x * x - y * y);     double ret = z * r * r / 12 * sqrt(3);     return ret;   }   double calc4(double r) {     double x = r / 2;     double y = r / 2;     double z = sqrt(r * r - x * x - y * y);     double ret = z * r * r / 3;     return ret;   }   double calc5(double r) {     double x = r / 2;     double y = r / 2 * (sqrt(5) + 1) / sqrt(10 - 2 * sqrt(5));     double z = sqrt(r * r - x * x - y * y);     double ret = z * r * r * 5 / 4 / sqrt(5 - sqrt(20)) / 3;     return ret;   }   void run() {     scanf( %d%d%d , &l3, &l4, &l5);     printf( %.12lf n , calc3(l3) + calc4(l4) + calc5(l5));   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 4;   string s, des[3];   int n, q, next_occur[26][MAX], dp[255][255][255];   void makeNO() {     for (int j = 0; j < 26; j++) next_occur[j][n + 1] = next_occur[j][n] = n;     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j < 26; j++) {         next_occur[j][i] = (s[i] -  a  == j ? i : next_occur[j][i + 1]);       }     }   }   void makeDp(int a, int b, int c) {     int& val = dp[a][b][c];     val = n;     if (a) val = min(val, next_occur[des[0][a - 1] -  a ][dp[a - 1][b][c] + 1]);     if (b) val = min(val, next_occur[des[1][b - 1] -  a ][dp[a][b - 1][c] + 1]);     if (c) val = min(val, next_occur[des[2][c - 1] -  a ][dp[a][b][c - 1] + 1]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     ;     cin >> n >> q >> s;     makeNO();     dp[0][0][0] = -1;     while (q--) {       char o, c;       int rel_id;       cin >> o >> rel_id;       rel_id--;       if (o ==  + ) {         cin >> c;         des[rel_id] += c;         int max0 = des[0].size(), max1 = des[1].size(), max2 = des[2].size();         int min0 = rel_id == 0 ? max0 : 0;         int min1 = rel_id == 1 ? max1 : 0;         int min2 = rel_id == 2 ? max2 : 0;         for (int b = min1; b <= max1; b++)           for (int a = min0; a <= max0; a++)             for (int c = min2; c <= max2; c++) makeDp(a, b, c);       } else {         des[rel_id].pop_back();       }       bool answer = dp[des[0].size()][des[1].size()][des[2].size()] < n;       cout << (answer ?  YES n  :  NO n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       vector<int> s[k];       for (int i = 0; i < k; ++i) {         int c;         cin >> c;         for (int j = 0; j < c; ++j) {           int p;           cin >> p;           s[i].push_back(p);         }       }       cout <<  ?   << n <<    ;       for (int i = 1; i <= n; i++) cout << i <<    ;       cout <<   n ;       int max;       cin >> max;       int l = 1, r = n;       while (l < r) {         int mid = (l + r) / 2;         cout <<  ?   << mid - l + 1 <<    ;         for (int i = l; i <= mid; i++) cout << i <<    ;         cout <<   n ;         int temp;         cin >> temp;         if (temp == max)           r = mid;         else           l = mid + 1;       }       int sind = 0;       for (int i = 0; i < k; ++i) {         for (int j : s[i]) {           if (j == l) {             sind = i;             break;           }         }       }       int smax;       cout <<  ?   << n - s[sind].size() <<    ;       for (int i = 1; i <= n; i++) {         bool flag = true;         for (int j : s[sind])           if (j == i) flag = false;         if (flag) cout << i <<    ;       }       cout <<   n ;       cin >> smax;       cout <<  !  ;       for (int i = 0; i < k; i++) {         if (i == sind)           cout << smax <<    ;         else           cout << max <<    ;       }       cout <<   n ;       string x;       cin >> x;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 10;   struct fridge {     int w, id;   } f[maxn];   struct edge {     int u, v;   } e[maxn];   bool cmp(fridge a, fridge b) { return a.w < b.w; }   int n, m, a[maxn], ans, fd[maxn];   int main() {     int t;     cin >> t;     while (t--) {       ans = 0;       cin >> n >> m;       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);         ans += a[i];       }       if (m < n || n == 2) {         printf( -1 n );         continue;       }       cout << ans * 2 << endl;       for (int i = 1; i < n; i++) {         printf( %d %d n , i, i + 1);       }       printf( %d %d n , n, 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MX = 1e5 + 9;   long long par[MX], num[MX];   void MS(long long v) { par[v] = v, num[v] = 1; }   long long FS(long long v) {     if (par[v] == v) return v;     return par[v] = FS(par[v]);   }   void US(long long a, long long b) {     a = FS(a), b = FS(b);     if (a == b) return;     if (num[a] < num[b]) swap(a, b);     par[b] = a;     num[a] += num[b];   }   bool lucky(string s) {     for (long long i = 0; i < s.size(); i++)       if (s[i] !=  4  && s[i] !=  7 ) return 0;     return 1;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) MS(i);     for (long long i = 1; i < n; i++) {       long long u, v;       string s;       cin >> u >> v >> s;       if (!lucky(s)) US(u, v);     }     long long ans = 0;     for (long long i = 1; i <= n; i++) {       long long sz = n - num[FS(i)];       ans += sz * (sz - 1);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     long long int k = 1, ans = 1;     cin >> n >> m;     for (int i = 0; i < m; i++) {       k *= 2;       k = k % 1000000009;     }     for (int i = 1; i <= n; i++) {       ans *= (k - i);       ans = ans % 1000000009;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<string, vector<string> > mp;     vector<string> v;     string pat;     cin >> pat;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string tx;       cin >> tx;       v.push_back(tx);     }     sort(v.begin(), v.end());     for (int i = 0; i < n; i++) {       for (int j = 0; j < v[i].length(); j++) {         string pr = v[i].substr(0, j + 1);         mp[pr].push_back(v[i]);       }     }     map<string, vector<string> >::iterator itr = mp.begin();     {       if (mp.find(pat) != mp.end()) {         cout << mp[pat][0] << endl;       } else {         cout << pat << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   int p[100005];   int main(void) {     int n, m, i, x;     scanf( %d%d , &m, &n);     for (i = 1; i <= n; i++) {       scanf( %d , &x);       x %= m;       if (p[x] == 0)         p[x] = 1;       else {         printf( %d n , i);         return 0;       }     }     return 0 * printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     map<string, string> mp;     for (int i = 0; i < m; i++) {       string s1, s2;       cin >> s1 >> s2;       if (s2.size() < s1.size())         mp[s1] = s2;       else         mp[s1] = s1;     }     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (auto it = mp.begin(); it != mp.end(); it++) {         if (it->first == s) {           cout << it->second <<    ;           break;         }       }     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3fll;   struct Shuffle {     vector<int> S;     Shuffle() {}     Shuffle(int len) {       S.resize(len);       iota((S).begin(), (S).end(), 0);     }     friend inline Shuffle operator*(const Shuffle &a, const Shuffle &b) {       static Shuffle res;       res = Shuffle(((int)(a.S).size()));       for (int i = 0; i < (((int)(a.S).size())); ++i) {         res.S[i] = b.S[a.S[i]];       }       return res;     }   };   int n, m;   char s[1 << 20], t[1 << 20];   int main() {     scanf( %s , s);     n = strlen(s);     scanf( %d , &m);     for (int i = 1; i <= (m); ++i) {       int k, d;       scanf( %d%d , &k, &d);       Shuffle a(n), b(n);       for (int j = 0; j < (n); ++j) a.S[j] = (j + n - 1) % n;       vector<vector<int> > ms(d);       for (int j = 0; j < (k); ++j) ms[j % d].push_back(j);       int cnt = 0;       for (int j = 0; j < (d); ++j)         for (int k = 0; k < (((int)(ms[j]).size())); ++k) {           b.S[ms[j][k]] = cnt++;         }       a = b * a;       b = Shuffle(n);       int tms = n - k + 1;       while (tms) {         if (tms & 1) b = b * a;         tms >>= 1;         a = a * a;       }       for (int j = 0; j < (n); ++j) t[b.S[j]] = s[j];       for (int j = 0; j < (n); ++j) s[j] = t[(j + k - 1) % n];       printf( %s n , s);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool major, minor;   map<string, int> P;   string x, y, z;   int k1, k2;   void go(string x, string y, string z) {     if (P[x] <= P[y])       k1 = P[y] - P[x];     else       k1 = 12 - P[x] + P[y];     if (P[y] <= P[z])       k2 = P[z] - P[y];     else       k2 = 12 - P[y] + P[z];     if (k1 == 4 && k2 == 3)       major = true;     else if (k1 == 3 && k2 == 4)       minor = true;   }   int main(int argc, char *argv[]) {     P[ C ] = 1;     P[ C# ] = 2;     P[ D ] = 3;     P[ D# ] = 4;     P[ E ] = 5;     P[ F ] = 6;     P[ F# ] = 7;     P[ G ] = 8;     P[ G# ] = 9;     P[ A ] = 10;     P[ B ] = 11;     P[ H ] = 12;     major = false;     minor = false;     cin >> x >> y >> z;     go(x, y, z);     go(x, z, y);     go(y, x, z);     go(y, z, x);     go(z, x, y);     go(z, y, x);     if (major)       cout <<  major  << endl;     else if (minor)       cout <<  minor  << endl;     else       cout <<  strange  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   vector<int> p, q;   vector<char> d;   int main() {     cin >> n >> k;     p.resize(n);     q.resize(n);     d.resize(n);     for (int i = 0; i < n; i++) {       cin >> d[i] >> p[i] >> q[i];     }     map<int, int> b, s;     for (int i = 0; i < n; i++) {       if (d[i] ==  S ) {         if (s.find(p[i]) == s.end())           s[p[i]] = q[i];         else           s[p[i]] += q[i];       } else {         if (b.find(-p[i]) == b.end())           b[-p[i]] = q[i];         else           b[-p[i]] += q[i];       }     }     int cnt = s.size();     for (map<int, int>::reverse_iterator it = s.rbegin(); it != s.rend(); it++) {       if (cnt <= k) {         cout <<  S   << it->first <<     << it->second <<   n ;       }       cnt--;     }     cnt = 0;     for (map<int, int>::iterator it = b.begin(); it != b.end(); it++) {       if (cnt < k) {         cout <<  B   << -it->first <<     << it->second <<   n ;       } else         break;       cnt++;     }     cin >> n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   struct node {     T sum, val;     int prior, cnt;     node *l, *r;     node() {       cnt = 1;       prior = (rand() << 16) + rand();       l = r = NULL;     }   };   template <class T>   class treap {     node<T> *root;     inline T getsum(node<T> *v) {       if (v)         return v->sum;       else         return *(new T);     }     inline int getcnt(node<T> *v) {       if (v)         return v->cnt;       else         return 0;     }     inline void upd(node<T> *v) {       if (!v) return;       v->sum = getsum(v->l) + getsum(v->r) + v->val;       v->cnt = getcnt(v->l) + getcnt(v->r) + 1;     }     node<T> *merge(node<T> *v1, node<T> *v2) {       if (!v1)         return v2;       else if (!v2)         return v1;       if (!(v1->val < v2->val)) swap(v1, v2);       if (v1->prior > v2->prior) {         v1->r = merge(v1->r, v2);         upd(v1);         return v1;       } else {         v2->l = merge(v1, v2->l);         upd(v2);         return v2;       }     }     void split(T x, node<T> *tree, node<T> *&l, node<T> *&r) {       if (!tree) {         l = NULL, r = NULL;         return;       } else {         if (tree->val < x) {           split(x, tree->r, l, r);           tree->r = l;           upd(tree);           l = tree;         } else {           split(x, tree->l, l, r);           tree->l = r;           upd(tree);           r = tree;         }       }     }     void insert(node<T> *n, node<T> *&tree) {       if (!tree)         tree = n;       else {         if (n->prior > tree->prior) {           split(n->val, tree, n->l, n->r);           tree = n;         } else if (n->val < tree->val)           insert(n, tree->l);         else           insert(n, tree->r);         upd(tree);       }     }     void del(T c, node<T> *&tree) {       if (!tree) return;       if (tree->val.i == c.i && tree->val.c == c.c) {         tree = merge(tree->l, tree->r);       } else {         if (c < tree->val)           del(c, tree->l);         else           del(c, tree->r);       }       upd(tree);     }     T getminsum(int cnt, node<T> *tree) {       if (!tree)         return *(new T);       else if (tree->cnt <= cnt)         return tree->sum;       else {         T ans;         ans = ans + getminsum(cnt, tree->l);         if (cnt > getcnt(tree->l)) ans = ans + tree->val;         if (cnt > getcnt(tree->l) + 1)           ans = ans + getminsum(cnt - getcnt(tree->l) - 1, tree->r);         return ans;       }     }       public:     void insert(T n) {       node<T> *nn = new node<T>;       nn->sum = nn->val = n;       insert(nn, root);     }     void erase(T n) { del(n, root); }     T getminsum(int cnt) { return getminsum(cnt, root); }   };   struct cost {     long long c;     int i;     cost() : c(0), i(0) {}   };   inline cost operator+(const cost &a, const cost &b) {     cost c;     c.c = a.c + b.c;     return c;   }   inline bool operator<(const cost &a, const cost &b) {     if (a.c == b.c)       return (a.i < b.i);     else       return (a.c < b.c);   }   const int maxn = 300000;   vector<pair<int, pair<int, int> > > levels;   int n, w, taskans[maxn];   treap<cost> tree;   void insert(long long a, int b) {     cost c;     c.c = a, c.i = b;     tree.insert(c);   }   int main() {     cin >> n >> w;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       levels.push_back(make_pair(b, make_pair(a, i)));     }     sort(levels.begin(), levels.end());     long long ans = 1LL << 50;     int maxi = 0;     long long sum = 0;     for (int i = 0; i < n; i++)       insert(levels[i].second.first, levels[i].second.second);     for (int i = 0; i <= n; i++) {       if (w < i) break;       if (w - i <= n) {         long long summm = tree.getminsum(w - i).c;         if (ans > sum + summm) ans = sum + summm, maxi = i;       }       if (i != n) {         cost d;         d.c = levels[i].second.first, d.i = levels[i].second.second;         tree.erase(d);         insert(levels[i].first - levels[i].second.first, levels[i].second.second);         sum += d.c;       }     }     cout << ans << endl;     set<pair<int, int> > s;     for (int i = 0; i < maxi; i++)       taskans[levels[i].second.second]++,           s.insert(make_pair(levels[i].first - levels[i].second.first,                              levels[i].second.second));     for (int i = maxi; i < n; i++)       s.insert(make_pair(levels[i].second.first, levels[i].second.second));     int j = 0;     for (set<pair<int, int> >::iterator i = s.begin();          i != s.end() && j < w - maxi; i++, j++) {       taskans[i->second]++;     }     for (int i = 0; i < n; i++) cout << taskans[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 0;     char ch;     vector<bool> v(26, 0);     while (cin >> ch) {       cin >> ch;       if (ch ==  {  || ch ==  }  || ch ==  ,  || ch ==    ) continue;       ch -= 97;       if (!v[ch]) {         v[ch] = true;         n++;       }     }     cout << n;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int INF = 2e9;   const long long INFLL = 1e18;   const int MAX_N = 20;   int N, M, Q;   string str1[MAX_N + 1], str2[MAX_N + 1];   int main() {     scanf( %d%d , &N, &M);     for (int i = 0; i < N; i++) {       cin >> str1[i];     }     for (int j = 0; j < M; j++) {       cin >> str2[j];     }     scanf( %d , &Q);     for (int i = 1; i <= Q; i++) {       int y;       scanf( %d , &y);       y--;       cout << str1[y % N] << str2[y % M] << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b, c, d, e, f, L;     scanf( %d%d%d%d%d%d , &a, &b, &c, &d, &e, &f);     L = a + b + c;     printf( %d n , L * L - a * a - c * c - e * e);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int MOD = 1e9 + 7;   const int MAXN = 1e6 + 3;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = res * x;       y = y >> 1;       x = x * x;     }     return res;   }   long long n;   const int maxn = 1e3 + 3;   long long dp1[2 * maxn][2 * maxn];   long long dp2[2 * maxn][2 * maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     n *= 2;     dp1[0][0] = 0ll;     dp2[0][0] = 1ll;     for (long long i = 1; i <= n; i++) {       for (long long j = 0; j <= i; j++) {         if (j == 0) {           dp2[i][j] = (1 + dp1[i - 1][j + 1]) % MOD;           dp1[i][j] = max(dp1[i - 1][j + 1], dp2[i - 1][j + 1]);         } else if (j == i) {           dp2[i][j] = (1 + dp1[i - 1][j - 1]) % MOD;           dp1[i][j] = max(dp1[i - 1][j - 1], dp2[i - 1][j - 1]);         } else {           dp2[i][j] = (1 + dp1[i - 1][j - 1] + dp1[i - 1][j + 1]) % MOD;           dp1[i][j] = max(dp1[i - 1][j - 1] + dp2[i - 1][j + 1],                           dp1[i - 1][j + 1] + dp2[i - 1][j - 1]) %                       MOD;         }       }     }     cout << dp1[n][0] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int inX[1000001] = {0};   int used[1000001] = {0};   vector<int> ans;   int main() {     int n;     scanf( %d , &n);     vector<int> given(n, 0);     for (int i = 0; i < n; i++) {       scanf( %d , &given[i]);       inX[given[i]] = 1;       used[given[i]] = 1;     }     vector<int> pairLeft;     int reqdPairs = 0;     for (int i = 1; i <= 1000000; i++) {       if (inX[i]) {         if (inX[1000000 + 1 - i] == 0) {           used[1000000 + 1 - i] = 1;           ans.push_back(1000000 + 1 - i);         } else {           reqdPairs += 1;         }       } else {         if (inX[i] == inX[1000000 + 1 - i]) pairLeft.push_back(i);       }     }     for (int i = 0; 2 * i < reqdPairs; i++) {       ans.push_back(pairLeft[i]);       ans.push_back(1000000 + 1 - pairLeft[i]);     }     printf( %d n , (int)ans.size());     for (int i = 0; i < (int)ans.size(); i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int a, b, c;     cin >> n;     int tong = 0, tong1 = 0, tong2 = 0;     for (int i = 0; i < n; i++) {       cin >> a >> b >> c;       tong += a;       tong1 += b;       tong2 += c;     }     if (tong == 0 && tong1 == 0 && tong2 == 0)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     int n, k;     cin >> n >> k;     if ((n - 1) / 2 < k)       cout << -1 <<   n ;     else {       cout << (n * k) <<   n ;       ;       for (int i = 1; i <= n; i++)         for (int j = 0; j < k; j++) cout << i <<     << (i + j) % n + 1 <<   n ;       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[1003], dp[1003][1003], ans = 1e9 + 10, fr[1003][1003], now;   vector<pair<int, int> > res;   void dfs(int x, int wants) {     if (x == 1) return;     if (x == wants) {       res.push_back(make_pair(x - 1, fr[x][wants]));       dfs(x - 2, fr[x][wants]);     }     if (wants + 1 == x) {       res.push_back(make_pair(x, fr[x][wants]));       dfs(x - 2, fr[x][wants]);     }     if (x != wants && x != wants + 1) {       res.push_back(make_pair(x, x - 1));       dfs(x - 2, fr[x][wants]);     }   }   int main() {     for (int i = 0; i < 1003; i++)       for (int j = 0; j < 1003; j++) dp[i][j] = 1e9 + 10;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     if (n == 1) {       cout << a[1];       cout <<   n1 ;       return 0;     }     if (n == 2) {       cout << max(a[1], a[2]);       cout <<   n1 2 ;       return 0;     }     dp[1][1] = 0;     for (int i = 3; i <= n; i += 2)       for (int j = 1; j < i - 1; j++) {         if (dp[i][j] > dp[i - 2][j] + max(a[i], a[i - 1]))           dp[i][j] = dp[i - 2][j] + max(a[i], a[i - 1]), fr[i][j] = j;         if (dp[i][i - 1] > dp[i - 2][j] + max(a[i], a[j]))           dp[i][i - 1] = dp[i - 2][j] + max(a[i], a[j]), fr[i][i - 1] = j;         if (dp[i][i] > dp[i - 2][j] + max(a[i - 1], a[j]))           dp[i][i] = dp[i - 2][j] + max(a[i - 1], a[j]), fr[i][i] = j;       }     if (n % 2 == 1) {       for (int i = 1; i <= n; i++)         if (ans > dp[n][i] + a[i]) ans = dp[n][i] + a[i], now = i;     } else {       for (int i = 1; i < n; i++)         if (ans > dp[n - 1][i] + max(a[i], a[n]))           ans = dp[n - 1][i] + max(a[i], a[n]), now = i;     }     cout << ans <<   n ;     if (n % 2 == 1) {       dfs(n, now);       reverse(res.begin(), res.end());       for (int i = 0; i < res.size(); i++)         cout << res[i].first <<     << res[i].second <<   n ;       cout << now <<   n ;     } else {       dfs(n - 1, now);       reverse(res.begin(), res.end());       for (int i = 0; i < res.size(); i++)         cout << res[i].first <<     << res[i].second <<   n ;       cout << now <<     << n <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     for (int i = 0; i < T; i++) {       int N;       cin >> N;       vector<int> vec(N);       for (int j = 0; j < N; j++) {         cin >> vec.at(j);       }       if (vec.at(0) + vec.at(1) <= vec.at(N - 1)) {         cout << 1 <<     << 2 <<     << N << endl;       } else {         cout << -1 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n, a, b, i, same, unique, ans;     cin >> t;     while (t--) {       cin >> n;       same = 0;       unique = 0;       unordered_map<long long, long long> m;       for (i = 0; i < n; i++) {         cin >> a;         m[a]++;         if (m[a] == 1) {           unique++;         }         same = max(same, m[a]);       }       if (same < unique + 1) unique--;       ans = min(same, unique);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a > b) {       swap(a, b);     }     if (a == 0) return b;     return gcd(b % a, a);   }   int invertBits(int num) {     int x = log2(num) + 1;     for (int i = 0; i < x; i++) num = (num ^ (1 << i));     return num;   }   string add(string f, string s) {     reverse(f.begin(), f.end());     reverse(s.begin(), s.end());     int i = 0, j = 0;     string t =   ;     int carry = 0;     while (i < f.size() && j < s.size()) {       int k = (f[i] -  0 ) + (s[j] -  0 ) + carry;       carry = k / 10;       int sum = k % 10;       t += (sum +  0 );       i++;       j++;     }     while (i < f.size()) {       int k = (f[i] -  0 ) + carry;       carry = k / 10;       int sum = k % 10;       t += (sum +  0 );       i++;     }     while (j < s.size()) {       int k = (s[j] -  0 ) + carry;       carry = k / 10;       int sum = k % 10;       t += (sum +  0 );       j++;     }     if (carry) {       t += (carry +  0 );     }     reverse(t.begin(), t.end());     return t;   }   int mulmod(int a, int b, int mod) {     int res = 0;     a = a % mod;     while (b > 0) {       if (b % 2 == 1) res = (res + a) % mod;       a = (a * 2) % mod;       b /= 2;     }     return res % mod;   }   int main() {     long long int n;     long long int m = 998244353;     cin >> n;     long long int i, a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     long long int ans = 0;     for (i = 0; i < n; i++) {       long long int k = a[i];       long long int mul = 1;       while (k != 0) {         long long int r = k % 10;         ans = (ans % m + ((r % m) * (mul % m) * (n % m)) % m) % m;         mul = mul * 10;         mul = mul % m;         ans = (ans % m + ((r % m) * (mul % m) * (n % m)) % m) % m;         mul = mul * 10;         mul = mul % m;         k = k / 10;       }     }     cout << (ans + m) % m;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long const mod = 1e9 + 7;   long long const long_max = LONG_LONG_MAX;   int interact(int i, int j) {     cout <<  ?   << i + 1 <<     << j + 1 <<   n ;     ;     cout.flush();     int x;     cin >> x;     return x;   }   void solve() {     int n;     cin >> n;     int ind = 0;     vector<int> b(n);     for (int i = 1; i < n; i++) {       int x = interact(ind, i);       int y = interact(i, ind);       if (x < y) {         b[i] = y;       } else {         b[ind] = x;         ind = i;       }     }     b[ind] = n;     cout <<  !  ;     for (auto i : b) cout << i <<    ;     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1, p;     p = t;     t = 1;     while (p--) {       solve();       t++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     char c = getchar();     long long u = 0, f = 1;     while (c !=  -  && (c <  0  ||  9  < c)) c = getchar();     if (c ==  - ) {       f = -1;       c = getchar();     }     while ( 0  <= c && c <=  9 ) {       u = u * 10 + c -  0 ;       c = getchar();     }     return u * f;   }   inline char readc() {     for (;;) {       char c = getchar();       if ( A  <= c && c <=  Z  ||  a  <= c && c <=  z ) return c;     }   }   inline int read_digit() {     for (;;) {       char c = getchar();       if ( 0  <= c && c <=  9 ) return c -  0 ;     }   }   inline int max(int a, int b) { return a > b ? a : b; }   inline int min(int a, int b) { return a < b ? a : b; }   template <typename T>   inline void updmax(T &a, T b) {     if (b > a) a = b;   }   template <typename T>   inline void updmin(T &a, T b) {     if (b < a) a = b;   }   inline void swap(int &a, int &b) {     int t = a;     a = b;     b = t;   }   inline void fileio(string s) {     if (s ==  txt ) {       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);     } else {       freopen((s +  .in ).c_str(),  r , stdin);       freopen((s +  .out ).c_str(),  w , stdout);     }   }   char a[1000010];   map<int, int> cnt;   int main() {     int n;     scanf( %d , &n);     long long ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %s , a);       int l = strlen(a);       int b[26] = {0};       for (int j = 0; j < l; j++) b[a[j] -  a ]++;       int num = 0, id = 1;       for (int j = 0; j < 26; j++) {         if (b[j] % 2 == 1) num += id;         id <<= 1;       }       ans += cnt[num];       for (int j = 0; j < 26; j++) {         int p = (1 << j);         if (num & p)           ans += cnt[num - p];         else           ans += cnt[num + p];       }       cnt[num]++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 500 * 1000 + 10;   vector<int> adj[MAX_N], vec[MAX_N];   int n, m, cnt;   queue<int> q;   set<int> s;   void readInput() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--, v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 0; i < n; i++) sort(adj[i].begin(), adj[i].end()), s.insert(i);   }   void solve() {     while (!s.empty()) {       q.push(*s.begin()), s.erase(s.begin());       while (!q.empty()) {         int u = q.front();         q.pop(), vec[cnt].push_back(u);         int cur = 0;         vector<int> tmp;         for (auto v : s) {           while (cur < adj[u].size() && adj[u][cur] < v) cur++;           if (cur == adj[u].size() || adj[u][cur] != v) tmp.push_back(v);         }         for (auto v : tmp) q.push(v), s.erase(v);       }       cnt++;     }   }   void writeOutput() {     cout << cnt << endl;     for (int i = 0; i < cnt; i++) {       cout << vec[i].size() <<    ;       for (auto u : vec[i]) cout << u + 1 <<    ;       cout << endl;     }   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     readInput(), solve(), writeOutput();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string n;   int ar[123], sum = 0;   int main() {     getline(cin, n);     for (int i = 1; i < n.size(); i += 3) {       ar[(int)n[i]] = 1;     }     for (int i = 0; i < 123; i++) {       sum += ar[i];     }     cout << sum;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   using namespace std;   long long int **sparse;   void buildSparseTable(long long int arr[], long long int n,                         long long int **sparse) {     for (long long int i = 0; i < n; i++) {       sparse[i][0] = i;     }     for (long long int j = 1; pow(2, j) <= n; j++) {       for (long long int i = 0; i + pow(2, j) - 1 < n; i++) {         if (arr[sparse[i][j - 1]] >=             arr[sparse[i + (long long int)pow(2, j - 1)][j - 1]]) {           sparse[i][j] = sparse[i][j - 1];         } else {           sparse[i][j] = sparse[i + (long long int)pow(2, j - 1)][j - 1];         }       }     }   }   long long int query(long long int l, long long int r, long long int **sparse,                       long long int arr[]) {     long long int len = r - l + 1;     long long int k = (log(len) / log(2.0));     long long int m;     if (arr[sparse[l][k]] >= arr[sparse[l + len - (long long int)pow(2, k)][k]]) {       return sparse[l][k];     } else       return sparse[l + len - (long long int)pow(2, k)][k];   }   int main() {     long long int n;     cin >> n;     long long int arr[n];     sparse = new long long int *[n];     for (long long int i = 0; i < n; i++) {       sparse[i] = new long long int[(long long int)floor(log(n) / log(2.0)) + 1];     }     arr[n - 1] = n - 1;     for (long long int i = 0; i < n - 1; i++) {       cin >> arr[i];       arr[i]--;     }     buildSparseTable(arr, n, sparse);     long long int dp[n];     dp[n - 1] = 0;     long long int sum = 0;     for (long long int i = n - 2; i >= 0; i--) {       long long int m = query(i + 1, arr[i], sparse, arr);       dp[i] = dp[m] - (arr[i] - m) + n - 1 - i;       sum += dp[i];     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxN = 1e5 + 21;   long long n, m, a[maxN], cnt[maxN], ans;   bool p[maxN], f = true;   vector<long long> g[maxN];   int32_t main() {     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     queue<long long> q;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       if (!a[i]) q.push(i);     }     while (!q.empty()) {       long long i = q.front();       q.pop();       if (a[i] == cnt[i]) {         cnt[i]++, p[i] = true, ans++;         for (long long j = 0; j < g[i].size(); j++) {           long long u = g[i][j];           cnt[u]++;           if (a[u] == cnt[u]) q.push(u);         }       }     }     for (long long i = 1; i <= n; i++)       if (a[i] == cnt[i]) f = false;     if (!f)       cout << -1 << endl;     else {       cout << ans << endl;       for (long long i = 1; i <= n; i++) {         if (p[i]) cout << i <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, h, a, b, k, t1, f1, t2, f2;     scanf( %lld%lld%lld%lld%lld , &n, &h, &a, &b, &k);     while (k--) {       scanf( %lld%lld%lld%lld , &t1, &f1, &t2, &f2);       if (t1 == t2)         printf( %lld n , abs(f2 - f1));       else {         long long int ans = abs(t1 - t2);         if (f1 > b) {           ans += f1 - b;           f1 = b;         } else if (f1 < a) {           ans += a - f1;           f1 = a;         }         ans += abs(f2 - f1);         printf( %lld n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     int n;     unsigned long long ans;     string str;     cin >> n >> str;     map<int, vector<int> > myMap;     myMap[0].push_back(0);     int cur = 0;     ans = 0;     for (int i = 0; i < str.size(); i++) {       if (str[i] ==  0 ) {       } else {         cur++;       }       if (cur >= n && myMap.count(cur - n) != 0) {         ans += myMap[cur - n].size();       }       myMap[cur].push_back(i);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500500;   bool x[maxn];   int p[maxn], num[maxn], tmp[110];   int main() {     int n, q;     long long ans = 0;     scanf( %d%d , &n, &q);     for (int i = 0; i < n; i++) scanf( %d , num + i + 1);     for (int u = 0; u < q; u++) {       int t, k, cnt = 0;       scanf( %d , &t);       k = num[t];       if (x[t]) {         for (int i = 2; i * i <= k; i++)           if (k % i == 0) {             tmp[cnt++] = i;             while (k % i == 0) k /= i;           }         if (k != 1) tmp[cnt++] = k;         for (int i = 0; i < (1 << cnt); i++) {           long long cur = 0;           int add = 0, mult = 1;           for (int j = 0; j < cnt; j++)             if (i & (1 << j)) mult *= tmp[j], add++;           p[mult]--;           cur = p[mult];           if (add & 1)             ans += cur;           else             ans -= cur;         }         x[t] = 0;       } else {         for (int i = 2; i * i <= k; i++)           if (k % i == 0) {             tmp[cnt++] = i;             while (k % i == 0) k /= i;           }         if (k != 1) tmp[cnt++] = k;         for (int i = 0; i < (1 << cnt); i++) {           long long cur = 0;           int add = 0, mult = 1;           for (int j = 0; j < cnt; j++)             if (i & (1 << j)) mult *= tmp[j], add++;           cur = p[mult];           p[mult]++;           if (add & 1)             ans -= cur;           else             ans += cur;         }         x[t] = 1;       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5;   const int INF = 1e9;   int n, m, cl, ce, v, q;   int a[maxn + 5], b[maxn + 5];   int main() {     scanf( %d%d%d%d%d , &n, &m, &cl, &ce, &v);     for (int i = 1; i <= cl; i++) scanf( %d , &b[i]);     for (int i = 1; i <= ce; i++) scanf( %d , &a[i]);     sort(a + 1, a + ce + 1);     sort(b + 1, b + cl + 1);     scanf( %d , &q);     while (q--) {       int Ax, Ay, Bx, By;       int Min = INF, t;       scanf( %d%d%d%d , &Ay, &Ax, &By, &Bx);       if (Ax > Bx) swap(Ax, Bx);       if (Ay > By) swap(Ay, By);       if (Ay == By) Min = min(Min, Bx - Ax);       int l = 1, r = ce, ans = 0;       while (l <= r) {         int mid = (l + r) / 2;         if (a[mid] <= Ax)           l = mid + 1, ans = mid;         else           r = mid - 1;       }       if (ans != 0)         t = (Ax - a[ans]) * 2 + (By - Ay + v - 1) / v + Bx - Ax;       else         t = INF;       Min = min(Min, t);       l = 1, r = cl, ans = 0;       while (l <= r) {         int mid = (l + r) / 2;         if (b[mid] <= Ax)           l = mid + 1, ans = mid;         else           r = mid - 1;       }       if (ans != 0)         t = (Ax - b[ans]) * 2 + By - Ay + Bx - Ax;       else         t = INF;       Min = min(Min, t);       l = 1, r = ce, ans = 0;       while (l <= r) {         int mid = (l + r) / 2;         if (a[mid] >= Ax)           r = mid - 1, ans = mid;         else           l = mid + 1;       }       if (ans != 0 && a[ans] <= Bx)         t = Bx - Ax + (By - Ay + v - 1) / v;       else         t = INF;       Min = min(Min, t);       l = 1, r = cl, ans = 0;       while (l <= r) {         int mid = (l + r) / 2;         if (b[mid] >= Ax)           r = mid - 1, ans = mid;         else           l = mid + 1;       }       if (ans != 0 && b[ans] <= Bx)         t = Bx - Ax + By - Ay;       else         t = INF;       Min = min(Min, t);       l = 1, r = ce, ans = 0;       while (l <= r) {         int mid = (l + r) / 2;         if (a[mid] >= Bx)           r = mid - 1, ans = mid;         else           l = mid + 1;       }       if (ans != 0)         t = (a[ans] - Bx) * 2 + Bx - Ax + (By - Ay + v - 1) / v;       else         t = INF;       Min = min(Min, t);       l = 1, r = cl, ans = 0;       while (l <= r) {         int mid = (l + r) / 2;         if (b[mid] >= Bx)           r = mid - 1, ans = mid;         else           l = mid + 1;       }       if (ans != 0)         t = (b[ans] - Bx) * 2 + Bx - Ax + By - Ay;       else         t = INF;       Min = min(Min, t);       printf( %d n , Min);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[300005];   int l[5005], r[5005];   long long dp[5005][5005];   const long long inf = 2e16;   void Min(long long &a, long long b) {     if (a > b) a = b;   }   int main() {     int n, k;     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     int cur = 0, tmp = n / k;     int c1 = n - tmp * k, c2 = k - c1;     for (int i = 0; i < 5005; i++)       for (int j = 0; j < 5005; j++) dp[i][j] = inf;     for (int i = 1; i <= k; i++) {       if (c1 < i)         r[i] = min(n, c1 * (tmp + 1) + (i - c1) * tmp);       else         r[i] = min(n, i * (tmp + 1));       if (c2 < i)         l[i] = min(n, c2 * tmp + (i - c2) * (tmp + 1));       else         l[i] = min(n, i * tmp);     }     dp[0][0] = 0;     for (int i = 1; i <= k; i++)       for (int j = l[i]; j <= r[i]; j++) {         int pre = j - tmp;         if (pre <= r[i - 1] && pre >= l[i - 1])           Min(dp[i][j - l[i]], dp[i - 1][pre - l[i - 1]] + a[j] - a[pre + 1]);         if (pre - 1 <= r[i - 1] && pre - 1 >= l[i - 1])           Min(dp[i][j - l[i]], dp[i - 1][pre - 1 - l[i - 1]] + a[j] - a[pre]);       }     printf( %d n , dp[k][n - l[k]]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200010];   int a[200010];   int ans[50];   int n, k, x;   void init() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> s[i];     for (int i = 1; i <= n; i++) a[i] = (int)s[i] -  a  + 1;     a[++n] = 30;     for (int i = 1; i <= 26; i++) {       int l;       bool flag = 0;       for (int j = 1; j <= n; j++) {         if (flag == 0 & a[j] == i) {           l = j;           flag = 1;         }         if (flag && a[j] != i) {           ans[i] += (j - l) / k;           flag = 0;         }       }     }   }   int main() {     init();     for (int i = 1; i <= 26; i++) x = max(ans[i], x);     cout << x;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int f, a, b;     scanf( %d , &f);     scanf( %d:%d , &a, &b);     if (b > 59) b %= 10;     if (a > f or a == 24) a %= 10;     if (a == 0 and f == 12) a = 10;     printf( %02d:%02d , a, b);   }


#include <bits/stdc++.h>   using namespace std;   int T, n, s, t;   int main() {     cin >> T;     while (T--) {       cin >> n >> s >> t;       cout << max(1, max(n - s + 1, n - t + 1)) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long int gcd(long long int a, long long int b) {     if (a < b)       return gcd(b, a);     else if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long int isPrime(long long int n) {     long long int p = (long long int)sqrt(n);     for (int i = (2); i <= (p); i += (1))       if (n % i == 0) return 0;     return 1;   }   long long int pow(long long int b, long long int e) {     if (e == 0)       return 1;     else if (e % 2 == 0) {       long long int a = pow(b, e / 2);       return a * a;     } else {       long long int a = pow(b, e / 2);       return b * a * a;     }   }   long long int powm(long long int x, long long int y,                      long long int m = 1000000007) {     x = x % m;     long long int res = 1;     while (y) {       if (y & 1) res = res * x;       res %= m;       y = y >> 1;       x = x * x;       x %= m;     }     return res;   }   long long int modInverse(long long int a, long long int m) {     return powm(a, m - 2, m);   }   int spf[10000005];   void sieve() {     spf[1] = 1;     for (int i = 2; i < 10000005; i++) spf[i] = i;     for (int i = 4; i < 10000005; i += 2) spf[i] = 2;     for (int i = 3; i * i < 10000005; i++) {       if (spf[i] == i) {         for (int j = i * i; j < 10000005; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   void solve() {     sieve();     int n;     cin >> n;     vector<int> arr(n);     vector<pair<long long int, long long int>> ans(n);     for (int i = (0); i <= (n - 1); i += (1)) {       cin >> arr[i];       int x = arr[i];       vector<int> fac;       while (x != 1) {         int temp = spf[x];         fac.push_back(spf[x]);         while (x % temp == 0) x /= temp;       }       bool poss = 0;       ans[i] = {-1, -1};       if ((int)fac.size() > 1) {         int a = fac[0], b = 1;         for (int i = (1); i <= ((int)fac.size() - 1); i += (1)) b *= fac[i];         ans[i] = {a, b};       }     }     for (int i = (0); i <= (n - 1); i += (1)) cout << ans[i].first <<    ;     cout <<   n ;     for (int i = (0); i <= (n - 1); i += (1)) cout << ans[i].second <<    ;     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int T = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   const int LIM = 1e5;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, q, x, p;     cin >> n >> q;     for (int i = 0; i < q; i++) {       cin >> x;       p = (n - x) + x / 2;       while (x % 2 == 0) {         x += p;         p >>= 1;       }       cout << (x + 1) / 2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void operator>>(istream& is, vector<T>& v) {     for (auto& e : v) {       is >> e;     }   }   template <class T>   void operator<<(ostream& os, const vector<T>& v) {     for (const auto& e : v) {       os << e <<    ;     }     os <<   n ;   }   long long LenToAns(long long len) { return len * (len + 1) / 2; }   struct Node {     int last;     int first;     int pref;     int suff;     int inf;     int size;     long long ans;   };   vector<Node> tree;   int n;   int n_full;   Node MakeNode(int v) { return {v, v, 1, 1, 1, 1, 1}; }   Node MakeNeutral() { return {0, 0, 0, 0, 0, 0, 0}; }   Node Merge(const Node& l, const Node& r) {     Node res;     res.first = l.first;     res.last = r.last;     res.pref = l.pref;     res.suff = r.suff;     res.inf = max(l.inf, r.inf);     res.ans = l.ans + r.ans;     if (l.last <= r.first) {       res.inf = max(res.inf, l.suff + r.pref);       res.ans += LenToAns(l.suff + r.pref);       res.ans -= LenToAns(l.suff);       res.ans -= LenToAns(r.pref);       if (l.pref == l.size) {         res.pref = l.size + r.pref;       }       if (r.pref == r.size) {         res.suff = l.suff + r.size;       }     }     res.size = l.size + r.size;     return res;   }   void Init(const vector<int>& a) {     n_full = 1;     while (n_full < n) {       n_full *= 2;     }     tree.resize(n_full * 2 - 1);     for (int i = 0; i < n; i++) {       tree[n_full + i - 1] = MakeNode(a[i]);     }     for (int i = n_full - 2; i >= 0; i--) {       tree[i] = Merge(tree[2 * i + 1], tree[2 * i + 2]);     }   }   void Set(int i, int v, int xi, int xl, int xr) {     if (xl > i || i >= xr) {       return;     }     if (xr - xl == 1) {       tree[xi] = MakeNode(v);       return;     }     int xm = (xl + xr) / 2;     Set(i, v, xi * 2 + 1, xl, xm);     Set(i, v, xi * 2 + 2, xm, xr);     tree[xi] = Merge(tree[xi * 2 + 1], tree[xi * 2 + 2]);   }   void Set(int i, int v) { Set(i, v, 0, 0, n_full); }   Node Sum(int l, int r, int xi, int xl, int xr) {     if (xl >= r || l >= xr) {       return MakeNeutral();     }     if (l <= xl && xr <= r) {       return tree[xi];     }     int xm = (xl + xr) / 2;     return Merge(Sum(l, r, xi * 2 + 1, xl, xm), Sum(l, r, xi * 2 + 2, xm, xr));   }   long long Sum(int l, int r) {     Node res = Sum(l, r, 0, 0, n_full);     return res.ans;   }   int main() {     int k;     cin >> n >> k;     vector<int> a(n);     cin >> a;     Init(a);     while (k--) {       int q;       cin >> q;       if (q == 1) {         int i, v;         cin >> i >> v;         i--;         Set(i, v);       } else {         int l, r;         cin >> l >> r;         l--;         cout << Sum(l, r) <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long t, n;   int main() {     cin >> t;     while (t--) {       cin >> n;       long long ls, mi = 0;       bool pd = false;       cin >> ls;       for (int i = 2; i <= n; i++) {         long long x, lg;         cin >> x;         if (x < ls) {           lg = int(floor(log2(ls - x)));           mi = max(mi, lg);           pd = true;         }         ls = max(ls, x);       }       if (!pd)         cout << 0 << endl;       else         cout << mi + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int p[100000];   int c[100000];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> p[i];       --p[i];     }     vector<long long int> loops;     for (int i = 0; i < n; ++i) {       if (c[i]) continue;       int j = i;       int q = 0;       while (c[j] == 0) {         c[j] = 1;         j = p[j];         ++q;       }       loops.push_back(q);     }     sort(loops.begin(), loops.end());     if (loops.size() > 1) {       loops[loops.size() - 2] += loops[loops.size() - 1];       loops.pop_back();     }     long long int ans = 0;     for (int i = 0; i < loops.size(); ++i) {       ans += loops[i] * loops[i];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char ss[100010];   string s;   string s1;   pair<int, int> b[2000000];   int m[100100];   unsigned long long h[100100];   unsigned long long p[100100];   int main() {     scanf( %s , &ss);     s = (string)ss;     h[0] = 0;     p[0] = 1;     for (int i = (1); i < (100100); ++i) p[i] = p[i - 1] * 257;     for (int i = (0); i < (s.size()); ++i)       h[i + 1] = h[i] + (unsigned int)s[i] * p[i];     int n;     cin >> n;     int sz = 0;     for (int it = (0); it < (n); ++it) {       cin >> s1;       unsigned long long h1 = 0;       for (int i = (0); i < (s1.size()); ++i) h1 += (unsigned int)s1[i] * p[i];       int pp = (int)(s.size()) - (int)s1.size();       for (int i = (0); i < (pp + 1); ++i) {         if (h1 * p[i] == h[i + s1.size()] - h[i]) {           b[sz] = make_pair(i, i + s1.size() - 1);           sz++;         }       }     }     for (int i = (0); i < (s.size()); ++i) m[i] = (int)s.size();     for (int i = (0); i < (sz); ++i)       m[b[i].first] =           ((m[b[i].first] < b[i].second) ? (m[b[i].first]) : (b[i].second));     for (int i = (int)s.size() - 2; i >= 0; --i)       m[i] = ((m[i] < m[i + 1]) ? (m[i]) : (m[i + 1]));     int res = 0;     int res1 = 0;     for (int i = (0); i < (s.size()); ++i) {       int len = m[i] - i;       if (len > res) {         res = len;         res1 = i;       }     }     printf( %d %d n , res, res1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long dp[2005][2005], m, d, ans, bit[2005], len;   char l[2005], r[2005];   long long dfs(int pos, long long sum, bool flag) {     if (pos == -1) return sum == 0;     if (!flag && dp[pos][sum] != -1) return dp[pos][sum];     long long res = 0;     for (int i = 0, up = flag ? bit[pos] : 9; i <= up; ++i) {       if ((len - pos) & 1) {         if (i == d) continue;       } else {         if (i != d) continue;       }       (res += dfs(pos - 1, (sum * 10 + i) % m, flag && (i == up))) %= MOD;     }     return flag ? res : dp[pos][sum] = res;   }   long long calc(char *x) {     len = strlen(x);     for (int i = 0; i < len; ++i) bit[len - i - 1] = x[i] -  0 ;     return dfs(len - 1, 0, 1);   }   int check() {     long long sum = 0;     len = strlen(l);     for (int i = 0; i < len; ++i) {       int x = l[i] -  0 ;       if ((i + 1) & 1) {         if (x == d) return 0;       } else {         if (x != d) return 0;       }       (sum = sum * 10 + x) %= m;     }     return sum == 0;   }   int main() {     memset(dp, -1, sizeof(dp));     scanf( %lld%lld , &m, &d);     scanf( %s , l);     scanf( %s , r);     ans = calc(r) - calc(l);     ans += check();     printf( %lld n , (ans + MOD) % MOD);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       long long int m, a[1000], b, sum = 0;       cin >> m >> b;       for (int j = 0; j < m; j++) {         cin >> a[j];       }       for (int j = 0; j < m; j++) {         sum = sum + a[j];       }       if (sum == b) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, i, x, ans;   int main() {     cin >> n >> m;     x = 1;     for (i = 1; i <= m; i++) x = x * 2 % 1000000009;     ans = 1;     for (i = 1; i <= n; i++) ans = ans * (x - i) % 1000000009;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.141592653589793238463;   void printVec(vector<int> v1) {     for (int i = 0; i < v1.size(); i++) cout << v1[i] <<    ;     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     cout.tie(NULL);     cin.tie(NULL);     priority_queue<long long, vector<long long>, greater<long long>> pQ;     long long n;     cin >> n;     string s;     long long opr;     vector<string> vec;     vector<long long> operations;     for (long long i = 0; i < n; i++) {       cin >> s;       vec.push_back(s);       if (s ==  removeMin ) {         operations.push_back(-1);         continue;       }       cin >> opr;       operations.push_back(opr);     }     vector<string> vec_Out;     vector<long long> operations_Out;     for (long long i = 0; i < n; i++) {       if (vec[i] ==  removeMin ) {         if (pQ.empty()) {           pQ.push(0);           vec_Out.push_back( insert  );           operations_Out.push_back(0);         }         pQ.pop();         vec_Out.push_back( removeMin );         operations_Out.push_back(-1);       } else if (vec[i][0] ==  i ) {         vec_Out.push_back( insert  );         operations_Out.push_back(operations[i]);         pQ.push(operations[i]);       } else {         opr = operations[i];         long long MIN = -2;         if (!pQ.empty()) {           MIN = pQ.top();         }         while (opr != MIN && !pQ.empty() && opr > MIN) {           pQ.pop();           if (!pQ.empty()) {             MIN = pQ.top();           }           vec_Out.push_back( removeMin );           operations_Out.push_back(-1);         }         if (pQ.empty() || opr < MIN) {           pQ.push(opr);           vec_Out.push_back( insert  );           operations_Out.push_back(opr);         }         vec_Out.push_back( getMin  );         operations_Out.push_back(opr);       }     }     cout << vec_Out.size() << endl;     for (long long i = 0; i < vec_Out.size(); i++) {       if (vec_Out[i] ==  removeMin ) {         cout << vec_Out[i] << endl;         continue;       }       cout << vec_Out[i] << operations_Out[i] << endl;     }     vec_Out.clear();     vec.clear();     operations.clear();     operations_Out.clear();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200001;   int n;   int d[maxn], anc[maxn][18], p[maxn];   array<int, 2> tree[maxn * 4];   int jua(int x, int y) {     int dd = d[y] - d[x];     for (int i = 17; i >= 0; i--) {       if (dd >= 1 << i) {         y = anc[y][i];         dd -= (1 << i);       }     }     return x == y;   }   int lca(int x, int y) {     if (d[x] < d[y]) swap(x, y);     int dd = d[x] - d[y];     for (int i = 17; i >= 0; i--) {       if (dd >= 1 << i) {         x = anc[x][i];         dd -= (1 << i);       }     }     if (x == y) return x;     for (int i = 17; i >= 0; i--) {       if (anc[x][i] != anc[y][i]) {         x = anc[x][i];         y = anc[y][i];       }     }     return anc[x][0];   }   void cmb2(array<int, 2> &p0, int x) {     if (p0[0] == -1 || x == -1) {       p0[0] = -1;       p0[1] = -1;       return;     }     if (d[p0[0]] > d[p0[1]]) swap(p0[0], p0[1]);     if (jua(p0[0], p0[1])) {       if (d[x] >= d[p0[0]] && d[x] <= d[p0[1]] && jua(x, p0[1])) {         return;       }       if (jua(p0[1], x)) {         p0[1] = x;         return;       }       int c = lca(p0[1], x);       if (d[c] > d[p0[0]]) {         p0[0] = p0[1] = -1;         return;       }       p0[0] = x;     } else {       int c = lca(p0[0], p0[1]);       if (d[x] >= d[c] && (jua(x, p0[0]) || jua(x, p0[1]))) {         return;       }       if (jua(p0[0], x)) {         p0[0] = x;         return;       }       if (jua(p0[1], x)) {         p0[1] = x;         return;       }       p0[0] = p0[1] = -1;     }     return;   }   array<int, 2> cmb(array<int, 2> p1, array<int, 2> p2) {     cmb2(p1, p2[0]);     cmb2(p1, p2[1]);     return p1;   }   void update(int v, array<int, 2> pp, int k, int l, int r) {     if (l == r) {       tree[k] = pp;       return;     }     int mid = (l + r) / 2;     if (v <= mid)       update(v, pp, k * 2, l, mid);     else       update(v, pp, k * 2 + 1, mid + 1, r);     tree[k] = cmb(tree[k * 2], tree[k * 2 + 1]);   }   int query(int k, int l, int r, array<int, 2> p) {     array<int, 2> t = tree[k];     if (l) t = cmb(t, p);     if (t[0] != -1) {       return r + 1;     }     if (l == r) return l;     int mid = (l + r) / 2;     array<int, 2> tt = tree[k * 2];     if (l) tt = cmb(tt, p);     if (tt[0] != -1)       return query(k * 2 + 1, mid + 1, r, tt);     else       return query(k * 2, l, mid, p);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> p[i];     }     memset(anc[0], -1, sizeof(anc[0]));     anc[1][0] = -1;     d[1] = 1;     for (int i = 1; i < n; i++) {       int x;       cin >> x, x--;       anc[i][0] = x;       d[i] = d[x] + 1;     }     for (int i = 1; i < n; i++) {       for (int j = 0; j < 17; j++) {         if (anc[i][j] != -1)           anc[i][j + 1] = anc[anc[i][j]][j];         else           anc[i][j + 1] = -1;       }     }     for (int i = 0; i < n; i++) {       update(p[i], {i, i}, 1, 0, n - 1);     }     int q;     cin >> q;     while (q--) {       int ju;       cin >> ju;       if (ju == 1) {         int x, y;         cin >> x >> y;         x--, y--;         swap(p[x], p[y]);         update(p[x], {x, x}, 1, 0, n - 1);         update(p[y], {y, y}, 1, 0, n - 1);       } else {         cout << query(1, 0, n - 1, {}) << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int t;   int n, m;   string A, B;   int f[405][405];   int main() {     int i, j, k;     cin >> t;     while (t--) {       cin >> A >> B;       n = A.length(), m = B.length();       A =  0  + A;       B =  0  + B;       i = 1, j = 1;       for (i = 1; i <= n; i++) {         if (A[i] == B[j]) {           j++;           if (j == m + 1) break;         }       }       if (j == m + 1) {         cout <<  YES  << endl;         continue;       }       bool flag = false;       for (k = 1; k < n; k++) {         memset(f, 0, sizeof(f));         f[0][0] = k;         for (i = 0; i < n; i++) {           for (j = 0; j <= k; j++) {             if (f[i][j] == 0) continue;             f[i + 1][j] = max(f[i + 1][j], f[i][j]);             if (j < k and A[i + 1] == B[j + 1]) {               f[i + 1][j + 1] = max(f[i + 1][j + 1], f[i][j]);             }             if (f[i][j] < m and A[i + 1] == B[f[i][j] + 1]) {               f[i + 1][j] = max(f[i + 1][j], f[i][j] + 1);             }           }         }         if (f[n][k] == m) {           flag = true;           break;         }       }       if (flag) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nmax = 1005;   const int inf = 1 << 28;   int n, m, A[nmax][nmax], B[nmax][nmax], C[nmax][nmax];   char a[nmax][nmax];   int dx[] = {-1, 0, 0, 1};   int dy[] = {0, -1, 1, 0};   deque<pair<int, int> > q;   bitset<nmax> inq[nmax];   void go(int x, int y, int d[nmax][nmax]) {     for (int i = 1; i <= n; i++) inq[i] = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) d[i][j] = inf;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] == a[x][y]) {           d[i][j] = 0;           q.push_back(make_pair(i, j));           inq[i][j] = 1;         }     while (!q.empty()) {       x = q.front().first;       y = q.front().second;       q.pop_front();       inq[x][y] = 0;       for (int k = 0; k < 4; k++) {         int newx = x + dx[k];         int newy = y + dy[k];         int cost;         if (a[newx][newy] >=  1  && a[newx][newy] <=  3 )           cost = 0;         else if (a[newx][newy] ==  . )           cost = 1;         else           cost = inf;         if (d[x][y] + cost < d[newx][newy]) {           d[newx][newy] = d[x][y] + cost;           if (!inq[newx][newy]) {             q.push_back(make_pair(newx, newy));             inq[newx][newy] = 1;           }         }       }     }   }   int main() {     cin.sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> (a[i] + 1);     bool foundA = 0;     bool foundB = 0;     bool foundC = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++)         if (a[i][j] ==  1  && !foundA) {           go(i, j, A);           foundA = 1;         } else if (a[i][j] ==  2  && !foundB) {           go(i, j, B);           foundB = 1;         } else if (a[i][j] ==  3  && !foundC) {           go(i, j, C);           foundC = 1;         }     }     int sol = inf;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         int cost;         if (a[i][j] ==  1  || a[i][j] ==  2  || a[i][j] ==  3 )           cost = 0;         else if (a[i][j] ==  . )           cost = 2;         sol = min(sol, A[i][j] + B[i][j] + C[i][j] - cost);       }     if (sol >= inf)       cout << -1;     else       cout << sol;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string solve1(string n) {     string res(n.length(),  9 );     for (char c =  8 ; c >=  0 ; c--) {       string t(n.length(), c);       if (t >= n) res = t;     }     return res;   }   string solve2(string n) {     string res = solve1(n);     for (char a =  0 ; a <=  9 ; a++)       for (char b = a + 1; b <=  9 ; b++) {         bool n_ok = true;         for (int i = 0; i < n.length(); i++) {           if (n[i] < b) {             string t = n;             if (t[i] < a)               t[i] = a;             else               t[i] = b;             for (int j = i + 1; j < n.length(); j++) t[j] = a;             if (res > t) res = t;           }           if (n[i] != a && n[i] != b) {             n_ok = false;             break;           }         }         if (n_ok) return n;       }     return res;   }   string solve() {     string n;     int k;     cin >> n >> k;     if (k == 1)       return solve1(n);     else       return solve2(n);   }   int main() {     int t;     cin >> t;     while (t--) cout << solve() <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long ll;   int main() {     ll t;     cin >> t;     while (t--) {       ll cnt3, cnt2;       cnt2 = cnt3 = 0;       ll n;       cin >> n;       while (n % 2 == 0) {         n = n / 2;         cnt2++;       }       while (n % 3 == 0) {         n = n / 3;         cnt3++;       }       if (n != 1 || cnt2 > cnt3)         cout << -1 <<   n ;       else {         ll ans = cnt2 + (cnt3 - cnt2) * 2;         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, n, mx, mn, p1, p2, poz, poz1, poz2, k, mx1, mx2, m, mij, u, x, y, z, q;   struct para {     int x, y, z, ind;   } a[100007];   int cmp(para k1, para k2) {     if (k1.x > k2.x)       return 0;     else if (k1.x == k2.x) {       if (k1.y > k2.y)         return 0;       else if (k1.y == k2.y) {         if (k1.z > k2.z)           return 0;         else if (k1.z == k2.z) {           return 0;         }         return 1;       }       return 1;     }     return 1;   }   int main() {     scanf( %d , &n);     mx = -1;     for (i = 1; i <= n; i++) {       scanf( %d%d%d , &a[i].x, &a[i].y, &a[i].z);       a[i].ind = i;       mn = a[i].x;       if (mn > a[i].y) mn = a[i].y;       if (mn > a[i].z) mn = a[i].z;       if (mx < mn) {         mx = mn;         k = 1;         poz = a[i].ind;       }       m = max(max(a[i].x, a[i].y), a[i].z);       mij = a[i].x + a[i].y + a[i].z - m - mn;       a[i].x = mn;       a[i].y = mij;       a[i].z = m;     }     sort(a + 1, a + n + 1, cmp);     for (i = 1; i <= n; i++) {       mx1 = -1;       mx2 = -1;       u = 0;       while (a[i].x == a[i + 1].x && a[i].y == a[i + 1].y) {         u = 1;         if (mx1 < a[i].z) {           mx2 = mx1;           poz2 = poz1;           mx1 = a[i].z;           poz1 = a[i].ind;         } else if (mx2 < a[i].z) {           mx2 = a[i].z;           poz2 = a[i].ind;         }         i++;       }       if (u == 1) {         if (mx1 < a[i].z) {           mx2 = mx1;           poz2 = poz1;           mx1 = a[i].z;           poz1 = a[i].ind;         } else if (mx2 < a[i].z) {           mx2 = a[i].z;           poz2 = a[i].ind;         }       }       q = min(min(a[i].x, a[i].y), mx1 + mx2);       if (mx < q) {         mx = q;         k = 2;         p1 = poz1;         p2 = poz2;       }     }     for (i = 1; i <= n; i++) {       x = a[i].x;       y = a[i].y;       z = a[i].z;       a[i].x = y;       a[i].y = z;       a[i].z = x;     }     sort(a + 1, a + n + 1, cmp);     for (i = 1; i <= n; i++) {       mx1 = -1;       mx2 = -1;       u = 0;       while (a[i].x == a[i + 1].x && a[i].y == a[i + 1].y) {         u = 1;         if (mx1 < a[i].z) {           mx2 = mx1;           poz2 = poz1;           mx1 = a[i].z;           poz1 = a[i].ind;         } else if (mx2 < a[i].z) {           mx2 = a[i].z;           poz2 = a[i].ind;         }         i++;       }       if (u == 1) {         if (mx1 < a[i].z) {           mx2 = mx1;           poz2 = poz1;           mx1 = a[i].z;           poz1 = a[i].ind;         } else if (mx2 < a[i].z) {           mx2 = a[i].z;           poz2 = a[i].ind;         }       }       q = min(min(a[i].x, a[i].y), mx1 + mx2);       if (mx < q) {         mx = q;         k = 2;         p1 = poz1;         p2 = poz2;       }     }     for (i = 1; i <= n; i++) {       x = a[i].x;       y = a[i].y;       z = a[i].z;       a[i].x = y;       a[i].y = z;       a[i].z = x;     }     sort(a + 1, a + n + 1, cmp);     for (i = 1; i <= n; i++) {       mx1 = -1;       mx2 = -1;       u = 0;       while (a[i].x == a[i + 1].x && a[i].y == a[i + 1].y) {         u = 1;         if (mx1 < a[i].z) {           mx2 = mx1;           poz2 = poz1;           mx1 = a[i].z;           poz1 = a[i].ind;         } else if (mx2 < a[i].z) {           mx2 = a[i].z;           poz2 = a[i].ind;         }         i++;       }       if (u == 1) {         if (mx1 < a[i].z) {           mx2 = mx1;           poz2 = poz1;           mx1 = a[i].z;           poz1 = a[i].ind;         } else if (mx2 < a[i].z) {           mx2 = a[i].z;           poz2 = a[i].ind;         }       }       q = min(min(a[i].x, a[i].y), mx1 + mx2);       if (mx < q) {         mx = q;         k = 2;         p1 = poz1;         p2 = poz2;       }     }     printf( %d n , k);     if (k == 1)       printf( %d n , poz);     else {       printf( %d %d n , p1, p2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     scanf( %d%d , &a, &b);     if (a < b) {       for (int i = b + 1; i <= (a + b + 1); i++) printf( %d  , i);       for (int j = b; j >= 1; j--) printf( %d  , j);     } else {       for (int i = 1; i <= a; i++) printf( %d  , i);       for (int j = (a + b + 1); j > a; j--) printf( %d  , j);     }   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   void qread(int &x) {     int neg = 1;     x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = 10 * x + c -  0 , c = getchar();     x *= neg;   }   const int maxn = 100005;   int n;   char c[maxn];   int dp[maxn][2][3];   int main() {     scanf( %d%s , &n, c);     memset(dp, -1, sizeof(dp));     dp[0][0][0] = dp[0][1][0] = 0;     for (int(i) = 0; (i) < n; i++)       for (int(j) = 0; (j) < 2; j++)         for (int(k) = 0; (k) < 3; k++) {           int cur = dp[i][j][k];           if (cur < 0) continue;           dp[i + 1][j][k] = max(dp[i + 1][j][k], cur);           if (c[i] -  0  != j)             dp[i + 1][c[i] -  0 ][k] = max(dp[i + 1][c[i] -  0 ][k], cur + 1);           else if (k < 2)             dp[i + 1][c[i] -  0 ][k + 1] =                 max(dp[i + 1][c[i] -  0 ][k + 1], cur + 1);         }     int ans = 0;     for (int(j) = 0; (j) < 2; j++)       for (int(k) = 0; (k) < 3; k++) ans = max(ans, dp[n][j][k]);     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, cnt, flag = 1;   int a[N], b[N], c[N];   int main() {     cnt = n = read();     a[0] = -1, b[0] = 0;     while (cnt--) {       for (int i = 0; i < N - 1; i++) c[i + 1] = a[i];       c[0] = 0;       for (int i = 0; i < N; i++) c[i] += b[i];       for (int i = 0; i < N; i++)         if (abs(c[i]) > 1) {           for (int i = 0; i < N - 1; i++) c[i + 1] = a[i] * (-1);           c[0] = 0;           for (int i = 0; i < N; i++) c[i] += b[i];           break;         }       for (int i = 0; i < N; i++) b[i] = a[i], a[i] = c[i];     }     cout << n << endl;     if (a[n] < 0)       flag = -1;     else       flag = 1;     for (int i = 0; i <= n; i++) cout << a[i] * flag <<    ;     cout << endl << n - 1 << endl;     if (b[n - 1] < 0)       flag = -1;     else       flag = 1;     for (int i = 0; i <= n - 1; i++) cout << b[i] * flag <<    ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( -O3 )   using namespace std;   const long long N = 1e6 + 5;   void pairsort(long long a[], long long b[], long long n) {     pair<long long, long long> pairt[n];     for (long long i = 0; i < n; i++) {       pairt[i].first = a[i];       pairt[i].second = b[i];     }     sort(pairt, pairt + n);     for (long long i = 0; i < n; i++) {       a[i] = pairt[i].first;       b[i] = pairt[i].second;     }   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long isPrime(long long n) {     if (n < 2) return 0;     if (n < 4) return 1;     if (n % 2 == 0 or n % 3 == 0) return 0;     for (long long i = 5; i * i <= n; i += 6)       if (n % i == 0 or n % (i + 2) == 0) return 0;     return 1;   }   long long C(long long n, long long r) {     if (r > n - r) r = n - r;     long long ans = 1;     for (long long i = 1; i <= r; i++) {       ans *= n - r + i;       ans /= i;     }     return ans;   }   long long mod = 1e9 + 7;   long long modexpo(long long x, long long p) {     long long res = 1;     x = x % mod;     while (p) {       if (p % 2) res = res * x;       p >>= 1;       x = x * x % mod;       res %= mod;     }     return res;   }   long long n, t, a[N], b[N], c[N], d[N], x[N];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> t;     a[n + 1] = 3000000000000000000 - t + 1;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= n; i++) cin >> x[i];     for (long long i = 1; i <= n; i++)       if (x[i] < x[i - 1] or x[i] < i) return cout <<  No , 0;     for (long long i = 1; i <= n; i++) b[i] = a[x[i] + 1] + t - 1;     for (long long i = n; i > 1; i--)       if (b[i - 1] >= b[i]) b[i - 1] = b[i] - 1;     for (long long i = 1; i <= n; i++) c[i + 1]++, c[x[i] + 1]--, d[x[i] + 1]++;     for (long long i = 1; i <= n; i++) c[i] += c[i - 1];     for (long long i = 1; i <= n; i++)       if (c[i] and a[i] + t > b[i - 1]) return cout <<  No , 0;     for (long long i = 1; i <= n; i++)       if (b[i] < a[i] + t) return cout <<  No , 0;     for (long long i = 1; i <= n; i++)       if (c[i] and d[i]) return cout <<  No , 0;     cout <<  Yes           <<   n ;     for (long long i = 1; i <= n; i++) cout << b[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const long long maxn = (long long)1e6 + 6;   const long double EPS = 1e-9;   const long long INF = (long long)1e18 + 18;   const long long mod = (long long)1e9 + 9;   long long n, m, k;   inline long long add(long long x, long long y) {     x += y;     if (x >= mod) x -= mod;     return x;   }   inline long long sub(long long x, long long y) {     x -= y;     if (x < 0) x += mod;     return x;   }   inline long long mul(long long x, long long y) { return (x * 1LL * y) % mod; }   inline long long binpow(long long a, long long b) {     long long x = 1 % mod;     while (b) {       if (b & 1) x = mul(x, a);       a = mul(a, a);       b >>= 1;     }     return x;   }   inline long long inv(long long a) { return binpow(a, mod - 2); }   bool works(long long x) {     long long t = x * k + ((n - x * k) / k) * (k - 1) + (n - x * k) % k;     return t >= m;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     long long left = 0, right = (n + k - 1) / k;     while (left < right) {       long long mid = (left + right) >> 1;       if (works(mid)) {         right = mid;       } else {         left = mid + 1;       }     }     long long ans = binpow(2, left + 1);     ans = sub(ans, 2);     ans = mul(ans, k);     ans = add(ans, sub(m, left * k));     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, u, r;   long long a[40], b[40], k[40], p[40];   long long maxx = (long long)1 << 63;   long long eval() {     long long val = 0;     for (int i = 0; i < n; i++) {       val += a[i] * k[i];     }     return val;   }   void gen(int now, int last) {     if (now % 2 == u % 2) maxx = max(maxx, eval());     if (now < u) {       long long temp[40];       memcpy(temp, a, sizeof(a));       if (last == 1) {         for (int i = 0; i < n; i++) {           a[i] = temp[i] ^ b[i];         }         gen(now + 1, 0);       }       for (int i = 0; i < n; i++) {         a[i] = temp[p[i]] + r;       }       gen(now + 1, 1);     }   }   int main() {     cin >> n >> u >> r;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     for (int i = 0; i < n; i++) {       cin >> k[i];     }     for (int i = 0; i < n; i++) {       cin >> p[i];       p[i]--;     }     gen(0, 1);     cout << maxx << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 1e7 + 5;   int n, pos[N], ans1, ans2;   long long ans = 1e14;   int main() {     scanf( %d , &n);     for (int i = 1, x; i <= n; ++i) {       scanf( %d , &x);       if (pos[x]) {         if (x < ans) ans1 = pos[x], ans2 = i, ans = x;       } else         pos[x] = i;     }     for (int i = 1, tmp1, tmp2; i < N; ++i) {       if (i >= ans) break;       tmp1 = tmp2 = 0;       for (int j = i; j < N; j += i) {         if (!pos[j]) continue;         if (!tmp1)           tmp1 = j, tmp2 = pos[j];         else {           if (1LL * j / i * tmp1 < ans) {             ans = 1LL * j / i * tmp1, ans1 = pos[j], ans2 = tmp2;             break;           }         }       }     }     if (ans1 > ans2) ans1 ^= ans2 ^= ans1 ^= ans2;     printf( %d %d n , ans1, ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long arr[200010], tot = 0;   int main(void) {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (i > 0)         tot += abs(arr[i] - arr[i - 1]);       else         tot += abs(arr[i]);     }     cout << tot;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void swap(long long int &x, long long int &y) {     x = x ^ y;     y = x ^ y;     x = x ^ y;   }   template <typename T>   void print(T a) {     for (auto i = a.begin(); i != a.end(); i++) cout << *i <<    ;     cout << endl;   }   bool isVowel(char c) {     if (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ) return true;     return false;   }   void sync() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     sync();     long long int n;     cin >> n;     map<long long int, long long int> ck1, ck2;     map<pair<long long int, long long int>, long long int> ck3;     while (n--) {       long long int x, y;       cin >> x >> y;       ck1[x]++;       ck2[y]++;       ck3[{x, y}]++;     }     long long int ans = 0;     for (auto i = ck1.begin(); i != ck1.end(); i++) {       long long int x = i->second;       ans += ((x) * (x - 1) / 2);     }     for (auto i = ck2.begin(); i != ck2.end(); i++) {       long long int x = i->second;       ans += ((x) * (x - 1) / 2);     }     for (auto i = ck3.begin(); i != ck3.end(); i++) {       long long int x = i->second;       ans -= ((x) * (x - 1) / 2);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int k = 0;     int cnt = 0;     int ans = 0;     for (int i = 0; i < n; i++) {       int p;       cin >> p;       if (p > k)         cnt++;       else         cnt = 1;       k = p;       ans = max(cnt, ans);     }     cout << ans;   }


#include <bits/stdc++.h>   namespace solution {}   namespace solution {   class ISolution {    public:     virtual void init(){};     virtual bool input() { return false; };     virtual void output(){};     virtual int run() = 0;   };   }  // namespace solution   namespace solution {   using namespace std;   const long long MOD = 1000000000LL;   const int SIZE = 2 * 100000 + 11;   const int QUERY_SIZE = 2 * 100000 + 11;   int n, m;   long long A[SIZE];   long long F[SIZE];   void query_1() {     int x, v;     cin >> x >> v;     A[x] = v;   }   void query_2() {     int l, r;     cin >> l >> r;     int len = r - l + 1;     long long sum = 0;     for (int i = 0; i < len; ++i) sum = (sum + F[i] * A[l + i]) % MOD;     cout << sum << endl;   }   void solve() {     F[0] = F[1] = 1;     for (int i = 2; i < SIZE; ++i) F[i] = (F[i - 1] + F[i - 2]) % MOD;     for (int i = 0; i < m; ++i) {       int t;       cin >> t;       if (t == 1) {         query_1();       } else if (t == 2) {         query_2();       }     }   }   class Solution : public ISolution {    public:     bool input() {       if (!(cin >> n >> m)) return false;       for (int i = 0; i < n; ++i) cin >> A[i + 1];       return true;     }     int run() {       while (init(), input()) {         solve();         output();       }       return 0;     }   };   }  // namespace solution   int main() { return solution::Solution().run(); }


#include <bits/stdc++.h>   using namespace std;   double x1, yy1, x2, y2, v, t, vx, vy, wx, wy, l, r, mid, x, y, dis;   int main() {     scanf( %lf%lf , &x1, &yy1);     scanf( %lf%lf , &x2, &y2);     scanf( %lf%lf , &v, &t);     scanf( %lf%lf , &vx, &vy);     scanf( %lf%lf , &wx, &wy);     l = 0.0;     r = 1e9;     for (int i = 1; i <= 1000; ++i) {       mid = (l + r) / 2;       x = x2 - x1 - min(t, mid) * vx - max(0.0, mid - t) * wx;       y = y2 - yy1 - min(t, mid) * vy - max(0.0, mid - t) * wy;       dis = sqrt(x * x + y * y);       if (v * mid > dis)         r = mid;       else         l = mid;     }     printf( %.10lf n , l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 2;   struct {     int x;     int last;     string it;   } a;   struct kek {     string w, e, r, t;   };   map<char, int> bak;   vector<string> st[N + 5][7], q;   vector<pair<string, string> > be, en;   vector<kek> ans;   int n, m;   string ins;   char c;   bool frog = false;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     bak[ u ] = 1;     bak[ a ] = 2;     bak[ o ] = 3;     bak[ e ] = 4;     bak[ i ] = 5;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ins;       m = ins.length();       a.x = 0;       a.last = 0;       for (int j = 0; j < m; j++) {         if (ins[j] ==  u  || ins[j] ==  a  || ins[j] ==  o  || ins[j] ==  e  ||             ins[j] ==  i ) {           a.x++;           c = ins[j];           a.last = bak[c];         }       }       a.it = ins;       st[a.x][a.last].push_back(ins);     }     for (int i = 1; i <= N; i++) {       q.clear();       for (int j = 1; j <= 5; j++) {         int k;         for (k = 1; k < st[i][j].size(); k += 2) {           en.push_back({st[i][j][k], st[i][j][k - 1]});         }         if (k == st[i][j].size()) {           q.push_back(st[i][j][k - 1]);         }       }       for (int j = 1; j < q.size(); j += 2) {         be.push_back({q[j], q[j - 1]});       }     }     while (!be.empty() && !en.empty()) {       ans.push_back(           {be.back().first, en.back().first, be.back().second, en.back().second});       en.pop_back();       be.pop_back();     }     for (int i = 1; i < en.size(); i += 2) {       ans.push_back(           {en[i].first, en[i - 1].first, en[i].second, en[i - 1].second});     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i) {       cout << ans[i].w <<     << ans[i].e << endl            << ans[i].r <<     << ans[i].t << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int N = 300009;   void swap(char *p, char *q) {     char temp = *p;     *p = *q;     *q = temp;     return;   }   long long int powxy(long long int x, long long int y) {     if (y == 0) return 1;     if (y % 2 == 1) return (x * powxy(x, y - 1)) % MOD;     long long int t = powxy(x, y / 2) % MOD;     return (t * t) % MOD;   }   vector<pair<int, int> > adj[N];   int dp[500005];   vector<int> ans[500001];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int ans = 1;       string s;       long long int n;       cin >> n >> s;       string temp = s;       for (int i = 0; i < n; i++) {         if ((i + 1) % 2 != 0) {           string q = s.substr(0, i);           if ((n - i + 1) % 2 == 0) reverse(q.begin(), q.end());           string p = s.substr(i, n - i) + q;           if (p < temp) {             temp = p;             ans = i + 1;           }         } else {           string q = s.substr(0, i);           reverse(q.begin(), q.end());           if ((n - i + 1) % 2 != 0) reverse(q.begin(), q.end());           string p = s.substr(i, n - i) + q;           if (p < temp) {             temp = p;             ans = i + 1;           }         }       }       cout << temp <<   n ;       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &a) {     register int b = 1, c = getchar();     a = 0;     for (; !isdigit(c); c = getchar())       if (c == 45) b *= -1;     for (; isdigit(c); c = getchar()) a = (a << 3) + (a << 1) + c - 48;     a *= b;   }   const int maxn = 105;   const int maxm = 1 << 18;   long long dp[maxm][maxn];   string str;   int len;   int m;   int main() {     cin >> str;     len = int((str).size());     read(m);     dp[0][0] = 1;     for (int msk = 0; msk < int(1 << len); msk++) {       for (int rem = 0; rem < int(m); rem++) {         for (int j = 0; j < int(len); j++)           if (!(msk & (1 << j))) {             int nwrem = (rem * 10 + str[j] -  0 ) % m;             int nwmsk = msk | (1 << j);             if (!msk && str[j] ==  0 ) continue;             dp[nwmsk][nwrem] += dp[msk][rem];           }       }     }     long long ans = dp[(1 << len) - 1][0];     for (int i = 0; i < int(10); i++) {       int cnt = 0;       for (int j = 0; j < int(len); j++) {         if (str[j] == i + 48) cnt++;       }       long long fac = 1;       for (int j = 1; j <= cnt; j++) fac *= j;       ans /= fac;     }     printf( %I64d n , ans);     return 0;   }


#include<bits/stdc++.h>   #define ll long long int   using namespace std;       int main()    {     int t;     cin>>t;     while(t--)     {      ll a, b, c;      cin>>a>>b>>c;            if((a+b+c)%9 == 0 && min(a, min(b,c)) >= (a+b+c)/9)       cout<< YES <<endl;      else       cout<< NO <<endl;     }    }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     if (k % 2 == 1) {       cout << 1 << endl;       return 0;     }     long long x = log2(k);     long long y = pow(2, x) - k;     while (y != 0) {       x = log2(y);       y = pow(2, x) - y;     }     cout << x + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1000000007;   const long long N = 1e5;   long long expo(long long x, long long y) {     long long res = 1;     x = x % M;     while (y > 0) {       if (y & 1) res = (res * x) % M;       y = y >> 1;       x = (x * x) % M;     }     return (res) % M;   }   string binary(long long n) {     if (n == 0) return  0 ;     string s;     while (n > 0) {       if (n & 1)         s +=  1 ;       else         s +=  0 ;       n >>= 1;     }     reverse(s.begin(), s.end());     return s;   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6) {       if (n % i == 0 || n % (i + 2) == 0) return false;     }     return true;   }   long long ncr(long long n, long long r) {     if (r > n - r) r = n - r;     long long ans = 1;     for (long long k = 0; k < r; k++) {       ans *= (n - k);       ans /= (k + 1);     }     return ans;   }   void solve() {     long long n, d;     cin >> n >> d;     if (n >= d) {       cout <<  YES n ;       return;     }     long long val = n / 2 + ceil(d / (1.0 * (n / 2 + 1)));     if (val <= n) {       cout <<  YES n ;     } else {       cout <<  NO n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     ;     long long test = 1;     cin >> test;     while (test--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = (int)1e9 + 207;   const int N = (int)1e6 + 2;   long long n, m, s, t;   long long cnt1[N], cnt2[N];   long long D1[N], D2[N];   vector<pair<long long, long long> > G1[N], G2[N];   vector<pair<long long, pair<long long, long long> > > edge;   void solve1() {     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> >,                    greater<pair<long long, long long> > >         pq;     for (int i = 0; i <= n; i++) D1[i] = 1e14;     D1[s] = 0;     cnt1[s] = 1;     pq.push(pair<long long, long long>(D1[s], s));     while (!pq.empty()) {       long long du = pq.top().first;       long long u = pq.top().second;       pq.pop();       if (du != D1[u]) continue;       for (int i = 0; i < G1[u].size(); i++) {         long long v = G1[u][i].first;         long long w = G1[u][i].second;         if (D1[v] > du + w) {           D1[v] = du + w;           cnt1[v] = cnt1[u];           pq.push(pair<long long, long long>(D1[v], v));         } else if (D1[v] == du + w) {           cnt1[v] += cnt1[u];         }         cnt1[v] %= mod;       }     }   }   void solve2() {     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> >,                    greater<pair<long long, long long> > >         pq;     for (int i = 0; i <= n; i++) D2[i] = 1e14;     D2[t] = 0;     cnt2[t] = 1;     pq.push(pair<long long, long long>(D2[t], t));     while (!pq.empty()) {       long long du = pq.top().first;       long long u = pq.top().second;       pq.pop();       if (du != D2[u]) continue;       for (int i = 0; i < G2[u].size(); i++) {         long long v = G2[u][i].first;         long long w = G2[u][i].second;         if (D2[v] > du + w) {           D2[v] = du + w;           cnt2[v] = cnt2[u];           pq.push(pair<long long, long long>(D2[v], v));         } else if (D2[v] == du + w) {           cnt2[v] += cnt2[u];         }         cnt2[v] %= mod;       }     }   }   int main() {     cin >> n >> m >> s >> t;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       edge.push_back(pair<long long, pair<long long, long long> >(           w, pair<long long, long long>(u, v)));       G1[u].push_back(pair<long long, long long>(v, w));       G2[v].push_back(pair<long long, long long>(u, w));     }     solve1();     solve2();     for (int i = 0; i < m; i++) {       long long u = edge[i].second.first;       long long v = edge[i].second.second;       long long w = edge[i].first;       if (D1[u] + w + D2[v] == D1[t] &&           ((1LL * cnt1[u] * cnt2[v]) % mod) == cnt1[t]) {         cout <<  YES n ;       } else if (D1[u] + D2[v] + 1 < D1[t]) {         cout <<  CAN   << w - (D1[t] - D1[u] - D2[v] - 1) <<   n ;       } else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, w = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) w = -1;       c = getchar();     }     while (c <=  9  && c >=  0 ) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     return w == 1 ? x : -x;   }   int r[40][40], v[40][40], n, m, ans = -1e9, bin[40];   inline int F(int x, int y) { return r[x][y] ? -v[x][y] : v[x][y]; }   inline int query(int x, int y, int d) {     r[x][y] = d;     r[x + m][y] = r[m][y] ^ d;     r[x][y + m] = r[x][m] ^ d;     r[x + m][y + m] = r[m][y + m] ^ r[x][y + m];     return F(x, y) + F(x + m, y) + F(x, y + m) + F(x + m, y + m);   }   inline int query(int y, int d) {     int res = 0;     r[m][y] = d;     r[m][y + m] = r[m][m] ^ d;     res += F(m, y) + F(m, y + m);     for (int x = 1; x < m; x++) res += max(query(x, y, 0), query(x, y, 1));     return res;   }   inline int calc() {     int res = 0;     for (int x = 1; x <= n; x++) res += F(x, m);     for (int y = 1; y < m; y++) res += max(query(y, 0), query(y, 1));     return res;   }   int main() {     n = read();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) v[i][j] = read();     m = (n + 1) >> 1;     ans = -1e9;     bin[0] = 1;     for (int i = 1; i <= m + 1; i++) bin[i] = bin[i - 1] << 1;     for (int zt = 0; zt < bin[m]; zt++) {       for (int x = 1; x <= m; x++) r[x][m] = zt >> (x - 1) & 1;       for (int x = 1; x < m; x++) r[x + m][m] = r[m][m] ^ r[x][m];       ans = max(ans, calc());     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int maxn = 1e5 + 5;   const int Inf = 1e9 + 7;   int main() {     int a, b;     while (cin >> a >> b) {       if (a == 0 && b == 0) {         printf( NO n );       } else if (abs(a - b) <= 1) {         printf( YES n );       } else {         printf( NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   inline long long getint() {     long long _x = 0, _tmp = 1;     char _tc = getchar();     while ((_tc <  0  || _tc >  9 ) && _tc !=  - ) _tc = getchar();     if (_tc ==  - ) _tc = getchar(), _tmp = -1;     while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar();     return _x * _tmp;   }   inline long long add(long long _x, long long _y,                        long long _mod = 1000000007LL) {     _x += _y;     return _x >= _mod ? _x - _mod : _x;   }   inline long long sub(long long _x, long long _y,                        long long _mod = 1000000007LL) {     _x -= _y;     return _x < 0 ? _x + _mod : _x;   }   inline long long mul(long long _x, long long _y,                        long long _mod = 1000000007LL) {     _x *= _y;     return _x >= _mod ? _x % _mod : _x;   }   long long mypow(long long _a, long long _x, long long _mod) {     if (_x == 0) return 1LL;     long long _ret = mypow(mul(_a, _a, _mod), _x >> 1, _mod);     if (_x & 1) _ret = mul(_ret, _a, _mod);     return _ret;   }   void sleep(double sec = 1021) {     clock_t s = clock();     while (clock() - s < CLOCKS_PER_SEC * sec)       ;   }   int __ = 1, _cs;   int dp[702][10];   int fac[702 + 702], inv[702 + 702];   inline int C(int a, int b) { return mul(fac[a], mul(inv[b], inv[a - b])); }   int pp[702], ten[702 + 702];   int sv[702][10][702];   int sv2[702][10][702];   int iten[702 + 702];   int dpw[10][702];   void build() {     ten[0] = fac[0] = inv[0] = 1;     iten[0] = 1;     int inv10 = mypow(10, 1000000007LL - 2, 1000000007LL);     for (int i = 1; i < 702 + 702; i++) {       fac[i] = mul(fac[i - 1], i);       inv[i] = mypow(fac[i], 1000000007LL - 2, 1000000007LL);       ten[i] = mul(ten[i - 1], 10);       iten[i] = mul(iten[i - 1], inv10);     }     int inv9 = mypow(9, 1000000007LL - 2, 1000000007LL);     for (int i = 1; i < 702; i++) pp[i] = mul(sub(ten[i], 1), inv9);     for (int i = 1; i < 10; i++) {       dpw[i][0] = 1;       for (int j = 1; j < 702; j++) dpw[i][j] = mul(dpw[i][j - 1], i);     }     for (int k = 0; k < 702; k++)       for (int dgt = 1; dgt < 10; dgt++)         for (int i = 0; i <= k; i++) {           int tmp = 1;           tmp = mul(tmp, C(k, i));           tmp = mul(tmp, dpw[dgt][i]);           if (9 - dgt > 0) tmp = mul(tmp, dpw[9 - dgt][k - i]);           tmp = mul(tmp, ten[k - i]);           sv[k][dgt][i] = tmp;           if (i) sv[k][dgt][i] = add(sv[k][dgt][i], sv[k][dgt][i - 1]);         }     for (int k = 1; k < 702; k++)       for (int dgt = 1; dgt < 10; dgt++) {         if (dgt == 9) {           for (int i = 0; i < k; i++) {             int j = k - i;             if (dgt == 9 and i + j < k) continue;             int way = C(k, j);             way = mul(way, C(k - j, i));             way = mul(way, dpw[dgt][i]);             if (9 - dgt > 0) way = mul(way, dpw[9 - dgt][k - i - j]);             way = mul(way, ten[k - i - j]);             way = mul(way, pp[j]);             dp[k][dgt] = add(dp[k][dgt], mul(way, dgt));           }           continue;         }         for (int j = 1; j <= k; j++) {           int way = C(k, j);           way = mul(way, sv[k - j][dgt][k - j]);           way = mul(way, pp[j]);           dp[k][dgt] = add(dp[k][dgt], mul(way, dgt));         }       }   }   char c[702];   int ans, len;   void init() {     scanf( %s , c);     len = strlen(c);   }   int cnt[10];   void go(int bt, bool bnd) {     if (bt == len or not bnd) {       int res = len - bt;       if (res) {         int ps = 0;         for (int i = 9; i; i--) {           ans = add(ans, mul(dp[res][i], ten[ps]));           ps += cnt[i];         }       }       int ps = 0;       for (int i = 0; i < 10; i++) {         if (i) {           for (int j = 0; j <= res; j++) {             int way = sv2[res][i][j];             way = mul(way, ten[len - (ps + j) - cnt[i]]);             way = mul(way, pp[cnt[i]]);             ans = add(ans, mul(i, way));           }         }         ps += cnt[i];       }       return;     }     for (int i = 0; i <= c[bt] -  0 ; i++) {       if (bt == 0 and i == 0) continue;       cnt[i]++;       go(bt + 1, i == c[bt] -  0 );       cnt[i]--;     }   }   void solve() {     for (int res = 0; res < 702; res++)       for (int i = 1; i < 10; i++) {         for (int j = 0; j <= res; j++) {           int way = C(res, j);           way = mul(way, dpw[i][j]);           way = mul(way, dpw[10 - i][res - j]);           sv2[res][i][j] = way;         }       }     if (len > 1) {       for (int i = 1; i < 10; i++) ans = add(ans, dp[len - 1][i]);     }     go(0, true);     cout << ans << endl;   }   int main() {     build();     while (__--) {       init();       solve();     }   }