#include <iostream>   #include <vector>   #include <string>   #include <algorithm>   #include <utility>   #include <set>   #include <queue>   #include <deque>   #include <stack>   #include <map>   #include <math.h>    #include <iomanip>   #include <fstream>   #include <bitset>   #include <sstream>       using namespace std;   //#define M_PI (ldb)3.14159265358979323846 // pi    #define forr(i,a,b,c) for(int i=a;i<b;i+=c)   #define forrb(i,a,b,c) for(int i=a;i>b;i-=c)   #define fori(i,n) forr(i,0,n,1)   #define forit(it,arr) for(auto it=arr.begin();it != arr.end();it++)   #define forib(i,n) forrb(i,n-1,-1,1)   #define forn(i,n) forr(i,1,n,1)   #define fornb(i,n) forrb(i,n-1,0,1)   #define fort(i,m,n) forr(i,m,n,1)   #define fortb(i,m,n) forrb(i,n-1,m-1,1)   #define forin(i,arr) fori(i,arr.size())   #define forinb(i,arr) forib(i,arr.size())   #define forrl(i,a,b,c) for(lol i=a;i<b;i+=c)   #define forrbl(i,a,b,c) for(lol i=a;i>b;i-=c)   #define foril(i,n) forrl(i,0,n,1)   #define foribl(i,n) forrbl(i,n-1,-1,1)   #define fornl(i,n) forrl(i,1,n,1)   #define fornbl(i,n) forrbl(i,n-1,0,1)   #define fortl(i,m,n) forrl(i,m,n,1)   #define fortbl(i,m,n) forrbl(i,n-1,m-1,1)   #define forinl(i,arr) foril(i,arr.size())   #define forinbl(i,arr) foribl(i,arr.size())   #define forpm(i) forr(i,-1,2,2)   #define into(i) cin >> i;   #define intov(arr,n) fori(kkkk,n){into(arr[kkkk])}   #define def(i) lol i; into(i)   #define deft(t,i) t i; into(i)   #define defl(i) lol i; into(i)   #define defs(i) string i; into(i)   #define defn def(n)   #define defp def(p)   #define defm def(m)   #define defk def(k)   #define defa def(a)   #define defb def(b)   #define defc def(c)   #define defd def(d)   //#define vec(a) vector<a>   #define co cout <<   #define out(a) cout << (a) <<   ;   #define el << endl;   #define ell <<   n ;   #define outv(arr,n) fori(iii,n){out(arr[iii])} co    el   #define outvv(arr,n,m) fori(jjj,n){outv(arr[jjj],m)}   #define cas(p) co  Case #  << p+1 << :  ;   #define ex return 0;    #define qii queue<int>   #define sti stack<int>   #define dei deque<int>   #define seti set<int>   #define con continue;   #define br break;   #define maxi 1000000007   // 998244353   #define maxiu 4294967295   #define lmaxi 2000000000000000007   #define mod %maxi   #define wne(arr) while(!arr.empty())   #define all(arr) arr.begin(),arr.end()   #define getv(arr,n) fori(i,n) {into(arr[i])}   #define defv(arr,n) veci arr(n); fori(i,n) {into(arr[i])}   #define min2(a,b) a=min(a,b);   #define max2(a,b) a=max(a,b);   #define vec vector   #define ff first   #define ss second   #define pow2(x) (x)*(x)   #define pow3(x) (x)*(x)*(x)   #define getgraph(m,cons) fori(i,m){defa defb a--; b--; cons[a].push_back(b);cons[b].push_back(a);}   #define getdirectedgraph(m,cons) fori(i,m){defa defb a--; b--; cons[a].push_back(b);}   #define getwightedgraph(m,cons) fori(i,m){defa defb defc a--; b--; cons[a].push_back({b,c});cons[b].push_back({a,c});}   #define getwighteddirectedgraph(m,cons) fori(i,m){defa defb defc a--; b--; cons[a].push_back({b,c});}   typedef vector<int> veci;   typedef long long lol;   typedef unsigned long long ulol;   typedef unsigned int uint;   typedef long double ldb;   typedef vector<lol> vecl;   typedef vector<uint> vecui;   typedef vector<ulol> vecul;   #define table(name,n,m) vector<veci> name(n,veci (m));   #define tablel(name,n,m) vector<vecl> name(n,vecl (m));   typedef pair<lol, lol> point;   #define setp set<point>   #define bmod %99999999999899999   typedef pair<point, point> poin;   typedef pair<long double, long double> pointd;   typedef pair<lol, point> poing;   typedef pair<point, lol> poinf;   typedef vector<point> vecp;   #define poi(x,y) make_pair(x,y)   struct BigNum {   #define sizer (lol) 1e9   #define digss (lol) 9    vecl value;    void set(lol x) { value = *(new vecl); value.push_back(x); }    void duplicate(BigNum other) { value = other.value; }    void add(BigNum other) {     vecl o = other.value;     if (o.size() > value.size()) {      vecl t = value;      value = o;      o = t;     }     forin(i, o) {      value[i] += o[i];      if (i < value.size() - 1 && value[i] >= sizer) {       value[i + 1] += value[i] / sizer;       value[i] = value[i] % sizer;      }     }     if (value.back() >= sizer) {      value.push_back(value.back() / sizer);      value[value.size() - 2] = value[value.size() - 2] % sizer;     }    }    void mul(lol mul) {     forin(i, value) {      value[i] *= mul;     }     fori(i, value.size() - 1) {      if (value[i] >= sizer) {       value[i + 1] += value[i] / sizer;       value[i] = value[i] % sizer;      }     }     if (value.back() >= sizer) {      value.push_back(value.back() / sizer);      value[value.size() - 2] = value[value.size() - 2] % sizer;     }    }    long double div(BigNum other1, BigNum other2) {     int s = value.size();     long double current = value.back();     if (s >= 2) {      current += ((long double)value[s - 2]) / sizer;     }     if (s >= 3) {      current += ((long double)value[s - 3]) / (sizer * sizer);     }     int s1 = other1.value.size();     int s2 = other2.value.size();     long double other = 0;     if (s1 + s2 - 1 == s) {      other += other1.value.back() * other2.value.back();      if (s1 >= 2) {       other += ((long double)other1.value[s1 - 2] * other2.value.back()) / sizer;      }      if (s2 >= 2) {       other += ((long double)other2.value[s2 - 2] * other1.value.back()) / sizer;      }      if (s1 >= 3) {       other += ((long double)other1.value[s1 - 3] * other2.value.back()) / (sizer * sizer);      }      if (s2 >= 3) {       other += ((long double)other2.value[s2 - 3] * other1.value.back()) / (sizer * sizer);      }     }     if (s1 + s2 - 1 == s - 1) {      other += other1.value.back() * other2.value.back();      if (s1 >= 2) {       other += ((long double)other1.value[s1 - 2] * other2.value.back()) / sizer;      }      if (s2 >= 2) {       other += ((long double)other2.value[s2 - 2] * other1.value.back()) / sizer;      }      other /= sizer;     }     if (s1 + s2 - 1 == s - 2) {      other += other1.value.back() * other2.value.back();      other /= sizer * sizer;     }     return other / current;    }    string stringify() {     string out = to_string(value.back());     forib(i, value.size() - 1) {      string cur = to_string(value[i] + sizer);      out += cur.substr(1);     }     return out;    }   };   lol gcd(lol a, lol b) {    if (b == 0) {     return a;    }    return gcd(b, a % b);   }   lol triangle(lol x) {    return ((x - 1) * x) / 2;   }   lol antitriangle(lol x) {    lol low = 0, high = 2 * maxi;    while (low < high) {     lol mid = (low + high + 1) / 2;     if (triangle(mid) <= x) {      low = mid;     }     else {      high = mid - 1;     }    }    return low;   }   lol modInverse(lol a)   {    lol m = maxi;    lol y = 0, x = 1;    while (a > 1)    {     lol q = a / m;     lol t = m;     m = a % m, a = t;     t = y;     y = x - q * y;     x = t;    }    if (x < 0) {     x += maxi;    }    return x;   }   lol modInverse(lol a, lol b)   {    lol m = b;    lol y = 0, x = 1;    while (a > 1)    {     lol q = a / m;     lol t = m;     m = a % m, a = t;     t = y;     y = x - q * y;     x = t;    }    if (x < 0) {     x += b;    }    return x;   }   lol poww(lol a, lol b) {    if (b == 0) {     return 1;    }    if (b % 2 == 0) {     return poww((a * a)mod, b / 2)mod;    }    return (a * poww((a * a)mod, b / 2))mod;   }   lol pow(lol a, lol b, lol m) {    if (b == 0) {     return 1;    }    if (b % 2 == 0) {     return pow((a * a) % m, b / 2, m) % m;    }    return (a * pow((a * a) % m, b / 2, m)) % m;   }   vecl dev(vecp divisors) {    if (divisors.size() == 0) {     vecl cur;     cur.push_back(1);     return cur;    }    lol x = divisors.back().first;    lol n = divisors.back().second;    divisors.pop_back();    vecl ans = dev(divisors);    vecl cur;    lol xi = 1;    fori(i, n + 1) {     forin(j, ans) {      cur.push_back(ans[j] * xi);     }     xi *= x;    }    return cur;   }   bool isprime(lol a) {    if (a == 1) {     return false;    }    for (int i = 2; i * i <= a; i++) {     if (a % i == 0) {      return false;     }    }    return true;   }   void add(veci & x, veci & y) {    forin(i, x) {     x[i] += y[i];    }   }   vecl mul(vecl x, lol a) {    forin(i, x) {     x[i] = (x[i] * a)mod;    }    return x;   }   vecl add(vecl x, vecl & y) {    forin(i, x) {     x[i] = (x[i] + y[i])mod;    }    return x;   }   #define logn 18   int lca(vector<veci> & f, veci & depth, int a, int b) {    if (depth[a] < depth[b]) {     swap(a, b);    }    fori(k, logn) {     if ((depth[a] - depth[b]) & (1 << k)) {      a = f[k][a];     }    }    if (a == b) {     return a;    }    forib(k, logn) {     if (f[k][a] != f[k][b]) {      a = f[k][a];      b = f[k][b];     }    }    return f[0][a];   }   int tredist(vector<veci>& f, veci& depth, int a, int b) {    return depth[a]+ depth[b]- 2*depth[lca(f,depth,a,b)];   }   struct pt   {   #define intopt(a) into(a.x) into(a.y)   #define defpt(a) pt a;intopt(a)    lol x, y;    lol d() const // squared length    {     return x * x + y * y;    }   };   typedef vector<pt> vecpp;   inline pt operator-(const pt & a) { return { -a.x, -a.y }; }   inline pt operator+(const pt & a, const pt & b) { return { a.x + b.x, a.y + b.y }; }   inline pt operator-(const pt & a, const pt & b) { return { a.x - b.x, a.y - b.y }; }   inline lol operator*(const pt & a, const pt & b) { return a.x* b.y - a.y * b.x; } // cross product   inline bool operator<(const pt& a, const pt& b) { if (a * b != 0) return a * b < 0; return a.d() < b.d(); }   bool llll(const pt & a, const pt & b) { return a * b > 0; }   inline bool operator<=(const pt & a, const pt & b) { return a * b <= 0; }   inline lol operator/(const pt & a, const pt & b) { return a.x* b.x + a.y * b.y; } // dot product   inline bool operator==(const pt & a, const pt & b) { return a.x == b.x && a.y == b.y; } // equal   inline bool operator!=(const pt & a, const pt & b) { return a.x != b.x || a.y != b.y; } // not equal   pt o = { 0 ,0 };   bool comp(pt a, pt b) {    if ((a - o) * (b - o) != 0)     return (a - o) * (b - o) < 0;    return (a - o).d() < (b - o).d();   }   bool decreasing(int a, int b) {    return a > b;   }   #define digits 30   struct booleantree   {    booleantree* left = NULL;    booleantree* right = NULL;    void add(int val) {     booleantree* cur = this;     forib(i, digits) {      if ((val & (1 << i))) {       if (cur->right == NULL) {        cur->right = new booleantree();       }       cur = cur->right;      }      else {       if (cur->left == NULL) {        cur->left = new booleantree();       }       cur = cur->left;      }     }    }    int find(int val) {     booleantree* cur = this;     int ans = 0;     forib(i, digits) {      if ((val & (1 << i))) {       if (cur->left == NULL) {        cur = cur->right;       }       else {        cur = cur->left;        ans += (1 << i);       }      }      else {       if (cur->right == NULL) {        cur = cur->left;       }       else {        cur = cur->right;        ans += (1 << i);       }      }     }     return ans;    }   };   struct segtremin {    vector<vecl> arr;    int n;    int curlogn;    segtremin(int size, int logni) {     n = size;     curlogn = logni;     arr.resize(curlogn);     fori(i, curlogn) {      arr[i].resize(size + 1);     }    }    inline lol val(int start, int end) {     if (end >= n) {      end = n - 1;     }     if (start < 0) {      start = 0;     }     lol mini = lmaxi;     fori(i, curlogn) {      if (start > end) {       br      }      if ((end & 1) == 0) {       min2(mini, arr[i][end]);       end--;       if (end < 0) {        br       }      }      if ((start & 1)) {       min2(mini, arr[i][start])        start++;      }      start /= 2;      end /= 2;     }     return mini;    }    inline void add(int start, lol num) {     arr[0][start] = num;     forn(i, curlogn) {      arr[i][start >> i] = min(arr[i - 1][(start >> i) * 2], arr[i - 1][(start >> i) * 2 + 1]);     }    }   };   struct segtreminplus {    vecl arr;    vector<vecl> arr2;    vector<vecl> arr3;    vector<vecl> arr4;    int n;    int curlogn;    segtreminplus(int size, int logni) {     n = size;     curlogn = logni;     arr.resize(size + 1);     arr2.resize(curlogn);     fori(i, curlogn) {      arr2[i].resize(size + 1);     }     arr3.resize(curlogn);     fori(i, curlogn) {      arr3[i].resize(size + 1);     }     arr4.resize(curlogn);     fori(i, curlogn) {      arr4[i].resize(size + 1);     }    }    inline void fixcate(int i, int j) {     if (j < 0) {      return;     }     if (i == 0) {      arr2[i][j] = 1;      arr3[i][j] = 1;      arr4[i][j] = 1;      return;     }     arr2[i][j] = max(arr2[i-1][2*j], arr2[i - 1][2 * j+1]);     arr3[i][j] = arr3[i - 1][2 * j];     arr4[i][j] = arr4[i - 1][2 * j+1];     if (((2 * j + 1) << (i - 1)) < n && arr[((2 * j + 1) << (i - 1))] > arr[((2 * j + 1) << (i - 1)) - 1]) {      arr2[i][j] = max(arr2[i][j], arr4[i - 1][2 * j]+ arr3[i - 1][2 * j+1]);      if (arr2[i - 1][2 * j+1] == (1 << (i - 1))) {       arr4[i][j] = arr4[i - 1][2 * j + 1] + arr4[i - 1][2 * j];      }      if (arr2[i - 1][2 * j] == (1 << (i - 1))) {       arr3[i][j] = arr3[i - 1][2 * j + 1] + arr3[i - 1][2 * j];      }     }    }    inline lol val(int start) {     if (start > 0) {      return arr[start];     }     return arr2[curlogn-1][0];    }    inline void change(int start, lol num) {     arr[start] = num;     fori(i, curlogn) {      fixcate(i, start >> i);     }    }   };   struct segtresum {    vector<vecl> arr;    int n;    int curlogn;    segtresum(int size, int logni) {     n = size;     curlogn = logni;     arr.resize(curlogn);     fori(i, curlogn) {      arr[i].resize(size + 1);     }    }    inline lol val(int start, int end) {     /*if (end >= n) {      end = n - 1;     }     if (start < 0) {      start = 0;     }*/     lol mini = 0;     fori(i, curlogn) {      if (start > end) {       br      }      if ((end & 1) == 0) {       mini += arr[i][end];       end--;       if (end < 0) {        br       }      }      if ((start & 1)) {       mini += arr[i][start];       start++;      }      start /= 2;      end /= 2;     }     return mini;    }    inline void add(int start, lol num) {     arr[0][start] = num;     forn(i, curlogn) {      arr[i][start >> i] = arr[i - 1][(start >> i) * 2] + arr[i - 1][(start >> i) * 2 + 1];     }    }    inline void radd(int start, lol num) {     arr[0][start] += num;     forn(i, curlogn) {      arr[i][start >> i] = arr[i - 1][(start >> i) * 2] + arr[i - 1][(start >> i) * 2 + 1];     }    }   };   struct segtresumplus {    vector<vecl> arr;    vector<vecl> arrplus;    vector<vecl> truearrplus;    int n;    int curlogn;    segtresumplus(int size, int logni) {     n = size;     curlogn = logni;     arr.resize(curlogn);     fori(i, curlogn) {      arr[i].resize(size + 1);     }     arrplus.resize(curlogn);     fori(i, curlogn) {      arrplus[i].resize(size + 1);     }     truearrplus.resize(curlogn);     fori(i, curlogn) {      truearrplus[i].resize(size + 1);     }    }    inline void fix(int h, int s) {     /*if (arrplus[h][s] == 0) {      return;     }     arr[h][s] += arrplus[h][s] << h;     if (h > 0) {      arrplus[h - 1][2 * s] += arrplus[h][s];      arrplus[h - 1][2 * s+ 1] += arrplus[h][s];     }     arrplus[h][s] = 0;*/    }    inline lol val(int start, int end) {     /*if (end >= n) {      end = n - 1;     }     if (start < 0) {      start = 0;     }*/     forib(i, curlogn) {      fix(i, start >> i);      fix(i, end >> i);     }     lol mini = 0;     fori(i, curlogn) {      if (start > end) {       br      }      if ((end & 1) == 0) {       fix(i, end);       mini += arr[i][end];       mini += arrplus[i][end];       fort(j, i + 1, curlogn) {        mini += truearrplus[j][end >> (j-i)]<< i;       }       end--;       if (end < 0) {        br       }      }      if ((start & 1)) {       fix(i, start);       mini += arr[i][start];       mini += arrplus[i][start];       fort(j, i + 1, curlogn) {        mini += truearrplus[j][start >> (j - i)] << i;       }       start++;      }      start /= 2;      end /= 2;     }     return mini;    }    inline void add(int start, lol num) {     arr[0][start] = num;     forn(i, curlogn) {      arr[i][start >> i] = arr[i - 1][(start >> i) * 2] + arr[i - 1][(start >> i) * 2 + 1];     }    }    inline void radd(int start,int end, lol num) {     fori(i, curlogn) {      if (start > end) {       br      }      if ((end & 1) == 0) {       truearrplus[i][end]+=num;       fort(j,i, curlogn) {        arrplus[j][end >> (j-i)] += num << i;       }       end--;       if (end < 0) {        br       }      }      if ((start & 1)) {       truearrplus[i][start] += num;       fort(j, i, curlogn) {        arrplus[j][start >> (j - i)] += num << i;       }       start++;      }      start /= 2;      end /= 2;     }    }   };   struct unionfind{    veci arr;   veci arr2;   int num;   unionfind(int size) {    arr.resize(size);    arr2.resize(size);    num = size;    fori(i, size) {     arr[i] = i;     arr2[i] = 1;    }   }   int find(int a) {    if (arr[a] == a) {     return a;    }    return arr[a] = find(arr[a]);   }   inline void unioner(int a, int b) {    a = find(a), b = find(b);    if (a != b) {     num--;     if (arr2[a] > arr2[b]) {      swap(a, b);     }     arr[a] = b;     arr2[b] += arr2[a];    }   }   };   string op(string s) {    string ans;    forinb(i, s) {     ans.push_back(s[i]);    }    return ans;   }   void merge(veci& color, vector<veci>& allcolor, int l, int r) {    if (color[l] == color[r]) {     return;    }    l = color[l];    r = color[r];    if (allcolor[l].size() < allcolor[r].size()) {     swap(l, r);    }    forin(j, allcolor[r]) {     color[allcolor[r][j]] = l;     allcolor[l].push_back(allcolor[r][j]);    }    allcolor[r].resize(0);   }   vecpp conv(vecpp a) {    pt left = { 99999999999999,999999999999999 };    forin(i, a) {     if (a[i].x < left.x || a[i].x == left.x && a[i].y > left.y) {      left = a[i];     }    }    o = left;    forin(i, a) {     if (a[i] == left) {      a[i] = a.back();      a.pop_back();      br     }    }    sort(all(a), comp);    vecpp conv(1, left);    forin(i, a) {     while (conv.size() > 1) {      if ((a[i] - conv.back()) * (conv.back() - conv[conv.size() - 2]) <= 0) {       conv.pop_back();      }      else {       br      }     }     conv.push_back(a[i]);    }    while (conv.size() > 1) {     if ((left - conv.back()) * (conv.back() - conv[conv.size() - 2]) <= 0) {      conv.pop_back();     }     else {      br     }    }    return conv;   }         int main() {    ios::sync_with_stdio(0);    cin.tie(0);    defn defm     veci a(n);    intov(a,n)    vector<veci> primer(100000);    vector<veci> nekt(logn, veci(n+1, n));    fori(i, n) {     fort(j,2, 400) {      if (a[i] % j == 0) {       primer[j].push_back(i);       while (a[i] % j == 0) {        a[i] /= j;       }      }     }     if (a[i] > 1) {      primer[a[i]].push_back(i);     }    }    forin(i, primer) {     fori(j, ((int)primer[i].size())-1) {      min2(nekt[0][primer[i][j]], primer[i][j + 1]);     }    }    forib(i, n-1) {     min2(nekt[0][i], nekt[0][i+1]);     forn(j, logn) {      nekt[j][i] = nekt[j - 1][nekt[j - 1][i]];     }    }    fori(i, m) {     defa defb      int ans = 1;     a--;     int k = logn - 1;     while (k >= 0) {      if (nekt[k][a] < b) {       a = nekt[k][a];       ans += 1 << k;      }      else {       k--;      }     }     co ans el    }    ex   }


#include <bits/stdc++.h>   using namespace std;   int solve();   int main() { solve(); }   int solve() {     string s;     vector<int> cnt(26);     cin >> s;     int ncnt = 0;     for (int i = 0; i < s.size(); ++i) ++cnt[s[i] -  a ];     for (int i = 0; i < 26; ++i) ncnt += (cnt[i] & 1);     while (ncnt > 1) {       for (int i = 25; i >= 0; --i) {         for (int j = 0; j < i; ++j) {           if ((cnt[i] & 1) && (cnt[j] & 1)) {             ncnt -= 2;             ++cnt[j];             --cnt[i];             break;           }         }       }     }     for (int i = 0; i < 26; ++i) {       for (int j = 0; j < cnt[i] / 2; ++j) {         cout << (char)(i +  a );       }     }     if (ncnt) {       for (int i = 0; i < 26; ++i) {         if (cnt[i] & 1) cout << (char)(i +  a );       }     }     for (int i = 25; i >= 0; --i) {       for (int j = 0; j < cnt[i] / 2; ++j) {         cout << (char)(i +  a );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 333333;   const int INF = 2000000000;   int n, m, k, a[M];   inline int read() {     char c = getchar();     int ans = 0;     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 )       ans = (ans << 1) + (ans << 3) + (c ^ 48), c = getchar();     return ans;   }   int main() {     n = read(), m = read(), k = read();     for (int i = 1; i <= m; i++) a[i] = INF;     for (int i = 1, x, c; i <= n; i++) {       x = read(), c = read();       a[x] = min(a[x], c);     }     int ans = 0;     for (int i = 1; i <= m; i++) ans += a[i];     printf( %d , min(ans, k));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, ans;   string a;   int main() {     cin >> a;     ans = a.size();     long long t = 0;     for (int i = 0; i < a.size(); i++) {       if (a[i] ==  ) )         t--;       else         t++;       if (t < 0) {         t = 0;         ans--;       }     }     cout << ans - t << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int m, n;     cin >> n >> m;     if (n > 26)       cout << m;     else {       int a = 2;       for (int i = 2; i <= n; i++) a = a * 2;       cout << m % a;     }   }


#include <bits/stdc++.h>   using namespace std;   int ans[10000];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int n, k;     string s;     cin >> n >> k;     cin >> s;     int cnt = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] == s[i - 1]) {         cnt++;       } else {         ans[s[i - 1]] += cnt / k;         cnt = 1;       }     }     ans[s[s.size() - 1]] += cnt / k;     int mx = -1;     for (char i =  a ; i <=  z ; i++) {       mx = max(ans[i], mx);     }     cout << mx;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long k, na;   };   const long maxn = 100001;   node a[maxn];   long n, b[maxn];   int qsort(long low, long high) {     long i = low, j = high, x = a[(i + j) / 2].k;     while (i < j) {       while (a[i].k < x) i++;       while (a[j].k > x) j--;       if (i <= j) {         swap(a[i], a[j]);         i++;         j--;       }     }     if (i < high) qsort(i, high);     if (j > low) qsort(low, j);     return 0;   }   void init() {     cin >> n;     for (long i = 1; i <= n; i++) {       cin >> a[i].k;       a[i].na = i;     }     qsort(1, n);   }   void work() {     memset(b, 0, sizeof(b));     for (long i = 1; i <= n; i++) b[a[i].k] += 1;     int bj = 1;     for (long i = 2; i <= a[n].k; i++)       if (b[i] > b[i - 1]) bj = 0;     if (bj) {       cout << b[1] << endl;       long s = 0;       for (long i = 1; i <= n; i++) {         if ((i == 1) || (a[i].k == a[i - 1].k))           s++;         else           s = 1;         b[a[i].na] = s;       }       for (long i = 1; i <= n; i++) {         cout << b[i];         if (i != n) cout <<    ;       }       cout << endl;     } else       cout << -1 << endl;   }   int main() {     init();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, w[1000999];   int arr[1009999];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &w[i]);       arr[w[i]]++;     }     for (int i = 0; i < 1000099; i++) {       arr[i + 1] += arr[i] / 2;       arr[i] = arr[i] % 2;     }     int ans = 0;     for (int i = 0; i < 1000099; i++) {       if (arr[i] >= 1) {         ans++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 500 + 5;   const int mod = 26;   long long qp(long long a, long long n) {     long long res = 1;     while (n > 0) {       if (n & 1) res = res * a % mod;       a = a * a % mod;       n >>= 1;     }     return res;   }   template <class T>   inline bool scan(T &ret) {     char c;     int sgn;     if (c = getchar(), c == EOF) return 0;     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     sgn = (c ==  - ) ? -1 : 1;     ret = (c ==  - ) ? 0 : (c -  0 );     while (c = getchar(), c >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     ret *= sgn;     return 1;   }   template <class T>   inline void out(T x) {     if (x > 9) out(x / 10);     putchar(x % 10 +  0 );   }   int n, m;   vector<pair<int, int> > mp[maxn];   int flag[maxn];   int res[maxn];   int main() {     scan(n), scan(m);     int x;     int flagt = 0, tmp = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         scan(x);         mp[i].emplace_back(x, j);       }       sort(mp[i].begin(), mp[i].end());       mp[i].erase(unique(mp[i].begin(), mp[i].end(),                          [](pair<int, int> &x, pair<int, int> &y) {                            return x.first == y.first;                          }),                   mp[i].end());       res[i] = mp[i][0].second;       if (mp[i].size() == 1) {         flag[i] = 1;         tmp ^= mp[i][0].first;       } else {         if (flagt == 0)           flagt = i;         else {           tmp ^= mp[i][0].first, flag[i] = 1;         }       }     }     for (int i = 0; i < mp[flagt].size(); ++i) {       if ((tmp ^ mp[flagt][i].first) != 0) {         res[flagt] = mp[flagt][i].second;         tmp ^= mp[flagt][i].first;         flagt = -1;         break;       }     }     if (flagt == -1 || (flagt == 0 && tmp)) {       puts( TAK );       for (int i = 1; i <= n; ++i) {         printf( %d  , res[i]);       }     } else {       puts( NIE );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 1, -1, 0};   int dy[] = {1, 0, 0, -1};   long double PI = 3.14159265358979323846264338327950;   pair<int, int> p[12000002];   int a[12000002], b[12000002];   int m, n, k;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> k;     for (int i = 1, x; i <= n; i++) {       cin >> x;       a[x]++;       if (a[x] > k) {         cout << -1;         return 0;       }     }     for (int i = 1, x; i <= m; i++) {       cin >> x;       p[i] = {x, i};     }     sort(p + 1, p + 1 + m);     int ch = 0;     int res = 0;     for (int i = 1; i <= m; i++) {       for (; a[ch] == k; ch++)         ;       if (ch > p[i].first)         continue;       else {         res++;         b[res] = p[i].second, a[ch]++;       }     }     cout << res <<   n ;     for (int i = 1; i <= res; i++) cout << b[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[111];   int id[111][111];   int vis[111];   int main() {     int n, m, k, q;     while (cin >> n >> k) {       m = n / k;       for (int i = 0; i < n; i++) {         cin >> a[i];         vis[i] = 0;       }       scanf( %d , &q);       double minv = 1 << 30, maxv = -1 << 30;       for (int i = 0; i < q; i++) {         int sum = 0;         for (int j = 0; j < m; j++) {           cin >> id[i][j];           vis[id[i][j] - 1] = 1;           sum += a[id[i][j] - 1];         }         if (double(sum) / m < minv) {           minv = double(sum) / m;         }         if (double(sum) / m > maxv) {           maxv = double(sum) / m;         }       }       vector<int> v;       for (int i = 0; i < n; i++) {         if (!vis[i]) {           v.push_back(a[i]);         }       }       sort(v.begin(), v.end());       if (v.size() >= m && (n - v.size()) < k * m) {         int sum = 0;         for (int i = 0; i < m; i++) {           sum += v[i];         }         if (double(sum) / m < minv) {           minv = double(sum) / m;         }         if (double(sum) / m > maxv) {           maxv = double(sum) / m;         }         reverse(v.begin(), v.end());         sum = 0;         for (int i = 0; i < m; i++) {           sum += v[i];         }         if (double(sum) / m < minv) {           minv = double(sum) / m;         }         if (double(sum) / m > maxv) {           maxv = double(sum) / m;         }       }       printf( %.9lf %.9lf n , minv, maxv);     }   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > vec1(312345), vec2(312346);   int g[123456], p[123456], t[123456];   int cons;   int h, w;   int computeup(int i) {     int val1, val;     vector<int>::iterator it;     val1 = t[i] - p[i] + cons;     it = upper_bound(vec1[val1].begin(), vec1[val1].end(), p[i]);     val = vec2[val1].size();     int siz = vec1[val1].end() - it;     it--;     if (val <= siz) {       it += val;       cout << *it <<     << h << endl;     } else {       cout << w <<     << vec2[val1][siz] << endl;     }     return 0;   }   int computehor(int i) {     int val1, val;     vector<int>::iterator it;     val1 = t[i] - p[i] + cons;     it = upper_bound(vec2[val1].begin(), vec2[val1].end(), p[i]);     val = vec1[val1].size();     int siz = vec2[val1].end() - it;     it--;     if (val <= siz) {       it += val;       cout << w <<     << *it << endl;     } else {       cout << vec1[val1][siz] <<     << h << endl;     }     return 0;   }   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n >> w >> h;     cons = 100010;     int i;     for (i = 0; i < n; i++) {       cin >> g[i] >> p[i] >> t[i];       if (g[i] == 1)         vec1[t[i] - p[i] + cons].push_back(p[i]);       else         vec2[t[i] - p[i] + cons].push_back(p[i]);     }     for (i = 0; i < 212345; i++) {       sort(vec1[i].begin(), vec1[i].end());       sort(vec2[i].begin(), vec2[i].end());     }     for (i = 0; i < n; i++) {       if (g[i] == 1)         computeup(i);       else         computehor(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(long long int mid, long long int r, vector<long long int>& a) {     long long int d = 0;     long long int cnt = 0;     for (long long int i = a.size() - 1; i >= 0; i--) {       if (a[i] - d <= 0)         continue;       else {         if (cnt < mid) {           d += r;           cnt++;         } else           return false;       }     }     return true;   }   void solve() {     long long int n, r;     cin >> n >> r;     vector<long long int> a(n);     for (long long int i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     a.erase(unique(a.begin(), a.end()), a.end());     long long int tl = -1, tr = 1e9;     while (tr - tl > 1) {       long long int mid = (tl + tr) / 2;       if (check(mid, r, a))         tr = mid;       else         tl = mid;     }     cout << tr <<   n ;   }   signed main() {     long long int t;     cin >> t;     for (long long int i = 0; i < t; i++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[10], b[10];   vector<int> p;   bool square(int i, int j) {     double len = sqrt((a[j].first - a[i].first) * (a[j].first - a[i].first) +                       (a[j].second - a[i].second) * (a[j].second - a[i].second));     for (int t = i + 1; t <= j; t++) {       double tmp =           sqrt((a[t].first - a[t - 1].first) * (a[t].first - a[t - 1].first) +                (a[t].second - a[t - 1].second) * (a[t].second - a[t - 1].second));       if (abs(len - tmp) > 0.000000001) return 0;     }     if (len * len > 0.000000001) {       int x1 = a[i + 3].first - a[i].first, x2 = a[i + 1].first - a[i].first;       int y1 = a[i + 3].second - a[i].second, y2 = a[i + 1].second - a[i].second;       if (x1 * x2 + y1 * y2 == 0)         return 1;       else         return 0;     }   }   bool rect(int i, int j) {     double len1 =         sqrt((a[i].first - a[i + 1].first) * (a[i].first - a[i + 1].first) +              (a[i].second - a[i + 1].second) * (a[i].second - a[i + 1].second));     double len2 = sqrt((a[i + 2].first - a[i + 1].first) *                            (a[i + 2].first - a[i + 1].first) +                        (a[i + 2].second - a[i + 1].second) *                            (a[i + 2].second - a[i + 1].second));     double len3 = sqrt((a[i + 2].first - a[i + 3].first) *                            (a[i + 2].first - a[i + 3].first) +                        (a[i + 2].second - a[i + 3].second) *                            (a[i + 2].second - a[i + 3].second));     double len4 =         sqrt((a[i + 3].first - a[i].first) * (a[i + 3].first - a[i].first) +              (a[i + 3].second - a[i].second) * (a[i + 3].second - a[i].second));     if (abs(len1 - len3) > 0.000000001 || abs(len2 - len4) > 0.000000001)       return 0;     else {       int x1 = a[i + 3].first - a[i].first, x2 = a[i + 1].first - a[i].first;       int y1 = a[i + 3].second - a[i].second, y2 = a[i + 1].second - a[i].second;       if (x1 * x2 + y1 * y2 == 0)         return 1;       else         return 0;     }   }   bool check() {     if (!square(0, 3)) return 0;     if (!rect(4, 7)) return 0;     return 1;   }   int main() {     for (int i = 0; i < 8; i++) {       cin >> a[i].first >> a[i].second;       b[i] = a[i];       p.push_back(i);     }     while (true) {       if (check()) {         cout <<  YES n ;         for (int i = 0; i <= 3; i++) cout << p[i] + 1 <<    ;         cout << endl;         for (int i = 4; i <= 7; i++) cout << p[i] + 1 <<    ;         return 0;       }       if (!next_permutation(p.begin(), p.end())) break;       for (int i = 0; i <= 7; i++) a[i] = b[p[i]];     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long n, k;   long long p[200005];   long long md = 998244353;   long long binpow(long long a, long long b) {     if (b == 1) {       return a % md;     }     long long z = binpow(a, b / 2);     if (b & 1) {       return z * z % md * a % md;     }     return z * z % md;   }   long long C(long long n, long long m) {     return p[n] * binpow(p[m] * p[n - m] % md, md - 2) % md;   }   int main() {     p[0] = 1;     for (long long i = 1; i <= 200000; i++) {       p[i] = p[i - 1] * i % md;     }     cin >> n >> k;     if (k >= n) {       cout << 0;       return 0;     }     long long c = n - k;     long long ans = 0;     long long x = 1;     for (long long i = c; i >= 0; i--) {       if (x == -1) {         ans = (ans + md - C(c, i) * binpow(i, n) % md) % md;         x = 1;       } else {         ans = (ans + C(c, i) * binpow(i, n) % md) % md;         x = -1;       }     }     ans = ans * C(n, c) % md;     if (k > 0) ans = ans * 2 % md;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int dp[2][4004];   struct node {     int st;     int cost;   } save[4004];   int n, k;   void checkmin(int &a, int b) {     if (a == -1 || a > b) a = b;   }   int main() {     int i, j;     int ans;     while (~scanf( %d%d , &n, &k)) {       memset(dp, -1, sizeof(dp));       for (i = 1; i <= n; i++) {         scanf( %d%d , &save[i].st, &save[i].cost);         save[i].cost;       }       dp[0][0] = 1;       save[i].st = 86400 + 1;       ans = save[1].st - 1;       for (i = 1; i <= n; i++)         for (j = 0; j <= k && j <= i; j++) {           if (j == 0) {             if (dp[(i - 1) & 1][0] != -1) {               if (save[i].st > dp[(i - 1) & 1][0])                 dp[i & 1][0] = save[i].st + save[i].cost;               else                 dp[i & 1][0] = dp[(i - 1) & 1][0] + save[i].cost;             }             if (dp[i & 1][0] != -1) ans = max(ans, save[i + 1].st - dp[i & 1][0]);           } else {             if (dp[(i - 1) & 1][j - 1] != -1)               dp[i & 1][j] = dp[(i - 1) & 1][j - 1];             if (dp[(i - 1) & 1][j] != -1) {               if (save[i].st > dp[(i - 1) & 1][j])                 checkmin(dp[i & 1][j], save[i].st + save[i].cost);               else                 checkmin(dp[i & 1][j], dp[(i - 1) & 1][j] + save[i].cost);             }             if (dp[i & 1][j] != -1) ans = max(ans, save[i + 1].st - dp[i & 1][j]);           }         }       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char** mat;   short ***sparse, ***rem;   void build() {     sparse = new short**[n + 1];     rem = new short**[n + 1];     for (int i = 0; i <= n; ++i) {       sparse[i] = new short*[m + 1];       rem[i] = new short*[m + 1];     }     for (int i = 0; i <= n; ++i) {       for (int j = 0; j <= m; ++j) {         sparse[i][j] = new short[4];         memset(sparse[i][j], 0, sizeof(short) * 4);         rem[i][j] = new short[4];         memset(rem[i][j], 0, sizeof(short) * 4);       }     }     for (int i = 1; i <= n; ++i) {       int prev = 0;       for (int j = 1; j <= m; ++j) {         if (mat[i][j]) {           sparse[i][j][0] = prev;           prev = j;         }       }       prev = 0;       for (int j = m; j > 0; --j) {         if (mat[i][j]) {           sparse[i][j][1] = prev;           prev = j;         }       }     }     for (int j = 1; j <= m; ++j) {       int prev = 0;       for (int i = 1; i <= n; ++i) {         if (mat[i][j]) {           sparse[i][j][2] = prev;           prev = i;         }       }       prev = 0;       for (int i = n; i > 0; --i) {         if (mat[i][j]) {           sparse[i][j][3] = prev;           prev = i;         }       }     }   }   void remove(int p, int q) {     int prox, prev;     prox = sparse[p][q][0];     prev = sparse[p][q][1];     if (prev) sparse[p][prev][0] = prox;     if (prox) sparse[p][prox][1] = prev;     rem[p][q][0] = prox;     prox = sparse[p][q][1];     prev = sparse[p][q][0];     if (prev) sparse[p][prev][1] = prox;     if (prox) sparse[p][prox][0] = prev;     rem[p][q][1] = prox;     prox = sparse[p][q][2];     prev = sparse[p][q][3];     if (prev) sparse[prev][q][2] = prox;     if (prox) sparse[prox][q][3] = prev;     rem[p][q][2] = prox;     prox = sparse[p][q][3];     prev = sparse[p][q][2];     if (prev) sparse[prev][q][3] = prox;     if (prox) sparse[prox][q][2] = prev;     rem[p][q][3] = prox;   }   void insert(int p, int q) {     int x;     x = rem[p][q][0];     if (x) sparse[p][x][1] = q;     x = rem[p][q][1];     if (x) sparse[p][x][0] = q;     x = rem[p][q][2];     if (x) sparse[x][q][3] = p;     x = rem[p][q][3];     if (x) sparse[x][q][2] = p;     for (int i = 0; i < 4; ++i) rem[p][q][i] = 0;   }   int solve(int p, int q) {     int tot = 0;     stack<pair<int, int> > s;     while (p and q) {       int prox, prev;       if (mat[p][q] ==  L ) {         prox = sparse[p][q][0];         if (p and q) remove(p, q);         if (p and q) s.push(make_pair(p, q));         q = prox;       } else if (mat[p][q] ==  R ) {         prox = sparse[p][q][1];         if (p and q) remove(p, q);         if (p and q) s.push(make_pair(p, q));         q = prox;       } else if (mat[p][q] ==  U ) {         prox = sparse[p][q][2];         if (p and q) remove(p, q);         if (p and q) s.push(make_pair(p, q));         p = prox;       } else {         prox = sparse[p][q][3];         if (p and q) remove(p, q);         if (p and q) s.push(make_pair(p, q));         p = prox;       }       tot++;     }     while (s.size()) {       pair<int, int> p = s.top();       s.pop();       insert(p.first, p.second);     }     return tot;   }   int main(int argc, char* argv[]) {     cin >> n >> m;     mat = new char*[n + 1];     for (int i = 0; i <= n; ++i) mat[i] = new char[m + 1];     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         cin >> mat[i][j];         if (mat[i][j] ==  . ) mat[i][j] = 0;       }     }     build();     int ans = 0, freq = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         int x = mat[i][j] ? solve(i, j) : 0;         if (x > ans) {           ans = x;           freq = 1;         } else if (x == ans)           freq++;       }     }     cout << ans <<     << freq << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int oriArr[2000001] = {0};   int arr[2000001];   int main() {     int oriCnt;     cin >> oriCnt;     int maxOri = 0;     for (int i = 0; i < oriCnt; i++) {       int tmp;       cin >> tmp;       oriArr[tmp] = 1;       if (maxOri < tmp) maxOri = tmp;     }     arr[0] = 0;     int cnt = 0;     for (int i = 1; i <= maxOri; i++) {       if (oriArr[i] == 0) {         arr[i] = arr[i - 1];       } else {         arr[i] = i;         cnt++;       }     }     if (cnt == 1) {       cout <<  0  << endl;       return 0;     }     int max = 0;     for (int i = maxOri - 1; i >= 0; i--) {       if (arr[i] < max) break;       if (oriArr[i] == 0) continue;       for (int j = 2; arr[i] * (j - 1) <= maxOri; j++) {         int tmp = j * arr[i] - 1;         if (tmp > maxOri) tmp = maxOri;         if (arr[tmp] % arr[i] > max) max = arr[tmp] % arr[i];       }     }     cout << max << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   long long ans, res;   int L[N], R[N];   int n, a[N];   long long dp[40][2];   void solve(int d, int l, int r) {     if (l >= r) return;     if (d == -1) return;     int nl = 0, nr = 0;     long long tmp1 = 0, tmp2 = 0;     ;     for (int i = l; i <= r; i++) {       if (a[i] >> d & 1)         L[++nl] = a[i], tmp1 += nr;       else         R[++nr] = a[i], tmp2 += nl;     }     dp[d][1] += tmp1;     dp[d][0] += tmp2;     int x = 1, y = 1;     for (int i = l; i <= r; i++) {       if (x <= nl)         a[i] = L[x++];       else         a[i] = R[y++];     }     solve(d - 1, l, l + nl - 1);     solve(d - 1, l + nl, r);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     solve(30, 1, n);     for (int i = 0; i <= 30; i++) {       if (dp[i][1] < dp[i][0])         ans += dp[i][1], res |= (1 << i);       else         ans += dp[i][0];     }     printf( %lld %lld n , ans, res);   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     std::ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     ;     long long CASE = 1;     while (CASE--) {       long long n;       cin >> n;       vector<std::pair<long long, long long> > c;       for (long long i = 0; i < n; ++i) {         long long x, y;         cin >> x >> y;         c.push_back({x, y});       }       double ans = 0;       for (long long i = 0; i < n; ++i) {         for (long long j = i + 1; j < n; ++j) {           double mx = INT_MIN, mn = INT_MAX;           for (long long k = 0; k < n; ++k) {             if (i == k || j == k) continue;             double area = (c[k].first * (c[i].second - c[j].second) +                            c[i].first * (c[j].second - c[k].second) +                            c[j].first * (c[k].second - c[i].second)) *                           0.5;             mx = max(mx, area);             mn = min(mn, area);           }           ans = max(ans, mx - mn);         }       }       cout << setprecision(10) << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string a;       cin >> a;       string b;       cin >> b;       string c = a;       int flag = 0;       int count = 0;       vector<int> ans;       int s = 1;       int e = n;       for (int i = n - 1; i >= 0; --i) {         char x;         if (flag == 0) {           x = a[s - 1];           ++s;         } else {           if (a[e - 1] ==  0 )             x =  1 ;           else             x =  0 ;           --e;         }         if (x != b[i]) {           ++count;           ans.push_back(i + 1);         } else {           count += 2;           ans.push_back(1);           ans.push_back(i + 1);         }         flag = 1 - flag;       }       cout << count <<    ;       for (auto it : ans) cout << it <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[310];   long long fac[310], rev[310];   bool mmp[310][310];   long long mod = (long long)1e9 + 7;   long long qmod(long long a, long long p) {     long long ret = 1;     while (p) {       if (p & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       p /= 2;     }     return ret;   }   void Init() {     fac[0] = 1;     for (int i = 1; i < 310; ++i) fac[i] = fac[i - 1] * i;     rev[0] = 1;     for (int i = 1; i < 310; ++i) rev[i] = qmod(fac[i], mod - 2);   }   long long C(int n, int m) { return fac[n] * rev[m] % mod * rev[n - m] % mod; }   bool isSqure(long long q) {     long long sq = (long long)sqrt(q);     return sq * sq == q;   }   void input() {     istream& in = cin;     in >> n;     for (int i = 1; i <= n; ++i) in >> a[i];   }   bool vis[310];   int dfs(int p) {     if (vis[p]) return 0;     vis[p] = 1;     int ret = 1;     for (int i = 1; i <= n; ++i) {       if (mmp[p][i]) {         ret += dfs(i);       }     }     return ret;   }   int num[310];   long long dp[310][310][310];   bool END[310];   void add(long long& a, long long b) {     a %= mod;     b %= mod;     a = (a + b) % mod;   }   int main() {     input();     Init();     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) {         if (isSqure(a[i] * a[j])) {           mmp[i][j] = mmp[j][i] = 1;         }       }     vector<int> block;     for (int i = 1; i <= n; ++i) {       int ret = dfs(i);       if (ret) block.push_back(ret);     }     sort(block.begin(), block.end());     reverse(block.begin(), block.end());     int sum = 0;     for (int p : block) {       for (int i = 1; i <= p; ++i) num[sum + i] = i;       sum += p;       END[sum] = 1;     }     dp[0][0][0] = 1;     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= n + 1; ++j)         for (int k = 0; k <= n + 1; ++k) {           long long& ref = dp[i - 1][j][k];           if (dp[i - 1][j][k] == 0) continue;           int allslot = i;           int prewa = j - k;           int nowwa = k;           int nookwaslot = (num[i] - 1) * 2 - 2 * nowwa;           int okslot = allslot - j - nookwaslot;           if (!END[i]) {             if (j > 0) add(dp[i][j - 1][k], dp[i - 1][j][k] * prewa);             add(dp[i][j + 1][k + 1], dp[i - 1][j][k] * nowwa);             add(dp[i][j][k], dp[i - 1][j][k] * okslot);             add(dp[i][j + 1][k + 1], dp[i - 1][j][k] * nookwaslot);           } else {             if (j > 0) add(dp[i][j - 1][0], dp[i - 1][j][k] * prewa);             add(dp[i][j + 1][0], dp[i - 1][j][k] * nowwa);             add(dp[i][j][0], dp[i - 1][j][k] * okslot);             add(dp[i][j + 1][0], dp[i - 1][j][k] * nookwaslot);           }         }     cout << dp[n][0][0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   struct par {     int x, t;     bool operator!=(par k) { return x != k.x || t != k.t; }   } p[N], p2[N];   int flag, n, sa[N], ea[N], sb[N], eb[N], _[N], _lans, _rans, key1[N], key2[N];   bool cmp(par x, par y) {     int kx = x.t == 1 ? sa[x.x] : ea[x.x];     int ky = y.t == 1 ? sa[y.x] : ea[y.x];     return kx * 2 + (1 ^ x.t) == ky * 2 + (1 ^ y.t)                ? x.x < y.x                : kx * 2 + (1 ^ x.t) < ky * 2 + (1 ^ y.t);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d%d%d%d , sa + i, ea + i, sb + i, eb + i);     for (int i = 1; i <= n; i++) _[i] = rand();     for (int i = 1; i <= 2 * n; i++) p[i] = (par){(i - 1) / 2 + 1, i & 1};     sort(p + 1, p + 1 + n + n, cmp);     _lans = _rans = 0;     for (int i = 1; i <= n; i++) _lans ^= _[i];     for (int i = 1; i <= 2 * n; i++) {       int x = p[i].x, t = p[i].t;       if (t) {         _lans ^= _[x];         key1[x] ^= _rans;       } else {         _rans ^= _[x];         key1[x] ^= _lans;       }     }     memcpy(p2, p, sizeof(p));     for (int i = 1; i <= n; i++) swap(sa[i], sb[i]), swap(ea[i], eb[i]);     for (int i = 1; i <= 2 * n; i++) p[i] = (par){(i - 1) / 2 + 1, i & 1};     sort(p + 1, p + 1 + n + n, cmp);     _lans = _rans = 0;     for (int i = 1; i <= n; i++) _lans ^= _[i];     for (int i = 1; i <= 2 * n; i++) {       int x = p[i].x, t = p[i].t;       if (t) {         _lans ^= _[x];         key2[x] ^= _rans;       } else {         _rans ^= _[x];         key2[x] ^= _lans;       }     }     for (int i = 1; i <= n; i++)       if (key1[i] != key2[i]) flag = 1;     puts(flag ?  NO  :  YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream &operator>>(istream &in, pair<T1, T2> &a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T amax(T &a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T &a, T1 b) {     if (b < a) a = b;     return a;   }   const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   const int N = 0;   void solve() {     unordered_map<char, int> m;     string s;     cin >> s;     int n = s.length();     for (int i = 0; i < n; i++) {       m[s[i]]++;     }     int left = 0;     for (auto x : m) {       if (x.second > 2) {         left = left + x.second - 2;       }     }     int j = n - left;     cout << j / 2 << endl;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int l, r, a;   int main() {     cin >> l >> r >> a;     if (l > r) swap(l, r);     if (l == r) return cout << (l + a / 2) * 2, 0;     if (l < r) {       if (l + a >= r) {         a -= abs(l - r), l = r;         cout << l * 2 + (a / 2) * 2;       } else         cout << (l + a) * 2;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[2003];   int depth[2003], root[2003];   int ans = 0, n;   void dfs(int x, int y) {     depth[x] = y;     for (int i = 0; i < v[x].size(); i++) {       dfs(v[x][i], y + 1);     }   }   int main() {     int i, j, a;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a;       if (a == -1)         root[i] = 1;       else         v[a].push_back(i);     }     for (i = 1; i <= n; i++) {       if (root[i]) dfs(i, 1);     }     for (i = 1; i <= n; i++) {       ans = max(ans, depth[i]);     }     cout << ans;     return 0;   }


#include <map>   #include <queue>   #include <cmath>   #include <vector>   #include <cstdio>   #include <cstring>   #include <algorithm>   #define itt map<int,int>::iterator    #define ll long long   #define ull unsigned long long    #define dd double   using namespace std;   const int maxn=5000,N1=maxn+5; const int inf=0x3f3f3f3f,p=998244353;      template <typename _T> void read(_T &ret)   {       ret=0; _T fh=1; char c=getchar();       while(c< 0 ||c> 9 ){ if(c== - ) fh=-1; c=getchar(); }       while(c>= 0 &&c<= 9 ){ ret=ret*10+c- 0 ; c=getchar(); }       ret=ret*fh;   }      int T,n,q;    int tag[N1];   ll f[2][N1] ,g[N1], s[N1];      int main()   {       scanf( %d ,&T);       while(T--){                  scanf( %d ,&n);       for(int i=1;i<=n;i++) read(tag[i]);;       for(int i=1;i<=n;i++) read(s[i]);       for(int i=1;i<=n;i++) f[0][i]=f[1][i]=g[i]=0;       int now=1, pst=0;       f[pst][1]=0;       for(int i=2;i<=n;i++)       {           for(int j=1;j<i;j++) f[now][j]=f[pst][j], g[j]=0;           for(int j=1;j<i;j++)            {               if(tag[i]==tag[j]) continue;               f[now][i]=max(f[now][i],f[pst][j]+abs(s[i]-s[j]));               if(j>1) g[j-1]=f[pst][j]+abs(s[i]-s[j]);           }           for(int j=i-1;j>=1;j--)           {               g[j]=max(g[j],g[j+1]);               if(tag[i]==tag[j]) continue;               f[now][j]=max(f[pst][j],g[j]+abs(s[i]-s[j]));           }           // for(int j=1;j<=i;j++) printf( %d  ,f[now][j]); puts(  );           swap(now,pst);       }       ll ans=0;       for(int i=1;i<=n;i++) ans=max(ans,f[pst][i]);       printf( %lld n ,ans);              }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, a;   int main() {     for (i = 1; i <= 5; i++) {       for (j = 1; j <= 5; j++) {         cin >> a;         if (a == 1) cout << (abs(3 - i) + abs(3 - j)) << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   signed long long p[1000005] = {0};   void sieve() {     p[0] = 1;     p[1] = 1;     for (signed long long i = 2; i * i <= 1000000; i++) {       if (p[i] == 0) {         for (signed long long j = 2 * i; j <= 1000000; j = j + i) p[j] = 1;       }     }   }   int main() {     signed long long n, m, wt;     cin >> n >> m;     sieve();     for (signed long long i = n - 1; i <= 1000000; i++) {       if (p[i] == 0) {         wt = i;         break;       }     }     cout << wt <<     << wt << endl;     ;     for (signed long long i = 1; i < n - 1; i++)       cout << i <<     << i + 1 <<                <<  1  << endl;     cout << n - 1 <<     << n <<     << wt - (n - 2) << endl;     signed long long cnt = n - 1;     for (signed long long i = 1; i <= n; i++) {       for (signed long long j = i + 2; j <= n; j++) {         if (cnt == m) return 0;         cout << i <<     << j <<     << wt + 5 << endl;         cnt++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long base, long long e) {     long long answer = 1;     while (e) {       if (e % 2 == 1) {         answer *= base;       }       base *= base;       e /= 2;     }     return answer;   }   int main() {     long long i, n, m, k, j;     cin >> n >> m;     string s[n];     for (i = 0; i < n; i++) {       cin >> s[i];     }     long long a[m];     for (i = 0; i < m; i++) {       cin >> a[i];     }     long long sum = 0;     for (i = 0; i < m; i++) {       long long f[5] = {0};       for (j = 0; j < n; j++) {         f[s[j][i] -  A ]++;       }       long long max = f[0];       for (j = 1; j < 5; j++) {         if (max <= f[j]) max = f[j];       }       sum += (max * a[i]);     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(int n) {     if (n <= 1) {       return false;     }     for (int i = 2; i < n; i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   vector<long long int> inisum;   long long int binary(long long int target) {     long long int end = inisum.size() - 1;     long long int start = 0;     long long int ans = -1;     while (start <= end) {       long long int mid = (start + end) / 2;       if (inisum[mid] <= target) {         start = mid + 1;       } else {         ans = mid;         end = mid - 1;       }     }     return ans;   }   bool isSum(long long int n) {     long long int sum = 0;     while (n != 0) {       sum += n % 10;       n /= 10;     }     if (sum == 10) {       return true;     } else {       return false;     }   }   int main(void) {     long long int t;     cin >> t;     while (t--) {       long long int x1, y1, z1;       long long int x2, y2, z2;       cin >> x1 >> y1 >> z1;       cin >> x2 >> y2 >> z2;       long long int count = 0;       if (z1 > y2) {         count += y2;         z1 -= y2;         y2 = 0;       } else {         count += z1;         y2 -= z1;         z1 = 0;       }       if (y1 > x2) {         y1 -= x2;         x2 = 0;       } else {         x2 -= y1;         y1 = 0;       }       if (y1 > y2) {         y1 -= y2;         y2 = 0;       } else {         y2 -= y1;         y1 = 0;       }       if (z1 > x2) {         z1 -= x2;         x2 = 0;       } else {         x2 -= z1;         z1 = 0;       }       if (z1 > y2) {         z1 -= y2;         y2 = 0;       } else {         y2 -= z1;         z1 = 0;       }       count -= min(y1, z2);       cout << count * 2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int a, b;     int c[4];     int minC = INT_MAX;     for (int i = 0; i < 4; i++) {       cin >> c[i];       if (minC > c[i]) minC = c[i];     }     cin >> a >> b;     int minXX = min(minC, b);     int ans = minXX - a;     bool baal = 0;     if (minXX != minC) baal = 1;     if (ans < 0)       cout << 0 << endl;     else if (a == b && minC > a)       cout << 1 << endl;     else if (baal == 1)       cout << ans + 1 << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   string s[1111];   int c[1111];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     int ans = 0;     for (int j = 0; j < m; j++) {       bool ret = false;       for (int i = 0; i < n - 1; i++)         if (s[i][j] > s[i + 1][j] && c[i] == 0) ret = true;       if (ret)         ans++;       else {         for (int i = 0; i < n - 1; i++)           if (s[i][j] < s[i + 1][j]) c[i] = 1;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   vector<pair<int, int> > dp(101);   int cntr[101] = {0};   int getIndexes(int &a, int &b, int &c, int &i, int &m, int x, int &xc, int &k) {     int res1 = 0;     int res2 = 0;     int f1 = 0, f2 = 0, j;     if (cntr[x] == 0) {       for (j = xc - m / 2; j <= xc + m / 2 + m % 2 - 1; j++)         res1 = res1 + (j > xc ? j - xc : xc - j) + i;       a = x;       b = dp[x].first = xc - m / 2;       c = dp[x].second = xc + m / 2 + m % 2 - 1;       return res1;     } else {       if (dp[x].first <= m) {         f1 = 1;         res1 = (1000 * 1000 * 1000 + 5);       } else {         for (j = dp[x].first - 1; j >= dp[x].first - m && j >= 1; j--)           res1 = res1 + (j > xc ? j - xc : xc - j) + i;       }       if (k - dp[x].second < m) {         f2 = 1;         res2 = (1000 * 1000 * 1000 + 5);       } else {         for (j = dp[x].second + 1; j <= dp[x].second + m && j <= k; j++)           res2 = res2 + (j > xc ? j - xc : xc - j) + i;       }       if (f1 == 1 && f2 == 1) return (1000 * 1000 * 1000 + 5);       if (res1 <= res2) {         a = x;         b = dp[x].first - m;         c = dp[x].first - 1;         return res1;       } else {         a = x;         b = dp[x].second + 1;         c = dp[x].second + m;         return res2;       }     }   }   int main() {     int n, k;     cin >> n >> k;     int xc = k / 2 + 1;     int yc = xc;     cntr[xc] = 0;     while (n--) {       int m, i;       cin >> m;       if (m > k) {         cout <<  -1  << endl;       } else {         int x, yl, yr;         int mfv = (1000 * 1000 * 1000 + 5);         for (i = 0; i < xc; i++) {           int a, b, c;           int mfu = (1000 * 1000 * 1000 + 5);           int mfd = (1000 * 1000 * 1000 + 5);           mfu = getIndexes(a, b, c, i, m, xc - i, xc, k);           if (mfv >= mfu) {             mfv = mfu;             x = a;             yl = b;             yr = c;           }           mfd = getIndexes(a, b, c, i, m, xc + i, xc, k);           if (mfv > mfd) {             mfv = mfd;             x = a;             yl = b;             yr = c;           }           if (cntr[xc - i] == 0 || cntr[xc + i] == 0) break;         }         if (mfv < (1000 * 1000 * 1000 + 5)) {           if (dp[x].first > yl || dp[x].first == 0) dp[x].first = yl;           if (dp[x].second < yr || dp[x].second == 0) dp[x].second = yr;           if (cntr[x] != 1) cntr[x] = 1;           cout << x <<     << yl <<     << yr << endl;         } else           cout <<  -1  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       string s;       cin >> n >> s;       int ans = 100;       for (int i = 0; i < n; i++) {         if (s[i] ==  > ) {           ans = min(ans, i);           break;         }       }       for (int i = n - 1; i >= 0; i--) {         if (s[i] ==  < ) {           ans = min(ans, n - i - 1);           break;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e4 + 7, M = 2e2 + 7;   bool fl[N];   int n, k, tot, fs[N], sum[N], pos[M], f[M][N];   map<int, bool> s[N];   struct edge {     int u, v;   } ed[N * M];   struct node {     int ch[M], num;   } qt[N];   inline int read() {     int num = 0;     char g = getchar();     while (g < 48 || 57 < g) g = getchar();     while (47 < g && g < 58)       num = (num << 1) + (num << 3) + g - 48, g = getchar();     return num;   }   inline int find(int u) {     if (fs[u] == u) return u;     return fs[u] = find(fs[u]);   }   inline bool equals(node a, node b) {     for (int i = 1; i <= k; i++)       if (a.ch[i] + 1 != b.ch[i]) return false;     return true;   }   inline bool cmp(node a, node b) {     for (int i = 1; i <= k; i++) {       if (a.ch[i] < b.ch[i]) return false;       if (a.ch[i] > b.ch[i]) return true;     }     return false;   }   int main() {     n = read(), k = read();     for (int i = 1; i <= k; i++)       for (int x = 1; x <= n; x++) f[i][x] = read();     for (int i = 1; i <= k; i++)       for (int x = 1; x <= n; x++)         if (!f[i][x]) pos[i] = x;     for (int i = 2; i <= k; i++) {       memset(sum, 0, sizeof(sum));       for (int c = 1; c <= n; c++)         if (f[i][c] + f[1][c] == f[1][pos[i]]) sum[f[1][c]] = c;       for (int c = 0; c <= f[1][pos[i]]; c++)         if (!sum[c]) {           puts( -1 );           return 0;         }       for (int c = 0; c < f[1][pos[i]]; c++)         if (!s[sum[c]][sum[c + 1]])           s[sum[c]][sum[c + 1]] = s[sum[c + 1]][sum[c]] = 1, ed[++tot].u = sum[c],                             ed[tot].v = sum[c + 1];     }     for (int i = 1; i <= n; i++) fs[i] = i;     for (int i = 1; i <= tot; i++) {       int a = ed[i].u, b = ed[i].v;       fl[a] = fl[b] = 1, fs[a] = find(a), fs[b] = find(b);       if (fs[a] == fs[b]) {         puts( -1 );         return 0;       }       fs[fs[a]] = find(b);     }     int tp = 1;     for (int x = 1; x <= n; x++) {       qt[x].num = x;       for (int i = 1; i <= k; i++) qt[x].ch[i] = f[i][x];     }     for (int i = 1; i <= k; i++) fl[pos[i]] = 1;     sort(qt + 1, qt + n + 1, cmp);     for (int i = 1; i <= n; i++) {       int c = qt[i].num;       if (fl[c]) continue;       while ((!equals(qt[tp], qt[i])) && tp <= n) tp++;       if (tp > n) {         puts( -1 );         return 0;       }       tot++, ed[tot].u = c, ed[tot].v = qt[tp].num;     }     for (int i = 1; i <= tot; i++) printf( %d %d n , ed[i].u, ed[i].v);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   const int INF = 1e9;   const long long MOD = 1e9 + 7;   const int N = 1e5 + 5, MO = 320, SQ = 600;   int n, q, A[N], QL[N], QR[N], P[N], T[N], C[N], K[N], Q[N];   vector<int> B, X, Y;   bool CMP(int i, int j) {     if (QL[i] / MO != QL[j] / MO) return QL[i] < QL[j];     return (QL[i] / MO) % 2 ? QR[i] < QR[j] : QR[i] > QR[j];   }   void Update(int x, int y) { T[C[x]]--, C[x] += y, T[C[x]]++; }   void Insert(int x, int y) {     if (x >= SQ && !K[x]) Y.push_back(x);     K[x] += y;   }   int Huf() {     X.clear(), Y.clear();     for (int i : B)       if (C[i] >= SQ) X.push_back(C[i]), K[C[i]]++;     sort(X.begin(), X.end());     int huf = 0, c = 0, x = 0, y = 0;     for (int i = 1; i < SQ; i++)       if (K[i] + T[i]) {         K[i] += T[i];         if (c) huf += i + c, K[i]--, Insert(i + c, 1), c = 0;         if (K[i] & 1) c = i, K[i]--;         if (K[i]) huf += i * K[i], Insert(i + i, K[i] >> 1), K[i] = 0;       }     while (x < (int)(X.size()) || y < (int)(Y.size())) {       while (x + 1 < (int)(X.size()) && X[x + 1] == X[x]) x++;       while (y + 1 < (int)(Y.size()) && Y[y + 1] == Y[y]) y++;       int i = 0;       if (x == (int)(X.size()))         i = Y[y++];       else if (y == (int)(Y.size()))         i = X[x++];       else if (X[x] < Y[y])         i = X[x++];       else         i = Y[y++];       if (c) huf += i + c, K[i]--, Insert(i + c, 1), c = 0;       if (K[i] & 1) c = i, K[i]--;       if (K[i]) huf += i * K[i], Insert(i + i, K[i] >> 1), K[i] = 0;     }     return huf;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     mt19937 Rnd(time(0));     cin >> n;     for (int i = 0; i < n; i++) cin >> A[i], C[A[i]]++;     for (int i = 0; i < N; i++)       if (C[i] >= SQ) B.push_back(i);     for (int i = 0; i < n; i++) C[A[i]]--;     cin >> q;     for (int i = 0; i < q; i++) cin >> QL[i] >> QR[i], QL[i]--, P[i] = i;     sort(P, P + q, CMP);     int L = 0, R = 0;     for (int i = 0; i < q; i++) {       int l = QL[P[i]], r = QR[P[i]];       while (l < L) Update(A[--L], +1);       while (R < r) Update(A[R++], +1);       while (L < l) Update(A[L++], -1);       while (r < R) Update(A[--R], -1);       Q[P[i]] = Huf();     }     for (int i = 0; i < q; i++) cout << Q[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const int prime = 9241;   const long double pi = acos(-1.);   int in[100005];   int masks[1000005];   bool used[1 << 22];   int main() {     int n, m, d;     scanf( %d%d%d , &n, &m, &d);     for (int i = 0; i < m; i++) {       int s;       scanf( %d , &s);       for (int j = 0; j < s; j++) {         int a;         scanf( %d , &a);         a--;         in[a] = i;       }     }     int cur[25] = {};     for (int i = 0; i < m; i++) cur[i] = 0;     for (int i = 0; i < d; i++) cur[in[i]]++;     int mcnt = 0;     masks[0] = 0;     for (int i = 0; i < m; i++)       if (cur[i] > 0) masks[0] |= 1 << i;     mcnt++;     for (int i = d; i < n; i++) {       cur[in[i - d]]--;       cur[in[i]]++;       masks[mcnt] = 0;       for (int j = 0; j < m; j++)         if (cur[j] > 0) masks[mcnt] |= 1 << j;       mcnt++;     }     queue<int> q;     for (int i = 0; i < (1 << m); i++) used[i] = 0;     for (int i = 0; i < mcnt; i++) {       q.push(masks[i]);       used[masks[i]] = 1;     }     while (!q.empty()) {       int cur = q.front();       q.pop();       for (int i = 0; i < m; i++) {         if (cur & (1 << i)) continue;         int nw = cur | (1 << i);         if (!used[nw]) {           used[nw] = 1;           q.push(nw);         }       }     }     int ans = 1000;     for (int i = 0; i < (1 << m); i++)       if (!used[i]) ans = min(ans, m - __builtin_popcount(i));     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int len = s.size();     int cnt = 0;     for (int i = 0; i < len; i++) {       if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  || s[i] ==  u )         cnt++;       if (s[i] ==  1  || s[i] ==  3  || s[i] ==  5  || s[i] ==  7  || s[i] ==  9 )         cnt++;     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long Labs(long long first) { return first < 0 ? -first : first; }   int main() {     long long n, d;     cin >> n >> d;     long long a[n];     for (int i = (0); i < (int)(n); i++) cin >> a[i];     long long ans = 0;     for (int i = (0); i < (int)(n); i++)       for (int j = (0); j < (int)(n); j++)         if (i != j && Labs(a[i] - a[j]) <= d) {           ++ans;         }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double inf = 1e18 + 7;   const long double eps = 1e-18;   long long gcd(long long a, long long b) {     while (a || b) a %= b, swap(a, b);     return a + b;   }   int main() {     ios_base::sync_with_stdio(0);     long long t;     cin >> t;     for (long long tt = 0; tt < t; ++tt) {       long long x, y, p, q;       cin >> x >> y >> p >> q;       long long ok = y - x;       long long wa = y - ok;       long long nok = q - p;       long long nwa = q - nok;       if (nok == nwa) {         cout << abs(ok - wa) << endl;         continue;       }       if (nok == 0) {         if (ok != 0) {           cout << -1 << endl;           continue;         } else {           cout << 0 << endl;           continue;         }       }       if (nwa == 0) {         if (wa != 0) {           cout << -1 << endl;           continue;         } else {           cout << 0 << endl;           continue;         }       }       if (nok < nwa) {         long long xx = ok + nok - 1;         xx /= nok;         xx *= nok;         long long l = -1;         long long r = 1e10;         while (l != r - 1) {           long long m = (l + r) / 2ll;           long long lx = xx + nok * m;           long long rx = lx / nok * nwa;           if (rx >= wa)             r = m;           else             l = m;         }         long long lx = xx + nok * r;         long long rx = lx / nok * nwa;         long long ans = lx - ok;         ans += rx - wa;         cout << ans << endl;       } else {         long long xx = wa + nwa - 1;         xx /= nwa;         xx *= nwa;         long long l = -1;         long long r = 1e10;         while (l != r - 1) {           long long m = (l + r) / 2;           long long lx = xx + m * nwa;           long long rx = lx / nwa * nok;           if (rx >= ok)             r = m;           else             l = m;         }         long long lx = xx + r * nwa;         long long rx = lx / nwa * nok;         long long ans = (lx - wa) + (rx - ok);         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[30000001];   int main() {     int n, a;     cin >> a >> n;     long long sum = 0, limit = n + a + 1;     memset((x), 0, sizeof(x));     for (long long i = 1; i * i < limit; i++)       for (long long j = i * i; j < limit; j += i * i) x[j] = i * i;     for (int i = a, j = 0; i < a + n; i++, j++) sum += (a + j) / x[i];     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, a, b;       cin >> n >> a >> b;       string s, ans;       for (long long i = 0; i < b; i++) {         long long m =  a ;         char c = m + i;         s += c;       }       for (long long i = 0; i < (n / b); i++) {         ans += s;       }       long long m = ans.length();       for (long long i = 0; i < n - m; i++) {         ans += s[i];       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long t, v;     cin >> t >> v;     long long a[t];     for (int i = 0; i < t; i++) cin >> a[i];     long long minx = 0;     sort(a, a + t);     for (int z = 0; z < t - 1; z++) {       minx = max(a[z + 1] - a[z], minx);     }     long long diff = max(a[0] - 0, v - a[t - 1]);     double re;     re = max(double(diff), double(minx) / 2.0);     cout << setprecision(10) << fixed << re;   }


//-->FIVAR_RoX   #include <bits/stdc++.h>   #include <vector>   #include <set>   #include <string>   #include <queue>   #define lli long long int   #define ld long double   //loops   #define dfloop(count1,count2,count3) for(lli i=count1;i>count2;i+=count3)   #define floop(count1,count2,count3) for(lli i=count1;i<count2;i+=count3)   #define floop1(count1,count2,count3) for(lli j=count1;j<count2;j+=count3)   #define vfloop(count1,count2,count3,i) for(lli i=count1;i<count2;i+=count3)   #define dvfloop(count1,count2,count3,i) for(lli i=count1;i>count2;i+=count3)   //outputs   #define qwe(x) cout<<x<<endl;   #define qw(x) cout<<x<<    ;   //for inputs   #define in(x) lli x; cin>>x;   #define make(a,x) lli a[x]; floop(0,x,1) cin>>a[i];   #define make1(a,x,y) lli a[x][y]; floop(0,x,1) floop1(0,y,1) cin>>a[i][j];   //for pairs   #define mkp make_pair   #define fst first   #define scd second   //vectors   #define pb push_back   //sets   #define sloop(s,i) for(auto i=s.begin();i!=s.end();i++)      using namespace std;   lli sum(lli* a,lli n){       lli s=0;       while(n--){           s+=a[n];    }       return s;   }   void print_Vector(vector<lli> Vec)    {        for (lli i = 0; i < Vec.size(); i++) {            cout << Vec[i] <<    ;        }        cout << endl;        return;    }    lli min_array(lli* a,lli n){       lli maxi=INT_MAX;       for (int i=0;i<n;i++){           if (maxi>a[i]) maxi=a[i];       }       return maxi;   }      void print_array(lli* a,lli n)   {       for (int i=0;i<n;i++){           cout<<a[i]<<   ;       }       cout<<endl;   }      void answer_fin(){       in(n)       lli k=n/2,k1,m1;       lli m=n-k;       k1=k+1;       m1=m+1;       lli ans;       if(n&1){           ans=k1*m1*2;       }       else ans=k1*m1;       qwe(ans)   }      int main()   {       lli test=1;      // cin>>test;       while(test--)       answer_fin();   }


#include <bits/stdc++.h>   using namespace std;   bool sieve[100000 + 5];   vector<long long> primes;   int inf[100000 + 5];   vector<vector<int> > g;   vector<vector<int> > h;   vector<int> rab;   vector<int> rtb;   vector<int> res;   void rec(int id, int del) {     if (id == rab.size()) {       res.push_back(del);       return;     }     int cum = 1;     for (int i = 0; i <= rab[id]; i++) {       rec(id + 1, del * cum);       cum *= rtb[id];     }   }   void gen1(int i) {     res.clear();     rab = g[i];     rtb = h[i];     rec(0, 1);   }   void fill() {     int san;     int cnt;     for (int i = 2; i < 100000 + 1; i++) {       san = i;       for (int j = 0; primes[j] <= san; j++) {         cnt = 0;         while (san % primes[j] == 0) {           san /= primes[j];           cnt++;         }         if (cnt > 0) {           g[i].push_back(cnt);           h[i].push_back(primes[j]);         }         if (san == 0) break;         if (sieve[san]) {           g[i].push_back(1);           h[i].push_back(san);           break;         }       }     }   }   void oku() {     memset(sieve, true, sizeof sieve);     g.assign(100000 + 1, vector<int>(0));     h.assign(100000 + 1, vector<int>(0));     sieve[1] = sieve[0] = false;     for (long long i = 2; i * i <= 100000; i++)       if (sieve[i])         for (long long j = i * i; j <= 100000; j += i) sieve[j] = false;     int cnt = 0;     for (int i = 0; i < 100000; i++)       if (sieve[i]) primes.push_back(i);     fill();     int n, x, y, id;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       gen1(x);       id = i + 1 - y;       cnt = 0;       for (int j = 0; j < int((res).size()); j++) {         if (inf[res[j]] < id) cnt++;         inf[res[j]] = i + 1;       }       printf( %d n , cnt);     }   }   int main() {     oku();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int INF = 1e9;   const long long INF64 = 9e18;   const long double EPS = 1e-9;   const long double PI = 3.14159265358979310000;   const long long MD = 1248742437;   const long long T = 378531;   const int N = 1200001;   const int M = 501;   int n, k, a[N];   int main() {     cin >> n >> k;     if (n / k < 3) {       cout << -1;       return 0;     }     int j = 1;     for (int i = 1; i <= k * 2; i++) {       a[i] = j;       j++;       if (j > k) j = 1;     }     j = k;     for (int i = k * 2 + 1; i <= n; i++) {       a[i] = j;       j--;       if (j == 0) j = k;     }     swap(a[k / 2], a[k / 2 + 1]);     for (int i = 1; i <= n; i++) printf( %d  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     bool watched[1000001];     cin >> n;     while (cin >> x) watched[x] = true;     for (int i = 1; i <= n; i++)       if (!watched[i]) cout << i;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tab[205];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> V;       for (int i = 0; i < n; i++) {         int x;         cin >> x;         tab[x] = 1;         V.push_back(x);       }       vector<int> V2;       bool b = 1;       for (int i : V) {         b = 0;         for (int j = i + 1; j <= 2 * n; j++) {           if (tab[j] == 0) {             tab[j] = 1;             b = 1;             V2.push_back(j);             break;           }         }         if (!b) {           break;         }       }       if (!b) {         cout <<  -1 n ;       } else {         for (int i = 0; i < n; i++) {           cout << min(V[i], V2[i]) <<     << max(V[i], V2[i]) <<    ;         }         cout <<   n ;       }       for (int i = 0; i <= 2 * n; i++) {         tab[i] = 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     t = 1;     while (t--) {       long long int n, m;       cin >> n >> m;       long long int arr[n];       string arr2[m];       for (long long int i = 0; i < n; i++) {         cin >> arr[i];       }       map<string, int> mp;       for (long long int i = 0; i < m; i++) {         cin >> arr2[i];         if (mp.find(arr2[i]) != mp.end()) {           std::map<string, int>::iterator it = mp.find(arr2[i]);           it->second++;         } else {           mp.insert({arr2[i], 1});         }       }       sort(arr, arr + n);       vector<long long int> freq;       for (auto &it : mp) {         freq.push_back(it.second);       }       sort(freq.begin(), freq.end(), greater<long long int>());       long long int ans = 0;       long long int ans2 = 0;       for (long long int i = 0; i < freq.size(); i++) {         ans += freq[i] * arr[i];         ans2 += freq[i] * arr[n - i - 1];       }       cout << ans <<     << ans2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 10;   const int maxn = 5e5 + 10;   int N, M;   struct edge {     int v, u, l, r;     edge() {}     edge(int v_, int u_, int l_, int r_) : v(v_), u(u_), l(l_), r(r_) {}     bool operator>(const edge& rhs) const { return l > rhs.l; }   };   priority_queue<edge, vector<edge>, greater<edge>> q;   vector<edge> adj[maxn][2];   int last[maxn][2];   void relax(int v, int start, int end) {     last[v][start & 1] = max(last[v][start & 1], end);     for (auto& e : adj[v][start & 1]) {       edge t = e;       t.l = start;       q.push(t);     }     adj[v][start & 1].clear();   }   int main() {     scanf( %d %d , &N, &M);     for (int i = 1; i <= M; ++i) {       int v, u, l, r;       scanf( %d %d %d %d , &v, &u, &l, &r);       --r;       q.push(edge(v, u, l, ((l & 1) == (r & 1) ? r : r - 1)));       q.push(edge(u, v, l, ((l & 1) == (r & 1) ? r : r - 1)));       q.push(edge(v, u, l + 1, (((l + 1) & 1) == (r & 1) ? r : r - 1)));       q.push(edge(u, v, l + 1, (((l + 1) & 1) == (r & 1) ? r : r - 1)));     }     if (N == 1) {       printf( 0 n );       return 0;     }     for (int i = 1; i <= N; ++i)       for (int j = 0; j < 2; ++j) last[i][j] = -1;     last[1][0] = 0;     while (!q.empty()) {       edge e = q.top();       q.pop();       if (e.l <= e.r) {         if (last[e.v][e.l & 1] >= e.l) {           if (e.u == N) {             printf( %d n , e.l + 1);             return 0;           }           relax(e.u, e.l + 1, e.r + 1);         } else {           adj[e.v][e.l & 1].push_back(e);         }       }     }     printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, A, B, x, y;     while (cin >> x >> y >> A >> B) {       int Count = 0;       for (i = A; i <= x; i++) {         for (j = B; j <= y; j++) {           if (i > j) {             Count++;           }         }       }       cout << Count << endl;       for (i = A; i <= x; i++) {         for (j = B; j <= y; j++) {           if (i > j) {             cout << i <<     << j << endl;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000000];   pair<int, int> b[1000000];   int ord[1000000];   int main() {     int n, k;     cin >> n >> k;     long long m;     cin >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i];       b[i] = make_pair(a[i], i);     }     sort(b + 1, b + n, greater<pair<int, int> >());     b[n].first = 0;     long long sum = 0;     for (int i = 1; i < n; i++) {       if (i < k) sum += b[i].first;       ord[b[i].second] = i;     }     int num = k - 1;     for (int i = 1; i < n; i++) {       long long s = sum;       if (ord[i] <= num) {         s -= b[ord[i]].first;         s += b[k].first;       }       if (m - s < a[i]) {         cout << i << endl;         return 0;       }     }     cout << n << endl;   }


#include <bits/stdc++.h>   using namespace std;   void rom(long long W) {     long long pot = 1LL;     char val[20] =  IVXLCDM ;     long long w = 0LL, z, i;     while (pot <= W) {       pot *= 10LL;       w++;     }     pot /= 10LL;     w--;     while (pot) {       z = W / pot;       if (z == 4)         printf( %c%c , val[w * 2], val[w * 2 + 1]);       else if (z == 9)         printf( %c%c , val[w * 2], val[w * 2 + 2]);       else {         if (z >= 5) {           printf( %c , val[w * 2 + 1]);           z -= 5;         }         for (i = 0; i < z; i++) printf( %c , val[w * 2]);       }       W -= W / pot * pot;       pot /= 10LL;       w--;     }     printf(  n );   }   void nice(long long W, long long B) {     if (W == 0LL) cout << 0;     long long pot = 1LL;     char val[300];     int i, j;     for (i = 0, j =  0 ; j <=  9 ; i++, j++) val[i] = j;     for (j =  A ; j <=  Z ; i++, j++) val[i] = j;     while (pot <= W) {       pot *= B;     }     pot /= B;     while (pot) {       printf( %c , val[W / pot]);       W -= (W / pot) * pot;       pot /= B;     }     printf(  n );   }   int main() {     long long a;     char b[10000], c[10000];     long long w, pot, i, j;     long long val[300];     memset(val, 0, sizeof(val));     for (i =  0 , j = 0; i <=  9 ; i++, j++) {       val[i] = j;     }     for (i =  A ; i <=  Z ; i++, j++) {       val[i] = j;     }     cin >> a;     scanf( %s%s , b, c);     w = 0LL;     pot = 1LL;     for (i = strlen(c) - 1; i >= 0; i--, pot *= a) {       w += (val[c[i]]) * pot;     }     if (b[0] ==  R )       rom(w);     else {       int q;       sscanf(b,  %d , &q);       nice(w, 0LL + q);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a = 0;     cin >> a;     int z = 0, e = 0;     char b;     for (int i = 0; i < a; i++) {       cin >> b;       if (b ==  D ) z++;       if (b ==  A ) e++;     }     if (e == z)       cout <<  Friendship ;     else if (e < z)       cout <<  Danik ;     else if (e > z)       cout <<  Anton ;   }


#include <bits/stdc++.h>   using namespace std;   bool good(long long int a, long long int b) {     while (a and b) {       if (a % 2 == 0 and b % 2 == 1) return false;       a /= 2;       b /= 2;     }     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<pair<long long int, long long int>> s(n);     for (int i = 0; i < n; i++) cin >> s[i].first;     for (int i = 0; i < n; i++) cin >> s[i].second;     sort(s.rbegin(), s.rend());     vector<bool> used(n, false);     int nb = 0;     long long int knw = 0;     long long int ans = 0;     for (int i = 1; i < n; i++) {       if (s[i].first == s[i - 1].first) {         knw |= s[i].first;         if (!used[i]) {           nb++;           ans += s[i].second;           used[i] = true;         }         if (!used[i - 1]) {           nb++;           ans += s[i - 1].second;           used[i - 1] = true;         }       }     }     for (int i = 0; i < n; i++) {       if (used[i]) continue;       for (int j = 0; j < n; j++) {         if (used[j] and (s[i].first | s[j].first) == s[j].first) {           ans += s[i].second;           nb++;           used[i] = true;           break;         }       }     }     if (nb < 2) ans = 0;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   deque<int> q;   int main() {     int n;     while (~scanf( %d , &n)) {       q.clear();       for (int i = 1; i <= n; i++) q.push_back(i);       for (int i = 2; i <= n; i++) {         int k = ((n - 1) / i) * i;         int tmp = q[k];         for (int j = k; j >= i; j -= i) q[j] = q[j - i];         q[0] = tmp;         q.push_back(q.front());         q.pop_front();       }       int sz = q.size();       for (int i = 0; i < sz; i++)         if (i == 0)           printf( %d , q[i]);         else           printf(  %d , q[i]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void setIO(string str, bool dbg) {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(nullptr);     if (!dbg) {       freopen((str +  .in ).c_str(),  r , stdin);       freopen((str +  .out ).c_str(),  w , stdout);     }   }   const int MAX = 5e3 + 5;   const int LEN = 2e3 + 5;   const int LVL = 2e1 + 0;   const long long int MOD = 1e9 + 7;   const long long int INF = 2e9;   int xyz = 1;   int n, q;   int pld[MAX][MAX];   int dps[MAX][MAX];   void fnc() {     string str;     cin >> str;     n = str.length();     for (int i = 0; i < n; i++) pld[i][i] = 1;     for (int i = 1; i < n; i++) {       for (int j = 0; j + i < n; j++) {         int l = j;         int r = i + j;         pld[l][r] = str[l] == str[r] ? pld[l + 1][r - 1] || r - l == 1 : 0;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j + i < n; j++) {         int l = j;         int r = i + j;         dps[l][r] = pld[l][r] + dps[l + 1][r] + dps[l][r - 1] - dps[l + 1][r - 1];       }     }     cin >> q;     for (int i = 0; i < q; i++) {       int l;       int r;       cin >> l >> r;       cout << dps[l - 1][r - 1] <<   n ;     }   }   int main() {     setIO(  , 1);     while (xyz--) fnc();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, i, j, k, n;     cin >> t;     while (t--) {       cin >> n;       long long int ans = 0;       int i = 0;       while (n) {         ans += n;         n = n / 2;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 998244353;   long long gcd(long long a, long long b) {     long long c;     while (a != 0) {       c = a;       a = b % a;       b = c;     }     return b;   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long N;     cin >> N;     vector<long long> A(N);     long long res = 1;     for (long long i = 0; i < N; i++) {       cin >> A[i];     }     map<long long, long long> mp;     map<long long, long long> num;     vector<long long> C;     set<long long> st;     for (long long i = 0; i < N; i++) {       long long X = pow(A[i], 0.25);       X = max((long long)0, X - 3);       while (X * X * X * X < A[i]) X++;       if (X * X * X * X == A[i]) {         mp[X] += 4;         st.insert(X);         continue;       }       X = pow(A[i], 1.0 / 3);       X = max((long long)0, X - 3);       while (X * X * X < A[i]) X++;       if (X * X * X == A[i]) {         mp[X] += 3;         st.insert(X);         continue;       }       X = sqrt(A[i]);       X = max((long long)0, X - 3);       while (X * X < A[i]) X++;       if (X * X == A[i]) {         mp[X] += 2;         st.insert(X);         continue;       }       num[A[i]]++;       if (num[A[i]] == 1) {         C.push_back(A[i]);       }     }     vector<long long> V(C.size(), 0);     for (long long i = 0; i < C.size(); i++) {       for (long long j = i + 1; j < C.size(); j++) {         long long a = gcd(C[i], C[j]);         if (a != 1) {           st.insert(a);           st.insert(C[i] / a);           st.insert(C[j] / a);         }       }     }     vector<long long> sv;     for (auto s : st) {       sv.push_back(s);     }     for (long long i = 0; i < C.size(); i++) {       bool ok = true;       for (long long j = 0; j < sv.size(); j++) {         if (C[i] % sv[j] == 0) {           mp[sv[j]] += num[C[i]];           mp[C[i] / sv[j]] += num[C[i]];           ok = false;           break;         }       }       if (ok) {         long long t = num[C[i]] + 1;         res = (res * t * t) % MOD;       }     }     for (auto m : mp) {       res = (res * (m.second + 1)) % MOD;     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a, b;   int main() {     while (cin >> a >> b) {       if (b % 2 == 0)         cout << a * b / 2 << endl;       else         cout << a * (b / 2) + a / 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e6 + 5;   const int MAXN = 7e6 + 5;   const long long INF = 0x3f3f3f3f3f3f3f3f;   int n, q, s, first[MAX], nextt[MAXN], u[MAXN], v[MAXN], cnt;   long long w[MAXN];   void add(int a, int b, long long c) {     u[cnt] = a, v[cnt] = b, w[cnt] = c;     nextt[cnt] = first[u[cnt]];     first[u[cnt]] = cnt;     ++cnt;   }   void build_tree_one(int p, int l, int r) {     if (l == r) {       add(p + 4 * n, l, 0);       return;     }     int mid = (l + r) >> 1;     add(p + 4 * n, (p << 1) + 4 * n, 0);     add(p + 4 * n, (p << 1 | 1) + 4 * n, 0);     build_tree_one(p << 1, l, mid);     build_tree_one(p << 1 | 1, mid + 1, r);   }   void build_tree_two(int p, int l, int r) {     if (l == r) {       add(l, p + 8 * n, 0);       return;     }     int mid = (l + r) >> 1;     add((p << 1) + 8 * n, p + 8 * n, 0);     add((p << 1 | 1) + 8 * n, p + 8 * n, 0);     build_tree_two(p << 1, l, mid);     build_tree_two(p << 1 | 1, mid + 1, r);   }   void add_tree_one(int p, int l, int r, int x, int y, int dot,                     long long length) {     if (r < x || l > y) return;     if (l >= x && r <= y) {       add(dot, p + 4 * n, length);       return;     }     int mid = (l + r) >> 1;     add_tree_one(p << 1, l, mid, x, y, dot, length);     add_tree_one(p << 1 | 1, mid + 1, r, x, y, dot, length);   }   void add_tree_two(int p, int l, int r, int x, int y, int dot,                     long long length) {     if (r < x || l > y) return;     if (l >= x && r <= y) {       add(p + 8 * n, dot, length);       return;     }     int mid = (l + r) >> 1;     add_tree_two(p << 1, l, mid, x, y, dot, length);     add_tree_two(p << 1 | 1, mid + 1, r, x, y, dot, length);   }   long long dis[MAX];   bool vis[MAX];   struct point {     int dot;     long long length;   };   bool operator<(point a, point b) { return a.length > b.length; }   void dijkstra() {     priority_queue<point> list1;     dis[s] = 0;     list1.push({s, 0});     while (!list1.empty()) {       point now = list1.top();       list1.pop();       if (vis[now.dot]) continue;       vis[now.dot] = true;       for (int num = first[now.dot]; num != -1; num = nextt[num]) {         if (dis[v[num]] > dis[now.dot] + w[num]) {           dis[v[num]] = dis[now.dot] + w[num];           list1.push({v[num], dis[v[num]]});         }       }     }   }   void solve() {     while (~scanf( %d%d%d , &n, &q, &s)) {       cnt = 0;       for (int i = 0; i < MAX; ++i) first[i] = -1, dis[i] = INF, vis[i] = false;       build_tree_one(1, 1, n);       build_tree_two(1, 1, n);       for (int i = 1; i <= q; ++i) {         int op;         scanf( %d , &op);         if (op == 1) {           int a, b;           long long c;           scanf( %d%d%lld , &a, &b, &c);           add(a, b, c);         } else if (op == 2) {           int a, l, r;           long long c;           scanf( %d%d%d%lld , &a, &l, &r, &c);           add_tree_one(1, 1, n, l, r, a, c);         } else {           int a, l, r;           long long c;           scanf( %d%d%d%lld , &a, &l, &r, &c);           add_tree_two(1, 1, n, l, r, a, c);         }       }       dijkstra();       for (int i = 1; i <= n; ++i)         printf( %lld%c , dis[i] == INF ? -1 : dis[i], i == n ?   n  :    );     }   }   int main(void) {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long q, n;   string h;   int main() {     ios::sync_with_stdio(NULL);     cin.tie(0);     cout.tie(0);     cin >> q;     while (q--) {       cin >> n;       if (n == 1) {         cout <<  a n ;         continue;       }       for (long long i = 1; i <= n / 2; i++) cout <<  a ;       cout << ((n % 2 == 0) ?  b  :  bc );       for (long long i = 1; i <= n / 2 - 1; i++) cout <<  a ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long double mem[50 + 5][50 + 5][50 + 5];   long double fact[55];   vector<int> num;   int n, p, L;   long double dp(int sum, int idx, int cnt, int last) {     if (sum > p || cnt > L) {       return 0;     }     if (idx == n) {       return (sum + num[last] > p && cnt + 1 == L);     }     long double &ret = mem[sum][idx][cnt];     if (ret == ret) {       return ret;     }     ret = 0;     if (idx != last) ret += dp(sum + num[idx], idx + 1, cnt + 1, last);     ret += dp(sum, idx + 1, cnt, last);     return ret;   }   void solve() {     long double ans = 0;     fact[0] = 1;     for (int i = 1; i <= 50; i++) {       fact[i] = fact[i - 1] * i;     }     for (int i = 2; i <= n; i++) {       for (int j = 0; j < n; j++) {         memset(mem, -1, sizeof(mem));         L = i;         long double ret = dp(0, 0, 0, j);         if (ret) ans += (fact[i - 1] * fact[n - i] / fact[n] * ret * (i - 1));       }     }     int sum = 0;     for (int i = 0; i < n; i++) {       sum += num[i];     }     if (ans == 0 && sum <= p) ans = n;     cout << ans << endl;   }   int main() {     int a;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       num.push_back(a);     }     cin >> p;     solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[4];     cin >> arr[0] >> arr[1] >> arr[2] >> arr[3];     sort(arr, arr + 4);     if ((arr[0] + arr[3]) == (arr[1] + arr[2]) ||         (arr[0] + arr[1] + arr[2]) == arr[3]) {       cout <<  YES  <<   n ;     } else {       cout <<  NO  <<   n ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   bool check(string& a, string& b) {     if (a.size() != b.size()) return false;     int ind1 = -1, ind2 = -1;     bool check = false;     bool buck[26] = {0};     int count = 0;     for (int i = 0; i < a.size(); i++) {       if (a[i] != b[i]) {         count++;         if (count > 2) return false;         if (ind1 == -1)           ind1 = i;         else           ind2 = i;       } else {         if (buck[a[i] -  a ])           check = true;         else           buck[a[i] -  a ] = true;       }     }     if (count == 1) return false;     if (count == 0) {       return check;     }     return (a[ind1] == b[ind2]) && (a[ind2] == b[ind1]);   }   int main() {     string a, b;     cin >> a;     cin >> b;     if (check(a, b))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t = 1;     while (t--) {       string s;       cin >> s;       sort(s.begin(), s.end());       long long n = s.size(), ans = 0;       long long l = 0, r = n - 1;       while (l <= r) {         long long m = l + (r - l) / 2;         if (s[m] == s[n - 1]) {           if (s[m - 1] != s[n - 1] || m == 0) {             ans = m;             break;           } else             r = m - 1;         } else {           l = m + 1;         }       }       cout << s.substr(ans) << endl;     }   }


#include <bits/stdc++.h>   const int maxn = 1011;   const int mod = 256;   char str[maxn];   int main() {     gets(str);     int len = strlen(str);     int sad = 0;     for (int i = 0; i < len; i++) {       int a[11] = {0}, j = 0, temp = 0;       int c = str[i];       while (c) {         a[j++] = c % 2;         c /= 2;       }       for (int j = 7, k = 1; j >= 0; j--, k *= 2) {         temp += a[j] * k;       }       int res = (sad - temp + mod) % mod;       printf( %d n , res);       sad = temp;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int a[maxn], m, n, ans, dp[maxn];   inline bool check(int x) {     memset(dp, 0, sizeof(dp));     for (int sta = 0; sta <= 1 && sta < n; sta++) {       dp[sta] = sta ? max(a[0] + x, a[1]) : a[0];       for (int i = sta + 1; i < n; i++) {         dp[i] = dp[i - 1];         if (dp[i - 1] >= a[i] - 1) dp[i] = max(dp[i], a[i] + x);         if (dp[i - 1] >= a[i] - x - 1) dp[i] = max(dp[i], a[i]);         if (dp[i - 2] >= a[i] - x - 1 && i >= 2) dp[i] = max(dp[i], a[i - 1] + x);       }       if (dp[n - 1] >= min(m - 1, m + a[sta] - x - 1)) return 1;     }     return 0;   }   int main() {     scanf( %d%d , &m, &n);     for (int i = 0; i < n; i++) scanf( %d , a + i);     sort(a, a + n);     pair<int, int> pos(a[0] + m - a[n - 1], 0);     for (int i = 1; i < n; i++) {       pos = max(pos, make_pair(a[i] - a[i - 1], i));     }     rotate(a, a + pos.second, a + n);     for (int i = n - 1; i >= 0; i--) {       a[i] -= a[0];       if (a[i] < 0) {         a[i] += m;       }     }     int l = 0, r = a[0] - a[n - 1] + m - 1, ans = r;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid)) {         ans = mid, r = mid - 1;       } else         l = mid + 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, k;     cin >> n >> k;     vector<int> a(n + 1);     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     int u = 0, v = 1;     vector<vector<double>> d[2];     d[u].assign(n + 1, vector<double>(n + 1));     for (int i = 1; i <= n; ++i) {       for (int j = i + 1; j <= n; ++j) {         if (a[i] < a[j]) {           d[u][i][j] = 1.0;         } else {           d[u][j][i] = 1.0;         }       }     }     double p = 2.0 / (n * (n + 1));     for (; k--; swap(u, v)) {       d[v].assign(n + 1, vector<double>(n + 1));       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= n; ++j) {           if (i == j) {             continue;           }           for (int x = 1; x <= n; ++x) {             for (int y = x; y <= n; ++y) {               int ni = i;               if (x <= i && i <= y) {                 ni = x + y - i;               }               int nj = j;               if (x <= j && j <= y) {                 nj = x + y - j;               }               d[v][ni][nj] += d[u][i][j] * p;             }           }         }       }     }     double ans = 0.0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j < i; ++j) {         ans += d[u][i][j];       }     }     cout << ans << endl;   }   void init() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f(int, int);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m, k;     cin >> n >> m >> k;     int a[m + 1];     int c[m];     int b = 0;     for (int i = 0; i < m; i++) {       c[i] = 0;     }     for (int i = 0; i <= m; i++) {       cin >> a[i];     }     for (int i = 0; i < m; i++) {       for (int j = 1; j <= n; j++) {         if (f(a[i], j) != f(a[m], j)) c[i]++;       }       if (c[i] <= k) b++;     }     cout << b;     return (0);   }   int f(int q, int w) {     int e = q;     for (int i = 1; i < w; i++) {       e = e / 2;     }     return (e % 2);   }