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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int maxn = 1 << 23; n char s[55][55]; n int p[55], r[55], d[55], h[55], ans = 0; n int f[maxn], g[maxn], bit[maxn]; n int ff(int x) { n   if (p[x] != x) p[x] = ff(p[x]); n   return p[x]; n } n void funion(int x, int y) { n   x = ff(x); n   y = ff(y); n   if (x != y) p[y] = x; n } n int main() { n   int n, m, i, j; n   scanf( %d , &n); n   for (i = 0; i < n; i++) scanf(  %s , s[i]); n   for (i = 0; i < n; i++) p[i] = i; n   for (i = 0; i < n; i++) { n     for (j = 0; j < n; j++) { n       if (i == j) continue; n       if (s[i][j] ==  A ) funion(i, j); n     } n   } n   for (i = 0; i < n; i++) d[ff(i)]++; n   memset(h, -1, sizeof(h)); n   for (i = m = 0; i < n; i++) { n     if (d[i] > 1) h[i] = m++; n   } n   for (i = 0; i < n; i++) { n     for (j = 0; j < n; j++) { n       if (i == j) continue; n       if (s[i][j] ==  X ) { n         if (ff(i) == ff(j)) { n           return puts( -1 ), 0; n         } n         if (d[ff(i)] > 1 && d[ff(j)] > 1) { n           r[h[ff(i)]] |= 1 << h[ff(j)]; n           r[h[ff(j)]] |= 1 << h[ff(i)]; n         } n       } n     } n   } n   if (!m) { n     printf( %d n , n - 1); n     return 0; n   } n   for (i = 0; i < m; i++) r[i] ^= (1 << m) - 1; n   for (i = 0; i < (1 << m); i++) { n     if ((i & (-i)) == i) n       f[i] = 1; n     else { n       j = i ^ (1 << (__builtin_ffs(i) - 1)); n       if (f[j] && (r[__builtin_ffs(i) - 1] & j) == j) f[i] = 1; n     } n     g[i] = 1; n     bit[i] = (m - __builtin_popcount(i)) & 1; n   } n   for (i = 0; i < m; i++) { n     for (j = 0; j < (1 << m); j++) { n       if ((j >> i) & 1) f[j] += f[j ^ (1 << i)]; n     } n   } n   for (i = 0; i < m; i++) { n     for (j = 0; j < (1 << m); j++) g[j] *= f[j]; n     int x = 0; n     for (j = 0; j < (1 << m); j++) { n       if (bit[j]) n         x -= g[j]; n       else n         x += g[j]; n     } n     if (x) break; n   } n   printf( %d n , n + i); n   return 0; n } n


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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