#include <bits/stdc++.h>
 const int N = 100100;
 const long long mod = 1e9 + 7;
 using namespace std;
 int n, Xa, Ya, Xb, Yb;
 int Smallest(int a, int b, int c, int d) {
   int min_ = a;
   if (min_ > b) min_ = b;
   if (min_ > c) min_ = c;
   if (min_ > d) min_ = d;
   return min_;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin >> n >> Xa >> Ya >> Xb >> Yb;
   if ((Xa == Xb && (Xa == 0 || Xa == n)) || (Ya == Yb && (Ya == 0 || Ya == n)))
     cout << abs(Xa - Xb) + abs(Ya - Yb) <<
 ;
   else
     cout << Smallest(abs(0 - Xa) + abs(0 - Ya) + abs(0 - Xb) + abs(0 - Yb),
                      abs(0 - Xa) + abs(n - Ya) + abs(0 - Xb) + abs(n - Yb),
                      abs(n - Xa) + abs(0 - Ya) + abs(n - Xb) + abs(0 - Yb),
                      abs(n - Xa) + abs(n - Ya) + abs(n - Xb) + abs(n - Yb))
          <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, k;
   scanf( d d , &n, &k);
   int a[500005];
   map<int, vector<int>> m;
   set<int> s;
   for (int i = 0; i < n; i++) s.insert(i);
   for (int i = 0; i < n; i++) {
     scanf( d , &a[i]);
     m[a[i]].push_back(i);
   }
   int llast = n + k;
   int last = n;
   int cnt = 0;
   for (auto it : m) {
     if (!cnt && it.second[0] < last - k) {
       auto it = s.lower_bound(llast - k);
       if (it != s.end()) last = *it;
       cnt = 1;
     }
     if (it.second[0] < last - k) {
       printf( NO
 );
       return 0;
     }
     for (auto it2 : it.second) {
       s.erase(it2);
     }
     llast = last;
     last = min(it.second[0], last);
   }
   printf( YES
 );
 }


#include <bits/stdc++.h>
 using namespace std;
 map<int, int> glosy;
 map<pair<int, int>, int> parki;
 int main() {
   int n, m;
   scanf( dd , &n, &m);
   for (int i = (0); i < (n); i++) {
     int a, b;
     scanf( dd , &a, &b);
     if (a > b) swap(a, b);
     if (glosy.find(a) != glosy.end())
       glosy[a]++;
     else
       glosy.insert(make_pair(a, 1));
     if (glosy.find(b) != glosy.end())
       glosy[b]++;
     else
       glosy.insert(make_pair(b, 1));
     if (parki.find(make_pair(a, b)) != parki.end())
       parki[make_pair(a, b)]++;
     else
       parki.insert(make_pair(make_pair(a, b), 1));
   }
   if (m == 0) {
     cout << (n * 1LL * (n - 1LL)) / 2LL << endl;
     return 0;
   }
   long long int res = 0LL;
   vector<int> v;
   for (map<int, int>::iterator it = glosy.begin(); it != glosy.end(); it++)
     v.push_back(it->second);
   int jeszcze = n - v.size();
   sort(v.begin(), v.end());
   int k = v.size();
   for (int i = (0); i < (k); i++) {
     vector<int>::iterator it2 = lower_bound(v.begin(), v.end(), m - v[i]);
     int ile = (v.end() - it2);
     if (v[i] + v[i] >= m) ile--;
     if (v[i] >= m) ile += 2 * jeszcze;
     res += ile * 1LL;
   }
   res = res / 2;
   for (map<pair<int, int>, int>::iterator it = parki.begin(); it != parki.end();
        it++) {
     pair<int, int> para = it->first;
     int a = para.first;
     int b = para.second;
     int x = glosy[a] + glosy[b] - it->second;
     if (x < m && ((glosy[a] + glosy[b]) >= m)) res--;
   }
   cout << res << endl;
   return 0;
 }


#include <bits/stdc++.h>
 const int LG = 21;
 const int N = 500005;
 const long long MOD = 1e9 + 7;
 const long long INF = 1e9;
 const long long INFLL = 1e18;
 using namespace std;
 void dfs(int v, int paint, vector<int> &col,
          vector<vector<pair<int, int> > > &graph, vector<int> &need, int &cnt0,
          int &cnt1, int &fl) {
   col[v] = paint;
   if (paint == -1)
     cnt0++;
   else
     cnt1++;
   if (need[v] != 0) {
     if (paint == need[v])
       fl = 1;
     else
       fl = -1;
   }
   for (auto p : graph[v]) {
     if (col[p.first] == 0) {
       dfs(p.first, p.second * paint, col, graph, need, cnt0, cnt1, fl);
     }
   }
 }
 int root[N];
 vector<int> suns[N];
 int cntsame[N];
 int sametoroot[N];
 int fl[N];
 int ans;
 int Root(int x) { return root[x] == x ? x : Root(root[x]); }
 void complete_data(int v, int FL) {
   int x = Root(v);
   if (fl[x] != 0) return;
   FL *= sametoroot[v];
   int took_before = min(cntsame[x], (int)suns[x].size() - cntsame[x]);
   ans -= took_before;
   fl[x] = FL;
   if (FL == 1)
     ans += cntsame[x];
   else
     ans += suns[x].size() - cntsame[x];
 }
 void Merge(int v, int u, int w) {
   int x = Root(v), y = Root(u);
   if (x == y) return;
   if (suns[x].size() > suns[y].size()) {
     swap(v, u);
     swap(x, y);
   }
   w *= sametoroot[v];
   w *= sametoroot[u];
   if (fl[x] == 0 && fl[y] == 0) {
     ans -= min(cntsame[x], (int)suns[x].size() - cntsame[x]);
     ans -= min(cntsame[y], (int)suns[y].size() - cntsame[y]);
   }
   if (fl[x] == 0 && fl[y] != 0) {
     complete_data(x, fl[y] * w);
   }
   if (fl[x] != 0 && fl[y] == 0) {
     complete_data(y, fl[x] * w);
   }
   for (auto u : suns[x]) {
     suns[y].push_back(u);
     sametoroot[u] *= w;
     if (sametoroot[u] == 1) cntsame[y]++;
   }
   if (fl[x] == 0 && fl[y] == 0) {
     ans += min(cntsame[y], (int)suns[y].size() - cntsame[y]);
   }
   root[x] = y;
 }
 signed main() {
   srand(time(NULL));
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int n, k;
   cin >> n >> k;
   string s;
   cin >> s;
   vector<vector<int> > contains(n);
   for (int i = 0; i < k; i++) {
     int c;
     cin >> c;
     for (int j = 0; j < c; j++) {
       int x = 0;
       cin >> x;
       x--;
       contains[x].push_back(i);
     }
   }
   vector<vector<pair<int, int> > > graph(k);
   vector<int> need(k, 0);
   for (int i = 0; i < k; i++) root[i] = i;
   for (int i = 0; i < k; i++) suns[i].push_back(i);
   for (int i = 0; i < k; i++) cntsame[i] = 1;
   for (int i = 0; i < k; i++) sametoroot[i] = 1;
   for (int i = 0; i < n; i++) {
     if (contains[i].size() == 1) {
       if (s[i] == '1') {
         need[contains[i][0]] = -1;
         complete_data(contains[i][0], -1);
       } else {
         need[contains[i][0]] = 1;
         complete_data(contains[i][0], 1);
       }
     }
     if (contains[i].size() == 2) {
       if (s[i] == '0') {
         graph[contains[i][0]].push_back({contains[i][1], -1});
         graph[contains[i][1]].push_back({contains[i][0], -1});
         Merge(contains[i][0], contains[i][1], -1);
       } else {
         graph[contains[i][0]].push_back({contains[i][1], 1});
         graph[contains[i][1]].push_back({contains[i][0], 1});
         Merge(contains[i][0], contains[i][1], 1);
       }
     }
     cout << ans << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1e5 + 10;
 vector<int> v;
 set<pair<int, int> > st;
 int bfs(int x) {
   queue<int> q;
   q.push(x);
   int cnt = 0;
   while (!q.empty()) {
     int u = q.front();
     q.pop();
     cnt++;
     int len = v.size();
     for (int i = 0; i < len; i++, len = v.size()) {
       int p = v[i];
       if (st.find(make_pair(u, p)) != st.end())
         continue;
       else
         swap(v[i], v.back()), v.pop_back(), q.push(p), i--;
     }
   }
   return cnt;
 }
 int main() {
   int n, m;
   scanf( dd , &n, &m);
   for (int i = 0; i < m; i++) {
     int u, v;
     scanf( dd , &u, &v);
     st.insert(make_pair(u, v));
     st.insert(make_pair(v, u));
   }
   for (int i = 1; i <= n; i++) v.push_back(i);
   int ans = 0;
   while (!v.empty()) {
     int x = v.back();
     v.pop_back();
     bfs(x);
     ans++;
   }
   printf( d
 , ans - 1);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool essentiallyEqual(float a, float b) {
   return fabs(a - b) <= ((fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * 1e-6);
 }
 struct TVector {
   long long x, y;
   TVector operator+(TVector q) const { return {x + q.x, y + q.y}; }
   TVector operator-(TVector q) const { return {x - q.x, y - q.y}; }
   TVector operator*(int t) const { return {x * t, y * t}; }
   long long operator*(TVector q) const { return {x * q.x + y * q.y}; }
   long long operator^(TVector q) const { return {x * q.y - q.x * y}; }
   long double operator~() const { return {hypot(x, y)}; }
   long double disPointLine(TVector p, TVector q) {
     TVector r = *this;
     if (((r - p) * (q - p) >= 0) && ((r - q) * (p - q) >= 0)) {
       return abs((q - p) ^ (r - p)) / ~(p - q);
     } else {
       return min(~(r - p), ~(r - q));
     }
   }
   bool onLine(TVector p, TVector q) {
     TVector r = *this;
     long double dis = r.disPointLine(p, q);
     return essentiallyEqual(dis, 0);
   }
   long double sqrdDist(TVector p) {
     return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y);
   }
   int orientation(TVector b, TVector c) {
     TVector a = *this;
     int val = (c - a) ^ (b - a);
     return val;
   }
   int orientationV2(TVector b, TVector c) {
     TVector a = *this;
     int val = (c - a) ^ (b - a);
     if (val == 0) return 0;
     return (val > 0) ? 1 : 2;
   }
   void imprimePonto() { printf( lld lld , x, y); }
 };
 vector<TVector> stormtroopers;
 vector<int> isShot;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int n, x0, y0;
   cin >> n >> x0 >> y0;
   TVector gun;
   gun.x = x0;
   gun.y = y0;
   for (int i = 0; i < n; ++i) {
     int x, y;
     cin >> x >> y;
     stormtroopers.push_back({x, y});
     isShot.push_back(0);
   }
   int tiros = 0;
   for (int i = 0; i < n; ++i) {
     if (!isShot[i]) {
       tiros++;
       for (int j = i + 1; j < n; ++j) {
         if (!isShot[j]) {
           if (!gun.orientationV2(stormtroopers[i], stormtroopers[j]))
             isShot[j] = 1;
         }
       }
     }
   }
   cout << tiros << endl;
   return 0;
 }


#include <vector>
 #include <iostream>
 #include <algorithm>
 #include <string>
 #include <cmath>
 #include <map>
 #define ll long long
 using namespace std;

 int main()
 {
     ll t;
     cin >> t;
     while (t--) {
         ll n, m;
         cin >> n >> m;
         string s;
         vector<ll> a(n, 0);
         vector<ll> b(n, 0);
         vector<ll> c(m, 0);
         vector<ll> result(m, 0);
         vector<vector<ll>> bucket(n + 1, vector<ll>(0));

         for (auto& e : a)cin >> e;
         for (auto& e : b)cin >> e;
         for (auto& e : c)cin >> e;

         for (ll i = 0; i < n; i++)
         {
             if (b[i] != a[i]) {
                 bucket[b[i]].push_back(i);
             }
         }

         ll lastC = -1;
         if (bucket[c[m - 1]].size() > 0) {
             lastC = bucket[c[m - 1]].back();
             bucket[c[m - 1]].pop_back();
         }
         else {
             for (ll i = 0; i < n; i++)
             {
                 if (b[i] == c[m - 1]) {
                     lastC = i;
                     break;
                 }
             }
         }

         if (lastC == -1) {
             cout <<  NO  << endl;
         }
         else {
             result[m - 1] = lastC;
             for (ll i = 0; i < m - 1; i++)
             {
                 if (bucket[c[i]].size() == 0) {
                     result[i] = lastC;
                 }
                 else {
                     result[i] = bucket[c[i]].back();
                     bucket[c[i]].pop_back();
                 }
             }

             auto res = true;
             for (ll i = 0; i < n + 1; i++)
             {
                 if (bucket[i].size() > 0) {
                     res = false;
                 }
             }

             if (res == false) {
                 cout <<  NO  << endl;
             }
             else {
                 cout <<  YES  << endl;
                 for (ll i = 0; i < m; i++)
                 {
                     cout << result[i] + 1;
                     if (i < m - 1) {
                         cout <<    ;
                     }
                     else {
                         cout << endl;
                     }
                 }
             }
         }
     }
     return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int nmax = 1010;
 const int inf = 1000000007;
 int n;
 pair<int, int> a[nmax];
 int main() {
   ios_base::sync_with_stdio(false);
   cin >> n;
   for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;
   long double ans = 1e15;
   a[n + 1] = a[1];
   a[n + 2] = a[2];
   for (int i = 1; i <= n; ++i) {
     pair<int, int> a1 = a[i], a2 = a[i + 1], a3 = a[i + 2];
     long double A = a3.second - a1.second, B = a1.first - a3.first,
                 C = -A * a3.first - a3.second * B;
     long double d =
         abs(A * a2.first + B * a2.second + C) / (sqrt((A * A + B * B)));
     if (ans > d) ans = d;
   }
   cout << fixed << setprecision(15) << ans / (long double)2.0 <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long maxn = 1e6 + 666;
 long long saveori[maxn];
 long long save[maxn];
 long long getcnt(long long x) {
   long long cnt = 0;
   while (x) {
     if (x & 1) cnt++;
     x = x >> 1;
   }
   return cnt;
 }
 long long cnt[maxn][2];
 long long pre[maxn];
 signed main() {
   long long n;
   cin >> n;
   for (long long i = 1; i <= n; i++) {
     scanf( lld , &saveori[i]);
     save[i] = getcnt(saveori[i]);
   }
   long long sum = 0;
   for (long long i = 1; i <= n; i++) {
     cnt[i][0] = cnt[i - 1][0];
     cnt[i][1] = cnt[i - 1][1];
     cnt[i][sum  2]++;
     sum += save[i];
     pre[i] = sum;
   }
   long long ans = 0;
   for (long long i = n; i >= 1; i--) {
     long long maxval = -1;
     sum = 0;
     for (long long j = i; j >= i - 64 && j > 0; j--) {
       sum += save[j];
       maxval = max(maxval, save[j]);
       if (maxval * 2 <= sum && sum  2 == 0) {
         ans++;
       }
     }
     if (i - 65 >= 1) {
       ans += cnt[i - 65][pre[i]  2];
     }
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 #define int long long int
 void next(char &x){
     if(x<='b'){
         x++;
     }else{
         x='a';
     }
 }
 void solve() {
     int n,k;
     cin>>n>>k;
     char cur='a';
     for(int i=0;i<n;i++){
         cout<<cur;
         next(cur);
     }
     cout<<endl;
 }
 signed main() {
     ios::sync_with_stdio(false);
     cin.tie(nullptr);
     cout.tie(nullptr);
     int t;
     cin >> t;
     while (t--){
         solve();
     }
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast )
 #pragma GCC target( avx,avx2,fma )
 #pragma GCC optimization( unroll-loops )
 const int mod = 1e9 + 7;
 using ll = int64_t;
 using namespace std;
 template <int MOD_>
 struct modnum {
   static constexpr int MOD = MOD_;
   static_assert(MOD_ > 0,  MOD must be positive );
   int v;

  private:
   using ll = long long;
   static int minv(int a, int m) {
     a = m;
     assert(a);
     return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
   }

  public:
   modnum() : v(0) {}
   modnum(ll v_) : v(int(v_  MOD)) {
     if (v < 0) v += MOD;
   }
   explicit operator int() const { return v; }
   friend std::ostream& operator<<(std::ostream& out, const modnum& n) {
     return out << int(n);
   }
   friend std::istream& operator>>(std::istream& in, modnum& n) {
     ll v_;
     in >> v_;
     n = modnum(v_);
     return in;
   }
   friend bool operator==(const modnum& a, const modnum& b) {
     return a.v == b.v;
   }
   friend bool operator!=(const modnum& a, const modnum& b) {
     return a.v != b.v;
   }
   modnum inv() const {
     modnum res;
     res.v = minv(v, MOD);
     return res;
   }
   friend modnum inv(const modnum& m) { return m.inv(); }
   modnum neg() const {
     modnum res;
     res.v = v ? MOD - v : 0;
     return res;
   }
   friend modnum neg(const modnum& m) { return m.neg(); }
   modnum operator-() const { return neg(); }
   modnum operator+() const { return modnum(*this); }
   modnum& operator++() {
     v++;
     if (v == MOD) v = 0;
     return *this;
   }
   modnum& operator--() {
     if (v == 0) v = MOD;
     v--;
     return *this;
   }
   modnum& operator+=(const modnum& o) {
     v += o.v;
     if (v >= MOD) v -= MOD;
     return *this;
   }
   modnum& operator-=(const modnum& o) {
     v -= o.v;
     if (v < 0) v += MOD;
     return *this;
   }
   modnum& operator*=(const modnum& o) {
     v = int(ll(v) * ll(o.v)  MOD);
     return *this;
   }
   modnum& operator/=(const modnum& o) { return *this *= o.inv(); }
   friend modnum operator++(modnum& a, int) {
     modnum r = a;
     ++a;
     return r;
   }
   friend modnum operator--(modnum& a, int) {
     modnum r = a;
     --a;
     return r;
   }
   friend modnum operator+(const modnum& a, const modnum& b) {
     return modnum(a) += b;
   }
   friend modnum operator-(const modnum& a, const modnum& b) {
     return modnum(a) -= b;
   }
   friend modnum operator*(const modnum& a, const modnum& b) {
     return modnum(a) *= b;
   }
   friend modnum operator/(const modnum& a, const modnum& b) {
     return modnum(a) /= b;
   }
 };
 using mi = modnum<mod>;
 void solve() {
   int n, m;
   cin >> n;
   vector<vector<int>> adj(n);
   for (int i = 0; i < n - 1; i++) {
     int a, b;
     cin >> a >> b;
     a--, b--;
     adj[a].push_back(b);
     adj[b].push_back(a);
   }
   cin >> m;
   vector<mi> fac(m);
   for (int i = 0; i < m; i++) {
     cin >> fac[i];
   }
   auto comp = [&](mi X, mi Y) -> bool { return X.v < Y.v; };
   sort(fac.begin(), fac.end(), comp);
   if (int(fac.size()) < n - 1) {
     reverse(fac.begin(), fac.end());
     while (int(fac.size()) < n - 1) {
       if (int(fac.size()) < n - 1) {
         fac.push_back(mi(1));
       }
     }
     reverse(fac.begin(), fac.end());
   }
   if (int(fac.size()) > n - 1) {
     mi cur = 1;
     while (int(fac.size()) >= n - 1) {
       cur *= fac.back();
       fac.pop_back();
     }
     fac.push_back(cur);
   }
   vector<ll> sz(n, 0), num;
   function<void(int, int)> dfs = [&](int node, int par) -> void {
     sz[node] = 1;
     for (auto i : adj[node]) {
       if (i != par) {
         dfs(i, node);
         sz[node] += sz[i];
         num.push_back((ll)sz[i] * (n - sz[i]));
       }
     }
   };
   mi answer = 0;
   dfs(0, 0);
   sort(num.begin(), num.end());
   assert(int(num.size()) >= n - 1);
   assert(int(fac.size()) == n - 1);
   for (int i = 0; i < n - 1; i++) {
     mi cur = (fac[i] * num[i]);
     answer += cur;
   }
   cout << answer << '
';
 }
 int main() {
   std::ios_base::sync_with_stdio(false);
   std::cin.tie(nullptr);
   int t(1);
   cin >> t;
   while (t--) {
     solve();
   }
 }


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


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1000005, mod = 1000000007;
 vector<int> pri;
 bool vis[80];
 int pos[80], a[maxn], n;
 long long w[80];
 long long dp[1 << 21], dp2[1 << 21], f[maxn];
 void prework() {
   for (int i = 2; i < (71); ++i) {
     if (!vis[i]) {
       pri.push_back(i);
       pos[i] = (int)pri.size() - 1;
       for (int j = i; j <= 70; j += i) vis[j] = 1;
     }
   }
   f[0] = 1;
   for (int i = 1; i < (maxn); ++i) f[i] = 2 * f[i - 1]  mod;
 }
 void init() {
   scanf( d , &n);
   for (int i = 0; i < (n); ++i) {
     scanf( d , &a[i]);
     w[a[i]]++;
   }
 }
 int gao(int n) {
   int tmp[30] = {0};
   for (int i = 2; i <= n; ++i) {
     while (n  i == 0) {
       n /= i;
       tmp[pos[i]] ^= 1;
     }
   }
   if (n > 1) tmp[pos[n]] ^= 1;
   int res = 0;
   for (int i = 0; i < (21); ++i)
     if (tmp[i]) res |= (1 << i);
   return res;
 }
 inline int get_nx(int st1, int st2) { return st1 ^ st2; }
 void solve() {
   dp[0] = 1;
   for (int i = 2; i < (71); ++i) {
     if (!w[i]) continue;
     int st = gao(i);
     for (int pre = 0; pre < (1 << 19); ++pre) {
       int nx_st = get_nx(st, pre);
       dp2[nx_st] += dp[pre] * f[w[i] - 1]  mod;
       dp2[pre] += dp[pre] * f[w[i] - 1]  mod;
       dp2[nx_st] = mod;
       dp2[pre] = mod;
     }
     for (int k = 0; k < (1 << 19); ++k) dp[k] = dp2[k], dp2[k] = 0;
   }
   long long ans = dp[0] - 1;
   if (w[1]) ans = (f[w[1]]) * ans  mod + f[w[1]] - 1;
   cout << ans  mod << endl;
 }
 int main() {
   prework();
   init();
   solve();
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 1000000007;
 ;
 const int maxn = 410;
 unsigned long long powmod(unsigned long long n, unsigned long long k) {
   unsigned long long ret = 1;
   while (k) {
     if (k & 1) ret = ret * n  mod;
     n = n * n  mod;
     k >>= 1;
   }
   return ret;
 }
 int nxt[maxn][26];
 int dp[maxn][maxn];
 void upd(int& n, int k) {
   if (n < 0 || n > k) n = k;
 }
 bool gao(const string& s, const string& t1, const string& t2) {
   memset(dp, -1, sizeof(dp));
   for (int i = 0; i <= t1.size(); i++)
     for (int j = 0; j <= t2.size(); j++)
       if (dp[i][j] >= 0 || i + j == 0) {
         int p = dp[i][j] + 1;
         if (i < t1.size()) {
           int n = nxt[p][t1[i] - 'a'];
           if (n >= 0) upd(dp[i + 1][j], n);
         }
         if (j < t2.size()) {
           int n = nxt[p][t2[j] - 'a'];
           if (n >= 0) upd(dp[i][j + 1], n);
         }
       }
   return dp[t1.size()][t2.size()] >= 0;
 }
 char str[maxn];
 char tt[maxn];
 int main() {
   int t;
   cin >> t;
   while (t--) {
     cin >> str >> tt;
     memset(nxt, -1, sizeof(nxt));
     for (int i = strlen(str) - 1; i >= 0; i--) {
       memcpy(nxt[i], nxt[i + 1], sizeof(nxt[i]));
       nxt[i][str[i] - 'a'] = i;
     }
     bool yes = false;
     if (strlen(tt) == 1)
       yes = (nxt[0][tt[0] - 'a'] >= 0);
     else {
       for (int i = 0; tt[i + 1]; i++) {
         char tmp = tt[i + 1];
         tt[i + 1] = 0;
         string t1 = tt;
         tt[i + 1] = tmp;
         string t2 = tt + i + 1;
         if (gao(str, t1, t2)) {
           yes = true;
           break;
         }
       }
     }
     if (yes)
       puts( YES );
     else
       puts( NO );
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 long long Query(long long L, long long R) {
   cout << L <<     << R << endl;
   fflush(stdout);
   string s;
   cin >> s;
   if (L == R && s ==  Yes ) exit(0);
   return s ==  Yes ;
 }
 int32_t main() {
   long long n, k;
   cin >> n >> k;
   long long L = 1, R = n;
   while (true) {
     if (R - L + 1 <= 4 * k + 7) {
       long long M = L + rng()  (R - L + 1);
       if (Query(M, M)) {
         return 0;
       } else {
         L = max(1LL, L - k);
         R = min(n, R + k);
       }
     } else {
       long long M = L + ((R - L) >> 1);
       if (Query(L, M)) {
         L = max(1LL, L - k);
         R = min(n, M + k);
       } else {
         L = max(1LL, M - k);
         R = min(n, R + k);
       }
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long MOD = (1e9 + 7);
 const long long INF = (1e9 + 123456789);
 const long long INFL = (INF * INF);
 inline long long addm(long long a, long long b, long long m = MOD) {
   return ((a + b)  m);
 }
 inline long long subm(long long a, long long b, long long m = MOD) {
   return (((a - b)  m + m)  m);
 }
 inline long long mulm(long long a, long long b, long long m = MOD) {
   return ((a * b)  m);
 }
 long long powm(long long a, long long b, long long m = MOD) {
   long long ret = (!b) ? 1 : powm(a, b / 2, m);
   return (!b) ? 1 : mulm(mulm(ret, ret, m), b  2 ? a : 1, m);
 }
 long long gcd(long long a, long long b) { return (!b) ? a : gcd(b, a  b); }
 long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
 long long inv(long long x, long long m = MOD) { return powm(x, m - 2, m); }
 const int N = 1000500;
 int a[N], lft[N], nxt[N];
 vector<int> nodes, g[N];
 struct SegmentTree {
   int f, t;
   SegmentTree *lc, *rc;
   bool has_child, has_lazy = false;
   int upd = 0;
   int vmax = 0;
   SegmentTree(int l, int r) {
     if (l == r) {
       f = t = l;
       lc = rc = NULL;
       has_child = false;
     } else {
       f = l;
       t = r;
       int mid = (l + r) / 2;
       lc = new SegmentTree(l, mid);
       rc = new SegmentTree(mid + 1, r);
       has_child = true;
     }
   }
   void change(int v) {
     vmax += v;
     upd += v;
     has_lazy = true;
   }
   void push() {
     if (!has_lazy) return;
     lc->change(upd);
     rc->change(upd);
     upd = 0;
     has_lazy = false;
   }
   void update(int l, int r, int x) {
     if (r < f || l > t) return;
     if (l <= f && t <= r) {
       change(x);
       return;
     }
     push();
     lc->update(l, r, x);
     rc->update(l, r, x);
     vmax = max(lc->vmax, rc->vmax);
   }
   int query(int l, int r) {
     if (r < f || l > t) return 0;
     if (l <= f && t <= r) return vmax;
     return vmax = max(lc->query(l, r), rc->query(l, r));
   }
 };
 void solve() {
   int n, k;
   cin >> n >> k;
   for (int i = 0; i < n; i++) cin >> a[i];
   stack<int> st;
   for (int i = n - 1; i >= 0; i--) {
     while (!st.empty() && a[st.top()] <= a[i]) st.pop();
     if (!st.empty())
       nxt[i] = st.top();
     else
       nxt[i] = n;
     st.push(i);
   }
   for (int i = 0; i < n; i++) g[nxt[i]].push_back(i);
   function<void(int)> post = [&](int v) {
     int l = (int)(nodes).size();
     for (int u : g[v]) post(u);
     lft[(int)(nodes).size()] = l;
     nodes.push_back(v);
   };
   post(n);
   SegmentTree root(0, n);
   for (int i = 0; i < k; i++) root.update(lft[i], i, 1);
   vector<int> ans;
   ans.push_back(root.query(0, n));
   for (int i = k; i < n; i++) {
     root.update(lft[i - k], i - k, -1);
     root.update(lft[i], i, 1);
     ans.push_back(root.query(0, n));
   }
   for (int i = 0; i < (int)(ans).size(); i++) {
     if (i) cout <<    ;
     cout << ans[i];
   }
   cout <<
 ;
 }
 int main(int argc, char *argv[]) {
   cin.sync_with_stdio(0);
   cin.tie(NULL);
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long N = 2e5 + 100;
 long long a[N];
 pair<long long, long long> ask(long long l, long long r) {
   cout <<  ?   << l <<     << r << endl;
   long long first;
   cin >> first;
   if (first == -1) exit(0);
   long long f;
   cin >> f;
   return {first, f};
 }
 void solve(long long l, long long r) {
   if (l > r) return;
   long long first, f;
   tie(first, f) = ask(l, r);
   long long l1 = r + 1 - f, r1 = l - 1 + f;
   if (l1 <= r1) {
     for (long long i = l1; i <= r1; i++) a[i] = first;
     solve(l, l1 - 1);
     solve(r1 + 1, r);
   } else {
     long long m = (l + r) / 2;
     solve(l, m);
     solve(m + 1, r);
   }
 }
 signed main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   long long n;
   cin >> n;
   solve(1, n);
   cout <<  !  ;
   for (long long i = 1; i <= n; i++) cout << a[i] <<    ;
   cout << endl;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast,unroll-loops,fast-math )
 using namespace std;
 const int MAXN = 102, K = 900;
 int n, m, k, u, v, x, y, t, a, b;
 int A[MAXN];
 short F1[MAXN][MAXN][2 * MAXN];
 short F2[MAXN][MAXN][2 * MAXN];
 short F3[MAXN][MAXN][2 * MAXN];
 double dp[2][MAXN][MAXN];
 int C(int x) { return x * (x + 1) / 2; }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin >> n >> k;
   k = min(k, K);
   for (int i = 0; i < n; i++) cin >> A[i];
   for (int l = 0; l < n; l++)
     for (int r = l; r < n; r++) {
       for (int i = 0; i < n; i++)
         for (int j = i + 1; j < n; j++) {
           bool ii = (l <= i && i <= r);
           bool jj = (l <= j && j <= r);
           if (ii && !jj) F1[i][j][l + r]++;
           if (!ii && jj) F2[i][j][l + r]++;
           if (ii && jj) F3[i][j][l + r]++;
         }
     }
   int prev = 0, curr = 1;
   for (int i = 0; i < n; i++)
     for (int j = 0; j < i; j++) dp[0][i][j] = 1;
   for (int x = 1; x <= k; x++) {
     for (int i = 0; i < n; i++)
       for (int j = i + 1; j < n; j++) {
         dp[curr][i][j] = (C(i) + C(j - i - 1) + C(n - j - 1)) * dp[prev][i][j];
         for (int cent = i; cent < n + i; cent++)
           dp[curr][i][j] += F1[i][j][cent] * dp[prev][cent - i][j];
         for (int cent = j; cent < n + j; cent++)
           dp[curr][i][j] += F2[i][j][cent] * dp[prev][i][cent - j];
         for (int cent = j; cent < n + i; cent++)
           dp[curr][i][j] += F3[i][j][cent] * dp[prev][cent - i][cent - j];
         dp[curr][i][j] /= C(n);
         dp[curr][j][i] = 1. - dp[curr][i][j];
       }
     swap(prev, curr);
   }
   double ans = 0;
   for (int i = 0; i < n; i++)
     for (int j = 0; j < n; j++)
       if (A[i] < A[j]) ans += dp[prev][i][j];
   cout << setprecision(12) << fixed << ans << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   int tab[n];
   long long s = 0;
   for (int i = 0; i < n; i++) {
     cin >> tab[i];
     if (i == tab[i]) {
       s++;
       tab[i] = -1;
     }
   }
   bool bo = false;
   for (int i = 0; i < n; i++) {
     if (tab[i] != -1) {
       if (tab[tab[i]] == i) {
         s += 2;
         bo = false;
         break;
       }
       bo = true;
     }
   }
   if (bo) s++;
   cout << s;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( O2 )
 using namespace std;
 string conv(int n) {
   string kq =   ;
   while (n != 0) {
     int r = n  26;
     if (r == 0) r = 26;
     kq = char(r - 1 + 'A') + kq;
     n = (n - r) / 26;
   }
   return kq;
 }
 int conv(string s) {
   int kq = 0;
   int n = s.size();
   int tmp = 1;
   for (int i = n - 1; i >= 0; i--) {
     int k = int(s[i] - 'A') + 1;
     kq += tmp * k;
     tmp *= 26;
   }
   return kq;
 }
 int type(string s) {
   if (s[0] != 'R') return 1;
   if (s[1] >= 'A' && s[1] <= 'Z') return 1;
   bool kt = false;
   int n = s.size();
   for (int i = 0; i <= n - 1; i++)
     if (s[i] == 'C') {
       kt = true;
       break;
     }
   if (!kt) return 1;
   return 2;
 }
 void chuyen(string s) {
   if (type(s) == 1) {
     int n = s.size();
     string x1 =   ;
     int j = 0;
     while (s[j] >= 'A' && s[j] <= 'Z') {
       x1 += s[j];
       j++;
     }
     cout <<  R ;
     for (int i = j; i <= n - 1; i++) cout << s[i];
     cout <<  C  << conv(x1) << '
';
   }
   if (type(s) == 2) {
     int kq = 0;
     int tmp = 1;
     int j = s.size() - 1;
     while (s[j] >= '0' && s[j] <= '9') {
       kq += (s[j] - '0') * tmp;
       tmp *= 10;
       j--;
     }
     cout << conv(kq);
     for (int i = 1; i <= j - 1; i++) cout << s[i];
     cout << '
';
   }
 }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int n;
   cin >> n;
   while (n--) {
     string s;
     cin >> s;
     chuyen(s);
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 void solution() {
   long long n;
   cin >> n;
   vector<vector<long long>> v(n, vector<long long>(n, 0));
   if (n  2 != 0) {
     v[n - 1][(n - 1) / 2] = 1;
     v[(n - 1) / 2][n - 1] = 1;
   }
   for (long long i = 0; i < n; i++) {
     for (long long j = 0; j < n; j++) {
       if (i == j || i == n - j - 1) v[i][j] = 1;
       cout << v[i][j] << ' ';
     }
     cout <<
 ;
   }
 }
 int32_t main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   ;
   long long t;
   cin >> t;
   while (t--) solution();
 }


#include <bits/stdc++.h>
 std::vector<int> V[200010], V2[200010];
 int check[200010];
 std::stack<int> St;
 void init(int k) {
   if (check[k] == 1) return;
   check[k] = 1;
   for (int i = 0; i < V[k].size(); i++) init(V[k][i]);
   St.push(k);
 }
 int color[200010];
 void makeSCC(int k, int c) {
   if (color[k] > 0) return;
   color[k] = c;
   for (int i = 0; i < V2[k].size(); i++) makeSCC(V2[k][i], c);
 }
 int x[200010], cost[200010];
 std::vector<int> V3[200010];
 int main() {
   int a;
   scanf( d , &a);
   for (int i = 1; i <= a; i++) scanf( d , &x[i]);
   for (int i = 1; i <= a; i++) {
     int b;
     scanf( d , &b);
     V[i].push_back(b);
     V2[b].push_back(i);
   }
   for (int i = 1; i <= a; i++) init(i);
   int c = 1;
   while (!St.empty()) {
     int k = St.top();
     St.pop();
     if (color[k] == 0) makeSCC(k, c++);
   }
   for (int i = 1; i <= a; i++) cost[i] = 123456789;
   for (int i = 1; i <= a; i++)
     cost[color[i]] = cost[color[i]] < x[i] ? cost[color[i]] : x[i];
   for (int i = 1; i <= a; i++)
     if (color[i] != color[V[i][0]]) V3[color[i]].push_back(color[V[i][0]]);
   long long int ans = 0;
   for (int i = 1; i <= a; i++)
     if (V3[i].size() == 0 && cost[i] < 123456789) ans += cost[i];
   printf( lld , ans);
 }


#include <bits/stdc++.h>
 int n, ust, x, y, mark[10];
 int main() {
   scanf( d , &n);
   scanf( d , &ust);
   for (int i = 0; i < n; i++) {
     scanf( d d , &x, &y);
     mark[x] = 1;
     mark[y] = 1;
     mark[7 - x] = 1;
     mark[7 - y] = 1;
     if (!mark[7 - ust])
       for (int j = 0; j < 7; j++) mark[j] = 0;
     else {
       printf( NO
 );
       return 0;
     }
   }
   printf( YES
 );
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int n;
   cin >> n;
   cout << n / (2520LL);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1000001;
 int n, kt[N], a[N], cnt, x[N];
 long long k, s;
 long long cal(int i) {
   long long res = i;
   return res * (res + 1) / 2;
 }
 int main() {
   scanf( dlld , &n, &k);
   if (k < cal(n)) {
     printf( -1 );
     return 0;
   }
   for (int i = n; i > 0; i--) {
     int h = n - (n - i) / 2;
     if (k - h < cal(i - 1)) h = k - cal(i - 1);
     k -= h;
     kt[h]++;
     if (kt[h] == 2) a[++cnt] = h;
   }
   for (int i = 1; i <= n; i++) s += kt[i] * i;
   printf( lld
 , s);
   for (int i = 1; i <= n; i++) {
     if (kt[i] == 1)
       x[i] = i;
     else if (kt[i] == 0) {
       x[a[cnt]] = i;
       x[i] = a[cnt];
       cnt--;
     }
   }
   for (int i = 1; i <= n; i++) printf( d  , i);
   printf(
 );
   for (int i = 1; i <= n; i++) printf( d  , x[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios::sync_with_stdio(false);
   int n, m, q;
   cin >> n >> m >> q;
   vector<vector<int>> r(n), c(m);
   for (int i = 0; i < q; ++i) {
     int x, y;
     cin >> x >> y;
     --x;
     --y;
     r[x].push_back(y);
     c[y].push_back(x);
   }
   if (n == 1) {
     cout << m - q;
     return 0;
   }
   if (m == 1) {
     cout << n - q;
     return 0;
   }
   vector<char> used_row(n, false);
   vector<char> used_col(m, false);
   int ans = 0;
   vector<int> cols_to_add(r[0]), next_cols_to_add;
   used_row[0] = true;
   for (int i = 0; i < m; ++i) {
     if (used_col[i]) continue;
     while (!cols_to_add.empty()) {
       next_cols_to_add.clear();
       for (int col : cols_to_add) {
         if (used_col[col]) continue;
         used_col[col] = true;
         for (int row : c[col]) {
           if (used_row[row]) continue;
           used_row[row] = true;
           for (int new_col : r[row]) {
             next_cols_to_add.push_back(new_col);
           }
         }
       }
       cols_to_add = next_cols_to_add;
     }
     if (!used_col[i]) {
       ++ans;
       cols_to_add.push_back(i);
     }
   }
   while (!cols_to_add.empty()) {
     next_cols_to_add.clear();
     for (int col : cols_to_add) {
       if (used_col[col]) continue;
       used_col[col] = true;
       for (int row : c[col]) {
         if (used_row[row]) continue;
         used_row[row] = true;
         for (int new_col : r[row]) {
           next_cols_to_add.push_back(new_col);
         }
       }
     }
     cols_to_add = next_cols_to_add;
   }
   for (int i = 1; i < n; ++i) {
     if (!used_row[i]) {
       ++ans;
     }
   }
   cout << ans;
 }


#include <bits/stdc++.h>
 bool canWin(long long b, long long e) {
   if (e  2 == 1) {
     return b  2 == 0;
   } else if (e < 2 * b) {
     return b  2 == 1;
   } else if (e < 4 * b) {
     return 1;
   } else {
     return canWin(b, e / 4);
   }
 }
 bool canLose(long long b, long long e) {
   if (e < 2 * b) {
     return 1;
   } else if (e / 2  2 == 1) {
     return b  2 == 0;
   } else if (e < 4 * b) {
     return b  2 == 1;
   } else {
     return canLose(b, e / 4);
   }
 }
 int main() {
   int t;
   scanf( d , &t);
   bool canBeWinner, canBeLoser;
   bool canBeFirst = true;
   bool canBeSecond = false;
   for (int i = 0; i < t; i++) {
     long long b, e;
     scanf( lldlld , &b, &e);
     bool cWin = canWin(b, e);
     bool cLose = canLose(b, e);
     canBeWinner = (canBeFirst && cWin) || (canBeSecond && !cWin);
     canBeLoser = (canBeFirst && cLose) || (canBeSecond && !cLose);
     canBeFirst = canBeLoser;
     canBeSecond = canBeWinner;
   }
   printf( d d
 , canBeWinner, canBeLoser);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using namespace std;
 const long long N = 4e7 + 5, N_ = 4e6 + 5;
 int cnt = 0, prime[N_];
 bitset<N> vis;
 void pre() {
   for (int i = 2; i < N; ++i) {
     if (!vis[i]) prime[cnt++] = i;
     for (int j = 0; i * prime[j] < N; ++j) {
       vis[i * prime[j]] = 1;
       if (i  prime[j] == 0) break;
     }
   }
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int n, m;
   cin >> n;
   if (n == 2) {
     cout <<  1 1  << endl;
     return 0;
   }
   if (n == 3) {
     cout <<  1 1 2  << endl;
     return 0;
   }
   if (n == 4) {
     cout <<  1 1 2 1  << endl;
     return 0;
   }
   if (n == 5) {
     cout <<  1 2 1 1 1  << endl;
     return 0;
   }
   if (n == 6) {
     cout <<  1 2 1 1 1 1  << endl;
     return 0;
   }
   pre();
   m = n * (n + 1) / 2;
   bool sign = 0;
   vector<int> res(n + 1, 0);
   int flag = 0;
   if (m & 1) {
     if (!vis[m - 2]) {
       ++res[2];
       res.erase(res.begin());
       for (auto i : res) cout << i + 1 <<    ;
       cout << endl;
       return 0;
     }
     m -= 3;
     flag = 3;
     res[3] = 2;
   }
   for (auto i : prime) {
     int t = m - i;
     if (!i || t < 0) break;
     if (!vis[t]) {
       for (int i = n; t && i > flag; --i) {
         if (i == flag) continue;
         if (i <= t) {
           t -= i;
           ++res[i];
         }
       }
       if (t) {
         res = vector<int>(n + 1, 0);
         res[flag] = 2;
       } else {
         sign = 1;
         break;
       }
     }
   }
   if (!sign) {
     cout << -1 << endl;
     return 0;
   }
   res.erase(res.begin());
   for (auto i : res) cout << i + 1 <<    ;
   cout << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, m;
 inline long long read() {
   long long x = 0, f = 1;
   char ch = getchar();
   while (ch < '0' || ch > '9') {
     if (ch == '-') f = -1;
     ch = getchar();
   }
   while (ch >= '0' && ch <= '9') {
     x = (x << 3) + (x << 1) + ch - '0';
     ch = getchar();
   }
   return x * f;
 }
 long long qpow(long long a, long long b) {
   long long ans = 1;
   while (b) {
     if (b & 1) ans = 1ll * ans * a  1000000007;
     a = 1ll * a * a  1000000007;
     b >>= 1;
   }
   return ans  1000000007;
 }
 signed main() {
   cin >> n >> m;
   long long c = n - m + 1;
   c *= 2;
   n++;
   n *= 2;
   m--;
   long long tot = qpow(n, m);
   long long amo = (c * tot)  1000000007;
   amo = 1000000007;
   cout << amo;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, k;
 int pr(int i) { return (i - 1 + n)  n; }
 int nx(int i) { return (i + 1)  n; }
 int get(int i, int j) {
   if (i > j) swap(i, j);
   return min(j - i, n - j + i);
 }
 char no(char el) {
   if (el == 'B')
     return 'W';
   else
     return 'B';
 }
 int gg(string s) {
   int b = 1;
   for (char i : s) {
     if (i != 'B') b = 0;
   }
   int w = 1;
   for (char i : s) {
     if (i != 'W') w = 0;
   }
   return max(w, b);
 }
 signed main() {
   string s;
   cin >> n >> k >> s;
   if (gg(s)) {
     cout << s;
     return 0;
   }
   vector<int> used(n, 0);
   int l = 0, r = 0, op = 1e6;
   bool ch = false;
   while (l < n && op > 0) {
     --op;
     if (used[l]) {
       ++l;
     } else if (s[l] == s[pr(l)]) {
       ch = true;
       while (s[l] == s[nx(l)]) used[l] = 1, l = nx(l);
       r = nx(l);
       while (s[r] != s[nx(r)]) used[r] = 1, r = nx(r);
       int cr = r;
       while (s[nx(cr)] == s[cr]) used[cr] = 1, cr = nx(cr);
       char last = s[l];
       for (int i = nx(l); i != r; i = nx(i)) {
         if (get(l, i) > k && get(r, i) > k)
           s[i] = no(last), last = no(last);
         else if (get(l, i) < get(r, i))
           s[i] = s[l], last = s[l];
         else if (get(l, i) >= get(r, i))
           s[i] = s[r], last = s[r];
       }
       ++l;
     } else {
       ++l;
     }
   }
   if (!ch) {
     if (k  2 == 0)
       cout << s;
     else
       for (char i : s) cout << no(i);
     return 0;
   }
   cout << s;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> g[100100];
 int aa[100100];
 long long dfs(int u, int fa) {
   vector<long long> tmp;
   for (int i = 0; i < g[u].size(); i++) {
     int v = g[u][i];
     if (v != fa && aa[v] - 1 >= 0) {
       aa[v] -= 1;
       tmp.push_back(dfs(v, u));
     }
   }
   sort(tmp.begin(), tmp.end());
   int cc = tmp.size();
   long long ans = 0;
   for (int i = aa[u]; i >= 1; i--) {
     if (cc > 0) {
       ans += tmp[--cc] + 2;
       aa[u]--;
     } else {
       break;
     }
   }
   for (int i = 0; i < g[u].size(); i++) {
     int v = g[u][i];
     if (v != fa) {
       int tmp = min(aa[u], aa[v]);
       ans += tmp * 2;
       aa[u] -= tmp;
       aa[v] -= tmp;
     }
   }
   return ans;
 }
 int main() {
   int n;
   scanf( d , &n);
   for (int i = 1; i <= n; i++) {
     scanf( d , &aa[i]);
   }
   for (int i = 0; i < n - 1; i++) {
     int u, v;
     scanf( dd , &u, &v);
     g[u].push_back(v);
     g[v].push_back(u);
   }
   int s;
   scanf( d , &s);
   printf( extra
 , dfs(s, -1));
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 string s;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   ;
   long long int TESTS, k, a, n, b, c, d, m, x, i, y, z;
   cin >> TESTS;
   while (TESTS--) {
     cin >> n;
     cin >> s;
     long long int ans = n;
     for (long long int i = 0; i <= n - 1; i++) {
       if (s[i] == '1') {
         a = max(i + 1, n - i);
         ans = max(ans, 2 * a);
       }
     }
     cout << ans <<
 ;
   }
   return 0;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 const int limit = 10000;
 int query(vector<long long> &v) {
   int n = (int)v.size();
   cout << n << ' ';
   for (int i = 0; i < n; i++) {
     cout << v[i] << (i == n - 1 ? '
' : ' ');
   }
   int k;
   cin >> k;
   if (k == -1) {
     exit(0);
   } else if (k == -2) {
     assert(false);
   }
   return k;
 }
 int main() {
   vector<vector<long long>> dp(6, vector<long long>(10010));
   for (int q = 1; q <= 5; q++) {
     for (long long p = 1; p <= limit; p++) {
       if (q == 5 && p == 2) {
         break;
       }
       long long x = p;
       for (int i = 0; i < p; i++) {
         x += dp[q - 1][min(10000LL, x)];
         x++;
       }
       x += dp[q - 1][min(10000LL, x)];
       dp[q][p] = x - p;
     }
   }
   long long lb = 1, ub = 10004205361450474LL;
   for (int q = 5; q >= 1; q--) {
     vector<long long> hoge;
     long long x = lb;
     for (int i = 0; i < min(10000LL, lb); i++) {
       x += dp[q - 1][min((long long)10000, x)];
       hoge.push_back(x);
       x++;
     }
     x += dp[q - 1][min(10000LL, x)];
     int k = query(hoge);
     if (k == 0) {
       ub = hoge[0] - 1;
     } else if (k == (int)hoge.size()) {
       lb = hoge.back() + 1;
     } else {
       lb = hoge[k - 1] + 1;
       ub = hoge[k] - 1;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = (int)1e5 + 10;
 int sx[MAXN], sy[MAXN], sz[MAXN];
 char s[MAXN];
 void solve(int x, int y, int z) {
   if (x + y + z < 3) {
     printf( YES
 );
     return;
   }
   int e = (x + y + z) / 3;
   vector<int> v;
   v.push_back(x);
   v.push_back(y);
   v.push_back(z);
   sort(v.begin(), v.end());
   if ((x + y + z)  3 == 0) {
     if (x == e && y == e && z == e)
       printf( YES
 );
     else
       printf( NO
 );
     return;
   } else if ((x + y + z)  3 == 1) {
     if (v[2] == e + 1 && v[1] == e)
       printf( YES
 );
     else
       printf( NO
 );
     return;
   } else {
     if (v[2] == e + 1 && v[1] == e + 1)
       printf( YES
 );
     else
       printf( NO
 );
     return;
   }
 }
 int main() {
   scanf( s , s);
   int n = strlen(s);
   for (int i = 1; i <= n; i++) {
     sx[i] = sx[i - 1] + (s[i - 1] == 'x');
     sy[i] = sy[i - 1] + (s[i - 1] == 'y');
     sz[i] = sz[i - 1] + (s[i - 1] == 'z');
   }
   int m;
   scanf( d , &m);
   for (int i = 1; i <= m; i++) {
     int l, r;
     scanf( dd , &l, &r);
     int x = sx[r] - sx[l - 1], y = sy[r] - sy[l - 1], z = sz[r] - sz[l - 1];
     solve(x, y, z);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long int siz = 3e5 + 5;
 map<int, vector<int>> adjList;
 long long int ans[siz] = {0};
 long long int cum[siz] = {0};
 map<long long int, long long int> q[siz];
 void dfs(int cur, int parent, int level, long long int val) {
   for (pair<long long int, long long int> temp : q[cur]) {
     cum[level] += temp.second;
     cum[min(level + temp.first + 1, siz - 1)] -= temp.second;
   }
   val += cum[level];
   ans[cur] = val;
   for (int child : adjList[cur]) {
     if (child != parent) {
       dfs(child, cur, level + 1, val);
     }
   }
   for (pair<long long int, long long int> temp : q[cur]) {
     cum[level] -= temp.second;
     cum[min(level + temp.first + 1, siz - 1)] += temp.second;
   }
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   ;
   int n;
   cin >> n;
   int y;
   long long int x;
   for (int i = 0; i < (int)(n - 1); i++) {
     cin >> x >> y;
     adjList[x].push_back(y);
     adjList[y].push_back(x);
   }
   int m;
   cin >> m;
   int d, v;
   for (int i = 0; i < (int)(m); i++) {
     cin >> v >> d >> x;
     q[v][d] += x;
   }
   dfs(1, -1, 1, 0);
   for (int i = 1; i <= (int)(n); i++) {
     cout << ans[i] <<    ;
   }
   cout << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 unsigned long long n, a[130], i, b = 1, f[10002];
 int main() {
   cin >> n;
   for (i = 1; i <= n; i++) {
     cin >> a[i];
     f[a[i]]++;
   }
   sort(a + 1, a + n + 1);
   cout << a[n] << ' ';
   for (i = 1; i < n; i++) {
     if (f[a[i]] == 1 && a[n]  a[i] != 0) {
       b = a[i];
     } else if (f[a[i]] == 2) {
       b = a[i];
     }
   }
   cout << b;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long MOD = 998244353;
 inline long long Msum(long long x) { return x; }
 template <typename... Rest>
 inline long long Msum(long long x, Rest... rest) {
   return (x + Msum(rest...))  MOD;
 }
 inline long long Mprod(long long x) { return x; }
 template <typename... Rest>
 inline long long Mprod(long long x, Rest... rest) {
   return x * Mprod(rest...)  MOD;
 }
 inline long long Mnorm(long long x) { return (x  MOD + MOD)  MOD; }
 long long Msq(long long x) { return x * x  MOD; }
 long long Mpow(long long b, long long e) {
   return e ? Mprod(Msq(Mpow(b, e >> 1)), (e & 1 ? b : 1)) : 1;
 }
 long long Minv(long long x) { return Mpow(x, MOD - 2); }
 const int MAXN = 51;
 int sns[MAXN], w[MAXN];
 int wi, sn;
 int sl, sd, S;
 long long dp[MAXN][MAXN][MAXN];
 long long f(int h, int hl, int hd, int t) {
   if (!t) return 0;
   long long &ret = dp[h][hl][hd];
   if (ret != -1) return ret;
   ret = 0;
   long long cS = S + hl - hd + sn * h;
   ret += Mprod(wi + sn * h, Minv(cS), 1 + f(h + 1, hl, hd, t - 1));
   ret = Mnorm(ret);
   ret += Mprod(sl + hl, Minv(cS), f(h, hl + 1, hd, t - 1));
   ret = Mnorm(ret);
   ret += Mprod(sd - hd, Minv(cS), f(h, hl, hd + 1, t - 1));
   ret = Mnorm(ret);
   assert(sd - hd + sl + hl + wi + sn * h == cS);
   return ret;
 }
 int main() {
   int n, m;
   scanf( d d , &n, &m);
   for (int i = 0; i < n; i++) {
     scanf( d , &sns[i]);
     sns[i] = sns[i] * 2 - 1;
   }
   for (int i = 0; i < n; i++) {
     scanf( d , &w[i]);
   }
   for (int i = 0; i < n; i++) {
     S = sl = sd = 0;
     wi = w[i];
     sn = sns[i];
     for (int j = 0; j < (int)n; j++) {
       S += w[j];
       if (j != i) {
         if (sns[j] == 1)
           sl += w[j];
         else
           sd += w[j];
       }
     }
     memset(dp, -1, sizeof(dp));
     printf( lld
 , Mnorm(wi + sn * f(0, 0, 0, m)));
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1111111;
 int a[N];
 int n, k;
 vector<int> prime, p;
 void Getprime() {
   for (int i = 2; i <= 1000; i++) {
     bool bo = 1;
     for (int j = 2; j * j <= i; j++) {
       if (i  j == 0) {
         bo = 0;
         break;
       }
     }
     if (bo) {
       prime.push_back(i);
     }
   }
 }
 int main() {
   Getprime();
   scanf( dd , &n, &k);
   for (int i = 1; i <= n; ++i) {
     scanf( d , &a[i]);
   }
   int K = k;
   for (int i = 0; i < prime.size() && prime[i] * prime[i] <= k; ++i) {
     int t = prime[i];
     if (k  t == 0) {
       int m = 1;
       while (K  t == 0 && K) {
         m *= t;
         K /= t;
       }
       p.push_back(m);
     }
   }
   if (K != 1) {
     p.push_back(K);
   }
   for (int i = 0; i < p.size(); ++i) {
     int pr = p[i];
     bool flag = false;
     for (int j = 1; j <= n; ++j) {
       if (a[j]  pr == 0) {
         flag = true;
         break;
       }
     }
     if (!flag) {
       puts( No );
       return 0;
     }
   }
   puts( Yes );
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 inline void smn(T &a, const T &b) {
   if (b < a) a = b;
 }
 template <class T>
 inline void smx(T &a, const T &b) {
   if (b > a) a = b;
 }
 template <class T>
 inline T gcd(T x, T y) {
   return y ? gcd(y, x  y) : x;
 }
 namespace std {
 template <class T, class U>
 struct hash<pair<T, U>> {
   inline size_t operator()(const pair<T, U> &p) const {
     return hash<T>()(p.first) * 701 + hash<U>()(p.second);
   }
 };
 }  // namespace std
 const double eps = 1e-8;
 const int key = 701;
 const int MN = 1000 * 1000 + 1000;
 string s;
 long long h1[MN], pw1[MN], h2[MN], pw2[MN];
 const int MOD = 1000 * 1000 * 1000 + 7;
 long long add[MN];
 int n, k;
 pair<long long, long long> get(int s, int e) {
   long long res1 = h1[e];
   if (s != 0) res1 -= pw1[e - s + 1] * h1[s - 1];
   long long res2 = h2[e];
   if (s != 0) res2 -= pw2[e - s + 1] * h2[s - 1], res2 = MOD;
   if (res2 < 0) res2 += MOD;
   return make_pair(res1, res2);
 }
 bool check(int l) {
   auto v = get(0, l - 1);
   int now = l;
   for (int i = 1; i < k; i++) {
     if (get(now, now + l - 1) != v) return 0;
     now += l;
   }
   return 1;
 }
 int fnd(int p) {
   int s = 1, e = n - p, res = 0;
   while (s <= e) {
     int m = (s + e) / 2;
     if (get(0, m - 1) == get(p, p + m - 1))
       res = m, s = m + 1;
     else
       e = m - 1;
   }
   return res;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin >> n >> k >> s;
   long long now = 0;
   for (int i = 0; i < n; i++) now = now * 701 + s[i], h1[i] = now;
   pw1[0] = 1;
   for (int i = 1; i <= n; i++) pw1[i] = 701 * pw1[i - 1];
   now = 0;
   for (int i = 0; i < n; i++) now = (now * 701 + s[i])  MOD, h2[i] = now;
   pw2[0] = 1;
   for (int i = 1; i <= n; i++) pw2[i] = (701 * pw2[i - 1])  MOD;
   for (int i = 1; i <= n; i++)
     if (n / i >= k && check(i)) {
       int t = i * k;
       int b = fnd(t);
       smn(b, i);
       add[t - 1] += 1;
       add[t + b] += -1;
     }
   now = 0;
   for (int i = 0; i < n; i++) {
     now += add[i];
     cout << (now ? 1 : 0);
   }
   cout << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline int upd(int& a, int b) { return a = min(a, b); }
 inline int _abs(int x) { return x > 0 ? x : -x; }
 char c;
 int n, cnt[3], type[80];
 int pos[3][80], leq[3][80];
 int dp[80][80][80][80];
 void getpos(void) {
   for (int p = 0; p <= 2; p++) {
     cnt[p] = 0;
     for (int y = 1; y <= n; y++) {
       while (y <= n && type[y] != p) y++;
       if (y <= n) pos[p][++cnt[p]] = y;
     }
     leq[p][0] = 0;
     for (int i = 1; i <= n; i++) leq[p][i] = leq[p][i - 1] + (type[i] == p);
   }
   return;
 }
 void trans(int i, int j, int k, int lst) {
   int p0 = pos[0][i], p1 = pos[1][j], p2 = pos[2][k];
   if (i > 0)
     upd(dp[0][i][j][k],
         dp[lst][i - 1][j][k] + _abs(j - leq[1][p0]) + _abs(k - leq[2][p0]));
   if (j > 0)
     upd(dp[1][i][j][k],
         dp[lst][i][j - 1][k] + _abs(i - leq[0][p1]) + _abs(k - leq[2][p1]));
   if (k > 0 && lst != 1)
     upd(dp[2][i][j][k],
         dp[lst][i][j][k - 1] + _abs(i - leq[0][p2]) + _abs(j - leq[1][p2]));
   return;
 }
 int main(void) {
   scanf( d , &n);
   for (int i = 1; i <= n; i++) {
     scanf(  c , &c);
     type[i] = (c == 'V' ? 1 : (c == 'K' ? 2 : 0));
   }
   getpos();
   memset(dp, 0x1f, sizeof(dp));
   dp[0][0][0][0] = 0;
   for (int i = 0; i <= cnt[0]; i++)
     for (int j = 0; j <= cnt[1]; j++)
       for (int k = 0; k <= cnt[2]; k++)
         for (int lst = 0; lst <= 2; lst++) trans(i, j, k, lst);
   int ans = n * n;
   for (int i = 0; i <= 2; i++) upd(ans, dp[i][cnt[0]][cnt[1]][cnt[2]]);
   printf( d
 , ans >> 1);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 2000000;
 int xx[1111111], yy[1111111];
 int pos[1111111], n, m, op[1111111], np[1111111], ff;
 int owner[3333333], first[3333333];
 int ans[1111111];
 bool used[1111111];
 void imp() {
   puts( -1 );
   exit(0);
 }
 inline int sum(int x) {
   int r = 0;
   while (x >= 0) {
     r += first[x];
     x = (x & (x + 1)) - 1;
   }
   return r;
 }
 inline void add(int x, int d) {
   while (x <= maxn) {
     first[x] += d;
     x = (x | (x + 1));
   }
 }
 inline int getFirst(int x) {
   int l = -1, r = maxn;
   while (r - l > 1) {
     int mid = ((l + r) >> 1);
     if (sum(mid) >= x) {
       r = mid;
     } else {
       l = mid;
     }
   }
   return r;
 }
 int main() {
   scanf( dd , &n, &m);
   for (int i = 0; i < m; ++i) {
     scanf( dd , &xx[i], &yy[i]);
     --xx[i];
   }
   memset(owner, -1, sizeof(owner));
   memset(pos, -1, sizeof(pos));
   int ff = m;
   for (int i = 1; i <= n; ++i) {
     add(ff + i, 1);
   }
   for (int i = 0; i < m; ++i) {
     int &oldPlace = op[i];
     int &newPlace = np[i];
     int &x = xx[i];
     int &y = yy[i];
     oldPlace = getFirst(y);
     if ((pos[x] != -1 && oldPlace != pos[x]) ||
         (owner[oldPlace] != -1 && owner[oldPlace] != x)) {
       imp();
     }
     newPlace = ff--;
     owner[oldPlace] = -1;
     add(oldPlace, -1);
     add(newPlace, 1);
     pos[x] = newPlace;
     owner[newPlace] = x;
   }
   for (int i = m - 1; i >= 0; --i) {
     int &oldPlace = op[i];
     int &newPlace = np[i];
     int &x = xx[i];
     int &y = yy[i];
     pos[x] = oldPlace;
     owner[oldPlace] = x;
     add(oldPlace, 1);
     owner[newPlace] = -1;
     add(newPlace, -1);
   }
   memset(ans, -1, sizeof(ans));
   for (int i = 0; i < n; ++i)
     if (pos[i] != -1) {
       int p = sum(pos[i]);
       ans[p - 1] = i;
       used[i] = true;
     }
   int fx = 0;
   for (int i = 0; i < n; ++i)
     if (ans[i] == -1) {
       while (used[fx]) {
         ++fx;
       }
       ans[i] = fx;
       used[fx] = true;
     }
   for (int i = 0; i < n; ++i) {
     if (i > 0) {
       putchar(' ');
     }
     printf( d , ans[i] + 1);
   }
   puts(  );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long spf[100001];
 bool isPrime(long long n) {
   if (n <= 1) return false;
   if (n <= 3) return true;
   if (n  2 == 0 || n  3 == 0) return false;
   for (long long i = 5; i * i <= n; i = i + 6)
     if (n  i == 0 || n  (i + 2) == 0) return false;
   return true;
 }
 long long power(long long a, long long b) {
   long long res = 1;
   while (b > 0) {
     if (b & 1) res = (res * a);
     a = (a * a);
     b >>= 1;
   }
   return res;
 }
 long long modpow(long long a, long long b, long long x) {
   long long res = 1;
   while (b > 0) {
     if (b & 1) res = (res * a)  x;
     a = (a * a)  x;
     b >>= 1;
   }
   return res;
 }
 void sieve() {
   spf[1] = 1;
   for (long long i = 2; i < 100001; i++) spf[i] = i;
   for (long long i = 4; i < 100001; i += 2) spf[i] = 2;
   for (long long i = 3; i * i < 100001; i++)
     if (spf[i] == i)
       for (long long j = i * i; j < 100001; j += i)
         if (spf[j] == j) spf[j] = i;
 }
 vector<long long> getFactorization(long long x) {
   vector<long long> ret;
   while (x != 1) {
     ret.push_back(spf[x]);
     x = x / spf[x];
   }
   return ret;
 }
 void solve() {
   long long n, m;
   cin >> n >> m;
   vector<long long> adj[n + 1];
   for (int i = 0; i < m; i++) {
     long long a, b;
     cin >> a >> b;
     adj[a].push_back(b);
     adj[b].push_back(a);
   }
   vector<pair<long long, long long>> topic(n);
   for (int i = 0; i < n; i++) {
     long long a;
     cin >> a;
     topic[i] = {a, i + 1};
   }
   sort(topic.begin(), topic.end());
   vector<long long> res;
   vector<set<long long>> around(n + 1);
   for (int i = 0; i < topic.size(); i++) {
     long long u = topic[i].second;
     res.push_back(u);
     if (around[u].find(topic[i].first) != around[u].end() ||
         around[u].size() != topic[i].first - 1) {
       cout << -1 <<
 ;
       return;
     }
     for (auto j : adj[u]) {
       around[j].insert(topic[i].first);
     }
   }
   for (auto i : res) cout << i <<    ;
   cout <<
 ;
   ;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   long long t = 1;
   while (t--) solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e5 + 5;
 vector<long long> v[N];
 long long vis[N];
 long long col[N];
 set<long long> che;
 void dfs(long long x) {
   vis[x] = 1;
   che.insert(x);
   for (auto it : v[x]) {
     if (!vis[it]) {
       dfs(it);
     }
   }
 }
 void solve() {
   long long n;
   cin >> n;
   long long i, x, y;
   vector<pair<long long, long long> > e, spe;
   for (i = 0; i < n - 1; i++) {
     cin >> x >> y;
     x--, y--;
     e.push_back(make_pair(x, y));
   }
   for (i = 0; i < n; i++) {
     cin >> col[i];
   }
   for (auto it : e) {
     if (col[it.first] != col[it.second]) {
       spe.push_back(make_pair(it.first, it.second));
     }
   }
   long long m = spe.size();
   long long f = 0, ind = 0;
   long long cnt[n];
   memset(cnt, 0, sizeof(cnt));
   if (m == 0) {
     cout <<  YES
1 ;
     return;
   }
   for (auto it : spe) {
     cnt[it.first]++;
     cnt[it.second]++;
   }
   for (i = 0; i < n; i++) {
     if (cnt[i] == m) {
       cout <<  YES
  << i + 1;
       return;
     }
   }
   cout <<  NO
 ;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   if (fopen( input.txt ,  r )) {
     freopen( input.txt ,  r , stdin);
     freopen( output.txt ,  w , stdout);
   }
   long long t = 1;
   while (t--) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int n;
   cin >> n;
   int zD = 1;
   int zABC = 0;
   for (int i = 1; i <= n; i++) {
     int nzD = zABC * 3LL  1000000007;
     int nzABC = (zABC * 2LL + zD)  1000000007;
     zD = nzD;
     zABC = nzABC;
   }
   cout << zD;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int t;
   cin >> t;
   while (t--) {
     int n, m;
     cin >> n >> m;
     auto chk = [&](int x, int y) { return 0 <= x && x < n && 0 <= y && y < m; };
     vector<int> nxt(n * m, -1), deg(n * m), dp(n * m), dp2(n * m);
     for (int i = 0; i < n; ++i) {
       for (int j = 0; j < m; ++j) {
         char c;
         cin >> c;
         int x = i, y = j;
         if (c == 'L') --y;
         if (c == 'R') ++y;
         if (c == 'U') --x;
         if (c == 'D') ++x;
         if (chk(x, y)) {
           nxt[i * m + j] = x * m + y;
           deg[x * m + y] += 1;
         }
       }
     }
     for (int i = 0; i < n * m; ++i) dp2[i] = i;
     queue<int> q;
     for (int i = 0; i < n * m; ++i)
       if (deg[i] == 0) q.push(i);
     while (!q.empty()) {
       int u = q.front();
       q.pop();
       if (nxt[u] != -1) {
         int v = nxt[u];
         if (dp[v] < dp[u] + 1) {
           dp[v] = dp[u] + 1;
           dp2[v] = dp2[u];
         }
         if (--deg[v] == 0) q.push(v);
       }
     }
     int ans = 0;
     for (int i = 0; i < n * m; ++i) {
       if (deg[i] == 0) continue;
       int p = nxt[i];
       vector<int> loop;
       while (p != i) {
         loop.push_back(p);
         p = nxt[p];
       }
       loop.push_back(i);
       for (int j : loop) dp[j] += loop.size() - 1, deg[j] = 0;
     }
     int mx = -1, x = -1, y = -1;
     for (int i = 0; i < n; ++i) {
       for (int j = 0; j < m; ++j) {
         if (dp[i * m + j] > mx) {
           mx = dp[i * m + j];
           x = dp2[i * m + j] / m;
           y = dp2[i * m + j]  m;
         }
       }
     }
     cout << x + 1 <<     << y + 1 <<     << mx + 1 << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 void addmod(int &a, long long b) {
   a = (a + b);
   if (a >= 1000000007) a -= 1000000007;
 }
 void mulmod(int &a, long long b) { a = (a * b)  1000000007; }
 int gi() {
   int a;
   scanf( d , &a);
   return a;
 }
 long long gll() {
   long long a;
   scanf( lld , &a);
   return a;
 }
 class rangesum {
   vector<long long> s;

  public:
   rangesum(const vector<int> &inp, const int &n) {
     s.resize(n + 1);
     for (int i = 0; i < n; i++) s[i + 1] = s[i] + inp[i];
   }
   long long get(int x, int y) { return s[y + 1] - s[x]; }
 };
 int main() {
   int n = gi(), l, u;
   vector<int> a(n);
   for (auto i = 0; i < n; i++) {
     a[i] = gi();
   }
   rangesum rs(a, n);
   set<int> rm;
   multiset<long long, greater<long long>> v;
   rm.insert(-1);
   rm.insert(n);
   v.insert(rs.get(0, n - 1));
   for (int i = 0; i < n; i++) {
     int ix = gi() - 1;
     auto it = rm.upper_bound(ix);
     u = (*it) - 1;
     it--;
     l = (*it) + 1;
     auto mit = v.find(rs.get(l, u));
     assert(mit != v.end());
     v.erase(mit);
     if (ix > l) v.insert(rs.get(l, ix - 1));
     if (ix < u) v.insert(rs.get(ix + 1, u));
     rm.insert(ix);
     printf( lld
 , (v.size() ? *v.begin() : 0));
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long BIG = 1000000000000000000LL;
 void solve();
 signed main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   solve();
   return 0;
 }
 long long nbBoxes;
 long long reqSom = 0;
 bool cycor[1 << 15];
 pair<long long, pair<long long, long long> > cymem[1 << 15];
 long long dpGo[1 << 15];
 long long origSom[15];
 vector<long long> yolo[15];
 map<long long, long long> loc;
 map<long long, long long> ds;
 vector<long long> maskOk;
 pair<long long, long long> finRes[15];
 long long osef[15];
 long long getMap(long long x) {
   auto it = loc.find(x);
   if (it == loc.end())
     return -1;
   else
     return it->second;
 }
 void tester(long long dep, long long valEnvoi, long long suiv,
             bool act = false) {
   if (dep == suiv) {
     if (origSom[dep] == reqSom) {
       cycor[1LL << dep] = true;
       cymem[1LL << dep] = {dep, {valEnvoi, suiv}};
       if (act) finRes[dep] = {dep, osef[dep]};
     }
     return;
   }
   long long gauche = dep;
   long long cg = reqSom - (origSom[dep] - valEnvoi);
   long long mask = (1LL << gauche);
   if (act) finRes[dep] = {suiv, valEnvoi};
   while (true) {
     long long prev = gauche;
     gauche = getMap(cg);
     if (gauche != -1 && act) finRes[gauche] = {prev, cg};
     if (gauche == -1 || gauche == dep) break;
     if (mask & (1LL << gauche)) break;
     cg = reqSom - (origSom[gauche] - cg);
     mask |= (1LL << gauche);
   }
   if (gauche == dep && cg == valEnvoi) {
     cycor[mask] = true;
     cymem[mask] = {dep, {valEnvoi, suiv}};
   }
 }
 void solve() {
   cin >> nbBoxes;
   for (long long i = (0); i < (nbBoxes); ++i) {
     long long ni;
     cin >> ni;
     for (long long i00 = (0); i00 < (ni); ++i00) {
       long long x;
       cin >> x;
       yolo[i].push_back(x);
       reqSom += x;
       origSom[i] += x;
       loc[x] = i;
       osef[i] = x;
     }
   }
   if (reqSom  nbBoxes != 0) {
     cout <<  No
 ;
     return;
   }
   reqSom /= nbBoxes;
   for (long long i = (0); i < (nbBoxes); ++i) {
     for (long long x : yolo[i]) {
       tester(i, x, -1);
       tester(i, x, i);
     }
   }
   for (long long i = (0); i < ((1 << 15)); ++i) {
     dpGo[i] = -1;
   }
   dpGo[0] = 0;
   for (long long mask = 1; mask < (1 << 15); ++mask) {
     for (long long s = mask; s > 0; s = ((s - 1) & mask)) {
       if (cycor[s] && dpGo[mask ^ s] != -1) {
         dpGo[mask] = s;
         break;
       }
     }
   }
   long long cur = (1LL << nbBoxes) - 1;
   while (dpGo[cur] != 0) {
     if (dpGo[cur] == -1) {
       cout <<  No
 ;
       return;
     }
     long long ret = dpGo[cur];
     long long dep = cymem[ret].first, valEnv = cymem[ret].second.first,
               suiv = cymem[ret].second.second;
     tester(dep, valEnv, suiv, true);
     cur ^= ret;
   }
   cout <<  Yes
 ;
   for (long long i = (0); i < (nbBoxes); ++i)
     cout << finRes[i].second <<     << finRes[i].first + 1 <<
 ;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, k, a[300010], sum[300010], ans;
 int main() {
   scanf( lldlld , &n, &k);
   for (int i = 1; i <= n; i++) scanf( lld , &a[i]);
   for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
   ans += k * sum[n];
   sort(sum + 1, sum + n);
   for (int i = 1; i < k; i++) ans -= sum[i];
   printf( lld , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using LL = long long;
 using LD = long double;
 using ULL = unsigned long long;
 template <class T1, class T2>
 using P = pair<T1, T2>;
 using PII = P<int, int>;
 using PLL = P<LL, LL>;
 using PLD = P<LD, LD>;
 template <class T>
 using V = vector<T>;
 using VI = V<int>;
 using VLL = V<LL>;
 using VLD = V<LD>;
 using VB = V<bool>;
 using VS = V<string>;
 template <class T, class Comp = greater<T>>
 using PQ = priority_queue<T, V<T>, Comp>;
 template <class T>
 int sz(const T& x) {
   return (int)size(x);
 }
 template <class T>
 bool amin(T& a, const T& b) {
   if (b < a) {
     a = b;
     return true;
   }
   return false;
 }
 template <class T>
 bool amax(T& a, const T& b) {
   if (b > a) {
     a = b;
     return true;
   }
   return false;
 }
 const size_t rseed =
     std::chrono::high_resolution_clock::now().time_since_epoch().count();
 mt19937 rnd(rseed);
 int randint(int lo, int hi) {
   return uniform_int_distribution<int>{lo, hi}(rnd);
 }
 int main() {
   int T;
   scanf( d , &T);
   for (int t = (1); t <= (T); t++) {
     int n;
     scanf( d , &n);
     string s(n + 1, ' ');
     scanf( s , &s[0]);
     string a(n, ' '), b(n, ' ');
     bool f = false;
     for (int i = (0); i <= (n - 1); i++) {
       if (f) {
         a[i] = '0';
         b[i] = s[i];
       } else {
         if (s[i] == '1') {
           f = true;
           a[i] = '1';
           b[i] = '0';
         } else if (s[i] == '2')
           a[i] = b[i] = '1';
         else
           a[i] = b[i] = '0';
       }
     }
     printf( s
s
 , a.c_str(), b.c_str());
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int seq[100];
 int main() {
   int n;
   int acc, t, pen;
   scanf( d , &n);
   for (int i = 0; i < n; i++) {
     scanf( d , seq + i);
   }
   sort(seq, seq + n);
   acc = 10;
   t = 0;
   pen = 0;
   for (int i = 0; i < n; i++) {
     acc += seq[i];
     if (acc > 720) {
       break;
     }
     t++;
     if (acc > 360) {
       pen += ((acc - 360) < 0 ? -(acc - 360) : (acc - 360));
     }
   }
   printf( d d
 , t, pen);
   return 0;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 const long long maxx = 1e5 + 20, sqr = 150, mod = 1e9 + 7;
 long long len, n, dp[maxx][sqr][2], q, pw25[maxx], pw26[maxx], pwmod[maxx],
     fac[maxx], tmp[maxx];
 string s;
 long long pw(long long a, long long b) {
   if (!b) return 1ll;
   long long x = pw(a, b / 2);
   x = (x * x)  mod;
   if (b  2) x = (x * a)  mod;
   return x;
 }
 long long sel(long long a, long long b) {
   long long x = 1ll;
   x = (x * fac[a])  mod;
   x = (x * pwmod[b])  mod;
   x = (x * pwmod[a - b])  mod;
   return x;
 }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   pw25[0] = pw26[0] = 1;
   for (long long i = 1; i < maxx; i++)
     pw25[i] = (pw25[i - 1] * 25)  mod, pw26[i] = (pw26[i - 1] * 26)  mod;
   fac[0] = 1;
   for (long long i = 1; i < maxx; i++) fac[i] = (fac[i - 1] * i)  mod;
   for (long long i = 0; i < maxx; i++) pwmod[i] = pw(fac[i], mod - 2);
   for (long long j = 0; j < sqr; j++) {
     dp[j][j][1] = dp[j][j][0] = 1;
     for (long long i = j + 1; i < maxx; i++) {
       dp[i][j][0] = (((dp[i - 1][j][0] * 26)  mod) +
                      (j >= 1 ? dp[i - 1][j - 1][1] : 0))
                     mod;
       dp[i][j][1] = (((dp[i - 1][j][1] * 25)  mod) +
                      (j >= 1 ? dp[i - 1][j - 1][1] : 0))
                     mod;
     }
   }
   long long c = 0;
   cin >> n >> s;
   len = s.length();
   if (len >= sqr) {
     fill(tmp, tmp + maxx, 0);
     tmp[len - 1] = 1;
     for (long long j = len; j < maxx; j++)
       tmp[j] = (((tmp[j - 1] * 26ll)  mod) +
                 (((long long)sel(j, len - 1) * pw25[j + 1 - len])  mod))
                mod;
   }
   for (long long i = 0; i < n; i++) {
     long long type;
     cin >> type;
     if (type == 1) {
       cin >> s, len = s.length();
       if (len >= sqr) {
         fill(tmp, tmp + maxx, 0);
         tmp[len - 1] = 1;
         for (long long j = len; j < maxx; j++)
           tmp[j] = (((tmp[j - 1] * 26ll)  mod) +
                     (((long long)sel(j, len - 1) * pw25[j + 1 - len])  mod))
                    mod;
       }
     } else {
       c++;
       cin >> q;
       if (len < sqr) {
         if (len > q)
           cout << 0 << '
';
         else
           cout << dp[q][len][0] << '
';
         continue;
       }
       long long ans = 0ll;
       cout << tmp[q - 1] << '
';
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<array<int, 2>> tree(1);
 int terminal[110];
 unsigned long long inf = (1ull << 63) - 1;
 int s;
 struct Mat {
   vector<unsigned long long> data;
   Mat() { data.assign(s * s, inf); }
 };
 Mat operator*(const Mat& a, const Mat& b) {
   Mat r;
   for (int i = 0; i < s; i++) {
     for (int k = 0; k < s; k++) {
       for (int j = 0; j < s; j++) {
         r.data[i * s + j] =
             min(r.data[i * s + j], a.data[i * s + k] + b.data[k * s + j]);
       }
     }
   }
   return r;
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int g, n, m;
   cin >> g >> n >> m;
   vector<pair<int, vector<int>>> mut;
   vector<vector<vector<int>>> node(g);
   for (int i = 0; i < n; i++) {
     int a, k;
     cin >> a >> k;
     node[a].push_back(vector<int>(k));
     mut.emplace_back(a, vector<int>());
     for (int& v : node[a].back()) {
       cin >> v;
       mut.back().second.push_back(v);
     }
   }
   for (int i = 0; i < m; i++) {
     int k;
     cin >> k;
     int p = 0;
     while (k--) {
       int c;
       cin >> c;
       if (!tree[p][c]) {
         tree[p][c] = tree.size();
         tree.push_back({0, 0});
       }
       p = tree[p][c];
     }
     terminal[p] = 1;
   }
   {
     vector<int> link(tree.size());
     queue<int> q;
     q.push(0);
     while (q.size()) {
       int p = q.front();
       q.pop();
       int par = link[p];
       terminal[p] |= terminal[par];
       for (int c : {0, 1}) {
         if (!tree[p][c]) {
           tree[p][c] = tree[par][c];
         } else {
           link[tree[p][c]] = p ? tree[par][c] : 0;
           q.push(tree[p][c]);
         }
       }
     }
   }
   s = tree.size();
   for (int p = 0; p < s; p++)
     if (terminal[p]) tree[p][0] = tree[p][1] = p;
   vector<Mat> mat(g);
   for (int c : {0, 1}) {
     for (int i = 0; i < s; i++) {
       mat[c].data[i * s + tree[i][c]] = 1;
     }
   }
   vector<int> changed(g, 1);
   while (1) {
     int found = 0;
     vector<int> nchanged(g);
     for (auto& [a, v] : mut) {
       int need = 0;
       for (int b : v)
         if (changed[b]) need = 1;
       if (!need) continue;
       Mat prod = mat[v[0]];
       for (int i = 1; i < (int)v.size(); i++) {
         prod = prod * mat[v[i]];
       }
       for (int i = 0; i < s * s; i++) {
         if (prod.data[i] < mat[a].data[i]) {
           mat[a].data[i] = prod.data[i];
           nchanged[a] = 1;
           found = 1;
         }
       }
     }
     changed = nchanged;
     if (!found) break;
   }
   for (int a = 2; a < g; a++) {
     unsigned long long mi = inf;
     for (int i = 0; i < s; i++) {
       if (!terminal[i]) mi = min(mi, mat[a].data[i]);
     }
     if (mi < inf)
       cout <<  NO   << mi << endl;
     else
       cout <<  YES  << endl;
   }
 }


#include <bits/stdc++.h>
 #pragma GCC optimize  -O3
 using namespace std;
 const int MAXN = 310000;
 int n;
 int a[MAXN];
 vector<int> pr;
 int bb[MAXN];
 int go[MAXN];
 int cc[MAXN];
 int ans[MAXN];
 vector<int> fc[MAXN];
 int gcd(int a, int b) {
   while (b) {
     int q = a  b;
     a = b;
     b = q;
   }
   return a;
 }
 int dp[1 << 7];
 int gg;
 int gog[1 << 7];
 void run(int x, int msk, int ml, int k) {
   if (x == k) {
     dp[msk] = cc[ml];
     gog[msk] = ml;
     return;
   }
   run(x + 1, msk, ml, k);
   run(x + 1, msk + (1 << x), ml * fc[gg][x], k);
 }
 int main() {
   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   for (int i = 0; i < MAXN; ++i) bb[i] = i;
   for (int i = 2; i < MAXN; ++i) {
     if (bb[i] == i) pr.push_back(i);
     for (int j : pr) {
       if (j * i >= MAXN || bb[i] < j) break;
       bb[j * i] = j;
     }
   }
   for (int i = 1; i < MAXN; ++i) {
     int cur = 1;
     int x = i;
     while (x != 1) {
       int d = bb[x];
       while (x  d == 0) x /= d;
       cur *= d;
       fc[i].push_back(d);
     }
     go[i] = cur;
   }
   cin >> n;
   int now = 0;
   fill(ans, ans + MAXN, 1000);
   for (int i = 0; i < n; ++i) {
     cin >> a[i];
     now = gcd(now, a[i]);
     a[i] = go[a[i]];
     ++cc[a[i]];
     ans[a[i]] = 1;
   }
   if (now != 1) {
     cout << -1 <<
 ;
     return 0;
   }
   for (int i = 1; i < MAXN; ++i) {
     for (int j = 2 * i; j < MAXN; j += i) cc[i] += cc[j];
   }
   for (int i = MAXN - 1; i > 1; --i) {
     if (go[i] != i) continue;
     int k = fc[i].size();
     gg = i;
     run(0, 0, 1, k);
     for (int i = (1 << k) - 1; i > 0; --i) {
       for (int j = (i - 1) & i; j > 0; j = (j - 1) & i) dp[j] -= dp[i];
       dp[0] -= dp[i];
     }
     for (int j = 0; j < (1 << k); ++j)
       if (dp[j]) ans[gog[j]] = min(ans[gog[j]], ans[i] + 1);
   }
   cout << ans[1] <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, x, m;
 priority_queue<int> s;
 int main() {
   scanf( d , &n);
   m = n;
   for (int i = 0; i < int(n); i++) {
     scanf( d , &x);
     if (x < m) {
       s.push(x);
       cout <<    ;
     } else if (x == m) {
       cout << x <<    ;
       m--;
       while (!s.empty() && m == s.top()) {
         cout << s.top() <<    ;
         s.pop();
         m--;
       }
     }
     cout << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 char s[12000];
 int n, i, j;
 vector<int> ans;
 int cek(int v, int t, string e) {
   if (v >= strlen(s) - 1) return v;
   int i = v;
   do {
     string tmp =   ;
     for (i = i;; i++) {
       tmp.push_back(s[i]);
       if (s[i] == '>') break;
     }
     i++;
     if (e ==  <table>  && tmp ==  </table> ) break;
     if (e ==  <tr>  && tmp ==  </tr> ) break;
     if (e ==  <td>  && tmp ==  </td> ) {
       ans[t]++;
       break;
     }
     if (tmp ==  <table> ) {
       ans.push_back(0);
       i = cek(i, ans.size() - 1, tmp);
     } else if (tmp ==  <tr> ) {
       i = cek(i, t, tmp);
     } else if (tmp ==  <td> ) {
       i = cek(i, t, tmp);
     }
   } while (i < strlen(s));
   return i;
 }
 int main() {
   n = 0;
   bool f = 1;
   while (scanf( c , &s[n]) != EOF) {
     if (s[n] != '
') n++;
   }
   int k = cek(0, -1,    );
   sort(ans.begin(), ans.end());
   for (i = 0; i < ans.size(); i++) {
     if (f)
       f = 0;
     else
       printf(   );
     cout << ans[i];
   }
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, p, k;
 int a[333333];
 long long ans;
 map<int, int> mp, mpb;
 int main() {
   scanf( ddd , &n, &p, &k);
   for (int i = 1; i <= n; i++) scanf( d , &a[i]);
   for (int i = 1; i <= n; i++) {
     mp[a[i]]++;
   }
   for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {
     if (1ll * ((it->first) + (it->first)) *
             (2ll * (it->first) * (it->first)  p)  p !=
         k)
       ans -= (1ll * (it->second) * ((it->second) - 1));
   }
   for (int i = 1; i <= n; i++) {
     mpb[((1ll * a[i] * a[i]  p * a[i]  p * a[i] - 1ll * k * a[i])  p + p)
         p]++;
   }
   for (map<int, int>::iterator it = mpb.begin(); it != mpb.end(); it++) {
     ans += (1ll * (it->second) * ((it->second) - 1));
   }
   printf( lld
 , ans / 2);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using namespace std::chrono;
 long long fac[1000006];
 inline long long exp(long long x, long long n) {
   long long r = 1;
   x = x;
   while (n) {
     if (n  2) r = (r * x)  10000000000000007;
     x = (x * x)  10000000000000007;
     n = n / 2;
   }
   return r;
 }
 inline long long mmi(long long a) {
   return exp(a, 10000000000000007 - 2)  10000000000000007;
 }
 inline long long fact(long long n) {
   long long res = 1;
   for (long long i = 1; i < (n + 1); ++i) {
     res = (res * i)  10000000000000007;
   }
   return res;
 }
 inline void fact_a() {
   fac[0] = 1;
   fac[1] = 1;
   for (long long i = 1; i < (105); ++i) {
     fac[i] = (fac[i - 1] * i)  10000000000000007;
   }
 }
 inline long long inv_fact(long long n) {
   long long par = fac[n];
   long long res = mmi(par);
   return res;
 }
 inline long long comb(long long n, long long r) {
   if (n == r && r == 0) return 1;
   if (n < r) return 0;
   return ((fac[n] * inv_fact(r))  10000000000000007 * inv_fact(n - r))
          10000000000000007;
 }
 struct triplet {
   long long a, b, c;
 };
 bool operator<(const triplet &t1, const triplet &t2) {
   if (t1.a < t2.a) return true;
   if (t1.a == t2.a && t1.b < t2.b) return true;
   if (t1.a == t2.a && t1.b == t2.b && t1.c < t2.c) return true;
   return false;
 }
 pair<long long, pair<long long, long long> > ex_gcd(long long a, long long b) {
   if (b == 0) {
     return make_pair(a, make_pair(1, 0));
   }
   pair<long long, pair<long long, long long> > p = ex_gcd(b, a  b);
   long long gcd = p.first;
   long long x1 = p.second.first;
   long long y1 = p.second.second;
   long long x = y1;
   long long y = x1 - (a / b) * y1;
   return make_pair(gcd, make_pair(x, y));
 }
 long long prime[3000006];
 long long spf_prime[3000006];
 void sieve() {
   prime[1] = 1;
   for (long long i = 2; i * i <= 3000000; i++)
     if (prime[i] == 0)
       for (long long j = i * i; j <= 3000000; j += i) prime[j] = 1;
 }
 void spf() {
   for (long long i = 2; i * i <= 3000000; i++)
     if (!spf_prime[i])
       for (long long j = i * i; j <= 3000000; j += i)
         if (!spf_prime[j]) spf_prime[j] = i;
   for (long long i = 2; i <= 3000000; i++)
     if (!spf_prime[i]) spf_prime[i] = i;
 }
 long long getparent_BIT(long long idx) { return idx - (idx & -idx); }
 long long getnext_BIT(long long idx) { return idx + (idx & -idx); }
 long long getsum_BIT(long long idx, long long BIT[], long long n) {
   long long sum = 0;
   while (idx > 0) {
     sum += BIT[idx];
     idx = getparent_BIT(idx);
   }
   return sum;
 }
 void update_BIT(long long idx, long long BIT[], long long val, long long n) {
   while (idx <= n) {
     BIT[idx] += val;
     idx = getnext_BIT(idx);
   }
 }
 void build_BIT(long long BIT[], long long a[], long long n) {
   for (long long i = 0; i < (n); ++i) {
     update_BIT(i, BIT, a[i], n);
   }
 }
 void comp_lps(string s, long long lps[], long long n) {
   long long i = 1, j = 0;
   while (i < n) {
     if (s[i] == s[j]) {
       lps[i++] = ++j;
     } else {
       if (j != 0)
         j = lps[j - 1];
       else
         lps[i++] = 0;
     }
   }
 }
 void dfs_l(long long u, vector<vector<long long> > &adj, long long status[]) {
   if (status[u] == 1) return;
   status[u] = 1;
   for (long long i = 0; i < (adj[u].size()); ++i) dfs_l(adj[u][i], adj, status);
 }
 long long dij(long long u, long long n,
               vector<vector<pair<long long, long long> > > &adj,
               long long status[]) {
   long long dist[n];
   for (long long i = 0; i < (n); ++i) dist[i] = 1000000000;
   dist[0] = 0;
   priority_queue<pair<long long, long long>,
                  vector<pair<long long, long long> >,
                  greater<pair<long long, long long> > >
       q;
   q.push(make_pair(0, 0));
   while (!q.empty()) {
     pair<long long, long long> p;
     p = q.top();
     q.pop();
     long long x = p.second;
     long long w = p.first;
     if (status[x] == 1) continue;
     status[x] = 1;
     for (long long i = 0; i < (adj[x].size()); ++i) {
       long long ww = adj[x][i].first;
       long long y = adj[x][i].second;
       if (dist[x] + ww < dist[y]) {
         dist[y] = dist[x] + ww;
         q.push(make_pair(dist[y], y));
       }
     }
   }
   if (dist[n - 1] >= 1000000000) return -1;
   return dist[n - 1];
 }
 long long phi(long long n) {
   vector<long long> v;
   long long k = n;
   ;
   for (long long i = 2; i * i <= n; i++) {
     if (k  i == 0) {
       v.push_back(i);
       while (k  i == 0) k /= i;
     }
   }
   if (k > 1) v.push_back(k);
   long long ans = n;
   for (long long i = 0; i < (v.size()); ++i) ans -= (ans / v[i]);
   return ans;
 }
 struct trie {
   struct trie *left, *right;
   bool isend;
 };
 trie *get_trie() {
   trie *ptr = new trie;
   ptr->left = NULL;
   ptr->right = NULL;
   ptr->isend = false;
   return ptr;
 }
 bool isempty(trie *root) {
   if (root->left == NULL && root->right == NULL) return true;
   return false;
 }
 void insert_trie(trie *root, string key) {
   trie *ptr = root;
   for (long long i = 0; i < (key.size()); ++i) {
     if (key[i] == '0') {
       if (ptr->left == NULL) {
         ptr->left = get_trie();
       }
       ptr = ptr->left;
     } else {
       if (ptr->right == NULL) ptr->right = get_trie();
       ptr = ptr->right;
     }
   }
   ptr->isend = true;
 }
 trie *remove_trie(trie *root, string key, long long idx = 0) {
   if (root == NULL) return NULL;
   if (idx == key.size()) {
     if (isempty(root)) {
       delete (root);
       root = NULL;
     }
     return root;
   }
   if (key[idx] == '0')
     root->left = remove_trie(root->left, key, idx + 1);
   else
     root->right = remove_trie(root->right, key, idx + 1);
   if (isempty(root)) {
     delete (root);
     root = NULL;
   }
   return root;
 }
 long long search_trie(trie *root, string key) {
   trie *ptr = root;
   string s =   ;
   for (long long i = 0; i < (key.size()); ++i) {
     if (key[i] == '0') {
       if (ptr->right != NULL) {
         ptr = ptr->right;
         s += '1';
       } else {
         ptr = ptr->left;
         s += '0';
       }
     } else {
       if (ptr->left != NULL) {
         ptr = ptr->left;
         s += '1';
       } else {
         ptr = ptr->right;
         s += '0';
       }
     }
   }
   long long res = 0;
   reverse(s.begin(), s.end());
   for (long long i = s.length() - 1; i >= (0); --i)
     res = res * 2 + (s[i] - '0');
   return res;
 }
 struct Comp {
   bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) {
     if (a.first != b.first) {
       return a.first < b.first;
     }
     return a.second > b.second;
   }
 };
 void dearr() {
   long long dar[1005];
   dar[0] = 1;
   dar[1] = 0;
   dar[2] = 1;
   for (long long i = 3; i < (1002); ++i) {
     dar[i] = (i - 1) * (dar[i - 1] + dar[i - 2]);
   }
 }
 int main() {
   long long n;
   cin >> n;
   if (n  2 == 0) {
     cout <<  white
          <<
 ;
     cout << 1 <<     << 2 <<
 ;
   } else
     cout <<  black
          <<
 ;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int first, second;
   cin >> second >> first;
   if ((second == 1 && first == 0) || first == 0) {
     cout <<  NO ;
     return 0;
   } else if (first == 1 && second == 0) {
     cout <<  YES ;
     return 0;
   }
   int tot = first;
   int co = first - 1;
   if (first == 1 && second >= 0) {
     cout <<  NO ;
     return 0;
   }
   if ((second - co)  2 == 0 && (second - co) >= 0)
     cout <<  YES ;
   else
     cout <<  NO ;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, x, k, lb, ub, ans = -1;
 int main() {
   long long l, r;
   scanf( lldlldlldlld , &n, &l, &r, &k);
   x = (r >= l ? r - l + 1 : r + n - l + 1)  n;
   for (long long i = k, j, r; i; i = j) {
     j = k / (k / i + 1);
     r = k / i;
     ub = min(2 * n, i);
     lb = max(n, j + 1);
     ub = min(ub, min((2 * n + k - 2 * x + 1) / (r + 1), (k - x) / r));
     lb = max(lb, (k - 2 * x + r - 1) / r);
     if (ub >= lb) ans = max(ans, ub);
   }
   if (x <= k && k <= x * 2) ans = max(ans, n + min(k - x, x - 1) + n - x + 1);
   if (!x && k == n) ans = max(ans, n + 1);
   printf( lld
 , ~ans ? ans - n : ans);
 }


#include <bits/stdc++.h>
 using namespace std;
 const long double epsilon = 1e-9;
 int main() {
   int n;
   cin >> n;
   vector<int> a(n), b(n);
   for (int i = 0; i < n; i++) cin >> a[i];
   for (int i = 0; i < n; i++) cin >> b[i];
   vector<pair<int, int> > moves;
   for (int i = 0; i < n; i++) {
     if (b[i] != a[i]) {
       for (int j = i + 1; j < n; j++) {
         if (b[j] == a[i]) {
           for (int k = j; k > i; k--) {
             moves.push_back(make_pair(k - 1, k));
             swap(b[k], b[k - 1]);
           }
           break;
         }
       }
     }
   }
   cout << moves.size() << endl;
   for (int i = 0; i < moves.size(); i++)
     cout << moves[i].first + 1 <<     << moves[i].second + 1 << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long a, b, c, d, e, first;
   cin >> a >> b >> c >> d >> e >> first;
   b = min(c, b);
   if (d < a && d < b)
     cout << d * max(e, first);
   else {
     long long p = min(a, d) * e + min(d - min(d, a), b) * first;
     long long q = min(b, d) * first + min(d - min(d, b), a) * e;
     cout << max(p, q);
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   long long n;
   cin >> n;
   string s;
   cin >> s;
   for (long long i = 0; i < n - 1; i++) {
     if (s[i] > s[i + 1]) {
       cout <<  YES  << endl;
       cout << i + 1 <<     << i + 2 << endl;
       return 0;
     }
   }
   cout <<  NO  << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 21;
 int a[1 << maxn], n;
 long long ans[maxn][2];
 void mergesort(int l, int r, int dep) {
   if (r - l <= 1) return;
   int m = (l + r) / 2;
   mergesort(l, m, dep - 1);
   mergesort(m, r, dep - 1);
   for (int i = l; i < m; i++) {
     ans[dep][0] += lower_bound(a + m, a + r, a[i]) - a - m;
   }
   for (int i = m; i < r; i++) {
     ans[dep][1] += lower_bound(a + l, a + m, a[i]) - a - l;
   }
   inplace_merge(a + l, a + m, a + r);
 }
 long long solve(int q) {
   long long res = 0;
   while (q) swap(ans[q][0], ans[q][1]), q--;
   for (int i = 1; i <= n; i++) {
     res += ans[i][0];
   }
   return res;
 }
 int main() {
   int m, q;
   cin >> n;
   for (int i = 0; i < 1 << n; i++) scanf( d , &a[i]);
   cin >> m;
   mergesort(0, 1 << n, n);
   for (int i = 0; i < m; i++) {
     scanf( d , &q);
     cout << solve(q) << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double eps = 1e-8;
 const double pi = acos(-1.0);
 const int INF = 0x3f3f3f3f;
 const long long inf = (((long long)1) << 61) + 5;
 const int N = 100005;
 int f[N];
 int g[N];
 int a[N];
 int bit[N];
 int ans[N];
 int sum1(int x) {
   int ans = 0;
   for (int i = x; i > 0; i -= i & -i) ans = max(bit[i], ans);
   return ans;
 }
 void add1(int x, int val) {
   for (int i = x; i <= N; i += i & -i) bit[i] = max(bit[i], val);
 }
 int sum2(int x) {
   int ans = 0;
   for (int i = x; i <= N; i += i & -i) ans = max(bit[i], ans);
   return ans;
 }
 void add2(int x, int val) {
   for (int i = x; i > 0; i -= i & -i) bit[i] = max(bit[i], val);
 }
 int main() {
   int n, res = 0;
   scanf( d , &n);
   for (int i = 1; i <= n; i++) {
     scanf( d , &a[i]);
     int x = sum1(a[i] - 1);
     f[i] = x + 1;
     if (f[i] > res) res = f[i];
     add1(a[i], f[i]);
   }
   memset(bit, 0, sizeof bit);
   for (int i = n; i >= 1; i--) {
     int x = sum2(a[i] + 1);
     g[i] = x + 1;
     add2(a[i], g[i]);
   }
   vector<int> q[N];
   for (int i = 1; i <= n; i++) {
     if (f[i] + g[i] - 1 < res)
       ans[i] = 1;
     else
       q[f[i]].push_back(i);
   }
   for (int i = 1; i <= res; i++) {
     int sz = q[i].size();
     for (int j = 0; j < sz; j++) {
       int v = q[i][j];
       if (sz == 1)
         ans[v] = 3;
       else
         ans[v] = 2;
     }
   }
   for (int i = 1; i <= n; i++) printf( d , ans[i]);
   puts(  );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 0x3f3f3f3f;
 template <typename T>
 inline void read(T &x) {
   x = 0;
   T fl = 1;
   char ch = 0;
   for (; ch < '0' || ch > '9'; ch = getchar())
     if (ch == '-') fl = -1;
   for (; ch >= '0' && ch <= '9'; ch = getchar())
     x = (x << 1) + (x << 3) + (ch ^ 48);
   x *= fl;
 }
 template <typename T, typename... Args>
 inline void read(T &x, Args &...args) {
   read(x);
   read(args...);
 }
 const int N = 1e5 + 5;
 struct data {
   int s, m, r, t;
   data(int x = 0) { t = x; }
   bool operator<(const data &b) const { return t < b.t; }
   long long calc(long long tim) { return min(s + tim * r, m * 1ll); }
 } a[18][N];
 struct seg {
   int trt[N << 2];
   long long trm[18][N << 2], trr[18][N << 2];
   void pushdown(int nod) {
     if (trt[nod] >= 0) trt[(nod << 1)] = trt[(nod << 1 | 1)] = trt[nod];
   }
   void pushup(int nod) {
     if (trt[(nod << 1)] != trt[(nod << 1 | 1)])
       trt[nod] = -1;
     else
       trt[nod] = trt[(nod << 1)];
   }
   void build(int nod, int l, int r, int dep) {
     trt[nod] = -2;
     if (l == r) {
       read(a[dep][l].s, a[dep][l].m, a[dep][l].r);
       if (a[dep][l].r == 0)
         a[dep][l].t = inf;
       else
         a[dep][l].t = a[dep][l].m  a[dep][l].r == 0
                           ? a[dep][l].m / a[dep][l].r
                           : a[dep][l].m / a[dep][l].r + 1;
       trm[dep][l] = trm[dep][l - 1] + a[dep][l].m;
       trr[dep][l] = trr[dep][l - 1] + a[dep][l].r;
       return;
     }
     int mid = (l + r) >> 1;
     build((nod << 1), l, mid, dep + 1);
     build((nod << 1 | 1), mid + 1, r, dep + 1);
     for (int i = (l); i <= (r); i++) a[dep][i] = a[dep + 1][i];
     sort(a[dep] + l, a[dep] + r + 1);
     for (int i = (l); i <= (r); i++) {
       trm[dep][i] = trm[dep][i - 1] + a[dep][i].m;
       trr[dep][i] = trr[dep][i - 1] + a[dep][i].r;
     }
   }
   long long query(int tim, int nod, int l, int r, int ql, int qr, int dep) {
     long long res = 0;
     if (ql <= l && r <= qr && trt[nod] != -1) {
       if (trt[nod] == -2)
         for (int i = (l); i <= (r); i++) res += a[dep][i].calc(tim);
       else {
         int i = upper_bound(a[dep] + l, a[dep] + 1 + r, data(tim - trt[nod])) -
                 a[dep] - 1;
         res = (tim - trt[nod]) * (trr[dep][r] - trr[dep][i]) + trm[dep][i] -
               trm[dep][l - 1];
       }
       trt[nod] = tim;
       return res;
     }
     pushdown(nod);
     int mid = (l + r) >> 1;
     if (ql <= mid) res += query(tim, (nod << 1), l, mid, ql, qr, dep + 1);
     if (qr > mid)
       res += query(tim, (nod << 1 | 1), mid + 1, r, ql, qr, dep + 1);
     pushup(nod);
     return res;
   }
 } sgt;
 int n, m;
 int main() {
   read(n);
   sgt.build(1, 1, n, 0);
   read(m);
   for (int _ = (1); _ <= (m); _++) {
     int t, l, r;
     read(t);
     read(l);
     read(r);
     printf( lld
 , sgt.query(t, 1, 1, n, l, r, 0));
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long a, i, j, n, aux, cnt, ans, div1[10000010], v[10000010];
 int main() {
   cin >> a >> n;
   v[1] = 1;
   for (i = 3; i * i <= a + n - 1; i += 2)
     if (!div1[i]) {
       div1[i] = i;
       for (j = i * i; j <= a + n - 1; j += 2 * i) div1[j] = i;
     }
   for (i = 2; i <= a + n - 1; i += 2) div1[i] = 2;
   for (i = 2; i <= a + n - 1; i++) {
     aux = i;
     cnt = 0;
     if (!div1[i]) div1[i] = i;
     while (aux  div1[i] == 0) aux /= div1[i], cnt++;
     v[i] = v[aux];
     if (cnt & 1) v[i] *= div1[i];
   }
   for (i = a; i <= a + n - 1; i++) ans += v[i];
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast )
 #pragma GCC optimize( unroll-loops )
 #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )
 using namespace std;
 vector<long long> v;
 unordered_map<long long, long long> m;
 long long falla(long long n) {
   if (m.count(n)) {
     return m[n];
   }
   long long ans;
   long long k = 0;
   for (int j = n - 1; j >= 1; j--) {
     if (n  j == 0) {
       ans = j;
       break;
     }
     if (n  (n - j + 1) == 0) {
       ans = n / (n - j + 1);
       break;
     }
   }
   m[ans] = ans;
   return ans;
 }
 int main() {
   long long casos;
   cin >> casos;
   long long num = pow(2, 25) - 1;
   for (int i = 1; i < 30; i++) {
     v.push_back((1 << i) - 1);
   }
   long long flag = 0;
   while (casos--) {
     long long num;
     long long ans1;
     cin >> num;
     if (m.count(num)) {
       cout << m[num] << endl;
       flag = 1;
     }
     if (flag == 0) {
       ans1 = lower_bound((v).begin(), (v).end(), num) - v.begin();
       if (num == v[ans1]) {
         ans1 = falla(num);
         m[num] = ans1;
         cout << ans1 << endl;
       } else {
         m[num] = v[ans1];
         cout << v[ans1] << endl;
       }
     }
     flag = 0;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 long long dp[200005][2];
 bool vst[200005][2];
 long long A[200005], n;
 long long go(long long v, bool b) {
   if (vst[v][b]) return dp[v][b];
   vst[v][b] = true;
   long long val = 0;
   if (!b) {
     if ((v - A[v]) > 1)
       val = go(v - A[v], b ^ 1);
     else if ((v - A[v]) == 1)
       val = -1;
   } else {
     if ((v + A[v]) <= n) val = go(v + A[v], b ^ 1);
   }
   if (val != -1)
     dp[v][b] = A[v] + val;
   else
     dp[v][b] = -1;
   return dp[v][b];
 }
 int main() {
   long long i;
   cin >> n;
   for (i = (2); i <= (n); i++) {
     cin >> A[i];
   }
   memset((vst), (0), sizeof(vst));
   long long j;
   memset((dp), (-1), sizeof(dp));
   for (i = (2); i <= (n); i++) {
     go(i, 0);
     if (dp[i][0] != -1)
       cout << dp[i][0] + i - 1 << endl;
     else
       cout << -1 << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double eps = 1e-10;
 const double Pi = 3.1415926535897932;
 const int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1};
 const int maxn = 1e4 + 5;
 struct EDGE {
   int a, b;
   int A, B;
 } edge[maxn];
 int n, m;
 int last[maxn];
 vector<int> G[maxn], tree[maxn];
 int d[maxn];
 int A[maxn], B[maxn];
 bool vis[maxn];
 vector<int> ans;
 int in[maxn];
 void dfs_tree(int a, int fa) {
   vis[a] = true;
   for (int i = 0; i < G[a].size(); i++) {
     int p = G[a][i];
     if (p == last[a]) continue;
     int b = edge[p].a ^ edge[p].b ^ a;
     if (!vis[b]) {
       tree[a].push_back(p);
       in[p] = true;
       d[b] = d[a] + 1;
       last[b] = p;
       dfs_tree(b, a);
     } else if (d[a] > d[b]) {
       if (d[a] - d[b] + 1 & 1) {
         ans.push_back(p);
         B[a]++;
         B[b]--;
       } else {
         A[a]++;
         A[b]--;
       }
     }
   }
 }
 void dfs(int a) {
   vis[a] = true;
   for (int i = 0; i < tree[a].size(); i++) {
     int p = tree[a][i];
     int b = edge[p].a ^ edge[p].b ^ a;
     if (!vis[b]) dfs(b);
     A[a] += A[b];
     B[a] += B[b];
   }
   edge[last[a]].A = A[a];
   edge[last[a]].B = B[a];
 }
 int main() {
   scanf( dd , &n, &m);
   for (int i = 1; i <= m; i++) {
     int a, b;
     scanf( dd , &a, &b);
     edge[i] = EDGE{a, b};
     G[a].push_back(i);
     G[b].push_back(i);
   }
   for (int i = 1; i <= n; i++) {
     if (!vis[i]) dfs_tree(i, -1);
   }
   memset(vis, false, sizeof(vis));
   for (int i = 1; i <= n; i++) {
     if (!vis[i]) dfs(i);
   }
   if (ans.size() == 0) {
     for (int i = 1; i <= m; i++) ans.push_back(i);
   } else if (ans.size() == 1) {
     for (int i = 1; i <= m; i++)
       if (in[i]) {
         if (edge[i].A == 0 && edge[i].B) ans.push_back(i);
       }
   } else {
     int t = ans.size();
     ans.clear();
     for (int i = 1; i <= m; i++)
       if (in[i]) {
         if (edge[i].B) {
           if (edge[i].B == t && edge[i].A == 0) ans.push_back(i);
         }
       }
   }
   sort(ans.begin(), ans.end());
   printf( d
 , ans.size());
   for (int i = 0; i < ans.size(); i++)
     printf( d , ans[i]), putchar(i == ans.size() - 1 ? '
' : ' ');
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 pair<long long, long long> a[200];
 int n;
 int main() {
   cin >> n;
   for (int i = 1; i <= n; i++) {
     cin >> a[i].second;
     long long tmp = a[i].second;
     while (tmp  3 == 0) {
       a[i].first--;
       tmp /= 3;
     }
   }
   sort(a + 1, a + n + 1);
   for (int i = 1; i <= n; i++) cout << a[i].second <<    ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long arr[3];
   scanf( extraextraextra , &arr[0], &arr[1], &arr[2]);
   sort(arr, arr + 3);
   if (arr[0] == arr[1] && arr[1] == arr[2])
     printf( 0
 );
   else if (arr[2] == arr[1] && arr[1] > arr[0]) {
     printf( extra
 , arr[2] - arr[0] - 1);
   } else if (arr[2] > arr[1] && arr[1] == arr[0]) {
     printf( extra
 , (arr[2] - arr[1] - 1) + (arr[2] - arr[0] - 1));
   } else if (arr[2] > arr[1] && arr[1] > arr[0]) {
     printf( extra
 , (arr[2] - arr[1] - 1) + (arr[2] - arr[0] - 1));
   }
 }