#define DEBUG 0      #include <bits/stdc++.h>   using namespace std;      #if DEBUG   // basic debugging macros   int __i__,__j__;   #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<< - ;}cout<<endl   #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl   #define printVar(n) cout<<#n<< :  <<n<<endl   #define printArr(a,l) cout<<#a<< :  ;for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<   ;}cout<<endl   #define print2dArr(a,r,c) cout<<#a<< : n ;for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<   ;}cout<<endl;}   #define print2dArr2(a,r,c,l) cout<<#a<< : n ;for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(   )<<a[__i__][__j__]<<   ;}cout<<endl;}      // advanced debugging class   // debug 1,2, A , test ;   class _Debug {       public:           template<typename T>           _Debug& operator,(T val) {               cout << val << endl;               return *this;           }   };   #define debug _Debug(),   #else   #define printLine(l)   #define printLine2(l,c)   #define printVar(n)   #define printArr(a,l)   #define print2dArr(a,r,c)   #define print2dArr2(a,r,c,l)   #define debug   #endif      // define   #define MAX_VAL 999999999   #define MAX_VAL_2 999999999999999999LL   #define EPS 1e-6   #define mp make_pair   #define pb push_back      // typedef   typedef unsigned int UI;   typedef long long int LLI;   typedef unsigned long long int ULLI;   typedef unsigned short int US;   typedef pair<int,int> pii;   typedef pair<LLI,LLI> plli;   typedef vector<int> vi;   typedef vector<LLI> vlli;   typedef vector<pii> vpii;   typedef vector<plli> vplli;      // ---------- END OF TEMPLATE ----------      int p[200001],k[200001],b[200001],w[200001];   int seed = 0,base = 0;   int rnd() {       int ret = seed;       seed = ((LLI) seed*base + 233) % 1000000007;       return ret;   }   int a[5000000],o[5000000],t[5000000];   int main() {       int i,j;       int n,m;       scanf( %d %d ,&n,&m);       for (i = 1; i <= m; i++) {           scanf( %d %d %d %d ,&p[i],&k[i],&b[i],&w[i]);           seed = b[i],base = w[i];           for (j = p[i-1]; j < p[i]; j++) {               t[j] = (rnd() % 2) + 1;               o[j] = a[j] = (rnd() % k[i]) + 1;           }       }          LLI s1 = 0,s2 = 0;       for (i = 0; i < n; i++) {           if (t[i] == 1) s1 += a[i];           else s2 += a[i];       }       if (s1 <= s2) {           for (i = 0; i < n; i++) t[i] ^= 3;       }       if (t[0] == 1) a[0]--;       LLI s = 0;       for (i = 0; i < n; i++) {           if (t[i] == 2) s += a[i],a[i] = 0;           else {               LLI x = min((LLI) a[i],s);               a[i] -= x,s -= x;           }       }       for (i = 0; i < n; i++) {           if (t[i] == 2) s += a[i],a[i] = 0;           else {               LLI x = min((LLI) a[i],s);               a[i] -= x,s -= x;           }       }       LLI ans = 1;       for (i = 0; i < n; i++) {           ans *= (((o[i]-a[i])^((LLI) (i+1)*(i+1)))+1) % 1000000007;           ans %= 1000000007;       }       printf( %I64d n ,ans);          return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   const long long xx = 2e5 + 10;   vector<long long> pos[xx];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m, k;     cin >> n >> m >> k;     vector<long long> v(n);     vector<pair<long long, long long>> pi;     for (long long i = 0; i < n; i++) {       cin >> v[i];       pi.emplace_back(v[i], i);     }     sort(pi.rbegin(), pi.rend());     vector<pair<long long, long long>> vp;     long long sum = 0;     for (long long i = 0; i < m * k; i++) {       sum += pi[i].first;       vp.emplace_back(pi[i].second, pi[i].first);     }     sort(vp.begin(), vp.end());     cout << sum <<   n ;     for (long long i = m - 1; i < vp.size() - m; i += m) {       long long x = vp[i].first;       cout << x + 1 <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100010], mx1 = -100010, mx2 = -100010 - 10, ans = 1, cnt[100010];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       if (a[i] > mx1) {         mx2 = mx1;         mx1 = a[i];         cnt[a[i]]--;       } else if (a[i] > mx2) {         mx2 = a[i];         cnt[mx1]++;       }     }     for (int i = 1; i <= n; i++)       if (cnt[i] > cnt[ans]) ans = i;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool visited[10000];   int main() {     ios::sync_with_stdio(false);     ios_base::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     string input;     int counter;     while (cin >> input) {       counter = 0;       for (int i = 0; i < input.size() - 1; i++)         if (input[i] ==  V  && input[i + 1] ==  K )           counter++, visited[i] = visited[i + 1] = 1, i++;       for (int i = 0; i < input.size() - 1; i++)         if (!visited[i] && !visited[i + 1])           if ((input[i] ==  V  && input[i + 1] ==  V ) ||               ((input[i] ==  K  && input[i + 1] ==  K ))) {             counter++;             break;           }     }     cout << counter << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   template <class T>   inline T SQR(T a) {     return a * a;   }   int C[100001][3];   bool can(int *A, int n, int k) {     int pos = k;     for (int i = (0), ei = (k); i < ei; i++) C[i][0] = A[i];     int cnt = 0;     while (pos < n && cnt < k) {       if (A[pos] < C[cnt][0]) C[cnt++][1] = A[pos];       pos++;     }     if (cnt != k) return false;     cnt = 0;     while (pos < n && cnt < k) {       if (A[pos] < C[cnt][1]) C[cnt++][2] = A[pos];       pos++;     }     return cnt == k;   }   int main() {     int n;     int A[100001];     cin >> n;     for (int i = (0), ei = (n); i < ei; i++) scanf( %d , A + i);     sort(A, A + n, greater<int>());     int l = 0, r = n / 3;     int ans = 0;     while (l <= r) {       int c = (l + r) >> 1;       if (can(A, n, c)) {         l = c + 1;         ans = c;       } else         r = c - 1;     }     can(A, n, ans);     printf( %d n , ans);     for (int i = (0), ei = (ans); i < ei; i++)       printf( %d %d %d n , C[i][0], C[i][1], C[i][2]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX_N = 4e3 + 10;   const long long MAX_M = 65 + 10;   const long long mod = 1e9 + 7;   const int INF = 1e9;   inline long long bpow(long long t, long long n) {     long long ans = 1;     while (n > 0) {       if (n & 1) ans = (ans * t) % mod;       t = (t * t) % mod, n >>= 1;     }     return ans;   }   int dp[MAX_N][MAX_M][MAX_M][2];   int a[MAX_N];   int cdp(int l, int r, int k, int x) {     if ((r - l + 1) < k) return 0;     if (dp[l][r - l][k][x] != -1) return dp[l][r - l][k][x];     int& ans = dp[l][r - l][k][x];     if (x == 0)       ans = max(cdp(l + k, r, k, 1) + a[l + k - 1] - a[l - 1],                 (r - l >= k) ? (a[l + k] - a[l - 1] + cdp(l + k + 1, r, k + 1, 1))                              : (-INF));     else       ans = min(a[r - k] - a[r] + cdp(l, r - k, k, 0),                 (r - l >= k) ? (a[r - k - 1] - a[r] + cdp(l, r - k - 1, k + 1, 0))                              : INF);     return ans;   }   int main() {     memset(dp, -1, sizeof dp);     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cout << fixed << setprecision(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) a[i] += a[i - 1];     cout << cdp(1, n, 1, 0);   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int mod = 1e9 + 7;   template <class X>   void print(X a) {     cout << a << endl;     exit(0);   }   long long n, k, m;   vector<pair<long long, long long> > reduce(       vector<pair<long long, long long> >& a) {     vector<pair<long long, long long> > b;     pair<long long, long long> last = {-1, -1};     for (auto& x : a) {       if (last.first == x.first)         b.back().second += x.second;       else         b.push_back(x);       if (b.back().second % k == 0) b.pop_back();       if (!b.empty())         last = b.back();       else         last = {-1, -1};     }     for (auto& x : b) x.second %= k;     return b;   }   int main() {     time_t t1, t2;     t1 = clock();     ios_base::sync_with_stdio(0);     cin >> n >> k >> m;     long long faltu[n + 1];     for (int i = 1; i <= n; i++) cin >> faltu[i];     vector<pair<long long, long long> > a;     int i = 1;     while (i <= n) {       int j = i;       for (j = i; j <= n; j++) {         if (faltu[j] != faltu[i]) break;       }       a.push_back({faltu[i], j - i});       i = j;     }     long long sum = 0;     a = reduce(a);     for (auto& x : a) sum += x.second;     long long total = sum * m;     __f( total , total);     int finish_idx = -1;     for (int i = 0, j = a.size() - 1; i < (int)a.size(); i++, j--) {       if (a[i].first != a[j].first or a[i].second + a[j].second != k) {         finish_idx = i;         break;       }     }     if (finish_idx == -1) {       if (m & 1)         cout << sum << endl;       else         cout << 0 << endl;     } else {       long long to_sub = 0;       long long start_sub = 0, end_sub = 0;       long long left_over = 0;       long long c;       for (int i = 0, j = a.size() - 1; i <= finish_idx; i++, j--) {         if (i == finish_idx and a[i].first != a[j].first)           break;         else if (i == finish_idx and a[i].first == a[j].first and                  a[i].second + a[j].second < k)           break;         else if (i == finish_idx)           left_over = (a[i].second + a[j].second) % k;         to_sub += (a[i].second + a[j].second);         start_sub += a[i].second;         end_sub += a[j].second;       }       to_sub *= m;       long long ans = total - to_sub;       ans += start_sub + end_sub;       ans += left_over * (m - 1);       if ((int)a.size() & 1 and finish_idx == (int)a.size() / 2) {         vector<pair<long long, long long> > new_a;         for (int i = 0; i < (int)a.size(); i++) {           if (i == finish_idx)             new_a.push_back({a[i].first, a[i].second * m});           else             new_a.push_back(a[i]);         }         new_a = reduce(new_a);         ans = 0;         for (auto& x : new_a) {           ans += x.second;         }       }       cout << ans << endl;     }     t2 = clock();     cerr <<  time taken:   << t2 - t1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     double x;     double y;     Point(double _x = 0, double _y = 0) : x(_x), y(_y) {}     double length() const { return sqrt(x * x + y * y); }     double distance(const Point& other) const {       return Point(x - other.x, y - other.y).length();     }   };   Point operator+(const Point& first, const Point& second) {     return Point(first.x + second.x, first.y + second.y);   }   Point operator-(const Point& first, const Point& second) {     return Point(first.x - second.x, first.y - second.y);   }   double vector_product(const Point& first, const Point& second) {     return first.x * second.y - first.y * second.x;   }   double scalar_product(const Point& first, const Point& second) {     return first.x * second.x + first.y * second.y;   }   struct Segment {     Point A;     Point B;     Segment() {}     Segment(const Point& _A, const Point& _B) : A(_A), B(_B) {}     double length() const;     double distance(const Point& C) const;     double distance(const Segment& S) const;   };   double Segment::length() const {     double dx = B.x - A.x;     double dy = B.y - A.y;     return sqrt(dx * dx + dy * dy);   }   double Segment::distance(const Point& C) const {     if (scalar_product(C - A, B - A) < 0 || scalar_product(C - B, A - B) < 0) {       return min(Segment(A, C).length(), Segment(B, C).length());     } else {       return fabs(vector_product(C - A, B - A)) / length();     }   }   double Segment::distance(const Segment& S) const {     double r = distance(S.A);     r = min(r, distance(S.B));     r = min(r, S.distance(A));     r = min(r, S.distance(B));     return r;   }   struct Arc {     int head;     double weight;     Arc() : head(-1), weight(0) {}     Arc(int to, double label) : head(to), weight(label) {}   };   enum VertexColor { WHITE = 0, GRAY, BLACK };   const double INF = 1000000000;   void dijkstra_on_array(const std::vector<std::vector<Arc> >& graph, int source,                          vector<double>& distance) {     vector<int> color(graph.size(), WHITE);     color[source] = GRAY;     distance.assign(graph.size(), INF);     distance[source] = 0;     for (int step = 0; step < graph.size(); ++step) {       int min_gray_vertex = 0;       double min_distance_to_gray = INF;       for (int vertex = 0; vertex < graph.size(); ++vertex) {         if (color[vertex] == GRAY && distance[vertex] < min_distance_to_gray) {           min_gray_vertex = vertex;           min_distance_to_gray = distance[vertex];         }       }       if (min_distance_to_gray == INF) {         break;       }       color[min_gray_vertex] = BLACK;       for (int arc_index = 0; arc_index < graph[min_gray_vertex].size();            ++arc_index) {         const Arc& arc = graph[min_gray_vertex][arc_index];         if (color[arc.head] != BLACK &&             distance[arc.head] > min_distance_to_gray + arc.weight) {           color[arc.head] = GRAY;           distance[arc.head] = min_distance_to_gray + arc.weight;         }       }     }   }   int main() {     double a, b;     cin >> a >> b;     Point A, B;     cin >> A.x >> A.y >> B.x >> B.y;     int n;     cin >> n;     vector<Segment> segments(n);     for (int i = 0; i < n; ++i) {       cin >> segments[i].A.x >> segments[i].A.y >> segments[i].B.x >>           segments[i].B.y;     }     std::vector<std::vector<Arc> > g(n + 2);     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         if (segments[i].distance(segments[j]) <= a + 1e-9) {           g[i].push_back(Arc(j, a + b));           g[j].push_back(Arc(i, a + b));         }       }     }     for (int i = 0; i < n; ++i) {       double da = segments[i].distance(A);       double db = segments[i].distance(B);       if (da <= a + 1e-9) {         g[n].push_back(Arc(i, a + b));       }       if (db <= a + 1e-9) {         g[i].push_back(Arc(n + 1, db));       }     }     if (A.distance(B) <= a + 1e-9) {       cout.precision(8);       cout << fixed << A.distance(B) << endl;     } else {       vector<double> d;       dijkstra_on_array(g, n, d);       if (d[n + 1] == INF) {         cout << -1 << endl;       } else {         cout.precision(8);         cout << fixed << d[n + 1] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;      typedef long long ll;   const int maxn=1e6+7;   const int inf=2e9;   const ll inff=1e18;   const ll mod=1e9+7;   #define pii pair<int,int>   #define mkp make_pair   #define F first   #define S second   #define pb push_back   #define sz(v) ((int)(v).size())   #define all(v) (v).begin(),(v).end()   //#define int ll      int32_t main(){    ios::sync_with_stdio(0); cin.tie(0);       int t; cin>>t;       while (t--) {           int n; cin>>n;           vector<int> v(n);           for (int &i:v) cin>>i;           sort(all(v));              ll ans=0;           for (int i=1;i<n;i++) ans+=(v[i]-v[i-1]);           for (int i=1;i<n;i++) {               ans-=i*1LL*(n-i)*(v[i]-v[i-1]);           }           cout<<ans<<  n ;       }   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   bool f(long long x, long long y, long long z) {     if ((k - x - y - z) < 0 || (k - x - y - z) % 3 != 0) return false;     long long m = max(x, max(y, z)), p = n - (k + 3 * m - (x + y + z));     if (p < 0 || p % 3 != 0) return false;     return true;   }   int main() {     int t;     ios_base::sync_with_stdio(0);     cin >> t;     for (int i = 0; i < t; i++) {       long long d1, d2;       cin >> n >> k >> d1 >> d2;       long long d = max(d1, d2);       if (f(0ll, d1, d1 + d2) || f(d1 + d2, d2, 0ll) || f(d1, 0ll, d2) ||           f(d - d1, d, d - d2))         cout <<  yes  << endl;       else         cout <<  no  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int N, K, S;   int q[153];   vector<vector<int> > prev_, next_;   const int INF = 1e9;   int main() {     scanf( %d%d%d , &N, &K, &S);     S = min(S, N * (N - 1) / 2);     for (int i = 1; i <= N; i++) scanf( %d , &q[i]);     prev_ = vector<vector<int> >(K + 1, vector<int>(S + 1, INF));     prev_[0][0] = 0;     for (int i = 1; i <= N; i++) {       next_ = prev_;       for (int j = 1; j <= min(K, i); j++)         for (int k = 0; k <= S; k++) {           if (k + abs(i - j) <= S)             next_[j][k + abs(i - j)] =                 min(next_[j][k + abs(i - j)], prev_[j - 1][k] + q[i]);         }       swap(prev_, next_);     }     int ans = INF;     for (int i = 0; i <= S; i++) ans = min(ans, prev_[K][i]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const double eps = 1e-9;   const double INF = inf;   const double EPS = eps;   vector<long long> V;   int cmp(long long b, long double d, long long a) {     if (d > 2e18) return 1;     if (b > a) return 1;     if (b == a) return 0;     return -1;   }   int calc(long long n, long long p, long long k) {     long double d = (2.0 * k + 1.0) * (k + p - 1ll);     long long l = (2ll * k + 1) * (k + p - 1ll);     return cmp(l, d, n);   }   void solve(long long n, long long p) {     p = (1ll << p);     if (p - 1 > n) return;     long long l = 0, r = n + 1;     while (r - l > 1) {       long long m = (l + r) / 2;       (calc(n, p, m) <= 0) ? (l = m) : (r = m);     }     if (calc(n, p, l) == 0) V.push_back(p * (2ll * l + 1ll));   }   int main() {     long long n;     int i;     scanf( %I64d , &n);     for (i = 0; i < 60; i++) solve(n, i);     sort(V.begin(), V.end());     if (!V.size()) {       puts( -1 );       return 0;     }     for (i = 0; i < (int)V.size(); i++) printf( %I64d n , V[i]);     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double sn = 1e-6;   int n;   int arr[35];   int res;   bool visited[310][310];   bool notAgain[310][310][35][8];   pair<int, int> dirs[8] = {{0, 1},  {1, 1},   {1, 0},  {1, -1},                             {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}};   void dfs(int dir, int sx, int sy, int sc) {     if (notAgain[sx][sy][sc][dir]) return;     notAgain[sx][sy][sc][dir] = true;     for (int i = 0; i < arr[sc]; i++) {       sx += dirs[dir].first;       sy += dirs[dir].second;       if (!visited[sx][sy]) {         visited[sx][sy] = true;         res++;       }     }     if (sc < n - 1) {       dfs(dir != 7 ? dir + 1 : 0, sx, sy, sc + 1);       dfs(dir != 0 ? dir - 1 : 7, sx, sy, sc + 1);     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     dfs(0, 155, 155, 0);     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const signed long long int LINF = LLONG_MAX;   const double EPS = 1e-9;   const int MOD = 1000000007;   const int MAXN = 100001;   const int ALPH = 26;   const int DALPH = 52;   int q;   map<string, string> match, rmatch;   set<string> current;   int main() {     scanf( %d , &q);     while (q--) {       string s1, s2;       cin >> s1 >> s2;       if (current.find(s1) == current.end()) {         current.insert(s2);         match[s1] = s2;         rmatch[s2] = s1;       } else {         current.erase(s1);         current.insert(s2);         match[rmatch[s1]] = s2;         rmatch[s2] = rmatch[s1];         rmatch.erase(s1);       }     }     printf( %d n , (int)(match).size());     for (pair<string, string> p : match) {       cout << p.first <<     << p.second <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2005, maxm = 200005;   vector<int> g[maxn];   int tmp, vis[maxn], dis[maxn], mp[maxn][maxn];   int n, m, ans, cnt, tot, res, ecnt, info[maxn], nx[maxm], v[maxm];   int id, en, dfn[maxn], low[maxn], ori[maxn], sta[maxn], outd[maxn];   void add(int u1, int v1) {     nx[++ecnt] = info[u1];     info[u1] = ecnt;     v[ecnt] = v1;   }   void targin(int x, int fa) {     dfn[x] = low[x] = ++id;     sta[++en] = x;     for (int i = info[x]; i; i = nx[i]) {       if (v[i] == fa) continue;       if (!dfn[v[i]])         targin(v[i], x), low[x] = min(low[x], low[v[i]]);       else         low[x] = min(low[x], dfn[v[i]]);     }     if (low[x] == dfn[x]) {       int v;       cnt++;       do v = sta[en--], ori[v] = cnt;       while (v != x);     }   }   void dfs(int x, int fa) {     vis[x] = 1;     dis[x] = dis[fa] + 1;     if (dis[tmp] < dis[x]) tmp = x;     for (int i = 0, lim = g[x].size(); i < lim; i++)       if (g[x][i] != fa) dfs(g[x][i], x);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1, u1, v1; i <= m; i++)       scanf( %d%d , &u1, &v1), add(u1, v1), add(v1, u1);     for (int i = 1; i <= n; i++)       if (!dfn[i]) targin(i, 0);     if (cnt == 1) {       printf( %d n , n - 1);       return 0;     }     for (int x = 1; x <= n; x++)       for (int i = info[x]; i; i = nx[i])         if (!mp[ori[x]][ori[v[i]]] && ori[x] != ori[v[i]]) {           mp[ori[x]][ori[v[i]]] = 1;           g[ori[x]].push_back(ori[v[i]]);           outd[ori[x]]++;         }     for (int i = 1; i <= cnt; i++)       if (outd[i] == 1) res++;     for (int i = 1, p1, p2; i <= cnt; i++)       if (!vis[i]) {         tot++;         tmp = 0;         dfs(i, 0);         p1 = tmp;         tmp = 0;         dfs(p1, 0);         p2 = tmp;         if (dis[p2] < 2)           res++;         else           res += dis[p2] - 2;       }     printf( %d n , n - res + tot - 1);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int M = 5e3 + 10;   const int mod = 1e9 + 7;   int cnt[M][M];   void init() {     for (int i = 1; i < M; i++) {       int p = i;       for (int j = 1; j <= i; j++) cnt[i][j] = cnt[i - 1][j];       for (int j = 2; j <= p; j++) {         if (p % j == 0) {           while (p % j == 0) p /= j, cnt[i][j]++;         }       }     }   }   int n, f[M], v[M], siz[M];   int main() {     init();     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       v[x]++;     }     long long ans = 0;     for (int i = 1; i < M; i++)       for (int j = 1; j <= i; j++)         if (cnt[i][j]) f[i] = j, ans += 1ll * v[i] * cnt[i][j];     while (1) {       memset(siz, 0, sizeof(siz));       for (int i = 1; i < M; i++) siz[f[i]] += v[i];       int mx = 0, pl = 1;       for (int i = 1; i < M; i++)         if (siz[i] > mx) {           mx = siz[i];           pl = i;         }       if (pl == 1) break;       if (2 * mx <= n) break;       ans = ans + n - 2 * mx;       for (int i = 1; i < M; i++) {         if (f[i] != pl)           f[i] = 1;         else {           cnt[i][f[i]]--;           while (!cnt[i][f[i]] && f[i] > 1) f[i]--;         }       }     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   inline istream& operator>>(istream& fin, pair<T1, T2>& pr) {     fin >> pr.first >> pr.second;     return fin;   }   template <class T0, class T1, class T2>   inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) {     fin >> get<0>(t) >> get<1>(t) >> get<2>(t);     return fin;   }   template <class T>   inline istream& operator>>(istream& fin, vector<T>& a) {     for (auto& u : a) fin >> u;     return fin;   }   template <class T, size_t n>   inline istream& operator>>(istream& fin, array<T, n>& a) {     for (auto& u : a) fin >> u;     return fin;   }   void f538() {     size_t n;     cin >> n;     vector<int> a(n);     cin >> a;     vector<int> acc(n);     for (size_t j = 1; j < n; ++j)       if (a[j] < a[0]) ++acc[j];     for (size_t i = 1; i < n; ++i)       for (size_t l = i + 1, r = i + 2, k = 1; r - i - 1 < n;            l += i, r += i + 1, ++k)         for (size_t j = max(l, r - i - 1); j < min(r, n); ++j)           if (a[j] < a[i]) ++acc[k], --acc[(j + i - 1) / i];     partial_sum(begin(acc) + 1, end(acc), ostream_iterator<int>(cout,    ));   }   int main(const int argc, char* argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     f538();     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   typedef vector<int> vi;   typedef pair<int, int> ii;   using namespace std;   int n, q, len = 0, nxt[100005], nxtb[100005], disb[100005];   int main() {     int a, b, c, op;     scanf( %d%d , &n, &q);     len = n / 327 + 1;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a);       if (i + a <= n)         nxt[i] = i + a;       else         nxt[i] = n + 1;     }     for (int i = 1; i <= n; i += 327) {       b = min(n, i + 327 - 1);       for (int j = b; j >= i; --j) {         if (nxt[j] <= b) {           nxtb[j] = nxtb[nxt[j]];           disb[j] = disb[nxt[j]] + 1;         } else {           nxtb[j] = j;           disb[j] = 1;         }       }     }     while (q--) {       scanf( %d , &op);       if (op == 0) {         scanf( %d%d , &a, &b);         if (a + b <= n)           nxt[a] = a + b;         else           nxt[a] = n + 1;         b = a / 327 * 327;         c = min(n, b + 327);         for (int i = a; i > b; --i) {           if (nxt[i] <= c) {             nxtb[i] = nxtb[nxt[i]];             disb[i] = disb[nxt[i]] + 1;           } else {             nxtb[i] = i;             disb[i] = 1;           }         }       } else if (op == 1) {         scanf( %d , &a);         b = disb[a];         a = nxtb[a];         while (nxt[a] <= n) {           b += disb[nxt[a]];           a = nxtb[nxt[a]];         }         printf( %d %d n , a, b);       } else         assert(0);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)(1e9 + 7);   bool check(pair<int, int> a, pair<int, int> b) { return (a.first < b.first); }   int main() {     int t;     cin >> t;     while (t--) {       int m, n;       cin >> m >> n;       int a[31][31];       pair<int, int> x[65];       for (int i = 0; i < 65; i++) {         x[i] = {0, 0};       }       for (int i = 1; i <= m; i++) {         for (int j = 1; j <= n; j++) {           cin >> a[i][j];         }       }       for (int i = 1; i <= m; i++) {         for (int j = 1; j <= n; j++) {           x[i + j].first += a[i][j];           x[i + j].second++;         }       }       int sum = 0;       for (int i = 2; 2 * i <= m + n + 1; i++) {         sum += min(x[i].first + x[m + n + 2 - i].first,                    x[i].second + x[m + n + 2 - i].second -                        (x[i].first + x[m + n + 2 - i].first));       }       cout << sum << endl;     }   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   const int mod = 1000000007;   const int inf = 2012345678;   const long long infl = 9012345678901234567;   const double pi = 3.1415926535897932384626433832795;   struct rat {     long long a, b;     rat(long long _a = 0, long long _b = 1) {       if (_b < 0) _a = -_a, _b = -_b;       a = _a;       b = _b;     }     bool operator<(const rat& ot) const { return a * ot.b < ot.a * b; }     rat operator-() const { return rat(-a, b); }     bool operator==(const rat& ot) const { return a * ot.b == ot.a * b; }   };   const int N = 100000;   const int LG = 17;   vector<int> adj[N];   int rnk[N], up[N], anc[N][LG], down[N], hvc[N], cnt[N];   void dfs0(int u) {     cnt[u] = 1;     hvc[u] = -1;     for (auto& x : adj[u]) {       if (x == anc[u][0]) continue;       rnk[x] = rnk[u] + 1;       anc[x][0] = u;       dfs0(x);       cnt[u] += cnt[x];       if (hvc[u] == -1 || cnt[x] > cnt[hvc[u]]) hvc[u] = x;     }   }   void dfs1(int u, bool hv) {     if (hv)       up[u] = u;     else       up[u] = up[anc[u][0]];     if (hvc[u] == -1) {       down[u] = u;     } else {       dfs1(hvc[u], false);       down[u] = down[hvc[u]];     }     for (auto& x : adj[u]) {       if (x == anc[u][0] || x == hvc[u]) continue;       dfs1(x, true);     }   }   int lca(int u, int v) {     if (rnk[u] < rnk[v]) swap(u, v);     int d = rnk[u] - rnk[v];     for (int i = 0; i < (LG); i++)       if (d & (1 << i)) u = anc[u][i];     if (u == v) return u;     for (int i = LG - 1; i >= 0; i--)       if (anc[u][i] != anc[v][i]) u = anc[u][i], v = anc[v][i];     return anc[u][0];   }   struct Query {     int X, Y;     int s, c;     Query() {}     Query(int a, int b, int x, int y) : X(a), Y(b), s(x), c(y) {}   };   vector<Query> qs[N];   double ans = 1e12;   int chk[N];   void solve(int u) {     priority_queue<tuple<rat, int, int, int> > pq;     auto cmp = [&](int i, int j) -> bool {       if (rat(qs[u][i].X, qs[u][i].c) < rat(qs[u][j].X, qs[u][j].c)) {         return rat((long long)qs[u][i].c * qs[u][j].X, qs[u][j].c) <                qs[u][j].s - qs[u][i].s + qs[u][i].X;       } else {         return rat(qs[u][i].s - qs[u][j].s + qs[u][j].X, 1) <                rat((long long)qs[u][i].X * qs[u][j].c, qs[u][i].c);       }     };     set<int, decltype(cmp)> st(cmp);     int sz = qs[u].size();     for (int i = 0; i < (sz); i++) {       pq.push(make_tuple(rat(-qs[u][i].X, qs[u][i].c), 2, i, 0));       pq.push(make_tuple(rat(-qs[u][i].Y, qs[u][i].c), 1, i, 0));       chk[i] = 0;     }     while (!pq.empty()) {       auto T = pq.top();       pq.pop();       int tp = get<1>(T);       rat time = -get<0>(T);       if (tp == 1) {         int i = get<2>(T);         chk[i] = 0;         auto it = st.find(i);         it = st.erase(it);         auto it2 = it;         if (it != st.begin()) {           it2--;           if (it != st.end()) {             int i = *it;             int j = *it2;             if (qs[u][i].c != qs[u][j].c) {               rat ntime = rat(qs[u][i].X - qs[u][j].X - qs[u][i].s + qs[u][j].s,                               qs[u][i].c - qs[u][j].c);               if (!(ntime < time)) {                 pq.push(make_tuple(-ntime, 3, i, j));               }             }           }         }       } else if (tp == 2) {         int i = get<2>(T);         chk[i] = 1;         auto P = st.insert(i);         if (!P.second) {           ans = min(ans, (double)time.a / time.b);           return;         }         auto it2 = P.first;         auto it = it2;         if (it != st.begin()) {           it2--;           int j = *it2;           if (qs[u][i].c != qs[u][j].c) {             rat ntime = rat(qs[u][i].X - qs[u][j].X - qs[u][i].s + qs[u][j].s,                             qs[u][i].c - qs[u][j].c);             if (!(ntime < time)) {               pq.push(make_tuple(-ntime, 3, i, j));             }           }         }         it2 = it;         it2++;         if (it2 != st.end()) {           int j = *it2;           if (qs[u][i].c != qs[u][j].c) {             rat ntime = rat(qs[u][i].X - qs[u][j].X - qs[u][i].s + qs[u][j].s,                             qs[u][i].c - qs[u][j].c);             if (!(ntime < time)) {               pq.push(make_tuple(-ntime, 3, i, j));             }           }         }       } else {         int u = get<2>(T);         int v = get<3>(T);         if (!chk[u] || !chk[v]) continue;         ans = min(ans, (double)time.a / time.b);         return;       }     }   }   int main() {     freopen( input.txt ,  r , stdin);     int n, m;     scanf( %d%d , &(n), &(m));     for (int i = 0; i < (n - 1); i++) {       int a, b;       scanf( %d%d , &(a), &(b));       a--;       b--;       adj[a].push_back(b);       adj[b].push_back(a);     }     anc[0][0] = -1;     dfs0(0);     dfs1(0, true);     for (int j = 1; j <= (LG - 1); j++)       for (int i = 0; i < (n); i++) {         int a = anc[i][j - 1];         if (a == -1)           anc[i][j] = -1;         else           anc[i][j] = anc[a][j - 1];       }     for (int i = 0; i < (m); i++) {       int t, c, u, v;       scanf( %d%d , &(t), &(c));       scanf( %d%d , &(u), &(v));       u--;       v--;       bool good = false;       int L = lca(u, v);       int ou = u;       while (up[u] != up[L]) {         int uu = up[u];         qs[uu].emplace_back(-(c * t + rnk[ou] - rnk[u]),                             -(c * t + rnk[ou] - rnk[uu] + 1), rnk[u], -c);         u = anc[uu][0];       }       if (u != L) {         qs[up[u]].emplace_back(-(c * t + rnk[ou] - rnk[u]),                                -(c * t + rnk[ou] - rnk[L]), rnk[u], -c);         good = true;       }       int d = rnk[ou] - rnk[L];       while (up[v] != up[L]) {         int vv = up[v];         qs[vv].emplace_back(t * c + rnk[vv] - 1 - rnk[L] + d,                             t * c + rnk[v] - rnk[L] + d, rnk[vv] - 1, c);         v = anc[vv][0];       }       if (v != L) {         good = true;         qs[up[v]].emplace_back(t * c + d, t * c + rnk[v] - rnk[L] + d, rnk[L], c);       }       if (!good) {         qs[up[L]].emplace_back(t * c + d, t * c + d, rnk[L], c);       }     }     for (int i = 0; i < (n); i++) {       if (up[i] == i) {         solve(i);       }     }     if (ans > 1e11) {       puts( -1 );     } else       printf( %.15f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string pixels;     getline(cin, pixels);     getline(cin, pixels);     int len = 0, flen = 0, last = pixels.at(0) -  0 ;     bool first = false;     for (int i = (0); i < (pixels.size()); i += (2)) {       if ((pixels.at(i) ==  0  && last == 0) ||           (pixels.at(i) ==  1  && last == 1))         len++;       else {         if (!first) {           flen = len;           first = true;         } else if (flen != len) {           printf( NO );           return 0;         }         len = 1;         last = 1 - last;       }     }     if (!flen || flen == len)       printf( YES );     else       printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[200010];   long long num[200010];   struct P {     int x, y, fl;     bool operator<(const P &hs) const {       if (x != hs.x)         return x < hs.x;       else         return y < hs.y;     }   } p[200010];   int row[200010];   int pre[200010];   int n, k;   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d %d , &p[i].x, &p[i].y);       p[i].fl = 1;       p[i + n].x = p[i].x + k;       p[i + n].y = p[i].y;       p[i + n].fl = -1;       row[i] = p[i].y;       row[i + n] = row[i] + k;     }     sort(row, row + 2 * n);     int ro = 0;     for (int i = 1; i < 2 * n; i++)       if (row[i] != row[ro]) row[++ro] = row[i];     sort(p, p + 2 * n);     for (int i = 0; i < 2 * n; i++) {       int y = lower_bound(row, row + ro, p[i].y) - row;       for (int j = y; row[j] < row[y] + k; j++) {         if (cnt[j] > 0)           num[cnt[j]] += (long long)(row[j + 1] - row[j]) * (p[i].x - pre[j]);         cnt[j] += p[i].fl;         pre[j] = p[i].x;       }     }     for (int i = 1; i <= n; i++) printf( %I64d%c , num[i], i == n ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MM = 10000000000000001;   int n;   long long a[200005];   int rs[200005];   long long lazy[4 * 200005];   pair<long long, int> it[4 * 200005];   pair<long long, int> minp(pair<long long, int> A, pair<long long, int> B) {     if (A.first < B.first) return A;     if (A.first > B.first) return B;     if (A.second > B.second) return A;     return B;   }   void build(int x, int l, int r) {     if (l == r) {       it[x] = make_pair(a[l], l);       return;     }     int mid = (l + r) / 2;     build(2 * x, l, mid);     build(2 * x + 1, mid + 1, r);     it[x] = minp(it[2 * x], it[2 * x + 1]);   }   void lazy_upd(int x, int l, int r) {     it[x].first += lazy[x];     if (l != r) {       lazy[2 * x] += lazy[x];       lazy[2 * x + 1] += lazy[x];     }     lazy[x] = 0;   }   void update(int x, int l, int r, int u, int v, long long val) {     lazy_upd(x, l, r);     if ((r < u) || (v < l)) return;     if ((u <= l) && (r <= v)) {       lazy[x] += val;       lazy_upd(x, l, r);       return;     }     int mid = (l + r) / 2;     update(2 * x, l, mid, u, v, val);     update(2 * x + 1, mid + 1, r, u, v, val);     it[x] = minp(it[2 * x], it[2 * x + 1]);   }   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     build(1, 1, n);     for (int i = 1; i <= n; i++) {       pair<long long, int> p = it[1];       int id = p.second;       rs[id] = i;       update(1, 1, n, id, id, MM);       update(1, 1, n, id + 1, n, -i);     }     for (int i = 1; i <= n; i++) cout << rs[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     int mx = *max_element(v.begin(), v.end());     int mn = *min_element(v.begin(), v.end());     int ind1 = 0, ind2 = 0;     for (int i = 0; i < n; i++) {       if (v[i] == mx && ind1 == 0)         ind1 = i + 1;       else if (v[i] == mn)         ind2 = i + 1;     }     ind2--;     ind1--;     if (ind1 > ind2) ind2++;     long long result = ind1 + n - ind2 - 1;     cout << result;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, l, i, j = 0, s = 0, a, b, x, y;     cin >> n >> a >> x >> b >> y;     while (a != x && b != y) {       a++;       b--;       if (b == 0 && b != y) b = n;       if (a == n + 1 && a != x) a = 1;       if (a == b) {         cout <<  yes ;         j = 1;         break;       }       if (a == x || b == y) break;     }     if (j != 1) cout <<  no ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n;   long long k;   long long a[maxn];   long long b[maxn], c[maxn], d[maxn];   int main() {     scanf( %d%lld , &n, &k);     for (int i = 1; i <= n; i++) scanf( %lld , a + i);     sort(a + 1, a + n + 1);     int m = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == a[m]) {         ++b[m];       } else {         a[++m] = a[i];         b[m] = 1;       }     }     n = m;     for (int i = 1; i <= n; i++) {       c[i] = c[i - 1] + b[i];     }     for (int i = n; i; i--) {       d[i] = d[i + 1] + b[i];     }     int l = 1, r = n;     long long L = a[l], R = a[r];     while (l != r) {       if (c[l] <= d[r]) {         if (c[l] * (a[l + 1] - a[l]) > k) {           L = a[l] + k / c[l];           break;         } else {           k -= c[l] * (a[l + 1] - a[l]);           L = a[++l];         }       } else {         if (d[r] * (a[r] - a[r - 1]) > k) {           R = a[r] - k / d[r];           break;         } else {           k -= d[r] * (a[r] - a[r - 1]);           R = a[--r];         }       }     }     printf( %lld n , R - L);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   double PI = 3.1415926535897932384626433832795;   const long long oo = (long long)1e9 + 1;   const double eps = 1e-9;   const long long mod = 1000000007;   string s;   long long nb, ns, nc, pb, ps, pc, R;   int main() {     cin >> s;     cin >> nb >> ns >> nc;     cin >> pb >> ps >> pc;     cin >> R;     int cb = 0, cs = 0, cc = 0;     for (int i = 0; s[i]; i++)       if (s[i] ==  B )         cb++;       else if (s[i] ==  S )         cs++;       else         cc++;     long long l = 0, r = 1e15, ret = 0;     while (l <= r) {       long long mid = (l + r) >> 1;       if (max(cb * mid - nb, 0ll) * pb + max(cs * mid - ns, 0ll) * ps +               max(cc * mid - nc, 0ll) * pc <=           R)         ret = mid, l = mid + 1;       else         r = mid - 1;     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     long long palite, primeite;     std::cin >> palite >> primeite;     long long primes = 0, palindromes = 0, max;     static bool prime[12000001];     for (long long i = 0; i <= 12000000; i++) {       prime[i] = true;     }     prime[1] = false;     std::string str =  0 ;     for (long long i = 1; i <= 12000000; i++) {       if (prime[i]) {         primes += primeite;         for (long long j = i * i; j <= 12000000; j += i) {           prime[j] = false;         }       }       long long pos;       for (pos = str.length() - 1; pos >= 0; pos--) {         if (str[pos] ==  9 ) {           str[pos] =  0 ;         } else {           str[pos]++;           break;         }       }       if (pos == -1) {         str.insert(str.begin(),  1 );       }       palindromes += palite;       for (long long j = 0, back = str.length() - 1; back > j; j++, back--) {         if (str[j] != str[back]) {           palindromes -= palite;           break;         }       }       if (primes <= palindromes) {         max = i;       }     }     if (max == 12000000) {       std::cout <<  Palindromic tree is better than splay tree ;     } else {       std::cout << max;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j;     string s;     cin >> n;     cin >> s;     n = s.size();     for (i = 0; i < n - 1; i++) {       if (s[i] > s[i + 1]) break;     }     if (i != n - 1) {       cout <<  YES             <<   n ;       cout << i + 1 <<     << i + 2 <<   n ;     } else {       cout <<  NO             <<   n ;     }   }


#include <bits/stdc++.h>   int main() {     char s[512];     scanf( %s , s);     int length = strlen(s);     int i;     int alpha_cnt = 0;     for (i = 0; i < length; i++) {       if (s[i] -  a  > alpha_cnt) {         puts( NO );         return 0;       }       if (s[i] -  a  == alpha_cnt) {         alpha_cnt++;       }     }     puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = double;   using pll = pair<ll, ll>;   using vll = vector<ll>;   using vpll = vector<pll>;   using vvll = vector<vll>;   vector<vector<ll>> g;   vector<bool> v;   ll res;   pair<bool, bool> dfs(int u, int depth) {     v[u] = true;     if (depth > 2 && g[u].size() == 1) return make_pair(false, false);     bool inSet = false;     bool isDominated = false;     for (ll i = 0; i < (ll)g[u].size(); ++i) {       if (v[g[u][i]]) continue;       auto t = dfs(g[u][i], depth + 1);       inSet |= !t.first;       isDominated |= t.second;     }     if (depth <= 1) return make_pair(true, true);     if (inSet) res++;     return make_pair(isDominated || inSet, inSet);   }   int main() {     ios::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     ll n;     cin >> n;     g = vector<vector<ll>>(n);     v = vector<bool>(n);     for (ll i = 0; i < (ll)n - 1; ++i) {       ll u, v;       cin >> u >> v;       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(0, 0);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void solve() {     long long n;     cin >> n;     vector<long long> a(n), b;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     b = a;     sort(b.begin(), b.end());     b.resize(unique(b.begin(), b.end()) - b.begin());     for (long long i = 0; i < n; i++) {       a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();     }     vector<long long> dp(n, -1e9);     dp[a[0]] = 1;     for (long long i = 1; i < n; i++) {       dp[a[i]] = 1;       if (a[i]) dp[a[i]] = max(dp[a[i]], dp[a[i] - 1] + 1);     }     long long ans = n - *max_element(dp.begin(), dp.end());     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long q;     cin >> q;     while (q--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int n, j = 0;     cin >> n;     int a[n], b[n];     pair<int, int> s[n];     for (auto &i : s) cin >> i.first, i.second = j++;     sort(s, s + n);     map<int, int> mp;     for (int i = 0; i < n; i++) mp[s[i].second] = i;     for (int i = 0; i < (n + 2) / 3; i++) a[i] = i;     for (int i = (n + 2) / 3; i < (2 * n + 2) / 3; i++) b[i] = i;     for (int i = n - 1; i >= (2 * n + 2) / 3; i--) b[i] = n - 1 - i;     for (int i = (n + 2) / 3; i < n; i++) a[i] = s[i].first - b[i];     for (int i = 0; i < (n + 2) / 3; i++) b[i] = s[i].first - a[i];     cout <<  YES  <<   n ;     for (int i = 0; i < n; i++) cout << a[mp[i]] <<    ;     cout <<   n ;     for (int i = 0; i < n; i++) cout << b[mp[i]] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   void populate(string& s, char c, int n) {     for (int i = 0; i < n; ++i) s[s.find_first_of( ? )] = c;   }   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     string s;     cin >> s;     auto na = count(s.begin(), s.end(),  A );     auto nc = count(s.begin(), s.end(),  C );     auto ng = count(s.begin(), s.end(),  G );     auto nt = count(s.begin(), s.end(),  T );     auto nq = count(s.begin(), s.end(),  ? );     auto m = max(na, max(nc, (max(ng, nt))));     auto da = m - na;     auto dc = m - nc;     auto dg = m - ng;     auto dt = m - nt;     if (nq < da + dc + dg + dt) {       cout <<  ===  << endl;     } else if ((nq - (da + dc + dg + dt)) % 4 != 0) {       cout <<  ===  << endl;     } else {       populate(s,  A , da);       populate(s,  C , dc);       populate(s,  G , dg);       populate(s,  T , dt);       for (int i = 0; i < (nq - (da + dc + dg + dt)); i += 4) {         populate(s,  A , 1);         populate(s,  C , 1);         populate(s,  G , 1);         populate(s,  T , 1);       }       cout << s << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   using Real = long double;   Real g_err = 1e-9;   bool r_eq(Real x, Real y, Real err = g_err) {     return abs(x - y) <= err || abs(x - y) <= abs(x) * err;   }   bool r_le(Real x, Real y, Real err = g_err) {     return x - y <= err || x - y <= abs(x) * err;   }   bool r_ge(Real x, Real y, Real err = g_err) { return r_le(y, x, err); }   bool r_gt(Real x, Real y, Real err = g_err) { return !r_le(x, y, err); }   bool r_lt(Real x, Real y, Real err = g_err) { return !r_le(y, x, err); }   bool r_ne(Real x, Real y, Real err = g_err) { return !r_eq(x, y, err); }   bool rp_eq(Real x, Real y, Real err = g_err) { return abs(x - y) <= err; }   bool rp_le(Real x, Real y, Real err = g_err) { return x - y <= err; }   bool rp_ge(Real x, Real y, Real err = g_err) { return rp_le(y, x, err); }   bool rp_gt(Real x, Real y, Real err = g_err) { return !rp_le(x, y, err); }   bool rp_lt(Real x, Real y, Real err = g_err) { return !rp_le(y, x, err); }   bool rp_ne(Real x, Real y, Real err = g_err) { return !rp_eq(x, y, err); }   template <typename T>   bool updMax(T& tmax, const T& x) {     if (x > tmax) {       tmax = x;       return true;     } else {       return false;     }   }   template <typename T>   bool updMin(T& tmin, const T& x) {     if (x < tmin) {       tmin = x;       return true;     } else {       return false;     }   }   struct Point {     Real x;     Real y;     Point() : x(0), y(0) {}     Point(Real x_, Real y_) : x(x_), y(y_) {}     bool operator==(const Point& p) const { return x == p.x && y == p.y; }     bool operator!=(const Point& p) const { return !(*this == p); }     bool sim(const Point& p, Real err = g_err) const {       return r_eq(x, p.x, err) && r_eq(y, p.y, err);     }     static bool sim(const Point& p1, const Point& p2, Real err = g_err) {       return p1.sim(p2, err);     }     Point& operator+=(const Point& p) {       x += p.x;       y += p.y;       return *this;     }     Point& operator-=(const Point& p) {       x -= p.x;       y -= p.y;       return *this;     }     Point& operator*=(Real k) {       x *= k;       y *= k;       return *this;     }     Point& operator/=(Real k) {       x /= k;       y /= k;       return *this;     }     Point operator+(const Point& p) const { return Point(*this) += p; }     Point operator-(const Point& p) const { return Point(*this) -= p; }     Point operator*(Real k) const { return Point(*this) *= k; }     Point operator/(Real k) const { return Point(*this) /= k; }     Point operator-() const { return (*this) * (-1); }     Real len() const { return hypot(x, y); }     static Point polar(Real r, Real th) {       return Point(r * cos(th), r * sin(th));     }     Point rotate(Real th) const { return polar(len(), atan2(y, x) + th); }     Point rotateQ() const { return Point(-y, x); }     bool parallel(const Point& p, Real err = g_err) const {       return r_eq(x * p.y, y * p.x, err);     }     Real innerProd(const Point& p) const { return x * p.x + y * p.y; }     Real outerProd(const Point& p) const { return x * p.y - y * p.x; }     Real arg() const { return atan2(y, x); }     Real angle(const Point& p) const {       Real th = atan2(p.y, p.x) - atan2(y, x);       return th > 3.141592653589793238462643383279502884L                  ? th - 2 * 3.141592653589793238462643383279502884L              : th <= -3.141592653589793238462643383279502884L                  ? th + 2 * 3.141592653589793238462643383279502884L                  : th;     }   };   Point operator*(Real k, const Point& p) { return p * k; }   ostream& operator<<(ostream& os, const Point& p) {     return os <<  (  << p.x <<  ,   << p.y <<  ) ;   }   struct Line;   ostream& operator<<(ostream& os, const Line& l);   struct Line {     Point dir;     Point base;     static Line x_axis;     static Line y_axis;     static constexpr int SIDE_ON = 1;     static constexpr int SIDE_P = 2;     static constexpr int SIDE_N = 4;     static constexpr int IST_NONE = -1;     static constexpr int IST_ALL = -2;     static constexpr int IST_ONE = 0;     Line() : dir(0, 0), base(0, 0) {}     Line(const Point& d, const Point& b) : dir(d), base(b) {}     bool operator==(const Line& l) const {       return dir == l.dir && base == l.base;     }     bool operator!=(const Line& l) const { return !(*this == l); }     bool sim(const Line& l1, Real err = g_err) const {       return dir.sim(l1.dir, err) && dir.sim(l1.base - base, err);     }     static bool sim(const Line& l1, const Line& l2, Real err = g_err) {       return l1.sim(l2, err);     }     static Line connect(const Point& p1, const Point& p2) {       return Line(p2 - p1, p1);     }     bool parallel(const Line& l, Real err = g_err) const {       return dir.parallel(l.dir, err);     }     int ptSide(const Point& p, Real err = g_err) const {       Real t1 = dir.y * (p.x - base.x);       Real t2 = dir.x * (p.y - base.y);       if (r_eq(t1, t2, err)) return SIDE_ON;       if (r_lt(t1, t2, err)) return SIDE_P;       return SIDE_N;     }     bool ptOn(const Point& p, Real err = g_err) const {       return ptSide(p, err) == SIDE_ON;     }     tuple<int, Real, Real> intersect_coeff(const Line& l) const {       if (dir.parallel(l.dir)) {         if (ptOn(l.base))           return make_tuple(IST_ALL, 0, 0);         else           return make_tuple(IST_NONE, 0, 0);       } else {         Real d = dir.x * (-l.dir.y) - (-l.dir.x) * dir.y;         Point z = l.base - base;         Real t1 = ((-l.dir.y) * z.x + l.dir.x * z.y) / d;         Real t2 = ((-dir.y) * z.x + dir.x * z.y) / d;         return {IST_ONE, t1, t2};       }     }     Point unsafe_intersect(const Line& l) const {       auto [rc, t1, t2] = intersect_coeff(l);       assert(rc == IST_ONE);       return base + t1 * dir;     }     Point perpend_foot(const Point& p) const {       Real t1 = perpend_foot_coeff(p);       return base + t1 * dir;     }     Real perpend_foot_coeff(const Point& p) const {       auto [rc, t1, t2] = intersect_coeff(Line(dir.rotateQ(), p));       return t1;     }     Real len(const Point& p) const { return (p - perpend_foot(p)).len(); }   };   ostream& operator<<(ostream& os, const Line& l) {     return os <<  [d   << l.dir <<  , b   << l.base <<  ) ;   }   Line Line::x_axis(Point(1, 0), Point(0, 0));   Line Line::y_axis(Point(0, 1), Point(0, 0));   struct Circle {     Point c;     Real r;     Circle() : c(0, 0), r(0) {}     Circle(const Point& c_, Real r_) : c(c_), r(r_) {}     bool operator==(const Circle& o) const { return c == o.c && r == o.r; }     bool operator!=(const Circle& o) const { return !(*this == o); }     bool sim(const Circle& o, Real err = g_err) const {       return c.sim(o.c, err) && r_eq(r, o.r, err);     }     static bool sim(const Circle& c1, const Circle& c2, Real err = g_err) {       return c1.sim(c2, err);     }     bool ptOn(const Point& p, Real err = g_err) const {       return r_eq((p - c).len(), r, err);     }     tuple<bool, Point, Point> intersect(const Line& o) const {       Point f = o.perpend_foot(c);       Real d = (f - c).len();       if (d > r) return make_tuple(false, Point(), Point());       Real t = sqrt(r * r - d * d);       Point e = o.dir / o.dir.len();       return make_tuple(true, f + t * e, f - t * e);     }     tuple<bool, Point, Point> intersect(const Circle& o) const {       Real d = (o.c - c).len();       if (d + r < o.r || d + o.r < r || r + o.r < d) {         return make_tuple(false, Point(), Point());       }       Point v = (o.c - c) / d;       Real t = (r * r - o.r * o.r + d * d) / (2 * d);       Line l(v.rotateQ(), c + t * v);       return intersect(l);     }   };   ostream& operator<<(ostream& os, const Circle& circ) {     return os <<  [c   << circ.c <<  ,   << circ.r <<  ] ;   }   Point circumcenter(const Point& z1, const Point& z2, const Point& z3) {     Line l12((z2 - z1).rotateQ(), (z1 + z2) / 2);     Line l23((z3 - z2).rotateQ(), (z2 + z3) / 2);     return l12.unsafe_intersect(l23);   }   vector<Point> convex_hull(const vector<Point>& pts) {     vector<Point> spts(pts);     int n = pts.size();     if (n == 0) return vector<Point>();     auto sub = [&]() -> vector<Point> {       vector<Point> ret;       for (int i = 0; i < n; i++) {         Point pt = spts.at(i);         if (i > 0 && spts.at(i - 1).sim(spts.at(i))) continue;         while (true) {           int rs = ret.size();           if (rs - 2 < 0) break;           Point q0 = ret.at(rs - 2);           Point q1 = ret.at(rs - 1);           if ((q0 - q1).outerProd(pt - q1) < 0) break;           ret.pop_back();         }         ret.push_back(pt);       }       ret.pop_back();       return ret;     };     sort(spts.begin(), spts.end(), [](const Point& a, const Point& b) -> bool {       if (a.x != b.x) return a.x < b.x;       return a.y < b.y;     });     auto vec1 = sub();     reverse(spts.begin(), spts.end());     auto vec2 = sub();     vec1.insert(vec1.end(), vec2.begin(), vec2.end());     if (vec1.empty()) return vector<Point>({pts.at(0)});     return vec1;   }   tuple<Real, int, int> convex_diameter(const vector<Point>& pts) {     int n = pts.size();     if (n <= 1) {       cerr <<  diameter is called with <=1 points. n ;       exit(1);     }     auto conn = [&](long long int i, long long int j) -> Point {       return pts.at(j % n) - pts.at(i % n);     };     auto edge = [&](long long int i) -> Point { return conn(i, i + 1); };     if (n == 2) return make_tuple(conn(0, 1).len(), 0, 1);     int k = -1;     int m = -1;     for (int i = 0, cnt = 0; cnt < 2; i++) {       if (edge(i).y <= 0 && edge(i + 1).y > 0) {         m = i + 1;         cnt++;       }       if (edge(i).y >= 0 && edge(i + 1).y < 0) {         k = i + 1;         cnt++;       }     }     Real vmax = 0;     int k0 = -1, m0 = -1;     bool run_k = true;     bool run_m = true;     while (run_k || run_m) {       if (!run_m ||           (run_k && edge(k).arg() - (-3.141592653589793238462643383279502884L) <=                         edge(m).arg())) {         if (updMax(vmax, conn(k + 1, m).len())) {           k0 = k + 1, m0 = m;         }         k++;         if (edge(k).y > 0) run_k = false;       } else {         if (updMax(vmax, conn(k, m + 1).len())) {           k0 = k, m0 = m + 1;         }         m++;         if (edge(m).y < 0) run_m = false;       }     }     return make_tuple(vmax, k0 % n, m0 % n);   }   int in_triangle(const Point& pt, const Point& tr0, const Point& tr1,                   const Point& tr2) {     auto chk = [&](const Point& b, const Point& e, const Point& p) -> bool {       Point be = e - b;       Point bp = p - b;       Real r = r_eq(be.x, 0.0) ? bp.y / be.y : bp.x / be.x;       return 0.0 <= r && r <= 1.0;     };     Line l01 = Line::connect(tr0, tr1);     Line l12 = Line::connect(tr1, tr2);     Line l20 = Line::connect(tr2, tr0);     int side = l01.ptSide(tr2);     if (side == Line::SIDE_ON) {       if (!l01.ptOn(pt)) return Line::SIDE_N;       return chk(tr0, tr1, pt) || chk(tr1, tr2, pt) || chk(tr2, tr0, pt)                  ? Line::SIDE_ON                  : Line::SIDE_N;     }     int other = side ^ (Line::SIDE_P | Line::SIDE_N);     if (l01.ptSide(pt) == other || l12.ptSide(pt) == other ||         l20.ptSide(pt) == other)       return Line::SIDE_N;     if (l01.ptSide(pt) == Line::SIDE_ON || l12.ptSide(pt) == Line::SIDE_ON ||         l20.ptSide(pt) == Line::SIDE_ON)       return Line::SIDE_ON;     return Line::SIDE_P;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& os, const pair<T1, T2>& p) {     os <<  (  << p.first <<  ,   << p.second <<  ) ;     return os;   }   template <typename T1, typename T2, typename T3>   ostream& operator<<(ostream& os, const tuple<T1, T2, T3>& t) {     os <<  (  << get<0>(t) <<  ,   << get<1>(t) <<  ,   << get<2>(t) <<  ) ;     return os;   }   template <typename T1, typename T2, typename T3, typename T4>   ostream& operator<<(ostream& os, const tuple<T1, T2, T3, T4>& t) {     os <<  (  << get<0>(t) <<  ,   << get<1>(t) <<  ,   << get<2>(t) <<  ,          << get<3>(t) <<  ) ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     os <<  [ ;     for (auto it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     os <<  ] ;     return os;   }   template <typename T, typename C>   ostream& operator<<(ostream& os, const set<T, C>& v) {     os <<  { ;     for (auto it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     os <<  } ;     return os;   }   template <typename T, typename C>   ostream& operator<<(ostream& os, const unordered_set<T, C>& v) {     os <<  { ;     for (auto it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     os <<  } ;     return os;   }   template <typename T, typename C>   ostream& operator<<(ostream& os, const multiset<T, C>& v) {     os <<  { ;     for (auto it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << *it;     }     os <<  } ;     return os;   }   template <typename T1, typename T2, typename C>   ostream& operator<<(ostream& os, const map<T1, T2, C>& mp) {     os <<  [ ;     for (auto it = mp.begin(); it != mp.end(); it++) {       if (it != mp.begin()) os <<  ,  ;       os << it->first <<  :   << it->second;     }     os <<  ] ;     return os;   }   template <typename T1, typename T2, typename C>   ostream& operator<<(ostream& os, const unordered_map<T1, T2, C>& mp) {     os <<  [ ;     for (auto it = mp.begin(); it != mp.end(); it++) {       if (it != mp.begin()) os <<  ,  ;       os << it->first <<  :   << it->second;     }     os <<  ] ;     return os;   }   template <typename T, typename T2>   ostream& operator<<(ostream& os, const queue<T, T2>& orig) {     queue<T, T2> que(orig);     bool first = true;     os <<  [ ;     while (!que.empty()) {       T x = que.front();       que.pop();       if (!first) os <<  ,  ;       os << x;       first = false;     }     return os <<  ] ;   }   template <typename T, typename T2>   ostream& operator<<(ostream& os, const deque<T, T2>& orig) {     deque<T, T2> que(orig);     bool first = true;     os <<  [ ;     while (!que.empty()) {       T x = que.front();       que.pop_front();       if (!first) os <<  ,  ;       os << x;       first = false;     }     return os <<  ] ;   }   template <typename T, typename T2, typename T3>   ostream& operator<<(ostream& os, const priority_queue<T, T2, T3>& orig) {     priority_queue<T, T2, T3> pq(orig);     bool first = true;     os <<  [ ;     while (!pq.empty()) {       T x = pq.top();       pq.pop();       if (!first) os <<  ,  ;       os << x;       first = false;     }     return os <<  ] ;   }   template <typename T>   ostream& operator<<(ostream& os, const stack<T>& st) {     stack<T> tmp(st);     os <<  [ ;     bool first = true;     while (!tmp.empty()) {       T& t = tmp.top();       if (first)         first = false;       else         os <<  ,  ;       os << t;       tmp.pop();     }     os <<  ] ;     return os;   }   ostream& operator<<(ostream& os, int8_t x) {     os << (int32_t)x;     return os;   }   template <class... Args>   string dbgFormat(const char* fmt, Args... args) {     size_t len = snprintf(nullptr, 0, fmt, args...);     char buf[len + 1];     snprintf(buf, len + 1, fmt, args...);     return string(buf);   }   template <class Head>   void dbgLog(bool with_nl, Head&& head) {     cerr << head;     if (with_nl) cerr << endl;   }   template <class Head, class... Tail>   void dbgLog(bool with_nl, Head&& head, Tail&&... tail) {     cerr << head <<    ;     dbgLog(with_nl, forward<Tail>(tail)...);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout << setprecision(20);     long long int n, q;     cin >> n >> q;     vector<Point> P(n);     for (long long int i = 0; i < n; i++) {       long long int x, y;       cin >> x >> y;       P[i] = Point(x, y);     }     Point g(0, 0);     Real tots = 0;     for (long long int i = 1; i < n - 1; i++) {       Point lg = (P[0] + P[i] + P[i + 1]) / 3.0;       Point v0i = P[i] - P[0];       Point v0j = P[i + 1] - P[0];       Real s = abs(v0i.x * v0j.y - v0i.y * v0j.x);       tots += s;       g += s * lg;     }     g = g / tots;     vector<Real> L(n), Th(n);     for (long long int i = 0; i < n; i++) {       L[i] = (P[i] - g).len();       Th[i] = (P[0] - g).angle(P[i] - g);     };     ;     ;     Real th0 = (P[0] - g).arg();     ;     long long int pinA = 0, pinB = 1;     for (long long int _q = 0; _q < q; _q++) {       long long int tp;       cin >> tp;       if (tp == 1) {         long long int f, t;         cin >> f >> t;         f--;         t--;         if (f == pinA) {           pinA = pinB;           pinB = t;         } else {           pinB = t;         };         Point e(L[pinA], 0);         Point pa = g + e.rotate(th0 + Th[pinA]);         g = pa + e.rotate(3 * 3.141592653589793238462643383279502884L / 2);         ;         th0 += 3.141592653589793238462643383279502884L / 2.0 - (th0 + Th[pinA]);         ;       } else if (tp == 2) {         long long int v;         cin >> v;         v--;         Point e(L[v], 0);         Point pv = g + e.rotate(th0 + Th[v]);         cout << pv.x <<     << pv.y <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long k;       vector<long long> ans;       if (n > 3) {         if (n % 2 == 1)           k = n - 1;         else           k = n;         while (k > 0) {           if (k == 4) ans.push_back(2);           if (k == 2) ans.push_back(4);           if (k != 4 && k != 2) ans.push_back(k);           k -= 2;         }         k = 1;         while (k <= n) {           ans.push_back(k);           k += 2;         }         for (auto u : ans) cout << u <<    ;         cout << endl;       } else {         cout <<  -1  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, r;     cin >> n >> r;     double alpha = 90.0 - 180.0 / n;     double val = cos(alpha * 3.14159265 / 180.0);     double ans = val * (double)r / (1 - val);     cout << fixed << setprecision(6) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100009;   int acc[MAXN], sav[MAXN];   int extr(string &s) {     int num = 0;     for (int i = 1; i < s.length(); i++) {       num *= 10;       num += (s[i] -  0 );     }     return num;   }   int main() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     int pl = 0, mn = 0;     vector<string> statements;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       statements.push_back(s);       int z = extr(s);       if (s[0] ==  + )         acc[z]++, pl++;       else         sav[z]++, mn++;     }     set<int> Suspects;     for (int i = 1; i < n + 1; i++) {       int tr = acc[i] + mn - sav[i];       if (tr == m) {         Suspects.insert(i);       }     }     for (int i = 0; i < n; i++) {       string s = statements[i];       int z = extr(s);       if (s[0] ==  + ) {         if (Suspects.find(z) == Suspects.end()) {           cout <<  Lie  <<   n ;           continue;         }         if (Suspects.size() == 1) {           cout <<  Truth  <<   n ;         } else {           cout <<  Not defined  <<   n ;         }       } else {         if (Suspects.size() == 1 && Suspects.find(z) != Suspects.end()) {           cout <<  Lie  <<   n ;           continue;         }         if (Suspects.find(z) == Suspects.end()) {           cout <<  Truth  <<   n ;           continue;         } else           cout <<  Not defined  <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1e6 + 1e5 + 5;   struct Node {     int len, pa;     int trans[26];   } st[maxN + 1];   int n, m, last, cnt;   int L[11], R[11];   int sum[11][maxN + 1];   char s[maxN + 1];   vector<int> son[maxN + 1];   inline int insert(int c) {     if (st[last].trans[c] && st[st[last].trans[c]].len == st[last].len + 1)       return st[last].trans[c];     int np = ++cnt, p = last, f = np;     st[np].len = st[p].len + 1;     while (p && !st[p].trans[c]) st[p].trans[c] = np, p = st[p].pa;     if (!p)       st[np].pa = 1;     else {       int q = st[p].trans[c];       if (st[q].len == st[p].len + 1)         st[np].pa = q;       else {         int nq = ++cnt;         if (p == last) f = nq;         st[nq] = st[q];         st[nq].len = st[p].len + 1;         st[np].pa = st[q].pa = nq;         while (p && st[p].trans[c] == q) st[p].trans[c] = nq, p = st[p].pa;       }     }     return f;   }   inline void calc(int u) {     for (int i = 0; i < son[u].size(); i++) {       int v = son[u][i];       calc(v);       for (int j = 0; j <= m; j++) sum[j][u] += sum[j][v];     }   }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     last = cnt = 1;     for (int i = 1; i <= n; i++) last = insert(s[i] -  a ), sum[0][last]++;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %s %d %d , s + 1, &L[i], &R[i]);       int len = strlen(s + 1);       last = 1;       for (int j = 1; j <= len; j++) last = insert(s[j] -  a ), sum[i][last]++;     }     for (int i = 1; i <= cnt; i++) son[st[i].pa].push_back(i);     calc(1);     long long ans = 0;     for (int i = 2; i <= cnt; i++) {       if (!sum[0][i]) continue;       bool flag = true;       for (int j = 1; j <= m; j++)         if (sum[j][i] < L[j] || sum[j][i] > R[j]) {           flag = false;           break;         }       if (flag) ans += st[i].len - st[st[i].pa].len;     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long linf = 4000000000000000000LL;   const long long inf = 1000000007;   void pv(vector<int> a) {     for (auto& x : a) cout << x <<    ;     cout << endl;   }   void pv(vector<long long> a) {     for (auto& x : a) cout << x <<    ;     cout << endl;   }   void pv(vector<vector<int>> a) {     for (int i = (0); i < (int(a.size())); ++i) {       cout << i << endl;       pv(a[i]);       cout << endl;     }   }   void pv(vector<vector<long long>> a) {     for (int i = (0); i < (int(a.size())); ++i) {       cout << i << endl;       pv(a[i]);     }     cout << endl;   }   void pv(vector<string> a) {     for (auto& x : a) cout << x << endl;     cout << endl;   }   void setIO(string second) {     ios_base::sync_with_stdio(0);     cin.tie(0);   }   int n, k;   vector<pair<long long, long long>> a;   void init() {     vector<pair<long long, long long>> t;     for (auto& x : a)       if (x.first == 0 && x.second == 0)         k--, n--;       else         t.push_back(x);     a = t;   }   bool check(long double r) {     long double pi = acos(-1);     vector<pair<long double, int>> ranges;     for (int i = (0); i < (n); ++i) {       long double d = sqrt(a[i].first * a[i].first + a[i].second * a[i].second);       if (d > 2 * r) continue;       long double theta = acos(d / (2 * r));       long double theta1 = atan((long double)a[i].second / a[i].first);       if (theta1 < 0 || (theta1 == 0 && a[i].first < 0)) theta1 += pi;       if (a[i].second < 0) theta1 += pi;       long double x = theta1 - theta, y = theta1 + theta;       if (x < 0 && y >= 0) {         ranges.push_back({x + 2 * pi, 1});         ranges.push_back({2 * pi, -1});         ranges.push_back({0, 1});         ranges.push_back({y, -1});       } else if (x < 2 * pi && y >= 2 * pi) {         ranges.push_back({x, 1});         ranges.push_back({2 * pi, -1});         ranges.push_back({0, 1});         ranges.push_back({y - 2 * pi, -1});       } else {         ranges.push_back({x, 1});         ranges.push_back({y, -1});       }     }     sort(ranges.begin(), ranges.end(),          [](pair<long double, int> x, pair<long double, int> y) {            if (x.first == y.first) return x.second > y.second;            return x.first < y.first;          });     int m = 0;     int cur = 0;     for (auto& x : ranges) {       cur += x.second;       m = max(m, cur);     }     return m >= k;   }   int main() {     setIO( test1 );     cin >> n >> k;     a.resize(n);     for (auto& x : a) cin >> x.first >> x.second;     init();     long double l = 0, r = 222222;     for (int i = (0); i < (31); ++i) {       long double m = (l + r) / 2;       if (check(m))         r = m;       else         l = m;     }     cout << setprecision(20) << l << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   const long long G = 300005, BASE = 666667, M1 = 2e9 + 11, M2 = 1e9 + 9;   long long IB1, IB2;   long long a, o;   long long m[G], pwb1[G], pwb2[G];   long long binpow(long long x, long long k, long long mod) {     long long res = 1;     for (; k; k >>= 1) {       if (k & 1) res = res * x % mod;       x = x * x % mod;     }     return res;   }   long long modInv(long long x, long long mod) { return binpow(x, mod - 2, mod); }   void rec(long long l, long long r) {     long long d = r - l + 1;     if (d < 2) return;     long long md = (l + r) / 2;     vector<pair<long long, long long> > hl, hr;     vector<long long> stq;     for (long long q = md, hs1 = 0, hs2 = 0; q >= l; q--) {       if (stq.size() && stq.back() == m[q]) {         hs1 = (hs1 - m[q] + M1) % M1;         hs1 = hs1 * IB1 % M1;         hs2 = (hs2 - m[q] + M2) % M2;         hs2 = hs2 * IB2 % M2;         stq.pop_back();       } else {         stq.push_back(m[q]);         hs1 = (hs1 * BASE + m[q]) % M1;         hs2 = (hs2 * BASE + m[q]) % M2;       }       hl.push_back({hs1, hs2});     }     stq.clear();     for (long long q = md + 1, hs1 = 0, hs2 = 0; q <= r; q++) {       if (stq.size() && stq.back() == m[q]) {         hs1 = (hs1 - m[q] + M1) % M1;         hs1 = hs1 * IB1 % M1;         hs2 = (hs2 - m[q] + M2) % M2;         hs2 = hs2 * IB2 % M2;         stq.pop_back();       } else {         stq.push_back(m[q]);         hs1 = (hs1 * BASE + m[q]) % M1;         hs2 = (hs2 * BASE + m[q]) % M2;       }       hr.push_back({hs1, hs2});     }     sort(hl.begin(), hl.end());     sort(hr.begin(), hr.end());     for (pair<long long, long long> i : hl) {       o += upper_bound(hr.begin(), hr.end(), i) -            lower_bound(hr.begin(), hr.end(), i);     }     rec(l, md);     rec(md + 1, r);   }   long long solve() {     cin >> a;     for (int q = 0; q < a; q++) cin >> m[q];     o = 0;     rec(0, a - 1);     return o;   }   int main() {     cin.tie(0);     cout.tie(0);     cin.sync_with_stdio(0);     cout.sync_with_stdio(0);     ;     IB1 = modInv(BASE, M1);     IB2 = modInv(BASE, M2);     pwb1[0] = 1;     pwb2[0] = 1;     for (int q = 1; q < G; q++) pwb1[q] = pwb1[q - 1] * BASE % M1;     for (int q = 1; q < G; q++) pwb2[q] = pwb2[q - 1] * BASE % M2;     int z;     cin >> z;     for (; z--;) {       cout << solve() <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long unorder(int n) {     if (n == 0) return 1;     if (n == 1) return 0;     bool good;     long long ans = 0;     vector<int> V(n);     for (int i = 0; i < n; i++) V[i] = i;     do {       good = true;       for (int i = 0; i < n && good; i++) good = (V[i] != i);       if (good) ans++;     } while (next_permutation(V.begin(), V.end()));     return ans;   }   long long newton(int n, int k) {     if (k > n) return 0;     if (2 * k > n) k = n - k;     long long ans = 1;     for (int i = n - k + 1; i <= n; i++) ans *= i;     for (int i = 1; i <= k; i++) ans /= i;     return ans;   }   int main() {     int n, k;     long long ans = 0;     cin >> n >> k;     for (int i = 0; i <= k; i++) {       long long unorders = unorder(i), combinations = newton(n, n - i);       ans += combinations * unorders;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dist[100010], n;   vector<pair<int, int> > gr[100010];   void dfs() {     memset(dist, -1, sizeof(dist));     dist[1] = 0;     queue<int> q;     q.push(1);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < gr[u].size(); i++) {         int next = gr[u][i].first;         if (dist[next] == -1) {           dist[next] = dist[u] + 1;           q.push(next);         }       }     }   }   vector<pair<int, pair<int, int> > > ans;   int v_ans = 0;   int dp[100010];   map<pair<int, int>, int> mark;   int calc_dp(int u) {     if (dp[u] != -1) return dp[u];     if (u == 1) return dp[u] = 0;     for (int i = 0; i < gr[u].size(); i++) {       int next = gr[u][i].first;       if (dist[next] == dist[u] - 1)         dp[u] = max(dp[u], calc_dp(next) + gr[u][i].second);     }     return dp[u];   }   void calc_ans(int u) {     if (u == 1) {       return;     }     for (int i = 0; i < gr[u].size(); i++) {       int next = gr[u][i].first;       if (dist[next] == dist[u] - 1 && dp[next] == dp[u] - gr[u][i].second) {         calc_ans(next);         mark[{min(next, u), max(next, u)}] = 1;         break;       }     }   }   int main() {     ios::sync_with_stdio(false);     memset(dp, -1, sizeof(dp));     int m;     cin >> n >> m;     int cont = 0;     vector<pair<int, pair<int, int> > > edges;     for (int i = 0; i < m; i++) {       int a, b, z;       cin >> a >> b >> z;       cont += z;       gr[a].push_back({b, z});       gr[b].push_back({a, z});       edges.push_back({z, {min(a, b), max(a, b)}});     }     dfs();     int v = calc_dp(n);     cout << (cont - v) + (dist[n] - v) << endl;     calc_ans(n);     for (int i = 0; i < m; i++) {       if (edges[i].first == 1 && !mark[edges[i].second])         cout << edges[i].second.first <<     << edges[i].second.second <<   0 n ;       if (edges[i].first == 0 && mark[edges[i].second])         cout << edges[i].second.first <<     << edges[i].second.second <<   1 n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b;   vector<pair<int, int> > x[255][4005];   int main() {     scanf( %d n , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d n , &a, &b);       x[a / 4000][b / 250].push_back(make_pair(a, i + 1));     }     for (int i = 0; i < 252; i++) {       for (int j = 0; j < 4002; j++)         if (!x[i][j].empty()) {           sort(x[i][j].begin(), x[i][j].end());           for (size_t k = 0; k < x[i][j].size(); k++)             printf( %d  , x[i][j][k].second);         }       i++;       for (int j = 4001; j >= 0; j--)         if (!x[i][j].empty()) {           sort(x[i][j].begin(), x[i][j].end());           for (size_t k = 0; k < x[i][j].size(); k++)             printf( %d  , x[i][j][k].second);         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     cin >> k;     vector<vector<int> > v = {{1}};     for (int i = 0; i < k; i++) {       int current = v.size();       for (int j = 0; j < current; j++) {         vector<int> vnew(2 * current);         for (int l = 0; l < current; l++) {           vnew[l] = v[j][l];           vnew[current + l] = v[j][l];           v[j].push_back(-v[j][l]);         }         v.push_back(vnew);       }     }     for (int i = 0; i < v.size(); i++) {       for (int j = 0; j < v[i].size(); j++) {         cout << ((v[i][j] == 1) ?  +  :  * );       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     cout << --n / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace IO {   template <typename t>   inline void read(t& x) {     x = 0;     bool f = 1;     char ch;     for (ch = getchar(); ch <  0  ||  9  < ch; ch = getchar())       if (ch ==  - ) f ^= 1;     for (;  0  <= ch && ch <=  9 ; ch = getchar())       x = (x << 3) + (x << 1) + (ch ^ 48);     x = f ? x : -x;   }   }  // namespace IO   const int MAXN = 50 + 10;   const int CHAR_RANGE = 26 + 10;   int n, len[2], f[MAXN][MAXN];   bool can[2][MAXN][MAXN][CHAR_RANGE];   char str[2][MAXN], tmp[10];   vector<int> trans[CHAR_RANGE], rtrans[CHAR_RANGE * CHAR_RANGE + 100];   void calc(int _) {     for (int i = (1), iend = (len[_]); i <= iend; ++i)       can[_][i][i][str[_][i] -  a ] = true;     for (int l = (2), lend = (len[_]); l <= lend; ++l) {       for (int i = (1), iend = (len[_] - l + 1); i <= iend; ++i) {         int j = i + l - 1;         for (int k = (i), kend = (j - 1); k <= kend; ++k)           for (int ch1 = (0), ch1end = (25); ch1 <= ch1end; ++ch1)             if (can[_][i][k][ch1])               for (int ch2 = (0), ch2end = (25); ch2 <= ch2end; ++ch2) {                 if (can[_][k + 1][j][ch2]) {                   for (int x : rtrans[26 * ch1 + ch2]) can[_][i][j][x] = true;                 }               }       }     }   }   int main() {     scanf( %s , str[0] + 1), scanf( %s , str[1] + 1);     len[0] = strlen(str[0] + 1), len[1] = strlen(str[1] + 1);     IO::read(n);     for (int i = (1), iend = (n); i <= iend; ++i) {       scanf( %s , tmp + 1);       rtrans[26 * (tmp[4] -  a ) + tmp[5] -  a ].push_back(tmp[1] -  a );     }     memset(f, -1, sizeof f);     f[0][0] = 0;     calc(0), calc(1);     for (int i = (1), iend = (len[0]); i <= iend; ++i)       for (int j = (1), jend = (len[1]); j <= jend; ++j) {         f[i][j] = 1e9;         for (int i2 = (0), i2end = (i - 1); i2 <= i2end; ++i2)           for (int j2 = (0), j2end = (j - 1); j2 <= j2end; ++j2)             if (f[i2][j2] != -1)               for (int ch1 = (0), ch1end = (25); ch1 <= ch1end; ++ch1) {                 if (can[0][i2 + 1][i][ch1] && can[1][j2 + 1][j][ch1]) {                   f[i][j] = min(f[i2][j2] + 1, f[i][j]);                 }               }         if (f[i][j] == 1e9) f[i][j] = -1;       }     printf( %d n , f[len[0]][len[1]]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     int n, h;     cin >> n >> h;     bool flag;     for (int k = 0; k < n; k++) {       flag = false;       for (int j = 0; j < n; j++) {         if (flag) cout <<    ;         flag = true;         if (j == k)           cout << h;         else           cout <<  0 ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p, q, ans = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> p;       cin >> q;       if (q - p >= 2) ans++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct vals {     bool vd;     char val[1010];     bool cur;     int idx[2];     string nome, op;   } s[5020];   bool valdef(bool k, int vv, int curidx) {     if (s[curidx].idx[vv] == -1) return k;     return s[s[curidx].idx[vv]].cur;   }   bool value(string op, bool k, int curidx) {     if (op ==  XOR ) {       return valdef(k, 0, curidx) ^ valdef(k, 1, curidx);     } else if (op ==  OR ) {       return valdef(k, 0, curidx) | valdef(k, 1, curidx);     } else if (op ==  AND ) {       return valdef(k, 0, curidx) & valdef(k, 1, curidx);     }   }   int main() {     int n, m;     char c;     char aux1[12], aux2[1010], aux3[5], aux4[12];     map<string, int> mpi;     cin >> n >> m;     for (int i = 0; i < (n); ++i) {       scanf( %s := %s%c , aux1, aux2, &c);       mpi[string(aux1)] = i;       if (c ==    ) {         scanf( %s %s , aux3, aux4);         if (string(aux2) !=  ? )           s[i].idx[0] = mpi[string(aux2)];         else           s[i].idx[0] = -1;         s[i].op = string(aux3);         if (string(aux4) !=  ? )           s[i].idx[1] = mpi[string(aux4)];         else           s[i].idx[1] = -1;         s[i].vd = false;       } else if (c ==   n  or c ==   r ) {         strcpy(s[i].val, aux2);         s[i].vd = true;       } else         cout <<  erro  << endl;     }     string sauxmax =   ;     string sauxmin =   ;     for (int i = 0; i < (m); ++i) {       vector<int> vsoma(2, 0);       for (int k = 0; k < (2); ++k) {         for (int j = 0; j < (n); ++j) {           bool baux;           if (s[j].vd) {             baux = s[j].val[i] -  0 ;             s[j].cur = baux;           } else {             baux = value(s[j].op, k, j);             s[j].cur = baux;           }           vsoma[k] += baux;         }       }       if (vsoma[1] > vsoma[0])         sauxmax +=  1 , sauxmin +=  0 ;       else if (vsoma[1] == vsoma[0])         sauxmax +=  0 , sauxmin +=  0 ;       else if (vsoma[1] < vsoma[0])         sauxmax +=  0 , sauxmin +=  1 ;     }     cout << sauxmin << endl << sauxmax << endl;   }


#include <bits/stdc++.h>   using namespace std;   string A[8];   int dx[9] = {-1, -1, -1, 0, 1, 1, 1, 0, 0};   int dy[9] = {-1, 0, 1, 1, 1, 0, -1, -1, 0};   bool dfs(int x, int y, int tour) {     if (x == 0 && y == 7) return 1;     if (tour > 8) return true;     for (int k = 0; k <= 8; k++) {       int nx = x + dx[k], ny = y + dy[k];       if (nx < 0 || ny < 0 || nx > 7 || ny > 7) continue;       if (nx - tour >= 0 && A[nx - tour][ny] ==  S ) continue;       if (nx - tour - 1 >= 0 && A[nx - tour - 1][ny] ==  S ) continue;       if (dfs(nx, ny, tour + 1)) return 1;     }     return 0;   }   int main() {     vector<pair<int, int> > S;     for (int i = 0; i < 8; i++) {       cin >> A[i];     }     if (dfs(7, 0, 0))       cout <<  WIN  << endl;     else       cout <<  LOSE  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void io() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   const int N = 2e5 + 9;   const long long MOD = 1e9 + 7;   const int INF = 1e9;   int dx[5] = {0, -1, 1, 0, 0};   int dy[5] = {0, 0, 0, -1, 1};   char dc[5] = { 0 ,  U ,  D ,  L ,  R };   int main() {     int test;     test = 1;     while (test--) {       int x, y;       cin >> x >> y;       int ans = 0;       while (x > 0 && y > 0) {         if (x > y) swap(x, y);         if (x < 100) x++;         y -= 2;         if (y < 0) break;         ans++;       }       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, m, d[N], a[N];   bool flag[N];   bool check(int x) {     memset(flag, 0, sizeof(flag));     int cur = x - 1;     for (int i = x; i >= 1; i--) {       cur = min(cur, i - 1);       if (d[i] && !flag[d[i]] && a[d[i]] <= cur) {         flag[d[i]] = 1;         cur -= a[d[i]] + 1;       }     }     for (int i = 1; i <= m; i++) {       if (!flag[i]) return 0;     }     return 1;   }   int main() {     int ans = -1;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , d + i);     for (int i = 1; i <= m; i++) scanf( %d , a + i);     int l = 1, r = n, mid;     while (l <= r) {       mid = (l + r) >> 1;       if (check(mid))         r = mid - 1, ans = mid;       else         l = mid + 1;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, size_t N>   struct ma : array<T, N> {     T &operator[](size_t n) { return (*static_cast<array<T, N> *>(this))[n]; }   };   template <class T>   string to_str(const T &a) {     ostringstream os;     os << a;     return os.str();   }   template <>   string to_str<long double>(const long double &a) {     ostringstream os;     os.precision(10);     os.setf(ios::fixed);     os << a;     return os.str();   }   template <class T>   T from_str(const string &s) {     istringstream is;     T val;     is >> val;     return val;   }   int cond = (long long)0;   void solve() {     int n, m;     scanf( %d%d , &n, &m);     vector<int> co(n);     for (auto i = (0); i < (n); ++i) scanf( %d , &co[i]);     long long ret = 0;     for (auto i = (0); i < (m); ++i) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       ret += min(co[a], co[b]);     }     cout << ret << endl;   }   void brute() {}   void gen(int i, int n, int k) {}   int main(int argc, char **argv) {     ios::sync_with_stdio(false);     vector<string> args;     int nr_test = -1;     int t = 1;     for (auto i = (1); i <= (argc - 1); ++i) args.push_back(argv[i]);     for (auto &it : (args))       if (it ==  q ) cond = 10000000;     for (auto &it : (args))       if (it ==  all ) t = 1000;     for (auto &it : (args))       if (atoi(it.c_str()) > 0) nr_test = atoi(it.c_str());     for (auto &it : (args))       if (it ==  b ) {         brute();         return 0;       }     for (auto &it : (args))       if (it ==  g  && args.size() >= 4) {         gen(atoi(args[1].c_str()), atoi(args[2].c_str()), atoi(args[3].c_str()));         return 0;       }     for (auto i = (1); i <= (t); ++i) {       if (nr_test == -1 || i <= nr_test) solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, dx4[4] = {-1, 0, 1, 0};   int dy8[8] = {0, -1, -1, -1, 0, 1, 1, 1}, dy4[4] = {0, -1, 0, 1};   inline void open(string name) {     freopen((name +  .in ).c_str(),  r , stdin);     freopen((name +  .out ).c_str(),  w , stdout);   }   inline void close() {     fclose(stdin);     fclose(stdout);   }   inline int io() {     register char c;     while (1) {       c = getchar_unlocked();       if (c !=   n  && c !=    ) break;     }     int res = 0, sign = 1;     if (c ==  - )       sign = -1;     else       res = c -  0 ;     while (1) {       c = getchar_unlocked();       if (c ==     || c ==   n  || c == EOF) break;       res = (res << 3) + (res << 1) + c -  0 ;     }     return res * sign;   }   const int N = 100005;   struct Bullet {     int x;     int y;     int idx;     Bullet() {}     bool operator<(Bullet other) const {       if (x == other.x) {         if (y == other.y)           return idx < other.idx;         else           return y < other.y;       } else         return x < other.x;     }   };   Bullet origin[N], arr[N];   struct Node {     vector<pair<int, int> > bullet_list;     vector<int> RMQ;     Node() {       bullet_list.clear();       RMQ.clear();     }     void Build() {       RMQ.resize(4 * bullet_list.size());       Build(1, 0, bullet_list.size() - 1);     }     void Build(int id, int l, int r) {       if (l == r)         RMQ[id] = bullet_list[l].second;       else {         int chld = id << 1, m = (l + r) >> 1;         Build(chld, l, m);         Build(chld + 1, m + 1, r);         RMQ[id] = min(RMQ[chld], RMQ[chld + 1]);       }     }     int Query(int ya, int yb) {       int st =           lower_bound(bullet_list.begin(), bullet_list.end(), make_pair(ya, 0)) -           bullet_list.begin();       int en = upper_bound(bullet_list.begin(), bullet_list.end(),                            make_pair(yb, 1000000000)) -                bullet_list.begin();       en--;       if (st > en)         return 1000000000;       else         return Query(1, 0, bullet_list.size() - 1, st, en);     }     int Query(int id, int l, int r, int x, int y) {       if (x <= l && r <= y)         return RMQ[id];       else {         int chld = (id << 1), m = (l + r) >> 1;         int res = 1000000000;         if (x <= m) res = min(res, Query(chld, l, m, x, y));         if (y > m) res = min(res, Query(chld + 1, m + 1, r, x, y));         return res;       }     }     void Del(int id) {       int ya = origin[id].y;       int st =           lower_bound(bullet_list.begin(), bullet_list.end(), make_pair(ya, id)) -           bullet_list.begin();       Del(1, 0, bullet_list.size() - 1, st);     }     void Del(int id, int l, int r, int x) {       if (l == r) {         RMQ[id] = 1000000000;       } else {         int chld = id << 1, m = (l + r) >> 1;         if (x <= m)           Del(chld, l, m, x);         else           Del(chld + 1, m + 1, r, x);         RMQ[id] = min(RMQ[chld], RMQ[chld + 1]);       }     }   };   Node rtree[4 * N];   vector<int> X;   int n, q;   int ans[N];   void BuildRangeTree(int id, int l, int r) {     if (l == r) {       rtree[id].bullet_list.push_back(make_pair(arr[l].y, arr[l].idx));     } else {       int chld = id << 1, m = (l + r) >> 1;       BuildRangeTree(chld, l, m);       BuildRangeTree(chld + 1, m + 1, r);       int i = 0, j = 0;       while (i < rtree[chld].bullet_list.size() &&              j < rtree[chld + 1].bullet_list.size()) {         if (rtree[chld].bullet_list[i] < rtree[chld + 1].bullet_list[j])           rtree[id].bullet_list.push_back(rtree[chld].bullet_list[i++]);         else           rtree[id].bullet_list.push_back(rtree[chld + 1].bullet_list[j++]);       }       while (i < rtree[chld].bullet_list.size())         rtree[id].bullet_list.push_back(rtree[chld].bullet_list[i++]);       while (j < rtree[chld + 1].bullet_list.size())         rtree[id].bullet_list.push_back(rtree[chld + 1].bullet_list[j++]);     }     rtree[id].Build();   }   void UpdateRangeTree(int pos) {     int idpos = lower_bound(arr, arr + q, origin[pos]) - arr;     int id = 1, l = 0, r = q - 1;     while (1) {       rtree[id].Del(pos);       if (l == r) break;       int chld = id << 1, m = (l + r) >> 1;       if (idpos <= m)         r = m, id = chld;       else         l = m + 1, id = chld + 1;     }   }   int QueryRangeTree(int id, int l, int r, int x, int y, int ya, int yb) {     int res = 1000000000;     if (x <= l && r <= y)       res = rtree[id].Query(ya, yb);     else {       int chld = (id << 1), m = (l + r) >> 1;       res = 1000000000;       if (x <= m) res = min(res, QueryRangeTree(chld, l, m, x, y, ya, yb));       if (y > m) res = min(res, QueryRangeTree(chld + 1, m + 1, r, x, y, ya, yb));     }     return res;   }   struct Target {     int xa;     int ya;     int xb;     int yb;     int z;     int idx;     Target() {}     bool operator<(Target other) const {       if (z == other.z) return idx < other.idx;       return z < other.z;     }   };   Target arr2[N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d %d %d %d , &arr2[i].xa, &arr2[i].xb, &arr2[i].ya, &arr2[i].yb,             &arr2[i].z);       arr2[i].idx = i;     }     sort(arr2, arr2 + n);     scanf( %d , &q);     for (int i = 0; i < q; i++) {       scanf( %d %d , &origin[i].x, &origin[i].y);       origin[i].idx = i;       X.push_back(origin[i].x);       arr[i] = origin[i];     }     sort(arr, arr + q);     sort(X.begin(), X.end());     BuildRangeTree(1, 0, q - 1);     memset(ans, -1, sizeof ans);     for (int i = 0; i < n; i++) {       int x1 = lower_bound(X.begin(), X.end(), arr2[i].xa) - X.begin();       int x2 = upper_bound(X.begin(), X.end(), arr2[i].xb) - X.begin();       x2--;       if (x1 <= x2) {         int res = QueryRangeTree(1, 0, q - 1, x1, x2, arr2[i].ya, arr2[i].yb);         if (res != 1000000000) {           ans[res] = arr2[i].idx;           UpdateRangeTree(res);         }       }     }     for (int i = 0; i < q; i++) printf( %d n , ans[i] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     char tmp =  z ;     cin >> str;     for (int i = 0; i < str.length(); i++) {       if (str[i] <= tmp) {         tmp = str[i];         cout <<  Mike  << endl;       } else {         cout <<  Ann  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, m, a, b;     cin >> n >> m >> a >> b;     long long int res, ans;     res = n / m;     if (n % m) res++;     res = (res * m - n) * a;     ans = (n % m) * b;     cout << min(res, ans) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long min(long long a, long long b) { return (a < b) ? a : b; }   long long max(long long a, long long b) { return (a > b) ? a : b; }   long long fp(long long a, long long b) {     if (b == 0) return 1;     long long x = fp(a, b / 2);     x = (x * x) % mod;     if (b & 1) x = (x * a) % mod;     return x;   }   const long long N = 2e5 + 5;   long long a[N];   long long n;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     long long cnt[60] = {0};     for (long long i = 1; i <= n; i++) {       cin >> a[i];       for (long long b = 0; b < 20; b++) {         if ((a[i] >> b) & 1) {           cnt[b]++;         }       }     }     long long ans = 0;     for (long long i = 1; i <= n; i++) {       long long x = 0;       for (long long b = 0; b < 20; b++) {         if (cnt[b]) {           cnt[b]--;           x |= (1ll << b);         }       }       ans += x * x;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x;   vector<pair<int, int> > leti[26];   vector<pair<int, int> > shift;   vector<int> dis[26];   int main() {     cin >> n >> m >> x;     int d = x * x;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         char t;         cin >> t;         if (t ==  S )           shift.push_back(pair<int, int>(i, j));         else           leti[t -  a ].push_back(pair<int, int>(i, j));       }     }     for (int i = 0; i < 26; i++) {       for (int j = 0; j < leti[i].size(); j++) {         int mn = 0x7fffffff;         for (int k = 0; k < shift.size(); k++) {           int dx = shift[k].first - leti[i][j].first;           int dy = shift[k].second - leti[i][j].second;           mn = min(mn, dx * dx + dy * dy);         }         dis[i].push_back(mn);       }     }     int q;     cin >> q;     int cnt = 0;     for (int i = 0; i < q; i++) {       char t;       cin >> t;       if (((t -  a ) >= 0) && leti[t -  a ].empty()) {         cout << -1 << endl;         return 0;       }       if (((t -  a ) < 0) && leti[t -  A ].empty()) {         cout << -1 << endl;         return 0;       }       if (((t -  a ) < 0) && shift.empty()) {         cout << -1 << endl;         return 0;       }       if ((t -  a ) < 0) {         int flag = true;         for (int j = 0; j < leti[t -  A ].size(); j++) {           if (dis[t -  A ][j] <= d) {             flag = false;             break;           }         }         if (flag)           cnt++;         else           flag = true;       }     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long int Maxn3 = 1e3 + 10;   const long long int Maxn4 = 1e4 + 10;   const long long int Maxn5 = 1e5 + 10;   const long long int Maxn6 = 1e6 + 10;   const long long int Maxn7 = 1e7 + 10;   const long long int Maxn8 = 1e8 + 10;   const long long int Maxn9 = 1e9 + 10;   const long long int Maxn18 = 1e18 + 10;   const long long int Mod1 = 1e7 + 7;   const long long int Mod2 = 1e9 + 7;   const long long int LLMax = LLONG_MAX;   const long long int LLMin = LLONG_MIN;   const long long int INTMax = INT_MAX;   const long long int INTMin = INT_MIN;   long long int mn = LLMax, mx = LLMin;   bool prime(int x) {     for (int i = 2; i * i <= x; i++)       if (x % i == 0) return 0;     return 1;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n;     cin >> n;     if (prime(n) == 1)       return cout <<  1 n  << n, 0;     else {       cout <<  3 n3  ;       n -= 3;       for (int i = 3; i < n; i += 2)         if (prime(n - i) and prime(i)) return cout << i <<     << n - i, 0;     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   FILE *in = stdin, *out = stdout;   using namespace std;   #pragma comment(linker,  /stack:36777216 )   int n;   char a[300005];   int D[300005];   void input() {     fscanf(in,  %d , &n);     fscanf(in,  %s , &a[1]);   }   bool isSame(int x) {     if (x & 1) return false;     for (int i = (1); i <= (x / 2); i++) {       if (a[i] != a[i + x / 2]) return false;     }     return true;   }   void pro() {     int ans = n;     for (int i = (1); i <= (n); i++) {       if (isSame(i)) ans = min(ans, i / 2 + 1 + (n - i));     }     fprintf(out,  %d , ans);   }   int main() {     input();     pro();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     cin >> n >> m;     if (m / n == 2)       cout << n - m % n;     else if (m / n == 1)       cout << m % n;     else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 110, M = 10010;   int n;   long double x;   int c[N], all;   long double binom[N][N];   long double f[N][M];   int main() {     cin >> n >> x;     for (int i = 1; i <= n; i++) scanf( %d , &c[i]), all += c[i];     f[0][0] = 1;     for (int i = 0; i <= n; i++) {       binom[i][0] = binom[i][i] = 1;       for (int j = 1; j < i; j++)         binom[i][j] = binom[i - 1][j] + binom[i - 1][j - 1];     }     f[0][0] = 1;     for (int id = 1; id <= n; id++) {       for (int i = id; i; i--) {         for (int j = all; j >= c[id]; j--) {           f[i][j] += f[i - 1][j - c[id]];         }       }     }     long double ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= all; j++) {         long double v = f[i][j];         v /= binom[n][i];         v *= min(x / 2 + x / 2 * n / i, (long double)j / (long double)i);         ans += v;       }     }     printf( %.15Lf n , ans);   }