#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e6 + 6;
 const long long M = 1e9 + 7;
 const double eps = 1e-7;
 int a[N];
 int Int() {
   int x;
   scanf( %d , &x);
   return x;
 }
 long long Lnt() {
   long long x;
   scanf( %I64d , &x);
   return x;
 }
 long long Bigmod(long long A, long long B, long long C) {
   if (B == 0LL) return 1LL;
   long long x = Bigmod(A, B / 2LL, C);
   x = (x * x) % C;
   if (B % 2 == 1) x = (x * A) % C;
   return x;
 }
 struct mar {
   int i, j, c, d;
 } cr[N];
 bool cmp(mar a, mar b) {
   if (a.i == b.i) return a.j < b.j;
   return a.i < b.i;
 }
 bool Cmp(int a, int b) { return a > b; }
 void print(int n) { printf( %d
 , n); }
 void Print(long long n) { printf( %I64d
 , n); }
 void debug(int n) { printf( %d  , n); }
 int main() {
   int x1 = Int(), x2 = Int(), x3 = Int(), x4 = Int(), x5 = Int(), x6 = Int();
   int c = x3 + x5;
   int d = max(x4, x6);
   if (x1 > x2) swap(x1, x2);
   if ((x1 >= c && x2 >= d) or (x2 >= c && x1 >= d)) return puts( YES ), 0;
   c = x3 + x6;
   d = max(x4, x5);
   if ((x1 >= c && x2 >= d) or (x1 >= d and x2 >= c)) return puts( YES ), 0;
   c = x4 + x5;
   d = max(x3, x6);
   if ((x1 >= c && x2 >= d) or (x1 >= d and x2 >= c)) return puts( YES ), 0;
   c = x4 + x6;
   d = max(x3, x5);
   if ((x1 >= c && x2 >= d) or (x1 >= d and x2 >= c)) return puts( YES ), 0;
   return puts( NO );
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int a[2005];
 long long int cnt[2005];
 long long int b[2005];
 long long int vis[2005];
 vector<long long int> v;
 vector<long long int> vv;
 vector<long long int> ans;
 long long int prime[2005];
 bool pr[2005];
 set<char> st;
 priority_queue<long long int> bob;
 priority_queue<long long int> ali;
 priority_queue<long long int> bth;
 queue<long long int> q;
 map<long long int, long long int> mp;
 long long int taken[105];
 map<long long int, long long int>::iterator it;
 map<long long int, vector<long long int> > ck;
 string ss, tt;
 long long int pos[205];
 long long int afs[205];
 long long int pre[2005];
 long long int aa[2005];
 long long int cs[27];
 long long int ct[27];
 long long int power(long long int k, long long int i) {
   long long int res = 1;
   for (long long int j = 1; j <= i; j++) {
     res = res * k;
   }
   return res;
 }
 int main() {
   long long int n, i, j, k, t, m;
   cin >> t;
   long long int minis;
   long long int res;
   long long int x, y;
   long long int pp;
   string fg;
   long long int l, r;
   long long int h;
   long long int p, q;
   string tt;
   while (t--) {
     v.clear();
     cin >> n;
     cin >> ss >> tt;
     string fg;
     long long int kk = n;
     res = 0;
     for (i = n - 1; i >= 0; i--) {
       if (ss[i] == tt[i]) {
         kk--;
         continue;
       } else {
         if (ss[0] == tt[i]) {
           res = res + 1;
           v.push_back(1);
           if (ss[0] == '0')
             ss[0] = '1';
           else
             ss[0] = '0';
         }
         fg.clear();
         for (j = 0; j <= i; j++) {
           if (ss[j] == '0')
             fg.push_back('1');
           else
             fg.push_back('0');
         }
         reverse(fg.begin(), fg.end());
         res = res + 1;
         v.push_back(kk);
         for (j = 0; j <= i; j++) {
           ss[j] = fg[j];
         }
       }
       kk--;
     }
     cout << res <<    ;
     for (i = 0; i < v.size(); i++) cout << v[i] <<    ;
     cout << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string s;
   cin >> s;
   int n = (int)int(s.size());
   int num = (s[n - 1] - '0') + 10 * (s[n - 2] - '0');
   if (num % 4 == 0)
     cout << 4;
   else
     cout << 0;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void dfs(long long a, long long b, char A, char B) {
   if (a == 1 && b == 1) return;
   if (a < b) swap(a, b), swap(A, B);
   printf( %I64d%c , (a - 1) / b, A);
   dfs(a - (a - 1) / b * b, b, A, B);
 }
 long long gcd(long long a, long long b) {
   if (b == 0) return a;
   return gcd(b, a % b);
 }
 int main() {
   long long a, b;
   cin >> a >> b;
   if (gcd(a, b) != 1) {
     puts( Impossible );
     return 0;
   }
   dfs(a, b, 'A', 'B');
   puts(  );
 }


#include <bits/stdc++.h>
 using namespace std;
 struct node;
 typedef node *Node;
 const int inf = 1000000;
 bool fl = 0;
 struct node {
   Node left, right, link, parent;
   int size, prior, sum, number;
   set<int> all;
   pair<int, int> mmin;
   node(int number) : number(number) {
     left = right = link = parent = NULL;
     prior = rand() + (rand() << 16);
     update();
   }
   int key() {
     int ans = 1;
     if (left) ans += left->size;
     return ans;
   }
   void update() {
     size = 1;
     sum = all.size();
     if (sum == 0)
       mmin = make_pair(inf, inf);
     else
       mmin = make_pair(*all.begin(), number);
     if (left) {
       size += left->size;
       sum += left->sum;
       mmin = min(mmin, left->mmin);
       left->parent = this;
     }
     if (right) {
       size += right->size;
       sum += right->sum;
       mmin = min(mmin, right->mmin);
       right->parent = this;
     }
   }
 };
 void upd_min(Node t) {
   while (t) {
     t->update();
     t = t->parent;
   }
 }
 void add_ppl(Node &t, int ppl) {
   t->all.insert(ppl);
   t->sum++;
   upd_min(t);
 }
 void del_ppl(Node &t, int ppl) {
   t->all.erase(ppl);
   t->sum--;
   upd_min(t);
 }
 Node merge(Node l, Node r) {
   if (!l) return r;
   if (!r) return l;
   if (l->prior > r->prior) {
     l->right = merge(l->right, r);
     l->update();
     return l;
   } else {
     r->left = merge(l, r->left);
     r->update();
     return r;
   }
 }
 void split(Node t, int key, Node &l, Node &r) {
   if (!t) return void(l = r = NULL);
   if (t->key() <= key) {
     split(t->right, key - t->key(), t->right, r);
     l = t;
   } else {
     split(t->left, key, l, t->left);
     r = t;
   }
   t->update();
   t->parent = NULL;
 }
 int get_pos(Node t) {
   vector<char> vc;
   Node v = t;
   while (v->parent) {
     if (v->parent->left == v)
       vc.push_back(0);
     else
       vc.push_back(1);
     v = v->parent;
   }
   reverse(vc.begin(), vc.end());
   int pos = 0;
   for (int i = 0; i < vc.size(); ++i) {
     if (vc[i] == 0)
       v = v->left;
     else
       pos += v->key(), v = v->right;
   }
   pos += v->key();
   return pos;
 }
 Node get_root(Node t) {
   Node ans = NULL;
   while (t) {
     ans = t;
     t = t->parent;
   }
   return ans;
 }
 Node leftmost(Node t) {
   Node ans = NULL;
   while (t) {
     ans = t;
     t = t->left;
   }
   return ans;
 }
 Node rightmost(Node t) {
   Node ans = NULL;
   while (t) {
     ans = t;
     t = t->right;
   }
   return ans;
 }
 void set_link(Node t, Node v) {
   if (!t) return;
   t->link = v;
 }
 void cut_out(Node t) {
   int pos = get_pos(t);
   Node l, r;
   split(get_root(t), pos, l, r);
   set_link(leftmost(r), t);
 }
 void cut_out1(Node t) {
   int pos = get_pos(t);
   Node l, r;
   split(get_root(t), pos - 1, l, r);
   set_link(leftmost(r), rightmost(l));
 }
 void expose(Node v) {
   cut_out(v);
   v = leftmost(get_root(v));
   while (v->link) {
     cut_out(v->link);
     merge(get_root(v->link), get_root(v));
     set_link(v, NULL);
     v = leftmost(get_root(v));
   }
 }
 void link(Node u, Node v) {
   set_link(u, v);
   expose(u);
 }
 void cut(Node u, Node v) {
   expose(v);
   set_link(u, NULL);
 }
 Node lca(Node v, Node u, bool &one_tree) {
   expose(u);
   if (get_root(u) == get_root(v)) {
     one_tree = 1;
     return v;
   }
   expose(v);
   expose(u);
   return leftmost(get_root(v))->link;
 }
 vector<Node> nodes;
 const int maxn = 100000;
 vector<pair<int, int> > add;
 vector<int> g[maxn + 1];
 vector<int> deep;
 void dfs(int v, int p = -1) {
   for (int i = 0; i < g[v].size(); ++i) {
     int tv = g[v][i];
     if (tv == p) continue;
     deep[tv] = deep[v] + 1;
     dfs(tv, v);
   }
 }
 void print_(Node v) {
   if (!v) return;
   print_(v->left);
   cout <<  	  << v->number <<     << (v->link ? v->link->number : -1) << endl;
   print_(v->right);
 }
 void print(Node v) { print_(get_root(v)); }
 void print_all(int n) {
   for (int i = 1; i <= n; ++i) {
     cout << i <<  :
 ;
     print(nodes[i]);
     cout << endl;
   }
 }
 void do_the_thing(Node v, int x) {
   Node t = get_root(v);
   int k = min(x, t->sum);
   cout << k <<    ;
   vector<pair<int, int> > add_after;
   for (int i = 0; i < k; ++i) {
     pair<int, int> cmin = t->mmin;
     cout << cmin.first <<    ;
     del_ppl(nodes[cmin.second], cmin.first);
     add_after.push_back(cmin);
   }
   cout << endl;
   for (int i = 0; i < add_after.size(); ++i) {
     pair<int, int> ct = add_after[i];
     add_ppl(nodes[ct.second], ct.first);
   }
 }
 int main() {
   srand(time(NULL));
   ios_base::sync_with_stdio(0);
   int n, m, q;
   cin >> n >> m >> q;
   nodes.resize(n + 1);
   deep.assign(n + 1, 0);
   for (int i = 1; i <= n; ++i) nodes[i] = new node(i);
   for (int i = 0; i < n - 1; ++i) {
     int a, b;
     cin >> a >> b;
     add.push_back(make_pair(a, b));
     g[a].push_back(b);
     g[b].push_back(a);
   }
   dfs(1);
   for (int i = 0; i < add.size(); ++i) {
     int a = add[i].first;
     int b = add[i].second;
     if (deep[a] < deep[b]) swap(a, b);
     link(nodes[a], nodes[b]);
   }
   for (int i = 1; i <= m; ++i) {
     int city;
     cin >> city;
     add_ppl(nodes[city], i);
   }
   for (int i = 0; i < q; ++i) {
     int v, u, x;
     cin >> v >> u >> x;
     bool one_tree = 0;
     Node t = lca(nodes[v], nodes[u], one_tree);
     if (one_tree) {
       cut_out1(nodes[v]);
       do_the_thing(nodes[v], x);
     } else {
       int split_key = get_root(nodes[v])->size;
       cut_out1(t);
       merge(get_root(nodes[v]), get_root(t));
       do_the_thing(nodes[v], x);
       Node l, r;
       split(get_root(nodes[v]), split_key, l, r);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma comment(linker,  /STACK:100000000000000 )
 using namespace std;
 const long long int INF = 2e18;
 int nex[20000][35];
 int at[35];
 int main() {
   string f, s;
   cin >> f >> s;
   memset(nex, -1, sizeof nex);
   memset(at, -1, sizeof at);
   for (int i = 0; i < f.size(); i++) {
     int he = f[i] - 'a';
     if (at[he] == -1) {
       at[he] = i;
     }
   }
   for (int i = f.size() - 1; i >= 0; i--) {
     for (int j = 0; j < 35; j++) {
       nex[i][j] = at[j];
     }
     at[f[i] - 'a'] = i;
   }
   int now = (f[0] == s[0] ? 0 : nex[0][s[0] - 'a']);
   int cur = 0;
   int cnt = 1;
   while (cur < s.size()) {
     if (now == -1) {
       cout << -1;
       return 0;
     }
     cur++;
     if (cur == s.size()) break;
     int gogo = nex[now][s[cur] - 'a'];
     if (gogo == -1) {
       cout << -1;
       return 0;
     }
     if (gogo <= now) {
       cnt++;
     }
     now = gogo;
   }
   cout << cnt;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, m;
   cin >> n >> m;
   vector<int> dis(n + 1, n), cnt(n + 1, -1);
   while (m--) {
     int a, b;
     cin >> a >> b;
     ++cnt[a];
     dis[a] = min(dis[a], a > b ? b - a + n : b - a);
   }
   for (int i = 1; i <= n; ++i) {
     int res = 0;
     for (int j = 1; j <= n; ++j)
       if (~cnt[j])
         res = max(res, (i > j ? j - i + n : j - i) + cnt[j] * n + dis[j]);
     cout << res << ' ';
   }
   cout << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie();
   string s, mx;
   cin >> s;
   int len = s.length();
   for (int i = 1; i < 1 << len; i++) {
     string foo;
     for (int j = 0; j < len; j++)
       if (i & (1 << j)) foo += s[j];
     bool flag = 1;
     for (int k = 0; k <= foo.length() / 2; k++)
       if (foo[k] != foo[foo.length() - k - 1]) flag = 0;
     if (flag && foo > mx) mx = foo;
   }
   cout << mx;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int size = 300000001;
 bitset<size> gut;
 int main() {
   int l, r;
   cin >> l >> r;
   gut.set();
   for (int i = 3; i * i <= r; i += 2) {
     if (gut[i])
       for (int j = i * i; j <= r; j += (i << 1)) {
         gut[j] = false;
       }
   }
   int rez = 0;
   rez = (l <= 2 && r >= 2);
   for (int i = 5; i <= r; i += 4) {
     if (i >= l && gut[i]) rez++;
   }
   cout << rez << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 3010;
 struct edge {
   int v, next, flag;
 } e[N << 2];
 int head[N], cnt;
 void addedge(int u, int v, int flag) {
   e[cnt].v = v;
   e[cnt].flag = flag;
   e[cnt].next = head[u];
   head[u] = cnt++;
 }
 int sum[N], dp[N];
 void dfs(int u, int pre) {
   sum[u] = 0;
   for (int i = head[u]; i != -1; i = e[i].next) {
     if (e[i].v == pre) continue;
     dfs(e[i].v, u);
     int v = e[i].v;
     sum[u] += sum[v] + e[i].flag;
   }
   dp[u] = sum[u];
   for (int i = head[u]; i != -1; i = e[i].next) {
     if (e[i].v == pre) continue;
     int v = e[i].v;
     dp[u] = min(dp[u], sum[u] - sum[v] + 1 - e[i].flag + dp[v] - e[i].flag);
   }
 }
 int main() {
   memset(head, -1, sizeof(head));
   int n;
   scanf( %d , &n);
   for (int i = 1; i < n; i++) {
     int x, y, z;
     scanf( %d%d , &x, &y);
     addedge(x, y, 0);
     addedge(y, x, 1);
   }
   int ans = 0x7fffffff;
   for (int i = 1; i <= n; i++) {
     dfs(i, -1);
     for (int j = 1; j <= n; j++) {
       ans = min(ans, sum[i] - sum[j] + dp[j]);
     }
   }
   printf( %d
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int t[35], mp[400][400], n;
 void dfs(int step, int x, int y, int dir) {
   if (step > n) return;
   if (dir == 0) {
     dfs(step + 1, x, y + t[step], 1 - dir);
     for (int i = 0; i < 400; i++)
       for (int j = 0; j < 400; j++)
         if (mp[i][j]) {
           mp[i][j] = mp[x * 2 - i][j] = 1;
         }
     for (int i = 1; i <= t[step]; i++) mp[x][y + i] = 1;
   } else {
     dfs(step + 1, x + t[step], y + t[step], 1 - dir);
     int b = y - x;
     for (int i = 0; i < 400; i++)
       for (int j = 0; j < 400; j++)
         if (mp[i][j]) {
           mp[i][j] = mp[j - b][i + b] = 1;
         }
     for (int i = 1; i <= t[step]; i++) {
       mp[x + i][y + i] = 1;
     }
   }
 }
 int main() {
   scanf( %d , &n);
   for (int i = 1; i <= n; i++) scanf( %d , t + i);
   memset(mp, 0, sizeof(mp));
   dfs(1, 200, 199, 0);
   int ans = 0;
   for (int i = 0; i < 400; i++)
     for (int j = 0; j < 400; j++)
       if (mp[i][j]) ans++;
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, m, X, Y, Z, p;
   int x, y;
   while (scanf( %d%d%d%d%d%d , &n, &m, &X, &Y, &Z, &p) != EOF) {
     X %= 4;
     Y %= 2;
     Z %= 4;
     int tn = n;
     int tm = m;
     for (int i = 1; i <= p; i++) {
       n = tn;
       m = tm;
       scanf( %d%d , &x, &y);
       if (X == 1) {
         int xx = x;
         x = y;
         y = n + 1 - xx;
         int nn = n;
         n = m;
         m = nn;
       } else if (X == 2) {
         x = n + 1 - x;
         y = m + 1 - y;
       } else if (X == 3) {
         int xx = x;
         x = m + 1 - y;
         y = xx;
         int nn = n;
         n = m;
         m = nn;
       }
       if (Y == 1) {
         y = m + 1 - y;
       }
       if (Z == 1) {
         int xx = x;
         x = m + 1 - y;
         y = xx;
         int nn = n;
         n = m;
         m = nn;
       } else if (Z == 2) {
         x = n + 1 - x;
         y = m + 1 - y;
       } else if (Z == 3) {
         int xx = x;
         x = y;
         y = n + 1 - xx;
         int nn = n;
         n = m;
         m = nn;
       }
       printf( %d %d
 , x, y);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize(2)
 using namespace std;
 const int INF = 1e9 + 7;
 const int N = 4e5 + 7;
 const int M = 5e6 + 7;
 int vis[M];
 int p[N];
 int qt[N];
 signed main() {
   ios::sync_with_stdio(false);
   int q, x, y;
   cin >> q >> x;
   set<pair<int, int>> vals;
   for (int i = 0; i < x; i++) vals.insert({qt[i], i});
   while (q--) {
     int y;
     cin >> y;
     y %= x;
     vals.erase({qt[y], y});
     vals.insert({++qt[y], y});
     auto k = *vals.begin();
     int nVal = k.first * x + k.second;
     cout << nVal << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   double n, m;
   cin >> n >> m;
   printf( %.10lf
 , n * pow(1.000000011, m));
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, x, l[60], r[60], ans;
 int main() {
   scanf( %d %d , &n, &x);
   for (int i = 1; i <= n; ++i) {
     scanf( %d %d , &l[i], &r[i]);
   }
   for (int i = 1; i <= n; ++i) {
     ans += (l[i] - r[i - 1] - 1) % x;
     ans += r[i] - l[i] + 1;
   }
   printf( %d , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2000 + 7, Mod = 1000000000 + 7;
 inline int Inc(int A, int B) {
   A += B;
   return A >= Mod ? A - Mod : A;
 }
 inline int Dec(int A, int B) {
   A -= B;
   return A < 0 ? A + Mod : A;
 }
 int n, m, A, B, Dpd[N][N], Dpr[N][N], Sumd[N][N], Sumr[N][N], d[N][N], r[N][N];
 char Map[N][N];
 int main() {
   scanf( %d%d , &n, &m);
   for (int i = (1), iLimit = (n); i <= iLimit; (++(i)))
     for (int j = (1), jLimit = (m); j <= jLimit; (++(j))) cin >> Map[i][j];
   if (n == 1 && m == 1) {
     if (Map[1][1] == 'R')
       puts( 0 );
     else
       puts( 1 );
     return 0;
   }
   for (int i = (n), iLimit = (1); i >= iLimit; (--(i)))
     for (int j = (m), jLimit = (1); j >= jLimit; (--(j))) {
       d[i][j] = d[i + 1][j] + (Map[i + 1][j] == 'R');
       r[i][j] = r[i][j + 1] + (Map[i][j + 1] == 'R');
     }
   Dpd[n][m] = Dpr[n][m] = Sumd[n][m] = Sumr[n][m] = (Map[n][m] != 'R');
   for (int i = (n), iLimit = (1); i >= iLimit; (--(i)))
     for (int j = (m), jLimit = (1); j >= jLimit; (--(j)))
       if (i != n || j != m) {
         Dpr[i][j] = Dec(Sumd[i][j + 1], Sumd[i][m - r[i][j] + 1]);
         Dpd[i][j] = Dec(Sumr[i + 1][j], Sumr[n - d[i][j] + 1][j]);
         Sumr[i][j] = Inc(Sumr[i + 1][j], Dpr[i][j]);
         Sumd[i][j] = Inc(Sumd[i][j + 1], Dpd[i][j]);
       }
   printf( %d , Inc(Dpr[1][1], Dpd[1][1]));
   return 0;
 }


#include <bits/stdc++.h>
 #pragma comment(linker,  /STACK:256000000 )
 const long long INF = 1e9;
 const long long mod = 1e9 + 7;
 const long long LINF = 1e14;
 using namespace std;
 long long n, l;
 vector<long long> c;
 vector<int> b;
 int main() {
   std::ios::sync_with_stdio(false);
   cin >> n >> l;
   c.resize(n);
   cin >> c[0];
   for (long long i = (1); i < (n); i++) {
     cin >> c[i];
     c[i] = min(c[i - 1] * 2, c[i]);
   }
   while (l > 0) b.push_back(l % 2), l /= 2;
   while (c.size() < b.size()) c.push_back(c.back() * 2);
   while (b.size() < c.size()) b.push_back(0);
   c.push_back(c.back() * 2);
   n = b.size();
   vector<long long> d(n + 1, LINF);
   d[0] = 0;
   for (long long i = (1); i < (n + 1); i++) {
     d[i] = min(d[i - 1], c[i - 1]);
     if (b[i - 1] == 1) d[i] += c[i - 1];
   }
   cout << min(d[n], c.back()) << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int x;
   cin >> x;
   int k = x % 4;
   if (k == 1) {
     cout << 0 <<   A  << endl;
   } else if (k == 0) {
     cout << 1 <<   A  << endl;
   } else if (k == 2) {
     cout << 1 <<   B  << endl;
   } else {
     cout << 2 <<   A  << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename A, typename B>
 inline void chmin(A &a, B b) {
   if (a > b) a = b;
 }
 template <typename A, typename B>
 inline void chmax(A &a, B b) {
   if (a < b) a = b;
 }
 struct UnionFindTree {
   vector<long long> par, sz;
   UnionFindTree(long long n) {
     par.resize(n);
     sz.resize(n);
     for (long long i = 0; i < n; i++) {
       par[i] = i;
       sz[i] = 1;
     }
   }
   long long find(long long x) {
     return x == par[x] ? x : par[x] = find(par[x]);
   }
   void unite(long long x, long long y) {
     x = find(x);
     y = find(y);
     if (x == y) return;
     if (sz[x] < sz[y]) swap(x, y);
     sz[x] += sz[y];
     par[y] = x;
   }
   bool areSame(long long x, long long y) { return find(x) == find(y); }
   long long size(long long x) { return sz[find(x)]; }
 };
 const long long SIZE = 1000000;
 long long N, M;
 long long A[SIZE], B[SIZE];
 long long cnt[SIZE];
 signed main() {
   scanf( %lld%lld , &N, &M);
   for (long long i = 0; i < (M); i++) scanf( %lld%lld , &A[i], &B[i]);
   vector<long long> vs;
   for (long long i = 0; i < (M); i++) {
     vs.push_back(A[i]);
     vs.push_back(B[i]);
   }
   sort((vs).begin(), (vs).end());
   vs.erase(unique((vs).begin(), (vs).end()), vs.end());
   for (long long i = 0; i < (M); i++) {
     A[i] = lower_bound((vs).begin(), (vs).end(), A[i]) - vs.begin();
     B[i] = lower_bound((vs).begin(), (vs).end(), B[i]) - vs.begin();
   }
   N = vs.size();
   UnionFindTree uf(N);
   for (long long i = 0; i < (M); i++) uf.unite(A[i], B[i]);
   if (uf.size(0) != N) {
     puts( 0 );
     return 0;
   }
   long long luz = 0;
   for (long long i = 0; i < (M); i++) {
     if (A[i] == B[i])
       luz++;
     else {
       cnt[A[i]]++;
       cnt[B[i]]++;
     }
   }
   long long ans = 0;
   ans += luz * (M - luz);
   ans += luz * (luz - 1) / 2;
   for (long long i = 0; i < N; i++) ans += cnt[i] * (cnt[i] - 1) / 2;
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int N = 100000, M = 100000;
 long long int MOD = 1000000007;
 void solve() {
   long long int n;
   cin >> n;
   long long int a[n + 1], b[n + 1];
   for (long long int i = 0; i < n; i++) cin >> a[i];
   for (long long int i = 0; i < n; i++) {
     b[i] = a[i] - i;
     if (b[i] < 0)
       b[i] = 0;
     else if (b[i] % n == 0)
       b[i] = b[i] / n;
     else
       b[i] = (b[i] / n) + 1;
   }
   for (long long int i = 0; i < n; i++) b[i] = i + (n * b[i]);
   long long int min1 = b[0];
   long long int ans = 0;
   for (long long int i = 0; i < n; i++) {
     if (min1 > b[i]) {
       min1 = b[i];
       ans = i;
     }
   }
   cout << ans + 1;
 }
 int main() {
   long long int t = 1;
   while (t--) {
     solve();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int k, m;
 set<int> S;
 int pw[10];
 void rec(int ind, int number, int value) {
   if (ind == 4) {
     if (value > k && value - k < 10000) {
       S.insert(number * 10000 + (value - k));
     }
     if (k >= value && k - value < 10000) {
       S.insert(number * 10000 + (k - value));
     }
     return;
   }
   for (int i = 1; i + ind < 5; i++) {
     for (int j = 0; j < pw[i]; j++) {
       if (ind == 0) {
         rec(ind + i, j, j);
       } else {
         rec(ind + i, number * pw[i] + j, value + j);
         rec(ind + i, number * pw[i] + j, value - j);
         rec(ind + i, number * pw[i] + j, value * j);
       }
     }
   }
 }
 int main() {
   scanf( %d , &k);
   scanf( %d , &m);
   pw[0] = 1;
   for (int i = 1; i <= 6; i++) pw[i] = pw[i - 1] * 10;
   rec(0, 0, 0);
   for (set<int>::iterator it = S.begin(); (it != S.end()) && m; it++, m--) {
     cout << setw(8) << setfill('0') << (*it) << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma comment(linker,  /STACK:102400000,102400000 )
 using namespace std;
 int main() {
   int cases;
   scanf( %d , &cases);
   while (cases--) {
     char str[1009];
     int ret[9];
     scanf( %s , str);
     int num = 0;
     int i;
     int cnt = 0;
     int flag = -1;
     for (i = 0; str[i]; i++) {
       if (str[i] >= 'A' && str[i] <= 'Z') {
         str[i] = str[i] - 'A' + 'a';
       }
       if (str[i] == ':') {
         if (str[i + 1] == ':') {
           flag = cnt;
           i++;
         }
         ret[cnt] = num;
         cnt++;
         num = 0;
       } else if (str[i] >= '0' && str[i] <= '9') {
         num = num * 16 + str[i] - '0';
       } else {
         num = num * 16 + str[i] - 'a' + 10;
       }
     }
     ret[cnt++] = num;
     int k = 0;
     for (int j = 0; j < cnt; j++) {
       printf( %04x , ret[j]);
       k++;
       if (k != 8) {
         putchar(':');
       }
       if (flag == j) {
         for (i = 0; i < 8 - cnt; i++) {
           printf( 0000 );
           k++;
           if (k != 8) {
             putchar(':');
           }
         }
       }
     }
     putchar(10);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long n, i, j, r, mn, mx, x, cnt = 0, a = 1, b = 1;
   string s;
   cin >> n;
   for (i = 0; i < n; i++) {
     cin >> s;
     if (s ==  UR  || s ==  DL )
       a++;
     else if (s ==  UL  || s ==  DR )
       b++;
     else {
       a++, b++;
     }
   }
   cout << a * b << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 2e9;
 int n;
 pair<int, int> p[25];
 int dis[25][25];
 int dp[1 << 24 | 1];
 int pre[1 << 24 | 1];
 int main() {
   scanf( %d%d%d , &p[0].first, &p[0].second, &n);
   for (int i = 1; i <= n; ++i) {
     scanf( %d%d , &p[i].first, &p[i].second);
   }
   for (int i = 0; i <= n; ++i)
     for (int j = i; j <= n; ++j) {
       dis[i][j] = dis[j][i] =
           pow(p[i].first - p[j].first, 2) + pow(p[i].second - p[j].second, 2);
     }
   for (int m = 1; m < (1 << n); ++m) {
     dp[m] = INF;
   }
   dp[0] = 0;
   for (int m = 0; m < (1 << n); ++m) {
     if (dp[m] == INF) continue;
     for (int i = 1; i <= n; ++i) {
       if (m & 1 << (i - 1)) continue;
       for (int j = 1; j <= n; ++j) {
         if (m & 1 << (j - 1)) continue;
         if (dp[m | (1 << i - 1) | (1 << j - 1)] >
             dp[m] + dis[0][i] + dis[i][j] + dis[j][0]) {
           dp[m | (1 << i - 1) | (1 << j - 1)] =
               dp[m] + dis[0][i] + dis[i][j] + dis[j][0];
           pre[m | (1 << i - 1) | (1 << j - 1)] = m;
         }
       }
       break;
     }
   }
   printf( %d
 , dp[(1 << n) - 1]);
   int num = (1 << n) - 1;
   while (num) {
     printf( 0  );
     int t = pre[num] ^ num;
     for (int i = 0; i < n; ++i) {
       if (t & (1 << i)) {
         printf( %d  , i + 1);
       }
     }
     num = pre[num];
   }
   printf( 0
 );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long MAXN = 1000001;
 long long n, l[MAXN], r[MAXN], id[MAXN], K;
 bool cmp(long long i, long long j) {
   return (l[i] / K == l[j] / K)
              ? ((l[i] / K & 1) ? (r[i] < r[j]) : (r[i] > r[j]))
              : (l[i] < l[j]);
 }
 int main() {
   scanf( %lld , &n);
   K = 1000;
   for (long long i = 1; i <= n; i++) scanf( %lld%lld , &l[i], &r[i]), id[i] = i;
   sort(id + 1, id + 1 + n, cmp);
   for (int i = 1; i <= n; i++) printf( %lld  , id[i]);
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long neutral = 0;
 class SegmentTree {
   vector<long long> a;
   int n;

  public:
   SegmentTree(long long* st, long long* en) {
     int sz = int(en - st);
     for (n = 1; n < sz; n <<= 1)
       ;
     a.assign(n << 1, neutral);
     for (int i = 0; i < sz; i++) a[i + n] = st[i];
     for (int i = n + sz - 1; i > 1; i--) a[i >> 1] = ((a[i >> 1]) | (a[i]));
   }
   void update(int i, long long x) {
     a[i += n] = x;
     for (i >>= 1; i; i >>= 1) a[i] = ((a[i << 1]) | (a[1 + (i << 1)]));
   }
   long long query(int l, int r) {
     long long ans = neutral;
     for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
       if (l & 1) ans = ((ans) | (a[l++]));
       if (r & 1) ans = ((ans) | (a[--r]));
     }
     return ans;
   }
 };
 int main() {
   cin.sync_with_stdio(0);
   cin.tie(0);
   cin.exceptions(cin.failbit);
   int n, q, m;
   string s;
   cin >> s;
   n = (int)(s).size();
   long long v[n];
   for (int i = 0; i < (n); ++i) {
     v[i] = 1LL << (s[i] - 'a');
   }
   cin >> q;
   SegmentTree st(v, v + n);
   while (q--) {
     int t;
     cin >> t;
     if (t == 2) {
       int a, b;
       cin >> a >> b;
       long long res = st.query(a - 1, b - 1), c = 0;
       while (res > 0) c++, res -= (res & -res);
       cout << c << endl;
     } else {
       int a;
       char c;
       cin >> a >> c;
       int b = c - 'a';
       st.update(a - 1, 1LL << b);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9;
 const long long INF = 1e15;
 template <class o>
 void qr(o& x) {
   char c = getchar();
   x = 0;
   int f = 1;
   while (!isdigit(c)) {
     if (c == '-') f = -1;
     c = getchar();
   }
   while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
   x *= f;
 }
 template <class o>
 void qw(o x) {
   if (x / 10) qw(x / 10);
   putchar(x % 10 + '0');
 }
 template <class o>
 void pr1(o x) {
   if (x < 0) x = -x, putchar('-');
   qw(x);
   putchar(' ');
 }
 template <class o>
 void pr2(o x) {
   if (x < 0) x = -x, putchar('-');
   qw(x);
   putchar(10);
 }
 template <class o>
 void cmax(o& x, o y) {
   if (x < y) x = y;
 }
 void cmax(int& x, int y) { x = x - y >> 31 ? y : x; }
 template <class o>
 void cmin(o& x, o y) {
   if (x > y) x = y;
 }
 void cmin(int& x, int y) { x = x - y >> 31 ? x : y; }
 int n, m, a[N], p[N], b[N];
 struct BIT {
   int c[N];
   void clear() { memset(c + 1, 0, n * sizeof(int)); }
   void clear(int x) {
     for (; x <= n; x += x & -x) c[x] = 0;
   }
   int ask(int x) {
     int y = 0;
     for (; x; x -= x & -x) y += c[x];
     return y;
   }
   int ask(int l, int r) { return ask(r) - ask(l - 1); }
   void add(int x, int y) {
     for (; x <= n; x += x & -x) c[x] += y;
   }
 } tr;
 struct Q {
   int l, r, y, v, id;
   Q(int _l, int _r, int _y, int _v, int _id = 0)
       : l(_l), r(_r), y(_y), v(_v), id(_id){};
   Q(){};
   bool operator<(Q b) const { return y < b.y; }
 } q[N * 5], t[N * 5];
 int tot, ans[N], id;
 void cdq(int l, int r) {
   if (r - l < 100) {
     int j = 0;
     for (auto i = l; i <= r; i++) {
       if (!q[i].id)
         t[++j] = q[i];
       else
         for (auto k = 1; k <= j; k++) {
           if (q[i].l <= t[k].l && t[k].l <= q[i].r && t[k].y <= q[i].y)
             ans[q[i].id] += q[i].v * t[k].v;
         }
     }
     sort(q + l, q + r + 1);
     return;
   }
   int mid = (l + r) / 2;
   cdq(l, mid);
   cdq(mid + 1, r);
   Q* p = t;
   for (int i = l, j = mid + 1; i <= mid || j <= r;) {
     if (j > r || (i <= mid && q[i].y <= q[j].y)) {
       if (!q[i].id) tr.add(q[i].l, q[i].v);
       *p++ = q[i++];
     } else {
       if (q[j].id) ans[q[j].id] += q[j].v * tr.ask(q[j].l, q[j].r);
       *p++ = q[j++];
     }
   }
   if (r - l > 2333)
     tr.clear();
   else
     for (auto i = l; i <= mid; i++)
       if (!q[i].id) tr.clear(q[i].l);
   for (auto i = r; i >= l; i--) q[i] = *--p;
 }
 void solve() {
   qr(n);
   qr(m);
   for (auto i = 1; i <= n; i++) qr(a[i]), p[a[i]] = i;
   for (auto i = 1; i <= n; i++)
     qr(b[i]), b[i] = p[b[i]], q[++tot] = Q(i, i, b[i], 1);
   int op, x, y, l, r;
   while (m--) {
     qr(op);
     qr(x);
     qr(y);
     if (op == 1) {
       qr(l);
       qr(r);
       ++id;
       q[++tot] = Q(l, r, y, 1, id);
       q[++tot] = Q(l, r, x - 1, -1, id);
     } else {
       q[++tot] = Q(x, x, b[x], -1);
       q[++tot] = Q(y, y, b[y], -1);
       swap(b[x], b[y]);
       q[++tot] = Q(x, x, b[x], 1);
       q[++tot] = Q(y, y, b[y], 1);
     }
   }
   cdq(1, tot);
   for (auto i = 1; i <= id; i++) pr2(ans[i]);
 }
 int main() {
   int T = 1;
   while (T--) solve();
   return 0;
 }


#include <bits/stdc++.h>
 template <class T>
 class _Fenwick {
  private:
   std::vector<T> sum;
   int _size;

  public:
   _Fenwick() { _size = 0; }
   void reset(int n) {
     _size = n;
     sum.clear();
     sum.resize(n + 1);
   }
   void add(int x, T y) {
     while (x <= _size) {
       sum[x] += y;
       x += x & -x;
     }
   }
   T query(int x, T y) {
     T ans = y;
     while (x) {
       ans += sum[x];
       x -= x & -x;
     };
     return ans;
   }
   void build(T *a, int n) {
     reset(n);
     for (int i = 1; i <= n; ++i) add(i, a[i]);
   }
 };
 template <typename T>
 void read(T &x);
 template <typename T>
 void read(T &x, T &y);
 template <typename T>
 void read(T &x, T &y, T &z);
 template <typename T>
 void write(T x);
 template <typename T>
 void writeC(T x);
 template <typename T>
 void writeN(T x);
 template <typename T>
 void _binary(T x, int len);
 long long _qpow(long long a, long long b, long long M);
 long long _inv(long long x, long long M);
 long long ans;
 int n, a[200005], b[200005][31], R[200005][31], L[200005][31], pre[35];
 signed main() {
   read(n);
   for (int i = 1; i <= (n); ++i) read(a[i]);
   ;
   long long ans = (long long)n * (n + 1) / 2;
   for (int i = 1; i <= n; ++i)
     for (int j = 0; j <= 30; ++j) b[i][j] = (a[i] >> j) & 1;
   for (int i = 1; i <= n; ++i) {
     for (int j = 0; j <= 30; ++j) {
       L[i][j] = pre[j];
       if (b[i][j]) pre[j] = i;
     }
   }
   for (int i = 0; i <= 30; ++i) pre[i] = n + 1;
   for (int i = n; i >= 1; i--) {
     for (int j = 0; j <= 30; ++j) {
       R[i][j] = pre[j];
       if (b[i][j]) pre[j] = i;
     }
   }
   std::map<int, int> last;
   for (int i = 1; i <= n; ++i) {
     int l = last[a[i]] + 1, r = n;
     for (int j = 0; j <= 30; ++j)
       if (!b[i][j]) {
         l = std::max(l, L[i][j] + 1);
         r = std::min(r, R[i][j] - 1);
       }
     ans -= (long long)(i - l + 1) * (r - i + 1);
     last[a[i]] = i;
   }
   printf( %lld , ans);
 }
 template <typename T>
 void read(T &x) {
   x = 0;
   char c = getchar();
   T flag = 1;
   while (c < '0' || c > '9') {
     if (c == '-') flag = -flag;
     c = getchar();
   }
   while ('0' <= c && c <= '9') {
     x = x * 10 + c - '0';
     c = getchar();
   }
   x *= flag;
 }
 template <typename T>
 void read(T &x, T &y) {
   read(x);
   read(y);
 }
 template <typename T>
 void read(T &x, T &y, T &z) {
   read(x);
   read(y);
   read(z);
 }
 template <typename T>
 void writeC(T x) {
   if (x < 0) x = ~x + 1, putchar('-');
   if (x > 9) writeC(x / 10);
   putchar(x % 10 + '0');
 }
 template <typename T>
 void write(T x) {
   writeC(x);
   putchar(' ');
 }
 template <typename T>
 void writeN(T x) {
   writeC(x);
   puts(  );
 }
 template <typename T>
 void _binary(T x, int len) {
   for (int i = len - 1; i >= 0; --i) writeC((x >> i) & 1);
 }
 long long _inv(long long x, long long M) {
   assert(x != 0);
   return x == 1 ? 1 : (M - M / x) * _inv(M % x, M) % M;
 }
 long long _qpow(long long a, long long b, long long M) {
   long long res = 1;
   while (b > 0) {
     if (b & 1) res = res * a % M;
     a = a * a % M;
     b >>= 1;
   }
   return res;
 }


#include <bits/stdc++.h>
 using namespace std;
 int num[400005];
 int tot = 0;
 set<int> st;
 int mp[20];
 int freq[20];
 long long push[20][20];
 long long addp[20][1048576];
 vector<int> pos[20];
 long long sum[20];
 int cnt[20];
 long long memo[1048576];
 long long cost(int mask, int ofst, int id) {
   return sum[id] + addp[id][mask] -
          1LL * (ofst + 1 + ofst + cnt[id]) * cnt[id] / 2;
   ;
 }
 long long dp(int i, int mask, int ofst) {
   if (i == tot) return 0;
   if (memo[mask] != -1) return memo[mask];
   long long mn = 1000000000000000000;
   int id;
   for (int j = (0); j <= (tot - 1); j++) {
     if ((mask >> j) & 1) continue;
     long long v =
         dp(i + 1, mask | (1 << j), ofst + cnt[j]) + cost(mask, ofst, j);
     if (v < mn) {
       mn = v;
       id = j;
     }
   }
   return memo[mask] = mn;
 }
 int main() {
   int n;
   scanf( %d , &n);
   for (int i = (1); i <= (n); i++) {
     scanf( %d , &num[i]);
     --num[i];
     st.insert(num[i]);
   }
   for (auto u : st) {
     mp[u] = tot++;
   }
   for (int i = (0); i <= (tot - 1); i++) pos[i].push_back(0);
   for (int i = (1); i <= (n); i++) {
     num[i] = mp[num[i]];
     int t = num[i];
     pos[t].push_back(i);
     cnt[t]++;
     sum[t] += i;
   }
   memset(push, 0, sizeof(push));
   for (int i = (1); i <= (n); i++) {
     freq[num[i]]++;
     for (int j = (0); j <= (tot - 1); j++) {
       push[num[i]][j] += cnt[j] - freq[j];
     }
   }
   memset(addp, 0, sizeof(addp));
   for (int i = (0); i <= (tot - 1); i++) {
     for (int j = (0); j <= ((1 << tot) - 1); j++) {
       if ((j >> i) & 1) continue;
       for (int k = (0); k <= (tot - 1); k++) {
         if (~(j >> k) & 1) continue;
         addp[i][j] += push[i][k];
       }
     }
   }
   memset(memo, -1, sizeof(memo));
   printf( %lld
 , dp(0, 0, 0));
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> adj[200010];
 long long int ans = 0LL;
 int odd = 0, sz[200010] = {};
 void dfs(int cur, int par = -1, int ht = 0) {
   sz[cur]++;
   for (int u : adj[cur]) {
     if (u == par) continue;
     dfs(u, cur, ht ^ 1);
     sz[cur] += sz[u];
   }
   if (ht) odd++;
 }
 int main() {
   int n;
   scanf( %d , &n);
   for (int i = 0; i < n - 1; i++) {
     int x, y;
     scanf( %d %d , &x, &y);
     adj[x].push_back(y);
     adj[y].push_back(x);
   }
   dfs(1);
   for (int i = 1; i <= n; i++) ans += (1LL) * sz[i] * (n - sz[i]);
   ans += (1LL) * odd * (n - odd);
   printf( %lld
 , ans / 2);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> adj[300003];
 vector<int> adje[300003];
 int d[300003];
 int pickd[300003];
 bool vis[300003];
 int n, m;
 int x;
 int dfs1(int u) {
   int ans = 0;
   if (d[u] == -1)
     x = u;
   else if (d[u] == 1)
     ++ans;
   vis[u] = true;
   for (int v : adj[u]) {
     if (!vis[v]) {
       ans += dfs1(v);
     }
   }
   return ans;
 }
 int dfs2(int u) {
   int ans = 0;
   if (d[u] == 1) ++ans;
   vis[u] = true;
   for (int i = 0; i < ((int)(adj[u].size())); ++i) {
     int v = adj[u][i];
     if (!vis[v]) {
       int c = dfs2(v);
       if (c % 2) pickd[adje[u][i]] = 1;
       ans += c;
     }
   }
   return ans;
 }
 bool solve() {
   memset(vis, 0, sizeof(vis));
   for (int i = 1; i <= n; ++i) {
     if (!vis[i]) {
       x = -1;
       int c = dfs1(i);
       if (c % 2) {
         if (x == -1)
           return false;
         else {
           d[x] = 1;
         }
       }
     }
   }
   memset(vis, 0, sizeof(vis));
   memset(pickd, 0, sizeof(pickd));
   for (int i = 1; i <= n; ++i) {
     if (!vis[i]) {
       dfs2(i);
     }
   }
   int k = accumulate(pickd + 1, pickd + m + 1, 0);
   cout << k <<
 ;
   for (int i = 1; i <= m; ++i) {
     if (pickd[i]) {
       cout << i <<
 [(--k) == 0];
     }
   }
   return true;
 }
 int main() {
   ios ::sync_with_stdio(0);
   while (cin >> n >> m) {
     for (int i = 1; i <= n; ++i) {
       cin >> d[i];
     }
     for (int i = 1; i <= m; ++i) {
       int u, v;
       cin >> u >> v;
       adj[u].push_back(v);
       adj[v].push_back(u);
       adje[u].push_back(i);
       adje[v].push_back(i);
     }
     if (!solve()) cout <<  -1
 ;
     for (int i = 1; i <= n; ++i) {
       adj[i].clear();
       adje[i].clear();
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline void read(int &x) {
   char ch = getchar();
   x = 0;
   while (!isdigit(ch)) ch = getchar();
   while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
 }
 int n, m, mx, now, a[5200];
 signed main() {
   read(n), read(m);
   int tmp = 0;
   for (int i = 3; i <= n; ++i) {
     if (i & 1) ++tmp;
     mx += tmp;
   }
   if (m > mx) return puts( -1 ), 0;
   a[1] = 1, a[2] = 2;
   int p = n + 1;
   tmp = 0;
   for (int i = 3; i <= n; ++i) {
     if (i & 1) ++tmp;
     if (now + tmp > m) {
       p = i - 1;
       break;
     }
     now += tmp, a[i] = i;
   }
   m -= now;
   if (m)
     a[p + 1] = p - m * 2 + 1 + p, p += 2;
   else
     ++p;
   for (int i = p; i <= n; ++i) a[i] = 200000000 + i * n;
   for (int i = 1; i <= n; ++i) printf( %d  , a[i]);
   puts(  );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long INF = 1e9 + 7;
 const int N = 5e3 + 10;
 vector<double> vd;
 int flag = 0;
 vector<int> check(double x, int sz) {
   vector<int> v;
   int cur = 0;
   double tot = x;
   while (v.size() < sz) {
     int o = tot / 10;
     cur += o;
     v.push_back(cur);
     tot -= o * 10;
     if (v.size() == sz) break;
     tot += x;
   }
   if (flag) vd.push_back(tot);
   return v;
 }
 double solve(vector<int>& v1, int o = 0) {
   double l = 10 + 1e-10;
   double r = INF;
   int cnt = 200;
   while (cnt--) {
     double mid = (l + r) / 2;
     auto v2 = check(mid, v1.size());
     for (int i = 0; i < v1.size(); i++) {
       if (v1[i] < v2[i]) {
         r = mid;
         break;
       }
       if (v1[i] > v2[i]) {
         l = mid;
         break;
       }
     }
     if (v1 != v2) continue;
     if (o == 0)
       l = mid;
     else
       r = mid;
   }
   return l;
 }
 int main() {
   int n;
   cin >> n;
   vector<int> v(n);
   for (auto& x : v) cin >> x;
   double key1 = solve(v, 0);
   double key2 = solve(v, 1);
   flag = 1;
   if (key1 > key2) swap(key1, key2);
   int ans1 = check(key1, n + 1).back();
   int ans2 = check(key2, n + 1).back();
   if (abs(vd[0] - 10) <= 1e-8) ans1++;
   if (ans1 == ans2)
     puts( unique ), printf( %d
 , ans1), exit(0);
   else
     puts( not unique );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long p[11];
 int main() {
   string s;
   cin >> s;
   int n = s.size();
   p[0] = 1;
   for (int i = 1; i < n; i++) p[i] = p[i - 1] * 9ll;
   long long ans = 1ll;
   for (char c : s) ans *= (long long)(c - '0');
   ans = max(ans, p[n - 1]);
   long long pre = 1;
   for (int i = 1; i <= n; i++) {
     for (long long j = 1; j < s[i - 1] - '0'; j++) {
       ans = max(ans, pre * j * p[n - i]);
     }
     pre *= (long long)(s[i - 1] - '0');
   }
   cout << ans <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   string a;
   cin >> a;
   int sum = 0;
   char b[3] = {'R', 'G', 'B'};
   for (int i = 1; i < n; i++) {
     if (a[i - 1] == a[i] && a[i] == a[i + 1]) {
       for (int j = 0; j < 3; j++) {
         if (b[j] != a[i]) {
           a[i] = b[j];
           break;
         }
       }
       sum++;
     } else if (a[i - 1] == a[i]) {
       for (int j = 0; j < 3; j++) {
         if (b[j] != a[i] && b[j] != a[i + 1]) {
           a[i] = b[j];
           break;
         }
       }
       sum++;
     }
   }
   printf( %d
 , sum);
   for (int i = 0; i < n; i++) {
     printf( %c , a[i]);
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long r, i;
   int flag = 1;
   cin >> r;
   for (i = 1; i <= 1000000; i++) {
     if ((r - i * i - i - 1) > 0 && (r - i * i - i - 1) % (2 * i) == 0) {
       flag = 0;
       break;
     }
   }
   if (flag == 0)
     printf( %lld %lld
 , i, (r - i * i - i - 1) / 2 * i);
   else
     puts( NO );
 }


#include <bits/stdc++.h>
 using namespace std;
 int distance(int x1, int y1, int x2, int y2) {
   return (int)ceil(sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)));
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int n, m, x, q, cnt = 0;
   string t;
   char ch;
   map<char, vector<pair<int, int>>> keys;
   int freq[26] = {0};
   cin >> n >> m >> x;
   for (int i = 1; i <= n; i++) {
     for (int j = 1; j <= m; j++) {
       cin >> ch;
       if (!freq[ch - 'a']) freq[ch - 'a']++;
       keys[ch].push_back(make_pair(i, j));
     }
   }
   if (keys.count('S')) {
     vector<pair<int, int>> shiftCords = keys['S'];
     vector<pair<int, int>> chCords;
     for (int i = 'a'; i <= 'z'; i++) {
       if (keys.count(i)) {
         chCords = keys[i];
         bool validDistance = 0;
         for (int j = 0; j < (int)chCords.size(); j++) {
           for (int k = 0; k < (int)shiftCords.size(); k++) {
             if (distance(chCords[j].first, chCords[j].second,
                          shiftCords[k].first, shiftCords[k].second) <= x) {
               freq[i - 'a']++;
               validDistance = 1;
               break;
             }
           }
           if (validDistance) break;
         }
       }
     }
   }
   cin >> q;
   cin >> t;
   for (int i = 0; i < q; i++) {
     char c = t[i];
     if (islower(c)) {
       if (!freq[c - 'a']) {
         cout << -1 << endl;
         return 0;
       }
     } else {
       c = tolower(c);
       if (!keys.count('S') || !freq[c - 'a']) {
         cout << -1 << endl;
         return 0;
       } else {
         if (freq[c - 'a'] == 1) cnt++;
       }
     }
   }
   cout << cnt << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int k;
   cin >> k;
   int maxP = 0;
   int maxQ = 0;
   for (int i = 0; i < k; i++) {
     int p = 0;
     int q = 0;
     cin >> p;
     cin >> q;
     if (p < q) {
       cout <<  Happy Alex  << endl;
       return 0;
     }
   }
   cout <<  Poor Alex  << endl;
   return 0;
 }


#include <bits/stdc++.h>
 const int maxn = 4e5 + 10;
 const int maxm = 2e5 + 10;
 const int inf = 0x3f3f3f3f;
 const long long mod = 1e9 + 7;
 const double eps = 1e-7;
 using namespace std;
 long long cnt[25][25], dp[1 << 21];
 int n;
 vector<int> col[25];
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin >> n;
   for (int i = 1; i <= n; i++) {
     int x;
     cin >> x;
     col[x].push_back(i);
   }
   for (int i = 1; i <= 20; ++i)
     for (int j = 1; j <= 20; ++j)
       if (i != j) {
         if (!col[i].size() || !col[j].size()) continue;
         int l = 0;
         for (int k = 0; k < col[i].size(); ++k) {
           while (true) {
             if (l == col[j].size() - 1 || col[j][l + 1] > col[i][k]) break;
             l++;
           }
           if (col[j][l] < col[i][k]) cnt[i][j] += l + 1;
         }
       }
   memset(dp, 0x3f, sizeof dp);
   dp[0] = 0;
   for (int S = 0; S < 1 << 20; ++S) {
     for (int i = 0; i < 20; ++i)
       if (!(S >> i & 1)) {
         long long sum(0);
         for (int j = 0; j < 20; ++j)
           if (S >> j & 1) sum += cnt[j + 1][i + 1];
         dp[S | (1 << i)] = min(dp[S | (1 << i)], dp[S] + sum);
       }
   }
   cout << dp[(1 << 20) - 1] << endl;
   return ~~(0 - 0);
 }


#include <bits/stdc++.h>
 using namespace std;
 long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
 long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   long long v;
   cin >> v;
   for (long long i = 0; i < v; i++) {
     vector<long double> arr(250);
     for (long long j = 0; j < 250; j++) cin >> arr[j];
     long double avg1 = 0;
     for (long long j = 0; j < 250; j++) avg1 += arr[j];
     avg1 /= 250.0;
     sort(arr.begin(), arr.end());
     long double v1 = ((arr[249] - arr[0]) * (arr[249] - arr[0])) / 12.0;
     long double v2 = 0;
     for (long long j = 0; j < 250; j++)
       v2 += ((avg1 - arr[j]) * (avg1 - arr[j]));
     v2 /= 250.0;
     long double avg2 = 0;
     if (abs(v2 - avg1) > abs(v1 - v2))
       cout <<  uniform
 ;
     else
       cout <<  poisson
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool check(string new_l, string old_l) {
   int len_1;
   int col_izm;
   col_izm = 0;
   len_1 = new_l.length();
   if (len_1 == old_l.length()) {
     for (int i = 0; i < len_1; i++) {
       if (new_l[i] == old_l[i]) {
         col_izm++;
       } else if (((new_l[i] == '1') || (new_l[i] == 'i') || (new_l[i] == 'l') ||
                   (new_l[i] == 'I') || (new_l[i] == 'L')) &&
                  ((old_l[i] == '1') || (old_l[i] == 'i') || (old_l[i] == 'l') ||
                   (old_l[i] == 'I') || (old_l[i] == 'L'))) {
         col_izm++;
       } else if (((new_l[i] == '0') || (new_l[i] == 'o') ||
                   (new_l[i] == 'O')) &&
                  ((old_l[i] == '0') || (old_l[i] == 'o') ||
                   (old_l[i] == 'O'))) {
         col_izm++;
       } else if (((new_l[i] - old_l[i]) == 32) ||
                  ((new_l[i] - old_l[i]) == -32)) {
         col_izm++;
       } else
         return true;
     }
     if (col_izm == len_1)
       return false;
     else
       return true;
   } else
     return true;
 }
 int main() {
   string n_login, login;
   int col;
   cin >> n_login;
   cin >> col;
   for (int i = 0; i < col; i++) {
     cin >> login;
     if (!check(n_login, login)) {
       cout <<  No  << endl;
       return 0;
     }
   }
   cout <<  Yes  << endl;
   return 0;
 }


#include <bits/stdc++.h>
 int cmp(const void *a, const void *b) { return *((int *)a) - *((int *)b); }
 int maximum(int a, int b) {
   if (a > b) {
     return a;
   } else {
     return b;
   }
 }
 int minimum(int a, int b) {
   if (a < b) {
     return a;
   } else {
     return b;
   }
 }
 int main() {
   int a[2000];
   int p = 0, q = 1, x = 1, i, j;
   int pl, pr, vl, vr, k;
   long long c = 0, d;
   a[0] = 0;
   for (i = 0; i < 9; i++) {
     for (j = p; j < q; j++) {
       a[x++] = a[j] * 10 + 4;
       a[x++] = a[j] * 10 + 7;
     }
     p = q;
     q = x;
   }
   qsort(a, x, sizeof(int), cmp);
   a[x] = 1000000001;
   scanf( %d %d %d %d %d , &pl, &pr, &vl, &vr, &k);
   d = (long long)(pr - pl + 1) * (vr - vl + 1);
   for (i = 1; i <= x - k; i++) {
     if (pl <= a[i] && vr >= a[i + k - 1]) {
       int s1 = minimum(a[i], pr);
       int s2 = maximum(a[i - 1] + 1, pl);
       int t1 = maximum(a[i + k - 1], vl);
       int t2 = minimum(a[i + k] - 1, vr);
       if (s1 - s2 >= 0 && t2 - t1 >= 0) {
         c += (long long)(s1 - s2 + 1) * (t2 - t1 + 1);
       }
     }
     if (vl <= a[i] && pr >= a[i + k - 1]) {
       int s1 = minimum(a[i], vr);
       int s2 = maximum(a[i - 1] + 1, vl);
       int t1 = maximum(a[i + k - 1], pl);
       int t2 = minimum(a[i + k] - 1, pr);
       if (s1 - s2 >= 0 && t2 - t1 >= 0) {
         c += (long long)(s1 - s2 + 1) * (t2 - t1 + 1);
       }
     }
   }
   if (k == 1) {
     for (i = 1; i < x; i++) {
       if (pl <= a[i] && pr >= a[i] && vl <= a[i] && vr >= a[i]) c--;
     }
   }
   printf( %.20lf
 , (double)c / d);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 5100;
 char Map[N][N];
 int dp[N][N];
 int main() {
   int i, j;
   int line, row;
   scanf( %d%d , &line, &row);
   for (i = 0; i < line; i++) scanf( %s , Map[i]);
   for (i = 0; i < line; i++) {
     for (j = row - 1; j >= 0; j--) {
       if (Map[i][j] == '1')
         dp[j][i] = dp[j + 1][i] + 1;
       else
         dp[j][i] = 0;
     }
   }
   int ret = 0;
   for (i = 0; i < row; i++) {
     sort(dp[i], dp[i] + line);
     for (j = 0; j < line; j++) {
       ret = max(ret, (line - j) * dp[i][j]);
     }
   }
   printf( %d
 , ret);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long s[1000005];
 int main(void) {
   int n, d, ans = 0;
   cin >> n >> d >> s[1];
   for (int i = 2; i <= n; ++i) {
     cin >> s[i];
     int cnt = 0;
     if (s[i] <= s[i - 1]) cnt = (s[i - 1] - s[i] + d) / d;
     s[i] += cnt * d;
     ans += cnt;
   }
   return cout << ans << '
', 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast )
 #pragma GCC target( sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx )
 using namespace std;
 const double eps = 0.000001;
 const long double pi = acos(-1);
 const int maxn = 1e7 + 9;
 const int mod = 1e9 + 7;
 const long long MOD = 1e18 + 9;
 const long long INF = 1e18 + 123;
 const int inf = 2e9 + 11;
 const int mxn = 1e6 + 9;
 const int N = 3e5 + 123;
 const int PRI = 555557;
 const int pri = 997;
 int tests = 1;
 int n, m, q;
 int sz[N], pr[N], ans[N];
 bool u[N];
 vector<int> g[N];
 void dfs(int v, int p = 1) {
   sz[v] = 1;
   pr[v] = p;
   for (int to : g[v]) {
     if (to == p) continue;
     dfs(to, v);
     sz[v] += sz[to];
   }
 }
 void dfs_center(int v) {
   u[v] = 1;
   if (sz[v] == 1) {
     ans[v] = v;
     return;
   }
   int mx = g[v].back();
   for (int to : g[v]) {
     if (u[to]) continue;
     dfs_center(to);
     if (sz[mx] < sz[to]) {
       mx = to;
     }
   }
   int c = ans[mx];
   while (sz[v] > sz[c] * 2) {
     c = pr[c];
   }
   ans[v] = c;
 }
 inline void Solve() {
   cin >> n >> q;
   for (int i = 2; i <= n; i++) {
     int x;
     cin >> x;
     g[x].push_back(i);
   }
   dfs(1);
   dfs_center(1);
   while (q--) {
     int x;
     cin >> x;
     cout << ans[x] << '
';
   }
 }
 int main() {
   ios_base::sync_with_stdio(0), cin.tie(0);
   while (tests--) {
     Solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string s;
   cin >> s;
   regex w( WUB );
   cout << regex_replace(s, w,    );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long MOD = int(1e9) + 7;
 int debug = 0;
 const int N = int(2e3) + 5;
 using namespace std;
 int a[N], b[N], p[N];
 int main() {
   int i, j, n, t;
   ios::sync_with_stdio(false);
   cin >> n;
   for (i = 0; i < n; i++) cin >> a[i];
   for (i = 0; i < n; i++) cin >> b[i];
   int ans = 0;
   vector<pair<int, int> > moves;
   for (i = 0; i < n; i++) p[a[i]] = i;
   for (i = 0; i < n; i++) {
     int pos = -1;
     for (j = 0; j < n; j++)
       if (debug)
         cerr <<  j
              <<  :   << j <<   |
              <<  b[j]
              <<  :   << b[j] << endl;
     ;
     for (j = 0; j < n; j++)
       if (p[b[j]] == i) pos = j;
     if (j == i) continue;
     if (debug)
       cerr <<  pos
            <<  :   << pos <<   |
            <<  i
            <<  :   << i << endl;
     ;
     int cur = pos;
     for (j = pos - 1; j >= i; j--) {
       if (p[b[j]] >= cur) {
         ans += cur - j;
         moves.push_back(make_pair(j, cur));
         b[cur] = b[j];
         b[j] = i;
         cur = j;
       }
     }
   }
   cout << ans <<
 ;
   reverse(moves.begin(), moves.end());
   cout << moves.size() <<
 ;
   for (i = 0; i < moves.size(); i++)
     cout << moves[i].second + 1 <<     << moves[i].first + 1 <<
 ;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 3079;
 int r, c, n, k;
 vector<int> nx(maxn, -1), pv(maxn, -1), kth(maxn, -1);
 vector<vector<int> > my(maxn);
 class point {
  public:
   int x, y;
 };
 bool cmp(point& a, point& b) { return (a.y == b.y ? a.x < b.x : a.y < b.y); }
 vector<point> v(maxn);
 long long sum(int i) { return (v[i].y - v[pv[i]].y) * (c + 1 - v[kth[i]].y); }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cin >> r >> c >> n >> k;
   long long ans = 0;
   int m = n + k + 1;
   for (int i = 1; i <= n; i++) cin >> v[i].x >> v[i].y;
   v[0] = {r + 1, 0};
   for (int i = n + 1; i < m; i++) v[i] = {r + 1, c + 1};
   sort(v.begin(), v.begin() + m, cmp);
   for (int i = n + 1; i < m; i++)
     kth[i] = m - 1, pv[i] = i - 1, nx[i] = min(m - 1, i + 1);
   for (int i = m - 1; i >= 0; i--) my[v[i].x].push_back(i);
   for (int x1 = 1; x1 <= r; x1++) {
     int p = 0;
     for (int i = 1; i <= n; i++) {
       if (v[i].x < x1) continue;
       nx[p] = i, pv[i] = p;
       p = i;
     }
     nx[p] = n + 1, pv[n + 1] = p;
     kth[p] = (k == 1 ? p : pv[m - 1]);
     for (int i = p; i >= 0; i = pv[i]) kth[i] = pv[kth[nx[i]]];
     long long cur = 0;
     for (int i = nx[0]; i <= n; i = nx[i]) cur += sum(i);
     for (int x2 = r; x2 >= x1; x2--) {
       ans += cur;
       for (int i : my[x2]) {
         cur -= sum(i);
         for (int j = pv[i], cnt = 0; cnt < k - 1 && j; cnt++, j = pv[j]) {
           cur -= sum(j);
           if (j < i) kth[j] = nx[kth[j]];
           cur += sum(j);
         }
         cur -= sum(nx[i]);
         nx[pv[i]] = nx[i], pv[nx[i]] = pv[i];
         cur += sum(nx[i]);
       }
     }
   }
   cout << ans <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 5e5 + 233;
 const int INF = numeric_limits<int>::max();
 void read(int &x) {
   x = 0;
   char ch = getchar();
   int f = 1;
   while (!isdigit(ch)) (ch == '-' ? f = -1 : 0), ch = getchar();
   while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
   x *= f;
 }
 int f[N][105], g[105];
 int n, K, p, a[N], nw, s[N];
 int x, sum, st[N], tp;
 signed main() {
   memset(g, 0x7f, sizeof(g));
   memset(f, 0x7f, sizeof(f));
   read(n);
   read(K);
   read(p);
   if (p * K > n) {
     for (int i = 1; i <= n; ++i) {
       read(x);
       x %= p;
       a[i] = x;
       sum = (sum + a[i]) % p;
       f[i][1] = sum;
       g[1] = sum;
       for (int j = min(K, i); j >= 2; --j)
         if (i == j) {
           f[i][j] = f[i - 1][j - 1] + x;
           g[j] = x;
         } else {
           int l = f[i - 1][j - 1] + x;
           int r = f[i - 1][j] + x;
           if (g[j] + x >= p) r -= p;
           if (l < r)
             f[i][j] = l, g[j] = x;
           else if (l > r)
             f[i][j] = r, g[j] = (g[j] + x) % p;
           else
             f[i][j] = l, g[j] = max(x, (g[j] + x) % p);
         }
     }
     return printf( %d , f[n][K]), 0;
   }
   for (int i = 1; i <= n; ++i)
     read(a[i]), a[i] %= p, sum += a[i], s[i] = (s[i - 1] + a[i]) % p;
   for (int i = 1; i <= n - 1; ++i) {
     int pos = upper_bound(st + 1, st + 1 + tp, s[i]) - st;
     if (pos > tp) ++tp;
     st[pos] = s[i];
   }
   int pos = upper_bound(st + 1, st + 1 + tp, s[n]) - st;
   if (pos >= K)
     printf( %d , s[n]);
   else
     printf( %d , s[n] + p);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, k;
 int y;
 vector<pair<int, int> > p[3];
 int dp[111][111][3];
 bool check(int x, int t, int y) {
   for (int i = 0; i < p[y].size(); i++) {
     if (x >= p[y][i].first - 2 * t && x <= p[y][i].second - 2 * t) return false;
   }
   return true;
 }
 int go(int x, int t, int y) {
   if (x == n - 1) return true;
   int& res = dp[x][t][y];
   if (res != -1) return res;
   res = 0;
   for (int i = 0; i < p[y].size(); i++) {
     if (x >= p[y][i].first - 2 * t && x <= p[y][i].second - 2 * t ||
         x + 1 >= p[y][i].first - 2 * t && x + 1 <= p[y][i].second - 2 * t)
       return res = false;
   }
   if (check(x + 1, t, y)) res |= go(x + 1, t + 1, y);
   if (check(x + 1, t, min(2, y + 1))) res |= go(x + 1, t + 1, min(2, y + 1));
   if (check(x + 1, t, max(y - 1, 0))) res |= go(x + 1, t + 1, max(y - 1, 0));
   return res;
 }
 void R(string s, int v) {
   int i = 0;
   if (s[0] == 's') {
     y = v;
     s[0] = '.';
   }
   while (i < s.size()) {
     if (s[i] != '.') {
       int l = i;
       int r = l;
       while (i < s.size() && s[i] == s[l]) i++;
       r = i - 1;
       i--;
       p[v].push_back(make_pair(l, r));
       if (i == s.size() - 1) return;
     }
     i++;
   }
 }
 int main() {
   int t;
   cin >> t;
   for (int i = 0; i < t; i++) {
     p[0].clear();
     p[1].clear();
     p[2].clear();
     memset(dp, -1, sizeof(dp));
     cin >> n >> k;
     string s1, s2, s3;
     cin >> s1 >> s2 >> s3;
     R(s1, 0);
     R(s2, 1);
     R(s3, 2);
     if (go(0, 0, y))
       cout <<  YES  << endl;
     else
       cout <<  NO  << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 namespace IO {
 const int sz = 1 << 15;
 char inbuf[sz], outbuf[sz];
 char *pinbuf = inbuf + sz;
 char *poutbuf = outbuf;
 inline char _getchar() {
   if (pinbuf == inbuf + sz) fread(inbuf, 1, sz, stdin), pinbuf = inbuf;
   return *(pinbuf++);
 }
 inline void _putchar(char x) {
   if (poutbuf == outbuf + sz) fwrite(outbuf, 1, sz, stdout), poutbuf = outbuf;
   *(poutbuf++) = x;
 }
 inline void flush() {
   if (poutbuf != outbuf)
     fwrite(outbuf, 1, poutbuf - outbuf, stdout), poutbuf = outbuf;
 }
 }  // namespace IO
 inline int read() {
   int x = 0, p = 1;
   char c = IO::_getchar();
   while (c < '0' || c > '9') {
     if (c == '-') p = -1;
     c = IO::_getchar();
   }
   while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = IO::_getchar();
   return x * p;
 }
 namespace Mymath {
 long long qp(long long x, long long p, long long mod) {
   long long ans = 1;
   while (p) {
     if (p & 1) ans = ans * x % mod;
     x = x * x % mod;
     p >>= 1;
   }
   return ans;
 }
 long long inv(long long x, long long mod) { return qp(x, mod - 2, mod); }
 long long C(long long N, long long K, long long fact[], long long mod) {
   return fact[N] * inv(fact[K], mod) % mod * inv(fact[N - K], mod) % mod;
 }
 template <typename Tp>
 Tp gcd(Tp A, Tp B) {
   if (B == 0) return A;
   return gcd(B, A % B);
 }
 template <typename Tp>
 Tp lcm(Tp A, Tp B) {
   return A * B / gcd(A, B);
 }
 };  // namespace Mymath
 const int Maxn = 705;
 const long long mod = 1e9 + 7;
 int dp[Maxn][3][Maxn][11];
 int tot[11][Maxn];
 char c[Maxn];
 int n;
 void Add(int &x, int y) {
   x += y;
   if (x >= mod) x -= mod;
 }
 int main() {
   scanf( %s , c);
   n = strlen(c);
   for (int i = 0; i <= 9; i++) dp[0][1][0][i] = 1;
   for (int i = 0; i < n; i++) {
     int curv = c[i] - '0';
     for (int j = 0; j <= i; j++) {
       for (int k = 0; k <= 9; k++) {
         if (i)
           for (int l = 0; l < 3; l++) Add(tot[k][j], dp[i][l][j][k]);
         Add(dp[i + 1][1][j + (curv >= k)][k], dp[i][1][j][k]);
         for (int l = 0; l <= 9; l++) {
           if (!i && !l) continue;
           if (l == curv) continue;
           Add(dp[i + 1][(l < curv) ? 0 : 2][j + (l >= k)][k], dp[i][1][j][k]);
         }
         for (int l = 0; l <= 9; l++) {
           if (!i && !l) continue;
           Add(dp[i + 1][0][j + (l >= k)][k], dp[i][0][j][k]);
           Add(dp[i + 1][2][j + (l >= k)][k], dp[i][2][j][k]);
         }
       }
     }
   }
   for (int j = 0; j <= n; j++) {
     for (int k = 0; k <= 9; k++) {
       for (int l = 0; l < 2; l++) Add(tot[k][j], dp[n][l][j][k]);
     }
   }
   for (int i = 0; i <= 9; i++) {
     for (int j = n; j >= 0; j--) {
       Add(tot[i][j], tot[i][j + 1]);
     }
   }
   long long ans = 0;
   int w = 1;
   for (int i = 0; i < n; i++) {
     for (int j = 1; j <= 9; j++) {
       int cnt = tot[j][i + 1] - tot[j + 1][i + 1];
       if (cnt < 0) cnt += mod;
       ans += 1ll * cnt * w % mod * j;
       ans %= mod;
     }
     w = 1ll * w * 10 % mod;
   }
   printf( %I64d
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 std::ostream &operator<<(std::ostream &out, vector<T> &v) {
   for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
     out << v[i] <<    ;
   out <<
 ;
   return out;
 }
 template <typename T>
 std::ostream &operator<<(std::ostream &out, vector<vector<T> > &v) {
   for (size_t i = 0; i < v.size(); ++i) {
     for (size_t j = 0; j < v[i].size(); ++j) {
       out << v[i][j] <<    ;
     }
     out <<
 ;
   }
   return out;
 }
 int main() {
   std::ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   long long n, k;
   cin >> n >> k;
   vector<long long> divisors;
   for (long long i = 1; i * i <= n; ++i) {
     if (n % i == 0) {
       divisors.push_back(i);
       if (n / i != i) {
         divisors.push_back(n / i);
       }
     }
   }
   if (k > divisors.size()) {
     cout <<  -1
 ;
     return 0;
   }
   sort(divisors.begin(), divisors.end());
   cout << divisors[k - 1] <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 100000;
 struct node {
   int n;
   int i;
   node(int n, int i) : n(n), i(i) {}
   node() {}
   bool operator<(const node& n1) const { return n < n1.n; }
   bool is_happy() const {
     int a = n;
     while (a) {
       if (a % 10 != 7 && a % 10 != 4) return false;
       a /= 10;
     }
     return true;
   }
 };
 node nodes[maxn];
 int rev[maxn];
 inline void sw(int i, int j, vector<pair<int, int> >& ans) {
   ans.push_back(pair<int, int>(nodes[i].i, nodes[j].i));
   swap(nodes[i].i, nodes[j].i);
   rev[nodes[i].i] = i;
   rev[nodes[j].i] = j;
 }
 int main() {
   int n;
   scanf( %d , &n);
   bool sorted = true;
   int x = -1, prev;
   for (int i = 0; i < n; i++) {
     prev = x;
     scanf( %d , &x);
     if (prev > x) sorted = false;
     nodes[i] = node(x, i);
   }
   if (sorted) {
     printf( 0
 );
     return 0;
   }
   sort(nodes, nodes + n);
   for (int i = 0; i < n; i++) {
     rev[nodes[i].i] = i;
   }
   int happy = -1;
   for (int i = 0; i < n; i++) {
     if (nodes[i].is_happy()) {
       happy = i;
       break;
     }
   }
   if (happy == -1) {
     printf( -1
 );
     return 0;
   }
   vector<pair<int, int> > ans;
   for (int i = 0; i < n; i++)
     if (i != happy && nodes[i].i != i) {
       if (rev[i] != happy) sw(rev[i], happy, ans);
       sw(happy, i, ans);
     }
   printf( %d
 , ans.size());
   for (int i = 0; i < ans.size(); i++) {
     printf( %d %d
 , ans[i].first + 1, ans[i].second + 1);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int Mod = 1e9 + 7;
 int qpow(long long a, long long b) {
   long long c = 1;
   while (b) {
     if (b & 1) c = c * a % Mod;
     if (b >>= 1) a = a * a % Mod;
   }
   return c;
 }
 int n;
 long long a;
 int p, q;
 int main() {
   scanf( %d , &n);
   bool minus = 1;
   q = 2;
   for (int i = 1; i <= n; i++) {
     scanf( %I64d , &a);
     if (!(a & 1)) minus = 0;
     q = qpow(q, a);
   }
   q = q * 500000004ll % Mod;
   if (minus) {
     p = q - 1;
     if (p < 0) p += Mod;
   } else
     p = q + 1;
   p = p * 333333336ll % Mod;
   printf( %d/%d
 , p, q);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int dx[4] = {-1, 0, 0, +1};
 long long int dy[4] = {0, -1, +1, 0};
 const long long int LINF = 1e18;
 const long long int INF = 1e9;
 const long long int mod = 1e9 + 7;
 long long int power(long long int a, long long int b, long long int m) {
   if (b == 0) return 1;
   if (b == 1) return a % m;
   long long int t = power(a, b / 2, m);
   t = (t * t) % m;
   if (b & 1) t = (t * a) % m;
   return t;
 }
 long long int modInverse(long long int a, long long int m) {
   return power(a, m - 2, m);
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   long long int t;
   cin >> t;
   while (t--) {
     long long int n, ans = 0, i, j;
     string ip;
     cin >> ip;
     long long int sz = ip.size();
     if (ip[0] == '?') {
       if (sz >= 2 && ip[1] == 'a')
         ip[0] = 'b';
       else
         ip[0] = 'a';
     }
     for (long long int i = 1; i <= -1 + ip.size(); i++) {
       if (ip[i] == '?') {
         if (ip[i - 1] == 'a') {
           if ((i + 1) < sz && ip[i + 1] == 'b')
             ip[i] = 'c';
           else
             ip[i] = 'b';
         } else if (ip[i - 1] == 'b') {
           if ((i + 1) < sz && ip[i + 1] == 'a')
             ip[i] = 'c';
           else
             ip[i] = 'a';
         } else if (ip[i - 1] == 'c') {
           if ((i + 1) < sz && ip[i + 1] == 'a')
             ip[i] = 'b';
           else
             ip[i] = 'a';
         } else
           ip[i] = 'a';
       }
     }
     bool poss = true;
     for (long long int i = 1; i <= sz - 1; i++) {
       if (ip[i] == ip[i - 1]) {
         cout << -1 << endl;
         poss = false;
         break;
       }
     }
     if (poss) cout << ip << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, a[105], b[105], c[105], tot, ans;
 char s[105];
 int main() {
   scanf( %d , &n);
   scanf( %s , s + 1);
   for (int i = 1; i <= n; i++) {
     scanf( %d%d , &a[i], &b[i]);
     c[i] = s[i] - '0';
     if (c[i] == 1) tot++;
   }
   ans = tot;
   for (int i = 1; i <= 125; i++) {
     for (int j = 1; j <= n; j++) {
       if (i < b[j]) continue;
       int k = i - b[j];
       if (k % a[j] != 0) continue;
       tot -= c[j];
       c[j] ^= 1;
       tot += c[j];
     }
     ans = max(ans, tot);
   }
   printf( %d
 , ans);
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 0x7fffffff;
 const int oo = 0x3f3f3f3f;
 template <typename T>
 inline void rd(T &x) {
   x = 0;
   int f = 1;
   char CH = getchar();
   while (!isdigit(CH)) {
     if (CH == '-') f = 0;
     CH = getchar();
   }
   while (isdigit(CH)) {
     x = ((x + (x << 2)) << 1) + (CH - 48);
     CH = getchar();
   }
   x = (f == 1) ? x : -x;
   return;
 }
 const int MXN = 2e6;
 int a[MXN], n;
 inline void solve() {
   long long fuck;
   rd(fuck);
   if (fuck > 36) {
     cout << -1;
     return;
   }
   if (fuck == 1)
     cout << 6;
   else if (fuck == 2)
     cout << 8;
   else if (fuck > 2) {
     while (fuck > 2) fuck -= 2, cout << 8;
     if (fuck == 1) cout << 0;
     if (fuck == 2) cout << 8;
   }
 }
 int main() { solve(); }


#include <bits/stdc++.h>
 const int MAXN = 100;
 char s[MAXN + 5];
 int main() {
   int n, p, q;
   scanf( %d%d%d , &n, &p, &q);
   scanf( %s , s);
   for (int i = 0; p * i <= n; i++) {
     if ((n - p * i) % q == 0) {
       int j = (n - p * i) / q;
       printf( %d
 , i + j);
       int pos = 0;
       for (int k = 1; k <= i; k++) {
         for (int l = 1; l <= p; l++) {
           printf( %c , s[pos]);
           pos++;
         }
         puts(  );
       }
       for (int k = 1; k <= j; k++) {
         for (int l = 1; l <= q; l++) {
           printf( %c , s[pos]);
           pos++;
         }
         puts(  );
       }
       return 0;
     }
   }
   puts( -1 );
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 void read(T &x) {
   x = 0;
   bool f = 0;
   char c = getchar();
   for (; !isdigit(c); c = getchar())
     if (c == '-') f = 1;
   for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
   if (f) x = -x;
 }
 long long T, n, m, k;
 int main() {
   read(T);
   while (T--) {
     read(n), read(k);
     k = k * k;
     if ((n & 1) != (k & 1) || k > n)
       puts( NO );
     else
       puts( YES );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mxn(3e5 + 10), mxm(4e5 + 10);
 const long long modl(998244353);
 int nm, n, m, p, t, k;
 int ans;
 int a[mxn], b[mxn], c[mxn];
 int main() {
   ios_base::sync_with_stdio(false);
   cin >> nm;
   while (cin >> n >> m) {
     ans = max(0, n + m - 3) / m + 1;
     cout << ans;
     cout << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e5 + 27;
 vector<vector<int>> g;
 int t, tin[N], tout[N], up[N][20], sz[N], d[N];
 void dfs(int v, int p = 0, int dp = 0) {
   tin[v] = t++;
   d[v] = dp;
   sz[v] = 1;
   up[v][0] = p;
   for (int i = 1; i < 20; i++) up[v][i] = up[up[v][i - 1]][i - 1];
   for (int u : g[v]) {
     if (u != p) {
       dfs(u, v, dp + 1);
       sz[v] += sz[u];
     }
   }
   tout[v] = t++;
 }
 bool is(int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; }
 int get_up(int a, int b) {
   for (int i = 18; i >= 0; i--) {
     if (!is(up[a][i], b)) a = up[a][i];
   }
   return a;
 }
 int lca(int a, int b) {
   if (is(a, b)) return a;
   if (is(b, a)) return b;
   return up[get_up(a, b)][0];
 }
 int main() {
   int n;
   cin >> n;
   g.resize(n + 1);
   for (int i = 1; i < n; i++) {
     int a, b;
     cin >> a >> b;
     g[a].push_back(b);
     g[b].push_back(a);
   }
   tin[0] = -1;
   tout[0] = 3 * N;
   dfs(1);
   int q;
   cin >> q;
   for (int o = 0; o < q; o++) {
     int a, b;
     cin >> a >> b;
     int l = lca(a, b);
     if (a == b)
       cout << n << '
';
     else if (d[b] - d[l] == d[a] - d[l]) {
       a = get_up(a, l);
       b = get_up(b, l);
       cout << n - sz[a] - sz[b] << '
';
     } else {
       if (d[a] < d[b]) swap(a, b);
       int dist = d[a] + d[b] - 2 * d[l];
       if (dist % 2) {
         puts( 0 );
         continue;
       }
       dist /= 2;
       int u = a;
       for (int i = 18; i >= 0; i--) {
         if (d[a] - d[up[u][i]] < dist) u = up[u][i];
       }
       int m = up[u][0];
       cout << sz[m] - sz[u] << '
';
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 string s;
 int l, t, c, a;
 bool vis[26];
 bool ok = false;
 int main() {
   cin >> s;
   l = s.size();
   if (l < 26) {
     cout << -1 << endl;
     return 0;
   }
   for (int i = 0; i < l; ++i) {
     memset(vis, 0, sizeof vis);
     t = c = 0;
     for (int j = i; j < i + 26 && j < l; ++j) {
       if (vis[s[j] - 'A']) break;
       if (s[j] == '?') {
         c++;
         continue;
       }
       vis[s[j] - 'A']++;
       t++;
     }
     if (c + t == 26) {
       a = i;
       ok = true;
       break;
     }
   }
   if (!ok) {
     cout << -1 << endl;
     return 0;
   }
   queue<char> q;
   for (int j = 0; j < 26; ++j) {
     if (!vis[j]) q.push((char)j + 'A');
   }
   for (int i = 0; i < a; ++i)
     if (s[i] != '?')
       cout << s[i];
     else
       cout << 'A';
   for (int i = a; i < 26 + a; ++i)
     if (s[i] != '?')
       cout << s[i];
     else {
       cout << q.front();
       q.pop();
     }
   for (int i = 26 + a; i < l; ++i)
     if (s[i] != '?')
       cout << s[i];
     else
       cout << 'A';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main(void) {
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   long long k;
   cin >> k;
   long long second = 2000 + k;
   long long ar[2000];
   ar[0] = -1;
   for (long long int i = 1; i < 2000; i++) {
     if (second <= 1000000) {
       ar[i] = second;
       second = 0;
     } else {
       ar[i] = 1000000;
       second -= 1000000;
     }
   }
   cout << 2000 << '
';
   for (long long int i = 0; i < 2000; i++)
     cout << ar[i] << ((i == (2000 - 1)) ? '
' : ' ');
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<long long> blame(1002, 0);
 vector<bool> visited(1002, false);
 long long dfs(long long u) {
   if (visited[u]) return u;
   visited[u] = true;
   return dfs(blame[u]);
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   long long n;
   cin >> n;
   for (long long i = 1; i <= n; i++) {
     cin >> blame[i];
   }
   for (long long i = 1; i <= n; i++) {
     cout << dfs(i) <<    ;
     fill(visited.begin(), visited.end(), false);
   }
   return 0;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 int n, m, x[300300], y[300300];
 vector<int> graph[300300];
 int counter, dfs_num[300300], dfs_low[300300], dfs_parent[300300];
 vector<pair<int, int> > bs;
 void bridges(int u) {
   dfs_low[u] = dfs_num[u] = counter++;
   for (int v : graph[u]) {
     if (!dfs_num[v]) {
       dfs_parent[v] = u;
       bridges(v);
       if (dfs_low[v] > dfs_num[u]) bs.push_back(pair<int, int>(u, v));
       dfs_low[u] = min(dfs_low[u], dfs_low[v]);
     } else if (v != dfs_parent[u]) {
       dfs_low[u] = min(dfs_low[u], dfs_num[v]);
     }
   }
 }
 vector<pair<int, int> > ng[300300];
 struct subset {
   int parent, _rank;
 } subsets[300300];
 int Find(int i) {
   if (subsets[i].parent != i) subsets[i].parent = Find(subsets[i].parent);
   return subsets[i].parent;
 }
 void Union(int x, int y) {
   int xroot = Find(x), yroot = Find(y);
   if (subsets[xroot]._rank < subsets[yroot]._rank)
     subsets[xroot].parent = yroot;
   else if (subsets[xroot]._rank > subsets[yroot]._rank)
     subsets[yroot].parent = xroot;
   else {
     subsets[yroot].parent = xroot;
     subsets[xroot]._rank++;
   }
 }
 int maxi = 1, dist[300300];
 void dfs(int u, int p, int d) {
   if (d > dist[maxi]) maxi = u;
   dist[u] = d;
   for (pair<int, int> v : ng[u]) {
     if (v.first != p) {
       dfs(v.first, u, d + v.second);
     }
   }
 }
 int main() {
   scanf( %d %d , &n, &m);
   for (int i = 0; i < m; i++) {
     scanf( %d %d , &x[i], &y[i]);
     graph[x[i]].push_back(y[i]);
     graph[y[i]].push_back(x[i]);
   }
   counter = 1;
   for (int i = 1; i <= n; i++)
     if (!dfs_num[i]) bridges(i);
   for (int i = 1; i <= n; i++) {
     subsets[i].parent = i;
     subsets[i]._rank = 1;
   }
   for (int i = 0; i < bs.size(); i++) {
     Union(bs[i].first, bs[i].second);
     ng[bs[i].first].push_back(pair<int, int>(bs[i].second, 1));
     ng[bs[i].second].push_back(pair<int, int>(bs[i].first, 1));
   }
   for (int i = 0; i < m; i++) {
     if (Find(x[i]) == Find(y[i])) continue;
     Union(x[i], y[i]);
     ng[x[i]].push_back(pair<int, int>(y[i], 0));
     ng[y[i]].push_back(pair<int, int>(x[i], 0));
   }
   dfs(1, 0, 0);
   memset(dist, 0, sizeof dist);
   dfs(maxi, 0, 0);
   printf( %d
 , dist[maxi]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int A[100005], D[100005], n, m, w, L[100005];
 bool go(int h) {
   fill(L, L + n, 0);
   for (int i = 0; i < n; ++i) D[i] = max(h - A[i], 0);
   int pow = 0, cap = m, d;
   for (int i = 0; i < n; ++i) {
     pow -= L[i];
     d = max(D[i] - pow, 0);
     if (d > cap) return false;
     pow += d;
     cap -= d;
     if (i + w < n) L[i + w] += d;
   }
   return true;
 }
 int main() {
   std::ios::sync_with_stdio(false);
   int mini = 2e9;
   cin >> n >> m >> w;
   for (int i = 0; i < n; ++i) {
     cin >> A[i];
     mini = min(mini, A[i]);
   }
   int lo = mini, hi = mini + m + 1, mid;
   while (hi - lo > 1) {
     mid = (hi + lo) >> 1;
     if (go(mid))
       lo = mid;
     else
       hi = mid;
   }
   cout << lo << endl;
 }


#include <bits/stdc++.h>
 int main(void) {
   int t, n, d;
   scanf( %d , &t);
   while (t--) {
     scanf( %d %d , &n, &d);
     int i = 0;
     int flag = 1;
     while (i < n) {
       int te = d / (i + 1);
       te = te * (i + 1) == d ? te : te + 1;
       if (i + te <= n) {
         printf( YES
 );
         flag = 0;
         break;
       }
       i++;
     }
     if (flag) printf( NO
 );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int n, m1 = 0, m2 = 0;
   cin >> n;
   vector<vector<long long> > m(n, vector<long long>(n));
   vector<int> a(n);
   for (int i = 0; i < n; i++)
     for (int j = 0; j < n; j++) cin >> m[i][j];
   for (int i = 1; i < n - 1; i++)
     a[i] = sqrt(m[i][i + 1] * m[i - 1][i] / m[i - 1][i + 1]);
   a[0] = m[0][1] / a[1];
   a[n - 1] = m[0][n - 1] / a[0];
   for (int i = 0; i < n; i++) cout << a[i] << ' ';
   return 0;
 }


#include <bits/stdc++.h>
 const long long maxm = 1e5 + 100;
 long long n, m;
 struct node {
   long long col[maxm * 4], tag[maxm * 4], sum[maxm * 4], siz[maxm * 4];
   inline void pushup(long long o) {
     sum[o] = sum[(o << 1)] + sum[(o << 1) | 1];
     col[o] = col[(o << 1)] == col[(o << 1) | 1] ? col[(o << 1)] : 0;
   }
   inline void pushdown(long long o) {
     if (tag[o]) {
       tag[(o << 1)] += tag[o];
       tag[(o << 1) | 1] += tag[o];
       sum[(o << 1)] += siz[(o << 1)] * tag[o];
       sum[(o << 1) | 1] += siz[(o << 1) | 1] * tag[o];
       col[(o << 1)] = col[(o << 1) | 1] = col[o];
       tag[o] = 0;
     }
   }
   void build(long long o, long long l, long long r) {
     siz[o] = (r - l + 1);
     if (l >= r) {
       col[o] = l;
       return;
     }
     long long mid = (l + r) >> 1;
     build((o << 1), l, mid), build((o << 1) | 1, mid + 1, r);
     pushup(o);
   }
   void cover(long long o, long long l, long long r, long long ql, long long qr,
              long long c) {
     if (ql > r || qr < l) return;
     if ((ql <= l) && (r <= qr) && col[o]) {
       tag[o] += abs(col[o] - c);
       sum[o] += abs(col[o] - c) * siz[o];
       col[o] = c;
       return;
     }
     pushdown(o);
     long long mid = (l + r) >> 1;
     cover((o << 1), l, mid, ql, qr, c),
         cover((o << 1) | 1, mid + 1, r, ql, qr, c);
     pushup(o);
   }
   long long ask(long long o, long long l, long long r, long long ql,
                 long long qr) {
     if (ql > r || qr < l) return 0;
     if ((ql <= l) && (r <= qr)) return sum[o];
     pushdown(o);
     long long mid = (l + r) >> 1;
     return ask((o << 1), l, mid, ql, qr) +
            ask((o << 1) | 1, mid + 1, r, ql, qr);
   }
 } st;
 signed main() {
   scanf( %I64d%I64d , &n, &m);
   st.build(1, 1, n);
   for (long long i = 1; i <= m; i++) {
     long long opt, l, r, x;
     scanf( %I64d%I64d%I64d , &opt, &l, &r);
     if (opt == 1)
       scanf( %I64d , &x), st.cover(1, 1, n, l, r, x);
     else
       printf( %I64d
 , st.ask(1, 1, n, l, r));
   }
   return 0;
 }


#include <bits/stdc++.h>
 template <typename Arg1>
 void ZZ(const char* name, Arg1&& arg1) {
   std::cout << name <<   =   << arg1 << std::endl;
 }
 template <typename Arg1, typename... Args>
 void ZZ(const char* names, Arg1&& arg1, Args&&... args) {
   const char* comma = strchr(names + 1, ',');
   std::cout.write(names, comma - names) <<   =   << arg1;
   ZZ(comma, args...);
 }
 using namespace std;
 long long int to_ll(string& s) {
   long long int i, ret = 0, p = 1;
   for (i = (long long int)s.length() - 1; i >= 0; i--)
     ret += (s[i] - '0') * p, p *= 10LL;
   return ret;
 }
 long long int gcd(long long int x, long long int y) {
   if (y == 0) return x;
   return gcd(y, x % y);
 }
 long long int pwr(long long int base, long long int expo, long long int m) {
   if (base == 0) return 0LL;
   if (expo == 0) return (1LL % m);
   if ((expo & 1) == 0) {
     long long int temp = pwr(base, expo >> 1, m);
     return (temp * temp) % m;
   }
   return ((base % m) * pwr(base, expo - 1, m)) % 1000000007;
 }
 vector<long long int> adj[200009];
 long long int dp_down[200009][5], dp_up[200009][5], sz_down[200009][5],
     sz_up[200009][5], p[200009], dp[200009][5], dp_sz[200009][5];
 bool v_dp_down[200009][5], v_dp_up[200009][5], v_sz_down[200009][5],
     v_sz_up[200009][5];
 long long int n, k;
 void dfs(long long int node, long long int parent) {
   long long int i;
   p[node] = parent;
   for (i = 0; i < adj[node].size(); i++) {
     long long int nxt = adj[node][i];
     if (nxt == parent) continue;
     dfs(nxt, node);
   }
 }
 void dfs_sz_down(long long int node, long long int parent, long long int m) {
   long long int i;
   if (v_sz_down[node][m] == 1) return;
   v_sz_down[node][m] = 1;
   for (i = 0; i < adj[node].size(); i++) {
     long long int nxt = adj[node][i];
     long long int nxt_m = ((m - 1) % k + k) % k;
     if (nxt == parent) continue;
     dfs_sz_down(nxt, node, nxt_m);
     sz_down[node][m] += sz_down[nxt][nxt_m];
     dp_sz[node][nxt_m] += sz_down[nxt][nxt_m];
   }
   if (m == 0) sz_down[node][m]++;
 }
 void dfs_sz_up(long long int node, long long int parent, long long int m) {
   if (v_sz_up[node][m] == 1) return;
   v_sz_up[node][m] = 1;
   if (m == 0) sz_up[node][m]++;
   if (parent == -1) return;
   long long int nxt_m = ((m - 1) % k + k) % k, i;
   dfs_sz_up(parent, p[parent], nxt_m);
   sz_up[node][m] += sz_up[parent][nxt_m];
   sz_up[node][m] += dp_sz[parent][((m - 2) % k + k) % k];
   sz_up[node][m] -= sz_down[node][((m - 2) % k + k) % k];
 }
 void dfs_up(long long int node, long long int parent, long long int m) {
   if (v_dp_up[node][m] == 1) return;
   v_dp_up[node][m] = 1;
   if (parent == -1) return;
   long long int nxt_m = ((m - 1) % k + k) % k, i;
   dfs_up(parent, p[parent], nxt_m);
   dp_up[node][m] += sz_up[parent][nxt_m] + dp_up[parent][nxt_m];
   dp_up[node][m] += dp[parent][((m - 2) % k + k) % k];
   dp_up[node][m] -= (2 * sz_down[node][((m - 2) % k + k) % k] +
                      dp_down[node][((m - 2) % k + k) % k]);
 }
 void dfs_down(long long int node, long long int parent, long long int m) {
   if (v_dp_down[node][m] == 1) return;
   v_dp_down[node][m] = 1;
   long long int i;
   for (i = 0; i < adj[node].size(); i++) {
     long long int nxt = adj[node][i];
     long long int nxt_m = ((m - 1) % k + k) % k;
     if (nxt == parent) continue;
     dfs_down(nxt, node, nxt_m);
     dp_down[node][m] += sz_down[nxt][nxt_m] + dp_down[nxt][nxt_m];
     dp[node][nxt_m] += (2 * sz_down[nxt][nxt_m] + dp_down[nxt][nxt_m]);
   }
 }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   ;
   long long int i, j, x, y, ans = 0;
   cin >> n >> k;
   for (i = 0; i < n - 1; i++) {
     cin >> x >> y;
     adj[x].push_back(y);
     adj[y].push_back(x);
   }
   dfs(1, -1);
   for (i = 1; i <= n; i++)
     for (j = 0; j < k; j++) dfs_sz_down(i, p[i], j);
   for (i = 1; i <= n; i++)
     for (j = 0; j < k; j++) dfs_sz_up(i, p[i], j);
   for (i = 1; i <= n; i++)
     for (j = 0; j < k; j++) dfs_down(i, p[i], j);
   for (i = 1; i <= n; i++)
     for (j = 0; j < k; j++) dfs_up(i, p[i], j);
   for (j = 0; j < k; j++) {
     for (i = 1; i <= n; i++) {
       long long int total = dp_up[i][j] + dp_down[i][j];
       long long int total_sz = sz_down[i][j] + sz_up[i][j];
       if (j == 0) total_sz--;
       long long int val = ((total - total_sz * j) / k);
       if (j != 0) val += total_sz;
       ans += val;
     }
   }
   cout << ans / 2 <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e6 + 4;
 int n, m, a, b, ay[N], by[N], l[N], linkY[N << 1];
 void read() {
   cin >> n >> m >> a >> b;
   for (int i = 1; i <= n; ++i) {
     cin >> ay[i];
   }
   for (int i = 1; i <= m; ++i) {
     cin >> by[i];
   }
   for (int i = 1; i <= m; ++i) {
     cin >> l[i];
   }
 }
 long double dist = 1e18;
 int ida, idb, idTmp;
 long double sqr(long double x) { return x * x; }
 long double euc(long double xa, long double ya, long double xb,
                 long double yb) {
   return sqrt(sqr(xa - xb) + sqr(ya - yb));
 }
 long double f(int ni, int mi) {
   return euc(0, 0, a, ay[ni]) + euc(a, ay[ni], b, by[mi]);
 }
 long double ternarySearch(int num) {
   int l = 1, r = n;
   while (l + 2 < r) {
     int dm = (r - l) / 3;
     int m1 = l + dm;
     int m2 = r - dm;
     long double d1 = f(m1, num);
     long double d2 = f(m2, num);
     if (fabs(d1 - d2) < 1e-9) {
       l = m1;
       r = m2;
     } else if (d1 < d2) {
       r = m2;
     } else {
       l = m1;
     }
   }
   idTmp = l;
   for (int i = l + 1; i <= r; ++i) {
     if (f(i, num) < f(idTmp, num)) {
       idTmp = i;
     }
   }
   return f(idTmp, num);
 }
 void calc() {
   for (int i = 1; i <= m; ++i) {
     long double distTmp = ternarySearch(i) + l[i];
     if (distTmp < dist) {
       dist = distTmp;
       ida = idTmp;
       idb = i;
     }
   }
 }
 void sovle() {
   read();
   calc();
   cout << ida <<     << idb;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cout.tie(0);
   cin.tie(0);
   sovle();
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast,unroll-loops )
 #pragma GCC target( avx,avx2,sse,sse2 )
 using namespace std;
 using vi = vector<long long>;
 mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
 long long powmod(long long a, long long b, long long mod) {
   if (b == 0 || a == 1) {
     if (mod == 1)
       return 0;
     else
       return 1;
   }
   if (b % 2 == 0) {
     long long k = powmod(a, b / 2, mod);
     return (k * k) % mod;
   } else {
     long long k = powmod(a, b / 2, mod);
     return ((k * k) % mod * a) % mod;
   }
 }
 long long gcd(long long a, long long b) {
   if (a == 0) return b;
   if (b == 0) return a;
   if (a > b)
     return gcd(a % b, b);
   else
     return gcd(b % a, a);
 }
 long long prime(long long p) {
   if (p == 1) return 0;
   for (long long i = 2; i * i <= p; i++) {
     if (p % i == 0 && i < p) return i;
   }
   return 1;
 }
 long long inv(long long a, long long mod) { return powmod(a, mod - 2, mod); }
 long long random_modul() {
   uniform_int_distribution<long long> u1(1e9, 2e9);
   long long pepega = u1(rnd);
   while (prime(pepega) != 1) pepega = u1(rnd);
   return pepega;
 }
 template <typename T1>
 void ifmax(T1& max, T1 kek) {
   if (kek > max) max = kek;
   return;
 }
 template <typename T1>
 void ifmin(T1& min, T1 kek) {
   if (kek < min) min = kek;
   return;
 }
 template <typename T1>
 istream& operator>>(std::istream& in, pair<T1, T1>& a) {
   in >> a.first >> a.second;
   return in;
 }
 template <typename T1>
 istream& operator>>(std::istream& in, vector<T1>& a) {
   for (long long i = 0; i < a.size(); i++) in >> a[i];
   return in;
 }
 template <typename T1>
 ostream& operator<<(std::ostream& out, vector<T1>& b) {
   for (long long i = 0; i < b.size(); i++) out << b[i];
   return out;
 }
 template <typename T1>
 void sort(vector<T1>& m) {
   sort(m.begin(), m.end());
 }
 template <typename T1>
 void reverse(vector<T1>& m) {
   reverse(m.begin(), m.end());
 }
 long long mod = 1000000007;
 long long fac[200005];
 long long inv_fac[200005];
 long long co(long long a, long long b) {
   long long ans = 1;
   ans *= fac[b];
   ans *= inv_fac[b - a];
   ans %= mod;
   ans *= inv_fac[a];
   return ans % mod;
 }
 void solve() {
   string a, b;
   cin >> a >> b;
   long long s1 = a.size();
   long long s2 = b.size();
   string ans;
   for (long long i = 1; i <= s1; i++) {
     for (long long j = 1; j <= s2; j++) {
       string cur =   ;
       for (long long k = 0; k < i; k++) cur += a[k];
       for (long long k = 0; k < j; k++) cur += b[k];
       if (i == 1 && i == j)
         ans = cur;
       else
         ans = min(ans, cur);
     }
   }
   cout << ans;
   return;
 }
 signed main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   cout << fixed << setprecision(10);
   long long multitest = 0;
   long long tututu;
   tututu = 1;
   long long combinatorics = 0;
   if (combinatorics) {
     fac[1] = 1;
     fac[0] = 1;
     for (long long i = 2; i < 200005; i++) {
       fac[i] = fac[i - 1] * i;
       fac[i] %= mod;
     }
     for (long long i = 0; i < 200005; i++) {
       inv_fac[i] = inv(fac[i], mod);
     }
   }
   if (multitest) cin >> tututu;
   for (long long qwerty = 0; qwerty < tututu; qwerty++) solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long double n;
   cin >> n;
   long long m = sqrt(n);
   if (m * m == n) {
     cout << 2 * m;
   } else if ((long long)m * (long long)(m + 1) >= n) {
     cout << (long long)m + (long long)(m + 1);
   } else
     cout << (long long)2 * (long long)(m + 1);
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int t, i, oo = 0, oz = 0, zo = 0, zz = 0;
   char s1[2000005], s2[2000005];
   cin >> t;
   cin >> s1;
   cin >> s2;
   t = 2 * t;
   for (i = 0; i < t; i++) {
     if (s1[i] == '1' && s2[i] == '1')
       oo++;
     else if (s1[i] == '1' && s2[i] == '0')
       oz++;
     else if (s1[i] == '0' && s2[i] == '1')
       zo++;
     else
       zz++;
   }
   if (oo % 2 == 0) {
     if (oz > zo)
       cout <<  First ;
     else if (oz + 1 == zo || oz == zo)
       cout <<  Draw ;
     else
       cout <<  Second ;
   } else {
     if (oz >= zo)
       cout <<  First ;
     else if (oz + 1 == zo || oz + 2 == zo)
       cout <<  Draw ;
     else
       cout <<  Second ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m, l, r, q;
 map<pair<int, int>, int> vi;
 int V[100005 << 2], ly[100005 << 2];
 void push_down(int o) {
   if (ly[o]) {
     ly[o << 1] |= ly[o];
     ly[o << 1 | 1] |= ly[o];
     V[o << 1] |= ly[o];
     V[o << 1 | 1] |= ly[o];
     ly[o] = 0;
   }
 }
 void push_up(int o) { V[o] = V[o << 1] & V[o << 1 | 1]; }
 void ud(int o, int l, int r, int L, int R, int x) {
   int mid = (l + r) / 2;
   if (L <= l && r <= R) {
     V[o] |= x;
     ly[o] |= x;
     return;
   }
   push_down(o);
   if (L <= mid) ud(o << 1, l, mid, L, R, x);
   if (R > mid) ud(o << 1 | 1, mid + 1, r, L, R, x);
   push_up(o);
 }
 int qy(int o, int l, int r, int L, int R) {
   int mid = (l + r) / 2;
   if (L <= l && r <= R) return V[o];
   push_down(o);
   int ans = (1 << 30) - 1;
   if (L <= mid) ans &= qy(o << 1, l, mid, L, R);
   if (R > mid) ans &= qy(o << 1 | 1, mid + 1, r, L, R);
   push_up(o);
   return ans;
 }
 int main() {
   cin >> n >> m;
   int ok = 1;
   for (int i = 0; i < m; i++) {
     scanf( %d%d%d , &l, &r, &q);
     int tp = qy(1, 1, n, l, r);
     if (vi[make_pair(l, r)]) {
       if (tp != q) {
         ok = 0;
       }
     }
     if (!ok) continue;
     vi[make_pair(l, r)] = 1;
     if ((tp & q) == tp)
       ud(1, 1, n, l, r, q);
     else
       ok = 0;
   }
   if (!ok) {
     puts( NO );
     return 0;
   }
   printf( YES
 );
   for (int i = 1; i <= n; i++) printf( %d  , qy(1, 1, n, i, i));
 }


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


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e5 + 10;
 int main() {
   list<int> a;
   int n;
   scanf( %d , &n);
   for (int i = 1; i <= n; i++) {
     int x;
     scanf( %d , &x);
     a.push_back(x);
   }
   for (auto t = a.begin(); t != a.end(); t++) {
     auto s = t;
     s--;
     if (t == a.begin()) continue;
     while (true) {
       if (*t == *s) {
         *t = *t + 1;
         t = a.erase(s);
         if (t == a.begin()) break;
         s = t, s--;
       } else
         break;
     }
   }
   printf( %d
 , a.size());
   for (auto t : a) printf( %d  , t);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long MOD = 1e9 + 7;
 template <typename T>
 void chmin(T &a, T b) {
   if (a > b) a = b;
 }
 template <typename T>
 void chmax(T &a, T b) {
   if (a < b) a = b;
 }
 template <typename T>
 void add(T &a, T b) {
   a += b;
   if (a < 0) a += MOD;
   if (a >= MOD) a -= MOD;
 }
 void FastIn(int &T) {
   char C;
   bool F = 0;
   for (; C = getchar(), C < '0' || C > '9';)
     if (C == '-') F = 1;
   for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
     ;
   F && (T = -T);
 }
 int in() {
   int x;
   scanf( %d , &x);
   return x;
 }
 long long lin() {
   long long x;
   scanf( %lld , &x);
   return x;
 }
 double din() {
   double x;
   scanf( %lf , &x);
   return x;
 }
 long long p2[63];
 void initP2() {
   p2[0] = 1;
   for (int i = (1); i <= (62); ++i) {
     p2[i] = p2[i - 1] * 2;
   }
 }
 int countBitsBaseB(long long n, long long b) {
   if (n == 0) return 1;
   int ret = 0;
   while (n) {
     ret++;
     n /= b;
   }
   return ret;
 }
 int count1(long long n) {
   int ret = 0;
   while (n) {
     ret += n & 1;
     n >>= 1;
   }
   return ret;
 }
 long long c[1024][1024] = {0};
 void initC() {
   for (int i = 0; i < (1024); ++i) {
     for (int j = 0; j < (i + 1); ++j) {
       if (j == 0 || j == i) {
         c[i][j] = 1;
       } else {
         c[i][j] = c[i - 1][j - 1];
         add(c[i][j], c[i - 1][j]);
       }
     }
   }
 }
 bool IsPrime(int n) {
   if (n < 2) return false;
   for (int i = 2; i * i <= n; i++) {
     if (n % i == 0) return false;
   }
   return true;
 }
 void init() {
   initP2();
   initC();
 }
 const unsigned INVALID = 2000000001;
 struct CMD {
   int cmd, x, y;
 } q[(int)(2e5 + 10)];
 struct DSU {
   int f[(int)(2e5 + 10)];
   int h[(int)(2e5 + 10)];
   int *addr[(int)(2e5 + 10) << 2];
   int val[(int)(2e5 + 10) << 2];
   int stkSize = 0;
   void init(int n) {
     for (int i = (1); i <= (n); ++i) {
       f[i] = i;
       h[i] = 1;
     }
     stkSize = 0;
   }
   int find(int x) { return x == f[x] ? x : find(f[x]); }
   void merge(int x, int y) {
     x = find(x);
     y = find(y);
     if (x == y) {
       return;
     }
     if (h[x] > h[y]) swap(x, y);
     addr[stkSize] = &f[x];
     val[stkSize++] = f[x];
     f[x] = y;
     if (h[x] == h[y]) {
       addr[stkSize] = &h[y];
       val[stkSize++] = h[y];
       h[y]++;
     }
   }
   void mergeFast(int x, int y) {
     x = find(x);
     y = find(y);
     if (x == y) {
       return;
     }
     if (h[x] > h[y]) swap(x, y);
     f[x] = y;
     if (h[x] == h[y]) {
       h[y]++;
     }
   }
   void undo(int size) {
     while (stkSize > size) {
       stkSize--;
       *addr[stkSize] = val[stkSize];
     }
   }

  private:
 } dsu;
 const int BLOCK = 5000;
 int last[(int)(2e5 + 10)];
 pair<int, int> GetEdge(int x, int y, int der, int n) {
   x += der - 1;
   if (x >= n) x -= n;
   y += der - 1;
   if (y >= n) y -= n;
   if (x > y) swap(x, y);
   return make_pair(x + 1, y + 1);
 }
 void Switch(const pair<int, int> &edge, set<pair<int, int>> &edges) {
   if (edges.find(edge) != edges.end()) {
     edges.erase(edge);
   } else {
     edges.insert(edge);
   }
 }
 int main() {
   init();
   int n = in(), m = in();
   for (int i = (1); i <= (m); ++i) {
     q[i].cmd = in();
     q[i].x = in();
     q[i].y = in();
   }
   last[0] = 0;
   for (int start = 1; start <= m; start += BLOCK) {
     int end = start + BLOCK - 1;
     if (end > m) {
       end = m;
     }
     set<pair<int, int>> nowEdges;
     nowEdges.clear();
     for (int i0 = (start); i0 <= (end); ++i0) {
       nowEdges.insert(GetEdge(q[i0].x, q[i0].y, 0, n));
       nowEdges.insert(GetEdge(q[i0].x, q[i0].y, 1, n));
     }
     set<pair<int, int>> possible;
     possible.clear();
     set<pair<int, int>> impossible;
     impossible.clear();
     for (int i1 = (1); i1 <= (start - 1); ++i1) {
       if (q[i1].cmd == 2) {
         continue;
       }
       auto edge0 = GetEdge(q[i1].x, q[i1].y, last[i1 - 1], n);
       if (nowEdges.find(edge0) == nowEdges.end()) {
         Switch(edge0, impossible);
       } else {
         Switch(edge0, possible);
       }
     }
     dsu.init(n);
     for (auto edge1 : impossible) {
       dsu.mergeFast(edge1.first, edge1.second);
     }
     for (int i2 = (start); i2 <= (end); ++i2) {
       if (q[i2].cmd == 1) {
         last[i2] = last[i2 - 1];
         Switch(GetEdge(q[i2].x, q[i2].y, last[i2 - 1], n), possible);
         continue;
       } else {
         const int top = dsu.stkSize;
         for (auto edge1 : possible) {
           dsu.merge(edge1.first, edge1.second);
         }
         auto queryEdge = GetEdge(q[i2].x, q[i2].y, last[i2 - 1], n);
         last[i2] = dsu.find(queryEdge.first) == dsu.find(queryEdge.second);
         putchar('0' + last[i2]);
         dsu.undo(top);
       }
     }
   }
   cout << endl;
   return 0;
 }