#include <bits/stdc++.h>
 using namespace std;
 const int T = 31;
 const int mod = 1000000007;
 const long long oo = 1LL << 60;
 long long N;
 int K;
 long long B[T][T];
 long long power[70];
 long long dp[70][T][T];
 bool bio[70];
 long long rot[T][T][T];
 long long mult(long long a, long long b) {
   if (a == 0) return 0;
   if (b >= oo / a + 1) return oo;
   return a * b;
 }
 void mult(long long A[T][T], long long B[T][T]) {
   static long long C[T][T];
   for (int i = (0); i < (T); ++i)
     for (int j = (0); j < (T); ++j) C[i][j] = 0;
   for (int i = (0); i < (T); ++i)
     for (int j = (0); j < (T); ++j)
       for (int k = (0); k < (T); ++k)
         C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;
   for (int i = (0); i < (T); ++i)
     for (int j = (0); j < (T); ++j) A[i][j] = C[i][j];
 }
 void rec(long long prefix, int n, long long A[T][T]) {
   long long lo = mult(prefix, power[n]);
   long long hi = lo + power[n] - 1;
   if (lo >= N) return;
   long long z = prefix % K;
   mult(A, rot[z]);
   if (n == 0) {
     mult(A, B);
   } else {
     bool memo = hi < N;
     auto AA = memo ? dp[n] : A;
     if (!bio[n] && memo)
       for (int i = (0); i < (T); ++i) AA[i][i] = 1;
     if (!bio[n] || !memo)
       for (int i = (0); i < (K); ++i) rec(prefix * K + i, n - 1, AA);
     if (memo) bio[n] = true, mult(A, AA);
   }
   mult(A, rot[(K - z) % K]);
 }
 int main() {
   scanf( %lld%d , &N, &K);
   for (int i = (0); i < (K); ++i) B[i][i] = 1;
   for (int i = (1); i < (K); ++i) B[i][0] = 1;
   B[K][0] = 1;
   B[K][K] = 1;
   for (int x = (0); x < (K); ++x)
     for (int i = (0); i < (K); ++i) rot[x][i][(i + x) % K] = 1;
   for (int x = (0); x < (K); ++x)
     for (int i = (K); i < (T); ++i) rot[x][i][i] = 1;
   static long long A[T][T];
   A[0][K] = 1;
   power[0] = 1;
   for (int i = (1); i < (70); ++i) power[i] = mult(power[i - 1], K);
   rec(0, 69, A);
   long long ans = 1;
   for (int i = (0); i < (K); ++i) ans = (ans + A[0][i]) % mod;
   printf( %lld
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base ::sync_with_stdio(false);
   cin.tie(NULL);
   int n, p, q;
   cin >> n;
   vector<pair<int, int>> v1;
   int x1, x2;
   for (size_t i = 0; i < n; i++) {
     cin >> x1 >> x2;
     v1.push_back(make_pair(x1, x2));
   }
   bool s = true;
   sort(v1.begin(), v1.end());
   for (size_t i = 0; i < n; i++) {
     if (v1[i].second > v1[i + 1].second && i + 1 < n) {
       s = false;
       break;
     }
   }
   if (s == true) {
     cout <<  Poor Alex ;
   } else {
     cout <<  Happy Alex ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 int main() {
   int n;
   scanf( %d , &n);
   printf( %d , n % 2);
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> t;
 int n, x, i, j, h, sol, temp;
 int main() {
   ios::sync_with_stdio(false);
   cin >> n;
   for (i = 0; i < n; i++) {
     cin >> x;
     t.push_back(x);
   }
   cin >> h;
   sort(t.begin(), t.end());
   sol = 0;
   for (i = 0; i < n; i++) {
     temp = 1;
     for (j = i + 1; j < n; j++) {
       if (t[j] - t[i] <= h) temp++;
     }
     sol = max(sol, temp);
   }
   cout << sol << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 305;
 int n, m;
 class Point {
  public:
   long long x, y;
   Point() : x(0), y(0) {}
   Point(long long _x, long long _y) : x(_x), y(_y) {}
   void read() { scanf( %lld%lld , &x, &y); }
   Point operator+(const Point &o) const { return Point(x + o.x, y + o.y); }
   Point operator-(const Point &o) const { return Point(x - o.x, y - o.y); }
   long long operator*(const Point &o) const { return x * o.y - y * o.x; }
   bool operator<(const Point &o) const {
     int c = (y == 0 && x > 0) || (y > 0);
     int oc = (o.y == 0 && o.x > 0) || (o.y > 0);
     if (c != oc) return c > oc;
     return (*this) * o > 0;
   }
 } p[maxn];
 class Edge {
  public:
   Point w;
   int u, v;
   Edge() {}
   Edge(Point _w, int _u, int _v) : w(_w), u(_u), v(_v) {}
   bool operator<(const Edge &o) const { return w < o.w; }
 } e[maxn * maxn];
 long long dp[maxn][maxn][6];
 int main() {
   scanf( %d , &n);
   for (int i = 0; i < n; i++) p[i].read();
   for (int i = 0; i < n; i++)
     for (int j = i + 1; j < n; j++) {
       e[m++] = Edge(p[j] - p[i], i, j);
       e[m++] = Edge(p[i] - p[j], j, i);
     }
   sort(e, e + m);
   for (int i = 0; i < n; i++) dp[i][i][0] = 1;
   for (int i = 0; i < m; i++)
     for (int j = 0; j < n; j++)
       for (int k = 0; k < 5; k++) dp[j][e[i].v][k + 1] += dp[j][e[i].u][k];
   long long ans = 0;
   for (int i = 0; i < n; i++) ans += dp[i][i][5];
   printf( %lld
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void solve() {
   long long n, x;
   cin >> n >> x;
   string second;
   cin >> second;
   long long ans = 0;
   long long sm = 0;
   for (long long i = 0; i < n; i++) {
     if (second[i] == '0')
       sm++;
     else
       sm--;
   }
   long long c = 0;
   for (long long i = 0; i < n; i++) {
     if (sm == 0 && c == x) {
       cout << -1 << endl;
       return;
     }
     if ((x - c) % sm == 0 && (x - c) / sm >= 0 && sm != 0) ans++;
     if (second[i] == '0')
       c++;
     else
       c--;
   }
   cout << ans << endl;
 }
 int main() {
   long long t;
   cin >> t;
   while (t--) solve();
 }


#include <bits/stdc++.h>
 using namespace std;
 struct sort_pred {
   bool operator()(const std::pair<int, int> &left,
                   const std::pair<int, int> &right) {
     return right.first > left.first;
   }
 };
 int n, m, k, t;
 int r = 0;
 vector<bool> visited;
 vector<vector<int>> v;
 vector<int> distanc;
 queue<int> q;
 map<pair<int, int>, int> mp;
 vector<bool> chosen;
 void bfs(int first) {
   visited[first] = true;
   q.push(first);
   while (!q.empty()) {
     int s = q.front();
     q.pop();
     for (auto u : v[s]) {
       if (distanc[s] - mp[make_pair(s, u)] >= 0 &&
           distanc[s] - mp[make_pair(s, u)] > distanc[u]) {
         if (!visited[u]) r++;
         visited[u] = true;
         distanc[u] = distanc[s] - mp[make_pair(s, u)];
         if (chosen[u]) distanc[u] = t;
         q.push(u);
       }
     }
   }
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int n;
   cin >> n;
   map<int, int> mp;
   vector<int> b(n);
   for (int i = 0; i < n; i++) {
     int first;
     cin >> first;
     mp[first] = i + 1;
   }
   for (int i = 0; i < n; i++) {
     int first;
     cin >> first;
     cout << mp[first] <<    ;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 1e9 + 7;
 const int inf = 1e9 + 5;
 long long powmod(long long a, long long b) {
   long long ret = 1;
   while (b) {
     if (b & 1) ret = (ret * a) % mod;
     a = (a * a) % mod;
     b >>= 1;
   }
   return ret;
 }
 const int maxn = 3e5 + 5;
 long long a[maxn];
 int n, m;
 int q[maxn];
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   cin >> n;
   long long tot = 0;
   for (int i = 0; i <= n - 1; i++) {
     cin >> a[i];
     tot += a[i];
   }
   sort(a, a + n);
   cin >> m;
   for (int i = 0; i <= m - 1; i++) {
     cin >> q[i];
     cout << tot - a[n - q[i]] <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 1002000, CAN = 34;
 int n, m, p, vis[MAXN], pr[MAXN], pcnt;
 char w1[MAXN], w2[MAXN];
 vector<int> can[300];
 int muln(int x, int y) { return 1LL * x * y % p; }
 int mo(int x) {
   while (x >= p) x -= p;
   while (x < 0) x += p;
   return x;
 }
 int qpow(int x, int y) {
   int ret = 1;
   for (; y; y >>= 1, x = muln(x, x))
     if (y & 1) ret = muln(ret, x);
   return ret;
 }
 struct poly {
   int deg;
   vector<int> a;
   poly(int x = 0) : deg(x) { a.resize(x + 1, 0); }
   int& operator[](int idx) { return a[idx]; }
   void print(string s) {
     cerr <<  Poly   << s <<  :  ;
     for (auto g : a) printf( %d  , g);
     cerr << endl;
   }
   int at(int x) {
     x = mo(x);
     int ret = 0;
     for (int i = deg; i >= 0; --i) ret = mo(muln(ret, x) + mo(a[i]));
     return ret;
   }
   void norm() {
     for (auto& g : a) g = mo(g);
   }
 } I;
 void sieve() {
   for (int i = 2; i <= 1000000; ++i) {
     if (!vis[i]) {
       pr[++pcnt] = i;
     }
     for (int j = 1; j <= pcnt && i * pr[j] <= 1000000; ++j) {
       vis[i * pr[j]] = true;
       if (i % pr[j] == 0) break;
     }
   }
   for (int k = 1, i = pr[k]; k <= pcnt; i = pr[++k]) {
     if (i > m)
       for (int j = 1; j <= CAN; ++j)
         if ((i - 1) % pr[j] == 0) can[j].push_back(i);
   }
 }
 void sol(int opt) {
   int d = pr[opt];
   poly a(d - 1);
   for (int i = 0; i < n; ++i) a[i % d] += I[i];
   for (auto pri : can[opt]) {
     p = pri;
     int rr = 2;
     while (qpow(rr, (p - 1) / d) == 1) rr++;
     rr = qpow(rr, (p - 1) / d);
     for (int Cnt = 1; Cnt < d; ++Cnt) {
       int r = qpow(rr, Cnt);
       if (r < 2 || r > p - 2) continue;
       int val = a.at(r);
       if (val == 0) {
         printf( %d %d
 , p, r);
         exit(0);
       }
     }
   }
 }
 int main() {
   scanf( %d%d%s%s , &n, &m, w1, w2);
   sieve();
   I = poly(n - 1);
   for (int i = 0; i < n; ++i) I[i] = w1[i] - w2[i];
   for (int i = 1; i <= CAN; ++i) sol(i);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 int a[100007], ans[100007], vis[100007];
 int count(int x) {
   int cnt = 0, now = 0;
   memset(vis, 255, sizeof(vis));
   for (int i = 1; i <= n; i++) {
     if (vis[a[i]] == now) continue;
     vis[a[i]] = now;
     if (++cnt > x) {
       cnt = 1;
       vis[a[i]] = ++now;
     }
   }
   return now + 1;
 }
 void work(int l, int r) {
   if (l > r) return;
   int cnt1 = count(l), cnt2 = count(r);
   if (cnt1 == cnt2) {
     for (int i = l; i <= r; i++) ans[i] = cnt1;
     return;
   }
   ans[l] = cnt1;
   ans[r] = cnt2;
   int mid = (l + r) >> 1;
   work(l + 1, mid);
   work(mid + 1, r - 1);
 }
 int main() {
   scanf( %d , &n);
   for (int i = 1; i <= n; i++) scanf( %d , &a[i]);
   work(1, n);
   for (int i = 1; i <= n; i++) printf( %d  , ans[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long N = 1e5 + 5;
 int32_t main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   long long n;
   cin >> n;
   long long a[n];
   for (long long i = 0; i < n; i++) cin >> a[i];
   vector<long long> good, bad;
   for (long long i = 0; i < n; i++) {
     long long val = sqrt(a[i]);
     if (val * val == a[i])
       good.push_back(a[i]);
     else
       bad.push_back(a[i]);
   }
   long long sz1 = good.size(), sz2 = bad.size();
   if (sz1 == sz2) {
     cout << 0 << '
';
   } else if (sz1 > sz2) {
     long long nz = 0;
     for (auto it : good) {
       if (it) nz++;
     }
     long long req = (sz1 - sz2) / 2;
     if (nz >= req)
       cout << req << '
';
     else
       cout << nz + (req - nz) * 2 << '
';
   } else {
     vector<long long> ans;
     long long req = (sz2 - sz1) / 2;
     for (auto it : bad) {
       long long val = sqrt(it);
       long long down = it - val * val, up = (val + 1) * (val + 1) - it;
       ans.push_back(min(down, up));
     }
     sort(ans.begin(), ans.end());
     long long fans = 0;
     for (long long i = 0; i < req; i++) {
       fans += ans[i];
     }
     cout << fans << '
';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX = (1 << 22) + 5;
 int n, m;
 bool is[MAX], seen[MAX];
 int conj(int x) {
   int r = 0;
   for (int i = 0; i < n; ++i)
     if (!(x & (1 << i))) r += (1 << i);
   return r;
 }
 void dfs(int st, bool p = 0) {
   if (seen[st]) return;
   seen[st] = 1;
   if (is[st]) dfs(conj(st), 1);
   if (p) {
     for (int i = 0; i < n; ++i)
       if (st & (1 << i)) {
         dfs(st - (1 << i), 1);
       }
   }
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0), cout.tie(0);
   cin >> n >> m;
   vector<int> st((1 << n) + 1, 0);
   vector<bool> lz((1 << n) + 1, 0);
   for (int i = 0; i < m; ++i) {
     int x;
     cin >> x;
     is[x] = 1;
   }
   int cnt = 0;
   for (int i = 0; i < (1 << n); ++i) {
     if (!seen[i] && is[i]) {
       dfs(i);
       ++cnt;
     }
   }
   cout << cnt << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main(void) {
   long long int n, x;
   cin >> n;
   vector<vector<long long int> > a(n);
   for (long long int i = 0; i < n; i++) {
     cin >> x;
     for (long long int j = 0; j < x; j++) {
       long long int tp;
       cin >> tp;
       a[i].push_back(tp);
     }
   }
   long long int a1 = 0, b = 0;
   vector<long long int> q;
   for (long long int i = 0; i < n; i++) {
     long long int f = a[i].size();
     if (f % 2 != 0) {
       for (long long int j = 0; j < (f - 1) / 2; j++) {
         a1 += a[i][j];
       }
       for (long long int j = (f - 1) / 2 + 1; j < f; j++) {
         b += a[i][j];
       }
       q.push_back(a[i][(f - 1) / 2]);
     } else {
       for (long long int j = 0; j < f / 2; j++) {
         a1 += a[i][j];
       }
       for (long long int j = f / 2; j < f; j++) {
         b += a[i][j];
       }
     }
   }
   sort(q.begin(), q.end(), greater<long long int>());
   for (long long int k = 0; k < q.size(); k++) {
     if (k % 2 == 0)
       a1 += q[k];
     else
       b += q[k];
   }
   cout << a1 <<     << b;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxN = 3 * (int)1e5 + 100;
 int b[maxN];
 int t[4 * maxN];
 int a[maxN];
 void build(int v, int tl, int tr) {
   if (tl == tr) {
     t[v] = a[tl];
     return;
   }
   int tm = (tl + tr) / 2;
   build(v + v, tl, tm);
   build(v + v + 1, tm + 1, tr);
   t[v] = min(t[v + v], t[v + v + 1]);
 }
 void upd(int v, int tl, int tr, int pos, int val) {
   if (tl == tr) {
     t[v] = val;
     return;
   }
   int tm = (tl + tr) / 2;
   if (pos <= tm)
     upd(v + v, tl, tm, pos, val);
   else
     upd(v + v + 1, tm + 1, tr, pos, val);
   t[v] = min(t[v + v], t[v + v + 1]);
 }
 const int INF = (int)1e9 + 100;
 int get(int v, int tl, int tr, int l, int r) {
   if (l > r) return INF;
   if (tl == l && tr == r) {
     return t[v];
   }
   int tm = (tl + tr) / 2;
   return min(get(v + v, tl, tm, l, min(r, tm)),
              get(v + v + 1, tm + 1, tr, max(l, tm + 1), r));
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   int q;
   cin >> q;
   while (q--) {
     int n;
     cin >> n;
     set<pair<int, int> > s;
     for (int i = 1; i <= n; i++) {
       cin >> a[i];
       s.insert(make_pair(a[i], i));
     }
     bool ok = true;
     build(1, 1, n);
     for (int i = 1; i <= n; i++) {
       cin >> b[i];
       if (!ok) continue;
       auto it = s.lower_bound(make_pair(b[i], -1));
       if (it == s.end() || ((it->first) != b[i])) {
         ok = false;
         continue;
       }
       int ind = (it->second);
       s.erase(it);
       if (b[i] != get(1, 1, n, 1, ind)) {
         ok = false;
       }
       upd(1, 1, n, ind, INF);
     }
     if (ok)
       cout <<  YES  << '
';
     else
       cout <<  NO  << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[11];
 int main() {
   int i, n, m, x;
   while (scanf( %d , &a[0]) > 0) {
     int c[33] = {0};
     c[a[0]]++;
     for ((i) = 0; (i) < (5); (i)++) {
       scanf( %d , &a[i + 1]);
       c[a[i + 1]]++;
     }
     bool f = 0;
     int mx = 0;
     for ((i) = 0; (i) < (11); (i)++) {
       mx = max(mx, c[i]);
       c[i] = c[i] % 4;
       if (c[i] == 2) f = 1;
     }
     if (mx < 4)
       printf( Alien
 );
     else if (f)
       printf( Elephant
 );
     else
       printf( Bear
 );
   }
   return 0;
 }


#include <bits/stdc++.h>
 const int MAXN = 2000 + 10;
 const int INF = std::numeric_limits<int>::max();
 const double EPS = 1e-6;
 const int dx[] = {1, 0, -1, 0};
 const int dy[] = {0, 1, 0, -1};
 int a[MAXN][MAXN];
 std::deque<std::pair<std::pair<int, int>, int>> q;
 using std::cin;
 using std::cout;
 using std::endl;
 int main() {
   std::ios_base::sync_with_stdio(false);
   std::cin.tie(0);
   std::cout.tie(0);
   int n, m;
   cin >> n >> m;
   int r, c;
   cin >> r >> c;
   int x, y;
   cin >> x >> y;
   for (int i = 0; i <= n + 1; ++i) {
     for (int j = 0; j <= m + 1; ++j) {
       a[i][j] = -1;
     }
   }
   for (int i = 1; i <= n; ++i) {
     for (int j = 1; j <= m; ++j) {
       char c;
       cin >> c;
       if (c == '.') a[i][j] = INF;
     }
   }
   q.push_back({{r, c}, 0});
   a[r][c] = 0;
   while (!q.empty()) {
     int cur_x = q.front().first.first, cur_y = q.front().first.second,
         cur_step = q.front().second;
     q.pop_front();
     for (int i = 0; i < 4; ++i) {
       if (a[cur_x + dx[i]][cur_y + dy[i]] > cur_step + (dy[i] == -1)) {
         a[cur_x + dx[i]][cur_y + dy[i]] = cur_step + (dy[i] == -1);
         if (dy[i] == -1)
           q.push_back({{cur_x + dx[i], cur_y + dy[i]}, cur_step + 1});
         else
           q.push_front({{cur_x + dx[i], cur_y + dy[i]}, cur_step});
       }
     }
   }
   int ans = 0;
   for (int i = 1; i <= n; ++i) {
     for (int j = 1; j <= m; ++j) {
       if (a[i][j] != -1) {
         if (a[i][j] <= x && a[i][j] + j - c <= y) {
           ++ans;
         }
       }
     }
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast,unroll-loops,no-stack-protector,fast-math,inline )
 #pragma GCC target( \n      sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )
 using namespace std;
 template <typename T>
 ostream &operator<<(ostream &os, const vector<T> &v) {
   os << '{';
   string sep;
   for (const auto &x : v) os << sep << x, sep =  ,  ;
   return os << '}';
 }
 template <typename A, typename B>
 ostream &operator<<(ostream &os, const pair<A, B> &p) {
   return os << '(' << p.first <<  ,   << p.second << ')';
 }
 void dbg_out() { cerr << endl; }
 template <typename Head, typename... Tail>
 void dbg_out(Head H, Tail... T) {
   cerr << ' ' << H;
   dbg_out(T...);
 }
 template <const int &MOD>
 struct _m_int {
   int val;
   _m_int(int64_t v = 0) {
     if (v < 0) v = v % MOD + MOD;
     if (v >= MOD) v %= MOD;
     val = v;
   }
   static int inv_mod(int a, int m = MOD) {
     int g = m, r = a, x = 0, y = 1;
     while (r != 0) {
       int q = g / r;
       g %= r;
       swap(g, r);
       x -= q * y;
       swap(x, y);
     }
     return x < 0 ? x + m : x;
   }
   explicit operator int() const { return val; }
   explicit operator int64_t() const { return val; }
   _m_int &operator+=(const _m_int &other) {
     val -= MOD - other.val;
     if (val < 0) val += MOD;
     return *this;
   }
   _m_int &operator-=(const _m_int &other) {
     val -= other.val;
     if (val < 0) val += MOD;
     return *this;
   }
   static unsigned fast_mod(uint64_t x, unsigned m = MOD) {
     return x % m;
     unsigned x_high = x >> 32, x_low = (unsigned)x;
     unsigned quot, rem;
     asm( divl %4
  :  =a (quot),  =d (rem) :  d (x_high),  a (x_low),  r (m));
     return rem;
   }
   _m_int &operator*=(const _m_int &other) {
     val = fast_mod((uint64_t)val * other.val);
     return *this;
   }
   _m_int &operator/=(const _m_int &other) { return *this *= other.inv(); }
   friend _m_int operator+(const _m_int &a, const _m_int &b) {
     return _m_int(a) += b;
   }
   friend _m_int operator-(const _m_int &a, const _m_int &b) {
     return _m_int(a) -= b;
   }
   friend _m_int operator*(const _m_int &a, const _m_int &b) {
     return _m_int(a) *= b;
   }
   friend _m_int operator/(const _m_int &a, const _m_int &b) {
     return _m_int(a) /= b;
   }
   _m_int &operator++() {
     val = val == MOD - 1 ? 0 : val + 1;
     return *this;
   }
   _m_int &operator--() {
     val = val == 0 ? MOD - 1 : val - 1;
     return *this;
   }
   _m_int operator++(int) {
     _m_int before = *this;
     ++*this;
     return before;
   }
   _m_int operator--(int) {
     _m_int before = *this;
     --*this;
     return before;
   }
   _m_int operator-() const { return val == 0 ? 0 : MOD - val; }
   bool operator==(const _m_int &other) const { return val == other.val; }
   bool operator!=(const _m_int &other) const { return val != other.val; }
   _m_int inv() const { return inv_mod(val); }
   _m_int pow(int64_t p) const {
     if (p < 0) return inv().pow(-p);
     _m_int a = *this, result = 1;
     while (p > 0) {
       if (p & 1) result *= a;
       a *= a;
       p >>= 1;
     }
     return result;
   }
   friend ostream &operator<<(ostream &os, const _m_int &m) {
     return os << m.val;
   }
 };
 extern const int MOD = 998244353;
 using mod_int = _m_int<MOD>;
 const int BITS = 53;
 template <typename T>
 struct xor_basis {
   T basis[BITS];
   int n = 0;
   T min_value(T start) const {
     if (n == BITS) return 0;
     for (int i = 0; i < n; i++) start = min(start, start ^ basis[i]);
     return start;
   }
   T max_value(T start = 0) const {
     if (n == BITS) return ((T)1 << BITS) - 1;
     for (int i = 0; i < n; i++) start = max(start, start ^ basis[i]);
     return start;
   }
   bool add(T x) {
     x = min_value(x);
     if (x == 0) return false;
     basis[n++] = x;
     for (int k = n - 1; k > 0 && basis[k] > basis[k - 1]; k--)
       swap(basis[k], basis[k - 1]);
     return true;
   }
   void merge(const xor_basis<T> &other) {
     for (int i = 0; i < other.n && n < BITS; i++) add(other.basis[i]);
   }
   void merge(const xor_basis<T> &a, const xor_basis<T> &b) {
     if (a.n > b.n) {
       *this = a;
       merge(b);
     } else {
       *this = b;
       merge(a);
     }
   }
 };
 int N, M, B;
 vector<int64_t> basis;
 vector<int64_t> answers;
 void generate_all() {
   vector<int64_t> change(B + 1, 0);
   int64_t prefix = 0;
   for (int i = 0; i < B; i++) {
     prefix ^= basis[i];
     change[i] = prefix;
   }
   change[B] = prefix;
   int64_t value = 0;
   for (unsigned mask = 0; mask < 1U << B; mask++) {
     answers[__builtin_popcountll(value)]++;
     value ^= change[__builtin_ctz(mask + 1)];
   }
 }
 void dp_on_repeats() {
   ;
   for (int i = 0; i < B; i++)
     for (int j = i + 1; j < B; j++)
       basis[i] = min(basis[i], basis[i] ^ basis[j]);
   ;
   vector<int> repeats;
   for (int bit = 0; bit < M; bit++) {
     int count = 0;
     for (int i = 0; i < B; i++)
       if (basis[i] >> bit & 1) count++;
     if (count > 1) repeats.push_back(bit);
   }
   int R = repeats.size();
   vector<pair<int, int>> options(B);
   int count_sum = 0;
   for (int i = 0; i < B; i++) {
     int64_t value = basis[i];
     int count = __builtin_popcountll(value);
     int repeat_mask = 0;
     for (int r = 0; r < R; r++)
       if (value >> repeats[r] & 1) {
         count--;
         repeat_mask |= 1 << r;
       }
     options[i] = {count, repeat_mask};
     count_sum += count;
   };
   sort(options.begin(), options.end());
   if (R <= 20) {
     vector<vector<int64_t>> dp(count_sum + 1, vector<int64_t>(1 << R, 0));
     dp[0][0] = 1;
     int max_count = 0;
     for (pair<int, int> &option : options) {
       int opt_count = option.first;
       int opt_mask = option.second;
       for (int count = max_count; count >= 0; count--)
         for (int mask = 0; mask < 1 << R; mask++)
           dp[count + opt_count][mask ^ opt_mask] += dp[count][mask];
       max_count += opt_count;
     }
     for (int count = 0; count <= count_sum; count++)
       for (int mask = 0; mask < 1 << R; mask++)
         if (dp[count][mask] > 0)
           answers[count + __builtin_popcount(mask)] += dp[count][mask];
   } else {
     vector<vector<unsigned>> dp(count_sum - 1, vector<unsigned>(1 << R, 0));
     int max_count = 0;
     for (pair<int, int> &option : options) {
       int opt_count = option.first;
       int opt_mask = option.second;
       for (int count = min(max_count - 1, count_sum - 1 - opt_count - 1);
            count >= 0; count--)
         for (int mask = 0; mask < 1 << R; mask++)
           dp[count + opt_count][mask ^ opt_mask] += dp[count][mask];
       dp[opt_count - 1][opt_mask]++;
       max_count += opt_count;
     }
     for (int count = 0; count < count_sum - 1; count++)
       for (int mask = 0; mask < 1 << R; mask++)
         if (dp[count][mask] > 0)
           answers[count + 1 + __builtin_popcount(mask)] += dp[count][mask];
     int everything = 0;
     for (int i = 0; i < B; i++) everything ^= options[i].second;
     answers[count_sum + __builtin_popcount(everything)]++;
     answers[0]++;
   }
 }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(nullptr);
   cin >> N >> M;
   xor_basis<int64_t> basis_obj;
   for (int i = 0; i < N; i++) {
     int64_t a;
     cin >> a;
     basis_obj.add(a);
   }
   B = basis_obj.n;
   basis.resize(B);
   for (int i = 0; i < B; i++) basis[i] = basis_obj.basis[i];
   answers.assign(M + 1, 0);
   if (B <= 0.57 * M)
     generate_all();
   else
     dp_on_repeats();
   for (int i = 0; i <= M; i++) {
     mod_int answer = answers[i];
     answer *= mod_int(2).pow(N - B);
     cout << answer << (i < M ? ' ' : '
');
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m;
 int g[405][405];
 vector<int> v[405];
 double ans;
 double gai[405];
 double pos[405];
 double suan(int yi, int juli) {
   memset(gai, 0, sizeof(gai));
   for (int i = 1; i <= n; i++) {
     if (g[i][yi] == juli) {
       for (int j = 0; j < (int)v[i].size(); j++) {
         gai[v[i][j]] += 1.0 / n / (int)v[i].size();
       }
     }
   }
   vector<int> r;
   r.clear();
   for (int i = 1; i <= n; i++)
     if (gai[i]) r.push_back(i);
   double ret = 0;
   for (int i = 1; i <= n; i++) {
     double tmp = 0;
     for (int j = 0; j < (int)r.size(); j++) {
       pos[g[i][r[j]]] = max(pos[g[i][r[j]]], gai[r[j]]);
     }
     for (int j = 0; j < (int)r.size(); j++) {
       tmp += pos[g[i][r[j]]];
       pos[g[i][r[j]]] = 0;
     }
     ret = max(ret, tmp);
   }
   return ret;
 }
 int main() {
   scanf( %d%d , &n, &m);
   for (int i = 1; i <= n; i++) {
     for (int j = 1; j <= n; j++)
       if (i != j) g[i][j] = 199912310;
   }
   for (int i = 1; i <= m; i++) {
     int x, y, z;
     scanf( %d%d , &x, &y);
     g[x][y] = 1;
     g[y][x] = 1;
     v[x].push_back(y);
     v[y].push_back(x);
   }
   for (int k = 1; k <= n; k++) {
     for (int i = 1; i <= n; i++) {
       for (int j = 1; j <= n; j++)
         g[i][j] = g[j][i] = min(g[i][j], g[i][k] + g[k][j]);
     }
   }
   for (int i = 1; i <= n; i++) {
     double now = 0;
     for (int dist = 0; dist < n; dist++) {
       int cnt = 0;
       for (int j = 1; j <= n; j++) {
         if (g[i][j] == dist) cnt++;
       }
       if (!cnt) continue;
       double p = 1.0 / n;
       double q = suan(i, dist);
       now += max(p, q);
     }
     ans = max(ans, now);
   }
   printf( %.8lf
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool voltea;
 int A[100005], B[100005], I[100005], D[100005], R[100005], ctos, hay, x, y, mid,
     en;
 int Z[100005], grande;
 void lis() {
   B[1] = A[1];
   if (voltea)
     D[ctos] = 1;
   else
     I[1] = 1;
   hay = 1;
   for (int i = 2; i <= ctos; i++) {
     if (A[i] > B[hay]) {
       ++hay;
       B[hay] = A[i];
       en = hay;
     } else {
       x = 1;
       y = hay;
       while (x < y) {
         mid = (x + y) / 2;
         if (B[mid] < A[i]) {
           x = mid + 1;
         } else {
           y = mid;
         }
       }
       B[x] = A[i];
       en = x;
     }
     if (voltea) {
       D[ctos - i + 1] = en;
     } else {
       I[i] = en;
     }
   }
 }
 int main() {
   scanf( %d , &ctos);
   for (int i = 1; i <= ctos; i++) {
     scanf( %d , &A[i]);
   }
   lis();
   voltea = true;
   x = 1;
   y = ctos;
   while (x < y) {
     swap(A[x], A[y]);
     A[x] *= -1;
     A[y] *= -1;
     ++x;
     --y;
   }
   if (x == y) {
     A[x] *= -1;
   }
   lis();
   grande = 1;
   for (int i = 1; i <= ctos; i++) {
     if (I[i] + D[i] - 1 > grande) {
       grande = I[i] + D[i] - 1;
     }
   }
   for (int i = 1; i <= ctos; i++) {
     if (I[i] + D[i] - 1 == grande) {
       Z[I[i]]++;
     } else {
       R[i] = 1;
     }
   }
   for (int i = 1; i <= ctos; i++) {
     if (R[i] == 0) {
       R[i] = 2;
       if (Z[I[i]] == 1) {
         R[i] = 3;
       }
     }
     printf( %d , R[i]);
   }
   printf(
 );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int a, b, c;
   cin >> a >> b >> c;
   if (a >= c || b >= c) {
     cout <<  0 ;
   } else if (a <= 0 && b <= 0) {
     cout <<  -1 ;
   } else {
     long long int count = 0;
     while (a < c && b < c) {
       if (a > b) {
         swap(a, b);
       } else if (a < 0) {
         count += (abs(a) / b + (abs(a) % b != 0));
         if (abs(a) % b) {
           long long int r = abs(a) % b;
           a = (b - r);
         } else {
           a = 0;
         }
       } else {
         long long int p = b;
         b += a;
         a = p;
         count++;
       }
     }
     cout << count;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 1000000000;
 const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
 const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                          {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
 int par[200010], r[200010], lar[200010];
 void init() {
   for (int i = 0; i < 200010; i++) {
     par[i] = i;
     r[i] = 0;
     lar[i] = 1;
   }
 }
 int find(int x) {
   if (par[x] == x) return x;
   return par[x] = find(par[x]);
 }
 bool same(int x, int y) { return find(x) == find(y); }
 void unit(int x, int y) {
   if (same(x, y)) return;
   x = find(x);
   y = find(y);
   if (r[x] < r[y]) {
     par[x] = y;
     lar[y] += lar[x];
   } else {
     par[y] = x;
     lar[x] += lar[y];
     if (r[x] == r[y]) {
       r[x]++;
     }
   }
 }
 int main() {
   static int n;
   static int a[200010];
   scanf( %d , &n);
   for (int i = 1; i <= n; i++) {
     scanf( %d , &a[i]);
   }
   init();
   bool used[200010];
   for (int i = 0; i < 200010; i++) {
     used[i] = false;
   }
   vector<pair<int, int> > vec;
   for (int i = 1; i <= n; i++) {
     vec.push_back(pair<int, int>(a[i], i));
   }
   sort(vec.begin(), vec.end());
   reverse(vec.begin(), vec.end());
   int ans[200010];
   int k = 1;
   for (int i = 0; i < vec.size(); i++) {
     pair<int, int> p = vec[i];
     used[p.second] = true;
     if (used[p.second - 1]) {
       unit(p.second, p.second - 1);
     }
     if (used[p.second + 1]) {
       unit(p.second, p.second + 1);
     }
     for (; k <= lar[find(p.second)]; k++) {
       ans[k] = p.first;
     }
   }
   for (int i = 1; i <= n; i++) {
     printf( %d  , ans[i]);
   }
   puts(  );
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 100 + 7;
 int n;
 map<pair<int, int>, int> id;
 vector<int> g[N];
 long double rep(long double x) {
   if (x >= 2) {
     x -= 2;
   }
   return x;
 }
 void dfs(int a, int p = 0, long double t = 0) {
   int deg = (int)g[a].size();
   long double jump = 2 / (long double)deg;
   for (auto &b : g[a]) {
     if (b == p) continue;
     t = rep(t + jump);
     cout << 1 <<     << id[{a, b}] <<    ;
     if (t <= 1) {
       cout << b <<     << a <<     << fixed << setprecision(6) << 1 - t <<
 ;
     } else {
       cout << a <<     << b <<     << fixed << setprecision(6) << 1 - rep(t + 1)
            <<
 ;
     }
     dfs(b, a, rep(t + 1));
   }
 }
 signed main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cin >> n;
   for (int i = 1; i < n; i++) {
     int x, y;
     cin >> x >> y;
     id[{x, y}] = i;
     id[{y, x}] = i;
     g[x].push_back(y);
     g[y].push_back(x);
   }
   int root = 1;
   cout << n - 1 <<
 ;
   dfs(root);
 }


#include <bits/stdc++.h>
 const double eps = 1e-8;
 const double pi = acos(-1.0);
 const int INF = 0x7f7f7f7f;
 const double inf = 1e50;
 template <class T>
 inline T minx(T a, T b) {
   return (a == -1 || b < a) ? b : a;
 }
 template <class T>
 inline T gcd(T a, T b) {
   return b ? gcd(b, a % b) : a;
 }
 template <class T>
 inline T lcm(T a, T b) {
   return a * (b / gcd(a, b));
 }
 template <class T>
 inline T getbit(T n) {
   return n ? (1 + getbit(n & (n - 1))) : 0;
 }
 template <class T>
 inline T lowbit(T n) {
   return n & (-n);
 }
 using namespace std;
 pair<double, double> parse(double x, double y) { return make_pair(x, y); }
 int main() {
   int i, j, k;
   pair<double, double> A, B, C;
   double x, y;
   double dx, dy, tx, ty;
   while (cin >> x >> y) {
     A = parse(x, y);
     cin >> x >> y;
     B = parse(x, y);
     cin >> x >> y;
     C = parse(x, y);
     dx = B.first - A.first;
     dy = B.second - A.second;
     tx = C.first - B.first;
     ty = C.second - B.second;
     double res = dx * ty - dy * tx;
     if (res == 0)
       puts( TOWARDS );
     else if (res > 0)
       puts( LEFT );
     else
       puts( RIGHT );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long mod = 1000000009;
 const int maxn = 1000010;
 long long p[maxn], q[maxn];
 int main() {
   int i, n;
   long long nAns = 0;
   cin >> n;
   n /= 2;
   p[1] = 2;
   q[1] = 1;
   for (i = 2; i <= n; i++) {
     p[i] = p[i - 1] * 2 % mod;
     q[i] = q[i - 1] * (p[i] - 3) % mod;
     nAns = (nAns + q[i] * 4) % mod;
   }
   cout << (2 * nAns * nAns % mod + nAns * 8 % mod + 10) % mod << endl;
   return 0;
 }


#include <bits/stdc++.h>
 const int maxn = 1e5 + 7;
 int main(int argc, char *argv[]) {
   std::ios::sync_with_stdio(false);
   std::cin.tie(0);
   int n, k;
   std::set<std::pair<int, int> > t[maxn], s;
   std::cin >> n >> k;
   int u, v, w;
   int ans = 0;
   for (int i = 0; i < n - 1; i++) {
     std::cin >> u >> v >> w;
     t[u].insert(std::make_pair(v, w));
     t[v].insert(std::make_pair(u, w));
   }
   for (int i = 1; i <= n; i++) {
     if (t[i].size() == 1) {
       s.insert(std::make_pair((*t[i].begin()).second, i));
     }
   }
   while (n > k || s.size() > 2) {
     auto i = *s.begin();
     s.erase(i);
     int cur = i.second;
     ans = i.first;
     n--;
     int nxt = (*t[cur].begin()).first;
     t[nxt].erase(t[nxt].lower_bound(std::make_pair(cur, 0)));
     if (t[nxt].size() == 1) {
       s.insert(std::make_pair((*t[nxt].begin()).second + ans, nxt));
     }
   }
   std::cout << ans << std::endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 3e3 + 5;
 const int MOD = 1e9 + 7;
 int N, M, A, B;
 int G[MAXN * MAXN], X, Y, Z;
 int H[MAXN][MAXN];
 int P[MAXN][MAXN];
 int T[MAXN][MAXN];
 long long ans;
 deque<pair<int, int> > qu;
 void reset() { qu.clear(); }
 void push(int v, int p) {
   while (qu.size() && qu.back().first >= v) {
     qu.pop_back();
   }
   qu.push_back({v, p});
 }
 int pop(int p) {
   while (qu.size() && qu.front().second < p) {
     qu.pop_front();
   }
   assert(qu.size());
   return qu.front().first;
 }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cin >> N >> M >> A >> B;
   cin >> G[0] >> X >> Y >> Z;
   for (int i = 1; i < N * M; i++) {
     G[i] = (1LL * G[i - 1] * X + Y) % Z;
   }
   for (int i = 0; i < N; i++) {
     for (int j = 0; j < M; j++) {
       H[i][j] = G[i * M + j];
     }
   }
   for (int i = 0; i < N; i++) {
     reset();
     for (int j = 0; j < B; j++) push(H[i][j], j);
     P[i][B - 1] = pop(0);
     for (int j = B; j < M; j++) {
       push(H[i][j], j);
       P[i][j] = pop(j - B + 1);
     }
   }
   for (int j = B - 1; j < M; j++) {
     reset();
     for (int i = 0; i < A; i++) push(P[i][j], i);
     ans += pop(0);
     for (int i = A; i < N; i++) {
       push(P[i][j], i);
       ans += pop(i - A + 1);
     }
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int withoutzero(int x);
 int main() {
   int a, b, c, d, e, f;
   cin >> a >> b;
   d = withoutzero(a);
   e = withoutzero(b);
   c = a + b;
   f = withoutzero(c);
   if ((d + e) == f) {
     cout <<  YES ;
   } else {
     cout <<  NO ;
   }
 }
 int withoutzero(int x) {
   int arr[10], i = 0, t = 0, k = 0;
   while (x > 0) {
     arr[i] = x % 10;
     x = x / 10;
     i++;
   }
   for (int j = 0; j < i; j++) {
     if (arr[j] != 0) {
       t += arr[j] * pow(10, k);
       k++;
     }
   }
   return t;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long f[100000 + 1], a[100000 + 1], n, d, b;
 int main() {
   scanf( %lld%lld%lld , &n, &d, &b);
   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);
   f[0] = 0;
   for (int i = 1; i <= n; i++) f[i] += f[i - 1] + a[i];
   long long a1 = 0, a2 = 0;
   for (long long i = 1; i <= n / 2; i++) {
     if (f[min(n, i + i * d)] >= (a1 + 1) * b) ++a1;
     if (f[n] - f[max((long long)1, n - i - i * d)] >= (a2 + 1) * b) ++a2;
   }
   printf( %lld , n / 2 - min(a1, a2));
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long N = 500005;
 long long MAX = 9223372036854775807;
 long long MOD = 1000000007;
 long double PI = 4 * atan(1);
 long long int t, a, b, res;
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   ;
   cin >> t;
   while (t--) {
     cin >> a >> b;
     res = 0;
     a = abs(a - b);
     res += a / 5;
     a = a % 5;
     res += a / 2 + a % 2;
     cout << res << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 signed main() {
   ios_base::sync_with_stdio(0);
   cin.tie(NULL);
   long long int T;
   cin >> T;
   while (T--) {
     long long int n;
     cin >> n;
     long long int a[n];
     for (long long int i = 0; i < n; i++) cin >> a[i];
     if (a[n - 1] > a[0])
       cout <<  YES
            <<
 ;
     else
       cout <<  NO
            <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, siz[200005], l[200005], r[200005], a[200005], p[200005], an = 0,
                                                                 b[200005];
 bool vis[200005];
 vector<int> vt[200005], vec;
 set<int> st;
 set<int>::iterator it;
 int root(int node) {
   while (p[node] != node) {
     p[node] = p[p[node]];
     node = p[node];
   }
   return node;
 }
 int merging(int n1, int n2) {
   int p1 = root(n1), p2 = root(n2);
   if (p1 == 0) return p2;
   if (p2 == 200005 - 1) return p1;
   if (p1 == p2) return p1;
   if (siz[p1] > siz[p2]) {
     siz[p1] += siz[p2];
     p[p2] = p[p1];
     l[p1] = min(l[p1], l[p2]);
     r[p1] = max(r[p1], r[p2]);
     return p1;
   } else {
     siz[p2] += siz[p1];
     p[p1] = p[p2];
     l[p2] = min(l[p2], l[p1]);
     r[p2] = max(r[p1], r[p2]);
     return p2;
   }
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   ;
   scanf( %d , &n);
   int lef = 1, cur = 1, ri;
   st.insert(0);
   st.insert(200005 - 1);
   for (int i = 1; i <= n; i++) {
     scanf( %d , &a[i]);
     if (i != 1 && a[i] != a[i - 1]) {
       l[cur] = lef, r[cur] = i - 1;
       siz[cur] = r[cur] - l[cur] + 1;
       vt[siz[cur]].push_back(l[cur]);
       p[cur] = cur;
       cur++;
       lef = i;
     }
     st.insert(i);
     b[i] = cur;
   }
   l[cur] = lef, r[cur] = n, siz[cur] = n - lef + 1;
   vt[siz[cur]].push_back(l[cur]);
   p[cur] = cur;
   for (int i = 200005 - 1; i >= 1; i--) {
     sort(vt[i].begin(), vt[i].end());
     for (int j = 0, par, tmp, tpp, lol, now; j < vt[i].size(); j++) {
       now = vt[i][j];
       if (vis[now]) continue;
       par = root(b[now]);
       it = st.lower_bound(l[par]);
       it--;
       tmp = *it;
       it = st.lower_bound(r[par]);
       it++;
       tpp = *it;
       if (a[tmp] == a[tpp] && a[tmp]) {
         lol = merging(b[tmp], b[tpp]);
         if (siz[lol] >= i) {
           vt[i][j] = l[lol];
           j--;
         } else
           vt[siz[lol]].push_back(l[lol]);
       }
       for (it = st.lower_bound(l[par]); *it <= r[par]; it++) vec.push_back(*it);
       for (int k = 0; k < vec.size(); k++) {
         st.erase(vec[k]), vis[vec[k]] = true;
       }
       vec.clear();
       an++;
     }
   }
   printf( %d
 , an);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   string s;
   cin >> s;
   int maxi = 0;
   int ind = 0;
   string ret =   ;
   for (int i = 0; i < n; i++) {
     string temp;
     int d = 10 - (s[i] - 48);
     int j = i;
     int ctr = 0;
     while (ctr < n) {
       ctr++;
       temp += ((s[j] - 48 + d) % 10) + 48;
       j = (j + 1) % s.length();
     }
     if (ret ==   )
       ret = temp;
     else if (temp < ret)
       ret = temp;
   }
   cout << ret;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(false);
   long long n;
   cin >> n;
   vector<vector<long long> > p(2, vector<long long>(n)),
       suf(2, vector<long long>(n + 1)), ebalVLevo(2, vector<long long>(n + 1)),
       ebalVPravo(2, vector<long long>(n + 1));
   for (long long i = 0; i < 2; i++) {
     for (long long j = 0; j < n; j++) {
       cin >> p[i][j];
     }
   }
   for (long long i = 0; i < 2; i++) {
     suf[i][n - 1] = p[i][n - 1];
     for (long long j = n - 2; j >= 0; j--) {
       suf[i][j] = suf[i][j + 1] + p[i][j];
     }
   }
   for (long long i = 0; i < 2; i++) {
     ebalVPravo[i][0] = (n)*p[i][0];
     for (long long j = 1; j < n; j++) {
       ebalVPravo[i][j] = ebalVPravo[i][j - 1] + p[i][j] * (n + j);
     }
   }
   for (long long i = 0; i < 2; i++) {
     ebalVLevo[i][n - 1] = p[i][n - 1];
     for (long long j = n - 2; j >= 0; j--) {
       ebalVLevo[i][j] = ebalVLevo[i][j + 1] + p[i][j] * (n - j);
     }
   }
   long long sum = 0;
   long long ans = 0;
   long long i = 0, j = 0;
   bool lastI = false;
   for (long long t = 0; t < 2 * n; t++) {
     sum += t * p[i][j];
     long long tmp = sum;
     long long tmpR =
         ebalVPravo[i][n - 1] - ebalVPravo[i][j] - (n - t + j) * suf[i][j + 1];
     long long tmpL = 0;
     long long tmpLL = 0;
     if (t == 0) {
       tmpL = ebalVLevo[1][j] + (t + (n - j) - 1) * suf[1][j];
     } else if (i == 0) {
       tmpL = ebalVLevo[1][j + 1] + (t + (n - j) - 1) * suf[1][j + 1];
     } else if (i == 1) {
       tmpL = ebalVLevo[0][j + 1] + (t + (n - j) - 1) * suf[0][j + 1];
     }
     ans = max(ans, tmp + tmpL + tmpR);
     if (!lastI) {
       if (!i) {
         i++;
       } else {
         i--;
       }
       lastI = true;
     } else {
       j++;
       lastI = false;
     }
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long dp[300005];
 vector<long long> g[300005];
 long long ans = 1;
 long long subs[300005];
 long long f[300005][2];
 void dfs(long long s, long long p) {
   dp[s] = 0;
   long long mx1 = 0;
   long long mx2 = 0;
   long long cnt = 0;
   for (auto it : g[s]) {
     if (it != p) {
       dfs(it, s);
       if (mx1 < dp[it]) {
         mx2 = mx1;
         mx1 = dp[it];
       } else if (mx2 < dp[it])
         mx2 = dp[it];
       cnt++;
     }
   }
   f[s][0] = mx1;
   f[s][1] = mx2;
   subs[s] = cnt;
   dp[s] += mx1 + cnt;
 }
 void ans_dfs(long long s, long long p) {
   for (auto it : g[s]) {
     if (it != p) ans_dfs(it, s);
   }
   if (s == p) {
     ans = max(ans, 1 + dp[s] + f[s][1]);
     return;
   }
   long long y = f[p][0];
   if (y == dp[s]) y = f[p][1];
   long long z = max(y, f[s][1]);
   ans = max(ans, 1 + dp[s] + z + 1);
 }
 int32_t main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   ;
   long long t;
   cin >> t;
   while (t--) {
     long long n;
     cin >> n;
     for (long long i = 1; i <= n; i++) {
       dp[i] = 0;
       g[i].clear();
     }
     for (long long i = 0; i < n - 1; i++) {
       long long a, b;
       cin >> a >> b;
       g[a].push_back(b);
       g[b].push_back(a);
     }
     ans = 1;
     dfs(1, 1);
     ans_dfs(1, 1);
     cout << ans <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 18;
 long long dp[(1 << N)][105];
 string n;
 int qwq;
 int m, pw[20];
 bool used[10];
 void init() {
   pw[0] = 1;
   for (int i = 1; i <= n.size(); i++) pw[i] = pw[i - 1] * 10 % m;
 }
 int main() {
   cin >> n >> m;
   dp[0][0] = 1;
   init();
   for (int i = 1; i < (1 << n.size()); i++) {
     int sz = n.size() - __builtin_popcount(i);
     for (int k = 0; k < m; k++) {
       for (int j = 0; j < 10; j++) used[j] = false;
       for (int j = 0; j < n.size(); j++)
         if (((i >> j) & 1) && !used[n[j] - '0'])
           if (sz != (int)n.size() - 1 || n[j] != '0')
             dp[i][k] +=
                 dp[i - (1 << j)][(m + k - (n[j] - '0') * pw[sz] % m) % m],
                 used[n[j] - '0'] = true;
     }
   }
   cout << dp[(1 << n.size()) - 1][0] <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXM = 500 + 5;
 const int MAXN = 500 + 5;
 const int MAXQ = 300 + 5;
 const int MAXK = 800 + 5;
 const int P = 5;
 const int MOD = 1e9 + 7;
 int n, m, q, a[MAXN][MAXK];
 int inv[P], ans = 1;
 char buf[MAXM];
 int main() {
   for (int i = 0; i < P; i++) inv[i] = i * i * i % P;
   scanf( %d%d , &n, &m);
   for (int i = 1; i <= n; i++) {
     scanf( %s , buf + 1);
     for (int j = 1; j <= m; j++) a[j][i] = buf[j] - 'a';
   }
   scanf( %d , &q);
   for (int i = 1; i <= q; i++) {
     scanf( %s , buf + 1);
     for (int j = 1; j <= m; j++) a[j][i + n] = buf[j] - 'a';
   }
   int cur = 1, r = 0;
   for (int i = 1; i <= m && cur <= n; i++) {
     while (cur <= n) {
       int t = i;
       for (int j = i + 1; j <= m; j++)
         if (a[j][cur]) t = j;
       for (int j = 1; j <= n + q; j++) swap(a[i][j], a[t][j]);
       if (a[i][cur]) break;
       cur++;
     }
     if (cur == n + 1) break;
     for (int j = cur + 1; j <= n + q; j++)
       a[i][j] = a[i][j] * inv[a[i][cur]] % P;
     a[i][cur] = 1;
     for (int j = i + 1; j <= m; j++) {
       for (int k = cur + 1; k <= n + q; k++) {
         a[j][k] -= a[j][cur] * a[i][k] % P;
         if (a[j][k] < 0) a[j][k] += P;
       }
       a[j][cur] = 0;
     }
     r++;
   }
   for (int i = 1; i <= n - r; i++) ans = ans * 5ll % MOD;
   for (int i = 1; i <= q; i++) {
     int x = ans;
     for (int j = 1; j <= m; j++) {
       bool flg = 1;
       for (int k = 1; k <= n; k++) flg &= (a[j][k] == 0);
       flg &= (a[j][n + i] > 0);
       if (flg) x = 0;
     }
     printf( %d
 , x);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> st[100000], edge[200000], topo;
 vector<pair<int, int> > ps;
 int incnt[200000], tol;
 priority_queue<int> que;
 bool visit[200000];
 int main(void) {
   int n, m, in;
   while (scanf( %d %d , &n, &m) == 2) {
     for (int i = 0; i < m; ++i) st[i].clear();
     for (int i = 0; i < n; ++i)
       for (int j = 0; j < m; ++j) {
         scanf( %d , &in);
         st[j].push_back(in);
       }
     memset(incnt, 0, sizeof(incnt));
     tol = m;
     for (int i = 0; i < 200000; ++i) edge[i].clear();
     for (int i = 0; i < n; ++i) {
       ps.clear();
       for (int j = 0; j < m; ++j)
         if (st[j][i] >= 0) ps.push_back(make_pair(st[j][i], j));
       sort(ps.begin(), ps.end());
       for (int a = 0, b, k = ps.size(), pre = -1; a < k; a = b) {
         for (b = a; (b < k) && (ps[b].first == ps[a].first); ++b) {
           int now = ps[b].second;
           if (pre >= 0) {
             edge[pre].push_back(now);
             ++incnt[now];
           }
           edge[now].push_back(tol);
           ++incnt[tol];
         }
         pre = tol++;
       }
     }
     topo.clear();
     for (int i = 0; i < tol; ++i)
       if (!incnt[i]) que.push(-i);
     while (!que.empty()) {
       int now = -que.top();
       que.pop();
       if (now < m) topo.push_back(now + 1);
       for (int i = 0, j = edge[now].size(); i < j; ++i) {
         --incnt[edge[now][i]];
         if (!incnt[edge[now][i]]) que.push(-edge[now][i]);
       }
     }
     if (topo.size() != m)
       puts( -1 );
     else {
       printf( %d , topo[0]);
       for (int i = 1, j = topo.size(); i < j; ++i) printf(  %d , topo[i]);
       putchar('
');
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 map<string, int> mp;
 map<int, string> mp_back;
 vector<int> way[5005 * 2];
 int n, j, i, ans[5005 * 2] = {};
 int main() {
   cin >> n;
   int w = 0;
   for (i = 1; i <= n; i++) {
     int v1, v2;
     string s1, s2;
     cin >> s1 >> s2;
     if (!mp[s1])
       ++w, mp[s1] = w, v1 = w, mp_back[w] = s1;
     else
       v1 = mp[s1];
     if (!mp[s2])
       ++w, mp[s2] = w, v2 = w, mp_back[w] = s2;
     else
       v2 = mp[s2];
     way[v1].push_back(v2);
     way[v2].push_back(v1);
   }
   for (i = 1; i <= w; i++) {
     int friends[5005 * 2] = {}, friends2[5005 * 2] = {};
     for (j = 0; j < way[i].size(); j++) friends[way[i][j]] = 1;
     int maxf = 0;
     for (j = 1; j <= w; j++)
       if (!friends[j] && j != i) {
         int size = 0;
         for (int h = 0; h < way[j].size(); h++)
           if (friends[way[j][h]]) ++size;
         maxf = max(maxf, size);
         friends2[j] = size;
       }
     for (j = 1; j <= w; j++)
       if (friends2[j] == maxf && !friends[j] && j != i) ans[i]++;
   }
   cout << w << endl;
   for (i = 1; i <= w; i++) cout << mp_back[i] <<     << ans[i] << endl;
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( O3 )
 #pragma GCC target( avx2 )
 #pragma comment(linker,  /stack:200000000 )
 #pragma GCC optimize( Ofast )
 #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )
 using namespace std;
 void solve() {
   int n;
   cin >> n;
   vector<int> ans;
   for (int i = 1; i <= 1000; i += 2) {
     ans.push_back(i);
     ans.push_back(i);
   }
   if (ans.size() < n) {
     for (int i = 0; i < ans.size(); i++) {
       cout << ans[i] <<    ;
     }
     n -= ans.size();
     for (int i = 0; i < n; i++) {
       cout << ans[i] <<    ;
     }
     cout << endl;
     return;
   }
   for (int i = int(0); i < int(n); i++) {
     cout << ans[i] <<    ;
   }
   cout << endl;
 }
 signed main() {
   int t;
   cin >> t;
   while (t--) {
     solve();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int a, b, c, i, j, sum, p[3][3];
   stack<int> s;
   queue<int> q1, q2;
   for (i = 0; i < 3; i++)
     for (j = 0; j < 3; j++) p[i][j] = (j + 3 - i) % 3;
   while (s.size()) s.pop();
   while (q1.size()) q1.pop();
   while (q2.size()) q2.pop();
   scanf( %d%d , &a, &b);
   while (a) {
     q1.push(a % 3);
     a /= 3;
   }
   while (b) {
     q2.push(b % 3);
     b /= 3;
   }
   if (q1.size() > q2.size())
     for (i = q2.size(); i < q1.size(); i++) q2.push(0);
   else {
     if (q2.size() > q1.size())
       for (i = q1.size(); i < q2.size(); i++) q1.push(0);
   }
   while (q1.size()) {
     a = q1.front();
     q1.pop();
     b = q2.front();
     q2.pop();
     s.push(p[a][b]);
   }
   sum = 0;
   while (s.size()) {
     c = s.top();
     s.pop();
     sum = sum * 3 + c;
   }
   printf( %d
 , sum);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double eps = 1e-7;
 const int MOD = 1e9 + 7;
 const long long INFLL = 0x3f3f3f3f3f3f3f3f;
 const int INF = 0x3f3f3f3f;
 const int MAXN = 4e5 + 5;
 char s[MAXN];
 int vis[200], t[200];
 int check(int n, int l) {
   int need = (l / 2) * n, cnt = 0;
   for (int i = 0; i < 200; i++) cnt += vis[i] / 2;
   if (cnt >= need) return 1;
   return 0;
 }
 void solve(int n, int l) {
   vector<char> v1, v2;
   printf( %d
 , n);
   for (int i = 0; i < 200; i++) {
     while (vis[i] >= 2) v1.push_back((char)i), vis[i] -= 2;
     if (vis[i]) v2.push_back((char)i);
   }
   for (int i = 0; i < n; i++) {
     int p = 0;
     while (p < l / 2) {
       s[p] = s[l - 1 - p] = v1[v1.size() - 1];
       v1.pop_back();
       p++;
     }
     if (l & 1) {
       if (v2.empty())
         s[p] = v1[v1.size() - 1], v2.push_back(v1[v1.size() - 1]),
         v1.pop_back();
       else
         s[p] = v2[v2.size() - 1], v2.pop_back();
     }
     s[l] = 0;
     printf( %s  , s);
   }
 }
 int main() {
   int n;
   cin >> n;
   scanf( %s , s + 1);
   for (int i = 1; i <= n; i++) vis[s[i]]++;
   int maxn = INF;
   for (int i = 1; i * i <= n; i++) {
     if (n % i == 0) {
       if (check(i, n / i)) maxn = min(i, maxn);
       if (check(n / i, i)) maxn = min(n / i, maxn);
     }
   }
   solve(maxn, n / maxn);
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, a[100001];
 vector<vector<pair<int, int>>> o[6], ans;
 void relax(vector<int>& m) {
   o[m.size()].push_back({});
   for (size_t i = 0; i < m.size(); i++)
     o[m.size()].back().push_back({m[i], m[(i + 1) % m.size()]});
   m.resize(1);
 }
 void gao(int x, int y) {
   if (!y) ans.insert(ans.end(), o[x].begin(), o[x].end());
   while (o[x].size() > (x == y) && o[y].size()) {
     ans.push_back(o[x].back());
     o[x].pop_back();
     ans.back().insert(ans.back().end(), o[y].back().begin(), o[y].back().end());
     o[y].pop_back();
   }
 }
 int main() {
   scanf( %d , &n);
   for (int i = 1; i <= n; i++) scanf( %d , a + i);
   for (int i = 1; i <= n; i++)
     if (a[i] != i) {
       vector<int> u = {i}, m = {i};
       while (a[u.back()] != i) u.push_back(a[u.back()]);
       for (size_t c = 1; c < u.size(); c++) {
         if (m.size() == 5) relax(m);
         m.push_back(a[u[c]] = u[c]);
       }
       relax(m);
     }
   gao(5, 0);
   gao(4, 0);
   gao(2, 3);
   while (o[3].size() >= 2) {
     auto u = o[3].back();
     o[3].pop_back();
     o[2].push_back({{u[0].first, u[1].first}, {u[1].first, u[0].first}});
     o[2].push_back({{u[1].first, u[2].first}, {u[2].first, u[1].first}});
     gao(2, 3);
   }
   gao(2, 2);
   gao(3, 0);
   gao(2, 0);
   printf( %d
 , ans.size());
   for (auto& c : ans) {
     printf( %d
 , c.size());
     for (auto x : c) printf( %d  , x.first);
     puts(  );
     for (auto x : c) printf( %d  , x.second);
     puts(  );
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m, tot, a[100010], ans[100010];
 vector<pair<int, int> > q[100010];
 set<int> s;
 int main() {
   scanf( %d%d , &n, &m);
   for (int i = 1; i <= n; i++) scanf( %d , &a[i]);
   for (int i = 1, l, x; i <= m; i++) {
     scanf( %d%d , &l, &x);
     q[l].emplace_back(i, x);
   }
   s.insert(0);
   tot = 1;
   for (int i = 1; i <= n; i++) {
     if (s.count(a[i]))
       tot = 1ll * tot * 2 % 1000000007;
     else {
       vector<int> v;
       for (int u : s) v.push_back(u ^ a[i]);
       for (int u : v) s.insert(u);
     }
     for (auto &p : q[i]) ans[p.first] = s.count(p.second) ? tot : 0;
   }
   for (int i = 1; i <= m; i++) printf( %d
 , ans[i]);
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename Arg1>
 void __f(const char* name, Arg1&& arg1) {
   std::cerr << name <<   :   << arg1 << endl;
 }
 template <typename Arg1, typename... Args>
 void __f(const char* names, Arg1&& arg1, Args&&... args) {
   const char* comma = strchr(names + 1, ',');
   std::cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;
   __f(comma + 1, args...);
 }
 long long int solve() {
   long long int n;
   cin >> n;
   std::vector<long long int> v;
   long long int seg = 0;
   long long int count = 0;
   for (long long int i = 0; i < n; i++) {
     long long int a;
     cin >> a;
     v.push_back(a);
     if (a != i + 1) {
       count++;
     } else {
       if (count) {
         seg++;
         count = 0;
       }
     }
   }
   if (count) {
     seg++;
   }
   if (seg == 0) {
     cout << 0 <<
 ;
   } else if (seg == 1) {
     cout << 1 <<
 ;
   } else {
     cout << 2 <<
 ;
   }
   return 0;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   long long int T = 1;
   cin >> T;
   while (T--) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, sav, mn = 1e9;
 struct point {
   long long x, y, uz;
 } p[2005];
 string s;
 int det(point A, point B, point C) {
   if (A.x * B.y + A.y * C.x + B.x * C.y - A.x * C.y - A.y * B.x - B.y * C.x < 0)
     return -1;
   return 1;
 }
 int main() {
   ios::sync_with_stdio(false);
   cin >> n;
   for (int i = 1; i <= n; i++) {
     cin >> p[i].x >> p[i].y;
     if (p[i].y < mn) {
       mn = p[i].y;
       sav = i;
     }
   }
   cin >> s;
   p[sav].uz = 1;
   cout << sav << ' ';
   for (int i = 0; i < s.size(); i++) {
     int crt = 1, j, sgn;
     while (p[crt].uz) crt++;
     j = crt + 1;
     if (s[i] == 'R')
       sgn = 1;
     else
       sgn = -1;
     while (j <= n) {
       while (j <= n && p[j].uz) j++;
       if (j > n) break;
       if (det(p[sav], p[crt], p[j]) == sgn) crt = j;
       j++;
     }
     sav = crt;
     p[crt].uz = 1;
     cout << sav << ' ';
   }
   for (int i = 1; i <= n; i++)
     if (!p[i].uz) cout << i << ' ';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   vector<int> a;
   vector<string> ss;
   bool possible = false;
   for (int i = 0; i < n; ++i) {
     string s;
     cin >> s;
     if (!possible) {
       if (s.substr(0, 2) ==  OO ) {
         possible = true;
         s[0] = '+';
         s[1] = '+';
       } else if (s.substr(3, 2) ==  OO ) {
         possible = true;
         s[3] = '+';
         s[4] = '+';
       }
     }
     ss.push_back(s);
   }
   if (possible) {
     cout <<  YES
 ;
     for (int j = 0; j < n; ++j) {
       cout << ss[j] << '
';
     }
   } else {
     cout <<  NO ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int maxd(long long int n) {
   long long int temp = 10 * n, mm = 0;
   while (temp /= 10) mm = max(mm, temp % 10);
   return mm;
 }
 int main() {
   long long int n, ans = 0;
   cin >> n;
   while (n) {
     n -= maxd(n);
     ans++;
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 1e9 + 1;
 const int N = 100123;
 int z, n;
 int a[N];
 int best[N];
 long long ans[N];
 long long res;
 pair<int, int> tree[N << 2];
 void build(int v, int l, int r) {
   if (l == r) {
     tree[v] = {a[l], l};
     return;
   }
   int mid = (l + r) >> 1;
   build(2 * v, l, mid);
   build(2 * v + 1, mid + 1, r);
   tree[v] = max(tree[2 * v], tree[2 * v + 1]);
 }
 pair<int, int> query(int v, int l, int r, int ql, int qr) {
   if (ql <= l && qr >= r) {
     return tree[v];
   }
   int mid = (l + r) >> 1;
   pair<int, int> res = {0, 0};
   if (ql <= mid) res = max(res, query(2 * v, l, mid, ql, qr));
   if (qr >= mid + 1) res = max(res, query(2 * v + 1, mid + 1, r, ql, qr));
   return res;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin >> n;
   for (int i = 1; i <= n - 1; i++) {
     cin >> a[i];
   }
   a[n] = n;
   build(1, 1, n);
   for (int i = 1; i <= n; i++) {
     pair<int, int> b = query(1, 1, n, i, a[i]);
     best[i] = b.second;
   }
   ans[n - 1] = 1;
   res++;
   for (int i = n - 2; i >= 1; i--) {
     ans[i] = ans[best[i]] + (best[i] - i) + (n - a[i]);
     res += ans[i];
   }
   cout << res << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long md = 1e9 + 7;
 const int N = 2e6 + 34;
 char s[N];
 long long p[N];
 int n, k, m;
 int lst[100];
 int c, cur, mn;
 int main() {
   scanf( %d %d
 , &n, &k);
   gets(s);
   m = strlen(s);
   for (int i = 0; i < k; i++) lst[i] = -1;
   p[0] = 0;
   p[1] = 1;
   for (int i = 0; i < m; i++) {
     c = s[i] - 'a';
     cur = p[i + 1] - p[lst[c] + 1];
     p[i + 2] = (p[i + 1] + cur + md) % md;
     lst[c] = i;
   }
   for (int i = m; i < m + n; i++) {
     mn = 0;
     for (int j = 1; j < k; j++)
       if (lst[j] < lst[mn]) mn = j;
     c = mn;
     cur = p[i + 1] - p[lst[c] + 1];
     p[i + 2] = (p[i + 1] + cur + md) % md;
     lst[c] = i;
   }
   cout << p[n + m + 1];
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 map<string, string> mp;
 set<string> st;
 int n;
 char in[30];
 string read() {
   scanf(  %s , in);
   return (string)in;
 }
 int main() {
   scanf( %d , &n);
   for (int i = 1; i <= n; i += 1) {
     string a = read();
     string b = read();
     if (st.find(b) != st.end()) {
       continue;
     }
     st.insert(a);
     if (mp.find(a) != mp.end()) {
       mp[b] = mp[a];
       mp.erase(a);
       continue;
     }
     mp[b] = a;
   }
   printf( %d
 , mp.size());
   for (auto x : mp) {
     if (x.second ==  _ ) {
       continue;
     }
     printf( %s %s
 , x.second.c_str(), x.first.c_str());
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m;
 vector<vector<int>> p;
 bool is(int val) {
   int c = 0;
   vector<bool> pres(n, 0);
   bool flag = 0;
   for (int i = 0; i < m; i++) {
     c = 0;
     for (int j = 0; j < n; j++) {
       if (p[i][j] >= val) {
         pres[j] = true;
         c++;
       }
     }
     if (c > 1) flag = 1;
   }
   if (!flag) return false;
   bool ans = 1;
   for (bool i : pres)
     if (!i) return false;
   return true;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int t;
   cin >> t;
   while (t--) {
     cin >> m >> n;
     p.assign(m, vector<int>(n));
     int minn = INT_MAX, maxx;
     for (int i = 0; i < m; i++)
       for (int j = 0; j < n; j++) cin >> p[i][j];
     for (int i = 0; i < n; i++) {
       maxx = -1;
       for (int j = 0; j < m; j++) {
         maxx = max(maxx, p[j][i]);
       }
       minn = min(maxx, minn);
     }
     int l = 1, r = minn + 3;
     while (r - l > 1) {
       int mid = (l + r) / 2;
       if (is(mid))
         l = mid;
       else
         r = mid;
     }
     cout << l << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 4e5 + 123;
 long long n, m, k;
 int num[maxn];
 int dp[maxn][5];
 int presum[maxn];
 int tmp[maxn];
 int main(int argc, char const *argv[]) {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   std::cin >> n;
   for (int i = 1; i <= n; i++) {
     long long u;
     std::cin >> u;
     int one = 0;
     while (u) {
       if (u % 2 == 1) {
         one++;
       }
       u /= 2;
     }
     num[i] = one;
   }
   long long ans = 0;
   for (int i = 1; i <= n; i++) {
     dp[i][1] = dp[i - 1][1];
     dp[i][0] = dp[i - 1][0];
     presum[i] = presum[i - 1] + num[i];
     if (presum[i] % 2 == 1) {
       dp[i][1] += 1;
     } else {
       dp[i][0] += 1;
     }
   }
   int cur = n + 1;
   for (int i = n; i >= 0; --i) {
     tmp[i] = cur;
     if (num[i] != 0) {
       cur = i;
     }
   }
   for (int i = 1; i <= n; i++) {
     int k = presum[i - 1] % 2;
     int cur = i;
     int sum = num[i];
     int maxx = num[i];
     for (int j = 1; j < 71; j++) {
       int kk = tmp[cur];
       if (maxx <= sum / 2) {
         ans += dp[kk - 1][k] - dp[cur - 1][k];
       }
       maxx = max(maxx, num[kk]);
       sum += num[kk];
       cur = kk;
       if (cur > n) {
         break;
       }
     }
     ans += dp[n][k] - dp[cur - 1][k];
   }
   std::cout << ans << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int cnt(long long int x) {
   long long int ans = 0;
   while (x) {
     x /= 2;
     ans++;
   }
   return ans;
 }
 int main() {
   int t;
   cin >> t;
   while (t--) {
     long long int d, m;
     cin >> d >> m;
     long long int temp = cnt(d) - 1;
     long long int ans = d - pow(2, temp) + 2;
     for (long long int i = temp - 1; i >= 0; i--) {
       ans = ans * (pow(2, i) + 1);
       ans %= m;
     }
     ans = (ans - 1) % m;
     if (ans < 0) ans = m + ans;
     cout << ans << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 inline int nextint() {
   int res = 0;
   char c = 0;
   while (c < '0' || c > '9') c = getchar();
   while (c >= '0' && c <= '9') {
     res = res * 10 + c - '0';
     c = getchar();
   }
   return res;
 }
 int n;
 long long a[200000], b[200000];
 bool good[200000];
 bool ans[200000];
 long long diff[200000];
 const int maxh = 17;
 const int maxn = (1 << maxh);
 long long tree[2 * maxn];
 void build() {
   for (int i = maxn - 1; i; i--) tree[i] = min(tree[i + i], tree[i + i + 1]);
 }
 long long get(int i, int j) {
   long long result = (long long)1e18;
   for (i += maxn - 1, j += maxn; i + 1 != j; i >>= 1, j >>= 1) {
     if (!(i & 1)) result = min(result, tree[i + 1]);
     if (j & 1) result = min(result, tree[j - 1]);
   }
   return result;
 }
 long long get_min(int i, int j) {
   long long result = (long long)1e18;
   if (i <= j) result = get(i + 1, j + 2);
   return result;
 }
 void go() {
   memset(tree, 0, sizeof(tree));
   for (int i = 0; i < (int)(n); ++i)
     tree[maxn + i + 1] = tree[maxn + i] + diff[i];
   build();
   for (int i = 0; i < (int)(n); ++i) {
     long long presum = tree[maxn + i];
     long long postsum = tree[maxn + n] - presum;
     long long m_main = get_min(i, n - 1);
     long long m_oth = get_min(0, i - 1);
     bool ok = true;
     if (-presum + m_main < 0) ok = false;
     if (postsum + m_oth < 0) ok = false;
     good[i] = ok;
   }
 }
 int main() {
   cin >> n;
   for (int i = 0; i < (int)(n); ++i) {
     int _a;
     scanf( %d , &_a);
     a[i] = _a;
   }
   for (int i = 0; i < (int)(n); ++i) {
     int _b;
     scanf( %d , &_b);
     b[i] = _b;
   }
   for (int i = 0; i < (int)(n); ++i) diff[i] = a[i] - b[i];
   go();
   for (int i = 0; i < (int)(n); ++i)
     if (good[i]) ans[i] = true;
   memset(good, 0, sizeof(good));
   reverse(a + 1, a + n);
   reverse(b, b + n);
   for (int i = 0; i < (int)(n); ++i) diff[i] = a[i] - b[i];
   go();
   for (int i = 0; i < (int)(n); ++i)
     if (good[i]) ans[(n - i) % n] = true;
   int ans_size = 0;
   for (int i = 0; i < (int)(n); ++i)
     if (ans[i]) ans_size++;
   cout << ans_size << endl;
   for (int i = 0; i < (int)(n); ++i)
     if (ans[i]) cout << (i + 1) <<    ;
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> edges[8];
 int calc(int a, int b) {
   vector<int> cnt(8);
   for (auto e : edges[a]) cnt[e]++;
   for (auto e : edges[b]) cnt[e]++;
   int sol = 0;
   for (int i = 1; i <= 7; i++)
     if (cnt[i] == 2) sol++;
   return sol;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n, m, a, b;
   cin >> n >> m;
   for (int i = 0; i < m; i++) {
     cin >> a >> b;
     edges[a].push_back(b);
     edges[b].push_back(a);
   }
   if (n <= 6) {
     cout << m <<
 ;
     return 0;
   }
   int mmin = 1e9;
   for (int i = 1; i <= n; i++) {
     for (int j = i + 1; j <= n; j++) {
       mmin = min(mmin, calc(i, j));
     }
   }
   cout << m - mmin <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 300010;
 const int M = 1000010;
 const int MOD = 1000000007;
 const int INF = 2e9;
 const double eps = 1e-8;
 const double PI = acos(-1.0);
 int fx[] = {1, -1, 0, 0};
 int fy[] = {0, 0, 1, -1};
 int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 int lcm(int x, int y) {
   x /= gcd(x, y);
   return x * y;
 }
 int Min(int a, int b) { return a < b ? a : b; }
 int Max(int a, int b) { return a > b ? a : b; }
 bool prime[M + 5], isprime[M + 5];
 vector<int> v;
 int n, m, q, cs, ar[123456];
 void sieve() {
   v.push_back(2);
   prime[1] = 1;
   int limit = (int)sqrt(M);
   for (int i = 4; i <= M; i += 2) prime[i] = 1;
   for (int i = 3; i <= M; i += 2) {
     if (!prime[i]) {
       v.push_back(i);
       if (i <= limit) {
         for (int j = i * i; j <= M; j += 2 * i) prime[j] = 1;
       }
     }
   }
 }
 int br[123456];
 int main() {
   long long n, tot = 0;
   cin >> n;
   for (int i = 0; i < n; i++) {
     cin >> ar[i];
     tot += ar[i];
   }
   for (int i = 0; i < n; i++) cin >> br[i];
   sort(br, br + n);
   long long a = br[n - 1], b = br[n - 2];
   if (tot <= a + b)
     cout <<  YES ;
   else
     cout <<  NO ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, e = 0, st[100005], d[100005], T[100005], s[100005], Time;
 struct Node {
   int v, t;
   double p;
 };
 struct {
   int v, t, nx;
 } edge[200005];
 vector<Node> E[100005];
 bool cmp(Node a, Node b) { return a.p < b.p; }
 void add(int u, int v, int t) {
   edge[e].v = v;
   edge[e].t = t;
   edge[e].nx = st[u];
   st[u] = e++;
 }
 void dfs(int u, int fa, int t) {
   s[u] = 1;
   d[u] = 2 * t;
   for (int i = st[u]; ~i; i = edge[i].nx) {
     int v = edge[i].v;
     if (v != fa) {
       Node tmp;
       t = edge[i].t;
       tmp.v = v;
       tmp.t = t;
       E[u].push_back(tmp);
       dfs(v, u, t);
       s[u] += s[v];
       d[u] += d[v];
     }
   }
 }
 void Dfs(int u) {
   int m = E[u].size();
   for (int i = 0; i < m; i++)
     E[u][i].p = (double)d[E[u][i].v] / (double)s[E[u][i].v];
   sort(E[u].begin(), E[u].end(), cmp);
   for (int i = 0; i < m; i++) {
     int v = E[u][i].v;
     int t = E[u][i].t;
     Time += t;
     T[v] = Time;
     Dfs(v);
     Time += t;
   }
 }
 int main() {
   while (~scanf( %d , &n)) {
     e = 0;
     memset(st, -1, sizeof(st));
     int a, b, t;
     for (int i = 1; i < n; i++) {
       scanf( %d%d%d , &a, &b, &t);
       add(a, b, t);
       add(b, a, t);
     }
     dfs(1, -1, 0);
     Time = 0;
     Dfs(1);
     double ans = 0;
     for (int i = 2; i <= n; i++) ans += 1.0 * T[i];
     printf( %.12f
 , ans / 1.0 / (n - 1));
   }
 }


#include <bits/stdc++.h>
 const int INT_INF = 0x3f3f3f3f;
 const int INT_M_INF = 0x7f7f7f7f;
 const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
 const long long LL_M_INF = 0x7f7f7f7f7f7f7f7f;
 const double pi = acos(-1.0);
 using namespace std;
 inline void debug(char ch) {
   for (int __ii = 0; __ii < 20; ++__ii) putchar(ch);
   printf(
 );
 }
 const double eps = 1e-8;
 inline int dcmp(double a, double b) {
   if (fabs(a - b) < eps) return 0;
   return a < b ? -1 : 1;
 }
 const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
 const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
 const int MAXN = 4000 + 10;
 const int MAXT = 10000 + 10;
 char s[MAXN], t[MAXN];
 int main() {
   memset(s, 0, sizeof s);
   memset(t, 0, sizeof t);
   while (scanf( %s%s , s, t) == 2) {
     int slen = strlen(s), tlen = strlen(t), ans = 0;
     for (int i = 0; i < slen; ++i) {
       int num = 0;
       for (int j = 0; j < tlen; ++j)
         if (s[i + j] == t[j]) ++num;
       ans = max(ans, num);
     }
     for (int i = 0; i < tlen; ++i) {
       int num = 0;
       for (int j = 0; j < slen; ++j)
         if (t[i + j] == s[j]) ++num;
       ans = max(ans, num);
     }
     printf( %d
 , tlen - ans);
     memset(s, 0, sizeof s);
     memset(t, 0, sizeof t);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int nump;
   int arr[7];
   scanf( %d , &nump);
   scanf( %d , &arr[0]);
   for (int i = 1; i < 7; i++) {
     scanf( %d , &arr[i]);
     arr[i] += arr[i - 1];
   }
   int tmp = (nump / arr[6]), idx = 0;
   if (tmp && arr[6] * tmp >= nump)
     tmp = (tmp - 1) * arr[6];
   else
     tmp *= arr[6];
   while (tmp + arr[idx] < nump) idx++;
   printf( %d
 , idx + 1);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string s, s1, s2;
   getline(cin, s);
   getline(cin, s1);
   getline(cin, s2);
   int substr = s.find(s1), substr1;
   int forward = 0, backward = 0;
   if (substr != -1) {
     substr1 = s.find(s2, substr + s1.length());
     if (substr1 != -1) forward = 1;
   }
   string inverted;
   for (substr = 0; substr <= s.length() - 1; substr++)
     inverted = s[substr] + inverted;
   substr = inverted.find(s1);
   if (substr != -1) {
     substr1 = inverted.find(s2, substr + s1.length());
     if (substr1 != -1) backward = 1;
   }
   if (forward == 1 && backward == 0) cout <<  forward  << endl;
   if (forward == 0 && backward == 1) cout <<  backward  << endl;
   if (forward == 1 && backward == 1) cout <<  both  << endl;
   if (forward == 0 && backward == 0) cout <<  fantasy  << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int Maxn = 50005;
 char str[Maxn];
 int hs[26];
 int main() {
   scanf( %s , str);
   int len = strlen(str), cCnt = 0;
   int xNum = 0, sta = 0;
   bool ok = false;
   int i;
   for (i = 0; i < len; i++) {
     if (i - sta >= 26 && cCnt + xNum == 26) {
       ok = true;
       for (int j = sta; j < sta + 26; j++) {
         if (str[j] == '?') {
           for (int k = 0; k < 26; k++) {
             if (hs[k] == 0) {
               hs[k] = 1;
               str[j] = 'A' + k;
               break;
             }
           }
         }
       }
       break;
     }
     if (str[i] == '?')
       xNum++;
     else {
       if (hs[str[i] - 'A'] == 0) {
         hs[str[i] - 'A'] = 1;
         cCnt++;
       } else {
         hs[str[i] - 'A']++;
         cCnt++;
         for (int j = sta; j < i; j++) {
           if (str[j] == str[i]) {
             hs[str[j] - 'A']--;
             cCnt--;
             sta = j + 1;
             break;
           } else {
             if (str[j] == '?')
               xNum--;
             else {
               hs[str[j] - 'A']--;
               cCnt--;
             }
           }
         }
       }
     }
   }
   if (!ok && i - sta >= 26 && cCnt + xNum == 26) {
     ok = true;
     for (int j = sta; j < sta + 26; j++) {
       if (str[j] == '?') {
         for (int k = 0; k < 26; k++) {
           if (hs[k] == 0) {
             hs[k] = 1;
             str[j] = 'A' + k;
             break;
           }
         }
       }
     }
   }
   if (ok) {
     for (int i = 0; i < len; i++) {
       if (str[i] == '?') str[i] = 'A';
     }
     printf( %s
 , str);
   } else {
     puts( -1 );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1e5 + 30;
 int n, a[maxn];
 long long k, res;
 bool check(long long x) {
   long long sum = 0;
   for (int i = 0; i < n; ++i) {
     sum += min((long long)a[i], x);
     if (sum > k) return false;
   }
   return true;
 }
 int main() {
   scanf( %dextra , &n, &k);
   long long sum = 0;
   for (int i = 0; i < n; ++i) {
     scanf( %d , &a[i]);
     sum += a[i];
   }
   if (k > sum) {
     printf( -1
 );
     return 0;
   }
   long long l = 0, r = sum;
   while (l <= r) {
     long long m = l + (r - l) / 2;
     if (check(m))
       l = m + 1;
     else
       r = m - 1;
   }
   sum = 0;
   for (int i = 0; i < n; ++i) sum += min((long long)a[i], r);
   res = k - sum;
   int st = 0, flag = 1;
   for (int i = 0; i < n; ++i) {
     a[i] -= min((long long)a[i], r);
     if (a[i]) {
       if (res == 0 && flag) {
         flag = 0;
         st = i;
       } else if (res > 0) {
         --res;
         --a[i];
       }
     }
   }
   for (int i = st; i < n; ++i)
     if (a[i]) printf( %d  , i + 1);
   for (int i = 0; i < st; ++i)
     if (a[i]) printf( %d  , i + 1);
   puts(  );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int x[3], y[3], r[3];
 double ansx, ansy;
 bool bisecting_normal(double x1, double y1, double x2, double y2, double &a,
                       double &b, double &c) {
   double xm = (x1 + x2) * 0.5;
   double ym = (y1 + y2) * 0.5;
   double xl = x2 - x1;
   double yl = y2 - y1;
   if (fabs(xl) < 1.0e-10 && fabs(yl) < 1.0e-10) return false;
   a = xl;
   b = yl;
   c = -xl * xm - yl * ym;
   return true;
 }
 bool dividing_locus(double x1, double y1, double r1, double x2, double y2,
                     double r2, double &xa, double &ya, double &ra) {
   double a, b, c;
   if (fabs(r1 - r2) < 1.0e-10) return false;
   a = -r1 * r1;
   b = r2 * r2;
   c = a + b;
   a /= c;
   b /= c;
   xa = x1 * b + x2 * a;
   ya = y1 * b + y2 * a;
   ra = fabs(r1 * r2 / c) * sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
   return true;
 }
 bool line2line() {
   double a, b, c, d, e, f, g;
   bisecting_normal(x[0], y[0], x[1], y[1], a, b, c);
   bisecting_normal(x[0], y[0], x[2], y[2], d, e, f);
   g = a * e - b * d;
   if (fabs(g) < 1.0e-10) return false;
   ansx = (b * f - e * c) / g;
   ansy = (d * c - a * f) / g;
   return true;
 }
 bool line2circle(int z) {
   int z1, z2;
   double a, b, c, d, e, s, t, u, n, xm, ym, xa1, xa2, ya1, ya2, d1, d2;
   z1 = (z + 1) % 3;
   z2 = (z + 2) % 3;
   bisecting_normal(x[z1], y[z1], x[z2], y[z2], a, b, c);
   dividing_locus(x[z], y[z], r[z], x[z1], y[z1], r[z1], s, t, u);
   n = sqrt(a * a + b * b);
   d = (a * s + b * t + c) / n;
   if (d > u) return false;
   xm = s - d * a / n;
   ym = t - d * b / n;
   e = sqrt(u * u - d * d);
   xa1 = xm + e * b / n;
   ya1 = ym - e * a / n;
   xa2 = xm - e * b / n;
   ya2 = ym + e * a / n;
   d1 = (xa1 - x[z]) * (xa1 - x[z]) + (ya1 - y[z]) * (ya1 - y[z]);
   d2 = (xa2 - x[z]) * (xa2 - x[z]) + (ya2 - y[z]) * (ya2 - y[z]);
   if (d1 < d2) {
     ansx = xa1;
     ansy = ya1;
   } else {
     ansx = xa2;
     ansy = ya2;
   }
   return true;
 }
 bool circle2circle() {
   double a, b, c, d, f, e, s1, t1, u1, s2, t2, u2, xm, ym, xv, yv, xa1, xa2,
       ya1, ya2, d1, d2;
   dividing_locus(x[0], y[0], r[0], x[1], y[1], r[1], s1, t1, u1);
   dividing_locus(x[0], y[0], r[0], x[2], y[2], r[2], s2, t2, u2);
   xv = t2 - t1;
   yv = s1 - s2;
   d = xv * xv + yv * yv;
   if ((u1 + u2) * (u1 + u2) < d || (u1 - u2) * (u1 - u2) > d) return false;
   a = d + u1 * u1 - u2 * u2;
   b = d - u1 * u1 + u2 * u2;
   c = a + b;
   a /= c;
   b /= c;
   xm = s1 * b + s2 * a;
   ym = t1 * b + t2 * a;
   d = sqrt(d);
   xv /= d;
   yv /= d;
   f = (d * d + u1 * u1 - u2 * u2) / (2. * d);
   e = fabs(sqrt(u1 * u1 - f * f));
   xa1 = xm + e * xv;
   ya1 = ym + e * yv;
   xa2 = xm - e * xv;
   ya2 = ym - e * yv;
   d1 = (xa1 - x[0]) * (xa1 - x[0]) + (ya1 - y[0]) * (ya1 - y[0]);
   d2 = (xa2 - x[0]) * (xa2 - x[0]) + (ya2 - y[0]) * (ya2 - y[0]);
   if (d1 < d2) {
     ansx = xa1;
     ansy = ya1;
   } else {
     ansx = xa2;
     ansy = ya2;
   }
   return true;
 }
 int main() {
   bool exists;
   for (int i = 0; i < 3; i++) {
     cin >> x[i] >> y[i] >> r[i];
   }
   if (r[0] == r[1]) {
     if (r[0] == r[2]) {
       exists = line2line();
     } else {
       exists = line2circle(2);
     }
   } else {
     if (r[0] == r[2]) {
       exists = line2circle(1);
     } else {
       exists = circle2circle();
     }
   }
   if (exists) {
     cout << fixed << setprecision(5) << ansx <<     << ansy << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long inf = 2000000002;
 pair<long long, long long> p[100005];
 long long minl[100005], maxl[100005], minr[100005], maxr[100005];
 int main() {
   int i, j, n, a, b;
   while (~scanf( %d , &n)) {
     for (i = 0; i < n; i++) {
       scanf( %d%d , &a, &b);
       p[i] = make_pair(a - b, a + b);
     }
     sort(p, p + n);
     minl[0] = maxl[0] = p[0].second;
     for (i = 1; i < n; i++)
       minl[i] = min(minl[i - 1], p[i].second),
       maxl[i] = max(maxl[i - 1], p[i].second);
     minr[n - 1] = maxr[n - 1] = p[n - 1].second;
     for (i = n - 2; i >= 0; i--)
       minr[i] = min(minr[i + 1], p[i].second),
       maxr[i] = max(maxr[i + 1], p[i].second);
     long long l = 0, r = 4 * inf;
     while (l < r) {
       long long s = (l + r) / 2;
       bool can = 0;
       j = 0;
       for (i = 0; i < n; i++) {
         while (j < n - 1 && p[j + 1].first - p[i].first <= s) j++;
         if (i == 0 && j == n - 1) {
           can = true;
           break;
         }
         long long miny = inf, maxy = -inf;
         if (i > 0) miny = min(minl[i - 1], miny), maxy = max(maxl[i - 1], maxy);
         if (j < n - 1)
           miny = min(miny, minr[j + 1]), maxy = max(maxr[j + 1], maxy);
         if (maxy - miny <= s) can = true;
         if (can) break;
       }
       if (can)
         r = s;
       else
         l = s + 1;
     }
     double t = l * 0.5;
     printf( %.8lf
 , t);
   }
   return 0;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 const long long MOD = 1e9 + 7;
 const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
 int main() {
   int n, m, array1[100][100], mini, maxi = -OO, i, j;
   scanf( %d %d , &n, &m);
   for (i = 0; i < n; ++i) {
     for (j = 0; j < m; ++j) {
       scanf(  %d , &array1[i][j]);
     }
   }
   for (i = 0; i < n; ++i) {
     mini = OO;
     for (j = 0; j < m; ++j) {
       mini = min(mini, array1[i][j]);
     }
     maxi = max(maxi, mini);
   }
   printf( %d , maxi);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   ;
   long long i, j, k, l, n, m;
   long long t;
   cin >> t;
   while (t--) {
     cin >> n >> m;
     for (i = 1; i <= n; i++) {
       for (j = 1; j <= m; j++) {
         if (i == 1 && j == 1)
           cout <<  B ;
         else if (i == 1 && j >= 2)
           cout <<  W ;
         else
           cout <<  B ;
       }
       cout <<
 ;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<vector<int> > bord(312345);
 vector<int> ans;
 int main() {
   std::ios::sync_with_stdio(false);
   int n, a, b, k;
   cin >> n >> a >> b >> k;
   string s;
   cin >> s;
   int i, sumi = 0, counter = 0;
   for (i = 0; i < n; i++) {
     if (s[i] == '1') {
       counter++;
     } else {
       bord[counter].push_back(i + 1);
     }
   }
   for (i = 0; i < counter + 1; i++) {
     sumi += bord[i].size() / b;
   }
   sumi -= a;
   sumi++;
   cout << sumi << endl;
   for (i = 0; i < counter + 1; i++) {
     int val = bord[i].size();
     int j = b - 1;
     while (sumi) {
       if (j < val) {
         ans.push_back(bord[i][j]);
         j += b;
         sumi--;
       } else {
         break;
       }
     }
   }
   for (i = 0; i < ans.size(); i++) {
     cout << ans[i] <<    ;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1000000 + 10;
 const int INF = 1e9 + 7;
 const int MOD = 1e9 + 7;
 const double eps = 1e-10;
 const double pi = acos(-1);
 int T, cases, n, m;
 int main() {
   ios::sync_with_stdio(false);
   ;
   cin >> n >> m;
   int ans;
   if (n == 1 || m == 1)
     ans = n * m;
   else if (n == 2 || m == 2) {
     if (m == 2) swap(n, m);
     if (m % 4 == 1)
       ans = m / 4 * 4 + 2;
     else
       ans = (m + 3) / 4 * 4;
   } else
     ans = max((n * m) / 2, (n * m) - (n * m / 2));
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1610;
 typedef int MAP[maxn][maxn];
 int n, m;
 MAP A, B, flag, used;
 int total;
 int num[maxn * maxn], que[maxn * maxn * 2];
 MAP temp;
 int px[] = {0, 0, 1, -1, 0}, py[] = {1, -1, 0, 0, 0};
 bool isok(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; }
 void zoomin(MAP X) {
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= m; j++) {
       int value = 1;
       for (int x = 0; x < 5; x++)
         if (isok(i + px[x], j + py[x]) && X[i + px[x]][j + py[x]] == 0)
           value = 0;
       temp[i][j] = value;
     }
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= m; j++) X[i][j] = temp[i][j];
 }
 void zoomout(MAP X) {
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= m; j++) {
       int value = 0;
       for (int x = 0; x < 5; x++)
         if (isok(i + px[x], j + py[x]) && X[i + px[x]][j + py[x]] == 1)
           value = 1;
       temp[i][j] = value;
     }
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= m; j++) X[i][j] = temp[i][j];
 }
 void bfs(int x, int y, int& index) {
   index++;
   int start = 1, tail = 0, sum = 0;
   que[++tail] = x;
   que[++tail] = y;
   used[x][y] = 1;
   while (start <= tail) {
     x = que[start++];
     y = que[start++];
     flag[x][y] = index;
     sum++;
     for (int i = 0; i < 4; i++)
       if (isok(x + px[i], y + py[i]) && !used[x + px[i]][y + py[i]] &&
           B[x + px[i]][y + py[i]] == 1) {
         used[x + px[i]][y + py[i]] = 1;
         que[++tail] = x + px[i];
         que[++tail] = y + py[i];
       }
   }
   if (sum < 100) index--;
 }
 void bfs(int x, int y) {
   int start = 1, tail = 0, sum = 0, index = 0;
   que[++tail] = x;
   que[++tail] = y;
   used[x][y] = 1;
   while (start <= tail) {
     x = que[start++];
     y = que[start++];
     sum++;
     for (int i = 0; i < 4; i++)
       if (isok(x + px[i], y + py[i]) && !used[x + px[i]][y + py[i]] &&
           A[x + px[i]][y + py[i]] == 1) {
         if (!flag[x + px[i]][y + py[i]]) {
           used[x + px[i]][y + py[i]] = 1;
           que[++tail] = x + px[i];
           que[++tail] = y + py[i];
         } else {
           index = flag[x + px[i]][y + py[i]];
         }
       }
   }
   if (sum > 2) num[index]++;
 }
 int main() {
   scanf( %d%d , &n, &m);
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= m; j++) scanf( %d , &A[i][j]);
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= m; j++) B[i][j] = A[i][j];
   for (int i = 1; i <= 3; i++) zoomin(B);
   for (int i = 1; i <= 4; i++) zoomout(B);
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= m; j++)
       if (!used[i][j] && B[i][j]) bfs(i, j, total);
   memset(used, 0, sizeof(used));
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= m; j++)
       if (!used[i][j] && A[i][j] && !flag[i][j]) bfs(i, j);
   sort(num + 1, num + 1 + total);
   cout << total << endl;
   for (int i = 1; i <= total; i++) cout << num[i] <<    ;
   return 0;
 }


#include <bits/stdc++.h>
 int main(void) {
   int n, sum = 0;
   scanf( %d , &n);
   getchar();
   char str[n];
   gets(str);
   for (int i = 0; i < n; i++) {
     if (str[i] == '+')
       sum++;
     else if (str[i] == '-' && sum != 0)
       sum--;
   }
   printf( %d
 , sum);
   return 0;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2e5 + 10, inf = 0x3f3f3f3f;
 int sa[N];
 int rk[N];
 int tmp[N];
 int lcp[N];
 char s[N], t[N];
 int n, k;
 bool cmp(int i, int j) {
   if (rk[i] != rk[j])
     return rk[i] < rk[j];
   else {
     int ri = i + k <= n ? rk[i + k] : -1;
     int rj = j + k <= n ? rk[j + k] : -1;
     return ri < rj;
   }
 }
 void build(char *s, int *sa) {
   n = strlen(s);
   for (int i = 0; i <= n; i++) {
     sa[i] = i;
     rk[i] = i < n ? s[i] : -1;
   }
   for (k = 1; k <= n; k *= 2) {
     sort(sa, sa + n + 1, cmp);
     tmp[sa[0]] = 0;
     for (int i = 1; i <= n; i++) {
       tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) ? 1 : 0);
     }
     for (int i = 0; i <= n; i++) {
       rk[i] = tmp[i];
     }
   }
 }
 void LCP(char *s, int *sa, int *lcp) {
   n = strlen(s);
   for (int i = 0; i <= n; i++) rk[sa[i]] = i;
   int h = 0;
   lcp[0] = 0;
   for (int i = 0; i < n; i++) {
     int j = sa[rk[i] - 1];
     for (h ? h-- : 0; j + h < n && i + h < n && s[j + h] == s[i + h]; h++)
       ;
     lcp[rk[i] - 1] = h;
   }
 }
 int st[N], pos[N];
 int main() {
   int T;
   scanf( %d , &T);
   while (T--) {
     scanf( %s , s);
     int n = strlen(s);
     build(s, sa);
     LCP(s, sa, lcp);
     for (int i = 0; i < n; i++) {
     }
     int now = 0;
     lcp[n] = 0;
     long long ans = 0;
     for (int i = 1; i <= n; i++) {
       int newpos = i, len = lcp[i];
       while (now > 0 && st[now] > len) {
         long long v1 = st[now] - max(st[now - 1], len);
         long long v2 = i - pos[now] + 1;
         ans += v1 * v2 * v2;
         newpos = pos[now--];
       }
       st[++now] = len;
       pos[now] = newpos;
     }
     for (int i = 0; i < n; i++) {
       ans += n - i - max(lcp[rk[i] - 1], lcp[rk[i]]);
     }
     printf( %lld
 , ans);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX_N = 2000;
 int n, m, k, t, a[MAX_N + 1], b[MAX_N + 1], p[MAX_N + 1];
 vector<int> x;
 vector<int> y;
 int main() {
   int i, j, ans = 0;
   scanf( %d , &n);
   for (i = 1; i <= n; i++) scanf( %d , a + i);
   for (i = 1; i <= n; i++) scanf( %d , b + i), p[b[i]] = i;
   for (i = 1; i <= n; i++) {
     for (k = i;; k++)
       if (p[a[k]] == i) break;
     while (k != i) {
       for (j = i; j <= k; j++)
         if (p[a[j]] >= k) {
           x.push_back(k);
           y.push_back(j);
           ans += k - j;
           swap(a[j], a[k]);
           k = j;
         }
     }
   }
   printf( %d
%d
 , ans, x.size());
   for (i = 0; i < x.size(); i++) printf( %d %d
 , x[i], y[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long a, b;
   cin >> a >> b;
   cout << fixed << setprecision(7) << a * pow(double(1.000000011), b) << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 1000000000;
 long long mod = 1000000007LL;
 long long mod2 = 998244353LL;
 int n, m, k;
 bool a[1000005];
 int main() {
   cin >> n >> m >> k;
   memset(a, false, sizeof(a));
   for (int i = 1; i <= n; ++i) {
     int ai;
     scanf( %d , &ai);
     a[ai] = true;
   }
   int ans = 0;
   deque<int> dq;
   for (int i = 1; i <= 1000001; ++i) {
     if (a[i]) {
       dq.push_back(i);
     }
     while (!dq.empty() && i - dq.front() >= m) {
       dq.pop_front();
     }
     if (i >= m) {
       int det = dq.size() - (k - 1);
       if (det > 0) {
         for (int j = 1; j <= det; ++j) {
           dq.pop_back();
           ans++;
         }
       }
     }
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int cnt[5005][5005];
 int len;
 char st[5005];
 bool palin[5005][5005];
 void updateFreq(int r, int c) {
   int cc;
   while (r <= len) {
     cc = c;
     while (cc <= len) {
       cnt[r][cc]++;
       cc += (cc & (-cc));
     }
     r += (r & (-r));
   }
 }
 int readFreq(int r, int c) {
   int ret = 0;
   int cc;
   while (r > 0) {
     cc = c;
     while (cc > 0) {
       ret += cnt[r][cc];
       cc -= (cc & (-cc));
     }
     r -= (r & (-r));
   }
   return ret;
 }
 int main() {
   scanf( %s , st + 1);
   len = strlen(st + 1);
   int q;
   scanf( %d , &q);
   for (int d = 0, lets_stop_here = (int)len + 1; d < lets_stop_here; d++) {
     for (int i = 1, lets_stop_here = (int)len; i <= lets_stop_here; i++) {
       int j = i + d;
       if (j > len) break;
       if (i == j)
         palin[i][j] = true;
       else if (j - i == 1)
         palin[i][j] = st[i] == st[j] ? true : false;
       else if (palin[i + 1][j - 1])
         palin[i][j] = st[i] == st[j] ? true : false;
       else
         palin[i][j] = false;
       if (palin[i][j]) updateFreq(i, j);
     }
   }
   while (q--) {
     int l, r;
     scanf( %d %d , &l, &r);
     int ans = readFreq(r, r) - readFreq(r, l - 1) - readFreq(l - 1, r) +
               readFreq(l - 1, l - 1);
     printf( %d
 , ans);
   }
   return 0;
 }


#include <bits/stdc++.h>
 const int maxn = 1e5 + 51;
 const int mod1 = 1e9 + 7;
 const int mod2 = 1e9 + 9;
 std::vector<std::pair<int, int>> g[maxn];
 int dfn[maxn], idx = 0;
 int f[maxn], fw[maxn];
 int xr;
 std::vector<std::vector<int>> V;
 void dfs(int u, int fa) {
   dfn[u] = ++idx;
   for (auto x : g[u]) {
     int v = x.first, w = x.second;
     if (v == fa) continue;
     if (!dfn[v]) {
       f[v] = u, fw[v] = w;
       dfs(v, u);
     } else if (dfn[v] > dfn[u]) {
       std::vector<int> vec;
       int cur = w;
       for (int now = v; now ^ u; now = f[now]) cur ^= fw[now];
       vec.push_back(cur ^ w);
       for (int now = v; now ^ u; now = f[now]) vec.push_back(cur ^ fw[now]);
       xr ^= cur;
       V.push_back(vec);
     }
   }
 }
 int add(int x, int y, const int& mod) {
   x += y;
   return (x >= mod) ? x - mod : x;
 }
 int dec(int x, int y, const int& mod) {
   x -= y;
   return (x < 0) ? x + mod : x;
 }
 int n, m;
 int main() {
   std::ios::sync_with_stdio(false);
   std::cin.tie(nullptr);
   std::cout.tie(nullptr);
   std::cin >> n >> m;
   for (int i = 1; i <= m; i++) {
     int u, v, w;
     std::cin >> u >> v >> w;
     g[u].push_back({v, w});
     g[v].push_back({u, w});
     xr ^= w;
   }
   dfs(1, 0);
   static int a[1 << 17 | 3], b[1 << 17 | 3];
   auto fwt = [&](int* f, int lim, const int& inv, const int& mod) {
     for (int len = 1; len < lim; len <<= 1) {
       for (int i = 0; i < lim; i += len << 1) {
         for (int j = 0; j < len; j++) {
           int x = f[i + j], y = f[i + j + len];
           f[i + j] = add(x, y, mod);
           f[i + j + len] = dec(x, y, mod);
           if (inv > 1)
             f[i + j] = 1ll * f[i + j] * inv % mod,
                   f[i + j + len] = 1ll * f[i + j + len] * inv % mod;
         }
       }
     }
   };
   a[xr] = 1, b[xr] = 1;
   fwt(a, 1 << 17, 1, mod1);
   fwt(b, 1 << 17, 1, mod2);
   static int c[1 << 17 | 3], d[1 << 17 | 3];
   for (auto v : V) {
     memset(c, 0, sizeof(c));
     memset(d, 0, sizeof(d));
     for (auto x : v) c[x]++, d[x]++;
     fwt(c, 1 << 17, 1, mod1);
     fwt(d, 1 << 17, 1, mod2);
     for (int i = 0; i < (1 << 17); i++) {
       a[i] = 1ll * a[i] * c[i] % mod1;
       b[i] = 1ll * b[i] * d[i] % mod2;
     }
   }
   fwt(a, 1 << 17, (mod1 + 1) >> 1, mod1);
   fwt(b, 1 << 17, (mod2 + 1) >> 1, mod2);
   for (int i = 0; i < (1 << 17); i++)
     if (a[i] || b[i]) {
       std::cout << i << ' ' << a[i] << '
';
       return 0;
     }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e5 + 9;
 const long long mod = 998244353;
 long long dp[N][1 << 7];
 int s[N][1 << 7], st[N], Log[1 << 7];
 struct node {
   int v, id;
 } a[N];
 bool cmp(node a, node b) { return a.v > b.v; }
 void upd(long long &a, long long b) {
   if (a < b) a = b;
 }
 int main() {
   int n, p, k;
   for (int i = (1); i < (N); ++i) st[i] = st[i >> 1] + (i & 1);
   for (int i = (0); i < (7); ++i) Log[1 << i] = i;
   scanf( %d%d%d , &n, &p, &k);
   for (int i = (1); i < (n + 1); ++i) {
     scanf( %d , &a[i].v);
     a[i].id = i;
   }
   sort(a + 1, a + 1 + n, cmp);
   int op = (1 << p) - 1;
   for (int i = (1); i < (n + 1); ++i)
     for (int j = (0); j < (p); ++j) scanf( %d , &s[i][j]);
   for (int i = (1); i < (p + k + 1); ++i) {
     for (int mask = (0); mask < (1 << p); ++mask) {
       if (st[mask] > i - 1) continue;
       upd(dp[i - st[mask]][mask], dp[i - st[mask] - 1][mask] + a[i].v);
       int pos = op ^ mask;
       while (pos) {
         upd(dp[i - st[mask] - 1][mask | ((pos) & (-pos))],
             dp[i - st[mask] - 1][mask] + s[a[i].id][Log[((pos) & (-pos))]]);
         pos ^= ((pos) & (-pos));
       }
     }
   }
   for (int i = (p + k + 1); i < (n + 1); ++i) {
     for (int mask = (1 << p) - 1; mask >= (0); --mask) {
       int pos = mask;
       while (pos) {
         upd(dp[k][mask],
             dp[k][mask ^ ((pos) & (-pos))] + s[a[i].id][Log[((pos) & (-pos))]]);
         pos ^= ((pos) & (-pos));
       }
     }
   }
   printf( %lld , dp[k][op]);
 }


#include <bits/stdc++.h>
 using namespace std;
 long long ans[100010];
 long long ans2[100010];
 int main() {
   int n, p;
   int l, r;
   while (cin >> n >> p) {
     for (int i = 0; i < n; i++) {
       scanf( %d%d , &l, &r);
       ans[i] = r / p - l / p;
       ans2[i] = r - l + 1;
       if (l % p == 0) ans[i]++;
     }
     ans[n] = ans[0];
     ans2[n] = ans2[0];
     double anss = 0;
     for (int i = 0; i < n; i++)
       anss += ((ans[i] * (ans2[i + 1] - ans[i + 1]) +
                 (ans2[i] - ans[i]) * ans[i + 1] + ans[i] * ans[i + 1]) *
                1.0) /
               (ans2[i] * ans2[i + 1] * 1.0) * 2000;
     printf( %.10llf , anss);
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma warning(disable : 4996)
 using namespace std;
 int IT_MAX = 1 << 17;
 const long long MOD = 5000000;
 const int INF = 1034567891;
 const long long LL_INF = 1234567890123456789ll;
 const double PI = 3.141592653589793238;
 const double ERR = 1E-11;
 int in[200050];
 int lr[200050][2];
 int v[200050];
 int main() {
   int N, T, K, i, j;
   scanf( %d %d %d , &N, &T, &K);
   for (i = 1; i <= T; i++) scanf( %d , &in[i]);
   in[0] = 1;
   for (i = 1; i < T; i++) {
     lr[i][1] = in[i] - 1;
     lr[i][0] = max(0, in[i] - in[i + 1]);
   }
   lr[T][0] = lr[T][1] = in[T];
   int mn = 0, mx = 0;
   for (i = 1; i <= T; i++) mn += lr[i][0], mx += lr[i][1];
   if (K < mn || mx < K) return !printf( -1
 );
   int t = K - mn;
   for (i = 1; i <= T; i++) {
     int t2 = min(t, lr[i][1] - lr[i][0]);
     t -= t2;
     v[i] = in[i] - (lr[i][0] + t2);
   }
   v[0] = 1;
   printf( %d
 , N);
   int pst = 1;
   for (i = 1; i <= T; i++) {
     int st = pst + in[i - 1];
     for (j = 0; j < v[i - 1]; j++) printf( %d %d
 , pst + j, st + j);
     for (j = v[i - 1]; j < in[i]; j++) printf( %d %d
 , pst, st + j);
     pst = st;
   }
   return 0;
 }


#include<bits/stdc++.h>
 #define LL long long
 #define dl double
 #define P pair<int,int>
 using namespace std;

 const int N = 2e5 + 10;

 int n;
 struct ghb{
   int a,b;
   bool operator < (const ghb &o)const{
     return min(a,b) < min(o.a,o.b);
   }
 }f[N];
 LL ans;
 int mx;

 int main(){
   // freopen( in.txt , r ,stdin);
   // freopen( o.txt , w ,stdout);
   std::ios::sync_with_stdio(false);
   std::cin.tie(nullptr);
   cin >> n;
   for(int i = 1;i <= n;i++)cin >> f[i].a;
   for(int i = 1;i <= n;i++)cin >> f[i].b;
   for(int i = 1;i <= n;i++)ans += abs(f[i].a - f[i].b);
   sort(f + 1,f + n + 1);
   int mx_1 = 0,mx_2 = 0;
   for(int i = 1;i <= n;i++){
     if(f[i].a > f[i].b){
       if(mx_1)mx = max(mx,min(mx_1,f[i].a) - f[i].b);
       mx_2 = max(mx_2,f[i].a);
     }
     else {
       if(mx_2)mx = max(mx,min(mx_2,f[i].b) - f[i].a);
       mx_1 = max(mx_1,f[i].b);
     }
   }
   cout << ans - 2 * mx << endl;
   return 0;
 }
 /**/


#include <bits/stdc++.h>
 using namespace std;
 long long GCD(long long a, long long b) { return (b == 0) ? a : GCD(b, a % b); }
 bool isPrime(int x) {
   for (int i = 2; i <= sqrt(x); i++)
     if (x % i == 0) return 0;
   return 1;
 }
 bool C[26];
 int main() {
   int n, a;
   cin >> n >> a;
   vector<int> v(n);
   for (int i = 0; i < n; i++) {
     scanf( %d , &v[i]);
   }
   int ans = 0;
   if (a - 1 < n - a) {
     reverse(v.begin(), v.end());
     a = n - a + 1;
   }
   a--;
   for (int i = 0; i < a + 1; i++) {
     if (v[i] == 1 && ((2 * a - i) >= n || i == a))
       ans++;
     else if (v[i] == 1 && v[2 * a - i] == 1)
       ans += 2;
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long a, b;
 long long c, d;
 int main() {
   while (cin >> a >> b) {
     cin >> c >> d;
     for (int i = 0; i <= 1000; ++i) {
       for (int j = 0; j <= 1000; ++j) {
         if ((b + a * i) == (d + c * j)) {
           cout << b + a * i << endl;
           return 0;
         }
       }
     }
     cout <<  -1  << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int t;
   cin >> t;
   while (t--) {
     int mid, i, j;
     string a;
     cin >> a;
     if ((a.length()) % 2) {
       cout <<  NO
 ;
       continue;
     }
     mid = (a.length()) / 2;
     j = mid;
     i = 0;
     while (i < mid) {
       if (a[i] == a[j]) {
         i++;
         j++;
       } else {
         cout <<  NO
 ;
         break;
       }
     }
     if (i == mid) {
       cout <<  YES
 ;
     }
   }
 }


#include <bits/stdc++.h>
 const int N = 100100;
 const long long mod = 1e9 + 7;
 using namespace std;
 int n, Xa, Ya, Xb, Yb;
 int Smallest(int a, int b, int c, int d) {
   int min_ = a;
   if (min_ > b) min_ = b;
   if (min_ > c) min_ = c;
   if (min_ > d) min_ = d;
   return min_;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin >> n >> Xa >> Ya >> Xb >> Yb;
   if ((Xa == Xb && (Xa == 0 || Xa == n)) || (Ya == Yb && (Ya == 0 || Ya == n)))
     cout << abs(Xa - Xb) + abs(Ya - Yb) <<
 ;
   else
     cout << Smallest(abs(0 - Xa) + abs(0 - Ya) + abs(0 - Xb) + abs(0 - Yb),
                      abs(0 - Xa) + abs(n - Ya) + abs(0 - Xb) + abs(n - Yb),
                      abs(n - Xa) + abs(0 - Ya) + abs(n - Xb) + abs(0 - Yb),
                      abs(n - Xa) + abs(n - Ya) + abs(n - Xb) + abs(n - Yb))
          <<
 ;
   return 0;
 }