#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:33554432 )   using namespace std;   const double PI = 2 * acos(0.0);   const double EPS = 1e-8;   const int INF = (1 << 30) - 1;   int n;   string s;   vector<int> p;   set<int> ans;   void add01(char c1, char c2, int a, int b) {     for (int i = 0; i < a; ++i) s[p[i]] = c1;     for (int i = 0; i < b; ++i) s[p[a + i]] = c2;   }   int getans() {     int i = n - 1;     while (s[i] !=  0 ) --i;     int j = n - 1;     while (s[j] !=  1 ) --j;     if (i < j)       return 1;     else       return 2;   }   void printbin(int n) { cout << n / 2 << n % 2 << endl; }   int main() {     cin >> s;     if ((int)((s).size()) % 2 == 1) s =  0  + s;     n = (int)((s).size());     int cnt = 0, cnt1 = 0, cnt0 = 0;     for (int i = 0; i < n; ++i)       if (s[i] ==  ? ) {         ++cnt;         p.push_back(i);       } else if (s[i] ==  1 )         ++cnt1;       else if (s[i] ==  0 )         ++cnt0;     if (cnt0 >= cnt1 + cnt + 2) {       cout <<  00 ;       return 0;     }     if (cnt1 >= cnt0 + cnt + 2) {       cout <<  11 ;       return 0;     }     if (cnt0 + cnt >= cnt1 + 2) ans.insert(0);     if (cnt1 + cnt >= cnt0 + 2) ans.insert(3);     add01( 0 ,  1 , n / 2 - cnt0, n / 2 - cnt1);     ans.insert(getans());     add01( 1 ,  0 , n / 2 - cnt1, n / 2 - cnt0);     ans.insert(getans());     for (set<int>::iterator i = ans.begin(); i != ans.end(); ++i) printbin(*i);     return 0;   };


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2 * 100000 + 10;   int _min(int a, int b) {     if (a < b)       return a;     else       return b;   }   int _max(int a, int b) {     if (a > b)       return a;     else       return b;   }   char s[1005];   int col[4] = {0};   int row[4] = {0};   int main() {     scanf( %s , s);     int len = strlen(s);     for (int i = 0; i < len; i++) {       if (s[i] ==  0 ) {         for (int j = 0; j < 4; j++) {           if (col[j] == 0) {             col[j] = 1;             printf( %d %d n , 1, j + 1);             break;           }         }       } else {         for (int j = 0; j < 4; j++) {           if (row[j] == 0) {             row[j] = 1;             if (j == 0) printf( 3 1 n );             if (j == 1) printf( 3 3 n );             if (j == 2) printf( 4 1 n );             if (j == 3) printf( 4 3 n );             break;           }         }       }       int flag = 0;       for (int j = 0; j < 4; j++) {         if (col[j] == 0) {           flag = 1;           break;         }       }       if (flag == 0) {         for (int j = 0; j < 4; j++) col[j] = 0;       }       if (row[0] == 1 && row[1] == 1) {         row[0] = 0;         row[1] = 0;       }       if (row[2] == 1 && row[3] == 1) {         row[2] = 0;         row[3] = 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, v, t, p, cnt1, cnt2, x;   vector<pair<int, int>> k, c;   vector<int> ans;   void add(bool sm) {     v--;     if (sm) {       x += k[cnt1].first;       ans.push_back(k[cnt1++].second);     } else {       x += c[cnt2].first;       ans.push_back(c[cnt2++].second);       v--;     }   }   void solve() {     cin >> n >> v;     for (int i = 0; i < n; ++i) {       cin >> t >> p;       t--;       if (t) {         c.push_back({p, i + 1});       } else {         k.push_back({p, i + 1});       }     }     sort(k.begin(), k.end());     sort(c.begin(), c.end());     reverse(k.begin(), k.end());     reverse(c.begin(), c.end());     while ((v >= 1 && cnt1 < k.size()) || (v >= 2 && cnt2 < c.size())) {       add((cnt2 == c.size() || v == 1) || (k[cnt1].first > c[cnt2].first) ||           (cnt1 < k.size() - 1 &&            k[cnt1].first + k[cnt1 + 1].first > c[cnt2].first));     }     cout << x << endl;     for (int i = 0; i < ans.size(); ++i) {       cout << ans[i] <<    ;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     map<long long int, long long int> mpp;     long long int n;     cin >> n;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       mpp[__builtin_popcount(x)]++;     }     long long int ans = 0;     for (auto p : mpp) {       ans += (p.second) * (p.second - 1) / 2;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int N, T, K;   int a[200333];   int lo[200333], hi[200333];   int mid[200333];   int main() {     scanf( %d%d%d , &N, &T, &K);     for (int i = 1; i <= T; i++) scanf( %d , &a[i]);     K = N - K - 1;     for (int t = 1; t < T; t++) hi[t] = min(a[t], a[t + 1]);     for (int t = 1; t < T; t++) lo[t] = 1;     int hiSum = 0;     for (int t = 1; t < T; t++) hiSum += hi[t];     int loSum = 0;     for (int t = 1; t < T; t++) loSum += lo[t];     bool possible = loSum <= K && K <= hiSum;     if (!possible) {       puts( -1 );       exit(0);     }     for (int t = 1; t <= T; t++) {       mid[t] = lo[t];       K -= lo[t];     }     for (int t = 1; K; t++) {       int val = min(K, hi[t] - mid[t]);       K -= val;       mid[t] += val;     }     printf( %d n , N);     for (int v = 2; v <= 1 + a[1]; v++) printf( %d %d n , 1, v);     int uStart = 2;     for (int t = 1; t < T; t++) {       int u = uStart;       int upCnt = mid[t] - 1;       for (int v = uStart + a[t]; v < uStart + a[t] + a[t + 1]; v++) {         printf( %d %d n , u, v);         if (upCnt) {           upCnt--;           u++;         }       }       uStart = uStart + a[t];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1005;   int parent[2 * M];   vector<pair<pair<int, int>, pair<int, int> > > edges;   void init() {     for (int i = 0; i < 2 * M; i++) parent[i] = i;   }   int find(int u) {     if (u == parent[u]) return u;     return parent[u] = find(parent[u]);   }   void un(int u, int v) {     u = find(u);     v = find(v);     parent[u] = v;   }   int main() {     int n, m, q;     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i <= m; i++) {       int a, b, c;       scanf( %d %d %d , &a, &b, &c);       edges.push_back(make_pair(make_pair(c, i), make_pair(a, b)));     }     sort(edges.begin(), edges.end(),          greater<pair<pair<int, int>, pair<int, int> > >());     while (q--) {       int l, r;       scanf( %d %d , &l, &r);       int ans = -1;       init();       for (int i = 0; i < edges.size(); i++) {         int c = edges[i].first.first;         int id = edges[i].first.second;         int u = edges[i].second.first;         int v = edges[i].second.second;         if (id < l || id > r) continue;         if (find(u) == find(v)) {           ans = c;           break;         }         un(u, v + n);         un(u + n, v);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double inf = 1e13;   const double eps = 1e-9;   int Sgn(double k) { return fabs(k) < eps ? 0 : (k < 0 ? -1 : 1); }   int Cmp(double k1, double k2) { return Sgn(k1 - k2); }   struct Point {     double x, y;   };   Point operator-(Point k1, Point k2) {     return (Point){k1.x - k2.x, k1.y - k2.y};   }   Point operator+(Point k1, Point k2) {     return (Point){k1.x + k2.x, k1.y + k2.y};   }   double operator*(Point k1, Point k2) { return k1.x * k2.x + k1.y * k2.y; }   double operator^(Point k1, Point k2) { return k1.x * k2.y - k1.y * k2.x; }   Point operator*(Point k1, double k2) { return (Point){k1.x * k2, k1.y * k2}; }   Point operator/(Point k1, double k2) { return (Point){k1.x / k2, k1.y / k2}; }   double GetLen(Point k) { return sqrt(k * k); }   double GetDisPointToPoint(Point k1, Point k2) {     return sqrt((k2 - k1) * (k2 - k1));   }   Point Rotate(Point k, double ang) {     return (Point){k.x * cos(ang) - k.y * sin(ang),                    k.x * sin(ang) + k.y * cos(ang)};   }   Point Rotate90(Point k) { return (Point){-k.y, k.x}; }   struct Circle {     Point o;     double r;   };   bool IsInside(Circle k1, Circle k2) {     double dis = GetDisPointToPoint(k1.o, k2.o);     if (Cmp(k1.r - k2.r, dis) >= 0 || Cmp(k2.r - k1.r, dis) >= 0) return true;     return false;   }   bool IsOutside(Circle k1, Circle k2) {     double dis = GetDisPointToPoint(k1.o, k2.o);     if (Cmp(dis, k1.r + k2.r) > 0) return true;     return false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cout << fixed << setprecision(10);     Point s, t;     cin >> s.x >> s.y >> t.x >> t.y;     int n;     cin >> n;     vector<Circle> c(n);     for (auto &it : c) cin >> it.o.x >> it.o.y >> it.r;     Point mid_point = (s + t) / 2.0;     Point dir = Rotate90(t - s) / GetLen(t - s);     double dis_div2 = GetDisPointToPoint(s, mid_point);     bool ans_flag = true;     for (auto &it : c) {       Circle cur = (Circle){mid_point, dis_div2};       if (!IsInside(cur, it) && !IsOutside(cur, it)) {         ans_flag = false;         break;       }     }     if (ans_flag) {       cout << dis_div2 << endl;       return 0;     }     vector<pair<double, double>> record;     for (auto &it : c) {       bool dir_flag;       if (Sgn((it.o - mid_point) * dir) > 0)         dir_flag = true;       else         dir_flag = false;       double inside_record, outside_record;       Circle binary_search_cur;       int binary_search_cnt = 0;       double binary_search_left = -inf, binary_search_right = inf;       while (Cmp(binary_search_left, binary_search_right) &&              binary_search_cnt++ < 100) {         double binary_search_mid =             (binary_search_left + binary_search_right) / 2.0;         binary_search_cur.o = dir * binary_search_mid + mid_point;         binary_search_cur.r =             sqrt(binary_search_mid * binary_search_mid + dis_div2 * dis_div2);         if (IsInside(binary_search_cur, it)) {           inside_record = binary_search_mid;           if (dir_flag)             binary_search_right = binary_search_mid;           else             binary_search_left = binary_search_mid;         } else {           if (dir_flag)             binary_search_left = binary_search_mid;           else             binary_search_right = binary_search_mid;         }       }       binary_search_cnt = 0;       binary_search_left = -inf, binary_search_right = inf;       while (Cmp(binary_search_left, binary_search_right) &&              binary_search_cnt++ < 100) {         double binary_search_mid =             (binary_search_left + binary_search_right) / 2.0;         binary_search_cur.o = dir * binary_search_mid + mid_point;         binary_search_cur.r =             sqrt(binary_search_mid * binary_search_mid + dis_div2 * dis_div2);         if (IsOutside(binary_search_cur, it)) {           outside_record = binary_search_mid;           if (dir_flag)             binary_search_left = binary_search_mid;           else             binary_search_right = binary_search_mid;         } else {           if (dir_flag)             binary_search_right = binary_search_mid;           else             binary_search_left = binary_search_mid;         }       }       if (Cmp(inside_record, outside_record) > 0)         swap(inside_record, outside_record);       record.push_back(make_pair(inside_record, outside_record));     }     sort(record.begin(), record.end(),          [&](pair<double, double> k1, pair<double, double> k2) {            return Cmp(k1.first, k2.first) < 0;          });     double ans = Cmp(-record[0].first, 0.0) > 0 ? -record[0].first : 0.0;     double fi = record[0].first, se = record[0].second;     for (int i = 1; i < record.size(); ++i) {       if (Cmp(se, record[i].first) < 0) {         if (Cmp(ans, fabs(se)) > 0) ans = fabs(se);         if (Cmp(ans, fabs(record[i].first)) > 0) ans = fabs(record[i].first);         fi = record[i].first;       }       if (Cmp(record[i].second, se) > 0) se = record[i].second;     }     if (Cmp(ans, fabs(se)) > 0) ans = fabs(se);     cout << sqrt(ans * ans + dis_div2 * dis_div2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   long long Pot(long long a, long long b) {     if (b == 0) return 1;     if (b % 2 == 0) {       long long x = Pot(a, b / 2);       return x * x % MOD;     } else       return Pot(a, b - 1) * a % MOD;   }   long long Inv(long long x) { return Pot(x, MOD - 2); }   int main() {     ios_base::sync_with_stdio(0);     string s;     long long n, k;     cin >> s >> k;     n = s.size();     long long odp = 0;     for (long long i = 0; i < n; ++i) {       if (s[i] ==  0  || s[i] ==  5 ) {         long long pot1 = Pot(2, n * k) - 1;         if (pot1 < 0) pot1 += MOD;         long long pot2 = Pot(2, n) - 1;         if (pot2 < 0) pot2 += MOD;         long long il = Pot(2, i) * pot1 % MOD;         il = (il * Inv(pot2)) % MOD;         odp = (odp + il) % MOD;       }     }     cout << odp;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, i, j;   int main() {     ios::sync_with_stdio(false);     cin >> n;     cout << 3 * n / 2 <<   n ;     for (i = 2; i <= n; i += 2) cout << i <<    ;     for (i = 1; i <= n; i += 2) cout << i <<    ;     for (i = 2; i <= n; i += 2) cout << i <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gi() {     char cc = getchar();     int cn = 0, flus = 1;     while (cc <  0  || cc >  9 ) {       if (cc ==  - ) flus = -flus;       cc = getchar();     }     while (cc >=  0  && cc <=  9 ) cn = cn * 10 + cc -  0 , cc = getchar();     return cn * flus;   }   const int N = 2e5 + 5;   struct E {     int to, next;   } e[N << 1];   int n, cnt, A, B, head[N];   void add(int x, int y) {     e[++cnt] = (E){y, head[x]}, head[x] = cnt, e[++cnt] = (E){x, head[y]},     head[y] = cnt;   }   void Dfs(int x, int fa, int dep) {     (dep ^ 1) ? ++A : ++B;     for (register int i = head[x]; i; i = e[i].next)       if (e[i].to ^ fa) Dfs(e[i].to, x, dep ^ 1);   }   signed main() {     n = gi();     int x, y;     for (register int i = (2); i <= (n); ++i) x = gi(), y = gi(), add(x, y);     Dfs(1, 1, 0);     cout << min(A, B) - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static char a[55][55];   bool vis[55][55];   bool dfs(int i, int j, int px, int py, int n, int m) {     bool flag = false;     if (i > n || j > m) return false;     if (i == 0 || j == 0) return false;     vis[i][j] = 1;     int xi[] = {1, 0, -1, 0};     int yi[] = {0, -1, 0, 1};     for (int k = 0; k < 4; k++) {       int x = xi[k] + i;       int y = yi[k] + j;       if (x == px && y == py) continue;       if (a[x][y] == a[i][j]) {         if (vis[x][y]) {           return true;         } else           flag = dfs(x, y, i, j, n, m);         if (flag) {           return true;         }       }     }     return false;   }   int main() {     int n, m;     char ch;     scanf( %d%d , &n, &m);     memset(a,  . , sizeof(a));     for (int i = 1; i <= n; i++) {       scanf( %c , &ch);       for (int j = 1; j <= m; j++) {         scanf( %c , &a[i][j]);       }     }     memset(vis, 0, sizeof(vis));     bool flag = false;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (vis[i][j] == true)           continue;         else           flag = dfs(i, j, 0, 0, n, m);         if (flag) break;       }       if (flag) break;     }     if (flag)       printf( Yes );     else       printf( No );   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   string tos(T a) {     stringstream ss;     string ret;     ss << a;     ss >> ret;     return ret;   }   int n, a;   vector<int> arr;   int main() {     while (cin >> n) {       arr.clear();       for (int(i) = (0); (i) < (n); (i)++) {         cin >> a;         arr.push_back(a);       }       int boro = *max_element((arr).begin(), (arr).end());       if (boro == 1) {         sort(arr.begin(), arr.end());         arr[arr.size() - 1] = 2;       } else {         for (int(i) = (0); (i) < (n); (i)++) {           if (arr[i] == boro) {             arr[i] = 1;             break;           }         }         sort(arr.begin(), arr.end());       }       for (int(i) = (0); (i) < (n); (i)++) {         if (i) cout <<    ;         cout << arr[i];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 105000;   int n, m;   int tin[MAXN], tout[MAXN];   vector<int> g[MAXN];   vector<int> gr[MAXN];   vector<int> gg[MAXN];   vector<int> vv;   bool used[MAXN];   int sz[MAXN];   int cursize;   int p[MAXN];   bool has[MAXN];   int ans;   void dfs(int v) {     used[v] = true;     for (int i = 0; i < (int)g[v].size(); i++) {       int to = g[v][i];       if (!used[to]) dfs(to);     }     vv.push_back(v);   }   void dfs2(int v, int par) {     used[v] = true;     p[v] = par;     sz[par]++;     for (int i = 0; i < (int)gr[v].size(); i++) {       int to = gr[v][i];       if (!used[to]) dfs2(to, par);     }   }   void dfs3(int v) {     used[v] = true;     has[v] = true;     for (int i = 0; i < (int)gg[v].size(); i++) {       int to = gg[v][i];       if (!used[to]) dfs3(to);     }   }   void dfs4(int v) {     used[v] = true;     cursize++;     for (int i = 0; i < (int)gg[v].size(); i++) {       int to = gg[v][i];       if (!used[to]) dfs4(to);     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       int from, to;       scanf( %d %d , &from, &to);       g[from].push_back(to);       gr[to].push_back(from);       gg[from].push_back(to);       gg[to].push_back(from);     }     for (int i = 1; i <= n; i++) {       if (!used[i]) {         dfs(i);       }     }     memset(used, 0, sizeof(used));     for (int i = 1; i <= n; i++) {       int cur = vv[n - i];       if (!used[cur]) {         dfs2(cur, cur);         if (sz[cur] > 1) {           has[cur] = true;         }       }     }     memset(used, 0, sizeof(used));     for (int i = 1; i <= n; i++)       if (!used[i] && has[i]) {         dfs3(i);       }     memset(used, 0, sizeof(used));     for (int i = 1; i <= n; i++) {       if (!used[i]) {         cursize = 0;         dfs4(i);         if (has[i])           ans += cursize;         else           ans += cursize - 1;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long n = s.size() / 2 + s.size() % 2;     long long x = n;     cout << s[x - 1];     for (long long t = 1; t <= 100; t++) {       if (x + t - 1 < s.size()) cout << s[x + t - 1];       if (x - t - 1 >= 0) cout << s[x - t - 1];     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimization( unroll-loops )   using namespace std;   template <typename T>   ostream& operator<<(ostream& out, vector<T>& a) {     for (auto& p : a) out << p <<    ;     return out;   }   template <typename T>   istream& operator>>(istream& inp, vector<T>& a) {     for (auto& p : a) inp >> p;     return inp;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cout.precision(20);     srand((signed)time(NULL));     long long n = 0, ans = 0;     cin >> n;     vector<pair<long long, long long>> arr(n);     for (auto& p : arr) cin >> p.first >> p.second;     map<long long, long long> gx, gy;     for (long long i = 0; i < n; i++) {       ans += gx[arr[i].first] + gy[arr[i].second];       gx[arr[i].first]++, gy[arr[i].second]++;     }     map<pair<long long, long long>, long long> gg;     for (long long i = 0; i < n; i++) gg[arr[i]]++;     for (auto& p : gg) ans -= p.second * (p.second - 1) / 2;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace math {   template <typename T>   T gcd(T a, T b) {     if (a < 0) a = -a;     if (b < 0) b = -b;     while (b > 0) {       T r = a % b;       a = b;       b = r;     }     return a;   }   }  // namespace math   template <typename C>   int SZ(const C& c) {     return (int)c.size();   }   template <size_t n, class... Types>   struct TupleHashHelper {     static std::size_t calc(const std::tuple<Types...>& t) {       using std::size_t;       std::hash<typename std::tuple_element<n - 1, std::tuple<Types...>>::type>           elemHash;       return elemHash(std::get<n - 1>(t)) +              31013 * TupleHashHelper<n - 1, Types...>::calc(t);     }   };   template <class... Types>   struct TupleHashHelper<0, Types...> {     static std::size_t calc(const std::tuple<Types...>&) { return 0; }   };   template <class... Types>   struct TupleHash {     std::size_t operator()(const std::tuple<Types...>& t) const {       static const size_t n = std::tuple_size<std::tuple<Types...>>::value;       return TupleHashHelper<n, Types...>::calc(t);     }   };   class Solution {    public:     void solve(std::istream& in, std::ostream& out) {       int n;       in >> n;       vector<int> x(n), y(n);       for (int i = 0; i < n; ++i) in >> x[i] >> y[i];       unordered_map<tuple<int, int, int>, set<int>, TupleHash<int, int, int>>           lines;       for (int i = 0; i < n; ++i)         for (int j = i + 1; j < n; ++j) {           using math::gcd;           int a = y[j] - y[i], b = x[i] - x[j];           int c = -a * x[i] - b * y[i];           int d = gcd(gcd(a, b), c);           if (a < 0) {             a = -a;             b = -b;             c = -c;           } else if (a == 0 && b < 0) {             b = -b;             c = -c;           }           auto t = make_tuple(a / d, b / d, c / d);           lines[t].insert(i);           lines[t].insert(j);         }       long long res = (long long)n * (n - 1) * (n - 2) / 6;       for (const auto& p : lines) {         long long s = SZ(p.second);         res -= s * (s - 1) * (s - 2) / 6;       }       out << res << endl;     }   };   void solve(std::istream& in, std::ostream& out) {     out << std::setprecision(12);     Solution solution;     solution.solve(in, out);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     istream& in = cin;     ostream& out = cout;     solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int toInt(string s) {     int v;     istringstream sin(s);     sin >> v;     return v;   }   template <class T>   inline string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   template <class T>   inline T sqr(T x) {     return x * x;   }   const double EPS = 1e-10;   const double PI = acos(-1.0);   const int dx[] = {-1, 1, 0, 0};   const int dy[] = {0, 0, 1, -1};   int n, k, ret;   bool us[11];   int main() {     cin >> n >> k;     for (int i = (0); i < (n); ++i) {       string s;       bool f = true;       cin >> s;       for (int j = (0); j < (10); ++j) us[j] = false;       for (int j = (0); j < (s.size()); ++j) us[s[j] -  0 ] = true;       for (int j = (0); j < (k + 1); ++j)         if (!us[j]) f = false;       ret += f;     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p2(long long x) { return x * x; }   int main() {     long long n;     cin >> n;     if (n <= 2)       cout << -1 << endl;     else if (!(n % 2))       cout << (n * n) / 4 - 1 <<     << (n * n) / 4ll + 1ll << endl;     else       cout << (n * n - 1) / 2ll <<     << (n * n + 1) / 2ll << endl;     return 0;   }


///Bismillahir Rahmanir Rahim   #include<bits/stdc++.h>   #define        u64             uint64_t   #define        ll              long long   #define        endl              n    #define        PI              acos(-1)   #define        fi              first   #define        si              second   #define        mkp             make_pair   #define        pb              push_back   #define        set0(arr)       memset(arr, 0, sizeof(arr))   #define        setinf(arr)     memset(arr, 126, sizeof(arr))   #define        all(x)          (x).begin(),(x).end()   #define        sz(v)           ((ll)(v).size())   #define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)   using namespace std;   using          pll        =      pair<ll, ll> ;   using          vl         =      vector<ll> ;   using          vpll       =      vector<pll> ;   using          mll        =      map<ll, ll> ;   using          mcl        =      map<char, ll> ;   using          msl        =      map<string,ll> ;   using          sl         =      set<ll> ;   using          sc         =      set<char> ;   using          dl         =      deque<ll> ;   const int N = 1e6+5 ;      ll      mod = 1e9+7 ;   vl      adj[N] ;   vpll    adjc[N] ;   ll      vis[N] ;   ll      arr[N] ;      ll sumd(ll a,ll b){return (((a%mod)+(b%mod))%mod);}   ll muld(ll a,ll b){return (((a%mod)*(b%mod))%mod);}   ll subd(ll a,ll b){return (((a%mod)-(b%mod)+mod)%mod);}            int main()   {       IOS;       ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;       string   str ;       char     ch ;       double   db ;       ll       l, r ;       //code          cin>>tc;       for(cs=1;cs<=tc;cs++)       {           ll c1,c2,c3,a1,a2,a3,a4,a5;           cin>>c1>>c2>>c3;           cin>>a1>>a2>>a3>>a4>>a5;           c1-=a1;           c2-=a2;           c3-=a3;           if(c1<0||c2<0||c3<0)           {                  cout<< NO n ;continue;           }           if(c1>=a4)           {                          if(c2>=a5){}                          else                          {                              a5-=c2;                              c3-=a5;                              if(c3<0)                              {                                    cout<< NO n ;continue;                              }                          }           }           else           {                  a4-=c1;                  c3-=a4;                  if(c3<0)                  {                         cout<< NO n ;continue;                  }                  else                  {                                     if(c2>=a5);                  else                 {                 a5-=c2;                 c3-=a5;                 if(c3<0)                 {                 cout<< NO n ;continue;                 }                 }                 }           }           cout<< YES n ;          }             //code       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pwr(long long a, long long b, long long mod) {     a %= mod;     if (a < 0) a += mod;     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b /= 2;     }     return ans;   }   long long pwr(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans *= a;       a *= a;       b /= 2;     }     return ans;   }   long long gcd(long long a, long long b) {     while (b) {       long long temp = a;       a = b;       b = temp % b;     }     return a;   }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   long long modularInverse(long long a, long long m) {     assert(false);     return pwr(a, m - 2, m);   }   const int mod = 1000000007;   int DP[5001][5001];   int PDP[5001][5001];   int n, k, a, b;   void generatePDP(int u) {     PDP[u][0] = DP[u][0];     for (int i = 1; i <= n; ++i) {       PDP[u][i] = (PDP[u][i - 1] + DP[u][i]) % mod;     }   }   int main() {     std::ios::sync_with_stdio(false);     cin >> n >> a >> b >> k;     for (int i = 1; i <= n; ++i) DP[0][i] = 1;     DP[0][b] = 0;     for (int i = 1; i <= k; ++i) {       generatePDP(i - 1);       for (int j = 1; j <= n; ++j) {         if (j == b) {           DP[i][b] = 0;         } else if (j < b) {           int dist = b - j;           int start = max(1, j - dist + 1);           int end = b - 1;           if (start - 1 >= 1)             DP[i][j] = PDP[i - 1][end] - PDP[i - 1][start - 1] - DP[i - 1][j];           else             DP[i][j] = PDP[i - 1][end] - DP[i - 1][j];         } else if (j > b) {           int dist = j - b;           int start = b + 1;           int end = min(j + dist - 1, n);           if (start - 1 >= 1)             DP[i][j] = PDP[i - 1][end] - PDP[i - 1][start - 1] - DP[i - 1][j];           else             DP[i][j] = PDP[i - 1][end] - DP[i - 1][j];         }         DP[i][j] %= mod;         if (DP[i][j] < 0) DP[i][j] += mod;       }     }     cout << DP[k][a] << endl;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll P = 998244353;   constexpr ll modPow(ll a, ll b, ll c) {     if ((b & 1) == 1) return a * modPow(a, b - 1, c) % c;     if (b == 0) return 1 % c;     return modPow(a * a % c, b / 2, c);   }   void bitReverse(vector<int>& vec) {     int n = vec.size();     int lg = 0;     while ((1 << lg) < n) ++lg;     for (int i = 0; i < n; ++i) {       int t = 0;       for (int j = 0; j < lg; ++j) {         if (i & (1 << j)) t |= 1 << (lg - 1 - j);       }       if (i < t) swap(vec[i], vec[t]);     }   }   void ntt(vector<int>& pol, bool inv) {     bitReverse(pol);     int n = pol.size();     int lg = 0;     while ((1 << lg) < n) ++lg;     ll nth_root = modPow(3, (P - 1) / n, P);     if (inv) nth_root = modPow(nth_root, n - 1, P);     vector<ll> pows(lg, nth_root);     for (int i = lg - 2; i >= 0; --i) pows[i] = (pows[i + 1] * pows[i + 1]) % P;     ll tmp = 1;     for (int i = 0; i < n; ++i) tmp = (tmp * nth_root) % P;     for (lg = 0; (1 << lg) < n; ++lg) {       int h = 1 << lg;       int len = h << 1;       ll root = pows[lg];       for (int j = 0; j < n; j += len) {         ll curr = 1;         for (int i = j; i < j + h; ++i) {           int tmp = (curr * pol[i + h]) % P;           curr = (curr * root) % P;           pol[i + h] = P - tmp + pol[i];           if (pol[i + h] >= P) pol[i + h] -= P;           pol[i] += tmp;           if (pol[i] >= P) pol[i] -= P;         }       }     }   }   vector<int> polyMult(vector<int> a, vector<int> b) {     int as = a.size();     int bs = b.size();     int n = 1;     while (n < (as + bs)) n <<= 1;     a.resize(n, 0);     b.resize(n, 0);     ntt(a, false);     ntt(b, false);     vector<int> c(n);     int n_inv = modPow(n, P - 2, P);     for (int i = 0; i < n; ++i) {       ll prod = (ll)a[i] * b[i] % P;       c[i] = prod * n_inv % P;     }     ntt(c, true);     c.resize(as + bs - 1);     return c;   }   const int N = 10 + 4 * (int)1e5;   ll fact[N];   ll inv_fact[N];   ll twop[N];   ll choose(int a, int b) {     if (b > a) return 0;     ll div = inv_fact[b] * inv_fact[a - b] % P;     return fact[a] * div % P;   }   vector<int> build(const vector<ll>& as, ll h) {     int n = as.size();     int x = 0, y = 0;     for (int i = 0; i < n && as[i] < h;) {       int j = i;       while (j < n && as[j] == as[i]) ++j;       if (j - i == 1)         ++x;       else         ++y;       i = j;     }     n = x + 2 * y + 1;     vector<int> vec1(n, 0), vec2(n, 0);     for (int i = 0; i < n; ++i) {       vec1[i] = choose(2 * y, i);       vec2[i] = choose(x, i) * twop[i] % P;     }     vector<int> res = polyMult(vec1, vec2);     while (res.back() == 0) res.pop_back();     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     fact[0] = 1;     twop[0] = 1;     inv_fact[0] = 1;     for (int i = 1; i < N; ++i) {       fact[i] = (i * fact[i - 1]) % P;       twop[i] = (2 * twop[i - 1]) % P;       inv_fact[i] = modPow(fact[i], P - 2, P);     }     int n, k;     cin >> n >> k;     vector<ll> as(n), bs(k);     for (int i = 0; i < n; ++i) cin >> as[i];     for (int i = 0; i < k; ++i) cin >> bs[i];     sort(as.begin(), as.end());     vector<vector<int>> dp(k);     for (int j = 0; j < k; ++j) dp[j] = build(as, bs[j]);     int q;     cin >> q;     for (int qi = 0; qi < q; ++qi) {       int t;       cin >> t;       ll res = 0;       for (int j = 0; j < k; ++j) {         int c = (t / 2) - bs[j] - 1;         if (c >= 0 && c < dp[j].size()) {           res += dp[j][c];         }       }       cout << (res % P) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long qpow(long long x, long long k) {     return k == 0 ? 1                   : 1ll * qpow(1ll * x * x % mod, k >> 1) * (k & 1 ? x : 1) % mod;   }   const int md = 1e9 + 7;   const int Maxn = 5005;   int n, k;   long long dp[Maxn][Maxn];   int main() {     scanf( %d%d , &n, &k);     dp[0][0] = 1;     for (int i = 1; i <= k; i++) {       for (int j = 1; j <= i; j++) {         dp[i][j] = (dp[i - 1][j] * j + dp[i - 1][j - 1] * (n - j + 1)) % md;       }     }     long long ans = 0;     for (int i = 1; i <= min(n, k); i++) {       ans = (ans + dp[k][i] * qpow(2, n - i)) % md;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mat[101][101];   int min(int a, int b) { return a < b ? a : b; }   int max(int a, int b) { return a > b ? a : b; }   int main() {     int n, m;     int i, j;     string s;     cin >> n >> m;     for (i = 0; i < n; ++i) {       cin >> s;       for (j = 0; j < m; ++j) {         if (s[j] ==  W )           mat[i][j] = 0;         else           mat[i][j] = 1;       }     }     int left = -1, right = 101, top = -1, bot = 101;     int bcount = 0;     for (i = 0; i < n; ++i) {       for (j = 0; j < m; ++j) {         if (mat[i][j] == 1) {           ++bcount;           if (left == -1)             left = j;           else             left = min(left, j);           if (right == 101)             right = j;           else             right = max(right, j);           if (top == -1)             top = i;           else             top = min(top, i);           if (bot == 101)             bot = i;           else             bot = max(bot, i);         }       }     }     int c = 0;     if (bot == 101 && right == 101 && left == -1 && top == -1)       c = 1;     else if (bot == top && right == left)       c = 0;     else {       int hor = bot - top + 1;       int ver = right - left + 1;       int side = max(hor, ver);       if (side > n || side > m)         c = -1;       else {         c = side * side - bcount;       }     }     cout << c << endl;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   const int MOD = 998244353;   int fact[N], factinv[N];   int lgcput(int b, int p) {     int a = 1;     while (p) {       if (p & 1) {         a = (1LL * a * b) % MOD;       }       b = (1LL * b * b) % MOD;       p /= 2;     }     return a;   }   int inv(int x) { return lgcput(x, MOD - 2); }   int main() {     int n, k;     cin >> n >> k;     fact[0] = factinv[0] = 1;     for (int i = 1; i <= n; i++) {       fact[i] = (1LL * i * fact[i - 1]) % MOD;       factinv[i] = (1LL * inv(i) * factinv[i - 1]) % MOD;     }     int c = n - k;     if (k >= n) {       cout <<  0 ;       return 0;     }     int ans = 0;     for (int i = 0; i <= c; i++) {       int dead =           (1LL *            ((1LL * ((1LL * fact[c] * factinv[i]) % MOD) * factinv[c - i]) % MOD) *            lgcput(c - i, n)) %           MOD;       if (i & 1)         ans -= dead;       else         ans += dead;       if (ans < 0) ans += MOD;       if (ans >= MOD) ans -= MOD;     }     ans = (1LL * (1LL * (1LL * ans * fact[n] % MOD) * factinv[c] % MOD) *            factinv[n - c]) %           MOD;     if (k == 0) {       cout << ans;       return 0;     }     ans *= 2;     ans %= MOD;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nMax = 200003;   int smen[nMax];   int main() {     cin.sync_with_stdio(false);     cin.tie(NULL);     int n, k, q, st, dr;     cin >> n >> k >> q;     int m = nMax - 3;     for (int i = 1; i <= n; i++) {       cin >> st >> dr;       smen[st]++;       smen[dr + 1]--;     }     for (int i = 1; i <= m; i++) {       smen[i] = smen[i - 1] + smen[i];     }     for (int i = 1; i <= m; i++) {       if (smen[i] >= k) {         smen[i] = 1;       } else {         smen[i] = 0;       }     }     for (int i = 1; i <= m; i++) {       smen[i] = smen[i - 1] + smen[i];     }     int x, y;     for (int i = 1; i <= q; i++) {       cin >> x >> y;       cout << smen[y] - smen[x - 1] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> dp;   long long fastPow(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = (ret * a) % 1000000007;       a = (a * a) % 1000000007;       b >>= 1;     }     return ret;   }   long long cc(long long y) {     if (dp.find(y) != dp.end()) return dp[y];     dp[y] = fastPow(2, y - 1);     for (int i = 2; i * i <= y; i++) {       if (!(y % i)) {         dp[y] = (dp[y] - cc(i) + 1000000007) % 1000000007;         if (i != y / i) {           dp[y] = (dp[y] - cc(y / i) + 1000000007) % 1000000007;         }       }     }     dp[y]--;     return dp[y];   }   int main() {     long long x, y;     cin >> x >> y;     if (!(y % x)) {       y /= x;       if (y == 1) {         cout << 1 << endl;         return 0;       }       cout << cc(y) << endl;       return 0;     }     cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int cases;     scanf( %d , &cases);     while (cases--) {       int n, p;       scanf( %d%d , &n, &p);       for (int i = 2; i <= n; i++) {         printf( %d %d n , 1, i);       }       for (int i = 2; i < n; i++) {         printf( %d %d n , i, i + 1);       }       printf( %d %d n , n, 2);       int count = 0, extra = 2 * n + p - 2 * (n - 1);       for (int i = 2; i <= n; i++) {         for (int j = i + 2; j <= n; j++) {           if (i == 2 && j == n) break;           printf( %d %d n , i, j);           count++;           if (count == extra) goto here;         }       }     here:       continue;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   int dx[]{-1, 0, 0, 1};   int dy[]{-1, -1, 1, 1};   void solve() {     string str;     cin >> str;     cout << str;     reverse(str.begin(), str.end());     cout << str <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     solve();     cerr <<  Time elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<  s. n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace FastIO {   const int L = (1 << 20);   char buf[L], *S, *T;   inline char getchar() {     if (S == T) {       T = (S = buf) + fread(buf, 1, L, stdin);       if (S == T) return EOF;     }     return *S++;   }   inline int read() {     int s = 0, f = 1;     char t = getchar();     while ( 0  > t || t >  9 ) {       if (t ==  - ) f = -1;       t = getchar();     }     while ( 0  <= t && t <=  9 ) {       s = (s << 1) + (s << 3) + t -  0 ;       t = getchar();     }     return s * f;   }   }  // namespace FastIO   using FastIO::read;   const int N = 55;   const int Mod = 998244353;   int dp[N][N][N * 2], sum, Sadd, Ssub;   int w[N], a[N], n, m;   int Inc(int x, int y) { return x + y >= Mod ? x + y - Mod : x + y; }   int Dec(int x, int y) { return x - y < 0 ? x - y + Mod : x - y; }   int Mul(int x, int y) { return (long long)x * y % Mod; }   int Fpow(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = Mul(ans, a);       b >>= 1;       a = Mul(a, a);     }     return ans;   }   int Inv(int x) { return Fpow(x, Mod - 2); }   void Dp(int c) {     memset(dp, 0, sizeof(dp));     dp[0][0][0] = 1;     for (int i = 0; i < m; i++) {       for (int k = 0; k <= i; k++) {         int now = (a[c] ? w[c] + k : w[c] - k);         if (now < 0) continue;         for (int d = 0; d <= i; d++) {           if (!dp[i][k][d]) continue;           int Dw = sum + d - (i - d);           Dw = Inv(Dw);           int Up_add = Sadd + d;           int Up_sub = Ssub - (i - d);           if (a[c]) {             dp[i + 1][k + 1][d + 1] =                 Inc(dp[i + 1][k + 1][d + 1], Mul(dp[i][k][d], Mul(now, Dw)));             dp[i + 1][k][d + 1] =                 Inc(dp[i + 1][k][d + 1], Mul(dp[i][k][d], Mul(Up_add - now, Dw)));             dp[i + 1][k][d] =                 Inc(dp[i + 1][k][d], Mul(dp[i][k][d], Mul(Up_sub, Dw)));           } else {             dp[i + 1][k + 1][d] =                 Inc(dp[i + 1][k + 1][d], Mul(dp[i][k][d], Mul(now, Dw)));             dp[i + 1][k][d + 1] =                 Inc(dp[i + 1][k][d + 1], Mul(dp[i][k][d], Mul(Up_add, Dw)));             dp[i + 1][k][d] =                 Inc(dp[i + 1][k][d], Mul(dp[i][k][d], Mul(Up_sub - now, Dw)));           }         }       }     }     int Ans = 0;     for (int k = 0; k <= m; k++) {       int now = (a[c] ? w[c] + k : w[c] - k);       if (now < 0) continue;       for (int d = 0; d <= m; d++) {         Ans = Inc(Ans, Mul(now, dp[m][k][d]));       }     }     cout << Ans <<   n ;   }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) {       w[i] = read();       if (a[i])         Sadd += w[i];       else         Ssub += w[i];       sum += w[i];     }     for (int i = 1; i <= n; i++) Dp(i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <class T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <class T>   inline void printsp(T first) {     print(first);     putchar(   );   }   template <class T>   inline void println(T first) {     print(first);     putchar(  n );   }   template <class T, class U>   inline void print(T first, U second) {     printsp(first);     println(second);   }   template <class T, class U, class V>   inline void print(T first, U second, V z) {     printsp(first);     printsp(second);     println(z);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int tp[250] = {       0,    4,     10,    20,    35,    56,    83,    116,   155,   198,  244,       292,  341,   390,   439,   488,   537,   586,   635,   684,   733,  782,       831,  880,   929,   978,   1027,  1076,  1125,  1174,  1223,  1272, 1321,       1370, 1419,  1468,  1517,  1566,  1615,  1664,  1713,  1762,  1811, 1860,       1909, 1958,  2007,  2056,  2105,  2154,  2203,  2252,  2301,  2350, 2399,       2448, 2497,  2546,  2595,  2644,  2693,  2742,  2791,  2840,  2889, 2938,       2987, 3036,  3085,  3134,  3183,  3232,  3281,  3330,  3379,  3428, 3477,       3526, 3575,  3624,  3673,  3722,  3771,  3820,  3869,  3918,  3967, 4016,       4065, 4114,  4163,  4212,  4261,  4310,  4359,  4408,  4457,  4506, 4555,       4604, 4653,  4702,  4751,  4800,  4849,  4898,  4947,  4996,  5045, 5094,       5143, 5192,  5241,  5290,  5339,  5388,  5437,  5486,  5535,  5584, 5633,       5682, 5731,  5780,  5829,  5878,  5927,  5976,  6025,  6074,  6123, 6172,       6221, 6270,  6319,  6368,  6417,  6466,  6515,  6564,  6613,  6662, 6711,       6760, 6809,  6858,  6907,  6956,  7005,  7054,  7103,  7152,  7201, 7250,       7299, 7348,  7397,  7446,  7495,  7544,  7593,  7642,  7691,  7740, 7789,       7838, 7887,  7936,  7985,  8034,  8083,  8132,  8181,  8230,  8279, 8328,       8377, 8426,  8475,  8524,  8573,  8622,  8671,  8720,  8769,  8818, 8867,       8916, 8965,  9014,  9063,  9112,  9161,  9210,  9259,  9308,  9357, 9406,       9455, 9504,  9553,  9602,  9651,  9700,  9749,  9798,  9847,  9896, 9945,       9994, 10043, 10092, 10141, 10190, 10239, 10288, 10337, 10386, 10435};   int main() {     int n;     gn(n);     if (n < 201)       println(tp[n]);     else       println(tp[200] + (long long)(n - 200) * 49);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a;     scanf( %d %d %*d , &n, &a);     map<long long, int> cnt1;     map<pair<int, int>, int> cnt2;     long long ans = 0;     for (int i = 0; i < n; ++i) {       int vx, vy;       scanf( %*d %d %d , &vx, &vy);       long long v = 1LL * a * vx - vy;       ans += cnt1[v];       ans -= cnt2[{vx, vy}];       ++cnt1[v];       ++cnt2[{vx, vy}];     }     printf( %lld n , ans * 2);   }


#include <bits/stdc++.h>   using namespace std;   long long L[200005], R[200005], U[200005], D[200005];   long long n;   string S;   long long x, y, sx = 0, sy = 0;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> S >> x >> y;     S =  _  + S;     L[0] = R[0] = U[0] = D[0] = 0;     for (long long i = 1; i <= n; i++) {       L[i] = L[i - 1];       R[i] = R[i - 1];       D[i] = D[i - 1];       U[i] = U[i - 1];       if (S[i] ==  L )         L[i]++, sx--;       else if (S[i] ==  R )         R[i]++, sx++;       else if (S[i] ==  U )         U[i]++, sy++;       else if (S[i] ==  D )         D[i]++, sy--;     }     if (sx == x && sy == y) {       cout << 0;       return 0;     }     if ((sx + sy + x + y) % 2 != 0) {       cout << -1;       return 0;     }     long long s_ind = 1, g_ind = n + 1;     while (g_ind > s_ind) {       long long len = (g_ind + s_ind) / 2;       bool b = 0;       for (long long j = len; j <= n; j++) {         long long l = L[n] - L[j] + L[j - len], r = R[n] - R[j] + R[j - len],                   u = U[n] - U[j] + U[j - len], d = D[n] - D[j] + D[j - len];         long long curx = r - l, cury = u - d;         if (abs(curx - x) + abs(cury - y) <= len) {           b = 1;           break;         }       }       if (b)         g_ind = len;       else         s_ind = len + 1;     }     if (s_ind <= n)       cout << s_ind;     else       cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500023;   bool vis[N];   vector<int> adj[N];   void solve() {     long long int n;     cin >> n;     vector<long long int> v;     for (long long int i = 0; i < n; i++) {       long long int c;       cin >> c;       v.push_back(c);     }     sort((v).begin(), (v).end());     long long int ans = 0;     if (v[2] != v[1]) {       for (int i = 2; i < n; i++) {         if (v[i] == v[2])           ans++;         else           break;       }     } else if ((v[2] == v[1]) && (v[1] != v[0])) {       long long int count = 0;       for (int i = 1; i < n; i++) {         if (v[i] == v[1])           count++;         else           break;       }       ans = (count * (count - 1)) / 2;     } else {       long long int count = 0;       for (int i = 0; i < n; i++) {         if (v[i] == v[0])           count++;         else           break;       }       ans = (count * (count - 1) * (count - 2)) / 6;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T = 1;     int t = 0;     while (t++ < T) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long fact(int x) {     long long ans = 0;     while (x > 0) {       ans += x;       x--;     }     return ans;   }   int main() {     int n;     cin >> n;     vector<vector<char> > a(n, vector<char>(n));     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> a[i][j];     vector<int> ansi(n);     vector<int> ansj(n);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (a[i][j] ==  C ) {           ansi[i]++;           ansj[j]++;         }     long long count = 0;     long long ans = 0;     for (int i = 0; i < n; i++) count += fact(ansi[i] - 1);     ans += count;     count = 0;     for (int i = 0; i < n; i++) count += fact(ansj[i] - 1);     ans += count;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans, a[300010];   bool check(int mid) {     int pre = mid + a[1] >= m ? 0 : a[1];     for (int i = 2; i <= n; i++) {       if (a[i] + mid < pre) return false;       if (a[i] <= pre)         continue;       else if (a[i] + mid >= m && (a[i] + mid) % m >= pre)         continue;       pre = a[i];     }     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int l = 0, r = m - 1;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define int unsigned long long      const int N = 100010;   int n, a[N];      signed main(void)   {       ios::sync_with_stdio(false);       map <int, int> mp;       int T;       cin >> T;       while(T--)       {           mp.clear();           int res = 0;           int n;           cin >> n;           for(int i = 1; i <= n; i++)           {               cin >> a[i];               res += mp[a[i]] * (n - i + 1);               mp[a[i]] += i;           }           cout << res << endl;       }       return 0;   }   /*   ————————————————   版权声明：本文为CSDN博主「zhbbbb！」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。   原文链接：https://blog.csdn.net/zhbbbbbb/article/details/117330722*/


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,fast-math,unroll-loops )   using namespace std;   const int maxn = 2e5 + 50;   inline char nc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline int read() {     char ch = nc();     int sum = 0;     while (!(ch >=  0  && ch <=  9 )) ch = nc();     while (ch >=  0  && ch <=  9 ) sum = sum * 10 + ch - 48, ch = nc();     return sum;   }   int t, n;   string str;   int sum1[maxn], sum2[maxn];   map<pair<int, int>, int> mp;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n >> str;       str =      + str;       n++;       for (int i = 1; i <= n; i++)         sum1[i] = sum1[i - 1] + (str[i] ==  L ) - (str[i] ==  R ),         sum2[i] = sum2[i - 1] + (str[i] ==  U ) - (str[i] ==  D );       int ans = 0x3f3f3f3f, l = 0, r = 0;       mp.clear();       for (int i = 1; i <= n; i++) {         if (mp[make_pair(sum1[i], sum2[i])] != 0) {           int tmp = mp[make_pair(sum1[i], sum2[i])];           if (i - tmp < ans) ans = i - tmp, l = tmp + 1, r = i;         }         mp[make_pair(sum1[i], sum2[i])] = i;       }       if (ans == 0x3f3f3f3f)         printf( -1 n );       else         printf( %d %d n , l - 1, r - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m;   long long n;   long long deg[1001001], result;   vector<vector<int> > e;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       deg[a]++;       deg[b]++;     }     result = 0;     for (int i = 1; i <= n; i++) result += (n - 1 - deg[i]) * deg[i];     result /= 2;     result = n * (n - 1) * (n - 2) / 6 - result;     cout << result;   }


#include <bits/stdc++.h>   const int MAXN = 1e5 + 19;   int qpow(int a, int b, int p) {     int res = 1;     while (b) {       if (b & 1) res = (long long)res * a % p;       a = (long long)a * a % p, b >>= 1;     }     return res;   }   int n, m, k, p;   int fa[MAXN], size[MAXN];   int getf(int node) {     return fa[node] == node ? node : fa[node] = getf(fa[node]);   }   int main() {     std::scanf( %d%d%d , &n, &m, &p);     for (int i = 1; i <= n; ++i) fa[i] = i, size[i] = 1;     for (int i = 1; i <= m; ++i) {       int u, v;       std::scanf( %d%d , &u, &v);       if (getf(u) != getf(v)) {         size[getf(v)] += size[getf(u)];         fa[getf(u)] = getf(v);       }     }     int ans = 1;     for (int i = 1; i <= n; ++i)       if (fa[i] == i) ++k, ans = (long long)ans * size[i] % p;     if (k >= 2)       ans = (long long)ans * qpow(n, k - 2, p) % p;     else       ans = 1;     std::printf( %d n , ans % p);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<long long int> vec1, vec2;     vector<long long int>::iterator it;     long long int n, a, sz, s1 = 0, s2 = 0, s3 = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       s1 += a;     }     n--;     for (int i = 0; i < n; i++) {       cin >> a;       s2 += a;     }     n--;     for (int i = 0; i < n; i++) {       cin >> a;       s3 += a;     }     cout << s1 - s2 << endl << s2 - s3;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2000000000;   const int maxn = 1000005;   int n;   int a[maxn];   bool vis[maxn];   int main() {     long long ans = 0LL;     scanf( %d , &n);     for (int i = n; i >= 0; i--) {       if (vis[i]) continue;       int t = 0, s = 0;       for (int j = 0; j < 20; j++)         if (i & (1 << j)) s = j;       for (int j = s - 1; j >= 0; j--)         if (!(i & (1 << j))) t |= (1 << j);       a[i] = t, a[t] = i;       vis[i] = vis[t] = 1;       ans += 2 * (i ^ t);     }     printf( %I64d n , ans);     for (int i = 0; i < n; i++) printf( %d  , a[i]);     printf( %d n , a[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fail[1000006];   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     fail[-1] = fail[0] = -1;     for (int i = 1; i < n; ++i) {       int ptr = i - 1;       while (s[i] != s[fail[ptr] + 1] && ptr > 0) ptr = fail[ptr];       fail[i] = fail[ptr] + (s[i] == s[fail[ptr] + 1]);     }     for (int i = 0; i < n; ++i) {       int le = i - fail[i];       int cc = (i + 1) / le;       if ((i + 1) % le == 0) {         if (cc / k - cc % k >= 0)           cout << 1;         else           cout << 0;       } else {         if (cc / k - cc % k > 0)           cout << 1;         else           cout << 0;       }     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long min(long long x, long long y) { return (x < y) ? x : y; }   long long max(long long x, long long y) { return (x > y) ? x : y; }   const int N = 100009;   int x, y, n, m, i, u, w, z, sum, best, j, k, t, mx;   int a[N];   string s, ans;   int main() {     ios_base::sync_with_stdio(false);     cin >> s;     n = s.size();     while (i < n) {       if (s[i] ==  d  && s[i + 1] ==  o  && s[i + 2] ==  t  && i != 0 &&           i != n - 3) {         ans.push_back( . );         i += 2;       } else if (s[i] ==  a  && s[i + 1] ==  t  && !x && i != 0 && i != n - 2) {         x = 1;         i++;         ans.push_back( @ );       } else         ans.push_back(s[i]);       i++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> V[1005];   int dis[1005], rdis[1005], G[1005][1005];   void spfa(int s, int e) {     queue<int> Q;     memset(dis, 0x3f, sizeof(dis));     memset(rdis, 0x3f, sizeof(rdis));     Q.push(s);     dis[s] = 0;     while (!Q.empty()) {       int f = Q.front();       for (int i = (0); i < ((int)(V[f]).size()); i++) {         int nex = V[f][i];         if (dis[nex] > dis[f] + 1) {           dis[nex] = dis[f] + 1;           Q.push(nex);         }       }       Q.pop();     }     Q.push(e);     rdis[e] = 0;     while (!Q.empty()) {       int f = Q.front();       for (int i = (0); i < ((int)(V[f]).size()); i++) {         int nex = V[f][i];         if (rdis[nex] > rdis[f] + 1) {           rdis[nex] = rdis[f] + 1;           Q.push(nex);         }       }       Q.pop();     }   }   int main() {     int n, m, s, e;     scanf( %d%d%d%d , &n, &m, &s, &e);     while (m--) {       int a, b;       scanf( %d%d , &a, &b);       V[a].push_back(b);       V[b].push_back(a);       G[a][b] = G[b][a] = 1;     }     int ans = 0;     spfa(s, e);     for (int i = (1); i < (n + 1); i++)       for (int j = (i + 1); j < (n + 1); j++)         if (dis[i] + 1 + rdis[j] >= dis[e] && dis[j] + 1 + rdis[i] >= dis[e] &&             !G[i][j])           ans++;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   typedef long long ll;   using namespace std;      int k;      int addk(int a,int b)   {    int base,aw,bw,ret=0;    for(base=1;base<=max(a,b);base*=k)    {     aw=a/base%k;     bw=b/base%k;     ret+=(aw+bw)%k*base;    }     return ret;   }      int subk(int a,int b)   {    int base,aw,bw,ret=0;    for(base=1;base<=max(a,b);base*=k)    {     aw=a/base%k;     bw=b/base%k;     ret+=(aw-bw+k)%k*base;    }     return ret;   }      int main()   {    int T,n,y,i,r;    scanf( %d ,&T);    while(T--)    {     scanf( %d%d ,&n,&k);     for(i=0;i<n;i++)     {      if(i==0)       y=0;      else if(i&1)       y=subk(i-1,i);      else       y=subk(i,i-1);      printf( %d n ,y);      fflush(stdout);      scanf( %d ,&r);      if(r==1)       break;     }    }   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   const int maxn = 1e5 + 10;   stack<int> max_seen;   int ans[maxn];   vector<int> to[maxn];   void calc(int a) {     int s = max(a - k, 0), t = min(n, a + k + 1);     if (max_seen.empty())       ans[a] += t - s;     else       ans[a] += t - max(max_seen.top(), s);     max_seen.push(t);     for (int i = 0; i < to[a].size(); i++) {       ans[to[a][i]] = ans[a];       calc(to[a][i]);     }     max_seen.pop();   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (x > 0) to[x - 1].push_back(i);     }     for (int i = 0; i < n; i++)       if (ans[i] == 0) calc(i);     for (int i = 0; i < n; i++) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     long ans = 0;     for (int i = 0; i < n; i++) {       if ((s[i] -  0 ) % 2 == 0) ans += (i + 1);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 35;   int n, m;   int a[MAXN][MAXN];   int part[MAXN][MAXN], partn = 0;   long long ans = 0;   int x[MAXN][2];   int res[MAXN][MAXN];   int c[MAXN];   int u[MAXN];   void read() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       char tmp[35];       scanf( %s , tmp + 1);       for (int j = 1; j <= m; j++) {         if (tmp[j] ==  . )           a[i][j] = 0;         else if (tmp[j] >=  a )           a[i][j] = tmp[j] -  a  + 1;         else           a[i][j] = tmp[j] -  A  + 26 + 1;       }     }   }   void prepare() {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] != 0 && !part[i][j]) {           partn++;           part[i][j] = part[i][j + 1] = part[i + 1][j] = part[i + 1][j + 1] =               partn;         }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] != 0) {           int k = a[i][j];           if (x[k][0] == 0)             x[k][0] = part[i][j];           else             x[k][1] = part[i][j];         }     for (int i = 1; i <= 28; i++) {       if (x[i][0] > x[i][1]) x[i][0] ^= x[i][1] ^= x[i][0] ^= x[i][1];     }   }   bool chk(int p) {     bool e[10][10];     memset(e, 0, sizeof(e));     for (int i = 1; i <= 28; i++)       if (x[i][1] <= p) {         int f = c[x[i][0]], g = c[x[i][1]];         if (f > g) f ^= g ^= f ^= g;         if (e[f][g]) return false;         e[f][g] = true;       }     return true;   }   void dfs(int p) {     if (p > partn) {       if (ans == 0) {         for (int i = 1; i <= n; i++)           for (int j = 1; j <= m; j++)             if (a[i][j] != 0) res[i][j] = c[part[i][j]];       }       ans += 5040;       return;     }     for (int i = 0; i <= 6; i++)       if (u[i] <= 1) {         c[p] = i;         if (!chk(p)) continue;         u[i]++;         dfs(p + 1);         u[i]--;         if (u[i] == 0) return;       }   }   void work() { dfs(1); }   void print() {     printf( %I64d n , ans);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[i][j] == 0)           printf( . );         else           printf( %d , res[i][j]);       }       printf(  n );     }   }   int main() {     read();     prepare();     work();     print();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int ar[305][305];   vector<pair<int, int> > poss[90005];   int dp[305][305];   vector<int> col[305];   int vis[305];   int n, m, p;   void pr() {}   void solve() {     memset(dp, 127, sizeof(dp));     ;     scanf( %d %d %d , &n, &m, &p);     for (int i = 0; i < (int)(n); i++) {       for (int j = 0; j < (int)(m); j++) {         scanf( %d , &ar[i][j]);         poss[ar[i][j]].push_back(make_pair(i, j));         if (ar[i][j] == 1) {           dp[i][j] = i + j;         }       }     }     for (int val = 2; val <= p; val++) {       memset(vis, 0, sizeof(vis));       ;       for (int i = 0; i < (int)(m); i++) {         col[i].clear();       }       for (int i = 0; i < poss[val].size(); i++) {         pair<int, int> a = poss[val][i];         col[a.second].push_back(a.first);       }       for (int i = 0; i < poss[val - 1].size(); i++) {         pair<int, int> a = poss[val - 1][i];         vis[a.first] = 1;       }       for (int i = 0; i < n; i++) {         if (!vis[i]) continue;         int best = 1e9;         for (int j = 0; j < m; j++) {           best++;           if (ar[i][j] == val - 1) best = min(best, dp[i][j]);           for (int k = 0; k < col[j].size(); k++) {             dp[col[j][k]][j] = min(dp[col[j][k]][j], best + abs(col[j][k] - i));           }         }         best = 1e9;         for (int j = m; j >= 0; j--) {           best++;           if (ar[i][j] == val - 1) best = min(best, dp[i][j]);           for (int k = 0; k < col[j].size(); k++) {             dp[col[j][k]][j] = min(dp[col[j][k]][j], best + abs(col[j][k] - i));           }         }       }     }     printf( %d , dp[poss[p][0].first][poss[p][0].second]);   }   int main() {     int TC = 1;     for (int ZZ = 1; ZZ <= TC; ZZ++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)2E9;   const long long LINF = (long long)9E18;   const long double PI = acos(-1.0);   const long double EPS = 1E-11;   template <typename T>   inline T sqr(const T x) {     return x * x;   }   template <typename T>   T gcd(T a, T b) {     return (b == 0) ? a : gcd(b, a % b);   }   template <typename T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <typename T>   T mod(T a, T b) {     a %= b;     if (a < 0) a += b;     return a;   }   template <typename T>   inline T rad(const T x) {     return x * PI / 180;   }   template <typename T>   inline string toString(T x) {     ostringstream oss;     oss << x;     return oss.str();   }   inline long long toInt(const string& st) {     istringstream istringstream(st);     long long x;     istringstream >> x;     return x;   }   inline long double toDouble(const string& st) {     istringstream istringstream(st);     long double x;     istringstream >> x;     return x;   }   inline string toLower(string st) {     for (int i = 0; i < (((int)(st).size())); ++i) st[i] = tolower(st[i]);     return st;   }   inline string toUpper(string st) {     for (int i = 0; i < (((int)(st).size())); ++i) st[i] = toupper(st[i]);     return st;   }   const int dx[] = {-1, 0, 1, 0};   const int dy[] = {0, 1, 0, -1};   int DEBUG = false;   const char DEBUG_PARAM[] =  __LOCAL_TESTING ;   const int MAXCLOCK = 100;   int aClock[MAXCLOCK], mClock[MAXCLOCK], nClock = 0, iClock = 0;   inline void tick(int maxTime = 10000) {     if (DEBUG) {       mClock[nClock] = maxTime;       aClock[nClock++] = clock();     }   }   inline void untick(string name =  Execution Time ) {     if (DEBUG) {       int numClock = clock() - aClock[--nClock];       cout <<  @   << name <<  : [             << (int)((double)(numClock) / CLOCKS_PER_SEC * 1000) <<   ms] ;       if (numClock > (int)(mClock[nClock]))         cout <<   [TLE] ;       else if (numClock > (int)(mClock[nClock] * 0.9))         cout <<   [almost TLE] ;       cout << endl;     }   }   const char IN[] =  _.in ;   const char OUT[] =  _.out ;   int ntest = 1, test = 1;   int n;   map<string, string> type;   pair<int, int> findDefRef(string w) {     int d = 0, r = 0;     while (d < ((int)(w).size()) && w[d] ==  & ) d++;     while (r < ((int)(w).size()) && w[((int)(w).size()) - r - 1] ==  * ) r++;     return make_pair(d, r);   }   string removeDefRef(string w) {     pair<int, int> tmp = findDefRef(w);     return w.substr(tmp.first, ((int)(w).size()) - tmp.first - tmp.second);   }   string findType(string original, int def, int ref) {     if (type.count(original) == 0) {       return  errtype ;     }     string nowType = type[original];     if (nowType ==  errtype ) {       return nowType;     }     pair<int, int> tmp = findDefRef(nowType);     nowType = removeDefRef(nowType);     def += tmp.first, ref += tmp.second;     if (def > ref) {       return  errtype ;     } else {       ref -= def;       def = 0;     }     for (int i = 0; i < (ref); ++i) nowType = nowType +  * ;     return nowType;   }   inline void run() {     type[ void ] =  void ;     type[ errtype ] =  errtype ;     for (test = 1; test <= ntest; ++test) {       tick((int)2E3);       cin >> n;       string command, a, b;       pair<int, int> tmp;       int def, ref;       for (int i = (1); i <= (n); ++i) {         cin >> command;         if (command ==  typedef ) {           cin >> a >> b;           tmp = findDefRef(a);           def = tmp.first, ref = tmp.second;           a = removeDefRef(a);           type[b] = findType(a, def, ref);         } else {           cin >> a;           tmp = findDefRef(a);           def = tmp.first, ref = tmp.second;           a = removeDefRef(a);           cout << findType(a, def, ref) << endl;         }       }       untick( #  + toString(test));     }   }   int main(int argc, char* argv[]) {     if (argc > 1 && strcmp(argv[1], DEBUG_PARAM) == 0) {       DEBUG = true;     }     if (DEBUG) {       tick((int)1E4);       freopen(IN,  r , stdin);     }     run();     if (DEBUG) {       untick( TOTAL );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int cnt[1001] = {0}, a[n];     for (int i = 0; i < n; ++i) {       cin >> a[i];       cnt[a[i]] = i;     }     int vis[1001] = {0};     vector<int> res;     for (int i = 0; i < n; i++) {       if (cnt[a[i]] == i) res.push_back(a[i]);     }     cout << res.size() << endl;     for (int i = 0; i < res.size(); ++i) cout << res[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   using namespace chrono;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long int advceil(long long int num, long long int den) {     return (num % den == 0 ? num / den : num / den + 1);   }   long long int lstbt(long long int val) {     long long int msk = val & (val - 1);     return log2(val ^ msk);   }   long long int modmul(long long int a, long long int b) {     a %= 1000000007;     b %= 1000000007;     long long int res = 0;     while (b > 0) {       if (b & 1) res = (res + a) % 1000000007;       a = (a * 2) % 1000000007;       b /= 2;     }     return res;   }   long long int modexpo(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = modmul(res, a);       a = modmul(a, a);       b /= 2;     }     return res;   }   long long int gcd(long long int a, long long int b) {     return a == 0 ? b : gcd(b % a, a);   }   vector<long long int> CALCfactor(long long int n) {     vector<long long int> factor(n + 2, 0);     for (long long int i = 4; i <= n; i += 2) factor[i] = 2;     for (long long int j = 3; j <= n; j += 2) {       if (factor[j]) continue;       for (long long int i = 2 * j; i <= n; i += j) factor[i] = j;     }     return factor;   }   vector<long long int> CALCprimeNUM(long long int n) {     vector<long long int> factor = CALCfactor(n);     vector<long long int> primeNUM;     primeNUM.reserve(n + 2);     for (long long int i = 2; i <= n; i++)       if (!factor[i]) primeNUM.push_back(i);     return primeNUM;   }   vector<long long int> CALCprimeFACTOR(long long int n) {     vector<long long int> factor = CALCfactor(n);     vector<long long int> ans;     while (factor[n] != 0) {       ans.push_back(factor[n]);       n /= factor[n];     }     ans.push_back(n);     return ans;   }   vector<long long int> unique(vector<long long int> x) {     sort(x.begin(), x.end());     set<long long int> s;     vector<long long int> ans;     ans.reserve(x.size());     for (auto elem : x) s.insert(elem);     for (auto elem : s) ans.push_back(elem);     return ans;   }   vector<long long int> ZALGO(string s, string pat) {     long long int lens = pat.length();     pat += char(36);     pat += s;     s = pat;     vector<long long int> pref(s.length() + 1, 0);     pref[0] = s.length();     long long int spt = -1;     long long int ept = -1;     long long int processCnt = 0;     for (long long int i = 1; i < s.length(); i++) {       bool isdone = false;       if (i <= ept and i >= spt) {         if (pref[i - spt] + i <= ept) pref[i] = pref[i - spt], isdone = true;         processCnt++;       }       if (!isdone) {         long long int ptr = i;         long long int lo = 0;         while (s[lo] == s[ptr]) ptr++, lo++, processCnt++;         if (ept < ptr - 1) {           spt = i;           ept = ptr - 1;         }         pref[i] = lo;       }     }     vector<long long int> ans;     ans.reserve(s.length() - lens);     for (long long int i = lens + 1; i < s.length(); i++) ans.push_back(pref[i]);     return ans;   }   void spclSort(       vector<pair<pair<long long int, long long int>, long long int>>& v) {     long long int n = v.size();     {       vector<long long int> cnt(n);       for (auto elem : v) {         cnt[elem.first.second]++;       }       vector<pair<pair<long long int, long long int>, long long int>> a_new(n);       vector<long long int> pos(cnt.size());       pos[0] = 0;       for (long long int i = 1; i < cnt.size(); i++) {         pos[i] = cnt[i - 1] + pos[i - 1];       }       for (auto elem : v) {         a_new[pos[elem.first.second]] = elem;         pos[elem.first.second]++;       }       v = a_new;     }     {       vector<long long int> cnt(n, 0);       for (auto elem : v) {         cnt[elem.first.first]++;       }       vector<pair<pair<long long int, long long int>, long long int>> a_new(n);       vector<long long int> pos(cnt.size());       pos[0] = 0;       for (long long int i = 1; i < cnt.size(); i++) {         pos[i] = cnt[i - 1] + pos[i - 1];       }       for (auto elem : v) {         a_new[pos[elem.first.first]] = elem;         pos[elem.first.first]++;       }       v = a_new;     }   }   pair<vector<vector<long long int>>, vector<vector<long long int>>> getOrdering(       string s) {     s += char(36);     vector<vector<long long int>> dp;     dp.reserve(log2(s.length()) + 3);     vector<vector<long long int>> dp2;     dp2.reserve(log2(s.length()) + 3);     vector<long long int> ordering(s.length()), eqClass(s.length());     {       vector<pair<char, long long int>> temp(s.length());       for (long long int i = 0; i < s.length(); i++) temp[i] = {s[i], i};       sort(temp.begin(), temp.end());       for (long long int i = 0; i < temp.size(); i++)         ordering[temp[i].second] = i;       eqClass[temp[0].second] = 0;       for (long long int i = 1; i < temp.size(); i++) {         if (temp[i].first != temp[i - 1].first)           eqClass[temp[i].second] = eqClass[temp[i - 1].second] + 1;         else           eqClass[temp[i].second] = eqClass[temp[i - 1].second];       }       dp.push_back(ordering);       dp2.push_back(eqClass);     }     long long int k = 1;     while ((1 << (k - 1)) < s.length()) {       vector<pair<pair<long long int, long long int>, long long int>> arr(           s.length());       for (long long int i = 0; i < s.length(); i++) {         arr[i] = {{eqClass[i], eqClass[(i + (1 << (k - 1))) % s.length()]}, i};       }       spclSort(arr);       for (long long int i = 0; i < s.length(); i++) ordering[arr[i].second] = i;       eqClass[arr[0].second] = 0;       for (long long int i = 1; i < s.size(); i++) {         if (arr[i].first != arr[i - 1].first)           eqClass[arr[i].second] = eqClass[arr[i - 1].second] + 1;         else           eqClass[arr[i].second] = eqClass[arr[i - 1].second];       }       dp.push_back(ordering);       dp2.push_back(eqClass);       k++;     }     return {dp, dp2};   }   vector<long long int> sortOrdering(vector<vector<long long int>> dp) {     vector<long long int> arr = dp[dp.size() - 1];     vector<long long int> ans(arr.size());     long long int cnt = 0;     for (auto elem : arr) {       ans[elem] = cnt;       cnt++;     }     return ans;   }   vector<long long int> getLps(string pat) {     long long int i = 1;     long long int j = 0;     vector<long long int> lps(pat.length(), 0);     lps[0] = 0;     while (i < pat.length()) {       if (pat[i] == pat[j])         lps[i] = j + 1, i++, j++;       else if (j == 0)         lps[i] = 0, i++;       else         j = lps[j - 1];     }     return lps;   }   pair<vector<long long int>, vector<long long int>> getFact(long long int n) {     vector<long long int> fact(n + 1, 1), invfact(n + 1, 1);     for (long long int i = 1; i <= n; i++)       fact[i] = (i * (fact[i - 1])) % 1000000007;     for (long long int i = 1; i <= n; i++)       invfact[i] = (modexpo(i, 1000000007 - 2) * invfact[i - 1]) % 1000000007;     return {fact, invfact};   }   void solve() {     long long int n;     cin >> n;     cout << 2 <<   n ;     for (long long int i = 3; i <= n + 1; i++) {       cout << (i * (i) * (i - 1) - (i - 2)) <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     auto start1 = high_resolution_clock::now();     solve();     auto stop1 = high_resolution_clock::now();     auto duration = duration_cast<microseconds>(stop1 - start1);   }


#include <bits/stdc++.h>   using namespace std;   int k;   int n;   int planks[1005];   int g = 0;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> k;     for (int t = 0; t < k; t++) {       cin >> n;       for (int i = 0; i < n; i++) cin >> planks[i];       sort(planks, planks + n, [](int a, int b) { return a > b; });       g = 0;       for (int i = 0; i < n; i++)         if (planks[i] >= i + 1) g = max(g, i + 1);       cout << g <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long A[200005];   long long fast_pow(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b >>= 1;     }     return res;   }   int main() {     long long div = 1, num = 1;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> A[i];       num = (num * A[i]) % 1000000007;     }     sort(A, A + n);     int idx = 0;     bool chk = true;     while (idx < n) {       long long p = A[idx];       long long cnt = 0;       while (idx < n && p == A[idx]) {         idx++;         cnt++;       }       div = (div * (cnt + 1LL)) % (2LL * (1000000007 - 1));       chk = (chk && (cnt % 2 == 0));     }     div = (div % ((1000000007 - 1) * 2LL)) / 2;     long long ans = fast_pow(num, div);     if (chk) {       idx = 0;       while (idx < n) {         long long p = A[idx];         long long cnt = 0;         while (idx < n && p == A[idx]) {           idx++;           cnt++;         }         ans = (ans * fast_pow(p, cnt / 2)) % 1000000007;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     if ((n == 1 && k > 0) || (k == 0 && n > 1) || k < n / 2)       cout << -1;     else if (k == 0)       cout << 1;     else {       int x = k - (n - 2) / 2;       cout << x <<     << x * 2 <<    ;       for (int i = 1; i <= n - 2; ++i) cout << x * 2 + i <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2001000, mod = 998244353;   int n, a[N], b[N], f[N], ans, sum, inv[N];   void Init() {     f[0] = inv[1] = 1;     f[1] = n;     for (int i = 2; i < N; ++i) {       inv[i] = mod - mod / i * (long long)inv[mod % i] % mod;       f[i] = (long long)f[i - 1] * (n - 1 + i) % mod * inv[i] % mod;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     Init();     for (int i = 1; i <= n; ++i) {       cin >> a[i];       ++b[a[i]];     }     for (int i = 0, j = 0; i < n; ++i) {       j += b[i];       if (j >= i + 2) {         cout << (ans + 1) % mod <<   n ;         return 0;       }       ans = (ans + f[i - j + 1]) % mod;     }     memset(b, 0, sizeof b);     ans = 0;     for (int i = 1; i <= n; ++i) sum += a[i] / n, b[a[i] % n]++;     for (int i = 0; i < n; ++i) {       ans = (ans + f[sum]) % mod;       sum -= b[i] - 1;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sum[51], ind[51];   int main() {     for (int i = 1; i <= 50; ++i) sum[i] = i * (i + 1) / 2;     for (int i = 1; i <= 50; ++i) ind[i] = i;     int n, temp, reqind;     cin >> n;     for (int i = 1; i <= 50; ++i) {       if (n <= sum[i]) {         temp = sum[i];         reqind = i;         break;       }     }     int diff = temp - n;     if (diff == 0) {       cout << reqind << endl;       for (int k = 1; k <= reqind; ++k) cout << ind[k] <<    ;       cout << endl;       return 0;     }     cout << reqind - 1 << endl;     for (int i = 1; i <= reqind; ++i) {       if (i != diff) cout << i <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       long long s, f, t;       cin >> s >> f >> t;       if (s == f) {         cout << t << endl;       } else if (s < f) {         long long t1 = s - 1;         while (t1 < t) {           t1 += (m - s) + (m - 1) + (s - 1);         }         t1 += (f - s);         cout << t1 << endl;       } else if (s > f) {         long long t1 = (m - 1) + (m - s);         while (t1 < t) {           t1 += (m - 1) + (m - s) + (s - 1);         }         t1 += (s - f);         cout << t1 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 405;   const int inf = 0x3f3f3f3f;   int n, m;   int a[maxn];   int f[maxn][maxn][maxn];   template <typename T>   inline void minimize(T &target, const T &value) {     if (target > value) {       target = value;     }   }   void divide(int a[], int f[], int g[], int l, int r, int pl, int pr) {     if (l > r) {       return;     }     int m = (l + r) / 2;     int ptr = l;     for (int i = pl; i < min(m, pr + 1); ++i) {       int tmp = max(f[i], a[m] - a[i]);       if (tmp < g[m]) {         g[m] = tmp;         ptr = i;       }     }     divide(a, f, g, l, m - 1, pl, ptr);     divide(a, f, g, m + 1, r, ptr, pr);   }   void compute(int a[], int n, int f[maxn][maxn]) {     f[0][0] = 0;     for (int i = 1; i < n; ++i) {       divide(a, f[i - 1], f[i], 0, n - 1, 0, n - 1);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);     }     memset(f, inf, sizeof(f));     compute(a, n, f[0]);     for (int i = 0; i < n; ++i) {       compute(a + i, n - i, f[i]);     }     long long ans = 0;     while (m--) {       int s, f, c, r;       scanf( %d%d%d%d , &s, &f, &c, &r), s--, f--;       r++;       r = min(r, f - s);       r = max(r, 1);       ans = max(ans, (long long)c * ::f[s][r][f - s]);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> pairs[2 * 100000 + 10];   vector<int> adj[100000 + 10];   bool done[100000 + 10];   int result[100000 + 10];   void check(int N) {     bool adj[N + 2][N + 2];     memset(adj, false, sizeof(adj));     for (int i = 1; i <= 2 * N; i++) {       scanf( %d %d , &pairs[i].first, &pairs[i].second);       adj[pairs[i].first][pairs[i].second] = true;       adj[pairs[i].second][pairs[i].first] = true;     }     int A[N];     for (int i = 0; i < N; i++) A[i] = i + 1;     do {       bool found = true;       for (int i = 0; i < N; i++)         if (!(adj[A[i]][A[(i + 1) % N]] && adj[A[i]][A[(i + 2) % N]]))           found = false;       if (found) {         for (int i = 0; i < N; i++) printf( %d  , A[i]);         printf(  n );         return;       }     } while (next_permutation(A, A + N));     printf( -1 n );   }   bool contains(int a, int b) {     for (int i = 0; i < adj[a].size(); i++)       if (adj[a][i] == b) return true;     return false;   }   int main() {     int N;     scanf( %d , &N);     if (N == 5 || N == 6) {       check(N);       return 0;     }     for (int i = 1; i <= 2 * N; i++) {       scanf( %d %d , &pairs[i].first, &pairs[i].second);       adj[pairs[i].first].push_back(pairs[i].second);       adj[pairs[i].second].push_back(pairs[i].first);     }     int prev = 1;     done[1] = true;     result[0] = 1;     int candidate[4 + 1], counts[4 + 1], num;     for (int i = 1; i <= N; i++)       if (adj[i].size() != 4) {         printf( -1 n );         return 0;       }     for (int i = 1; i < N; i++) {       int num = 0;       for (int j = 0; j < adj[prev].size(); j++) candidate[num++] = adj[prev][j];       memset(counts, 0, sizeof(counts));       for (int j = 0; j < num; j++)         for (int k = 0; k < adj[candidate[j]].size(); k++)           for (int l = 0; l < num; l++)             if (adj[candidate[j]][k] == candidate[l]) counts[l]++;       for (int j = 0; j < num; j++)         if (!done[candidate[j]] && counts[j] >= 2) {           prev = candidate[j];           done[prev] = true;           result[i] = prev;           break;         }     }     for (int i = 1; i <= N; i++)       if (!done[i]) {         printf( -1 n );         return 0;       }     bool found = true;     for (int i = 0; i < N; i++)       if (!(contains(result[i], result[(i + 1) % N]) &&             contains(result[i], result[(i + 2) % N])))         found = false;     if (!found) {       printf( -1 n );       return 0;     }     for (int i = 0; i < N; i++) printf( %d  , result[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   struct Comp {     double re, im;     Comp(double x = 0.0, double y = 0.0) : re(x), im(y) {}     Comp operator+(const Comp& rhs) const {       return Comp(re + rhs.re, im + rhs.im);     }     Comp operator-(const Comp& rhs) const {       return Comp(re - rhs.re, im - rhs.im);     }     Comp operator*(const Comp& rhs) const {       return Comp(re * rhs.re - im * rhs.im, re * rhs.im + im * rhs.re);     }     Comp operator/(double x) const { return Comp(re / x, im / x); }   };   int fft_len, fft_lg;   vector<int> r;   void ensure_base(int deg) {     fft_len = 2, fft_lg = 1;     while (fft_len <= deg) fft_len <<= 1, fft_lg++;     r = vector<int>(fft_len, 0);     for (int i = 0; i < fft_len; ++i)       r[i] = (r[i >> 1] >> 1) | ((i & 1) << (fft_lg - 1));   }   void fft(vector<Comp>& A, int dft) {     for (int i = 0; i < fft_len; ++i)       if (i < r[i]) swap(A[i], A[r[i]]);     for (int mid = 1; mid < fft_len; mid <<= 1) {       Comp wn = Comp(cos(PI / mid), sin(PI / mid) * dft);       for (int len = mid << 1, s = 0; s < fft_len; s += len) {         Comp w(1, 0);         for (int k = 0; k < mid; ++k, w = w * wn) {           Comp x = A[s + k], y = w * A[s + k + mid];           A[s + k] = x + y;           A[s + k + mid] = x - y;         }       }     }     if (dft == -1)       for (int i = 0; i < fft_len; ++i) A[i] = A[i] / fft_len;   }   void fft_pmul(vector<Comp>& A, int degA, vector<Comp>& B, int degB) {     ensure_base(degA + degB);     A.resize(fft_len, 0), B.resize(fft_len, 0);     fft(A, 1);     fft(B, 1);     for (int i = 0; i < fft_len; ++i) A[i] = A[i] * B[i];     fft(A, -1);   }   int p[26], q[26];   string s, t;   int main() {     ios::sync_with_stdio(false);     for (int i = 0; i < 26; ++i) cin >> q[i], p[q[i] - 1] = i;     cin >> t >> s;     int n = s.length(), m = t.length();     reverse(t.begin(), t.end());     vector<Comp> ps1(n), ps2(n), ps3(n), pt1(m), pt2(m), pt3(m);     vector<double> p0(n);     for (int i = 0; i < n; ++i) {       int v = s[i] -  a ;       ps3[i].re = -(2 * v + 2 * p[v]);       ps2[i].re = v * v + 4 * v * p[v] + p[v] * p[v];       ps1[i].re = -2 * v * p[v] * (v + p[v]);       p0[i] = v * v * p[v] * p[v];       if (i) p0[i] += p0[i - 1];     }     double t4 = 0;     for (int i = 0; i < m; ++i) {       int v = t[i] -  a ;       pt3[i].re = v * v * v;       pt2[i].re = v * v;       pt1[i].re = v;       t4 += v * v * v * v;     }     fft_pmul(ps3, n, pt3, m);     fft_pmul(ps2, n, pt2, m);     fft_pmul(ps1, n, pt1, m);     for (int i = m - 1; i < n; ++i) {       double res = t4 + ps3[i].re + ps2[i].re + ps1[i].re + p0[i] -                    (i - m < 0 ? 0 : p0[i - m]);       putchar( 0  + (fabs(res) < 0.8));     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long a[100100], b[100100];   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, m, cl, ce, v, x1, y1, x2, y2, q, mi;     cin >> n >> m >> cl >> ce >> v;     for (long long i = 0; i < cl; i++) cin >> a[i];     for (long long i = 0; i < ce; i++) cin >> b[i];     cin >> q;     while (q--) {       mi = 1e18;       cin >> x1 >> y1 >> x2 >> y2;       swap(x1, y1);       swap(x2, y2);       if (x1 > x2) swap(x1, x2), swap(y1, y2);       long long t = abs(y1 - y2);       if (t == 0) {         cout << abs(x1 - x2) << endl;         continue;       }       long long p = lower_bound(a, a + cl, x1) - a;       if (p != cl) {         if (a[p] <= x2)           mi = min(mi, x2 - x1 + t);         else           mi = min(mi, a[p] - x1 + a[p] - x2 + t);       }       p = upper_bound(a, a + cl, x1) - a;       if (p != 0) mi = min(mi, x2 - a[p - 1] + x1 - a[p - 1] + t);       p = lower_bound(b, b + ce, x1) - b;       if (p != ce) {         if (b[p] <= x2)           mi = min(mi, x2 - x1 + (t % v == 0 ? (t / v) : (t / v + 1)));         else           mi = min(mi,                    b[p] - x2 + b[p] - x1 + (t % v == 0 ? (t / v) : (t / v + 1)));       }       p = upper_bound(b, b + ce, x1) - b;       if (p != 0)         mi = min(mi, x2 - b[p - 1] + x1 - b[p - 1] +                          (t % v == 0 ? (t / v) : (t / v + 1)));       cout << mi << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     string com;     cin >> com;     string s[5];     for (int i = 0; i < 5; i++) {       cin >> s[i];       if (s[i][0] == com[0] || s[i][1] == com[1]) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[200001];   bool vis[200001];   int en = -1;   int a[200005], b[200005];   void dfs(int x) {     vis[x] = 1;     for (auto it = adj[x].begin(); it != adj[x].end(); ++it) {       if (!vis[*it]) {         dfs(*it);       }     }     if (en == -1) en = x;   }   int main() {     int n, m, i, k, l = 0, ans = 0;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       adj[i].push_back(a[i]);     }     int flag = 0;     for (i = 1; i <= n; i++) {       cin >> b[i];       if (b[i]) flag++;     }     if (!flag)       ans++;     else if (flag % 2 == 0)       ans++;     int temp = -1;     for (i = 1; i <= n; i++) {       if (!vis[i]) {         temp = en;         en = -1;         dfs(i);         adj[en].clear();         if (temp > 0) {           ans++;           adj[temp].push_back(i);         }       }     }     if (temp != -1) {       adj[en].push_back(1);       ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p;   long long fac[250005], ans;   int main() {     scanf( %d%d , &n, &p);     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;     for (int i = 1; i <= n; i++)       ans = (ans + fac[n - i + 1] * (n - i + 1) % p * fac[i] % p) % p;     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long s[n];     for (long long c = 0; c < n; c++) cin >> s[c];     long long sum = 0;     long long nextAllowedNum = 10000000000000 + 33;     for (long long c = n - 1; c >= 0; c--) {       if (nextAllowedNum <= 0) break;       long long takeval = 0;       takeval = s[c] <= nextAllowedNum ? s[c] : nextAllowedNum;       nextAllowedNum = takeval - 1;       sum += takeval;     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void vin(vector<long long int> &v, long long int t) {     for (long long int i = 0; i < t; i++) cin >> v[i];   }   void vout(vector<long long int> &v, long long int t) {     for (long long int i = 0; i < t; i++) cout << v[i] <<    ;     cout << endl;   }   void ingraph(vector<vector<long long int>> &graph, long long int m) {     long long int x, y;     for (long long int i = 0; i < m; i++) {       cin >> x >> y;       x--, y--;       graph[x].push_back(y);       graph[y].push_back(x);     }   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return a * b / gcd(a, b);   }   void solve() {     long long int n, m, x, y;     cin >> n >> m >> x >> y;     long long int cost = 0;     y = min(y, 2 * x);     for (long long int i = 0; i < n; i++) {       string s;       cin >> s;       for (long long int j = 0; j < m; j++) {         if (s[j] ==  . ) {           if (j != m - 1 && s[j + 1] ==  . )             cost += y, j++;           else             cost += x;         }       }     }     cout << cost <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int gi() {     char c = getchar();     int x = 0, f = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) x = (x << 1) + (x << 3) + c -  0 ;     return x * f;   }   const int N = 5e5 + 5, Mod = 1e9 + 7;   int x[N], y[N], n;   long long ara, sx[N], sy[N], ssum[N], ans;   long long sum[N];   long long cross(int i, int j) { return 1ll * x[i] * y[j] - 1ll * x[j] * y[i]; }   long long cross(long long x1, long long y1, long long x2, long long y2,                   bool b = true) {     if (!b) return x1 * y2 - x2 * y1;     x1 %= Mod, y1 %= Mod;     return (x1 * y2 - x2 * y1) % Mod;   }   int main() {     n = gi();     for (int i = 1; i <= n; ++i) x[i] = gi(), y[i] = gi();     for (int i = 3; i <= n; ++i)       ara += cross(x[i] - x[1], y[i] - y[1], x[i - 1] - x[1], y[i - 1] - y[1], 0);     for (int i = 2; i <= n; ++i)       sum[i] = sum[i - 1] + cross(i, i - 1),       ssum[i] = (ssum[i - 1] + sum[i]) % Mod;     for (int i = 1; i <= n; ++i)       sx[i] = sx[i - 1] + x[i], sy[i] = sy[i - 1] + y[i];     for (int i = 1, j = 0; i <= n; ++i) {       for (j = max(j, i + 2); j <= n - (i == 1); ++j)         if (2ull * (sum[j] - sum[i] - cross(j, i)) > ara) break;       const int m = n - (i == 1);       int tmp = 0;       tmp = (ssum[j - 1] - ssum[i + 1] - sum[i] % Mod * (j - i - 2)) % Mod;       tmp = (tmp -              cross(sx[j - 1] - sx[i + 1], sy[j - 1] - sy[i + 1], x[i], y[i])) %             Mod;       ans = (ans + ara % Mod * (j - i - 2) % Mod - 2 * tmp % Mod + Mod) % Mod;       if (j > m) continue;       tmp = (ssum[m] - ssum[j - 1] - sum[i] % Mod * (m - j + 1)) % Mod;       tmp = (tmp - cross(sx[m] - sx[j - 1], sy[m] - sy[j - 1], x[i], y[i])) % Mod;       ans = ((ans + tmp * 2 - ara % Mod * (m - j + 1) % Mod) % Mod + Mod) % Mod;     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 7, inf = 1e9;   long long n, m, cnt, ans;   long long a[N], b[N], c[N], tr[N];   long long lowbit(long long x) { return x & -x; }   long long query(long long x) {     long long sum = 0;     for (; x; x -= lowbit(x)) sum += tr[x];     return sum;   }   void add(long long x) {     for (; x <= cnt; x += lowbit(x)) tr[x]++;   }   long long check(long long x) {     long long sum = 0;     add(lower_bound(b + 1, b + cnt + 1, 0) - b);     for (long long i = 1; i <= n; i++) {       if (a[i] - x < b[1])         sum += i;       else if (a[i] - x > b[cnt])         ;       else {         long long pos = lower_bound(b + 1, b + cnt + 1, a[i] - x) - b;         if (b[pos] > a[i] - x) pos--;         sum += i - query(pos);       }       add(c[i]);     }     return sum;   }   signed main() {     scanf( %lld%lld , &n, &m);     for (long long i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (long long i = 1; i <= n; i++) a[i] = a[i - 1] + a[i], b[i] = a[i];     b[n + 1] = 0;     sort(b + 1, b + n + 2);     cnt = unique(b + 1, b + n + 2) - b - 1;     for (long long i = 1; i <= n; i++)       c[i] = lower_bound(b + 1, b + cnt + 1, a[i]) - b;     printf( %lld n , check(m));   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6 + 10;   long long n, k, A[maxn];   int32_t main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (long long i = 0; i < n; i++) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       if (a > b * c) {         cout << -1 << endl;         continue;       }       long long e = (a + d * b - 1) / (d * b);       cout << e * a - (e * (e - 1ll) / 2ll * d * b) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct Boot {     int _pos;     char _char;   };   struct PairBoots {     Boot _left;     Boot _right;   };   int main() {     int n;     string leftBoots;     string rightBoots;     vector<vector<Boot>> leftBootsBucket(27);     vector<vector<Boot>> rightBootsBucket(27);     vector<PairBoots> ans;     cin >> n;     cin.ignore();     getline(cin, leftBoots);     getline(cin, rightBoots);     for (int i = 0; i < n; i++) {       Boot leftBoot;       leftBoot._pos = i;       leftBoot._char = leftBoots[i];       if (leftBoot._char ==  ? )         leftBootsBucket[26].push_back(leftBoot);       else         leftBootsBucket[leftBoots[i] -  a ].push_back(leftBoot);       Boot rightBoot;       rightBoot._pos = i;       rightBoot._char = rightBoots[i];       if (rightBoot._char ==  ? )         rightBootsBucket[26].push_back(rightBoot);       else         rightBootsBucket[rightBoots[i] -  a ].push_back(rightBoot);     }     for (int i = 0; i < 27; i++) {       for (int j = 0;            j < leftBootsBucket[i].size() || j < rightBootsBucket[i].size(); j++) {         PairBoots temp;         if (j < leftBootsBucket[i].size() && j < rightBootsBucket[i].size()) {           temp._left = leftBootsBucket[i][j];           temp._right = rightBootsBucket[i][j];         } else {           if (j < leftBootsBucket[i].size()) {             if (rightBootsBucket[26].size() != 0) {               temp._left = leftBootsBucket[i][j];               temp._right = rightBootsBucket[26][rightBootsBucket[26].size() - 1];               rightBootsBucket[26].pop_back();               goto here;             }           }           if (j < rightBootsBucket[i].size()) {             if (leftBootsBucket[26].size() != 0) {               temp._left = leftBootsBucket[26][leftBootsBucket[26].size() - 1];               temp._right = rightBootsBucket[i][j];               leftBootsBucket[26].pop_back();               goto here;             }           }           break;         }       here:         ans.push_back(temp);       }     }     cout << ans.size() <<   n ;     for (auto i : ans) {       cout << i._left._pos + 1 <<     << i._right._pos + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   bool choice_first(std::vector<size_t> a, std::vector<size_t> b) {     uint64_t sum_a, sum_b;     sum_a = sum_b = 0;     for (auto elem : a) {       sum_a += elem;     }     for (auto elem : b) {       sum_b += elem;     }     return sum_a > sum_b || (sum_a == sum_b && a < b);   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(0);     std::cout.tie(0);     size_t n, m;     std::cin >> n;     std::vector<std::vector<std::vector<size_t>>> dp(         n + 1, std::vector<std::vector<size_t>>(n + 1));     std::vector<size_t> a(n);     for (size_t i = 0; i < n; i++) {       std::cin >> a[i];     }     std::cin >> m;     for (size_t i = 0; i < n; i++) {       if (i == 0) {         dp[1][i] = {a[0]};         continue;       }       dp[1][i] = std::max(std::vector<size_t>{a[i]}, dp[1][i - 1]);     }     for (size_t i = 2; i <= n; i++) {       for (size_t j = i - 1; j < n; j++) {         if (j == i - 1) {           std::vector<size_t> cur = dp[i - 1][j - 1];           cur.push_back(a[j]);           dp[i][j] = cur;           continue;         }         std::vector<size_t> first, second;         first = dp[i - 1][j - 1];         first.push_back(a[j]);         second = dp[i][j - 1];         if (choice_first(first, second)) {           dp[i][j] = first;         } else {           dp[i][j] = second;         }       }     }     for (size_t i = 0; i < m; i++) {       size_t k, pos;       std::cin >> k >> pos;       std::cout << dp[k][n - 1][pos - 1] <<   n ;     }   }