#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     s = s +  x ;     int dol = 0;     int cent = 0;     int td = 0;     int tc = 0;     for (int i = 0; i < s.length(); ++i) {       if (s[i] >=  a  && s[i] <=  z ) {         dol += td;         cent += tc;         td = 0;         tc = 0;         continue;       }       if (s[i] >=  0  && s[i] <=  9 ) td = td * 10 + (int)(s[i] -  0 );       if (s[i] ==  . ) {         if (s[i + 3] >=  0  && s[i + 3] <=  9 )           continue;         else           for (int j = 0; j < 2; ++j) {             ++i;             tc = tc * 10 + (int)(s[i] -  0 );           }       }     }     dol = dol + cent / 100;     cent = cent % 100;     int storecent = cent;     int dig = 0;     string sd;     string sc;     if (dol == 0 && cent > 0) {       sd =  .  + sd;       sd =  0  + sd;     }     while (dol > 0) {       if (dig == 0) sd =  .  + sd;       sd = (char)((dol % 10) +  0 ) + sd;       dol /= 10;       dig = (dig + 1) % 3;     }     while (cent > 0) {       sc = (char)((cent % 10) +  0 ) + sc;       cent /= 10;     }     if (sc.length() == 1) sc =  0  + sc;     for (int i = 0; i < sd.length() - 1; ++i) cout << sd[i];     if (storecent != 0) {       cout <<  . ;       cout << sc[0] << sc[1];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 1;   bool v[N];   int n, m, x, y, k, q[N], t, d[N], A[N], c;   vector<int> a[N];   void D(int x) {     q[++t] = x, d[x] = t;     for (int i = 0; i < a[x].size(); i++)       if (!d[a[x][i]])         D(a[x][i]);       else if (d[x] - d[a[x][i]] + 1 >= k) {         cout << 2 <<   n  << d[x] - d[a[x][i]] + 1 <<   n ;         for (int j = d[a[x][i]]; j <= d[x]; j++) cout << q[j] <<    ;         exit(0);       }     if (!v[x]) {       A[++c] = x;       for (int i = 0; i < a[x].size(); i++) v[a[x][i]] = true;     }     t--;   }   int main() {     cin >> n >> m;     while (m-- && cin >> x >> y) a[x].push_back(y), a[y].push_back(x);     k = sqrt(n - 1) + 1, D(1);     cout << 1 <<   n ;     for (int i = 1; i <= k; i++) cout << A[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, t, cur = 1, pre, s;     cin >> n >> pre;     s = n;     n--;     for (int i = 0; i < (int)(n); ++i) {       cin >> t;       if (t == pre)         cur++;       else if (t != pre && cur > 1) {         s += (cur * (cur - 1) / 2);         cur = 1;       }       pre = t;     }     if (cur > 1) s += (cur * (cur - 1) / 2);     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     string s;     cin >> s;     int n = s.size();     int ps[n + 5];     ps[0] = s[0] -  0 ;     for (int i = 1; i < n; i++) ps[i] = ps[i - 1] + s[i] -  0 ;     long long ans = 0;     for (int i = 0; i < n; i++) {       int it1 = lower_bound(ps + i, ps + n, (i ? ps[i - 1] : 0) + k) - ps;       if (it1 == n) continue;       int it2 = lower_bound(ps + i, ps + n, (i ? ps[i - 1] : 0) + k + 1) - 1 - ps;       ans += it2 - it1 + 1;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long int x;   long long int k;   long long int res;   long long int curr;   long long int exponentiation(long long int base, long long int power) {     long long int ans = 1;     while (power > 0) {       if (power % 2) ans = (ans * base) % mod;       base = (base * base) % mod;       power /= 2;     }     return ans % mod;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> x >> k;     if (x == 0) {       res = 0;     } else if (k == 0) {       res = (2 * x) % mod;     } else {       curr = (2 * x - 1 - x + mod) % mod;       res =           (x + ((((curr + x) % mod) * exponentiation(2, k)) % mod - curr) + mod) %           mod;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long N;     cin >> N;     long long frend[N + 1][N + 1];     long long i, j, k;     for (i = 1; i <= N; i++) {       for (j = 1; j <= N; j++) {         cin >> frend[i][j];       }     }     long long alex[N + 1];     long long liking[N + 1];     long long c = N + 9;     for (i = 1; i <= N; i++) {       cin >> alex[i];       liking[alex[i]] = c--;     }     for (i = 1; i <= N; i++) {       for (j = 1; j <= N; j++) {         if (frend[i][j] == i) continue;         long long mx = 0;         for (k = 1; k <= frend[i][j]; k++) {           if (k == i) continue;           mx = max(mx, liking[k]);         }         if (mx == liking[frend[i][j]]) {           cout << frend[i][j] <<    ;           break;         }       }     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int count_inversions(vector<int> v) {     int t = 0;     for (int i = 0; i < (int)v.size(); ++i)       for (int j = i + 1; j < (int)v.size(); ++j)         if (v[i] > v[j]) t++;     return t;   }   int main() {     int n;     scanf( %d , &n);     vector<int> v(n);     for (int i = 0; i < n; ++i) scanf( %d , &v[i]);     int inversions = count_inversions(v);     cout << (inversions / 2) * 4 + (inversions % 2) << endl;   }


#include <bits/stdc++.h>   long long mod;   long long solve(int dep, long long idx, long long left, long long right,                   long long l, long long r, long long u, long long v) {     if (right < l) return 0;     if (left > r) return 0;     if (left >= l && right <= r) {       long long delta = (1LL << dep);       long long begin = idx, end = idx + (right - left) * delta;       if (end < u) return 0;       if (begin > v) return 0;       if (begin < u) begin = begin + (u - begin) / delta * delta;       if (begin < u) begin += delta;       if (end > v) end = end - (end - v) / delta * delta;       if (end > v) end -= delta;       if (begin > end) return 0;       long long total = (end - begin) / delta + 1;       return ((total % mod) * ((begin + end) % mod)) % mod;     }     long long delta = (1LL << dep);     long long mid = (left + right) / 2;     return (solve(dep + 1, idx, left, mid, l, r, u, v) +             solve(dep + 1, idx + delta, mid + 1, right, l, r, u, v)) %            mod;   }   int main() {     long long n;     int m;     while (scanf( %I64d%d%I64d , &n, &m, &mod) == 3) {       mod *= 2;       for (int i = 0; i < m; i++) {         long long l, r, u, v;         scanf( %I64d%I64d%I64d%I64d , &l, &r, &u, &v);         printf( %I64d n , solve(0, 1, 1, n, l, r, u, v) / 2);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct _ {     ios_base::Init i;     _() {       cin.sync_with_stdio(0);       cin.tie(0);     }   } _;   const int MAXN = -1;   int n, m;   int main() {     int a, b;     cin >> a >> b;     int n = a + b + 1;     for (int i = n - a; i <= n; ++i) cout << i <<    ;     for (int i = n - a - 1; i >= 1; --i) cout << i <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, s = 0;     scanf( %I64d%I64d , &a, &b);     while (b != 0) {       s = s + a / b;       c = b;       b = a % b;       a = c;     }     printf( %I64d n , s);     return 0;   }


#include<bits/stdc++.h>   #define X first   #define Y second   #define sz(a) (int)a.size()   #define ll long long   //#define int long long   using namespace std;   const int mod = 1e9 + 7;   const int N = 3e5;      signed main()   {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);       int n, k;       cin >> n >> k;       string s;       cin >> s;       vector <int> vec;       for(int i = 0; i < n; i++)       {           if(s[i] ==  ? )           {               vec.push_back(-1);           }           else           {               vec.push_back(s[i] -  a );           }       }       vector <vector <int> > right(k, vector <int> (n, 0));       for(int i = 0; i < k; i++)       {           for(int j = n - 1; j >= 0; j--)           {               if(vec[j] == i || vec[j] == -1)               {                   if(j == n - 1)                   {                       right[i][j] = 1;                   }                   else                   {                       right[i][j] = right[i][j + 1] + 1;                   }               }      //         cout << right[i][j] <<    ;           }        //   cout <<   n ;       }       int l = 0, r = n + 1;       while(r - l > 1)       {           int midd = (r + l) / 2;           vector <vector <int> > mass(26);           for(int i = 0; i < k; i++)           {               for(int j = 0; j < n; j++)               {                   if(right[i][j] >= midd)                   {                       mass[i].push_back(j);                   }               }           }           vector <int> dp(1 << k, 1e9);           dp[0] = -1;           vector <int> iter(k, 0);           vector <vector <int> > mass1(n + 1);           mass1[0].push_back(0);           for(int i = 0; i < n; i++)           {               for(int j = 0; j < k; j++)               {                   while(iter[j] < sz(mass[j]) && mass[j][iter[j]] < i)                   {                       iter[j]++;                   }               }               for(auto p : mass1[i])               {                   if(dp[p] != i - 1)                   {                       continue;                   }                   for(int j = 0; j < k; j++)                   {                       if((1 << j) & p)                       {                           continue;                       }                       if(iter[j] < sz(mass[j]))                       {                           int u = mass[j][iter[j]];                           if(dp[(1 << j) | p] > u + midd - 1)                           {                               dp[(1 << j) | p] = u + midd - 1;                               mass1[u + midd].push_back((1 << j) | p);                           }                       }                   }               }           }           if(dp[(1 << k) - 1] < n)           {               l = midd;           }           else           {               r = midd;           }       }       cout << l;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int n, k, tot, root;   int ak[30];   int son[20000005][2], g[20000005];   long long ans;   void calc(int v, int *a) {     memset(a, 0, 120);     int i = 0;     while (v) {       a[i++] = v & 1;       v >>= 1;     }     return;   }   int make_node() {     ++tot;     return tot;   }   int get_ans(int x, int d) {     if (!son[x][d]) return 0;     return g[son[x][d]];   }   int ax[30];   void update(int x) {     int nd = root;     g[root]++;     for (int i = 30 - 1; i >= 0; i--) {       if (!son[nd][ax[i]]) son[nd][ax[i]] = make_node();       nd = son[nd][ax[i]];       g[nd]++;     }     return;   }   void query(int x) {     int nd = root;     for (int i = 30 - 1; i >= 0; i--) {       if (!ak[i]) {         ans += get_ans(nd, ax[i] ^ 1);         nd = son[nd][ax[i]];       } else         nd = son[nd][ax[i] ^ 1];       if (!nd) return;     }     ans += g[nd];     return;   }   int main() {     int x, y = 0;     scanf( %d %d , &n, &k);     root = make_node();     update(0);     calc(k, ak);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       y ^= x;       calc(y, ax);       query(y);       update(y);     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   vector<int> T;   int l, size;   void Stworz(int n) {     int p = 1;     while (p < n) p *= 2;     l = p;     size = 2 * p - 1;     for (int i = 0; i <= size; ++i) T.push_back(INF);   }   void Ustaw(int a, int x) {     a += l;     T[a] = x;     a /= 2;     while (a != 0) {       T[a] = min(T[2 * a], T[2 * a + 1]);       a /= 2;     }   }   int Mini(int a, int b) {     a += l;     b += l;     int m = min(T[a], T[b]);     while (a / 2 != b / 2) {       if (a % 2 == 0) m = min(m, T[a + 1]);       if (b % 2 == 1) m = min(m, T[b - 1]);       a /= 2;       b /= 2;     }     return m;   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<int> a(n);     map<int, int> wyst, pier;     for (int i = 0; i < n; ++i) {       cin >> a[i];       wyst[a[i]] = 0;       pier[a[i]] = INF;     }     Stworz(n);     vector<int> odp;     for (int L = 0; L < n;) {       int P = L;       while (P < n) {         ++wyst[a[P]];         if (pier[a[P]] == INF) pier[a[P]] = P;         Ustaw(P, pier[a[P]]);         if (pier[a[P]] + 1 <= P - 1) {           int ind = Mini(pier[a[P]] + 1, P - 1);           if (ind < pier[a[P]]) {             odp.push_back(a[ind]);             odp.push_back(a[P]);             odp.push_back(a[ind]);             odp.push_back(a[P]);             break;           }         }         if (wyst[a[P]] >= 4) {           for (int i = 0; i < 4; ++i) odp.push_back(a[P]);           break;         }         ++P;       }       for (int i = L; i <= min(P, n); ++i) {         --wyst[a[i]];         pier[a[i]] = INF;       }       L = P + 1;     }     cout << odp.size() << endl;     for (int i = 0; i < odp.size(); ++i) cout << odp[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, y, x, h, n;     cin >> a >> b >> c >> d;     y = (a * 3) / 10, x = (a - ((a / 250) * c)), h = (b * 3) / 10,     n = (b - ((b / 250) * d));     if (max(y, x) > max(n, h))       cout <<  Misha ;     else if (max(y, x) < max(n, h))       cout <<  Vasya ;     else       cout <<  Tie ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using P = pair<int, int>;   using Pl = pair<ll, int>;   const int mod = 1e9 + 7, INF = 1 << 30;   const double EPS = 1e-12, PI = 3.1415926535897932384626;   const ll LINF = 1LL << 60, lmod = 1e9 + 7;   const int MAX_N = 102;   vector<P> graph[MAX_N];   int memo[2][MAX_N][MAX_N][30];   int solve(bool is_first, int a, int b, int score) {     if (memo[int(is_first)][a][b][score] != -1)       return memo[int(is_first)][a][b][score];     if (is_first) {       bool win = false;       for (auto p : graph[a]) {         int u, c;         tie(u, c) = p;         if (c >= score) {           win |= (solve(false, u, b, c) == 1);         }       }       if (!win)         return memo[int(is_first)][a][b][score] = 0;       else         return memo[int(is_first)][a][b][score] = 1;     } else {       bool win = true;       for (auto p : graph[b]) {         int u, c;         tie(u, c) = p;         if (c >= score) {           win &= (solve(true, a, u, c) == 1);         }       }       if (win)         return memo[int(is_first)][a][b][score] = 1;       else         return memo[int(is_first)][a][b][score] = 0;     }   }   int main() {     int N, M;     cin >> N >> M;     for (int i = 0; i < M; i++) {       int a, b;       char c;       cin >> a >> b >> c;       a--;       b--;       graph[a].push_back(P(b, int(c -  a )));     }     for (int i = 0; i < 2; i++)       for (int j = 0; j < MAX_N; j++)         for (int k = 0; k < MAX_N; k++)           for (int l = 0; l < 30; l++) memo[i][j][k][l] = -1;     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) cout << (solve(true, i, j, 0) == 1 ?  A  :  B );       cout <<    << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     vector<pair<int, int>> v;     for (int i = 0; i < n; i++) {       long long a, b;       cin >> a >> b;       v.push_back(make_pair(a, b));     }     int c = 0;     for (int i = 0; i < n; i++) {       int up = 0, lo = 0, r = 0, l = 0;       for (int j = 0; j < n; j++) {         if (v[i].first > v[j].first && v[i].second == v[j].second) up = 1;         if (v[i].first < v[j].first && v[i].second == v[j].second) lo = 1;         if (v[i].first == v[j].first && v[i].second < v[j].second) l = 1;         if (v[i].first == v[j].first && v[i].second > v[j].second) r = 1;       }       if (up + lo + l + r == 4) c++;     }     cout << c;   }


#include <bits/stdc++.h>   using namespace std;   const short int N = 1000;   short int n, m, ax[] = {0, 0, 1, -1}, ay[] = {1, -1, 0, 0}, man_dis[N][N];   bool vis[N][N], v[N][N], g[N][N];   void good() {     for (short int i = 0; i < n; i++) {       for (short int j = 0; j < m; j++) {         bool f = 0;         if (i and v[i][j] == v[i - 1][j]) f = 1;         if (j and v[i][j] == v[i][j - 1]) f = 1;         if (i < n - 1 and v[i][j] == v[i + 1][j]) f = 1;         if (j < m - 1 and v[i][j] == v[i][j + 1]) f = 1;         g[i][j] = f;       }     }   }   void man_dist() {     queue<pair<short int, short int>> q;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (g[i][j]) man_dis[i][j] = 0, q.push({i, j}), vis[i][j] = true;     while (q.size()) {       short int y = q.front().first, x = q.front().second;       q.pop();       for (int i = 0; i < 4; i++) {         int nx = x + ax[i], ny = y + ay[i];         if (nx < 0 || ny < 0 || nx >= m || ny >= n || vis[ny][nx]) continue;         man_dis[ny][nx] = man_dis[y][x] + 1;         vis[ny][nx] = true;         q.push({ny, nx});       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt, ii = 0;     short int k = 0;     cin >> n >> m >> tt;     for (short int i = 0; i < n; i++)       for (short int j = 0; j < m; j++) {         char x;         cin >> x;         v[i][j] = (x ==  1 );       }     good();     man_dist();     while (ii++ < tt) {       short int i, j;       long long p;       cin >> i >> j >> p;       i--, j--;       if (n + m == 2) {         cout << v[i][j] << endl;         continue;       }       short int f = man_dis[i][j];       if (p <= f || !vis[i][j])         cout << v[i][j] << endl;       else         cout << (p - f + v[i][j]) % 2 << endl;     }     cerr <<  [Execution :   << (1.0 * clock()) / CLOCKS_PER_SEC <<  s] n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool oppSign(double a, double b) {     if (a == 0 || b == 0) return false;     if (a > 0 && b < 0) return true;     if (a < 0 && b > 0) return true;     return false;   }   void parr(vector<double>& a) {     for (int i = 0; i < a.size(); ++i) {       cout << a[i] <<    ;     }     cout << endl;   }   int main() {     int n;     cin >> n;     double a, b;     cin >> a >> b;     vector<pair<double, double> > v;     for (int i = 0; i < (n); ++i) {       double x, y;       scanf( %lf%lf , &x, &y);       double y1, y2;       y1 = x * a + y;       y2 = x * b + y;       v.push_back(make_pair((y1), (y2)));     }     sort(v.begin(), v.end());     vector<double> ar, br;     for (int i = 0; i < v.size(); ++i) {       double x = v[i].first;       double y = v[i].second;       ar.push_back(x);       br.push_back(y);     }     vector<double> bkr(br.size());     bkr[br.size() - 1] = br[br.size() - 1];     for (int i = br.size() - 2; i >= 0; --i) {       if (br[i] > bkr[i + 1])         bkr[i] = bkr[i + 1];       else         bkr[i] = br[i];     }     bool flag = false;     for (int i = 0; i < ar.size() - 1; ++i) {       if (ar[i] != ar[i + 1] && br[i] != bkr[i + 1] &&           oppSign((ar[i] - ar[i + 1]), (br[i] - bkr[i + 1]))) {         flag = true;         break;       }     }     if (flag == false)       cout <<  NO n ;     else       cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long ans;   int a[150000 + 1];   int main() {     scanf( %d , &n);     for (register int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       ans += 1LL * a[i] * (n - a[i] + 1);     }     for (register int i = 1; i <= n; ++i)       ans -= 1LL * min(a[i], a[i + 1]) * (n - max(a[i], a[i + 1]) + 1);     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = ~0u >> 1, N = 1000005;   int n, r, x, ans, fr;   char o[N];   void output(int x, int y) {     for (int i = n; i; --i)       if (x >= y)         o[i - 1] =  T , x -= y;       else         o[i - 1] =  B , y -= x;   }   int evaluate(int x, int y) {     int sta = 0, stb = 0, t;     while (x != 0 && y != 0 && sta <= n) {       if (x > y) {         if (x % y != 0) {           t = x / y;           sta += t;           stb += t - 1;           x %= y;         } else {           t = x / y - 1;           sta += t;           stb += t - 1;           x = y;           ++sta;           y = 0;         }       } else {         if (y % x != 0) {           t = y / x;           sta += t;           stb += t - 1;           y %= x;         } else {           t = y / x - 1;           sta += t;           stb += t - 1;           y = x;           ++sta;           x = 0;         }       }     }     if (x == 0 && y == 1 && sta == n)       return stb;     else       return -1;   }   void nrun() {     ans = n;     for (int i = 1; i < r; ++i) {       x = evaluate(i, r);       if (x != -1 && x <= ans) ans = x, fr = i;       x = evaluate(r, i);       if (x != -1 && x <= ans) ans = x, fr = -i;     }     if (ans == n)       printf( IMPOSSIBLE n );     else {       printf( %d n , ans);       if (fr > 0)         output(fr, r);       else         output(r, -fr);       puts(o);     }   }   int main() {     scanf( %d%d , &n, &r);     if (r == 1) {       printf(n == 1 ?  0 nT n  :  IMPOSSIBLE n );     } else       nrun();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   int n, k, a, b;   vector<int> v;   int ret(int lt, int rt) {     int id2 = upper_bound(v.begin(), v.end(), rt) - v.begin();     int id1 = lower_bound(v.begin(), v.end(), lt) - v.begin();     return id2 - id1;   }   long long dfs(int lt, int rt) {     int nm = ret(lt, rt);     if (!nm) return a;     long long on = b * 1LL;     on *= nm;     on *= (rt - lt + 1);     if (lt == rt) return on;     int md = (lt + rt) / 2;     long long tw = dfs(lt, md) + dfs(md + 1, rt);     return min(on, tw);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k >> a >> b;     for (int i = 1; i <= k; i++) {       int x;       cin >> x;       v.push_back(x);     }     sort(v.begin(), v.end());     cout << dfs(1, 1 << n) << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int inf = 1e9 + 9;   const long long MOD = 1e9 + 696969;   const long long INF = 1e18;   int n, m, k, a, b, c, w, h;   char s[1000100];   int dp[1000100][26], last[1000100][26];   pair<int, int> SECOND, MIN;   inline pair<int, int> minexc(int x) {     if (x != MIN.second) return MIN;     return SECOND;   }   char ret[1000100];   int main() {     scanf( %d%d , &n, &k) ?: 0;     scanf( %s , s + 1) ?: 0;     for (int i = 1; i <= n; ++i)       for (int j = 0; j < k; ++j) dp[i][j] = inf;     MIN = {0, -1};     SECOND = {0, 0};     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < k; ++j)         if (s[i] == (char)j +  A ) {           dp[i][j] = minexc(j).first;           last[i][j] = minexc(j).second;         } else           dp[i][j] = minexc(j).first + 1, last[i][j] = minexc(j).second;       MIN = {inf, inf};       SECOND = {inf, inf};       for (int j = 0; j < k; ++j)         if (dp[i][j] < MIN.first) {           SECOND = MIN;           MIN = make_pair(dp[i][j], j);         } else if (dp[i][j] < SECOND.first)           SECOND = make_pair(dp[i][j], j);     }     int res = inf, poz = inf;     for (int i = 0; i < k; ++i)       if (dp[n][i] < res) res = dp[n][i], poz = i;     cout << res << endl;     if (res == 0) {       for (int i = 1; i <= n; ++i) printf( %c , s[i]);       exit(0);     }     for (int i = n; i > 0; --i) {       ret[i] = poz +  A ;       poz = last[i][poz];     }     for (int i = 1; i <= n; ++i) printf( %c , ret[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9;   const long long INF64 = (long long)1e18;   const long double eps = 1e-9;   const long double pi = 3.14159265358979323846;   int dp[20][50];   int frmP[20][50], frmQ[20][50], frmE[20][50];   long long ten[20];   char str[60];   vector<long long> arr;   pair<long long, long long> rev[60];   long long num[20];   void update(int p1, int q1, int p2, int q2, int val) {     if (dp[p1][q1] == 0) {       dp[p1][q1] = 1;       frmP[p1][q1] = p2;       frmQ[p1][q1] = q2;       frmE[p1][q1] = val;     }   }   void re(int p1, int q1, int dep) {     if (p1) {       re(frmP[p1][q1], frmQ[p1][q1], dep + 1);       int xx, yy;       int i;       long long val;       val = arr[frmE[p1][q1]];       xx = rev[val].first;       yy = rev[val].second;       for (i = 0; i < xx; i++) num[i] += (4LL * ten[dep]);       for (i = 0; i < yy; i++) num[i + xx] += (7LL * ten[dep]);     }   }   int main() {     long long i, j, k;     for (i = 0; i <= 6; i++) {       for (j = 0; j + i <= 6; j++) {         arr.push_back(i * 4 + 7 * j);         rev[i * 4 + 7 * j] = (make_pair(i, j));       }     }     sort((arr).begin(), (arr).end());     int tn;     int len;     long long t;     t = 1;     for (i = 0; i <= 18; i++) {       ten[i] = t;       t *= 10LL;     }     cin >> tn;     while (tn--) {       cin >> str;       len = strlen(str);       memset(dp, 0, sizeof(dp));       dp[0][0] = 1;       for (i = 1; i <= len; i++) {         for (j = 0; j < 50; j++) {           if (dp[i - 1][j]) {             t = j * 10LL + (str[i - 1] -  0 );             for (k = 0; k < (int((arr).size())) && arr[k] <= t; k++) {               if (t - arr[k] < 50LL) {                 update(i, t - arr[k], i - 1, j, k);               }             }           }         }       }       if (!dp[len][0])         printf( -1 n );       else {         memset(num, 0, sizeof(num));         re(len, 0, 0);         for (i = 0; i < 6; i++) {           if (i) printf(   );           cout << num[i];         }         puts(  );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   const long long llinf = 1e18 + 7;   const double eps = 1e-15;   const int N = 2e5 + 5;   int cnt0[N], cnt1[N];   long long sum(int cnt[N], int l, int r) {     long long ret = cnt[r];     if (l) ret -= cnt[l - 1];     return ret;   }   int main() {     string a, b;     cin >> a >> b;     memset(cnt0, 0, sizeof cnt0);     memset(cnt1, 0, sizeof cnt1);     for (int i = 0; i < b.size(); ++i) {       cnt0[i] += b[i] ==  0 ;       if (i) cnt0[i] += cnt0[i - 1];       cnt1[i] += b[i] ==  1 ;       if (i) cnt1[i] += cnt1[i - 1];     }     long long ans = 0;     for (int i = 0; i < a.size(); ++i) {       int lastloc = int(b.size()) - int(a.size()) + i;       if (a[i] ==  1 ) {         ans += sum(cnt0, i, lastloc);       } else         ans += sum(cnt1, i, lastloc);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, r1, r2;     cin >> n >> r1 >> r2;     int a[n + 2];     for (int i = 1; i <= n; i++)       if (i != r1)         cin >> a[i];       else         a[i] = 0;     int v = r2, x = a[r2];     do {       int y = a[x];       a[x] = v;       v = x;       x = y;     } while (x != 0);     for (int i = 1; i <= n; i++)       if (i != r2) cout << a[i] <<    ;   }


#include<bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int,int>;   using pll = pair<ll,ll>;   #ifdef eclipse   #define debug(...) do{    fprintf(stderr,  LINE %d: (%s) =  ,__LINE__, #__VA_ARGS__ );     _do(__VA_ARGS__);    }while(0)   template<typename T> void _do(T &&_x) {cerr << _x << endl;}   template<typename T, typename ...S> void _do(T &&_x, S &&..._t) {cerr << _x <<  ,  ; _do(_t...);}   #else   #define debug(...)   #endif      const int MAXN = 300005;   int n, in[MAXN], in2[MAXN];      int calc() {    int ans = 0;    for (int i = 1; i < n - 1; ++i) {     if (in[i] < min(in[i-1], in[i+1])) ans++;     else if (in[i] > max(in[i-1], in[i+1])) ans++;    }     return ans;   }         int calc2(int idx) {    int x, y; x = y = 0;    for (int i = idx - 1; i <= idx + 1; ++i) {     if (i == 0 || i == n - 1) continue;     if (in[i] < min(in[i-1], in[i+1])) y++;     else if (in[i] > max(in[i-1], in[i+1])) y++;    }       for (int i = idx - 1; i <= idx + 1; ++i) {     if (i == 0 || i == n - 1) continue;     if (in2[i] < min(in2[i-1], in2[i+1])) x++;     else if (in2[i] > max(in2[i-1], in2[i+1])) x++;    }    return x - y;   }      signed main (){    ios::sync_with_stdio(0),cin.tie(0);    int t;    cin >> t;    while (t--) {     cin >> n;     for (int i = 0; i < n; ++i) cin >> in[i];     for (int i = 0; i < n; ++i) in2[i] = in[i];     int ans, now = calc();     ans = now;     for (int i = 1; i < n - 1; ++i) {      int tmp = in[i];      in[i] = in[i-1];      ans = min(ans, now - calc2(i));      in[i] = in[i+1];      ans = min(ans, now - calc2(i));      in[i] = tmp;     }      cout << ans <<   n ;    }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   int resp;   int ask(long long x) {     printf( ? %lld n , x);     fflush(stdout);     scanf( %d , &resp);     return resp;   }   void ans(long long x) {     printf( = %lld n , x);     fflush(stdout);   }   void solve() {     scanf( %lld , &n);     if (n == 2ll) {       resp = ask(1ll);       resp = ask(2ll);       if (resp)         ans(1ll);       else         ans(2ll);       return;     } else if (n == 3ll) {       resp = ask(2ll);       resp = ask(1ll);       if (resp)         ans(1ll);       else {         resp = ask(3ll);         if (resp)           ans(2ll);         else           ans(3ll);       }       return;     }     vector<long long> path_mid_to_hi;     long long lf = 1ll, rg = n - 1ll;     for (long long md; lf <= rg;) {       md = (lf + rg) / 2ll;       path_mid_to_hi.push_back(md);       if (lf == rg && md == n - 1ll) break;       lf = md + 1ll;     }     long long st = n, bf = n;     reverse(path_mid_to_hi.begin(), path_mid_to_hi.end());     bool go_left = 1;     for (long long i : path_mid_to_hi) {       bf = st;       if (go_left)         st -= i;       else         st += i;       go_left ^= 1;     }     if (bf < st)       go_left = 1;     else       go_left = 0;     lf = 1ll, rg = n - 1ll;     long long res = n;     resp = ask(st);     for (long long md; lf <= rg;) {       md = (lf + rg) / 2;       if (go_left)         st -= md;       else         st += md;       resp = ask(st);       if (resp) {         res = md;         rg = md - 1;       } else         lf = md + 1;       go_left ^= 1;     }     ans(res);     return;   }   int main() {     int tc;     scanf( %d , &tc);     for (; tc--;) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n, m;     cin >> n >> m;     vector<long long int> v;     long long int s = (m + 1) / 2;     v.push_back(s);     long long int i = 1;     if (m % 2) {       while (1) {         if (s + i == m + 1) break;         if (s - i > 0) v.push_back(s - i);         v.push_back(s + i);         i++;       }     } else {       while (1) {         if (s + i == m + 1) break;         v.push_back(s + i);         if (s - i > 0) v.push_back(s - i);         i++;       }     }     i = 0;     while (i < n) {       cout << v[i] <<   n ;       v.push_back(v[i]);       i++;     }     return 0;   }


#include <bits/stdc++.h>   const int INF = 1 << 29;   int cmp(const void* a, const void* b);   long long maxv(long long a, long long b);   long long minv(long long a, long long b);   long long gcd(long long u, long long v);   int main() {     long long t = 1, i = 0;     while (t--) {       long long r, d, n;       scanf( %lld%lld%lld , &r, &d, &n);       long long ans = 0, x, y, cr;       for (long long i = 0; i < (n); i++) {         scanf( %lld%lld%lld , &x, &y, &cr);         if (x * x + y * y <= (r - cr) * (r - cr) && 2 * cr <= d &&             x * x + y * y >= (r - d + cr) * (r - d + cr))           ans++;       }       printf( %lld n , ans);     }   }   int cmp(const void* a, const void* b) {     if (*(long long*)a - *(long long*)b < 0) return -1;     if (*(long long*)a - *(long long*)b > 0) return 1;     return 0;   }   long long maxv(long long a, long long b) {     if (a > b) return a;     return b;   }   long long minv(long long a, long long b) {     if (a < b) return a;     return b;   }   long long gcd(long long u, long long v) {     if (v == 0) return u;     return gcd(v, u % v);   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, -1, 1};   void arquivo() {     freopen(  ,  r , stdin);     freopen(  ,  w , stdout);   }   const int N = 505050;   struct no {     int l, r;     int op;     no(){};     no(int a, int b, int c) {       op = a;       l = b;       r = c;     }   };   no vet[N];   int n, m, p;   char s[N];   inline void print() {     p = vet[0].r;     while (p != n + 1) {       printf( %c , vet[p].op == 1 ?  (  :  ) );       p = vet[p].r;     }     printf(  n );   }   inline void goRemove() {     int p1 = p;     int p2 = p;     int qtd = vet[p1].op;     while (qtd > 0) {       p2 = vet[p2].r;       qtd += vet[p2].op;     }     while (qtd < 0) {       p2 = vet[p2].l;       qtd += vet[p2].op;     }     int esq = min(p1, p2);     int dir = max(p1, p2);     esq = vet[esq].l;     dir = vet[dir].r;     vet[esq].r = dir;     vet[dir].l = esq;     if (dir != n + 1)       p = dir;     else       p = esq;   }   int main() {     scanf( %d %d %d , &n, &m, &p);     vet[0].r = 1;     vet[0].l = 0;     for (int i = 1; i <= n; ++i) {       char c;       scanf(  %c , &c);       if (c ==  ( )         vet[i] = no(1, i - 1, i + 1);       else         vet[i] = no(-1, i - 1, i + 1);     }     vet[n + 1].l = n;     vet[n + 1].r = n + 1;     scanf(  %s , s);     int len = strlen(s);     for (int i = 0; i < len; ++i) {       if (s[i] ==  L )         p = vet[p].l;       else if (s[i] ==  R )         p = vet[p].r;       else         goRemove();     }     print();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long f[305][305][5];   struct point {     int x, y;     point(int x = 0, int y = 0) : x(x), y(y) {}   } a[305];   struct edge {     int u, v;     double w;     edge(int u = 0, int v = 0, double w = 0) : u(u), v(v), w(w) {}     bool operator<(const edge b) const { return w < b.w; }   } s[305 * 305];   int read() {     char c = getchar();     int x = 0, s = 1;     while (!isdigit(c)) {       if (c ==  - ) s = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }     return x * s;   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) {       a[i].x = read();       a[i].y = read();     }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         if (i != j) s[++m] = edge(i, j, atan2(a[i].y - a[j].y, a[i].x - a[j].x));     sort(s + 1, s + m + 1);     for (int i = 1; i <= m; ++i) {       int u = s[i].u, v = s[i].v;       f[u][v][0] = 1;       for (int k = 1; k <= 4; ++k)         for (int j = 1; j <= n; ++j) f[j][v][k] += f[j][u][k - 1];     }     long long ans = 0;     for (int i = 1; i <= n; ++i) ans += f[i][i][4];     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int in[30];   int out[1050000][2];   int oc;   int n;   int pre[30];   int cnt[30][2];   inline int cntf(int np, int b) {     if (cnt[np][b] != -1) return cnt[np][b];     if (np == n) return cnt[np][b] = 0;     if (!b)       return cnt[np][b] = cntf(pre[np] + 1, b) * 2 + (pre[np] - np + 1);     else {       int w1 = cntf(np + 1, 0) * 2 + 1;       int w2 = cntf(pre[np] + 1, 0) * 2 + cntf(pre[np] + 1, 1) +                (pre[np] - np + 1) * 2;       return cnt[np][b] = min(w1, w2);     }   }   inline void move(int a, int b, int c, bool base, int np) {     if (np == n) return;     if (base) {       int d1 = cntf(np, 1);       int d2 = cntf(np + 1, 0) * 2 + 1;       if (d1 == d2) {         move(a, c, b, false, np + 1);         out[oc][0] = a;         out[oc][1] = b;         oc++;         move(c, b, a, false, np + 1);       } else {         move(a, b, c, false, pre[np] + 1);         for (int i = np; i <= pre[np]; i++) {           out[oc][0] = a;           out[oc][1] = c;           oc++;         }         move(b, a, c, false, pre[np] + 1);         for (int i = np; i <= pre[np]; i++) {           out[oc][0] = c;           out[oc][1] = b;           oc++;         }         move(a, b, c, true, pre[np] + 1);       }     } else {       move(a, c, b, false, pre[np] + 1);       for (int i = np; i <= pre[np]; i++) {         out[oc][0] = a;         out[oc][1] = b;         oc++;       }       move(c, b, a, false, pre[np] + 1);     }   }   int main() {     int i;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &in[i]);     }     pre[n - 1] = n - 1;     for (i = n - 2; i >= 0; i--) {       if (in[i] == in[i + 1])         pre[i] = pre[i + 1];       else         pre[i] = i;     }     memset(cnt, -1, sizeof(cnt));     oc = 0;     move(1, 3, 2, true, 0);     printf( %d n , oc);     for (i = 0; i < oc; i++) printf( %d %d n , out[i][0], out[i][1]);   }


#include <bits/stdc++.h>   using namespace std;   using std::bitset;   const double Pi = acos(-1);   inline long long read() {     long long x = 0;     bool fu = 0;     char ch = 0;     while (ch >  9  || ch <  0 ) {       ch = getchar();       if (ch ==  - ) fu = 1;     }     while (ch <=  9  && ch >=  0 ) x = (x * 10 - 48 + ch), ch = getchar();     return fu ? -x : x;   }   long long n, mod, w[100002], q, l, r;   map<long long, long long> phi;   inline long long go(long long num) {     long long rt = num;     for (long long i = 2; i * i <= num; i++) {       if (num % i == 0) rt = rt * (i - 1) / i;       while (num % i == 0) num /= i;     }     if (num > 1) rt = rt * (num - 1) / num;     return rt;   }   inline long long pw(long long x, long long p, long long mod) {     bool flag = 0;     long long rt = 1;     while (p) {       if (p & 1) {         if (rt * x >= mod) flag = 1;         rt = rt * x % mod;       }       if (x * x >= mod) flag = 1;       x = x * x % mod, p >>= 1;     }     return rt + flag * mod;   }   inline long long dfs(long long pos, long long mod) {     if (pos > r || mod == 1) return 1;     return pw(w[pos], dfs(pos + 1, phi[mod]), mod);   }   signed main() {     cin >> n >> mod;     l = mod;     phi[1] = 1;     while (l > 1) phi[l] = go(l), l = phi[l];     for (register long long i = 1, iend = n; i <= iend; ++i) w[i] = read();     cin >> q;     while (q--) {       l = read(), r = read();       cout << dfs(l, mod) % mod <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int maxn = 200;   long long x, y, l, r;   void solve() {     set<long long> a, b, S;     a.insert(1);     b.insert(1);     long long base = x;     while (base <= INF) {       a.insert(base);       if (INF / base < x || x == 1) break;       base *= x;     }     base = y;     while (base <= INF) {       b.insert(base);       if (INF / base < y || y == 1) break;       base *= y;     }     for (auto i : a)       for (auto j : b)         if (i + j <= r && i + j >= l) S.insert(i + j);     S.insert(r + 1);     long long pre = l - 1;     long long ans = 0;     for (auto z : S) {       ans = max(ans, z - pre - 1);       pre = z;     }     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(false);     while (cin >> x >> y >> l >> r) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int m;     int a[100005] = {0};     int b[100005] = {0};     cin >> s;     s =     + s;     cin >> m;     for (int i = 1; i <= s.length(); i++) {       if (s[i] == s[i + 1]) a[i] = 1;     }     for (int i = 1; i <= s.length(); i++) {       b[i] = b[i - 1] + a[i];     }     while (m--) {       int l, r, flag = 0;       cin >> l >> r;       flag = b[r - 1] - b[l - 1];       cout << flag << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void test_case() {     int n, i, cnt;     cin >> n;     string str;     cin >> str;     cnt = 0;     vector<int> c(n + 5, 0);     vector<int> flag(n + 5, 0);     int fl = 0;     for (i = n - 1; i >= 0; i--) {       if (str[i] ==  ( )         cnt++;       else         cnt--;       c[i] = cnt;       if (cnt > 0) fl = 1;       flag[i] = fl;     }     cnt = 0;     int ans = 0;     fl = 0;     for (i = 0; i < n; i++) {       if (fl == 0 && str[i] ==  )  && cnt + 1 == -c[i + 1] && cnt + 1 >= 0 &&           flag[i + 1] == 0) {         ans++;       } else if (fl == 0 && str[i] ==  (  && cnt - 1 == -c[i + 1] &&                  cnt - 1 >= 0 && flag[i + 1] == 0) {         ans++;       }       if (str[i] ==  ( )         cnt++;       else if (str[i] ==  ) )         cnt--;       if (cnt < 0) fl = 1;     }     cout << ans <<   n ;     return;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int t;     t = 1;     while (t--) {       test_case();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000 + 4;   char s[maxn];   int a[maxn];   void get(bitset<maxn> &B) {     scanf( %s , s);     int m = strlen(s);     int x = 1, y = -1;     for (int i = 0; i < m; i++) a[m - 1 - i] = s[i] -  0 ;     m--;     x += m + y;     ++x;     for (int i = 0; i < maxn && x >= 0; i++) {       int rem = 0;       for (int j = m; j >= 0; j--) a[j] += rem * 10, rem = (a[j] & 1), a[j] >>= 1;       B[i] = rem;       while (m >= 0 && !a[m]) m--;       x = m;     }   }   int pos[maxn];   bitset<maxn> b[maxn], st[maxn];   int main() {     if (fopen( in ,  r )) {       freopen( in ,  r , stdin);       freopen( out ,  w , stdout);     }     memset(pos, -1, sizeof(pos));     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       get(b[i]);       st[i][i] = 1;       bool ok = 1;       for (int j = 0; j < maxn; j++)         if (b[i][j]) {           if (pos[j] == -1) {             ok = 0;             pos[j] = i;             break;           }           b[i] ^= b[pos[j]];           st[i] ^= st[pos[j]];         }       if (!ok) {         printf( 0 n );         continue;       }       st[i][i] = 0;       printf( %d , st[i].count());       for (int j = 0; j < maxn; j++)         if (st[i][j]) printf(  %d , j);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   ifstream fin;   ofstream fout;   FILE *outt, *inn;   const int N = 100009, M = 70;   int k, b[M], d[M], k2, y, yy;   unsigned long long m, c[M][M], l, r, cur;   void find() {     for (int i = 0; i <= 64; i++) {       for (int j = 0; j <= 64; j++) {         if (i == 0) {           c[i][j] = 1;           continue;         }         if (i > j) continue;         c[i][j] = c[i - 1][j - 1] + c[i][j - 1];       }     }   }   int cnt;   bool is;   void binary(unsigned long long x) {     memset(b, 0, sizeof(b));     is = 0;     cnt = 69;     while (x > 0) {       b[--cnt] = x % 2;       x /= 2;     }     b[0] = cnt;     for (int i = b[0] + 1; i <= 68; i++) {       if (b[i]) {         return;       }     }     is = 1;   }   unsigned long long solve(unsigned long long x) {     cur = 0;     binary(2 * x);     k2 = k - 1;     for (int i = b[0] + 1; i <= 68; i++) {       if (b[i] == 1) {         y = 68 - i;         cur += c[k2][y];         k2--;       }       if (k2 == 0) {         for (int j = i + 1; j <= 68; j++) {           if (b[j]) {             cur++;             break;           }         }         break;       }     }     k2 = 0;     for (int i = b[0]; i <= 68; i++) {       if (b[i]) k2++;     }     if (k2 == k) cur++;     binary(x + 1);     if (!is) {       k2 = k - 1;       for (int i = b[0] + 1; i <= 68; i++) {         if (b[i] == 0) {           cur += c[k2 - 1][68 - i];         }         if (b[i] == 1) {           k2--;         }         if (k2 == 0) {           break;         }       }       k2 = 0;       for (int i = b[0]; i <= 68; i++) {         if (b[i]) k2++;       }       if (k2 == k) cur++;     }     return cur;   }   int main() {     memset(c, 0, sizeof(c));     find();     cin >> m >> k;     r = (unsigned long long)1;     while (solve(r) < m) {       r *= 2;     }     l = r / 2 + 1;     while (l < r) {       unsigned long long mid = (l + r) / 2;       unsigned long long res = solve(mid);       if (res < m) {         l = mid + 1;       } else if (res > m) {         r = mid - 1;       } else {         cout << mid;         return 0;       }     }     cout << l;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<pair<int, int>, int> ord;   vector<pair<int, int> > edges;   vector<int> adj[200000];   int n;   int main() {     cin >> n;     cout << n - 1 << endl;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       edges.push_back(make_pair(a, b));       ord[make_pair(a, b)] = ord[make_pair(b, a)] = i;       adj[a].push_back(b);       adj[b].push_back(a);       cout <<  2   << a <<     << b << endl;     }     for (int i = 1; i <= n; i++)       for (int j = 0; j < adj[i].size() - 1; j++)         cout << ord[make_pair(i, adj[i][j])] <<                  << ord[make_pair(i, adj[i][j + 1])] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int Max[100010 * 4], Min[100010 * 4];   int dp_Min[100010 * 4];   int a[100010];   int dp[100010];   int ql, qr, val;   void build(int l, int r, int o) {     if (l == r) {       Max[o] = Min[o] = a[l];       return;     }     int mid = l + (r - l) / 2;     build(l, mid, o * 2);     build(mid + 1, r, o * 2 + 1);     Max[o] = max(Max[o * 2], Max[o * 2 + 1]);     Min[o] = min(Min[o * 2], Min[o * 2 + 1]);   }   int query_max(int l, int r, int o) {     if (ql <= l && qr >= r) {       return Max[o];     }     int mid = l + (r - l) / 2;     int ans = -0x3f3f3f3f;     if (ql <= mid) ans = max(ans, query_max(l, mid, o * 2));     if (qr > mid) ans = max(ans, query_max(mid + 1, r, o * 2 + 1));     return ans;   }   int query_min(int l, int r, int o) {     if (ql <= l && qr >= r) {       return Min[o];     }     int mid = l + (r - l) / 2;     int ans = 0x3f3f3f3f;     if (ql <= mid) ans = min(ans, query_min(l, mid, o * 2));     if (qr > mid) ans = min(ans, query_min(mid + 1, r, o * 2 + 1));     return ans;   }   int query2(int l, int r, int o) {     if (ql <= l && qr >= r) {       return dp_Min[o];     }     int mid = l + (r - l) / 2;     int ans = 0x3f3f3f3f;     if (ql <= mid) ans = min(ans, query2(l, mid, o * 2));     if (qr > mid) ans = min(ans, query2(mid + 1, r, o * 2 + 1));     return ans;   }   void update(int l, int r, int o) {     if (l == r) {       dp_Min[o] = val;       return;     }     int mid = l + (r - l) / 2;     if (ql <= mid)       update(l, mid, o * 2);     else       update(mid + 1, r, o * 2 + 1);     dp_Min[o] = min(dp_Min[o * 2], dp_Min[o * 2 + 1]);   }   int main() {     int n, s, l;     scanf( %d%d%d , &n, &s, &l);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     build(1, n, 1);     memset(dp_Min, 0x3f3f3f3f, sizeof(dp_Min));     for (int i = 1; i < l; i++) dp[i] = 0x3f3f3f3f;     for (int i = l; i <= n; i++) {       int x = 1, y = i - l + 2;       while (x < y) {         int mid = x + (y - x) / 2;         ql = mid, qr = i;         int val = query_max(1, n, 1) - query_min(1, n, 1);         if (val > s)           x = mid + 1;         else           y = mid;       }       if (x == i - l + 2) {         dp[i] = 0x3f3f3f3f;         continue;       }       ql = x - 1, qr = i - l;       if (ql <= qr && qr)         dp[i] = query2(1, n, 1) + 1;       else         dp[i] = 0x3f3f3f3f;       if (x - 1 == 0) dp[i] = 1;       val = dp[i];       ql = i;       update(1, n, 1);     }     printf( %d n , dp[n] >= 0x3f3f3f3f ? -1 : dp[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[100010];     int b[100010];     while (scanf( %d , &a[0]) != EOF) {       getchar();       int n = 1;       while (scanf( %d , &a[n]) != EOF) {         n++;         getchar();       }       sort(a, a + n);       a[n] = 9999999;       int h = 0;       for (int i = 0; i < n; i++) {         if (i == 0) {           b[h++] = a[i];         } else if (a[i] != a[i - 1]) {           b[h++] = a[i];         }       }       b[h] = 99999;       int p = b[0];       int q = b[0];       int flag = 0;       int ff = 0;       for (int i = 1; i <= h; i++) {         if (b[i] == b[i - 1] + 1) {           p = b[i];         } else if (b[i] != b[i - 1] + 1) {           ff = 1;           if (flag == 1) {             printf( , );           }           flag = 1;           if (p == q) {             printf( %d , p);           } else {             printf( %d-%d , q, p);           }           p = b[i];           q = b[i];         }       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[1010];   int main() {     long long n, k, p;     int q;     scanf( %I64d%I64d%d , &n, &k, &q);     p = n - k;     for (int i = 0; i < q; i++) scanf( %I64d , a + i);     if (k == 0) {       for (int i = 0; i < q; i++) printf( . );       return 0;     }     for (int i = 0; i < q; i++) {       if (n % 2 == 0) {         if (k <= p) {           if (a[i] <= n - 2 * k)             printf( . );           else if (a[i] % 2 == 1)             printf( . );           else             printf( X );         } else {           if (a[i] > 2 * p)             printf( X );           else if (a[i] % 2 == 1)             printf( . );           else             printf( X );         }       } else {         if (p < k) {           if (a[i] <= 2 * p) {             if (a[i] % 2 == 1)               printf( . );             else               printf( X );           } else             printf( X );         } else {           if (a[i] == n)             printf( X );           else if (a[i] <= p - k + 1)             printf( . );           else if (a[i] % 2 == 1)             printf( . );           else             printf( X );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.14159265358979323846;   const int MAXN = 1e5 + 3;   long long n, a, b, p, q;   bool isLeap(int a) {     if (a % 400 == 0) return true;     if (a % 4 == 0 && a % 100) return true;     return false;   }   void solve() {     int y;     cin >> y;     int cnt = 0;     bool f = 0;     if (isLeap(y)) f = 1;     y++;     bool isl = 0;     while (1) {       cnt += 365;       isl = isLeap(y);       if (isl) cnt++;       if (cnt % 7 == 0 && isl == f) break;       y++;     }     cout << y;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod1 = 1e9 + 7, mod = 998244353;   const long long N = 3e5 + 7;   long long ncr[N];   void fact(long long A) {     auto binexp = [&](long long a, long long b) {       long long res = 1;       while (b) {         if (b & 1) res *= a;         a *= a;         b >>= 1;         a %= mod;         res %= mod;       }       return res;     };     ncr[0] = 1;     for (long long i = 1; i <= A; i++)       ncr[i] = ncr[i - 1] * (A - i + 1) % mod * binexp(i, mod - 2) % mod;   }   void a_b_l() {     long long n;     cin >> n;     n <<= 1;     long long ar[n];     for (long long i = 0; i < n; i++) cin >> ar[i];     sort(ar, ar + n);     long long k = 0;     for (long long i = 0; i < n / 2; i++) {       k += ar[n - i - 1] - ar[i];       k %= mod;     }     fact(n);     long long ans = k * ncr[n / 2] % mod;     cout << ans <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     ;     long long t = 1;     while (t--) a_b_l();   }


#include <bits/stdc++.h>   using namespace std;   const double PAI = atan(1.0) * 4;   const double EPS = 1e-5;   int n;   double theta;   struct Point {     double x, y;     Point() {}     Point(double _x, double _y) : x(_x), y(_y) {}     Point operator+(const Point &r) const { return Point(x + r.x, y + r.y); }     Point operator-(const Point &r) const { return Point(x - r.x, y - r.y); }     Point operator*(double r) const { return Point(x * r, y * r); }     Point operator/(double r) const { return Point(x / r, y / r); }     Point rotate(double alpha) const {       double s = sin(alpha), c = cos(alpha);       return Point(x * c - y * s, x * s + y * c);     }     double lenght(const Point &r) const {       return sqrt((x - r.x) * (x - r.x) + (y - r.y) * (y - r.y));     }     Point cross_X(const Point &r) const {       double l = x - r.x;       l = l * r.y / (r.y - y);       return Point((x * r.y - y * r.x) / (r.y - y), 0);     }   } p[105];   bool same(double x, double y) { return ((x - y) <= EPS && (y - x) <= EPS); }   bool check() {     double l[105];     l[1] = p[1].lenght(p[n]);     for (int i = 2; i <= n; i++) l[i] = p[i].lenght(p[i - 1]);     for (int i = 1; i <= n; i++) {       if (p[i].x > 1000000 || p[i].x < -1000000) return false;       if (p[i].y > 1000000 || p[i].y < -1000000) return false;       if (l[i] > 1000 || l[i] < 1) return false;       for (int j = 1; j < i; j++)         if (same(l[i], l[j])) return false;     }     return true;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     if (n <= 4) {       cout <<  No solution  << endl;       return 0;     }     theta = 2 * PAI / n;     while (true) {       p[1] = Point(0, 0);       for (int i = 2; i <= n / 2; i++) {         p[i] = Point(2 * i, 0);         p[i] = p[i].rotate(theta * (i - 1)) + p[i - 1];       }       p[n / 2 + 1] = Point(900, 0);       p[n / 2 + 1] = p[n / 2 + 1].rotate(theta * (n / 2)) + p[n / 2];       for (int i = n / 2 + 2; i <= n; i++) {         p[i] = Point(2 * (i - n / 2) - 1, 0);         p[i] = p[i].rotate(theta * (i - 1)) + p[i - 1];       }       p[n] = p[n - 1].cross_X(p[n]);       if (check()) break;     }     for (int i = 1; i <= n; i++) printf( %lf %lf n , p[i].x, p[i].y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class point {    public:     int x, ind;     point(int dx = 0, int _ind = 0) {       x = dx;       ind = _ind;     }   };   int n, k, f[210][210];   point a[210], c[210];   bool cmpx(point A, point B) { return A.x < B.x; }   bool cmpi(point A, point B) { return A.ind < B.ind; }   int main() {     cin >> n >> k;     for (int i = 0; i < n; ++i) {       cin >> a[i].x;       a[i].ind = i;       c[i] = a[i];     }     sort(c, c + n, cmpx);     for (int i = 0; i < n; ++i)       for (int j = i; j < n; ++j)         for (int q = i; q <= j; ++q) f[i][j] += a[q].x;     for (int i = 0; i < n; ++i)       for (int j = i; j < n; ++j) {         sort(a + i, a + j + 1, cmpx);         int t = n - 1;         int cnt = k;         for (int q = i; q <= j; ++q) {           while ((c[t].ind >= i) && (c[t].ind <= j) && (t >= 0)) --t;           if ((t >= 0) && (cnt > 0) && (c[t].x > a[q].x)) {             f[i][j] = f[i][j] - a[q].x + c[t].x;             --t;             --cnt;           } else             break;         }         sort(a + i, a + j + 1, cmpi);       }     int mx = f[0][0];     for (int i = 0; i < n; ++i)       for (int j = i; j < n; ++j)         if (mx < f[i][j]) mx = f[i][j];     cout << mx;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   double h, d, c, n, mx;   int hh, mm;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> hh >> mm;     hh = hh * 60 + mm;     cin >> h >> d >> c >> n;     double nec = ceil(h / n) * c;     if (hh >= 1200 && hh < 1440)       return cout << setprecision(5) << fixed << nec * 0.8, 0;     mm = 20 * 60;     int diff = mm - hh;     double nec2 = ceil((diff * d + h) / n) * c;     cout << setprecision(5) << fixed << min(nec2 * 0.8, nec);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static int i = 0;   int fun(long long n) {     i++;     if (n % 2 == 1)       return 0;     else       fun(n / 2);   }   int main() {     int n;     long long k;     scanf( %d %lld , &n, &k);     fun(k);     printf( %d , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, id[105], m, i, j;   unsigned long long cant[105], c[105], T[105], total, sol, factor, x, llevo;   bool cmp(const int i, const int j) { return c[i] < c[j]; }   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++) {       cin >> cant[i] >> c[i];       total += cant[i];       id[i] = i;     }     sort(id, id + n, cmp);     scanf( %d , &m);     for (i = 0; i < m; i++) cin >> T[i];     factor = 1;     llevo = 0;     i = 0;     while (total > 0 && i < m) {       if (llevo == T[i]) factor++, i++;       j = 0;       while (total > 0 && i < m && llevo < T[i]) {         x = min(cant[id[j]], T[i] - llevo);         cant[id[j]] -= x;         total -= x;         sol += x * factor * c[id[j]];         llevo += x;         j++;       }     }     for (i = 0; i < n; i++) sol += cant[i] * factor * c[i];     cout << sol << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct segment {     int l, r, p;   } seg[300005];   struct PS {     int l, r, val;   } P[300005 * 20];   int n, m, k, a, b, l, r, tot;   int suf[300005];   int get(int node, int bas, int son, int x, int y) {     if (bas >= x && son <= y) return P[node].val;     bool l = (((bas + son) >> 1) >= x);     bool r = (((bas + son) >> 1) + 1 <= y);     if (l & r)       return max(get(P[node].l, bas, ((bas + son) >> 1), x, y),                  get(P[node].r, ((bas + son) >> 1) + 1, son, x, y));     if (l) return get(P[node].l, bas, ((bas + son) >> 1), x, y);     return get(P[node].r, ((bas + son) >> 1) + 1, son, x, y);   }   void create(int& node) {     node = ++tot;     P[node].val = 1005000000;   }   void up(int& node, int prv, int bas, int son, int x, int val) {     if (!node) create(node);     if (bas == x && son == x) {       P[node].val = min(val, P[prv].val);       return;     }     if (x <= ((bas + son) >> 1)) {       P[node].r = P[prv].r;       up(P[node].l, P[prv].l, bas, ((bas + son) >> 1), x, val);     } else {       P[node].l = P[prv].l;       up(P[node].r, P[prv].r, ((bas + son) >> 1) + 1, son, x, val);     }     P[node].val = max(P[P[node].l].val, P[P[node].r].val);   }   int main() {     P[0].val = 1005000000;     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= k; i++) {       scanf( %d %d %d , &seg[i].l, &seg[i].r, &seg[i].p);     }     sort(seg + 1, seg + 1 + k, [](segment a, segment b) { return a.l < b.l; });     for (int i = k; i >= 1; i--) {       up(suf[i], suf[i + 1], 1, n, seg[i].p, seg[i].r);     }     while (m--) {       scanf( %d %d %d %d , &a, &b, &l, &r);       int bas = 1, son = k;       while (bas <= son) {         if (seg[((bas + son) >> 1)].l < l)           bas = ((bas + son) >> 1) + 1;         else           son = ((bas + son) >> 1) - 1;       }       printf(get(suf[bas], 1, n, a, b) > r ?  no  :  yes );       puts(  );       fflush(stdout);     }   }