#include <bits/stdc++.h>   inline long long int min(long long int a, long long int b) {     return (a < b) ? a : b;   }   long long int dp[303][303], cost[303][303];   int main() {     int n, m, k, o, j, i;     scanf( %d %d %d , &n, &m, &o);     for (i = 0; i <= n; i++)       for (j = 0; j <= n; j++) dp[i][j] = cost[i][j] = 10000000000000LL;     for (i = 0; i < m; i++) {       int l, r, c;       scanf( %d %d %d , &l, &r, &c);       cost[l][r] = min(cost[l][r], c);     }     for (i = 1; i <= n; i++)       for (j = 1; j <= i; j++)         for (k = i; k <= n; k++) {           cost[j][i] = min(cost[j][i], cost[j][k]);           cost[i][k] = min(cost[i][k], cost[j][k]);         }     for (i = 0; i <= n; i++) {       dp[i][0] = 0;       for (j = 1; j <= i; j++) {         dp[i][j] = min(cost[i - j + 1][i], dp[i - 1][j]);         for (k = 1; k < j; k++)           dp[i][j] = min(dp[i][j], cost[i - k + 1][i] + dp[i - k][j - k]);       }     }     if (dp[n][o] != 10000000000000LL)       printf( %I64d n , dp[n][o]);     else       printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast ,  unroll-loops )   using namespace std;   const long long inf = 1ll << 60;   const long long iinf = 2147483647;   const long long mod = 998244353;   const long long maxn = 1e3 + 5;   long long pw(long long x, long long p) {     long long ret = 1;     while (p > 0) {       if (p & 1) {         ret *= x;         ret %= mod;       }       x *= x;       x %= mod;       p >>= 1;     }     return ret;   }   long long inv(long long x) { return pw(x, mod - 2); }   long long dp[5005][5005];   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     long long n;     cin >> n;     vector<long long> vc(n);     for (long long i = (0); i < (n); i++) {       cin >> vc[i];     }     for (long long i = (1); i < (n + 1); i++) {       for (long long j = (1); j < (n - i + 1 + 1); j++) {         if (i == 1) {           dp[i][j] = vc[j - 1];           continue;         }         dp[i][j] = dp[i - 1][j] ^ dp[i - 1][j + 1];       }     }     for (long long i = (1); i < (n + 1); i++) {       for (long long j = (1); j < (n - i + 1 + 1); j++) {         dp[i][j] = max({dp[i][j], dp[i - 1][j], dp[i - 1][j + 1]});       }     }     long long q;     cin >> q;     for (long long i = (0); i < (q); i++) {       long long l, r;       cin >> l >> r;       cout << dp[r - l + 1][l] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     deque<int> items;     int tmp;     for (int i = 0; i < k; i++) {       cin >> tmp;       items.push_back(tmp);     }     int ans = 0;     for (int i = 0; i < n * m; i++) {       cin >> tmp;       for (int j = 0; j < items.size(); j++) {         if (items[j] == tmp) {           ans += j + 1;           items.erase(items.begin() + j);           items.push_front(tmp);           break;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long x = 31;   unsigned long long X[60000];   int Ql[20], Qr[20];   char str[60000], s[60000];   int N;   map<unsigned long long, int> T[20];   map<unsigned long long, bool> A;   void add(int index, unsigned long long H) { T[index][H] = T[index][H] + 1; }   void CalcHashes(char s[], int index) {     unsigned long long H;     int i, j, L = strlen(s);     for (i = 1; i <= L; i++) {       H = 0;       for (j = 0; j < i; j++) H += X[i - j - 1] * (s[j] -  a  + 1);       add(index, H);       for (j = i; j < L; j++) {         H = (H - X[i - 1] * (s[j - i] -  a  + 1)) * x + (s[j] -  a  + 1);         add(index, H);       }     }   }   int answer;   void check(unsigned long long H) {     if (A[H]) return;     A[H] = true;     int i, t;     bool v = true;     for (i = 0; i < N && v; i++) {       t = T[i][H];       if (t < Ql[i] || Qr[i] < t) v = false;     }     if (v) answer++;   }   int main() {     unsigned long long H;     int i, j, L;     for (X[0] = 1, i = 1; i <= 60000; i++) X[i] = X[i - 1] * x;     scanf( %s , str);     scanf( %d , &N);     for (i = 0; i < N; i++) {       scanf( %s%d%d , &s, &Ql[i], &Qr[i]);       CalcHashes(s, i);     }     L = strlen(str);     for (i = 1; i <= L; i++) {       H = 0;       for (j = 0; j < i; j++) H += X[i - j - 1] * (str[j] -  a  + 1);       check(H);       for (j = i; j < L; j++) {         H = (H - X[i - 1] * (str[j - i] -  a  + 1)) * x + (str[j] -  a  + 1);         check(H);       }     }     printf( %d , answer);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     scanf( %d , &n);     for (i = 1; i <= (n / 2); i++) {       if (i & 1)         cout <<  ab ;       else         cout <<  ba ;     }     int k = n / 2;     if (n & 1) {       if ((k) % 2 == 0)         printf( a );       else         printf( b );     }   }


#include<bits/stdc++.h>   using namespace std;      int main(){    int t,n,x;    set<int> notes;    cin>>t;    while(t--){     cin>>n;     notes.clear();     for(int i=0;i<n;i++){      cin>>x;      if(notes.find(x)==notes.end()){       notes.insert(x);      }else{       notes.insert(x+1);      }     }     cout<<notes.size()<<endl;    }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 7;   struct node {     long long l, r, i;   };   bool cmp(node &a, node &b) { return a.l < b.l; }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long x, y;       bool flag = 0;       vector<long long> ans(n);       vector<node> a;       for (long long i = 0; i < n; i++) {         cin >> x >> y;         a.push_back({x, y, i});       }       sort((a).begin(), (a).end(), cmp);       long long p = -1;       x = a[0].r;       for (long long i = 1; i < n; i++) {         if (x < a[i].l) {           p = i;           break;         }         x = max(x, a[i].r);       }       if (p == -1)         cout << -1 <<   n ;       else {         for (long long i = 0; i < p; i++) ans[a[i].i] = 1;         for (long long i = p; i < n; i++) ans[a[i].i] = 2;         for (auto i : ans) cout << i <<    ;         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const double eps = 1e-9;   const int inf = 1e9;   int deg[N];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, x;       scanf( %d%d , &n, &x);       for (int i = 0; i < n + 10; i++) deg[i] = 0;       for (int i = 1; i < n; i++) {         int u, v;         scanf( %d%d , &u, &v);         deg[u]++;         deg[v]++;       }       if (deg[x] < 2)         printf( Ayush n );       else {         if (n & 1)           printf( Ashish n );         else           printf( Ayush n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout <<  YES n ;     for (int i = 1; i <= n; i++) {       int x1, x2, y1, y2;       cin >> x1 >> y1 >> x2 >> y2;       cout << (2 * ((x1 % 2 + 2) % 2) + (y1 % 2 + 2) % 2) + 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int get() {     char ch;     while (ch = getchar(), (ch <  0  || ch >  9 ) && ch !=  - )       ;     if (ch ==  - ) {       int s = 0;       while (ch = getchar(), ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 ;       return -s;     }     int s = ch -  0 ;     while (ch = getchar(), ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 ;     return s;   }   const int N = 1e3 + 5;   int n;   struct point {     int x, y, col, id;     void read() {       x = get();       y = get();       col = get();     }   } a[N];   int cross(point a, point b, point c) {     return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);   }   int operator*(point a, point b) { return a.x * b.y - a.y * b.x; }   point operator-(point a, point b) {     a.x -= b.x, a.y -= b.y;     return a;   }   point operator+(point a, point b) {     a.x += b.x, a.y += b.y;     return a;   }   int be[N];   point sta[N];   int top;   bool cmp(point a, point b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }   struct edge {     int x, y;     edge(const int x_ = 0, const int y_ = 0) {       x = x_;       y = y_;     }   } ed[N];   int tot;   point que[N];   int k;   bool inside(point a, point b, point c, point q) {     return ((cross(a, b, q) >= 0) != (cross(a, c, q) >= 0)) &&            ((cross(b, a, q) >= 0) != cross(b, c, q) >= 0) &&            ((cross(c, a, q) >= 0) != (cross(c, b, q) >= 0));   }   void solve(point A, point B, point C) {     for (int i = 1; i <= n; i++)       if (a[i].col == C.col && inside(A, B, C, a[i])) {         ed[++tot] = edge(C.id, a[i].id);         solve(A, B, a[i]);         solve(a[i], C, A);         solve(a[i], C, B);         return;       }     for (int i = 1; i <= n; i++)       if (inside(A, B, C, a[i])) ed[++tot] = edge(A.id, a[i].id);   }   int main() {     n = get();     int all = 0;     for (int i = 1; i <= n; i++) {       a[i].read();       a[i].id = i;       all |= 1 << a[i].col;     }     if (all != 3) {       printf( %d n , n - 1);       for (int i = 1; i <= n - 1; i++) printf( %d %d n , 0, i);       return 0;     }     sort(a + 1, a + 1 + n, cmp);     top = 0;     for (int i = 1; i <= n; i++) {       if (top && sta[top].x == a[i].x) continue;       while (top > 1 && cross(sta[top - 1], a[i], sta[top]) >= 0) top--;       sta[++top] = a[i];     }     for (int i = 1; i <= top; i++) be[sta[i].id] = 1;     top = 0;     for (int i = n; i >= 1; i--) {       if (top && sta[top].x == a[i].x) continue;       while (top > 1 && cross(sta[top - 1], a[i], sta[top]) >= 0) top--;       sta[++top] = a[i];     }     for (int i = 1; i <= top; i++)       if (!be[sta[i].id]) be[sta[i].id] = 2;     k = 0;     for (int i = 1; i <= n; i++)       if (be[a[i].id] == 1) que[++k] = a[i];     for (int i = n; i >= 1; i--)       if (be[a[i].id] == 2) que[++k] = a[i];     int cnt = 0, keyw = 0;     for (int i = 1; i <= k; i++)       if (que[i].col != que[(i + k - 2) % k + 1].col) {         cnt++;         keyw = i;       }     if (cnt > 2) return printf( Impossible n ), 0;     if (cnt == 0) {       for (int i = 1; i <= k - 1; i++) ed[++tot] = edge(que[i].id, que[i + 1].id);       point other;       for (int i = 1; i <= n; i++)         if (a[i].col != que[1].col) {           other = a[i];           break;         }       for (int i = 1; i <= k - 1; i++) solve(que[i], que[i + 1], other);       solve(que[k], que[1], other);     } else {       int x = keyw;       for (; que[x].col == que[keyw].col; x = x % k + 1) {         if (que[x].col == que[x % k + 1].col) {           solve(que[x], que[x % k + 1], que[(keyw + k - 2) % k + 1]);           ed[++tot] = edge(que[x].id, que[x % k + 1].id);         }       }       int lst = (x + k - 2) % k + 1;       for (; x != keyw; x = x % k + 1) {         if (que[x].col == que[x % k + 1].col) {           solve(que[x], que[x % k + 1], que[lst]);           ed[++tot] = edge(que[x].id, que[x % k + 1].id);         }       }     }     printf( %d n , tot);     for (int i = 1; i <= tot; i++) printf( %d %d n , ed[i].x - 1, ed[i].y - 1);     return 0;   }


#include <bits/stdc++.h>   int sm(int a, int b) {     if (a % b == 0)       return b;     else       return a % b;   }   int main() {     int n, m, s;     scanf( %d%d%d , &n, &m, &s);     printf( %I64d , (long long)sm(n, s) * sm(m, s) * ((n - 1) / s + 1) *                         ((m - 1) / s + 1));   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e17 + 9;   long long n, m;   vector<int> num;   long long dp[100009][2];   void solve(int tp) {     multiset<int> s;     multiset<int>::iterator it;     if (tp == 0) {       for (long long i = 1; i < (m + 1); ++i) {         s.insert(num[i]);         it = s.upper_bound(num[i]);         if (it != s.end()) s.erase(it);         dp[i][tp] = (long long)(s).size();       }     } else {       for (long long i = m + 1 - 1; i >= 1; i--) {         s.insert(num[i]);         it = s.upper_bound(num[i]);         if (it != s.end()) s.erase(it);         dp[i][tp] = (long long)(s).size();       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     long long acum[100009];     memset(acum, 0, sizeof acum);     for (long long i = 0; i < (n); ++i) {       long long a, b;       cin >> a >> b;       acum[a]++;       acum[b + 1]--;     }     for (long long i = 1; i < (m + 2); ++i) {       acum[i] += acum[i - 1];     }     for (long long i = 0; i < (m + 1); ++i) {       num.push_back(acum[i]);     }     solve(0);     solve(1);     long long ans = 0;     for (long long i = 1; i < (m + 1); ++i) {       ans = max({dp[i][0] + dp[i][1] - 1, ans});     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i;     cin >> n;     pair<int, int> a[n];     for (i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i + 1;     }     sort(a, a + n);     int ans = a[0].first / max(a[0].second - 1, n - a[0].second);     for (i = 1; i < n - 1; i++)       ans = min(ans, a[i].first / max(a[i].second - 1, n - a[i].second));     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class substr {    public:     string str;     int id;     bool operator<(const substr &a) const { return str > a.str; }   };   priority_queue<substr> Q;   int main() {     string s;     int k, n;     cin >> s >> k;     n = s.length();     for (int i = 0; i < n; i++) {       substr a;       a.str = s[i];       a.id = i;       Q.push(a);     }     while (!Q.empty()) {       substr p;       p = Q.top();       Q.pop();       k--;       if (!k) {         cout << p.str << endl;         return 0;       }       if (p.id != n - 1) {         p.str = p.str + s[p.id + 1];         p.id = p.id + 1;         Q.push(p);       }     }     cout <<  No such line.  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double dp[1 << 20][20], p[20][20];   bool mark[1 << 20][20];   int n;   double mem(int mask, int winner) {     if (!mask) return (winner == 1);     if (mark[mask][winner]) return dp[mask][winner];     mark[mask][winner] = true;     double &ret = dp[mask][winner];     for (int i = 1; i < n; i++)       if (mask & (1 << i)) {         double tmp = 0;         tmp += p[i][winner] * mem(mask ^ (1 << i), i);         tmp += p[winner][i] * mem(mask ^ (1 << i), winner);         ret = max(ret, tmp);       }     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       p[i][0] = 1;       for (int j = 1; j <= n; j++) cin >> p[i][j];     }     n++;     cout << setprecision(10) << fixed << mem((1 << n) - 2, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = int(1e9) + 7;   int main() {     ios::sync_with_stdio(false);     ios_base::sync_with_stdio(false);     long long n, m;     cin >> n >> m;     vector<long long> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     if (n >= 1001) {       cout << 0;       return 0;     }     long long res = 1;     for (int i = 0; i < n; ++i)       for (int j = i + 1; j < n; ++j) res = (res * (abs(a[i] - a[j]))) % m;     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int dp[100005];     vector<int> t;     vector<pair<int, int> > p;     int r, n;     cin >> r >> n;     t.push_back(0);     p.push_back(make_pair(1, 1));     for (int i = 0; i < n; i++) {       dp[i] = 0;       int x, y;       cin >> x;       t.push_back(x);       cin >> x >> y;       p.push_back(make_pair(x, y));     }     int maxi = 0, ans = 0;     dp[n] = 0;     for (int i = n; i >= 0; i--) {       for (int j = i - 1; j >= max(0, i - 2000); j--) {         int dif = abs(p[i].first - p[j].first) + abs(p[i].second - p[j].second);         if (dif <= abs(t[i] - t[j])) {           dp[j] = max(dp[j], dp[i] + 1);         }       }     }     cout << dp[0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10005;   void solve() {     string s;     cin >> s;     int n = s.size();     s =  a  + s;     set<int> one, zero;     vector<int> ans[n];     for (int i = 0; i < n; i++) zero.insert(i);     for (int i = 1; i <= n; i++) {       if (s[i] ==  0 ) {         if (zero.size() == 0) {           cout << -1;           return;         } else {           auto it = zero.begin();           int val = *it;           ans[val].push_back(i);           zero.erase(it);           one.insert(val);         }       } else {         if (one.size() == 0) {           cout << -1;           return;         } else {           auto it = one.begin();           int val = *it;           ans[val].push_back(i);           one.erase(it);           zero.insert(val);         }       }     }     int cnt = 0;     for (int i = 0; i < n; i++) {       if (ans[i].size() == 0) break;       if (s[ans[i][ans[i].size() - 1]] ==  1 ) {         cout <<  -1 ;         return;       }       cnt++;     }     cout << cnt <<   n ;     for (int i = 0; i < cnt; i++) {       cout << ans[i].size() <<    ;       for (auto X : ans[i]) cout << X <<    ;       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     srand(time(NULL));     ;     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int a[3010], id[3010], num[3010];   vector<int> ans;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     int m;     scanf( %d , &m);     int need = n - m;     while (true) {       int tot = 0;       memset(id, -1, sizeof(id));       memset(num, 0, sizeof(num));       for (int i = 1; i <= n; i++) {         if (id[i] == -1) {           id[i] = tot;           int now = a[i];           while (now != i) {             id[now] = tot;             now = a[now];           }           tot++;         }       }       for (int i = 1; i <= n; i++) {         num[id[i]]++;       }       if (tot == need) break;       if (tot > need) {         for (int i = 2; i <= n; i++) {           if (id[i] != id[1]) {             ans.push_back(1);             ans.push_back(i);             swap(a[1], a[i]);             break;           }         }       } else {         for (int i = 1; i <= n; i++) {           if (num[id[i]] == 1) continue;           for (int j = i + 1; j <= n; j++) {             if (id[i] == id[j]) {               ans.push_back(i);               ans.push_back(j);               swap(a[i], a[j]);               break;             }           }           break;         }       }     }     printf( %d n , ans.size() / 2);     for (int i = 0; i < ans.size(); i++) {       if (i) printf(   );       printf( %d , ans[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug;   const int inf = 1e9 + 5;   const int nax = 205;   int k;   namespace MinCost {   struct Edge {     int w, c, v, rev;     Edge(int _w, int _c, int _v, int _rev) : w(_w), c(_c), v(_v), rev(_rev) {}   };   int odl[nax], pot[nax], pop[nax], pop_kraw[nax];   vector<Edge> v[nax];   bool bylo[nax];   void init(int n) {     for (int i = 0; i <= n; ++i) v[i].clear();   }   void AddEdge(int a, int b, int cap, int cost) {     v[a].push_back(Edge(b, cap, cost, int(v[b].size()) + (a == b)));     v[b].push_back(Edge(a, 0, -cost, int(v[a].size() - 1)));   }   pair<int, int> MinCostMaxFlow(int s, int t, int n) {     int flow = 0, cost = 0;     for (int i = 0; i <= n; ++i) pot[i] = 0;     while (true) {       for (int i = 0; i <= n; ++i) {         odl[i] = inf;         bylo[i] = false;       }       odl[s] = 0;       for (int k = 0; k <= (n)-1; ++k) {         int x = 0;         int najm = inf;         for (int i = 0; i <= n; ++i)           if (!bylo[i] && najm > odl[i]) {             x = i;             najm = odl[i];           }         bylo[x] = true;         int dl = v[x].size();         for (int i = 0; i <= (dl)-1; ++i)           if (v[x][i].c > 0 &&               odl[v[x][i].w] > odl[x] + pot[x] - pot[v[x][i].w] + v[x][i].v) {             odl[v[x][i].w] = odl[x] + pot[x] - pot[v[x][i].w] + v[x][i].v;             pop[v[x][i].w] = x;             pop_kraw[v[x][i].w] = i;           }       }       if (odl[t] == inf) break;       for (int i = 0; i <= n; ++i) pot[i] += odl[i];       int x = t;       int cap = inf;       while (x != s) {         cap = min(cap, v[pop[x]][pop_kraw[x]].c);         x = pop[x];       }       x = t;       int one_path_cost = 0;       while (x != s) {         one_path_cost += v[pop[x]][pop_kraw[x]].v;         v[pop[x]][pop_kraw[x]].c -= cap;         v[x][v[pop[x]][pop_kraw[x]].rev].c += cap;         x = pop[x];       }       int ile_zmiesci = one_path_cost ? (k - cost) / one_path_cost : inf;       cost += min(cap, ile_zmiesci) * one_path_cost;       flow += min(cap, ile_zmiesci);       if (ile_zmiesci < cap) break;     }     return make_pair(flow, cost);   }   };  // namespace MinCost   using namespace MinCost;   int n, a;   int main(int argc, char* argv[]) {     scanf( %d%d , &n, &k);     init(n - 1);     for (int i = 0; i <= (n)-1; ++i)       for (int j = 0; j <= (n)-1; ++j) {         scanf( %d , &a);         if (a > 0) {           AddEdge(i, j, a, 0);           AddEdge(i, j, k, 1);         }       }     printf( %d n , MinCostMaxFlow(0, n - 1, n - 1).first);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int num[10];   int main(void) {     int T, n;     scanf( %d , &T);     while (T--) {       memset(num, 0, sizeof(num));       scanf( %d , &n);       num[1] = n / 2;       if (n & 01) {         printf( 7 );         for (int i = 1; i < num[1]; ++i) printf( 1 );       } else         for (int i = 0; i < num[1]; ++i) printf( 1 );       if (T) printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   int tree[2000005] = {0}, num[500005] = {0}, dp[500005] = {1};   void modify(int index, int l, int r, int ql, int qr, int v) {     if (ql <= l && qr >= r) {       tree[index] = v;       return;     }     int mid = (l + r) >> 1;     if (ql <= mid && qr >= l) modify(index << 1, l, mid, ql, qr, v);     if (ql <= r && qr >= mid + 1) modify(index << 1 | 1, mid + 1, r, ql, qr, v);     tree[index] = max(tree[index << 1], tree[index << 1 | 1]);   }   int query(int index, int l, int r, int ql, int qr) {     if (ql <= l && qr >= r) return tree[index];     int mid = (l + r) >> 1, ans = 0;     if (ql <= mid && qr >= l) ans = max(ans, query(index << 1, l, mid, ql, qr));     if (ql <= r && qr >= mid + 1)       ans = max(ans, query(index << 1 | 1, mid + 1, r, ql, qr));     return ans;   }   int main() {     int i, n, k, d, index = 0;     scanf( %d%d%d , &n, &k, &d);     for (i = 1; i <= n; i++) scanf( %d , &num[i]);     sort(num + 1, num + n + 1);     modify(1, 0, n, 0, 0, 1);     for (i = 1; i <= n; i++) {       while (num[i] > num[index] + d) index++;       if (i - k >= index - 1)         dp[i] = query(1, 0, n, index - 1, i - k);       else         dp[i] = 0;       modify(1, 0, n, i, i, dp[i]);     }     if (dp[n])       puts( YES );     else       puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     long long res = 0;     cin >> n >> m >> k;     map<int, long long> dp;     bool arr[n + 1], s[m + 1];     for (int i = 0; i < n; i++) cin >> arr[i];     arr[n] = 0;     for (int i = 0; i < m; i++) cin >> s[i];     s[m] = 0;     int ones = 0;     for (int i = 0; i < n + 1; i++) {       if (arr[i])         ones++;       else if (ones) {         if (dp.find(ones) != dp.end()) {           res += dp[ones];           ones = 0;           continue;         }         int tones = 0;         long long dpres = 0;         long long prev = 0;         for (int j = 0; j < m + 1; j++) {           if (s[j]) {             tones++;             dpres += prev;             if (k % tones == 0 && tones * ones >= k) {               dpres += ones - (k / tones) + 1;               prev += ones - (k / tones) + 1;             }           } else {             tones = 0;             prev = 0;           }         }         dp[ones] = dpres;         res += dpres;         ones = 0;       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int n;   signed main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> s;     vector<pair<int, int>> a;     vector<int> p(n, 0), nxt(n, 0);     stack<pair<int, int>> S;     S.push({0, -1});     for (int i = 0; i < n; ++i) {       if (s[i] ==  ( ) {         p[i] = S.top().second;         a.push_back({S.top().first + 1, i});         S.push({a.back().first, i});       } else {         nxt[S.top().second] = i;         S.pop();       }     }     sort(a.rbegin(), a.rend());     string k(n,  x );     for (int i = 0; i < int(a.size()); ++i) {       int y = a[i].second;       if (k[y] !=  x ) {         k[nxt[y]] = k[y];         continue;       }       int c = -1, cnt = 0;       for (y = a[i].second; y != -1 && k[y] ==  x ; y = p[y]) cnt ^= 1;       if (y != -1) c = k[y] -  0 ;       int t = 1;       if (c != -1) t = c ^ cnt;       for (y = a[i].second; y != -1 && k[y] ==  x ; t ^= 1, y = p[y])         k[y] = t +  0 ;       k[nxt[a[i].second]] = k[a[i].second];     }     cout << k <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> S;   void dfs(int Cur, int dgt, int x, int y) {     if (dgt == 11) return;     if (Cur > 0) S.insert(Cur);     dfs(Cur * 10 + x, dgt + 1, x, y);     dfs(Cur * 10 + y, dgt + 1, x, y);     return;   }   int main() {     int n, Ans = 0;     cin >> n;     S.insert(1e9);     for (int i = 0; i < 10; i++) {       for (int j = 0; j < 10; j++) {         dfs(0, 1, i, j);       }     }     for (auto x : S) {       if (x > n)         break;       else         Ans++;     }     cout << Ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool deb_mode = 0;   class debugger {     vector<string> vars;       public:     template <typename T>     debugger &operator,(const T v) {       stringstream ss;       ss << v, vars.push_back(ss.str());       return *this;     }     void printall() {       int j = 0, l = vars.size();       for (int i = 0; i < (l - 1); i++) {         if (i) cout <<  ,  ;         for (; j < vars[l - 1].size(); j++) {           if (vars[l - 1][j] ==  , ) {             j++;             break;           }           cout << vars[l - 1][j];         }         cout <<   =   << vars[i];       }       vars.clear();     }   } Dbug;   template <typename T1, typename T2>   inline ostream &operator<<(ostream &os, const pair<T1, T2> &p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <typename T>   inline ostream &operator<<(ostream &os, const vector<T> &v) {     bool first = true;     os <<  { ;     for (unsigned int i = 0; i < v.size(); i++) {       if (!first) os <<  , ;       os << v[i];       first = false;     }     return os <<  } ;   }   template <typename T>   inline ostream &operator<<(ostream &os, const set<T> &v) {     bool first = true;     os <<  { ;     for (typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {       if (!first) os <<  , ;       os << *ii;       first = false;     }     return os <<  } ;   }   template <typename T1, typename T2>   inline ostream &operator<<(ostream &os, const map<T1, T2> &v) {     bool first = true;     os <<  { ;     for (typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end();          ++ii) {       if (!first) os <<  , ;       os << *ii;       first = false;     }     return os <<  } ;   }   template <typename T>   void getarray(T a[], int b, int e) {     for (int i = b; i < e + b; i++) cin >> a[i];   }   template <typename T>   void printarray(T a[], int b, int e) {     for (int i = b; i < e - 1 + b; i++) cout << a[i] <<    ;     if (e - 1 + b >= 0) cout << a[e - 1 + b] <<   n ;   }   template <typename T>   void printV(vector<T> v) {     int sz = v.size();     if (sz) cout << v[0];     for (int i = 1; i < sz; i++) cout <<     << v[i];     printf(  n );   }   template <typename T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <typename T>   T BigMod(T b, T p, T m) {     if (p == 0) return 1;     if (p % 2 == 0) {       T s = BigMod(b, p / 2, m);       return ((s % m) * (s % m)) % m;     }     return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;   }   template <typename T>   T ModInv(T b, T m) {     return BigMod(b, m - 2, m);   }   pair<long long int, pair<long long int, long long int> > ext_gcd(       long long int a, long long int b) {     if (b == 0) return make_pair(a, make_pair(1LL, 0LL));     pair<long long int, pair<long long int, long long int> > t =         ext_gcd(b, a % b);     return make_pair(         t.first,         make_pair(t.second.second, t.second.first - a / b * t.second.second));   }   long long int ModInvNonPrimeM(long long int N, long long int M) {     pair<long long int, pair<long long int, long long int> > r = ext_gcd(N, M);     r.second.first %= M;     if (r.second.first < 0) r.second.first += M;     return r.second.first;   }   template <class T>   inline void read(T &x) {     bool Minus = 0;     char c;     for (c = getchar(); c <= 32; c = getchar())       ;     if (c ==  - ) Minus = 1, c = getchar();     for (x = 0; c > 32; c = getchar()) x = x * 10 + c -  0 ;     if (Minus) x = -x;   }   char getc() {     char c;     for (c = getchar(); c <= 32; c = getchar())       ;     return c;   }   int CI(int &_x) { return scanf( %d , &_x); }   int CI(int &_x, int &_y) { return scanf( %d %d , &_x, &_y); }   int CI(int &_x, int &_y, int &_z) { return scanf( %d %d %d , &_x, &_y, &_z); }   int CI(int &_a, int &_b, int &_c, int &_d) {     return scanf( %d %d %d %d , &_a, &_b, &_c, &_d);   }   template <class T1, class T2>   inline T1 UMAX(T1 &m, T2 other) {     if (m < other) m = other;     return m;   }   template <class T1, class T2>   inline T1 UMIN(T1 &m, T2 other) {     if (m > other) m = other;     return m;   }   template <class T>   string toString(T n) {     ostringstream oss;     oss << n;     return oss.str();   }   int toInt(string s) {     int r = 0;     istringstream sin(s);     sin >> r;     return r;   }   long long int toLong(string s) {     long long int r = 0;     istringstream sin(s);     sin >> r;     return r;   }   bool isVowel(char ch) {     ch = tolower(ch);     if (ch ==  a  || ch ==  e  || ch ==  i  || ch ==  o  || ch ==  u )       return true;     return false;   }   bool isUpper(char c) { return c >=  A  && c <=  Z ; }   bool isLower(char c) { return c >=  a  && c <=  z ; }   int dr8[8] = {+1, -1, +0, +0, +1, -1, -1, +1};   int dc8[8] = {+0, +0, -1, +1, +1, +1, -1, -1};   int dr4[4] = {+0, +0, +1, -1};   int dc4[4] = {-1, +1, +0, +0};   int kn8r[8] = {+1, +2, +2, +1, -1, -2, -2, -1};   int kn8c[8] = {+2, +1, -1, -2, -2, -1, +1, +2};   const double EPS = 1e-9;   const int INF = (1 << 30) - 1;   const long long int LINF = (1ll << 62) - 1;   const int mod = (int)1e9 + 7;   const int MAX = (int)1e5;   int N, M, X;   int main() {     if (deb_mode) srand(int(time(NULL)));     int i, j, k, l, n, m, q, a, b, c;     cin >> N >> M >> X;     X--;     if (N > M) {       cout <<  0 n ;       return 0;     }     int DP[2][N + 5][N + 5];     memset(DP, 0, sizeof(DP));     DP[M & 1][N][0] = 1;     int posNow, posPrev;     for (int pos = M; pos >= 0; pos--) {       posNow = pos & 1;       posPrev = (pos - 1) & 1;       for (i = 0; i < N + 1; i++)         for (j = 0; j < N + 1; j++) DP[posPrev][i][j] = 0;       for (int seg = 0; seg <= N; seg++) {         for (int open = 0; open <= N; open++) {           if (open)             DP[posPrev][seg][open - 1] =                 (DP[posPrev][seg][open - 1] + DP[posNow][seg][open]) % mod;           if (pos - 1 != X && seg)             DP[posPrev][seg - 1][open + 1] =                 (DP[posPrev][seg - 1][open + 1] + DP[posNow][seg][open]) % mod;           if (seg)             DP[posPrev][seg - 1][open] =                 (DP[posPrev][seg - 1][open] + DP[posNow][seg][open]) % mod;           if (pos - 1 != X)             DP[posPrev][seg][open] =                 (DP[posPrev][seg][open] + DP[posNow][seg][open]) % mod;         }       }     }     long long int ANS = DP[posNow][0][0];     for (i = 1; i <= N; i++) ANS = (ANS * i) % mod;     cout << ANS <<   n ;     if (deb_mode)       cerr <<  EXECUTION TIME =   << (1.0 * clock()) / CLOCKS_PER_SEC            <<   SECONDS n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, l, r, x, y, o, e, w, z, b[50000], aa, bb, ans;   vector<int> vec;   map<int, int> ma;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> l >> r >> x >> y;     if (y % x != 0) {       cout << 0 << endl;       return 0;     } else       y /= x;     for (int i = 2; i * i <= y; i++)       if (y % i == 0) {         vec.push_back(i);         while (y % i == 0) {           y /= i;           ma[i]++;         }       }     if (y > 1) {       vec.push_back(y);       ma[y]++;     }     z = vec.size();     for (int i = 0; i < (1 << z); i++) {       w = i;       for (int j = 0; j < z; j++) b[j] = 0;       o = 0;       while (w) {         b[o] = w & 1;         w >>= 1;         o++;       }       aa = bb = 1;       for (int j = 0; j < z; j++)         if (b[j] == 1) {           e = ma[vec[j]];           for (int h = 1; h <= e; h++) aa *= vec[j];         } else {           e = ma[vec[j]];           for (int h = 1; h <= e; h++) bb *= vec[j];         }       if (l <= aa * x && aa * x <= r && l <= bb * x && bb * x <= r) ans++;     }     cout << ans << endl;     return 0;   }


#include<bits/stdc++.h>    using namespace std;    #define ll long long   int main() {    ll k,l,r,t,x,y;    cin>>k>>l>>r>>t>>x>>y;    if(k<l || k>r) {        cout<< No <<endl; return 0;    }    if(x>y) {        if(k+y>r) k-=x; t--;        if(k<l) return cout<< No <<endl,0;        if((k-l)/(x-y) < t ) {            cout<< No <<endl; return 0;        }        cout<< Yes <<endl; return 0;    }    else {        vector<bool> was(x,false);        while(t>0) {            if(was[k%x]) return cout<< Yes <<endl,0;            was[k%x]=true;            ll remd=min(t,(k-l)/x);            k-=remd*x;            t-=remd;            if(t==0) return cout<< Yes <<endl,0;            t--;            if(k+y<=r) k+=y;            k=k-x;            if(k<l || k>r) return cout<< No <<endl,0;        }        cout<< Yes <<endl;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)3e5 + 99;   const long long INF = (long long)1e18 + 100;   int a[N];   int b[N];   long long dp[N][3];   int n;   long long calc(long long add, long long pos) {     long long &res = dp[pos][add];     if (res != -1) return res;     res = INF;     if (pos == n) return res = 0;     for (long long x = 0; x <= 2; x++) {       if (pos == 0 || a[pos] + x != a[pos - 1] + add)         res = min(res, calc(x, pos + 1) + x * (b[pos]));     }     return res;   }   void Solve() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i] >> b[i];     for (int i = 0; i <= n; i++) dp[i][0] = dp[i][1] = dp[i][2] = -1;     cout << calc(0, 0) <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       Solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int cnt = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  + ) {         cnt++;       } else if (s[i] ==  -  && cnt) {         cnt--;       }     }     cout << cnt << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   vector<int> v[3001];   int size1[3001];   map<vector<int>, int> mm;   long dis[3001][3001];   void dijkstra(int n) {     priority_queue<vector<int>> pq;     vector<int> p(3, 0), p1(3);     p[0] = 0;     p[2] = 1;     pq.push(p);     long size = 1;     while (size) {       p = pq.top();       pq.pop();       --size;       if ((dis[p[2]][p[1]] > p[0]) && (dis[p[2]][p[1]] != 0)) {         continue;       }       if (p[2] == n) return;       for (int i = 0; i < size1[p[2]]; ++i) {         p1[0] = p[1];         p1[1] = p[2];         p1[2] = v[p[2]][i];         if (mm[p1] == 1) continue;         if ((dis[p1[2]][p1[1]] < dis[p[2]][p[1]] - 1) ||             (dis[p1[2]][p1[1]] == 0)) {           dis[p1[2]][p1[1]] = dis[p[2]][p[1]] - 1;           p1[0] = dis[p1[2]][p1[1]];           pq.push(p1);           ++size;           if ((p1[2] == n) && (p1[0] == -1)) return;         }       }     }   }   int main() {     int n, m, a, b, c, k;     cin >> n >> m >> k;     vector<int> arr(3);     for (int i = 0; i < m; ++i) {       scanf( %d %d , &a, &b);       v[a].emplace_back(b);       size1[a]++;       v[b].emplace_back(a);       size1[b]++;     }     for (int i = 0; i < k; ++i) {       scanf( %d %d %d , &arr[0], &arr[1], &arr[2]);       mm[arr] = 1;     }     dijkstra(n);     long maxim = 0;     int maximindex = 0;     for (int i = 1; i <= n; ++i) {       if (dis[n][i] == 0) {         continue;       }       if ((dis[n][i] > maxim) || (maxim == 0)) {         maxim = dis[n][i];         maximindex = i;       }     }     if (maxim == 0) {       cout <<  -1  << endl;       return 0;     }     int i = n;     int j = maximindex;     stack<int> s;     s.push(i);     long ans = 1;     int size2 = 1;     i = maximindex;     maxim++;     while (maxim < 0) {       for (int j = 1; j <= n; ++j) {         if (dis[i][j] == 0) continue;         if (dis[i][j] == maxim) {           maximindex = j;           break;         }       }       ++ans;       s.push(i);       ++size2;       maxim++;       i = maximindex;     }     cout << ans << endl;     cout <<  1           <<    ;     while (size2) {       printf( %d  , s.top());       s.pop();       --size2;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, a[2000 + 10][2000 + 10], ans[2000 + 10][2000 + 10], viz[30];   pair<int, int> fs[30], ls[30];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       int n, m, l = 0;       pair<int, int> aux = {0, 0};       cin >> n >> m;       for (int i = 1; i <= 26; i++) viz[i] = 0, fs[i] = {0, 0}, ls[i] = {0, 0};       for (int i = 1; i <= n; i++) {         string s;         cin >> s;         for (int j = 0; j < m; j++) {           if (s[j] >=  a  && s[j] <=  z )             a[i][j + 1] = s[j] -  a  + 1;           else             a[i][j + 1] = 0;         }       }       for (int ch = 1; ch <= 26; ch++)         for (int i = 1; i <= n && !viz[ch]; i++)           for (int j = 1; j <= m && !viz[ch]; j++)             if (a[i][j] == ch) {               viz[ch] = 1;               fs[ch] = {i, j};               int j1 = j + 1, i1 = i + 1, ok = 0;               while (j1 <= m) {                 if (a[i][j1] == ch) ok = 1, ls[ch] = {i, j1};                 j1++;               }               while (i1 <= n) {                 if (a[i1][j] == ch) ok = 1, ls[ch] = {i1, j};                 i1++;               }               if (!ok) ls[ch] = fs[ch];               l = ch;               aux = fs[ch];             }       for (int i = 1; i <= l; i++) {         if (!fs[i].first) {           fs[i] = aux;           ls[i] = aux;         }         for (int i1 = fs[i].first; i1 <= ls[i].first; i1++)           for (int j1 = fs[i].second; j1 <= ls[i].second; j1++) ans[i1][j1] = i;       }       int ok = 1;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++)           if (ans[i][j] != a[i][j]) ok = 0;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) a[i][j] = ans[i][j] = 0;       if (!ok) {         cout <<  NO  <<   n ;         continue;       }       cout <<  YES  <<   n ;       cout << l <<   n ;       for (int i = 1; i <= l; i++)         cout << fs[i].first <<     << fs[i].second <<     << ls[i].first <<                  << ls[i].second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 9e2 + 1;   int n, m, g[maxn], G, o1[maxn], o2[maxn], deg[maxn];   vector<int> e[maxn], e_s[maxn], r_e_s[maxn], topo, ans, wow[maxn];   vector<pair<int, int> > edge, res;   bool mark[maxn];   map<int, int> is[maxn];   void dfs(int v) {     mark[v] = 1;     for (auto u : e[v]) {       if (is[v][u] == 0) {         e_s[v].push_back(u);         r_e_s[u].push_back(v);         is[v][u] = 1;         is[u][v] = 1;       }       if (mark[u] == 0) {         dfs(u);       }     }   }   void topol(int v) {     mark[v] = 1;     for (auto u : e_s[v]) {       if (mark[u] == 0) {         topol(u);       }     }     topo.push_back(v);   }   void col(int v) {     mark[v] = 1;     g[v] = G;     o2[G] = v;     for (auto u : r_e_s[v]) {       if (mark[u] == 0) {         col(u);       }     }     return;   }   void Last_one(int v) {     mark[v] = 1;     for (auto u : wow[v]) {       if (mark[u] == 0) {         Last_one(u);       }     }     if (deg[v] == 1) {       ans.push_back(v);     }     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     if (n == 2) {       cout << -1 << endl;       return 0;     }     for (int i = 0; i < m; i++) {       int t1, t2;       cin >> t1 >> t2;       e[t1].push_back(t2);       e[t2].push_back(t1);       edge.push_back({t1, t2});     }     dfs(1);     for (int i = 1; i <= n; i++) {       mark[i] = 0;     }     topol(1);     for (int i = 1; i <= n; i++) {       mark[i] = 0;     }     reverse(topo.begin(), topo.end());     G = 1;     for (auto u : topo) {       if (mark[u] == 0) {         o1[G] = u;         col(u);         G++;       }     }     for (auto tmp : edge) {       if (g[tmp.first] != g[tmp.second]) {         deg[g[tmp.first]]++;         deg[g[tmp.second]]++;         wow[g[tmp.first]].push_back(g[tmp.second]);         wow[g[tmp.second]].push_back(g[tmp.first]);       }     }     if (G == 3) {       ans.push_back(1);       ans.push_back(2);     } else {       for (int i = 1; i <= n; i++) {         mark[i] = 0;       }       for (int i = 1; i < G; i++) {         if (deg[i] >= 2) {           Last_one(i);           break;         }       }     }     for (int i = 0; i < ((int)ans.size() + 1) / 2; i++) {       int t1 = ans[i];       int t2 = ans[i + (ans.size()) / 2];       if (is[o1[t1]][o1[t2]] == 0) {         res.push_back({o1[t1], o1[t2]});       } else {         res.push_back({o2[t1], o2[t2]});       }     }     cout << res.size() << endl;     for (auto u : res) {       cout << u.first <<      << u.second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long N, K;   long long num[3000];   long long OAO[3000];   bool test(long long c) {     for (long long Ni = 0; Ni <= N; Ni++) {       OAO[Ni] = Ni;       for (long long Nj = 0; Nj < Ni; Nj++) {         if (Ni != N && abs(num[Ni] - num[Nj]) > (long long)(c) * (Ni - Nj))           continue;         OAO[Ni] = min(OAO[Ni], OAO[Nj] + Ni - Nj - 1);       }     }     if (OAO[N] > K)       return false;     else       return true;   }   int main() {     scanf( %I64d %I64d , &N, &K);     long long p = 0;     for (long long Ni = 0; Ni < N; Ni++) {       scanf( %I64d , &num[Ni]);       if (Ni) p = max(p, (long long)abs(num[Ni] - num[Ni - 1]));     }     long long l = -1, r = p, mid;     while (l + 1 != r) {       mid = (l + r) / 2;       if (test(mid))         r = mid;       else         l = mid;     }     printf( %I64d n , r);   }


#include <bits/stdc++.h>   using namespace std;   int regions[100000][4];   string name[100000][3];   void compareScore(int regionNo, int score, string str) {     if (score >= regions[regionNo][0]) {       string tempName1 = name[regionNo][0];       string tempName2 = name[regionNo][1];       int tempScore1 = regions[regionNo][0];       int tempScore2 = regions[regionNo][1];       regions[regionNo][0] = score;       name[regionNo][0] = str;       regions[regionNo][1] = tempScore1;       regions[regionNo][2] = tempScore2;       name[regionNo][1] = tempName1;       name[regionNo][2] = tempName2;     } else if (score >= regions[regionNo][1]) {       string tempName2 = name[regionNo][1];       int tempScore2 = regions[regionNo][1];       regions[regionNo][1] = score;       name[regionNo][1] = str;       regions[regionNo][2] = tempScore2;       name[regionNo][2] = tempName2;     } else if (score >= regions[regionNo][2]) {       regions[regionNo][2] = score;       name[regionNo][2] = str;     }     if (!name[regionNo][1].empty() && !name[regionNo][2].empty() &&         regions[regionNo][1] == regions[regionNo][2]) {       regions[regionNo][3] = -1;     } else {       regions[regionNo][3] = 1;     }   }   void solve(int n, int m) {     for (int i = 0; i < n; i++) {       string str;       int regionNo, score;       cin >> str >> regionNo >> score;       compareScore(regionNo, score, str);     }     for (int i = 1; i <= m; i++) {       if (regions[i][3] == 1) {         cout << name[i][0] <<     << name[i][1] << endl;       } else {         cout <<  ?  << endl;       }     }   }   int main() {     int n, m;     cin >> n >> m;     solve(n, m);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, sum = 0;       cin >> n;       vector<long long> v(n), ans, odd;       for (long long i = 0; i < n; i++) {         cin >> v[i];         if (v[i] % 2 == 0) {           ans.push_back(i);         } else           odd.push_back(i);         sum += v[i];       }       long long count = 0;       for (long long i = 2; i * i <= sum; i++) {         if (sum % i == 0) count++;       }       if (count > 0) {         cout << n << endl;         for (long long i = 0; i < n; i++) cout << i + 1 <<    ;       } else {         cout << n - 1 << endl;         odd.pop_back();         for (long long i = 0; i < ans.size(); i++) {           cout << ans[i] + 1 <<    ;         }         for (long long i = 0; i < odd.size(); i++) {           cout << odd[i] + 1 <<    ;         }       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INFINITE = (int)(0xffffffff >> 2);   int n;   int gs[600];   int dp[600][600];   int run(int l, int r) {     if (l > r) return 0;     if (l == r) return 1;     if (dp[l][r] != INFINITE) {       return dp[l][r];     }     dp[l][r] = min(dp[l][r], run(l + 1, r) + 1);     for (int k = l + 2; k <= r; k++) {       if (gs[l] == gs[k]) {         dp[l][r] = min(dp[l][r], run(l + 1, k - 1) + run(k + 1, r));       }     }     if (gs[l] == gs[l + 1]) {       dp[l][r] = min(dp[l][r], run(l + 2, r) + 1);       return dp[l][r];     }     return dp[l][r];   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> gs[i];     for (int i = 0; i < 600; i++) {       int *row = dp[i];       for (int j = 0; j < 600; j++) {         row[j] = INFINITE;       }     }     cout << run(1, n) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   ,  ;     err(++it, args...);   }   namespace fastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   inline void read(int &x) {     char ch;     while (blank(ch = nc()))       ;     if (IOerror) return;     for (x = ch -  0 ; (ch = nc()) >=  0  && ch <=  9 ; x = x * 10 + ch -  0 )       ;   }   }  // namespace fastIO   using namespace fastIO;   const double PI = acos(-1.0);   const double eps = 1e-8;   const int maxn = 3e5 + 7;   const int N = 1e4 + 10;   const int mod = 998244353;   long long qp(long long b, long long n) {     long long r = 1;     if (n < 0) n += mod - 1;     b %= mod;     for (; n; n >>= 1, b = b * b % mod)       if (n & 1) r = r * b % mod;     return r;   }   int sgn(double x) {     if (x < -eps) return -1;     return x > eps ? 1 : 0;   }   int n;   long long dp[3][N];   long long sum[N], suf[N];   int a[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     sort(a + 1, a + 1 + n);     long long _c2 = (n * (n - 1) / 2);     for (int i = 1; i <= n; ++i) {       for (int j = i + 1; j <= n; ++j) {         dp[0][a[j] - a[i]]++;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = i + 1; j <= n; ++j) {         dp[1][a[j] - a[i]]++;       }     }     for (int i = 1; i <= 10000; ++i) {       for (int j = 1; j < i; ++j) {         int k = i - j;         dp[2][i] += dp[0][j] * dp[1][k];       }       sum[i] = sum[i - 1] + dp[2][i];     }     double ans = 0;     for (int i = 10000; i >= 1; --i) {       ans += sum[i - 1] * dp[0][i];     }     printf( %.12lf n , 1.0 * ans / _c2 / _c2 / _c2);   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 2139063143;   const int N = 1010000;   const int P = 1000000007;   const long double eps = 1e-7;   template <typename T>   inline void sc(T &x) {     x = 0;     static int p;     p = 1;     static char c;     c = getchar();     while (!isdigit(c)) {       if (c ==  - ) p = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c - 48);       c = getchar();     }     x *= p;   }   template <typename T>   inline void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) print(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   inline void pr(T x) {     print(x), putchar(  n );   }   template <typename T1, typename T2>   void chkmax(T1 &A, T2 B) {     A = A >= B ? A : B;   }   template <typename T1, typename T2>   void chkmin(T1 &A, T2 B) {     A = A <= B ? A : B;   }   const long double PI = acos(-1);   int n, m;   struct po {     long double x, y;     po(long double xx = 0, long double yy = 0) { x = xx, y = yy; }   } a[N], s[N];   po operator+(po A, po B) { return po(A.x + B.x, A.y + B.y); }   po operator-(po A, po B) { return po(A.x - B.x, A.y - B.y); }   long double operator*(po A, po B) { return A.x * B.y - A.y * B.x; }   po operator*(po A, long double B) { return po(A.x * B, A.y * B); }   po operator*(long double B, po A) { return po(A.x * B, A.y * B); }   long double triangle(po A, po B, po C) { return abs((B - A) * (C - A)) / 2; }   long double area() {     long double g = a[n] * a[1];     for (int i = 1; i < n; i++) g += a[i] * a[i + 1];     return abs(g) / 2;   }   po core(po A, po B, po C) { return (A + B + C) * (1. / 3); }   po O;   void core() {     long double S = area();     for (int i = 2; i < n; i++)       O = O + (triangle(a[1], a[i], a[i + 1]) / S) * core(a[1], a[i], a[i + 1]);   }   long double S(long double A) { return A * A; }   long double getlen(po A) { return sqrt(S(A.x) + S(A.y)); }   long double len[N], b[N];   long double atan2(po A) { return atan2(A.y, A.x); }   po rotate(po A, long double x) {     long double s = sin(x), c = cos(x);     return po(A.x * c - A.y * s, A.x * s + A.y * c);   }   int ia = 1, ib = 2;   po A, B, p;   po getpos(int i) { return O + rotate(s[i], b[0] - b[ia]); }   int main() {     sc(n), sc(m);     for (int i = 1; i <= n; i++) {       int x, y;       sc(x), sc(y);       a[i] = po(x, y);     }     core();     for (int i = 1; i <= n; i++)       s[i] = a[i] - O, len[i] = getlen(s[i]), b[i] = atan2(s[i]);     b[0] = atan2(po(0, 1));     A = a[1], B = a[2];     bool fg = 0;     while (m--) {       int op, x, y;       sc(op), sc(x);       if (op == 1) {         sc(y);         if (ia == x) swap(ia, ib), swap(A, B);         O = po(A.x, A.y - len[ia]);         ib = y, B = getpos(ib);         fg = 1;       } else {         if (fg)           p = getpos(x), printf( %.9Lf %.9Lf n , p.x, p.y);         else           printf( %.9Lf %.9Lf n , a[x].x, a[x].y);       }     }     return 0;   }


#include <bits/stdc++.h>   int n, k, a, b, p, na;   std::vector<int> avg;   long long f(int l, int r) {     auto it1 = std::upper_bound(avg.begin(), avg.end(), r);     auto it2 = std::lower_bound(avg.begin(), avg.end(), l);     if (it2 != avg.end())       na = it1 - it2;     else       na = 0;     long long ans;     if (na)       ans = 1LL * b * na * (r - l + 1);     else       ans = a;     if (na && r != l)       ans = std::min(ans, f(l, (l + r) / 2) + f((l + r) / 2 + 1, r));     return ans;   }   int main() {     scanf( %d%d%d%d , &n, &k, &a, &b);     for (int i = 0; i < k; i++) {       scanf( %d , &p);       avg.push_back(p - 1);     }     std::sort(avg.begin(), avg.end());     printf( %lld n , f(0, (1 << n) - 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   const long long INFll = 1ll * 1000000000 * 1000000000;   const long double PI =       3.141592653589793238462643383279502884197169399375105820974944;   int mul(int a, int b, int mod = 1000000007) { return int(a * 1ll * b % mod); }   int norm(int a, int mod = 1000000007) {     while (a >= mod) a -= mod;     while (a < 0) a += mod;     return a;   }   int powmod(int x, int y, int mod = 1000000007) {     int res = 1;     while (y > 0) {       if (y & 1) res = mul(res, x, mod);       x = mul(x, x, mod);       y = y >> 1;     }     return res;   }   int inv(int a, int mod = 1000000007) { return powmod(a, mod - 2); }   int main() {     fast();     int n;     cin >> n;     vector<int> dp((1 << 22), -1), a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       dp[a[i]] = a[i];     }     int p = (1 << 22);     for (int i = 0; i < p; i++) {       if (dp[i] != -1)         for (int j = 0; j < 22; j++) {           if ((i & (1 << j)) == 0) {             dp[i | (1 << j)] = dp[i];           }         }     }     for (int i = 0; i < n; i++) {       cout << dp[(1 << 22) - 1 - a[i]] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void io() {}   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cout.tie();     cout << fixed << setprecision(8);     long long int n, a, b, c = 0, k;     cin >> a >> b >> n;     for (int i = 0; i < 10; i++) {       if (((a * 10) + i) % b == 0) {         c++;         k = (a * 10) + i;         break;       }     }     if (c == 1) {       cout << k;       for (int i = 1; i < n; i++) {         cout <<  0 ;       }     } else {       cout <<  -1 ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int a, b, n;       cin >> a >> b >> n;       long long int cnt = 0;       while (1) {         if (b > a) {           a += b;           cnt++;         } else {           b += a;           cnt++;         }         if (a > n || b > n) break;       }       cout << cnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> joy;     while (n > 0) {       int f, t;       cin >> f >> t;       if (t > k) f = f - t + k;       joy.push_back(f);       n--;     }     sort(joy.begin(), joy.end());     cout << joy.back();   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v;   long long int arr[100001], operation[100001][3], kitnibaar1[100002],       kitnibaar[100002], update1[100002], update[100002];   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       cin >> arr[i];     }     for (int i = 1; i <= m; i++) {       cin >> operation[i][0];       cin >> operation[i][1];       cin >> operation[i][2];     }     for (int i = 1; i <= k; i++) {       int start, end;       cin >> start >> end;       kitnibaar1[start]++;       kitnibaar1[end + 1]--;     }     long long int up = 0;     for (int i = 1; i <= m; i++) {       up += kitnibaar1[i];       kitnibaar[i] += up;     }     up = 0;     for (int i = 1; i <= m; i++) {       operation[i][2] *= kitnibaar[i];       update[operation[i][0]] += operation[i][2];       update[operation[i][1] + 1] -= operation[i][2];     }     up = 0;     for (int i = 1; i <= n; i++) {       up += update[i];       arr[i] += up;       cout << arr[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400010;   int n, ans[N], where[N];   long long sz[N];   vector<int> v[N];   bool visit[N];   void init() {     scanf( %d , &n);     int a, b;     for (int i = 0; i < n - 1; ++i) {       scanf( %d %d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }   }   void dfs(int now) {     visit[now] = true;     for (int i = 0; i < v[now].size(); ++i)       if (!visit[v[now][i]]) {         dfs(v[now][i]);         sz[now] += sz[v[now][i]];       }     if (sz[now] == 0)       sz[now] = 1;     else       sz[now] += 1;   }   int find_centroid(int now) {     visit[now] = true;     for (int i = 0; i < v[now].size(); ++i) {       if (visit[v[now][i]]) continue;       if (sz[v[now][i]] > n / 2) return find_centroid(v[now][i]);     }     return now;   }   void sv(int now, int value) {     if (visit[now]) return;     visit[now] = true;     where[now] = value;     for (int i = 0; i < v[now].size(); ++i) sv(v[now][i], value);   }   void dfs2(int now) {     visit[now] = true;     for (int i = 0; i < v[now].size(); ++i) sv(v[now][i], i);   }   void solve() {     dfs(1);     for (int i = 1; i <= n; ++i) visit[i] = false;     int centroid = find_centroid(1);     for (int i = 1; i <= n; ++i) visit[i] = false;     dfs2(centroid);     for (int i = 1; i <= n; ++i) {       visit[i] = false;       sz[i] = 0;     }     dfs(centroid);     vector<int> tmp;     for (int i = 0; i < v[centroid].size(); ++i)       tmp.push_back(sz[v[centroid][i]]);     int max1 = -1000000006, idx1, max2 = -1000000006, idx2;     for (int i = 0; i < tmp.size(); ++i)       if (tmp[i] > max1) {         max1 = tmp[i];         idx1 = i;       }     if ((n % 2 == 0) && max1 == n / 2)       max2 = n / 2;     else {       for (int i = 0; i < tmp.size(); ++i)         if (tmp[i] > max2 && i != idx1) {           max2 = tmp[i];           idx2 = i;         }     }     for (int i = 1; i <= n; ++i) {       if (i == centroid)         ans[i] = 1;       else if (where[i] == idx1) {         int tmp = n - sz[i] - max2;         if (tmp <= n / 2)           ans[i] = 1;         else           ans[i] = 0;       } else {         int tmp = n - sz[i] - max1;         if (tmp <= n / 2)           ans[i] = 1;         else           ans[i] = 0;       }     }     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     printf(  n );   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int __ = 1;     while (__--) {       init();       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const long long ooo = 9223372036854775807ll;   const int _cnt = 1000 * 1000 + 7;   const int _p = 1000 * 1000 * 1000 + 7;   const int N = 1001005;   const double PI = acos(-1.0);   const double eps = 1e-9;   int o(int x) { return x % _p; }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   void file_put() {     freopen( filename.in ,  r , stdin);     freopen( filename.out ,  w , stdout);   }   long long a, b, p, x, r[N], tt = 1, q[N], x0, ans = 0, T = 1, T_rev;   bool v[N];   long long Pow(long long x, long long k) {     long long ans = 1;     for (; k; k >>= 1, (x *= x) %= p)       if (k & 1) (ans *= x) %= p;     return ans;   }   int main() {     scanf( %I64d%I64d%I64d%I64d , &a, &b, &p, &x);     if (a == 1)       if (x < b)         return 0 * printf( 0 n );       else         return 0 * printf( %I64d n , (x - b) / p + 1);     v[1] = 1;     while (1) {       (tt *= a) %= p;       if (v[tt]) break;       v[tt] = 1;       T++;     }     r[1] = tt = 1;     for (int i = (1); i <= (T - 1); ++i) q[(tt *= a) %= p] = i;     q[1] = 0;     T_rev = Pow(T, p - 2);     for (int i = (2); i <= (p - 1); ++i) r[i] = (p - p / i) * r[p % i] % p;     for (int i = (1); i <= (p - 1); ++i) {       if (i > 1 && !q[i]) continue;       long long t = i;       x0 = (r[t] * b % p * T * T_rev + q[t] * p) % (p * T);       if (x < x0) continue;       ans += (x - x0) / (p * T) + 1;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char str[200];     int num, i, j, k;     int pre = 0;     char temp[10];     cin.getline(str, 200,   n );     for (i = 0; str[i] != 0; i++) {       num = str[i];       j = 0;       while (num != 0) {         k = num % 2;         temp[j++] = k +  0 ;         num = (num - k) / 2;       }       while (j < 8) temp[j++] =  0 ;       temp[j] =   0 ;       for (j = 0; j < 8; j++) num += (temp[j] -  0 ) << (7 - j);       k = (pre - num) % 256;       if (k < 0) k += 256;       cout << k << endl;       pre = num;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct triple {     int first;     int second;     int third;     void set(int a, int b, int c) {       first = a;       second = b;       third = c;     }   };   triple t[53][53][8] = {0};   int table[53][53] = {0};   void f(int a, int b, int c) {     if (table[a][b] == 0 || b > 50 || a > 50 || a < 1 || b < 1) return;     int x = a;     int y = b;     if (c == 0) {       while (table[x - 1][y] == table[a][b]) x--;       while (table[x][y + 1] == table[a][b]) y++;       if (table[x][y + 1] != 0)         t[a][b][c].set(x, y + 1, c);       else         t[a][b][c].set(a, b, 1);     } else if (c == 1) {       while (table[x + 1][y] == table[a][b]) x++;       while (table[x][y + 1] == table[a][b]) y++;       if (table[x][y + 1] != 0)         t[a][b][c].set(x, y + 1, c);       else         t[a][b][c].set(a, b, 2);     } else if (c == 2) {       while (table[x + 1][y] == table[a][b]) x++;       while (table[x][y + 1] == table[a][b]) y++;       if (table[x + 1][y] != 0)         t[a][b][c].set(x + 1, y, c);       else         t[a][b][c].set(a, b, 3);     } else if (c == 3) {       while (table[x + 1][y] == table[a][b]) x++;       while (table[x][y - 1] == table[a][b]) y--;       if (table[x + 1][y] != 0)         t[a][b][c].set(x + 1, y, c);       else         t[a][b][c].set(a, b, 4);     } else if (c == 4) {       while (table[x + 1][y] == table[a][b]) x++;       while (table[x][y - 1] == table[a][b]) y--;       if (table[x][y - 1] != 0)         t[a][b][c].set(x, y - 1, c);       else         t[a][b][c].set(a, b, 5);     } else if (c == 5) {       while (table[x - 1][y] == table[a][b]) x--;       while (table[x][y - 1] == table[a][b]) y--;       if (table[x][y - 1] != 0)         t[a][b][c].set(x, y - 1, c);       else         t[a][b][c].set(a, b, 6);     } else if (c == 6) {       while (table[x - 1][y] == table[a][b]) x--;       while (table[x][y - 1] == table[a][b]) y--;       if (table[x - 1][y] != 0)         t[a][b][c].set(x - 1, y, c);       else         t[a][b][c].set(a, b, 7);     } else if (c == 7) {       while (table[x - 1][y] == table[a][b]) x--;       while (table[x][y + 1] == table[a][b]) y++;       if (table[x - 1][y] != 0)         t[a][b][c].set(x - 1, y, c);       else         t[a][b][c].set(a, b, 0);     }   }   int main() {     int n, m;     cin >> n >> m;     string s;     int h = 0;     cin.ignore();     for (int i = 0; i < n; i++) {       getline(cin, s);       for (int j = 0; j < s.size(); j++) {         table[i + 1][j + 1] = s[j] -  0 ;       }     }     h = s.size();     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= h; j++) {         for (int k = 0; k < 8; k++) {           f(i, j, k);         }       }     }     int q1 = 1, q2 = 1, q3 = 0;     int w1, w2, w3;     for (int i = 0; i < m; i++) {       w1 = t[q1][q2][q3].first;       w2 = t[q1][q2][q3].second;       w3 = t[q1][q2][q3].third;       q1 = w1;       q2 = w2;       q3 = w3;     }     cout << table[q1][q2] << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int V = 25;   int n, k, sx, sy;   bool adj[V][V];   double p[V];   double mat[V * V][V * V];   int id[V][V], deg[V];   double calc_p(int i, int j) {     return (i == j) ? p[i] : (adj[i][j]) ? (1 - p[i]) / deg[i] : 0.0;   }   void gauss(double a[][V * V], int m, int n) {     for (int i = 0; i < m; i++) {       int u = i;       for (int r = i + 1; r < m; r++)         if (fabs(a[r][i]) > fabs(a[u][i])) u = r;       if (u != i)         for (int j = i; j < m + n; j++) swap(a[i][j], a[u][j]);       double t = a[i][i];       for (int j = i; j < m + n; j++) a[i][j] /= t;       for (int c = 0; c < m; c++)         if (c != i) {           t = a[c][i];           for (int j = i; j < m + n; j++) a[c][j] -= t * a[i][j];         }     }   }   int main() {     int a, b;     scanf( %d%d%d%d , &n, &k, &sx, &sy);     sx--;     sy--;     memset(deg, 0, sizeof(deg));     memset(adj, 0, sizeof(adj));     for (int i = 0; i < k; i++) {       scanf( %d%d , &a, &b);       a--;       b--;       adj[a][b] = adj[b][a] = true;       deg[a]++;       deg[b]++;     }     int m = 0;     for (int i = 0; i < n; i++)       for (int j = i; j < n; j++) id[i][j] = id[j][i] = m++;     for (int i = 0; i < n; i++) scanf( %lf , &p[i]);     memset(mat, 0, sizeof(mat));     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) {         for (int x = 0; x < n; x++)           for (int y = 0; y < n; y++) {             mat[id[i][j]][id[x][y]] += calc_p(i, x) * calc_p(j, y);           }       }     for (int i = 0; i < m; i++) mat[i][i] -= 1;     for (int i = 0; i < n; i++) mat[id[i][i]][id[i][i]] = 1;     for (int i = 0; i < n; i++) mat[id[i][i]][m + i] = 1;     gauss(mat, m, n);     for (int i = 0; i < n; i++) {       if (i) printf(   );       printf( %.9f , mat[id[sx][sy]][m + i]);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int dp[1 << 25];   int tick[25][25], value[25][25], cost[25][25];   int n, m;   string s[25];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> value[i][j];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int maxi = 0;         for (int x = 0; x < n; x++)           if (s[i][j] == s[x][j]) {             tick[i][j] |= (1 << x);             maxi = max(maxi, value[x][j]);             cost[i][j] += value[x][j];           }         cost[i][j] -= maxi;       }     memset(dp, 1000000005, sizeof(dp));     dp[0] = 0;     for (int mask = 1; mask < (1 << n); mask++) {       int t;       for (int pos = 0; pos < n; pos++)         if ((mask >> pos) & 1) {           t = pos;           break;         }       for (int pos = 0; pos < m; pos++) {         dp[mask] = min(dp[mask], dp[mask & (mask ^ tick[t][pos])] + cost[t][pos]);         dp[mask] = min(dp[mask], dp[mask - (1 << t)] + value[t][pos]);       }     }     cout << dp[(1 << n) - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937_64 rnd(time(NULL));   const int N = 25;   const int inf = 1e9;   const double MAX_T = 1000;   const double MIN_T = 1e-5;   const int max_mutations = 10;   int n, m;   vector<int> A, B;   vector<vector<int> > best_ans, cur_ans;   int best_cost = 0;   inline void mutation(vector<vector<int> > &a) {     int cnt = rnd() % max_mutations + 1;     for (; cnt; cnt--) {       int x = rnd() % n, y = rnd() % m;       a[x][y] = rnd() % 2;     }   }   inline int calc(vector<vector<int> > &a) {     int x = 0, res = 0;     for (int i = 0; i < n; i++) {       x = 0;       for (int j = 0; j < m; j++) {         if (a[i][j] == 1 && (j == 0 || a[i][j - 1] == 0)) x++;       }       res += (x - A[i]) * (x - A[i]);     }     for (int i = 0; i < m; i++) {       x = 0;       for (int j = 0; j < n; j++) {         if (a[j][i] == 1 && (j == 0 || a[j - 1][i] == 0)) x++;       }       res += (x - B[i]) * (x - B[i]);     }     return res;   }   inline double ok(double E, double t) { return exp(-E / t); }   inline bool valid(double E, double t) {     if (E < 0) return true;     double x = ok(E, t);     x *= inf;     return (rnd() % inf <= x);   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     A.resize(n, 0);     B.resize(m, 0);     for (int i = 0; i < n; i++) cin >> A[i];     for (int j = 0; j < m; j++) cin >> B[j];     cur_ans.assign(n, vector<int>(m));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cur_ans[i][j] = rnd() % 2;     best_ans = cur_ans;     best_cost = calc(cur_ans);     double T = MAX_T;     int i = 1;     while (T > MIN_T && best_cost != 0) {       mutation(cur_ans);       int cur_cost = calc(cur_ans);       if (valid(cur_cost - best_cost, T)) {         best_cost = min(best_cost, cur_cost);         if (best_cost == cur_cost) best_ans = cur_ans;       } else         cur_ans = best_ans;       T = MAX_T * 0.1 / i;       i++;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (best_ans[i][j])           cout <<  * ;         else           cout <<  . ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lint = long long;   using ld = long double;   using pint = pair<int, int>;   using plint = pair<lint, lint>;   lint _pow(lint a, lint n) {     if (n == 0)       return 1;     else {       lint res = 1;       lint buf = a;       while (n > 0) {         if (n % 2 == 1) {           res *= buf;           res %= 998244353LL;         }         buf *= buf;         buf %= 998244353LL;         n /= 2;       }       return res;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> c(n + 10, 0);     for (lint i = 0; i < (int)n; i++) {       int a;       cin >> a;       c[a]++;     }     lint ans = 0;     vector<lint> dp(n + 10, 0);     dp[0] = 1;     vector<lint> rev(n + 10);     for (lint i = 0; i < (int)n + 10; i++) rev[i] = _pow(i, 998244353LL - 2);     for (lint i = 0; i < (int)n + 10; i++) {       if (c[i] == 0) continue;       if (c[i] >= 2) {         for (lint j = 0; j < (int)n + 10; j++) {           lint p = dp[j];           p *= c[i];           p %= 998244353LL;           p *= c[i] - 1;           p %= 998244353LL;           p *= rev[n - j];           p %= 998244353LL;           p *= rev[n - j - 1];           p %= 998244353LL;           ans += p;           ans %= 998244353LL;         }       }       vector<lint> ndp(n + 10, 0);       for (lint j = 0; j < (int)n + 10; j++) ndp[j] += dp[j];       for (lint j = 1; j < (int)n + 10; j++) {         lint p = dp[j - 1];         p *= c[i];         p %= 998244353LL;         p *= rev[n - j + 1];         p %= 998244353LL;         ndp[j] += p;         ndp[j] %= 998244353LL;       }       dp = ndp;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:104857600 )   using namespace std;   const int c = 1000100;   int n, m;   int a[c];   int ans;   int d;   void go(int i, int b) {     if (a[i]) return;     a[i] = 1;     int k = (m - 1) << 1;     int nb = b;     int p = i;     while (k) {       if (b > 0)         d = min(k, n - p);       else         d = min(k, p - 1);       p += d * b;       if (d < k) b = -b;       k -= d;     }     go(p, b);     k = (m - 1) << 1;     p = i;     b = -nb;     while (k) {       if (b > 0)         d = min(k, n - p);       else         d = min(k, p - 1);       p += d * b;       if (d < k) b = -b;       k -= d;     }     go(p, b);   }   int main() {     scanf( %d%d , &n, &m);     ans = 0;     int i;     for (i = 1; i <= n; ++i)       if (!a[i]) {         ++ans;         go(i, 1);       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   long long small(long long a, long long b) {     if (a < b) return a;     return b;   }   long long large(long long a, long long b) {     if (a > b) return a;     return b;   }   long long root(long long x, vector<long long>& a) {     if (a[x] == x) return x;     a[x] = root(a[x], a);     return (a[x]);   }   int main() {     long long t;     t = 1;     while (t--) {       long long n, i, c, m, x, y, a1, h, k = 0;       cin >> n >> m;       vector<long long> v(n + 1, 0), a(n + 1, 0);       for (i = 1; i <= n; i++) {         cin >> v[i];         a[i] = i;       }       while (m--) {         cin >> x >> y;         x = root(x, a);         y = root(y, a);         if (v[x] < v[y])           a[y] = x;         else           a[x] = y;       }       for (i = 1; i <= n; i++) {         if (a[i] == i) k = k + v[i];       }       cout << k << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int const maxn = 60, maxl = 10010;   int f[maxn * maxl];   int n, d, c, sum;   int main() {     cin >> n >> d;     f[0] = 1;     for (int i = 0; i < n; i++) {       cin >> c;       for (int j = sum; j >= 0; j--)         if (f[j]) f[j + c] = 1;       sum += c;     }     int last = 0, t = 0;     while (true) {       int cur = last;       for (int i = d; i > 0; i--) {         if (f[last + i]) {           cur = last + i;           break;         }       }       if (cur == last) {         cout << last <<     << t << endl;         break;       }       last = cur;       t++;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length();     int row, col;     if (n <= 20) {       int row = 1;       int col = n;       cout << row <<     << col << endl;       cout << s;     } else if (n >= 21 && n <= 40) {       int row = 2;       int stars = 0;       int col;       if (n % 2 == 0) {         col = n / 2;       } else {         col = n / 2 + 1;         stars = col * 2 - n;       }       int ctr = 0;       cout << row <<     << col << endl;       for (int i = 0; i < row - 1; i++) {         if (stars > 0) {           for (int j = 0; j < col - 1; j++) {             cout << s[ctr];             ctr++;           }           cout <<  * ;           stars--;           cout << endl;         } else {           for (int j = 0; j < col; j++) {             cout << s[ctr];             ctr++;           }           cout << endl;         }       }       while (ctr <= (n - 1)) {         cout << s[ctr];         ctr++;       }       if (stars > 0) cout <<  * ;     } else if (n >= 41 && n <= 60) {       int row = 3;       int stars = 0;       int col;       if (n % 3 == 0) {         col = n / 3;       } else {         col = n / 3 + 1;         stars = col * 3 - n;       }       int ctr = 0;       cout << row <<     << col << endl;       for (int i = 0; i < row - 1; i++) {         if (stars > 0) {           for (int j = 0; j < col - 1; j++) {             cout << s[ctr];             ctr++;           }           cout <<  * ;           stars--;           cout << endl;         } else {           for (int j = 0; j < col; j++) {             cout << s[ctr];             ctr++;           }           cout << endl;         }       }       while (ctr <= (n - 1)) {         cout << s[ctr];         ctr++;       }       if (stars > 0) cout <<  * ;     } else if (n >= 61 && n <= 80) {       int row = 4;       int stars = 0;       int col;       if (n % 4 == 0) {         col = n / 4;       } else {         col = n / 4 + 1;         stars = col * 4 - n;       }       int ctr = 0;       cout << row <<     << col << endl;       for (int i = 0; i < row - 1; i++) {         if (stars > 0) {           for (int j = 0; j < col - 1; j++) {             cout << s[ctr];             ctr++;           }           cout <<  * ;           stars--;           cout << endl;         } else {           for (int j = 0; j < col; j++) {             cout << s[ctr];             ctr++;           }           cout << endl;         }       }       while (ctr <= (n - 1)) {         cout << s[ctr];         ctr++;       }       if (stars > 0) cout <<  * ;     } else {       int row = 5;       int stars = 0;       int col;       if (n % 5 == 0) {         col = n / 5;       } else {         col = n / 5 + 1;         stars = col * 5 - n;       }       int ctr = 0;       cout << row <<     << col << endl;       for (int i = 0; i < row - 1; i++) {         if (stars > 0) {           for (int j = 0; j < col - 1; j++) {             cout << s[ctr];             ctr++;           }           cout <<  * ;           stars--;           cout << endl;         } else {           for (int j = 0; j < col; j++) {             cout << s[ctr];             ctr++;           }           cout << endl;         }       }       while (ctr <= (n - 1)) {         cout << s[ctr];         ctr++;       }       if (stars > 0) cout <<  * ;     }   }


#include <bits/stdc++.h>   using namespace std;   int a, b;   int noOfDivisors(int n) {     int till = sqrt(n);     int c = 0;     for (int i = 1; i < till + 1; i++) {       if ((n % i) == 0) {         if (i > b) c++;         if ((n / i) > b && (n != i * i)) c++;       }     }     return c;   }   int main() {     scanf( %d%d , &a, &b);     int ans = 0;     if (a == b) {       printf( infinity );       return 0;     } else {       printf( %d , noOfDivisors(a - b));     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200;   const int maxm = maxn * maxn;   const int INF = 0x3f3f3f3f;   int n, k, s, ans, res;   int a[maxn];   int dp[maxn][maxm];   inline int read() {     int x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x;   }   int main() {     if (fopen( D.in ,  r ) != NULL) {       freopen( D.in ,  r , stdin);       freopen( D.out ,  w , stdout);     }     n = read(), k = read(), s = read();     s = min(s, n * (n - 1) / 2);     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= k; i++) ans += a[i];     memset(dp, INF, sizeof(dp));     dp[0][0] = 0;     for (int p = 1; p <= k; p++)       for (int i = p - 1; i >= 0; i--)         for (int j = s - (k + 1 - p); j >= 0; j--)           dp[i + 1][j + k + 1 - p] =               min(dp[i + 1][j + k + 1 - p], dp[i][j] - a[p]);     for (int p = k + 1; p <= n; p++)       for (int i = 1; i <= k; i++)         for (int j = s - (p - (k + 1)); j >= 0; j--)           dp[i - 1][j + p - (k + 1)] =               min(dp[i - 1][j + p - (k + 1)], dp[i][j] + a[p]);     for (int i = 0; i <= s; i++) res = min(res, dp[0][i]);     printf( %d n , ans + res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)2e9;   const long long INFL = (long long)9e18;   const int MAXINT = ((~0) ^ (1 << 31));   const long long MAXLL = ((~0) ^ ((long long)1 << 63));   template <class T>   inline T pow2(T a) {     return a * a;   }   template <class T>   inline bool mineq(T& a, T b) {     return (a > b) ? (a = b, true) : false;   }   template <class T>   inline bool maxeq(T& a, T b) {     return (a < b) ? (a = b, true) : false;   }   const int maxn = 2e5 + 100;   long long n, m, d, lt, a, b, t;   long long dp[2 * maxn];   long long rmq[2 * maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> d;     for (int i = 0; i < (int)(m); i++) {       cin >> a >> b >> t;       t = t - lt;       lt = lt + t;       long long gap = min(n, t * d);       deque<int> stk;       for (int i = 0; i < (int)(2 * n); i++) {         while (!stk.empty() && dp[stk.back()] <= dp[i]) stk.pop_back();         if (!stk.empty() && stk.front() == i - 2 * gap - 1) stk.pop_front();         stk.push_back(i);         rmq[i] = dp[stk.front()];       }       for (int i = 0; i < (int)(n); i++) {         dp[i] = rmq[i + gap] + b - abs(a - i - 1);       }       for (int i = n; i < (int)(2 * n); i++) dp[i] = -INF / 2;     }     cout << *max_element(dp, dp + n) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod7 = 998244353;   vector<vector<long long> > mul(vector<vector<long long> > &A,                                  vector<vector<long long> > &B,                                  long long mod = mod7) {     vector<vector<long long> > res(A.size(), vector<long long>(B[0].size()));     for (size_t i = 0; i < A.size(); ++i)       for (size_t j = 0; j < B[0].size(); ++j)         for (size_t k = 0; k < B.size(); ++k)           res[i][j] = (res[i][j] + A[i][k] * B[k][j]) % mod;     return res;   }   vector<vector<long long> > pow(vector<vector<long long> > A, long long n,                                  long long mod = mod7) {     vector<vector<long long> > res(A.size(), vector<long long>(A.size()));     for (size_t i = 0; i < A.size(); ++i) res[i][i] = 1;     for (; n; A = mul(A, A, mod), n >>= 1)       if (n & 1) res = mul(res, A, mod);     return res;   }   inline long long gcd(long long a, long long b) {     while (a && b) a > b ? a %= b : b %= a;     return a + b;   }   inline void exgcd(long long a, long long b, long long &x, long long &y) {     for (x = 1, y = 0; b;) {       long long t = a / b;       swap(a -= t * b, b);       swap(x -= t * y, y);     }   }   inline long long mmul(long long a, long long b, long long mod = mod7) {     a *= b;     return a >= mod ? a % mod : a;   }   inline long long minv(long long a, long long mod = mod7) {     if (gcd(a, mod) != 1) return -1;     long long x, y;     exgcd(a, mod, x, y);     return x < 0 ? x + mod : x;   }   inline long long mdiv(long long a, long long b, long long mod = mod7) {     if (a == 0) return 0;     long long g = gcd(b, mod);     if (a % g) return -1;     a /= g, b /= g, mod /= g;     return mmul(a, minv(b, mod), mod);   }   inline long long mpow(long long a, long long n, long long mod = mod7) {     long long res = 1;     for (; n; n >>= 1, a = mmul(a, a, mod))       if (n & 1) res = mmul(res, a, mod);     return res;   }   inline long long mlog(long long a, long long b, long long mod = mod7) {     int s = sqrt(mod) + 1;     long long t = 1;     unordered_map<long long, long long> m;     for (int i = 0; i < s; ++i, t = mmul(t, a, mod)) m[t] = i;     t = minv(t, mod);     for (int i = 0; i < s; ++i, b = mmul(t, b, mod))       if (m.count(b)) return m[b] + i * s;     throw;     return -1;   }   long long find_generator(long long order, long long p) {     vector<int> v;     long long o = order;     for (int i = 2; 1ll * i * i <= o; ++i)       if (o % i == 0) {         v.push_back(order / i);         while (o % i == 0) o /= i;       }     if (o > 1) v.push_back(order / o);     for (long long i = 2, t;; ++i) {       for (int j : v)         if ((t = mpow(i, j, p)) == 1ll) break;       if (t != 1ll) return i;     }   }   inline long long find_order(long long n) {     long long res = n;     for (long long i = 2; i * i <= n; ++i)       if (n % i == 0) {         while (n % i == 0) n /= i;         res /= i;         res *= (i - 1);       }     if (n > 1) res /= n, res *= (n - 1);     return res;   }   inline long long mroot(long long exp, long long b, long long mod = mod7) {     long long o = find_order(mod);     long long g = find_generator(o, mod);     long long o2 = mlog(g, b, mod);     long long o1 = mdiv(o2, exp, o);     if (o1 == -1) return -1;     return mpow(g, o1, mod);   }   long long N, M, K;   long long arr[105];   void init() {     cin >> K;     for (int i = 0; i < K; ++i) cin >> arr[i];     cin >> N >> M;   }   void sol() {     vector<vector<long long> > res(K, vector<long long>(K));     for (int i = 0; i < K; ++i) res[i][0] = arr[i];     for (int i = 1; i < K; ++i) res[i - 1][i] = 1;     res = pow(res, N - K, mod7 - 1);     N = res[0][0];     cout << mroot(N, M, mod7) << endl;   }   int main() {     init();     sol();   }


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


#include <bits/stdc++.h>   using namespace std;   void sdvig(char *c, int n) {     int i;     char s = c[0];     for (i = 0; i < n - 1; i++) {       c[i] = c[i + 1];     }     c[n - 1] = s;   }   int main() {     int n;     scanf( %d n , &n);     char c[1010], cc[1010];     cin >> cc;     int i, g, f, l = n - 1;     int mmin = 1000000000, kol;     bool fl;     for (f = 0; f < n; f++) {       kol = 0;       for (i = 0; i < n; i++) {         c[i] = cc[i];       }       while (true) {         i = 0;         g = l;         while (c[i] ==  H ) i++;         while (c[g] ==  T ) g--;         if (i < g) {           swap(c[i], c[g]);           kol++;         } else {           break;         }       }       if (kol < mmin) mmin = kol;       sdvig(cc, n);     }     cout << mmin;     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   namespace Xrocks {}   using namespace Xrocks;   namespace Xrocks {   class in {   } user_input;   class out {   } output;   in& operator>>(in& X, int& Y) {     scanf( %d , &Y);     return X;   }   in& operator>>(in& X, char* Y) {     scanf( %s , Y);     return X;   }   in& operator>>(in& X, float& Y) {     scanf( %f , &Y);     return X;   }   in& operator>>(in& X, double& Y) {     scanf( %lf , &Y);     return X;   }   in& operator>>(in& X, char& C) {     scanf( %c , &C);     return X;   }   in& operator>>(in& X, string& Y) {     cin >> Y;     return X;   }   in& operator>>(in& X, long long& Y) {     scanf( %lld , &Y);     return X;   }   template <typename T>   in& operator>>(in& X, vector<T>& Y) {     for (auto& x : Y) user_input >> x;     return X;   }   template <typename T>   out& operator<<(out& X, const T& Y) {     cout << Y;     return X;   }   template <typename T>   out& operator<<(out& X, vector<T>& Y) {     for (auto& x : Y) output << x <<    ;     return X;   }   out& operator<<(out& X, const int& Y) {     printf( %d , Y);     return X;   }   out& operator<<(out& X, const char& C) {     printf( %c , C);     return X;   }   out& operator<<(out& X, const string& Y) {     printf( %s , Y.c_str());     return X;   }   out& operator<<(out& X, const long long& Y) {     printf( %lld , Y);     return X;   }   out& operator<<(out& X, const float& Y) {     printf( %f , Y);     return X;   }   out& operator<<(out& X, const double& Y) {     printf( %lf , Y);     return X;   }   out& operator<<(out& X, const char Y[]) {     printf( %s , Y);     return X;   }   template <typename T>   T max(T A) {     return A;   }   template <typename T, typename... args>   T max(T A, T B, args... S) {     return max(A > B ? A : B, S...);   }   template <typename T>   T min(T A) {     return A;   }   template <typename T, typename... args>   T min(T A, T B, args... S) {     return min(A < B ? A : B, S...);   }   template <typename T>   void vectorize(int y, vector<T>& A) {     A.resize(y);   }   template <typename T, typename... args>   void vectorize(int y, vector<T>& A, args&&... S) {     A.resize(y);     vectorize(y, S...);   }   long long fast(long long a, long long b, long long pr) {     if (b == 0) return 1 % pr;     long long ans = 1 % pr;     while (b) {       if (b & 1) ans = (ans * a) % pr;       b >>= 1;       a = (a * a) % pr;     }     return ans;   }   int readInt() {     int n = 0;     int ch = getchar_unlocked();     int sign = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) sign = -1;       ch = getchar_unlocked();     }     while (ch >=  0  && ch <=  9 )       n = (n << 3) + (n << 1) + ch -  0 , ch = getchar_unlocked();     n = n * sign;     return n;   }   long long readLong() {     long long n = 0;     int ch = getchar_unlocked();     int sign = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) sign = -1;       ch = getchar_unlocked();     }     while (ch >=  0  && ch <=  9 )       n = (n << 3) + (n << 1) + ch -  0 , ch = getchar_unlocked();     n = n * sign;     return n;   }   long long readBin() {     long long n = 0;     int ch = getchar_unlocked();     int sign = 1;     while (ch <  0  || ch >  1 ) {       if (ch ==  - ) sign = -1;       ch = getchar_unlocked();     }     while (ch >=  0  && ch <=  1 )       n = (n << 1) + (ch -  0 ), ch = getchar_unlocked();     return n;   }   long long inv_(long long val,                  long long pr = static_cast<long long>(1000000007)) {     return fast(val, pr - 2, pr);   }   }  // namespace Xrocks   class solve {    public:     solve() {       set<int> Buy, Sell, Mid;       int n;       user_input >> n;       Buy.insert(-1);       Sell.insert(1e9);       char action[10];       int num;       int B1 = 0, B2 = 0;       long long ans = 1;       for (int i = 0; i < n; i++) {         scanf( %s%d , action, &num);         if (action[1] ==  D ) {           B1 = *Buy.rbegin();           B2 = *Sell.begin();           if (B1 < num && B2 > num) {             Mid.insert(num);           } else if (B1 > num) {             Buy.insert(num);           } else             Sell.insert(num);         } else {           if (Mid.find(num) != Mid.end()) {             set<int>::iterator it = Mid.find(num);             ++it;             while (it != Mid.end()) {               Sell.insert(*it);               ++it;             }             set<int>::iterator it2 = Mid.begin();             while (*it2 < num) {               Buy.insert(*it2);               ++it2;             }             Mid.clear();             ans = (ans * 2) % static_cast<long long>(1000000007);           } else if (num == (*Buy.rbegin())) {             Buy.erase(num);             Sell.insert(Mid.begin(), Mid.end());             Mid.clear();           } else if (num == (*Sell.begin())) {             Sell.erase(Sell.begin());             Buy.insert(Mid.begin(), Mid.end());             Mid.clear();           } else {             output << 0;             return;           }         }       }       if (Mid.size())         ans = (ans * (Mid.size() + 1)) % static_cast<long long>(1000000007);       output << ans;     }   };   int32_t main() {     int t = 1, i = 1;     if (0 || 0) scanf( %d , &t);     while (t--) {       if (0) printf( Case #%d:  , i++);       new solve;     }     output <<   n ;     return 0;   }


#include <iostream>         using namespace std;         int main()   {    int n, q;       cin >> n >> q;       char s[n+1];    int x[n+1];       for (int i = 1; i < n+1; i++)    {     cin >> s[i];     x[i] = x[i-1] + s[i] -  ` ;       }        int l, r;       for (int i = 0; i < q; i++)    {     cin >> l >> r;     cout << (x[r]-x[l-1]) << endl;       }                      return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long f[61 + 1], g[61 + 1], x, k;   int Q, op, pos;   int main() {     scanf( %d , &Q);     f[0] = 1;     for (int i = 1; i < 61; i++) f[i] = f[i - 1] * 2;     while (Q--) {       scanf( %d , &op);       if (op == 1) {         scanf( %I64d%I64d , &x, &k);         for (int i = 0; i < 61; i++)           if (f[i] >= x) {             pos = i;             break;           } else             x -= f[i];         g[pos] = (g[pos] + k) % f[pos];       }       if (op == 2) {         scanf( %I64d%I64d , &x, &k);         for (int i = 0; i < 61; i++)           if (f[i] >= x) {             pos = i;             break;           } else             x -= f[i];         k %= f[pos];         for (int i = pos; i < 61; i++) {           g[i] = (g[i] + k) % f[i];           k *= 2;         }       }       if (op == 3) {         scanf( %I64d , &x);         printf( %I64d , x);         long long tmp = x;         for (int i = 0; i < 61; i++)           if (f[i] >= x) {             pos = i;             break;           } else             x -= f[i];         x = tmp;         while (x != 1) {           long long xx = x, fa;           xx += g[pos];           if (xx < f[pos]) xx += f[pos];           if (xx >= f[pos + 1]) xx -= f[pos];           fa = xx / 2;           pos--;           fa -= g[pos];           if (fa < f[pos]) fa += f[pos];           if (fa >= f[pos + 1]) fa -= f[pos];           x = fa;           printf(  %I64d , fa);         }         printf(  n );       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5, SQ = 5555;   unordered_map<int, int> ed[N];   set<pair<int, int>> edge, bad;   int n, m, k, last, par[N];   struct Query {     int t, u, v;   } qu[SQ];   bool mark[N];   queue<int> q;   int gg(int u) { return ~par[u] ? par[u] = gg(par[u]) : u; }   void merge(int u, int v) {     u = gg(u);     v = gg(v);     if (u == v) return;     par[v] = u;   }   void upd(int u, int v) {     if (u > v) swap(u, v);     int a = gg(u), b = gg(v);     if (edge.erase({u, v})) {       if (!--ed[a][b]) ed[a].erase(b);       if (!--ed[b][a]) ed[b].erase(a);     } else {       edge.insert({u, v});       ed[a][b]++, ed[b][a]++;     }   }   void bfs(int root, bool st) {     q.push(root);     mark[root] = st;     while (!q.empty()) {       int u = q.front();       for (auto v : ed[u])         if (mark[v.first] ^ st) {           mark[v.first] = st;           q.push(v.first);         }       q.pop();     }   }   bool get(int u, int v) {     bfs(u = gg(u), true);     bool ans = mark[gg(v)];     return bfs(u, false), ans;   }   int main() {     scanf( %d%d , &n, &m);     while (m) {       bad.clear();       m -= (k = min(m, SQ));       for (int i = 0; i < k; i++) {         int t, u, v;         scanf( %d%d%d , &t, &u, &v);         if (u % n > v % n) swap(u, v);         bad.insert({u % n, v % n});         if (u-- > v--) swap(u, v);         qu[i] = {t, u, v}, bad.insert({u, v});       }       memset(par, -1, sizeof par);       for (int i = 0; i < n; i++) ed[i].clear();       for (auto x : edge)         if (!bad.count(x)) merge(x.first, x.second);       for (auto x : edge)         if (bad.count(x)) {           ed[gg(x.first)][gg(x.second)]++;           ed[gg(x.second)][gg(x.first)]++;         }       for (int i = 0; i < k; i++) {         (qu[i].u += last) %= n;         (qu[i].v += last) %= n;         if (qu[i].t & 1)           upd(qu[i].u, qu[i].v);         else           printf( %d , last = get(qu[i].u, qu[i].v));       }     }   }


#include <bits/stdc++.h>   using namespace std;   double a, b, m;   double vx, vy, vz;   double x0, z0;   int main() {     scanf( %lf %lf %lf , &a, &b, &m);     {       scanf( %lf %lf %lf , &vx, &vy, &vz);       double t = -(m / vy);       double sx = vx * t;       double sz = vz * t;       int d = (int)(sz / b);       if (d % 2 == 0) {         z0 = sz - d * b;       } else {         z0 = b - (sz - d * b);       }       if (sx < -a / 2) {         sx = -(sx + a / 2);       } else {         sx = sx + a / 2;       }       d = (int)(sx / a);       if (d % 2 == 0) {         x0 = sx - d * a;       } else {         x0 = a - (sx - d * a);       }       printf( %.10lf %.10lf n , x0, z0);     }     return 0;   }


#include <bits/stdc++.h>   double arr[1005][4];   int main() {     int n, k;     scanf( %d%d , &n, &k);     int i;     long long population = k;     double maxRadius = -1, minRadius = 1e6;     for (i = 0; i < n; i++) {       scanf( %lf%lf%lf , &arr[i][0], &arr[i][1], &arr[i][2]);       population += arr[i][2];       arr[i][3] = sqrt((arr[i][0] * arr[i][0]) + (arr[i][1] * arr[i][1]));     }     if (population < 1000000)       printf( -1 n );     else {       int i, j;       for (i = 0; i < n; i++) {         for (j = 0; j < n - 1; j++) {           if (arr[j][3] > arr[j + 1][3]) {             double temp = arr[j][3];             arr[j][3] = arr[j + 1][3];             arr[j + 1][3] = temp;             temp = arr[j][0];             arr[j][0] = arr[j + 1][0];             arr[j + 1][0] = temp;             temp = arr[j][1];             arr[j][1] = arr[j + 1][1];             arr[j + 1][1] = temp;             temp = arr[j][2];             arr[j][2] = arr[j + 1][2];             arr[j + 1][2] = temp;           }         }       }       double radius = 0;       population = k;       for (i = 0; i < n; i++) {         if (population >= 1000000)           break;         else {           radius = arr[i][3];           population += arr[i][2];           for (j = i + 1; arr[j][3] == arr[i][3] && population < 1000000; j++) {             population += arr[j][2];           }           i = j - 1;         }       }       printf( %lf n , radius);     }     return 0;   }