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

 #define ll long long
 #define vi vector<int>
 #define pii pair<int,int>
 #define mii map<int,int>
 #define pqb priority_queue<int>
 #define pqs priority_queue<int,vi,greater<int> >

 #define ff first
 #define ss second
 #define pb push_back
 #define mp make_pair
 #define PI 3.1415926535897932384626
 #define MOD 1000000007
 #define ps(x,y) fixed<<setprecision(y)<<x

 long long int fact[200005];

 long long int pwr(long long int a,long long int b){
     if(b==0) return 1;
     if(b==1) return a%MOD;
     long long int q = pwr((a*a)%MOD,b/2);
     if(b%2) return (q*a)%MOD;
     return q;
 }

 long long int C(long long int a,long long int b){
     if(b<0) return 0;
     if(a<b) return 0;

     long long int t1 = (fact[a])%MOD;
     long long int t2 = (fact[b]*fact[a-b])%MOD;
     t2 = pwr(t2,MOD-2)%MOD;

     return (t1*t2)%MOD;
 }

 void solve(){

     long long int n,l,r;
     cin>>n>>l>>r;

     long long int ans=0;
     ans = C(n,n/2)%MOD;
     if(n%2) ans = (ans*2)%MOD;
     ans = (ans*(min(1-l,r-n)))%MOD;
     for(long long int p=min(1-l,r-n)+1;p<=min(r,n+1-l);p++){
         long long int a = p + l - 1;
         if(a<=0) a = 0;
         long long int b = n + p - r;
         if(b<=0) b=0;

         ans = (C(n-a-b,n/2-a) + ans)%MOD;
         if(n%2) ans = (C(n-a-b,n/2-b) + ans)%MOD;
     }
     cout<<ans<<endl;

     return;
 }

 int main(){

     ios_base::sync_with_stdio(false);
     cin.tie(NULL);

     // freopen( input.txt ,  r , stdin);
     // freopen( error.txt ,  w , stderr);
     // freopen( output.txt ,  w , stdout);

     fact[0]=1;
     for(long long int i=1;i<200005;i++){
         fact[i] = (fact[i-1]*i)%MOD;
     }

     int t=1;
     cin>>t;

     for(int i=1;i<=t;i++){
         // cout<< Case # <<i<< :  ;
         solve();
     }

     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;
     return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 char str[10000];
 int n, m, Q;
 map<string, int> mem;
 map<string, int>::iterator iter;
 struct Func {
   string name;
   int num;
   int v[10];
   bool operator==(const Func& A) const {
     if (name != A.name) return false;
     if (num != A.num) return false;
     for (int i = 0; i < num; ++i)
       if (v[i] * A.v[i] != 0 && v[i] != A.v[i]) return false;
     return true;
   }
 } g[2000], pre;
 int Type(string x) {
   if (x ==  T ) return 0;
   if (x ==  int ) return 1;
   if (x ==  double ) return 2;
   if (x ==  string ) return 3;
   return -1;
 }
 void inputFunc(int gs) {
   gets(str);
   int i = 0, j = 0, len = strlen(str);
   while (str[j] != 'd') ++j;
   ++j;
   while (j < len) {
     if (str[j] != ' ') str[i++] = str[j];
     j++;
   }
   len = i;
   i = 0;
   g[gs].name =   ;
   while (str[i] != '(') {
     g[gs].name += str[i];
     i++;
   }
   string temp =   ;
   i++;
   for (;;) {
     if (str[i] == ',' || str[i] == ')') {
       g[gs].v[g[gs].num++] = Type(temp);
       temp =   ;
       if (str[i] == ')') break;
     } else
       temp += str[i];
     i++;
   }
 }
 void inputType() {
   string a, b;
   cin >> a >> b;
   mem[b] = Type(a);
 }
 void solve() {
   gets(str);
   int i = 0, j = 0, len = strlen(str);
   for (j = 0; j < len; ++j) {
     if (str[j] != ' ') str[i++] = str[j];
   }
   len = i;
   i = 0;
   pre.name =   ;
   pre.num = 0;
   while (str[i] != '(') {
     pre.name += str[i];
     i++;
   }
   string temp =   ;
   i++;
   for (;;) {
     if (str[i] == ',' || str[i] == ')') {
       pre.v[pre.num++] = mem.find(temp)->second;
       temp =   ;
       if (str[i] == ')') break;
     } else
       temp += str[i];
     i++;
   }
   int ans = 0;
   for (int i = 0; i < n; ++i)
     if (pre == g[i]) ++ans;
   printf( %d
 , ans);
 }
 int main() {
   scanf( %d , &n);
   gets(str);
   for (int i = 0; i < n; ++i) inputFunc(i);
   scanf( %d , &m);
   gets(str);
   mem.clear();
   while (m--) inputType();
   scanf( %d , &Q);
   gets(str);
   while (Q--) solve();
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 1000000007;
 int main() {
   long long n, a;
   long long fuck = 0, fucck = 0;
   cin >> n;
   priority_queue<int> prio1, prio2;
   for (int i = 0; i < n; ++i) {
     cin >> a;
     prio1.push(a);
     fuck += a;
   }
   for (int i = 0; i < n; ++i) {
     cin >> a;
     prio2.push(a);
     fucck += a;
   }
   prio1.push(-1);
   prio2.push(-1);
   long long sum1 = 0, sum2 = 0;
   int mark = 1;
   for (int i = 0; i < 2 * n; ++i) {
     if (mark == 1) {
       if (prio1.top() >= prio2.top()) {
         fuck -= prio1.top();
         sum1 += prio1.top();
         prio1.pop();
       } else {
         fucck -= prio2.top();
         prio2.pop();
       }
       mark = 2;
     } else {
       if (prio2.top() >= prio1.top()) {
         fucck -= prio2.top();
         sum2 += prio2.top();
         prio2.pop();
       } else {
         fuck -= prio1.top();
         prio1.pop();
       }
       mark = 1;
     }
   }
   cout << (sum1 - sum2) << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 pair<char, int> check(string s) {
   map<char, int> used;
   int l = s.size(), i, maxVal = 0;
   char ans;
   for (i = 0; i < l; i++) {
     used[s.at(i)]++;
     if (used[s.at(i)] > maxVal) {
       maxVal = used[s.at(i)];
       ans = s.at(i);
     }
   }
   return make_pair(ans, maxVal);
 }
 int execute() {
   int n, i, diff[4] = {0}, minVal = 10e8 + 7;
   cin >> n;
   vector<pair<char, int> > val(4);
   string a[3];
   for (i = 0; i < 3; i++) {
     cin >> a[i];
     val[i] = check(a[i]);
     diff[i] = a[i].size() - val[i].second;
     diff[i] = max(0 + (diff[i] + 1 == n && !diff[i]), diff[i] - n);
     minVal = min(minVal, diff[i]);
   }
   int index;
   for (i = 0; i < 3; i++) {
     if (minVal == diff[i]) {
       index = i;
     }
   }
   sort(diff, diff + 3);
   if (diff[0] == diff[1])
     cout <<  Draw  << endl;
   else {
     switch (index) {
       case (0):
         cout <<  Kuro  << endl;
         break;
       case (1):
         cout <<  Shiro  << endl;
         break;
       default:
         cout <<  Katie  << endl;
     }
   }
   return 0;
 }
 char mtest = false;
 unsigned short TE = 1;
 int main() {
   ios_base::sync_with_stdio(false);
   if (mtest) cin >> TE;
   while (TE--) execute();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e6 + 1;
 long long a[4], mn = 1e12 + 1;
 char b, c, d;
 int main() {
   cin >> a[0] >> a[1] >> a[2] >> a[3];
   cin >> b >> c >> d;
   sort(a, a + 4);
   do {
     long long first, second, temp;
     if (b == '+')
       first = a[0] + a[1];
     else
       first = a[0] * a[1];
     long long a1[3];
     a1[0] = first;
     a1[1] = a[2];
     a1[2] = a[3];
     sort(a1, a1 + 3);
     do {
       if (c == '+')
         second = a1[0] + a1[1];
       else
         second = a1[0] * a1[1];
       if (d == '+')
         temp = second + a1[2];
       else
         temp = second * a1[2];
       mn = min(mn, temp);
     } while (next_permutation(a1, a1 + 3));
   } while (next_permutation(a, a + 4));
   cout << mn;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 char s[100010];
 typedef struct record {
   char ch;
   int po;
 } rec;
 int main() {
   int leng, ans, l, r;
   rec tmp1, tmp2;
   int tmp3;
   bool flag;
   stack<rec> st;
   while (~scanf( %s , s)) {
     flag = false;
     while (!st.empty()) st.pop();
     leng = strlen(s);
     for (int i = 0; i < leng; i++) {
       if (!st.empty()) tmp2 = st.top();
       if (!st.empty() && ((tmp2.ch == '(' && s[i] == ')') ||
                           (tmp2.ch == '[' && s[i] == ']'))) {
         st.pop();
       } else {
         tmp1.ch = s[i];
         tmp1.po = i;
         st.push(tmp1);
       }
     }
     ans = 0;
     if (st.empty()) {
       for (int i = 0; i < leng; i++)
         if (s[i] == '[') ans++;
       printf( %d
%s
 , ans, s);
     } else {
       bool once = true;
       flag = false;
       ans = -1;
       int tmpr, tmpl;
       while (st.size() != 0) {
         tmp3 = 0;
         if (once) {
           tmpr = leng - 1;
           tmpl = st.top().po + 1;
           once = false;
         } else {
           if (st.size() != 1) {
             tmpr = st.top().po - 1;
             st.pop();
             tmpl = st.top().po + 1;
           } else {
             tmpr = st.top().po - 1;
             tmpl = 0;
             st.pop();
           }
         }
         if (tmpl < tmpr) {
           flag = true;
           for (int j = tmpl; j <= tmpr; j++)
             if (s[j] == '[') tmp3++;
         }
         if (tmp3 > ans) {
           ans = tmp3;
           l = tmpl;
           r = tmpr;
         }
       }
       if (flag) {
         printf( %d
 , ans);
         for (int i = l; i <= r; i++) printf( %c , s[i]);
         printf(
 );
       } else
         printf( 0
 );
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize(2)
 using namespace std;
 const int INF = 0x3f3f3f3f;
 const long long inf = 0x3f3f3f3f3f3f3f3f;
 const int mod = 1e9 + 7;
 const int maxn = 1e3 + 5;
 int n, m, qq, s[maxn][maxn], f[maxn][maxn];
 bool vis[maxn][maxn];
 int a[4] = {0, 1, 0, -1};
 int b[4] = {-1, 0, 1, 0};
 bool judge(int x, int y) {
   for (int i = 0; i <= 3; i++) {
     int xx = x + a[i], yy = y + b[i];
     if (xx <= 0 || xx > n || yy <= 0 || yy > m) continue;
     if (s[xx][yy] == s[x][y]) return true;
   }
   return false;
 }
 void bfs() {
   queue<pair<int, int> > q;
   for (int i = 1; i <= n; i++) {
     for (int j = 1; j <= m; j++) {
       if (judge(i, j)) {
         vis[i][j] = 1;
         f[i][j] = 0;
         q.push({i, j});
       }
     }
   }
   while (!q.empty()) {
     int x = q.front().first;
     int y = q.front().second;
     q.pop();
     for (int i = 0; i <= 3; i++) {
       int xx = x + a[i], yy = y + b[i];
       if (xx <= 0 || xx > n || yy <= 0 || yy > m) continue;
       if (vis[xx][yy]) continue;
       f[xx][yy] = f[x][y] + 1;
       vis[xx][yy] = 1;
       q.push({xx, yy});
     }
   }
 }
 int main() {
   scanf( %d%d%d , &n, &m, &qq);
   for (int i = 1; i <= n; i++) {
     for (int j = 1; j <= m; j++) {
       scanf( %1d , &s[i][j]);
     }
   }
   bfs();
   while (qq--) {
     int x, y;
     long long t;
     scanf( %d%d%lld , &x, &y, &t);
     if (vis[x][y]) {
       if (t < f[x][y])
         printf( %d
 , s[x][y]);
       else
         printf( %d
 , s[x][y] ^ ((t - f[x][y]) & 1));
     } else {
       printf( %d
 , s[x][y]);
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m;
 vector<int> adj[100005];
 vector<int> vis(100005, 1);
 vector<int> ans;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int T = 1;
   for (int qq = 1; qq <= T; qq++) {
     cin >> n >> m;
     for (int i = 0; i < m; i++) {
       int x, y;
       cin >> x >> y;
       adj[x].push_back(y);
       adj[y].push_back(x);
     }
     priority_queue<int> v;
     v.push(-1);
     vis[1] = 0;
     while (!v.empty()) {
       int u = -v.top();
       v.pop();
       ans.push_back(u);
       for (auto i : adj[u])
         if (vis[i]) v.push(-i), vis[i] = 0;
     }
     for (auto i : ans) cout << i << ' ';
     cout << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long inf = 1e18 + 1e17;
 const long long mod = 1e9 + 7;
 long long modInverse(long long a, long long m) {
   long long m0 = m;
   long long y = 0, x = 1;
   if (m == 1) return 0;
   while (a > 1) {
     long long q = a / m;
     long long t = m;
     m = a % m, a = t;
     t = y;
     y = x - q * y;
     x = t;
   }
   if (x < 0) x += m0;
   return x;
 }
 long long powm(long long a, long long b) {
   a = a % mod;
   long long res = 1;
   while (b) {
     if (b & 1) res = (res * a) % mod;
     a = (a * a) % mod;
     b >>= 1;
   }
   return (res % mod);
 }
 const long long N = 5e3 + 6;
 int n, k, water;
 vector<int> v;
 int dp[N][2], dpr[N][2];
 int arr[N];
 bool brr[N];
 int ip = 1e9;
 void makedp() {
   dp[0][0] = 1;
   dp[0][1] = -1;
   for (int i = 0; i < n; i++) {
     int x = arr[i] % k;
     memset(dpr, -1, sizeof(dpr));
     dpr[0][0] = 1;
     for (int j = 1; j < k; j++) {
       if (dp[j][0] == 0 && dp[(j - x + k) % k][0] == 1) {
         dpr[j][0] = 1;
         dpr[j][1] = i;
       } else {
         dpr[j][0] = dp[j][0];
         dpr[j][1] = dp[j][1];
       }
     }
     swap(dpr, dp);
   }
 }
 bool check() {
   int tt = 0;
   for (int i = 0; i < n; i++) tt += arr[i];
   if (tt < water || dp[water % k][0] == 0) {
     cout <<  NO
 ;
     return true;
     ;
   }
   return false;
 }
 void find() {
   int val = water % k;
   int x = dp[val][1];
   while (x != -1) {
     v.push_back(dp[val][1]);
     val = (val - arr[x] % k + k) % k;
     x = dp[val][1];
   }
 }
 void seperate() {
   memset(brr, 0, sizeof(brr));
   int tt = 0;
   for (int i : v) {
     brr[i] = 1;
     tt += arr[i];
   }
   for (int i = 1; i < v.size(); i++)
     cout << ip << ' ' << v[i] + 1 << ' ' << v[0] + 1 << '
';
   int mark = -1;
   int tc = 0;
   for (int i = 0; i < n; i++)
     if (!brr[i]) {
       mark = i;
       tc += arr[i];
     }
   for (int i = 0; i < n; i++)
     if (!brr[i] && mark != i)
       cout << ip << ' ' << i + 1 << ' ' << mark + 1 << '
';
   if (v.size() == 0) v.push_back(0);
   if (tt > water)
     cout << (tt - water) / k << ' ' << v[0] + 1 << ' ' << (0 == v[0] ? 2 : 1)
          << '
';
   else if (tt < water)
     cout << (water - tt) / k << ' ' << mark + 1 << ' ' << v[0] + 1 << '
';
 }
 void solve() {
   cin >> n >> k >> water;
   for (int i = 0; i < n; i++) cin >> arr[i];
   makedp();
   if (check()) return;
   cout <<  YES
 ;
   find();
   seperate();
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long t = 1;
   for (long long i = 1; i <= t; i++) {
     solve();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int freq[27];
 char sent[101];
 int main() {
   int n;
   scanf( %d , &n);
   scanf( %s , sent);
   while (n--) {
     if (isupper(sent[n])) sent[n] = tolower(sent[n]);
     freq[sent[n] - 'a']++;
   }
   for (int i = 0; i < 26; i++)
     if (!freq[i]) {
       printf( NO
 );
       return 0;
     }
   printf( YES
 );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2e5 + 5;
 const int INF = 1e9 + 5;
 int read(int base = 10) {
   int x = 0;
   char ch = getchar();
   while (!isdigit(ch)) ch = getchar();
   while (isdigit(ch)) x = x * base + ch - '0', ch = getchar();
   return x;
 }
 struct Node {
   int num[12][2];
 } tree[N << 2];
 void push_up(int o, int l, int r) {
   int tmp[4];
   for (int ii = 1; ii <= 11; ii++) {
     tmp[0] = tree[o << 1].num[ii][0];
     tmp[1] = tree[o << 1].num[ii][1];
     tmp[2] = tree[o << 1 | 1].num[ii][0];
     tmp[3] = tree[o << 1 | 1].num[ii][1];
     sort(tmp, tmp + 4);
     tree[o].num[ii][0] = tmp[0];
     tree[o].num[ii][1] = tmp[1];
   }
 }
 void build(int o, int l, int r) {
   if (l == r) {
     int x = read();
     int tmp = x;
     for (int ii = 1; ii <= 11; tmp /= 10, ii++) {
       if (tmp % 10 == 0) {
         tree[o].num[ii][0] = tree[o].num[ii][1] = INF;
         continue;
       }
       tree[o].num[ii][0] = x;
       tree[o].num[ii][1] = INF;
     }
     return;
   }
   int mid = (l + r) >> 1;
   build(o << 1, l, mid);
   build(o << 1 | 1, mid + 1, r);
   push_up(o, l, r);
 }
 int id, x;
 void update(int o, int l, int r) {
   if (l == r) {
     int tmp = x;
     for (int ii = 1; ii <= 11; ii++, tmp /= 10) {
       if (tmp % 10) {
         tree[o].num[ii][0] = x;
         tree[o].num[ii][1] = INF;
       } else {
         tree[o].num[ii][0] = tree[o].num[ii][1] = INF;
       }
     }
     return;
   }
   int mid = (l + r) >> 1;
   if (id <= mid)
     update(o << 1, l, mid);
   else
     update(o << 1 | 1, mid + 1, r);
   push_up(o, l, r);
 }
 int L, R, ans[12][2];
 int tmp[4];
 void query_up(int o, int i) {
   tmp[0] = ans[i][0];
   tmp[1] = ans[i][1];
   tmp[2] = tree[o].num[i][0];
   tmp[3] = tree[o].num[i][1];
   sort(tmp, tmp + 4);
   ans[i][0] = tmp[0];
   ans[i][1] = tmp[1];
 }
 void query(int o, int l, int r) {
   if (L <= l && r <= R) {
     for (int ii = 1; ii <= 11; ii++) {
       query_up(o, ii);
     }
     return;
   }
   int mid = (l + r) >> 1;
   if (L <= mid) query(o << 1, l, mid);
   if (R > mid) query(o << 1 | 1, mid + 1, r);
 }
 int main() {
   int n = read(), m = read();
   build(1, 1, n);
   while (m--) {
     int op = read();
     if (op == 1) {
       id = read(), x = read();
       update(1, 1, n);
     } else {
       L = read(), R = read();
       for (int i = 1; i <= 11; i++) ans[i][0] = ans[i][1] = INF;
       query(1, 1, n);
       int all = INF * 2;
       ;
       for (int i = 1; i <= 11; i++) {
         if (ans[i][0] == INF || ans[i][1] == INF) continue;
         all = min(all, ans[i][0] + ans[i][1]);
       }
       if (all == INF * 2) {
         cout <<  -1
 ;
       } else {
         cout << all <<
 ;
       }
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename Arg1>
 void __f(const char* name, Arg1&& arg1) {
   cerr << name <<  :   << arg1 << endl;
 }
 template <typename Arg1, typename... Args>
 void __f(const char* names, Arg1&& arg1, Args&&... args) {
   const char* comma = strchr(names + 1, ',');
   cerr.write(names, comma - names) <<  :   << arg1 <<   | ;
   __f(comma + 1, args...);
 }
 const int INF = 1 << 30;
 const int MOD = 1e9 + 7;
 const int N = 1e6;
 int a[N];
 double sqr(double x) { return x * x; }
 int main() {
   int cas;
   scanf( %d , &cas);
   double ret = 0;
   for (int num = 0; num < cas; ++num) {
     int n = 250;
     double ave = 0;
     for (int i = 0; i < n; ++i) {
       scanf( %d , &a[i]);
       ave += a[i];
     }
     ave /= n;
     double V = 0;
     for (int i = 0; i < n; ++i) {
       V += sqr(ave - a[i]);
     }
     V /= n;
     double ratio = ave / V;
     ret = max(ret, abs(ratio - 1));
     puts(abs(ratio - 1) < 0.5 ?  poisson  :  uniform );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int me;
   int bebia;
   int iliko = 0;
   int ilarioni = 0;
   cin >> me;
   for (int i = 0; i < me; i++) {
     cin >> bebia;
     if (bebia > 0) iliko += bebia;
     if (bebia == -1) {
       if (iliko - 1 < 0) {
         ilarioni++;
       } else
         iliko--;
     }
   }
   cout << ilarioni;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int i, j, t;
   int n;
   int a[105];
   cin >> n;
   for (i = 0; i < n; i++) cin >> a[i];
   sort(a, a + n);
   int b[105] = {0};
   int cnt = 1;
   for (i = 0; i < n; i++) {
     for (j = 0; j <= cnt; j++) {
       if (!b[j]) {
         b[j]++;
         break;
       } else if (b[j] <= a[i]) {
         b[j]++;
         break;
       }
     }
     if (j == cnt) cnt++;
   }
   cout << cnt << endl;
   return 0;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   long long a, b, c, d;
   cin >> a >> b >> c >> d;
   long long sum = a + b + c + d;
   if (sum % 2 == 0) {
     if (a + b == sum / 2 || a + c == sum / 2 || a + d == sum / 2 ||
         b + c == sum / 2 || b + d == sum / 2 || c + d == sum / 2 ||
         a == sum / 2 || b == sum / 2 || c == sum / 2 || d == sum / 2)
       cout <<  YES  << endl;
     else
       cout <<  NO  << endl;
   } else
     cout <<  NO  << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int i, j, r, n, x;
   cin >> x;
   r = x % 4;
   if (r == 0) {
     cout <<  1
          <<   A ;
   }
   if (r == 1) {
     cout <<  0
          <<   A ;
   }
   if (r == 2) {
     cout <<  1
          <<   B ;
   }
   if (r == 3) {
     cout <<  2
          <<   A ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline bool SR(int &x) { return scanf( %d , &x) == 1; }
 inline bool SR(long long &x) { return scanf( %lld , &x) == 1; }
 inline bool SR(double &x) { return scanf( %lf , &x); }
 inline bool SR(char *s) { return scanf( %s , s); }
 inline bool RI() { return 1; }
 template <typename I, typename... T>
 bool RI(I &x, T &...tail) {
   return SR(x) && RI(tail...);
 }
 inline void SP(const int x) { printf( %d , x); }
 inline void SP(const long long x) { printf( %lld , x); }
 inline void SP(const double x) { printf( %.10f , x); }
 inline void SP(const char *s) { printf( %s , s); }
 inline void PL() { puts(  ); }
 template <typename I, typename... T>
 void PL(const I x, const T... tail) {
   SP(x);
   if (sizeof...(tail)) putchar(' ');
   PL(tail...);
 }
 template <typename I>
 inline void _DOING(const char *s, I &&x) {
   cerr << s <<   =   << x << '
';
 }
 template <typename I, typename... T>
 void _DOING(const char *s, I &&x, T &&...tail) {
   int c = 0;
   while (*s != ',' || c != 0) {
     if (*s == '(' || *s == '[' || *s == '{') c++;
     if (*s == ')' || *s == ']' || *s == '}') c--;
     cerr << *s++;
   }
   cerr <<   =   << x <<   ,  ;
   _DOING(s + 1, tail...);
 }
 const int INF = 0x3f3f3f3f;
 const long long INF64 = 0x3f3f3f3f3f3f3f3fll;
 inline int RAND() {
   static int x = 880301;
   return x = (x * 0xdefacedll + 1ll) % 0x7fffffffll;
 }
 int n;
 map<pair<int, int>, int> rd;
 inline bool check(long long a, int b) {
   long long x = 1;
   while (b) {
     if (a >= n) return 0;
     if (b & 1) x = x * a;
     if (x >= n) return 0;
     a = a * a;
     b >>= 1;
   }
   return 1;
 }
 int dfs(int a, int b) {
   if (rd.count(make_pair(a, b))) return rd[make_pair(a, b)];
   if (!check(a, b)) return rd[make_pair(a, b)] = 1;
   if (a == 1) {
     if (!check(a + 1, b))
       return rd[make_pair(a, b)] = 0;
     else if (dfs(a + 1, b) == -1 || dfs(a, b + 1) == -1)
       return rd[make_pair(a, b)] = 1;
     else if (dfs(a + 1, b) == 0 || dfs(a, b + 1) == 0)
       return rd[make_pair(a, b)] = 0;
     else
       return rd[make_pair(a, b)] = -1;
   } else if (b == 1) {
     if (1ll * a * a >= n) {
       if ((n - a) & 1)
         return rd[make_pair(a, b)] = -1;
       else
         return rd[make_pair(a, b)] = 1;
     } else if (dfs(a + 1, b) == -1 || dfs(a, b + 1) == -1)
       return rd[make_pair(a, b)] = 1;
     else if (dfs(a + 1, b) == 0 || dfs(a, b + 1) == 0)
       return rd[make_pair(a, b)] = 0;
     else
       return rd[make_pair(a, b)] = -1;
   } else {
     if (dfs(a + 1, b) == -1 || dfs(a, b + 1) == -1)
       return rd[make_pair(a, b)] = 1;
     else
       return rd[make_pair(a, b)] = -1;
   }
 }
 int main() {
   int a, b;
   RI(a, b, n);
   int res = dfs(a, b);
   if (res == 1)
     PL( Masha );
   else if (res == -1)
     PL( Stas );
   else
     PL( Missing );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxN = 50000 + 10;
 int n;
 int B[maxN];
 vector<pair<int, int>> VB;
 int main() {
   scanf( %d , &n);
   for (int i = 0; i < n; i++) scanf( %d , &B[i]);
   for (int i = 0; i < n; i++) {
     VB.push_back(make_pair(B[i] + B[(i + 1) % n], i));
   }
   sort(VB.begin(), VB.end());
   for (int i = 0; i < n; i++) {
     auto p = VB[i];
     B[p.second] = i;
   }
   for (int i = 0; i < n; i++) printf( %d%c , B[i], (i == n - 1) ? '
' : ' ');
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main(int argc, char *argv[]) {
   int n, tmp = 1, res = 1;
   cin >> n;
   int A[n][2];
   for (int i = 0; i < n; i++) cin >> A[i][0] >> A[i][1];
   for (int i = 0; i < n - 1; i++) {
     if ((A[i][0] == A[i + 1][0]) && (A[i][1] == A[i + 1][1])) {
       tmp++;
       if (res < tmp) res = tmp;
     } else
       tmp = 1;
   }
   cout << res << endl;
   return EXIT_SUCCESS;
 }


#include <bits/stdc++.h>
 using namespace std;
 unsigned long long int expo_fast(long long int a, long long int b) {
   a = a;
   long long int result = 1;
   while (b) {
     if (b & 1) result = (result * a);
     b >>= 1;
     a = (a * a);
   }
   return (result);
 }
 void take_in(vector<long long int> *arr) {
   for (int i = 0; i < arr->size(); i++) cin >> (*(arr))[i];
 }
 long long int gcd(long long int a, long long int b) {
   if (b == 0) return a;
   return gcd(b, a % b);
 }
 unsigned long long int power(long long int x, unsigned long long int y,
                              long long int p) {
   long long int res = 1;
   x = x % p;
   while (y > 0) {
     if (y & 1) res = (res * x) % p;
     y = y >> 1;
     x = (x * x) % p;
   }
   return res;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   long long int n, x1, x2, done = 0;
   cin >> n >> x1 >> x2;
   vector<pair<long long int, long long int> > arr;
   vector<long long int> dp(n + 1);
   for (int i = 0; i < n; i++) {
     long long int x;
     cin >> x;
     arr.push_back({x, i});
   }
   sort(arr.begin(), arr.end());
   dp[n] = arr[n - 1].first;
   for (int i = n - 1; i > 0; i--) {
     dp[i] = max(dp[i + 1], arr[i - 1].first * (n - i + 1));
   }
   auto bs = [n](long long int x, long long int tar) -> long long int {
     int low = 1, high = n, ans = n + 1;
     while (low <= high) {
       int mid = (low + high) / 2;
       if (x * mid >= tar) {
         ans = mid;
         high = mid - 1;
       } else
         low = mid + 1;
     }
     return ans;
   };
   for (int i = 1; i <= n; i++) {
     vector<int> indx;
     long long int len = bs(arr[i - 1].first, x1);
     if (i + len - 1 < n && dp[i + len] >= x2) {
       done = 1;
       cout <<  Yes
 ;
       for (int j = n; j >= 1; j--) {
         if (dp[j] >= x2) {
           indx.push_back(j);
           indx.push_back(n);
           break;
         }
       }
       cout << len <<     << indx[1] - indx[0] + 1 <<
 ;
       for (int k = i; k < i + len; k++) cout << arr[k - 1].second + 1 <<    ;
       cout <<
 ;
       for (int k = indx[0]; k <= n; k++) cout << arr[k - 1].second + 1 <<    ;
       break;
     }
     if (!done) {
       len = bs(arr[i - 1].first, x2);
       if (i + len - 1 < n && dp[i + len] >= x1) {
         done = 1;
         cout <<  Yes
 ;
         for (int j = n; j >= 1; j--) {
           if (dp[j] >= x1) {
             indx.push_back(j);
             indx.push_back(n);
             break;
           }
         }
         cout << indx[1] - indx[0] + 1 <<     << len <<
 ;
         for (int k = indx[0]; k <= n; k++) cout << arr[k - 1].second + 1 <<    ;
         cout <<
 ;
         for (int k = i; k < i + len; k++) cout << arr[k - 1].second + 1 <<    ;
         break;
       }
     }
   }
   if (!done) cout <<  No ;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m, k, l[100100], c[100100];
 vector<int> g[100100];
 vector<int> s;
 void dfs(int t) {
   s.push_back(t);
   l[t] = s.size();
   for (auto v : g[t]) {
     if (!l[v])
       dfs(v);
     else {
       if (l[t] - l[v] + 1 >= k) {
         printf( 2
%d
 , l[t] - l[v] + 1);
         for (int i = l[v] - 1; i < l[t]; i++) printf( %d  , s[i]);
         exit(0);
       }
     }
   }
   if (!c[t])
     for (auto v : g[t]) c[v] = 1;
   s.pop_back();
 }
 int main() {
   int i, a, b;
   scanf( %d %d , &n, &m);
   for (i = 0; i < m; i++) {
     scanf( %d %d , &a, &b);
     g[a].push_back(b);
     g[b].push_back(a);
   }
   while (k * k < n) k++;
   dfs(1);
   printf( 1
 );
   for (i = 1; k; i++) {
     if (!c[i]) {
       printf( %d  , i);
       k--;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> v[200008];
 int val[200008];
 int n, tk;
 int dp[200008];
 int lim;
 int siz[200008];
 int cnt, tot;
 int no[200008];
 void dfs(int x, int p) {
   no[x] = val[x] < lim;
   dp[x] = 0;
   int b1 = 0, b2 = 0, b3 = 0;
   siz[x] = 1;
   for (int i = 0; i < v[x].size(); i++) {
     int y = v[x][i];
     if (y == p) continue;
     dfs(y, x);
     siz[x] += siz[y], no[x] += no[y];
     if (no[y] == 0)
       b3 += siz[y];
     else {
       if (dp[y] > b1)
         b2 = b1, b1 = dp[y];
       else
         b2 = max(b2, dp[y]);
     }
   }
   if (val[x] < lim) return;
   dp[x] = b1 + b3 + 1;
   if (tot == no[x])
     cnt = max(cnt, 1 + n - siz[x] + b1 + b2 + b3);
   else
     cnt = max(cnt, 1 + b1 + b2 + b3);
 }
 int check(int mid) {
   lim = mid;
   cnt = 0;
   tot = 0;
   for (int i = 1; i <= n; i++)
     if (val[i] < lim) tot++;
   dfs(1, 0);
   return cnt >= tk;
 }
 int main() {
   scanf( %d%d , &n, &tk);
   for (int i = 1; i <= n; i++) scanf( %d , &val[i]);
   for (int i = 1; i < n; i++) {
     int x, y;
     scanf( %d%d , &x, &y);
     v[x].push_back(y);
     v[y].push_back(x);
   }
   int l = 0, r = 1000000;
   int ans = -1;
   while (l <= r) {
     int mid = (l + r) / 2;
     if (check(mid))
       ans = mid, l = mid + 1;
     else
       r = mid - 1;
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int mini(long long int p, long long int q) {
   if (p < q) return p;
   return q;
 }
 int main() {
   long long int k2, k3, k5, k6, total = 0;
   cin >> k2 >> k3 >> k5 >> k6;
   int m = 0;
   m = mini(k2, k5);
   m = mini(m, k6);
   total = m * 256;
   m = mini(k2 - m, k3);
   total += m * 32;
   cout << total << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double PI = 2.0 * acos(0.0);
 inline int getInt() {
   int x;
   scanf( %d , &x);
   return x;
 }
 inline long long getLL() {
   long long x;
   scanf( %lld , &x);
   return x;
 };
 inline int NUM(char c) { return (int)c - 48; }
 inline char CHR(int n) { return (char)(n + 48); }
 template <class T>
 inline T MAX(T a, T b) {
   if (a > b) return a;
   return b;
 }
 template <class T>
 inline T MIN(T a, T b) {
   if (a < b) return a;
   return b;
 }
 inline void OPEN(const string &s) {
   freopen((s +  .in ).c_str(),  r , stdin);
   freopen((s +  .out ).c_str(),  w , stdout);
 }
 map<string, int> score, sco, mis;
 map<string, int> times;
 int main() {
   vector<string> v;
   for (int k = 0, _n = (5); k < _n; k++) {
     string A, B, C;
     cin >> A >> B;
     cin >> C;
     for (int i = 0, _n = ((C).size()); i < _n; i++)
       if (C[i] == ':') C[i] = ' ';
     stringstream ss(C);
     int s, m;
     ss >> s >> m;
     if (s > m)
       score[A] += 3;
     else if (s < m)
       score[B] += 3;
     else {
       score[A]++;
       score[B]++;
     }
     sco[A] += s;
     mis[A] += m;
     sco[B] += m;
     mis[B] += s;
     v.push_back(A);
     v.push_back(B);
     times[A]++;
     times[B]++;
   }
   sort((v).begin(), (v).end());
   v.resize(unique((v).begin(), (v).end()) - v.begin());
   string OTHER;
   for (int i = 0, _n = ((v).size()); i < _n; i++) {
     if (times[v[i]] == 2 && v[i] !=  BERLAND ) OTHER = v[i];
   }
   vector<pair<int, pair<int, pair<int, string> > > > sorted;
   for (int d = (1), _b = (50); d <= _b; d++) {
     for (int m = (0), _b = (50); m <= _b; m++) {
       int s = m + d;
       string A, B;
       A =  BERLAND , B = OTHER;
       score[A] += 3;
       sco[A] += s;
       sco[B] += m;
       mis[B] += s;
       mis[A] += m;
       sorted.clear();
       for (int i = 0, _n = ((v).size()); i < _n; i++) {
         sorted.push_back(make_pair(
             -score[v[i]],
             make_pair(-sco[v[i]] + mis[v[i]], make_pair(-sco[v[i]], v[i]))));
       }
       sort((sorted).begin(), (sorted).end());
       if (sorted[0].second.second.second ==  BERLAND  ||
           sorted[1].second.second.second ==  BERLAND ) {
         cout << s <<  :  << m << endl;
         return 0;
       }
       score[A] -= 3;
       sco[A] -= s;
       sco[B] -= m;
       mis[B] -= s;
       mis[A] -= m;
     }
   }
   cout <<  IMPOSSIBLE  << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX = 1 << 20, KOR = 32000;
 const long long INF = 1e18;
 int n;
 int p[MAX];
 int sito[KOR];
 int bezp[MAX], sp[MAX];
 int cijseg, cijprom;
 vector<int> Pr;
 void Eratosten() {
   for (int i = 2; i < KOR; i++) {
     if (!sito[i]) {
       Pr.push_back(i);
       for (int j = 2 * i; j < KOR; j += i) sito[j] = i;
     }
   }
 }
 vector<int> Fak(int x) {
   vector<int> R;
   for (int i = 0; i < (int)Pr.size(); i++) {
     if (!(x % Pr[i])) R.push_back(Pr[i]);
     for (; !(x % Pr[i]); x /= Pr[i])
       ;
   }
   if (x > 1) R.push_back(x);
   return R;
 }
 long long Rijesi(int x) {
   memset(bezp, 0, sizeof bezp);
   memset(sp, 0, sizeof sp);
   int prvi = n, zadnji = 0;
   int ukprom = 0;
   for (int i = 0; i < n; i++) {
     if (!(p[i] % x)) bezp[i] = 1;
     if (!((p[i] + 1) % x) || !((p[i] - 1) % x)) sp[i] = 1;
     if (!bezp[i] && !sp[i]) {
       prvi = min(prvi, i);
       zadnji = max(zadnji, i);
     }
     if (!bezp[i] && sp[i]) ukprom++;
   }
   if (!ukprom && prvi == n) return 0;
   long long ret = INF;
   if (prvi == n) ret = (long long)cijprom * ukprom;
   long long maxx = -cijseg;
   int tprom = 0;
   for (int i = 0; i < n; i++) {
     if (!bezp[i] && sp[i]) tprom++;
     if (i >= zadnji)
       ret = min(ret, (long long)i * cijseg - maxx +
                          ((long long)ukprom - tprom) * cijprom);
     if (i < prvi)
       maxx = max(maxx, (long long)-tprom * cijprom + (long long)i * cijseg);
   }
   return ret;
 }
 int main() {
   Eratosten();
   scanf( %d%d%d , &n, &cijseg, &cijprom);
   for (int i = 0; i < n; i++) scanf( %d , &p[i]);
   long long rje = INF;
   vector<int> Bitni;
   for (int i = -1; i <= 1; i++) {
     vector<int> T = Fak(p[0] + i);
     for (int j = 0; j < (int)T.size(); j++) Bitni.push_back(T[j]);
   }
   for (int i = -1; i <= 1; i++) {
     vector<int> T = Fak(p[n - 1] + i);
     for (int j = 0; j < (int)T.size(); j++) Bitni.push_back(T[j]);
   }
   sort(Bitni.begin(), Bitni.end());
   Bitni.resize(unique(Bitni.begin(), Bitni.end()) - Bitni.begin());
   for (int i = 0; i < (int)Bitni.size(); i++) rje = min(rje, Rijesi(Bitni[i]));
   printf( %lld
 , rje);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long N = 1000006, MOD = 1e9 + 7, INF = 1e16;
 long long a[N], b, n, m, k, g[105][105], q, x, ans, Ans, pre[N], l, r;
 string s;
 pair<int, int> p[N];
 int main() {
   ios_base::sync_with_stdio(false), cin.tie(0);
   cin >> n >> m;
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= m; j++) cin >> g[i][j];
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= m; j++)
       if (g[i][j] < 1) x = 1;
   while (!x) {
     Ans++;
     q += min(n, m);
     for (int i = 1; i <= n; i++)
       for (int j = 1; j <= m; j++) {
         g[i][j]--;
         if (g[i][j] < 1) x = 1;
       }
   }
   ans = 0;
   x = 0;
   for (int i = 1; i <= n; i++)
     if (!g[i][1]) x = 1;
   while (!x) {
     ans++, r++;
     for (int i = 1; i <= n; i++) {
       g[i][1]--;
       if (!g[i][1]) x = 1;
     }
   }
   x = 0;
   for (int i = 1; i <= m; i++)
     if (!g[1][i]) x = 1;
   while (!x) {
     ans++, l++;
     for (int i = 1; i <= m; i++) {
       g[1][i]--;
       if (!g[1][i]) x = 1;
     }
   }
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= m; j++)
       if (g[i][j] != g[1][j] + g[i][1]) {
         cout << -1;
         return 0;
       }
   for (int i = 1; i <= n; i++) ans += g[i][1];
   for (int i = 2; i <= m; i++) ans += g[1][i];
   cout << ans + q << endl;
   for (int i = 1; i <= l; i++)
     cout <<  row
          <<     << 1 << endl;
   for (int i = 1; i <= r; i++)
     cout <<  col
          <<     << 1 << endl;
   for (int i = 1; i <= n; i++)
     for (int u = 1; u <= g[i][1]; u++)
       cout <<  row
            <<     << i << endl;
   for (int i = 1; i <= m; i++)
     for (int u = 1; u <= g[1][i]; u++)
       cout <<  col
            <<     << i << endl;
   if (n < m)
     s =  row ;
   else
     s =  col ;
   for (int i = 0; i < min(n, m) * Ans; i++)
     cout << s <<     << i % min(n, m) + 1 << endl;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(NULL);
   cout.tie(NULL);
   int n, k;
   cin >> n >> k;
   int i = 1;
   for (i = k - 1; i > 0; i--) {
     if ((n % i) == 0) break;
   }
   if (i == 0) i = 1;
   int x = (n / i) * k;
   for (; x % k != i; x++) {
   }
   cout << x;
 }


#include <bits/stdc++.h>
 using namespace std;
 using ll = long long;
 const ll INF = 4e18;
 const int MAXN = 1.1e5;
 ll T[MAXN];
 int main() {
   ios::sync_with_stdio(0), cin.tie(0);
   ll N, M, A, D;
   cin >> N >> M >> A >> D;
   for (ll i = 0; i < M; i++) {
     cin >> T[i];
   }
   sort(T, T + M);
   T[M] = INF;
   auto getEmployee = [&](ll i) -> ll { return i <= N ? i * A : INF; };
   ll est = 1;
   ll cst = 0;
   ll ans = 0;
   while (est <= N || cst < M) {
     ll nxt = D + min(getEmployee(est), T[cst]);
     ll een = min(N + 1, (nxt / A) + 1);
     ll cen = ll(upper_bound(T, T + M, nxt) - T);
     ans++;
     if (cst == cen) {
       ll delta = een - est;
       assert(delta > 0);
       ll tgt = min(N + 1, T[cst] / A);
       ll extra = max(tgt - een, ll(0)) / delta;
       ans += extra;
       een += extra * delta;
     }
     assert(een > est || cen > cst);
     assert(est <= een && cst <= cen);
     tie(est, cst) = {een, cen};
   }
   cout << ans << '
';
   return 0;
 }


#include <iostream>
 #include <cstring>
 using namespace std;
 int a[10005],s[10005];
 signed main() {
   int T;
   cin >> T;
   while(T--)
   {
     int n;
     cin >> n;
     memset(s,0,sizeof s);
     for(int i=1;i<=n;i++) cin >> a[i];
     long long ans=0;
     for(int i=1;i<=n;i++)
     {
       ans+=max(0,a[i]-s[i]-1);
       s[i]=max(s[i],a[i]-1);
       for(int j=i+2;j<=min(n,i+a[i]);j++)
         ++s[j];
       s[i+1]+=max(0,s[i]-a[i]+1);
     }
     cout << ans <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int l[51], r[51], a[51], c[51], dp[51][51][51];
 void inline FilterRestrictions(int i, int j, int h, vector<int> &v) {
   vector<int> u;
   for (int x : v) {
     if (r[x] < i || j < l[x] || a[x] >= h) {
       continue;
     }
     u.push_back(x);
   }
   v = u;
   u.clear();
   sort(v.begin(), v.end(), [](int i, int j) { return l[i] > l[j]; });
 }
 int Solve(int i, int j, int h, vector<int> v) {
   if (j < i) {
     return 0;
   }
   if (dp[i][j][h] != -1) {
     return dp[i][j][h];
   }
   FilterRestrictions(i, j, h, v);
   int ans = Solve(i, j, h - 1, v), cost = h * h;
   vector<vector<int> > V(51 + 1);
   vector<int> v1;
   for (int x = i; x <= j; ++x) {
     for (; !v.empty() && l[v.back()] == x; v.pop_back()) {
       int k = v.back();
       cost -= c[k];
       V[r[k] + 1].push_back(k);
     }
     for (auto k : V[x]) {
       cost += c[k];
       v1.push_back(k);
     }
     int ansx = cost + Solve(i, x - 1, h, v1) + Solve(x + 1, j, h, v);
     ans = max(ans, ansx);
   }
   dp[i][j][h] = ans;
   return ans;
 }
 int main() {
   int n, h, m;
   cin >> n >> h >> m;
   for (int i = 1; i <= m; ++i) {
     cin >> l[i] >> r[i] >> a[i] >> c[i];
   }
   vector<int> v;
   for (int i = 1; i <= m; ++i) {
     v.push_back(i);
   }
   for (int i = 1; i <= n; ++i) {
     for (int j = i; j <= n; ++j) {
       for (int x = 1; x <= h; ++x) {
         dp[i][j][x] = -1;
       }
     }
   }
   cout << Solve(1, n, h, v) << '
';
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast )
 #pragma GCC optimize( unroll-loops )
 #pragma GCC target( \n      sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )
 using namespace std;
 template <typename T1, typename T2>
 void ckmin(T1 &a, T2 b) {
   if (a > b) a = b;
 }
 template <typename T1, typename T2>
 void ckmax(T1 &a, T2 b) {
   if (a < b) a = b;
 }
 int read() {
   int x = 0, f = 0;
   char ch = getchar();
   while (!isdigit(ch)) f |= ch == '-', ch = getchar();
   while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
   return f ? -x : x;
 }
 template <typename T>
 void print(T x) {
   if (x < 0) putchar('-'), x = -x;
   if (x >= 10) print(x / 10);
   putchar(x % 10 + '0');
 }
 template <typename T>
 void print(T x, char let) {
   print(x), putchar(let);
 }
 const int mlen = 1 << 20;
 const int N = mlen + 5;
 const int mod = 998244353;
 unsigned long long omgs[N];
 int rev[N];
 int qpow(int a, int b = mod - 2) {
   int res = 1;
   while (b) {
     if (b & 1) res = 1ll * res * a % mod;
     a = 1ll * a * a % mod;
     b >>= 1;
   }
   return res;
 }
 const int G = qpow(3, (mod - 1) / mlen);
 void setup() {
   omgs[mlen / 2] = 1;
   for (int i = mlen / 2 + 1; i < mlen; i++) omgs[i] = G * omgs[i - 1] % mod;
   for (int i = mlen / 2 - 1; i > 0; i--) omgs[i] = omgs[i << 1];
 }
 int getR(int len) {
   int lim = 1, L = 0;
   while (lim <= len) lim <<= 1, L++;
   for (int i = 0; i < lim; i++)
     rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << L - 1);
   return lim;
 }
 inline void dft(vector<int> &a, int lim) {
   a.resize(lim);
   static unsigned long long A[N];
   for (int i = 0; i < lim; i++) A[rev[i]] = a[i];
   for (int mid = 1; mid < lim; mid <<= 1) {
     for (int i = 0; i < lim; i += mid << 1) {
       unsigned long long *W = omgs + mid;
       for (int j = 0; j < mid; j++) {
         unsigned long long tmp = *(W++) * A[i + j + mid] % mod;
         A[i + j + mid] = A[i + j] + mod - tmp;
         A[i + j] += tmp;
       }
     }
   }
   for (int i = 0; i < lim; i++) a[i] = A[i] % mod;
 }
 inline void idft(vector<int> &a, int lim) {
   a.resize(lim);
   dft(a, lim), reverse(a.begin() + 1, a.end());
   int linv = mod - (mod - 1) / lim;
   for (int i = 0; i < lim; i++) a[i] = 1ll * a[i] * linv % mod;
 }
 vector<int> operator*(vector<int> a, vector<int> b) {
   int len = (int(a.size())) + (int(b.size())) - 1, lim = getR(len);
   dft(a, lim), dft(b, lim);
   for (int i = 0; i < lim; i++) a[i] = 1ll * a[i] * b[i] % mod;
   idft(a, lim), a.resize(len);
   return a;
 }
 vector<int> adj[N];
 int n;
 int son[N];
 void dfs1(int u, int fa) {
   for (auto v : adj[u]) {
     if (v == fa) continue;
     son[u]++;
     dfs1(v, u);
   }
 }
 int fac[N], ifac[N];
 inline int C(int n, int m) {
   return 1ll * fac[n] * ifac[n - m] % mod * ifac[m] % mod;
 }
 int main() {
   setup();
   n = read();
   fac[0] = 1;
   for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
   ifac[n] = qpow(fac[n]);
   for (int i = n; i >= 1; i--) ifac[i - 1] = 1ll * ifac[i] * i % mod;
   for (int i = 1; i <= n - 1; i++) {
     int u = read(), v = read();
     adj[u].push_back(v), adj[v].push_back(u);
   }
   dfs1(1, 0);
   vector<int> f = {1};
   sort(son + 1, son + n + 1, greater<int>());
   for (int i = 1; i <= n; i++) {
     int j = i;
     while (j < n && son[i] == son[j + 1]) j++;
     int up = j - i + 1;
     vector<int> g(up + 1);
     int cf = 1;
     for (int i = 0; i <= up; i++) {
       int coef = 1ll * C(up, i) * cf % mod;
       g[i] = coef;
       cf = 1ll * cf * (mod - son[j]) % mod;
     }
     f = f * g;
     i = j;
   }
   int ans = 0;
   for (int i = 0; i <= n - 1; i++) ans = (ans + 1ll * fac[n - i] * f[i]) % mod;
   print(ans, '
');
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct MinMax {
   int min, max;
   MinMax() : min(INT_MAX), max(INT_MIN){};
   MinMax(int min, int max) : min(min), max(max){};
 };
 int main(int argc, char const *argv[]) {
   ios_base::sync_with_stdio(false);
   int n, m;
   cin >> n >> m;
   MinMax a[n];
   for (int i = 0; i < m; i++) {
     int c;
     cin >> c;
     a[c - 1].min = min(a[c - 1].min, i);
     a[c - 1].max = max(a[c - 1].max, i);
   }
   int sum = 0;
   for (int i = 0; i < n; i++) {
     int cnt = 3;
     if (i == 0 || i == n - 1) cnt--;
     if (a[i].min < INT_MAX) cnt--;
     if (i < n - 1) {
       if (a[i].min < a[i + 1].max) cnt--;
     }
     if (i > 0) {
       if (a[i - 1].max > a[i].min) cnt--;
     }
     sum += cnt;
   }
   if (n == 1) sum = 0;
   cout << sum << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long int t, n, i, j, k, h = 0;
   cin >> n;
   long long int a[n], b[n];
   for (i = 0; i < n; ++i) {
     cin >> a[i] >> b[i];
   }
   if (n == 1) cout << a[0] << endl;
   if (n > 1) {
     set<long long int> s1, s, s3;
     set<long long int>::iterator jt, it;
     j = a[0];
     while (j % 2 == 0) {
       s.insert(2);
       j /= 2;
     }
     for (k = 3; k <= sqrt(j); k = k + 2) {
       while (j % k == 0) {
         s.insert(k);
         j /= k;
       }
     }
     if (j > 2) s.insert(j);
     j = b[0];
     while (j % 2 == 0) {
       s.insert(2);
       j /= 2;
     }
     for (k = 3; k <= sqrt(j); k = k + 2) {
       while (j % k == 0) {
         s.insert(k);
         j /= k;
       }
     }
     if (j > 2) s.insert(j);
     j = a[1];
     while (j % 2 == 0) {
       s1.insert(2);
       j /= 2;
     }
     for (k = 3; k <= sqrt(j); k = k + 2) {
       while (j % k == 0) {
         s1.insert(k);
         j /= k;
       }
     }
     if (j > 2) s1.insert(j);
     j = b[1];
     while (j % 2 == 0) {
       s1.insert(2);
       j /= 2;
     }
     for (k = 3; k <= sqrt(j); k = k + 2) {
       while (j % k == 0) {
         s1.insert(k);
         j /= k;
       }
     }
     if (j > 2) s1.insert(j);
     for (it = s.begin(); it != s.end(); ++it) {
       for (jt = s1.begin(); jt != s1.end(); jt++) {
         if ((*jt) % (*it) == 0) {
           s3.insert(*it);
         } else if ((*it) % (*jt) == 0)
           s3.insert(*jt);
       }
     }
     s.clear();
     for (i = 2; i < n; ++i) {
       for (it = s3.begin(); it != s3.end(); ++it) {
         if (a[i] % (*it) == 0) s.insert(*it);
         if (b[i] % (*it) == 0) s.insert(*it);
       }
       s3.clear();
       for (it = s.begin(); it != s.end(); ++it) {
         s3.insert(*it);
       }
       s.clear();
     }
     if (s3.size() > 0) {
       for (it = s3.begin(); it != s3.end(); ++it) {
         cout << *it << endl;
         break;
       }
     } else
       cout <<  -1
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long n;
   cin >> n;
   if (n == 0)
     cout << 1;
   else {
     n %= 4;
     if (n == 0) n = 4;
     n = pow(8, n);
     cout << n % 10;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, m;
   cin >> n >> m;
   vector<double> a(n), b(n);
   for (int i = 0; i < n; i++) {
     cin >> a[i];
     if (a[i] <= 1) {
       printf( -1
 );
       exit(0);
     }
   }
   for (int i = 0; i < n; i++) {
     cin >> b[i];
     if (b[i] <= 1) {
       printf( -1
 );
       exit(0);
     }
   }
   double s = m;
   s += s / (b[0] - 1);
   for (int i = n - 1; i >= 1; i--) {
     s += s / (a[i] - 1);
     s += s / (b[i] - 1);
   }
   s += s / (a[0] - 1);
   printf( %.10f
 , s - m);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using ll = long long;
 using ull = unsigned long long;
 const int MAX_N = 1e6 + 5;
 int fen[MAX_N];
 int n;
 int lowbit(int x) { return x & (-x); }
 void add(int x, int val) {
   for (int i = x; i <= n; i += lowbit(i)) fen[i] += val;
 }
 int sum(int x) {
   int s = 0;
   for (int i = x; i; i -= lowbit(i)) s += fen[i];
   return s;
 }
 int sum(int l, int r) { return sum(r) - sum(l); }
 map<int, int> cnt;
 int pre[MAX_N];
 int back[MAX_N];
 int arr[MAX_N];
 int main() {
   ios::sync_with_stdio(false);
   cin >> n;
   for (int i = 0; i < n; i++) {
     cin >> arr[i];
     cnt[arr[i]]++;
     pre[i] = cnt[arr[i]];
   }
   cnt.clear();
   for (int i = n - 1; i >= 0; i--) {
     cnt[arr[i]]++;
     back[i] = cnt[arr[i]];
     add(back[i], 1);
   }
   ll ans = 0;
   for (int i = 0; i < n; i++) {
     add(back[i], -1);
     ans += sum(pre[i] - 1);
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e6 + 9;
 bool p[N];
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   ;
   vector<int> k;
   for (int i = 2; i <= 1e6; i++) {
     if (p[i]) continue;
     k.push_back(i);
     for (int j = i + i; j <= 1e6; j += i) {
       p[j] = 1;
     }
   }
   int t;
   cin >> t;
   while (t--) {
     long long x;
     cin >> x;
     long long m = sqrtl(x);
     long long r = upper_bound(k.begin(), k.end(), x) - k.begin();
     long long l = upper_bound(k.begin(), k.end(), m) - k.begin();
     cout << r - l + 1 << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 1000000007;
 const int N = 100100;
 int n;
 int main() {
   cin >> n;
   for (int i = n + 1; i <= n + n; i++) cout << i <<    ;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double EPS = 1e-9;
 struct DDMY {
   ostringstream o;
   template <class T>
   DDMY &operator,(const T &t) {
     o << t <<  , ;
     return *this;
   }
   string operator*() { return o.str().substr(0, o.str().size() - 1); }
 };
 template <class T>
 std::ostream &operator<<(std::ostream &o, const std::vector<T> &v) {
   o <<  [ ;
   for (std::size_t i = 0; i < v.size(); i++)
     o << v[i] << (i < v.size() - 1 ?  ,  :   );
   return o <<  ] ;
 }
 template <class T, class U>
 std::ostream &operator<<(std::ostream &o, const std::pair<T, U> &v) {
   return o << v.first <<  :  << v.second;
 }
 template <class T, class U>
 std::ostream &operator<<(std::ostream &o, const std::map<T, U> &v) {
   o <<  { ;
   typename std::map<T, U>::const_iterator i = v.begin(), j = i;
   ++j;
   for (; i != v.end(); ++i, ++j) o << *i << (j != v.end() ?  ,  :   );
   return o <<  } ;
 }
 template <class T>
 std::ostream &operator<<(std::ostream &o, const std::set<T> &v) {
   o <<  { ;
   typename std::set<T>::const_iterator i = v.begin(), j = i;
   ++j;
   for (; i != v.end(); ++i, ++j) o << *i << (j != v.end() ?  ,  :   );
   return o <<  } ;
 }
 void error() {
   cout << -1 << endl;
   exit(0);
 }
 int main(int argc, char *argv[]) {
   ios::sync_with_stdio(false);
   int a1, a2, a3, a4;
   cin >> a1 >> a2 >> a3 >> a4;
   if (max(a3, a4) > a1 || max(a3, a4) > a2) {
     error();
   }
   string line;
   if (a3 >= a4) {
     for (int i = 0; i < a3; i++) {
       line +=  47 ;
     }
     a1 -= a3;
     a2 -= a3;
     a4 -= a3 - 1;
     if (a1 < 0 || a2 < 0 || a4 < 0) {
       error();
     }
     if (a4 == 1) {
       if (a1 == 0) {
         if (a2 > 0) {
           line = '7' + line;
           a2--;
           if (a2 > 0) line += string(a2, '7');
         } else {
           error();
         }
       } else {
         line += string(a2, '7');
         line += '4';
         a1--;
       }
     } else if (a4 == 0) {
       line += string(a2, '7');
     } else {
       error();
     }
     if (a1 > 0) line = string(a1, '4') + line;
   } else {
     for (int i = 0; i < a4; i++) {
       line +=  74 ;
     }
     a1 -= a4;
     a2 -= a4;
     a3 -= a4 - 1;
     if (a1 < 0 || a2 < 0 || a4 < 0) {
       error();
     }
     if (a3 == 0) {
       if (a4 > 1) {
         line = line.substr(0, line.size() - 2);
         line = line.substr(2);
         line = '7' + string(a1 + 1, '4') + line;
         line += string(a2 + 1, '7') + '4';
       } else if (a4 == 1) {
         a1 += a4;
         a2 += a4;
         if (a2 > 0 && a1 > 0) {
           line = string(a2, '7') + string(a1, '4');
         } else {
           error();
         }
       } else if (a4 == 0) {
         if (a1 == 0 || a2 == 0) {
           if (a1 > 0) {
             line = string(a1, '4');
           } else if (a2 > 0) {
             line = string(a2, '7');
           }
         } else {
           error();
         }
       } else {
         error();
       }
     } else {
       error();
     }
   }
   cout << line << endl;
   return 0;
 }


#include <bits/stdc++.h>

 template <class T>
 inline void read(T &res)
 {
 	res = 0; bool bo = 0; char c;
 	while (((c = getchar()) < '0' || c > '9') && c != '-');
 	if (c == '-') bo = 1; else res = c - 48;
 	while ((c = getchar()) >= '0' && c <= '9')
 		res = (res << 3) + (res << 1) + (c - 48);
 	if (bo) res = ~res + 1;
 }

 const int N = 505;

 int n, m, a[N][N];

 int main()
 {
 	read(n); read(m);
 	for (int i = 1; i <= n; i++)
 		for (int j = 1; j <= m; j++)
 			read(a[i][j]);
 	for (int i = 1; i <= n; i++)
 	{
 		for (int j = 1; j <= m; j++)
 			printf( %d  , i + j & 1 ? 720720 : 720720 - a[i][j]
 				* a[i][j] * a[i][j] * a[i][j]);
 		puts(  );
 	}
 	return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long double pi = 3.141592653589793238462643383279502884197;
 vector<long long int> v(14);
 void Compute() {
   for (long long int i = 1; i < 14; i++) {
     v[i] = pow(2, i) + v[i - 1];
   }
 }
 void solve() {
   long long int n;
   cin >> n;
   long long int ans = 0;
   string s = to_string(n);
   long long int si = s.size();
   ans += v[si - 1];
   for (long long int i = 0; i < s.size(); i++) {
     if (s[i] == '7') ans += pow(2, (si - 1 - i));
   }
   ans++;
   cout << ans << endl;
 }
 int main() {
   Compute();
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int V = 100000 + 5;
 int n, num[V];
 int main() {
   int i, j;
   scanf( %d , &n);
   for (i = 0; i < n; ++i) scanf( %d , &num[i]);
   sort(num, num + n);
   printf( %d  , num[n - 1]);
   for (i = 1; i < n - 1; ++i) printf( %d  , num[i]);
   printf( %d
 , num[0]);
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e6 + 10;
 const double pi = acos(-1.0);
 struct Complex {
   double x, y;
   Complex(double x = 0.0, double y = 0.0) {
     this->x = x;
     this->y = y;
   }
   Complex operator-(const Complex &b) const {
     return Complex(x - b.x, y - b.y);
   }
   Complex operator+(const Complex &b) const {
     return Complex(x + b.x, y + b.y);
   }
   Complex operator*(const Complex &b) const {
     return Complex(x * b.x - y * b.y, x * b.y + y * b.x);
   }
 };
 void change(Complex y[], int len) {
   for (int i = 1, j = len / 2; i < len - 1; i++) {
     if (i < j) swap(y[i], y[j]);
     int k = len / 2;
     while (j >= k) {
       j -= k;
       k /= 2;
     }
     if (j < k) j += k;
   }
 }
 void fft(Complex y[], int len, int on) {
   change(y, len);
   for (int h = 2; h <= len; h <<= 1) {
     Complex wn(cos(-on * 2 * pi / h), sin(-on * 2 * pi / h));
     for (int j = 0; j < len; j += h) {
       Complex w(1, 0);
       for (int k = j; k < j + h / 2; k++) {
         Complex u = y[k];
         Complex t = w * y[k + h / 2];
         y[k] = u + t;
         y[k + h / 2] = u - t;
         w = w * wn;
       }
     }
   }
   if (on == -1)
     for (int i = 0; i < len; i++) y[i].x /= len;
 }
 int n, m, k, i, j, p[30];
 Complex A[N], B[N], C[N];
 int a[N], b[N];
 char sa[N], sb[N];
 int main() {
   for (i = 1; i <= 26; i++) scanf( %d , &p[i]);
   scanf( %s %s , sa, sb);
   m = strlen(sa), n = strlen(sb);
   for (i = 0, j = m - 1; i < j; i++, j--) swap(sa[i], sa[j]);
   for (i = 0; i < m; i++) a[i] = sa[i] - 'a' + 1;
   for (i = 0; i < n; i++) b[i] = sb[i] - 'a' + 1;
   for (k = 1; k < n; k <<= 1)
     ;
   for (i = 0; i < k; i++)
     A[i] = Complex(2 * a[i] * p[a[i]] * (a[i] + p[a[i]]), 0),
     B[i] = Complex(b[i], 0);
   for (fft(A, k, 1), fft(B, k, 1), i = 0; i < k; i++) C[i] = C[i] - A[i] * B[i];
   for (i = 0; i < k; i++)
     A[i] = Complex(a[i] * a[i] + p[a[i]] * p[a[i]] + 4 * a[i] * p[a[i]], 0),
     B[i] = Complex(b[i] * b[i], 0);
   for (fft(A, k, 1), fft(B, k, 1), i = 0; i < k; i++) C[i] = C[i] + A[i] * B[i];
   for (i = 0; i < k; i++)
     A[i] = Complex(2 * (a[i] + p[a[i]]), 0),
     B[i] = Complex(b[i] * b[i] * b[i], 0);
   for (fft(A, k, 1), fft(B, k, 1), i = 0; i < k; i++) C[i] = C[i] - A[i] * B[i];
   for (i = 0; i < k; i++) {
     if (i < m)
       A[i] = Complex(1, 0);
     else
       A[i] = Complex(0, 0);
     B[i] = Complex(b[i] * b[i] * b[i] * b[i], 0);
   }
   for (fft(A, k, 1), fft(B, k, 1), i = 0; i < k; i++) C[i] = C[i] + A[i] * B[i];
   for (i = 0; i < k; i++) {
     A[i] = Complex(a[i] * a[i] * p[a[i]] * p[a[i]], 0);
     if (i < n)
       B[i] = Complex(1, 0);
     else
       B[i] = Complex(0, 0);
   }
   for (fft(A, k, 1), fft(B, k, 1), i = 0; i < k; i++) C[i] = C[i] + A[i] * B[i];
   fft(C, k, -1);
   for (int i = 0; i < n - m + 1; i++)
     printf( %d , ((long long)(C[i + m - 1].x + 0.5) == 0));
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline void read(int& n) {
   int x = 0, f = 1;
   char ch = getchar();
   while (ch < '0' || ch > '9') {
     if (ch == '-') f = -1;
     ch = getchar();
   }
   while (ch >= '0' && ch <= '9')
     x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
   n = x * f;
 }
 int outputarray[20];
 inline void write(int k) {
   int num = 0;
   if (k < 0) putchar('-'), k = -k;
   do {
     outputarray[++num] = k % 10, k /= 10;
   } while (k);
   while (num) putchar(outputarray[num--] + '0');
   puts(  );
 }
 const int N = 50;
 int n, m, sg[N][N][N][N][2];
 char s[N][N];
 int dfs(int x0, int x2, int y0, int y2, int type) {
   if (sg[x0][x2][y0][y2][type] >= 0) return sg[x0][x2][y0][y2][type];
   int a[N * N];
   memset(a, 0, sizeof(a));
   for (int i = 0; i < n; i++)
     for (int j = 0; j < m; j++)
       if (((i + j) & 1) == type) {
         int x = i + j, y = i - j + m;
         if (x >= x0 && x < x2 && y >= y0 && y < y2) {
           int tmp = 0;
           if (s[i][j] == 'L')
             tmp = dfs(x0, x, y0, y2, type) ^ dfs(x + 1, x2, y0, y2, type);
           if (s[i][j] == 'R')
             tmp = dfs(x0, x2, y0, y, type) ^ dfs(x0, x2, y + 1, y2, type);
           if (s[i][j] == 'X')
             tmp = dfs(x0, x, y0, y, type) ^ dfs(x0, x, y + 1, y2, type) ^
                   dfs(x + 1, x2, y0, y, type) ^ dfs(x + 1, x2, y + 1, y2, type);
           a[tmp] = 1;
         }
       }
   while (a[++sg[x0][x2][y0][y2][type]])
     ;
   return sg[x0][x2][y0][y2][type];
 }
 int main() {
   memset(sg, -1, sizeof(sg));
   read(n), read(m);
   for (int i = 0; i < n; i++) scanf( %s , s[i]);
   if (dfs(0, n + m, 0, n + m, 0) ^ dfs(0, n + m, 0, n + m, 1))
     puts( WIN );
   else
     puts( LOSE );
   return 0;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 int arr[4005];
 int nxt[4005], prv[4005];
 map<int, int> M;
 map<int, int> Q;
 int main() {
   int n;
   cin >> n;
   int ans = 0;
   for (int i = 0; i < n; ++i) {
     cin >> arr[i];
     if (M.find(arr[i]) != M.end()) {
       nxt[M[arr[i]]] = i;
       prv[i] = M[arr[i]];
       Q[arr[i]]++;
       ans = max(ans, Q[arr[i]]);
     } else {
       prv[i] = -1;
       Q[arr[i]]++;
       ans = max(ans, Q[arr[i]]);
     }
     M[arr[i]] = i;
     nxt[i] = -1;
   }
   for (int i = 0; i < n; ++i) {
     if (prv[i] != -1) {
       continue;
     }
     for (int j = i + 1; j < n; ++j) {
       if (prv[j] != -1) {
         continue;
       }
       int cur = 2;
       int t1 = i, t2 = j;
       while (t1 != -1 && t2 != -1) {
         if (t1 < t2) {
           if (nxt[t1] > t2) {
             ++cur;
           }
           t1 = nxt[t1];
         } else {
           if (nxt[t2] > t1) {
             ++cur;
           }
           t2 = nxt[t2];
         }
       }
       ans = max(ans, cur);
     }
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int b = 3e6;
 long long a[b];
 void ans(long long x, long long y, long long k, long long i) {
   long long sidl = k + k * y, ans = k;
   long long ez1 = (sidl - 3 + x) / (x - 1);
   ans += ez1;
   a[i] = ans;
 }
 int main() {
   long long t, x, y, k, j;
   cin >> t;
   for (int i = 0; i < t; i++) {
     cin >> x >> y >> k;
     ans(x, y, k, i);
   }
   for (int i = 0; i < t; i++) cout << a[i] << endl;
   return 0;
 };


#include <bits/stdc++.h>
 using namespace std;
 int test() {
   long long n;
   cin >> n;
   long long cL = 0, cR = 0;
   long long si = 3 * 100001;
   long long *right = new long long[si], *left = new long long[si];
   for (long long i = 0; i < si; i++) {
     right[i] = 0;
     left[i] = 0;
   }
   long long prop = 0, l = 0, r = 0;
   string temp;
   for (long long i = 0; i < n; i++) {
     cin >> temp;
     long long tempS = temp.size();
     for (long long i = 0; i < tempS; i++) {
       if (temp[i] == '(') {
         cL++;
         l++;
       } else {
         cR++;
         if (l != 0)
           l--;
         else
           r++;
       }
     }
     if (r != 0 && l != 0) {
     } else if (cR == cL)
       prop++;
     else if (cR > cL)
       right[cR - cL]++;
     else
       left[cL - cR]++;
     l = 0;
     r = 0;
     cL = 0;
     cR = 0;
   }
   long long S = 0;
   for (long long i = 0; i < si; i++) {
     if (right[i] != 0 && left[i] != 0) {
       S += right[i] * left[i];
     }
   }
   S += prop * prop;
   cout << S;
   return 0;
 }
 int hacker() { return 0; }
 int main() {
   while (true) {
     return test();
     cout <<

-- ;
     hacker();
     cout <<

-----------------------------

 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double EPS = 1e-6;
 double n, r;
 bool check(double R) {
   double x1 = r + R;
   double y1 = 0;
   double x2 = cos(2 * acos(-1) / n) * (r + R);
   double y2 = sin(2 * acos(-1) / n) * (r + R);
   double len = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
   if (len <= 2 * R)
     return true;
   else
     return false;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   cin >> n >> r;
   double l1 = 0, r1 = 10000;
   for (int i = 0; i < 500; i++) {
     double mm = (l1 + r1) / 2.0;
     if (check(mm))
       r1 = mm;
     else
       l1 = mm;
   }
   cout.fixed;
   cout.precision(15);
   cout << l1;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int a, b, c;
   cin >> a;
   cin >> b;
   cin >> c;
   int d = a + b - c;
   int e = b + c - a;
   int f = a + c - b;
   if (d < 0 || e < 0 || f < 0 || e % 2 || d % 2 || f % 2) {
     cout <<  Impossible ;
     return 0;
   }
   cout << d / 2 <<     << e / 2 <<     << f / 2 << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct node {
   int l, r, num;
 } a[100005];
 int n, ans[100005];
 bool cmp(node x, node y) {
   if (x.l == y.l) return x.r < y.r;
   return x.l < y.l;
 }
 void solve() {
   cin >> n;
   for (int i = 1; i <= n; i++) {
     cin >> a[i].l >> a[i].r;
     a[i].num = i + 1;
   }
   sort(a + 1, a + n + 1, cmp);
   set<int> F;
   int mx = -1;
   for (int i = 1; i <= n - 1; i++) {
     F.insert(a[i].num);
     mx = max(mx, a[i].r);
     if (mx < a[i + 1].l) {
       for (int j = 1; j <= n; j++) {
         if (F.count(a[j].num))
           ans[a[j].num] = 1;
         else
           ans[a[j].num] = 2;
       }
       for (int j = 2; j <= n + 1; j++) cout << ans[j] <<    ;
       cout << endl;
       return;
     }
   }
   cout << -1 << endl;
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int T;
   cin >> T;
   while (T--) solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int n, a, b, c, d, e, f, g, h;
   cin >> n;
   vector<long long int> values(n), kalues(n), malues;
   for (int i = 0; i < n; i++) {
     cin >> values[i];
     cin >> kalues[i];
     kalues[i]--;
     malues.push_back(values[i]);
     malues.push_back(kalues[i]);
   }
   sort(values.begin(), values.end());
   sort(kalues.begin(), kalues.end());
   sort(malues.begin(), malues.end());
   long long int mini = -5, year = -1;
   malues.erase(unique(malues.begin(), malues.end()), malues.end());
   for (int i = 0; i < 2 * n; i++) {
     long long int helebele =
         lower_bound(kalues.begin(), kalues.end(), malues[i]) - kalues.begin();
     helebele += n - (upper_bound(values.begin(), values.end(), malues[i]) -
                      values.begin());
     if (mini < n - helebele) mini = n - helebele, year = malues[i];
   }
   cout << year <<     << mini << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 char s[55];
 int l;
 int df[55][10];
 int f(int pos, int c) {
   if (pos == l) return 1;
   if (df[pos][c] != -1) return df[pos][c];
   int res = 0;
   int nn = c + s[pos];
   res += f(pos + 1, nn / 2);
   if (nn & 1) res += f(pos + 1, (nn + 1) / 2);
   return df[pos][c] = res;
 }
 bool good() {
   for (int i = 1; i < l; i++) {
     int nn = s[i] + s[i - 1];
     if (nn & 1) {
       if (nn / 2 != s[i] && (nn + 1) / 2 != s[i]) return false;
     } else {
       if (nn / 2 != s[i]) return false;
     }
   }
   return true;
 }
 int main() {
   memset(df, -1, sizeof(df));
   scanf( %s , s);
   l = strlen(s);
   for (int i = 0; i < l; i++) s[i] -= '0';
   long long ans = 0;
   for (int i = 0; i < 10; i++) ans += f(1, i);
   if (good()) ans--;
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 const int INF = 1e9;
 using namespace std;
 int R, C, frow, fcol, row, col, srow, scol, nxcol, nxrow;
 int ans, intest[1005][1005], goal;
 char grid[1005][1005];
 queue<pair<int, int> > q;
 const int dr[4] = {-1, 0, 1, 0};
 const int dc[4] = {0, -1, 0, 1};
 bool inside(int r, int c) { return r > 0 && c > 0 && r <= R && c <= C; }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cin >> R >> C;
   for (int r = 1; r <= R; r++) {
     for (int c = 1; c <= C; c++) {
       cin >> grid[r][c];
       intest[r][c] = INF;
       if (grid[r][c] == 'S')
         srow = r, scol = c;
       else if (grid[r][c] == 'E')
         frow = r, fcol = c;
     }
   }
   intest[frow][fcol] = 0;
   q.push(make_pair(frow, fcol));
   while (!q.empty()) {
     pair<int, int> cur = q.front();
     q.pop();
     row = cur.first;
     col = cur.second;
     for (int i = 0; i <= 3; i++) {
       nxrow = row + dr[i];
       nxcol = col + dc[i];
       if (!inside(nxrow, nxcol)) continue;
       if (grid[nxrow][nxcol] == 'T') continue;
       if (intest[nxrow][nxcol] != INF) continue;
       intest[nxrow][nxcol] = intest[row][col] + 1;
       q.push(make_pair(nxrow, nxcol));
     }
   }
   goal = intest[srow][scol];
   for (int i = 1; i <= R; i++) {
     for (int j = 1; j <= C; j++) {
       if (grid[i][j] - '0' > 0 && grid[i][j] < 58) {
         srow = i, scol = j;
         if (intest[srow][scol] <= goal) ans += (grid[i][j] - '0');
       }
     }
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   int a[n];
   for (int i = 0; i < n; i++) cin >> a[i];
   sort(a, a + n);
   for (int i = 0; i < n; i++) cout << a[i] << ' ';
 }


#include <bits/stdc++.h>
 using namespace std;
 int x, y, z;
 int _x, _y, _z;
 int a[6];
 long long int ans = 0LL;
 int main() {
   ios::sync_with_stdio(false);
   cin >> x >> y >> z;
   cin >> _x >> _y >> _z;
   for (int i = 0; i < 6; i++) cin >> a[i];
   if (y < 0) ans += a[0];
   if (y > _y) ans += a[1];
   if (z < 0) ans += a[2];
   if (z > _z) ans += a[3];
   if (x < 0) ans += a[4];
   if (x > _x) ans += a[5];
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int SZ = 8e6 + 10;
 const int INF = 1e9 + 10;
 const int mod = 998244353;
 const long double eps = 1e-8;
 long long read() {
   long long n = 0;
   char a = getchar();
   bool flag = 0;
   while (a > '9' || a < '0') {
     if (a == '-') flag = 1;
     a = getchar();
   }
   while (a <= '9' && a >= '0') {
     n = n * 10 + a - '0', a = getchar();
   }
   if (flag) n = -n;
   return n;
 }
 int a[SZ], f[1010][1010], b[SZ], c[SZ];
 int main() {
   int n = read(), k = read();
   for (int i = 1; i <= n; i++) a[i] = read();
   sort(a + 1, a + 1 + n);
   for (int i = 1; i <= n; i++) {
     for (int j = i + 1; j <= n; j++) {
       b[++b[0]] = a[j] - a[i];
     }
   }
   sort(b + 1, b + 1 + b[0]);
   b[0] = unique(b + 1, b + 1 + b[0]) - b - 1;
   int ans = 0;
   for (int j = 1; j <= b[0]; j++) {
     int minx = b[j];
     if (minx > 1e5 / (k - 1)) break;
     for (int i = 1; i <= n; i++) f[i][1] = f[i - 1][1] + 1;
     for (int l = 2; l <= k; l++) {
       for (int i = 2, lst = 0; i <= n; i++) {
         while (lst < i && a[lst + 1] <= a[i] - minx) lst++;
         f[i][l] = f[lst][l - 1];
       }
       for (int i = 1; i <= n; i++) (f[i][l] += f[i - 1][l]) %= mod;
     }
     c[j] = f[n][k];
   }
   for (int j = 1; j <= b[0]; j++)
     (ans += 1ll * b[j] * (c[j] - c[j + 1] + mod) % mod) %= mod;
   printf( %d
 , ans);
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e6 + 5;
 long long le[N], ri[N], mid, lee, rii;
 long long a[N], b[N], c[N], mp[35], ans, n, answ, idx, idx1, pw[35], bb;
 int main() {
   std::ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   cin >> n;
   for (int i = 1; i <= n; i++) {
     cin >> a[i];
   }
   pw[0] = 1;
   for (int i = 1; i <= 35; i++) {
     pw[i] = pw[i - 1] * 2;
   }
   for (int i = 0; i <= 30; i++) {
     for (int j = 1; j <= n; j++) {
       b[j] += a[j] & pw[i];
       c[j] = b[j];
     }
     std::stable_sort(c + 1, c + n + 1);
     idx = n;
     for (int j = 1; j <= n; j++) {
       idx = max(idx, j + 1LL);
       bb = 0;
       while (c[j] + c[idx] >= pw[i] && idx > j) {
         idx--;
         bb = 1;
       }
       if (bb == 1) idx++;
       if (c[j] + c[idx] < pw[i] || idx > n)
         le[j] = -1;
       else
         le[j] = idx;
     }
     idx = n;
     for (int j = 1; j <= n; j++) {
       idx = max(idx, j + 1LL);
       while (c[j] + c[idx] >= pw[i + 1] && idx > j + 1) {
         idx--;
       }
       if (c[j] + c[idx] >= pw[i + 1] || idx > n)
         ri[j] = -1;
       else
         ri[j] = idx;
     }
     for (int j = 1; j <= n; j++) {
       if (le[j] != -1 && ri[j] != -1) mp[i] += ri[j] - le[j] + 1;
     }
     idx = n;
     for (int j = 1; j <= n; j++) {
       idx = max(idx, j + 1LL);
       bb = 0;
       while (c[j] + c[idx] >= pw[i + 1] + pw[i] && idx > j) {
         bb = 1;
         idx--;
       }
       if (bb == 1) idx++;
       if (c[j] + c[idx] < pw[i + 1] + pw[i] || idx > n)
         le[j] = -1;
       else
         le[j] = idx;
     }
     idx = n;
     for (int j = 1; j <= n; j++) {
       idx = max(idx, j + 1LL);
       while (c[j] + c[idx] >= pw[i + 2] && idx > j + 1) {
         idx--;
       }
       if (c[j] + c[idx] >= pw[i + 2] || idx > n)
         ri[j] = -1;
       else
         ri[j] = idx;
     }
     for (int j = 1; j <= n; j++) {
       if (le[j] != -1 && ri[j] != -1) mp[i] += ri[j] - le[j] + 1;
     }
   }
   for (int i = 0; i <= 30; i++) {
     if (mp[i] % 2) answ += (1LL << i);
   }
   cout << answ << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[20000], num[20000];
 int dp[400];
 int n, m, t, k, ans, maxm;
 int main() {
   scanf( %d%d , &n, &m);
   maxm = 0;
   ans = 0;
   for (int i = 1; i <= n; i++) {
     scanf( %d , &a[i]);
     num[a[i]]++;
     maxm = max(maxm, num[a[i]]);
   }
   t = min(n, m);
   k = t;
   int temp = 0;
   while (--k) {
     temp += n;
     for (int i = 1; i <= n; i++) a[temp + i] = a[i];
   }
   for (int i = 1; i <= n * t; i++) {
     dp[a[i]]++;
     for (int j = a[i] - 1; j >= 0; j--) dp[a[i]] = max(dp[a[i]], dp[j] + 1);
     ans = max(dp[a[i]], ans);
   }
   ans += maxm * (m - t);
   printf( %d
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 const int inf = 1500000000;
 const int d = 1e9 + 7;
 using namespace std;
 struct triple {
   int a;
   int b;
   int c;
   bool flag;
   triple() { flag = true; }
 };
 int main() {
   int n;
   cin >> n;
   vector<triple> t(n - 1, triple());
   vector<int> adj[n + 1];
   for (int i = 1; i <= n - 2; i++) {
     cin >> t[i].a >> t[i].b >> t[i].c;
     adj[t[i].a].push_back(i);
     adj[t[i].b].push_back(i);
     adj[t[i].c].push_back(i);
   }
   int first;
   triple f;
   for (int i = 1; i <= n; i++) {
     if (adj[i].size() == 1) {
       first = i;
       f = t[adj[i][0]];
       break;
     }
   }
   int second;
   if (adj[f.a].size() == 2) {
     second = f.a;
   }
   if (adj[f.b].size() == 2) {
     second = f.b;
   }
   if (adj[f.c].size() == 2) {
     second = f.c;
   }
   vector<int> perm;
   perm.push_back(first);
   perm.push_back(second);
   while (perm.size() != n) {
     int third;
     for (int i = 0; i < adj[first].size(); i++) {
       int ind = adj[first][i];
       if (t[ind].flag == true) {
         t[ind].flag = false;
         third = (t[ind].a + t[ind].b + t[ind].c) - first - second;
         perm.push_back(third);
         first = second;
         second = third;
         break;
       }
     }
   }
   for (int i = 0; i < perm.size(); i++) cout << perm[i] <<    ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int k;
 string s;
 int main() {
   cin >> k;
   cin >> s;
   int n = s.length();
   for (int i = 0; i < n; ++i) {
     if (s[i] == '?' && s[n - i - 1] == '?') {
       continue;
     } else if (s[i] == '?') {
       s[i] = s[n - i - 1];
     } else if (s[n - i - 1] == '?') {
       s[n - i - 1] = s[i];
     } else if (s[i] != s[n - i - 1]) {
       cout <<  IMPOSSIBLE ;
       return 0;
     }
   }
   bool flag[26];
   memset(flag, 0, sizeof(flag));
   for (int i = 0; i < n; ++i) {
     if (s[i] != '?') {
       flag[s[i] - 'a'] = true;
     }
   }
   int miss = 0;
   for (int c = 0; c < k; ++c) {
     if (!flag[c]) {
       ++miss;
     }
   }
   int have = 0;
   for (int i = 0; i <= n - i - 1; ++i) {
     if (s[i] == '?') {
       ++have;
     }
   }
   if (miss > have) {
     cout <<  IMPOSSIBLE ;
     return 0;
   }
   for (int i = 0; i < n; ++i) {
     if (s[i] == '?') {
       if (have > miss) {
         s[i] = s[n - i - 1] = 'a';
       } else {
         for (int c = 0; c < k; ++c) {
           if (!flag[c]) {
             s[i] = s[n - i - 1] = c + 'a';
             flag[c] = true;
             break;
           }
         }
         --miss;
       }
       --have;
     }
   }
   cout << s << endl;
   return 0;
 }


#include <bits/stdc++.h>
 const long double EPS = 1e-10;
 const long long int MOD = 1000000007ll;
 const long long int mod1 = 1000000009ll;
 const long long int mod2 = 1100000009ll;
 int INF = (int)1e9;
 long long int INFINF = (long long int)1e18;
 int debug = 0;
 long double PI = acos(-1.0);
 using namespace std;
 long long int bit_count(long long int _x) {
   long long int _ret = 0;
   while (_x) {
     if (_x % 2 == 1) _ret++;
     _x /= 2;
   }
   return _ret;
 }
 long long int bit(long long int _mask, long long int _i) {
   return (_mask & (1 << _i)) == 0 ? 0 : 1;
 }
 long long int powermod(long long int _a, long long int _b,
                        long long int _m = MOD) {
   long long int _r = 1;
   while (_b) {
     if (_b % 2 == 1) _r = (_r * _a) % _m;
     _b /= 2;
     _a = (_a * _a) % _m;
   }
   return _r;
 }
 long long int add(long long int a, long long int b, long long int m = MOD) {
   long long int x = a + b;
   while (x >= m) x -= m;
   while (x < 0) x += m;
   return x;
 }
 long long int sub(long long int a, long long int b, long long int m = MOD) {
   long long int x = a - b;
   while (x < 0) x += m;
   while (x >= m) x -= m;
   return x;
 }
 long long int mul(long long int a, long long int b, long long int m = MOD) {
   long long int x = a * 1ll * b;
   x %= m;
   if (x < 0) x += m;
   return x;
 }
 int N, M, K;
 vector<int> G[1010];
 bool spec[1010];
 bool vis[1010];
 int tot, cnt;
 vector<int> sizes;
 void dfs(int u) {
   tot++;
   cnt++;
   vis[u] = true;
   for (int v : G[u]) {
     if (!vis[v]) {
       dfs(v);
     }
   }
 }
 int main() {
   if (0) {
     freopen( input.txt ,  r , stdin);
     debug = 1;
   }
   srand(time(NULL));
   scanf( %d , &N);
   scanf( %d , &M);
   scanf( %d , &K);
   for (int i = 1; i <= K; i++) {
     int x;
     scanf( %d , &x);
     spec[x] = true;
   }
   for (int i = 1; i <= M; i++) {
     int u, v;
     scanf( %d , &u);
     scanf( %d , &v);
     G[u].push_back(v);
     G[v].push_back(u);
   }
   for (int i = 1; i <= N; i++) {
     if (spec[i]) {
       cnt = 0;
       dfs(i);
       sizes.push_back(cnt);
     }
   }
   sort(sizes.begin(), sizes.end());
   reverse(sizes.begin(), sizes.end());
   sizes[0] += (N - tot);
   long long int ans = 0;
   for (int it : sizes) {
     ans += (it * (it - 1)) / 2;
   }
   cout << ans - M;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename Q>
 void inin(Q &x) {
   x = 0;
   int f = 0;
   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();
   x = f ? -x : x;
 }
 int n, a[100010], b[100010];
 long long sum[100010], ans[100010], tot[100010];
 int erfen(int x, int l, int r) {
   int ll = l, rr = r, mid;
   while (ll < rr) {
     mid = (ll + rr) >> 1;
     if (sum[mid] - sum[l - 1] < x)
       ll = mid + 1;
     else
       rr = mid;
   }
   if (ll == n && sum[n] - sum[l - 1] < x) return n + 1;
   return ll;
 }
 int main() {
   inin(n);
   for (int i = (1); i <= (n); i++) inin(a[i]);
   for (int i = (1); i <= (n); i++) inin(b[i]), sum[i] = sum[i - 1] + b[i];
   for (int i = (1); i <= (n); i++) {
     int x = erfen(a[i], i, n);
     tot[x]--;
     ans[x] += a[i] - (sum[x - 1] - sum[i - 1]);
     tot[i] += tot[i - 1] + 1;
     ans[i] += 1LL * b[i] * tot[i];
   }
   for (int i = (1); i <= (n); i++) printf( %lld  , ans[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long mod = 1e9 + 7;
 const long long sze = 1e5 + 2;
 const long long inf = 0x3f3f3f3f;
 void solve() {
   long long n, k;
   cin >> n;
   cin >> k;
   long long swap = k;
   long long last = n;
   long long i = 1;
   bool turn = true;
   while (swap) {
     if (turn) {
       cout << i <<    ;
       i++;
       turn = false;
     } else {
       cout << last <<    ;
       last--;
       turn = true;
     }
     swap--;
   }
   if (k % 2 == 0) {
     while (last >= i) {
       cout << last <<    ;
       last--;
     }
     return;
   }
   while (i <= last) {
     cout << i <<    ;
     i++;
   }
 }
 signed main() {
   long long test = 1;
   while (test--) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int a, b;
   vector<pair<int, int> > v, re;
   scanf( %d %d  , &a, &b);
   v.push_back(make_pair(a, b));
   scanf( %d %d  , &a, &b);
   v.push_back(make_pair(a, b));
   scanf( %d %d  , &a, &b);
   v.push_back(make_pair(a, b));
   sort(v.begin(), v.end());
   pair<int, int> A = v[0], B = v[1], C = v[2];
   int x = A.first, y = A.second;
   re.push_back(make_pair(x, y));
   if (C.second > A.second) {
     int dy = max(min(B.second, C.second), A.second);
     for (int i = A.second + 1; i <= dy; i++) {
       re.push_back(make_pair(x, i));
     }
     y = dy;
     for (int i = A.first + 1; i <= C.first; i++) {
       re.push_back(make_pair(i, y));
     }
     x = C.first;
     for (int i = y + 1; i <= C.second; i++) {
       re.push_back(make_pair(x, i));
     }
   } else {
     int dy = min(max(B.second, C.second), A.second);
     for (int i = A.second - 1; i >= dy; i--) {
       re.push_back(make_pair(x, i));
     }
     y = dy;
     for (int i = A.first + 1; i <= C.first; i++) {
       re.push_back(make_pair(i, y));
     }
     x = C.first;
     for (int i = y - 1; i >= C.second; i--) {
       re.push_back(make_pair(x, i));
     }
   }
   if (B.second > y) {
     for (int i = y + 1; i <= B.second; i++) {
       re.push_back(make_pair(B.first, i));
     }
   } else {
     for (int i = y - 1; i >= B.second; i--) {
       re.push_back(make_pair(B.first, i));
     }
   }
   printf( %d
 , re.size());
   for (int i = 0; i < re.size(); i++) {
     printf( %d %d
 , re[i].first, re[i].second);
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int len, pos;
 void insert(int x) {
   len++;
   if (x <= pos) pos++;
 }
 void erase(int x) {
   if (x >= pos)
     len = x;
   else
     len -= x, pos -= x;
 }
 int main() {
   int m, t;
   scanf( %d%d%d%d , &len, &pos, &m, &t);
   while (t--) {
     int type, x;
     scanf( %d%d , &type, &x);
     if (type == 1)
       insert(x);
     else
       erase(x);
     printf( %d %d
 , len, pos);
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 using ll = long long;
 const int sz = 5e5 + 10;
 int ar[sz];
 int main() {
   int n, ans;
   while (cin >> n) {
     for (int i = 0; i < n; i++) cin >> ar[i];
     sort(ar, ar + n);
     ans = n;
     for (int i = n - 1, j = (n / 2) - 1; j >= 0; j--) {
       if (ar[i] >= ar[j] * 2) {
         ans--;
         i--;
       }
     }
     cout << ans <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int DX[8] = {1, -1, 0, 0, 1, 1, -1, -1};
 const int DY[8] = {0, 0, 1, -1, 1, -1, 1, -1};
 const int intmax = 0x7fffffff;
 map<int, int> mp;
 int main() {
   int n;
   scanf( %d , &n);
   for (int i = 0; i < n; i++) {
     int a;
     scanf( %d , &a);
     mp[a]++;
   }
   map<int, int>::iterator it = mp.begin();
   int deg = (it->second) * 2;
   int last = it->first;
   it++;
   for (; it != mp.end(); it++) {
     if ((it->first) != last + 1) {
       puts( NO );
       return 0;
     }
     if (!deg) {
       puts( NO );
       return 0;
     }
     deg = it->second * 2 - deg;
     if (deg < 0) {
       puts( NO );
       return 0;
     }
     last = it->first;
   }
   if (!deg)
     puts( YES );
   else
     puts( NO );
 }


#include <bits/stdc++.h>
 using namespace std;
 const long double PI = acos(-1);
 const long double eps = 0.0000000001;
 const long long INF = 0x3fffffffffffffff;
 long long a[200005], sum[200005], n, q, x, y;
 long long lowbit(long long now) { return now & -now; }
 void add(long long pos, long long v) {
   while (pos <= n) {
     sum[pos] += v;
     pos += lowbit(pos);
   }
 }
 long long query(long long now) {
   long long res = 0;
   while (now) {
     res += sum[now];
     now ^= lowbit(now);
   }
   return res;
 }
 long long findnext(long long now) {
   long long l = now + 1, r = n + 1, v = query(now);
   while (l < r) {
     long long mid = (l + r) >> 1;
     if (query(mid) < v << 1) {
       l = mid + 1;
     } else {
       r = mid;
     }
   }
   return l;
 }
 signed main() {
   ios::sync_with_stdio(false);
   cin >> n >> q;
   for (long long i = 1; i <= n; ++i) {
     cin >> a[i];
     add(i, a[i]);
   }
   for (long long i = 1; i <= q; ++i) {
     cin >> x >> y;
     add(x, -a[x]);
     a[x] = y;
     add(x, a[x]);
     long long now = 1;
     bool flag = false;
     if (a[1] == 0) {
       cout << 1 << endl;
       continue;
     }
     while (now <= n) {
       now = findnext(now);
       if (now <= n && query(now) == a[now] << 1) {
         cout << now << endl;
         flag = true;
         break;
       }
     }
     if (!flag) {
       cout << -1 << endl;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int n, p, q, b, l;
 long long int gcd(long long int a, long long int c) {
   if (!c) return a;
   return gcd(c, a % c);
 }
 long long int read_ll() {
   char ch;
   long long int num = 0;
   ch = getchar();
   while (!isdigit(ch)) {
     ch = getchar();
   }
   while (isdigit(ch)) {
     num = num * 10 + (long long int)ch - (long long int)'0';
     ch = getchar();
   }
   return num;
 }
 int main() {
   scanf( %ld , &n);
   while (n--) {
     p = read_ll();
     q = read_ll();
     b = read_ll();
     long long int d = gcd(p, q);
     p = p / d;
     q = q / d;
     while (1) {
       b = gcd(q, b);
       if (b == 1) {
         if (q == 1)
           printf( Finite
 );
         else
           printf( Infinite
 );
         break;
       }
       while (q % b == 0) q /= b;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int x, y, z;
   cin >> x >> y >> z;
   int total = x - y;
   if (total < 0) {
     if (total + z < 0) {
       cout <<  - ;
     } else {
       cout <<  ? ;
     }
   }
   if (total > 0) {
     if (total - z > 0) {
       cout <<  + ;
     } else {
       cout <<  ? ;
     }
   }
   if (total == 0) {
     if (total + z == 0) {
       cout <<  0 ;
     } else {
       cout <<  ? ;
     }
   }
   return 0;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 #pragma comment(linker,  /STACK:100000000 )
 int n;
 double l;
 pair<int, int> mas[1010];
 int lst[1010];
 double dp[1010];
 bool check(double r) {
   for (int i = 0; i <= n; i++) lst[i] = -1;
   for (int i = 1; i <= n; i++) dp[i] = -1e15;
   for (int i = 0; i < n; i++) {
     if (lst[i] == -1 && i != 0) continue;
     for (int j = i + 1; j <= n; j++) {
       double p = sqrt(abs(l - (double)(mas[j].first - mas[i].first)));
       if (dp[j] < dp[i] + (double)mas[j].second * r - p) {
         lst[j] = i;
         dp[j] = dp[i] + (double)mas[j].second * r - p;
       }
     }
   }
   if (lst[n] != -1 && dp[n] > -1e-9)
     return true;
   else
     return false;
 }
 int main() {
   scanf( %d %lf , &n, &l);
   for (int i = 1; i <= n; i++) scanf( %d %d , &mas[i].first, &mas[i].second);
   double l = 0, r = 1e9;
   for (int i = 0; i < 100; i++) {
     double av = (l + r) / 2.0;
     if (check(av))
       r = av;
     else
       l = av;
   }
   check(l);
   vector<int> ans;
   int cur = n;
   while (cur != 0) {
     ans.push_back(cur);
     cur = lst[cur];
   }
   for (int i = (int)(ans).size() - 1; i >= 0; i--) printf( %d  , ans[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int m = 31;
 const int maxn = 31;
 long long n, k;
 long long f[maxn + 5], g[maxn + 5];
 void init() {
   f[1] = g[1] = 1;
   for (int i = 2; i <= m; i++) {
     f[i] = (1LL << i * 2 - 2) + f[i - 1];
     g[i] = (1LL << i) - 1 + g[i - 1];
   }
 }
 int main() {
   init();
   long long T;
   cin >> T;
   while (T--) {
     cin >> n >> k;
     if (n > m) {
       printf( YES %I64d
 , n - 1);
       continue;
     }
     int flg = -1;
     for (int i = 0; i <= n; i++) {
       if (k >= g[i] &&
           k <= f[i] + f[n - i] * ((1ll << i) - 1) * ((1ll << i) - 1)) {
         flg = i;
         break;
       }
     }
     if (~flg)
       printf( YES %I64d
 , n - flg);
     else
       printf( NO
 );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string s;
   int n, m;
   cin >> n >> m;
   cin >> s;
   for (int i = 0; i < m; i++) {
     int l, r;
     char c1, c2;
     scanf( %d %d %c %c , &l, &r, &c1, &c2);
     for (int j = l - 1; j < r; j++) {
       if (s[j] == c1) {
         s[j] = c2;
       }
     }
   }
   cout << s << endl;
   cin >> n;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long h, n;
   cin >> h >> n;
   long long l = 1, r = (1LL << h), ret = 0, cur = 0, dir = 0;
   while (cur < h) {
     long long size = (1LL << (h - cur)), mid = (l + r) / 2;
     if (dir == 0) {
       if (n <= mid)
         ++ret, r = mid, dir = 1;
       else
         ret += size, l = mid + 1;
     } else {
       if (n <= mid)
         ret += size, r = mid;
       else
         ++ret, l = mid + 1, dir = 0;
     }
     ++cur;
   }
   cout << ret << endl;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast )
 #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx )
 template <class T = int>
 inline T readInt();
 inline double readDouble();
 inline int readUInt();
 inline int readChar();
 inline void readWord(char *s);
 inline bool readLine(char *s);
 inline bool isEof();
 inline int getChar();
 inline int peekChar();
 inline bool seekEof();
 inline void skipBlanks();
 inline std::string readString();
 template <class T>
 inline void writeInt(T x, char end = 0, int len = -1);
 inline void writeChar(int x);
 inline void writeWord(const char *s);
 inline void writeDouble(double x, int len = 0);
 inline void flush();
 static struct buffer_flusher_t {
   ~buffer_flusher_t() { flush(); }
 } buffer_flusher;
 using namespace std;
 template <typename T>
 inline void pv(const std::vector<T> &vector, char separator = ' ',
                char end = '
') {
   for (int i = 0; i < vector.size(); ++i) {
     if (i != 0) {
       writeChar(separator);
     }
     writeInt(vector[i]);
   }
   writeChar(end);
 }
 inline void init() {
   srand(time(0));
   ios_base::sync_with_stdio(0);
   cin.tie(0);
 }
 static const int buf_size = 4 * 4096;
 static unsigned char buf[buf_size];
 static int buf_len = 0, buf_pos = 0;
 inline string readString() {
   const int MAX = 1e6 + 42;
   static char buf[MAX];
   readWord(buf);
   return string(buf);
 }
 inline bool isEof() {
   if (buf_pos == buf_len) {
     buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
     if (buf_pos == buf_len) return 1;
   }
   return 0;
 }
 inline int getChar() { return isEof() ? -1 : buf[buf_pos++]; }
 inline int peekChar() { return isEof() ? -1 : buf[buf_pos]; }
 inline bool seekEof() {
   int c;
   while ((c = peekChar()) != -1 && c <= 32) buf_pos++;
   return c == -1;
 }
 inline void skipBlanks() {
   while (!isEof() && buf[buf_pos] <= 32U) buf_pos++;
 }
 inline int readChar() {
   int c = getChar();
   while (c != -1 && c <= 32) c = getChar();
   return c;
 }
 inline int readUInt() {
   int c = readChar(), x = 0;
   while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getChar();
   return x;
 }
 template <class T>
 inline T readInt() {
   int second = 1, c = readChar();
   T x = 0;
   if (c == '-')
     second = -1, c = getChar();
   else if (c == '+')
     c = getChar();
   while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getChar();
   return second == 1 ? x : -x;
 }
 inline double readDouble() {
   int second = 1, c = readChar();
   double x = 0;
   if (c == '-') second = -1, c = getChar();
   while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getChar();
   if (c == '.') {
     c = getChar();
     double coef = 1;
     while ('0' <= c && c <= '9') x += (c - '0') * (coef *= 1e-1), c = getChar();
   }
   return second == 1 ? x : -x;
 }
 inline void readWord(char *second) {
   int c = readChar();
   while (c > 32) *second++ = c, c = getChar();
   *second = 0;
 }
 inline bool readLine(char *second) {
   int c = getChar();
   while (c != '
' && c != -1) *second++ = c, c = getChar();
   *second = 0;
   return c != -1;
 }
 static int write_buf_pos = 0;
 static char write_buf[buf_size];
 inline void writeChar(int x) {
   if (write_buf_pos == buf_size)
     fwrite(write_buf, 1, buf_size, stdout), write_buf_pos = 0;
   write_buf[write_buf_pos++] = x;
 }
 inline void flush() {
   if (write_buf_pos)
     fwrite(write_buf, 1, write_buf_pos, stdout), write_buf_pos = 0;
 }
 template <class T>
 inline void writeInt(T x, char end, int output_len) {
   if (x < 0) writeChar('-'), x = -x;
   char second[24];
   int n = 0;
   while (x || !n) second[n++] = '0' + x % 10, x /= 10;
   while (n < output_len) second[n++] = '0';
   while (n--) writeChar(second[n]);
   if (end) writeChar(end);
 }
 inline void writeWord(const char *second) {
   while (*second) writeChar(*second++);
 }
 inline void writeDouble(double x, int output_len) {
   if (x < 0) writeChar('-'), x = -x;
   int t = (int)x;
   writeInt(t), x -= t;
   writeChar('.');
   for (int i = output_len - 1; i > 0; i--) {
     x *= 10;
     t = std::min(9, (int)x);
     writeChar('0' + t), x -= t;
   }
   x *= 10;
   t = std::min(9, (int)(x + 0.5));
   writeChar('0' + t);
 }
 const int MAXN = 3e5 + 42;
 const int MOD = 1e9 + 7;
 void solve() {
   int n = readInt();
   vector<pair<char, int>> oper;
   vector<int> pos;
   for (int i = 0; i < 2 * n; ++i) {
     char c = readChar();
     if (false) cerr <<  c =   << c << endl;
     if (c == '+') {
       oper.push_back({'+', 0});
       pos.push_back(oper.size() - 1);
       continue;
     } else {
       int cost = readInt();
       oper.push_back({'-', cost});
       if (pos.empty()) {
         writeWord( NO
 );
         return;
       }
       int x = pos.back();
       if (false) cerr << x << endl;
       pos.pop_back();
       oper[x].second = cost;
     }
   }
   set<int> have;
   vector<int> ans;
   for (auto [op, c] : oper) {
     if (false) cerr << op << ' ' << c << endl;
     if (op == '+') {
       have.insert(c);
       ans.push_back(c);
     } else {
       auto u = *have.begin();
       if (u != c) {
         writeWord( NO
 );
         return;
       }
       have.erase(have.begin());
     }
   }
   writeWord( YES
 );
   pv(ans);
 }
 signed main() {
   init();
   init();
   solve();
 }


#include <bits/stdc++.h>
 using ull = unsigned long long;
 using ll = long long;
 using ld = long double;
 using namespace std;
 const ll mod = 998244353;
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n, m, k, t;
   cin >> n >> k >> m >> t;
   deque<bool> cur(n);
   cur[k - 1] = 1;
   while (t--) {
     int f, pos;
     cin >> f >> pos;
     if (f == 1) {
       cur.insert(cur.begin() + (pos - 1), 0);
       for (int i = 0; i < ((int)(cur).size()); i++) {
         if (cur[i]) {
           cout << ((int)(cur).size()) <<     << i + 1 <<
 ;
           break;
         }
       }
     } else {
       int loc = -1;
       for (int i = 0; i < ((int)(cur).size()); i++) {
         if (cur[i]) {
           loc = i + 1;
           break;
         }
       }
       if (loc <= pos)
         while (((int)(cur).size()) > pos) cur.pop_back();
       else
         while (pos--) cur.pop_front();
       for (int i = 0; i < ((int)(cur).size()); i++) {
         if (cur[i]) {
           cout << ((int)(cur).size()) <<     << i + 1 <<
 ;
           break;
         }
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int maze[1500][1500];
 pair<int, int> was[1500][1500];
 int n, m;
 int sr, sc;
 inline int rem(int x, int y) {
   x %= y;
   return (x < 0) ? x + y : x;
 }
 bool dfs(int r, int c) {
   int rm = rem(r, n), cm = rem(c, m);
   if (maze[rm][cm] == 1) {
     return was[rm][cm] != pair<int, int>(r, c);
   }
   int rmn, cmn;
   if (maze[rm][cm] == 0) {
     maze[rm][cm] = 1;
     was[rm][cm] = pair<int, int>(r, c);
     rmn = rem(r, n), cmn = rem(c - 1, m);
     if (maze[rmn][cmn] != -1 && dfs(r, c - 1)) return true;
     rmn = rem(r, n), cmn = rem(c + 1, m);
     if (maze[rmn][cmn] != -1 && dfs(r, c + 1)) return true;
     rmn = rem(r + 1, n), cmn = rem(c, m);
     if (maze[rmn][cmn] != -1 && dfs(r + 1, c)) return true;
     rmn = rem(r - 1, n), cmn = rem(c, m);
     if (maze[rmn][cmn] != -1 && dfs(r - 1, c)) return true;
   }
   return false;
 }
 void TheSolution(istream& input, ostream& output) {
   input >> n >> m;
   string s;
   memset(maze, -1, sizeof(maze));
   for (int i = 0; i < n; i++) {
     input >> s;
     for (int j = 0; j < m; j++) {
       if (s[j] == '.') maze[i][j] = 0;
       if (s[j] == 'S') {
         sr = i;
         sc = j;
         maze[i][j] = 0;
       }
       was[i][j] = pair<int, int>(-1000000, -1000000);
     }
   }
   output << (dfs(sr, sc) ?  Yes  :  No );
 }
 int main() {
   TheSolution(cin, cout);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 struct node {
   int cnt;
   node* bit[3];
   node() {
     bit[0] = bit[1] = NULL;
     cnt = 0;
   }
 };
 node* root;
 void Insertt(int x) {
   node* cur = root;
   for (int i = 28; i >= 0; --i) {
     if (cur->bit[(x >> i) & 1] == NULL) cur->bit[(x >> i) & 1] = new node();
     cur = cur->bit[(x >> i) & 1];
     ++(cur->cnt);
   }
 }
 void Erasee(int x) {
   node* cur = root;
   for (int i = 28; i >= 0; --i) {
     --(cur->bit[(x >> i) & 1]->cnt);
     if (cur->bit[(x >> i) & 1]->cnt == 0) {
       cur->bit[(x >> i) & 1] = NULL;
       return;
     } else
       cur = cur->bit[(x >> i) & 1];
   }
 }
 int Query(int p, int l) {
   int res = 0;
   node* cur = root;
   for (int i = 28; i >= 0; --i) {
     if (((l >> i) & 1) == 0) {
       if (cur->bit[(p >> i) & 1] != NULL)
         cur = cur->bit[(p >> i) & 1];
       else
         return res;
     } else {
       if (cur->bit[(p >> i) & 1] != NULL) res += cur->bit[(p >> i) & 1]->cnt;
       if (cur->bit[(1 ^ ((p >> i) & 1))] != NULL)
         cur = cur->bit[(1 ^ ((p >> i) & 1))];
       else
         return res;
     }
   }
   return res;
 }
 int main() {
   scanf( %d , &n);
   root = new node();
   for (int i = 1; i <= n; ++i) {
     int type, p, l;
     scanf( %d%d , &type, &p);
     if (type == 1) Insertt(p);
     if (type == 2) Erasee(p);
     if (type == 3) {
       scanf( %d , &l);
       printf( %d
 , Query(p, l));
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long labs(long long a) { return a < 0 ? (-a) : a; }
 long long max(long long a, long long b) { return a > b ? a : b; }
 long long min(long long a, long long b) { return a < b ? a : b; }
 struct Fenwik {
   vector<long long> t;
   long long n;
   void Init(long long nn) {
     n = nn;
     t.assign(n, 0);
   }
   long long Sum(long long r) {
     long long result = 0;
     for (; r >= 0; r = (r & (r + 1)) - 1) result += t[r];
     return result;
   }
   void Inc(long long i, long long delta) {
     for (; i < n; i = (i | (i + 1))) t[i] += delta;
   }
   long long Sum(long long l, long long r) { return Sum(r) - Sum(l - 1); }
   void Init(const vector<long long>& a) {
     Init(a.size());
     for (int(i) = 0; (i) < (n); (i)++) Inc(i, a[i]);
   }
 };
 vector<Fenwik> f;
 vector<int> g;
 vector<int> gn;
 long long gs;
 map<long long, pair<int, int> > ids;
 long long h, m, n;
 long long gt;
 long long F(long long x) {
   long long pos = (gn[gt] + x) % gs;
   long long sum = 0;
   if (pos < gn[gt]) {
     sum = f[g[gt]].Sum(gn[gt], gs - 1) + f[g[gt]].Sum(0, pos);
   } else {
     sum = f[g[gt]].Sum(gn[gt], pos);
   }
   return x + 1 - sum;
 }
 long long UpperBound(long long l, long long r, long long f) {
   while (l < r) {
     long long m = (l + r) / 2;
     if (!(f < F(m))) {
       l = m + 1;
     } else {
       r = m;
     }
   }
   return l;
 }
 long long res = 0;
 void Add(long long id, long long t) {
   gt = t;
   long long lb = UpperBound(0, gs - 1, 0);
   res += lb;
   long long gg = g[t];
   long long nn = (gn[t] + lb) % gs;
   f[gg].Inc(nn, 1);
   ids[id] = make_pair(gg, nn);
 }
 void Delete(long long id) { f[ids[id].first].Inc(ids[id].second, -1); }
 int main() {
   cin >> h >> m >> n;
   g.resize(h, -1);
   gn.resize(h, 0);
   long long group = 0;
   for (int(i) = 0; (i) < (h); (i)++) {
     if (g[i] != -1) continue;
     g[i] = group;
     gs = 1;
     for (long long j = 1; (i + j * m) % h != i; j++) {
       g[(i + j * m) % h] = group;
       gn[(i + j * m) % h] = j;
       gs = j + 1;
     }
     group++;
   }
   f.resize(group);
   for (int(i) = 0; (i) < (group); (i)++) {
     f[i].Init(gs);
   }
   char c;
   long long id;
   long long t;
   for (int(i) = 0; (i) < (n); (i)++) {
     cin >> c >> id;
     if (c == '+') {
       cin >> t;
       Add(id, t);
     } else {
       Delete(id);
     }
   }
   cout << res << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 1e9 + 7;
 const int MAXN = 1e6 + 7;
 const double EPS = 1e-8;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   long long n, m;
   cin >> n >> m;
   vector<long long> cnt(m, 0);
   long long d = n % m;
   for (long long i = 0; i < m; i++) {
     cnt[i * i % m] += n / m;
     if (i && i <= d) {
       cnt[i * i % m]++;
     }
   }
   long long res = 0;
   for (long long i = 0; i < m; i++) {
     res += cnt[i] * cnt[(m - i) % m];
   }
   cout << res;
 }