#include <bits/stdc++.h>   using namespace std;   string tolower(string str) {     for (int i = 0; i < str.size(); i++) str[i] = tolower(str[i]);     return str;   }   int main() {     int n;     cin >> n;     vector<string> store;     for (int i = 0; i < n; i++) {       string str;       cin >> str;       store.push_back(tolower(str));     }     string str, temp, ans =   ;     cin >> temp;     vector<int> color(temp.size());     str = tolower(temp);     char letter;     cin >> letter;     for (int i = 0; i < str.size(); i++) {       for (int j = 0; j < store.size(); j++) {         string& here = store[j];         if (i + here.size() <= str.size()) {           string substr = str.substr(i, here.size());           if (substr == here) {             for (int k = i; k < i + here.size(); k++) color[k] = 1;           }         }       }     }     char second = (letter ==  a ) ?  b  :  a ;     for (int i = 0; i < str.size(); i++) {       if (color[i])         ans += (str[i] == letter) ? second : letter;       else         ans += str[i];       if (isupper(temp[i])) ans[i] = toupper(ans[i]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int inp() {     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     int sum = 0;     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum;   }   int x[200010], s1, s2, n;   bool check(int lim) {     int l = -2147483647;     int r = 2147483647;     for (int i = n; i >= 1; i--) {       if (x[i] >= l && x[i] <= r) {         l = x[i] - lim;         r = x[i] + lim;       } else {         l = std::max(l, x[i] - lim);         r = std::min(r, x[i] + lim);       }     }     return (l <= s1 && s1 <= r) || (l <= s2 && s2 <= r);   }   int main() {     n = inp();     s1 = inp();     s2 = inp();     int l = abs(s1 - s2);     int r = 1e9;     for (int i = 1; i <= n; i++) {       x[i] = inp();       if (x[i] == x[i - 1]) {         i--;         n--;       }     }     while (l < r) {       int mid = (l + r) >> 1;       if (check(mid))         r = mid;       else         l = mid + 1;     }     printf( %d n , l);   }


#include <bits/stdc++.h>   using namespace std;   int dp[55][35555], n, m, a[35555], las[35555], pre[35555], now;   struct LT {     int mx, lazy;   } tr[517171];   void U(int x) { tr[x].mx = max(tr[x << 1].mx, tr[x << 1 | 1].mx); }   void D(int x) {     tr[x << 1].lazy += tr[x].lazy;     tr[x << 1].mx += tr[x].lazy;     tr[x << 1 | 1].lazy += tr[x].lazy;     tr[x << 1 | 1].mx += tr[x].lazy;     tr[x].lazy = 0;     U(x);   }   void rebuild(int x, int l, int r) {     tr[x].lazy = 0;     if (l == r) {       tr[x].mx = dp[now][l - 1];       return;     }     int mid = (l + r) >> 1;     rebuild(x << 1, l, mid);     rebuild(x << 1 | 1, mid + 1, r);     U(x);   }   void C(int x, int l, int r, int st, int en) {     if (l == st && r == en) {       tr[x].mx++;       tr[x].lazy++;       return;     }     D(x);     int mid = (l + r) >> 1;     if (st <= mid) C(x << 1, l, mid, st, min(en, mid));     if (en > mid) C(x << 1 | 1, mid + 1, r, max(st, mid + 1), en);     U(x);   }   int Q(int x, int l, int r, int st, int en) {     if (l == st && r == en) {       return tr[x].mx;     }     D(x);     int t = 0, mid = (l + r) >> 1;     if (st <= mid) t = max(t, Q(x << 1, l, mid, st, min(en, mid)));     if (en > mid) t = max(t, Q(x << 1 | 1, mid + 1, r, max(st, mid + 1), en));     return t;   }   int main() {     scanf( %d%d , &n, &m);     memset(las, 0, sizeof(las));     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       pre[i] = las[a[i]];       las[a[i]] = i;     }     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= m; i++) {       now = i - 1;       rebuild(1, 1, n);       for (int j = 1; j <= n; j++) {         C(1, 1, n, pre[j] + 1, j);         dp[i][j] = Q(1, 1, n, 1, j);       }     }     printf( %d , dp[m][n]);   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0, f = 1, ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       x = (x << 1) + (x << 3) + ch -  0 , ch = getchar();     return f * x;   }   const long long maxn = 1000100, inf = 1000000000000000LL, mod = 998244353;   long long n, m, a[maxn];   long long x, y, c;   long long f[maxn], d[maxn], g[maxn], del[maxn], Max[maxn], mi[20], flag[maxn],       level;   pair<long long, long long> ch(long long x) {     for (long long i = (0); i <= (11); i++)       if (x < mi[i]) return make_pair(i, x - mi[i]);   }   void upp(long long o) {     while (f[o] > 0) {       g[o]++;       Max[o] = f[o] = Max[o] + mi[g[o] - 1] - mi[g[o]];     }   }   void pushdown(long long x) {     if (del[x]) {       Max[x << 1] += del[x], Max[x << 1 | 1] += del[x];       if (d[x << 1])         f[x << 1] += del[x], upp(x << 1);       else         del[x << 1] += del[x];       if (d[x << 1 | 1])         f[x << 1 | 1] += del[x], upp(x << 1 | 1);       else         del[x << 1 | 1] += del[x];       del[x] = 0;     }     if (d[x]) {       Max[x << 1] = Max[x << 1 | 1] = f[x];       del[x << 1] = del[x << 1 | 1] = 0;       g[x << 1] = g[x << 1 | 1] = g[x];       d[x << 1] = d[x << 1 | 1] = 1;       f[x << 1] = f[x << 1 | 1] = f[x];       d[x] = 0;       f[x] = 0;     }   }   void updata(long long x) {     Max[x] = max(Max[x << 1], Max[x << 1 | 1]);     g[x] = (Max[x << 1] > Max[x << 1 | 1]) ? g[x << 1] : g[x << 1 | 1];     if (flag[x << 1] && flag[x << 1 | 1] && Max[x << 1] == Max[x << 1 | 1] &&         g[x << 1] == g[x << 1 | 1])       flag[x] = 1;     else       flag[x] = 0;   }   long long query(long long l, long long r, long long o) {     if (l > y || r < x) return -inf;     if (l >= x && r <= y) {       level = g[o];       return Max[o];     }     pushdown(o);     return max(query(l, ((l + r) >> 1), o << 1),                query(((l + r) >> 1) + 1, r, o << 1 | 1));   }   void change(long long l, long long r, long long o) {     if (l > y || r < x) return;     if (l >= x && r <= y) {       d[o] = 1;       flag[o] = 1;       del[o] = 0;       pair<long long, long long> x = ch(c);       f[o] = x.second;       Max[o] = x.second;       g[o] = x.first;       return;     }     pushdown(o);     change(l, ((l + r) >> 1), o << 1);     change(((l + r) >> 1) + 1, r, o << 1 | 1);     updata(o);   }   void Change(long long l, long long r, long long o) {     if (l > y || r < x) return;     if (l >= x && r <= y) {       Max[o] += c;       if (d[o]) {         f[o] += c;         if (f[o] > 0) {           while (Max[o] > 0) {             g[o]++;             Max[o] = f[o] = Max[o] + mi[g[o] - 1] - mi[g[o]];           }         }       } else         del[o] += c;       return;     }     pushdown(o);     Change(l, ((l + r) >> 1), o << 1);     Change(((l + r) >> 1) + 1, r, o << 1 | 1);     updata(o);   }   void upgrade(long long l, long long r, long long o) {     if (flag[o]) {       while (Max[o] > 0) {         g[o]++;         Max[o] = Max[o] + mi[g[o] - 1] - mi[g[o]];       }       return;     }     pushdown(o);     if (Max[o << 1] > 0) upgrade(l, ((l + r) >> 1), o << 1);     if (Max[o << 1 | 1] > 0) upgrade(((l + r) >> 1) + 1, r, o << 1 | 1);     updata(o);   }   void build(long long l, long long r, long long o) {     if (l == r) {       flag[o] = 1;       pair<long long, long long> x = ch(a[l]);       Max[o] = x.second;       g[o] = x.first;       flag[o] = 1;       return;     }     build(l, ((l + r) >> 1), o << 1);     build(((l + r) >> 1) + 1, r, o << 1 | 1);     updata(o);   }   int main() {     n = read();     m = read();     mi[0] = 1;     for (long long i = (1); i <= (11); i++) mi[i] = mi[i - 1] * 42;     for (long long i = (1); i <= (n); i++) a[i] = read();     build(1, n, 1);     while (m--) {       long long ch = read();       if (ch == 1) {         y = x = read();         printf( %I64d n , query(1, n, 1) + mi[level]);       }       if (ch == 2) {         x = read(), y = read(), c = read();         change(1, n, 1);       }       if (ch == 3) {         x = read(), y = read(), c = read();         do {           Change(1, n, 1);           upgrade(1, n, 1);           if (Max[1] < 0) break;         } while (1);       }     }     return 0;   }


//  zukonit14 - Kunal Raut      #include<bits/stdc++.h>   using namespace std;      // #include  ext/pb_ds/assoc_container.hpp    // #include  ext/pb_ds/tree_policy.hpp    // using namespace __gnu_pbds;      // template<class T>   // using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;      // template<class key, class value, class cmp = std::less<key>>   // using omap = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;   // find_by_order(k)  returns iterator to kth element starting from 0;   // order_of_key(k) returns count of elements strictly smaller than k;      /*/-----------------------------DEFINES----------------------------------/*/      #define ll                  long long   #define ld                  long double   #define pb                  push_back   #define mp                  make_pair   #define fi                  first   #define se                  second   #define pi                  3.1415926535   #define all(v)              v.begin(), v.end()   #define allr(v)             v.rbegin(), v.rend()   #define ms(s, n)            memset(s, n, sizeof(s))   #define prec(n)             fixed<<setprecision(n)   #define forci(p,n)          for(ll i=p;i<(ll)n;i++)   #define forcj(p,n)          for(ll j=p;j<(ll)n;j++)   #define forc(i,p,n)            for(ll i=p;i<(ll)n;i++)   #define bolt                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);   #define bits(a)             __builtin_popcountll(a)   #define djokovic            freopen( input00.txt ,  r , stdin);freopen( output00.txt ,  w , stdout);   #define inrange(i,a,b)      ((i>=min(a,b)) && (i<=max(a,b)))   #define sz(a)               (ll)a.size()   #define sum(a)              ( accumulate ((a).begin(), (a).end(), 0ll))   #define mine(a)             (*min_element((a).begin(), (a).end()))   #define maxe(a)             (*max_element((a).begin(), (a).end()))   #define mini(a)             ( min_element((a).begin(), (a).end()) - (a).begin())   #define maxi(a)             ( max_element((a).begin(), (a).end()) - (a).begin())   #define lowb(a, x)          ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())   #define uppb(a, x)          ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())   clock_t time_p              = clock();   void rtime()                {time_p = clock() - time_p; cout <<   nTime Taken :   << fixed << (float)(time_p) / CLOCKS_PER_SEC <<  s n ;}         /*/-----------------------------INLINE FUNCTIONS----------------------------------/*/      inline ll gcd(ll a, ll b)          {if (b == 0) return a;    return gcd(b, a % b);}   inline ll lcm(ll a, ll b)          {return (a / gcd(a, b) * b);}   inline bool isprime(ll n)            {ll i; for (i = 2; i <= sqrt(n); i++) {if (n % i == 0)return false;} return true;}   inline ll ceil(ll num, ll den)      {return ((num + den - 1) / den);}      /*/-----------------------------TRACE FUNCTIONS----------------------------------/*/      template<class T> ostream& operator<<(ostream &os, string V) {       os <<  [  ;       for (auto v : V) os << v <<    ;       return os <<  ] ;   }   template<class T> ostream& operator<<(ostream &os, vector<T> V) {       os <<  [  ;       for (auto v : V) os << v <<    ;       return os <<  ] ;   }   template<class T> ostream& operator<<(ostream &os, set<T> S) {       os <<  {  ;       for (auto s : S) os << s <<    ;       return os <<  } ;   }   template<class T> ostream& operator<<(ostream &os, multiset<T> S) {       os <<  {  ;       for (auto s : S) os << s <<    ;       return os <<  } ;   }   template<class T, class T1> ostream& operator<<(ostream &os, map<T, T1> S) {       os <<  {  ;       for (auto s : S) os <<  (  << s.first <<  ,  << s.second <<  )  ;       return os <<  } ;   }   template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) {       return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   #define tracearr(a,n)  {cout << #a<<  :  ;cout<< [  ;for (ll i = 0; i < n; i++) cout << a[i] <<    ;cout <<  ] n ;}   #define TRACE   #ifdef TRACE   #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {       cout << name <<   :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {       const char* comma = strchr(names + 1,  , );       cout.write(names, comma - names) <<   :   << arg1 <<   |  ;       __f(comma + 1, args...);   }   #else   #define trace(...)   #endif      /*/-----------------------------MODULAR ARITHMETIC----------------------------------/*/      // const ll modx = 1e9 + 7;   const ll modx = 998244353;   const ll mod = modx;   inline ll add(ll x, ll y, ll mod = modx) {       x += y;       if (x >= mod) return x - mod;       return x % mod;   }   inline ll sub(ll x, ll y, ll mod = modx) {       x -= y;       if (x < 0) return x + mod;       return x;   }   inline ll mul(ll x, ll y, ll mod = modx) {       return (x * 1ll * y) % mod;   }   inline ll expo(ll x, ll y, ll mod = modx) {       ll ans = 1;       while (y) {           if (y & 1) ans = mul(ans, x, mod);           x = mul(x, x, mod);           y >>= 1;       }       return ans % mod;   }   inline ll inv(ll x, ll mod = modx) {       return expo(x, mod - 2, mod);   }   /*/-----------------------------CODE BEGINS----------------------------------/*/   #define int long long   ll rr[] = {0, 1, 1, 1, 0, -1, -1, -1};   ll cc[] = {1, 1, 0, -1, -1, -1, 0, 1};  //x-y -> URDL , row-column -> RDLU; 0-based;      const ll MAXN = 2e5 + 100, MAX2N = 2e3 + 10, LG = 20, INF = 2e18, base = 33;   const int N = 1e5 + 5;   ll n, m, k, q, x,  y, z, a[MAXN], d[MAXN], p[MAXN], vis[MAXN];   vector<ll>g[MAXN]; ll dp[MAXN];   void fill()   {       for (ll i = 0; i <= n; i++)           d[i] = -1, p[i] = -1, dp[i] = 0, g[i].clear(), vis[i] = 0;   }   void dijkstra(ll s) {       d[s] = 0;       queue<ll>q;       q.push(s);       while (!q.empty()) {           ll v = q.front();           q.pop();           for (auto u : g[v])           {               if (d[u] == -1)               {                   d[u] = d[v] + 1;                   q.push(u);               }           }       }   }   void dfs(ll s)   {       vis[s] = 1;       dp[s] = d[s];       for (auto to : g[s])       {           if (!vis[to] && d[s] < d[to]) {               dfs(to);           }           if (d[s] < d[to])               dp[s] = min(dp[s], dp[to]);           else               dp[s] = min(dp[s], d[to]);       }   }   void solve()   {       cin >> n >> m;       fill();       for (ll i = 0; i < m; i++)       {           ll u, v; cin >> u >> v; --u, --v;           g[u].pb(v);       }       dijkstra(0);       dfs(0);       for (ll i = 0; i < n; i++)           cout << dp[i] <<    ;       cout <<   n ;   }   signed main()   {       bolt;   #ifndef ONLINE_JUDGE       djokovic;   #endif       ll t;       t = 1;       cin >> t;       for (ll i = 1; i <= t; i++)       {           //cout <<  Case #  << i <<  :  ;           solve();       }       //rtime();   }


#include <bits/stdc++.h>   using namespace std;   string s;   map<string, bool> vis;   void ReadCube(string cube) {     int _4D[4][6] = {{0, 1, 2, 3, 4, 5},                      {0, 3, 2, 1, 5, 4},                      {0, 5, 2, 4, 1, 3},                      {0, 4, 2, 5, 3, 1}};     for (int i = 0; i < 4; ++i) {       string x(6,    );       for (int j = 0; j < 6; ++j) {         x[j] = cube[_4D[i][j]];       }       vis[x] = true;     }   }   void rotate90() {     swap(s[0], s[1]);     swap(s[1], s[2]);     swap(s[2], s[3]);     ReadCube(s);   }   void Left(string c) {     int p[] = {5, 1, 4, 3, 0, 2};     string x(6,    );     for (int i = 0; i < 6; ++i) {       x[i] = c[p[i]];     }     ReadCube(x);   }   void Right(string c) {     int p[] = {4, 1, 5, 3, 2, 0};     string x(6,    );     for (int i = 0; i < 6; ++i) {       x[i] = c[p[i]];     }     ReadCube(x);   }   int main() {     cin >> s;     int ans = 0;     sort(s.begin(), s.end());     do {       if (vis[s]) continue;       for (int i = 0; i < 4; ++i) {         rotate90();       }       Left(s);       Right(s);       ans++;     } while (next_permutation(s.begin(), s.end()));     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;       #define MAXN (int)(1e5 + 5)   #define MAXL 20   #define F first   #define S second   #define endl   n    #define MOD (lli)(1e9 + 9)   #define MOD2 (lli)(1e9 + 7)   #define lli long long int   #define sz(a) int(a.size())   #define DEBUG if (0) cout <<  aqui  << endl;   #define PI 2 * acos(0.0)   typedef pair<int, lli> ii;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};   int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};      int t;      int main(){     ios_base::sync_with_stdio(false);     cin.tie(NULL);        cin >> t;        while(t--) {       int k, n, m;       cin >> k >> n >> m;       vector<int> vec, vec2;          for(int i=0;i<n;i++) {         int a;         cin >> a;         vec.push_back(a);       }          for(int i=0;i<m;i++) {         int a;         cin >> a;         vec2.push_back(a);       }          vector<int> ans;       int a = 0, b = 0;       bool nono = false;       while(a < sz(vec) or b < sz(vec2)) {         bool at = false;            if(b < sz(vec2)) {           if(!vec2[b] or (a < sz(vec) && vec2[b] < vec[a])) at = true;         }            if(!at && a < sz(vec)) {           ans.push_back(vec[a]);           a++;         } else if(b < sz(vec2)) {           ans.push_back(vec2[b]);           b++;         }       }          int atual = k;       for(auto i : ans) {         if(!i) atual++;         else if(i > atual) nono = true;       }             if(nono) {         cout << -1 << endl;         continue;       }          for(auto i : ans) cout << i <<    ;       cout << endl;        }           return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-8;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const long long INF = 1e18;   long long power(long long x, long long y) {     long long t = 1;     while (y > 0) {       if (y % 2)         y -= 1, t = t * x % mod;       else         y /= 2, x = x * x % mod;     }     return t;   }   long long I[100][100], temp[100][100], M[100][100], store[100][100];   void copyM(long long M1[][100], long long M2[][100], int m) {     for (int i = 0; i < m; ++i) {       for (int j = 0; j < m; ++j) {         M2[i][j] = M1[i][j];       }     }   }   void matmul(long long M1[][100], long long M2[][100], int m) {     for (int i = 0; i < m; ++i) {       for (int j = 0; j < m; ++j) {         temp[i][j] = 0;         for (int k = 0; k < m; ++k)           temp[i][j] = (temp[i][j] + (M2[i][k] * M1[k][j]) % mod) % mod;       }     }   }   void setI(int m) {     for (int i = 0; i < m; ++i) {       for (int j = 0; j < m; ++j) {         if (i != j)           I[i][j] = 0;         else           I[i][j] = 1;       }     }   }   void powerM(long long M1[][100], int m, long long n) {     setI(m);     while (n > 0) {       if (n % 2 == 0) {         matmul(M1, M1, m);         copyM(temp, M1, m);         n /= 2;       } else {         matmul(M1, I, m);         copyM(temp, I, m);         n -= 1;       }     }   }   long long t[105];   int main() {     int n, b, k, x;     scanf( %d%d%d%d , &n, &b, &k, &x);     memset(M, 0, sizeof(M));     for (int i = 0; i < n; ++i) {       int p;       scanf( %d , &p);       p %= x;       t[p]++;     }     for (int i = 0; i < x; ++i)       for (int j = 0; j < x; ++j) {         M[i][(i * 10 + j) % x] += t[j];       }     powerM(M, x, b);     printf( %lld n , I[0][k]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     int n;     cin >> n;     vector<long long> l(n + 1), t(n + 1);     l[0] = 0;     t[0] = 0;     for (int i = 1; i <= n; i++) {       char c;       cin >> c;       l[i] = l[i - 1];       t[i] = t[i - 1];       if (c ==  L )         l[i]--;       else if (c ==  R )         l[i]++;       else if (c ==  U )         t[i]++;       else         t[i]--;     }     long long low = 0;     long long high = 1000000000LL * 1000000000LL * 4;     long long mid;     while (low < high) {       mid = (low + high) / 2;       long long tempx = (mid / n) * l[n] + l[mid % n];       long long tempy = (mid / n) * t[n] + t[mid % n];       if (abs(x1 + tempx - x2) + abs(y1 + tempy - y2) <= mid) {         high = mid;       } else {         low = mid + 1;       }     }     mid = low;     long long tempx = (mid / n) * l[n] + l[mid % n];     long long tempy = (mid / n) * t[n] + t[mid % n];     if (abs(x1 + tempx - x2) + abs(y1 + tempy - y2) <= mid)       cout << mid << endl;     else       cout << -1 << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 1200031;   int n, ar[N], w[N];   int gcd(int a, int b) {     while (a && b) a > b ? a %= b : b %= a;     return a + b;   }   vector<pair<int, int> > edges;   vector<int> entries[N];   int sz[N];   long long ANS[N];   vector<int> interesting;   long long cur_pairs;   void run_cleanup() {     for (int i = 0; i < interesting.size(); i++) {       int id = interesting[i];       sz[id] = 1;       w[id] = id;     }   }   int get(int x) {     interesting.push_back(x);     if (x == w[x]) return x;     return w[x] = get(w[x]);   }   long long F(int x) { return 1ll * x * (x - 1) / 2; }   void merge(int a, int b) {     a = get(a);     b = get(b);     if (a == b) return;     cur_pairs -= F(sz[a]);     cur_pairs -= F(sz[b]);     w[a] = b;     sz[b] += sz[a];     cur_pairs += F(sz[b]);   }   vector<int> divs[N];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ar[i];     }     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       edges.push_back(make_pair(a, b));     }     for (int i = 0; i < edges.size(); i++) {       int here = gcd(ar[edges[i].first], ar[edges[i].second]);       entries[here].push_back(i);     }     for (int i = 1; i <= n; i++) {       w[i] = i;       sz[i] = 1;     }     for (int i = 1; i <= 200000; i++) {       interesting.clear();       cur_pairs = 0;       for (int j = i; j <= 200000; j += i) {         for (int q = 0; q < entries[j].size(); q++) {           int id = entries[j][q];           merge(edges[id].first, edges[id].second);         }       }       ANS[i] = cur_pairs;       run_cleanup();     }     for (int i = 1; i <= 200000; i++) {       for (int j = i * 2; j <= 200000; j += i) divs[j].push_back(i);     }     for (int i = 200000; i; --i) {       for (int j = 0; j < divs[i].size(); j++) {         int p = divs[i][j];         ANS[p] -= ANS[i];       }     }     for (int i = 1; i <= n; i++) {       ANS[ar[i]]++;     }     for (int i = 1; i <= 200000; i++) {       if (ANS[i]) cout << i <<     << ANS[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   int a, n;   int main() {     scanf( %d %d , &n, &a);     int res = 0;     if (a % 2 == 1)       printf( %d n , a / 2 + a % 2);     else       printf( %d n , n / 2 - a / 2 + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int compare(const void* a, const void* b) { return (*(int*)a - *(int*)b); }   int main() {     int n;     long long k, sum2, sum3;     int a[100005], c[100005];     long long b[100005];     int i, j, count;     cin >> n;     cin >> k;     for (i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     count = 0;     for (i = 0; i < n; i++) {       j = i;       while (a[j] == a[i] && j < n) j++;       b[count] = j - i;       c[count] = a[i];       count++;       i = j - 1;     }     sum2 = 0;     for (i = 0; i < count; i++) {       if (sum2 + b[i] * n >= k) {         sum3 = 0;         for (j = 0; j < count; j++) {           sum3 += (b[i] * b[j]);           if (sum2 + sum3 >= k) {             printf( %d %d , c[i], c[j]);             return 0;           }         }       } else         sum2 += (b[i] * n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x, y, z, t1, t2, t3;   int main() {     scanf( %lld%lld%lld%lld%lld%lld , &x, &y, &z, &t1, &t2, &t3);     puts(abs(x - y) * t1 >= abs(x - y) * t2 + abs(x - z) * t2 + 3 * t3 ?  YES                                                                         :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, l, r, k, c, i;   string s;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     if (n == 0) {       cout <<  a             <<   n ;       return 0;     }     while (n > 0) {       l = 1;       r = 100000;       k++;       while (l < r) {         c = (l + r) / 2;         if (c * (c - 1) / 2 > n)           r = c;         else           l = c + 1;       }       if (l * (l - 1) / 2 > n) l--;       n -= (l * (l - 1) / 2);       for (i = 1; i <= l; i++) s += char(96 + k);     }     cout << s <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const long long MAX = 100005;   const long double PI = 3.14159265359;   const long double G = 9.807;   const long long INF = 1e18;   const long double EPS = 1e-6;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   bool isprime(long long a) {     if (a == 2) return 1;     if (!(a & 1)) return 0;     for (long long i = 3; i * i <= a; i += 2)       if (a % i == 0) return 0;     return 1;   }   long long mpow(long long base, long long exponent, long long modulus) {     if (modulus == 1) return 0;     long long result = 1;     base = base % modulus;     while (exponent) {       if (exponent % 2 == 1) result = (result * base) % modulus;       exponent = exponent >> 1;       base = (base * base) % modulus;     }     return result;   }   long long minv(long long a, long long mod) {     long long _gcd = gcd(a, mod);     assert(_gcd == 1);     return mpow(a, mod - 2, mod);   }   long long t;   long long dp[35];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> t;     while (t--) {       long long d, mod;       cin >> d >> mod;       long long temp = d;       long long mxb = 0;       memset(dp, 0, sizeof dp);       for (long long i = 0; i <= 32; ++i) {         long long p = (1LL << i);         if (p > temp) {           mxb = i;           break;         }       }       long long ans = 1 % mod;       dp[1] = 1 % mod;       for (long long i = 2; i <= mxb; ++i) {         long long nums = mpow(2LL, i - 1, mod);         if (i == mxb) {           nums = d - mpow(2LL, i - 1, mod) + 1;           nums += mod;           nums %= mod;         }         dp[i] += nums;         dp[i] %= mod;         for (long long j = i - 1; j >= 1; --j) {           dp[i] += dp[j] * nums % mod;           dp[i] %= mod;         }         ans += dp[i];         ans %= mod;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T smin(T &a, const T &b) {     return a > b ? a = b : a;   }   template <typename T>   inline T smax(T &a, const T &b) {     return a < b ? a = b : a;   }   inline void add(long long &l, const long long &r) {     l = (l + r) % (long long)10139;   }   long long gcd(long long v, long long u) { return u ? gcd(u, v % u) : v; }   long long po(long long v, long long u) {     return u ? (po(v * v % (long long)10139, u >> 1) * (u & 1 ? v : 1) %                 (long long)10139)              : 1;   }   int n, m;   int p[200010];   pair<long long, pair<int, int>> ed[200010];   vector<int> adj[200010];   const int lca_LG = 20;   int lca_par[lca_LG][200010], lca_level[200010], lca_cost[lca_LG][200010];   inline int oo(int v, int u) {     return ed[v].second.second + ed[v].second.first - u;   }   void lca_dfs(int lca_v, int lca_papa = 0) {     lca_par[0][lca_v] = lca_papa;     lca_level[lca_v] = lca_level[lca_papa] + 1;     for (auto lca_e : adj[lca_v]) {       if (oo(lca_e, lca_v) != lca_papa) {         lca_cost[0][oo(lca_e, lca_v)] = ed[lca_e].first;         lca_dfs(oo(lca_e, lca_v), lca_v);       }     }   }   int get_lca(int lca_v, int lca_u) {     int res = 0;     if (lca_level[lca_v] < lca_level[lca_u]) {       swap(lca_v, lca_u);     }     for (int i = lca_LG - 1; ~i; i--) {       if (lca_level[lca_par[i][lca_v]] >= lca_level[lca_u]) {         smax(res, lca_cost[i][lca_v]);         lca_v = lca_par[i][lca_v];       }     }     if (lca_v == lca_u) {       return res;     }     for (int i = lca_LG - 1; ~i; i--) {       if (lca_par[i][lca_v] != lca_par[i][lca_u]) {         smax(res, lca_cost[i][lca_v]);         smax(res, lca_cost[i][lca_u]);         lca_v = lca_par[i][lca_v];         lca_u = lca_par[i][lca_u];       }     }     smax(res, lca_cost[0][lca_v]);     smax(res, lca_cost[0][lca_u]);     return res;   }   int get_p(int v) {     if (p[v]) return p[v] = get_p(p[v]);     return v;   }   bool merge(int v, int u) {     v = get_p(v);     u = get_p(u);     if (v == u) return false;     p[v] = u;     return true;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++)       cin >> ed[i].second.first >> ed[i].second.second >> ed[i].first;     sort(ed, ed + m);     long long nc = n, cost = 0;     for (int i = 0; i < m; i++) {       if (merge(ed[i].second.first, ed[i].second.second)) {         cost += ed[i].first;         nc--;         adj[ed[i].second.first].push_back(i);         adj[ed[i].second.second].push_back(i);       }     }     if (nc == 1) {       lca_dfs(1);       for (int i = 1; i < lca_LG; i++) {         for (int j = 1; j <= n; j++) {           lca_par[i][j] = lca_par[i - 1][lca_par[i - 1][j]];           lca_cost[i][j] =               max(lca_cost[i - 1][j], lca_cost[i - 1][lca_par[i - 1][j]]);         }       }     }     int q;     cin >> q;     while (q--) {       int v, u;       cin >> v >> u;       if (nc > 2) {         cout << -1 <<   n ;         continue;       }       if (nc == 2) {         if (get_p(v) == get_p(u)) {           cout << -1 <<   n ;           continue;         }         cout << cost <<   n ;         continue;       }       cout << cost - get_lca(v, u) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     std::cout.tie(NULL);     ;     string s;     getline(cin, s);     long long int ans = 0, cur = 0;     int sg = +1;     for (int i = (0); i < (int((s).size())); i += (1)) {       if (s[i] ==  +  || s[i] ==  - ) {         ans += sg * cur;         cur = 0;       }       if (s[i] ==  + ) sg = +1;       if (s[i] ==  - ) sg = -1;       cur = (cur * 10) + (s[i] -  0 );       if (i == int((s).size()) - 1) {         ans += sg * cur;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 2e5 + 5;   int mark[2][M];   int h[2][M];   int32_t main() {     ios_base::sync_with_stdio(false);     ;     int n, k;     cin >> n >> k;     for (int i = 0; i < 2; i++) {       string s;       cin >> s;       for (int j = 0; j < n; j++)         if (s[j] ==  X ) mark[i][j] = 1;     }     mark[0][0] = 1;     queue<pair<int, int> > q;     q.push(make_pair(0, 0));     while (q.size()) {       int x = (q.front()).first;       int y = (q.front()).second;       if (y >= n) return cout <<  YES  << endl, 0;       int t = h[x][y];       for (int i = 0; i < 2; i++)         if (!mark[i][t]) mark[i][t] = 1;       if (!mark[x][y + 1]) {         h[x][y + 1] = h[x][y] + 1;         mark[x][y + 1] = 1;         q.push(make_pair(x, y + 1));       }       if (y > 0 && !mark[x][y - 1]) {         h[x][y - 1] = h[x][y] + 1;         mark[x][y - 1] = h[x][y] + 1;         q.push(make_pair(x, y - 1));       }       if (!mark[1 - x][y + k]) {         h[1 - x][y + k] = h[x][y] + 1;         mark[1 - x][y + k] = 1;         q.push(make_pair(1 - x, y + k));       }       q.pop();     }     return cout <<  NO  << endl, 0;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   int n;   vector<int> a[200];   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;     cin >> n;     int k = (1 + sqrt(1 + 8 * n)) / 2, x = 1;     cout << k << endl;     for (int i = 1; i <= k; i++) {       for (int j = i + 1; j <= k; j++) {         a[i].push_back(x);         a[j].push_back(x);         x++;       }     }     for (int i = 1; i <= k; i++) {       int m = a[i].size();       for (int j = 0; j < m; j++) {         cout << a[i][j] << (j == m - 1 ?   n  :    );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[100000];   vector<int> hs;   bool possible(int wantvalue, int maxcost) {     const int nhs = hs.size();     long long cost = 0;     int i = 0;     for (int j = 0; j <= nhs; j++) {       while (j - i > wantvalue) {         cost -= (hs[j - 1] - hs[i]);         i++;       }       if (j - i >= wantvalue && cost <= (long long)maxcost) return true;       if (j - i > 0 && j < nhs) {         cost += (long long)(hs[j] - hs[j - 1]) * (j - i);       }     }     return false;   }   void dfs(int v, int parent, int height) {     if (parent != -1) hs.push_back(height);     for (int i = 0; i < (int)adj[v].size(); i++) {       int v2 = adj[v][i];       if (v2 == parent) continue;       dfs(v2, v, height + 1);     }   }   int main(int argc, char** argv) {     int m, k, p;     scanf( %d %d %d , &m, &k, &p);     for (int i = 0; i < m - 1; i++) {       int a, b;       scanf( %d %d , &a, &b);       a--, b--;       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs(0, -1, 0);     sort(hs.begin(), hs.end());     int l = 0, r = k;     while (l < r) {       int mid = (l + r + 1) / 2;       if (possible(mid, p))         l = mid;       else         r = mid - 1;     }     printf( %d n , l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double Ax, Ay, Bx, By, Cx, Cy, a11, a12, a21, a22, det;   bool flag;   void f(double x, double y) {     double tx, ty;     tx = a11 * x + a12 * y;     ty = a21 * x + a22 * y;     cerr << tx <<     << ty <<   n ;     tx = fabs(tx);     ty = fabs(ty);     tx += 1e-11;     ty += 1e-11;     tx -= (long long)tx;     ty -= (long long)ty;     if (flag) {       tx = x;       ty = y;     }     if (fabs(tx) < 1e-10 && fabs(ty) < 1e-10) {       cout <<  YES n ;       exit(0);     }   }   int main() {     cin >> Ax >> Ay >> Bx >> By >> Cx >> Cy;     det = Cx * Cx + Cy * Cy;     flag = fabs(det) < 1e-10;     a11 = Cx / det;     a12 = Cy / det;     a21 = -Cy / det;     a22 = Cx / det;     f(Bx - Ax, By - Ay);     f(Bx - Ay, By + Ax);     f(Bx + Ax, By + Ay);     f(Bx + Ay, By - Ax);     cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a, b, d1, d2;   int main() {     int n, l;     cin >> n >> l;     a.resize(n);     b.resize(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 0; i < n; ++i) {       cin >> b[i];     }     a.push_back(l + a[0]);     b.push_back(l + b[0]);     for (int i = 1; i <= n; ++i) {       d1.push_back(a[i] - a[i - 1]);       d2.push_back(b[i] - b[i - 1]);     }     for (int i = 0; i < n; i++) {       bool flag = 1;       for (int j = 0; j < n; j++) {         if (d1[j] != d2[(j + i) % n]) {           flag = 0;           break;         }       }       if (flag) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long dp[11][2][1010][1010];   string s, t;   long long bt(int K, bool f, int a, int b) {     if (K == 0) return 0;     long long& ref = dp[K][f][a][b];     if (ref != -1) return ref;     ref = INT_MIN;     if (f) {       ref = bt(K - 1, 0, a, b);       if (a < s.size() && b < t.size() && s[a] == t[b])         ref = max(ref, 1 + bt(K, 1, a + 1, b + 1));     } else {       if (a < s.size()) ref = bt(K, 0, a + 1, b);       if (b < t.size()) ref = max(ref, bt(K, 0, a, b + 1));       if (a < s.size() && b < t.size() && s[a] == t[b])         ref = max(ref, 1 + bt(K, 1, a + 1, b + 1));     }     return ref;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int N, M, K;     cin >> N >> M >> K;     cin >> s >> t;     memset(dp, -1, sizeof dp);     assert(bt(K, 0, 0, 0) >= K);     cout << bt(K, 0, 0, 0) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void model(vector<int>& a, const vector<pair<int, int> >& v) {     for (pair<int, int> p : v) swap(a[p.first], a[p.second]);   }   bool check(int n, const vector<pair<int, int> >& v) {     vector<int> a(n);     for (int i = 0; i < n; ++i) a[i] = i;     model(a, v);     for (int i = 0; i < n; ++i)       if (a[i] != i) return false;     return true;   }   vector<pair<int, int> > sol0, sol1;   void solve(int n, vector<pair<int, int> >& res) {     if (n < 4) return;     solve(n - 4, res);     for (int i = 0; i + 1 < n - 4; i += 2) {       res.push_back(pair<int, int>(i, n - 4));       res.push_back(pair<int, int>(i + 1, n - 3));       res.push_back(pair<int, int>(i + 1, n - 4));       res.push_back(pair<int, int>(i, n - 3));       res.push_back(pair<int, int>(i, n - 2));       res.push_back(pair<int, int>(i + 1, n - 1));       res.push_back(pair<int, int>(i + 1, n - 2));       res.push_back(pair<int, int>(i, n - 1));     }     if (n % 2) {       res.push_back(pair<int, int>(n - 5, n - 4));       res.push_back(pair<int, int>(n - 5, n - 3));       res.push_back(pair<int, int>(n - 5, n - 2));       res.push_back(pair<int, int>(n - 4, n - 1));       res.push_back(pair<int, int>(n - 5, n - 1));       for (pair<int, int> p : sol1) {         res.push_back(pair<int, int>(p.first + n - 4, p.second + n - 4));       }     } else {       for (pair<int, int> p : sol0) {         res.push_back(pair<int, int>(p.first + n - 4, p.second + n - 4));       }     }     assert(res.size() == n * (n - 1) / 2);   }   void solve0() {     vector<pair<int, int> > v;     for (int i = 0; i < 4; ++i)       for (int j = i + 1; j < 4; ++j) v.push_back(pair<int, int>(i, j));     do {       if (check(4, v)) {         sol0 = v;         break;       }     } while (next_permutation(v.begin(), v.end()));     assert(!sol0.empty());   }   void solve1() {     vector<pair<int, int> > v;     for (int i = 0; i < 4; ++i)       for (int j = i + 1; j < 4; ++j)         if (pair<int, int>(i, j) != pair<int, int>(0, 3))           v.push_back(pair<int, int>(i, j));     do {       vector<int> st = {3, 0, 1, 2};       vector<int> en = {0, 1, 2, 3};       model(st, v);       if (st == en) {         sol1 = v;         break;       }     } while (next_permutation(v.begin(), v.end()));     assert(!sol1.empty());   }   int main() {     std::ios::sync_with_stdio(false);     solve0();     solve1();     int n;     cin >> n;     if (n * (n - 1) / 2 % 2) {       cout <<  NO n ;       return 0;     }     cout <<  YES n ;     vector<pair<int, int> > res;     solve(n, res);     for (int i = 0; i < res.size(); ++i) {       cout << min(res[i].first, res[i].second) + 1 <<                << max(res[i].first, res[i].second) + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   long long x, y;   int main() {     cin >> t;     while (t--) {       cin >> x >> y;       if (x == y)         cout << x << endl;       else if (x > y)         cout << x + y << endl;       else         cout << y - y % x / 2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int q;     cin >> q;     for (long long int l = 0; l < q; l++) {       long long int n;       cin >> n;       long long int ans = 0;       while (n != 1) {         long long int track = ans;         while (n % 2 == 0) {           n = n / 2;           ans++;         }         while (n % 3 == 0) {           n = 2 * n / 3;           ans++;         }         while (n % 5 == 0) {           n = 4 * n / 5;           ans++;         }         if (track == ans) break;       }       if (n != 1)         cout << -1 << endl;       else         cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n, i, j;     cin >> t;     while (t--) {       cin >> n;       if (n % 2 == 0) {         cout << n / 2 <<     << n / 2;       } else {         for (i = 3, j = 0; i * i <= n; i++) {           if (n % i == 0) {             cout << n / i <<     << n - (n / i);             j = 1;             break;           }         }         if (j == 0) cout << 1 <<     << n - 1;       }       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2E5 + 10;   const int P = 1E9 + 7;   int n, q;   struct node {     int l, r, id;   } qu[MAXN];   int a[MAXN], pri[1100], cnt;   int num[1000001];   long long ans[MAXN];   long long bin[MAXN];   vector<int> dir[1000001];   vector<int> rec[MAXN];   int pow(int a, int n) {     long long b = a;     long long ret = 1;     while (n) {       if (n & 1) ret = ret * b % P;       b = b * b % P;       n >>= 1;     }     return ret;   }   bool cmp(node n1, node n2) {     if (n1.l != n2.l)       return n1.l < n2.l;     else       return n1.r < n2.r;   }   bool prime(int p) {     for (int i = 0; pri[i] * pri[i] <= p; i++)       if (!(p % pri[i])) return false;     return true;   }   void init() {     pri[cnt = 0] = 2;     for (int i = 3; i < 100000; i++)       if (prime(i)) pri[++cnt] = i;     cnt++;     for (int i = 0; i < MAXN; i++) rec[i].clear();     for (int i = 0; i < MAXN; i++) bin[i] = 1;     for (int i = 0; i < 1000001; i++) dir[i].clear();     memset(num, 0, sizeof(num));   }   int exgcd(long long a, long long b, long long &x, long long &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     } else {       long long tx, ty;       long long d = exgcd(b % a, a, tx, ty);       x = ty - (b / a) * tx;       y = tx;       return d;     }   }   int inverse(int k) {     long long a = k, b = P, x, y;     exgcd(a, b, x, y);     return (x % P + P) % P;   }   int main() {     int temp, l, u, v;     init();     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %d , &q);     for (int i = 0; i < q; i++) {       scanf( %d%d , &qu[i].l, &qu[i].r);       qu[i].id = i;     }     sort(qu, qu + q, cmp);     for (int i = 1; i <= n; i++) {       for (int j = 0; pri[j] * pri[j] <= a[i]; j++) {         while (a[i] % pri[j] == 0) {           a[i] /= pri[j];           if (dir[pri[j]].empty())             temp = pri[j] - 1;           else             temp = pri[j];           dir[pri[j]].push_back(i);           rec[i].push_back(pri[j]);           for (int k = i; k <= n; k += k & -k) bin[k] = bin[k] * temp % P;         }       }       if (a[i] != 1) {         if (dir[a[i]].empty())           temp = a[i] - 1;         else           temp = a[i];         dir[a[i]].push_back(i);         rec[i].push_back(a[i]);         for (int k = i; k <= n; k += k & -k) bin[k] = bin[k] * temp % P;       }     }     l = 1;     for (int i = 0; i < q; i++) {       for (; l < qu[i].l; l++) {         for (int j = 0; j < rec[l].size(); j++) {           u = rec[l][j];           if (num[u] < dir[u].size() - 1)             v = dir[u][++num[u]];           else             v = n + 1;           temp = (long long)(u - 1) * inverse(u) % P;           for (int k = v; k <= n; k += k & -k) bin[k] = bin[k] * temp % P;         }       }       temp = qu[i].id;       ans[temp] = 1;       for (int k = qu[i].l - 1; k > 0; k -= k & -k)         ans[temp] = ans[temp] * bin[k] % P;       ans[temp] = inverse(ans[temp]);       for (int k = qu[i].r; k > 0; k -= k & -k) {         ans[temp] = ans[temp] * bin[k] % P;       }     }     for (int i = 0; i < q; i++) printf( %lld n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i;     string a[3];     cin >> a[0] >> a[1] >> a[2];     for (i = 0; i < 3; i++) {       if ((a[i] ==  rock ) && (a[(i + 1) % 3] ==  scissors ) &&           (a[(i + 2) % 3] ==  scissors )) {         break;       }       if ((a[i] ==  scissors ) && (a[(i + 1) % 3] ==  paper ) &&           (a[(i + 2) % 3] ==  paper )) {         break;       }       if ((a[i] ==  paper ) && (a[(i + 1) % 3] ==  rock ) &&           (a[(i + 2) % 3] ==  rock )) {         break;       }     }     if (i == 0) {       cout <<  F  << endl;     } else if (i == 1) {       cout <<  M  << endl;     } else if (i == 2) {       cout <<  S  << endl;     } else {       cout <<  ?  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, pos, lo, hi;     while (cin >> n >> pos >> lo >> hi) {       int cnt = 0;       if (lo == 1 && hi == n) {         cout <<  0  << endl;         continue;       }       int xlo = abs(pos - lo);       int xhi = abs(pos - hi);       if (lo - 1 >= 1 && hi + 1 <= n) {         cnt += 2;         if (xlo < xhi) {           cnt += xlo;         } else           cnt += xhi;         cnt += hi - lo;       } else if (lo - 1 >= 1) {         cnt += xlo;         cnt++;       } else {         cnt += xhi;         cnt++;       }       cout << cnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int M = 1e5 + 5;   int main() {     ios_base::sync_with_stdio(false);     int tt;     cin >> tt;     while (tt--) {       int n, i, j;       cin >> n;       vector<long long> v[N];       for (i = 0; i < n; i++) {         int m;         long long p;         cin >> m >> p;         v[m].push_back(p);       }       int want[N];       int cnt = 0;       for (i = 0; i < n; i++) {         int lu = v[i].size();         if (lu == 0) continue;         want[i] = max(0, i - cnt);         cnt += lu;       }       multiset<long long> st;       long long ans = 0;       int taken = 0;       for (i = n - 1; i >= 0; i--) {         int lu = v[i].size();         if (lu == 0) continue;         for (j = 0; j < lu; j++) {           st.insert(v[i][j]);         }         int fu = st.size();         int req = min(max(0, want[i] - taken), fu);         for (j = 0; j < req; j++) {           ans += *(st.begin());           taken++;           st.erase(st.begin());         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[500005], t[500005];   long long ans;   int n, k, now, tmp;   int main() {     scanf( %d %d n , &n, &k);     fread(s + 1, 1, n, stdin);     getchar();     fread(t + 1, 1, n, stdin);     s[n + 1] =  # ;     if (k == 1) return printf( %d n , n), 0;     for (now = 1; s[now] == t[now]; now++)       ;     if (now > n) return printf( %d n , n), 0;     ans = now + 1;     for (int i = now + 1; i <= n; i++) {       tmp = tmp << 1;       if (s[i] ==  a ) tmp++;       if (t[i] ==  b ) tmp++;       tmp = min(k - 2, tmp);       ans += tmp + 2;     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   template <typename TF>   void write_debug_output(ostream &out, TF const &f) {     out << f << std::endl;   }   template <typename TF, typename... TR>   void write_debug_output(ostream &out, TF const &f, TR const &...rest) {     out << f <<    ;     write_debug_output(out, rest...);   }   using ll = long long;   using ull = unsigned long long;   using ld = long double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using pdd = pair<double, double>;   using vi = vector<int>;   using vii = vector<pii>;   using vll = vector<ll>;   using vs = vector<string>;   const int DR[] = {-1, 0, 1, 0, -1, 1, 1, -1};   const int DC[] = {0, -1, 0, 1, -1, -1, 1, 1};   const double PI = acos(-1.0);   const double EPS = 1e-9;   const int MOD = 1e9 + 7;   const int INF = 1073741823;   const ll INFLL = 4e18;   const int MAX = 100;   int N, M, aa[MAX + 5], bb[MAX + 5];   void read() {     cin >> N >> M;     for (int i = 0; i < (int)N; i++) cin >> aa[i];     for (int i = 0; i < (int)M; i++) cin >> bb[i];   }   void solve() {     int xorA = 0, xorB = 0;     for (int i = 0; i < (int)N; i++) xorA ^= aa[i];     for (int i = 0; i < (int)M; i++) xorB ^= bb[i];     if (xorA != xorB) {       cout <<  NO n ;       return;     }     cout <<  YES n ;     int b = bb[1];     int c = aa[1];     int a = aa[0] ^ bb[1] ^ (xorB ^ bb[0] ^ bb[1]);     for (int i = 0; i < (int)N; i++) {       for (int j = 0; j < (int)M; j++) {         if (i == 0 && j == 0)           cout << a <<    ;         else if (i == 0 && j == 1)           cout << b <<    ;         else if (i == 1 && j == 0)           cout << c <<    ;         else if (i == 0)           cout << bb[j] <<    ;         else if (j == 0)           cout << aa[i] <<    ;         else           cout <<  0  ;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int TC = 1;     for (int tc = (int)1; tc <= (int)TC; tc++) {       read();       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000007, M = 5000007;   const long long INF = 1e14;   inline void read(int &first) {     char c = getchar();     while ((c < 48) || (c > 57)) c = getchar();     first = c ^ 48;     c = getchar();     while ((c >= 48) && (c <= 57)) {       first = first * 10 + (c ^ 48);       c = getchar();     }   }   struct node {     int l, r;     int maxx;   } tr[N << 2];   int n, m, t, k;   int first[N], second;   int a[N];   int num[N];   int s[N];   int pre[N];   void build(int p, int l, int r) {     tr[p] = {l, r, 0};     if (l == r) {       tr[p].maxx = s[r];       return;     }     int mid = l + r >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);     tr[p].maxx = max(tr[p << 1].maxx, tr[p << 1 | 1].maxx);   }   int query(int p, int l, int r) {     if (tr[p].l >= l && tr[p].r <= r) {       return tr[p].maxx;     }     int mid = tr[p].l + tr[p].r >> 1;     int res = 0;     if (l <= mid) res = max(res, query(p << 1, l, r));     if (r > mid) res = max(res, query(p << 1 | 1, l, r));     return res;   }   int main() {     scanf( %d , &t);     while (t--) {       for (int i = 0; i <= n; ++i) s[i] = pre[i] = num[i] = 0;       scanf( %d%d , &n, &m);       for (int i = 1; i <= n; ++i) scanf( %d , &first[i]), a[i] = first[i];       for (int i = 1; i <= n; ++i) scanf( %d , &second);       sort(a + 1, a + 1 + n);       int tot = unique(a + 1, a + 1 + n) - a - 1;       for (int i = 1; i <= n; ++i)         num[lower_bound(a + 1, a + 1 + tot, first[i]) - a]++;       for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + num[i];       for (int i = 1; i <= n; ++i)         s[i] = pre[upper_bound(a + i + 1, a + 1 + tot, a[i] + m) - a - 1] -                pre[i - 1];       build(1, 1, tot);       int ans = 0;       for (int i = 1; i <= tot; ++i) {         ans =             max(ans,                 s[i] + query(1, upper_bound(a + i + 1, a + 1 + tot, a[i] + m) - a,                              tot));       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<  :   << arg1 << std::endl;   }   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...);   }   int main() {     int k;     scanf( %d , &k);     int x[10];     memset(x, 0, sizeof(x));     char s[5];     for (auto i = 0; i < 4; i++) {       scanf( %s , s);       for (auto j = 0; j < 4; j++) {         if (s[j] ==  . ) {           continue;         }         x[s[j] -  0 ]++;       }     }     for (auto i = 1; i < 10; i++) {       if (x[i] > 2 * k) {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int ara[200010];   string res;   string str;   void func(int le, int ri, int chk, int past) {     if (res.size() < str.size()) {       res = str;     }     if (le > ri) {       return;     }     if (chk == 0) {       if ((past < ara[le]) && (ara[le] < ara[ri])) {         str +=  L ;         func(le + 1, ri, chk, ara[le]);         str.pop_back();       } else if ((past < ara[ri]) && (ara[ri] < ara[le])) {         str +=  R ;         func(le, ri - 1, chk, ara[ri]);         str.pop_back();       } else if ((past < ara[ri]) && (ara[ri] == ara[le])) {         str +=  L ;         func(le + 1, ri, 1, ara[le]);         str.pop_back();         str +=  R ;         func(le, ri - 1, 2, ara[ri]);         str.pop_back();       } else if (past < ara[le]) {         str +=  L ;         func(le + 1, ri, chk, ara[le]);         str.pop_back();       } else if (past < ara[ri]) {         str +=  R ;         func(le, ri - 1, chk, ara[ri]);         str.pop_back();       }     } else if (chk == 1) {       if (past < ara[le]) {         str +=  L ;         func(le + 1, ri, chk, ara[le]);         str.pop_back();       }     } else {       if (past < ara[ri]) {         str +=  R ;         func(le, ri - 1, chk, ara[ri]);         str.pop_back();       }     }   }   int main() {     cin >> n;     for (int i = 0; i <= n - 1; i++) {       cin >> ara[i];     }     str =   ;     res =   ;     func(0, n - 1, 0, 0);     cout << res.size() <<   n ;     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   const int N = 300300;   using namespace std;   struct edge {     int ul, ur, dl, dr, a, al, ar;     long long xl, xr;   };   edge comb(edge a, edge b, int sa, int sb) {     edge g;     g.a = max(a.a, b.a);     g.al = a.al;     g.xl = a.xl;     g.ul = a.ul;     g.dl = a.dl;     g.ar = b.ar;     g.xr = b.xr;     g.ur = b.ur;     g.dr = b.dr;     if (a.xr == b.xl) {       return g;     } else if (a.xr > b.xl) {       g.a = max(g.a, a.ar + b.dl);       if (sb == b.dl) g.ar = a.ar + b.dl;       if (sa == a.a) g.al = a.a + b.dl;       if (sa == a.dl) g.dl += b.dl;       if (sb == b.ur) g.ur += a.ur;       g.a = max(g.a, max(g.al, g.ar));       return g;     } else {       g.a = max(g.a, a.dr + b.al);       if (sb == b.a) g.ar = a.dr + b.a;       if (sa == a.dr) g.al = a.dr + b.al;       if (sb == b.dr) g.dr += a.dr;       if (sa == a.ul) g.ul += b.ul;       g.a = max(g.a, max(g.al, g.ar));       return g;     }   }   edge t[4 * N];   int n;   int a[N];   long long lz[4 * N];   void push(int x) {     if (lz[x] == 0) return;     t[x * 2].xl += lz[x];     t[x * 2].xr += lz[x];     t[x * 2 + 1].xl += lz[x];     t[x * 2 + 1].xr += lz[x];     lz[x * 2] += lz[x];     lz[x * 2 + 1] += lz[x];     lz[x] = 0;   }   void build(int x, int l, int r) {     if (l == r) {       t[x].xl = t[x].xr = a[l];       t[x].a = t[x].al = t[x].ar = t[x].dl = t[x].dr = t[x].ul = t[x].ur = 1;       return;     }     int m = (l + r) / 2;     build(x * 2, l, m);     build(x * 2 + 1, m + 1, r);     t[x] = comb(t[x * 2], t[x * 2 + 1], m - l + 1, r - m);   }   void upd(int x, int l, int r, int tl, int tr, long long d) {     if (tl > tr) return;     if (l == tl && r == tr) {       lz[x] += d;       t[x].xl += d;       t[x].xr += d;       return;     }     push(x);     int m = (l + r) / 2;     upd(x * 2, l, m, tl, min(m, tr), d);     upd(x * 2 + 1, m + 1, r, max(m + 1, tl), tr, d);     t[x] = comb(t[x * 2], t[x * 2 + 1], m - l + 1, r - m);   }   int main() {     ios_base::sync_with_stdio(0);     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     build(1, 1, n);     int m;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int l, r, d;       scanf( %d%d%d , &l, &r, &d);       upd(1, 1, n, l, r, d);       printf( %d n , t[1].a);     }   }


#include <bits/stdc++.h>   using namespace std;   int c[100010];   long long ans;   int main() {     int n, x;     scanf( %d%d , &n, &x);     for (int i = 1; i <= n; i++) scanf( %d , &c[i]);     sort(c + 1, c + n + 1);     if (n < x) {       ans = 0;       for (int i = 1; i <= n; i++) ans += (long long)c[i] * (x - i + 1);       printf( %I64d , ans);       return 0;     }     if (n >= x) {       ans = 0;       for (int i = 1; i <= x; i++) ans += (long long)i * c[x + 1 - i];       for (int i = x + 1; i <= n; i++) ans += c[i];     }     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)   #define INP(arr,n) for(int a=0;a<n;a++)cin>>arr[a]   #define OTP(arr,n) for(int a=0;a<n;a++)cout<<arr[a]<<      #define ll long long int   #define pb(v,a) v.push_back(a)   int main() {   IOS;int t = 0;cin >> t;   while (t--) {       ll n = 0;cin >> n;       ll arr[n];INP(arr,n);       cout <<  0  ;       for (ll a = 1;a < n;a++) {           ll x = 0,y = 1;           bitset <64> bs(arr[a - 1]);           bitset <64> bs2(arr[a]);           for (int b = 0;b < 64;b++,y *= 2)               bs2[b] == 0 && bs[b] == 1 ? x += y,arr[a] += y: x = x;           cout << x <<    ;       }       cout <<   n ;   }   }


#include <bits/stdc++.h>   using namespace std;   string p[3][2] = {{ lios ,  liala }, { etr ,  etra }, { initis ,  inites }}, s;   pair<int, int> kind(string q) {     int l = q.length();     if (l >= 4 && q.substr(l - 4, 4) == p[0][0]) return pair<int, int>(0, 0);     if (l >= 5 && q.substr(l - 5, 5) == p[0][1]) return pair<int, int>(0, 1);     if (l >= 3 && q.substr(l - 3, 3) == p[1][0]) return pair<int, int>(1, 0);     if (l >= 4 && q.substr(l - 4, 4) == p[1][1]) return pair<int, int>(1, 1);     if (l >= 6 && q.substr(l - 6, 6) == p[2][0]) return pair<int, int>(2, 0);     if (l >= 6 && q.substr(l - 6, 6) == p[2][1]) return pair<int, int>(2, 1);     return pair<int, int>(-1, -1);   }   int tran[2][3] = {{0, 1, -1}, {-1, -1, 1}};   int main() {     int g = -1, st = -1, ok = true, tow = false;     cin >> s;     g = kind(s).second;     if (g != -1) st = tran[0][kind(s).first];     while (cin >> s && ok) {       tow = true;       pair<int, int> t = kind(s);       if (t.second != g) ok = false;       if (st == -1) break;       st = tran[st][t.first];     }     if ((tow && ok && st == 1) || (!tow && g != -1))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, sb, a[4], data1[100001], num[100001];   void merge(int l, int r) {     int mid = (l + r) / 2;     int i = l, j = mid + 1, k = 0;     while (i <= mid && j <= r) {       if (data1[i] < data1[j])         num[k++] = data1[i++];       else         num[k++] = data1[j++];     }     while (i <= mid) num[k++] = data1[i++];     while (j <= r) num[k++] = data1[j++];     for (int p = 0; p < k; p++) data1[p + l] = num[p];   }   void sort(int l, int r) {     if (l >= r) return;     int mid = (l + r) / 2;     sort(l, mid);     sort(mid + 1, r);     merge(l, r);   }   int main() {     cin >> n;     for (int j = 0; j < n; j++) cin >> data1[j];     sort(0, n - 1);     for (int i = 1; i <= 3; i++) {       a[i] = 1;       while (data1[sb] == data1[sb + 1] && sb < n - 1) {         a[i]++;         sb++;       }       sb++;     }     if (data1[0] == data1[1]) {       if (data1[1] == data1[2])         cout << a[1] * (a[1] - 1) * (a[1] - 2) / 6;       else         cout << a[2];     } else {       if (data1[1] == data1[2])         cout << a[2] * (a[2] - 1) / 2;       else         cout << a[3];     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:336777216 )   const int sqrtn = 300;   const int inf = 987654321;   const int sz = 1e5 + 5;   const int mod = 1e9 + 7;   int n, vis[sz];   string str;   int main() {     scanf( %d , &n);     cin >> str;     int ret = 0, x = 0, y = 0, last = 0;     if (str[0] ==  U ) {       y++;       last = 1;     } else       x++, last = 0;     for (int i = 1; i < n; i++) {       if (str[i] ==  U )         y++;       else         x++;       if (vis[i - 1]) {         if (y > x && last == 0) {           ret++, last = 1;         } else if (x > y && last == 1) {           ret++, last = 0;         }       }       if (y == x) vis[i] = 1;     }     printf( %d , ret);   }


#include <bits/stdc++.h>   using namespace std;   namespace IO {   const int maxn(1 << 21 | 1);   char *iS, *iT, ibuf[maxn], obuf[maxn], *oS = obuf, *oT = obuf + maxn - 1, c,                                          st[20];   int f, tp, len;   inline char getc() {     return iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin),                        iS == iT ? EOF : *iS++)                     : *iS++;   }   template <class T>   inline void read(T &x) {     for (c = getc(), f = 1; c <  0  || c >  9 ; c = getc()) f = c ==  -  ? -1 : 1;     for (x = 0; c >=  0  && c <=  9 ; c = getc()) x = x * 10 + (c ^ 48);     x *= f;   }   template <class T, class... Other>   inline void read(T &x, Other &...y) {     read(x), read(y...);   }   inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; }   inline void putc(char ch) {     *oS++ = ch;     if (oS == oT) flush();   }   template <class T>   inline void print(T x, char ch =   n ) {     if (!x) putc( 0 );     if (x < 0) putc( - ), x = -x;     while (x) st[++tp] = x % 10 +  0 , x /= 10;     while (tp) putc(st[tp--]);     putc(ch);   }   template <class T, class... Other>   inline void print(T x, Other... y) {     print(x), print(y...);   }   inline void print_str(char *s) {     for (len = strlen(s), f = 0; f < len; ++f) putc(s[f]);   }   inline void read_str(char *s, int &l) {     for (l = 0, c = getc(); (c <  a  || c >  z ) && (c <  A  || c >  Z );          c = getc())       ;     for (; (c >=  a  && c <=  z ) || (c >=  A  && c <=  Z ); c = getc())       s[l++] = c;     s[l] =   0 ;   }   }  // namespace IO   using IO ::flush;   using IO ::print;   using IO ::print_str;   using IO ::read;   using IO ::read_str;   template <class T>   inline void cmax(T &x, T y) {     x = x >= y ? x : y;   }   template <class T, class... Other>   inline void cmax(T &x, T y, Other... z) {     Cmax(x, y), Cmax(x, z...);   }   template <class T>   inline void cmin(T &x, T y) {     x = x <= y ? x : y;   }   template <class T, class... Other>   inline void cmin(T &x, T y, Other... z) {     Cmin(x, y), Cmin(x, z...);   }   inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }   const int mod(1e9 + 7);   inline void inc(int &x, const int y) { x = x + y >= mod ? x + y - mod : x + y; }   inline void dec(int &x, const int y) { x = x - y < 0 ? x - y + mod : x - y; }   inline int add(const int x, const int y) {     return x + y >= mod ? x + y - mod : x + y;   }   inline int sub(const int x, const int y) {     return x - y < 0 ? x - y + mod : x - y;   }   inline int fpow(long long x, int y) {     long long ret = 1;     for (; y; y >>= 1, x = x * x % mod)       if (y & 1) ret = ret * x % mod;     return ret;   }   const int maxn(1e5 + 5);   int k, lg[23], ans = 1, f[55][10005], num, inv[55];   long long n, d[23];   inline int solve(int p, int lim) {     int i, j, l, ret = 0;     memset(f, 0, sizeof(f)), f[lim][0] = 1;     for (i = 1; i <= k; ++i)       for (j = 0; j <= lim; ++j)         for (l = j; l <= lim; ++l)           inc(f[j][i], (long long)f[l][i - 1] * inv[l + 1] % mod);     for (ret = 0, i = 0; i <= lim; ++i)       inc(ret, (long long)f[i][k] * fpow(p, i) % mod);     return ret;   }   int main() {     long long i;     read(n, k), ans = 1;     for (i = 1; i <= 50; ++i) inv[i] = fpow(i, mod - 2);     for (i = 2; i * i <= n; ++i)       if (n % i == 0) {         d[++num] = i;         while (n % i == 0) n /= i, ++lg[num];       }     if (n > 1) d[++num] = n, lg[num] = 1;     for (i = 1; i <= num; ++i)       ans = (long long)ans * solve(d[i] % mod, lg[i]) % mod;     print(ans);     return flush(), 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Query {     int p, s, id;     bool operator<(const Query &b) const { return (s < b.s); }   };   int main() {     int n;     scanf( %d , &n);     vector<int> a(n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     int m;     scanf( %d , &m);     vector<Query> q(m);     for (int i = 0; i < m; ++i) {       scanf( %d%d , &q[i].p, &q[i].s);       --q[i].p;       q[i].id = i;     }     sort(q.begin(), q.end());     vector<long long> ans(m, 0);     int lim = sqrt(n);     for (int i = 0; i < q.size(); ++i) {       if (q[i].s > lim) {         for (int j = q[i].p; j < n; j += q[i].s) ans[q[i].id] += a[j];       } else {         int cs = q[i].s;         vector<long long> sums(n, 0);         for (int j = n - 1; j >= 0; --j)           sums[j] = a[j] + ((j + cs < n) ? sums[j + cs] : 0);         int j;         for (j = i; j < q.size() && q[j].s == cs; ++j)           ans[q[j].id] = sums[q[j].p];         i = j - 1;       }     }     for (int i = 0; i < ans.size(); ++i) printf( %I64d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int mod = 1e9 + 7;   const int N = 4e5 + 10;   const int inf = 1e9;   int n, k, m;   map<pair<int, int>, int> vis;   int mx[N << 2], tag[N << 2];   int a[N];   void pd(int p, int k) {     mx[p << 1] += k;     tag[p << 1] += k;     mx[p << 1 | 1] += k;     tag[p << 1 | 1] += k;     tag[p] = 0;   }   void up(int dl, int dr, int l, int r, int p, int k) {     if (l == dl && r == dr) {       mx[p] += k;       tag[p] += k;       return;     }     int mid = l + r >> 1;     pd(p, tag[p]);     if (dr <= mid)       up(dl, dr, l, mid, p << 1, k);     else if (dl > mid)       up(dl, dr, mid + 1, r, p << 1 | 1, k);     else       up(dl, mid, l, mid, p << 1, k), up(mid + 1, dr, mid + 1, r, p << 1 | 1, k);     mx[p] = max(mx[p << 1], mx[p << 1 | 1]);   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> k >> m;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       int p = abs(x - k) + y;       if (vis[make_pair(x, y)]) {         up(1, p, 1, 2 * n, 1, -1);         a[p]--;         if (a[p] == 0) up(p, p, 1, 2 * n, 1, -p + 1);         vis[make_pair(x, y)] = 0;       } else {         up(1, p, 1, 2 * n, 1, 1);         if (a[p] == 0) up(p, p, 1, 2 * n, 1, p - 1);         ++a[p];         vis[make_pair(x, y)] = 1;       }       cout << max(0, mx[1] - n) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const long long linf = (long long)1e18;   const double eps = (double)1e-8;   const int mod = (int)1e9 + 7;   const int maxn = (int)1e5 + 5;   const int MX = (int)1e5;   const int PRIME = 31;   string s, t;   int n, m, first;   long long hs[maxn], ht[maxn], st[maxn];   int d[maxn][33];   int subs(int l, int r) {     return 1ll * (hs[r] - hs[l - 1] + mod) % mod * st[max(n, m) - r] % mod;   }   int subt(int l, int r) {     return 1ll * (ht[r] - ht[l - 1] + mod) % mod * st[max(n, m) - r] % mod;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     cin >> s;     s =  _  + s;     cin >> m;     cin >> t;     t =  _  + t;     cin >> first;     st[0] = 1;     for (int i = (1); i <= (int)(MX); ++i) {       st[i] = 1ll * st[i - 1] * PRIME % mod;     }     hs[0] = 0;     for (int i = (1); i <= (int)(n); ++i) {       hs[i] = (hs[i - 1] + st[i - 1] * (s[i] -  a  + 1)) % mod;     }     ht[0] = 0;     for (int i = (1); i <= (int)(m); ++i) {       ht[i] = (ht[i - 1] + st[i - 1] * (t[i] -  a  + 1)) % mod;     }     memset((d), 0, sizeof(d));     for (int i = (0); i <= (int)(n - 1); ++i) {       for (int j = (0); j <= (int)(first); ++j) {         d[i + 1][j] = max(d[i + 1][j], d[i][j]);         if (j == first) continue;         int l = 0;         int r = min(n - i, m - d[i][j]);         while (l < r) {           int mid = (l + r + 1) / 2;           if (subs(i + 1, i + mid) == subt(d[i][j] + 1, d[i][j] + mid))             l = mid;           else             r = mid - 1;         }         d[i + l][j + 1] = max(d[i + l][j + 1], d[i][j] + l);       }     }     for (int i = (1); i <= (int)(first); ++i) {       if (d[n][i] == m) {         cout <<  YES               <<   n ;         return 0;       }     }     cout <<  NO           <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a[123456], b[123456];   vector<long long int> v1, v2, v3;   map<long long int, long long int> mp;   map<string, long long int> mps;   map<char, long long int> mpc;   int main() {     long long int f = 0, x = 0, l = 0, r = 0, n, i;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b, b + i);     for (i = 0; i < n; i++) {       if (a[i] != b[i]) {         l = i + 1;         break;       }     }     for (i = n - 1; i >= 0; i--) {       if (a[i] != b[i]) {         r = i + 1;         break;       }     }     if (l == 0 && r == 0) {       l = 1;       r = 1;       cout <<  yes  << endl;       cout << l <<     << r << endl;       return 0;     }     long long int k = r - 1;     for (i = l - 1; i <= r - 1; i++) {       long long int aa = i;       long long int bb = k;       if (mp[bb] == 0 && mp[aa] == 0) {         swap(a[i], a[k]);         mp[aa] = 1;         mp[bb] = 1;         k--;       }     }     for (i = 0; i < n; i++) {       if (a[i] != b[i]) {         cout <<  no  << endl;         return 0;       }     }     cout <<  yes  << endl;     cout << l <<     << r << endl;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     map<string, vector<int> > mda;     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       int cost;       cin >> cost;       mda[s].push_back(cost);     }     for (auto &c : mda) {       sort(c.second.rbegin(), c.second.rend());     }     long long ans = 0;     long long odd = 0;     for (auto &c : mda) {       string t = c.first;       reverse(t.begin(), t.end());       if (t < c.first) {         long long best = 0;         long long s = 0;         for (int i = 0; i < (int)c.second.size() && i < mda[t].size(); i++) {           s += c.second[i];           s += mda[t][i];           best = max(best, s);         }         ans += best;       } else if (t == c.first) {         long long s = 0;         int mda = 0;         long long last = 0;         long long fir = -1e18;         for (int i = 0; i < (int)c.second.size(); i++) {           if (c.second[i] > 0) {             last = c.second[i];             s += c.second[i];             mda++;           } else {             fir = c.second[i];             break;           }         }         if (mda % 2 == 0) {           ans += s;         } else {           long long me = max(s - last, s + fir);           long long delta_odd = s - me;           ans += me;           odd = max(odd, delta_odd);         }       }     }     cout << ans + odd << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long tc, n, arr1[100005], m, arr2[100005], count = 0, even = 0,                                                     even2 = 0, odd = 0, odd2 = 0;     cin >> tc;     while (tc--) {       cin >> n;       for (int i = 0; i < n; i++) {         cin >> arr1[i];         if (arr1[i] % 2 == 0)           even++;         else           odd++;       }       cin >> m;       for (int i = 0; i < m; i++) {         cin >> arr2[i];         if (arr2[i] % 2 == 0)           even2++;         else           odd2++;       }       count += even * even2;       count += odd * odd2;       cout << count << endl;       count = 0;       even = 0;       even2 = 0;       odd = 0;       odd2 = 0;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   bool adj[4005][4005];   int edges[4005];   int main() {     int n, m, res = INF;     cin >> n >> m;     while (m--) {       int a, b;       cin >> a >> b;       adj[a][b] = adj[b][a] = 1;       edges[a]++;       edges[b]++;     }     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) {         if (adj[i][j] == 1) {           for (int k = j + 1; k <= n; k++)             if (adj[j][k] == 1 && adj[k][i] == 1)               res = min(res, edges[i] + edges[j] + edges[k] - 6);         }       }     if (res == INF)       puts( -1 );     else       cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long maxn = -1e18;   long long minn = 1e18;   long long mod = 1000000007;   long long ans = 0;   long long cur = 0;   long long tong = 0, tong2 = 0;   long long cnt = 0;   long long k, l;   string s;   long long n, m, x, y;   long long b[100005];   long long was[200005];   bool flag = true;   vector<long long> node[200005];   long long dp[105][105];   long long a[55];   long long c[55];   map<string, int> ok;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> a[2] >> a[3] >> a[5] >> a[6];     cout << min(a[2], min(a[5], a[6])) * 256 +                 min(a[2] - min(a[2], min(a[5], a[6])), a[3]) * 32;   }


#include <bits/stdc++.h>   using namespace std;   namespace scanfuck {   const int L = (1 << 21) + 1;   struct io {     char ibuf[L], *iS, *iT, obuf[L], *oS, *oT, c, st[55];     int f, tp;     void flush() {       fwrite(obuf, 1, oS - obuf, stdout);       oS = obuf;     }     void putc(char x) {       *oS++ = x;       if (oS == oT) flush();     }     template <class T>     T rd() {       register T x = 0;       for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin),                                   (iS == iT ? EOF : *iS++))                                 : *iS++);            !isdigit(c);            c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin),                            (iS == iT ? EOF : *iS++))                          : *iS++))         if (c ==  - ) f = -1;       for (x = 0; isdigit(c);            c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin),                            (iS == iT ? EOF : *iS++))                          : *iS++))         x = x * 10 + (c & 15);       return x * f;     }     template <class T>     void print(T x) {       if (!x)         putc( 0 );       else {         if (x < 0) putc( - ), x = -x;         for (tp = 0; x; st[tp++] = x % 10 + 48, x /= 10)           ;         for (tp--; ~tp; putc(st[tp--]))           ;       }     }     void gs(char* s, int& l) {       for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin),                            (iS == iT ? EOF : *iS++))                          : *iS++);            !isalpha(c);            c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin),                            (iS == iT ? EOF : *iS++))                          : *iS++))         ;       for (l = 0; isalpha(c);            c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin),                            (iS == iT ? EOF : *iS++))                          : *iS++))         s[l++] = c;     }     void ps(const char* s) {       for (tp = 0; tp < strlen(s); ++tp) putc(s[tp]);     }     io() : oS(obuf), oT(obuf + L - 1) {}     ~io() { flush(); }   } ip;   }  // namespace scanfuck   int n = scanfuck::ip.rd<int>(), m = scanfuck::ip.rd<int>(),       k = scanfuck::ip.rd<int>();   inline bool judge() {     if (!(n & 1)) return 1;     int t = sqrt(m);     for (register int i = 1; i <= t; ++i)       if (m % i == 0 && (i >= k && m / i > 1 || i > 1 && m / i >= k)) return 0;     return 1;   }   int main() { scanfuck::ip.ps(judge() ?  Marsel  :  Timur ); }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   vector<T>& operator--(vector<T>& v) {     for (auto& i : v) --i;     return v;   }   template <typename T>   vector<T>& operator++(vector<T>& v) {     for (auto& i : v) ++i;     return v;   }   template <typename T>   istream& operator>>(istream& is, vector<T>& v) {     for (auto& i : v) is >> i;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, vector<T>& v) {     for (auto& i : v) os << i <<    ;     return os;   }   template <typename T, typename U>   istream& operator>>(istream& is, pair<T, U>& p) {     is >> p.first >> p.second;     return is;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, pair<T, U>& p) {     os << p.first <<     << p.second;     return os;   }   template <typename T, typename U>   pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {     return make_pair(a.first - b.first, a.second - b.second);   }   template <typename T, typename U>   pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {     return make_pair(a.first + b.first, a.second + b.second);   }   template <typename T, typename U>   void umin(T& a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   void umax(T& a, U b) {     if (a < b) a = b;   }   const int K = 15;   array<array<bool, 1 << K>, K> dp;   int main() {     int k;     cin >> k;     vector<vector<int>> v(k);     map<int, int> where;     vector<long long> sms(k, 0);     long long need = 0;     for (int i = 0; i < k; ++i) {       int n;       cin >> n;       v[i].resize(n);       cin >> v[i];       for (auto u : v[i]) {         where[u] = i;         sms[i] += u;         need += u;       }     }     if (need % k != 0) {       cout <<  No n ;       return 0;     }     need /= k;     vector<map<int, pair<int, int>>> from(k);     for (int i = 0; i < k; ++i) {       for (int j = 0; j < v[i].size(); ++j) {         int next = need - (sms[i] - v[i][j]);         if (where.count(next)) {           from[i][v[i][j]] = make_pair(next, where[next]);         } else {           from[i][v[i][j]] = make_pair(0, -1);         }       }     }     set<int> used;     vector<pair<int, int>> sth;     for (int i = 0; i < k; ++i) {       for (int j = 0; j < v[i].size(); ++j) {         int start = v[i][j];         if (used.count(start)) continue;         int start_i = i;         int now = start;         int visited = 1 << i;         bool ok = true;         vector<int> was = {start};         while (true) {           auto [next, next_i] = from[start_i][start];           if (next_i == -1) {             ok = false;             break;           }           if (visited & (1 << next_i)) {             if (next != now) {               ok = false;             }             break;           }           visited |= (1 << next_i);           start = next;           start_i = next_i;           if (used.count(start)) {             ok = false;             break;           }           was.push_back(start);         }         if (ok) {           for (auto y : was) {             used.insert(y);           }           sth.emplace_back(visited, now);         }       }     }     dp[0].fill(false);     for (auto [mask, s] : sth) {       dp[0][mask] = true;     }     dp[0][0] = true;     for (int i = 1; i < k; ++i) {       for (int j = 0; j < (1 << k); ++j) {         int mask = j;         int submask = mask;         if (j == 0) {           dp[i][mask] = true;         } else {           dp[i][mask] = false;         }         while (submask != 0) {           if (dp[i - 1][submask] && dp[i - 1][mask ^ submask]) {             dp[i][mask] = true;             break;           }           submask = (submask - 1) & mask;         }       }     }     if (!dp[k - 1][(1 << k) - 1]) {       cout <<  No n ;       return 0;     }     cout <<  Yes n ;     vector<int> masks = {(1 << k) - 1};     for (int i = k - 1; i > 0; --i) {       vector<int> new_masks;       for (auto mask : masks) {         int submask = mask;         while (submask != 0) {           if (dp[i - 1][submask] && dp[i - 1][mask ^ submask]) {             if (submask) new_masks.push_back(submask);             if (mask ^ submask) new_masks.push_back(mask ^ submask);             break;           }           submask = (submask - 1) & mask;         }       }       swap(new_masks, masks);     }     sort(sth.begin(), sth.end());     42;     ;     vector<int> starts;     vector<pair<pair<int, int>, int>> ans;     for (auto mask : masks) {       auto it =           lower_bound(sth.begin(), sth.end(), make_pair(mask, (int)(-1e9 - 10)));       assert(it->first == mask);       int start = it->second;       int now = start;       int now_i = where[start];       int visited = 1 << now_i;       vector<pair<int, int>> path;       path.emplace_back(now_i, now);       while (true) {         auto [next, next_i] = from[now_i][now];         if (visited & (1 << next_i)) {           break;         }         now = next;         now_i = next_i;         path.emplace_back(now_i, now);         visited |= 1 << next_i;       }       for (int i = 0; i < path.size(); ++i) {         ans.emplace_back(path[i],                          path[(i - 1 + path.size()) % path.size()].first);       }     }     sort(ans.begin(), ans.end());     for (auto [p, y] : ans) {       cout << p.second <<     << y + 1 << endl;     }     return 0;   }