#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e5 + 10;
 bool lucky[10010];
 int n, m;
 int a[N];
 int t[N + N];
 void init() {
   memset(lucky, false, sizeof(lucky));
   lucky[0] = true;
   for (int i = 1; i <= 10000; i++)
     if (i % 10 == 4 || i % 10 == 7) lucky[i] = lucky[i / 10];
 }
 void update(int i, int v) {
   if (!v) return;
   i += n;
   while (i >= 1) {
     t[i] += v;
     i >>= 1;
   }
 }
 int query(int Left, int Right) {
   int res = 0;
   Left += n;
   Right += n;
   while (Left <= Right) {
     if (Left % 2) res += t[Left];
     if ((~Right) % 2) res += t[Right];
     Left = (Left + 1) >> 1;
     Right = (Right - 1) >> 1;
   }
   return res;
 }
 int main() {
   init();
   scanf( %d%d , &n, &m);
   memset(t, 0, sizeof(t));
   for (int i = 0; i < n; i++) {
     scanf( %d , &a[i]);
     update(i, lucky[a[i]]);
   }
   char x[10];
   int Left, Right, temp;
   while (m--) {
     scanf( %s , &x);
     if (strcmp(x,  count ) == 0) {
       scanf( %d%d , &Left, &Right);
       Left--;
       Right--;
       printf( %d
 , query(Left, Right));
     } else {
       scanf( %d%d%d , &Left, &Right, &temp);
       Left--;
       Right--;
       for (int i = Left; i <= Right; i++) {
         a[i] += temp;
         update(i, lucky[a[i]] - lucky[a[i] - temp]);
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double pi = acos(-1.0), eps = 1e-8;
 const int inf = ~0U >> 2;
 int mod = 1e9 + 7;
 int Pow(int x, long long t) {
   int r = 1;
   for (; t; t >>= 1, x = (long long)x * x % mod)
     if (t & 1) r = (long long)r * x % mod;
   return r;
 }
 const int N = 101010;
 int n, K;
 struct P {
   long long x, y;
   void in() { cin >> x >> y; }
   P(long long _x = 0, long long _y = 0) { x = _x, y = _y; }
   double dis() { return sqrt(x * x + y * y); }
   long long operator^(const P& b) { return x * b.y - y * b.x; }
   P operator-(const P& b) { return P(x - b.x, y - b.y); }
 } p[N << 1], q;
 long long mul(P& o, P& a, P& b) { return (a - o) ^ (b - o); }
 bool in(P q) {
   double a = 0;
   for (int i = 0; i < n; ++i) {
     long long aera = mul(q, p[i], p[i + 1]);
     double disa = (p[i] - q).dis(), disb = (p[i + 1] - q).dis(),
            disc = (p[i] - p[i + 1]).dis();
     double angle = acos(((disa) * (disa) + (disb) * (disb) - (disc) * (disc)) /
                         2.0 / disa / disb);
     if (aera > 0)
       a += angle;
     else
       a -= angle;
   }
   return fabs(a) >= 1;
 }
 long long wk() {
   q.in();
   if (!in(q)) return 0;
   long long ans = (long long)n * (n - 1) * (n - 2) / 6;
   for (int i = 0, j = 1; i < n; ++i) {
     while (mul(p[i], p[j], q) <= 0) ++j;
     int del = (j + n - i) % n;
     int rm = n - del;
     ans -= (long long)rm * (rm - 1) / 2;
   }
   return ans;
 }
 int main() {
   cin >> n;
   for (int i = 0; i < n; ++i) p[i].in(), p[i + n] = p[i];
   cin >> K;
   for (int i = 0; i < K; ++i) cout << wk() << endl;
   return 0;
 }


#include <bits/stdc++.h>

 using namespace std;

 bool palindrome(const string &s) {
     int n = s.length();
     for(int i = 0; i < n; i++) {
         if(s[i] != s[n - i - 1]) return false;
     }
     return true;
 }

 int main() {
     ios::sync_with_stdio(false);
     cin.tie(0);
     int te;
     cin >> te;
     while(te--) {
         string s;
         cin >> s;
         if(!palindrome(s + 'a')) {
             cout <<  YES
  << s << 'a' <<
 ;
         }else if(!palindrome('a' + s)) {
             cout <<  YES
  << 'a' << s << '
';
         }else {
             cout <<  NO
 ;
         }
     }
 }


#include <bits/stdc++.h>
 const long double PI(acosl(-1.0));
 long double eps = 1e-9;
 using namespace std;
 using namespace std;
 const int N = 1000000;
 int main() {
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int n;
   cin >> n;
   vector<pair<int, int> > p(n);
   int s = 0;
   for (int i(0); i < n; i++) {
     int x;
     cin >> x;
     s += x;
     p[i] = {x, i + 1};
   }
   sort(++p.begin(), p.end());
   reverse(++p.begin(), p.end());
   vector<pair<int, int> > ans;
   int j = 1;
   int i = 0;
   while (j < n) {
     while (j < n && p[i].first > 0) {
       ans.push_back({p[i].second, p[j].second});
       p[i].first--;
       j++;
     }
     i++;
     if (i == j) break;
   }
   if (j < n) {
     cout << -1;
     return 0;
   }
   cout << ans.size() << endl;
   for (int i(0); i < ans.size(); i++)
     cout << ans[i].first <<     << ans[i].second <<
 ;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 void CIN(T &a) {
   cin >> a;
 }
 template <class T>
 void CIN(T &a, T &b) {
   cin >> a >> b;
 }
 template <class T>
 void CIN(T &a, T &b, T &c) {
   cin >> a >> b >> c;
 }
 template <class T>
 void CIN(T &a, T &b, T &c, T &d) {
   cin >> a >> b >> c >> d;
 }
 template <class T>
 void PI(T a) {
   cout << a << endl;
 }
 template <class T>
 void PI(T a, T b) {
   cout << a <<     << b << endl;
 }
 template <class T>
 void PIS(T a) {
   cout << a <<    ;
 }
 template <class T>
 T abs(T a) {
   return a < 0 ? -a : a;
 }
 const int N = 10000010;
 long long n, x, y, dx, dy, t;
 int b[6][6] = {{2, 1, 1, 0, 1, 0}, {1, 2, 0, 1, 1, 0}, {1, 1, 1, 0, 1, 0},
                {1, 1, 0, 1, 1, 0}, {0, 0, 0, 0, 1, 1}, {0, 0, 0, 0, 0, 1}};
 struct matrix {
   long long a[6][6];
   matrix() { memset(a, 0, sizeof(a)); }
   void init() {
     int i, j;
     for (i = 0; i < (int)(6); ++i)
       for (j = 0; j < (int)(6); ++j) a[i][j] = b[i][j];
   }
   void unit() {
     memset(a, 0, sizeof(a));
     int i;
     for (i = 0; i < (int)(6); ++i) a[i][i] = 1;
   }
   matrix operator*(const matrix &b) const {
     matrix ret;
     int i, j, k;
     for (i = 0; i < (int)(6); ++i)
       for (j = 0; j < (int)(6); ++j)
         for (k = 0; k < (int)(6); ++k) {
           ret.a[i][j] += a[i][k] * b.a[k][j];
           ret.a[i][j] %= n;
         }
     return ret;
   }
   matrix Pow(long long k) {
     matrix ret, p = *this;
     ret.unit();
     while (k) {
       if (k & 1) ret = ret * p;
       k >>= 1;
       p = p * p;
     }
     return ret;
   }
 } mx;
 int main() {
   CIN(n);
   CIN(x, y, dx, dy);
   CIN(t);
   mx.init();
   mx = mx.Pow(t);
   long long ex = mx.a[0][0] * x + mx.a[0][1] * y + mx.a[0][2] * dx +
                  mx.a[0][3] * dy + mx.a[0][5];
   long long ey = mx.a[1][0] * x + mx.a[1][1] * y + mx.a[1][2] * dx +
                  mx.a[1][3] * dy + mx.a[1][5];
   ex %= n;
   if (ex <= 0) ex += n;
   ey %= n;
   if (ey <= 0) ey += n;
   PI(ex, ey);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int a, b, c;
   cin >> a >> b >> c;
   int max = 0;
   int n[100];
   n[0] = a * b + c, n[1] = a * b * c, n[2] = a + b * c, n[3] = a + b + c,
   n[4] = a * (b + c), n[5] = (a + b) * c;
   for (int i = 0; i < 6; i++) {
     if (n[i] > max) max = n[i];
   }
   cout << max << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;

 typedef long long Int;
 typedef pair<int,int> PII;
 typedef vector<int> VInt;

 #define FOR(i, a, b) for(i = (a); i < (b); ++i)
 #define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
 #define EACH(it, a) for(auto it = (a).begin(); it != (a).end(); ++it)
 #define CLEAR(a, b) memset(a, b, sizeof(a))
 #define SIZE(a) int((a).size())
 #define ALL(a) (a).begin(),(a).end()
 #define MP make_pair

 int f(VInt p, VInt s)
 {
 	int n = SIZE(p);
 	int left = 0, right = n - 1;
 	int res = 0;
 	VInt used(n, 0);
 	while(left < right)
 	{
 		int cnt = 0;
 		int flips = 0;
 		int l = left;
 		int r = right + 1;
 		while(l >= left || r <= right)
 		{
 			if(l >= left)
 			{
 				int a = left;
 				++left;
 				if(used[a] == 0)
 				{
 					int b = p[a];
 					used[a] = used[b] = 1;
 					++cnt;
 					flips += s[a];
 					if(b > r) return -1;
 					r = b;
 					if(l >= r) return -1;
 				}
 			}
 			if(r <= right)
 			{
 				int a = right;
 				--right;
 				if(used[a] == 0)
 				{
 					int b = p[a];
 					used[a] = used[b] = 1;
 					++cnt;
 					flips += s[a];
 					if(b < l) return -1;
 					l = b;
 					if(l >= r) return -1;
 				}
 			}
 		}
 		res += min(flips, cnt - flips);
 	}
 	return res;
 }

 void SolveTest(int test)
 {
 	int n;
 	cin >> n;
 	int i, j;
 	VInt p(n + n);
 	VInt s(n + n);
 	FOR(i, 0, n)
 	{
 		int a, b;
 		cin >> a >> b;
 		--a;
 		--b;
 		p[a] = b;
 		p[b] = a;
 		s[a] = 0;
 		s[b] = 1;
 	}

 	cout << f(p, s) << endl;
 }

 int main()
 {
 	int T, t;
 	T = 1;
 	//cin >> T;
 	FOR(t, 0, T) SolveTest(t);
 	return 0;
 };


#include <bits/stdc++.h>
 using namespace std;
 const int N = 55;
 const int MOD = 1e9 + 7;
 struct Node {
   int op, x, y, d;
   Node() {}
   Node(int _op, int _x, int _y, int _d) { op = _op, x = _x, y = _y, d = _d; }
   bool operator<(const Node &cur) const { return d > cur.d; }
 };
 priority_queue<Node> que;
 int dist[2][N][N], n, m, nx, ny;
 long long ans[2][N][N], C[N][N];
 void init() {
   int i, j;
   memset(C, 0, sizeof(C));
   for (i = 0; i < N; i++) {
     C[i][0] = 1;
     for (j = 1; j <= i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
   }
 }
 int main() {
   int i, j, tmp;
   init();
   while (scanf( %d%d , &n, &m) != EOF) {
     for (i = 1, nx = ny = 0; i <= n; i++) {
       scanf( %d , &tmp);
       if (tmp == 50)
         nx++;
       else
         ny++;
     }
     memset(dist, 0x3f, sizeof(dist));
     memset(ans, 0, sizeof(ans));
     while (!que.empty()) que.pop();
     dist[1][0][0] = 0;
     ans[1][0][0] = 1;
     que.push(Node(1, 0, 0, 0));
     while (!que.empty()) {
       Node cur = que.top();
       que.pop();
       if (cur.d > dist[cur.op][cur.x][cur.y]) continue;
       for (i = 0; i <= nx; i++)
         for (j = 0; j <= ny; j++) {
           if (i + j == 0 || 50 * i + 100 * j > m) continue;
           if (cur.op == 0 && cur.x >= i && cur.y >= j) {
             if (dist[1][cur.x - i][cur.y - j] >= cur.d + 1) {
               if (dist[1][cur.x - i][cur.y - j] > cur.d + 1) {
                 ans[1][cur.x - i][cur.y - j] = 0;
                 dist[1][cur.x - i][cur.y - j] = cur.d + 1;
                 que.push(Node(1, cur.x - i, cur.y - j, cur.d + 1));
               }
               ans[1][cur.x - i][cur.y - j] +=
                   ans[0][cur.x][cur.y] * C[cur.x][i] % MOD * C[cur.y][j] % MOD;
               ans[1][cur.x - i][cur.y - j] %= MOD;
             }
           }
           if (cur.op == 1 && cur.x + i <= nx && cur.y + j <= ny) {
             if (dist[0][cur.x + i][cur.y + j] >= cur.d + 1) {
               if (dist[0][cur.x + i][cur.y + j] > cur.d + 1) {
                 ans[0][cur.x + i][cur.y + j] = 0;
                 dist[0][cur.x + i][cur.y + j] = cur.d + 1;
                 que.push(Node(0, cur.x + i, cur.y + j, cur.d + 1));
               }
               ans[0][cur.x + i][cur.y + j] += ans[1][cur.x][cur.y] *
                                               C[nx - cur.x][i] % MOD *
                                               C[ny - cur.y][j] % MOD;
               ans[0][cur.x + i][cur.y + j] %= MOD;
             }
           }
         }
     }
     if (dist[0][nx][ny] == 0x3f3f3f3f) {
       printf( -1
0
 );
     } else {
       printf( %d
%I64d
 , dist[0][nx][ny], ans[0][nx][ny]);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 bool chmax(T &a, const T &b) {
   if (a < b) {
     a = b;
     return 1;
   }
   return 0;
 }
 template <class T>
 bool chmin(T &a, const T &b) {
   if (a > b) {
     a = b;
     return 1;
   }
   return 0;
 }
 template <class T>
 ostream &operator<<(ostream &os, const vector<T> &t) {
   os <<  [ ;
   for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
     if (it != t.begin()) os <<  , ;
     os << *it;
   }
   os <<  ] ;
   return os;
 }
 template <class T>
 ostream &operator<<(ostream &os, const set<T> &t) {
   os <<  { ;
   for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) {
     if (it != t.begin()) os <<  , ;
     os << *it;
   }
   os <<  } ;
   return os;
 }
 template <class S, class T>
 ostream &operator<<(ostream &os, const pair<S, T> &t) {
   return os <<  (  << t.first <<  ,  << t.second <<  ) ;
 }
 template <class S, class T>
 pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
   return pair<S, T>(s.first + t.first, s.second + t.second);
 }
 template <class S, class T>
 pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
   return pair<S, T>(s.first - t.first, s.second - t.second);
 }
 namespace geom {
 enum { TRUE = 1, FALSE = 0, BORDER = -1 };
 const long double INF = 1e8;
 long double EPS = 1e-6;
 const long double PI = 3.1415926535897932384626;
 inline int sig(const long double &x) {
   return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1);
 }
 inline int less(const long double &x, const long double &y) {
   return sig(x - y) ? x < y : BORDER;
 }
 inline long double norm(const complex<long double> &p) {
   return p.real() * p.real() + p.imag() * p.imag();
 }
 inline long double inp(const complex<long double> &a,
                        const complex<long double> &b) {
   return (conj(a) * b).real();
 }
 inline long double outp(const complex<long double> &a,
                         const complex<long double> &b) {
   return (conj(a) * b).imag();
 }
 inline complex<long double> unit(const complex<long double> &p) {
   return p / abs(p);
 }
 inline complex<long double> proj(const complex<long double> &s,
                                  const complex<long double> &t) {
   return t * inp(s, t) / norm(t);
 }
 inline int ccw(const complex<long double> &s, const complex<long double> &t,
                const complex<long double> &p, int adv = 0) {
   int res = sig(outp(t - s, p - s));
   if (res || !adv) return res;
   if (sig(inp(t - s, p - s)) < 0) return -2;
   if (sig(inp(s - t, p - t)) < 0) return 2;
   return 0;
 }
 }  // namespace geom
 using namespace geom;
 int f = 0;
 namespace std {
 bool operator<(const complex<long double> &a, const complex<long double> &b) {
   return sig(a.real() - b.real()) ? a.real() < b.real()
                                   : a.imag() + EPS < b.imag();
 }
 bool operator==(const complex<long double> &a, const complex<long double> &b) {
   return abs(a - b) < EPS;
 }
 istream &operator>>(istream &is, complex<long double> &p) {
   long double x, y;
   is >> x >> y;
   p = complex<long double>(x, y);
   return is;
 }
 }  // namespace std
 int n, m;
 complex<long double> p, q, v, w;
 long double vmax, ct;
 long double dist(complex<long double> v, complex<long double> wind,
                  long double t) {
   if (abs(v) > EPS) v = unit(v);
   long double l = 0, r = 1e10;
   for (int _ = 0; _ < (int)(100); _++) {
     long double mid = (l + r) / 2;
     long double vx = v.real() * mid;
     long double vy = v.imag() * mid;
     if ((vx * vx + vy * vy) <= vmax * vmax)
       l = mid;
     else
       r = mid;
   }
   return abs(v * l) * t;
 }
 int check(long double t) {
   complex<long double> s =
       q + v * min<long double>(t, ct) + w * max<long double>(t - ct, 0);
   complex<long double> vec = p - s;
   return dist(vec, v, min<long double>(t, ct)) +
              dist(vec, w, max<long double>(t - ct, 0)) >=
          abs(vec);
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cin >> q >> p;
   cin >> vmax >> ct;
   cin >> v >> w;
   long double l = 0, r = 1e10;
   for (int _ = 0; _ < (int)(100); _++) {
     long double mid = (l + r) / 2;
     if (check(mid))
       r = mid;
     else
       l = mid;
   }
   printf( %.20f
 , (double)l);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 long long a[305], Lcm;
 long long sol(long long x) {
   long long cnt = 0;
   for (long long i = 2; i * i <= x; i++) {
     if (x % i == 0) {
       cnt += 2;
       if (i * i == x) cnt--;
     }
   }
   return cnt;
 }
 int main() {
   int T;
   cin >> T;
   while (T--) {
     int ok = 1;
     scanf( %d , &n);
     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);
     sort(a, a + n);
     if (n == 1)
       Lcm = a[0] * a[0];
     else
       Lcm = a[0] * a[n - 1];
     for (int i = 1; i < (n + 1) / 2; i++) {
       if (a[i] * a[n - 1 - i] != Lcm) {
         ok = 0;
         break;
       }
     }
     if (ok && sol(Lcm) == n)
       printf( %lld
 , Lcm);
     else
       puts( -1 );
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 char ch[100001];
 int per[100001];
 bool is[100001];
 bool vis[100001];
 bool mem[100001];
 bool have[100001];
 vector<int> V;
 int main() {
   int i, j;
   int a, b;
   int n, m;
   cin >> n >> m;
   for (i = 0; i < m; i++) {
     cin >> ch[i] >> per[i];
     have[per[i]] = true;
   }
   V.clear();
   memset(is, true, sizeof is);
   for (i = 0; i < m; i++) {
     if (ch[i] == '+') {
       if (!vis[per[i]] && i) is[per[i]] = false;
       if (V.size()) {
         is[per[i]] = false;
       } else {
         for (j = i - 1; j >= 0; j--) {
           if (per[i] != per[j]) is[per[j]] = false;
           if (mem[j]) break;
         }
         mem[i - 1] = true;
       }
       V.push_back(per[i]);
     } else {
       if (!vis[per[i]]) {
         for (j = i - 1; j >= 0; j--) {
           is[per[j]] = false;
           if (mem[j]) break;
         }
         mem[i - 1] = true;
         if (V.size()) is[per[i]] = false;
       } else if (V.size() == 1) {
         if (V[0] == per[i])
           V.clear();
         else {
           int num = per[i];
           V.erase(std::remove(V.begin(), V.end(), num), V.end());
           is[num] = false;
         }
       } else if (V.size()) {
         int num = per[i];
         V.erase(std::remove(V.begin(), V.end(), num), V.end());
         is[num] = false;
       }
     }
     if (!vis[per[i]]) vis[per[i]] = true;
   }
   vector<int> res;
   res.clear();
   for (i = 1; i <= n; i++) {
     if (!have[i]) {
       res.push_back(i);
     } else {
       if (is[i]) res.push_back(i);
     }
   }
   int sz = res.size();
   cout << sz << endl;
   for (i = 0; i < sz; i++) cout << res[i] <<    ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 1e9 + 7;
 const long long inf = 2e18;
 struct custom_hash {
   static uint64_t splitmix64(uint64_t x) {
     x += 0x9e3779b97f4a7c15;
     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
     x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
     return x ^ (x >> 31);
   }
   size_t operator()(uint64_t x) const {
     static const uint64_t FIXED_RANDOM =
         chrono::steady_clock::now().time_since_epoch().count();
     return splitmix64(x + FIXED_RANDOM);
   }
 };
 int add(int a, int b) {
   int res = (a + b) % mod;
   if (res < 0) res += mod;
   return res;
 }
 int mult(int a, int b) {
   int res = (a * 1LL * b) % mod;
   if (res < mod) res += mod;
   return res;
 }
 int power(int a, int b) {
   int res = 1;
   while (b) {
     if ((b % 2) == 1) res = mult(res, a);
     a = mult(a, a);
     b /= 2;
   }
   return res;
 }
 template <typename A, typename B>
 string to_string(pair<A, B> p);
 template <typename A, typename B, typename C>
 string to_string(tuple<A, B, C> p);
 template <typename A, typename B, typename C, typename D>
 string to_string(tuple<A, B, C, D> p);
 string to_string(const string &s) { return ' ' + s + ' '; }
 string to_string(const char *s) { return to_string((string)s); }
 string to_string(bool b) { return (b ?  true  :  false ); }
 string to_string(char c) { return to_string(string(1, c)); }
 string to_string(vector<bool> v) {
   bool first = true;
   string res =  { ;
   for (int i = 0; i < static_cast<int>(v.size()); i++) {
     if (!first) {
       res +=  ,  ;
     }
     first = false;
     res += to_string(v[i]);
   }
   res +=  } ;
   return res;
 }
 template <size_t N>
 string to_string(bitset<N> v) {
   string res =   ;
   for (size_t i = 0; i < N; i++) {
     res += static_cast<char>('0' + v[i]);
   }
   return res;
 }
 template <typename A>
 string to_string(A v) {
   bool first = true;
   string res =  { ;
   for (const auto &x : v) {
     if (!first) {
       res +=  ,  ;
     }
     first = false;
     res += to_string(x);
   }
   res +=  } ;
   return res;
 }
 template <typename A, typename B>
 string to_string(pair<A, B> p) {
   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;
 }
 template <typename A, typename B, typename C>
 string to_string(tuple<A, B, C> p) {
   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +
          to_string(get<2>(p)) +  ) ;
 }
 template <typename A, typename B, typename C, typename D>
 string to_string(tuple<A, B, C, D> p) {
   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +
          to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;
 }
 void dbg() { cout << endl; }
 template <typename Head, typename... Tail>
 void dbg(Head H, Tail... T) {
   cout <<     << to_string(H);
   dbg(T...);
 }
 void solve() {
   int n;
   cin >> n;
   vector<int> v(n);
   for (int i = 0; i < n; i++) {
     cin >> v[i];
   }
   vector<int> dp(1 << 22, 0);
   for (int i = 0; i < n; i++) {
     dp[v[i]] = v[i];
   }
   for (int mask = 1; mask < (1 << 22); mask++) {
     for (int i = 0; i < 22; i++) {
       if (mask & (1 << i)) {
         dp[mask] = max(dp[mask], dp[mask ^ (1 << i)]);
       }
     }
   }
   for (int i = 0; i < n; i++) {
     int no = ((1 << 22) - 1) & (~v[i]);
     if (dp[no]) {
       cout << dp[no] <<    ;
     } else {
       cout <<  -1  ;
     }
   }
 }
 int32_t main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   cout << fixed << setprecision(10);
   int t = 1;
   for (int i = 1; i <= t; i++) {
     solve();
   }
 }


#include<bits/stdc++.h>
 using namespace std;
 #define ll long long
 #define ld long double
 #define For(i,x,y) for(ll i = (x);i <= (y);++i)
 #define FOr(i,x,y) for(ll i = (x);i >= (y);--i)
 #define fi first
 #define se second
 #define pa pair<ll,ll>
 #define mk make_pair
 #define pb push_back
 #define clr(a,b) memset(a,b,sizeof(a))
 #define cpy(a,b) memcpy(a,b,sizeof(b))
 #define y1 y11111111111111111111
 #define debug puts( @@@@@@@@@@@@@@@@@@@@ )
 #define NO puts( NO )
 #define YES puts( YES )
 #define Yes puts( Yes )
 #define No puts( No )
 inline ll read()
 {
 	ll x = 0,f = 1;char ch = getchar();
 	while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
 	while(ch >= '0' && ch <= '9'){x = x*10+ch-'0';ch = getchar();}
 	return x*f;
 }
 char s[999];
 int main()
 {
 	while (scanf( %s ,s)!=EOF)
 	{
 		if (s[1]=='s') puts( NO ),fflush(stdout);
 	}
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 double s;
 vector<int> E[100005];
 int dist[100005], pa[100005];
 int dfs(int u, int p, int d) {
   dist[u] = d;
   int ans = u;
   for (int v : E[u]) {
     if (v == p) continue;
     int tmp = dfs(v, u, d + 1);
     pa[v] = u;
     if (dist[ans] < dist[tmp]) ans = tmp;
   }
   return ans;
 }
 int main() {
   scanf( %d%lf , &n, &s);
   for (int i = 0; i < n - 1; i++) {
     int u, v;
     scanf( %d%d , &u, &v);
     E[u].push_back(v);
     E[v].push_back(u);
   }
   if (n == 2) {
     printf( %.10lf
 , s);
     return 0;
   }
   int l = 0;
   for (int i = 1; i <= n; i++) {
     if (E[i].size() == 1) l++;
   }
   printf( %.10lf
 , 2.0 * s / l);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long mk[100000];
 int main() {
   long a, b, m, r0, r;
   cin >> a >> b >> m >> r0;
   for (long i = 0; i < m; i++) mk[i] = -1;
   r = (a * r0 + b) % m;
   mk[r] = 1;
   long k = 1;
   while (true) {
     k++;
     r = (a * r + b) % m;
     if (mk[r] == -1)
       mk[r] = k;
     else {
       cout << k - mk[r];
       return 0;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, maxi = 2, ans = 2;
 int a[100005];
 vector<int> num;
 int main() {
   cin >> n;
   for (int i = 0; i < n; i++) cin >> a[i];
   if (n < 3) {
     cout << n;
     return 0;
   }
   for (int i = 2; i < n; i++) {
     if (a[i] == a[i - 1] + a[i - 2]) {
       ans++;
       maxi = max(maxi, ans);
     } else
       ans = 2;
   }
   cout << maxi;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 100010;
 const int mod = 1e9 + 7;
 long long dp[maxn] = {0, 1, 2, 3, 5, 8};
 int main() {
   for (int i = 6; i < maxn; i++) dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
   int n, m;
   cin >> n >> m;
   cout << (2 * (dp[n] + dp[m] - 1)) % mod << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int Set(int N, int pos) { return N = N | (1 << pos); }
 int reset(int N, int pos) { return N = N & ~(1 << pos); }
 bool check(long long N, int pos) { return (bool)(N & (1LL << pos)); }
 int n, m, l, r;
 string s;
 char c1, c2;
 int main() {
   cin >> n >> m;
   cin >> s;
   for (int i = 1; i <= m; i++) {
     cin >> l >> r >> c1 >> c2;
     l--, r--;
     for (int j = l; j <= r; j++) {
       if (s[j] == c1) s[j] = c2;
     }
   }
   cout << s << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string s;
   cin >> s;
   set<string> g;
   g.insert(s);
   int n = s.size();
   for (int k = 0; k < s.size(); k++) {
     string s1 =   ;
     s1 += s[n - 1];
     for (int i = 0; i < s.size() - 1; i++) {
       s1 += s[i];
     }
     s = s1;
     g.insert(s);
   }
   cout << g.size();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long mod = 1000000007;
 vector<long long> parent(200005), Size(200005, 1);
 long long answer = 0;
 long long find_set(long long n) {
   if (parent[n] == n)
     return n;
   else
     return find_set(parent[n]);
 }
 void add_edge(long long a, long long b) {
   long long A = find_set(a);
   long long B = find_set(b);
   if (Size[A] >= Size[B]) {
     answer -= ((Size[A] * (Size[A] - 1)) / 2);
     answer -= ((Size[B] * (Size[B] - 1)) / 2);
     Size[A] += Size[B];
     Size[B] = 0;
     parent[B] = A;
     answer += ((Size[A] * (Size[A] - 1)) / 2);
   } else {
     answer -= ((Size[B] * (Size[B] - 1)) / 2);
     answer -= ((Size[A] * (Size[A] - 1)) / 2);
     Size[B] += Size[A];
     Size[A] = 0;
     parent[A] = B;
     answer += ((Size[B] * (Size[B] - 1)) / 2);
   }
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long N, Q, p, q, r;
   cin >> N >> Q;
   if (N == 1) {
     for (long long i = 1; i <= Q; i++) cout <<  0  ;
     return 0;
   }
   for (long long i = 1; i <= N; i++) parent[i] = i;
   vector<pair<long long, pair<long long, long long>>> G;
   for (long long i = 1; i < N; i++) {
     cin >> p >> q >> r;
     G.push_back({r, {p, q}});
   }
   sort(G.begin(), G.end());
   vector<long long> final_ans(N + 1);
   long long ptr = 0;
   for (long long i = 1; i <= N;) {
     if (G[ptr].first == i) {
       add_edge(G[ptr].second.first, G[ptr].second.second);
       ptr++;
     } else {
       final_ans[i] = answer;
       i++;
     }
   }
   while (Q--) {
     long long k;
     cin >> k;
     cout << final_ans[k] << ' ';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   map<long long, long long> isolados;
   long long n, k, i, j, prox, qtd, x, resp;
   bool first = true;
   while (cin >> n >> k) {
     resp = 0;
     isolados.clear();
     prox = -1;
     first = true;
     for (i = 0; i < k; i++) {
       cin >> qtd;
       for (j = 0; j < qtd; j++) {
         cin >> x;
         if (x == 1) prox = 1;
         if (x == prox && first == true) {
           prox++;
         } else if (j == 0) {
           isolados[x] = 0;
         } else {
           isolados[x] = 1;
         }
       }
       if (prox != -1) first = false;
     }
     for (prox; prox <= n; prox++) {
       resp += isolados[prox] + 1;
     }
     cout << resp << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, sti[101], i, x, ans;
   cin >> n;
   memset(sti, 0, sizeof(sti));
   for (i = 1; i <= n; i++) {
     cin >> x;
     sti[x]++;
   }
   ans = 0;
   for (i = 1; i <= 100; i++) {
     ans += 2 * (sti[i] / 4);
     sti[i] %= 4;
     ans += sti[i] / 2;
   }
   cout << ans / 2 << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 double a[4010];
 int main() {
   cin >> n;
   n *= 2;
   for (int i = 1; i <= n; ++i) cin >> a[i];
   for (int i = 1; i <= n; ++i) a[i] = a[i] - int(a[i]);
   int cnt = 0;
   for (int i = 1; i <= n; ++i)
     if (abs(a[i] - 0) <= 0.0000001) cnt++;
   double sum = 0;
   for (int i = 1; i <= n; ++i) sum += a[i];
   double res = 1000000001;
   for (int i = 0; i <= cnt; ++i) res = min(res, abs(n / 2 - sum - i));
   printf( %.3f , res);
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int a[100005];
   int n, i;
   scanf( %d , &n);
   for (i = 0; i < n; i++) {
     scanf( %d , &a[i]);
   }
   sort(a, a + n);
   if (a[n - 1] == 1) {
     for (i = 0; i < n - 1; i++) {
       printf( %d  , a[i]);
     }
     puts( 2 );
   } else {
     printf( 1 );
     for (i = 0; i < n - 1; i++) {
       printf(  %d , a[i]);
     }
     printf(
 );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long solve(long long a, long long b, long long c) {
   long long a1 = a - c;
   a1 *= a1;
   long long b1 = c - b;
   b1 *= b1;
   long long c1 = b - a;
   c1 *= c1;
   return a1 + b1 + c1;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int t;
   t = 1;
   cin >> t;
   while (t--) {
     long long a, b, c;
     cin >> a >> b >> c;
     vector<long long> arr(a, 0), arr1(b, 0), arr2(c, 0);
     for (int i = 0; i < a; i++) {
       cin >> arr[i];
     }
     for (int i = 0; i < b; i++) {
       cin >> arr1[i];
     }
     for (int i = 0; i < c; i++) {
       cin >> arr2[i];
     }
     sort((arr).begin(), (arr).end());
     sort((arr1).begin(), (arr1).end());
     sort((arr2).begin(), (arr2).end());
     long long ans = 4 * (1e18);
     vector<long long>::iterator it;
     it = unique((arr).begin(), (arr).end());
     arr.resize(distance(arr.begin(), it));
     it = unique((arr1).begin(), (arr1).end());
     arr1.resize(distance(arr1.begin(), it));
     it = unique((arr2).begin(), (arr2).end());
     arr2.resize(distance(arr2.begin(), it));
     a = arr.size();
     b = arr1.size();
     c = arr2.size();
     for (int i = 0; i < a; i++) {
       long long in =
           lower_bound((arr1).begin(), (arr1).end(), arr[i]) - arr1.begin();
       vector<long long> a1;
       vector<long long> b1;
       if (in == b) {
         a1.push_back(arr1[in - 1]);
       } else {
         a1.push_back(arr1[in]);
         if (in < b - 1) {
           a1.push_back(arr1[in + 1]);
         }
         if (in > 0) {
           a1.push_back(arr1[in - 1]);
         }
       }
       in = lower_bound((arr2).begin(), (arr2).end(), arr[i]) - arr2.begin();
       if (in == c) {
         b1.push_back(arr2[in - 1]);
       } else {
         b1.push_back(arr2[in]);
         if (in < c - 1) {
           b1.push_back(arr2[in + 1]);
         }
         if (in > 0) {
           b1.push_back(arr2[in - 1]);
         }
       }
       for (int j = 0; j < a1.size(); j++) {
         for (int l = 0; l < b1.size(); l++) {
           long long k = solve(arr[i], a1[j], b1[l]);
           ans = min(k, ans);
         }
       }
     }
     for (int i = 0; i < b; i++) {
       long long in =
           lower_bound((arr).begin(), (arr).end(), arr1[i]) - arr.begin();
       vector<long long> a1;
       vector<long long> b1;
       if (in == a) {
         a1.push_back(arr[in - 1]);
       } else {
         a1.push_back(arr[in]);
         if (in < a - 1) {
           a1.push_back(arr[in + 1]);
         }
         if (in > 0) {
           a1.push_back(arr[in - 1]);
         }
       }
       in = lower_bound((arr2).begin(), (arr2).end(), arr1[i]) - arr2.begin();
       if (in == c) {
         b1.push_back(arr2[in - 1]);
       } else {
         b1.push_back(arr2[in]);
         if (in < c - 1) {
           b1.push_back(arr2[in + 1]);
         }
         if (in > 0) {
           b1.push_back(arr2[in - 1]);
         }
       }
       for (int j = 0; j < a1.size(); j++) {
         for (int l = 0; l < b1.size(); l++) {
           long long k = solve(arr1[i], a1[j], b1[l]);
           ans = min(k, ans);
         }
       }
     }
     for (int i = 0; i < c; i++) {
       long long in =
           lower_bound((arr1).begin(), (arr1).end(), arr2[i]) - arr1.begin();
       vector<long long> a1;
       vector<long long> b1;
       if (in == b) {
         a1.push_back(arr1[in - 1]);
       } else {
         a1.push_back(arr1[in]);
         if (in < b - 1) {
           a1.push_back(arr1[in + 1]);
         }
         if (in > 0) {
           a1.push_back(arr1[in - 1]);
         }
       }
       in = lower_bound((arr).begin(), (arr).end(), arr2[i]) - arr.begin();
       if (in == a) {
         b1.push_back(arr[in - 1]);
       } else {
         b1.push_back(arr[in]);
         if (in < a - 1) {
           b1.push_back(arr[in + 1]);
         }
         if (in > 0) {
           b1.push_back(arr[in - 1]);
         }
       }
       for (int j = 0; j < a1.size(); j++) {
         for (int l = 0; l < b1.size(); l++) {
           long long k = solve(arr2[i], a1[j], b1[l]);
           ans = min(k, ans);
         }
       }
     }
     cout << ans <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct group {
   int sz;
   vector<int> worst, best;
   group(vector<int>& a)
       : sz(1), worst(a.begin(), a.end()), best(a.begin(), a.end()) {}
   bool operator<(const group& a) const {
     for (int i = 0; i < best.size(); i++)
       if (best[i] >= a.worst[i]) return false;
     return true;
   }
   struct group& operator+=(const group& a) {
     sz += a.sz;
     for (int i = 0; i < best.size(); i++) {
       best[i] = max(best[i], a.best[i]);
       worst[i] = min(worst[i], a.worst[i]);
     }
     return *this;
   }
 };
 set<group> positions;
 int main() {
   int n, k;
   scanf( %d %d , &n, &k);
   while (n--) {
     vector<int> skills(k, 0);
     for (int i = 0; i < k; i++) scanf( %d , &skills[i]);
     group player = group(skills);
     auto f = positions.lower_bound(player), l = positions.upper_bound(player);
     while (f != l) {
       player += *f;
       f = positions.erase(f);
     }
     positions.insert(f, player);
     printf( %d
 , positions.rbegin()->sz);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 1e5 + 10, STAN = (1 << 30) - 1;
 struct QJ {
   int l, r, q;
 } q[MAXN];
 int n, m;
 struct Seg {
   int water[MAXN * 4], sh[MAXN * 4];
   bool fir[MAXN * 4];
   Seg() {
     memset(water, 0, sizeof(water));
     memset(fir, 0, sizeof(fir));
   }
   int _st, _ed, _x, _t;
   void _insert(int num, int l, int r) {
     if (_st <= l && r <= _ed) {
       water[num] |= _x;
       return;
     }
     int mid = (l + r) >> 1;
     if (_st <= mid) _insert(num << 1, l, mid);
     if (_ed >= mid + 1) _insert(num << 1 | 1, mid + 1, r);
   }
   int _swim(int num, int l, int r, int now) {
     int x;
     now |= water[num];
     if (l == r) {
       if (!fir[num]) {
         sh[num] = now;
         fir[num] = true;
       } else
         sh[num] &= now;
       return now;
     }
     int mid = (l + r) >> 1;
     if (_t <= mid)
       now = _swim(num << 1, l, mid, now);
     else
       now = _swim(num << 1 | 1, mid + 1, r, now);
     if (!fir[num]) {
       sh[num] = now;
       fir[num] = true;
     } else
       sh[num] &= now;
     return now;
   }
   int _check(int num, int l, int r) {
     if (l == r) return sh[num];
     if (_st <= l && r <= _ed) return sh[num];
     int mid = (l + r) >> 1;
     int ans = STAN;
     if (_st <= mid) ans &= _check(num << 1, l, mid);
     if (_ed >= mid + 1) ans &= _check(num << 1 | 1, mid + 1, r);
     return ans;
   }
   inline void Insert(int l, int r, int q) {
     _st = l, _ed = r, _x = q;
     _insert(1, 1, n);
   }
   inline int Swim(int t) {
     _t = t;
     return _swim(1, 1, n, 0);
   }
   inline bool Check(int l, int r, int q) {
     _st = l;
     _ed = r;
     return _check(1, 1, n) == q;
   }
 } T;
 int a[MAXN];
 int main() {
   scanf( %d%d , &n, &m);
   for (int i = 1; i <= m; i++) {
     scanf( %d%d%d , &q[i].l, &q[i].r, &q[i].q);
     T.Insert(q[i].l, q[i].r, q[i].q);
   }
   for (int i = 1; i <= n; i++) a[i] = T.Swim(i);
   for (int i = 1; i <= m; i++)
     if (!T.Check(q[i].l, q[i].r, q[i].q)) {
       printf( NO
 );
       return 0;
     }
   printf( YES
 );
   for (int i = 1; i <= n; i++) printf( %d  , a[i]);
   printf(
 );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 pair<int, int> a[5003];
 vector<int> color[5003];
 int ans[5003];
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int n, k, i, j;
   cin >> n >> k;
   for (i = 0; i < n; i++) {
     cin >> a[i].first;
     a[i].second = i;
   }
   sort(a, a + n);
   for (i = 0; i < n; i++) {
     color[i % k].push_back(a[i].first);
     ans[a[i].second] = (i % k);
   }
   for (i = 0; i < k; i++) {
     for (j = 1; j < color[i].size(); j++) {
       if (color[i][j] == color[i][j - 1]) {
         cout <<  NO ;
         return 0;
       }
     }
   }
   cout <<  YES
 ;
   for (i = 0; i < n; i++) {
     cout << (ans[i] + 1) <<    ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC target( avx2 )
 #pragma GCC optimization( O3 )
 #pragma GCC optimization( unroll-loops )
 using namespace std;
 const long long N = 1e5 + 10;
 const long double Pie = acos(-1);
 signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   long long t;
   cin >> t;
   while (t--) {
     long long n;
     cin >> n;
     long long arr[n];
     for (long long i = 0; i < n; i++) cin >> arr[i];
     for (long long i = 0; i < n; i++) {
       if (i % 2 == 0) {
         if (arr[i] >= 0)
           cout << arr[i] <<    ;
         else
           cout << -1 * arr[i] <<    ;
       } else if (i % 2 == 1) {
         if (arr[i] <= 0)
           cout << arr[i] <<    ;
         else
           cout << -1 * arr[i] <<    ;
       }
     }
     cout <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 1e9 + 7;
 const int maxn = 200005;
 vector<int> g[maxn];
 int dis[maxn];
 int pa[maxn];
 set<pair<int, int>> st;
 void dfs(int now, int pre = 0) {
   if (dis[now] > 2) {
     st.insert({dis[now], now});
   }
   for (auto &i : g[now]) {
     if (i ^ pre) {
       pa[i] = now;
       dis[i] = dis[now] + 1;
       dfs(i, now);
     }
   }
 }
 void go() {
   int n;
   cin >> n;
   for (int i = 0; i < n - 1; i++) {
     int x, y;
     cin >> x >> y;
     g[x].push_back(y);
     g[y].push_back(x);
   }
   dfs(1);
   int ans = 0;
   while (st.size()) {
     auto x = *(--st.end());
     int v = pa[x.second];
     st.erase({dis[v], v});
     for (auto &i : g[v]) {
       st.erase({dis[i], i});
     }
     ans++;
   }
   cout << ans << '
';
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int c = 0;
   int t;
   if (!c) {
     t = 1;
   } else {
     cin >> t;
   }
   while (t--) {
     go();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int newarr[1005];
 long long int dp[1005][1005];
 long long int n, k;
 long long int solution(long long int index, long long int m) {
   if (m < 0) m += k;
   if (index >= n && m != 0)
     return 0;
   else if (m == 0)
     return 1;
   else if (dp[index][m] != -1)
     return dp[index][m];
   else {
     long long int x = solution(index + 1, m);
     long long int y = solution(index + 1, m - newarr[index]);
     if (x > 0) x = 1;
     if (y > 0) y = 1;
     if (m >= newarr[index]) {
       dp[index + 1][m - newarr[index]] = y;
     }
     dp[index + 1][m] = x;
     return x + y;
   }
 }
 int32_t main() {
   memset(dp, -1, sizeof(dp));
   cin >> n;
   cin >> k;
   long long int arr[n];
   long long int ctr = 0;
   for (long long int i = 0; i < n; i++) {
     cin >> arr[i];
   }
   if (n > k) {
     cout <<  YES
 ;
   } else {
     for (long long int i = 0; i < n; i++) {
       newarr[i] = arr[i] % k;
       if (newarr[i] == 0) ctr++;
     }
     long long int x = solution(0, k);
     if (x > 0 || ctr > 0)
       cout <<  YES
 ;
     else
       cout <<  NO ;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 typedef long long lo;
 typedef vector<lo> vl;
 typedef vector<lo> vll;
 typedef vector<vl> vvl;
 template <typename T>
 ostream &operator<<(ostream &o, vector<T> v) {
   if (v.size() > 0) o << v[0];
   for (unsigned i = 1; i < v.size(); i++) o <<     << v[i];
   return o <<
 ;
 }
 template <typename U, typename V>
 ostream &operator<<(ostream &o, pair<U, V> p) {
   return o <<  (  << p.first <<  ,   << p.second <<  )  ;
 }
 template <typename T>
 istream &operator>>(istream &in, vector<T> &v) {
   for (unsigned i = 0; i < v.size(); i++) in >> v[i];
   return in;
 }
 template <typename T>
 istream &operator>>(istream &in, pair<T, T> &p) {
   in >> p.first;
   in >> p.second;
   return in;
 }
 string s;
 lo len[203][2];
 lo dp[203][203][203][2];
 lo cal(string &t) {
   for (lo i = t.size(); i > 0; i--) {
     if (s.substr(0, i) == t.substr(t.size() - i, i)) return i;
   }
   return 0;
 }
 void add(lo &a, lo b) {
   a += b;
   if (a >= 1000000007) a -= 1000000007;
   if (a < 0) a += 1000000007;
 }
 int main() {
   std::ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cout.precision(20);
   lo n, ssz;
   cin >> n >> s;
   ssz = s.size();
   if (s[0] == '(')
     len[0][0] = 1;
   else
     len[0][1] = 1;
   string pref;
   for (lo i = (0); i < (lo)ssz; i++) {
     pref += s[i];
     pref += '(';
     len[i + 1][0] = cal(pref);
     pref.pop_back();
     pref += ')';
     len[i + 1][1] = cal(pref);
     pref.pop_back();
   }
   dp[0][0][0][0] = 1;
   for (lo i = (0); i < (lo)2 * n; i++) {
     for (lo(j) = 0; (j) < (n + 1); (j)++) {
       for (lo(pos) = 0; (pos) < (ssz + 1); (pos)++) {
         for (lo(f) = 0; (f) < (2); (f)++) {
           if (dp[i][j][pos][f] == 0) continue;
           if (j + 1 <= n)
             add(dp[i + 1][j + 1][len[pos][0]][f | (len[pos][0] == ssz)],
                 dp[i][j][pos][f]);
           if (j > 0)
             add(dp[i + 1][j - 1][len[pos][1]][f | (len[pos][1] == ssz)],
                 dp[i][j][pos][f]);
         }
       }
     }
   }
   lo ans = 0;
   for (lo i = (0); i < (lo)ssz + 1; i++) add(ans, dp[2 * n][0][i][1]);
   cout << ans <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 inline void checkMax(T& a, const T& b) {
   if (a < b) a = b;
 }
 template <typename T>
 inline void checkMin(T& a, const T& b) {
   if (a > b) a = b;
 }
 const int kMod = 1000000007;
 template <typename U, typename V>
 inline void addMod(U& x, const V y) {
   x += y;
   if (x >= kMod) {
     x -= kMod;
   }
 }
 template <int N>
 struct CombinationTable {
   CombinationTable() { init(); }
   static long long table[N + 1][N + 1];
   static void init() {
     table[0][0] = 1;
     for (int i = 1; i <= N; ++i) {
       table[i][0] = table[i][i] = 1;
       for (int j = 1; j < i; ++j) {
         table[i][j] = table[i - 1][j] + table[i - 1][j - 1];
       }
     }
   }
 };
 template <int N>
 long long CombinationTable<N>::table[N + 1][N + 1];
 CombinationTable<40> comb_tbl;
 long long n, t;
 void go() {
   if ((t & -t) != t) {
     puts( 0 );
     return;
   }
   ++n;
   int tt = 1;
   while (t >>= 1) ++tt;
   int num_one;
   long long tmp = n;
   do {
     num_one += (tmp & 1);
   } while (tmp >>= 1);
   long long ans = (tt == num_one);
   for (int n___LINE__ = (50), i = 0; i < n___LINE__; ++i) {
     if (n & 1) {
       --num_one;
       if (num_one <= tt && i >= 0 && tt >= num_one && tt - num_one <= i) {
         ans += comb_tbl.table[i][tt - num_one];
       }
     }
     n >>= 1;
   }
   if (tt == 1) --ans;
   cout << ans << endl;
 }
 int main() {
   cin >> n >> t;
   go();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename S, typename T>
 ostream& operator<<(ostream& out, const pair<S, T> p) {
   out <<  (  << p.first <<  ,  << p.second <<  ) ;
   return out;
 }
 template <typename T>
 ostream& operator<<(ostream& out, const vector<T>& v) {
   for (auto a : v) out << a <<    ;
   return out;
 }
 template <typename T>
 ostream& operator<<(ostream& out, const set<T>& S) {
   for (auto a : S) cout << a <<    ;
   return out;
 }
 template <typename T>
 ostream& operator<<(ostream& out, const multiset<T>& S) {
   for (auto a : S) cout << a <<    ;
   return out;
 }
 template <typename S, typename T>
 ostream& operator<<(ostream& out, const map<S, T>& M) {
   for (auto m : M) cout <<  (  << m.first <<  ->  << m.second <<  )  ;
   return out;
 }
 template <typename S, typename T>
 pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
   return make_pair(a.first + b.first, a.second + b.second);
 }
 template <typename S, typename T>
 pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
   return make_pair(a.first - b.first, a.second - b.second);
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int n;
   cin >> n;
   cout << n + n / 2 << endl;
   return 0;
 }


#include <bits/stdc++.h>
 inline long long rd() {
   long long _x = 0;
   int _ch = getchar(), _f = 1;
   for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar())
     ;
   if (_ch == '-') {
     _f = 0;
     _ch = getchar();
   }
   for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0';
   return _f ? _x : -_x;
 }
 void write(long long _x) {
   if (_x >= 10)
     write(_x / 10), putchar(_x % 10 + '0');
   else
     putchar(_x + '0');
 }
 inline void wrt(long long _x, char _p) {
   if (_x < 0) putchar('-'), _x = -_x;
   write(_x);
   if (_p) putchar(_p);
 }
 int n, m;
 char s[1005][1005];
 bool flag1, flag2;
 bool vis[1005][1005];
 void dfs(int x, int y) {
   if (vis[x][y] || s[x][y] != '#' || x == 0 || y == 0 || x == n + 1 ||
       y == m + 1)
     return;
   vis[x][y] = 1;
   dfs(x + 1, y), dfs(x, y + 1);
   dfs(x - 1, y), dfs(x, y - 1);
 }
 int main() {
   n = rd(), m = rd();
   for (int i = 1; i <= n; i++) {
     scanf( %s , s[i] + 1);
   }
   for (int i = 1; i <= n; i++) {
     bool tag = 0;
     for (int j = 1; j <= m; j++) {
       if (s[i][j] == '#') tag = 1;
     }
     flag1 |= !tag;
   }
   for (int i = 1; i <= m; i++) {
     bool tag = 0;
     for (int j = 1; j <= n; j++) {
       if (s[j][i] == '#') tag = 1;
     }
     flag2 |= !tag;
   }
   if (((!flag1) && (flag2)) || ((flag1) && (!flag2))) {
     printf( -1
 );
     return 0;
   }
   bool flag = 0;
   for (int i = 1; i <= n; i++) {
     for (int j = 1; j <= m; j++) {
       if (s[i][j] == '#') {
         int t = j;
         while (s[i][t] == '#') t++;
         for (int k = t; k <= m; k++)
           if (s[i][k] == '#') flag = 1;
       }
     }
   }
   for (int i = 1; i <= m; i++) {
     for (int j = 1; j <= n; j++) {
       if (s[j][i] == '#') {
         int t = j;
         while (s[t][i] == '#') t++;
         for (int k = t; k <= n; k++)
           if (s[k][i] == '#') flag = 1;
       }
     }
   }
   if (flag) {
     printf( -1
 );
     return 0;
   }
   int cnt = 0;
   for (int i = 1; i <= n; i++) {
     for (int j = 1; j <= m; j++)
       if (s[i][j] == '#' && !vis[i][j]) {
         dfs(i, j);
         cnt++;
       }
   }
   wrt(cnt, '
');
 }


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


#include <bits/stdc++.h>
 using namespace std;
 int n, m;
 int p[100];
 char mm[100];
 int main() {
   while (scanf( %d , &n) != EOF) {
     scanf( %s , &mm);
     int len = strlen(mm);
     m = 0;
     for (int i = 0; i < len; ++i) m = m * 10 + (mm[i] - '0');
     if (n == 0) {
       if (strlen(mm) != 1)
         puts( WRONG_ANSWER );
       else if (m == 0)
         puts( OK );
       else
         puts( WRONG_ANSWER );
     } else {
       if (mm[0] == '0') {
         puts( WRONG_ANSWER );
         return 0;
       }
       int x = n;
       memset(p, 0, sizeof(p));
       while (x > 0) {
         p[x % 10]++;
         x /= 10;
       }
       int now = 0;
       for (int i = 1; i <= 9; ++i)
         if (p[i]) {
           now = i;
           p[i]--;
           break;
         }
       for (int i = 0; i <= 9; ++i) {
         while (p[i]) {
           now = now * 10 + i;
           p[i]--;
         }
       }
       if (now == m)
         puts( OK );
       else
         puts( WRONG_ANSWER );
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MX_N = 3e5 + 5;
 const int MX_M = 3e5 + 5;
 int N, M, D[MX_N];
 vector<pair<int, int>> al[MX_N];
 int vis[MX_N], sumD;
 vector<int> edges;
 void dfs(int u, int p = 0, int pe = 0) {
   vis[u] = 1;
   for (auto v : al[u])
     if (!vis[v.first]) {
       dfs(v.first, u, v.second);
     }
   if (D[u]) edges.push_back(pe), D[p] ^= 1;
 }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cin >> N >> M;
   for (int i = (1); i <= (N); ++i) {
     cin >> D[i];
     if (D[i] >= 0) sumD += D[i];
   }
   for (int i = (1); i <= (M); ++i) {
     int U, V;
     cin >> U >> V;
     al[U].emplace_back(V, i);
     al[V].emplace_back(U, i);
   }
   for (int i = (1); i <= (N); ++i)
     if (D[i] == -1) {
       if (sumD & 1)
         D[i] = 1, ++sumD;
       else
         D[i] = 0;
     }
   if (sumD & 1)
     cout << -1;
   else {
     dfs(1);
     cout << ((int)(edges).size()) << '
';
     sort(edges.begin(), edges.end());
     for (int& e : edges) cout << e << ' ';
   }
 }


#include <bits/stdc++.h>
 long long RemoveZeros(long long a) {
   long long temp;
   long long x = 0;
   long long i = 10;
   while (a > 0) {
     if (a % 10 != 0) {
       temp = (a % 10) * i;
       x += temp;
       i *= 10;
     }
     a /= 10;
   }
   return x / 10;
 }
 using namespace std;
 int main() {
   long long a, b, c;
   cin >> a >> b;
   c = a + b;
   long long a1 = RemoveZeros(a);
   long long b1 = RemoveZeros(b);
   long long c1 = RemoveZeros(c);
   if (a1 + b1 == c1)
     cout <<  YES ;
   else
     cout <<  NO ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using li = long long;
 using ld = long double;
 using pii = pair<int, int>;
 const int INF = 1e9 + 13;
 const int N = 2e5 + 13;
 const int M = 1e9 + 7;
 const int B = 600;
 const int A = 256;
 const ld e = 1e-8;
 const int LOGN = 20;
 mt19937 rnd(time(0));
 void solve() {
   int n, m;
   cin >> n >> m;
   vector<bool> a(n, false);
   for (int i = 0; i < m; i++) {
     int x, y, z;
     cin >> x >> y >> z;
     y--;
     a[y] = true;
   }
   int v = -1;
   for (int i = 0; i < n; i++)
     if (!a[i]) v = i;
   for (int i = 0; i < n; i++) {
     if (i != v) cout << v + 1 << ' ' << i + 1 << '
';
   }
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int t = 1;
   cin >> t;
   while (t--) solve();
 }


#include <bits/stdc++.h>
 #pragma GCC optimize  03
 using namespace std;
 const int N = 1e5 + 5;
 const int mod = 1e9 + 7;
 const int inf = 1e9 + 9;
 pair<int, int> ans[1004];
 signed main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   string s;
   cin >> s;
   int c1 = 0, c2 = 0;
   for (int i = 0; i < s.length(); i++) {
     if (s[i] == '0') {
       if (c1 == 0) {
         c1 = 1;
         ans[i].first = 3, ans[i].second = 1;
       } else {
         c1 = 0;
         ans[i].first = 1, ans[i].second = 1;
       }
     } else {
       if (c2 == 0) {
         c2 = 1;
         ans[i].first = 1, ans[i].second = 3;
       } else {
         c2 = 0;
         ans[i].first = 1, ans[i].second = 1;
       }
     }
   }
   for (int i = 0; i < s.length(); i++)
     cout << ans[i].first <<     << ans[i].second << '
';
   return 0;
 }


#include <bits/stdc++.h>
 const int MAX_N = 1e5 + 5;
 int n, m;
 char str[MAX_N], nxt[256];
 bool chk[256], vis[256], not_root[256], flag;
 std::vector<char> ans;
 void dfs(char c) {
   if (!vis[c]) {
     vis[c] = true;
     ans.push_back(c);
     if (nxt[c]) dfs(nxt[c]);
   } else
     flag = true;
 }
 int main() {
   scanf( %d , &n);
   while (n--) {
     scanf(  %s , str);
     m = strlen(str);
     for (int i = 0; i < m; ++i) chk[str[i]] = true;
     for (int i = 0; i + 1 < m; ++i) {
       if (nxt[str[i]] == 0)
         nxt[str[i]] = str[i + 1];
       else if (nxt[str[i]] != str[i + 1]) {
         printf( NO
 );
         return 0;
       }
       not_root[str[i + 1]] = true;
     }
   }
   for (char i = 'a'; i <= 'z'; ++i)
     if (!not_root[i] && chk[i]) dfs(i);
   for (char i = 'a'; i <= 'z'; ++i) flag |= chk[i] != vis[i];
   if (flag) {
     printf( NO
 );
     return 0;
   }
   for (char c : ans) printf( %c , c);
   printf(
 );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct S {
   int a, b;
   S() {}
   S(int _a, int _b) {
     a = _a;
     b = _b;
   }
   const bool operator<(const S &o) const { return a < o.a; }
 };
 string exm;
 inline void exf(void) {
   cout << exm <<
 ;
   exit(0);
 }
 template <typename T>
 inline void showAll(vector<T> &v, string sep =   ) {
   for (T &here : v) cout << here << sep;
 }
 template <typename T>
 inline void showAll(T arr[], int st, int end, string sep =   ) {
   for (int i = st; i <= end; i++) cout << arr[i] << sep;
 }
 template <typename T>
 inline vector<int> int_seperation(T N, int d = 10) {
   vector<int> v;
   while (N) {
     v.push_back(N % d);
     N /= d;
   }
   reverse(v.begin(), v.end());
   return v;
 }
 const int SIZE = 500009;
 char s[SIZE], t[SIZE];
 int main() {
   int n, k;
   scanf( %d %d , &n, &k);
   scanf( %s %s , s + 1, t + 1);
   long long INF = 1e18, ans = 0, diff = 0;
   for (int i = 1; i <= n; i++) {
     diff = 2 * diff + (t[i] - s[i]);
     diff = min(diff, INF);
     ans += min(diff + 1, (long long)k);
   }
   printf( %lld
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void qmax(int &x, int y) {
   if (x < y) x = y;
 }
 void qmin(int &x, int y) {
   if (x > y) x = y;
 }
 inline long long read() {
   char s;
   long long k = 0, base = 1;
   while ((s = getchar()) != '-' && s != EOF && !(isdigit(s)))
     ;
   if (s == EOF) exit(0);
   if (s == '-') base = -1, s = getchar();
   while (isdigit(s)) {
     k = k * 10 + (s ^ '0');
     s = getchar();
   }
   return k * base;
 }
 inline void write(int x) {
   static char cnt, num[15];
   cnt = 0;
   if (!x) {
     printf( 0 );
     return;
   }
   for (; x; x /= 10) num[++cnt] = x % 10;
   for (; cnt; putchar(num[cnt--] + 48))
     ;
 }
 const int maxn = 2020;
 int n, k;
 char ch[maxn][maxn];
 int a[maxn][maxn], Max;
 char d[maxn + maxn];
 bool vis[maxn][maxn];
 int main() {
   n = read();
   k = read();
   for (int i = 1; i <= n; i++) {
     scanf( %s , ch[i] + 1);
   }
   if (k >= (2 * n - 1)) {
     for (int i = 1; i <= n + n - 1; i++) putchar('a');
     return 0;
   }
   memset(a, 0x3f3f, sizeof(a));
   a[1][1] = 1;
   if (ch[1][1] == 'a') a[1][1] = 0;
   for (int l = 2; l <= n + n; l++) {
     for (int i = 1, j; i <= n; i++) {
       j = l - i;
       if (j <= 0) break;
       if (j > n) continue;
       if (i > n) continue;
       if (j + 1 <= n) qmin(a[i][j + 1], a[i][j] + (ch[i][j + 1] != 'a'));
       if (i + 1 <= n) qmin(a[i + 1][j], a[i][j] + (ch[i + 1][j] != 'a'));
       if (a[i][j] <= k) Max = max(Max, l);
     }
   }
   if (Max == n + n) {
     for (int i = 1; i <= n + n - 1; i++) putchar('a');
     return 0;
   }
   bool flag = false;
   if (!Max) Max = 2, vis[1][1] = true, d[2] = ch[1][1], flag = true;
   for (int i = 1, j; i <= n; i++) {
     j = Max - i;
     if (j <= 0) break;
     if (j > n) continue;
     if (a[i][j] <= k) vis[i][j] = true;
   }
   for (int l = Max; l <= n + n; l++) {
     char z = 'z';
     for (int i = 1, j; i <= n; i++) {
       j = l - i;
       if (j <= 0) break;
       if (j > n) continue;
       if (!vis[i][j]) continue;
       if (j + 1 <= n) z = min(z, ch[i][j + 1]);
       if (i + 1 <= n) z = min(z, ch[i + 1][j]);
     }
     d[l + 1] = z;
     for (int i = 1, j; i <= n; i++) {
       j = l - i;
       if (j <= 0) break;
       if (j > n) continue;
       if (!vis[i][j]) continue;
       if (j + 1 <= n && ch[i][j + 1] == z) vis[i][j + 1] = true;
       if (i + 1 <= n && ch[i + 1][j] == z) vis[i + 1][j] = true;
     }
   }
   if (flag) Max--;
   for (int i = 2; i <= Max; i++) d[i] = 'a';
   for (int i = 2; i <= n + n; i++) {
     putchar(d[i]);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long read() {
   long long a = 0;
   char c = getchar();
   while (c > '9' || c < '0') c = getchar();
   while ('0' <= c && c <= '9') {
     a = a * 10 + c - 48;
     c = getchar();
   }
   return a;
 }
 struct data {
   long long x, y, c;
   data(long long X = 0, long long Y = 0, long long C = 0) {
     x = X;
     y = Y;
     c = C;
   }
 } w[2005], e[2005];
 long long n, k, L;
 bool cmp(data a, data b) { return a.x < b.x; };
 bool cmp2(data a, data b) { return a.y < b.y; }
 long long nxt[2005], f[2005];
 multiset<long long> Set[2005];
 long long sum[2005 << 2], Max[2005 << 2], tag[2005 << 2];
 void pushup(long long x) {
   sum[x] = (sum[(x << 1)] + sum[(x << 1 | 1)]) % 1000000007;
   assert(Max[(x << 1)] <= Max[(x << 1 | 1)]);
   Max[x] = Max[(x << 1 | 1)];
 }
 void build(long long x, long long l, long long r) {
   tag[x] = 0;
   if (l == r) {
     sum[x] = f[l] * (e[l].y - e[l - 1].y) % 1000000007;
     Max[x] = f[l];
     return;
   }
   build((x << 1), l, ((l + r) >> 1));
   build((x << 1 | 1), ((l + r) >> 1) + 1, r);
   pushup(x);
 }
 void ptag(long long x, long long l, long long r, long long v) {
   assert(Max[x] <= v);
   sum[x] = v * (e[r].y - e[l - 1].y) % 1000000007;
   tag[x] = Max[x] = v;
 }
 void pushdown(long long x, long long l, long long r) {
   if (tag[x]) {
     ptag((x << 1), l, ((l + r) >> 1), tag[x]);
     ptag((x << 1 | 1), ((l + r) >> 1) + 1, r, tag[x]);
     tag[x] = 0;
   }
 }
 void chkmax(long long x, long long l, long long r, long long b, long long e,
             long long v) {
   if (r < b || l > e) return;
   if (l == r && Max[x] > v) return;
   if (Max[x] <= v && b <= l && r <= e) {
     ptag(x, l, r, v);
     return;
   }
   bool flag = (v > Max[(x << 1)]);
   pushdown(x, l, r);
   chkmax((x << 1), l, ((l + r) >> 1), b, e, v);
   if (flag) chkmax((x << 1 | 1), ((l + r) >> 1) + 1, r, b, e, v);
   pushup(x);
 }
 signed main() {
   n = read();
   k = read();
   L = read();
   for (long long i = 1; i <= n; ++i) {
     w[i].x = read() + 1;
     w[i].y = read() + 1;
     w[i].c = read();
     e[i] = w[i];
   }
   sort(w + 1, w + 1 + n, cmp);
   sort(e + 1, e + 1 + n, cmp2);
   e[n + 1].y = L + 1;
   w[n + 1].x = w[n + 2].x = L + 1;
   w[n + 1].y = L + 1;
   long long ans = 0;
   for (long long i = n; i; --i) {
     long long tmp = (w[i].x - w[i - 1].x);
     if (!tmp) continue;
     multiset<long long> S;
     S.clear();
     for (long long i = 1; i <= k; ++i) {
       S.insert(L + 1), nxt[i] = L + 1;
       Set[i].clear();
       Set[i].insert(L + 1);
       Set[i].insert(0);
     }
     for (long long j = n; j; --j) {
       if (e[j].x >= w[i].x) {
         S.erase(S.find(nxt[e[j].c]));
         nxt[e[j].c] = e[j].y;
         S.insert(nxt[e[j].c]);
         Set[e[j].c].insert(e[j].y);
       }
       f[j] = (*(--S.end()));
     }
     build(1, 1, n);
     for (long long j = n + 1; j > i; --j) {
       if (w[j].c) {
         assert(Set[w[j].c].find(w[j].y) != Set[w[j].c].end());
         Set[w[j].c].erase(Set[w[j].c].find(w[j].y));
         multiset<long long>::iterator it = --Set[w[j].c].upper_bound(w[j].y),
                                       ir = it;
         ++ir;
         long long ll = lower_bound(e, e + 1 + n, data(0, *it, 0), cmp2) - e;
         if (ll) assert(e[ll].y != e[ll - 1].y);
         chkmax(1, 1, n, ll + 1, n, *ir);
       }
       long long res = ((L + 1) * e[n].y - sum[1] + 1000000007) % 1000000007;
       ans =
           (ans + (res * tmp % 1000000007 * (w[j].x - w[j - 1].x))) % 1000000007;
     }
   }
   printf( %lld
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( O3 )
 #pragma GCC target( sse4 )
 using namespace std;
 using ii = pair<int, int>;
 using ll = long long;
 const int N = 1e5 + 5;
 const int mod = 1e9 + 7;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int a, b;
   cin >> a >> b;
   vector<int> ans1, ans2;
   ll limit = 0;
   for (; limit * (limit + 1) / 2 <= a + b; limit++)
     ;
   cerr << limit << '
';
   for (int i = --limit; i >= 1; i--) {
     if (a >= b)
       ans1.push_back(i), a -= i;
     else
       ans2.push_back(i), b -= i;
   }
   cout << ans1.size() << '
';
   for (auto x : ans1) cout << x << ' ';
   cout << '
';
   cout << ans2.size() << '
';
   for (auto x : ans2) cout << x << ' ';
   cout << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1e5 + 10;
 int t;
 int n;
 struct node {
   long long id, val;
   bool flag;
   friend bool operator<(node a, node b) {
     if (a.val == b.val) return a.flag == false;
     return a.val > b.val;
   }
 };
 int main() {
   while (~scanf( %d , &n)) {
     priority_queue<node> q;
     long long num;
     scanf( %lld , &num);
     node nxt;
     nxt.id = 1, nxt.val = num, nxt.flag = false;
     q.push(nxt);
     long long ans = 0;
     for (int i = 2; i <= n; ++i) {
       scanf( %lld , &num);
       nxt.flag = false;
       if (q.top().val < num) {
         node now = q.top();
         q.pop();
         ans = ans + num - now.val;
         if (now.flag) {
           now.flag = false;
           q.push(now);
         }
         nxt.flag = true;
       }
       nxt.id = i;
       nxt.val = num;
       q.push(nxt);
     }
     printf( %lld
 , ans);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 1e9 + 7, inf = 1061109567;
 const long long infll = 4557430888798830399;
 const int N = 2e5 + 5;
 int n, q, a[N], cnt[N];
 bool last[N], first[N];
 vector<int> app[N];
 bool start[N];
 signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin >> n >> q;
   for (int i = 0; i < n; i++) cin >> a[i];
   for (int i = 0; i < n; i++) app[a[i]].push_back(i);
   for (int i = 0; i < N; i++)
     if (app[i].size()) {
       first[app[i][0]] = 1;
       last[app[i].back()] = 1;
     }
   int thing = 0;
   memset(start, 0, sizeof start);
   start[0] = 1;
   for (int i = 0; i < n; i++) {
     if (first[i]) thing++;
     if (last[i]) thing--;
     if (!thing) start[i + 1] = 1;
   }
   int ans = 0;
   int cur = 0;
   while (cur < n) {
     int nxt = n - 1;
     for (int i = cur + 1; i < n; i++)
       if (start[i]) {
         nxt = i - 1;
         break;
       }
     int lolMax = 0;
     for (int i = cur; i < nxt + 1; i++) {
       cnt[a[i]]++;
       lolMax = max(lolMax, cnt[a[i]]);
     }
     ans += lolMax;
     for (int i = cur; i < nxt + 1; i++) cnt[a[i]]--;
     cur = nxt + 1;
   }
   cout << n - ans;
   return 0;
 }


#include <bits/stdc++.h>
 const int MAXN = (int)1e5 + 5;
 const int MODN = (int)1e9 + 7;
 int inf = 0x3f3f3f3f;
 using namespace std;
 char str[MAXN];
 int num[MAXN];
 int a[MAXN];
 int vis[MAXN];
 int main() {
   int n, m;
   while (scanf( %d , &n) != EOF) {
     memset(vis, 0, sizeof(vis));
     int sum = 0;
     for (int i = 0; i < n; i++) {
       scanf( %d , &a[i]);
       sum += a[i];
     }
     int it = sum * 2 / n;
     for (int i = 0; i < n; i++) {
       if (vis[i] == 0) {
         vis[i] = 1;
         printf( %d  , i + 1);
         for (int j = 0; j < n; j++) {
           if (vis[j] == 0 && a[j] + a[i] == it) {
             vis[j] = 1;
             printf( %d
 , j + 1);
             break;
           }
         }
       }
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int cntinv(vector<int> &a) {
   int n = a.size();
   int ans = 0;
   for (int i = 0; i < n; ++i) {
     for (int j = i + 1; j < n; ++j) {
       if (a[j] < a[i]) ans++;
     }
   }
   return ans;
 }
 int main(int argc, char const *argv[]) {
   int n;
   scanf( %d , &n);
   vector<int> a(n);
   for (int i = 0; i < n; ++i) {
     scanf( %d , &a[i]);
   }
   int pv = (cntinv(a) & 1);
   int m;
   scanf( %d , &m);
   while (m--) {
     int l, r, swaps;
     scanf( %d , &l);
     scanf( %d , &r);
     l--;
     r--;
     swaps = (r - l + 1) >> 1;
     int cur = pv;
     if (swaps & 1) cur = 1 - cur;
     if (cur)
       printf( odd
 );
     else
       printf( even
 );
     pv = cur;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 int a[100010], d[100010];
 int main() {
   int ans = 1, i, j;
   int temp;
   int dlen = 0, mx = 0;
   while (~scanf( %d , &n)) {
     for (i = 0; i != n; ++i) {
       dlen = mx = 0;
       scanf( %d , &temp);
       for (j = 2; j * j <= temp; j++) {
         if (temp % j == 0) {
           d[dlen++] = j;
           if (a[j] + 1 > mx) mx = a[j] + 1;
           while (temp % j == 0) temp /= j;
         }
       }
       if (temp > 1) {
         d[dlen++] = temp;
         if (a[temp] + 1 > mx) mx = a[temp] + 1;
       }
       for (j = 0; j != dlen; j++) a[d[j]] = mx;
       if (ans < mx) ans = mx;
     }
     printf( %d
 , ans);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct UF {
   vector<int> par, sz;
   UF(int n) {
     sz.resize(n);
     par.resize(n);
     for (int i = 0; i < n; i++) sz[i] = 1, par[i] = i;
   }
   int find(int x) {
     if (par[x] == x) return x;
     return par[x] = find(par[x]);
   }
   void unite(int x, int y) {
     x = find(x);
     y = find(y);
     if (x == y) return;
     if (sz[x] > sz[y]) swap(x, y);
     sz[y] += sz[x];
     par[x] = y;
   }
   bool same(int x, int y) { return find(x) == find(y); }
 };
 int main() {
   int i, j, n, m1, m2;
   cin >> n >> m1 >> m2;
   UF uf1(n), uf2(n);
   for (i = 0; i < m1; i++) {
     int a, b;
     cin >> a >> b;
     a--;
     b--;
     uf1.unite(a, b);
   }
   for (i = 0; i < m2; i++) {
     int a, b;
     cin >> a >> b;
     a--;
     b--;
     uf2.unite(a, b);
   }
   vector<pair<int, int>> p;
   for (i = 0; i < n; i++) {
     for (j = 0; j < n; j++) {
       if (!uf1.same(i, j)) p.push_back({i, j});
     }
   }
   int ans = 0;
   vector<pair<int, int>> ansv;
   for (i = 0; i < p.size(); i++) {
     int x = p[i].first, y = p[i].second;
     if (!uf1.same(x, y) && !uf2.same(x, y)) {
       uf1.unite(x, y);
       uf2.unite(x, y);
       ans++;
       ansv.push_back({x, y});
     }
   }
   cout << ans << endl;
   for (auto p : ansv) cout << p.first + 1 <<     << p.second + 1 << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = (int)1e6 + 100;
 const long long inf = (1ll << 60);
 const int mod2 = (int)998244353;
 const int mod = (int)1e9 + 7;
 int n, m;
 vector<long long> b;
 vector<long long> c;
 void add(long long x) {
   for (int i = 0; i < b.size(); i++) {
     if (c[i] & x) {
       x ^= b[i];
     }
   }
   if (x > 0) {
     long long y = 1;
     while (!(x & y)) y *= 2;
     for (int i = 0; i < b.size(); i++) {
       if (b[i] & y) {
         b[i] ^= x;
       }
     }
     b.push_back(x);
     c.push_back(y);
   }
 }
 long long d[maxn];
 int u[maxn];
 vector<pair<long long, long long> > g[maxn];
 vector<int> ord;
 void dfs(int v) {
   u[v] = 1;
   ord.push_back(v);
   for (auto to : g[v]) {
     if (u[to.first] == 0) {
       d[to.first] = d[v] ^ to.second;
       dfs(to.first);
     } else if (u[to.first] == 1) {
       add(d[v] ^ d[to.first] ^ to.second);
     }
   }
   u[v] = 2;
 }
 void solve() {
   cin >> n >> m;
   for (int i = 0; i < m; i++) {
     long long x, y, z;
     cin >> x >> y >> z;
     g[x].push_back({y, z});
     g[y].push_back({x, z});
   }
   long long ans = 0;
   for (int i = 1; i <= n; i++) {
     if (u[i]) continue;
     b.clear();
     c.clear();
     ord.clear();
     dfs(i);
     long long sz = ord.size();
     long long C = sz * (sz - 1) / 2;
     C %= mod;
     for (int j = 1; j < b.size(); j++) C = (C * 2) % mod;
     for (int j = 0; j <= 60; j++) {
       int ok = 0;
       long long cur = (1ll << j);
       for (long long x : b) {
         if (x & cur) {
           ok = 1;
         }
       }
       if (ok) {
         ans = (ans + cur % mod * C % mod) % mod;
       } else {
         long long cnt = 0;
         for (int v : ord) {
           if (d[v] & cur) {
             cnt++;
           }
         }
         long long cur_ans = cnt * (sz - cnt) % mod;
         cur_ans = (cur % mod * cur_ans) % mod;
         for (int j = 0; j < b.size(); j++) {
           cur_ans = (cur_ans * 2) % mod;
         }
         ans += cur_ans;
         ans %= mod;
       }
     }
   }
   cout << ans <<
 ;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t = 1;
   for (int i = 1; i <= t; i++) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline int read() {
   int X = 0, w = 1;
   char c = getchar();
   while (c < '0' || c > '9') {
     if (c == '-') w = -1;
     c = getchar();
   }
   while (c >= '0' && c <= '9') X = X * 10 + c - '0', c = getchar();
   return X * w;
 }
 const int N = 1000 + 10;
 int n, m, a[N];
 double f[N][N];
 int main() {
   n = read(), m = read();
   for (register int i = 1; i <= n; ++i) a[i] = read();
   for (register int i = 1; i <= n; ++i)
     for (register int j = 1; j <= n; ++j) f[i][j] = (a[i] > a[j]);
   while (m--) {
     int x = read(), y = read();
     for (register int i = 1; i <= n; ++i) {
       f[x][i] = f[y][i] = (f[x][i] + f[y][i]) / 2;
       f[i][x] = f[i][y] = 1 - f[x][i];
     }
     f[x][y] = f[y][x] = 0.5;
   }
   double ans = 0;
   for (register int i = 1; i <= n; ++i)
     for (register int j = i + 1; j <= n; ++j) ans += f[i][j];
   printf( %.9lf
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 char orz[500001];
 int gg[500001];
 int t;
 int main() {
   cin >> t;
   while (t--) {
     int n, q;
     scanf( %d%d , &n, &q);
     scanf( %s , orz + 1);
     int rrr = 1;
     for (int i = 1; i <= n; i++) {
       if (orz[i] == '+')
         gg[i] = gg[i - 1] + 1 * rrr;
       else
         gg[i] = gg[i - 1] - 1 * rrr;
       rrr *= -1;
     }
     while (q--) {
       int l, r;
       scanf( %d%d , &l, &r);
       int eee = abs(gg[r] - gg[l - 1]);
       if (eee != 0) {
         if (eee % 2 == 1) eee = 1;
         if (eee % 2 == 0) eee = 2;
       }
       cout << eee << endl << endl;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 struct debugger {
   template <typename T>
   debugger& operator,(const T& v) {
     cerr << v <<    ;
     return *this;
   }
 } dbg;
 void solve() {
   int n, m;
   cin >> n >> m;
   for (int i = 0; i < 200; i++) cout <<  9 ;
   cout << endl;
   for (int i = 0; i < 200; i++) cout <<  9 ;
   for (int i = 0; i < 199; i++) cout <<  0 ;
   cout <<  1 ;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   int t = 1, num = 1;
   while (t--) {
     ;
     ;
     solve();
     ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long MOD = 1e9 + 7;
 vector<vector<long long>> mul(vector<vector<long long>> A,
                               vector<vector<long long>> B) {
   int n = A.size();
   vector<vector<long long>> res(n, vector<long long>(n));
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < n; j++) {
       for (int k = 0; k < n; k++) {
         res[i][j] = (res[i][j] + A[i][k] * B[k][j]) % MOD;
       }
     }
   }
   return res;
 }
 vector<vector<long long>> mexp(vector<vector<long long>> M, long long e) {
   if (e == 1) return M;
   if (e % 2) return mul(M, mexp(M, e - 1));
   vector<vector<long long>> R = mexp(M, e / 2);
   return mul(R, R);
 }
 int main() {
   long long n, m;
   cin >> n >> m;
   if (m > n) {
     cout << 1 << endl;
     return 0;
   }
   vector<vector<long long>> M(m, vector<long long>(m));
   M[0][0] = M[0][m - 1] = 1;
   for (int i = 1; i < m; i++) M[i][i - 1] = 1;
   vector<vector<long long>> R = mexp(M, n - m + 1);
   long long res = 0;
   for (int i = 0; i < m; i++) res = (res + R[0][i]) % MOD;
   cout << res << endl;
 }


#include <bits/stdc++.h>
 using vi = std::vector<long long int>;
 using vvi = std::vector<vi>;
 using pii = std::pair<long long int, long long int>;
 using vpii = std::vector<pii>;
 using vvpii = std::vector<vpii>;
 using namespace std;
 const long long int N = 2e6 + 10;
 const long long int inf = 1e18 + 10;
 const long double Pi = 3.14159265;
 long long int n;
 vi a;
 long long int f(vi &a) {
   long long int n = a.size();
   if (a.empty() == 1) return 0;
   if (a.back() == 0) return a.size();
   long long int hig = 0;
   for (long long int i = 0; i <= n - 1; i++) {
     hig = max(hig, (long long int)log2(a[i]));
   }
   vi l, r;
   for (long long int i = 0; i <= n - 1; i++) {
     if ((long long int)log2(a[i]) < hig)
       l.emplace_back(a[i]);
     else
       r.emplace_back(a[i] ^ (1 << (long long int)log2(a[i])));
   }
   if (!(l.size() < r.size())) swap(l, r);
   a = vi();
   if (l.size() == 0) return f(r);
   return 1 + max(f(l), f(r));
 }
 void solve() {
   cin >> n;
   a.resize(n);
   for (long long int i = 1; i <= n; i++) cin >> a[i - 1];
   sort(a.begin(), a.end());
   cout << (a.size() - f(a));
 }
 int32_t main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   solve();
   return 0;
   long long int xx = 0;
   long long int t;
   cin >> t;
   while (t--) {
     ;
     solve();
     cout << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[111111], b[111111];
 vector<int> id[111111];
 int main() {
   int N, M;
   cin >> N >> M;
   for (int i = 1; i <= N; i++) id[i].clear();
   for (int i = 0; i < M; i++) scanf( %d , a + i);
   long long tot = 0;
   for (int i = 1; i < M; i++) {
     if (a[i] == a[i - 1]) continue;
     id[a[i]].push_back(a[i - 1]);
     id[a[i - 1]].push_back(a[i]);
     tot += abs(a[i] - a[i - 1]);
   }
   long long d = 0;
   for (int i = 1; i <= N; i++) {
     sort(id[i].begin(), id[i].end());
     long long s = 0;
     int k = id[i].size() / 2;
     for (int j = 0; j < id[i].size(); j++)
       s += abs(id[i][j] - id[i][k]) - abs(id[i][j] - i);
     if (d > s) d = s;
   }
   cout << tot + d << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long N = 1e5 + 5;
 vector<long long> tim(N), pos(N), cur(N);

 int main() {
     long long T, n, act, start, des, dir, ans, startTime;
     cin>>T;
     for(long long t = 1; t <= T; ++t) {
         tim[0] = pos[0] = start = des = act = ans = startTime = 0;
         cin>>n;
         for(long long i = 1; i <= n; ++i) {
             cin>>tim[i]>>pos[i];
             if(tim[i] >= act) {
                 cur[i] = des;
                 startTime = tim[i];
                 act = tim[i] + abs(des - pos[i]);
                 start = des;
                 des = pos[i];
             } else {
                 dir = (start <= des) ? 1 : -1;
                 cur[i] = start + dir * (tim[i] - startTime);
             }
         }
         cur[n+1] = des;
         for(long long i = 1; i <= n; ++i) {
             if(min(cur[i],cur[i+1]) <= pos[i] && pos[i] <= max(cur[i],cur[i+1])) {
                 ans += 1;
             }
         }
         cout<<ans<<endl;
     }
     return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int max_can;
 pair<int, int> red, blue;
 int main() {
   scanf( %d%d%d%d%d , &max_can, &red.first, &blue.first, &red.second,
         &blue.second);
   long long ans = 0;
   int sq = (int)sqrt(max_can);
   if (red.second >= sq) {
     for (int cnt = 0;; ++cnt) {
       if (red.second * cnt > max_can) break;
       int can = max_can - red.second * cnt;
       ans = max(ans,
                 cnt * 1ll * red.first + (can / blue.second) * 1ll * blue.first);
     }
     printf( %I64d
 , ans);
     return 0;
   } else if (blue.second >= sq) {
     for (int cnt = 0;; ++cnt) {
       if (blue.second * cnt > max_can) break;
       int can = max_can - blue.second * cnt;
       ans = max(ans,
                 cnt * 1ll * blue.first + (can / red.second) * 1ll * red.first);
     }
     printf( %I64d
 , ans);
     return 0;
   } else {
     if (red.first * 1ll * blue.second < blue.first * 1ll * red.second)
       swap(red, blue);
     for (int cnt = 0; cnt <= sq; ++cnt) {
       int weight = blue.second * cnt;
       if (weight > max_can) break;
       int can = max_can - weight;
       ans = max(ans,
                 blue.first * 1ll * cnt + (can / red.second) * 1ll * red.first);
     }
     printf( %I64d
 , ans);
     return 0;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline long long read() {
   long long x = 0, f = 0;
   char ch = getchar();
   while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
   while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
   return f ? -x : x;
 }
 inline void write(long long x) {
   if (x < 0) x = -x, putchar('-');
   if (x >= 10) write(x / 10);
   putchar(x % 10 + '0');
 }
 long long n, a[200005], tot[200005], tong[105], mx, mxat, now;
 signed main() {
   n = read();
   for (register long long i = 1; i <= n; i++) {
     a[i] = read();
     now = a[i];
     while (now && now % 2 == 0) {
       tot[i]++;
       now /= 2;
     }
     tong[tot[i]]++;
     if (tong[tot[i]] > mx) mx = tong[tot[i]], mxat = tot[i];
   }
   write(n - mx);
   puts(  );
   for (register long long i = 1; i <= n; i++)
     if (tot[i] != mxat) write(a[i]), putchar(' ');
   return 0;
 }


#include <bits/stdc++.h>
 int main() {
   int loop, cnt = 1, max = 1;
   scanf( %d , &loop);
   int arr[loop];
   for (int i = 0; i < loop; i++) scanf( %d , &arr[i]);
   for (int i = 1; i < loop; i++) {
     if (arr[i - 1] >= arr[i]) {
       cnt = 1;
     }
     if (arr[i - 1] < arr[i]) {
       cnt++;
     }
     if (max < cnt) max = cnt;
   }
   printf( %d , max);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 multiset<int> ms;
 const int MAXN = 1000000;
 int pos[MAXN], a[MAXN], b[MAXN], st[MAXN];
 int n, i, j, k, ans;
 int main() {
   scanf( %d , &n);
   for (i = 1; i <= n; ++i) {
     scanf( %d , &a[i]);
     pos[a[i]] = i;
   }
   for (j = 1; j <= n; ++j) {
     scanf( %d , &b[j]);
     int diff = j - pos[b[j]];
     st[j] = diff;
     ms.insert(diff);
   }
   for (i = 0; i < n; ++i) {
     ans = n;
     multiset<int>::iterator it = ms.lower_bound(i);
     if (it != ms.end()) ans = min(ans, abs(*(it)-i));
     if (it != ms.begin()) ans = min(ans, abs(*(--it) - i));
     cout << ans << endl;
     ms.erase(ms.find(st[i + 1]));
     int num = b[i + 1];
     ms.insert((i + n + 1) - pos[num]);
   }
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast )
 #pragma GCC optimize( unroll-loops )
 using namespace std;
 const long long N = 1000 + 5, L = 12, inf = LLONG_MAX;
 long long n, m, k;
 long long a[N][N], par[N * N], sz[N * N], res[N][N], hh, cnt;
 bool mark[N][N], vis[N][N];
 long long mp[N * N];
 vector<pair<long long, long long> > vec, all;
 set<long long> s;
 long long H[] = {0, 0, -1, 1};
 long long G[] = {1, -1, 0, 0};
 inline void er(long long x) {
   mp[x]--;
   if (mp[x] == 0) {
     s.erase(-x);
   }
   return;
 }
 inline void ad(long long x) {
   mp[x]++;
   if (mp[x] == 1) {
     s.insert(-x);
   }
   return;
 }
 long long find(long long a) {
   if (par[a] == a) return a;
   return par[a] = find(par[a]);
 }
 inline void _union(long long a, long long b) {
   a = find(a);
   b = find(b);
   if (a == b) return;
   if (sz[a] < sz[b]) swap(a, b);
   er(sz[a]);
   er(sz[b]);
   par[b] = a;
   sz[a] += sz[b];
   ad(sz[a]);
   return;
 }
 void dfs(long long x, long long y) {
   vis[x][y] = 1;
   all.push_back({x, y});
   for (long long k = 0; k < 4; k++) {
     long long i = x + H[k], j = y + G[k];
     if (i >= 0 && j >= 0 && i < n && j < m) {
       if (!vis[i][j] && a[i][j] >= hh) {
         dfs(i, j);
       }
     }
   }
   return;
 }
 int32_t main() {
   ios_base::sync_with_stdio(0);
   cin.tie(nullptr);
   cout.tie(nullptr);
   ;
   cin >> n >> m >> k;
   for (long long i = 0; i < n * m; i++) par[i] = i, sz[i] = 1;
   s.insert(-1);
   mp[1] = n * m;
   for (long long i = 0; i < n; i++)
     for (long long j = 0; j < m; j++) {
       cin >> a[i][j];
       vec.push_back({a[i][j], i * m + j});
     }
   sort(vec.begin(), vec.end(), greater<pair<long long, long long> >());
   long long ans = -1, xx = -1, yy = -1;
   for (auto p : vec) {
     long long x = p.second / m, y = p.second % m, h = p.first;
     mark[x][y] = 1;
     for (long long k = 0; k < 4; k++) {
       long long i = x + H[k], j = y + G[k];
       if (i >= 0 && j >= 0 && i < n && j < m && mark[i][j]) {
         _union(i * m + j, p.second);
       }
     }
     if (k % h == 0) {
       long long mx = sz[find(p.second)];
       if (mx >= k / h) {
         ans = mx;
         hh = h;
         xx = x;
         yy = y;
         break;
       }
     }
   }
   if (ans == -1) return cout <<  NO
 , 0;
   dfs(xx, yy);
   cout <<  YES
 ;
   long long sum = 0;
   for (auto p : all) {
     res[p.first][p.second] = hh;
     sum += hh;
     if (sum == k) break;
   }
   for (long long i = 0; i < n; i++) {
     for (long long j = 0; j < m; j++) cout << res[i][j] << ' ';
     cout << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, m;
 long long dp[1501][1501];
 long long a[1510][1501];
 long long func(long long here, long long here1) {
   if (here1 > m) return -999999999999999;
   if (here1 < 1) return -999999999999999;
   if (here == n + 1) return 0;
   long long &ret = dp[here][here1];
   if (ret != -1) return ret;
   ret = -999999999999999;
   if (here % 2) {
     ret = max(ret, func(here, here1 + 1));
     ret = max(ret, func(here + 1, here1 - 1) + a[here][here1]);
   } else {
     ret = max(ret, func(here, here1 - 1));
     ret = max(ret, func(here + 1, here1 + 1) + a[here][here1]);
   }
   return ret;
 }
 int main() {
   memset(dp, -1, sizeof(dp));
   scanf( %lld %lld , &n, &m);
   for (int i = 1; i <= n; i++) {
     for (int y = 1; y <= m; y++) {
       scanf( %lld , &a[i][y]);
       a[i][y] += a[i][y - 1];
     }
   }
   printf( %lld
 , func(1, 1));
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, m, i, j, k, mod, dp[605][605], rd[605], xs[605][605], ans = 1;
 vector<long long> ts, bi[605], nrd, ncd;
 long long gcd(long long x, long long y) {
   if (y == 0) return x;
   return gcd(y, x % y);
 }
 long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
 void dfs(int x) {
   int i;
   rd[x] = -1;
   ts.push_back(x);
   for (i = 0; i < bi[x].size(); i++) {
     rd[bi[x][i]]--;
     if (!rd[bi[x][i]]) {
       dfs(bi[x][i]);
     }
   }
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin >> n >> m >> mod;
   for (i = 1; i <= m; i++) {
     int x, y;
     cin >> x >> y;
     bi[x].push_back(y);
     rd[y]++;
   }
   for (i = 1; i <= n; i++) {
     if (rd[i] == 0) nrd.push_back(i);
     if (bi[i].size() == 0) ncd.push_back(i);
   }
   for (i = 0; i < nrd.size(); i++) {
     dfs(nrd[i]);
     dp[nrd[i]][nrd[i]] = 1;
   }
   for (i = 0; i < ts.size(); i++) {
     for (j = 0; j < ts.size(); j++) {
       for (k = 0; k < bi[ts[j]].size(); k++) {
         dp[ts[i]][bi[ts[j]][k]] += dp[ts[i]][ts[j]];
         dp[ts[i]][bi[ts[j]][k]] %= mod;
       }
     }
   }
   for (i = 0; i < nrd.size(); i++) {
     for (j = 0; j < ncd.size(); j++) {
       xs[i][j] = dp[nrd[i]][ncd[j]];
     }
   }
   long long cnt = 0;
   for (i = 0; i < ncd.size(); i++) {
     for (j = i + 1; j < nrd.size(); j++) {
       while (xs[j][i]) {
         long long t = -xs[i][i] / xs[j][i];
         for (k = i; k < nrd.size(); k++) {
           xs[i][k] += t * xs[j][k];
           xs[i][k] %= mod;
           xs[i][k] += mod;
           xs[i][k] %= mod;
         }
         for (k = i; k < nrd.size(); k++) {
           swap(xs[i][k], xs[j][k]);
         }
         cnt++;
       }
     }
   }
   if (cnt & 1) ans = mod - 1;
   for (i = 0; i < nrd.size(); i++) {
     ans *= xs[i][i];
     ans %= mod;
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 signed main() {
   string s;
   cin >> s;
   char zero = '0';
   s =  00  + s;
   long long n = (long long)s.size();
   for (long long i = 0; i < n - 2; i++) {
     long long temp = 100 * (s[i] - zero);
     for (long long j = i + 1; j < n - 1; j++) {
       temp += (10 * (s[j] - zero));
       for (long long k = j + 1; k < n; k++) {
         temp += (s[k] - zero);
         if (temp % 8 == 0) {
           cout <<  YES  << '
';
           cout << temp << '
';
           return 0;
         }
         temp -= (s[k] - zero);
       }
       temp -= (10 * (s[j] - zero));
     }
   }
   cout <<  NO  << '
';
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int Q;
   cin >> Q;
   while (Q--) {
     long long n, a, b, ans;
     cin >> n >> a >> b;
     double x = b / 2.0;
     if (x > a) {
       ans = a * n;
       cout << ans << endl;
     } else {
       if (n % 2 == 0) {
         ans = n / 2 * b;
         cout << ans << endl;
       } else {
         ans = (n - 1) / 2 * b + a;
         cout << ans << endl;
       }
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename S, typename T>
 ostream& operator<<(ostream& out, pair<S, T> const& p) {
   out << '(' << p.first <<  ,   << p.second << ')';
   return out;
 }
 template <typename T>
 ostream& operator<<(ostream& out, vector<T> const& v) {
   int l = v.size();
   for (int i = 0; i < l - 1; i++) out << v[i] << ' ';
   if (l > 0) out << v[l - 1];
   return out;
 }
 template <typename T>
 void trace(const char* name, T&& arg1) {
   cout << name <<   :   << arg1 << endl;
 }
 template <typename T, typename... Args>
 void trace(const char* names, T&& arg1, Args&&... args) {
   const char* comma = strchr(names + 1, ',');
   cout.write(names, comma - names) <<   :   << arg1 <<   |  ;
   trace(comma + 1, args...);
 }
 const int N = 100100;
 int pt;
 bool cmp(const int& i, const int& j) {
   if (i < pt and j < pt) {
     return i < j;
   } else if (i > pt and j > pt) {
     return i < j;
   } else {
     return i > j;
   }
 }
 vector<int> nxt[N];
 int a[N];
 int b[N];
 int lft[N];
 int rgt[N];
 pair<int, int> tosort[N];
 bool importance(const int& i, const int& j) { return tosort[i] < tosort[j]; }
 vector<int> face[N];
 vector<int> g[N];
 map<pair<int, int>, int> id;
 set<pair<int, int> > used;
 void buildFace(int from, int to, int f) {
   face[f].push_back(to);
   used.insert(make_pair(from, to));
   pt = to;
   vector<int>& v = nxt[to];
   int nxt = *upper_bound(v.begin(), v.end(), from, cmp);
   if (used.count(make_pair(to, nxt))) return;
   buildFace(to, nxt, f);
 }
 int vis[N];
 int usd[N];
 int sz[N];
 int lvl[N];
 void dfs(int x, int h) {
   sz[x] = 1;
   vis[x] = h;
   for (auto it = (g[x]).begin(); it != (g[x]).end(); ++it) {
     if (usd[*it]) continue;
     if (vis[*it] == h) continue;
     dfs(*it, h);
     sz[x] += sz[*it];
   }
 }
 int findCentroid(int x, int n, int prev) {
   for (auto it = (g[x]).begin(); it != (g[x]).end(); ++it) {
     if (vis[*it] != vis[x] or *it == prev) continue;
     if (sz[*it] > n / 2) return findCentroid(*it, n, x);
   }
   return x;
 }
 void decompose(int x, int h) {
   dfs(x, h);
   int c = findCentroid(x, sz[x], -1);
   lvl[c] = h;
   usd[c] = 1;
   for (auto it = (g[c]).begin(); it != (g[c]).end(); ++it) {
     if (!usd[*it]) decompose(*it, h + 1);
   }
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int n, m;
   cin >> n >> m;
   if (m == 0) {
     cout << 1 << endl;
     return 0;
   }
   if (m == 1) {
     cout <<  1 2  << endl;
     return 0;
   }
   nxt[1].push_back(n);
   nxt[n].push_back(1);
   for (int i = 2; i <= n; i++) {
     nxt[i].push_back(i - 1);
     nxt[i - 1].push_back(i);
   }
   for (int i = 0; i < m; i++) {
     cin >> a[i] >> b[i];
     if (a[i] < b[i]) swap(a[i], b[i]);
     id[make_pair(a[i], b[i])] = id[make_pair(b[i], a[i])] = i;
     nxt[a[i]].push_back(b[i]);
     nxt[b[i]].push_back(a[i]);
   }
   for (int i = 1; i <= n; i++) {
     pt = i;
     sort(nxt[i].begin(), nxt[i].end(), cmp);
   }
   int cur = 0;
   for (int i = 0; i < m; i++) {
     if (!used.count(make_pair(a[i], b[i]))) {
       face[++cur].push_back(a[i]);
       buildFace(a[i], b[i], cur);
       for (int j = 1; j < face[cur].size(); j++) {
         int x = face[cur][j - 1], y = face[cur][j];
         if (x - 1 != y and !(x == 1 and y == n)) {
           int k = id[make_pair(x, y)];
           if (x > y)
             lft[k] = cur;
           else
             rgt[k] = cur;
         }
       }
     }
     if (!used.count(make_pair(b[i], a[i]))) {
       face[++cur].push_back(b[i]);
       buildFace(b[i], a[i], cur);
       for (int j = 1; j < face[cur].size(); j++) {
         int x = face[cur][j - 1], y = face[cur][j];
         if (x - 1 != y and !(x == 1 and y == n)) {
           int k = id[make_pair(x, y)];
           if (x > y)
             lft[k] = cur;
           else
             rgt[k] = cur;
         }
       }
     }
     int x = lft[i], y = rgt[i];
     assert(x > 0 and y > 0);
     g[x].push_back(y);
     g[y].push_back(x);
   }
   for (int i = 1; i <= cur; i++) {
     int mx = 0, smx = 0;
     for (int j = 1; j < face[i].size(); j++) {
       int x = face[i][j];
       if (x > mx) {
         smx = mx;
         mx = x;
       } else if (x > smx)
         smx = x;
     }
     tosort[i] = make_pair(mx, smx);
   }
   vector<int> faces;
   for (int i = 1; i <= cur; i++) faces.push_back(i);
   sort(faces.begin(), faces.end(), importance);
   decompose(1, 1);
   for (int x : faces) {
     cout << lvl[x] << ' ';
   }
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, k, x, a, b, i, j, m[1000005], f[1000005];
 multiset<long long> s;
 pair<long long, long long> d[1000005];
 vector<long long> v;
 int main() {
   ios::sync_with_stdio(0);
   cin >> n >> k >> x;
   while (i < n) {
     cin >> m[i];
     i++;
   }
   i = 0;
   while (i < k) {
     cin >> d[i].first;
     d[i].second = i + 1;
     i++;
   }
   i = 0;
   sort(m, m + n);
   sort(d, d + k);
   s.insert(1000000001);
   while (i < n) {
     if (x * m[i] + x < i + 1)
       return cout << -1, 0;
     else
       f[i] = x * m[i] + x - i - 1, s.insert(f[i]);
     i++;
   }
   i = 0;
   while (i < n + 1) {
     while (j < k && a < *s.begin()) {
       if (x * d[j].first + x >= i + a + 1) a++, v.push_back(d[j].second);
       j++;
     }
     s.erase(s.lower_bound(f[i]));
     i++;
   }
   i = 0;
   cout << a << endl;
   while (i < a) {
     cout << v[i] <<    ;
     i++;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int i, count = 0;
   string str;
   cin >> str;
   int len = str.size();
   for (i = 0; i < len; i++) {
     if (str[i] == 'W' && str[i + 1] == 'U' && str[i + 2] == 'B') {
       i += 2;
       if (count > 0) cout <<    ;
     } else {
       cout << str[i];
       count = 1;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long inf = 2e9;
 int32_t main() {
   cin.tie(0)->sync_with_stdio(0);
   long long n, m;
   string s, t;
   cin >> n >> m >> s >> t;
   vector<long long> pi(m, 0), nxt(m, 0);
   for (long long i = 1; i < m; i++) {
     {
       t[i] = char('0' + (t[i] - '0') ^ 1);
       long long j = pi[i - 1];
       while (j > 0 and t[i] != t[j]) {
         j = pi[j - 1];
       }
       if (t[i] == t[j]) j++;
       nxt[i] = j;
       t[i] = char('0' + (t[i] - '0') ^ 1);
     }
     {
       long long j = pi[i - 1];
       while (j > 0 and t[i] != t[j]) {
         j = pi[j - 1];
       }
       if (t[i] == t[j]) j++;
       pi[i] = j;
     }
   }
   s = '#' + s;
   long long dp[n + 1][m][n - m + 2];
   fill(**dp, **dp + sizeof dp / sizeof(long long), inf);
   dp[0][0][0] = 0;
   for (long long i = 0; i < n; i++) {
     for (long long j = 0; j < m; j++) {
       for (long long k = 0; k < n - m + 2; k++) {
         if (dp[i][j][k] == inf) continue;
         if (j == m - 1) {
           dp[i + 1][pi.back()][k + 1] = min(dp[i + 1][pi.back()][k + 1],
                                             dp[i][j][k] + (s[i + 1] != t[j]));
         } else {
           dp[i + 1][j + 1][k] =
               min(dp[i + 1][j + 1][k], dp[i][j][k] + (s[i + 1] != t[j]));
         }
         dp[i + 1][nxt[j]][k] =
             min(dp[i + 1][nxt[j]][k], dp[i][j][k] + (s[i + 1] == t[j]));
       }
     }
   }
   for (long long i = 0; i < n - m + 2; i++) {
     long long mn = inf;
     for (long long j = 0; j < m; j++) {
       mn = min(mn, dp[n][j][i]);
     }
     if (mn == inf) mn = -1;
     cout << mn << ' ';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int t;
   cin >> t;
   while (t--) {
     int n;
     cin >> n;
     vector<pair<int, pair<int, int>>> v;
     for (int i = 0; i < n; i++) {
       int a, b;
       cin >> a >> b;
       v.push_back(make_pair(a, make_pair(b, i)));
     }
     sort(v.begin(), v.end());
     int g[100001]{}, r = v[0].second.first;
     g[v[0].second.second] = 1;
     for (int i = 1; i < n; i++) {
       if (v[i].first > r) break;
       g[v[i].second.second] = 1;
       r = max(r, v[i].second.first);
     }
     bool ans = true;
     for (int i = 0; i < n && ans; i++) ans &= g[i];
     if (ans) {
       cout << -1 << '
';
       continue;
     }
     for (int i = 0; i < n; i++) cout << g[i] + 1 <<    ;
     cout << '
';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 char A[300];
 int cnt[5];
 char data[5] =  ACGT ;
 int main() {
   int n;
   scanf( %d , &n);
   scanf( %s , A);
   for (int i = 0; A[i]; i++) {
     if (A[i] == 'A')
       cnt[0]++;
     else if (A[i] == 'C')
       cnt[1]++;
     else if (A[i] == 'G')
       cnt[2]++;
     else if (A[i] == 'T')
       cnt[3]++;
     else
       cnt[4]++;
   }
   int big = 0, dif = 0;
   ;
   for (int i = 0; i < 4; i++) big = max(big, cnt[i]);
   for (int i = 0; i < 4; i++) {
     cnt[i] = big - cnt[i];
     dif += cnt[i];
   }
   if (dif > cnt[4]) {
     printf( === );
     return 0;
   }
   if ((cnt[4] - dif) % 4 != 0) {
     printf( === );
     return 0;
   }
   int flag = 0;
   for (int i = 0; A[i]; i++) {
     if (A[i] == '?') {
       flag = 0;
       for (int j = 0; j < 4; j++) {
         if (cnt[j] > 0) {
           A[i] = data[j];
           cnt[j]--;
           flag = 1;
           break;
         }
       }
       if (flag == 0) {
         for (int j = 0; j < 4; j++) cnt[j]++;
         i--;
       }
     }
   }
   printf( %s , A);
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[2];
 string ans[2] = { Vladik ,  Valera };
 int main() {
   cin >> a[0] >> a[1];
   int turn = 0;
   int sub = 1;
   while (true) {
     if (a[turn] - sub >= 0) {
       a[turn] -= sub;
     } else {
       break;
     }
     sub++;
     turn = 1 - turn;
   }
   cout << ans[turn] << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m, loc[250] = {}, isi[250] = {}, idx = 0;
 int kosong() {
   for (int i = 0, _n = (n); i < _n; i++)
     if (isi[i] == -1) return i;
   return -111;
 }
 int main() {
   memset(isi, -1, sizeof isi);
   scanf( %d %d , &n, &m);
   for (int i = 0, _n = (m); i < _n; i++) {
     int a;
     scanf( %d , &a);
     for (int j = 0, _n = (a); j < _n; j++) {
       int x;
       scanf( %d , &x);
       x--;
       isi[x] = idx;
       loc[idx] = x;
       idx++;
     }
   }
   vector<pair<int, int> > ans;
   for (int i = 0, _n = (idx); i < _n; i++)
     if (isi[i] != i) {
       if (isi[i] == -1) {
         ans.push_back(make_pair(loc[i], i));
         isi[loc[i]] = -1;
         loc[i] = i;
         isi[i] = i;
       } else {
         int k = kosong();
         ans.push_back(make_pair(i, k));
         isi[k] = isi[i];
         loc[isi[i]] = k;
         isi[i] = -1;
         i--;
       }
     }
   printf( %d
 , ans.size());
   for (int i = 0, _n = (ans.size()); i < _n; i++)
     printf( %d %d
 , ans[i].first + 1, ans[i].second + 1);
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast )
 using namespace std;
 template <class T>
 void dbg(const char* xn, T x) {
   if (0) cout << xn <<  :   << x <<
 ;
 }
 template <class T, class... TA>
 void dbg(const char* xn, T x, TA... t) {
   while (*xn != ',')
     if (0) cout << *xn++;
   if (0) cout <<  :   << x <<  , ;
   dbg(xn + 1, t...);
 }
 template <class T>
 inline bool upd_max(T& x, T y) {
   return y > x ? x = y, true : false;
 }
 template <class T>
 inline bool upd_min(T& x, T y) {
   return y < x ? x = y, true : false;
 }
 const int N = 1000007;
 long long n, m1 = 0, m0 = 0, n1 = 0, n0 = 0;
 string A, B;
 void solve() {
   cin >> n;
   cin >> A;
   A = '#' + A;
   cin >> B;
   B = '#' + B;
   for (long long i = 1; i <= (n); ++i) {
     if (A[i] == '1')
       ++n1;
     else if (A[i] == '0')
       ++n0;
     if (A[i] == '1' && B[i] == '0') ++m1;
     if (A[i] == '0' && B[i] == '0') ++m0;
   }
   cout << m1 * n0 + m0 * n1 - m1 * m0;
 }
 int32_t main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout << fixed << setprecision(10);
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int sz = 5005;
 long long int x[sz];
 long long int a[sz];
 long long int b[sz];
 long long int c[sz];
 long long int d[sz];
 int n, s, e;
 const long long int Max = 1e16;
 long long int dp[sz][sz];
 long long int jumpl(int i) { return x[i] + c[i]; }
 long long int jumpr(int i) { return -x[i] + d[i]; }
 long long int landfr(int i) { return -x[i] + b[i]; }
 long long int landfl(int i) { return x[i] + a[i]; }
 long long int calc(int ch, int pl, int pr) {
   if (pl < 0 || pr < 0) {
     return Max;
   }
   if (dp[ch][pl] != 0) {
     return dp[ch][pl];
   }
   if (ch == 0) {
     if (s == 0) {
       return calc(ch + 1, pl, pr + 1) + jumpr(ch);
     } else if (e == 0) {
       return calc(ch + 1, pl + 1, pr) + landfr(ch);
     }
     return calc(ch + 1, pl + 1, pr + 1) + landfr(ch) + jumpr(ch);
   }
   if (ch == n - 1) {
     if (s == n - 1 && (pl == 1 && pr == 0)) {
       return jumpl(ch);
     } else if (e == n - 1 && (pl == 0 && pr == 1)) {
       return landfl(ch);
     } else if (pl == pr && pl == 1) {
       return landfl(ch) + jumpl(ch);
     } else {
       return Max;
     }
   } else if (pl == 0 && pr == 0) {
     return Max;
   }
   long long int m;
   if (ch == s) {
     m = min(calc(ch + 1, pl - 1, pr) + jumpl(ch),
             calc(ch + 1, pl, pr + 1) + jumpr(ch));
     dp[ch][pl] = m;
     return m;
   }
   if (ch == e) {
     m = min(calc(ch + 1, pl, pr - 1) + landfl(ch),
             calc(ch + 1, pl + 1, pr) + landfr(ch));
     dp[ch][pl] = m;
     return m;
   }
   m = calc(ch + 1, pl + 1, pr + 1) + jumpr(ch) + landfr(ch);
   m = min(m, calc(ch + 1, pl - 1, pr - 1) + jumpl(ch) + landfl(ch));
   if (pr > 0) {
     m = min(m, calc(ch + 1, pl, pr) + jumpr(ch) + landfl(ch));
   }
   if (pl > 0) {
     m = min(m, calc(ch + 1, pl, pr) + jumpl(ch) + landfr(ch));
   }
   dp[ch][pl] = m;
   return m;
 }
 int main() {
   ios::sync_with_stdio(false);
   cin >> n >> s >> e;
   --s, --e;
   for (int i = 0; i < n; ++i) {
     cin >> x[i];
   }
   for (int i = 0; i < n; ++i) {
     cin >> a[i];
   }
   for (int i = 0; i < n; ++i) {
     cin >> b[i];
   }
   for (int i = 0; i < n; ++i) {
     cin >> c[i];
   }
   for (int i = 0; i < n; ++i) {
     cin >> d[i];
   }
   cout << calc(0, 0, 0) << endl;
 }