#include <bits/stdc++.h>
 using namespace std;
 template <class T1>
 void debug(T1 e) {
   cout << e << endl;
 }
 template <class T1, class T2>
 void debug(T1 e1, T2 e2) {
   cout << e1 <<  	  << e2 << endl;
 }
 template <class T1, class T2, class T3>
 void debug(T1 e1, T2 e2, T3 e3) {
   cout << e1 <<  	  << e2 <<  	  << e3 << endl;
 }
 template <class T1, class T2, class T3, class T4>
 void debug(T1 e1, T2 e2, T3 e3, T4 e4) {
   cout << e1 <<  	  << e2 <<  	  << e3 <<  	  << e4 << endl;
 }
 template <class T1, class T2, class T3, class T4, class T5>
 void debug(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
   cout << e1 <<  	  << e2 <<  	  << e3 <<  	  << e4 <<  	  << e5 << endl;
 }
 template <class T1, class T2, class T3, class T4, class T5, class T6>
 void debug(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
   cout << e1 <<  	  << e2 <<  	  << e3 <<  	  << e4 <<  	  << e5 <<
        << e6 << endl;
 }
 template <class T>
 void debug(vector<vector<T> > e, int row, int col) {
   int i, j;
   for (i = 0; i < row; i++) {
     for (j = 0; j < col; j++) cout << e[i][j] <<    ;
     cout << endl;
   }
   cout << endl;
 }
 template <class T>
 void debug(vector<basic_string<T> > e, int row, int col) {
   int i, j;
   for (i = 0; i < row; i++) {
     for (j = 0; j < col; j++) cout << e[i][j];
     cout << endl;
   }
   cout << endl;
 }
 template <class T>
 void debug(T e[110][110], int row, int col) {
   int i, j;
   for (i = 0; i < row; i++) {
     for (j = 0; j < col; j++) cout << e[i][j] <<    ;
     cout << endl;
   }
 }
 template <class T>
 string toString(T n) {
   ostringstream oss;
   oss << n;
   oss.flush();
   return oss.str();
 }
 int toInt(string s) {
   int r = 0;
   istringstream sin(s);
   sin >> r;
   return r;
 }
 bool isVowel(char ch) {
   ch = tolower(ch);
   if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
     return true;
   return false;
 }
 bool isUpper(char c) { return c >= 'A' && c <= 'Z'; }
 bool isLower(char c) { return c >= 'a' && c <= 'z'; }
 int n;
 int arr[2000];
 int main() {
   int n;
   while (cin >> n) {
     int i;
     for (i = 1; i <= n; i++) cin >> arr[i];
     if (n  2 == 0 || n == 1) {
       cout <<  -1  << endl;
       continue;
     }
     int ans = 0;
     for (i = n - 1; i > 1; i -= 2) {
       int ma = max(arr[i], arr[i + 1]);
       arr[i] = 0;
       arr[i + 1] = 0;
       arr[i / 2] -= ma;
       arr[i / 2] = max(0, arr[i / 2]);
       ans += ma;
     }
     ans += arr[1];
     cout << ans << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int read() {
   char c = getchar();
   int d = 0, f = 1;
   for (; c < '0' || c > '9'; c = getchar())
     if (c == '-') f = -1;
   for (; c >= '0' && c <= '9'; d = d * 10 + c - 48, c = getchar())
     ;
   return d * f;
 }
 int r, d, n;
 const int N = 100001;
 struct xint {
   int x, y, r;
 } a[N];
 int main() {
   r = read(), d = read(), n = read();
   int ans = 0;
   for (int i = 1; i <= n; ++i) {
     a[i].x = read(), a[i].y = read(), a[i].r = read();
     int dis = a[i].x * a[i].x + a[i].y * a[i].y;
     if (dis >= (r - d + a[i].r) * (r - d + a[i].r) && r >= a[i].r &&
         dis <= (r - a[i].r) * (r - a[i].r))
       ans++;
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 0x3f3f3f3f;
 const double PI = acos(-1.0);
 const double E = exp(1);
 const double EPS = 1e-5;
 const int maxn = 2000 + 5;
 int n, m;
 char mp[maxn][maxn] = {0};
 int dx[] = {1, 0, 0, -1};
 int dy[] = {0, 1, -1, 0};
 int cnt = 0;
 bool check(int x, int y) {
   if (x < 0 || x >= m || y < 0 || y >= n || mp[x][y] != '.') return false;
   return true;
 }
 void dfs(int x, int y) {
   if (!check(x, y)) return;
   int num = 0;
   int dir;
   for (int i = 0; i < (4); i++) {
     int xx = x + dx[i];
     int yy = y + dy[i];
     if (check(xx, yy)) {
       dir = i;
       num++;
     }
   }
   if (num == 1) {
     if (dir == 0) {
       mp[x][y] = '^';
       mp[x + dx[dir]][y + dy[dir]] = 'v';
     } else if (dir == 1) {
       mp[x][y] = '<';
       mp[x + dx[dir]][y + dy[dir]] = '>';
     } else if (dir == 2) {
       mp[x][y] = '>';
       mp[x + dx[dir]][y + dy[dir]] = '<';
     } else if (dir == 3) {
       mp[x][y] = 'v';
       mp[x + dx[dir]][y + dy[dir]] = '^';
     }
     cnt += 2;
     for (int i = 0; i < (4); i++) dfs(x + dx[i] + dx[dir], y + dy[i] + dy[dir]);
   }
 }
 int main(void) {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cin >> m >> n;
   for (int i = 0; i < (m); i++) cin >> mp[i];
   for (int i = 0; i < (m); i++)
     for (int j = 0; j < (n); j++) {
       if (mp[i][j] == '*') cnt++;
       dfs(i, j);
     }
   if (cnt != m * n)
     puts( Not unique );
   else
     for (int i = 0; i < (m); i++) cout << mp[i] << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using LL = long long;
 using pss = pair<string, string>;
 using pis = pair<int, string>;
 const int maxn = 300300;
 int n;
 LL val[maxn], mask[maxn], sum;
 signed main() {
   while (cin >> n) {
     sum = 0;
     for (int i = 1; i <= n; i++) {
       cin >> val[i] >> mask[i];
       sum += val[i];
     }
     for (int i = 1; i <= n; i++) {
       if (sum < 0) {
         val[i] = -val[i];
       }
     }
     LL ret = 0;
     for (int k = 0; k < 62; k++) {
       LL tot = 0;
       for (int i = 1; i <= n; i++) {
         if (mask[i] == (1LL << k)) {
           tot += val[i];
         }
       }
       if (tot > 0) ret |= (1LL << k);
       for (int i = 1; i <= n; i++) {
         if ((1LL << k) & mask[i]) {
           mask[i] ^= (1LL << k);
           if (tot > 0) {
             val[i] = -val[i];
           }
         }
       }
     }
     cout << ret << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename Arg1>
 void __f(const char* name, Arg1&& arg1) {
   cerr << name <<   :   << arg1 << std::endl;
 }
 template <typename Arg1, typename... Args>
 void __f(const char* names, Arg1&& arg1, Args&&... args) {
   const char* comma = strchr(names + 1, ',');
   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;
   __f(comma + 1, args...);
 }
 bool isprime(int n) {
   for (int i = 2; i * i <= n; i++)
     if (n  i == 0) return false;
   return true;
 }
 int main() {
   int n;
   scanf( d , &n);
   int ans = 0;
   if (n <= 3)
     ans = 1;
   else if (n  2 == 0)
     ans = 2;
   else if (isprime(n))
     ans = 1;
   else if (isprime(n - 2))
     ans = 2;
   else
     ans = 3;
   printf( d
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool prime[100001];
 bool ispoweroftwo(long long int x) { return x && !(x & (x - 1)); }
 long long int xorcal(long long int n) {
   if (n  4 == 0) return n;
   if (n  4 == 1) return 1;
   if (n  4 == 2) return n + 1;
   if (n  4 == 3) return 0;
 }
 void sieve(long long int n) {
   memset(prime, true, sizeof(prime));
   prime[0] = false;
   prime[1] = false;
   for (long long int i = 2; i * i <= n; i++) {
     if (prime[i] == true) {
       for (long long int j = i * i; j <= n; j += i) {
         prime[j] = false;
       }
     }
   }
 }
 bool isprime(long long int n) {
   if (n <= 1) return false;
   if (n <= 3) return true;
   if (n  2 == 0 or n  3 == 0) return false;
   for (long long int i = 5; i * i <= n; i += 6) {
     if (n  i == 0 or n  (i + 2) == 0) return false;
   }
   return true;
 }
 long long int modinverse(long long int a, long long int m) {
   long long int m0 = m;
   long long int y = 0, x = 1;
   if (m == 1) return 0;
   while (a > 1) {
     long long int q = a / m;
     long long int t = m;
     m = a  m;
     a = t;
     t = y;
     y = x - q * y;
     x = t;
   }
   if (x < 0) x += m0;
   return x;
 }
 long long int gcd(long long int a, long long int b) {
   if (a == 0) {
     return b;
   }
   return (b  a, a);
 }
 long long int power(long long int A, long long int B) {
   if (A == 0) return 0;
   if (B == 0) return 1;
   long long int y;
   if (B  2 == 0) {
     y = power(A, B / 2);
     y = (y * y)  1000000007;
   } else {
     y = A  1000000007;
     y = (y * power(A, B - 1)  1000000007)  1000000007;
   }
   return (long long int)((y + 1000000007)  1000000007);
 }
 int main() {
   ios_base::sync_with_stdio(false);
   long long int n;
   cin >> n;
   string s;
   cin >> s;
   char f[10];
   for (long long int i = 1; i < 10; i++) {
     cin >> f[i];
   }
   long long int fl = 0;
   for (long long int i = 0; i < n; i++) {
     if (s[i] < f[s[i] - '0']) {
       s[i] = f[s[i] - '0'];
       fl = 1;
     } else if (fl == 1 and s[i] > f[s[i] - '0']) {
       break;
     }
   }
   cout << s << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 100010;
 int n, m, pnt[N], vis[N];
 long long vsum[N], esum[N], vcnt[N];
 pair<pair<int, int>, pair<int, int> > edge[N];
 vector<int> edge2[N];
 int find(int x) {
   if (x != pnt[x]) pnt[x] = find(pnt[x]);
   return pnt[x];
 }
 void dfs(int u, int root) {
   vis[u] = root;
   vsum[u] = vcnt[u];
   for (int i = 0; i < (int)(edge2[u]).size(); ++i) {
     int v = edge2[u][i];
     if (vis[v]) continue;
     dfs(v, root);
     vsum[u] += vsum[v];
   }
 }
 void solve() {
   int u, v, w;
   m = n - 1;
   memset(esum, 0, sizeof(esum));
   for (int i = 0; i < n; ++i) {
     vcnt[i] = 1;
     pnt[i] = i;
   }
   for (int i = 0; i < m; ++i) {
     scanf( ddd , &u, &v, &w);
     edge[i] = make_pair(make_pair(w, i), make_pair(u - 1, v - 1));
   }
   sort(edge, edge + m);
   for (int i = 0; i < m; ++i) {
     int j = i + 1;
     for (; j < m; ++j)
       if (edge[i].first.first != edge[j].first.first) break;
     set<int> s;
     for (int k = i; k < j; ++k) {
       s.insert(find(edge[k].second.first));
       s.insert(find(edge[k].second.second));
     }
     vector<int> vt((s).begin(), (s).end());
     for (int k = 0; k < (int)(vt).size(); ++k) {
       vsum[vt[k]] = vis[vt[k]] = 0;
       edge2[vt[k]] = vector<int>();
     }
     for (int k = i; k < j; ++k) {
       int p = find(edge[k].second.first);
       int q = find(edge[k].second.second);
       edge2[p].push_back(q);
       edge2[q].push_back(p);
     }
     for (int k = 0; k < (int)(vt).size(); ++k) {
       if (vis[vt[k]]) continue;
       dfs(vt[k], vt[k] + 1);
     }
     for (int k = i; k < j; ++k) {
       int p = find(edge[k].second.first);
       int q = find(edge[k].second.second);
       long long c = min(vsum[p], vsum[q]);
       esum[edge[k].first.second] = 2 * c * (vsum[vis[p] - 1] - c);
     }
     for (int k = i; k < j; ++k) {
       int p = find(edge[k].second.first);
       int q = find(edge[k].second.second);
       pnt[p] = q;
       vcnt[q] += vcnt[p];
     }
     i = j - 1;
   }
   long long ans = 0;
   int ct = 0;
   for (int i = 0; i < m; ++i) {
     if (ans < esum[i]) {
       ans = esum[i];
       ct = 1;
     } else if (ans == esum[i]) {
       ct++;
     }
   }
   printf(
        extra
         d
 ,
       ans, ct);
   bool first = true;
   for (int i = 0; i < m; ++i) {
     if (esum[i] != ans) continue;
     if (!first)
       printf(   );
     else
       first = false;
     printf( d , i + 1);
   }
   puts(  );
 }
 int main() {
   while (scanf( d , &n) != EOF) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   bool v[60], h[60];
   int a, b, n;
   while (cin >> n) {
     memset(v, false, sizeof(v));
     memset(h, false, sizeof(h));
     for (int i = 1; i <= n * n; i++) {
       cin >> a >> b;
       if (i == 1) {
         cout << 1;
         h[a] = true;
         v[b] = true;
       } else if (h[a] == false && v[b] == false) {
         h[a] = true;
         v[b] = true;
         cout <<     << i;
       }
     }
     cout << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename S, typename T>
 ostream &operator<<(ostream &os, pair<S, T> &m) {
   os << '[' << m.first <<     << m.second << ']';
   return os;
 }
 int n;
 vector<int> v;
 bool func(int k) {
   int x = k - 1, y = n - 1;
   for (int i = x; i >= 0; --i) {
     if (2 * v[x] > v[y]) return false;
     x--, y--;
   }
   return true;
 }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0), cout.tie(0);
   cin >> n;
   v.resize(n);
   for (int i = 0; i < n; ++i) cin >> v[i];
   sort(begin(v), end(v));
   int lo = 0, hi = n / 2, ans = 0;
   while (lo <= hi) {
     int mid = (lo + hi) / 2;
     if (func(mid)) {
       ans = mid;
       lo = mid + 1;
     } else
       hi = mid - 1;
   }
   cout << n - ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m, k;
 vector<int> v[1000010];
 vector<int> vv;
 bool visit[1000010] = {0};
 int t, tt;
 int res = 0;
 void dfs(int x) {
   visit[x] = 1;
   t++;
   for (int i = 0; i < v[x].size(); i++) {
     int xi = v[x][i];
     if (!visit[xi]) dfs(xi);
   }
 }
 int main() {
   scanf( ddd , &n, &m, &k);
   for (int i = 0; i < m; i++) {
     int x, y;
     scanf( dd , &x, &y);
     x--, y--;
     v[x].push_back(y);
     v[y].push_back(x);
   }
   for (int i = 0; i < n; i++) {
     if (!visit[i]) {
       t = 0;
       dfs(i);
       vv.push_back(min(t, k));
     }
   }
   if (k == 1) {
     cout << max(0, (int)(vv.size() - 2));
     return 0;
   }
   sort(vv.begin(), vv.end());
   reverse(vv.begin(), vv.end());
   tt = vv[0];
   for (int i = 1; i < vv.size(); i++) {
     if (tt)
       tt += vv[i] - 2;
     else {
       tt++;
       res++;
     }
   }
   cout << res;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 4000 + 1;
 const int sq = 100;
 const long long int mod = 1e9 + 7;
 const long long int inf = 4000 + 1;
 unordered_map<long long int, int> dp;
 int ps[N], n;
 inline int get(int l, int r) { return ps[r] - ps[l]; }
 int solve(int l, int r, int k, bool bol) {
   if (r - l < k || l >= r || r > n || l < 0) return 0;
   if (r - l == k && bol) return get(l, r);
   if (r - l == k) return -get(l, r);
   long long int key = l * N * sq * 2 + r * sq * 2 + k * 2 + bol;
   if (dp.count(key)) return dp[key];
   int ans, x, y;
   if (bol) {
     x = solve(l + k, r, k, 0) + get(l, l + k);
     y = solve(l + k + 1, r, k + 1, 0) + get(l, l + k + 1);
     ans = max(x, y);
   } else {
     x = solve(l, r - k, k, 1) - get(r - k, r);
     y = solve(l, r - k - 1, k + 1, 1) - get(r - k - 1, r);
     ans = min(x, y);
   }
   return dp[key] = ans;
 }
 int main() {
   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   dp.rehash(16e6);
   scanf( d , &n);
   for (int i = 0; i < n; i++) {
     int x;
     scanf( d , &x);
     ps[i + 1] = ps[i] + x;
   }
   printf( d
 , solve(0, n, 1, 1));
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void init() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
 }
 void skipInputLine() { cin.ignore(numeric_limits<streamsize>::max(), '
'); }
 template <typename TYPE>
 TYPE readNum() {
   TYPE item;
   cin >> item;
   return item;
 }
 template <typename COLLECTION>
 COLLECTION readNums(size_t count) {
   COLLECTION collection;
   typename COLLECTION::value_type item;
   for (size_t i = 0; i < count; i++) {
     cin >> item;
     collection.insert(item);
   }
   return collection;
 }
 template <typename COLLECTION>
 void writeNums(const COLLECTION &collection) {
   for (auto item : collection) {
     cout << item << ' ';
   }
   cout << endl;
 }
 struct Datum {
   Datum() {}
   Datum(uint32_t _x, uint32_t _count) : x(_x), count(_count) {}
   uint32_t x;
   uint32_t count;
 };
 void pass(const vector<Datum> &data, uint32_t k, vector<Datum> &ranges) {
   uint32_t idx_left = 0, idx_right = 0;
   uint32_t left_value = 0;
   while (idx_left < data.size() && idx_right < data.size()) {
     while (idx_right < data.size()) {
       if (idx_right + 1 < data.size() &&
           data[idx_right + 1].x <= data[idx_left].x + k) {
         idx_right++;
       } else {
         break;
       }
     }
     ranges.push_back(
         Datum(data[idx_left].x, data[idx_right].count - left_value));
     left_value = data[idx_left].count;
     idx_left++;
   }
 }
 uint32_t calc(uint32_t n, uint32_t k) {
   map<uint32_t, uint32_t> xs;
   for (size_t i = 0; i < n; i++) {
     uint32_t x;
     cin >> x;
     xs[x]++;
   }
   skipInputLine();
   skipInputLine();
   uint32_t cumulative = 0;
   vector<Datum> data(xs.size());
   uint32_t index = 0;
   for (map<uint32_t, uint32_t>::const_iterator it = xs.begin(); it != xs.end();
        it++) {
     cumulative += it->second;
     data[index++] = Datum(it->first, cumulative);
   }
   xs.clear();
   uint32_t width = data[data.size() - 1].x - data[0].x + 1;
   if (width <= 2 * (k + 1)) {
     return n;
   }
   vector<Datum> ranges;
   ranges.reserve(2 * data.size());
   pass(data, k, ranges);
   data.clear();
   map<uint32_t, uint32_t> best_sums;
   uint32_t bs = 0;
   for (size_t i = 0; i < ranges.size(); i++) {
     const Datum &range = ranges[i];
     bs = max(bs, range.count);
     best_sums[range.x] = bs;
   }
   uint32_t best_sum = 0;
   for (size_t i = 1; i < ranges.size(); i++) {
     const Datum &range = ranges[i];
     uint32_t sum = range.count;
     int32_t x = int32_t(range.x) - int32_t(k + 1);
     if (x < 0) {
       x = 0;
     }
     map<uint32_t, uint32_t>::const_iterator it = best_sums.upper_bound(x);
     if (it != best_sums.cbegin()) {
       it--;
       best_sum = max(best_sum, sum + it->second);
     }
   }
   return best_sum;
 }
 int main() {
   init();
   uint32_t t = readNum<uint32_t>();
   for (uint32_t i = 0; i < t; i++) {
     uint32_t n, k;
     cin >> n >> k;
     uint32_t res = calc(n, k);
     cout << res << '
';
   }
   cout << flush;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline long long read() {
   register long long x = 0, f = 1;
   char ch = getchar();
   while (!isdigit(ch)) {
     if (ch == '-') f = -1;
     ch = getchar();
   }
   while (isdigit(ch)) {
     x = (x << 1) + (x << 3) + (ch ^ 48);
     ch = getchar();
   }
   return x * f;
 }
 const long long N = 1e5 + 10;
 const long long M = N;
 const long long INF = 1e16;
 struct edge {
   long long u, v, w, next;
   bool operator<(const edge &x) const { return w < x.w; }
 } e[M << 1];
 long long head[N], cnt;
 void add(long long u, long long v, long long w = 0) {
   e[++cnt] = (edge){u, v, w, head[u]};
   head[u] = cnt;
 }
 long long n, m, k, ans = INF;
 long long dis[N], s[N], from[N];
 bool vis[N];
 struct node {
   long long u, d;
   bool operator<(const node &x) const { return d > x.d; }
 };
 priority_queue<node> q;
 void Dij() {
   for (long long i = 1; i <= n; i++) from[i] = vis[i] = 0, dis[i] = INF;
   for (long long i = 1; i <= k; i++)
     from[s[i]] = s[i], dis[s[i]] = 0, q.push((node){s[i], 0});
   while (!q.empty()) {
     long long u = q.top().u;
     q.pop();
     if (vis[u]) continue;
     vis[u] = 1;
     for (long long i = head[u]; i; i = e[i].next) {
       long long v = e[i].v;
       if (vis[v]) continue;
       if (dis[v] > dis[u] + e[i].w) {
         dis[v] = dis[u] + e[i].w;
         from[v] = from[u];
         q.push((node){v, dis[v]});
       }
     }
   }
 }
 long long fa[N];
 long long find(long long x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
 void krus() {
   for (long long i = 1; i <= cnt; i++) {
     e[i].w += dis[e[i].u] + dis[e[i].v];
     e[i].u = from[e[i].u], e[i].v = from[e[i].v];
   }
   sort(e + 1, e + cnt + 1);
   for (long long i = 1; i <= cnt; i++) {
     long long fx = find(e[i].u), fy = find(e[i].v);
     if (fx == fy) continue;
     ans += e[i].w;
     fa[fx] = fy;
   }
 }
 signed main() {
   n = read(), m = read();
   for (long long i = 1; i <= n; i++) fa[i] = i;
   for (long long i = 1; i <= m; i++) {
     long long u = read(), v = read(), w = read();
     add(u, v, w), add(v, u, w);
   }
   s[k = 1] = 1;
   Dij();
   k = read();
   for (long long i = 1; i <= k; i++) {
     s[i] = read();
     ans = min(ans, dis[s[i]]);
   }
   Dij();
   krus();
   cout << ans;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   string s;
   int n;
   while (cin >> n) {
     cin >> s;
     int gold = 0, cnt = 0, prev = 0, ans = 0;
     for (auto ch : s) {
       if (ch == 'G')
         gold++, cnt++;
       else
         prev = cnt, cnt = 0;
       ans = max(ans, prev + cnt + 1);
     }
     ans = min(ans, gold);
     cout << ans << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int t;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   cin >> t;
   while (t--) {
     int a, b, c;
     cin >> a >> b >> c;
     if (c == 0) {
       if (a <= b)
         cout << 0 << endl;
       else
         cout << 1 << endl;
       continue;
     } else if (a + c <= b) {
       cout << 0 << endl;
       continue;
     }
     int res;
     if (a == b) {
       res = c / 2;
       if (c  2 == 1) res++;
     } else if (a > b) {
       if (b + c < a)
         res = c + 1;
       else if (b + c == a)
         res = c;
       else {
         if ((b + c - a)  2 == 1)
           res = (b + c - a) / 2 + 1 + a - b;
         else
           res = (b + c - a) / 2 + a - b;
       }
     } else {
       if ((a + c - b)  2 == 1)
         res = (a + c - b) / 2 + 1;
       else
         res = (a + c - b) / 2;
     }
     cout << res << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   std::cin >> n;
   bool letters[26];
   bool d = false;
   int extra = 0;
   for (int i = 0; i < 26; i++) {
     letters[i] = true;
   }
   char action;
   string input =   ;
   for (int i = 0; i < n; i++) {
     cin >> action;
     cin >> input;
     if (action == '!') {
       for (int j = 0; j < 26; j++) {
         if (strchr(input.c_str(), j + 'a') == NULL) {
           letters[j] = false;
         }
       }
       if (d == true) extra++;
     }
     if (action == '.') {
       for (int j = 0; j < 26; j++) {
         if (strchr(input.c_str(), j + 'a') != NULL) {
           letters[j] = false;
         }
       }
     }
     if (action == '?') {
       letters[input[0] - 'a'] = false;
       if (d == true && i < n - 1) extra++;
     }
     if (d == false) {
       int truec = 0;
       for (int j = 0; j < 26; j++) {
         if (letters[j] == true) {
           truec++;
         }
       }
       if (truec == 1) {
         d = true;
       }
     }
   }
   cout << extra << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int M = 100010;
 int n, m;
 struct road {
   int to, th;
   bool f;
 } in;
 struct dot {
   int come_road;
   int come_point;
   bool func;
 } r[M];
 vector<road> work[M];
 vector<road> not_work[M];
 vector<road> rw[M];
 vector<road> rnw[M];
 bool vis[M];
 int d[M];
 int broken_road[M];
 bool inq[M];
 int tot, u;
 int input() {
   int ans = 0;
   char ch;
   while (1) {
     ch = getchar();
     if (ch == ' ' || ch == '
') return ans;
     ans *= 10;
     ans += ch - '0';
   }
   return ans;
 }
 void output(int out) {
   if (out == 0) {
     putchar('0');
     return;
   }
   char ans[10];
   int cnt = 0;
   while (out) {
     ans[cnt++] = out  10 + '0';
     out /= 10;
   }
   for (int i = cnt - 1; i >= 0; i--) putchar(ans[i]);
 }
 int main() {
   while (~scanf( dd , &n, &m)) {
     tot = 0;
     memset(broken_road, 0x3f, sizeof(broken_road));
     memset(vis, 0, sizeof(vis));
     memset(d, 0x3f, sizeof(d));
     for (int i = 1; i <= n; i++) {
       work[i].clear();
       not_work[i].clear();
       rw[i].clear();
       rnw[i].clear();
     }
     int x, y, fun;
     getchar();
     for (int i = 0; i < m; i++) {
       x = input();
       y = input();
       fun = input();
       in.to = y;
       in.th = i;
       if (!fun) {
         in.f = 0;
         not_work[x].push_back(in);
         in.to = x;
         rnw[y].push_back(in);
       } else {
         tot++;
         in.f = 1;
         work[x].push_back(in);
         in.to = x;
         rw[y].push_back(in);
       }
     }
     memset(inq, 0, sizeof(inq));
     inq[1] = 1;
     d[1] = 0;
     queue<int> q;
     q.push(1);
     broken_road[1] = 0;
     while (!q.empty()) {
       u = q.front();
       q.pop();
       inq[u] = 0;
       int v;
       for (int i = 0; i < work[u].size(); i++) {
         v = work[u][i].to;
         if (d[u] + 1 < d[v] ||
             (d[u] + 1 == d[v] && broken_road[u] < broken_road[v])) {
           d[v] = d[u] + 1;
           r[v].come_point = u;
           r[v].come_road = work[u][i].th;
           r[v].func = 1;
           broken_road[v] = broken_road[u];
           if (!inq[v]) {
             q.push(v);
             inq[v] = 1;
           }
         }
       }
       for (int i = 0; i < rw[u].size(); i++) {
         v = rw[u][i].to;
         if (d[u] + 1 < d[v] ||
             (d[u] + 1 == d[v] && broken_road[u] < broken_road[v])) {
           d[v] = d[u] + 1;
           r[v].come_point = u;
           r[v].come_road = rw[u][i].th;
           r[v].func = 1;
           broken_road[v] = broken_road[u];
           if (!inq[v]) {
             q.push(v);
             inq[v] = 1;
           }
         }
       }
       for (int i = 0; i < not_work[u].size(); i++) {
         v = not_work[u][i].to;
         if (d[u] + 1 < d[v] ||
             (d[u] + 1 == d[v] && broken_road[u] + 1 < broken_road[v])) {
           d[v] = d[u] + 1;
           r[v].come_point = u;
           r[v].come_road = not_work[u][i].th;
           r[v].func = 0;
           broken_road[v] = broken_road[u] + 1;
           if (!inq[v]) {
             q.push(v);
             inq[v] = 1;
           }
         }
       }
       for (int i = 0; i < rnw[u].size(); i++) {
         v = rnw[u][i].to;
         if (d[u] + 1 < d[v] ||
             (d[u] + 1 == d[v] && broken_road[u] + 1 < broken_road[v])) {
           d[v] = d[u] + 1;
           r[v].come_point = u;
           r[v].come_road = rnw[u][i].th;
           r[v].func = 0;
           broken_road[v] = broken_road[u] + 1;
           if (!inq[v]) {
             q.push(v);
             inq[v] = 1;
           }
         }
       }
     }
     int p = n;
     while (p != 1) {
       vis[r[p].come_road] = 1;
       if (r[p].func)
         tot--;
       else
         tot++;
       p = r[p].come_point;
     }
     output(tot);
     puts(  );
     for (int i = 1; i <= n; i++) {
       for (int j = 0; j < work[i].size(); j++) {
         if (!vis[work[i][j].th]) {
           output(i);
           putchar(' ');
           output(work[i][j].to);
           putchar(' ');
           puts( 0 );
         }
       }
       for (int j = 0; j < not_work[i].size(); j++) {
         if (vis[not_work[i][j].th]) {
           output(i);
           putchar(' ');
           output(not_work[i][j].to);
           putchar(' ');
           puts( 1 );
         }
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 1e9 + 7;
 void solve(int tc) {
   int n, k;
   cin >> n >> k;
   string s;
   cin >> s;
   for (int i = k; i < s.size(); i++) {
     if (s[i] == '?') {
       if (s[i - k] != '?') {
         s[i] = s[i - k];
       }
     } else {
       if (s[i - k] == '?') {
         s[i - k] = s[i];
       } else {
         if (s[i] != s[i - k]) {
           cout <<  NO  << endl;
           return;
         }
       }
     }
   }
   int count = 0;
   int free = 0;
   for (int i = 0; i < s.size(); i++) {
     if (i >= k) {
       if (s[i - k] == '?') {
         free--;
       } else {
         count -= ((s[i - k] == '1') ? 1 : 0);
       }
     }
     if (s[i] == '?') {
       free++;
     } else {
       count += ((s[i] == '1') ? 1 : 0);
     }
     if (i >= k - 1) {
       if (count > k / 2 || count + free < k / 2) {
         cout <<  NO  << endl;
         return;
       }
     }
   }
   cout <<  YES  << endl;
 }
 int main() {
   int t;
   cin >> t;
   for (int i = 1; i <= t; i++) {
     solve(i);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long double pi = 3.14159265359;
 inline long long add(long long a, long long b, long long m) {
   if ((a + b) >= m) return (a + b)  m;
   return a + b;
 }
 inline long long mul(long long a, long long b, long long m) {
   if ((a * b) < m) return a * b;
   return (a * b)  m;
 }
 long long power(long long x, long long y, long long m) {
   long long res = 1;
   x = x  m;
   if (x == 0) return 0;
   while (y > 0) {
     if (y & 1) res = (res * x)  m;
     y = y >> 1;
     x = (x * x)  m;
   }
   return res;
 }
 long long gcd(long long a, long long b) {
   if (b == 0) return a;
   return gcd(b, a  b);
 }
 int main() {
   ios_base::sync_with_stdio;
   cin.tie(0);
   cout.tie(0);
   int t = 1, n;
   cin >> t;
   while (t--) {
     string s;
     cin >> n;
     cin >> s;
     string ans;
     int i = 0;
     for (; i < s.length(); i++) {
       if (s[i] == '0') {
         ans.push_back(s[i]);
       } else {
         break;
       }
     }
     string ans2;
     for (int i = s.length() - 1; i > -1; i--) {
       if (s[i] == '1') {
         ans2.push_back(s[i]);
       } else {
         break;
       }
     }
     if (ans.length() + ans2.length() == s.length()) {
       cout << s << endl;
     } else
       cout << ans <<  0  << ans2 << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using ll = long long;
 const int N = 1e2 + 5;
 int ans[N][N][N];
 bool was[N][N][N];
 vector<pair<int, int> > adj[N];
 bool calc(int x, int y, int pr) {
   if (was[x][y][pr]) return ans[x][y][pr];
   was[x][y][pr] = 1;
   for (auto to : adj[x]) {
     if (to.second >= pr && !calc(y, to.first, to.second)) {
       ans[x][y][pr] = 1;
       break;
     }
   }
   return ans[x][y][pr];
 }
 int main() {
   ios ::sync_with_stdio(0), cin.tie(0);
   int n, m;
   cin >> n >> m;
   for (int i = 1; i <= m; ++i) {
     int u, v;
     char c;
     cin >> u >> v >> c;
     adj[u].push_back({v, c - 'a'});
   }
   for (int i = 1; i <= n; ++i) {
     for (int j = 1; j <= n; ++j) {
       if (!calc(i, j, 0))
         cout << 'B';
       else
         cout << 'A';
     }
     cout << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int v[2000];
 int a, b, n, res;
 int main() {
   scanf( d d d , &n, &a, &b);
   for (int i = 0; i < n; i++) scanf( d , &v[i]);
   sort(v, v + n);
   int res = v[b] - v[b - 1];
   cout << res << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long maxsize = 100000 + 9;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int T;
   T = 1;
   while (T--) {
     long long i, j, k, m, n, flag = 0;
     vector<int> v;
     string s;
     cin >> n >> s;
     for (i = 0; i < n; i++) {
       if (s[i] == '2') {
         v.push_back(2);
       }
       if (s[i] == '3') {
         v.push_back(3);
       }
       if (s[i] == '4') {
         v.push_back(3);
         v.push_back(2);
         v.push_back(2);
       }
       if (s[i] == '5') {
         v.push_back(5);
       }
       if (s[i] == '6') {
         v.push_back(5);
         v.push_back(3);
       }
       if (s[i] == '7') {
         v.push_back(7);
       }
       if (s[i] == '8') {
         v.push_back(7);
         v.push_back(2);
         v.push_back(2);
         v.push_back(2);
       }
       if (s[i] == '9') {
         v.push_back(7);
         v.push_back(3);
         v.push_back(3);
         v.push_back(2);
       }
     }
     sort(v.begin(), v.end());
     for (i = v.size() - 1; i >= 0; i--) {
       cout << v[i];
     }
     cout << '
';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, s = 0;
   cin >> n;
   if (n >= 1 && n <= 100) {
     if (n == 1)
       cout << 1;
     else {
       while (1) {
         if (n == 2) {
           s = s + 5;
           break;
         }
         s = s + (n * 2) + (n - 2) * 2;
         n = n - 1;
       }
       cout << s;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 using namespace std::chrono;
 long long gcd(long long a, long long b) {
   if (b == 0) {
     return a;
   } else {
     return gcd(b, a  b);
   }
 }
 void change(map<long long, long long> &m, long long n) {
   long long i;
   for (long long i = 1; i < n + 1; i++) {
     if (m[i] == 1)
       m.erase(i);
     else
       m[i]--;
   }
   return;
 }
 void solve() {
   long long n, i, l, t;
   cin >> n >> t;
   string ans =   ;
   map<long long, long long> m;
   for (long long i = 0; i < t; i++) {
     cin >> l;
     m[l]++;
     if ((long long)m.size() == n) {
       ans +=  1 ;
       change(m, n);
     } else {
       ans +=  0 ;
     }
   }
   cout << ans;
 }
 signed main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   ;
   long long t = 1;
   while (t--) {
     solve();
     cout <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int n, a[101][101] = {0}, d = 0;
   cin >> n;
   for (long long int i = 1; i <= n; i++) {
     long long int x1, x2, y1, y2;
     cin >> x1 >> y1 >> x2 >> y2;
     for (long long int j = x1; j <= x2; j++) {
       for (long long int k = y1; k <= y2; k++) {
         d++;
       }
     }
   }
   cout << d << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long getLL() {
   long long ret = 0;
   char c;
   while (1) {
     c = getchar();
     if (c >= '0' && c <= '9') break;
   }
   while (1) {
     ret = ret * 10 + c - '0';
     c = getchar();
     if (c < '0' || c > '9') break;
   }
   return ret;
 }
 int getInt() {
   int ret = 0;
   char c;
   while (1) {
     c = getchar();
     if (c >= '0' && c <= '9') break;
   }
   while (1) {
     ret = ret * 10 + c - '0';
     c = getchar();
     if (c < '0' || c > '9') break;
   }
   return ret;
 }
 const double eps = 1e-10;
 int dcmp(double x) { return (x < -eps) ? -1 : (x > eps); }
 struct Point {
   double x, y;
   int who;
   Point() {}
   Point(double _x, double _y, int _who) : x(_x), y(_y), who(_who){};
   bool operator<(const Point &b) const {
     if (dcmp(x - b.x) == 0) return y < b.y;
     return x < b.x;
   }
   Point operator-(const Point &b) const { return Point(x - b.x, y - b.y, 0); }
   double operator*(const Point &b) const { return x * b.y - y * b.x; }
 } A[1020304];
 int n, Stack[1020304], can[1020304], sameas[1020304];
 int main() {
   cin >> n;
   for (int i = 1; i <= n; ++i) {
     double r, s;
     scanf( lflf , &r, &s);
     A[i] = Point(10000.0 / r, 10000.0 / s, i);
   }
   sort(A + 1, A + n + 1);
   int Top = 0;
   vector<int> ans;
   for (int i = 1; i <= n; ++i) {
     if (i > 1 && dcmp(A[i].x - A[i - 1].x) == 0) continue;
     while (Top > 1 &&
            (dcmp((A[i] - A[Stack[Top]]) * (A[i] - A[Stack[Top - 1]])) > 0))
       --Top;
     Stack[++Top] = i;
   }
   for (int i = 1; i <= Top; ++i)
     if (i == 1 || dcmp(A[Stack[i]].y - A[Stack[i - 1]].y) < 0)
       can[Stack[i]] = true;
   for (int i = 1; i <= n; ++i) {
     if (dcmp(A[i].x - A[i - 1].x) == 0 && dcmp(A[i].y - A[i - 1].y) == 0)
       can[i] |= can[i - 1];
     if (can[i]) ans.push_back(A[i].who);
   }
   sort(ans.begin(), ans.end());
   for (auto x : ans) printf( d  , x);
   puts(  );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 12;
 int p[1 << N], q[1 << N], a[1 << N], pos[1 << N], ans[1 << N];
 void do_swap(int x, int y) {
   int val = (p[x] ^ q[x] ^ a[x]);
   if (!val) {
     return;
   }
   int idx = pos[a[x] ^ q[x]];
   swap(pos[p[x]], pos[p[idx]]);
   swap(p[x], p[idx]);
   swap(q[y], q[idx]);
   do_swap(idx, y);
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int n, i, j, k, l = 0;
   cin >> n;
   n = (1 << n);
   for (i = 0; i < n; i++) {
     cin >> a[i];
     l ^= a[i];
     p[i] = q[i] = pos[i] = i;
   }
   if (l) {
     cout <<  Fou ;
     return 0;
   }
   for (i = 0; i + 1 < n; i++) {
     do_swap(i, i + 1);
   }
   cout <<  Shi
 ;
   for (i = 0; i < n; i++) {
     cout << p[i] << ' ';
   }
   cout << '
';
   for (i = 0; i < n; i++) {
     cout << q[i] << ' ';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 long long r, d, n;
 vector<vector<long long>> data;
 const long double pi = 3.1415926535897932;
 long long per(vector<long long> x, vector<long long> y) {
   long long su = 0;
   for (long long(i) = 0; (i) < (5); (i)++) {
     su += x[i] * y[i];
   }
   return su;
 }
 long double pere(vector<long long> x, vector<long long> y) {
   long double su = per(x, y);
   su /= sqrt(per(x, x)) * sqrt(per(y, y));
   su = acos(su);
   return su;
 }
 int main() {
   cin >> n;
   data.resize(n);
   for (long long(i) = 0; (i) < (n); (i)++) {
     for (long long(j) = 0; (j) < (5); (j)++) {
       data[i].resize(5);
       cin >> data[i][j];
     }
   }
   if (n > 32) {
     cout << 0;
     return 0;
   }
   vector<long long> result;
   for (long long(i) = 0; (i) < (n); (i)++) {
     bool mark = false;
     for (long long(j) = 0; (j) < (n); (j)++) {
       if (mark) {
         break;
       }
       for (long long(l) = 0; (l) < (n); (l)++) {
         if (i == j || j == l || i == l) {
           continue;
         }
         vector<long long> x, y;
         x.resize(5);
         y.resize(5);
         for (long long(h) = 0; (h) < (5); (h)++) {
           x[h] = data[j][h] - data[i][h];
           y[h] = data[l][h] - data[i][h];
         }
         if (pere(x, y) < pi / 2) {
           mark = true;
           break;
         }
       }
     }
     if (!mark) {
       result.push_back(i);
     }
   }
   cout << result.size() << endl;
   for (long long(i) = 0; (i) < (result.size()); (i)++) {
     cout << result[i] + 1 << endl;
   }
 }


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


#include <bits/stdc++.h>
 using namespace std;
 using namespace chrono;
 const int infinity = (int)1e9 + 42;
 const int64_t llInfinity = (int64_t)1e18 + 256;
 const int module = (int)1e9 + 7;
 const long double eps = 1e-8;
 mt19937_64 randGen(system_clock().now().time_since_epoch().count());
 inline void raiseError(string errorCode) {
   cerr <<  Error :   << errorCode << endl;
   exit(42);
 }
 inline basic_string<int64_t> arith(int64_t n, int64_t base, int64_t step) {
   basic_string<int64_t> res;
   for (int64_t i = 0; i < n; i++) {
     res += base;
     base += step;
   }
   return res;
 }
 inline int64_t ask(basic_string<int64_t> b) {
   cout << b.size();
   for (int64_t i : b) {
     cout <<     << i;
   }
   cout << endl;
   int64_t x;
   cin >> x;
   if (x == -2) {
     exit(42);
   }
   if (x == -1) {
     exit(0);
   }
   return x;
 }
 inline void simpleGuess(int64_t l, int64_t r, int64_t knt, int64_t att) {
   for (int64_t i = 0; i < att; i++) {
     if (r - l + 1 <= knt) {
       ask(arith(r - l + 1, l, 1));
       exit(42);
     }
     int64_t delta = (r - l + 1 - knt) / (knt + 1);
     int64_t mod = (r - l + 1 - knt)  (knt + 1);
     int64_t val = l;
     basic_string<int64_t> bounds;
     bounds += l - 1;
     for (int64_t i = 1; i <= knt; i++) {
       int64_t add = delta + (i <= mod);
       val += add;
       bounds += val;
       val++;
     }
     bounds += r + 1;
     int64_t q = ask(bounds.substr(1, knt));
     l = bounds[q] + 1;
     r = bounds[q + 1] - 1;
   }
   exit(42);
 }
 signed main() {
   ios_base::sync_with_stdio(false);
   if (ask({204761410474}) == 0) {
     if (ask({2046}) == 0) {
       if (ask({6}) == 0) {
         if (ask({2}) == 0) {
           ask({1});
         } else {
           ask(arith(3, 3, 1));
         }
       } else {
         int64_t q = ask({14, 30, 62, 126, 254, 510, 1022});
         int64_t w = (8 << q) - 1;
         ask(arith(w, w, 1));
       }
     } else {
       int64_t base1 = 20468427, step1 = 100020001;
       int64_t w1 = ask(arith(2047, base1, step1));
       if (w1 == 0) {
         int64_t base2 = 16382, step2 = 10001;
         int64_t w2 =
             ask(basic_string<int64_t>{4094, 8190} + arith(2045, base2, step2));
         if (w2 <= 2) {
           int64_t abase = (2048 << w2) - 1;
           ask(arith(abase, abase, 1));
         } else {
           ask(arith(10000, base2 + (w2 - 3) * step2 + 1, 1));
         }
       } else {
         simpleGuess(base1 + (w1 - 1) * step1 + 1, base1 + w1 * step1 - 1, 10000,
                     2);
       }
     }
   } else {
     simpleGuess(204761410475, 10004205361450474, 10000, 4);
   }
   return 42;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int n, i, f = 0, se = 0, so = 0, sume = 0, sumo = 0, c = 0, x, y;
   cin >> n;
   long long int a[n];
   for (i = 0; i < n; i++) cin >> a[i];
   for (i = 0; i < n; i++) {
     if (i  2)
       so += a[i];
     else
       se += a[i];
   }
   for (i = 0; i < n; i++) {
     if (i  2) {
       x = so - sumo - a[i] + sume;
       y = se - sume + sumo;
       sumo += a[i];
     } else {
       x = so - sumo + sume;
       y = se - sume + sumo - a[i];
       sume += a[i];
     }
     if (x == y) c++;
   }
   cout << c <<
 ;
 }


#include <bits/stdc++.h>
 using namespace std;
 int dividers[60];
 int main() {
   long long int n, k;
   cin >> n >> k;
   if (k == 1) {
     cout <<  Yes ;
     return 0;
   }
   if (k == 2 && n == 1) {
     cout <<  Yes ;
     return 0;
   }
   if (n <= k) {
     cout <<  No ;
     return 0;
   }
   if (k > 50) {
     cout <<  No ;
     return 0;
   }
   long long int c = n + 1;
   for (int i = 2; i <= k; i++) {
     if (c  i != 0) {
       cout <<  No ;
       return 0;
     }
   }
   cout <<  Yes ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX = 2e3 + 5;
 char a[MAX][MAX];
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0), cout.tie(0);
   int n, m, k;
   cin >> n >> m >> k;
   for (int i = (1); i <= (n); ++i)
     for (int j = (1); j <= (m); ++j) cin >> a[i][j];
   int ans = 0;
   for (int i = (1); i <= (n); ++i) {
     int cnt = 0;
     for (int j = (1); j <= (m); ++j) {
       if (a[i][j] == '.')
         ++cnt;
       else {
         if (cnt >= k) ans += cnt - k + 1;
         cnt = 0;
       }
     }
     if (cnt >= k) ans += cnt - k + 1;
   }
   if (k > 1) {
     for (int i = (1); i <= (m); ++i) {
       int cnt = 0;
       for (int j = (1); j <= (n); ++j) {
         if (a[j][i] == '.')
           ++cnt;
         else {
           if (cnt >= k) ans += cnt - k + 1;
           cnt = 0;
         }
       }
       if (cnt >= k) ans += cnt - k + 1;
     }
   }
   cout << ans << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int oo = 10000000;
 int n, m, x, y, a, b;
 int vabs(int t) { return (t > 0) ? t : (-t); }
 int calc(int cx, int cy) {
   int dx = vabs(cx - x);
   int dy = vabs(cy - y);
   if (dx == 0 && dy == 0) return 0;
   if (dx  a != 0 || dy  b != 0) return oo;
   int ca = dx / a, cb = dy / b;
   if (vabs(ca - cb)  2 != 0) return oo;
   if (ca < cb && cx - a < 1 && cx + a > n) return oo;
   if (ca > cb && cy - b < 1 && cy + b > m) return oo;
   return max(ca, cb);
 }
 int main() {
   while (cin >> n) {
     cin >> m >> x >> y >> a >> b;
     int ans = oo;
     ans = min(ans, calc(1, 1));
     ans = min(ans, calc(1, m));
     ans = min(ans, calc(n, 1));
     ans = min(ans, calc(n, m));
     if (ans == oo)
       cout <<  Poor Inna and pony!  << endl;
     else
       cout << ans << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long N = 1e10;
 void solve() {
   long long n, c;
   cin >> n >> c;
   long long a[n], b[n];
   for (long long i = 0; i < n; i++) {
     cin >> a[i] >> b[i];
   }
   long long low = -1, high = -1;
   for (long long i = 1; i <= 100000; i++) {
     long long cnt = 0;
     for (long long j = 0; j < n; j++) {
       cnt++;
       cnt += (a[j] * i) / b[j];
     }
     if (cnt > c) break;
     if (cnt < c) continue;
     if (cnt == c) {
       if (low == -1) low = i;
       high = i;
     }
   }
   if (high == -1)
     cout << 0;
   else
     cout << high - low + 1;
 }
 int32_t main() {
   long long t = 1;
   while (t--) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 int main() {
   int n, x;
   std::cin >> n >> x;
   std::vector<int> data;
   int counter = 0;
   for (int i = 0; i != n; i++) {
     int temp;
     std::cin >> temp;
     data.push_back(temp);
   }
   std::sort(data.begin(), data.end());
   if (std::find(data.begin(), data.end(), x) != data.end()) {
     auto it = std::find(data.begin(), data.end(), x);
     counter++;
     data.erase(it);
   }
   for (int i = 0; i < x; i++) {
     if (std::find(data.begin(), data.end(), i) == data.end()) {
       data.push_back(i);
       counter++;
     }
   }
   std::cout << counter << std::endl;
   return 0;
 }


 #include <bits/stdc++.h>

 #define ll long long
 #define sz(x) ((int) (x).size())
 #define all(x) (x).begin(), (x).end()
 #define vi vector<int>
 #define pii pair<int, int>
 #define rep(i, a, b) for(int i = (a); i < (b); i++)
 using namespace std;
 template<typename T>
 using minpq = priority_queue<T, vector<T>, greater<T>>;

 struct pt {
     ll x, y;
     pt(ll x = 0, ll y = 0) : x(x), y(y) {}
     pt operator-(const pt &o) const {
         return pt(x - o.x, y - o.y);
     }
     ll cross(const pt &o) const {
         return x * o.y - y * o.x;
     }
     bool operator<(const pt &o) const {
         return cross(o) > 0;
     }
 };

 struct dsu {
     vi a;
     dsu(int n) {
         a.assign(n, -1);
     }
     int trace(int x) {
         return a[x] < 0 ? x : a[x] = trace(a[x]);
     }
     void join(int x, int y) {
         if((x = trace(x)) == (y = trace(y))) return;
         if(a[x] > a[y]) swap(x, y);
         a[x] += a[y];
         a[y] = x;
     }
 };

 int main() {
     ios::sync_with_stdio(false);
     cin.tie(0);
     int n;
     cin >> n;
     vi a(n + 1);
     vector<pt> p(n + 1);
     rep(i, 1, n + 1) {
         cin >> p[i].x >> p[i].y >> a[i];
     }
     int idx = -1;
     rep(i, 1, n + 1) {
         if(a[i] != i && (idx == -1 || p[i].y < p[idx].y)) {
             idx = i;
         }
     }
     if(idx == -1) {
         cout << 0 << '
';
         return 0;
     }
     vi balls;
     rep(i, 1, n + 1) {
         if(i != idx && a[i] != i) {
             balls.push_back(i);
         }
     }
     sort(all(balls), [&](int i, int j) {
         return p[i] - p[idx] < p[j] - p[idx];
     });
     dsu D(n + 1);
     rep(i, 1, n + 1) D.join(i, a[i]);
     int k = sz(balls);
     vector<pii> ops;
     auto pass = [&](int i, int j) {
         swap(a[i], a[j]);
         ops.push_back({i, j});
     };
     rep(i, 0, k - 1) {
         if(D.trace(balls[i]) != D.trace(balls[i + 1])) {
             pass(balls[i], balls[i + 1]);
             D.join(balls[i], balls[i + 1]);
         }
     }
     while(a[idx] != idx) {
         pass(idx, a[idx]);
     }

     cout << sz(ops) << '
';
     for(auto &pa : ops) {
         cout << pa.first << ' ' << pa.second << '
';
     }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 100110;
 const int maxm = 100010;
 char s[maxn][5];
 long long sum[maxm * 4][5][11];
 int n;
 void init() {
   for (int i = 1; i < maxn; i++)
     for (int z = 2; z <= 6; z++) {
       int tp = i  (2 * (z - 1));
       if (tp == 0)
         s[i][z - 2] = 2;
       else if (tp <= z)
         s[i][z - 2] = tp;
       else
         s[i][z - 2] = 2 * z - tp;
     }
 }
 void build(int pos, int l, int r) {
   for (int i = 2; i <= 6; i++)
     for (int j = 0; j <= 10; j++) sum[pos][i - 2][j] = 0;
   if (l == r) return;
   int mid = (l + r) >> 1;
   build((pos << 1), l, mid);
   build(((pos << 1) | 1), mid + 1, r);
 }
 void insert(int pos, int l, int r, int i, int a) {
   if (i < l || i > r) return;
   if (l == r) {
     for (int z = 2; z <= 6; z++)
       for (int j = 0; j <= 10; j++)
         sum[pos][z - 2][j] = (long long)s[i + j][z - 2] * a;
     return;
   }
   int mid = (l + r) >> 1;
   insert((pos << 1), l, mid, i, a);
   insert(((pos << 1) | 1), mid + 1, r, i, a);
   for (int z = 2; z <= 6; z++)
     for (int j = 0; j <= 10; j++)
       sum[pos][z - 2][j] =
           sum[(pos << 1)][z - 2][j] + sum[((pos << 1) | 1)][z - 2][j];
 }
 long long search(int pos, int l, int r, int x, int y, int z, int offset) {
   if (y < l || r < x) return 0;
   if (x <= l && r <= y) return sum[pos][z - 2][offset];
   int mid = (l + r) >> 1;
   return search((pos << 1), l, mid, x, y, z, offset) +
          search(((pos << 1) | 1), mid + 1, r, x, y, z, offset);
 }
 int main() {
   init();
   while (~scanf( d , &n)) {
     build(1, 1, n);
     for (int i = 1; i <= n; i++) {
       int a;
       scanf( d , &a);
       insert(1, 1, n, i, a);
     }
     int m;
     scanf( d , &m);
     while (m-- > 0) {
       int t, p, v, l, r, z;
       scanf( d , &t);
       if (t == 1) {
         scanf( dd , &p, &v);
         insert(1, 1, n, p, v);
       } else {
         scanf( ddd , &l, &r, &z);
         int offset = 0;
         if (s[l][z - 2] <= s[l + 1][z - 2]) {
           if (s[l][z - 2] == 1)
             offset = 0;
           else
             offset = z - s[l][z - 2] + z - 1;
         } else {
           offset = s[l][z - 2] - 1;
         }
         cout << search(1, 1, n, l, r, z, offset) << endl;
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   string s;
   cin >> n;
   getline(cin, s);
   for (int i = 0; i < n; ++i) {
     getline(cin, s);
     int len = s.length();
     if (len < 5)
       cout <<  OMG>.< I don't know!  << endl;
     else {
       string prefix(s.substr(0, 5));
       string suffix(s.substr(len - 5, 5));
       if (prefix ==  miao.  && suffix ==  lala. )
         cout <<  OMG>.< I don't know!  << endl;
       else if (prefix ==  miao. )
         cout <<  Rainbow's  << endl;
       else if (suffix ==  lala. )
         cout <<  Freda's  << endl;
       else
         cout <<  OMG>.< I don't know!  << endl;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 1e9 + 7;
 const int inf = 2e9 + 5;
 const int N = 1e5;
 int cost[26];
 map<long long, long long> m[26];
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(nullptr);
   for (int i = 0; i < 26; i++) cin >> cost[i];
   string s;
   cin >> s;
   long long n = s.length(), sum = 0;
   long long ans = 0;
   for (int i = 0; i < n; i++) {
     ans += m[s[i] - 'a'][sum];
     sum += cost[s[i] - 'a'];
     m[s[i] - 'a'][sum] += 1;
   }
   cout << ans <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void prv(vector<int> v) {
   int n = v.size();
   for (int i = 0; i < n; i++) cout << v[i] <<    ;
 }
 void swap(long long int &a, long long int &b) {
   int tm = a;
   a = b;
   b = tm;
 }
 bool comp(const pair<int, int> &p1, const pair<int, int> &p2) {
   if (p1.first > p2.first)
     return 1;
   else
     return 0;
 }
 const int N = 3e5 + 5;
 void findPrefix(string pattern, int m, int prefArray[]) {
   int length = 0;
   prefArray[0] = 0;
   for (int i = 1; i < m; i++) {
     if (pattern[i] == pattern[length]) {
       length++;
       prefArray[i] = length;
     } else {
       if (length != 0) {
         length = prefArray[length - 1];
         i--;
       } else
         prefArray[i] = 0;
     }
   }
 }
 int kmpPattSearch(string mainString, string pattern) {
   int n, m, i = 0, j = 0, fr = 0;
   n = mainString.size();
   m = pattern.size();
   int prefixArray[m];
   findPrefix(pattern, m, prefixArray);
   while (i < n) {
     if (mainString[i] == pattern[j]) {
       i++;
       j++;
     }
     if (j == m) {
       fr++;
       j = prefixArray[j - 1];
     } else if (i < n && pattern[j] != mainString[i]) {
       if (j != 0)
         j = prefixArray[j - 1];
       else
         i++;
     }
   }
   return fr;
 }
 string crts(int d, int m, int y) {
   string t;
   t.clear();
   while (y != 0) {
     t.push_back(y  10 + '0');
     y = y / 10;
   }
   t.push_back('-');
   while (m != 0) {
     t.push_back(m  10 + '0');
     m = m / 10;
   }
   if (t.size() == 6) t.push_back('0');
   t.push_back('-');
   while (d != 0) {
     t.push_back(d  10 + '0');
     d = d / 10;
   }
   if (t.size() == 9) t.push_back('0');
   reverse((t).begin(), (t).end());
   return t;
 }
 void solve() {
   string s, ans;
   cin >> s;
   int mx = 0;
   for (int i = 2013; i < 2016; ++i) {
     for (int j = 1; j <= 12; j++) {
       int k;
       if (j == 2)
         k = 28;
       else if (j == 1 || j == 3 || j == 5 || j == 7 || j == 8 || j == 10 ||
                j == 12)
         k = 31;
       else
         k = 30;
       for (int l = 1; l <= k; l++) {
         string t;
         int frq;
         t = crts(l, j, i);
         frq = kmpPattSearch(s, t);
         if (frq > mx) {
           mx = frq;
           ans = t;
         }
       }
     }
   }
   cout << ans;
 }
 signed int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int t = 1;
   while (t--) {
     solve();
     cout <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double PI = acos(-1.0);
 template <class T>
 T SQR(const T &a) {
   return a * a;
 }
 void run() {
   char str[1000100];
   scanf( s , str);
   int n = strlen(str);
   int m;
   cin >> m;
   int A[10001];
   int B[10001];
   map<int, int> res;
   char pat[100];
   for (int i = (0), ei = (m); i < ei; i++) {
     scanf(  s , pat);
     int mask = 0;
     for (int j = (0), ej = (strlen(pat)); j < ej; j++)
       mask |= 1 << (pat[j] - 'a');
     B[i] = A[i] = mask;
   }
   sort(B, B + m);
   int Pos[26] = {0};
   for (int i = (0), ei = (26); i < ei; i++) Pos[i] = -1;
   int mask = 0, curr;
   pair<int, int> P[26];
   str[n] = 'z' + 1;
   for (int i = (0), ei = (n); i < ei; i++) {
     mask |= 1 << (str[i] - 'a');
     Pos[str[i] - 'a'] = i;
     for (int j = (0), ej = (26); j < ej; j++) {
       P[j].first = Pos[j];
       P[j].second = j;
     }
     sort(P, P + 26);
     curr = mask;
     int next = 1 << (str[i + 1] - 'a');
     if (binary_search(B, B + m, mask) && (mask & next) == 0) res[mask]++;
     for (int j = (0), ej = (25); j < ej; j++)
       if (P[j].first != -1) {
         curr &= ~(1 << P[j].second);
         if (binary_search(B, B + m, curr) && (curr & next) == 0) res[curr]++;
       }
   }
   for (int i = (0), ei = (m); i < ei; i++) printf( d
 , res[A[i]]);
 }
 int main() {
   run();
   return 0;
 }


#include <bits/stdc++.h>

 #define st first
 #define nd second
 #define pb push_back
 #define BOOST ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
 #define PI 3.14159265359

 using namespace std;

 typedef long long ll;
 constexpr ll MOD = 1000000007, sup = 29;
 constexpr ll MOD_1 = 1234567891, sup_1 = 1009;
 constexpr ll MOD_2 = 1000000009, sup_2 = 107;
 constexpr int MXN = 200000+10, CZAPA = (1<<18), INF = 1000000000;

 int n, m;

 struct tree{
 	pair<int, int> tab[2*CZAPA+10];

 	void add(int leaf, int x){
 		int v = leaf + CZAPA;
 		tab[v] = {x, x};
 		v /= 2;
 		while(v >= 1){
 			tab[v].st = min(tab[2*v].st, tab[2*v+1].st);
 			tab[v].nd = max(tab[2*v].nd, tab[2*v+1].nd);
 			v /= 2;
 		}
 	}

 	pair<int, int> query(int a, int b, int v, int p, int q){
 		if(q < a || b < p)
 			return {INF, -INF};
 		if(p >= a && q <= b)
 			return tab[v];
 		int mid = (p+q)/2;
 		pair<int, int> x = query(a, b, 2*v, p, mid), y = query(a, b, 2*v+1, mid+1, q);
 		return {min(x.st, y.st), max(x.nd, y.nd)};
 	}

 	pair<int, int> query(int a, int b){
 		return query(a+CZAPA, b+CZAPA, 1, CZAPA, 2*CZAPA-1);
 	}
 };

 tree T;

 int tab[MXN];

 int main(){
 	BOOST;

 	int t;
 	cin>> t;
 	T.add(0, 0);
 	while(t--){
 		string s;
 		cin>> n >> m >> s;
 		for(int i=1; i<=n; i++){
 			tab[i] = tab[i-1];
 			if(s[i-1] == '-')
 				tab[i]--;
 			else
 				tab[i]++;
 			T.add(i, tab[i]);
 			//cout<< tab[i] << ' ';
 		}
 		//cout<< '
';
 		while(m--){
 			int a, b;
 			cin>> a >> b;
 			pair<int, int> x = T.query(0, a-1);
 			int sum = tab[b] - tab[a-1];
 			pair<int, int> y = T.query(b+1, n);
 			if(y.st == INF){
 				cout<< abs(x.st-x.nd)+1 << '
';
 				continue;
 			}
 			y.st -= sum;
 			y.nd -= sum;
 			pair<int, int> ans = {min(x.st, y.st), max(x.nd, y.nd)};
 			cout<< abs(ans.st-ans.nd)+1 << '
';
 			//cout<< x.st <<   ~   << x.nd <<  ,   << y.st <<   ~   << y.nd << '
';
 		}
 	}

 	return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline int read() {
   int s = 0, w = 1;
   char ch = getchar();
   while (ch < '0' || ch > '9') {
     if (ch == '-') w = -1;
     ch = getchar();
   }
   while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
   return s * w;
 }
 const int inf = 2e9 + 7;
 double eps = 1e-6;
 const int mod = 1e9 + 9;
 const int N = 1e3 + 10;
 const double pi = acos(-1.0);
 long long power(long long a, long long b) {
   long long res = 1;
   while (b) {
     if (b & 1) res = res * a  mod;
     a = a * a  mod;
     b >>= 1;
   }
   return res;
 }
 long long gcd(long long a, long long b) { return !b ? a : gcd(b, a  b); }
 long long exgcd(long long a, long long b, long long& x, long long& y) {
   long long c;
   return !b ? (x = 1, y = 0, a)
             : (c = exgcd(b, a  b, y, x), y -= (a / b) * x, c);
 }
 long long INV(long long a) {
   long long x, y;
   exgcd(a, mod, x, y);
   x = mod;
   if (x < 0) x += mod;
   return x;
 }
 int n;
 long long dp[N][N][11];
 struct AC {
   int tr[N][26], tot;
   int fail[N];
   int tr2[N][26];
   int Len[N];
   bool key[N];
   int insert(char s[]) {
     int u = 0;
     for (int i = 1; s[i]; i++) {
       int c = s[i] - 'a';
       if (!tr[u][c]) tr[u][c] = ++tot;
       Len[tr[u][c]] = Len[u] + 1;
       u = tr[u][c];
     }
     key[u] = 1;
     return u;
   }
   void build() {
     for (int i = 0; i <= tot; ++i)
       for (int j = 0; j <= 3; ++j) tr2[i][j] = tr[i][j];
     queue<int> q;
     for (int i = 0; i <= 25; ++i)
       if (tr[0][i]) q.push(tr[0][i]);
     while (!q.empty()) {
       int u = q.front();
       q.pop();
       for (int i = 0; i <= 25; ++i) {
         if (tr[u][i]) {
           fail[tr[u][i]] = tr[fail[u]][i], q.push(tr[u][i]);
         } else
           tr[u][i] = tr[fail[u]][i];
       }
     }
   }
   int dfs(int u, int len, int k) {
     bool ok = key[u];
     int now = u;
     while (1) {
       now = fail[now];
       if (Len[now] >= k && key[now]) {
         ok |= 1;
         break;
       }
       if (now == 0) break;
     }
     if (ok) k = 0;
     if (!u) return 0;
     if (dp[u][len][k] != -1) return dp[u][len][k];
     if (len == n) {
       bool ok = key[u];
       int now = u;
       while (1) {
         now = fail[now];
         if (Len[now] >= k && key[now]) {
           ok |= 1;
           break;
         }
         if (now == 0) break;
       }
       return dp[u][len][k] = ok;
     }
     long long& res = dp[u][len][k] = 0;
     for (int i = 0; i <= 3; i++) {
       if (tr2[u][i])
         res += dfs(tr2[u][i], len + 1, k + 1);
       else {
         int now = u;
         while (1) {
           now = fail[now];
           if (Len[now] >= k && tr2[now][i]) {
             res += dfs(tr2[now][i], len + 1, k + 1);
             break;
           }
           if (now == 0) break;
         }
       }
     }
     res = mod;
     return res;
   }
   int work() {
     memset(dp, -1, sizeof(dp));
     long long res = 0;
     for (int i = 0; i <= 3; i++) res += dfs(tr[0][i], 1, 1);
     res = mod;
     return res;
   }
 } ac;
 char s[N];
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int m;
   cin >> n >> m;
   map<char, char> mp;
   mp['A'] = 'a';
   mp['C'] = 'b';
   mp['T'] = 'c';
   mp['G'] = 'd';
   for (int i = 1; i <= m; ++i) {
     cin >> s + 1;
     for (int i = 1; i <= strlen(s + 1); ++i) s[i] = mp[s[i]];
     ac.insert(s);
   }
   ac.build();
   cout << ac.work() << '
';
 }


#include <bits/stdc++.h>
 using namespace std;
 struct edge {
   long long to, cost;
   edge() {}
   edge(long long a, long long b) { to = a, cost = b; }
 };
 const long long dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
 const long long mod = 1000000007;
 struct mint {
   long long x = 0;
   mint(long long y = 0) {
     x = y;
     if (x < 0 || x >= mod) x = (x  mod + mod)  mod;
   }
   mint(const mint& ope) { x = ope.x; }
   mint operator-() { return mint(-x); }
   mint operator+(const mint& ope) { return mint(x) += ope; }
   mint operator-(const mint& ope) { return mint(x) -= ope; }
   mint operator*(const mint& ope) { return mint(x) *= ope; }
   mint operator/(const mint& ope) { return mint(x) /= ope; }
   mint& operator+=(const mint& ope) {
     x += ope.x;
     if (x >= mod) x -= mod;
     return *this;
   }
   mint& operator-=(const mint& ope) {
     x += mod - ope.x;
     if (x >= mod) x -= mod;
     return *this;
   }
   mint& operator*=(const mint& ope) {
     x *= ope.x, x = mod;
     return *this;
   }
   mint& operator/=(const mint& ope) {
     long long n = mod - 2;
     mint mul = ope;
     while (n) {
       if (n & 1) *this *= mul;
       mul *= mul;
       n >>= 1;
     }
     return *this;
   }
   mint inverse() { return mint(1) / *this; }
   bool operator==(const mint& ope) { return x == ope.x; }
   bool operator!=(const mint& ope) { return x != ope.x; }
 };
 mint modpow(mint a, long long n) {
   if (n == 0) return mint(1);
   if (n  2)
     return a * modpow(a, n - 1);
   else
     return modpow(a * a, n / 2);
 }
 istream& operator>>(istream& is, mint& ope) {
   long long t;
   is >> t, ope.x = t;
   return is;
 }
 ostream& operator<<(ostream& os, mint& ope) { return os << ope.x; }
 ostream& operator<<(ostream& os, const mint& ope) { return os << ope.x; }
 vector<mint> fact, fact_inv;
 void make_fact(int n) {
   fact.resize(n + 1), fact_inv.resize(n + 1);
   fact[0] = mint(1);
   for (long long i = (1); (i) <= (n); (i)++) fact[i] = fact[i - 1] * mint(i);
   fact_inv[n] = fact[n].inverse();
   for (long long i = (n - 1); (i) >= (0); (i)--)
     fact_inv[i] = fact_inv[i + 1] * mint(i + 1);
 }
 mint comb(long long n, long long k) {
   if (n < 0 || k < 0 || n < k) return mint(0);
   return fact[n] * fact_inv[k] * fact_inv[n - k];
 }
 mint perm(long long n, long long k) { return comb(n, k) * fact[k]; }
 vector<int> prime;
 void make_prime(int n) {
   prime.resize(n + 1);
   for (long long i = (2); (i) <= (n); (i)++) {
     if (prime[i]) continue;
     for (int j = i; j <= n; j += i) prime[j] = i;
   }
 }
 bool exceed(long long x, long long y, long long m) { return x >= m / y + 1; }
 void mark() { cout <<  *  << endl; }
 void yes() { cout <<  YES  << endl; }
 void no() { cout <<  NO  << endl; }
 long long sgn(long long x) {
   if (x > 0) return 1;
   if (x < 0) return -1;
   return 0;
 }
 long long gcd(long long a, long long b) {
   if (b == 0) return a;
   return gcd(b, a  b);
 }
 long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
 long long digitnum(long long x, long long b = 10) {
   long long ret = 0;
   for (; x; x /= b) ret++;
   return ret;
 }
 long long digitsum(long long x, long long b = 10) {
   long long ret = 0;
   for (; x; x /= b) ret += x  b;
   return ret;
 }
 string lltos(long long x) {
   string ret;
   for (; x; x /= 10) ret += x  10 + '0';
   reverse(ret.begin(), ret.end());
   return ret;
 }
 long long stoll(string& s) {
   long long ret = 0;
   for (auto c : s) ret *= 10, ret += c - '0';
   return ret;
 }
 template <typename T>
 void uniq(T& vec) {
   sort(vec.begin(), vec.end());
   vec.erase(unique(vec.begin(), vec.end()), vec.end());
 }
 template <class S, class T>
 pair<S, T>& operator+=(pair<S, T>& s, const pair<S, T>& t) {
   s.first += t.first, s.second += t.second;
   return s;
 }
 template <class S, class T>
 pair<S, T>& operator-=(pair<S, T>& s, const pair<S, T>& t) {
   s.first -= t.first, s.second -= t.second;
   return s;
 }
 template <class S, class T>
 pair<S, T> operator+(const pair<S, T>& s, const pair<S, T>& t) {
   return pair<S, T>(s.first + t.first, s.second + t.second);
 }
 template <class S, class T>
 pair<S, T> operator-(const pair<S, T>& s, const pair<S, T>& t) {
   return pair<S, T>(s.first - t.first, s.second - t.second);
 }
 template <typename T>
 ostream& operator<<(ostream& os, vector<T>& vec) {
   for (int i = 0; i < vec.size(); i++)
     os << vec[i] << (i + 1 == vec.size() ?    :    );
   return os;
 }
 template <typename T>
 ostream& operator<<(ostream& os, deque<T>& deq) {
   for (int i = 0; i < deq.size(); i++)
     os << deq[i] << (i + 1 == deq.size() ?    :    );
   return os;
 }
 template <typename T, typename U>
 ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
   os <<  (  << pair_var.first <<  ,   << pair_var.second <<  ) ;
   return os;
 }
 template <typename T, typename U>
 ostream& operator<<(ostream& os, const pair<T, U>& pair_var) {
   os <<  (  << pair_var.first <<  ,   << pair_var.second <<  ) ;
   return os;
 }
 template <typename T, typename U>
 ostream& operator<<(ostream& os, map<T, U>& map_var) {
   for (typename map<T, U>::iterator itr = map_var.begin(); itr != map_var.end();
        itr++) {
     os <<  (  << itr->first <<  ,   << itr->second <<  ) ;
     itr++;
     if (itr != map_var.end()) os <<  , ;
     itr--;
   }
   return os;
 }
 template <typename T>
 ostream& operator<<(ostream& os, set<T>& set_var) {
   for (typename set<T>::iterator itr = set_var.begin(); itr != set_var.end();
        itr++) {
     os << *itr;
     ++itr;
     if (itr != set_var.end()) os <<    ;
     itr--;
   }
   return os;
 }
 template <typename T>
 ostream& operator<<(ostream& os, multiset<T>& set_var) {
   for (typename multiset<T>::iterator itr = set_var.begin();
        itr != set_var.end(); itr++) {
     os << *itr;
     ++itr;
     if (itr != set_var.end()) os <<    ;
     itr--;
   }
   return os;
 }
 template <typename T>
 void outa(T a[], long long s, long long t) {
   for (long long i = s; i <= t; i++) {
     cout << a[i];
     if (i < t) cout <<    ;
   }
   cout << endl;
 }
 void dump_func() { cout << endl; }
 template <class Head, class... Tail>
 void dump_func(Head&& head, Tail&&... tail) {
   cout << head;
   if (sizeof...(Tail) > 0) cout <<    ;
   dump_func(std::move(tail)...);
 }
 long long n;
 long long a[150005];
 bool check(long long i) {
   if (i <= 0 || i >= n) return true;
   if (i  2)
     return a[i] < a[i + 1];
   else
     return a[i] > a[i + 1];
 }
 int main(void) {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cin >> n;
   for (long long i = (1); (i) <= (n); (i)++) cin >> a[i];
   set<long long> S;
   set<pair<long long, long long> > ans;
   for (long long i = (1); (i) <= (n - 1); (i)++)
     if (!check(i)) S.insert(i);
   if (((long long)(S).size()) > 4) {
     dump_func(0);
     return 0;
   }
   set<long long> T;
   for (auto x : S) {
     T.insert(x);
     T.insert(x + 1);
   }
   for (auto x : T) {
     for (long long i = (1); (i) <= (n); (i)++) {
       if (i == x) continue;
       swap(a[i], a[x]);
       bool flag = true;
       for (auto y : S) flag &= check(y);
       for (long long j = (-1); (j) <= (1); (j)++)
         flag &= check(i + j), flag &= check(x + j);
       if (flag) {
         long long u = i, v = x;
         if (u > v) swap(u, v);
         ans.insert(pair<long long, long long>(u, v));
       }
       swap(a[i], a[x]);
     }
   }
   dump_func(((long long)(ans).size()));
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 0x3f3f3f3f;
 const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
 const double PI = acos(-1.0);
 const double EPS = 1e-8;
 const int MOD = 998244353;
 template <typename T>
 void cmin(T &x, T y) {
   if (y < x) x = y;
 }
 template <typename T>
 void cmax(T &x, T y) {
   if (y > x) x = y;
 }
 long long qpow(long long x, long long n, long long mod = MOD) {
   long long res = 1;
   while (n) {
     if (n & 1) res = res * x  mod;
     x = x * x  mod;
     n >>= 1;
   }
   return res;
 }
 namespace Solver {
 void InitOnce() {}
 int n, m, k;
 int u[200005];
 int v[200005];
 int deg[200005];
 vector<pair<int, int> > G[200005];
 void Read() {
   int res = scanf( ddd , &n, &m, &k);
   if (res == -1) exit(0);
   for (int i = 1; i <= n; ++i) G[i].clear();
   for (int i = 1; i <= m; ++i) {
     scanf( dd , &u[i], &v[i]);
     G[u[i]].emplace_back(v[i], i);
     G[v[i]].emplace_back(u[i], i);
   }
   for (int i = 1; i <= n; ++i) deg[i] = G[i].size();
 }
 bool vis[200005];
 int ans[200005];
 bool inQ[200005];
 queue<int> Q;
 void delEdge(int u, int v, int id) {
   if (vis[id]) return;
   vis[id] = 1;
   --deg[u];
   --deg[v];
   if (inQ[v] == 0 && deg[v] < k) {
     Q.push(v);
     inQ[v] = 1;
   }
 }
 void delEdge2(int u, int v, int id) {
   if (vis[id]) return;
   vis[id] = 1;
   --deg[u];
   --deg[v];
   if (inQ[u] == 0 && deg[u] < k) {
     Q.push(u);
     inQ[u] = 1;
   }
   if (inQ[v] == 0 && deg[v] < k) {
     Q.push(v);
     inQ[v] = 1;
   }
 }
 void Solve() {
   memset(vis, 0, sizeof(vis));
   memset(ans, 0, sizeof(ans));
   memset(inQ, 0, sizeof(inQ));
   for (int i = 1; i <= n; ++i) {
     if (deg[i] < k) {
       Q.push(i);
       inQ[i] = 1;
     }
   }
   int cur = n;
   while (!Q.empty()) {
     int u = Q.front();
     Q.pop();
     --cur;
     for (pair<int, int> &p : G[u]) {
       int v = p.first, id = p.second;
       delEdge(u, v, id);
     }
   }
   for (int i = 1; i <= n; ++i) {
     if (deg[i]) assert(deg[i] >= k);
   }
   ans[m] = cur;
   for (int i = m - 1; i >= 0; --i) {
     int de = i + 1;
     delEdge2(u[de], v[de], de);
     while (!Q.empty()) {
       int u = Q.front();
       Q.pop();
       --cur;
       for (pair<int, int> &p : G[u]) {
         int v = p.first, id = p.second;
         delEdge(u, v, id);
       }
     }
     ans[i] = cur;
   }
   for (int i = 1; i <= n; ++i) {
     assert(deg[i] == 0);
     assert(inQ[i] == 1);
   }
   for (int i = 1; i <= m; ++i) assert(vis[i] == 1);
   for (int i = 1; i <= m; ++i) printf( d
 , ans[i]);
   return;
 }
 }  // namespace Solver
 int main() {
   Solver::InitOnce();
   while (true) {
     Solver::Read();
     Solver::Solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long MOD = 1e9 + 7;
 const long long INF = 1e18;
 const string nl =
 ;
 int32_t main() {
   ios::sync_with_stdio(0);
   cin.tie(nullptr);
   long long n, k;
   cin >> n >> k;
   vector<long long> a(n);
   for (auto& i : a) {
     cin >> i;
   }
   vector<long long> pref(n);
   long long sum = 0, ans = 0;
   bool ok = 0;
   map<long long, long long> cnt;
   cnt[0] = 1;
   for (long long i = 0; i < n; ++i) {
     if (a[i] > k) {
       ++sum;
     } else if (a[i] < k) {
       --sum;
     }
     if (a[i] == k) {
       ok = 1;
     }
     if (ok) {
       ans += cnt[sum] + cnt[sum - 1];
     } else {
       ++cnt[sum];
     }
   }
   cout << ans << nl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int a, b, c, cc = 0;
   cin >> a >> b >> c;
   if (a < 0 || b < 2 || c < 4)
     cout << 0 << endl;
   else {
     while (a >= 1 && b >= 2 && c >= 4) {
       cc++;
       a--;
       b -= 2;
       c -= 4;
     }
     cout << cc * 7 << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<long long> v[100001];
 int main() {
   int n;
   cin >> n;
   for (long long i = 1; i < n; i++) {
     long long a, b;
     cin >> a >> b;
     v[a].push_back(b);
     v[b].push_back(a);
   }
   for (long long i = 1; i <= n; i++) {
     if (v[i].size() == 2) {
       cout <<  NO ;
       return 0;
     }
   }
   cout <<  YES ;
 }


#include <bits/stdc++.h>
 using namespace std;
 #pragma GCC optimize( -Ofast )
 #pragma GCC optimize( trapv )
 #pragma GCC target( \n      sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native )
 #pragma GCC optimize( -ffast-math )
 #pragma GCC optimize( -funroll-loops )
 #pragma GCC optimize( -funroll-all-loops,-fpeel-loops,-funswitch-loops )
 const int N = 1e3 + 40;
 const int MAXK = 12;
 const long long int INF = 1000000000000000000;
 const int RANDOM =
     chrono::high_resolution_clock::now().time_since_epoch().count();
 long long int expo_pow(long long int x, long long int y) {
   if (y == 0) return 1;
   y = y  ((1000000007) - 1);
   x = (1000000007);
   if (y == 0) y = (1000000007) - 1;
   long long int res = 1;
   while (y) {
     if (y & 1) res = (res * x)  (1000000007);
     x = (x * x)  (1000000007);
     y >>= 1;
   }
   return res;
 }
 long long int modInverse(long long int a, long long int m = (1000000007)) {
   return expo_pow(a, m - 2);
 }
 void solve() {
   int n;
   cin >> n;
   vector<vector<long long int>> cnt(n + 2);
   map<int, int> ones;
   map<int, int> t;
   for (long long int i = (1); i < (n + 1); i++) {
     int tp, w;
     cin >> tp >> w;
     if (w) ones[tp]++;
     t[tp]++;
   }
   for (auto x : t) {
     cnt[x.second].push_back(ones[x.first]);
   }
   priority_queue<pair<long long int, long long int>> pq;
   long long int ans = 0;
   long long int fo = 0;
   set<long long int> second;
   for (long long int i = (1); i < (n + 1); i++) {
     if (1) second.insert(i);
     for (long long int j = (0); j < (cnt[i].size()); j++) {
       pq.push(make_pair(cnt[i][j], i));
     }
   }
   while (second.size()) {
     if (pq.empty()) break;
     int x = pq.top().second;
     auto it = second.upper_bound(x);
     if (it == second.begin()) {
       pq.pop();
       continue;
     }
     it--;
     ans += *it;
     fo += min(*it, pq.top().first);
     pq.pop();
     second.erase(*it);
   }
   cout << ans <<     << fo << '
';
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int T = 1;
   cin >> T;
   while (T--) {
     solve();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 long n, k, iters, p[10000], q[1000], rp[1000], ar[200000], ar1[20000];
 long ans;
 bool not_same() {
   for (int i = 1; i <= n; i++)
     if (ar[i] != q[i]) return true;
   return false;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin >> n >> k;
   for (int i = 1; i <= n; i++) cin >> p[i];
   for (int i = 1; i <= n; i++) cin >> q[i];
   for (int i = 1; i <= n; i++) rp[p[i]] = i;
   long tf = 0;
   for (int i = 1; i <= n; i++)
     if (rp[i] != p[i]) tf = 1;
   ans = 0;
   for (int i = 1; i <= n; i++) ar[i] = i;
   iters = 0;
   while (not_same()) {
     ++iters;
     for (int i = 1; i <= n; i++) ar1[i] = ar[p[i]];
     for (int i = 1; i <= n; i++) ar[i] = ar1[i];
     if (iters > k) break;
   }
   if (iters <= k && iters  2 == k  2) ans = 1;
   for (int i = 1; i <= n; i++) ar[i] = i;
   iters = 0;
   while (not_same()) {
     ++iters;
     for (int i = 1; i <= n; i++) ar1[i] = ar[rp[i]];
     for (int i = 1; i <= n; i++) ar[i] = ar1[i];
     if (iters > k) break;
   }
   if (iters <= k && iters  2 == k  2) ans = 1;
   long fl = 0;
   for (int i = 1; i <= n; i++)
     if (q[i] != i) fl = 1;
   if (fl == 0) ans = 0;
   if (tf == 0 && k > 1) ans = 0;
   if (ans)
     cout <<  YES  << endl;
   else
     cout <<  NO  << endl;
   cin.get();
   cin.get();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, a, b, ans = 6;
 int len[15], last[15];
 void dfs(int x, int va) {
   if (x == 7) {
     ans = min(ans, va);
     return;
   }
   for (int i = 1; i <= va; i++) {
     if (last[i] >= len[x]) {
       last[i] -= len[x];
       dfs(x + 1, va);
       last[i] += len[x];
     }
   }
   last[va + 1] = n - len[x];
   dfs(x + 1, va + 1);
 }
 int main() {
   scanf( ddd , &n, &a, &b);
   for (int i = 1; i <= 4; i++) len[i] = a;
   for (int i = 5; i <= 6; i++) len[i] = b;
   dfs(1, 0);
   printf( d , ans);
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   vector<string> s;
   set<string> ss;
   string a, b, res;
   int n, cnt_a = 0, cnt_b = 0;
   cin >> n;
   for (int i = 0; i < n; i++) {
     cin >> a;
     ss.insert(a);
     s.push_back(a);
   }
   if (ss.size() == 1)
     cout << s[0] << endl;
   else {
     sort(s.begin(), s.end());
     a = s[0];
     b = s[n - 1];
     for (int i = 0; i < n; i++) {
       if (s[i].compare(a) == 0)
         cnt_a++;
       else
         cnt_b++;
     }
     res = (cnt_a > cnt_b) ? a : b;
     cout << res << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int t;
   cin >> t;
   int x, y;
   while (t--) {
     cin >> x >> y;
     if (y <= sqrt(x)) {
       if (x  2 == 0 && y  2 == 0)
         cout <<  YES  << endl;
       else if (x  2 == 1 && y  2 == 1)
         cout <<  YES  << endl;
       else
         cout <<  NO  << endl;
     } else
       cout <<  NO  << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 1000003;
 long double pi = 3.1415926536;
 const int mx = 1000003;
 long long gcd(long long x, long long y) {
   if (y == 0) return x;
   return gcd(y, x  y);
 }
 long long bp(long long a, long long b) {
   long long ans = 1;
   while (b > 0) {
     if (b & 1) ans = (ans * a)  mod;
     a = (a * a)  mod;
     b >>= 1;
   }
   return ans;
 }
 long long p(long long n) {
   for (long long i = 2; i * i <= n; i++) {
     if (n  i == 0) {
       return n / i;
     }
   }
   return 1;
 }
 void solve() {
   long long a, d, x, i = 1;
   cin >> a >> d;
   x = a++;
   while ((a  i) <= d) {
     x = (a - (a  i));
     i *= 10;
   }
   cout << x - 1;
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   solve();
 }


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


#include <bits/stdc++.h>
 using namespace std;
 long long qitaceruts(long long num) {
   long long n = 0, d, p = 1;
   while (num > 0) {
     d = num  10;
     num = num / 10;
     if (d != 0) {
       n = (d * p) + n;
       p *= 10;
     }
   }
   return n;
 }
 int main() {
   long long a, b, c1, c2;
   cin >> a >> b;
   c1 = a + b;
   a = qitaceruts(a);
   b = qitaceruts(b);
   c1 = qitaceruts(c1);
   if (a + b == c1) {
     cout <<  YES
 ;
   } else {
     cout <<  NO
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 string s1, s2;
 int main() {
   int n, i, j;
   scanf( d , &n);
   cin >> s1 >> s2;
   int ans = 0;
   for (i = 0; i < (n / 2); i++) {
     j = n - i - 1;
     map<char, int> mp;
     mp[s1[i]]++;
     mp[s1[j]]++;
     mp[s2[i]]++;
     mp[s2[j]]++;
     int len = mp.size();
     if (len == 4)
       ans += 2;
     else if (len == 3)
       ans += 1 + (s1[i] == s1[j]);
     else if (len == 2)
       ans += (mp[s1[i]] != 2);
   }
   if ((n  2) && (s1[n / 2] != s2[n / 2])) ans++;
   printf( d , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios::sync_with_stdio(false);
   cout.tie(0);
   int n;
   cin >> n;
   vector<bool> in(n + 1);
   for (int i = 0; i < n; i++) {
     int a;
     cin >> a;
     in[a] = true;
   }
   vector<int> b(n);
   for (int i = 0; i < n; i++) {
     cin >> b[i];
   }
   int ind = 0;
   int next_ = 1;
   vector<int> c = b;
   for (; next_ <= n; ind++) {
     int t = ind - n - 1;
     if (t >= 0 && t < n) {
       in[b[ind - n - 1]] = true;
     }
     if (c[ind  n] == next_) {
       next_++;
       c[ind  n] = -1;
       continue;
     }
     if (c[ind  n] == -1 && in[next_]) {
       next_++;
       continue;
     }
     c[ind  n] = -1;
     if (ind - next_ + 1 < n) {
       next_ = 1;
     }
   }
   cout << ind - n << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 long long L[500005];
 char ch[500005];
 class segtree {
  public:
   long long seg[(1 << 19) * 2];
   long long lazy[(1 << 19) * 2];
   void lazy_evaluate(int k) {
     if (k * 2 + 2 >= (1 << 19) * 2) return;
     lazy[k * 2 + 2] += lazy[k];
     lazy[k * 2 + 1] += lazy[k];
     seg[k * 2 + 2] += lazy[k];
     seg[k * 2 + 1] += lazy[k];
     lazy[k] = 0;
   }
   long long update(int beg, int end, int idx, int lb, int ub, long long num) {
     if (ub < beg || end < lb) {
       return seg[idx];
     }
     if (beg <= lb && ub <= end) {
       lazy[idx] += num;
       seg[idx] += num;
       return seg[idx];
     }
     if (lazy[idx]) {
       lazy_evaluate(idx);
     }
     return seg[idx] =
                min(update(beg, end, idx * 2 + 1, lb, (lb + ub) / 2, num),
                    update(beg, end, idx * 2 + 2, (lb + ub) / 2 + 1, ub, num));
   }
   long long query(int beg, int end, int idx, int lb, int ub) {
     if (ub < beg || end < lb) {
       return 1500000000000000000LL;
     }
     if (beg <= lb && ub <= end) {
       return seg[idx];
     }
     if (lazy[idx]) {
       lazy_evaluate(idx);
     }
     return min(query(beg, end, idx * 2 + 1, lb, (lb + ub) / 2),
                query(beg, end, idx * 2 + 2, (lb + ub) / 2 + 1, ub));
   }
 } kaede;
 int main() {
   scanf( d , &n);
   for (int i = 0; i < n; i++) scanf( lld , &L[i]);
   scanf( s , &ch);
   long long cur = 0;
   long long ans = 0;
   bool ok = 0;
   for (int i = 0; i < n; i++) {
     if (ch[i] == 'L')
       ans += L[i];
     else if (ch[i] == 'W')
       ans += L[i] * 3LL;
     else
       ans += L[i] * 5LL;
   }
   vector<long long> vec;
   int lasw, lasg;
   for (int i = 0; i < n; i++) {
     if (ch[i] == 'G') {
       cur += L[i];
       kaede.update(i, i, 0, 0, (1 << 19) - 1, cur);
       vec.push_back(L[i]);
       lasg = i;
       continue;
     }
     if (ch[i] == 'W') {
       cur += L[i];
       lasw = i;
       ok = 1;
       kaede.update(i, i, 0, 0, (1 << 19) - 1, cur);
       vec.push_back(L[i]);
       continue;
     }
     if (ch[i] == 'L') {
       if (cur >= L[i]) {
         cur -= L[i];
         kaede.update(i, i, 0, 0, (1 << 19) - 1, cur);
         vec.push_back(L[i]);
         continue;
       } else {
         long long need = L[i] - cur;
         if (ok) {
           ans += 3LL * need;
           vec[lasw] += need;
         } else {
           ans += 5LL * need;
           vec[lasg] += need;
         }
         cur = 0;
         vec.push_back(L[i]);
         kaede.update(i, i, 0, 0, (1 << 19) - 1, cur);
         continue;
       }
     }
   }
   for (int i = n - 1; i >= 0; i--) {
     if (ch[i] == 'L') continue;
     if (ch[i] == 'W') continue;
     long long mn = kaede.query(i, n - 1, 0, 0, (1 << 19) - 1);
     if (2LL * vec[i] <= mn) {
       kaede.update(i, n - 1, 0, 0, (1 << 19) - 1, -2LL * vec[i]);
       ans -= 4LL * vec[i];
     } else {
       kaede.update(i, n - 1, 0, 0, (1 << 19) - 1, -mn);
       ans -= 2LL * mn;
     }
   }
   for (int i = n - 1; i >= 0; i--) {
     if (ch[i] == 'L') continue;
     if (ch[i] == 'G') continue;
     long long mn = kaede.query(i, n - 1, 0, 0, (1 << 19) - 1);
     if (2LL * vec[i] <= mn) {
       kaede.update(i, n - 1, 0, 0, (1 << 19) - 1, -2LL * vec[i]);
       ans -= 2LL * vec[i];
     } else {
       kaede.update(i, n - 1, 0, 0, (1 << 19) - 1, -mn);
       ans -= 1LL * mn;
     }
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MOD = 1e9 + 7;
 const int INF = 0x3f3f3f3f;
 const int MAXN = 3e6 + 3;
 bool appear[MAXN];
 int ans[MAXN];
 signed main() {
   int cnt = 1;
   int n, x;
   scanf( dd , &n, &x);
   int now = 0;
   appear[0] = true;
   appear[x] = true;
   for (int i = 1; i < (1 << n); ++i) {
     if (appear[i]) continue;
     appear[i ^ x] = true;
     ans[cnt++] = i;
   }
   printf( d
 , cnt - 1);
   for (int i = 1; i < cnt; ++i) printf( d  , ans[i] ^ ans[i - 1]);
 }


#include <bits/stdc++.h>
 #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )
 using namespace std;
 void JIZZ(string output =   ) {
   cout << output;
   exit(0);
 }
 const long double PI = 3.14159265358979323846264338327950288;
 const long double eps = 1e-13;
 const long long mod = 1e9 + 7;
 long long a[200005], pre[200005];
 vector<int> good;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int n;
   long long k;
   cin >> n >> k;
   for (int i = 1; i <= n; ++i) cin >> a[i];
   for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + a[i];
   for (int i = 1; i <= n; ++i)
     if (a[i] > 1) good.push_back(i);
   good.push_back(n + 1);
   if (0) {
     long long ans = 0;
     for (int i = 1; i <= n; ++i) {
       long long s = 0, p = 1;
       for (int j = i; j <= n; ++j) {
         if (((long double)p) * a[j] > 2e18) break;
         p *= a[j], s += a[j];
         if (s * k == p) cout << i <<     << j << endl, ++ans;
       }
     }
     cout << ans << endl;
   }
   long long ans = 0;
   for (int i = 1; i <= n; ++i) {
     long long p = a[i], s = a[i];
     int now = i;
     auto ptr = upper_bound(good.begin(), good.end(), i);
     if (s * k <= p && p <= (s + *ptr - now) * k && p  k == 0) ++ans;
     while (p <= 2e18) {
       if (*ptr == n + 1) break;
       if (((long double)p) * a[*ptr] > 2e18) break;
       p *= a[*ptr];
       s += pre[*ptr] - pre[now];
       now = *ptr;
       ++ptr;
       if (s * k <= p && p <= (s + *ptr - now - 1) * k && p  k == 0) ++ans;
     }
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long N, Q;
 long long A[1100100], a, b;
 vector<pair<long long, long long> > qu[1100100];
 long long sol[1100100], dp[1100100];
 long long solve(long long I, long long b) {
   if (I > N) return 0;
   long long ret = A[I];
   return ret += solve(I + b, b);
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cin >> N;
   for (long long I = 1; I <= N; I++) cin >> A[I];
   cin >> Q;
   for (long long q = 1; q <= Q; q++) {
     cin >> a >> b;
     qu[b].push_back(pair<long long, long long>(a, q));
   }
   for (long long b = 1; b <= N; b++) {
     if (b < 300) {
       for (long long I = N; I >= 1; I--) {
         dp[I] = A[I];
         if (I + b <= N) dp[I] += dp[I + b];
       }
       for (typeof((qu[b]).begin()) it = (qu[b]).begin(); it != (qu[b]).end();
            it++)
         sol[it->second] = dp[it->first];
     } else {
       for (typeof((qu[b]).begin()) it = (qu[b]).begin(); it != (qu[b]).end();
            it++)
         sol[it->second] = solve(it->first, b);
     }
   }
   for (long long q = 1; q <= Q; q++) cout << sol[q] <<
 ;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX = 100000 + 10;
 int n, m;
 pair<int, int> s[MAX];
 pair<long long, long long> ans;
 void update(long long a, long long b) {
   if (b <= 0) return;
   if (a > ans.first) {
     ans.first = a;
     ans.second = b;
   } else if (a == ans.first)
     ans.second += b;
 }
 void work1() {
   int i, mi = n, mm = 0;
   long long num = 0;
   for ((i) = (1); (i) <= (m); ++(i))
     if (s[i].first == 0) {
       ++num;
       mi = min(mi, s[i].second);
       mm = max(mm, s[i].second);
     }
   long long num_mi = 0, num_mm = 0;
   for ((i) = (1); (i) <= (m); ++(i)) {
     if (s[i].first == 0 && s[i].second == mi) ++num_mi;
     if (s[i].first == 0 && s[i].second == mm) ++num_mm;
   }
   if (mm == mi) {
     update(0, num * (num - 1) * (num - 2) / 6);
     return;
   }
   num -= num_mi;
   num -= num_mm;
   update((mm - mi) * 2, (num_mi - 1) * num_mi / 2 * num_mm +
                             (num_mm - 1) * num_mm / 2 * num_mi +
                             num * num_mi * num_mm);
 }
 int cmp(pair<int, int> a, pair<int, int> b) {
   if (a.second != b.second)
     return a.second < b.second;
   else
     return a.first < b.first;
 }
 void work2() {
   sort(s + 1, s + m + 1, cmp);
   int i;
   long long num0 = 0;
   for ((i) = (1); (i) <= (m); ++(i))
     if (s[i].first == 0) ++num0;
   int largb = 0, numb = 0, tmp = num0;
   for ((i) = (1); (i) <= (m); ++(i))
     if (s[i].first == 0) {
       --tmp;
       if (largb != s[i].second)
         update(2LL * n + 2 * largb - 2 * s[i].second, (long long)tmp * numb);
     } else if (s[i].second == largb)
       ++numb;
     else if (s[i].second > largb)
       largb = s[i].second, numb = 1;
   int smallb = n + 1;
   numb = 0;
   tmp = num0;
   for (i = m; i >= 1; --i)
     if (s[i].first == 0) {
       --tmp;
       if (smallb != s[i].second)
         update(2LL * n - 2 * smallb + 2 * s[i].second, (long long)tmp * numb);
     } else if (s[i].second == smallb)
       ++numb;
     else if (s[i].second < smallb)
       smallb = s[i].second, numb = 1;
   map<int, int> hash;
   for ((i) = (1); (i) <= (m); ++(i))
     if (s[i].first == 0) hash[s[i].second]++;
   tmp = 0;
   for ((i) = (1); (i) <= (m); ++(i)) {
     if (s[i].first == 0)
       ++tmp;
     else {
       long long u = hash[s[i].second];
       long long now = (long long)tmp * (num0 - tmp) +
                       (long long)u * (u - 1) / 2 + (tmp - u) * u;
       update(2LL * n, now);
     }
   }
 }
 void work() {
   work1();
   work2();
 }
 int main() {
   int i;
   scanf( dd , &n, &m);
   for ((i) = (1); (i) <= (m); ++(i)) scanf( dd , &s[i].first, &s[i].second);
   work();
   for ((i) = (1); (i) <= (m); ++(i)) s[i].first ^= 1;
   work();
   cout << ans.second << endl;
   return 0;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 const int N = 200005;
 const int inf = 1e9 + 7;
 int main() {
   int n;
   scanf( d , &n);
   while (n--) {
     int x;
     scanf( d , &x);
     if (x <= 3 || x == 5 || x == 7 || x == 11)
       puts( -1 );
     else {
       int ans = 0, tg = x & 3;
       if (!tg) ans = max(ans, x / 4);
       if (tg == 2) ans = max(ans, 1 + (x - 6) / 4);
       if (tg == 1) ans = max(ans, 1 + (x - 9) / 4);
       if (tg == 3) ans = max(ans, 2 + (x - 15) / 4);
       printf( d
 , ans);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int Maxn = ((int)1e5) + 100;
 int arr[Maxn], n;
 map<int, int> num, numL, numR;
 long long Solve(int a[]) {
   int l = 0, r = n - 1;
   while (a[l] == a[r] && l < r) ++l, --r;
   if (l >= r) return n * 1ll * (n + 1) / 2;
   for (int(i) = (l); (i) <= (r); ++(i)) num[a[i]] += 1;
   int odds = 0, key = -1;
   for (auto it = num.begin(); it != num.end(); ++it)
     if ((it->second) & 1) odds += 1, key = it->first;
   if (odds > 1) return 0;
   int oks = 0, l2 = l - 1;
   while (oks < num.size()) {
     numL[a[++l2]] += 1;
     int _a = numL[a[l2]] << 1;
     int _b = _a - 2, _c = num[a[l2]];
     if (_a >= _c && _b < _c) ++oks;
   }
   oks = 0;
   int r2 = r + 1;
   while (oks < num.size()) {
     numR[a[--r2]] += 1;
     int _a = numR[a[r2]] << 1;
     int _b = _a - 2, _c = num[a[r2]];
     if (_a >= _c && _b < _c) ++oks;
   }
   int mid = (r + l) >> 1;
   if (l2 <= mid && (!(n & 1) || a[mid] == key)) {
     int g, h;
     if (n & 1)
       g = mid - 1, h = mid + 1;
     else
       g = mid, h = mid + 1;
     while (a[g] == a[h]) --g, ++h;
     l2 = g, r2 = h;
   }
   long long sum = 0;
   sum += (l + 1) * 1ll * (n - l2);
   sum += (n - r) * 1ll * (r2 + 1);
   sum -= (l + 1) * 1ll * (n - r);
   return sum;
 }
 int main() {
   iostream::sync_with_stdio(false);
   cin >> n;
   for (int(i) = (0); (i) <= (n - 1); ++(i)) cin >> arr[i];
   cout << Solve(arr) << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 1e9;
 const long long INF = 1e18;
 const int M = 1e9 + 7;
 const int maxn = 1e6;
 int b[maxn], c[maxn];
 signed main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cout.setf(ios::fixed);
   cout.precision(10);
   int m, k, n, s;
   cin >> m >> k >> n >> s;
   vector<int> a(m);
   for (int i = 0; i < m; ++i) {
     cin >> a[i];
   }
   for (int i = 0; i < s; ++i) {
     int x;
     cin >> x;
     ++b[x];
   }
   int res = inf;
   int l = 0, r = 0, cnt = 0;
   int L = 0, R = 0;
   while (r < m) {
     while (r < m && cnt < s) {
       if (c[a[r]] < b[a[r]]) {
         ++cnt;
       }
       ++c[a[r]];
       ++r;
     }
     while (l < m && cnt == s) {
       int tl = l / k, tr = (r - 1) / k;
       int tot;
       if (tl == tr) {
         tot = 0;
       } else {
         tot = r - tl * k - k;
       }
       if (tot < res) {
         L = l;
         R = r - 1;
         res = tot;
       }
       c[a[l]]--;
       if (c[a[l]] < b[a[l]]) {
         --cnt;
       }
       ++l;
     }
   }
   if ((m - res) / k < n) {
     cout << -1 << endl;
   } else {
     cout << res << endl;
     for (int i = R; i >= L - L  k; --i) {
       if (res == 0) break;
       if (!b[a[i]]) {
         cout << i + 1 << ' ';
         --res;
       } else {
         --b[a[i]];
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 100007;
 const int maxv = 100000;
 long long fac[maxn], fac2[maxn];
 map<pair<int, int>, int> save;
 int cnt;
 long long mypow(int base, int n) {
   if (n == 0) return 1;
   long long t = mypow(base, n / 2);
   t = (t * t)  1000000007;
   if (n & 1)
     return (t * base)  1000000007;
   else
     return t;
 }
 long long C(int n, int k) {
   long long res = fac[n] * fac2[k]  1000000007;
   res = res * fac2[n - k]  1000000007;
   return res;
 }
 long long solve(int f, int n) {
   if (f == 1) return (n == 1);
   if (f == n) return 1;
   if (f > n) return 0;
   if (save.count(pair<int, int>(f, n))) return save[pair<int, int>(f, n)];
   long long res = 0;
   for (int i = 2; i * i <= n; i++)
     if (n  i == 0) {
       int x = i;
       res = (res + solve(f, n / x))  1000000007;
       if (i * i == n) continue;
       x = n / i;
       res = (res + solve(f, n / x))  1000000007;
     }
   save[pair<int, int>(f, n)] =
       (C(n - 1, f - 1) - res + 1000000007)  1000000007;
   return save[pair<int, int>(f, n)];
 }
 int main() {
   fac[0] = 1;
   for (int i = 1, _c = maxv; i <= _c; i++) fac[i] = fac[i - 1] * i  1000000007;
   for (int v = 0, _c = maxv; v <= _c; v++)
     fac2[v] = mypow(fac[v], 1000000007 - 2);
   int q, f, n;
   scanf( d , &q);
   for (int i = 0, _a = (q); i < _a; ++i) {
     scanf( dd , &n, &f);
     printf( extra
 , solve(f, n));
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 inline long long in() {
   int32_t x;
   scanf( d , &x);
   return x;
 }
 inline string getStr() {
   char ch[1000000];
   scanf( s , ch);
   return ch;
 }
 const long long MOD = 1e9 + 7;
 const long long base = 29;
 const long long MAX_N = 3e5 + 1;
 inline long long divide(long long a, long long b) { return (a + b - 1) / b; }
 vector<long long> g[MAX_N];
 long long deg[MAX_N];
 bool vis[MAX_N];
 long long res[MAX_N];
 inline void dfs(long long node, long long part) {
   if (vis[node] == true) return;
   res[node] = part;
   long long cnt = 0;
   for (long long i = 0; i < g[node].size(); i++) {
     long long u = g[node][i];
     if (res[node] == res[u]) cnt++;
   }
   if (cnt > 1) {
     res[node] ^= 1;
     dfs(node, res[node]);
     vis[node] = false;
     return;
   }
   vis[node] = true;
   for (long long pt = 0; pt < g[node].size(); pt++) {
     long long u = g[node][pt];
     if (res[u] == res[node]) {
       dfs(u, res[u]);
       vis[node] = 0;
       return;
     }
   }
   vis[node] = false;
 }
 int32_t main() {
   long long n = in(), m = in();
   for (long long i = 0; i < m; i++) {
     long long v = in(), u = in();
     deg[v]++, deg[u]++;
     g[v].push_back(u);
     g[u].push_back(v);
   }
   for (long long i = 1; i <= n; i++) res[i] = 1;
   for (long long i = 1; i <= n; i++) {
     dfs(i, res[i]);
   }
   for (long long i = 1; i <= n; i++) cout << res[i];
 }


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


#include <bits/stdc++.h>
 using namespace std;
 int n, x, y, z, x_, y_, z_;
 int main() {
   cin >> n;
   for (int i = 0; i < n; i++) {
     cin >> x_ >> y_ >> z_;
     x += x_;
     z += z_;
     y += y_;
   }
   if (x != 0 || y != 0 || z != 0)
     cout <<  NO  << endl;
   else
     cout <<  YES  << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct IInt {
   int z;
 };
 bool cmp(int a, int b) { return a < b; }
 bool operator<(IInt a, IInt b) { return a.z > b.z; }
 int main() {
   int n, m, x, i, ans, ans1;
   IInt t;
   scanf( dd , &n, &m);
   vector<int> q;
   priority_queue<IInt> w;
   for (i = 0; i < m; i++) {
     scanf( d , &x);
     q.push_back(x);
     t.z = x;
     w.push(t);
   }
   make_heap(q.begin(), q.end(), cmp);
   ans = ans1 = 0;
   for (i = 0; i < n; i++) {
     ans += q[0];
     q[0]--;
     make_heap(q.begin(), q.end(), cmp);
   }
   for (i = 0; i < n; i++) {
     t = w.top();
     w.pop();
     ans1 += t.z;
     if (t.z == 1) {
       continue;
     } else {
       t.z--;
       w.push(t);
     }
   }
   printf( d d
 , ans, ans1);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2005, M = 2000010;
 const long long MOD = 1E9 + 7;
 long long Pow(long long a, long long b) {
   long long c = 1;
   for (; b; a = a * a  MOD, b >>= 1)
     if (b & 1) c = c * a  MOD;
   return c;
 }
 struct Node {
   int x, y;
   bool operator<(const Node &a) const {
     return (x != a.x) ? (x < a.x) : (y < a.y);
   }
 } p[N];
 int h, w, n, m;
 long long fac[M], fac_inv[M];
 long long f[N];
 void Init() {
   fac[0] = 1;
   for (int i = 1; i <= m; ++i) fac[i] = fac[i - 1] * i  MOD;
   fac_inv[m] = Pow(fac[m], MOD - 2);
   for (int i = m; i; --i) fac_inv[i - 1] = fac_inv[i] * i  MOD;
   return;
 }
 inline long long F(int a, int b) {
   return fac[a + b] * fac_inv[a]  MOD * fac_inv[b]  MOD;
 }
 int main() {
   scanf( ddd , &h, &w, &n);
   m = h + w;
   Init();
   for (int i = 1; i <= n; ++i) scanf( dd , &p[i].x, &p[i].y);
   sort(p + 1, p + n + 1);
   for (int i = 1; i <= n; ++i) {
     f[i] = F(p[i].x - 1, p[i].y - 1);
     for (int j = 1; j < i; ++j)
       if (p[j].y <= p[i].y)
         f[i] = (f[i] + MOD - f[j] * F(p[i].x - p[j].x, p[i].y - p[j].y)  MOD)
                MOD;
   }
   long long res = F(h - 1, w - 1);
   for (int i = 1; i <= n; ++i)
     res = (res + MOD - f[i] * F(h - p[i].x, w - p[i].y)  MOD)  MOD;
   printf( lld
 , res);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int h1, a1, c1, h2, a2;
   int move_counter = 0;
   vector<char> move;
   cin >> h1 >> a1 >> c1 >> h2 >> a2;
   while (h2 > 0) {
     if (h2 - a1 <= 0) {
       move.push_back('S');
       ++move_counter;
       break;
     } else {
       if (h1 - a2 <= 0) {
         h1 += c1;
         move.push_back('H');
         ++move_counter;
       } else {
         h2 -= a1;
         move.push_back('S');
         ++move_counter;
       }
       h1 -= a2;
     }
   }
   cout << move_counter << '
';
   for (const auto it : move) {
     if (it == 'H')
       cout <<  HEAL  << '
';
     else
       cout <<  STRIKE  << '
';
   }
 }