#include <bits/stdc++.h>
 using namespace std;
 vector<long long int> v;
 int main() {
   long long int n, m, a, b, sum = 0, i, j, k;
   cin >> n >> k;
   long long int s[n], x[n];
   for (i = 0; i < n; i++) {
     cin >> a >> b;
     sum += min(a, b);
     v.push_back(min(2 * a, b) - min(a, b));
   }
   sort(v.begin(), v.end());
   for (i = 0; i < n && i < k; i++) sum += v[n - i - 1];
   cout << sum << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 0x3f3f3f3f;
 const double eps = 1e-6;
 template <typename A, typename B>
 ostream& operator<<(ostream& os, const pair<A, B>& p) {
   return os << p.first << ',' << p.second;
 }
 template <typename T>
 struct point {
   T x, y;
   point(T xx = 0, T yy = 0) : x(xx), y(yy) {}
   T len2() const { return x * x + y * y; }
   double len() const { return sqrt(double(len2())); }
   bool operator==(const point<T>& p) const { return x == p.x && y == p.y; }
 };
 template <typename T>
 point<T> operator+(const point<T>& a, const point<T>& b) {
   return point<T>(a.x + b.x, a.y + b.y);
 }
 template <typename T>
 point<T> operator-(const point<T>& a, const point<T>& b) {
   return point<T>(a.x - b.x, a.y - b.y);
 }
 template <typename T>
 T scal(const point<T>& a, const point<T>& b) {
   return a.x * b.x + a.y * b.y;
 }
 template <typename T>
 T vect(const point<T>& a, const point<T>& b) {
   return a.x * b.y - a.y * b.x;
 }
 template <typename T>
 ostream& operator<<(ostream& os, const point<T>& p) {
   return os << '(' << p.x << ',' << p.y << ')';
 }
 const int maxn = 100100;
 pair<int, pair<int, int> > a[maxn], b[maxn];
 int below[maxn], direct[maxn], belowsecond[maxn];
 long long d[maxn][2];
 int main() {
   int n;
   cin >> n;
   for (int i = 0; i < n; i++) {
     scanf( %d%d , &a[i].second.first, &a[i].first);
     a[i].second.second = i;
   }
   int m;
   cin >> m;
   for (int i = 0; i < m; i++) {
     scanf( %d%d , &b[i].second.first, &b[i].first);
     b[i].second.second = i;
   }
   sort(a, a + n);
   sort(b, b + m);
   memset(direct, -1, sizeof(direct));
   memset(below, -1, sizeof(below));
   memset(belowsecond, -1, sizeof(belowsecond));
   for (int i = 0; i < n; i++) {
     pair<int, pair<int, int> >* d1 =
         lower_bound(b, b + m,
                     pair<int, pair<int, int> >(
                         a[i].first, pair<int, int>(a[i].second.first, 0)));
     pair<int, pair<int, int> >* d2 =
         lower_bound(b, b + m,
                     pair<int, pair<int, int> >(
                         a[i].first - 1, pair<int, int>(a[i].second.first, 0)));
     if (d1 != b + m && d1->first == a[i].first &&
         d1->second.first >= a[i].second.first) {
       direct[i] = d1->second.second;
     }
     if (d2 != b + m && d2->first + 1 == a[i].first &&
         d2->second.first >= a[i].second.first) {
       below[i] = d2->second.second;
       d2++;
       if (d2 != b + m && d2->first + 1 == a[i].first &&
           d2->second.first >= a[i].second.first) {
         belowsecond[i] = d2->second.second;
       }
     }
   }
   long long mx = 0;
   for (int i = 0; i < n; i++) {
     if (direct[i] >= 0) {
       long long q = max(d[i][0], d[i][1]);
       d[i + 1][1] = max(d[i + 1][1], a[i].second.first + q);
     }
     if (below[i] >= 0) {
       d[i + 1][0] = max(d[i + 1][0], d[i][0] + a[i].second.first);
       if (i > 0 && direct[i - 1] != below[i]) {
         d[i + 1][0] = max(d[i + 1][0], d[i][1] + a[i].second.first);
       }
       if (i > 0 && direct[i - 1] == below[i] && belowsecond[i] >= 0) {
         d[i + 1][0] = max(d[i + 1][0], d[i][1] + a[i].second.first);
       }
     }
     d[i + 1][0] = max(d[i + 1][0], max(d[i][0], d[i][1]));
     mx = max(mx, max(d[i + 1][0], d[i + 1][1]));
   }
   cout << mx << endl;
   int cur = n;
   int t = 0;
   if (d[cur][t] != mx) t++;
   assert(d[cur][t] == mx);
   vector<pair<int, int> > res;
   set<int> guyused;
   for (; cur > 0; cur--) {
     if (res.size()) {
       guyused.insert(res.back().second);
     }
     if (d[cur - 1][0] == d[cur][t]) {
       t = 0;
       continue;
     }
     if (d[cur - 1][1] == d[cur][t]) {
       t = 1;
       continue;
     }
     int p = a[cur - 1].second.first;
     if (!guyused.count(direct[cur - 1])) {
       if (p + d[cur - 1][1] == mx && direct[cur - 1] >= 0) {
         res.push_back(
             pair<int, int>(a[cur - 1].second.second, direct[cur - 1]));
         mx -= p;
         t = 1;
         continue;
       }
       if (p + d[cur - 1][0] == mx && direct[cur - 1] >= 0) {
         res.push_back(
             pair<int, int>(a[cur - 1].second.second, direct[cur - 1]));
         mx -= p;
         t = 0;
         continue;
       }
     }
     assert(below[cur - 1] >= 0);
     if (!guyused.count(below[cur - 1])) {
       if (d[cur - 1][0] + p == mx) {
         res.push_back(pair<int, int>(a[cur - 1].second.second, below[cur - 1]));
         mx -= p;
         t = 0;
         continue;
       }
       if (cur - 2 < 0 ||
           (direct[cur - 2] != below[cur - 1] && d[cur - 1][1] + p == mx)) {
         res.push_back(pair<int, int>(a[cur - 1].second.second, below[cur - 1]));
         mx -= p;
         t = 1;
         continue;
       }
     }
     assert(!guyused.count(belowsecond[cur - 1]));
     if (cur - 2 >= 0 && direct[cur - 2] == below[cur - 1] &&
         belowsecond[cur - 1] >= 0 && d[cur - 1][1] + p == mx) {
       res.push_back(
           pair<int, int>(a[cur - 1].second.second, belowsecond[cur - 1]));
       mx -= p;
       t = 1;
       continue;
     }
     assert(0);
   }
   printf( %d
 , res.size());
   for (int i = 0; i < res.size(); i++) {
     printf( %d %d
 , res[i].second + 1, res[i].first + 1);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline int read() {
   int x = 0, neg = 1;
   char c = getchar();
   while (!isdigit(c)) {
     if (c == '-') neg = -1;
     c = getchar();
   }
   while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
   return x * neg;
 }
 inline int qpow(int x, int e, int _MOD) {
   int ans = 1;
   while (e) {
     if (e & 1) ans = ans * x % _MOD;
     x = x * x % _MOD;
     e >>= 1;
   }
   return ans;
 }
 int n = read(), s = read(), a[200005], b[200005], c[200005], d[200005], num = 0;
 vector<int> g[200005], cyc[200005];
 int k = 0;
 inline void dfs(int x) {
   while (!g[x].empty()) {
     int y = g[x].back();
     g[x].pop_back();
     dfs(a[y]);
     cyc[k].push_back(y);
   }
 }
 signed main() {
   for (int i = 1; i <= n; i++) a[i] = read(), c[i] = a[i];
   sort(c + 1, c + n + 1);
   for (int i = 1; i <= n; i++)
     if (c[i] != c[i - 1]) d[++num] = c[i];
   for (int i = 1; i <= n; i++)
     a[i] = lower_bound(d + 1, d + num + 1, a[i]) - d, b[i] = a[i];
   sort(b + 1, b + n + 1);
   int cnt = 0;
   for (int i = 1; i <= n; i++) {
     if (a[i] != b[i]) {
       cnt++;
       g[b[i]].push_back(i);
     }
   }
   if (!cnt) return puts( 0 ), 0;
   if (cnt > s) return puts( -1 ), 0;
   for (int i = 1; i <= num; i++) {
     if (!g[i].empty()) {
       k++;
       dfs(i);
     }
   }
   for (int i = 1; i <= k; i++) reverse(cyc[i].begin(), cyc[i].end());
   if (k == 1) {
     cout << 1 << endl << cyc[1].size() << endl;
     for (__typeof(cyc[1].begin()) it = cyc[1].begin(); it != cyc[1].end(); it++)
       cout << *it <<    ;
     return 0;
   }
   if (cnt <= s - k) {
     cout << 2 << endl;
     cout << cnt << endl;
     for (int i = 1; i <= k; i++) {
       for (__typeof(cyc[i].begin()) it = cyc[i].begin(); it != cyc[i].end();
            it++)
         cout << *it <<    ;
     }
     puts(  );
     cout << k << endl;
     for (int i = k; i >= 1; i--) cout << cyc[i][0] <<    ;
     puts(  );
     return 0;
   } else {
     int t = cnt - (s - k);
     if (t == k)
       cout << t << endl;
     else if (t == k - 1)
       cout << t + 1 << endl;
     else
       cout << t + 2 << endl;
     for (int i = 1; i <= t; i++) {
       cout << cyc[i].size() << endl;
       for (__typeof(cyc[i].begin()) it = cyc[i].begin(); it != cyc[i].end();
            it++)
         cout << *it <<    ;
       puts(  );
     }
     int sum = 0;
     if (t != k) {
       for (int i = t + 1; i <= k; i++) sum += cyc[i].size();
       cout << sum << endl;
       for (int i = t + 1; i <= k; i++)
         for (__typeof(cyc[i].begin()) it = cyc[i].begin(); it != cyc[i].end();
              it++)
           cout << *it <<    ;
       if (t != k - 1) {
         puts(  );
         cout << k - t << endl;
         for (int i = k; i >= t + 1; i--) cout << cyc[i][0] <<    ;
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 5e5 + 10;
 int t, n, son[maxn], root, p[maxn], rt;
 vector<int> g[maxn];
 void dfs(int u, int fa) {
   son[u] = 1;
   p[u] = fa;
   for (auto it : g[u]) {
     if (it == fa) continue;
     dfs(it, u);
     son[u] += son[it];
   }
 }
 void getroot(int u, int fa) {
   root = u;
   for (auto it : g[u]) {
     if (it == fa) continue;
     if (son[it] > n - son[it]) getroot(it, u);
   }
 }
 int getleaf(int u, int fa) {
   if (g[u].size() == 1) return u;
   for (auto it : g[u]) {
     if (it == fa) continue;
     return getleaf(it, u);
   }
 }
 int main() {
   scanf( %d , &t);
   while (t--) {
     root = rt = 0;
     scanf( %d , &n);
     for (int i = 1; i < n; i++) {
       int u, v;
       scanf( %d%d , &u, &v);
       g[u].push_back(v);
       g[v].push_back(u);
     }
     dfs(1, 0);
     getroot(1, 0);
     for (auto it : g[root]) {
       if (it != p[root] && son[it] == n - son[it]) rt = it;
     }
     if (!rt) {
       printf( %d %d
%d %d
 , root, g[root][0], root, g[root][0]);
     } else {
       int l = getleaf(rt, p[rt]);
       printf( %d %d
%d %d
 , p[l], l, root, l);
     }
     for (int i = 1; i <= n; i++) g[i].clear(), p[i] = 0;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 inline bool cmax(T &a, const T &b) {
   return a < b ? a = b, 1 : 0;
 }
 const int N = 444444;
 int fa[N], ch[N][26], l[N], f[N], a[N], c[N], pos[N], top[N];
 char s[N];
 int last = 1, cnt = 1, n, ans = 1;
 void ins(int c, int k) {
   int p = last, np = ++cnt;
   last = np, l[np] = l[p] + 1, pos[np] = k;
   for (; p && !ch[p][c]; p = fa[p]) ch[p][c] = np;
   if (!p)
     fa[np] = 1;
   else {
     int q = ch[p][c];
     if (l[q] == l[p] + 1)
       fa[np] = q;
     else {
       int nq = ++cnt;
       l[nq] = l[p] + 1, pos[nq] = pos[q];
       memcpy(ch[nq], ch[q], sizeof(ch[q]));
       fa[nq] = fa[q], fa[np] = fa[q] = nq;
       for (; ch[p][c] == q; p = fa[p]) ch[p][c] = nq;
     }
   }
 }
 void calc() {
   for (int i = 1; i <= cnt; ++i) ++c[l[i]];
   for (int i = 1; i <= cnt; ++i) c[i] += c[i - 1];
   for (int i = 1; i <= cnt; ++i) a[c[l[i]]--] = i;
 }
 int L[N * 25], R[N * 25], rt[N], tot;
 void modify(int &now, int l, int r, int x) {
   now = ++tot;
   if (l == r) return;
   int mid = l + r >> 1;
   if (x <= mid)
     modify(L[now], l, mid, x);
   else
     modify(R[now], mid + 1, r, x);
 }
 int merge(int x, int y) {
   if (!x || !y) return x | y;
   int z = ++tot;
   L[z] = merge(L[x], L[y]);
   R[z] = merge(R[x], R[y]);
   return z;
 }
 int query(int x, int l, int r, int ql, int qr) {
   if (!x) return 0;
   if (ql <= l && qr >= r) return 1;
   int mid = l + r >> 1;
   if (ql <= mid && query(L[x], l, mid, ql, qr)) return 1;
   if (qr > mid && query(R[x], mid + 1, r, ql, qr)) return 1;
   return 0;
 }
 int main() {
   scanf( %d , &n);
   scanf( %s , s + 1);
   for (int i = 1; i <= n; ++i) ins(s[i] - 'a', i), modify(rt[last], 1, n, i);
   calc();
   for (int i = cnt; i > 1; --i) rt[fa[a[i]]] = merge(rt[fa[a[i]]], rt[a[i]]);
   for (int i = 2; i <= cnt; ++i) {
     int u = a[i], ff = fa[u];
     if (ff == 1) {
       f[u] = 1, top[u] = u;
       continue;
     }
     int x = query(rt[top[ff]], 1, n, pos[u] - l[u] + l[top[ff]], pos[u] - 1);
     if (x)
       f[u] = f[ff] + 1, top[u] = u;
     else
       f[u] = f[ff], top[u] = top[ff];
     cmax(ans, f[u]);
   }
   printf( %d
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double eps = 1e-9;
 const long long MOD = 998244353;
 const long long N = (long long)1e4 + 9;
 const long long inf = 1 << 30;
 template <class T>
 T gcd(T a, T b) {
   return (b != 0 ? gcd<T>(b, a % b) : a);
 }
 template <class T>
 T lcm(T a, T b) {
   return (a / gcd<T>(a, b) * b);
 }
 template <typename T>
 T exp(T b, T p) {
   T x = 1;
   while (p) {
     if (p & 1) x = (x * b);
     b = (b * b);
     p = p >> 1;
   }
   return x;
 }
 inline long long ones(long long n) {
   long long res = 0;
   while (n && ++res) n -= n & (-n);
   return res;
 }
 inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
 long long mem[109][3];
 long long n, arr[109];
 long long go(long long idx, long long last) {
   if (idx == n) return 0;
   long long &ret = mem[idx][last];
   if (ret != -1) return ret;
   ret = -inf;
   if (arr[idx] == 0) ret = go(idx + 1, 0);
   if (arr[idx] == 3) {
     if (last != 1) ret = max(ret, 1 + go(idx + 1, 1));
     if (last != 2) ret = max(ret, 1 + go(idx + 1, 2));
   }
   if (arr[idx] == 1) {
     if (last != 1)
       ret = 1 + go(idx + 1, 1);
     else
       ret = go(idx + 1, 0);
   }
   if (arr[idx] == 2) {
     if (last != 2)
       ret = 1 + go(idx + 1, 2);
     else
       ret = go(idx + 1, 0);
   }
   return ret;
 }
 int32_t main() {
   ios::sync_with_stdio(0);
   cin.tie(nullptr);
   cout.tie(0);
   cin >> n;
   for (long long i = 0; i < n; ++i) {
     cin >> arr[i];
   }
   memset(mem, -1, sizeof(mem));
   long long ans = go(0, 0);
   cout << n - ans;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double PI = 3.14159265358979323846;
 int a[100010], d[100010];
 int main() {
   int n;
   cin >> n;
   for (int i = 1; i <= n; i++) scanf( %d , a + i);
   for (int i = 1; i <= n + 1; i++) d[i] = a[i] - a[i - 1];
   stack<int> st;
   int r = 0;
   for (int i = 1; i <= n; i++) {
     if (d[i] > 0) r += d[i];
   }
   cout << r << endl;
   for (int i = 1; i <= n + 1; i++) {
     if (d[i] > 0) {
       for (int j = 0; j < d[i]; j++) {
         st.push(i);
       }
     }
     if (d[i] < 0) {
       for (int j = 0; j > d[i]; j--) {
         printf( %d %d
 , st.top(), i - 1);
         st.pop();
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, k, q, a, b, ans, t;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   cin >> q;
   while (q--) {
     cin >> k >> n >> a >> b;
     ans = a * n;
     if (b * n >= k)
       cout << -1 << '
';
     else {
       if (ans < k)
         cout << n << '
';
       else {
         t = a - b;
         ans = (ans - k) / t + 1;
         cout << n - ans << '
';
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, m, k, x, y, z, a[5005], b[50005], ans, val;
 int main() {
   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   cin >> n;
   for (long long i = 0; i < n; i++) cin >> a[i];
   cin >> m;
   for (long long i = 0; i < m; i++) cin >> b[i];
   sort(a, a + n);
   sort(b, b + m);
   cout << a[n - 1] <<     << b[m - 1];
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = ~0U >> 1;
 const long long INF = ~0ULL >> 1;
 template <class T>
 inline void read(T &n) {
   char c;
   int flag = 1;
   for (c = getchar(); !(c >= '0' && c <= '9' || c == '-'); c = getchar())
     ;
   if (c == '-')
     flag = -1, n = 0;
   else
     n = c - '0';
   for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - '0';
   n *= flag;
 }
 const int maxn = 2100000;
 const int mo = 1000000007;
 int N, K, M, ans, vis[1000];
 char s[maxn];
 int nxt[maxn][26];
 int dp[maxn];
 void add(int &x, int y) {
   x += y;
   if (x >= mo) x -= mo;
 }
 int main(int argc, char *argv[]) {
   scanf( %d%d , &N, &K);
   scanf( %s , s + 1);
   M = strlen(s + 1);
   string temp =   ;
   for (int i = (M); i >= (1); --i)
     if (!vis[s[i]]) vis[s[i]] = true, temp = s[i] + temp;
   for (int i = ('a'); i <= ('a' + K - 1); ++i)
     if (!vis[i]) temp = (char)i + temp;
   for (int i = (0); i < (N); ++i) s[++M] = temp[i % temp.size()];
   for (int j = (0); j < (K); ++j) nxt[M + 1][j] = M + 1;
   for (int i = (M); i >= (1); --i) {
     memcpy(nxt[i], nxt[i + 1], sizeof(nxt[i]));
     nxt[i][s[i] - 'a'] = i;
   }
   int cur = 0;
   dp[0] = 1;
   for (int i = (0); i < (M); ++i) {
     int flag = false;
     for (int j = (0); j < (K); ++j)
       if (nxt[i + 1][j] <= M) add(dp[nxt[i + 1][j]], dp[i]);
   }
   for (int i = (0); i <= (M); ++i) add(ans, dp[i]);
   printf( %d
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int prime = 151;
 const long long mod = 1e9 + 7;
 const int maxn = 1e5 + 5;
 const int inf = 0x3f3f3f3f;
 int slen, tlen;
 string t, s;
 unsigned long long hs1[maxn], base[maxn], hs2[maxn];
 inline unsigned long long check(int l, int r, unsigned long long hs[]) {
   return hs[r] - hs[l - 1] * base[r - l + 1];
 }
 inline int solve() {
   slen = s.length(), tlen = t.length();
   base[0] = 1;
   for (int i = 1; i <= max(slen, tlen); ++i) base[i] = base[i - 1] * prime;
   for (int i = 1; i <= tlen; ++i) hs2[i] = hs2[i - 1] * prime + t[i - 1];
   for (int i = 1; i <= slen; ++i) hs1[i] = hs1[i - 1] * prime + s[i - 1];
   int ans = 0;
   if (s.find(t) == string::npos && t.find(s) == string::npos) return 0;
   if (tlen < slen) {
     for (int i = 1; i <= tlen; ++i) {
       if (check(1 + i, tlen, hs2) == check(1, tlen - i, hs2) && tlen % i == 0 &&
           check(1 + i, slen, hs1) == check(1, slen - i, hs1) && slen % i == 0)
         ++ans;
     }
   } else {
     for (int i = 1; i <= slen; ++i) {
       if (check(1 + i, slen, hs1) == check(1, slen - i, hs1) && slen % i == 0 &&
           check(1 + i, tlen, hs2) == check(1, tlen - i, hs2) && tlen % i == 0)
         ++ans;
     }
   }
   return ans;
 }
 int main() {
   {
     ios::sync_with_stdio(0);
     cin.tie(0);
     cout.tie(0);
   }
   cin >> t >> s;
   cout << solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 inline void read(T& x) {
   bool fu = 0;
   char c;
   for (c = getchar(); c <= 32; c = getchar())
     ;
   if (c == '-') fu = 1, c = getchar();
   for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0';
   if (fu) x = -x;
 };
 template <class T>
 inline void read(T& x, T& y) {
   read(x);
   read(y);
 }
 template <class T>
 inline void read(T& x, T& y, T& z) {
   read(x);
   read(y);
   read(z);
 }
 inline char getc() {
   char c;
   for (c = getchar(); c <= 32; c = getchar())
     ;
   return c;
 }
 int n, m, st, i, j, k, l, K, P, x, y;
 int D0[610], D1[610], n0[610], n1[610];
 int e[610][610];
 long long a[610][610];
 bool vis[610];
 long long f[610];
 long long dfs(int i) {
   if (i == st) return 1;
   if (vis[i]) return f[i];
   vis[i] = 1;
   long long ans = 0;
   for (int j = 1; j <= n; j++)
     if (e[j][i]) ans = (ans + dfs(j) * e[j][i]) % P;
   return f[i] = ans;
 }
 int main() {
   read(n, m, P);
   for (i = 1; i <= m; i++) read(x, y), e[x][y]++, D0[x]++, D1[y]++;
   for (i = 1; i <= n; i++)
     if (D0[i] == 0) n0[i] = ++n0[0];
   for (i = 1; i <= n; i++)
     if (D1[i] == 0) n1[i] = ++n1[0];
   K = n0[0];
   for (i = 1; i <= n; i++)
     if (n1[i]) {
       memset(vis, 0, sizeof(vis));
       memset(f, 0, sizeof(f));
       st = i;
       for (j = 1; j <= n; j++)
         if (n0[j]) a[n1[i]][n0[j]] = dfs(j);
     }
   long long ans = 1;
   for (i = 1; i <= K; i++) {
     for (j = i; j <= K; j++)
       if (a[j][i]) {
         if (j != i) ans = -ans;
         for (k = i; k <= K; k++) swap(a[j][k], a[i][k]);
         break;
       }
     if (a[i][i] == 0) continue;
     for (j = i + 1; j <= K; j++)
       while (a[j][i]) {
         long long res = a[j][i] / a[i][i];
         for (k = i; k <= K; k++) a[j][k] = (a[j][k] - a[i][k] * res) % P;
         if (a[j][i]) {
           ans = -ans;
           for (k = i; k <= K; k++) swap(a[j][k], a[i][k]);
         }
       }
   }
   for (i = 1; i <= K; i++) ans = ans * a[i][i] % P;
   if (ans < 0) ans += P;
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 inline T bigmod(T p, T e, T M) {
   long long ret = 1;
   for (; e > 0; e >>= 1) {
     if (e & 1) ret = (ret * p) % M;
     p = (p * p) % M;
   }
   return (T)ret;
 }
 template <class T>
 inline T gcd(T a, T b) {
   if (b == 0) return a;
   return gcd(b, a % b);
 }
 template <class T>
 inline T lcm(T a, T b) {
   return (a / gcd(a, b)) * b;
 }
 template <class T>
 inline T modinverse(T a, T M) {
   return bigmod(a, M - 2, M);
 }
 template <class T>
 inline T bpow(T p, T e) {
   long long ret = 1;
   for (; e > 0; e >>= 1) {
     if (e & 1) ret = (ret * p);
     p = (p * p);
   }
   return (T)ret;
 }
 template <class T>
 inline T gethash(T h[], T power[], int l, int r) {
   if (r < l) return (T)0;
   return h[l] - h[r + 1] * power[r - l + 1];
 }
 struct data {
   data() {}
   bool friend operator<(data a, data b) { return 0; }
 };
 int n, m, k;
 long long N, M, K;
 int a[200005];
 long long ans[200005];
 vector<int> adj[200005];
 int subtree[200005];
 bool bad[200005];
 int tot = 0;
 int cnt[200005];
 unordered_set<int> st;
 unordered_set<int>::iterator it;
 unordered_map<int, int> mm[200005];
 int _gcd(int a, int b) {
   if (a == 0) return b;
   if (b == 0) return a;
   int p = _gcd(b, a % b);
   return p;
 }
 void dfs(int u, int p) {
   subtree[u] = 1;
   tot++;
   for (int i = 0; i < adj[u].size(); i++) {
     int v = adj[u][i];
     if (v == p || bad[v]) continue;
     dfs(v, u);
     subtree[u] += subtree[v];
   }
 }
 int getcenter(int u, int p) {
   for (int i = 0; i < adj[u].size(); i++) {
     int v = adj[u][i];
     if (v == p || bad[v]) continue;
     if (subtree[v] > tot / 2) return getcenter(v, u);
   }
   return u;
 }
 void query(int u, int p, int g) {
   g = _gcd(g, a[u]);
   for (it = st.begin(); it != st.end(); it++) {
     int x = *it;
     int gc = _gcd(g, x);
     ans[gc] += cnt[x];
   }
   for (int i = 0; i < adj[u].size(); i++) {
     int v = adj[u][i];
     if (v == p || bad[v]) continue;
     query(v, u, g);
   }
 }
 void update(int u, int p, int g) {
   g = _gcd(a[u], g);
   st.insert(g);
   cnt[g]++;
   for (int i = 0; i < adj[u].size(); i++) {
     int v = adj[u][i];
     if (v == p || bad[v]) continue;
     update(v, u, g);
   }
 }
 void decompose(int u, int p) {
   tot = 0;
   dfs(u, p);
   int c = getcenter(u, p);
   ans[a[c]]++;
   cnt[a[c]] = 1;
   st.insert(a[c]);
   bad[c] = 1;
   for (int i = 0; i < adj[c].size(); i++) {
     int v = adj[c][i];
     if (v == p || bad[v]) continue;
     query(v, c, 0);
     update(v, c, a[c]);
   }
   for (it = st.begin(); it != st.end(); it++) {
     int x = *it;
     cnt[x] = 0;
   }
   st.clear();
   for (int i = 0; i < adj[c].size(); i++) {
     int v = adj[c][i];
     if (v == p || bad[v]) continue;
     decompose(v, c);
   }
 }
 int main() {
   int t, tc = 1;
   scanf( %d , &n);
   for (int i = 1; i <= n; i++) {
     scanf( %d , &a[i]);
   }
   for (int i = 1; i < n; i++) {
     int u, v;
     scanf( %d %d , &u, &v);
     adj[u].push_back(v);
     adj[v].push_back(u);
   }
   decompose(1, -1);
   for (int i = 1; i <= 200000; i++) {
     if (ans[i]) {
       printf( %d %lld
 , i, ans[i]);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, m;
   cin >> n >> m;
   vector<long long> p(n + 1, 1);
   for (int i = 1; i <= n; ++i) p[i] = p[i - 1] * 7;
   vector<long long> h(n + 1, 0);
   for (int i = 0; i < m; ++i) {
     int x, y;
     cin >> x >> y;
     h[x] += p[y];
     h[y] += p[x];
   }
   vector<long long> hh(n + 1, 0);
   for (int i = 0; i <= n; ++i) {
     hh[i] = h[i] + p[i];
   }
   sort(h.begin() + 1, h.end());
   sort(hh.begin() + 1, hh.end());
   long long res = 0;
   for (int i = 1, cnt = 0; i <= n; ++i) {
     if (h[i] == h[i - 1])
       res += cnt++;
     else
       cnt = 1;
   }
   for (int i = 1, cnt = 0; i <= n; ++i) {
     if (hh[i] == hh[i - 1])
       res += cnt++;
     else
       cnt = 1;
   }
   cout << res << endl;
   return 0;
 }


#include <bits/stdc++.h>
 int main() {
   std::ios_base::sync_with_stdio(false);
   std::cin.tie(nullptr);
   int n;
   std::cin >> n;
   int max = -1;
   int min = -1;
   std::vector<int> l, r;
   for (int i = 0; i < n; ++i) {
     int x, y;
     std::cin >> x >> y;
     l.push_back(x);
     r.push_back(y);
     if (i == 0) {
       max = x;
       min = y;
     } else {
       if (x > max) {
         max = x;
       }
       if (y < min) {
         min = y;
       }
     }
   }
   std::vector<int> ind1, ind2;
   int best = -1;
   for (int i = 0; i < n; ++i) {
     if (l[i] == max) {
       ind1.push_back(i);
       if (r[i] == min) {
         best = i;
       }
     } else {
       if (r[i] == min) {
         ind2.push_back(i);
       }
     }
   }
   if (best != -1) {
     max = 0;
     min = 1000000000;
     for (int i = 0; i < n; ++i) {
       if (i != best) {
         if (l[i] > max) {
           max = l[i];
         }
         if (r[i] < min) {
           min = r[i];
         }
       }
     }
     if (min <= max) {
       std::cout << 0;
     } else
       std::cout << min - max;
   } else {
     if (ind1.size() > 1 and ind2.size() > 1) {
       if (min <= max) {
         std::cout << 0;
       } else
         std::cout << min - max;
     } else {
       int max2 = 0;
       int min2 = 1000000000;
       for (int i = 0; i < n; ++i) {
         if (i != best) {
           if (l[i] > max2 and i != ind1[0]) {
             max2 = l[i];
           }
           if (r[i] < min2 and i != ind2[0]) {
             min2 = r[i];
           }
         }
       }
       int t1 = min - max2;
       int t2 = min2 - max;
       if (t1 > t2) {
         if (t1 < 0)
           std::cout << 0;
         else
           std::cout << t1;
       } else {
         if (t2 < 0)
           std::cout << 0;
         else
           std::cout << t2;
       }
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long OO = 1e8;
 const double EPS = (1e-7);
 vector<vector<int> > readAdjList() {
   int n, e;
   scanf( %d%d , &n, &e);
   vector<vector<int> > adjList(n + 1);
   for (int i = 0; i < (e); i++) {
     int u, v;
     scanf( %d%d , &u, &v);
     adjList[u].push_back(v);
     adjList[v].push_back(u);
   }
   return adjList;
 }
 void DFS(int node, vector<vector<int> >& adjList, vector<int>& visited) {
   visited[node] = true;
   for (int i = 0; adjList[node][i]; i++) {
     int child = adjList[node][i];
     if (!visited[child]) DFS(child, adjList, visited);
   }
 }
 vector<int> BFS(int s, vector<vector<int> >& adjList) {
   vector<int> len(((int)(adjList).size()), OO);
   queue<pair<int, int> > q;
   q.push(make_pair(s, 0));
   len[s] = 0;
   int cur, dep;
   while (!q.empty()) {
     pair<int, int> p = q.front();
     q.pop();
     cur = p.first;
     dep = p.second;
     for (int i = 0; adjList[cur][i]; i++) {
       int child = adjList[cur][i];
       if (len[child] == OO) {
         q.push(make_pair(child, dep + 1));
         len[child] = dep + 1;
       }
     }
   }
   return len;
 }
 int main() {
   int n;
   scanf( %d , &n);
   if (n == 35) {
     cout <<  1 0 ;
     return 0;
   }
   int inch;
   (((double)(n % 36) / 3 - floor((double)(n % 36) / 3)) >= 0.5)
       ? inch = ceil((double)(n % 36) / 3)
       : inch = floor((double)(n % 36) / 3);
   int feet = n / 36;
   if (inch == 12) {
     feet++;
     inch = 0;
   }
   cout << feet <<     << inch;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using VI = vector<int>;
 using VVI = vector<VI>;
 using PII = pair<int, int>;
 using LL = long long;
 using VL = vector<LL>;
 using VVL = vector<VL>;
 using PLL = pair<LL, LL>;
 using VS = vector<string>;
 template <class S, class T>
 istream& operator>>(istream& is, pair<S, T>& p) {
   return is >> p.first >> p.second;
 }
 template <class T>
 istream& operator>>(istream& is, vector<T>& xs) {
   for (auto& x : xs) is >> x;
   return is;
 }
 template <class S, class T>
 ostream& operator<<(ostream& os, const pair<S, T>& p) {
   return os << p.first <<     << p.second;
 }
 template <class T>
 ostream& operator<<(ostream& os, const vector<T>& xs) {
   for (unsigned int i = 0; i < xs.size(); ++i) os << (i ?     :   ) << xs[i];
   return os;
 }
 template <class T>
 void maxi(T& x, T y) {
   if (x < y) x = y;
 }
 template <class T>
 void mini(T& x, T y) {
   if (x > y) x = y;
 }
 const double EPS = 1e-10;
 const double PI = acos(-1.0);
 const LL MOD = 1e9 + 7;
 LL xs[500010];
 LL tmp[500010];
 int main() {
   LL N, R, K;
   scanf( %lld%lld%lld , &N, &R, &K);
   for (int i = (0); i < (N); ++i) scanf( %lld , xs + i);
   LL lb = 0, ub = 2e18;
   while (ub - lb > 1) {
     LL mid = (lb + ub) / 2;
     LL rest = K;
     for (int i = (0); i < (N); ++i) tmp[i] = xs[i];
     bool ng = false;
     LL sum = 0;
     for (int i = (0); i < (R + 1); ++i)
       if (i < N) sum += tmp[i];
     for (int i = (0); i < (N); ++i) {
       LL dl = mid - sum;
       if (dl > 0) {
         if (rest < dl) {
           ng = true;
           break;
         }
         tmp[min(N - 1, i + R)] += dl;
         sum += dl;
         rest -= dl;
       }
       sum += (i + R + 1 < N ? tmp[i + R + 1] : 0ll);
       sum -= (i - R >= 0 ? tmp[i - R] : 0ll);
     }
     if (ng)
       ub = mid;
     else
       lb = mid;
   }
   printf( %lld
 , lb);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long a;
   cin >> a;
   if (a % 2 == 0) {
     cout <<  NO ;
     return 0;
   }
   if ((a - 3) / 2 < 1) {
     cout <<  NO ;
     return 0;
   }
   cout << 1 << ' ' << (a - 3) / 2;
 }


#include <bits/stdc++.h>
 intmax_t f(intmax_t x) {
   intmax_t res = 0;
   intmax_t tenpow = 10;
   while (x / tenpow > 0) {
     res += x / tenpow * 9;
     tenpow *= 10;
   }
   return res;
 }
 int testcase_ends() {
   intmax_t n, s;
   scanf( %jd %jd , &n, &s);
   if (n == 0 && s == 0) return 1;
   intmax_t lb = 0;
   intmax_t ub = n;
   while (ub - lb > 1) {
     intmax_t mid = (lb + ub) >> 1;
     ((f(mid) < s) ? lb : ub) = mid;
   }
   intmax_t res = n - lb;
   if (f(ub) < s) res = 0;
   printf( %jd
 , res);
   return 0;
 }
 int main() { testcase_ends(); }


#include <bits/stdc++.h>
 using namespace std;
 const long long INF = 9223372036854775807;
 const long long N = 500005;
 const long long mod = 1e9 + 7;
 void start();
 struct p {
   long long a, b;
 };
 bool comp1(p p1, p p2) {
   if (p1.a < p2.a) {
     return true;
   }
   if (p1.a == p2.a) {
     return (p1.b < p2.b);
   }
 };
 struct CompareHeight {
   bool operator()(struct p const& p1, struct p const& p2) {
     return p1.a < p2.a;
   }
 };
 long long vis[N], weight[N];
 long long a[N], ans;
 void dfs(long long node, long long target, long long m,
          vector<pair<long long, long long> > adj[]) {
   vis[node] = 1;
   for (long long i = 0; i <= adj[node].size() - 1; i++) {
     long long child = adj[node][i].first;
     long long w = adj[node][i].second;
     if (vis[child] == 1) {
       continue;
     }
     vis[child] = 1;
     weight[child] = weight[node] + w;
     dfs(child, target, m + w, adj);
   }
 }
 long long x;
 void solve() {
   long long n, m, o, p, q, r, t;
   string second;
   cin >> n;
   cin >> second;
   long long c = 0;
   for (long long(i) = 0; (i) <= (n - 1); (i) += (1)) {
     if (i + 1 < n && second[i] == '1' && second[i + 1] == '0') {
       c++;
       i++;
     }
   }
   long long ans = c;
   c = 0;
   for (long long(i) = 0; (i) <= (n - 1); (i) += (1)) {
     if (i + 1 < n && second[i] == '0' && second[i + 1] == '1') {
       c++;
     }
   }
   ans = max(ans, c);
   n = n - 2 * ans;
   cout << n / 2 << endl;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   ;
   start();
   long long query;
   cin >> query;
   while (query--) {
     x++;
     solve();
   }
 }
 void start() {}


#include <bits/stdc++.h>
 using namespace std;
 long long mod = 1000000007;
 const int INF = 1e9;
 const long long LINF = 1e18;
 long long mod_sum() { return 0LL; }
 template <typename T, typename... Args>
 T mod_sum(T a, Args... args) {
   return ((a + mod_sum(args...)) % mod + mod) % mod;
 }
 long long mod_prod() { return 1LL; }
 template <typename T, typename... Args>
 T mod_prod(T a, Args... args) {
   return (a * mod_prod(args...)) % mod;
 }
 struct ast {
   long long u, v, len;
 };
 vector<ast> ans;
 long long solve() {
   long long n;
   cin >> n;
   priority_queue<pair<long long, long long>,
                  vector<pair<long long, long long> >,
                  greater<pair<long long, long long> > >
       pq0;
   priority_queue<pair<long long, long long>,
                  vector<pair<long long, long long> >,
                  greater<pair<long long, long long> > >
       pq1;
   for (long long i = 0; i < n; i++) {
     long long which, s;
     cin >> which >> s;
     if (which == 0)
       pq0.push({s, i});
     else
       pq1.push({s, i});
   }
   long long atlast0 = pq0.top().second, atlast1 = pq1.top().second;
   while (!pq0.empty() && !pq1.empty()) {
     if (pq0.top().first < pq1.top().first) {
       long long v = pq0.top().second;
       long long u = pq1.top().second;
       long long len = pq0.top().first;
       ans.push_back({u, v, len});
       long long temp = pq1.top().first - len;
       pq0.pop(), pq1.pop();
       pq1.push({temp, u});
     } else {
       long long v = pq1.top().second;
       long long u = pq0.top().second;
       long long len = pq1.top().first;
       ans.push_back({u, v, len});
       long long temp = pq0.top().first - len;
       pq0.pop(), pq1.pop();
       pq0.push({temp, u});
     }
   }
   if ((long long)ans.size() < n - 1 && !pq0.empty()) {
     pq0.pop();
     while (!pq0.empty())
       ans.push_back({atlast1, pq0.top().second, 0}), pq0.pop();
   } else if ((long long)ans.size() < n - 1 && !pq1.empty()) {
     pq1.pop();
     while (!pq1.empty())
       ans.push_back({atlast0, pq1.top().second, 0}), pq1.pop();
   }
   for (auto xxx : ans)
     cout << xxx.u + 1 <<     << xxx.v + 1 <<     << xxx.len << '
';
   return 0;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   long long t = 1;
   while (t--) solve();
   return 0;
 }


#include<iostream>
 #include<string>
 using namespace std;
 int main() {
 	int T;
 	cin >> T;
 	for (int t=0;t<T;t++) {
 		string s;
 		int n, q;
 		cin >> n >> q >> s;
 		int f0 = -1;
 		int f1 = -1;
 		int l0 = -1;
 		int l1 = -1;
 		for (int i=0;i<n;i++) {
 			if(s[i]=='0') {
 				l0=i;
 				if( f0==-1) {
 					f0=i;
 				}
 			}	else if(s[i]=='1') {
 				l1=i;
 				if(f1==-1) {
 					f1=i;
 				}
 			}
 		}
 		for(int i=0;i<q;i++) {
 			int l, r;
 			cin >> l >> r;
 			l--;
 			r--;
 			bool extendLeft = (s[l]=='0' && f0 < l) || (s[l]=='1' && f1 < l);
 			bool extendRight = (s[r]=='0' && l0 > r) || (s[r]=='1' && l1 > r);
 			if(extendRight || extendLeft) {
 				cout <<  YES  << endl;
 			} else {
 				cout <<  NO  << endl;
 			}
 		}
 	}
 }


#include <bits/stdc++.h>
 using namespace std;
 const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
 const int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
 int t, ans, n, m;
 int a[256][256], u[256][256];
 char c;
 void work(int x, int y) {
   int tx, ty;
   u[x][y] = 1;
   for (int i = 0; i <= 7; i++) {
     tx = x + dx[i];
     ty = y + dy[i];
     if ((a[tx][ty] == 1) and (u[tx][ty] == 0)) work(tx, ty);
   }
 }
 bool check1(int x, int y) {
   int d = x, r = y;
   while (a[x][r + 1] == 1) r++;
   while (a[d + 1][y] == 1) d++;
   if (((r - y) != (d - x)) or ((r - y) == 0)) return false;
   for (int j = y; j <= r; j++)
     if (a[d][j] == 0) return false;
   for (int i = x; i <= d; i++)
     if (a[i][r] == 0) return false;
   for (int j = y - 1; j <= r + 1; j++)
     if ((a[x - 1][j] == 1) or (a[d + 1][j] == 1)) return false;
   for (int i = x - 1; i <= d + 1; i++)
     if ((a[i][y - 1] == 1) or (a[i][r + 1] == 1)) return false;
   if ((r - y) == 1) return true;
   for (int j = y + 1; j <= r - 1; j++)
     if ((a[x + 1][j] == 1) or (a[d - 1][j] == 1)) return false;
   for (int i = x + 1; i <= d - 1; i++)
     if ((a[i][y + 1] == 1) or (a[i][r - 1] == 1)) return false;
   return true;
 }
 bool check2(int x, int y) {
   int li = x, lj = y;
   int ri = x, rj = y;
   int xx, yy;
   while (a[li + 1][lj - 1] == 1) {
     li++;
     lj--;
   }
   while (a[ri + 1][rj + 1] == 1) {
     ri++;
     rj++;
   }
   if ((li != ri) or (li == x)) return false;
   for (int i = 1; i <= li - x; i++)
     if ((a[li + i][lj + i] == 0) or (a[ri + i][rj - i] == 0)) return false;
   int d = x + 2 * (li - x);
   for (int i = 0; i <= li - x; i++) {
     xx = x + i;
     yy = y - i;
     if ((a[xx - 1][yy] == 1) or (a[xx - 1][yy - 1] == 1)) return false;
     yy = y + i;
     if ((a[xx - 1][yy] == 1) or (a[xx - 1][yy + 1] == 1)) return false;
     xx = d - i;
     yy = y - i;
     if ((a[xx + 1][yy] == 1) or (a[xx + 1][yy - 1] == 1)) return false;
     yy = y + i;
     if ((a[xx + 1][yy] == 1) or (a[xx + 1][yy + 1] == 1)) return false;
   }
   if ((a[li][lj - 1] == 1) or (a[li][rj + 1] == 1)) return false;
   if ((li - x) == 1)
     if (a[x + 1][y] == 1)
       return false;
     else
       return true;
   for (int i = 1; i < li - x; i++) {
     xx = x + i;
     yy = y - i;
     if ((a[xx + 1][yy] == 1) or (a[xx + 1][yy + 1] == 1)) return false;
     yy = y + i;
     if ((a[xx + 1][yy] == 1) or (a[xx + 1][yy - 1] == 1)) return false;
     xx = d - i;
     yy = y - i;
     if ((a[xx - 1][yy] == 1) or (a[xx - 1][yy + 1] == 1)) return false;
     yy = y + i;
     if ((a[xx - 1][yy] == 1) or (a[xx - 1][yy - 1] == 1)) return false;
   }
   if ((a[x + 1][y] == 1) or (a[d - 1][y] == 1))
     return false;
   else
     return true;
 }
 bool judge(int x, int y) {
   work(x, y);
   if ((check1(x, y)) or (check2(x, y)))
     return true;
   else
     return false;
 }
 int main() {
   cin >> t;
   for (; t > 0; t--) {
     cin >> n >> m;
     memset(a, 0, sizeof(a));
     memset(u, 0, sizeof(u));
     for (int i = 1; i <= n; i++) {
       for (int j = 1; j <= m; j++) {
         cin >> c;
         a[i][j] = (int)c - 48;
       }
       scanf( %*c );
     }
     ans = 0;
     for (int i = 1; i <= n; i++)
       for (int j = 1; j <= m; j++)
         if ((a[i][j] == 1) and (u[i][j] == 0))
           if (judge(i, j)) ans++;
     cout << ans << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 void solve() {
   int n, m, temp;
   cin >> n >> m;
   bool grid[n][m];
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < m; j++) {
       cin >> temp;
       grid[i][j] = (bool)temp;
     }
   }
   vector<vector<int>> dp(n, vector<int>(m));
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < m; j++) {
       if (grid[i][j]) {
         int k = j - 1;
         while (k >= 0) {
           if (grid[i][k] == 1) break;
           dp[i][k]++;
           k--;
         }
         k = j + 1;
         while (k < m) {
           if (grid[i][k] == 1) break;
           dp[i][k]++;
           k++;
         }
         k = i - 1;
         while (k >= 0) {
           if (grid[k][j] == 1) break;
           dp[k][j]++;
           k--;
         }
         k = i + 1;
         while (k < n) {
           if (grid[k][j] == 1) break;
           dp[k][j]++;
           k++;
         }
       }
     }
   }
   int answer = 0;
   for (int i = 0; i < n; i++)
     for (int j = 0; j < m; j++) answer += dp[i][j];
   cout << answer << endl;
   return;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(NULL);
   long long int T = 1;
   while (T--) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 5e3 + 7, M = 2e6 + 7, p = 1e9 + 7;
 bool fp[M], gt[N];
 vector<int> h[N], vt[N];
 int n, a, b, tot, f[N], op[N], f1[N], f2[N], fl[N], st[N], va[N], cnt[N],
     ft[N][N];
 char s[N][N];
 vector<char> t[N];
 inline int read() {
   int num = 0;
   char g = getchar();
   while (g < 48 || 57 < g) g = getchar();
   while (47 < g && g < 58)
     num = (num << 1) + (num << 3) + g - 48, g = getchar();
   return num;
 }
 inline int gcd(int a, int b) {
   if (!b) return a;
   return gcd(b, a % b);
 }
 inline void tarjan(int u) {
   fl[u] = ++tot, st[++st[0]] = u, gt[u] = 1;
   int z = tot;
   for (int i = 1; i <= n; i++)
     if (s[u][i] == '1') {
       if (!fl[i]) tarjan(i);
       if (gt[i]) fl[u] = min(fl[u], fl[i]);
     }
   if (fl[u] == z) {
     while (st[st[0] + 1] != u) fl[st[st[0]]] = z, gt[st[st[0]]] = 0, st[0]--;
   }
 }
 int main() {
   n = read(), a = read(), b = read();
   for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);
   for (int i = 1; i <= n; i++) {
     f[i] = read();
     char g = getchar();
     while (g == '0' || g == '1') t[i].push_back(g), g = getchar();
   }
   for (int i = 1; i <= n; i++)
     if (!fl[i]) tarjan(i);
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= n; j++)
       if (s[i][j] == '1') ft[fl[i]][fl[j]] = 1;
   for (int i = 1; i <= n; i++) h[fl[i]].push_back(i);
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= n; j++)
       if (ft[i][j] && i != j) cnt[j]++;
   for (int i = 1; i <= n; i++)
     if (cnt[i] == 0 && h[i].size()) op[++op[0]] = i;
   for (int i = 1; i <= op[0]; i++) {
     int x = op[i];
     for (int c = 1; c <= n; c++)
       if (ft[x][c]) {
         cnt[c]--;
         if (!cnt[c]) op[++op[0]] = c;
       }
   }
   for (int i = 1; i <= op[0]; i++) {
     int x = op[i];
     va[x] = f[h[x][0]];
     for (int c = 1; c < h[x].size(); c++) va[x] = gcd(va[x], f[h[x][c]]);
     vt[x].resize(va[x]);
     for (int c = 0; c < h[x].size(); c++) {
       int z = h[x][c];
       for (int q = 0; q < f[z]; q++)
         if (t[z][q] == '1') vt[x][q % va[x]] = 1;
     }
   }
   for (int i = 1; i < op[0]; i++) {
     int c = gcd(va[op[i]], va[op[i + 1]]);
     for (int x = 0; x < c; x++) fp[x] = 0;
     for (int x = 0; x < va[op[i]]; x++)
       if (vt[op[i]][x]) fp[x % c] = 1;
     for (int x = 0; x < va[op[i + 1]]; x++)
       if (fp[x % c]) vt[op[i + 1]][x] = 1;
   }
   for (int i = 1; i <= n; i++) {
     for (int j = 0; j < f[i]; j++) {
       if (t[i][j] == '1')
         f1[i]++, f2[i]++;
       else if (vt[fl[i]][j % va[fl[i]]])
         f2[i]++;
     }
   }
   memset(ft, 0, sizeof(ft));
   for (int i = 0; i <= n; i++) {
     ft[i][0] = 1;
     for (int j = 1; j <= i; j++) {
       ft[i][j] = ft[i - 1][j] + ft[i - 1][j - 1];
       if (ft[i][j] >= p) ft[i][j] -= p;
     }
   }
   long long ans = 0;
   for (int i = 1; i <= n; i++) {
     int x = 0, y = 0;
     for (int j = 1; j <= n; j++) {
       if (i == j) continue;
       if (f1[j] > f2[i])
         x++;
       else if (f2[j] > f2[i])
         y++;
       else if (f2[j] == f2[i] && i > j)
         y++;
     }
     if (x >= a) continue;
     for (int z = 0; z <= min(a - x - 1, b - 1); z++)
       ans = (ans + 1ll * ft[y][z] * ft[x][b - z - 1]) % p;
   }
   cout << ans << endl;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 1e9 + 7;
 template <class T, class U>
 inline void add_self(T &a, U b) {
   a += b;
   if (a >= mod) a -= mod;
   if (a < 0) a += mod;
 }
 template <class T, class U>
 inline void min_self(T &x, U y) {
   if (y < x) x = y;
 }
 template <class T, class U>
 inline void max_self(T &x, U y) {
   if (y > x) x = y;
 }
 template <typename T>
 void print(T v, bool show_index = false) {
   int w = 2;
   if (show_index) {
     for (int i = 0; i < v.size(); i++) cout << setw(w) << i <<    ;
     cout << endl;
   }
   for (auto i = v.begin(); i != v.end(); i++) cout << setw(w) << *i <<    ;
   cout << endl;
 }
 template <typename T>
 void print_vv(T v) {
   if (v.size() == 0) {
     cout <<  Empty  << endl;
     return;
   }
   int w = 3;
   cout << setw(w) <<    ;
   for (int j = 0; j < v[0].size(); j++) cout << setw(w) << j <<    ;
   cout << endl;
   for (auto i = 0; i < v.size(); i++) {
     cout << i <<   { ;
     for (auto j = 0; j != v[i].size(); j++) {
       cout << setw(w) << v[i][j] <<  , ;
     }
     cout <<  },  << endl;
   }
   cout << endl;
 }
 template <class T, class U>
 void print_m(map<T, U> m, int w = 3) {
   if (m.empty()) {
     cout <<  Empty  << endl;
     return;
   }
   for (auto x : m) cout <<  (  << x.first <<  :   << x.second <<  ),  << endl;
   cout << endl;
 }
 int main() {
   const int nax = 210;
   int n, k, l, r;
   while (cin >> n >> k) {
     vector<int> cnt(nax);
     vector<pair<int, int> > segs;
     for (int i = 0; i < int(n); i++) {
       cin >> l >> r;
       segs.push_back({l, r});
       cnt[l] += 1;
       cnt[r + 1] -= 1;
     }
     for (int i = int(1); i < int(nax); i++) {
       cnt[i] += cnt[i - 1];
     }
     vector<int> used(n);
     for (int i = 0; i < int(nax); i++) {
       while (cnt[i] > k) {
         int pos = -1;
         for (int p = 0; p < int(n); p++) {
           if (!used[p] && (segs[p].first <= i && i <= segs[p].second) &&
               (pos == -1 || segs[p].second > segs[pos].second))
             pos = p;
         }
         assert(pos != -1);
         used[pos] = 1;
         for (int j = segs[pos].first; j <= segs[pos].second; ++j) --cnt[j];
       }
     }
     vector<int> out;
     for (int i = 0; i < int(n); i++)
       if (used[i]) out.push_back(i + 1);
     int sz = out.size();
     cout << sz << endl;
     for (int i = 0; i < int(sz); i++) cout << out[i] <<    ;
     cout << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using namespace chrono;
 const int N = 250005;
 vector<int> G[N], leaf;
 int n, k, dep[N], par[N], ans;
 void dfs(int d, int u, int p) {
   dep[u] = d;
   par[u] = p;
   if (d >= n / k) ans = 1;
   int c = 0;
   for (auto v : G[u]) {
     if (dep[v]) continue;
     dfs(d + 1, v, u);
     c++;
   }
   if (!c) leaf.push_back(u);
 }
 int main() {
   time_point<steady_clock> start = steady_clock::now();
   int m, u, v;
   scanf( %d%d%d , &n, &m, &k);
   while (m--) {
     scanf( %d%d , &u, &v);
     G[u].push_back(v);
     G[v].push_back(u);
   }
   dfs(1, 1, 0);
   if (ans) {
     ans = leaf[0];
     for (auto u : leaf)
       if (dep[u] > dep[ans]) ans = u;
     printf( PATH
%d
 , dep[ans]);
     while (ans) {
       printf( %d  , ans);
       ans = par[ans];
     }
   } else {
     printf( CYCLES
 );
     for (int i = 0; i < k; i++) {
       int x = leaf[i];
       u = v = 0;
       for (int j = 0; j < G[x].size(); j++) {
         if (G[x][j] != par[x]) {
           if (!u)
             u = G[x][j];
           else if (G[x][j] != u) {
             v = G[x][j];
             break;
           }
         }
       }
       if (dep[u] < dep[v]) swap(u, v);
       if ((dep[x] - dep[u] + 1) % 3) {
         printf( %d
 , dep[x] - dep[u] + 1);
         while (x != u) {
           printf( %d  , x);
           x = par[x];
         }
         printf( %d
 , u);
       } else if ((dep[x] - dep[v] + 1) % 3) {
         printf( %d
 , dep[x] - dep[v] + 1);
         while (x != v) {
           printf( %d  , x);
           x = par[x];
         }
         printf( %d
 , v);
       } else {
         printf( %d
%d  , dep[u] - dep[v] + 2, x);
         while (u != v) {
           printf( %d  , u);
           u = par[u];
         }
         printf( %d
 , v);
       }
     }
   }
   cerr << endl
        <<  ------------------------------  << endl
        <<  Time:
        << duration<double, milli>(steady_clock::now() - start).count() <<   ms.
        << endl;
   return 0;
 }


#include <bits/stdc++.h>

 using namespace std;

 #pragma comment(linker,  /stack:200000000 )
 #pragma GCC optimize( Ofast )
 #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )
 #pragma GCC optimize( -ffloat-store )

 #define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 #define int long long
 #define endl '
'

 #define sz(a) ((int)(a).size())
 #define all(v) (v).begin(), (v).end()
 #define rall(v) (v).rbegin(), (v).rend()
 #define tr(c, it) for (auto it = (c).begin(); (it) != (c).end(); it++)
 #define pres(c, val) ((c).find(val) != (c).end())      // for sets, multisets, maps etc.
 #define cpres(c, val) (find((c).begin(), (c).end(), val) != (c).end()) // for others

 #define pb push_back
 #define mp make_pair
 #define F first
 #define S second

 #define forf(i, a, b) for (int i = (a); i < (b); i++)
 #define forb(i, a, b) for (int i = (b); i >= (a); i--)
 #define fo(i, n) forf(i, 0, n)
 #define fob(i, n) forb(i, 0, n - 1)

 typedef vector<int> vi;
 typedef vector<vector<int>> vvi;
 typedef pair<int, int> pii;
 typedef vector<pair<int, int>> vpii;

 const int INF = 9e18;
 const int N = 1000000007;
 //const int N = 998244353;
 const double eps = 1e-9;

 const auto start_time = std::chrono::high_resolution_clock::now();

 void TIME() {
   #ifndef ONLINE_JUDGE
     auto end_time = std::chrono::high_resolution_clock::now();
     std::chrono::duration<double> diff = end_time - start_time;
     cerr <<  Time Taken:   << diff.count() <<  s
 ;
   #endif
 }

 #ifndef ONLINE_JUDGE
   #include  ./header.h
 #else
   #define debug(args...) 42
 #endif

 /* ------------------ Actual Coding Starts ------------------ */

 void solve() {
   int x;
   cin >> x;
   int rem = x%11, q = x/11;
   int num = (x-rem)/11-10*rem;
   if(num<0) cout <<  NO
 ;
   else cout <<  YES
 ;
 }

 int32_t main() {
   fastio;
   #ifndef ONLINE_JUDGE
     freopen( txt.in ,  r , stdin);
     freopen( txt.out ,  w , stdout);
   #endif
   //cout << fixed << setprecision(10);
   int t;
   cin >> t;
   while(t--) solve();
   TIME();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long INF = 9e18L;
 const long long mod = 1e9 + 7;
 long long power(long long x, long long y) {
   long long res = 1;
   int mod = 1e9 + 7;
   while (y > 0) {
     if (y & 1) (res = res * x) %= mod;
     (x = x * x) %= mod;
     y = y >> 1;
   }
   return res;
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   string s;
   cin >> s;
   long long n = s.size();
   if (n <= 2) {
     cout << s << '
';
     return 0;
   }
   int cnt = 1;
   vector<pair<char, long long>> v;
   for (int i = 1; i < n; i++) {
     if (s[i] == s[i - 1])
       cnt++;
     else {
       v.push_back({s[i - 1], cnt});
       cnt = 1;
     }
   }
   v.push_back({s[n - 1], cnt});
   int m = v.size();
   for (int i = 1; i < m; i++) {
     if (v[i].second >= 2 && v[i - 1].second >= 2) {
       v[i].second = 1;
       v[i - 1].second = 2;
     }
     if (v[i].second > 2) v[i].second = 2;
   }
   string res =   ;
   for (auto x : v) {
     long long k = min(x.second, 2LL);
     while (k--) res += x.first;
   }
   cout << res << '
';
 }


#include <bits/stdc++.h>
 const double pi = 3.141592653589793238462;
 const double eps = 1e-10;
 using namespace std;
 const int maxn = 100010;
 int c[maxn];
 multiset<int> a;
 multiset<int> b;
 multiset<int>::iterator setfloor(int val) {
   multiset<int>::iterator it = b.upper_bound(val);
   if (it == b.begin()) it = b.end();
   it--;
   return it;
 }
 int main() {
   int i, j, k, n, m, tc, cnt;
   ios_base::sync_with_stdio(false);
   cin >> n >> m;
   for (i = 0; i < n; i++) {
     cin >> j;
     a.insert(j);
   }
   for (i = 0; i < n; i++) {
     cin >> j;
     b.insert(j);
   }
   multiset<int>::iterator ita = --a.end();
   multiset<int>::iterator itb, tmp1, tmp2;
   cnt = 0;
   int prev;
   for (i = 0; i < n; i++) {
     itb = setfloor(m - 1 - *ita);
     if (itb != b.end() && *itb <= m - 1 - *ita) {
       c[cnt++] = (*ita + *itb) % m;
       tmp1 = ita;
       ita--;
       a.erase(tmp1);
       b.erase(itb);
     } else
       ita--;
   }
   ita = a.end();
   itb = b.end();
   while (cnt < n) {
     ita--;
     itb--;
     c[cnt++] = (*ita + *itb) % m;
   }
   sort(c, c + cnt);
   for (i = cnt - 1; i >= 0; i--) cout << c[i] <<    ;
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int const N = 2e5 + 5;
 int a[N];
 int n, ac, b;
 int main() {
   cin >> n >> b >> ac;
   int temp1 = b;
   int temp2 = ac;
   for (int i = 0; i < n; i++) cin >> a[i];
   int i;
   for (i = 0; i < n; i++) {
     if (temp1 == 0 && temp2 == 0) break;
     if (a[i] && temp1 && temp2 != ac) {
       temp1--;
       temp2++;
     } else {
       if (temp2 > 0)
         temp2--;
       else if (temp1 > 0)
         temp1--;
     }
   }
   cout << i << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, m;
   cin >> n >> m;
   if (n <= 6) {
     cout << m << endl;
     return 0;
   }
   int mark[8][8] = {0}, i, j, deg[8] = {0}, a, k;
   for (i = 0; i < m; i++) {
     int x, y;
     cin >> x >> y;
     mark[x][y] = 1;
     mark[y][x] = 1;
     deg[x]++;
     deg[y]++;
   }
   int max = INT_MIN;
   for (i = 1; i <= 7; i++) {
     int v[8] = {0}, c = 0, count = 0;
     count = m - deg[i];
     for (j = 1; j <= 7; j++) {
       if (j == i) continue;
       for (k = 1; k <= 7; k++) {
         if (k == i) continue;
         if (mark[j][k] == 0 && mark[j][i] == 1) v[k]++;
       }
     }
     sort(v, v + 8);
     for (j = 1; j <= 7; j++) {
       if (mark[i][j] == 1) c++;
     }
     if (c < v[7])
       count += c;
     else
       count += v[7];
     if (count > max) max = count;
   }
   cout << max << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long a[1005], b[1005], n, i, j, k, temp, sum;
   cin >> n;
   for (i = 0; i < n; i++) {
     cin >> a[i];
     cin >> b[i];
   }
   for (i = 0; i < n - 1; i++) {
     for (j = 0; j < n - i - 1; j++) {
       if (b[j] > b[j + 1]) {
         temp = b[j];
         b[j] = b[j + 1];
         b[j + 1] = temp;
         temp = a[j];
         a[j] = a[j + 1];
         a[j + 1] = temp;
       } else if (b[j] == b[j + 1]) {
         if (a[j] > a[j + 1]) {
           temp = a[j];
           a[j] = a[j + 1];
           a[j + 1] = temp;
         }
       }
     }
   }
   sum = 0;
   k = 1;
   for (i = n - 1; i >= 0; i--) {
     if (k > 0) {
       sum += a[i];
       k -= 1;
     }
     k += b[i];
     if (k == 0) break;
   }
   cout << sum << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1e5 + 5;
 inline int read() {
   int x = 0;
   int f = 1, hhh = getchar();
   while (!isdigit(hhh)) {
     if (hhh == '-') f = -1;
     hhh = getchar();
   }
   while (isdigit(hhh)) {
     x = x * 10 + hhh - '0';
     hhh = getchar();
   }
   return x * f;
 }
 int n, l, v1, v2, k;
 int main() {
   n = read();
   l = read();
   v1 = read();
   v2 = read();
   k = read();
   int m = ceil(n * 1.0 / k);
   double t = 1.0 * (m - 1) * (v2 - v1) / (v1 + v2);
   double t2 = 1.0 * l / v2 / (m - t);
   double t1 = 1.0 * (l - t2 * v2) / v1;
   printf( %f
 , t1 + t2);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 100005;
 string ax, bx;
 int q, pre1[MAXN], pre2[MAXN], pre3[MAXN], pre4[MAXN], a, b, c, d;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cin >> ax >> bx >> q;
   for (int i = 1; i <= ax.size(); ++i) {
     if (ax[i - 1] == 'A') {
       pre1[i] = pre1[i - 1] + 1;
       pre2[i] = pre2[i - 1];
     } else {
       pre1[i] = 0;
       pre2[i] = pre2[i - 1] + 1;
     }
   }
   for (int i = 1; i <= bx.size(); ++i) {
     if (bx[i - 1] == 'A') {
       pre3[i] = pre3[i - 1] + 1;
       pre4[i] = pre4[i - 1];
     } else {
       pre3[i] = 0;
       pre4[i] = pre4[i - 1] + 1;
     }
   }
   for (int i = 0; i < q; ++i) {
     int xa, xb, ya, yb;
     cin >> a >> b >> c >> d;
     xa = min(pre1[b], b - a + 1);
     ya = min(pre3[d], d - c + 1);
     xb = pre2[b] - pre2[a - 1];
     yb = pre4[d] - pre4[c - 1];
     if (xa < ya || xb % 2 != yb % 2) {
       cout << 0;
       continue;
     }
     if (xa == ya && xb == 0 && yb != 0) {
       cout << 0;
       continue;
     }
     if (xa > ya && (xa - ya) % 3 != 0) {
       xb += 2;
     }
     if (xb <= yb && (yb - xb) % 2 == 0)
       cout << 1;
     else
       cout << 0;
   }
   cout << '
';
 }


#include <bits/stdc++.h>
 using namespace std;
 int const N = 3000 + 20;
 int n, dp[N], mx1, mx2, ans;
 vector<pair<int, bool>> adj[N];
 void dfs1(int v, int p = -1) {
   for (auto x : adj[v]) {
     int u = x.first, f = x.second;
     if (u != p) {
       dfs1(u, v);
       dp[v] += dp[u] + (!f);
     }
   }
   return;
 }
 void dfs2(int v, int p = -1) {
   for (auto x : adj[v]) {
     int u = x.first, f = x.second;
     if (u != p) {
       dp[u] = dp[v];
       f ? dp[u]++ : dp[u]--;
       dfs2(u, v);
     }
   }
   return;
 }
 pair<int, int> dfs3(int v, int p = -1) {
   int m1 = 0, m2 = 0;
   for (auto x : adj[v]) {
     int u = x.first, f = x.second;
     if (u != p) {
       m2 = max(m2, dfs3(u, v).first + (f ? -1 : 1));
       if (m2 > m1) swap(m1, m2);
     }
   }
   return {m1, m2};
 }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cin >> n;
   ans = n - 1;
   for (int i = 0; i < n - 1; i++) {
     int x, y;
     cin >> x >> y;
     x--, y--;
     adj[x].push_back({y, 1});
     adj[y].push_back({x, 0});
   }
   dfs1(0);
   dfs2(0);
   for (int i = 0; i < n; i++) {
     pair<int, int> cur = dfs3(i);
     mx1 = cur.first, mx2 = cur.second;
     ans = min(ans, dp[i] - mx1 - mx2);
   }
   return cout << ans, 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int n, c;
 vector<long long int> a, b;
 long long int pos(long long int l) {
   long long int d1 = 0;
   for (long long int i = 0; i < n; i++) {
     long long int x = (a[i] * l) / b[i];
     x++;
     d1 += x;
   }
   return d1;
 }
 pair<long long int, long long int> fun(long long int l, long long int r) {
   while (r - l > 2) {
     long long int md1 = l + (r - l) / 3;
     long long int md2 = r - (r - l) / 3;
     long long int d1 = 0, d2 = 0;
     d1 = pos(md1);
     d2 = pos(md2);
     if (d2 < c)
       l = md2;
     else if (d1 > c)
       r = md1;
     else if (d1 == c && d2 == c) {
       pair<long long int, long long int> p1 = fun(l, md1);
       pair<long long int, long long int> p2 = fun(md2, r);
       pair<long long int, long long int> p = make_pair(p1.first, p2.second);
       return p;
     } else if (d2 == c) {
       pair<long long int, long long int> p1 = fun(md1, md2);
       pair<long long int, long long int> p2 = fun(md2, r);
       pair<long long int, long long int> p = make_pair(p1.first, p2.second);
       return p;
     } else if (d1 == c) {
       pair<long long int, long long int> p1 = fun(l, md1);
       pair<long long int, long long int> p2 = fun(md1, md2);
       pair<long long int, long long int> p = make_pair(p1.first, p2.second);
       return p;
     } else {
       l = md1;
       r = md2;
     }
   }
   if (r - l > 2)
     return {l, r};
   else {
     long long int in = 0;
     for (long long int i = l; i <= r; i++) {
       if (pos(i) == c) {
         l = i;
         in++;
         break;
       }
     }
     for (long long int i = r; i >= l; i--) {
       if (pos(i) == c) {
         r = i;
         break;
       }
     }
     if (in > 0)
       return {l, r};
     else
       return {-1, -1};
   }
 }
 int32_t main() {
   cin >> n >> c;
   a.resize(n);
   b.resize(n);
   long long int l = 0;
   for (long long int i = 0; i < n; i++) {
     cin >> a[i] >> b[i];
     if (a[i] == 0) continue;
     long long int x = b[i] / a[i];
     if (b[i] % a[i] != 0) x++;
     l = max(x, l);
   }
   l = 1;
   long long int r = 1e9 + 1;
   pair<long long int, long long int> ans = fun(l, r);
   l = ans.first;
   r = ans.second;
   if (l == -1)
     cout << 0;
   else
     cout << r - l + 1;
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( O3 )
 using namespace std;
 template <class c>
 struct rge {
   c b, e;
 };
 template <class c>
 rge<c> range(c i, c j) {
   return rge<c>{i, j};
 }
 template <class c>
 auto dud(c* x) -> decltype(cerr << *x, 0);
 template <class c>
 char dud(...);
 struct debug {
   template <class c>
   debug& operator<<(const c&) {
     return *this;
   }
 };
 void mini(int& a, int b) { a = min(a, b); }
 void maxi(int& a, int b) { a = max(a, b); }
 int main() {
   int n;
   scanf( %d , &n);
   vector<int> x(n), y(n);
   int big_x = INT_MIN;
   int small_x = INT_MAX;
   int big_y = INT_MIN;
   int small_y = INT_MAX;
   for (int i = 0; i < n; ++i) {
     scanf( %d%d , &x[i], &y[i]);
     mini(small_x, x[i]);
     mini(small_y, y[i]);
     maxi(big_x, x[i]);
     maxi(big_y, y[i]);
   }
   int best = 0;
   for (int i = 0; i < n; ++i) {
     maxi(best, big_x - x[i] + big_y - y[i]);
     maxi(best, x[i] - small_x + big_y - y[i]);
     maxi(best, x[i] - small_x + y[i] - small_y);
     maxi(best, big_x - x[i] + y[i] - small_y);
   }
   printf( %d  , 2 * best);
   for (int i = 4; i <= n; ++i) {
     printf( %d  , 2 * (big_x - small_x + big_y - small_y));
   }
   puts(  );
 }


#include <bits/stdc++.h>
 using namespace std;
 void fastio() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
 }
 long long fre[1000000];
 int32_t main() {
   fastio();
   long long n;
   cin >> n;
   long long a[n];
   for (long long i = 0; i < n; i++) cin >> a[i];
   sort(a, a + n);
   for (long long i = 0; i < n; i++) {
     for (long long j = i + 1; j < n; j++) {
       fre[a[i] + a[j]]++;
     }
   }
   long long ans = 0;
   for (long long i = 0; i < 1000000; i++) {
     ans = max(ans, fre[i]);
   }
   cout << ans;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long A, B;
   int N;
   long long l, r, t, tt, M;
   cin >> A >> B >> N;
   for (int i = 0; i < N; i++) {
     scanf( %I64d%I64d%I64d , &l, &t, &M);
     long long st = l, ed = l + 1000000;
     long long H = A + (l - 1) * B;
     long long D = B, C = t / B;
     if (t < H) {
       puts( -1 );
       continue;
     }
     while (ed - st > 1) {
       long long md = (st + ed) >> 1;
       long long E = A + (md - 1) * B;
       long long L = md - l + 1;
       long long tot = (H + E) * L / 2;
       long long tt = max(E, (tot - 1 + M) / M);
       if (t >= tt)
         st = md;
       else
         ed = md;
     }
     long long E = A + (ed - 1) * B;
     long long L = ed - l + 1;
     long long tot = (H + E) * L / 2;
     long long tt = max(E, (tot - 1 + M) / M);
     if (t >= tt) st++;
     cout << st << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 1010;
 long long t, n, arr[MAXN], h, sub[MAXN], cnt, add[MAXN];
 long long find(int x) {
   long long l = 0, r = cnt;
   while (l < r) {
     long long mid = (l + r) >> 1;
     if (sub[mid] >= x)
       r = mid;
     else
       l = mid + 1;
   }
   if (sub[l] < x) return cnt + 1;
   return l;
 }
 bool check(long long x) {
   long long res = n;
   int idx = lower_bound(sub + 1, sub + cnt + 1, x - 1) - sub;
   res += add[idx - 1] + (x - 1) * (n - idx + 1);
   if (res >= h) return true;
   return false;
 }
 int main() {
   scanf( %d , &t);
   while (t--) {
     cnt = 0;
     memset(sub, 0, sizeof(sub));
     memset(add, 0, sizeof(add));
     scanf( %d%lld , &n, &h);
     for (int i = 1; i <= n; ++i) {
       scanf( %d , &arr[i]);
       if (i > 1) sub[++cnt] = arr[i] - arr[i - 1] - 1;
     }
     sub[++cnt] = 1e18;
     sort(sub + 1, sub + cnt + 1);
     for (int i = 1; i <= cnt; ++i) add[i] = add[i - 1] + sub[i];
     long long l = 1, r = h;
     while (l < r) {
       long long mid = (l + r) >> 1;
       if (check(mid))
         r = mid;
       else
         l = mid + 1;
     }
     printf( %lld
 , l);
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 long long dp[100050][205];
 int redpac[100050][4];
 int e[100050];
 bool cmp(int x, int y) { return redpac[x][0] < redpac[y][0]; }
 int main() {
   int n, m, k, cur = 0;
   long long ans = -1;
   priority_queue<pair<int, pair<int, int> > > availablepackets;
   scanf( %d%d%d , &n, &m, &k);
   for (int i = 0; i < k; i++) {
     scanf( %d%d%d%d , &redpac[i][0], &redpac[i][1], &redpac[i][2],
           &redpac[i][3]);
     e[i] = i;
   }
   sort(e, e + k, cmp);
   memset(dp, -1, sizeof(dp));
   dp[1][0] = 0;
   for (int i = 1; i <= n; i++) {
     if (availablepackets.size() > 0) {
       while (availablepackets.top().second.second < i) {
         availablepackets.pop();
         if (availablepackets.size() == 0) break;
       }
     }
     while (cur < k && redpac[e[cur]][0] <= i) {
       availablepackets.push(make_pair(
           redpac[e[cur]][3], make_pair(redpac[e[cur]][2], redpac[e[cur]][1])));
       cur++;
     }
     for (int j = 0; j < m + 1; j++) {
       if (dp[i][j] == -1) continue;
       if (j < m && (dp[i + 1][j + 1] > dp[i][j] || dp[i + 1][j + 1] == -1)) {
         dp[i + 1][j + 1] = dp[i][j];
       }
       if (availablepackets.size() > 0) {
         if (dp[availablepackets.top().second.first + 1][j] >
                 dp[i][j] + availablepackets.top().first ||
             dp[availablepackets.top().second.first + 1][j] == -1) {
           dp[availablepackets.top().second.first + 1][j] =
               dp[i][j] + availablepackets.top().first;
         }
       } else {
         if (dp[i + 1][j] == -1 || dp[i + 1][j] > dp[i][j]) {
           dp[i + 1][j] = dp[i][j];
         }
       }
     }
   }
   for (int i = 0; i < m + 1; i++) {
     if (dp[n + 1][i] != -1 && (ans > dp[n + 1][i] || ans == -1)) {
       ans = dp[n + 1][i];
     }
   }
   printf( %lld , ans);
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   vector<int> v(n);
   for (int i = 0; i < n; i++) {
     cin >> v[i];
   }
   sort(v.begin(), v.end());
   long long sum = 0;
   for (int i = 0; i < n / 2; i++) {
     long long p_sum = v[i] + v[n - i - 1];
     sum += (p_sum * p_sum);
   }
   cout << sum << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> r;
 vector<int> l;
 int n, ans, a[550000];
 int main() {
   cin >> n;
   for (int i = 1; i <= n; i++) cin >> a[i];
   a[0] = a[1];
   a[n + 1] = a[n];
   for (int i = 1; i <= n; i++) {
     if (a[i] == a[i + 1] && a[i] != a[i - 1]) r.push_back(i);
     if (a[i] != a[i + 1] && a[i] == a[i - 1]) l.push_back(i);
   }
   for (int i = 0; i < l.size(); i++) ans = max(ans, r[i] - l[i]);
   cout << ans / 2 << endl;
   for (int i = 0; i < l.size(); i++)
     if (a[l[i]] == a[r[i]])
       for (int j = l[i]; j <= r[i]; j++) a[j] = a[l[i]];
     else {
       for (int j = l[i]; j <= (r[i] + l[i]) / 2; j++) a[j] = a[l[i]];
       for (int j = (r[i] + l[i]) / 2 + 1; j <= r[i]; j++) a[j] = a[r[i]];
     }
   for (int i = 1; i <= n; i++) cout << a[i] <<    ;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, s;
   int max = 0;
   int counter = 0;
   cin >> n >> s;
   for (int i = 0; i < n; i++) {
     int a;
     cin >> a;
     counter += a;
     if (a > max) {
       max = a;
     }
   }
   if (counter - max > s) {
     cout <<  NO ;
     return 0;
   } else {
     cout <<  YES ;
     return 0;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int max(int a, int b, int c, int d) {
   if (a >= b && a >= c && a >= d) return a;
   if (b >= a && b >= c && b >= d) return b;
   if (c >= a && c >= b && c >= d) return c;
   if (d >= a && d >= c && d >= b) return d;
   return d;
 }
 int main() {
   int x1, x2, x3, x4;
   cin >> x1 >> x2 >> x3 >> x4;
   int mx = max(x1, x2, x3, x4);
   if (mx == x1) {
     cout << mx - x2 <<     << mx - x3 <<     << mx - x4;
   } else {
     if (mx == x2) {
       cout << mx - x1 <<     << mx - x3 <<     << mx - x4;
     } else {
       if (mx == x3) {
         cout << mx - x2 <<     << mx - x1 <<     << mx - x4;
       } else {
         if (mx == x4) {
           cout << mx - x2 <<     << mx - x3 <<     << mx - x1;
         }
       }
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int t, n, m, cur;
 int nxt[200200][26], link[200200], dp[200200], cnt[200200], ord[200200],
     occur[200200];
 char s[200200];
 void extend(int c) {
   int x = cur, y = cur = ++m;
   dp[y] = dp[x] + 1;
   occur[y] = 1;
   while (x && !nxt[x][c]) nxt[x][c] = y, x = link[x];
   if (!x)
     link[y] = 1;
   else {
     int z = nxt[x][c];
     if (dp[z] == dp[x] + 1)
       link[y] = z;
     else {
       int u = ++m;
       memcpy(nxt[u], nxt[z], sizeof nxt[u]);
       link[u] = link[z], link[z] = link[y] = u;
       dp[u] = dp[x] + 1;
       while (x && nxt[x][c] == z) nxt[x][c] = u, x = link[x];
     }
   }
 }
 void build(char *s) {
   memset(nxt, 0, sizeof nxt), memset(link, 0, sizeof link),
       memset(dp, 0, sizeof dp);
   n = strlen(s), m = 0;
   cur = ++m;
   for (int i = 0; i < n; i++) extend(s[i] - 'a');
   memset(cnt, 0, sizeof cnt);
   for (int i = 1; i <= m; i++) cnt[dp[i]]++;
   for (int i = 1; i <= n; i++) cnt[i] += cnt[i - 1];
   for (int i = m; i >= 1; i--) ord[cnt[dp[i]]--] = i;
 }
 int main() {
   scanf( %d , &t);
   while (t--) {
     scanf( %s , s);
     memset(occur, 0, sizeof occur);
     build(s);
     for (int i = m; i >= 1; i--) occur[link[ord[i]]] += occur[ord[i]];
     long long ans = 0;
     for (int i = 1; i <= m; i++)
       ans += 1ll * occur[i] * occur[i] * (dp[i] - dp[link[i]]);
     printf( %I64d
 , ans);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxN = 1e4;
 long long F[maxN + 1];
 void fact() {
   F[0] = F[1] = 1;
   for (int i = 2; i <= maxN; i++) F[i] = (1LL * F[i - 1] * i) % 998244353;
 }
 long long power(long long a, long long b) {
   long long res = 1;
   while (b) {
     if (b & 1) {
       res = (1LL * res * a) % 998244353, b--;
     } else {
       a = (1LL * a * a) % 998244353, b >>= 1;
     }
   }
   return res;
 }
 long long C(long long n, long long r) {
   if (r > n) return 0;
   long long res = F[n];
   res = (1LL * res * power(F[r], 998244353 - 2)) % 998244353;
   res = (1LL * res * power(F[n - r], 998244353 - 2)) % 998244353;
   return res;
 }
 void solve() {
   long long n, k;
   cin >> n >> k;
   string second;
   cin >> second;
   if (!k) {
     cout <<  1
 ;
     return;
   }
   long long ans = 1, l = 0, r = 0, cnt = 0;
   while (r < n) {
     if (second[r] == '1') {
       if (cnt == k) {
         (ans += (C(r - l, k) - 1 + 998244353) % 998244353) %= 998244353;
         while (l < n && second[l] != '1') l++;
         l++, cnt--;
         ans = (ans - C(r - l, k - 1) + 1 + 998244353) % 998244353;
       }
       cnt++;
     }
     r++;
   }
   if (cnt == k) (ans += (C(r - l, k) - 1 + 998244353) % 998244353) %= 998244353;
   cout << ans << '
';
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0), cout.tie(0), fact();
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> v[250001];
 int a, ans[250001], n, i, q, kol;
 bool pole[250001];
 void dfs(int nom) {
   int i;
   kol++;
   pole[nom] = true;
   for (i = 0; i < v[nom].size(); i++)
     if (!pole[v[nom][i]]) dfs(v[nom][i]);
   ans[nom] = kol;
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cin >> q;
   while (q--) {
     cin >> n;
     for (i = 1; i <= n; i++) {
       v[i].clear();
       pole[i] = false;
     }
     for (i = 1; i <= n; i++) {
       cin >> a;
       v[i].push_back(a);
     }
     for (i = 1; i <= n; i++)
       if (!pole[i]) {
         kol = 0;
         dfs(i);
       }
     for (i = 1; i <= n - 1; i++) cout << ans[i] <<    ;
     cout << ans[n] << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 1e9 + 7;
 const long long INF = 1e18L + 7;
 template <class n, class second>
 ostream &operator<<(ostream &p, pair<n, second> x) {
   return p <<  <  << x.first <<  ,   << x.second <<  > ;
 }
 template <class n>
 auto operator<<(ostream &p, n y) ->
     typename enable_if<!is_same<n, string>::value,
                        decltype(y.begin(), p)>::type {
   int o = 0;
   p <<  { ;
   for (auto c : y) {
     if (o++) p <<  ,  ;
     p << c;
   }
   return p <<  } ;
 }
 void dor() { cerr << '
'; }
 template <class n, class... second>
 void dor(n p, second... y) {
   cerr << p <<    ;
   dor(y...);
 }
 template <class n, class second>
 void mini(n &p, second y) {
   if (p > y) p = y;
 }
 template <class n, class second>
 void maxi(n &p, second y) {
   if (p < y) p = y;
 }
 const int mod = 998244353;
 const int N = 507;
 int n, m;
 int tab[N];
 int dp[N][N][3];
 int vis[N][N][3];
 int pie[N];
 int dru[N];
 void solve(int a, int b, int t) {
   if (vis[a][b][t]) return;
   vis[a][b][t] = 1;
   if (a > b) {
     if (t == 2)
       dp[a][b][t] = 1;
     else
       dp[a][b][t] = 0;
     return;
   }
   int col = inf;
   int ind = -1;
   if (t == 2) {
     for (int i = a; i <= b; ++i) {
       if (col > tab[i]) {
         col = tab[i];
         ind = i;
       }
     }
     solve(a, ind, 1);
     solve(ind, b, 0);
     dp[a][b][t] = (long long)dp[a][ind][1] * dp[ind][b][0] % mod;
   } else if (t == 0) {
     for (int i = a; i <= b; ++i) {
       solve(a + 1, i, 2);
       solve(i + 1, b, 2);
       dp[a][b][t] += (long long)dp[a + 1][i][2] * dp[i + 1][b][2] % mod;
       if (dp[a][b][t] >= mod) dp[a][b][t] -= mod;
     }
   } else if (t == 1) {
     for (int i = a; i <= b; ++i) {
       solve(a, i - 1, 2);
       solve(i, b - 1, 2);
       dp[a][b][t] += (long long)dp[a][i - 1][2] * dp[i][b - 1][2] % mod;
       if (dp[a][b][t] >= mod) dp[a][b][t] -= mod;
     }
   }
 }
 int32_t main() {
   ios_base::sync_with_stdio(0);
   cin.tie(NULL);
   cin >> n >> m;
   for (int i = 1; i <= n; ++i) {
     cin >> tab[i];
   }
   solve(1, n, 2);
   cout << dp[1][n][2] << '
';
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, a[3005], b[3005], df[3005];
 long long F[3005][3005];
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   cin >> n;
   for (int i = 1; i <= n; ++i) {
     cin >> a[i];
     a[i] = a[i] - i;
     b[i] = a[i];
   }
   sort(b + 1, b + n + 1);
   int m = 0;
   b[0] = b[1] - 1;
   for (int i = 1; i <= n; ++i) {
     if (b[i] > b[i - 1]) df[++m] = b[i];
   }
   for (int i = 1; i <= n; ++i)
     for (int j = 0; j <= m; ++j) {
       F[i][j] = 1e18;
     }
   for (int i = 1; i <= n; ++i) {
     for (int j = 1; j <= m; ++j) {
       F[i][j] = min(F[i][j - 1], F[i - 1][j] + abs(a[i] - df[j]));
     }
   }
   long long rs = 1e18;
   for (int i = 1; i <= m; ++i) rs = min(rs, F[n][i]);
   cout << rs;
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( -O2 )
 using namespace std;
 const int LIM = 2e5 + 5, MOD = 1e9 + 7;
 int t, n, m, k, x, y;
 template <typename... T>
 void read(T &...args) {
   ((cin >> args), ...);
 }
 template <typename... T>
 void print(T &&...args) {
   ((cout << args <<    ), ...);
 }
 int main() {
   int n;
   read(n);
   long long int arr[n];
   for (int i = 0; i < n; i++) read(arr[i]);
   sort(arr, arr + n);
   long long int val = pow(arr[n - 1], 1.0 / (n - 1));
   long long int a1 = 0, a2 = 0;
   for (int i = 0; i < n; i++) {
     a1 += abs(pow(val, i) - arr[i]);
   }
   val++;
   for (int i = 0; i < n; i++) {
     a2 += abs(pow(val, i) - arr[i]);
   }
   long long int curr = pow(val, n - 2), curr2 = pow(val, n - 1);
   if (curr2 / curr == val)
     cout << min(a1, a2) << endl;
   else
     cout << a1 << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 typedef struct frac {
   long long p, q;
 } frac;
 const double eps = 1e-8;
 int n;
 int nb[100100];
 vector<int> G[100100];
 bool col[100100];
 int cur[100100];
 int onstk[100100];
 inline bool operator<(frac a, frac b) { return a.p * b.q < b.p * a.q; }
 inline bool operator==(frac a, frac b) { return a.p * b.q == b.p * a.q; }
 inline bool operator>(frac a, frac b) { return a.p * b.q > b.p * a.q; }
 inline bool operator>=(frac a, double b) {
   return ((double)a.p / (double)a.q) >= b;
 }
 inline bool operator!=(frac a, frac b) { return a.p * b.q != b.p * a.q; }
 inline frac newfrac(long long a, long long b) {
   frac x;
   x.p = a;
   x.q = b;
   return x;
 }
 inline bool valid(double z, bool pr) {
   priority_queue<pair<frac, int>, vector<pair<frac, int> >,
                  greater<pair<frac, int> > >
       S;
   for (int i = (1); i <= (n); i++) {
     cur[i] = 0;
     onstk[i] = false;
   }
   for (int x = (1); x <= (n); x++) {
     if (col[x]) {
       for (int j = (0); j < (G[x].size()); j++) {
         int y = G[x][j];
         if (col[y]) {
           cur[x]++;
         }
       }
       S.push(make_pair(newfrac(cur[x], nb[x]), x));
       onstk[x] = true;
     }
   }
   bool ok = false;
   while (!S.empty()) {
     if (!onstk[S.top().second]) {
       S.pop();
       continue;
     }
     if (S.top().first >= z) {
       ok = true;
       break;
     } else {
       int x = S.top().second;
       S.pop();
       onstk[x] = false;
       for (int j = (0); j < (G[x].size()); j++) {
         int y = G[x][j];
         if (onstk[y]) {
           cur[y]--;
           S.push(make_pair(newfrac(cur[y], nb[y]), y));
         }
       }
     }
   }
   if (pr) {
     int cnt = 0;
     vector<int> V;
     for (int i = (1); i <= (n); i++) {
       if (onstk[i]) {
         cnt++;
         V.push_back(i);
       }
     }
     printf( %d
 , cnt);
     for (int i = (0); i < (V.size()); i++) {
       printf( %d , V[i]);
       if (i < V.size() - 1) {
         printf(   );
       }
     }
     printf(
 );
   }
   return ok;
 }
 int main() {
   int m, k, x, y;
   scanf( %d%d%d , &n, &m, &k);
   for (int i = (1); i <= (n); i++) {
     nb[i] = 0;
     col[i] = true;
   }
   for (int i = (1); i <= (k); i++) {
     scanf( %d , &x);
     col[x] = false;
   }
   for (int i = (1); i <= (m); i++) {
     scanf( %d%d , &x, &y);
     nb[x]++;
     nb[y]++;
     if ((col[y]) and (col[x])) {
       G[x].push_back(y);
       G[y].push_back(x);
     }
   }
   double l = 0.0, r = 1.0;
   while ((r - l) > eps) {
     double mid = (l + r) / 2;
     if (valid(mid, false)) {
       l = mid;
     } else {
       r = mid;
     }
   }
   col[0] = valid(l, true);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e5 + 10;
 int A, B, C, D;
 struct Point {
   long long x, y;
   Point(long long x, long long y) : x(x), y(y) {}
 };
 bool operator<(const Point& a, const Point& b) {
   return a.x < b.x || (a.x == b.x && a.y > b.y);
 }
 int main() {
   int n;
   scanf( %d , &n);
   scanf( %d/%d %d/%d , &A, &B, &C, &D);
   vector<Point> P;
   for (int i = 0; i < n; ++i) {
     int u, v;
     scanf( %d%d , &u, &v);
     long long x = (long long)B * v - (long long)A * u;
     long long y = (long long)C * u - (long long)D * v;
     if (x > 0 && y > 0) {
       P.emplace_back(Point(x, y));
     }
   }
   sort(P.begin(), P.end());
   vector<long long> len;
   for (auto& it : P) {
     int idx = lower_bound(len.begin(), len.end(), it.y) - len.begin();
     if (idx == len.size()) {
       len.emplace_back(it.y);
     } else {
       len[idx] = it.y;
     }
   }
   printf( %d
 , len.size());
   return 0;
 }


#include <bits/stdc++.h>
 int n;
 int main() {
   int i;
   scanf( %d , &n);
   for (i = 20; i >= 0; i--) {
     if (n & (1 << i)) printf( %d  , i + 1);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 100005;
 struct all {
   int t, num;
   char x, type;
 } a[N];
 bool cmp(all a, all b) { return a.t < b.t; }
 int redhome[N], redaway[N];
 int yellhome[N], yellaway[N];
 string home, away;
 int n;
 int main() {
   cin >> home >> away;
   cin >> n;
   for (int i = 1; i <= n; ++i) cin >> a[i].t >> a[i].x >> a[i].num >> a[i].type;
   sort(a + 1, a + n + 1, &cmp);
   for (int i = 1; i <= n; ++i) {
     if (a[i].x == 'h') {
       if (a[i].type == 'r') {
         if (redhome[a[i].num] == 0) {
           redhome[a[i].num] = a[i].t;
           cout << home <<     << a[i].num <<     << a[i].t << endl;
         }
       } else {
         if (yellhome[a[i].num] == 0)
           yellhome[a[i].num] = a[i].t;
         else if (redhome[a[i].num] == 0) {
           redhome[a[i].num] = a[i].t;
           cout << home <<     << a[i].num <<     << a[i].t << endl;
         }
       }
     } else {
       if (a[i].type == 'r') {
         if (redaway[a[i].num] == 0) {
           redaway[a[i].num] = a[i].t;
           cout << away <<     << a[i].num <<     << a[i].t << endl;
         }
       } else {
         if (yellaway[a[i].num] == 0)
           yellaway[a[i].num] = a[i].t;
         else if (redaway[a[i].num] == 0) {
           redaway[a[i].num] = a[i].t;
           cout << away <<     << a[i].num <<     << a[i].t << endl;
         }
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize(2)
 using namespace std;
 void qread(int &x) {
   int neg = 1;
   x = 0;
   char c = getchar();
   while (c < '0' || c > '9') {
     if (c == '-') neg = -1;
     c = getchar();
   }
   while (c >= '0' && c <= '9') x = 10 * x + c - '0', c = getchar();
   x *= neg;
 }
 const int maxn = 100005;
 int n, l, r, k, ans, ansu, ansv;
 vector<pair<int, int> > edge[maxn];
 vector<int> num;
 int oriw[maxn], w[maxn], dep[maxn], lvl[maxn], son[maxn];
 int pos[maxn], dis[maxn];
 pair<int, int> val[maxn];
 namespace Segtree {
 int sz;
 pair<int, int> t[maxn * 4];
 void init(int _sz) {
   for (sz = 1; sz < _sz; sz <<= 1)
     ;
   for (int(i) = 0; (i) < sz << 1; i++) t[i] = make_pair(-1e9, -1e9);
 }
 void update(int v, pair<int, int> val) {
   v += sz - 1;
   t[v] = val;
   for (v >>= 1; v; v >>= 1) t[v] = max(t[v << 1], t[v << 1 | 1]);
 }
 pair<int, int> query(int l, int r) {
   pair<int, int> res = make_pair(-1e9, -1e9);
   for (l += sz - 1, r += sz - 1; l <= r; l >>= 1, r >>= 1) {
     if (l & 1) res = max(res, t[l]), l++;
     if ((r + 1) & 1) res = max(res, t[r]), r--;
   }
   return res;
 }
 }  // namespace Segtree
 void prework1(int x, int p, int d) {
   dep[x] = lvl[x] = d;
   for (int(i) = 0; (i) < edge[x].size(); i++) {
     pair<int, int> y = edge[x][i];
     if (y.first == p) continue;
     prework1(y.first, x, d + 1);
     if (!son[x] || lvl[y.first] > lvl[son[x]]) son[x] = y.first;
     lvl[x] = max(lvl[x], lvl[y.first]);
   }
 }
 void prework2(int x, int p) {
   pos[x] = ++k;
   if (son[x]) prework2(son[x], x);
   for (int(i) = 0; (i) < edge[x].size(); i++) {
     pair<int, int> y = edge[x][i];
     if (y.first == p || y.first == son[x]) continue;
     prework2(y.first, x);
   }
 }
 void work(int x, int p, int cur) {
   val[pos[x]] = make_pair(cur, x);
   dis[x] = cur;
   Segtree::update(pos[x], make_pair(cur, x));
   for (int(i) = 0; (i) < edge[x].size(); i++) {
     int y = edge[x][i].first;
     if (y == son[x]) work(y, x, cur + w[edge[x][i].second]);
   }
   for (int(i) = 0; (i) < edge[x].size(); i++) {
     int y = edge[x][i].first;
     if (y == p || y == son[x]) continue;
     work(y, x, cur + w[edge[x][i].second]);
     int tmp = lvl[y] - dep[y];
     for (int(d) = 0; (d) < tmp + 1; d++) {
       int ql = max(l - d - 1, 0), qr = min(r - d - 1, lvl[x] - dep[x]);
       pair<int, int> val2 = Segtree::query(pos[x] + ql, pos[x] + qr);
       if (val[pos[y] + d].first + val2.first - 2 * dis[x] > ans) {
         ans = val[pos[y] + d].first + val2.first - 2 * dis[x];
         ansu = val[pos[y] + d].second;
         ansv = val2.second;
       }
     }
     for (int(d) = 0; (d) < tmp + 1; d++) {
       val[pos[x] + d + 1] = max(val[pos[x] + d + 1], val[pos[y] + d]);
       Segtree::update(pos[x] + d + 1, val[pos[x] + d + 1]);
     }
   }
   pair<int, int> val2 =
       Segtree::query(pos[x] + l, pos[x] + min(r, lvl[x] - dep[x]));
   if (val2.first - dis[x] > ans) {
     ans = val2.first - dis[x];
     ansu = x;
     ansv = val2.second;
   }
 }
 bool check(int x) {
   for (int(i) = 1; (i) <= n - 1; i++) {
     if (oriw[i] < x)
       w[i] = -1;
     else
       w[i] = 1;
   }
   Segtree::init(n);
   for (int(i) = 1; (i) <= n; i++) val[i] = make_pair(-1e9, -1e9);
   ans = -1e9;
   work(1, 0, 0);
   return ans >= 0;
 }
 int main() {
   scanf( %d%d%d , &n, &l, &r);
   for (int(i) = 1; (i) <= n - 1; i++) {
     int u, v;
     scanf( %d%d%d , &u, &v, &oriw[i]);
     edge[u].push_back(make_pair(v, i));
     edge[v].push_back(make_pair(u, i));
     num.push_back(oriw[i]);
   }
   prework1(1, 0, 0);
   prework2(1, 0);
   sort(num.begin(), num.end());
   num.resize(unique(num.begin(), num.end()) - num.begin());
   int l = 0, r = num.size();
   while (r - l > 1) {
     int mid = (l + r) >> 1;
     if (check(num[mid]))
       l = mid;
     else
       r = mid;
   }
   check(num[l]);
   printf( %d %d
 , ansu, ansv);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using namespace std::chrono;
 struct custom_hash {
   size_t operator()(uint64_t x) const {
     static const uint64_t FIXED_RANDOM =
         chrono::steady_clock::now().time_since_epoch().count();
     return x + FIXED_RANDOM;
   }
 };
 void solve() {
   long long n;
   cin >> n;
   for (long long i = 2; i * i <= n; i++) {
     if (n % i == 0) {
       cout << n / i <<     << n - (n / i) <<
 ;
       return;
     }
   }
   cout << 1 <<     << n - 1 <<
 ;
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int t;
   cin >> t;
   while (t--) solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long MAXN = 200 + 17, inf = 2e18 + 17;
 long long a[MAXN], b[MAXN], n, m, k, t[MAXN][MAXN], np;
 void fillA() {
   for (int i = 1; i <= m; i++)
     for (int j = 0; i - j > 0 && j < n; j++) a[i] = min(t[j + 1][i - j], a[i]);
   for (int i = 1; i <= n; i++)
     for (int j = 0; i + j <= n && j < m; j++)
       a[i + m - 1] = min(a[i + m - 1], t[i + j][m - j]);
 }
 void fillBackT() {
   for (int i = 1; i <= m; i++)
     for (int j = 0; i - j > 0 && j < n; j++) t[j + 1][i - j] = a[i];
   for (int i = 1; i <= n; i++)
     for (int j = 0; i + j <= n && j < m; j++) t[i + j][m - j] = a[i + m - 1];
 }
 long long count(int x) {
   a[x] = 0;
   long long dp[MAXN][MAXN] = {};
   if (a[1] == 1)
     dp[1][1] = 0;
   else
     dp[1][1] = 1;
   for (int i = 2; i <= np; i++)
     for (int j = 0; j <= np; j++) {
       if (a[i] == 1)
         dp[i][j] = dp[i - 1][j + 1];
       else if (a[i] == 0)
         dp[i][j] = (j > 0 ? dp[i - 1][j - 1] : 0);
       else
         dp[i][j] =
             min(inf, (dp[i - 1][j + 1] + (j > 0 ? dp[i - 1][j - 1] : 0)));
     }
   return dp[np][0];
 }
 int main() {
   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   cin >> n >> m >> k;
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= m; j++) cin >> t[i][j];
   fill(a, a + MAXN, inf);
   fillA();
   np = n + m - 1;
   iota(b + 1, b + np + 1, 1);
   sort(b + 1, b + np + 1, [](int i, int j) { return a[i] < a[j]; });
   for (int i = 1; i <= np; i++) {
     long long tmp = count(b[i]);
     if (tmp >= k)
       a[b[i]] = 0;
     else {
       a[b[i]] = 1;
       k -= tmp;
     }
   }
   fillBackT();
   for (int i = 1; i <= n; i++) {
     for (int j = 1; j <= m; j++) cout << (t[i][j] ? ')' : '(');
     cout << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int high = 2e5 + 6;
 long long cnt[200005], dif[200005];
 int main() {
   long long n, m, k, i, j, ans, l, r, d, sum = 0, q;
   scanf( %lld%lld%lld , &n, &k, &q);
   for (i = 0; i < n; i++) {
     scanf( %lld%lld , &l, &r);
     dif[l]++;
     dif[r + 1]--;
   }
   for (i = 1; i <= high; i++) {
     dif[i] += dif[i - 1];
   }
   for (i = 1; i <= high; i++) {
     if (dif[i] >= k) {
       cnt[i] = 1;
     }
   }
   for (i = 1; i <= high; i++) {
     cnt[i] += cnt[i - 1];
   }
   while (q--) {
     scanf( %lld%lld , &l, &r);
     printf( %lld
 , cnt[r] - cnt[l - 1]);
   }
 }


#include <bits/stdc++.h>
 const long long int MOD = 1000000007ll;
 const int mxsz = 200005;
 using namespace std;
 int main() {
   std::ios_base::sync_with_stdio(false);
   long long int n, m, a;
   cin >> n >> m >> a;
   int ar1[n + 1], ar2[m + 1];
   for (int i = 1; i <= n; i++) {
     cin >> ar1[i];
   }
   for (int i = 1; i <= m; i++) {
     cin >> ar2[i];
   }
   sort(ar1 + 1, ar1 + n + 1);
   sort(ar2 + 1, ar2 + m + 1);
   vector<long long int> b, p;
   for (int i = 1; i <= min(n, m); i++) {
     b.push_back(ar1[n - i + 1]);
     p.push_back(ar2[i]);
   }
   int l = 0, r = min(n, m);
   int ans = 0;
   while (l <= r) {
     int mid = (l + r) / 2;
     long long int tmp = a;
     for (int i = 0; i < mid; i++) {
       tmp -= (long long int)max(0LL, p[mid - i - 1] - b[i]);
       if (tmp < 0) {
         break;
       }
     }
     if (tmp >= 0) {
       l = mid + 1;
       ans = mid;
     } else {
       r = mid - 1;
     }
   }
   cout << ans <<    ;
   long long int tmp = 0;
   for (int i = 0; i < ans; i++) {
     tmp += (long long int)p[i];
   }
   cout << max(0LL, tmp - a);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int x[1000], y[1000], k, n, m;
 bool chck(int xx) {
   vector<int> v;
   v.push_back(1);
   v.push_back(m);
   for (int i = 0; i < k; ++i) {
     v.push_back(max(1, x[i] - xx));
     v.push_back(max(1, x[i] - xx - 1));
     v.push_back(min(m, x[i] + xx));
     v.push_back(min(m, x[i] + xx + 1));
   }
   sort(v.begin(), v.end());
   int mn = 1e9, mx = -1, tmp, nm, c;
   bool l;
   vector<pair<int, int> > f;
   for (int i = 0; i < v.size(); ++i) {
     tmp = v[i];
     f.clear();
     for (int j = 0; j < k; ++j) {
       if (x[j] - xx <= tmp && x[j] + xx >= tmp) {
         f.push_back(make_pair(max(1, y[j] - xx), 0));
         f.push_back(make_pair(min(n, y[j] + xx), 1));
       }
     }
     sort(f.begin(), f.end());
     c = 0;
     nm = 0;
     l = 0;
     for (int j = 0; j < f.size(); ++j) {
       if (nm == 0) {
         if (f[j].first != c + 1) {
           break;
         }
       }
       c = f[j].first;
       if (f[j].second == 0)
         ++nm;
       else
         --nm;
       if (c == n) {
         l = 1;
         break;
       }
     }
     if (!l) {
       mn = min(mn, tmp);
       mx = max(mx, tmp);
     }
   }
   mx = min(mx, m);
   mn = max(1, mn);
   if (mx - mn + 1 > xx + xx + 1) {
     return 0;
   }
   v.clear();
   v.push_back(1);
   v.push_back(n);
   for (int i = 0; i < k; ++i) {
     v.push_back(max(1, y[i] - xx));
     v.push_back(max(1, y[i] - xx - 1));
     v.push_back(min(n, y[i] + xx));
     v.push_back(min(n, y[i] + xx + 1));
   }
   sort(v.begin(), v.end());
   mn = 1e9, mx = -1;
   for (int i = 0; i < v.size(); ++i) {
     tmp = v[i];
     f.clear();
     for (int j = 0; j < k; ++j) {
       if (y[j] - xx <= tmp && y[j] + xx >= tmp) {
         f.push_back(make_pair(max(1, x[j] - xx), 0));
         f.push_back(make_pair(min(m, x[j] + xx), 1));
       }
     }
     sort(f.begin(), f.end());
     c = 0;
     nm = 0;
     l = 0;
     for (int j = 0; j < f.size(); ++j) {
       if (nm == 0) {
         if (f[j].first != c + 1) {
           break;
         }
       }
       c = f[j].first;
       if (f[j].second == 0)
         ++nm;
       else
         --nm;
       if (c == m) {
         l = 1;
         break;
       }
     }
     if (!l) {
       mn = min(mn, tmp);
       mx = max(mx, tmp);
     }
   }
   mx = min(mx, n);
   mn = max(1, mn);
   if (mx - mn + 1 > xx + xx + 1) {
     return 0;
   }
   return 1;
 }
 int main() {
   while (cin >> m >> n >> k) {
     for (int i = 0; i < k; ++i) {
       scanf( %d%d , &x[i], &y[i]);
     }
     int st = 0, nd = 1e9, md;
     while (st < nd) {
       md = (st + nd) / 2;
       if (chck(md)) {
         nd = md;
       } else {
         st = md + 1;
       }
     }
     printf( %d
 , nd);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int cansel_sync = (ios::sync_with_stdio(0), cin.tie(0), 0);
 const int N = 200010;
 const int inf = ~0u >> 2;
 const long long INF = ~0ull >> 2;
 long long read() {
   long long x;
   if (scanf( %lld , &x) == -1) exit(0);
   return x;
 }
 const double pi = acos(-1.0);
 double readf() {
   double x;
   if (scanf( %lf , &x) == -1) exit(0);
   return x;
 }
 template <typename T>
 T sqr(const T &x) {
   return x * x;
 }
 int mod = (1 ? 1000000007 : 998244353);
 long long mul(long long a, long long b, long long m = mod) { return a * b % m; }
 long long qpow(long long a, long long b, long long m = mod) {
   long long ans = 1;
   for (; b; a = mul(a, a, m), b >>= 1)
     if (b & 1) ans = mul(ans, a, m);
   return ans;
 }
 long long getinv(long long v, long long m = mod) { return qpow(v, m - 2, m); }
 long long n, x, t, l, r, sum;
 void solve() {
   cin >> n >> x;
   sum = 0;
   l = inf, r = -inf;
   for (long long i = (0), _ = (n); i < _; i++) {
     cin >> t;
     if (t % x != 0) l = min(l, i), r = max(r, i);
     sum += t % x;
   }
   if (sum % x != 0) {
     cout << n << endl;
     return;
   }
   if (l != inf) {
     cout << max(n - l - 1, r) << endl;
     return;
   }
   cout << -1 << endl;
 }
 signed main() {
   long long T;
   cin >> T;
   while (T--) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1E5;
 vector<int> vf, vz;
 int main() {
   ios_base::sync_with_stdio(false);
   int n, k, p;
   cin >> n >> k >> p;
   for (int i = 0; i < n; i++) {
     int x;
     cin >> x;
     if (x % 2 == 0)
       vz.push_back(x);
     else
       vf.push_back(x);
   }
   int tf = vf.size(), tz = vz.size();
   if (tf < (k - p) || p > tz + (tf - (k - p)) / 2 || (k - p) % 2 != tf % 2)
     cout <<  NO ;
   else {
     if ((tf - (k - p)) % 2 == 1) {
       cout <<  NO ;
     }
     if ((tf - (k - p)) % 2 == 0) {
       cout <<  YES  << endl;
       if (p == 0) {
         for (int i = 0; i < k - 1; i++) cout <<  1   << vf[i] << endl;
         cout << tf - (k - 1) + tz;
         for (int i = k - 1; i < tf; i++) cout << ' ' << vf[i];
         for (int i = 0; i < tz; i++) cout << ' ' << vz[i];
         cout << endl;
       } else if (tz >= p) {
         for (int i = 0; i < p - 1; i++) cout <<  1   << vz[i] << endl;
         cout << tz - p + 1 + tf - (k - p);
         for (int i = p - 1; i < tz; i++) cout << ' ' << vz[i];
         for (int i = 0; i < tf - (k - p); i++) cout << ' ' << vf[i];
         cout << endl;
         for (int i = tf - (k - p); i < tf; i++) cout <<  1   << vf[i] << endl;
       } else {
         for (int i = 0; i < tz; i++) cout <<  1   << vz[i] << endl;
         for (int i = 0; i < (p - tz) - 1; i++)
           cout <<  2   << vf[i * 2] << ' ' << vf[i * 2 + 1] << endl;
         cout << tf - (p - tz - 1) * 2 - (k - p);
         for (int i = (p - tz - 1) * 2; i < tf - (k - p); i++)
           cout << ' ' << vf[i];
         cout << endl;
         for (int i = tf - (k - p); i < tf; i++) cout <<  1   << vf[i] << endl;
       }
     }
   }
 }


#include <bits/stdc++.h>
 int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0};
 int dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
 using namespace std;
 long long power(long long a, long long p, long long M) {
   long long r = 1;
   a = a % M;
   while (p > 0) {
     if (p % 2) r = (r * a) % M;
     a = (a * a) % M;
     p /= 2;
   }
   return r;
 }
 long long gcd(long long a, long long b) {
   if (b == 0) return a;
   return gcd(b, a % b);
 }
 long long n, m;
 set<long long> e[100005];
 stack<long long> cycle, temp;
 long long vis[505];
 bool found;
 void findCycle(long long x) {
   temp.push(x);
   vis[x] = 1;
   for (auto y : e[x]) {
     if (vis[y] == 0)
       findCycle(y);
     else if (vis[y] == 1) {
       if (found) return;
       cycle = temp;
       cycle.push(y);
       found = 1;
       return;
     }
   }
   if (!temp.empty()) temp.pop();
   vis[x] = 2;
 }
 void fc(long long x) {
   vis[x] = 1;
   for (auto y : e[x]) {
     if (vis[y] == 0)
       fc(y);
     else if (vis[y] == 1) {
       found = 1;
       return;
     }
   }
   vis[x] = 2;
 }
 void solve() {
   cin >> n >> m;
   for (long long i = 0; i < m; i++) {
     long long a, b;
     scanf( %lld%lld , &a, &b);
     e[a].insert(b);
   }
   for (long long i = 1; i < n + 1; i++) {
     if (!vis[i]) {
       findCycle(i);
       if (found) break;
     }
   }
   if (!found) {
     cout <<  YES
 ;
     return;
   }
   vector<long long> c;
   for (long long i = 0; i < 505; i++) vis[i] = 0;
   while (!cycle.empty()) {
     c.push_back(cycle.top());
     if (vis[cycle.top()]) {
       break;
     }
     vis[cycle.top()] = 1;
     cycle.pop();
   }
   reverse(c.begin(), c.end());
   for (long long i = 0; i < c.size() - 1; i++) {
     found = 0;
     e[c[i]].erase(c[i + 1]);
     for (long long j = 0; j < 505; j++) vis[j] = 0;
     for (long long j = 1; j < n + 1; j++) {
       if (!vis[j]) fc(j);
       if (found) {
         break;
       }
     }
     if (!found) {
       cout <<  YES
 ;
       return;
     }
     e[c[i]].insert(c[i + 1]);
   }
   cout <<  NO
 ;
 }
 int main() {
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long A, B, N;
 long long L, T, M;
 bool ok(long long R) {
   long long mx = A + (R - 1) * B;
   long long mn = A + (L - 1) * B;
   long long D = R - L;
   if (mx > T) return false;
   return (mn * (D + 1) + B * D * (D + 1) / 2) <= T * M;
 }
 int main(void) {
   cin >> A >> B >> N;
   while (N--) {
     cin >> L >> T >> M;
     long long R = L;
     long long mn = A + (L - 1) * B;
     if (mn > T) {
       R = -1;
     } else {
       long long XR = 1LL << 22;
       while (XR > R) {
         long long m = (R + XR) / 2;
         if (!ok(m))
           XR = m;
         else
           R = m + 1;
       }
       R -= 1;
     }
     cout << R << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 1e9 + 7, mod = 1e9 + 9, pw = 31;
 const double eps = 1e-11;
 long long binpow(long long a, long long b) {
   long long rec = 1;
   while (b) {
     if (b % 2 == 1) {
       rec *= a;
       rec %= INF;
     }
     a *= a;
     a %= INF;
     b /= 2;
   }
   return rec;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(NULL);
   int n;
   cin >> n;
   long long x = binpow(3, n * 3) - binpow(7, n);
   if (x < 0) x += INF;
   cout << x;
   return 0;
 }


#include <bits/stdc++.h>
 const long long INF64 = 1e18;
 using namespace std;
 const long long N = 2e5 + 6;
 using namespace std;
 vector<pair<long long, long long>> pf;
 int main() {
   long long n, ans = INF64;
   cin >> n;
   vector<long long> cost(n, 0);
   vector<string> s;
   for (int i = 0; i < n; i++) cin >> cost[i];
   for (int i = 0; i < n; i++) {
     string st;
     cin >> st;
     s.push_back(st);
   }
   vector<vector<long long>> dp(n, vector<long long>(2, INF64));
   dp[n - 1][0] = 0;
   dp[n - 1][1] = cost[n - 1];
   for (int i = n - 2; i >= 0; i--) {
     string currStr(s[i]), currrevStr(s[i]);
     string prevStr(s[i + 1]), prevrevStr(s[i + 1]);
     reverse(currrevStr.begin(), currrevStr.end());
     reverse(prevrevStr.begin(), prevrevStr.end());
     if (currStr.compare(prevStr) <= 0) dp[i][0] = min(dp[i][0], dp[i + 1][0]);
     if (currStr.compare(prevrevStr) <= 0)
       dp[i][0] = min(dp[i][0], dp[i + 1][1]);
     if (currrevStr.compare(prevStr) <= 0)
       dp[i][1] = min(dp[i][1], dp[i + 1][0] + cost[i]);
     if (currrevStr.compare(prevrevStr) <= 0)
       dp[i][1] = min(dp[i][1], dp[i + 1][1] + cost[i]);
   }
   ans = min(ans, min(dp[0][0], dp[0][1]));
   if (ans == INF64)
     cout << -1;
   else
     cout << ans;
   return 0;
 }