#include <bits/stdc++.h>
 using namespace std;
 long long max(long long a, long long b) {
   if (a > b)
     return a;
   else
     return b;
 }
 long long min(long long a, long long b) {
   if (a < b)
     return a;
   else
     return b;
 }
 int32_t main() {
   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
   long long n;
   cin >> n;
   string s = '';
   long long i = 0;
   while (i < n) {
     if (i < n) {
       s += 'a';
       i++;
     }
     if (i < n) {
       s += 'a';
       i++;
     }
     if (i < n) {
       s += 'b';
       i++;
     }
     if (i < n) {
       s += 'b';
       i++;
     }
   }
   cout << s << '
';
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 105;
 int n, m, a[maxn][maxn];
 int sumr[maxn], sumc[maxn];
 bool ar[maxn], ac[maxn];
 int main() {
   ios_base::sync_with_stdio(0);
   cin >> n >> m;
   for (int i = 0; i < n; i++)
     for (int j = 0; j < m; j++) cin >> a[i][j];
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < m; j++) sumr[i] += a[i][j];
   }
   for (int j = 0; j < m; j++) {
     for (int i = 0; i < n; i++) sumc[j] += a[i][j];
   }
   while (1) {
     bool b = 0;
     for (int i = 0; i < n; i++)
       if (sumr[i] < 0) {
         b = 1;
         ar[i] ^= 1;
         for (int j = 0; j < m; j++) sumc[j] -= 2 * a[i][j], a[i][j] = -a[i][j];
         sumr[i] *= -1;
       }
     for (int j = 0; j < m; j++)
       if (sumc[j] < 0) {
         b = 1;
         ac[j] ^= 1;
         for (int i = 0; i < n; i++) sumr[i] -= 2 * a[i][j], a[i][j] = -a[i][j];
         sumc[j] *= -1;
       }
     if (!b) break;
   }
   vector<int> vr, vc;
   for (int i = 0; i < n; i++)
     if (ar[i]) vr.push_back(i);
   for (int i = 0; i < m; i++)
     if (ac[i]) vc.push_back(i);
   cout << vr.size() << ' ';
   for (int i : vr) cout << i + 1 << ' ';
   cout << '
';
   cout << vc.size() << ' ';
   for (int i : vc) cout << i + 1 << ' ';
   cout << '
';
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int x1, y1;
   cin >> x1 >> y1;
   int x2, y2;
   cin >> x2 >> y2;
   int ans = 0x3f3f3f3f;
   for (int i = -1; i <= 1; i++) {
     for (int j = -1; j <= 1; j++) {
       if (i == 0 && j == 0) {
         continue;
       }
       ans = min(ans, abs(x1 - (x2 + i)) + abs(y1 - (y2 + j)));
     }
   }
   cout << 2 * ans + 8;
 }


#include <bits/stdc++.h>
 int main() {
   int n, m, a, b, t;
   while (scanf('%d%d%d%d', &n, &m, &a, &b) != EOF) {
     if (b == n) b = (n - 1) / m * m + m;
     a--;
     b--;
     if (a > b)
       while (1)
         ;
     if (a / m == b / m || m == 1)
       t = 1;
     else if (a % m == 0) {
       if (b % m == m - 1)
         t = 1;
       else
         t = 2;
     } else {
       if (b / m - a / m == 1)
         t = 2;
       else if (b % m == m - 1)
         t = 2;
       else if ((b - a + 1) % m == 0)
         t = 2;
       else
         t = 3;
     }
     printf('%d
', t);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int a[1000][7], i, j, m = 0, n;
   string ar;
   cin >> n;
   for (i = 0; i < n; i++) {
     cin >> ar;
     for (j = 0; j < 7; j++) {
       a[i][j] = ar[j] - 48;
     }
   }
   for (j = 0; j < 7; j++) {
     long long int l = 0;
     for (i = 0; i < n; i++) {
       if (a[i][j] == 1) {
         l++;
       }
     }
     if (l > m) {
       m = l;
     }
   }
   cout << m << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int Set(int N, int pos) { return N |= (1LL << pos); }
 int Reset(int N, int pos) { return N &= ~(1LL << pos); }
 bool Check(int N, int pos) { return N & (1LL << pos); }
 int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[] = {1, -1, 0, 0, 1, -1, -1, 1};
 template <class T>
 void cmin(T &a, T b) {
   if (b < a) a = b;
 }
 template <class T>
 void cmax(T &a, T b) {
   if (b > a) a = b;
 }
 template <class T>
 int len(const T &c) {
   return (int)c.size();
 }
 template <class T>
 int len(char c[]) {
   return (int)strlen(c);
 }
 string itos(long n) {
   string s;
   while (n) {
     s += (n % 10 + 48);
     n /= 10;
   }
   reverse(s.begin(), s.end());
   return s;
 }
 long stoi(string s) {
   long n = 0;
   for (int i(0), _n(len(s)); i < _n; ++i) n = n * 10 + (s[i] - 48);
   return n;
 }
 long long n, ar[200005], arr[200005], m, a, p, b, aa, bb, mx = 0;
 pair<int, int> fun(long d) {
   p = upper_bound(ar, ar + n, d) - ar;
   a = (p * 2 + (n - p) * 3);
   p = upper_bound(arr, arr + m, d) - arr;
   b = (p * 2 + (m - p) * 3);
   return make_pair(a, b);
 }
 int main() {
   mx = -100000000000000000LL;
   cin >> n;
   for (int i(0), _n(n); i < _n; ++i) cin >> ar[i];
   cin >> m;
   for (int i(0), _n(m); i < _n; ++i) cin >> arr[i];
   sort(ar, ar + n);
   sort(arr, arr + m);
   aa = n * 3;
   bb = m * 3;
   mx = aa - bb;
   pair<int, int> pr;
   pr = fun(ar[0] - 1);
   a = pr.first;
   b = pr.second;
   if (a - b > mx) {
     mx = a - b;
     aa = a;
     bb = b;
   } else if (a - b == mx && a > aa) {
     aa = a;
     bb = b;
   }
   for (int i(0), _n(n); i < _n; ++i) {
     pr = fun(ar[i]);
     a = pr.first;
     b = pr.second;
     if (a - b > mx) {
       mx = a - b;
       aa = a;
       bb = b;
     } else if (a - b == mx && a > aa) {
       aa = a;
       bb = b;
     }
   }
   for (int i(0), _n(m); i < _n; ++i) {
     pr = fun(arr[i]);
     a = pr.first;
     b = pr.second;
     if (a - b > mx) {
       mx = a - b;
       aa = a;
       bb = b;
     } else if (a - b == mx && a > aa) {
       aa = a;
       bb = b;
     }
   }
   pr = fun(ar[n - 1] + 1);
   a = pr.first;
   b = pr.second;
   if (a - b > mx) {
     mx = a - b;
     aa = a;
     bb = b;
   } else if (a - b == mx && a > aa) {
     aa = a;
     bb = b;
   }
   cout << aa << ':' << bb;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int getResult(long long y) {
   printf('%lld
', y);
   fflush(stdout);
   int vd;
   scanf('%d', &vd);
   if (vd <= 0) exit(0);
   vd--;
   return vd;
 }
 bool solve(vector<long long> a) {
   int maxIndex = 0;
   for (int i = 1; i < 3; i++)
     if (a[i] > a[maxIndex]) maxIndex = i;
   int minIndex = 0;
   for (int i = 1; i < 3; i++)
     if (a[i] < a[minIndex]) minIndex = i;
   int middle = 3 - maxIndex - minIndex;
   long long w = 2 * a[maxIndex] - a[minIndex] - a[middle];
   int r = getResult(w);
   if (r == maxIndex) {
     a[maxIndex] += w;
     return solve(a);
   } else {
     int otherone = 3 - maxIndex - r;
     long long w2 = a[maxIndex] - a[otherone];
     int r2 = getResult(w2);
     return r2 == 0;
   }
 }
 int main() {
   vector<long long> a(3);
   for (int i = 0; i < 3; i++) scanf('%lld', &a[i]);
   printf('First
');
   fflush(stdout);
   solve(a);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double EPS = 1e-8;
 const int INFI = 1000 * 1000 * 1000;
 const long long INFL = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
 const int MX_N = 1000;
 int N;
 string s, t;
 string strs[] = {'abc', 'acb', 'bac', 'bca', 'cab', 'cba'};
 int nstrs = 6;
 int main() {
   cin >> N;
   cin >> s >> t;
   int dobc = 0;
   cout << 'YES' << endl;
   if (s[0] == s[1]) ++dobc;
   if (t[0] == t[1]) ++dobc;
   if (N == 1 || !dobc) {
     for (int i = 0; i < nstrs; ++i) {
       string s1 = strs[i].substr(0, 2);
       string s2 = strs[i].substr(1, 2);
       if (s == s1 || s == s2 || t == s1 || t == s2) continue;
       for (int j = 0; j < 3; ++j)
         for (int k = 0; k < N; ++k) cout << strs[i][j];
       putchar('
');
       return 0;
     }
   } else {
     for (int i = 0; i < nstrs; ++i) {
       bool pass = true;
       string ap = strs[i] + strs[i];
       for (int j = 0; j < ap.size() - 1 && pass; ++j) {
         string sb = ap.substr(j, 2);
         if (s == sb || t == sb) pass = false;
       }
       if (!pass) continue;
       for (int j = 0; j < N; ++j) cout << strs[i];
       cout << endl;
       break;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[200000];
 long long INF = 1e12;
 inline bool comp_bit(int x, int y) { return !!(x & y); }
 inline int binsearch(int l, int r, int depth) {
   return (upper_bound(a + l, a + r, 1 << depth, comp_bit) - a);
 }
 long long connect(int depth, int l1, int r1, int l2, int r2) {
   if (l1 == r1 || l2 == r2) return INF;
   if (a[l1] == a[r1 - 1] && a[l2] == a[r2 - 1]) return a[l1] ^ a[l2];
   int mid1 = binsearch(l1, r1, depth), mid2 = binsearch(l2, r2, depth);
   if (mid1 == l1 && mid2 == r2 || mid1 == r1 && mid2 == l2)
     return connect(depth - 1, l1, r1, l2, r2);
   else
     return min(connect(depth - 1, l1, mid1, l2, mid2),
                connect(depth - 1, mid1, r1, mid2, r2));
 }
 long long solve(int depth, int l, int r) {
   if (!depth) return (a[l] ^ a[r - 1]) & 1;
   int mid = binsearch(l, r, depth);
   if (mid == l || mid == r)
     return solve(depth - 1, l, r);
   else
     return connect(depth - 1, l, mid, mid, r) + solve(depth - 1, l, mid) +
            solve(depth - 1, mid, r);
 }
 int main() {
   int n;
   scanf('%d', &n);
   for (int i = 0; i < n; ++i) scanf('%d', &a[i]);
   sort(a, a + n);
   printf('%lld', solve(29, 0, n));
 }


#include <bits/stdc++.h>
 using namespace std;
 struct tim {
   int begin, end;
 } t[200005];
 int cmp(tim a, tim b) {
   if (a.begin != b.begin) return a.begin < b.begin;
   return a.end < b.end;
 }
 int main() {
   int n;
   cin >> n;
   for (int i = 1; i <= n; i++) cin >> t[i].begin >> t[i].end;
   sort(t + 1, t + n + 1, cmp);
   t[0].end = -1;
   int p[3] = {0};
   int i;
   for (i = 1; i <= n; i++) {
     if (t[p[1]].end < t[i].begin) {
       p[1] = i;
       continue;
     }
     if (t[p[2]].end < t[i].begin) {
       p[2] = i;
       continue;
     }
     break;
   }
   if (i > n)
     cout << 'YES';
   else
     cout << 'NO';
 }


#include <bits/stdc++.h>
 using namespace std;
 int dx[] = {0, 0, -1, 1};
 int dy[] = {-1, 1, 0, 0};
 const int mod = 1000000007;
 const int INF = 1000000010;
 int n;
 char S[5020];
 int L[5010];
 int C[5010];
 int RV;
 pair<int, int> RM;
 int lookup[5010];
 int val[5010][15];
 int hp[5010][5010];
 int H[13][(1 << 13) + 3];
 void kmr() {
   for (int i = (0); i < (n); ++i) H[0][i] = S[i] - '0';
   pair<pair<int, int>, int> T[n];
   for (int s = (0); s < (12); ++s) {
     int d = (1 << s);
     for (int i = (0); i < (n); ++i)
       T[i] = make_pair(pair<int, int>(H[s][i], i + d < n ? H[s][i + d] : 0), i);
     sort(T, T + n);
     d = 0;
     for (int i = (0); i < (n); ++i) {
       if (i && T[i - 1].first != T[i].first) ++d;
       H[s + 1][T[i].second] = d;
     }
   }
 }
 bool eq(pair<int, int> a, pair<int, int> b) {
   if (a.second - a.first != b.second - b.first) return 0;
   return hp[a.first][a.second] == hp[b.first][b.second];
 }
 int cmp_d;
 bool cmp(pair<int, int> a, pair<int, int> b) {
   int ha = hp[a.first][a.second];
   int hb = hp[b.first][b.second];
   if (ha == hb) return a.first < b.first;
   return ha < hb;
 }
 int diff(pair<int, int> a, pair<int, int> b) {
   if (max(a.second - a.first, b.second - b.first) > 12) {
     if (!eq(pair<int, int>(a.first, a.second - 12),
             pair<int, int>(b.first, b.second - 12)))
       return INF;
     a.first = a.second - 12;
     b.first = b.second - 12;
   }
   return val[a.first][a.second - a.first] - val[b.first][b.second - b.first];
 }
 vector<pair<int, pair<int, int> > > P;
 pair<int, pair<int, int> > prep(pair<int, int> p) {
   return make_pair(hp[p.first][p.second], p);
 }
 int main() {
   scanf('%s', S);
   n = strlen(S);
   for (int i = (1); i < (n + 1); ++i) {
     int d = 0;
     while ((1 << (d + 1)) < i) ++d;
     lookup[i] = d;
   }
   for (int i = (0); i < (n); ++i) {
     val[i][0] = 0;
     for (int d = (1); d < (14); ++d)
       val[i][d] = val[i][d - 1] * 2 + S[i + d - 1] - '0';
   }
   kmr();
   for (int i = (0); i < (n); ++i)
     for (int j = (i + 1); j < (n + 1); ++j)
       hp[i][j] = (H[lookup[j - i]][i] << 16) +
                  H[lookup[j - i]][j - (1 << lookup[j - i])];
   for (int d = (1); d < (n + 1); ++d) {
     int m = P.size();
     for (int i = (0); i < (n + 1 - d); ++i)
       if (S[i] == '1') P.push_back(prep(pair<int, int>(i, i + d)));
     sort(P.begin() + m, P.end());
   }
   C[0] = 1;
   for (int i = (1); i < (n + 1); ++i) L[i] = INF;
   RV = INF;
   for (pair<int, pair<int, int> > p_ : P) {
     pair<int, int> p = p_.second;
     if (L[p.first] == INF) continue;
     C[p.second] = (C[p.second] + C[p.first]) % mod;
     L[p.second] = min(L[p.second], L[p.first] + 1);
     if (p.second == n) {
       if (RV == INF) {
         RV = L[n];
         RM = p;
       } else {
         if (diff(p, RM) < RV - L[n]) {
           RM = p;
           RV = L[n];
         }
       }
     }
   }
   printf('%d
', C[n]);
   int r = 0;
   for (int i = (RM.first); i < (RM.second); ++i) r = (2 * r + S[i] - '0') % mod;
   r = (r + RV) % mod;
   printf('%d
', r);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int c[210];
 int pre[210][210];
 int precnt[210];
 int cnt[210] = {0};
 int main() {
   int n;
   scanf('%d', &n);
   for (int i = 0; i < (n); i++) {
     scanf('%d', c + i);
     c[i] %= 3;
   }
   for (int i = 0; i < (n); i++)
     for (int j = 0; j < (n); j++) pre[i][j] = 0;
   for (int i = 0; i < (n); i++) {
     scanf('%d', precnt + i);
     int t;
     for (int j = 0; j < (precnt[i]); j++) {
       scanf('%d', &t);
       pre[i][t - 1] = 1;
     }
   }
   int mintime = 1000100;
   for (int p = 0; p < (3); p++) {
     int pos = p, time = 0, done = 0;
     for (int i = 0; i < (n); i++) cnt[i] = 0;
     while (done < n) {
       queue<int> Q;
       for (int i = 0; i < (n); i++)
         if (precnt[i] == cnt[i] && c[i] == pos) Q.push(i);
       while (!Q.empty()) {
         int part = Q.front();
         Q.pop();
         done++;
         time++;
         cnt[part]++;
         for (int i = 0; i < (n); i++)
           if (pre[i][part] == 1) {
             cnt[i]++;
             if (cnt[i] == precnt[i] && c[i] == pos) Q.push(i);
           }
       }
       pos = (pos + 1) % 3;
       time++;
     }
     time--;
     if (time < mintime) mintime = time;
   }
   printf('%d
', mintime);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int gcd(int a, int b) {
   if (b == 0) return a;
   return gcd(b, a % b);
 }
 bool isPrime(long long n) {
   long long c;
   if (n <= 1) return false;
   c = sqrt(n);
   for (int i = 2; i <= c; i++)
     if (n % i == 0) return false;
   return true;
 }
 int D(long long n) {
   int count = 0;
   while (n != 0) {
     n = n / 10;
     ++count;
   }
   return count;
 }
 const long long N = 2e5 + 7;
 long long l, k, d, tr, n, m, sum, mini, maxi, a, b, c, x, y;
 long long t[5007];
 set<int> vis;
 vector<int> v;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   for (cin >> tr; tr--;) {
     cin >> n;
     mini = 0;
     cin >> t[0];
     for (int i = 1; i < n; i++) {
       cin >> t[i];
       if (t[i] != t[i - 1]) {
         a = i;
         c = t[i];
         b = i - 1;
         mini++;
       }
     }
     if (mini) {
       cout << 'YES' << endl;
       for (int i = 0; i < n; i++) {
         if (i != a) {
           if (t[i] != c) {
             cout << i + 1 << ' ' << a + 1 << endl;
           } else {
             cout << i + 1 << ' ' << b + 1 << endl;
           }
         }
       }
     } else {
       cout << 'NO' << endl;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 3e5 + 5, LOG = 19, off = 1 << 19;
 pair<int, int> t[LOG][2 * off];
 void upd(int x, pair<int, int> p, int lg) {
   for (x += off; x; x /= 2) {
     t[lg][x].first = min(t[lg][x].first, p.first);
     t[lg][x].second = max(t[lg][x].second, p.second);
   }
 }
 pair<int, int> get(int x, int lo, int hi, int a, int b, int lg) {
   if (lo >= a && hi <= b) {
     return t[lg][x];
   }
   if (lo >= b || hi <= a) {
     return {off, 0};
   }
   int mid = (lo + hi) >> 1;
   pair<int, int> lson = get(x * 2, lo, mid, a, b, lg);
   pair<int, int> rson = get(x * 2 + 1, mid, hi, a, b, lg);
   return pair<int, int>(min(lson.first, rson.first),
                         max(lson.second, rson.second));
 }
 int r[MAXN];
 pair<int, int> par[MAXN][LOG];
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int n;
   cin >> n;
   for (int i = 0; i < n; ++i) {
     cin >> r[i];
   }
   if (n == 1) {
     cout << 0;
     return 0;
   }
   for (int i = 0; i < 2 * off; ++i)
     for (int lg = 0; lg < LOG; ++lg) {
       t[lg][i].first = off;
     }
   for (int i = 0; i < n; ++i)
     for (int j = 0; j < 3; ++j) {
       par[i + j * n][0].first = max(0, i + j * n - r[i]);
       par[i + j * n][0].second = min(3 * n - 1, i + j * n + r[i]);
       upd(i + j * n, par[i + j * n][0], 0);
     }
   for (int lg = 1; lg < LOG; ++lg) {
     for (int i = n; i < 2 * n; ++i) {
       par[i][lg] = get(1, 0, off, par[i][lg - 1].first,
                        par[i][lg - 1].second + 1, lg - 1);
     }
     for (int i = 0; i < n; ++i) {
       par[i][lg].first = max(0, par[i + n][lg].first - n);
       par[i][lg].second = min(3 * n - 1, par[i + n][lg].second - n);
     }
     for (int i = 2 * n; i < 3 * n; ++i) {
       par[i][lg].first = max(0, par[i - n][lg].first + n);
       par[i][lg].second = min(3 * n - 1, par[i - n][lg].second + n);
     }
     for (int i = 0; i < 3 * n; ++i) {
       upd(i, par[i][lg], lg);
     }
   }
   for (int j = 0; j < n; ++j) {
     int i = n + j;
     int lo = i, hi = i, sol = 0;
     for (int lg = LOG - 1; lg >= 0; --lg) {
       pair<int, int> res = get(1, 0, off, lo, hi + 1, lg);
       if (res.second - res.first + 1 < n) {
         lo = res.first;
         hi = res.second;
         sol += (1 << lg);
       }
     }
     cout << sol + 1 << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 #pragma comment(linker, '/STACK:255000000')
 bool firstout = 1;
 template <class T>
 T &minn(T &a, T b) {
   if (b < a) a = b;
   return a;
 }
 template <class T>
 T &maxx(T &a, T b) {
   if (a < b) a = b;
   return a;
 }
 int &madd(int &a, int b) {
   a += b;
   if (a >= 1000000009) a -= 1000000009;
   return a;
 }
 int &msub(int &a, int b) {
   a -= b;
   if (a < 0) a += 1000000009;
   return a;
 }
 int &mmult(int &a, int b) { return a = (long long)a * b % 1000000009; }
 int mdiv(long long a, long long b, long long m) {
   a = (a % m + m) % m;
   b = (b % m + m) % m;
   if (a % b == 0) return a / b;
   return (a + m * mdiv(-a, m, b)) / b;
 }
 int n, m;
 int A[201234];
 int B[201234];
 int R[201234];
 int RR[201234];
 int P[201234];
 vector<int> O[201234];
 vector<int> OO[201234];
 void fnd(int *R) {
   int i, j, k;
   for (i = (0); i < (n); ++i) P[B[i]] = i;
   for (i = (0); i < (2 * n); ++i) OO[i].clear(), O[i].clear();
   for (i = (0); i < (n); ++i) {
     j = P[A[i]];
     j = (i - j + n) % n;
     O[j].push_back(-j);
     OO[j + n - i].push_back(-j);
   }
   for (i = (0); i < (n); ++i) R[i] = 1012345678;
   multiset<int> s;
   s.clear();
   for (i = (0); i < (2 * n); ++i) {
     for (k = (0); k < (O[i].size()); ++k) s.insert(O[i][k]);
     for (k = (0); k < (OO[i].size()); ++k) s.erase(s.find(OO[i][k]));
     if (s.size()) minn(R[i % n], *s.begin() + i);
   }
 }
 int main() {
   int i, j, k;
   char c;
   int a, d;
   int ts;
   for (ts = 1; scanf('%'
                      'd',
                      &(n)) > 0;
        ++ts) {
     for (i = (0); i < (n); ++i)
       scanf(
           '%'
           'd',
           &(A[i])),
           --A[i];
     for (i = (0); i < (n); ++i)
       scanf(
           '%'
           'd',
           &(B[i])),
           --B[i];
     fnd(R);
     reverse(A, A + n);
     reverse(B, B + n);
     fnd(RR);
     int res = 0;
     for (i = (0); i < (n); ++i)
       printf(
           '%'
           'd',
           (min(RR[i], R[(n - i) % n]))),
           printf('
'), firstout = 1;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 map<double, int> a;
 double b[200007];
 inline long long int read() {
   long long int x = 0, f = 1;
   char ch = getchar();
   while (ch < '0' || ch > '9') {
     if (ch == '-') f = -1;
     ch = getchar();
   }
   while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
   return x * f;
 }
 inline void writ(int x) {
   if (x < 0) putchar('-'), x = -x;
   if (x > 9) writ(x / 10);
   putchar(x % 10 + '0');
 }
 inline void write(int x) {
   writ(x);
   putchar(' ');
 }
 int main() {
   a.clear();
   int n = read(), x, y, z;
   for (int i = 1; i <= n; ++i)
     x = read(), y = read(), z = read(), b[i] = (double)(x + y) / z, ++a[b[i]];
   for (int i = 1; i <= n; ++i) write(a[b[i]]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bitset<4001> g[4001];
 int main() {
   int n, m;
   cin >> n >> m;
   vector<pair<int, int> > v;
   for (int i = 0; i < m; i++) {
     int a, b;
     cin >> a >> b;
     a--;
     b--;
     g[a][b] = 1;
     g[b][a] = 1;
     v.push_back(pair<int, int>(a, b));
   }
   int minx = 100000000;
   bool was = 0;
   for (int i = 0; i < v.size(); i++) {
     int a = v[i].first;
     int b = v[i].second;
     for (int j = 0; j < n; j++) {
       if (g[a][j] && g[b][j]) {
         minx = min(minx, (int)(g[a].count() + g[b].count() + g[j].count()) - 6);
         was = true;
       }
     }
   }
   if (was)
     cout << minx;
   else
     cout << -1;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long mod = 1e9 + 7;
 const int N = 1e5 + 4;
 const long long MOD = 998244353;
 bool ans[2 * N];
 long long POW(long long base, long long exponent) {
   long long result = 1;
   while (exponent > 0) {
     if (exponent % 2 == 1) result = (result * base) % MOD;
     exponent = exponent >> 1;
     base = (base * base) % MOD;
   }
   return result;
 }
 long long Inv(long long x) { return POW(x, MOD - 2); }
 void BFS(int s, vector<int> &d, vector<int> edge[]) {
   d[s] = 0;
   queue<int> q;
   q.push(s);
   while (!q.empty()) {
     int v = q.front();
     q.pop();
     for (auto to : edge[v]) {
       if (d[to] == (int)1e9) {
         d[to] = d[v] + 1;
         q.push(to);
       }
     }
   }
 }
 int main() {
   std::ios::sync_with_stdio(false);
   cin.tie(0);
   int t;
   cin >> t;
   while (t--) {
     int n;
     cin >> n;
     int a[n];
     for (int i = 0; i < n; i++) cin >> a[i];
     int l = 0, r = n - 1, ls = 0, rs = 0, al = 0, b = 0, mv = 0;
     while (l <= r) {
       if (mv & 1) {
         rs = 0;
         while (rs <= ls and r >= l) rs += a[r--];
         b += rs;
         mv++;
       } else {
         ls = 0;
         while (ls <= rs and l <= r) ls += a[l++];
         al += ls;
         mv++;
       }
     }
     cout << mv << ' ' << al << ' ' << b << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int dis[75][1 << 18];
 bool mark[75][1 << 18];
 int n, m, A, B;
 vector<pair<int, int> > ve[75];
 struct zzt {
   pair<int, int> to;
   int di;
 };
 bool operator<(zzt aa, zzt bb) { return aa.di > bb.di; }
 priority_queue<zzt> q;
 int fa[75];
 int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }
 int sz[75];
 void merge(int x, int y) {
   x = gf(x);
   y = gf(y);
   if (x != y) fa[x] = y, sz[y] += sz[x];
 }
 int mk[75], mkid;
 int ozt(int x) { return mk[x] ? (1 << (mk[x] - 1)) : 0; }
 int main() {
   scanf('%d%d%d%d', &n, &m, &A, &B);
   for (int i = 1; i <= n; i++) fa[i] = i, sz[i] = 1;
   for (int i = 1; i <= m; i++) {
     int x, y, z;
     scanf('%d%d%d', &x, &y, &z);
     ve[x].push_back(pair<int, int>(y, z));
     ve[y].push_back(pair<int, int>(x, z));
     if (z == A) merge(x, y);
   }
   mkid = 0;
   for (int i = 1; i <= n; i++) {
     if ((!mk[i]) && sz[gf(i)] > 3) {
       ++mkid;
       for (int j = i; j <= n; j++) {
         if (gf(j) == gf(i)) mk[j] = mkid;
       }
     }
   }
   q.push((zzt){pair<int, int>(1, ozt(1)), 0});
   memset(dis, 0x3f, sizeof dis);
   dis[1][ozt(1)] = 0;
   while (q.size()) {
     int x = q.top().to.first;
     int zt = q.top().to.second;
     q.pop();
     if (mark[x][zt]) continue;
     mark[x][zt] = 1;
     for (auto p : ve[x]) {
       int y = p.first;
       int le = p.second;
       if (le == A) {
         if (dis[y][zt] > dis[x][zt] + le) {
           dis[y][zt] = dis[x][zt] + le;
           q.push((zzt){pair<int, int>(y, zt), dis[y][zt]});
         }
       } else if (gf(y) != gf(x) && (ozt(y) & zt) == 0) {
         if (dis[y][zt | ozt(y)] > dis[x][zt] + le) {
           dis[y][zt | ozt(y)] = dis[x][zt] + le;
           q.push((zzt){pair<int, int>(y, zt | ozt(y)), dis[y][zt | ozt(y)]});
         }
       }
     }
   }
   for (int i = 1; i <= n; i++) {
     int ans = 0x3f3f3f3f;
     for (int j = 0; j <= (1 << mkid) - 1; j++) {
       ans = min(ans, dis[i][j]);
     }
     cout << ans << ' ';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long i, j, k, l, m, n, t, x, y;
   cin >> n;
   if (n % 2 == 0)
     cout << n + 4 << ' ' << 4 << endl;
   else
     cout << n + 9 << ' ' << 9 << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline bool is_prime(int n) {
   for (int i = 2; i * i <= n; ++i)
     if (n % i == 0) return 0;
   return 1;
 }
 inline int Exp(int a, int p, int mod) {
   int res = 1;
   while (p) {
     if (p & 1) res = (long long)res * a % mod;
     p >>= 1;
     a = (long long)a * a % mod;
   }
   return res;
 }
 inline int get_root(int n) {
   for (int i = 2; i < n; ++i) {
     if (Exp(i, n - 1, n) != 1) continue;
     bool ok = 1;
     for (int j = 1; j < n - 1; ++j)
       if (Exp(i, j, n) == 1) {
         ok = 0;
         break;
       }
     if (ok) return i;
   }
   return -1;
 }
 int main() {
   int n;
   scanf('%d', &n);
   if (n == 1) {
     puts('YES');
     puts('1');
     return 0;
   }
   if (n == 4) {
     puts('YES');
     puts('1');
     puts('3');
     puts('2');
     puts('4');
     return 0;
   }
   if (n == 2) {
     puts('YES');
     puts('1 2');
     return 0;
   }
   if (is_prime(n)) {
     puts('YES');
     int g = get_root(n);
     printf('%d
', Exp(g, n - 1, n));
     for (int i = 1; i <= n - 2; ++i) {
       if (i & 1)
         printf('%d
', Exp(g, i, n));
       else
         printf('%d
', Exp(g, n - 1 - i, n));
     }
     printf('%d
', n);
   } else
     puts('NO');
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 char str[105];
 int main() {
   int n;
   scanf('%d', &n);
   scanf('%s', str);
   vector<int> g;
   int sum = 0;
   for (int i = 0; i < n; i++) {
     if (str[i] == 'B') {
       sum++;
     } else {
       if (sum) g.push_back(sum);
       sum = 0;
     }
   }
   if (sum) g.push_back(sum);
   printf('%d
', g.size());
   for (int i = 0; i < g.size(); i++) {
     printf('%d ', g[i]);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int T;
   scanf('%d', &T);
   while (T--) {
     long long s, n, k;
     scanf('%lld%lld%lld', &s, &n, &k);
     if (s < k)
       printf('NO
');
     else if (s == k)
       printf('YES
');
     else {
       long long left_sum = s - n;
       long long extra_sum = (n / k) * k;
       if (left_sum < extra_sum)
         printf('YES
');
       else
         printf('NO
');
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 long long gcd(long long a, long long b) {
   if (a == 0 || b == 0) return (a + b);
   if (a > b) return (gcd(a % b, b));
   return (gcd(a, b % a));
 }
 long long lcm(long long a, long long b) { return ((a * b / gcd(a, b))); }
 int sqr(int x) { return (x * x); }
 void out() {
   puts('NO');
   exit(0);
 }
 using namespace std;
 int n;
 int p[100008];
 int main() {
   cin >> n;
   for (int i = (int)(1); i < (int)(n + 1); ++i) p[i] = i;
   if (n % 2 == 1) {
     cout << '-1
';
     return 0;
   }
   for (int i = (int)(1); i < (int)(n + 1); ++i) {
     swap(p[i], p[i + 1]);
     i++;
   }
   for (int i = (int)(n); i >= (int)(1); --i) cout << i << ' ';
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, m, min, max, i, t, f = 0;
   cin >> n >> m;
   cin >> min;
   max = min;
   for (i = 1; i < n; i++) {
     cin >> t;
     if (t > max)
       max = t;
     else if (t < min)
       min = t;
   }
   if (2 * min > max) max = 2 * min;
   for (i = 0; i < m; i++) {
     cin >> t;
     if (t <= max) f = 1;
   }
   if (f == 1)
     cout << '-1
';
   else
     cout << max << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 inline void read(T& x) {
   char c = getchar();
   bool f = false;
   for (x = 0; !isdigit(c); c = getchar()) {
     if (c == '-') {
       f = true;
     }
   }
   for (; isdigit(c); c = getchar()) {
     x = x * 10 + c - '0';
   }
   if (f) {
     x = -x;
   }
 }
 template <typename T, typename... U>
 inline void read(T& x, U&... y) {
   read(x), read(y...);
 }
 const int N = 5e1 + 10;
 const double eps = 1e-6;
 int n;
 int ID[N];
 double K;
 double A[N], B[N], F[N][N];
 double V(int a) { return A[a] - K * B[a]; }
 bool cmp(int a, int b) { return A[a] == A[b] ? V(a) > V(b) : A[a] > A[b]; }
 int main() {
   read(n);
   for (int i = 1; i <= n; ++i) scanf('%lf', &A[i]);
   for (int i = 1; i <= n; ++i) scanf('%lf', &B[i]), ID[i] = i;
   double L = 0.01, R = 5e9, res = 233;
   while (R - L >= eps) {
     double mid = (L + R) / 2.0;
     K = mid;
     sort(ID + 1, ID + n + 1, cmp);
     for (int i = 0; i <= n; ++i)
       for (int j = 0; j <= n; ++j) F[i][j] = 1e18;
     F[0][0] = 0;
     int cnt = 0;
     for (int i = 1; i <= n; ++i) {
       ++cnt;
       double sum = V(ID[i]);
       int p = i;
       while (p != n && A[ID[p + 1]] == A[ID[i]]) sum += V(ID[++p]);
       double g = 0;
       int s = p - i + 1;
       for (int j = 0; j <= s; ++j) {
         if (j) g += V(ID[i + j - 1]);
         for (int k = 0; k <= i - 1; ++k)
           if (j <= k) {
             F[cnt][k - j + s - j] =
                 min(F[cnt][k - j + s - j], F[cnt - 1][k] + sum - g);
           }
       }
       i = p;
     }
     double ANS = 1e18;
     for (int i = 0; i <= n; ++i) ANS = min(ANS, F[cnt][i]);
     if (ANS <= eps)
       res = mid, R = mid - eps;
     else
       L = mid + eps;
   }
   printf('%lld
', (long long)(res * 100000 + 99) / 100);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int Maxn = 200005;
 struct M {
   int val, pos;
 };
 M a[Maxn], b[Maxn];
 int idx[Maxn], idy[Maxn], Nx[Maxn], Ny[Maxn];
 int read() {
   int sum = 0, t = 1;
   char c = getchar();
   while (c < '0' || c > '9') {
     if (c == '-') t = -1;
     c = getchar();
   }
   while (c >= '0' && c <= '9') {
     sum = sum * 10 + c - '0';
     c = getchar();
   }
   return sum * t;
 }
 bool cmp(M x, M y) {
   return (x.val < y.val || (x.val == y.val && b[x.pos].val < b[y.pos].val));
 }
 long long C2(long long x) { return 1ll * x * (x - 1) / 2; }
 int main() {
   int n;
   scanf('%d', &n);
   for (int i = 1; i <= n; ++i) {
     a[i].val = read(), b[i].val = read();
     a[i].pos = b[i].pos = i;
   }
   sort(a + 1, a + n + 1, cmp);
   int cnt = 0, same = 1;
   long long res = 0;
   a[0].val = b[0].val = -0x3f3f3f3f;
   cnt = 0;
   for (int i = 1; i <= n; ++i) {
     if (a[i].val != a[i - 1].val)
       cnt++, res += C2(same), same = 1;
     else {
       if (b[a[i].pos].val == b[a[i - 1].pos].val)
         same++;
       else
         res += C2(same), same = 1;
     }
     idx[a[i].pos] = cnt;
   }
   res += C2(same);
   sort(b + 1, b + n + 1, cmp);
   cnt = 0;
   for (int i = 1; i <= n; ++i) {
     if (b[i].val != b[i - 1].val) cnt++;
     idy[b[i].pos] = cnt;
   }
   for (int i = 1; i <= n; ++i) {
     Nx[idx[i]]++;
     Ny[idy[i]]++;
   }
   long long ans = 0;
   for (int i = 1; i <= n; ++i) {
     ans += C2(Nx[i]) + C2(Ny[i]);
   }
   ans -= res;
   printf('%lld', ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m, k, i, dis = 10000000, temp, a[1000];
 int main() {
   cin >> n >> m >> k;
   for (i = 0; i < n; ++i) cin >> a[i];
   for (i = 0; i < n; ++i) {
     if (a[i] != 0 && a[i] <= k) {
       if (m <= i)
         temp = (i - m + 1) * 10;
       else
         temp = (m - i - 1) * 10;
       if (dis > temp) dis = temp;
     }
   }
   cout << dis;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long k, m = 9, x;
   long long r = 1, n, j, d = 0;
   cin >> k;
   while (k - m * r > 0) {
     k -= m * r;
     ++r;
     m = m * 10;
   }
   n = (k - 1) / r;
   j = (k - 1) % r;
   x = pow(10, r - 1) + n;
   for (long i = 0; i < r - j - 1; ++i) x /= 10;
   d = x % 10;
   cout << d << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, count1 = 0, count2 = 0, sum = 0;
   scanf('%d', &n);
   vector<pair<int, int> > v1;
   vector<pair<int, int> > v2;
   for (int i = 0; i < n; i++) {
     int x, a;
     scanf('%d %d', &x, &a);
     if (x < 0) {
       v1.push_back(make_pair(x, a));
       count1++;
     } else {
       v2.push_back(make_pair(x, a));
       count2++;
     }
   }
   sort(v1.begin(), v1.end());
   reverse(v1.begin(), v1.end());
   sort(v2.begin(), v2.end());
   vector<pair<int, int> >::iterator it1 = v1.begin();
   vector<pair<int, int> >::iterator it2 = v2.begin();
   vector<pair<int, int> >::iterator it3 = v1.end();
   vector<pair<int, int> >::iterator it4 = v2.end();
   if (count1 > count2) {
     while (it1 != v1.end()) {
       sum += it1->second;
       it1++;
       if (it2 != v2.end()) {
         sum += it2->second;
         it2++;
       } else
         break;
     }
   } else if (count1 < count2) {
     while (it2 != v2.end()) {
       sum += it2->second;
       it2++;
       if (it1 != v1.end()) {
         sum += it1->second;
         it1++;
       } else
         break;
     }
   } else if (count1 == count2) {
     if ((it3->second) > (it4->second)) {
       while (it1 != v1.end()) {
         sum += it1->second;
         it1++;
         sum += it2->second;
         it2++;
       }
     } else {
       while (it2 != v2.end()) {
         sum += it2->second;
         it2++;
         sum += it1->second;
         it1++;
       }
     }
   }
   printf('%d
', sum);
 }


#include <bits/stdc++.h>
 using namespace std;
 inline int read() {
   int x = 0, f = 1;
   char c = getchar();
   while (c < '0' || c > '9') {
     if (c == '-') f = -1;
     c = getchar();
   }
   while (c >= '0' && c <= '9') {
     x = (x << 3) + (x << 1) + c - '0';
     c = getchar();
   }
   return x * f;
 }
 const int MAX_N = 1e3 + 10;
 int H[MAX_N][MAX_N], CM[MAX_N][MAX_N], TM[MAX_N][MAX_N], N, M, A, B, SUM = 0;
 long long S[MAX_N][MAX_N];
 bool vis[MAX_N][MAX_N];
 vector<pair<long long, pair<int, int> > > V, Ans;
 struct MY_QUEUE {
   deque<pair<int, int> > Q;
   inline void reset() { Q.clear(); }
   inline void push(int val, int mark) {
     pair<int, int> now = make_pair(val, mark);
     while (Q.size() && Q.back().first > val) Q.pop_back();
     Q.push_back(make_pair(val, mark));
   }
   inline void pop(int mark) {
     if (Q.front().second == mark) Q.pop_front();
   }
   inline int get() { return Q.front().first; }
 };
 inline bool check_X(int x) { return x >= 0 && x < N; }
 inline bool check_Y(int y) { return y >= 0 && y < M; }
 signed main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   N = read();
   M = read();
   A = read();
   B = read();
   for (int i = 0; i < N; i++)
     for (int j = 0; j < M; j++) H[i][j] = read();
   for (int i = 0; i < M; i++) {
     MY_QUEUE QUEUE;
     for (int j = 0; j < N; j++) {
       QUEUE.push(H[j][i], j);
       if (j >= A) QUEUE.pop(j - A);
       if (j >= A - 1) CM[j - A + 1][i] = QUEUE.get();
     }
   }
   for (int i = 0; i < N; i++) {
     MY_QUEUE QUEUE;
     for (int j = 0; j < M; j++) {
       QUEUE.push(CM[i][j], j);
       if (j >= B) QUEUE.pop(j - B);
       if (j >= B - 1) TM[i][j - B + 1] = QUEUE.get();
     }
   }
   for (int i = 1; i <= N; i++)
     for (int j = 1; j <= M; j++)
       S[i][j] = (long long)S[i][j] + S[i][j - 1] + H[i - 1][j - 1];
   for (int i = 1; i <= M; i++)
     for (int j = 1; j <= N; j++) S[j][i] = (long long)S[j][i] + S[j - 1][i];
   for (int i = 0; i <= N - A; i++)
     for (int j = 0; j <= M - B; j++) {
       long long sum = (long long)S[i + A][j + B] - S[i + A][j] - S[i][j + B] +
                       S[i][j],
                 dec = (long long)TM[i][j] * A * B;
       V.push_back(make_pair(sum - dec, make_pair(i, j)));
     }
   sort(V.begin(), V.end());
   for (int i = 0; i < V.size(); i++) {
     long long val = V[i].first;
     int X = V[i].second.first, Y = V[i].second.second;
     if (vis[X][Y]) continue;
     SUM++;
     Ans.push_back(make_pair(val, make_pair(X + 1, Y + 1)));
     for (int i = X - A + 1; i <= X + A - 1; i++)
       for (int j = Y - B + 1; j <= Y + B - 1; j++)
         if (check_X(i) && check_Y(j)) vis[i][j] = 1;
   }
   printf('%d
', SUM);
   for (int i = 0; i < Ans.size(); i++)
     printf('%d %d %I64d
', Ans[i].second.first, Ans[i].second.second,
            Ans[i].first);
   return 0;
 }


#include <bits/stdc++.h>
 #pragma comment(linker, '/STACK:1024000000,1024000000')
 using namespace std;
 const int maxm = 100005 * 2;
 const int maxn = 100005;
 const int mod = 1000000007;
 struct Edge {
   int v, next;
 } E[maxm];
 struct sw {
   int v, next;
 } EE[maxm];
 int head[maxn], ind;
 int headd[maxn], indd;
 int dfs[maxn], low[maxn], clo;
 int bri, cou, S[maxn], hi;
 int n, m;
 int f[maxn], have[maxn];
 void add(int u, int v) {
   E[ind].v = v, E[ind].next = head[u], head[u] = ind++;
   E[ind].v = u, E[ind].next = head[v], head[v] = ind++;
 }
 void add1(int u, int v) {
   EE[indd].v = v, EE[indd].next = headd[u], headd[u] = indd++;
   EE[indd].v = u, EE[indd].next = headd[v], headd[v] = indd++;
 }
 void init() {
   memset(head, -1, sizeof(head));
   memset(headd, -1, sizeof(headd));
   memset(dfs, -1, sizeof(dfs));
   memset(low, -1, sizeof(low));
   clo = ind = indd = 0;
 }
 vector<int> vvv[maxn];
 void tarjan(int u, int id) {
   dfs[u] = low[u] = clo++;
   S[hi++] = u;
   for (int i = head[u]; ~i; i = E[i].next) {
     if (i == (id ^ 1)) continue;
     int v = E[i].v;
     if (dfs[v] == -1) {
       tarjan(v, i);
       low[u] = min(low[u], low[v]);
       if (dfs[u] < low[v]) {
         bri++;
         vvv[u].push_back(v);
       }
     } else
       low[u] = min(low[u], dfs[v]);
   }
   if (dfs[u] == low[u]) {
     int v;
     do {
       v = S[--hi];
       f[v] = u;
       for (int j = 0; j < vvv[v].size(); j++) {
         int pa = f[vvv[v][j]];
         add1(u, pa);
       }
       have[u]++;
     } while (u != v);
   }
 }
 void work() {
   hi = 0;
   for (int i = 1; i <= n; i++)
     if (dfs[i] == -1) {
       tarjan(i, -1);
     }
 }
 int ff[maxn][18], lev;
 int dep[maxn];
 long long dis[maxn];
 int LCA(int x, int y) {
   if (dep[x] > dep[y]) x = x ^ y, y = x ^ y, x = x ^ y;
   for (int i = lev; i >= 0; i--)
     if (dep[y] - dep[x] >> i & 1) y = ff[y][i];
   if (x == y) return x;
   for (int i = lev; i >= 0; i--)
     if (ff[x][i] != ff[y][i]) x = ff[x][i], y = ff[y][i];
   return ff[x][0];
 }
 void done(int u, int p) {
   dep[u] = dep[p] + 1;
   if (have[u] > 1)
     dis[u] = dis[p] * 2 % mod;
   else
     dis[u] = dis[p];
   ff[u][0] = p;
   int v;
   for (int i = headd[u]; ~i; i = EE[i].next) {
     v = EE[i].v;
     if (v != p) {
       done(v, u);
     }
   }
 }
 void initLca() {
   dis[0] = 1;
   done(1, 0);
   lev = 1;
   for (; (1 << lev) <= n; lev++)
     for (int i = 0; i <= n; i++)
       if (f[i] == i) ff[i][lev] = ff[ff[i][lev - 1]][lev - 1];
   lev--;
 }
 long long extend_gcd(long long a, long long b, long long &x, long long &y) {
   if (b == 0) {
     x = 1, y = 0;
     return a;
   }
   long long gcd = extend_gcd(b, a % b, x, y);
   long long t = x;
   x = y;
   y = t - a / b * x;
   return gcd;
 }
 long long Get_Inverse(long long num) {
   long long x, y;
   extend_gcd(num, 1000000007, x, y);
   return (x % 1000000007 + 1000000007) % 1000000007;
 }
 int main(void) {
   while (~scanf('%d%d', &n, &m)) {
     init();
     while (m--) {
       int u, v;
       scanf('%d%d', &u, &v);
       add(u, v);
     }
     work();
     initLca();
     int k, a, b, fa, fb, pa;
     scanf('%d', &k);
     for (int i = 0; i < k; i++) {
       scanf('%d%d', &a, &b);
       fa = f[a];
       fb = f[b];
       long long ans = dis[fa] * dis[fb] % mod;
       pa = LCA(fa, fb);
       int need = (have[pa] > 1 ? 2 : 1);
       ans = ans * Get_Inverse(dis[pa]) % mod;
       ans = ans * (Get_Inverse(dis[pa] * Get_Inverse(need) % mod)) % mod;
       printf('%I64d
', ans);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int x, a, b, i, j, k, siz, cnt = 0, p, q, s, t, z, h, po;
   string str;
   cin >> str;
   cin >> x;
   siz = str.size();
   for (i = 0; i < siz; i++) {
     if (str[i] != '*' && str[i] != '?') cnt++;
   }
   p = siz - cnt;
   q = cnt - p;
   if (x < q)
     cout << 'Impossible' << endl;
   else if (x >= q && x <= cnt) {
     s = 0;
     t = cnt - x;
     for (i = 0; i < siz; i++) {
       if (s < t && (str[i + 1] == '?' || str[i + 1] == '*')) {
         s++;
       } else {
         if (str[i] >= 'a' && str[i] <= 'z') cout << str[i];
       }
     }
   } else {
     z = x - cnt;
     h = 0;
     for (i = 0; i < siz; i++) {
       if (str[i] == '*') {
         h++;
         po = i;
         break;
       }
     }
     if (h == 0)
       cout << 'Impossible' << endl;
     else {
       for (i = 0; i < siz; i++) {
         if (i == po) {
           for (j = 1; j <= z; j++) {
             cout << str[i - 1];
           }
         } else {
           if (str[i] >= 'a' && str[i] <= 'z') {
             cout << str[i];
           }
         }
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize('Ofast')
 #pragma GCC optimize('unroll-loops')
 #pragma GCC target('sse,sse2,sse3,ssse3,abm,mmx,tune=native')
 using namespace std;
 long long gcd(long long i, long long j) {
   if (j == 0)
     return i;
   else
     return gcd(j, i % j);
 }
 template <typename T>
 inline T getint() {
   T val = 0;
   char c;
   bool neg = false;
   while ((c = getchar()) && !(c >= '0' && c <= '9')) {
     neg |= c == '-';
   }
   do {
     val = (val * 10) + c - '0';
   } while ((c = getchar()) && (c >= '0' && c <= '9'));
   return val * (neg ? -1 : 1);
 }
 const long long INF = 1e9 + 100;
 const int mod = 1000000007;
 const long double eps = 1e-10, pi = acosl(-1);
 const long long maxN = 300010, maxT = 10010, A = 179, mid = 150;
 mt19937 mt_rand(time(0));
 long long bp(long long et, long long b) {
   b %= mod - 1;
   long long res = 1;
   for (int i = 30; i >= 0; --i) {
     res = (res * res) % mod;
     if ((b & (1 << i)) != 0) res = (res * et) % mod;
   }
   return res;
 }
 void panic() {
   cout << '-1
';
   exit(0);
 }
 const int byben_size = 23;
 vector<int> merge(const vector<int>& a, const vector<int>& b,
                   bool want_mx = true) {
   int s1 = a.size(), s2 = b.size();
   int sz = min(s1 + s2, byben_size);
   vector<int> r(sz);
   if (!want_mx) {
     int y1 = 0, y2 = 0;
     int y = 0;
     while (y < sz && y1 < s1 && y2 < s2) {
       if (a[y1] < b[y2])
         r[y++] = a[y1++];
       else
         r[y++] = b[y2++];
     }
     while (y < sz && y1 < s1) r[y++] = a[y1++];
     while (y < sz && y2 < s2) r[y++] = b[y2++];
   } else {
     int y1 = s1 - 1, y2 = s2 - 1;
     int y = sz - 1;
     while (y >= 0 && y1 >= 0 && y2 >= 0) {
       if (a[y1] > b[y2])
         r[y--] = a[y1--];
       else
         r[y--] = b[y2--];
     }
     while (y >= 0 && y1 >= 0) r[y--] = a[y1--];
     while (y >= 0 && y2 >= 0) r[y--] = b[y2--];
   }
   return r;
 }
 vector<int> t[1 << 18];
 int sz = 1 << 17;
 int a[maxN];
 vector<int> l1[maxN], r1[maxN];
 inline void add(int l, int r, int id, bool want_mx) {
   for (l += sz, r += sz; l <= r; l >>= 1, r >>= 1) {
     if (l & 1) {
       int v = l++;
       t[v].push_back(id);
       int szz = t[v].size();
       int rr = szz;
       --szz;
       while (szz > 0 && t[v][szz] < t[v][szz - 1]) {
         swap(t[v][szz], t[v][szz - 1]);
         --szz;
       }
       if (rr > byben_size) {
         if (want_mx)
           t[v].erase(t[v].begin());
         else
           t[v].pop_back();
       }
     }
     if (~r & 1) {
       int v = r--;
       t[v].push_back(id);
       int szz = t[v].size();
       int rr = szz;
       --szz;
       while (szz > 0 && t[v][szz] < t[v][szz - 1]) {
         swap(t[v][szz], t[v][szz - 1]);
         --szz;
       }
       if (rr > byben_size) {
         if (want_mx)
           t[v].erase(t[v].begin());
         else
           t[v].pop_back();
       }
     }
   }
 }
 vector<int> get(int v, bool want_mx) {
   vector<int> r;
   v |= sz;
   for (v = v | sz; v; v >>= 1) {
     r = merge(t[v], r, want_mx);
   }
   return r;
 }
 long double pw[maxT];
 void solve() {
   pw[0] = 1;
   for (int i = 1; i < maxT; ++i) pw[i] = pw[i - 1] * 2;
   int n = getint<int>();
   for (int i = 1; i <= n; ++i) {
     a[i] = getint<int>();
   }
   add(0, sz - 1, 0, 1);
   for (int i = 1; i <= n; ++i) {
     add(0, a[i], i, 1);
     l1[i] = get(a[i], 1);
   }
   for (int i = 0; i < 2 * sz; ++i) t[i].clear();
   add(0, sz - 1, n + 1, 0);
   for (int i = n; i > 0; --i) {
     add(0, a[i], i, 0);
     r1[i] = merge({i}, get(a[i] + 1, 0), 0);
   }
   long double ans = 0;
   for (int i = 1; i <= n; ++i) {
     for (int j = 1; j < l1[i].size(); ++j) {
       for (int k = 0; k + 1 < r1[i].size(); ++k) {
         long long cnt =
             (long long)(l1[i][j] - l1[i][j - 1]) * (r1[i][k + 1] - r1[i][k]);
         int pww = k + l1[i].size() - j;
         if (pww > byben_size) break;
         ans += (long double)cnt / pw[pww] * a[i];
       }
     }
   }
   cout << fixed << ans / n / n << '
';
 }
 int32_t main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   cout.precision(20);
   int t = 1;
   while (t--) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int max_n = 303333, inf = 1000111222;
 int n, x, y;
 pair<int, int> a[max_n];
 void wa() {
   printf('No
');
   exit(0);
 }
 int main() {
   scanf('%d%d%d', &n, &x, &y);
   for (int i = 0; i < n; ++i) {
     scanf('%d', &a[i].first);
     a[i].second = i + 1;
   }
   sort(a, a + n);
   int last = -1;
   for (int i = n - 1; i >= 0; --i) {
     if (1LL * a[i].first * (n - i) >= y) {
       last = i;
       break;
     }
   }
   if (last == -1) {
     wa();
   }
   for (int i = 0; i < n; ++i) {
     int need = (x + a[i].first - 1) / a[i].first;
     if (i + need <= last) {
       printf('Yes
');
       printf('%d %d
', need, n - last);
       for (int j = i; j < i + need; ++j) {
         printf('%d ', a[j].second);
       }
       printf('
');
       for (int j = last; j < n; ++j) {
         printf('%d ', a[j].second);
       }
       printf('
');
       return 0;
     }
   }
   swap(x, y);
   last = -1;
   for (int i = n - 1; i >= 0; --i) {
     if (1LL * a[i].first * (n - i) >= y) {
       last = i;
       break;
     }
   }
   if (last == -1) {
     wa();
   }
   for (int i = 0; i < n; ++i) {
     int need = (x + a[i].first - 1) / a[i].first;
     if (i + need <= last) {
       printf('Yes
');
       printf('%d %d
', n - last, need);
       for (int j = last; j < n; ++j) {
         printf('%d ', a[j].second);
       }
       printf('
');
       for (int j = i; j < i + need; ++j) {
         printf('%d ', a[j].second);
       }
       printf('
');
       return 0;
     }
   }
   wa();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void prime(long long int n, set<long long int> &s) {
   if (n % 2 == 0) {
     s.insert(2);
     n /= 2;
   }
   while (n % 2 == 0) {
     n /= 2;
   }
   for (int i = 3; i <= sqrt(n); i += 2) {
     if (n % i == 0) {
       s.insert(i);
       n /= i;
     }
     while (n % i == 0) {
       n /= i;
     }
   }
   if (n > 2) s.insert(n);
 }
 int main() {
   long long int n;
   cin >> n;
   set<long long int> s;
   prime(n, s);
   if (s.size() == 1)
     cout << *(s.begin()) << endl;
   else
     cout << 1 << endl;
   return (0);
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 inline T BigMod(T b, T p, T m) {
   if (p == 0) return 1;
   if (p % 2 == 0) {
     T s = BigMod(b, p / 2, m);
     return ((s % m) * (s % m)) % m;
   }
   return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
 }
 template <typename T>
 inline T ModInv(T b, T m) {
   return BigMod(b, m - 2, m);
 }
 template <typename T>
 inline T Bigmod(T b, T p, T m) {
   if (p == 0)
     return 1;
   else if (!(p & 1))
     return (Bigmod(b, p / 2, m) * Bigmod(b, p / 2, m)) % m;
   else
     return ((b % m) * Bigmod(b, p - 1, m)) % m;
 }
 template <typename T>
 inline T gcd(T a, T b) {
   if (b == 0) return a;
   return gcd(b, a % b);
 }
 template <typename T>
 inline T lcm(T a, T b) {
   if (a < 0) return lcm(-a, b);
   if (b < 0) return lcm(a, -b);
   return a * (b / gcd(a, b));
 }
 template <typename T>
 inline T euclide(T a, T b, T &x, T &y) {
   if (a < 0) {
     T d = euclide(-a, b, x, y);
     x = -x;
     return d;
   }
   if (b < 0) {
     T d = euclide(a, -b, x, y);
     y = -y;
     return d;
   }
   if (b == 0) {
     x = 1;
     y = 0;
     return a;
   } else {
     T d = euclide(b, a % b, x, y);
     T t = x;
     x = y;
     y = t - (a / b) * y;
     return d;
   }
 }
 template <typename T>
 inline T Dis(T x1, T y1, T x2, T y2) {
   return sqrt((((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))));
 }
 template <typename T>
 inline T Angle(T x1, T y1, T x2, T y2) {
   return atan(double(y1 - y2) / double(x1 - x2));
 }
 template <typename T>
 inline T DIFF(T a, T b) {
   T d = a - b;
   if (d < (T)0)
     return -d;
   else
     return d;
 }
 template <typename T>
 inline T ABS(T a) {
   if (a < 0)
     return -a;
   else
     return a;
 }
 template <typename T>
 inline long long isLeft(T a, T b, T c) {
   return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);
 }
 template <typename T>
 inline void _in(T &x) {
   register int c = getchar();
   x = 0;
   bool neg = 0;
   for (; ((c<48 | c> 57) && c != '-'); c = getchar())
     ;
   if (c == '-') {
     neg = 1;
     c = getchar();
   }
   for (; c > 47 && c < 58; c = getchar()) {
     x = (x << 1) + (x << 3) + c - 48;
   }
   if (neg) x = -x;
 }
 template <typename T>
 inline bool isLeapYear(T N) {
   if (N % 4)
     return 0;
   else if (N % 100)
     return 1;
   else if (N % 400)
     return 0;
   else
     return 1;
 }
 template <typename T>
 inline T Set(T N, T pos) {
   T A = 1;
   return N = N | (A << pos);
 }
 template <typename T>
 inline T Reset(T N, T pos) {
   T A = 1;
   return N = N & ~(A << pos);
 }
 template <typename T>
 inline bool Check(T N, T pos) {
   T A = 1;
   return (bool)(N & (A << pos));
 }
 template <class T, class X>
 inline T togglebit(T a, X i) {
   T t = 1;
   return (a ^ (t << i));
 }
 template <class T, class X>
 inline T toInt(T &sm, X s) {
   stringstream ss(s);
   ss >> sm;
   return sm;
 }
 template <typename T>
 inline int cdigittoint(T ch) {
   return ch - '0';
 }
 template <typename T>
 inline bool isVowel(T ch) {
   ch = toupper(ch);
   if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
     return true;
   return false;
 }
 template <typename T>
 inline bool isConst(T ch) {
   if (isalpha(ch) && !isVowel(ch)) return true;
   return false;
 }
 inline double DEG(double x) { return (180.0 * x) / (2 * acos(0.0)); }
 inline double RAD(double x) { return (x * (double)2 * acos(0.0)) / (180.0); }
 int main() {
   long long b1 = ({
     long long a;
     _in(a);
     a;
   }),
             q = ({
               long long a;
               _in(a);
               a;
             }),
             l = ({
               long long a;
               _in(a);
               a;
             }),
             m = ({
               long long a;
               _in(a);
               a;
             });
   map<long long, bool> A;
   for (long long i = 1; i <= m; i++)
     A[({
       long long a;
       _in(a);
       a;
     })] = true;
   if (abs(b1) > l) {
     printf('0
');
     return 0;
   }
   if (q == 0 || q == 1 || q == -1) {
     if (q == 0) {
       if (A[b1]) {
         if (A[0] == 0)
           printf('inf
');
         else
           printf('0
');
       } else {
         if (A[0] == 0)
           printf('inf
');
         else {
           if (abs(b1) <= l)
             printf('1
');
           else
             printf('0
');
         }
       }
     } else if (q == 1) {
       if (A[b1])
         printf('0
');
       else {
         if (abs(b1) <= l)
           printf('inf
');
         else
           printf('0
');
       }
     } else {
       if (A[-b1] == 1 && A[b1] == 1)
         printf('0
');
       else if (A[-b1] == 1 || A[b1] == 1) {
         if (abs(b1) <= l)
           printf('inf
');
         else
           printf('0
');
       } else {
         if (abs(b1) <= l)
           printf('inf
');
         else
           printf('0
');
       }
     }
   } else {
     if (b1 == 0) {
       if (A[b1] == 0)
         printf('inf
');
       else
         printf('0
');
       return 0;
     }
     long long count = 0;
     while (true) {
       if (A[b1] == 0 && abs(b1) <= l) count++;
       b1 *= q;
       if (abs(b1) > l) break;
     }
     printf('%lld
', count);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bitset<64> f1[3610], f2[3610];
 int n, m;
 map<int, vector<int>> mp1, mp2;
 int y[66], y2[66];
 set<int> s;
 vector<int> res;
 int main() {
   cin >> n >> m;
   for (int i = 1; i <= n; i++) cin >> y[i], y[i] *= 2, mp1[y[i]].push_back(i);
   for (int i = 1; i <= m; i++)
     cin >> y2[i], y2[i] *= 2, mp2[y2[i]].push_back(i);
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= m; j++) res.push_back((y[i] + y2[j]) / 2);
   sort(res.begin(), res.end());
   res.erase(unique(res.begin(), res.end()), res.end());
   for (int i = 0; i < res.size(); i++) {
     int k = res[i];
     for (int j = 1; j <= m; j++) {
       int d = 2 * k - y2[j];
       if (mp1[d].size())
         for (auto xx : mp1[d]) f1[i].set(xx, 1);
     }
   }
   for (int i = 0; i < res.size(); i++) {
     int k = res[i];
     for (int j = 1; j <= n; j++) {
       int d = 2 * k - y[j];
       if (mp2[d].size())
         for (auto xx : mp2[d]) f2[i].set(xx, 1);
     }
   }
   int ans = 0;
   for (int i = 0; i < res.size(); i++)
     for (int j = 0; j < res.size(); j++) {
       int tmp = (f1[i] | f1[j]).count() + (f2[i] | f2[j]).count();
       ans = max(ans, tmp);
     }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int t;
   cin >> t;
   while (t--) {
     long long int n, m, i, j, zero = 0, neg = 0, tot = 0, val = INT_MIN,
                               val2 = INT_MAX;
     cin >> n >> m;
     long long int b[n][m];
     for (i = 0; i < n; i++) {
       for (j = 0; j < m; j++) {
         cin >> b[i][j];
         if (b[i][j] < 0) {
           neg++;
           if (neg == 1)
             val = b[i][j];
           else if (val < b[i][j])
             val = b[i][j];
         } else if (b[i][j] == 0)
           zero++;
         else
           val2 = min(val2, b[i][j]);
         tot += abs(b[i][j]);
       }
     }
     if (neg % 2 == 0 || zero != 0)
       cout << tot << endl;
     else {
       cout << tot + 2 * max(val, -val2) << endl;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 50 + 5;
 int n, dp[N][N][N][N];
 char g[N][N];
 int dfs(int x, int y, int h, int w) {
   if (dp[x][y][h][w] != -1) return dp[x][y][h][w];
   if (h == 1 && w == 1) return dp[x][y][h][w] = g[x][y] == '#';
   if (h == 0 || w == 0) return dp[x][y][h][w] = 0;
   dp[x][y][h][w] = max(h, w);
   for (int i = 0; i <= h; ++i) {
     dp[x][y][h][w] =
         min(dp[x][y][h][w], dfs(x, y, i, w) + dfs(x + i, y, h - i, w));
   }
   for (int j = 0; j <= w; ++j) {
     dp[x][y][h][w] =
         min(dp[x][y][h][w], dfs(x, y, h, j) + dfs(x, y + j, h, w - j));
   }
   return dp[x][y][h][w];
 }
 int main() {
   memset(dp, -1, sizeof(dp));
   cin >> n;
   for (int i = 1; i <= n; ++i) {
     for (int j = 1; j <= n; ++j) {
       cin >> g[i][j];
     }
   }
   printf('%d', dfs(1, 1, n, n));
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 100010;
 const int inf = 0x3f3f3f3f;
 int n, m;
 int mi[maxn], cnt[maxn];
 int main() {
   cin >> n >> m;
   memset(mi, 0x3f, sizeof(mi));
   for (int i = 1; i <= m; i++) {
     int x, y;
     cin >> x >> y;
     mi[x] = min(mi[x], (y - x + n) % n);
     cnt[x]++;
   }
   for (int i = 1; i <= n; i++) {
     long long ans = 0;
     for (int j = 1; j <= n; j++)
       if (cnt[j])
         ans = max(ans, (j - i + n) % n + (long long)n * (cnt[j] - 1) + mi[j]);
     cout << ans << ' ';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 void pv(T a, T b) {
   for (T i = a; i != b; ++i) cout << *i << ' ';
   cout << endl;
 }
 template <class T>
 void chmin(T &t, const T &f) {
   if (t > f) t = f;
 }
 template <class T>
 void chmax(T &t, const T &f) {
   if (t < f) t = f;
 }
 int in() {
   int x;
   scanf('%d', &x);
   return x;
 }
 int N, M;
 int X[1000010], Y[1000010];
 int bitN;
 int bit[2100010];
 void bitAdd(int pos, int val) {
   for (int x = pos; x <= bitN; x += x & -x) bit[x] += val;
 }
 int bitLowerBound(int w) {
   if (w <= 0) return 0;
   int x = 0;
   for (int k = bitN; k > 0; k /= 2) {
     if (x + k <= bitN && bit[x + k] < w) {
       w -= bit[x + k];
       x += k;
     }
   }
   return x + 1;
 }
 int perm[1000010];
 int ids[2000010];
 bool used[1000010];
 bool solve() {
   for (bitN = 2; bitN < M + N + 5; bitN <<= 1)
     ;
   memset(bit, 0, sizeof(bit));
   memset(perm, ~0, sizeof(perm));
   memset(ids, ~0, sizeof(ids));
   for (int j = 1; j <= N; ++j) {
     bitAdd(M + j, +1);
     ids[M + j] = j;
   }
   for (int i = 0; i < M; ++i) {
     const int pos = bitLowerBound(Y[i]);
     const int j = ids[pos];
     if (!~perm[j]) {
       perm[j] = X[i];
     }
     if (perm[j] != X[i]) {
       return false;
     }
     bitAdd(pos, -1);
     bitAdd(M - i, +1);
     ids[pos] = -1;
     ids[M - i] = j;
   }
   memset(used, 0, sizeof(used));
   for (int j = 1; j <= N; ++j)
     if (~perm[j]) {
       if (used[perm[j]]) {
         return false;
       }
       used[perm[j]] = true;
     }
   int k = 1;
   for (int j = 1; j <= N; ++j)
     if (!~perm[j]) {
       for (; used[k]; ++k)
         ;
       perm[j] = k;
       used[k] = true;
     }
   return true;
 }
 int main() {
   for (; ~scanf('%d%d', &N, &M);) {
     for (int i = 0; i < M; ++i) {
       X[i] = in();
       Y[i] = in();
     }
     bool res = solve();
     if (res) {
       for (int j = 1; j <= N; ++j) {
         if (j > 1) printf(' ');
         printf('%d', perm[j]);
       }
       puts('');
     } else {
       puts('-1');
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MN = 70010;
 vector<int> vs[MN];
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int n;
   cin >> n;
   vector<string> vs(n);
   for (int i = 0; i < n; i++) cin >> vs[i];
   vector<string> ans(n);
   for (int len = 1; len < 10; len++) {
     map<string, set<int> > mapper;
     for (int i = 0; i < n; i++)
       for (int j = 0; j + len - 1 < 9; j++)
         mapper[vs[i].substr(j, len)].insert(i);
     for (auto &curr : mapper)
       if (((int)curr.second.size()) == 1) {
         int id = *curr.second.begin();
         if (ans[id] == '') ans[id] = curr.first;
       }
   }
   for (int i = 0; i < n; i++) cout << ans[i] << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 inline void remax(T& A, T B) {
   if (A < B) A = B;
 }
 template <class T>
 inline void remin(T& A, T B) {
   if (A > B) A = B;
 }
 string ToString(long long num) {
   string ret;
   do {
     ret += ((num % 10) + '0');
     num /= 10;
   } while (num);
   reverse(ret.begin(), ret.end());
   return ret;
 }
 long long ToNumber(string s) {
   long long r = 0, p = 1;
   for (int i = s.size() - 1; i >= 0; --i) r += (s[i] - '0') * p, p *= 10;
   return r;
 }
 long long Gcd(long long a, long long b) {
   while (a %= b ^= a ^= b ^= a)
     ;
   return b;
 }
 long long Power(long long base, long long power) {
   long long ret = 1;
   while (power) {
     if (power & 1) ret *= base;
     power >>= 1;
     base *= base;
   }
   return ret;
 }
 long long PowerMod(long long base, long long power, long long mod) {
   if (!power) return 1;
   if (power & 1) return (base * PowerMod(base, power - 1, mod)) % mod;
   return PowerMod((base * base) % mod, power >> 1, mod);
 }
 int Log(long long num, long long base) {
   int ret = 0;
   while (num) {
     ++ret;
     num /= base;
   }
   return ret;
 }
 int Count(long long mask) {
   int ret = 0;
   while (mask) {
     if (mask & 1) ++ret;
     mask >>= 1;
   }
   return ret;
 }
 inline void run() {
   int arr[2000];
   int n, b, ans;
   scanf('%d%d', &n, &b);
   for (int i = 0; i < n;) scanf('%d', arr + i++);
   ans = b;
   for (int i = 0; i < n; ++i)
     for (int j = i + 1; j < n; ++j)
       remax(ans, arr[j] * (b / arr[i]) + b % arr[i]);
   printf('%d
', ans);
 }
 int main() {
   run();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long exgcd(long long a, long long b, long long &x, long long &y) {
   if (b == 0) {
     x = 1, y = 0;
     return a;
   }
   long long g = exgcd(b, a % b, x, y);
   long long t;
   t = x, x = y, y = t - (a / b) * y;
   return g;
 }
 int main() {
   long long a, b, c, x, y;
   cin >> a >> b >> c;
   long long t = exgcd(a, b, x, y);
   if (c % t == 0)
     printf('%lld %lld
', -x * c / t, -y * c / t);
   else
     printf('-1
');
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MOD = 1e9 + 7;
 const int N = 1010;
 int dp[N][N][2];
 int bits[N];
 int t, k;
 long long dfs(int len, int pos, int num, bool mark) {
   int maxx;
   long long sum;
   if (!len) {
     if (num == 1) {
       return true;
     } else {
       return false;
     }
   }
   if (!mark && dp[len][pos][num] != -1) {
     return dp[len][pos][num];
   }
   if (mark) {
     maxx = bits[len];
   } else {
     maxx = 9;
   }
   sum = 0;
   for (int i = 0; i <= maxx; i++) {
     if (i == 4 || i == 7) {
       sum +=
           dfs(len - 1, len, (pos && pos - len <= k) | num, mark && i == maxx);
     } else {
       sum += dfs(len - 1, pos, num, mark && i == maxx);
     }
   }
   sum %= MOD;
   if (!mark) {
     dp[len][pos][num] = sum;
   }
   return sum;
 }
 long long f(string s) {
   int len;
   len = 0;
   for (int i = s.size() - 1; i >= 0; i--) {
     len++;
     bits[len] = s[i] - '0';
   }
   return dfs(len, 0, 0, 1);
 }
 bool check(string &s) {
   int p;
   p = 0;
   for (int i = 1; i <= s.size(); i++) {
     if (s[i - 1] == '4' || s[i - 1] == '7') {
       if (!p || i - p > k) {
         p = i;
       } else if (i - p <= k) {
         return true;
       }
     }
   }
   return false;
 }
 int main() {
   string l, r;
   long long ans;
   while (scanf('%d%d', &t, &k) == 2) {
     memset(dp, -1, sizeof(dp));
     for (int i = 0; i < t; i++) {
       cin >> l >> r;
       ans = f(r) - f(l) + (check(l) ? 1 : 0);
       printf('%lld
', (ans % MOD + MOD) % MOD);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int vis[200005][3], n;
 long long dp[200005][3], a[200005];
 long long dfs(int x, int s) {
   if (dp[x][s]) return dp[x][s];
   if (vis[x][s]) return -1;
   vis[x][s] = 1;
   int k;
   if (s)
     k = x + a[x];
   else
     k = x - a[x];
   if (k <= 0 || k > n)
     dp[x][s] += a[x];
   else {
     dp[x][s] = dfs(k, s ^ 1);
     if (dp[x][s] != -1) dp[x][s] += a[x];
   }
   return dp[x][s];
 }
 int main() {
   while (scanf('%d', &n) != EOF) {
     memset(vis, 0, sizeof(vis));
     memset(dp, 0, sizeof(dp));
     for (int i = 2; i <= n; i++) scanf('%I64d', &a[i]);
     for (int i = 2; i <= n; i++) dfs(i, 0);
     for (int i = 1; i < n; i++) {
       if (dp[i + 1][0] == -1)
         printf('-1
');
       else
         printf('%I64d
', i + dp[i + 1][0]);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 double PI = acos(-1.0);
 long long mod = 998244353;
 struct custom_hash {
   static uint64_t splitmix64(uint64_t x) {
     x += 0x9e3779b97f4a7c15;
     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
     x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
     return x ^ (x >> 31);
   }
   size_t operator()(uint64_t x) const {
     static const uint64_t FIXED_RANDOM =
         chrono::steady_clock::now().time_since_epoch().count();
     return splitmix64(x + FIXED_RANDOM);
   }
 };
 long long GCD(long long a, long long b) {
   if (b == 0) return a;
   return GCD(b, a % b);
 }
 long long prod(long long a, long long b) {
   long long res = 0;
   a %= mod;
   while (b) {
     if (b & 1ll) res = (res + a) % mod;
     a = (2ll * a) % mod;
     b >>= 1ll;
   }
   return res;
 }
 long long power(long long a, long long b) {
   long long res = 1ll;
   while (b > 0) {
     if (b % 2ll) res = (res * a) % mod;
     a = (a * a) % mod;
     b /= 2ll;
   }
   return res;
 }
 long long binaryExponentiation(long long a, long long b) {
   long long result = 1ll;
   while (b > 0) {
     if (b % 2 == 1) result = (result * a) % mod;
     a = (a * a) % mod;
     b /= 2ll;
   }
   return result;
 }
 long long ModularInverse(long long a) {
   return binaryExponentiation(a, mod - 2);
 }
 long long n, m;
 void solve() {
   cin >> n;
   vector<long long> a(n);
   for (long long i = 0; i < n; i++) {
     cin >> a[i];
   }
   for (long long i = 0; i < n; i++) {
     if (a[i] >= 0) {
       a[i] = -a[i] - 1;
     }
   }
   long long x = INT_MAX, p = 0;
   for (long long i = 0; i < n; i++) {
     if (a[i] < x) {
       x = a[i];
       p = i;
     }
   }
   if (n % 2) {
     a[p] = -a[p] - 1;
   }
   for (auto &e : a) {
     cout << e << ' ';
   }
   cout << '
';
 }
 signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long t = 1;
   while (t--) {
     solve();
   }
 }


#include <bits/stdc++.h>
 #define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 #define testCase    int T; cin>>T; while(T--)
 #define debug(P) cout<<#P<<' '<<P<<endl
 #define endl '
'

 using namespace std;

 typedef long long ll;

 int main() {
   testCase {
   	int n;
   	cin>>n;
   	string s;
   	cin>>s;

   	bool poss = true;

   	int t = 0;

   	for(char x : s) {
   		if(x == 'T')++t;
   	}

   	if(2*(n-t) != t) {
   		poss = false;
   	}

   	t = 0;

   	for(int i = 0; i < n; ++i) {
   		if(s[i] == 'T') ++t;
   		else {
   			--t;
   			if(t < 0) {
   				poss = false;
   				break;
   			}
   		}
   	}

   	t = 0;

   	for(int i = n-1; i >= 0; --i) {
   		if(s[i] == 'T') ++t;
   		else {
   			--t;
   			if(t < 0) {
   				poss = false;
   				break;
   			}
   		}
   	}

   	if(poss) {
   		cout<< 'YES
';
   	} else {
   		cout<< 'NO
';
   	}

   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   if (n % 2 == 0)
     cout << (n * n) / 2 << endl;
   else
     cout << (n / 2) * (n / 2) + (n / 2 + 1) * (n / 2 + 1) << endl;
   for (int i = 1; i <= n; i++) {
     for (int j = 1; j <= n; j++)
       if ((i + j) % 2 == 0)
         cout << 'C';
       else
         cout << '.';
     cout << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = (int)2e6 + 10;
 vector<int> a[N];
 vector<int> pos[N];
 string ans;
 int n;
 string s[N];
 int m;
 vector<int> cur;
 int cnt[N];
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   memset(cnt, 0, sizeof(cnt));
   m = 0;
   cin >> n;
   for (int i = 1; i <= n; i++) {
     cin >> s[i];
     int len = s[i].length();
     int k;
     cin >> k;
     while (k--) {
       int p;
       cin >> p;
       p--;
       m = max(m, p + len);
       a[p].push_back(i);
       a[p + len].push_back(-i);
       pos[i].push_back(p);
     }
   }
   ans.resize(m);
   for (int i = 0; i < m; i++) {
     for (int x : a[i]) {
       if (x > 0) {
         cur.push_back(x);
         cnt[x]++;
       } else {
         cnt[-x]--;
       }
     }
     while (!cur.empty() && cnt[cur.back()] == 0) cur.pop_back();
     if (cur.empty())
       ans[i] = 'a';
     else {
       int id = cur.back();
       auto it = upper_bound(pos[id].begin(), pos[id].end(), i);
       it--;
       int p = *it;
       if (i - p >= (int)s[id].length()) continue;
       ans[i] = s[id][i - p];
     }
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int a, b, c;
   while (cin >> a >> b >> c) {
     long long l = 0, r = 100000000;
     while (l <= r) {
       long long t = (l + r) / 2;
       long long w = b * t;
       long long d = b * t;
       bool ok = true;
       while (d < a * c) {
         if (w < a) {
           ok = false;
           break;
         }
         w -= a;
         w += b;
         d += b;
       }
       if (ok)
         r = t - 1;
       else
         l = t + 1;
     }
     cout << l - 1 << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline int read() {
   int x = 0;
   char ch = getchar();
   while (ch < '0' || ch > '9') ch = getchar();
   while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
   return x;
 }
 vector<pair<int, int> > v[1000000 + 5];
 int s[1000000 / 5], num = 0, last[1000000 + 5], vis[1000000 + 5],
                     la[1000000 + 5], lastans = 0, n, q, mx, a[1000000 + 5],
                     rt[1000000 + 5], cnt = 0, inv[1000000 + 5],
                     Ans[1000000 + 5];
 struct Tree {
   int l, r, x;
 } T[1000000 * 4 + 5];
 bool b[1000000 + 5];
 int Build(int l, int r) {
   int x = ++cnt;
   T[x].x = 1;
   if (l != r) {
     int mid = l + r >> 1;
     T[x].l = Build(l, mid);
     T[x].r = Build(mid + 1, r);
   }
   return x;
 }
 void Modify(int x, int l, int r, int lt, int rt, int v) {
   if (l == lt && r == rt) {
     T[x].x = 1LL * T[x].x * v % 1000000007;
     return;
   }
   int mid = lt + rt >> 1;
   if (r <= mid)
     Modify(T[x].l, l, r, lt, mid, v);
   else if (l > mid)
     Modify(T[x].r, l, r, mid + 1, rt, v);
   else
     Modify(T[x].l, l, mid, lt, mid, v),
         Modify(T[x].r, mid + 1, r, mid + 1, rt, v);
 }
 void Query(int x, int k, int lt, int rt) {
   lastans = 1LL * lastans * T[x].x % 1000000007;
   if (lt == rt) return;
   int mid = lt + rt >> 1;
   if (k <= mid)
     Query(T[x].l, k, lt, mid);
   else
     Query(T[x].r, k, mid + 1, rt);
 }
 int main() {
   n = read();
   inv[0] = inv[1] = 1;
   for (int i = 1; i <= n; ++i) mx = max(mx, a[i] = read());
   q = read();
   for (register int i = 2; i <= mx; ++i) {
     inv[i] =
         1LL * (1000000007 - 1000000007 / i) * inv[1000000007 % i] % 1000000007;
     if (!b[i]) s[++num] = i, last[i] = i;
     for (int j = 1; s[j] * i <= mx; ++j) {
       b[s[j] * i] = 1;
       last[s[j] * i] = s[j];
       if (i % s[j] == 0) break;
     }
   }
   rt[0] = Build(1, n);
   for (int i = 1; i <= q; ++i) {
     int l = read(), r = read();
     v[r].push_back(make_pair(l, i));
   }
   for (register int i = 1; i <= n; ++i) {
     Modify(rt[i] = rt[i - 1], 1, i, 1, n, a[i]);
     for (int t = a[i]; t > 1; t /= last[t])
       if (vis[last[t]] != i) {
         vis[last[t]] = i;
         Modify(rt[i], la[last[t]] + 1, i, 1, n,
                1LL * inv[last[t]] * (last[t] - 1) % 1000000007);
         la[last[t]] = i;
       }
     for (int j = 0; j < v[i].size(); ++j)
       lastans = 1, Query(rt[i], v[i][j].first, 1, n),
       Ans[v[i][j].second] = lastans;
   }
   for (int i = 1; i <= q; ++i) printf('%d
', Ans[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using LL = long long;
 const LL MOD = 998244353;
 string s;
 LL cal(int x) {
   if (x < 10 || x > 18) return 0;
   return 9 - (x - 10);
 }
 struct SegmentTree {
   struct Node {
     int L, R, l, r;
     LL v[2][2];
   };
   vector<Node> N;
   int p;
   vector<int> rt;
   int n;
   inline void init(int _n) {
     n = _n;
     N.resize(n * 4);
     p = 1;
     rt.clear();
     rt.push_back(build(0, n));
   }
   inline int copy(Node u) { return N[p] = u, p++; }
   int build(int L, int R) {
     int u = copy({L, R}), M = (L + R) >> 1;
     ;
     if (R - L == 1)
       return N[u].v[0][0] = s[L] - '0' + 1, N[u].v[0][1] = 1, N[u].v[1][0] = 1,
              N[u].v[1][1] = 0, u;
     return pull(u, build(L, M), build(M, R));
   }
   inline int push(int u) { return u; }
   inline int pull(int u, int l, int r) {
     if (!l || !r) return l ? l : r;
     push(N[u].l = l);
     push(N[u].r = r);
     for (int i = 0; i < 2; i++) {
       for (int j = 0; j < 2; j++) {
         N[u].v[i][j] =
             (N[l].v[i][0] * N[r].v[0][j] +
              N[l].v[i][1] * N[r].v[1][j] % MOD *
                  cal((s[N[l].R - 1] - '0') * 10 + (s[N[r].L] - '0'))) %
             MOD;
       }
     }
     return u;
   }
   int m(int L, int R, int u, int v) {
     if (!u || R <= N[u].L || N[u].R <= L) return u;
     push(u);
     if (L <= N[u].L && N[u].R <= R) return N[u].v[0][0] = v + 1, u;
     return pull(u, m(L, R, N[u].l, v), m(L, R, N[u].r, v));
   }
   int q(int L, int R, int u) {
     if (!u || R <= N[u].L || N[u].R <= L) return 0;
     if (L <= N[u].L && N[u].R <= R) return u;
     push(u);
     return pull(copy(N[u]), q(L, R, N[u].l), q(L, R, N[u].r));
   }
   inline void modify(int L, int R, int ver, int v) {
     rt[ver] = m(L, R, rt[ver], v);
   }
   inline Node& query(int L, int R, int ver) {
     p = 2 * n + 1;
     return N[q(L, R, rt[ver])];
   }
 } solver;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int n, q;
   cin >> n >> q;
   cin >> s;
   solver.init(n);
   while (q--) {
     int x, d;
     cin >> x >> d;
     x--;
     s[x] = '0' + d;
     solver.modify(x, x + 1, 0, d);
     auto v = solver.query(0, n, 0).v;
     cout << v[0][0] << '
';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> av;
 int main() {
   int n;
   scanf('%d', &n);
   for (int i = max(1, n - 100); i <= n; i++) {
     int j = i, ans = i;
     while (j) {
       ans += j % 10;
       j /= 10;
     }
     if (ans == n) av.push_back(i);
   }
   int avs = av.size();
   printf('%d
', avs);
   for (int i = 0; i < avs; i++) {
     printf('%d
', av[i]);
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize('O3')
 #pragma GCC optimize('Ofast')
 using namespace std;
 long long int n, res[200005], cnt = 0, ans[200005];
 vector<long long int> g[200005];
 vector<long long int> v[200005];
 map<long long int, long long int> c;
 queue<long long int> q;
 void dfs1(long long int node, long long int color) {
   c[node] = color;
   for (auto it : g[node]) {
     if (!c[it]) {
       dfs1(it, color % 2 + 1);
     }
   }
 }
 void dfs2(long long int node, long long int p) {
   for (auto it : g[node]) {
     if (it != p) {
       dfs2(it, node);
     }
   }
   for (auto it : g[node]) {
     if (c[it] != c[node] && res[it] == 0 && res[node] == 0) {
       cnt++;
       res[it] = cnt;
       res[node] = cnt;
       q.push(it);
       q.push(node);
     }
   }
 }
 int32_t main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   ;
   cin >> n;
   for (long long int i = 1; i < n; i++) {
     long long int x, y;
     cin >> x >> y;
     g[x].push_back(y);
     g[y].push_back(x);
   }
   dfs1(1, 1);
   dfs2(1, 1);
   while (!q.empty()) {
     long long int x = q.front();
     q.pop();
     for (auto it : g[x]) {
       if (res[it] == 0) {
         res[it] = res[x];
         q.push(it);
       }
     }
   }
   for (long long int i = 1; i <= n; i++) {
     v[res[i]].push_back(i);
   }
   long long int mn = 0;
   for (long long int i = 1; i <= cnt; i++) {
     mn += (v[i].size() - 1) * 2;
     for (long long int j = 0; j < v[i].size(); j++) {
       ans[v[i][j]] = v[i][(j + 1) % v[i].size()];
     }
   }
   cout << mn << '
';
   for (long long int i = 1; i <= n; i++) {
     cout << ans[i] << ' ';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int block_size = 320;
 const long long mod = 1e9 + 7;
 const long long inf = 1e9 + 7;
 const long double eps = 1e-9;
 const double PI = atan(1) * 4;
 template <typename T>
 inline int sign(const T &a) {
   if (a < 0) return -1;
   if (a > 0) return 1;
   return 0;
 }
 string to_string(string s) { return ''' + s + '''; }
 string to_string(const char *s) { return to_string((string)s); }
 string to_string(bool b) { return (b ? 'true' : 'false'); }
 template <typename A, typename B>
 string to_string(pair<A, B> p) {
   return '(' + to_string(p.first) + ', ' + to_string(p.second) + ')';
 }
 template <typename A>
 string to_string(A v) {
   bool first = true;
   string res = '{';
   for (const auto &x : v) {
     if (!first) {
       res += ', ';
     }
     first = false;
     res += to_string(x);
   }
   res += '}';
   return res;
 }
 void debug_out() { cerr << endl; }
 template <typename Head, typename... Tail>
 void debug_out(Head H, Tail... T) {
   cerr << ' ' << to_string(H);
   debug_out(T...);
 }
 template <typename T, typename S>
 inline bool upmin(T &a, const S &b) {
   return a > b ? a = b, 1 : 0;
 }
 template <typename T, typename S>
 inline bool upmax(T &a, const S &b) {
   return a < b ? a = b, 1 : 0;
 }
 template <typename T>
 inline void in(T &x) {
   x = 0;
   T f = 1;
   char ch = getchar();
   while (!isdigit(ch)) {
     if (ch == '-') f = -1;
     ch = getchar();
   }
   while (isdigit(ch)) {
     x = x * 10 + ch - '0';
     ch = getchar();
   }
   x *= f;
 }
 long long twop(int x) { return 1LL << x; }
 template <typename A, typename B>
 inline void in(A &x, B &y) {
   in(x);
   in(y);
 }
 template <typename A, typename B, typename C>
 inline void in(A &x, B &y, C &z) {
   in(x);
   in(y);
   in(z);
 }
 template <typename A, typename B, typename C, typename D>
 inline void in(A &x, B &y, C &z, D &d) {
   in(x);
   in(y);
   in(z);
   in(d);
 }
 long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
 namespace SOLVE {
 int n, q;
 string s;
 int nxt[100010][26];
 int dp[255][255][255];
 vector<int> word[3];
 void solve(int i, int j, int k) {
   dp[i][j][k] = inf;
   if (i and dp[i - 1][j][k] <= n)
     upmin(dp[i][j][k], nxt[dp[i - 1][j][k]][word[0][i]]);
   if (j and dp[i][j - 1][k] <= n)
     upmin(dp[i][j][k], nxt[dp[i][j - 1][k]][word[1][j]]);
   if (k and dp[i][j][k - 1] <= n)
     upmin(dp[i][j][k], nxt[dp[i][j][k - 1]][word[2][k]]);
 }
 void main() {
   cin >> n >> q >> s;
   for (long long i = 0; i < n; i++) s[i] -= 'a';
   s = ' ' + s;
   for (long long i = 0; i < 26; i++) nxt[n][i] = inf;
   for (long long i = n - 1; i >= 0; i--) {
     for (long long j = 0; j < 26; j++) nxt[i][j] = nxt[i + 1][j];
     nxt[i][s[i + 1]] = i + 1;
   }
   for (long long i = 0; i < 3; i++) word[i].push_back(0);
   dp[0][0][0] = 0;
   while (q--) {
     string op;
     cin >> op;
     int id;
     cin >> id;
     id--;
     if (op == '+') {
       string sss;
       cin >> sss;
       int ch = sss[0] - 'a';
       word[id].push_back(ch);
       if (id == 0) {
         for (long long b = 0; b < ((int)word[1].size()); b++) {
           for (long long c = 0; c < ((int)word[2].size()); c++) {
             solve(((int)word[0].size()) - 1, b, c);
           }
         }
       }
       if (id == 1) {
         for (long long b = 0; b < ((int)word[0].size()); b++) {
           for (long long c = 0; c < ((int)word[2].size()); c++) {
             solve(b, ((int)word[1].size()) - 1, c);
           }
         }
       }
       if (id == 2) {
         for (long long b = 0; b < ((int)word[0].size()); b++) {
           for (long long c = 0; c < ((int)word[1].size()); c++) {
             solve(b, c, ((int)word[2].size()) - 1);
           }
         }
       }
     } else {
       word[id].pop_back();
     }
     cout << ((dp[((int)word[0].size()) - 1][((int)word[1].size()) - 1]
                 [((int)word[2].size()) - 1] <= n)
                  ? 'YES'
                  : 'NO')
          << endl;
   }
 }
 }  // namespace SOLVE
 signed main() {
   int t;
   t = 1;
   while (t--) {
     SOLVE::main();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int t;
   cin >> t;
   while (t--) {
     long long int n;
     cin >> n;
     long long int a[n];
     long long int sum = 0;
     for (int i = 0; i < n; i++) {
       cin >> a[i];
       if (!(i & 1)) sum += a[i];
     }
     long long int best = 0;
     long long int cur = 0;
     long long int z, z1;
     if (n & 1)
       z = n - 1;
     else
       z = n;
     for (int i = 0; i < z; i += 2) {
       cur = max(0ll, cur + a[i + 1] - a[i]);
       best = max(cur, best);
     }
     cur = 0;
     if (!(n & 1))
       z1 = n - 1;
     else
       z1 = n;
     for (int i = 1; i < z1; i += 2) {
       cur = max(0ll, cur + a[i] - a[i + 1]);
       best = max(cur, best);
     }
     cout << sum + best << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 35000 + 10;
 const int MAXK = 55;
 int tree[MAXN << 2], info[MAXN << 2];
 int dp[MAXK][MAXN];
 int nums[MAXN];
 int pre[MAXN], cur[MAXN];
 void build(int node, int start, int end, int i) {
   if (start == end) {
     tree[node] = dp[i][start - 1];
     info[node] = 0;
     return;
   }
   int mid = (start + end) >> 1;
   build((node << 1), start, mid, i);
   build(((node << 1) | 1), mid + 1, end, i);
   tree[node] = max(tree[(node << 1)], tree[((node << 1) | 1)]);
   info[node] = 0;
 }
 void update(int node, int start, int end, int i, int j, int val) {
   if (end < i || j < start) return;
   if (i <= start && end <= j) {
     tree[node] += val;
     info[node] += val;
     return;
   }
   int mid = (start + end) >> 1;
   if (info[node] != 0) {
     update((node << 1), start, mid, start, mid, info[node]);
     update(((node << 1) | 1), mid + 1, end, mid + 1, end, info[node]);
     info[node] = 0;
   }
   update((node << 1), start, mid, i, j, val);
   update(((node << 1) | 1), mid + 1, end, i, j, val);
   tree[node] = max(tree[(node << 1)], tree[((node << 1) | 1)]);
 }
 int query(int node, int start, int end, int i, int j) {
   if (end < i || j < start) return INT_MIN;
   if (i <= start && end <= j) {
     return tree[node];
   }
   int mid = (start + end) >> 1;
   if (info[node] != 0) {
     update((node << 1), start, mid, start, mid, info[node]);
     update(((node << 1) | 1), mid + 1, end, mid + 1, end, info[node]);
     info[node] = 0;
   }
   return max(query((node << 1), start, mid, i, j),
              query(((node << 1) | 1), mid + 1, end, i, j));
 }
 int main() {
   int n, k;
   cin >> n >> k;
   for (int i = 1; i <= n; i++) {
     scanf('%d', &nums[i]);
     pre[i] = cur[nums[i]];
     cur[nums[i]] = i;
   }
   for (int i = 1; i <= k; i++) {
     build(1, 1, n, i - 1);
     for (int j = i; j <= n; j++) {
       update(1, 1, n, pre[j] + 1, j, 1);
       dp[i][j] = query(1, 1, n, 1, j);
     }
   }
   cout << dp[k][n] << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 typedef struct {
   int x;
   int y;
   long long z;
   long long o;
 } H;
 long long b, g, i, j, k, sz, t, p[200040], w[200040];
 int pv[200040];
 H e[400005];
 int C(H a, H b) { return a.x < b.x; }
 void BP(void);
 void S(void);
 long long dfs(int v);
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   for (cin >> t; t--;) {
     S();
     BP();
     k++;
     for (i = 0; i++ < k;) {
       if (w[i] < 2 && !p[e[pv[i]].y]) {
         dfs(pv[i]);
         p[e[pv[i]].y] = 1;
       }
     }
     for (b = g = i = 0; i < sz; i++) {
       if (!e[i].o) {
         if (w[e[i].y] < 2)
           e[i].o = 1;
         else
           e[i].o = k - 1;
       }
       if (e[i].o * 2 < k || e[i].o * 2 == k && e[i].x < e[i].y) {
         g += e[i].o % 2 * e[i].z;
         b += e[i].o * e[i].z;
       }
     }
     cout << g << ' ' << b << '
';
     for (i = 0; i++ < k + 1;) p[i] = pv[i] = w[i] = 0;
     for (i = 0; i < sz + 1; i++) e[i].o = 0;
   }
 }
 void BP(void) {
   for (int i = 0; ++i < sz;) {
     if (e[i].x > e[i - 1].x) {
       for (int j = e[i - 1].x; j++ < e[i].x;) {
         pv[j] = i;
       }
     }
   }
   for (int j = e[sz - 1].x; j++ < k + 2;) pv[j] = sz;
 }
 void S(void) {
   cin >> k;
   k = 2 * k - 1;
   for (int i = 0; i < k; i++) {
     cin >> e[i].x >> e[i].y >> e[i].z;
     e[i + k].x = e[i].y;
     e[i + k].y = e[i].x;
     e[i + k].z = e[i].z;
     w[e[i].x]++;
     w[e[i].y]++;
   }
   sz = 2 * k;
   sort(e, e + sz, C);
 }
 long long dfs(int v) {
   long long s = 0;
   if (e[v].o) return e[v].o;
   for (int i = pv[e[v].y]; i < pv[e[v].y + 1]; i++) {
     if (e[i].y != e[v].x) s += dfs(i);
   }
   return e[v].o = s + 1;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int a, b;
   cin >> a >> b;
   if ((a >= 0 && b < 0) || (a < 0 && b >= 0)) {
     cout << '-1';
     return 0;
   }
   if (a == 0 && b == 0) {
     cout << '-1';
     return 0;
   }
   if (a < 0 && b < 0) {
     cout << '-1';
     return 0;
   }
   if (b == 0 && a > 0) {
     cout << '-1';
     return 0;
   }
   if (a == b) {
     cout << a;
     return 0;
   }
   if (a > 0 && b > 0) {
     if (b > a) {
       cout << '-1';
       return 0;
     } else {
       int k1 = (a - b) / (2 * b);
       double x1 = (double)(a - b) / (2 * k1);
       int k2 = (a + b) / (2 * b);
       double x2 = (double)(a + b) / (2 * k2);
       cout << setprecision(10) << min(x1, x2);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int fr[301][301];
   int al[301];
   int i, j, n;
   cin >> n;
   for (i = 1; i <= n; ++i)
     for (j = 1; j <= n; ++j) cin >> fr[i][j];
   for (i = 1; i <= n; ++i) cin >> al[i];
   int k, best[301], best_time[301], cur;
   for (j = 1; j <= n; ++j) {
     best[j] = 301;
     best_time[j] = 301;
     for (i = 1; i <= n; ++i) {
       if (j == 1 && i == 1) continue;
       for (k = 1; k <= n; ++k)
         if (al[k] <= i && al[k] != j) {
           cur = al[k];
           break;
         }
       for (k = 1; k <= n; ++k) {
         if (cur == fr[j][k]) {
           if (k < best[j]) {
             best[j] = k;
             best_time[j] = i;
           }
           break;
         }
       }
     }
   }
   for (i = 1; i <= n; ++i) cout << best_time[i] << '	';
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   int x = 0, xi = INT_MIN, q = 0;
   vector<int> v;
   for (int i = 0; i < n; i++) {
     int y;
     cin >> y;
     q = x;
     v.push_back(y);
     xi = max(x, v[i]);
     if (x != q) x = i;
   }
   long long ans = 0;
   for (int i = 0; i < n; i++) {
     int z = (abs(x - i) + i + x) * 2;
     ans += (z * v[i]);
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline int min(int _a, int _b) { return _a < _b ? _a : _b; }
 inline int max(int _a, int _b) { return _a > _b ? _a : _b; }
 template <class _T>
 inline void rd(_T &_a) {
   int _f = 0, _ch = getchar();
   _a = 0;
   while (_ch < '0' || _ch > '9') {
     if (_ch == '-') _f = 1;
     _ch = getchar();
   }
   while (_ch >= '0' && _ch <= '9') _a = _a * 10 + _ch - '0', _ch = getchar();
   if (_f) _a = -_a;
 }
 const int inf = 0x3f3f3f3f;
 const double eps = 1e-8;
 const int mod = 1e9 + 7, N = 15;
 int mp[N][N], f[N][N], ct[N], n, m, k, ans;
 void dfs(int x, int y) {
   if (y > m) x++, y = 1;
   if (x > n) {
     ans++;
     ans %= mod;
     return;
   }
   int st = f[x - 1][y] | f[x][y - 1], pre, d = -1;
   if (n + m - x - y + 1 > k - __builtin_popcount(st)) return;
   for (int i = 1; i <= k; i++)
     if (!(st >> i - 1 & 1) && (!mp[x][y] || mp[x][y] == i)) {
       f[x][y] = st | (1 << i - 1);
       ct[i]++;
       if (ct[i] == 1) {
         if (~d)
           ans += d;
         else {
           pre = ans;
           dfs(x, y + 1);
           d = ans - pre;
         }
       } else
         dfs(x, y + 1);
       ans %= mod;
       ct[i]--;
     }
 }
 int main() {
   rd(n);
   rd(m);
   rd(k);
   if (n + m - 1 > k) return puts('0'), 0;
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= m; j++) {
       rd(mp[i][j]);
       if (mp[i][j]) ct[mp[i][j]]++;
     }
   dfs(1, 1);
   printf('%d', ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int a, b, n, m;
 int A[100010], B[100010], L[100010];
 double dis(int a, int b, int c, int d) {
   return sqrt(
       double((a - c + 0.0) * (a - c + 0.0) + (b - d + 0.0) * (b - d + 0.0)));
 }
 double getK(int y) { return 1.0 * y * a / (b * 1.0); }
 int find(double xx) {
   int x = xx;
   return upper_bound(A, A + n, x) - A;
 }
 int main() {
   int ll, rr, id;
   double ans = 0, tmp;
   scanf('%d%d%d%d', &n, &m, &a, &b);
   for (int i = 0; i < n; i++) scanf('%d', A + i);
   for (int i = 0; i < m; i++) scanf('%d', B + i);
   for (int i = 0; i < m; i++) scanf('%d', L + i);
   ll = rr = 0;
   ans = dis(0, 0, a, A[0]) + dis(a, A[0], b, B[0]) + L[0];
   for (int i = 0; i < m; i++) {
     double k = getK(B[i]);
     id = find(k);
     id = max(0, id - 2);
     for (int j = id; j < n && j <= id + 4; j++) {
       tmp = dis(0, 0, a, A[j]) + dis(a, A[j], b, B[i]) + 1.0 * L[i];
       if (tmp < ans) ans = tmp, ll = j, rr = i;
     }
   }
   printf('%d %d
', ll + 1, rr + 1);
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int base(long long int n, long long int k) {
   string res = '';
   long long int temp = 0, i;
   while (n >= k) {
     res += to_string(n % k);
     n /= k;
   }
   res += to_string(n);
   reverse(res.begin(), res.end());
   for (i = 0; i < res.length(); i++) {
     temp = temp * 10 + (res[i] - '0');
   }
   return temp;
 }
 int main() {
   long long int n, i, j, flag = 0;
   cin >> n;
   flag = 9;
   for (i = 1; i <= n - 1; i++) {
     for (j = 1; j <= n - 1; j++) {
       cout << base(i * j, n) << ' ';
     }
     cout << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXM = 2e5 + 3, MAXN = 2e5 + 3, MAXQ = 2e5 + 3, MAXC = 2e5 + 3,
           ADD = 1 << 18;
 int n, m, q;
 int edge_from[MAXM << 1], edge_to[MAXM << 1], edge_nex[MAXM << 1];
 int cntm = 1, head[MAXN];
 void link(int from, int to) {
   edge_from[++cntm] = from;
   edge_to[cntm] = to;
   edge_nex[cntm] = head[from];
   head[from] = cntm;
 }
 bool isb[MAXM << 1];
 int edge1_to[MAXC << 1], edge1_nex[MAXC << 1];
 int cntm1 = 0, head1[MAXC];
 void link1(int from, int to) {
   edge1_to[++cntm1] = to;
   edge1_nex[cntm1] = head1[from];
   head1[from] = cntm1;
 }
 int dfn[MAXN], low[MAXN], cntd = 0;
 void tarjan(int now, int fa) {
   low[now] = dfn[now] = ++cntd;
   for (int i = head[now]; i; i = edge_nex[i]) {
     if ((i ^ 1) == fa) continue;
     if (!dfn[edge_to[i]]) {
       tarjan(edge_to[i], i);
       if (low[edge_to[i]] > low[now]) {
         isb[i] = isb[i ^ 1] = 1;
       } else {
         low[now] = low[edge_to[i]];
       }
     } else {
       low[now] = min(low[now], low[edge_to[i]]);
     }
   }
 }
 int col[MAXN], cntc = 0, Fa[MAXC][23], Deep[MAXC], cntd1 = 0;
 void dfs(int now) {
   col[now] = cntc;
   for (int i = head[now]; i; i = edge_nex[i])
     if (!col[edge_to[i]] && !isb[i]) dfs(edge_to[i]);
 }
 void dfs2(int now) {
   for (int i = head1[now]; i; i = edge1_nex[i]) {
     if (!Deep[edge1_to[i]] && edge1_to[i] != Fa[now][0]) {
       Fa[edge1_to[i]][0] = now;
       Deep[edge1_to[i]] = Deep[now] + 1;
       dfs2(edge1_to[i]);
     }
   }
 }
 long long val1[MAXN];
 long long sum1;
 bool Arr[MAXN];
 int ans = 1;
 void dfs3(int now) {
   if (!ans) return;
   Arr[now] = 1;
   long long in1 = sum1;
   sum1 += val1[now];
   for (int i = head1[now]; i; i = edge1_nex[i])
     if (!Arr[edge1_to[i]] && ans) dfs3(edge1_to[i]);
   in1 = sum1 - in1;
   if ((in1 >> 18) && in1 - ((in1 >> 18) << 18)) ans = 0;
 }
 inline int lca(register int A, register int B) {
   if (Deep[A] < Deep[B]) swap(A, B);
   for (int i = 17; i >= 0; i--) {
     if (Deep[Fa[A][i]] >= Deep[B]) A = Fa[A][i];
   }
   if (A == B) return A;
   for (int i = 17; i >= 0; i--) {
     if (Fa[A][i] != Fa[B][i]) {
       A = Fa[A][i];
       B = Fa[B][i];
     }
   }
   if (Fa[A][0] == Fa[B][0] && Fa[A][0] != 0) return Fa[A][0];
   return -1;
 }
 int main() {
   ios::sync_with_stdio(false);
   cin >> n >> m >> q;
   for (int i = 1, U, V; i <= m; i++) {
     cin >> U >> V;
     link(U, V);
     link(V, U);
   }
   for (int i = 1; i <= n; i++)
     if (!dfn[i]) tarjan(i, 0);
   for (int i = 1; i <= n; i++)
     if (!col[i]) {
       cntc++;
       dfs(i);
     }
   for (int i = 2; i <= cntm; i++)
     if (isb[i]) link1(col[edge_from[i]], col[edge_to[i]]);
   for (int i = 1; i <= cntc; i++)
     if (!Deep[i]) {
       Deep[i] = 1;
       dfs2(i);
     }
   for (int i = 1; i <= 17; i++)
     for (int j = 1; j <= cntc; j++) Fa[j][i] = Fa[Fa[j][i - 1]][i - 1];
   for (int i = 1, i2, i3, i4; i <= q; i++) {
     cin >> i2 >> i3;
     i2 = col[i2];
     i3 = col[i3];
     if (i2 == i3) continue;
     i4 = lca(i2, i3);
     if (i4 == -1) {
       ans = 0;
       break;
     }
     val1[i2] += 1;
     val1[i4] -= 1;
     val1[i3] += ADD;
     val1[i4] -= ADD;
   }
   for (int i = 1; i <= cntc; i++)
     if (!Arr[i]) dfs3(i);
   if (ans)
     cout << 'Yes';
   else
     cout << 'No';
 }


#include <bits/stdc++.h>
 using namespace std;
 int adj[205][205];
 int rgraph[205][205];
 int n, m;
 int parent[205];
 bool visited[205];
 int a[105];
 int b[105];
 bool bfs(int s, int t) {
   memset(visited, 0, sizeof(visited));
   queue<int> q;
   q.push(s);
   visited[s] = true;
   parent[s] = -1;
   while (!q.empty()) {
     int u = q.front();
     q.pop();
     for (int i = 0; i <= 2 * n + 1; i++) {
       if (!visited[i] && rgraph[u][i] > 0) {
         q.push(i);
         parent[i] = u;
         visited[i] = true;
       }
     }
   }
   return visited[t] == true;
 }
 int solve(int s, int t) {
   for (int i = 0; i <= 2 * n + 1; i++) {
     for (int j = 0; j <= 2 * n + 1; j++) {
       rgraph[i][j] = adj[i][j];
     }
   }
   int max_flow = 0;
   while (bfs(0, 2 * n + 1)) {
     int path = 2000000000;
     for (int i = t; i != s; i = parent[i]) {
       int u = parent[i];
       path = min(path, rgraph[u][i]);
     }
     for (int i = t; i != s; i = parent[i]) {
       int u = parent[i];
       rgraph[u][i] -= path;
       rgraph[i][u] += path;
     }
     max_flow += path;
   }
   return max_flow;
 }
 int main() {
   cin >> n >> m;
   int suma = 0, sumb = 0;
   for (int i = 1; i <= n; i++) {
     cin >> a[i];
     adj[0][i] = a[i];
     suma += a[i];
   }
   for (int i = 1; i <= n; i++) {
     cin >> b[i];
     adj[n + i][2 * n + 1] = b[i];
     sumb += b[i];
     adj[i][n + i] = 1000000;
   }
   for (int i = 0; i < m; i++) {
     int c, d;
     cin >> c >> d;
     adj[c][n + d] = 1000000;
     adj[d][n + c] = 1000000;
   }
   int ans = solve(0, 2 * n + 1);
   if (ans == suma && ans == sumb) {
     printf('YES
');
     for (int i = 1; i <= n; i++) {
       for (int j = 1; j <= n; j++) {
         if (rgraph[i][n + j] != 0)
           printf('%d ', 1000000 - rgraph[i][n + j]);
         else
           printf('%d ', rgraph[i][n + j]);
       }
       printf('
');
     }
   } else {
     printf('NO
');
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int32_t main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long t;
   t = 1;
   for (long long test = 1; test <= t; test++) {
     long long n;
     cin >> n;
     vector<long long> a;
     for (long long i = 0; i <= n - 1; i++) {
       long long x;
       cin >> x;
       if (x != 0) a.push_back(x);
     }
     long long bits[61] = {0};
     n = a.size();
     for (long long i = 0; i <= n - 1; i++) {
       long long temp = a[i];
       long long j = 0;
       while (temp > 0) {
         if (temp & 1) bits[j]++;
         temp = temp >> 1;
         j++;
       }
     }
     for (long long i = 0; i <= 60; i++)
       if (bits[i] >= 3) {
         cout << 3;
         exit(0);
       }
     long long cyclec = -1;
     vector<vector<long long>> adj(n);
     for (long long i = 0; i < n; i++)
       for (long long j = i + 1; j < n; j++)
         if ((a[i] & a[j]) != 0) {
           adj[i].push_back(j);
           adj[j].push_back(i);
         }
     for (long long i = 0; i <= n - 1; i++)
       if (adj[i].size() != 0) {
         vector<long long> dis(n, -1);
         vector<long long> par(n, -1);
         queue<long long> q;
         q.push(i);
         dis[i] = 0;
         par[i] = -1;
         while (!q.empty()) {
           auto x = q.front();
           q.pop();
           for (auto y : adj[x])
             if (dis[y] == -1) {
               dis[y] = 1 + dis[x];
               par[y] = x;
               q.push(y);
             } else if (y != par[x]) {
               if (cyclec == -1)
                 cyclec = (dis[y] + dis[x] + 1);
               else
                 cyclec = min(cyclec, dis[y] + dis[x] + 1);
             }
         }
       }
     cout << cyclec;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long N = 200001;
 std::vector<long long> g[N];
 long long s[N];
 long long h[N];
 long long a[N] = {0};
 bool visited[N] = {false};
 void dfs1(long long n, long long parent, long long depth) {
   h[n] = depth;
   for (long long v : g[n]) {
     if (v != parent) {
       dfs1(v, n, depth + 1);
     }
   }
 }
 void dfs2(long long n, long long parent) {
   if (h[n] % 2 == 0) {
     for (long long v : g[n]) {
       if (v != parent) {
         a[n] = s[v] - s[parent];
       }
     }
     for (long long v : g[n]) {
       if (v != parent) {
         a[n] = min(s[v] - s[parent], a[n]);
       }
     }
     s[n] = a[n] + s[parent];
   } else {
     a[n] = s[n] - s[parent];
   }
   for (long long v : g[n]) {
     if (v != parent) {
       dfs2(v, n);
     }
   }
 }
 int main() {
   long long n;
   cin >> n;
   for (long long i = 2; i <= n; i++) {
     long long parent;
     cin >> parent;
     g[parent].push_back(i);
     g[i].push_back(parent);
   }
   for (long long i = 1; i <= n; i++) {
     cin >> s[i];
   }
   dfs1(1, -1, 1);
   a[1] = s[1];
   dfs2(1, n + 1);
   long long sum = 0;
   for (long long i = 1; i <= n; i++) {
     if (a[i] < 0) {
       cout << '-1' << endl;
       return 0;
     }
     sum += a[i];
   }
   cout << sum << endl;
 }


#include <bits/stdc++.h>
 template <typename C>
 int sz(const C &c) {
   return c.size();
 }
 using namespace std;
 int main() {
   iostream::sync_with_stdio(false);
   int64_t n;
   cin >> n;
   int k;
   cin >> k;
   int64_t maxV = 0;
   int maxI = 1;
   int64_t maxC = 0;
   for (int i = 1; i <= k; ++i) {
     int64_t a;
     cin >> a;
     if (a * (n / a) > maxV) {
       maxV = a * (n / a);
       maxI = i;
       maxC = n / a;
     }
   }
   cout << maxI << ' ' << maxC << '
';
 }