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


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


#include <bits/stdc++.h>
 using namespace std;
 char buffer[200];
 int main() {
   int n;
   string data;
   while (scanf( d , &n) != EOF) {
     getchar();
     for (int i = 0; i < n; i++) {
       gets(buffer);
       data = string(buffer);
       int firstM = data.find( miao. );
       int lastL = data.rfind( lala. );
       if (firstM != data.npos &&
           (lastL == data.npos || lastL != data.size() - 5) && firstM == 0) {
         printf( Rainbow's
 );
       } else if ((firstM == data.npos || firstM != 0) && lastL != data.npos &&
                  lastL == data.size() - 5) {
         printf( Freda's
 );
       } else {
         printf( OMG>.< I don't know!
 );
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MOD = 1e9 + 7;
 const long double PI = 3.1415926535898;
 const long long LLMAX = LLONG_MAX;
 int a[(int)2e5 + 5], b[(int)2e5 + 5], c[(int)2e5 + 5];
 int n;
 vector<vector<int> > v((int)2e5 + 5);
 int type10 = 0;
 int type01 = 0;
 long long ans = 0;
 int one[(int)2e5 + 5] = {0};
 int zero[(int)2e5 + 5] = {0};
 void solve(int parent, int node) {
   if (b[node] != c[node]) {
     if (b[node])
       one[node]++;
     else
       zero[node]++;
   }
   if (parent) a[node] = min(a[node], a[parent]);
   for (int i = 0; i < v[node].size(); i++) {
     if (v[node][i] == parent)
       continue;
     else {
       solve(node, v[node][i]);
       one[node] += one[v[node][i]];
       zero[node] += zero[v[node][i]];
     }
   }
   int dec = min(one[node], zero[node]);
   one[node] -= dec;
   zero[node] -= dec;
   ans += (long long)a[node] * 2 * dec;
 }
 int main() {
   int x, y;
   cin >> n;
   for (int i = 1; i <= n; i++) {
     cin >> a[i] >> b[i] >> c[i];
     if (b[i] == 0 && c[i] == 1)
       type01++;
     else if (b[i] == 1 && c[i] == 0)
       type10++;
   }
   for (int i = 1; i < n; i++) {
     cin >> x >> y;
     v[x].push_back(y);
     v[y].push_back(x);
   }
   solve(0, 1);
   if (type01 != type10) {
     cout << -1 <<
 ;
   } else {
     cout << ans <<
 ;
   }
 }


#include<bits/stdc++.h>
 using namespace std;
 #define mp make_pair
 #define fi first
 #define se second
 #define pb push_back
 #define pf push_front
 #define ppb pop_back
 #define ppf pop_front
 #define sz(v) (v).size()
 #define all(v) (v).begin(),(v).end()
 #define REP(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
 #define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
 #define Time (double)clock()/CLOCKS_PER_SEC
 typedef long long ll;
 typedef unsigned long long ull;
 typedef double db;
 typedef long double ldb;
 typedef pair<int,int> pi;
 template <class T> void chmax(T &x,T y) {x=x>y?x:y;return;}
 template <class T> void chmin(T &x,T y) {x=x<y?x:y;return;}
 template <class T> T sqr(T x) {return x*x;}
 template <class T> T gcd(T x,T y) {return y==0?x:gcd(y,xy);}
 template <class T> T lcm(T x,T y) {return x/gcd(x,y)*y;}
 const int inf=1000000000,mod=1000000007;
 const ll infll=1000000000000000000ll,modll=ll(mod);
 const db maxdb=db(infll),eps=1e-14,PI=acos(-1.0);
 //#define mydef
 //#define LOCAL
 #ifdef mydef
 #define foreach(v,it) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
 #endif
 #define debug
 #define putnum(x) cout<<#x<< :  <<x<<endl
 #define putvec(v) cout<<#v<< :  ;REP(i,0,sz(v)) cout<<v[i]<<   ;cout<<endl
 template <class T> inline void read(T &x){
 	T w=1;x=0;char c=getchar();
 	while(c<'0'||c>'9') {if(c=='-')w=-1;c=getchar();}
 	while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+(c&15);c=getchar();}
 	x*=w;
 }
 template <class T> inline void write(T x) {
 	if(x<0) putchar('-'),x=~x+1;
 	if(x) write(x/10),putchar(x10+'0');
 }

 const int maxn=200005;
 int n;
 ll sum[2],a[maxn];
 vector<ll> odd,even;

 void solve() {
 	odd.clear();
 	even.clear();
 	cin>>n;
 	for(int i=1;i<=n;i++) {
 		cin>>a[i];
 		if(a[i]&1ll) odd.pb(a[i]);
 		else even.pb(a[i]);
 	}
 	sort(all(odd));
 	sort(all(even));

 	sum[0]=sum[1]=0ll;
 	int p=0;
 	for(int i=0;i<n;i++) {
 		ll A=even.empty()?-infll:even.back();
 		ll B=odd.empty()?-infll:odd.back();
 		if(A>B) {
 			if(!p) sum[p]+=A;
 			even.ppb();
 		} else {
 			if(p) sum[p]+=B;
 			odd.ppb();
 		}
 		p^=1;
 	}
 	cout<<(sum[0]>sum[1]? Alice :(sum[0]==sum[1]? Tie : Bob ))<<endl;
 	return;
 }

 int main() {
 	#ifdef LOCAL
 		freopen( input.in , r ,stdin);
 		freopen( output.out , w ,stdout);
 	#endif
 	int T;
 	cin>>T;
 	while(T--) solve();
 	return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using ll = long long;
 using vi = vector<int>;
 using vpi = vector<pair<int, int>>;
 using pi = pair<int, int>;
 const int nax = 1e5 + 7;
 const int mod = 1e9 + 7;
 const int inf = numeric_limits<int>::max() - (int)9e6;
 struct monotonic_queue {
   queue<int> qu;
   deque<int> mx, mn;
   void push(int v) {
     qu.push(v);
     while (mx.size() && mx.back() < v) mx.pop_back();
     mx.push_back(v);
     while (mn.size() && mn.back() > v) mn.pop_back();
     mn.push_back(v);
   }
   void pop() {
     if (mx.front() == qu.front()) mx.pop_front();
     if (mn.front() == qu.front()) mn.pop_front();
     qu.pop();
   }
   int front() const { return qu.front(); }
   int max() const { return mx.front(); }
   int min() const { return mn.front(); }
   int size() const { return qu.size(); }
   bool empty() { return qu.empty(); }
 };
 int n;
 void test() {
   cin >> n;
   int s, l;
   cin >> s >> l;
   vi v(n);
   for (int i = 0; i < (int)n; i++) cin >> v[i];
   monotonic_queue q;
   vi g(n, n);
   for (int i = n - 1, j = n - 1; i >= 0; i--) {
     while (j >= 0 and (q.empty() or (((q.max() - q.min()) <= s)))) {
       q.push(v[j--]);
     }
     g[i] = (((q.max() - q.min()) <= s) ? j : j + 1);
     if (((int)(q).size())) q.pop();
   }
   while (((int)(q).size())) q.pop();
   vi dp(n + 1, inf);
   dp[0] = 0;
   for (int i = l, j = 0; i <= n; i++) {
     q.push(dp[i - l]);
     while (((int)(q).size()) and j <= g[i - 1]) q.pop(), j++;
     if (((int)(q).size())) dp[i] = q.min() + 1;
   }
   cout << (dp[n] >= inf ? -1 : dp[n]);
 }
 signed main() {
   ios_base ::sync_with_stdio(false);
   cin.tie(NULL);
   int T = 1;
   while (T--) {
     test();
     cout <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e5 + 5;
 int a[20];
 long long ans, p[] = {1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29}, limit = 1e18;
 void dfs(int num, int len) {
   if (num == 1) {
     long long res = 1;
     for (int i = 1; i <= len; ++i) {
       for (int j = 1; j < a[i]; ++j) {
         if (limit / p[i] <= res) {
           return;
         }
         res *= p[i];
       }
     }
     ans = min(ans, res);
     return;
   }
   for (int i = 2; i <= num; ++i) {
     if (num  i == 0) {
       a[len + 1] = i;
       dfs(num / i, len + 1);
     }
   }
 }
 int main() {
   int n;
   cin >> n;
   if (n == 1) {
     cout << 1 << endl;
     return 0;
   } else if (n == 2) {
     cout << 2 << endl;
     return 0;
   }
   ans = limit;
   for (int i = 1; i <= n; ++i) {
     if (n  i == 0) {
       a[1] = i;
       dfs(n / i, 1);
     }
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long oo = 0x3f3f3f3f3f3f3f3fLL;
 struct Edge {
   int u, v;
   long long cap[2], flow;
 };
 vector<int> d, act;
 bool bfs(int s, int t, vector<vector<int>>& adj, vector<Edge>& E,
          long long lim = 1) {
   queue<int> Q;
   d = vector<int>(adj.size(), -1);
   d[t] = 0;
   Q.push(t);
   for (Q.push(t); Q.size() and d[s] == -1; Q.pop()) {
     int u = Q.front();
     for (int i = (0); i < int(adj[u].size()); i++) {
       int e = adj[u][i], v = (E[e].u ^ E[e].v ^ u);
       if (((E[e].u == v) ? E[e].cap[0] - E[e].flow : E[e].cap[1] + E[e].flow) >=
               lim and
           d[v] == -1) {
         d[v] = d[u] + 1;
         Q.push(v);
       }
     }
   }
   return d[s] >= 0;
 }
 long long dfs(int u, int t, long long bot, vector<vector<int>>& adj,
               vector<Edge>& E) {
   if (bot == 0) return 0;
   if (u == t) return bot;
   for (; act[u] < int(adj[u].size()); ++act[u]) {
     int e = adj[u][act[u]];
     if (d[u] == d[(E[e].u ^ E[e].v ^ u)] + 1) {
       long long inc = dfs((E[e].u ^ E[e].v ^ u), t,
                           min(bot, ((E[e].u == u) ? E[e].cap[0] - E[e].flow
                                                   : E[e].cap[1] + E[e].flow)),
                           adj, E);
       if (inc) {
         E[e].flow += ((E[e].u == u) ? (inc) : (-(inc)));
         return inc;
       }
     }
   }
   return 0;
 }
 long long maxflow(int s, int t, vector<vector<int>>& adj, vector<Edge>& E,
                   int F = 0) {
   for (auto& e : E) e.flow = 0;
   long long flow = 0, bot;
   for (int lim = (1 << F); lim >= 1; lim >>= 1) {
     while (bfs(s, t, adj, E, lim)) {
       act = vector<int>(adj.size(), 0);
       while ((bot = dfs(s, t, oo, adj, E))) flow += bot;
     }
   }
   return flow;
 }
 inline void addEdge(int x, int y, vector<vector<int>>& adj, vector<Edge>& E,
                     long long c, long long rc = 0) {
   Edge e;
   e.u = x;
   e.v = y;
   e.flow = 0;
   e.cap[0] = c;
   e.cap[1] = rc;
   adj[x].push_back(int((E).size()));
   adj[y].push_back(int((E).size()));
   E.push_back(e);
 }
 long long anss = 0;
 void gomory_hu(vector<vector<int>>& adj, vector<Edge>& E, vector<int>& parent,
                vector<vector<long long>>& ans) {
   int n = int((adj).size());
   parent.assign(n, 0);
   ans.assign(n, vector<long long>(n, oo));
   for (int i = (1); i < int(n); i++) {
     long long f = maxflow(i, parent[i], adj, E);
     anss += f;
     bfs(i, parent[i], adj, E);
     for (int j = (i + 1); j < int(n); j++)
       if (d[j] == -1 and parent[j] == parent[i]) parent[j] = i;
     ans[i][parent[i]] = ans[parent[i]][i] = f;
     for (int j = (0); j < int(i); j++)
       ans[i][j] = ans[j][i] = min(f, ans[parent[i]][j]);
   }
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int n, m;
   cin >> n >> m;
   vector<vector<int>> adj(n);
   vector<Edge> E;
   for (int i = (0); i < int(m); i++) {
     int a, b, c;
     cin >> a >> b >> c;
     --a, --b;
     addEdge(a, b, adj, E, c, c);
   }
   vector<int> par;
   vector<vector<long long>> d;
   gomory_hu(adj, E, par, d);
   cout << anss << endl;
   int best = 0;
   vector<int> res(n);
   for (int i = 0; i < n; ++i) {
     res[i] = i;
   }
   for (int i = 0; i < 1; ++i) {
     vector<int> order;
     order.push_back(i);
     vector<int> used(n, 0);
     used[i] = true;
     int score = 0;
     while (int((order).size()) != n) {
       int best = -1, index = -1;
       for (int j = 0; j < n; ++j) {
         if (!used[j] && d[order.back()][j] > best) {
           best = d[order.back()][j];
           index = j;
         }
       }
       score += best;
       order.push_back(index);
       used[index] = true;
     }
     if (score > best) {
       best = score;
       res = order;
     }
   }
   for (int i = 0; i < res.size(); ++i) {
     printf( d  , res[i] + 1);
   }
   printf(
 );
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 0x3f3f3f3f;
 const long long INF = 0x3f3f3f3f3f3f3f3fll;
 const int maxn = 1000010;
 const long long mod = 1e9 + 7;
 char str1[maxn], str2[maxn];
 int ans[maxn];
 long long L1[maxn], R1[maxn], L2[maxn], R2[maxn];
 int main() {
   while (scanf( s , str1 + 1) != -1) {
     scanf( s , str2 + 1);
     int len1 = strlen(str1 + 1);
     int len2 = strlen(str2 + 1);
     if (len1 - 1 != len2) {
       printf( 0
 );
       continue;
     }
     L1[0] = 0;
     L2[0] = 0;
     R1[len1 + 1] = 0;
     R2[len2 + 1] = 0;
     for (int i = 1; i <= len1; i++) L1[i] = (L1[i - 1] * 26 + str1[i])  mod;
     for (int i = len1; i >= 1; i--) R1[i] = (R1[i + 1] * 26 + str1[i])  mod;
     for (int i = 1; i <= len2; i++) L2[i] = (L2[i - 1] * 26 + str2[i])  mod;
     for (int i = len2; i >= 1; i--) R2[i] = (R2[i + 1] * 26 + str2[i])  mod;
     int len = 0;
     for (int i = 1; i <= len1; i++) {
       if (L1[i - 1] == L2[i - 1] && R1[i + 1] == R2[i]) ans[len++] = i;
     }
     printf( d
 , len);
     for (int i = 0; i < len; i++) {
       if (i == len - 1)
         printf( d
 , ans[i]);
       else
         printf( d  , ans[i]);
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int gcd(int a, int b) { return b == 0 ? a : gcd(b, a  b); }
 const int MAXN = 100000;
 const int MAXQ = 200000;
 int nq;
 int qkind[MAXQ], qx[MAXQ], qy[MAXQ], qans[MAXQ];
 int n;
 map<pair<int, int>, int> mp;
 int px[MAXN], py[MAXN], pl[MAXN], pr[MAXN];
 map<long long, vector<int>> byrad;
 map<pair<int, int>, vector<pair<int, int>>> matches;
 map<pair<int, int>, vector<pair<int, int>>> singles;
 map<pair<int, int>, vector<int>> queries;
 void run() {
   scanf( d , &nq);
   for (int i = (0); i < (nq); ++i) scanf( ddd , &qkind[i], &qx[i], &qy[i]);
   n = 0;
   mp.clear();
   for (int i = (0); i < (nq); ++i) {
     if (qkind[i] == 1) {
       int id = n++;
       pair<int, int> key = make_pair(qx[i], qy[i]);
       assert(!mp.count(key));
       mp[key] = id;
       px[id] = qx[i], py[id] = qy[i], pl[id] = i, pr[id] = -1;
     }
     if (qkind[i] == 2) {
       pair<int, int> key = make_pair(qx[i], qy[i]);
       assert(mp.count(key));
       int id = mp[key];
       mp.erase(key);
       pr[id] = i;
     }
     if (qkind[i] == 3) {
       qans[i] = ((int)(mp).size());
     }
   }
   for (auto it = mp.begin(); it != mp.end(); ++it) {
     int id = it->second;
     pr[id] = nq;
   }
   mp.clear();
   for (int i = (0); i < (n); ++i)
     byrad[(long long)px[i] * px[i] + (long long)py[i] * py[i]].push_back(i);
   for (auto it = byrad.begin(); it != byrad.end(); ++it) {
     vector<int> lst = it->second;
     for (int ii = (0); ii < (((int)(lst).size())); ++ii)
       for (int jj = (ii + 1); jj < (((int)(lst).size())); ++jj) {
         int i = lst[ii], j = lst[jj];
         int l = max(pl[i], pl[j]), r = min(pr[i], pr[j]);
         if (l > r) continue;
         assert(px[i] != px[j] || py[i] != py[j]);
         int cx = px[i] + px[j], cy = py[i] + py[j], g = gcd(cx, cy);
         cx /= g, cy /= g;
         matches[make_pair(cx, cy)].push_back(make_pair(l, r));
       }
   }
   for (int i = (0); i < (n); ++i) {
     int cx = px[i], cy = py[i], g = gcd(cx, cy);
     cx /= g, cy /= g;
     singles[make_pair(cx, cy)].push_back(make_pair(pl[i], pr[i]));
   }
   for (int i = (0); i < (nq); ++i)
     if (qkind[i] == 3) {
       int cx = qx[i], cy = qy[i], g = gcd(cx, cy);
       cx /= g, cy /= g;
       queries[make_pair(cx, cy)].push_back(i);
     }
   for (auto it = queries.begin(); it != queries.end(); ++it) {
     vector<int> cqueries = it->second;
     vector<pair<int, int>> cmatches = matches[it->first];
     vector<pair<int, int>> csingles = singles[it->first];
     vector<pair<int, int>> evt;
     for (int i = (0); i < (((int)(cmatches).size())); ++i)
       evt.push_back(make_pair(cmatches[i].first, -2)),
           evt.push_back(make_pair(cmatches[i].second + 1, +2));
     for (int i = (0); i < (((int)(csingles).size())); ++i)
       evt.push_back(make_pair(csingles[i].first, -1)),
           evt.push_back(make_pair(csingles[i].second + 1, +1));
     sort(cqueries.begin(), cqueries.end());
     sort(evt.begin(), evt.end());
     int at = 0, sum = 0;
     for (int i = (0); i < (((int)(cqueries).size())); ++i) {
       int id = cqueries[i];
       while (at < ((int)(evt).size()) && id >= evt[at].first)
         sum += evt[at++].second;
       qans[id] += sum;
     }
   }
   for (int i = (0); i < (nq); ++i)
     if (qkind[i] == 3) printf( d
 , qans[i]);
 }
 int main() {
   run();
   return 0;
 }


#include <bits/stdc++.h>
 int main(void) {
   int i, j, k, m, n, max_length, length;
   char string[101];
   for (n = 0, scanf( s , string); string[n]; n++)
     ;
   for (m = 1, max_length = 0; m < n; m++) {
     for (i = m - 1; i >= 0; i--) {
       for (j = i, k = m, length = 0; k && string[j] == string[k];
            j--, k--, length++)
         ;
       if (max_length < length) {
         max_length = length;
       }
     }
   }
   printf( d , max_length);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int K;
   cin >> K;
   int sinir = 2 * K * K;
   int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 27, 31, 37, 39};
   set<int> mynums;
   int i;
   for (i = 0; i < sizeof(primes) / sizeof(int); i++) {
     mynums.clear();
     int t1 = 1, t2 = 1, t = 1;
     for (int j = 0; j <= i; j++) t *= primes[j];
     for (int j = 0; j <= i / 4; j++) t1 *= primes[j] * primes[i - j];
     for (int j = i / 4 + 1; j < i - i / 4; j++) t2 *= primes[j];
     mynums.insert(t);
     for (int y = 0; y < 30; y++) {
       for (int j = 0; j <= i; j++) {
         for (set<int>::iterator it = mynums.begin(); it != mynums.end(); it++) {
           if (*it * primes[j] <= sinir) {
             mynums.insert(*it * primes[j]);
           }
         }
       }
     }
     if (mynums.size() > K) break;
     if (t1 > 1) mynums.insert(t1);
     if (t2 > 1) mynums.insert(t2);
     for (int y = 0; y < 30; y++) {
       for (int j = 0; j <= i; j++) {
         for (set<int>::iterator it = mynums.begin(); it != mynums.end(); it++) {
           if (*it * primes[j] <= sinir) {
             mynums.insert(*it * primes[j]);
           }
         }
       }
     }
     if (mynums.size() <= K / 2) continue;
     if (mynums.size() > K) break;
   }
   set<int>::iterator it = mynums.end();
   it--;
   cout << *it;
   i = 1;
   for (it--; it != mynums.begin() && i < K; it--, i++) cout <<     << *it;
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m, k;
 char s[504][504];
 int vis[504][504];
 vector<pair<char, pair<int, int> > > v;
 vector<pair<int, int> > ord;
 int dx[] = {1, 0, -1, 0};
 int dy[] = {0, 1, 0, -1};
 void dfs(int x, int y) {
   ord.push_back(make_pair(x, y));
   for (int i = 0; i < 4; i++)
     if (x + dx[i] < n and y + dy[i] < m and x + dx[i] >= 0 and
         y + dy[i] >= 0 and s[x + dx[i]][y + dy[i]] != '#' and
         !vis[x + dx[i]][y + dy[i]]) {
       vis[x + dx[i]][y + dy[i]] = 1;
       dfs(x + dx[i], y + dy[i]);
     }
 }
 int main() {
   scanf( ddd , &n, &m, &k);
   for (int i = 0; i < n; i++) scanf( s , &s[i]);
   for (int i = 0; i < n; i++)
     for (int j = 0; j < m; j++)
       if (s[i][j] == '.') v.push_back(make_pair('B', make_pair(i, j)));
   for (int i = 0; i < n; i++)
     for (int j = 0; j < m; j++)
       if (!vis[i][j] and s[i][j] != '#') {
         ord.clear();
         vis[i][j] = 1;
         dfs(i, j);
         for (int k = ord.size() - 1; k >= 1; k--) {
           v.push_back(make_pair('D', ord[k]));
           v.push_back(make_pair('R', ord[k]));
         }
       }
   printf( d
 , v.size());
   for (int i = 0; i < v.size(); i++)
     printf( c d d
 , v[i].first, v[i].second.first + 1,
            v[i].second.second + 1);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void solve() {
   char S[110];
   scanf( s , S);
   int len = strlen(S);
   sort(S, S + len);
   for (int i = 0; i < len - 1; i++) {
     if (S[i + 1] - S[i] != 1) {
       printf( NO
 );
       return;
     }
   }
   printf( YES
 );
 }
 int main() {
   int T;
   scanf( d , &T);
   while (T--) solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int sqr(long long int x) { return x * x; }
 inline long long int add(long long int a, long long int b) {
   long long int c = a + b;
   if (c >= 1000000007) c -= 1000000007;
   return c;
 }
 inline long long int mul(long long int a, long long int b) {
   return (a * 1ll * b)  1000000007;
 }
 inline long long int sub(long long int a, long long int b) {
   long long int c = a - b;
   if (c < 0) c += 1000000007;
   return c;
 }
 const int nax = 1000 * 1000 + 10;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   auto ok = [](vector<int> &v, int pos) {
     swap(v[pos + 1], v[pos + 2]);
     swap(v[pos], v[pos + 1]);
   };
   int t;
   cin >> t;
   while (t--) {
     int n;
     cin >> n;
     vector<int> v(n);
     vector<pair<int, int>> x(n);
     for (int i = 0; i < n; ++i) {
       cin >> v[i];
       x[i] = {v[i], i};
     }
     sort(x.begin(), x.end());
     for (int i = 0; i < n; ++i) {
       v[x[i].second] = i;
     }
     int cnt = 0;
     for (int i = 0; i < n; ++i) {
       for (int j = i + 1; j < n; ++j) {
         cnt += (v[j] < v[i]);
       }
     }
     if (cnt & 1) {
       for (int i = 0; i < n - 1; ++i) {
         if (x[i].first == x[i + 1].first) {
           swap(v[x[i].second], v[x[i + 1].second]);
           break;
         }
       }
     }
     vector<int> ans;
     for (int i = 0; i < n - 2; ++i) {
       int pos = min_element(v.begin() + i, v.end()) - v.begin();
       while (pos > i + 1) {
         ok(v, pos - 2);
         ans.push_back(pos - 2);
         pos -= 2;
       }
       if (pos != i) {
         ok(v, i);
         ok(v, i);
         ans.push_back(i);
         ans.push_back(i);
       }
     }
     for (int i = 0; i < 3; ++i) {
       if (is_sorted(v.begin(), v.end())) break;
       ok(v, n - 3);
       ans.push_back(n - 3);
     }
     if (!is_sorted(v.begin(), v.end())) {
       cout << -1 <<
 ;
     } else {
       cout << ans.size() <<
 ;
       for (int i = 0; i < ans.size(); ++i) cout << ans[i] + 1 <<    ;
       cout <<
 ;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   while (cin >> n) {
     string str;
     cin >> str;
     bool flag = true;
     if (n < 3) {
       if (n == 1) {
         if (str[0] == '1')
           cout <<  Yes  << endl;
         else
           cout <<  No  << endl;
       } else {
         if (str !=  00  && str !=  11 )
           cout <<  Yes  << endl;
         else
           cout <<  No  << endl;
       }
       continue;
     }
     for (int i = 0; i < n - 2; i++) {
       int ans = 0;
       for (int j = i; j < i + 3; j++) {
         ans += str[j] - '0';
       }
       if (ans == 1)
         continue;
       else if (ans == 0 || ans == 3) {
         flag = false;
         break;
       } else {
         if (str[i + 1] != '0') {
           flag = false;
           break;
         }
       }
     }
     if (str[0] == '0' && str[1] == '0' && str[2] == '1') flag = false;
     if (str[n - 1] == '0' && str[n - 2] == '0' && str[n - 3] == '1')
       flag = false;
     if (flag)
       cout <<  Yes  << endl;
     else
       cout <<  No  << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 struct SCC {
   vector<pair<int, int>> minmax;
   int size;
   SCC(vector<int> v) {
     minmax.resize(v.size());
     for (int i = 0; i < (int)v.size(); i++) {
       minmax[i].first = v[i];
       minmax[i].second = v[i];
     }
     size = 1;
   }
   bool operator<(SCC const& other) const {
     for (int i = 0; i < (int)minmax.size(); i++) {
       if (other.minmax[i].first < minmax[i].second) return false;
     }
     return true;
   }
 };
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n, k;
   cin >> n >> k;
   set<SCC> s;
   for (int i = 0; i < n; i++) {
     vector<int> v(k);
     for (int i = 0; i < k; i++) {
       cin >> v[i];
     }
     SCC scc(v);
     auto a = s.lower_bound(scc);
     auto b = s.upper_bound(scc);
     if (a != b) {
       auto x = a;
       while (x != b) {
         for (int K = 0; K < k; K++) {
           scc.minmax[K].first = min(scc.minmax[K].first, x->minmax[K].first);
           scc.minmax[K].second = max(scc.minmax[K].second, x->minmax[K].second);
         }
         scc.size += x->size;
         x++;
       }
       s.erase(a, b);
     }
     s.insert(scc);
     cout << s.rbegin()->size << '
';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 struct he {
   int ind;
   int val;
   he(int ind_ = 0, int val_ = 0) : ind(ind_), val(val_) {}
   bool operator<(const he oth) const { return val > oth.val; }
 };
 int n, m, k;
 vector<int> p[200200], c[200200];
 int minv[200200], maxv[200200];
 int np[200200], nc[200200];
 int ans[200200];
 queue<int> q;
 priority_queue<he> d_cand, id_cand;
 int main() {
   cin >> n >> m >> k;
   for (int i = 1; i <= n; ++i) {
     int a;
     cin >> a;
     if (a == 0) {
       minv[i] = 0;
       maxv[i] = k + 1;
     } else {
       minv[i] = a;
       maxv[i] = a;
     }
   }
   for (int i = 0; i < m; ++i) {
     int a, b;
     cin >> a >> b;
     p[b].push_back(a);
     c[a].push_back(b);
   }
   for (int i = 1; i <= n; ++i) {
     np[i] = p[i].size();
     if (np[i] == 0) {
       maxv[i] = min(k, maxv[i]);
       q.push(i);
     }
   }
   int reached = 0;
   while (!q.empty()) {
     int ind = q.front();
     q.pop();
     ++reached;
     for (int x : c[ind]) {
       maxv[x] = min(maxv[x], maxv[ind] - 1);
       --np[x];
       if (np[x] == 0) q.push(x);
     }
   }
   if (reached < n) {
     cout <<  -1
 ;
     return 0;
   }
   for (int i = 1; i <= n; ++i) {
     nc[i] = c[i].size();
     if (nc[i] == 0) {
       id_cand.push(he(i, minv[i]));
     }
   }
   for (int step = 1; step <= k; ++step) {
     while (!id_cand.empty() && id_cand.top().val <= step) {
       int x = id_cand.top().ind;
       id_cand.pop();
       d_cand.push(he(x, maxv[x]));
     }
     if (d_cand.empty()) {
       cout <<  -1
 ;
       return 0;
     }
     int added = 0;
     while (!d_cand.empty() && d_cand.top().val == step) {
       ++added;
       int x = d_cand.top().ind;
       d_cand.pop();
       ans[x] = step;
       for (int y : p[x]) {
         --nc[y];
         minv[y] = max(minv[y], step + 1);
         if (nc[y] == 0) {
           id_cand.push(he(y, minv[y]));
         }
       }
     }
     if (added == 0) {
       int x = d_cand.top().ind;
       d_cand.pop();
       if (maxv[x] < step) {
         cout <<  -1
 ;
         return 0;
       }
       ans[x] = step;
       for (int y : p[x]) {
         --nc[y];
         minv[y] = max(minv[y], step + 1);
         if (nc[y] == 0) {
           id_cand.push(he(y, minv[y]));
         }
       }
     }
   }
   for (int i = 1; i <= n; ++i) {
     cout << ans[i] <<    ;
   }
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 map<int, int> mp;
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n;
   cin >> n;
   for (int i = 1; i <= n; i++) {
     int num;
     cin >> num;
     mp[num]++;
   }
   if (mp.size() != 2) {
     cout <<  NO ;
     exit(0);
   }
   if (mp.begin()->second != mp.rbegin()->second) {
     cout <<  NO ;
     exit(0);
   }
   cout <<  YES
 ;
   cout << mp.begin()->first << ' ' << mp.rbegin()->first;
   return 0;
 }


#include<cstdio>
 #include<iostream>
 #include<cstring>
 #include<string>
 #include<cmath>
 #include<map>
 #include<algorithm>
 #include<vector>
 #include<set>
 #define Quick ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
 #define ll long long
 #define INF 0x3f3f3f3f
 #define PI acos(-1)
 #define mem(a, b) memset(a, b, sizeof a)
 using namespace std;
 const int N = 1e6 + 3;
 const int mod =1e9 + 7;
 int a[N];
 ll dp[N];
 int vis[N];
 int tot = 0;

 int main()
 {
 	Quick;
 	int n; cin >> n;
 	cout << (n - 1)  9 + 1 << endl;;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e6 + 5;
 int par[N], ran[N];
 struct DSU {
   DSU() {
     for (int i = 1; i < N; ++i) par[i] = i, ran[i] = 1;
   }
   int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
   bool unite(int a, int b) {
     a = find(a), b = find(b);
     if (a == b) return false;
     ran[a] += ran[a] == ran[b];
     if (ran[a] < ran[b]) swap(a, b);
     par[b] = a;
     return true;
   }
 };
 int a[N];
 int n, q;
 vector<int> primes;
 int spf[N];
 void sieve() {
   for (int i = 2; i < N; ++i) {
     if (spf[i] == 0) spf[i] = i, primes.push_back(i);
     int sz = primes.size();
     for (int j = 0; j < sz && i * primes[j] < N && primes[j] <= spf[i]; ++j) {
       spf[i * primes[j]] = primes[j];
     }
   }
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   sieve();
   cin >> n >> q;
   DSU ds;
   for (int i = 1; i <= n; ++i) {
     cin >> a[i];
   }
   for (int i = 1; i <= n; ++i) {
     int x = a[i];
     while (x > 1) {
       ds.unite(spf[a[i]], spf[x]);
       x /= spf[x];
     }
   }
   set<pair<int, int>> pary;
   for (int i = 1; i <= n; ++i) {
     int x = a[i];
     vector<int> v;
     while (x > 1) {
       v.push_back(spf[x]);
       x /= spf[x];
     }
     x = a[i] + 1;
     while (x > 1) {
       v.push_back(spf[x]);
       x /= spf[x];
     }
     v.resize(unique(v.begin(), v.end()) - v.begin());
     for (auto &j : v) {
       j = ds.find(j);
     }
     for (auto j : v) {
       for (auto k : v) {
         if (j < k) pary.insert({j, k});
       }
     }
   }
   while (q--) {
     int x, y;
     cin >> x >> y;
     x = spf[a[x]], y = spf[a[y]];
     if (ds.find(x) == ds.find(y))
       cout << 0 << endl;
     else {
       x = ds.find(x);
       y = ds.find(y);
       if (x > y) swap(x, y);
       if (pary.count({x, y}))
         cout << 1 << endl;
       else
         cout << 2 << endl;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 T extgcd(T a, T b, T& x, T& y) {
   for (T u = y = 1, v = x = 0; a;) {
     T q = b / a;
     swap(x -= q * u, u);
     swap(y -= q * v, v);
     swap(b -= q * a, a);
   }
   return b;
 }
 template <class T>
 T mod_inv(T a, T m) {
   T x, y;
   extgcd(a, m, x, y);
   return (m + x  m)  m;
 }
 long long mod_pow(long long a, long long n, long long mod) {
   long long ret = 1;
   long long p = a  mod;
   while (n) {
     if (n & 1) ret = ret * p  mod;
     p = p * p  mod;
     n >>= 1;
   }
   return ret;
 }
 template <long long mod, long long primitive_root>
 class NTT {
  public:
   long long get_mod() const { return mod; }
   void _ntt(vector<long long>& a, long long sign) {
     const long long n = ((long long)(a).size());
     const long long g = primitive_root;
     long long h = (long long)mod_pow(g, (mod - 1) / n, mod);
     if (sign == -1) h = (long long)mod_inv(h, mod);
     long long i = 0;
     for (long long j = 1; j < n - 1; ++j) {
       for (long long k = n >> 1; k > (i ^= k); k >>= 1)
         ;
       if (j < i) swap(a[i], a[j]);
     }
     for (long long m = 1; m < n; m *= 2) {
       const long long m2 = 2 * m;
       const long long base = mod_pow(h, n / m2, mod);
       long long w = 1;
       for (long long x = 0; x < (m); x++) {
         for (long long s = x; s < n; s += m2) {
           long long u = a[s];
           long long d = a[s + m] * w  mod;
           a[s] = u + d;
           if (a[s] >= mod) a[s] -= mod;
           a[s + m] = u - d;
           if (a[s + m] < 0) a[s + m] += mod;
         }
         w = w * base  mod;
       }
     }
     for (auto& x : a)
       if (x < 0) x += mod;
   }
   void ntt(vector<long long>& input) { _ntt(input, 1); }
   void intt(vector<long long>& input) {
     _ntt(input, -1);
     const long long n_inv = mod_inv(((long long)(input).size()), mod);
     for (auto& x : input) x = x * n_inv  mod;
   }
   vector<long long> convolution(const vector<long long>& a,
                                 const vector<long long>& b) {
     long long ntt_size = 1;
     while (ntt_size < ((long long)(a).size()) + ((long long)(b).size()))
       ntt_size *= 2;
     vector<long long> _a = a, _b = b;
     _a.resize(ntt_size);
     _b.resize(ntt_size);
     ntt(_a);
     ntt(_b);
     for (long long i = 0; i < (ntt_size); i++) {
       (_a[i] *= _b[i]) = mod;
     }
     intt(_a);
     return _a;
   }
   vector<long long> powup(const vector<long long>& a, long long exponent) {
     long long ntt_size = 1;
     while (ntt_size < (((long long)(a).size()) * exponent)) ntt_size *= 2;
     vector<long long> _a = a;
     _a.resize(ntt_size);
     ntt(_a);
     for (long long i = 0; i < (ntt_size); i++) {
       _a[i] = mod_pow(_a[i], exponent, mod);
     }
     intt(_a);
     return _a;
   }
 };
 vector<long long> mul(vector<long long> a, vector<long long> b, long long mod) {
   for (auto& x : a) x = mod;
   for (auto& x : b) x = mod;
   NTT<167772161, 3> ntt1;
   NTT<469762049, 3> ntt2;
   NTT<1224736769, 3> ntt3;
   auto x = ntt1.convolution(a, b);
   auto y = ntt2.convolution(a, b);
   auto z = ntt3.convolution(a, b);
   const long long m1 = ntt1.get_mod(), m2 = ntt2.get_mod(), m3 = ntt3.get_mod();
   const long long m1_inv_m2 = mod_inv<long long>(m1, m2);
   const long long m12_inv_m3 = mod_inv<long long>(m1 * m2, m3);
   const long long m12_mod = m1 * m2  mod;
   vector<long long> ret(((long long)(x).size()));
   for (long long i = 0; i < (((long long)(x).size())); i++) {
     long long v1 = (y[i] - x[i]) * m1_inv_m2  m2;
     if (v1 < 0) v1 += m2;
     long long v2 = (z[i] - (x[i] + m1 * v1)  m3) * m12_inv_m3  m3;
     if (v2 < 0) v2 += m3;
     long long constants3 = (x[i] + m1 * v1 + m12_mod * v2)  mod;
     if (constants3 < 0) constants3 += mod;
     ret[i] = constants3;
   }
   return ret;
 }
 vector<long long> exppoly(vector<long long> base, long long e, long long mod) {
   vector<long long> ans = {1};
   while (e > 0) {
     if (e  2 == 1) {
       ans = mul(ans, base, mod);
       e--;
     } else {
       base = mul(base, base, mod);
       e /= 2;
     }
   }
   return ans;
 }
 const long long MOD = 1000000007LL;
 int main() {
   ios_base::sync_with_stdio(false);
   long long a, b, k, t;
   cin >> a >> b >> k >> t;
   vector<long long> v;
   for (long long x = 0; x < 2 * k + 1; x++) v.push_back(1);
   vector<long long> got = exppoly(v, t, MOD);
   long long len = got.size();
   vector<long long> suf = got;
   for (long long x = len - 2; x >= 0; x--) suf[x] = (suf[x] + suf[x + 1])  MOD;
   long long ans = 0;
   for (long long x = 0; x < len; x++) {
     long long me = b + x;
     long long youneed = max(0LL, me + 1 - a);
     if (youneed >= len) continue;
     ans += (got[x] * suf[youneed]);
     ans = MOD;
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 0x3f3f3f3f;
 bool dp[505][505];
 int c[505];
 int N, K, a[505], b[505];
 long long s1, s2;
 int main() {
   ios::sync_with_stdio(false);
   cin >> N >> K;
   for (int i = 1; i <= N; ++i) cin >> a[i] >> b[i], s1 += a[i], s2 += b[i];
   dp[0][0] = 1;
   for (int i = 0; i < N; ++i) {
     for (int j = 0; j < K; ++j) c[j] = 0, dp[i + 1][j] = dp[i][j];
     if (a[i + 1] + b[i + 1] >= K)
       for (int j = 0; j < K; ++j) {
         if (!dp[i][j]) continue;
         int l, r;
         l = max(1, K - b[i + 1]);
         r = min(K - 1, a[i + 1]);
         if (l <= r) {
           int St, Ed;
           St = j + l;
           Ed = j + r;
           St = K;
           Ed = K;
           c[St]++;
           if (Ed >= St) {
             c[Ed + 1]--;
           } else {
             c[0]++;
             c[Ed + 1]--;
           }
         }
       }
     for (int j = 0; j < K; ++j) {
       if (j) c[j] += c[j - 1];
       dp[i + 1][j] |= c[j];
     }
   }
   long long res = 0;
   for (int j = 0; j < K; ++j) {
     if (!dp[N][j]) continue;
     long long l1, l2;
     l1 = s1, l2 = s2;
     l1 -= j;
     l2 -= (K - j)  K;
     long long cur = bool(j) + (l1 / K) + (l2 / K);
     res = max(res, cur);
   }
   cout << res << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   char ch;
   int n, cnt = 0;
   long long x, a;
   scanf( dextra , &n, &x);
   for (int i = 0; i < n; i++) {
     while (isspace(ch = getchar()))
       ;
     scanf( extra , &a);
     if (ch == '+')
       x += a;
     else {
       if (x < a)
         cnt++;
       else
         x -= a;
     }
   }
   cout << x << ' ' << cnt << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 200005;
 int cnt[N];
 int n, k;
 int cut[N];
 vector<pair<int, int> > arr;
 struct Sub {
   bool operator()(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
     if (a.first != b.first)
       return a.first < b.first;
     else
       return (cnt[a.second.second] / (a.second.first + 1)) <
              (cnt[b.second.second] / (b.second.first + 1));
   }
 };
 bool ForSort(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }
 int main() {
   scanf( dd , &n, &k);
   int tx;
   for (int i = 1; i <= n; i++) scanf( d , &tx), cnt[tx]++;
   for (int i = 1; i <= 200000; i++)
     if (cnt[i] > 0) arr.push_back({cnt[i], i});
   sort(arr.begin(), arr.end(), ForSort);
   priority_queue<pair<int, pair<int, int> >,
                  vector<pair<int, pair<int, int> > >, Sub>
       pq;
   int len = 1, ex = arr[0].first;
   cut[arr[0].second] = 1;
   cout << arr[0].second <<    ;
   pq.push(pair<int, pair<int, int> >(arr[0].first,
                                      pair<int, int>(1, arr[0].second)));
   int i = 1;
   pair<int, pair<int, int> > u =
       pair<int, pair<int, int> >(2, pair<int, int>(10, 1));
   pair<int, pair<int, int> > v =
       pair<int, pair<int, int> >(2, pair<int, int>(4, 2));
   while (len < k) {
     pair<int, pair<int, int> > u = pq.top();
     if (i >= arr.size()) {
       if (cut[u.second.second] + 1 <= cnt[u.second.second]) {
         len++;
         cut[u.second.second] = u.second.first + 1;
         pq.pop();
         cout << u.second.second <<    ;
         pq.push(pair<int, pair<int, int> >(
             cnt[u.second.second] / (u.second.first + 1),
             pair<int, int>(u.second.first + 1, u.second.second)));
       } else
         pq.pop();
     } else {
       if (u.second.first + 1 <= cnt[u.second.second] &&
           cnt[u.second.second] / (u.second.first + 1) > arr[i].first) {
         cut[u.second.second] = u.second.first + 1;
         cout << u.second.second <<    ;
         len++;
         pq.pop();
         pq.push(pair<int, pair<int, int> >(
             cnt[u.second.second] / (u.second.first + 1),
             pair<int, int>(u.second.first + 1, u.second.second)));
       } else {
         ex = min(ex, arr[i].first);
         cut[arr[i].second] = 1;
         cout << arr[i].second <<    ;
         len++;
         pq.push(pair<int, pair<int, int> >(arr[i].first,
                                            pair<int, int>(1, arr[i].second)));
         i++;
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 300010;
 long long n, a[N], t;
 map<long long, bool> vis;
 int solve() {
   scanf( lld , &t);
   while (t--) {
     scanf( lld , &n);
     vis.clear();
     bool imp = 0;
     for (int i = 1; i <= n; i++) {
       scanf( lld , &a[i]);
       long long nw = (i + a[i])  n;
       if (nw < 0) nw += n;
       if (vis[nw]) {
         imp = 1;
       }
       vis[nw] = 1;
     }
     if (imp)
       printf( NO
 );
     else
       printf( YES
 );
   }
   return 0;
 }
 int main() { return solve(); }


#include <bits/stdc++.h>
 using namespace std;
 void file() {}
 void fast() {
   std::ios_base::sync_with_stdio(0);
   cin.tie(NULL);
 }
 const int N = 510 + 20;
 const double PI = acos(-1.0);
 bool cmp(complex<double> a, complex<double> b) {
   if (a.real() == b.real()) return a.imag() < b.imag();
   return a.real() < b.real();
 }
 bool cmp_doub(double a, double b) {
   if (fabs(a - b) <= 1e-9) {
     return 1;
   }
   return 0;
 }
 bool is_correct(complex<double> p1, complex<double> p2, complex<double> p3,
                 complex<double> p4) {
   vector<double> dists;
   double dist1 = (hypot((p1 - p2).imag(), (p1 - p2).real()));
   double dist2 = (hypot((p2 - p4).imag(), (p2 - p4).real()));
   double dist3 = (hypot((p3 - p4).imag(), (p3 - p4).real()));
   double dist4 = (hypot((p3 - p1).imag(), (p3 - p1).real()));
   double dist5 = (hypot((p2 - p3).imag(), (p2 - p3).real()));
   double dist6 = (hypot((p1 - p4).imag(), (p1 - p4).real()));
   dists.push_back(dist1);
   dists.push_back(dist2);
   dists.push_back(dist3);
   dists.push_back(dist4);
   dists.push_back(dist5);
   dists.push_back(dist6);
   sort(((dists).begin()), ((dists).end()));
   if (dists[0] > 0 && cmp_doub(dists[0], dists[1]) &&
       cmp_doub(dists[1], dists[2]) && cmp_doub(dists[2], dists[3]) &&
       cmp_doub(dists[3], dists[2])) {
     if (cmp_doub(dists[4], dists[5]) && !cmp_doub(dists[5], dists[0])) {
       return 1;
     }
   }
   return 0;
 }
 complex<double> rotate(complex<double> a, complex<double> b, int c) {
   for (int i = 0; i < c; i++) {
     a = (((((a) - (b))) * exp(complex<double>(0, PI / 2.0))) + b);
   }
   return a;
 }
 int main() {
   file();
   fast();
   int n;
   cin >> n;
   for (int i = 0; i < n; i++) {
     vector<pair<complex<double>, complex<double>>> points;
     for (int j = 0; j < 4; j++) {
       int x, y, z, m;
       cin >> x >> y >> z >> m;
       points.push_back({complex<double>(x, y), complex<double>(z, m)});
     }
     int ans = 1e9;
     for (int j1 = 0; j1 < 4; j1++) {
       for (int j2 = 0; j2 < 4; j2++) {
         for (int j3 = 0; j3 < 4; j3++) {
           for (int j4 = 0; j4 < 4; j4++) {
             vector<complex<double>> points1(4);
             points1[0] = rotate(points[0].first, points[0].second, j1);
             points1[1] = rotate(points[1].first, points[1].second, j2);
             points1[2] = rotate(points[2].first, points[2].second, j3);
             points1[3] = rotate(points[3].first, points[3].second, j4);
             if (is_correct(points1[0], points1[1], points1[2], points1[3])) {
               ans = min(ans, j1 + j2 + j3 + j4);
             }
           }
         }
       }
     }
     if (ans == 1e9) ans = -1;
     cout << ans << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[300001];
 const long long mod = 1000000007;
 int main(int argc, const char* argv[]) {
   string S;
   cin >> S;
   int n = (int)S.size();
   string A(n, '2');
   int scr = 0;
   for (int i = 0; i < n; ++i) {
     char a = S[(i + n - 1)  n];
     char b = S[i];
     char c = S[(i + 1)  n];
     if (a == b && b == c)
       A[i] = '0';
     else if (a == b && b != c) {
       ++scr;
       A[i] = '1';
       A[(i + 1)  n] = '0';
     } else if (a != b && b == c)
       A[i] = '0';
   }
   int fst = 0;
   while (fst < n && !(A[fst] != '2' && A[(fst + 1)  n] == '2')) ++fst;
   if (fst == n) {
     if (A[0] == '2')
       cout << n / 2 << endl;
     else
       cout << scr << endl;
     return 0;
   }
   int j = 0;
   for (int i = 0; i < n; ++i) {
     char a = A[(i + fst)  n];
     char b = A[(i + fst + 1)  n];
     if (a == '2' && b != '2') {
       scr += (i - j + 1) / 2;
     }
     if (a != '2' && b == '2') j = i;
   }
   cout << scr << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 string s;
 int main() {
   int n, a, b, k;
   scanf( dddd , &n, &a, &b, &k);
   int tot = 0;
   cin >> s;
   int prev = -1;
   for (int i = 0; i < n; i++)
     if (s[i] == '1') {
       tot += (i - prev - 1) / b;
       prev = i;
     }
   tot += (n - prev - 1) / b;
   int ans = tot - a + 1;
   printf( d
 , ans);
   int cnt = 0;
   for (int i = 0; i < n; i++) {
     if (s[i] == '1') {
       cnt = 0;
     } else {
       cnt++;
     }
     if (cnt == b && ans) {
       ans--;
       printf( d  , i + 1);
       cnt = 0;
     }
   }
   printf(
 );
   return 0;
 }


#include<bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 typedef unsigned long long ull;
 const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
 const int inf = 0x3f3f3f3f;
 const ll linf = 0x3f3f3f3f3f3f3f3f;
 const ll mod = 1e9 + 7;
 //const ll mod = 998244353;

 ll ksm(ll x,ll k) {
 	ll ret=1;
 	while(k) {
 		if(k&1)	ret=ret*xmod;
 		x=x*xmod,k>>=1;
 	}
 	return ret;
 }

 ll prime[10000005],pcnt,phi[10000005];
 bool mark[10000005];
 inline void pre(ll n) {
 	mark[1]=1;
 	for(ll i=2;i<=n;i++) {
 		if(!mark[i])	prime[++pcnt]=i/*,phi[i]=i-1*/;
 		for(ll j=1;j<=pcnt;j++) {
 			ll k=i*prime[j];
 			if(k>n)	break;
 			mark[k]=1;
 			if(iprime[j]==0) {
 //				phi[k]=phi[i]*prime[j];
 				break;
 			}
 //			else	phi[k]=phi[i]*(prime[j]-1);
 		}
 	}
 }

 struct data {
 	int u,v,val;
 	data(int _u=0,int _v=0,int _val=0):u(_u),v(_v),val(_val) {}
 	bool operator < (const data &x) const {
 		if(val==x.val)	return u<x.u;
 		return val<x.val;
 	}
 }a[505*505];
 int fa[505*505],c[505*505];
 vector <int> u,v;

 int getfa(int x) {
 	return x==fa[x] ? x:fa[x]=getfa(fa[x]);
 }

 int main() {
 	ios::sync_with_stdio(false);
 	cin.tie(nullptr);
 	int T=1;
 //	cin>>T;
 	while(T--) {
 		int n; cin>>n;
 		for(int i=1;i<=n*n;i++)	fa[i]=i;
 		int cnt=0;
 		for(int i=1;i<=n;i++) {
 			for(int j=1;j<=n;j++) {
 				int x; cin>>x;
 				if(i==j)	c[i]=x;
 				if(i>=j)	continue;
 				a[++cnt]=data(i,j,x);
 			}
 		}
 		sort(a+1,a+cnt+1);
 		int k=n;
 		for(int i=1;i<=cnt;i++) {
 			int fu=getfa(a[i].u),fv=getfa(a[i].v);
 			if(fu==fv)	continue;
 			if(fu>n && c[fu]==a[i].val) {
 				fa[fv]=fu,u.push_back(fv),v.push_back(fu);
 				continue;
 			}
 			if(fv>n && c[fv]==a[i].val) {
 				fa[fu]=fv,u.push_back(fu),v.push_back(fv);
 				continue;
 			}
 			k++;
 			fa[fu]=fa[fv]=k;
 			c[k]=a[i].val;
 			u.push_back(fu),v.push_back(k);
 			u.push_back(fv),v.push_back(k);
 		}
 		cout<<k<<
 ;
 		for(int i=1;i<=k;i++)	cout<<c[i]<<   ;
 		cout<<
 ;
 		cout<<k<<
 ;
 		for(int i=0;i<u.size();i++)	cout<<u[i]<<   <<v[i]<<
 ;
 	}
 }


#include <bits/stdc++.h>
 using namespace std;
 int gcd(int a, int b);
 bool prime(int n);
 long long sumdigit(long long n);
 bool ispowerof2(int n);
 long long onesinbinary(long long n);
 long long power(long long a, long long b);
 bool cmp(pair<int, int> x, pair<int, int> y) { return x.second < y.second; }
 bool cmp(int x, int y) { return x > y; }
 int main() {
   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   long long t;
   cin >> t;
   while (t--) {
     int n;
     cin >> n;
     char arr[2][n];
     for (int i = 0; i < 2; i++) {
       for (int j = 0; j < n; j++) {
         cin >> arr[i][j];
       }
     }
     int ans = 0;
     vector<int> v;
     for (int i = 0; i < n; i++) {
       if (arr[0][i] == '0' && arr[1][i] == '0')
         ans++;
       else if (arr[0][i] == '0' || arr[1][i] == '0')
         ans += 2;
       else {
         v.push_back(i);
       }
     }
     int x = v.size();
     for (int i = 0; i < x; i++) {
       if (v[i] < n - 1 && v[i] > 0) {
         if (arr[0][v[i] - 1] == '0' && arr[1][v[i] - 1] == '0') {
           ans++;
         } else if (arr[0][v[i] + 1] == '0' && arr[1][v[i] + 1] == '0') {
           ans++;
           arr[0][v[i] + 1] = '1', arr[1][v[i] + 1] = '1';
         }
       } else if (v[i] == n - 1) {
         if (arr[0][v[i] - 1] == '0' && arr[1][v[i] - 1] == '0') {
           ans++;
         }
       } else if (v[i] == 0) {
         if (arr[0][v[i] + 1] == '0' && arr[1][v[i] + 1] == '0') {
           ans++;
           arr[0][v[i] + 1] = '1', arr[1][v[i] + 1] = '1';
         }
       }
     }
     cout << ans << endl;
   }
   return 0;
 }
 long long onesinbinary(long long n) {
   long long cnt = 0;
   while (n) {
     n = n & (n - 1);
     cnt++;
   }
   return cnt;
 }
 int gcd(int a, int b) {
   if (b == 0) return a;
   return gcd(b, a  b);
 }
 bool prime(int n) {
   for (int i = 2; i * i <= n; i++)
     if (n  i == 0) return false;
   return true;
 }
 long long sumdigit(long long n) {
   int c = 0;
   while (n > 0) {
     c += n  10;
     n /= 10;
   }
   return c;
 }
 bool ispowerof2(int n) {
   if (n == 0) return false;
   return (!(n & ((n) & (n - 1))));
 }
 long long power(long long a, long long b) {
   if (b == 0) return 1;
   long long res = 1;
   while (b) {
     if (b  2 == 1) res = (res * a)  1000000007;
     a = (a * a)  1000000007;
     b /= 2;
   }
   return res;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int p, c = 0;
   cin >> p;
   long long int x = p;
   long long int n = std::numeric_limits<int>::digits - 1;
   std::string s;
   s.reserve(n + 1);
   do s.push_back(((x >> n) & 1) + '0');
   while (--n > -1);
   for (auto x : s)
     if (x == '1') c++;
   cout << c;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct Str {
   int l;
   char *s;
 } str[50010 << 2];
 int tot;
 char s[3100000];
 int k;
 int n, l[50010], r[50010];
 char ans[3100000];
 int cut(int pos) {
   for (int i = 0; i < tot; i++)
     if (pos == 0) {
       tot++;
       for (int k = tot - 1; k > i; k--) str[k] = str[k - 1];
       return i;
     } else if (str[i].l <= pos)
       pos -= str[i].l;
     else {
       tot += 2;
       for (int k = tot - 1; k > i + 1; k--) str[k] = str[k - 2];
       str[i + 2].l = str[i].l - pos;
       str[i + 2].s = str[i].s + pos;
       str[i].l = pos;
       return i + 1;
     }
   return tot++;
 }
 void getans(int h, int t) {
   int l = 0;
   for (int i = 0; t >= 0 && i < tot; i++)
     if (str[i].l <= h) {
       h -= str[i].l;
       t -= str[i].l;
     } else {
       for (int k = max(0, h); k < str[i].l && k <= t; k++)
         ans[l++] = str[i].s[k];
       int tmp = min(str[i].l, t);
       h -= tmp;
       t -= tmp;
     }
 }
 void deal(int d, int len) {
   if (d < 0) {
     Str tmp;
     tmp.l = len;
     tmp.s = s + 1;
     str[tot++] = tmp;
     return;
   }
   if (r[d] >= len) {
     deal(d - 1, len);
     return;
   }
   int c = r[d] - l[d] + 1;
   if (r[d] + c >= len) {
     deal(d - 1, r[d]);
     Str tmp;
     tmp.l = len - r[d];
     tmp.s = new char[len - r[d]];
     int c_2 = c / 2;
     int D = (tmp.l >= c_2) ? c : (tmp.l * 2);
     getans(l[d], l[d] + D - 1);
     for (int i = 0; i < tmp.l; i++)
       if (i < c_2)
         tmp.s[i] = ans[i * 2 + 1];
       else
         tmp.s[i] = ans[(i - c_2) << 1];
     str[tot++] = tmp;
   } else {
     deal(d - 1, len - c);
     int pos = cut(r[d] + 1);
     Str tmp;
     tmp.l = c;
     tmp.s = new char[c];
     int c_2 = c / 2;
     getans(l[d], r[d]);
     for (int i = 0; i < c; i++)
       if (i < c_2)
         tmp.s[i] = ans[i * 2 + 1];
       else
         tmp.s[i] = ans[(i - c_2) << 1];
     str[pos] = tmp;
   }
 }
 int main() {
   scanf( s , s + 1);
   scanf( d , &k);
   scanf( d , &n);
   for (int i = 0; i < n; i++) scanf( dd , &l[i], &r[i]);
   tot = 1;
   str[0].l = 1;
   str[0].s = new char[1];
   str[0].s[0] = ' ';
   deal(n - 1, k);
   getans(0, k);
   ans[k + 1] = 0;
   printf( s
 , ans + 1);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long n;
   while (cin >> n) {
     long long i = 5, cnt = 1, x, ans = 0, y, z = 5, m;
     if (n < 5 || n == 5) {
       if (n == 1)
         cout <<  Sheldon  << endl;
       else if (n == 2)
         cout <<  Leonard  << endl;
       else if (n == 3)
         cout <<  Penny  << endl;
       else if (n == 4)
         cout <<  Rajesh  << endl;
       else if (n == 5)
         cout <<  Howard  << endl;
       continue;
     }
     while (i < n || i == n) {
       x = i;
       if (i == n) {
         x = 0;
         break;
       } else {
         z += z;
         i += z;
       }
       cnt = cnt * 2;
     }
     if (x == 0)
       cout <<  Howard  << endl;
     else {
       y = n - x;
       if (y < 1) y *= -1;
       ans = y / cnt;
       ans++;
       if (y  cnt == 0) ans--;
       if (ans == 1)
         cout <<  Sheldon  << endl;
       else if (ans == 2)
         cout <<  Leonard  << endl;
       else if (ans == 3)
         cout <<  Penny  << endl;
       else if (ans == 4)
         cout <<  Rajesh  << endl;
       else if (ans == 5)
         cout <<  Howard  << endl;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 300010;
 int ans[N], vis[N];
 vector<int> G[N], s[N], tmp;
 void dfs(int u, int fa) {
   int sz = s[u].size();
   for (int i = 1; i <= sz; i++) vis[i] = 0;
   for (int j : s[u]) {
     if (ans[j] && ans[j] <= sz) vis[ans[j]] = 1;
   }
   for (int j = 1; j <= sz; j++) {
     if (!vis[j]) tmp.push_back(j);
   }
   int cur = 0;
   for (int j : s[u]) {
     if (!ans[j]) ans[j] = tmp[cur++];
   }
   tmp.clear();
   for (int v : G[u]) {
     if (v == fa) continue;
     dfs(v, u);
   }
 }
 int main() {
   int n, m;
   scanf( dd , &n, &m);
   for (int i = 1; i <= n; i++) {
     int cnt;
     scanf( d , &cnt);
     for (int j = 1; j <= cnt; j++) {
       int x;
       scanf( d , &x);
       s[i].push_back(x);
     }
   }
   for (int i = 1; i <= n - 1; i++) {
     int u, v;
     scanf( dd , &u, &v);
     G[u].push_back(v);
     G[v].push_back(u);
   }
   dfs(1, 0);
   int mx = 0;
   for (int i = 1; i <= m; i++) {
     if (!ans[i]) ans[i] = 1;
     mx = max(mx, ans[i]);
   }
   printf( d
 , mx);
   for (int i = 1; i <= m; i++) printf( d  , ans[i]);
   printf(
 );
   return 0;
 }


#include<bits/stdc++.h>
 using namespace std;
 bool ok[100005];
 typedef long long int ll;
 int gcd(int a ,int b)
 {
     if(b==0)
     return a;
     else if(a==0)
     return a;
     else

      return gcd(b,ab);
 }
 int main()
 {
     int n;
     cin>>n;
     ll prod=1;
     for(int i=1;i<n;i++)
     {
         if(gcd(n,i)==1)
         {
             ok[i]=1;
             prod=(prod*i)n;
         }
     }
     if(prod!=1)
     ok[prod]=0;

     cout<<count(ok+1,ok+n,1)<<endl;
     for(int i=1;i<n;i++)
     {
         if(ok[i])
         cout<<i<<   ;
     }
     return 0;

 }


#include <bits/stdc++.h>
 using namespace std;
 int inf = 1000000000, mxx, mxy, mnx = inf, mny = inf, n, m, i, j, r = 0,
     x[2000001], y[2000001];
 char a[3001][3001], c[3001][3001];
 bool ok(int mxx, int mxy, int mnx, int mny) {
   for (int i = 0; i < r; i++)
     if (x[i] < mnx || x[i] > mxx || y[i] < mny || y[i] > mxy ||
         (x[i] != mxx && x[i] != mnx && y[i] != mxy && y[i] != mny))
       return false;
   return (mxx - mnx == mxy - mny && mxx < n && mxy < m && mnx >= 0 && mny >= 0);
 }
 void go(int mxx, int mxy, int mnx, int mny) {
   int i, j;
   for (i = 0; i < n; i++)
     for (j = 0; j < m; j++) {
       if (i >= mnx && i <= mxx && j >= mny && j <= mxy &&
           ((i == mxx || i == mnx) || (j == mxy || j == mny)) && a[i][j] != 'w')
         c[i][j] = '+';
       else
         c[i][j] = a[i][j];
     }
 }
 int main() {
   cin >> n >> m;
   for (i = 0; i < n; i++)
     for (j = 0; j < m; j++) {
       cin >> a[i][j];
       if (a[i][j] == 'w') {
         x[r] = i;
         y[r] = j;
         r++;
       }
     }
   for (i = 0; i < r; i++) {
     if (x[i] > mxx) mxx = x[i];
     if (y[i] > mxy) mxy = y[i];
     if (x[i] < mnx) mnx = x[i];
     if (y[i] < mny) mny = y[i];
   }
   for (i = 0; i <= m; i++) {
     if (ok(mxx, i + (mxx - mnx), mnx, i)) {
       go(mxx, i + (mxx - mnx), mnx, i);
       for (i = 0; i < n; i++)
         for (j = 0; j < m; j++) {
           cout << c[i][j];
           if (j == m - 1) cout << endl;
         }
       return 0;
     }
   }
   for (i = 0; i <= n; i++) {
     if (ok(i + (mxy - mny), mxy, i, mny)) {
       go(i + (mxy - mny), mxy, i, mny);
       for (i = 0; i < n; i++)
         for (j = 0; j < m; j++) {
           cout << c[i][j];
           if (j == m - 1) cout << endl;
         }
       return 0;
     }
   }
   cout <<  -1 ;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 11, MAXL = 100000 + 10;
 struct State {
   int len, fa, num[MAXN], tr[26];
   State() : len(0), fa(0) {
     memset(num, 0, sizeof(num));
     memset(tr, 0, sizeof(tr));
   }
   State(int len, int fa, int numr, int ref) : len(len), fa(fa) {
     memset(num, 0, sizeof(num));
     memset(tr, 0, sizeof(tr));
     num[ref] = numr;
   }
 } SAM[MAXL * 2];
 int n, tot = 1, c[MAXN][2];
 string str[MAXN];
 void Construct_SAM(const string &str, int ref) {
   int ns = str.size();
   for (int cp = 1, pre = 1, i = 0, id = str[i] - 'a'; i < ns;
        id = str[++i] - 'a', pre = cp) {
     if (SAM[cp].tr[id] && SAM[SAM[cp].tr[id]].len == SAM[cp].len + 1) {
       cp = SAM[cp].tr[id];
       ++SAM[cp].num[ref];
       continue;
     }
     cp = ++tot;
     SAM[cp] = State(SAM[pre].len + 1, 0, 1, ref);
     for (; pre && !SAM[pre].tr[id]; SAM[pre].tr[id] = cp, pre = SAM[pre].fa)
       ;
     if (pre != 0)
       if (SAM[pre].len + 1 == SAM[SAM[pre].tr[id]].len)
         SAM[cp].fa = SAM[pre].tr[id];
       else {
         int tp = SAM[pre].tr[id];
         SAM[++tot] = State(SAM[pre].len + 1, SAM[tp].fa, 0, 0);
         memcpy(SAM[tot].tr, SAM[tp].tr, sizeof(SAM[tp].tr));
         SAM[cp].fa = SAM[tp].fa = tot;
         for (; pre && SAM[pre].tr[id] == tp;
              SAM[pre].tr[id] = tot, pre = SAM[pre].fa)
           ;
       }
     else
       SAM[cp].fa = 1;
   }
 }
 void init() {
   cin >> str[0];
   c[0][0] = 1, c[0][1] = MAXL;
   Construct_SAM(str[0], 0);
   cin >> n;
   for (int i = 1; i <= n; ++i) {
     cin >> str[i] >> c[i][0] >> c[i][1];
     Construct_SAM(str[i], i);
   }
 }
 vector<int> l[MAXL];
 void Calc(int id) {
   for (int i = MAXL - 1; i >= 0; --i)
     for (int j = 0; j < (int)l[i].size(); ++j)
       SAM[SAM[l[i][j]].fa].num[id] += SAM[l[i][j]].num[id];
 }
 bool Check(int x) {
   for (int i = 0; i <= n; ++i)
     if (!(SAM[x].num[i] >= c[i][0] && SAM[x].num[i] <= c[i][1])) return false;
   return true;
 }
 void solve() {
   for (int i = 1; i <= tot; ++i) l[SAM[i].len].push_back(i);
   for (int i = 0; i <= n; ++i) Calc(i);
   long long CC = 0;
   for (int i = 2; i <= tot; ++i)
     if (Check(i)) CC += SAM[i].len - SAM[SAM[i].fa].len;
   cout << CC << endl;
 }
 int main() {
   init();
   solve();
   fclose(stdin);
   fclose(stdout);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 set<long long int> st;
 set<long long int>::iterator it;
 long long int cnt[200010];
 int main() {
   long long int n, a, b, x, y, z, p, m, d, mn, mx, t, i;
   scanf( lld , &t);
   while (t--) {
     scanf( lld , &n);
     p = 0;
     for (i = 1; i <= n; i++) {
       scanf( lld , &a);
       st.insert(a);
       cnt[a]++;
       p = max(p, cnt[a]);
     }
     x = st.size();
     if (x == 1) {
       if (p >= 2) {
         cout << 1 << endl;
       } else
         cout << 0 << endl;
     } else {
       x = x - 1;
       if (p <= x)
         cout << p << endl;
       else {
         d = p - x;
         if (d > 1)
           cout << x + 1 << endl;
         else
           cout << x << endl;
       }
     }
     for (i = 1; i <= n; i++) cnt[i] = 0;
     st.clear();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool prime[1500000 + 10];
 bool a[1500000 + 10];
 int func(int N, int x) {
   int i, ans = 0;
   if (x == 2) return 0;
   if (a[1]) return 1;
   if (x >= 1500000) return -1;
   for (i = 2; i <= x - 1; i++)
     if (prime[i])
       if (a[i])
         ans++;
       else
         return -1;
   return ans;
 }
 int main(void) {
   int i, j, N, x, tmp;
   for (i = 2; i < 1500000; i++) prime[i] = true;
   for (i = 2; i * i < 1500000; i++)
     if (prime[i])
       for (j = i * i; j < 1500000; j += i) prime[j] = false;
   scanf( dd , &N, &x);
   for ((i) = 0; (i) < (int)(N); (i)++) {
     scanf( d , &tmp);
     if (tmp < 1500000) a[tmp] = true;
   }
   int ans = func(N, x);
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void task();
 int main() {
   srand(time(0));
   ios_base::sync_with_stdio(0);
   task();
   return 0;
 }
 vector<int> prefix_function(string s) {
   int n = s.length();
   vector<int> p(n, 0);
   for (int i = 1; i < n; ++i) {
     int j = p[i - 1];
     while (j > 0 && s[i] != s[j]) j = p[j - 1];
     if (s[i] == s[j]) p[i] = j + 1;
   }
   return p;
 }
 string s[3];
 void task() {
   cin >> s[0] >> s[1] >> s[2];
   sort(s, s + 3);
   int ans = 1e9 + 10;
   do {
     string ss = s[0];
     {
       vector<int> p = prefix_function(s[1] +  !  + s[0]);
       int mx = 0;
       for (int i = s[1].length(); i < ((int)((p).size())); ++i)
         mx = max(mx, p[i]);
       if (p.back() != ((int)((s[1]).size())) && mx != ((int)((s[1]).size())))
         ss += s[1].substr(p.back(), ((int)((s[1]).size())) - p.back());
     }
     {
       vector<int> p = prefix_function(s[2] +  !  + ss);
       int mx = 0;
       for (int i = s[2].length(); i < ((int)((p).size())); ++i)
         mx = max(mx, p[i]);
       if (p.back() != ((int)((s[2]).size())) && mx != ((int)((s[2]).size())))
         ss += s[2].substr(p.back(), ((int)((s[2]).size())) - p.back());
       ans = min(ans, ((int)((ss).size())));
     }
   } while (next_permutation(s, s + 3));
   cout << ans;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 0x3f3f3f3f;
 const int MOD = 1e9 + 7;
 const int maxn = 3e5 + 10;
 const int maxv = 1e3 + 10;
 const double eps = 1e-9;
 std::vector<int> G[maxn];
 int ans[maxn];
 void inv(int i) { ans[i] ^= 1; }
 bool bad(int u) {
   int cnt = 0;
   for (int i = 0; i < G[u].size(); i++) {
     cnt += ans[u] == ans[G[u][i]];
   }
   return cnt >= 2;
 }
 int main() {
   int n, m;
   scanf( dd , &n, &m);
   for (int i = 1; i <= m; i++) {
     int u, v;
     scanf( dd , &u, &v);
     if (u > v) swap(u, v);
     G[v].push_back(u);
     G[u].push_back(v);
   }
   stack<int> s;
   for (int i = 1; i <= n; i++) {
     if (bad(i)) s.push(i);
   }
   while (s.size()) {
     int u = s.top();
     s.pop();
     if (bad(u)) inv(u);
     for (int i = 0; i < G[u].size(); i++) {
       int v = G[u][i];
       if (bad(G[u][i])) s.push(v);
     }
   }
   for (int i = 1; i <= n; i++) {
     printf( d , ans[i]);
   }
   puts(  );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 char s[105];
 string S;
 multiset<string> st;
 vector<string> v;
 inline bool cmp(string a, string b) { return a.length() < b.length(); }
 int cnt[26];
 char ans[105];
 int f[105][26];
 int main() {
   scanf( d , &n);
   if (n <= 3) {
     if (n == 1) {
       printf( ? 1 1
 ), fflush(stdout);
       scanf( s , s);
       printf( ! s
 , s);
       return 0;
     }
     printf( ? 2 d
 , n), fflush(stdout);
     for (int i = 1; i <= n * (n - 1) / 2; i++) {
       scanf( s , s);
       S = s;
       sort(S.begin(), S.end());
       st.insert(S);
     }
     printf( ? 1 d
 , n), fflush(stdout);
     for (int i = 1; i <= n * (n + 1) / 2; i++) {
       scanf( s , s);
       S = s;
       sort(S.begin(), S.end());
       if (st.find(S) == st.end())
         v.push_back(S);
       else
         st.erase(st.find(S));
     }
     sort(v.begin(), v.end(), cmp);
     printf( !  );
     for (int i = 0; i < n; i++) {
       if (i == 0) {
         printf( c , v[i][0]);
         continue;
       }
       for (int j = 0; j < i + 1; j++) cnt[v[i][j] - 'a']++;
       for (int j = 0; j < i; j++) cnt[v[i - 1][j] - 'a']--;
       for (int j = 0; j < 26; j++) {
         if (cnt[j]) {
           cnt[j] = 0, printf( c , j + 'a');
           break;
         }
       }
     }
     puts(  );
     return 0;
   }
   int m = (n + 1) / 2;
   printf( ? 2 d
 , m), fflush(stdout);
   for (int i = 1; i <= m * (m - 1) / 2; i++) {
     scanf( s , s);
     S = s;
     sort(S.begin(), S.end());
     st.insert(S);
   }
   printf( ? 1 d
 , m), fflush(stdout);
   for (int i = 1; i <= m * (m + 1) / 2; i++) {
     scanf( s , s);
     S = s;
     sort(S.begin(), S.end());
     if (st.find(S) == st.end())
       v.push_back(S);
     else
       st.erase(st.find(S));
   }
   sort(v.begin(), v.end(), cmp);
   for (int i = 0; i < m; i++) {
     if (i == 0) {
       ans[i + 1] = v[i][0];
       continue;
     }
     for (int j = 0; j < i + 1; j++) cnt[v[i][j] - 'a']++;
     for (int j = 0; j < i; j++) cnt[v[i - 1][j] - 'a']--;
     for (int j = 0; j < 26; j++) {
       if (cnt[j]) {
         cnt[j] = 0, ans[i + 1] = j + 'a';
         break;
       }
     }
   }
   printf( ? 1 d
 , n), fflush(stdout);
   for (int i = 1; i <= n * (n + 1) / 2; i++) {
     scanf( s , s);
     int len = strlen(s);
     for (int j = 0; j < len; j++) {
       f[len][s[j] - 'a']++;
     }
   }
   for (int i = m; i; i--) {
     for (int j = 0; j < 26; j++) {
       int x = f[i][j] - f[i - 1][j];
       for (int k = i; k < n + 1 - i; k++) x -= ans[k] == j + 'a';
       if (x) {
         ans[n + 1 - i] = j + 'a';
         break;
       }
     }
   }
   printf( !  );
   for (int i = 1; i <= n; i++) printf( c , ans[i]);
   puts(  );
 }


#include <bits/stdc++.h>
 using namespace std;
 long long a, b;
 vector<long long> A, B, C;
 int main() {
   scanf( lld lld , &a, &b);
   for (long long i = 1; i <= sqrt(a); i++)
     if (a  i == 0) A.push_back(i);
   for (long long i = 1; i <= sqrt(b); i++)
     if (b  i == 0) B.push_back(i);
   for (long long i = 1; i <= sqrt(a + b); i++)
     if ((a + b)  i == 0) C.push_back(i);
   long long ans;
   for (long long i : C) {
     for (long long j : A) {
       if (j <= i && a / j <= (a + b) / i) ans = 2 * i + (2 * (a + b) / i);
     }
     for (long long j : B) {
       if (j <= i && b / j <= (a + b) / i) ans = 2 * i + (2 * (a + b) / i);
     }
   }
   printf( lld
 , ans);
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> a, b, e;
 char s[5];
 long long ans;
 int c;
 int main() {
   int n, f;
   scanf( d , &n);
   while (n--) {
     scanf( s d , &s, &f);
     if (s[0] == '0' && s[1] == '1')
       a.push_back(f);
     else if (s[0] == '1' && s[1] == '0')
       b.push_back(f);
     else if (s[0] == '0' && s[1] == '0')
       e.push_back(f);
     else {
       c++;
       ans += f;
     }
   }
   int temp = c + 2 * min((int)a.size(), (int)b.size());
   c += min((int)a.size(), (int)b.size());
   if (!a.empty()) sort(a.rbegin(), a.rend());
   if (!b.empty()) sort(b.rbegin(), b.rend());
   for (int i = 0; i < min((int)a.size(), (int)b.size()); ++i) {
     ans += a[i];
     ans += b[i];
   }
   if (a.size() > b.size()) {
     for (int i = min(a.size(), b.size()); i < a.size(); ++i) e.push_back(a[i]);
   } else if (b.size() > a.size()) {
     for (int i = min(a.size(), b.size()); i < b.size(); ++i) e.push_back(b[i]);
   }
   if (!e.empty()) sort(e.rbegin(), e.rend());
   for (int i = 0; i < e.size(); ++i) {
     if (((temp + 2) / 2) <= c) {
       ans += e[i];
       temp++;
     }
   }
   printf( lld , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 ifstream fin( Sisend.txt );
 int n, c;
 bool b[100005];
 vector<int> v, v1;
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   cerr.tie(0);
   cin >> n;
   for (int(i) = (0); ((i)) < ((n)); ((i))++) {
     cin >> c;
     v.emplace_back(c);
   }
   sort(v.rbegin(), v.rend());
   int l = 1, r = v.size() / 2 + 1;
   int vas = 0;
   v1.emplace_back(v[0]);
   while (r < v.size()) {
     while (r < v.size() and v[r] == v[l]) r++;
     v1.emplace_back(v[r]), v1.emplace_back(v[l]);
     b[r] = 1;
     vas++;
     l++;
     r++;
   }
   while (l < v.size()) {
     if (!b[l]) {
       v1.emplace_back(v[l]);
     }
     l++;
   }
   cout << vas << endl;
   for (int i : v1) cout << i <<    ;
 }


///****In the name of ALLAH, most Gracious, most Compassionate****//
 #include<bits/stdc++.h>

 #define Input                   freopen( in.txt , r ,stdin)
 #define Output                  freopen( out.txt , w ,stdout)
 #define ll                      long long int
 #define ull                     unsigned long long int
 #define pii                     pair<int,int>
 #define pll                     pair<ll,ll>
 #define sc                      scanf
 #define scin(x)                 sc( d ,&(x))
 #define scin2(x,y)              sc( d d ,&(x),&(y))
 #define scln(x)                 sc( lld ,&(x))
 #define scln2(x,y)              sc( lld lld ,&(x),&(y))
 #define pf                      printf
 #define all(a)                  (a.begin()),(a.end())
 #define UNIQUE(X)               (X).erase(unique(all(X)),(X).end())
 #define SORT_UNIQUE(c)          (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
 #define ms(a,b)                 memset(a,b,sizeof(a))
 #define pb(a)                   push_back(a)
 #define mp                      make_pair
 #define db                      double
 #define EPS                     10E-10
 #define ff                      first
 #define ss                      second
 #define sqr(x)                  (x)*(x)
 #define vi                      vector<int>
 #define vl                      vector<ll>
 #define vii                     vector<vector<int> >
 #define vll                     vector<vector<ll> >
 #define DBG                     pf( HI
 )
 #define MOD                     1000000007
 #define CIN                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define RUN_CASE(t,T)           for(__typeof(t) t=1;t<=T;t++)
 #define CASE(t)                 printf( Case d:  ,t)
 #define CASEl(t)                printf( Case d:
 ,t)
 #define intlimit                2147483690
 #define longlimit               9223372036854775800
 #define infinity                (1<<28)
 #define gcd(a,b)                __gcd(a,b)
 #define lcm(a,b)                (a)*(b)/gcd(a,b)
 #define mxx                     123456789
 #define PI                      2*acos(0.0)
 #define rep(i,a,b)              for(__typeof(i) i=a;i<=b;i++)
 #define rev(i,a,b)              for(__typeof(i) i=a;i>=b;i--)
 #define coutv(v)                for(auto it:v)cout<<it<<' ';cout<<'
';
 #define cinv(v)                 for(auto &it:v)cin>>it;
 #define srt(v)                  sort(v.begin(),v.end());
 #define rsrt(v)                 sort(v.rbegin(),v.rend());
 #define rvs(v)                  reverse(v.begin(),v.end());

 using namespace std;
 /**     toint, tostring, BigMod, Power , sieve, Primefactorize ,frequency in n!     **/
 //ll toint(string s){ll n=0,k=1;for(int i=s.size()-1; i>=0; i--){n += ((s[i]-'0')*k);k*=10;}return n;}
 //string tostring(ll x){string s=  ;while(x){s += (x10)+'0';x/=10;}reverse(s.begin(),s.end());return s;}
 //ll BigMod(ll a,ll b){if(b == 0)return 1MOD;else if(b2 == 0){ll temp=BigMod(a,b/2);return ((tempMOD)*(tempMOD))MOD;}else{return ((aMOD)*BigMod(a,b-1)MOD)MOD;}}
 //ll Power(ll a,ll n){ll ret=1;for(ll i=1 ; i<=n ; i++)ret = ((retMOD)*(aMOD))MOD;return ret;}
 //bool isPrime(ll n){for(ll i=2 ; i*i<=n ; i++){if(ni == 0)return 0;}return 1;}
 //vector<ll>Prime;
 //bool mark[10000003];
 //void sieve(ll n){ll i,j;mark[1]=1;for(i=4; i<=n; i+=2)mark[i]=1;Prime.push_back(2);for(i=3; i<=n; i+=2){if(!mark[i]){Prime.push_back(i);if(i*i<=n){for(j=i*i; j<=n; j+=(i*2))mark[j]=1;}}}}
 //map<ll,ll>Factor;
 //void Primefactorize(ll n){for(ll i=0; i<Prime.size() && Prime[i]*Prime[i]<=n; i++){if(nPrime[i] == 0){while(nPrime[i] == 0){Factor[Prime[i]]++;n/=Prime[i];}}}if(n>1){Factor[n]++;}}
 //ll frequency(ll n,ll factor)/** Frequency of a factor in n! **/{ll cnt=0;while(n){cnt += (n/factor);n /= factor;}return cnt;}
 /**     Order Set       **/
 //#include <ext/pb_ds/assoc_container.hpp>
 //using namespace __gnu_pbds;
 //template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
 //orderset<int> s ; //orderset<int>::iterator it ;
 //orderset<int> X; //X.insert(1); //X.insert(2); //X.insert(4); //X.insert(8); //X.insert(16);
 //cout<<*X.find_by_order(0)<<endl; // 2 //cout<<*X.find_by_order(2)<<endl; // 4 //cout<<*X.find_by_order(4)<<endl; // 16 //cout<<(end(X)==X.find_by_order(6))<<endl; // true
 //cout<<X.order_of_key(-5)<<endl;  // 0 //cout<<X.order_of_key(1)<<endl;   // 0 //cout<<X.order_of_key(3)<<endl;   // 2 //cout<<X.order_of_key(4)<<endl;   // 2 //cout<<X.order_of_key(400)<<endl; // 5

 struct custom_hash {    ///For unordered map or set
     static uint64_t splitmix64(uint64_t x) {
         x += 0x9e3779b97f4a7c15;
         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
         return x ^ (x >> 31);
     }

     size_t operator()(uint64_t x) const {
         static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
         return splitmix64(x + FIXED_RANDOM);
     }
 };

 /** Debugging Tool **/
 #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 void err(istream_iterator<string> it) {}
 template<typename T, typename... Args>
 void err(istream_iterator<string> it, T a, Args... args)
 {
     cerr << *it <<   =   << a << endl;
     err(++it, args...);
 }
 ///

 inline int add(int a, int b) {a += b; return a >= MOD ? a - MOD : a;}
 inline int sub(int a, int b) {a -= b; return a < 0 ? a + MOD : a;}
 inline int mul(int a, int b) {return (ll) a * b  MOD;}
 int Set(int N, int pos) {return  N = N | (1<<pos);}
 int Reset(int N, int pos) {return  N = N & ~(1<<pos);}
 bool Cheek(int N, int pos) {return  (bool)(N & (1<<pos));}

 //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 //int my_rand(int l,int r)
 //{
 //    return uniform_int_distribution<int>(l , r) (rng);
 //}

 //string small =  abcdefghijklmnopqrstuvwxyz ;
 //string capital =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ;

 ///------------------Graph Moves-------------------
 ///const int fx[] = {+1,-1,+0,+0};
 ///const int fy[] = {+0,+0,+1,-1};
 ///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
 ///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///King's move
 ///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///Knight's move
 ///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///Knight's move

 ll s[5009],added[5009];

 void Solve(int t)
 {
     ll i,j,k,n,ans=0;
     scln(n);
     for(i=1 ; i<=n ; i++)
         scln(s[i]);

     for(i=1 ; i<=n ; i++){
         if(s[i] - added[i] <= 1){
             for(j=i+2 ; j<=min(n , i+s[i]) ; j++)
                 added[j]++;
             if(added[i] >= s[i]){
                 ll xtra = added[i] - (s[i] - 1);
                 added[i+1] += xtra;
             }
             continue;
         }

         ll temp = (s[i] - 1) - added[i];
         added[i] += temp;
         ans += temp;

 //        error(i , temp);
         for(j=i+2 ; j<=min(n , i+s[i]) ; j++){
             added[j]++;
         }

         if(added[i] >= s[i]){
             ll xtra = added[i] - (s[i] - 1);
             added[i+1] += xtra;
         }
     }
     pf( lld
 ,ans);

     for(i=1 ; i<=n+2 ; i++)
         s[i] = added[i] = 0;
 }

 int main()
 {
     int t,T;
     T = 1;
     cin>>T;
     RUN_CASE(t,T)
     {
         Solve(t);
     }
     return 0;
 }

 /** Stuff u should look for
     * Avoid overflow
     * Corner(Small) case
     * Don't get stuck on one approach
     * Don't forget to clean used memory in each case
 **/


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 2e9;
 const long long BIG_INF = 1e18;
 const long long MOD = 1e9 + 7;
 const int maxn = 1e5 + 5;
 vector<int> g[maxn];
 int p[maxn], max_height, deep_v;
 void dfs(int v, int height) {
   if (height > max_height) {
     max_height = height;
     deep_v = v;
   }
   for (int j = 0; j < (int)g[v].size(); j++) {
     int to = g[v][j];
     dfs(to, height + 1);
   }
 }
 void out(int v) {
   if (v) out(p[v]);
   ;
   cout << v <<    ;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int n;
   cin >> n;
   for (int i = 1; i < n; i++) {
     int u;
     cin >> u;
     p[i] = u;
     g[u].push_back(i);
   }
   dfs(0, 0);
   vector<int> ans;
   int v = deep_v;
   while (1) {
     while (v && (int)g[p[v]].size() == 1) v = p[v];
     if (!v) break;
     int par = p[v];
     g[par].erase(find(g[par].begin(), g[par].end(), v));
     int to = g[par][0];
     ans.push_back(v);
     g[to].push_back(v);
     p[v] = to;
   }
   out(deep_v);
   cout <<
 ;
   reverse(ans.begin(), ans.end());
   cout << (int)ans.size() <<
 ;
   for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] <<    ;
   cout <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n;
 long long a[1006];
 long long fac[1000006];
 long long power(long long a, long long i) {
   if (i == 0) return 1  1000000007;
   long long t = power(a, i / 2);
   long long ans = t * t  1000000007;
   if (i  2 == 1) ans = ans * a  1000000007;
   return ans;
 }
 long long work(long long m, long long i) {
   return ((fac[m]  1000000007) *
           (power(fac[i] * fac[m - i]  1000000007, 1000000007 - 2)
            1000000007))
          1000000007;
 }
 int main() {
   fac[0] = 1;
   for (int i = 1; i < 1000006; i++) fac[i] = (fac[i - 1] * i)  1000000007;
   long long ans = 1;
   long long sum = 0;
   cin >> n;
   for (int i = 1; i <= n; i++) {
     cin >> a[i];
     sum += a[i];
   }
   for (int i = n; i >= 1; i--) {
     ans = ans * work(sum - 1, a[i] - 1)  1000000007;
     sum -= a[i];
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void solve() {
   long long int n, k;
   cin >> n >> k;
   long long int a[n], s = 0;
   vector<pair<long long int, long long int> > v;
   for (int i = 0; i < n; i++) {
     cin >> a[i];
     if (a[i] <= k) {
       v.push_back({a[i], i + 1});
       s += a[i];
     }
   }
   if (s < (k + 1) / 2) {
     cout << -1 << endl;
     return;
   }
   s = 0;
   sort(v.begin(), v.end());
   vector<long long int> ans;
   for (int i = v.size() - 1; i >= 0; i--) {
     if (s + v[i].first >= (k + 1) / 2 and s + v[i].first <= k) {
       s += v[i].first;
       ans.push_back(v[i].second);
       break;
     } else if (s + v[i].first < (k + 1) / 2) {
       ans.push_back(v[i].second);
       s += v[i].first;
     }
   }
   if (ans.size() == 0) {
     cout << -1 << endl;
   }
   sort(ans.begin(), ans.end());
   cout << ans.size() << endl;
   for (int i = 0; i < ans.size(); i++) {
     cout << ans[i] <<    ;
   }
   cout << endl;
 }
 int main() {
   int t;
   cin >> t;
   while (t--) {
     solve();
   }
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( O3 )
 using namespace std;
 const long long INF = 1e12;
 const int MOD = 1e9 + 7;
 const unsigned long long BIT_FLAG_0 = (1 << 0);
 const unsigned long long BIT_FLAG_1 = (1 << 1);
 const unsigned long long BIT_FLAG_2 = (1 << 2);
 const unsigned long long BIT_FLAG_3 = (1 << 3);
 const unsigned long long BIT_FLAG_4 = (1 << 4);
 const unsigned long long BIT_FLAG_5 = (1 << 5);
 const unsigned long long BIT_FLAG_6 = (1 << 6);
 const unsigned long long BIT_FLAG_7 = (1 << 7);
 const long long dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
 const long long Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
                 Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
 void print() { cout <<
 ; }
 template <class Head, class... Tail>
 void print(Head &&head, Tail &&...tail) {
   cout << head;
   if (sizeof...(tail) != 0) cout <<    ;
   print(forward<Tail>(tail)...);
 }
 template <class T>
 void print(vector<T> &vec) {
   for (auto &a : vec) {
     cout << a;
     if (&a != &vec.back()) cout <<    ;
   }
   cout <<
 ;
 }
 template <class T>
 void print(set<T> &set) {
   for (auto &a : set) {
     cout << a <<    ;
   }
   cout <<
 ;
 }
 template <class T>
 void print(vector<vector<T>> &df) {
   for (auto &vec : df) {
     print(vec);
   }
 }
 long long power(long long a, long long n) {
   long long res = 1;
   while (n > 0) {
     if (n & 1) res = res * a;
     a *= a;
     n >>= 1;
   }
   return res;
 }
 long long comb(long long n, long long k) {
   vector<vector<long long>> v(n + 1, vector<long long>(n + 1, 0));
   for (long long i = 0; i < (long long)((v).size()); i++) {
     v[i][0] = 1;
     v[i][i] = 1;
   }
   for (long long k = 1; k < (long long)((v).size()); k++) {
     for (long long j = 1; j < k; j++) {
       v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
     }
   }
   return v[n][k];
 }
 void add(long long &a, long long b) {
   a += b;
   if (a >= MOD) a -= MOD;
 }
 template <class T>
 inline bool chmin(T &a, T b) {
   if (a > b) {
     a = b;
     return true;
   }
   return false;
 }
 template <class T>
 inline bool chmax(T &a, T b) {
   if (a < b) {
     a = b;
     return true;
   }
   return false;
 }
 __attribute__((constructor)) void faster_io() {
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
 }
 long long n, k;
 map<long long, long long> got;
 pair<bool, multiset<long long>> isOK(long long idx) {
   multiset<long long> ans;
   multiset<long long> trueans;
   long long cnt = 0;
   for (const auto &[key, value] : got) {
     long long types = value / idx;
     cnt += types;
     for (long long ti = 0; ti < (long long)(types); ti++) {
       ans.insert(key);
     }
   }
   if (cnt >= k) {
     long long now = 0;
     for (auto i : ans) {
       trueans.insert(i);
       now++;
       if (now == k) {
         break;
       }
     }
     return make_pair(true, trueans);
   } else {
     return make_pair(false, trueans);
   }
 }
 multiset<long long> bin_search() {
   multiset<long long> finalans;
   long long ng = n + 1;
   long long ok = 0;
   while (abs(ok - ng) > 1) {
     long long mid = (ok + ng) / 2;
     long long bl = isOK(mid).first;
     auto nums = isOK(mid).second;
     if (bl) {
       ok = mid;
       finalans = nums;
     } else
       ng = mid;
   }
   return finalans;
 }
 signed main() {
   cin >> n >> k;
   vector<long long> A(n);
   for (long long ni = 0; ni < (long long)(n); ni++) {
     long long v;
     cin >> v;
     A[ni] = v;
     got[v]++;
   }
   auto ret = bin_search();
   for (auto i : ret) {
     cout << i <<    ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX = 1e6 + 5;
 int main() {
   ios_base::sync_with_stdio(0);
   long long q;
   cin >> q;
   while (q--) {
     long long n;
     cin >> n;
     long long cnt = 0;
     long long flag = 1;
     while (n != 1) {
       if (n  2 == 0) {
         n = n / 2;
         cnt++;
       } else if (n  3 == 0) {
         n = (2 * n) / 3;
         cnt++;
       } else if (n  5 == 0) {
         n = (4 * n) / 5;
         cnt++;
       } else {
         cout <<  -1  << endl;
         flag = 0;
         break;
       }
     }
     if (flag) cout << cnt << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int x;
   while (cin >> x) {
     map<char, int> p1;
     string str, strr;
     ;
     bool l = 0;
     int sum;
     cin >> str;
     for (int i = 0; i < str.size(); i++) {
       p1[str[i]]++;
     }
     for (int i = 0; i < str.size(); i++) {
       if (p1[str[i]]  x != 0) {
         l = 1;
         break;
       }
     }
     if (l == 0) {
       for (char i = 'a'; i <= 'z'; i++) {
         sum = 0;
         if (p1[i] > 0) {
           sum = p1[i] / x;
         }
         while (sum--) {
           strr += i;
         }
       }
       while (x--) {
         cout << strr;
       }
     } else
       cout << -1;
     cout << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 200200;
 const int mod = 1e9 + 7;
 int n, a, b;
 vector<int> q;
 int main() {
   cin >> n >> a >> b;
   q.push_back(a);
   q.push_back(a);
   q.push_back(a);
   q.push_back(a);
   q.push_back(b);
   q.push_back(b);
   sort(q.begin(), q.end());
   int res = 1e9;
   do {
     int ans = 1, cur = n;
     for (int i = 0; i < q.size(); ++i)
       if (cur - q[i] >= 0)
         cur -= q[i];
       else
         ans++, cur = n - q[i];
     res = min(res, ans);
   } while (next_permutation(q.begin(), q.end()));
   cout << res;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using lli = long long int;
 lli mod = 1000000007.0;
 int main(void) {
   long long t;
   cin >> t;
   lli x;
   lli n;
   while (t--) {
     cin >> n;
     x = 1;
     for (lli i = 2 * n; i >= 3; i--) {
       x *= i;
       x = x  mod;
     }
     cout << x << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, x[210], y[210], ans, dp[210][210];
 long long S[210][210];
 bool in[210][210][210];
 int gogo(int x) {
   if (x  n == 0) return n;
   return x  n;
 }
 long long cp(int a, int b, int c) {
   return 1LL * (x[a] - x[c]) * (y[b] - y[c]) -
          1LL * (y[a] - y[c]) * (x[b] - x[c]);
 }
 int main() {
   scanf( d , &n);
   for (int i = 1; i <= n; i++) scanf( dd , &x[i], &y[i]);
   for (int i = 1; i <= n; i++)
     for (int j = i; j <= n; j++) {
       for (int p = i + 1; p < j; p++) S[i][j] += cp(p, p + 1, i);
     }
   for (int i = 1; i <= n; i++)
     for (int j = 1; j < i; j++) {
       for (int p = gogo(i + 1); p != j; p = gogo(p + 1))
         S[i][j] += cp(gogo(p), gogo(p + 1), i);
     }
   for (int i = 1; i <= n; i++)
     for (int j = i + 1; j <= n; j++)
       for (int p = j + 1; p <= n; p++)
         if (abs(cp(j, p, i)) + abs(S[i][j]) + abs(S[j][p]) + abs(S[p][i]) ==
                 abs(S[1][n]) &&
             cp(j, p, i)) {
           in[i][j][p] = true;
         }
   for (int i = 1; i <= n; i++) dp[i][i + 1] = 1;
   for (int i = n; i; i--)
     for (int j = i + 1; j <= n; j++)
       for (int p = i + 1; p < j; p++)
         if (in[i][p][j])
           dp[i][j] = (dp[i][j] + 1LL * dp[i][p] * dp[p][j])  1000000007;
   ans = dp[1][n];
   printf( d
 , ans);
 }


#include <bits/stdc++.h>
 using namespace std;
 int round_up(int i) {
   while (i & (i - 1)) {
     i = ((i - 1) | i) + 1;
   }
   return i;
 }
 class seg_t {
  public:
   vector<int> seg, ar;
   int n;
   seg_t(vector<int>& a) {
     n = a.size();
     ar = a;
     int si = round_up(n);
     seg.resize(si * 2);
     build(0, 0, n - 1);
   }
   void build(int i, int l, int r) {
     if (l == r) {
       seg[i] = ar[l];
       return;
     }
     int mid = (l + r) / 2;
     build(i * 2 + 1, l, mid);
     build(i * 2 + 2, mid + 1, r);
     seg[i] = min(seg[i * 2 + 1], seg[i * 2 + 2]);
   }
   int q(int i, int l, int r, int lind, int rind, int val) {
     if (r < lind || r > rind) {
       return -1;
     }
     if (l == r) {
       if (seg[i] >= val) return -1;
       return l;
     }
     if (lind <= l && r <= rind) {
       if (seg[i] >= val) return -1;
     }
     int mid = (l + r) / 2;
     int t = q(i * 2 + 1, l, mid, lind, rind, val);
     if (t >= 0) return t;
     return q(i * 2 + 2, mid + 1, r, lind, rind, val);
   }
   int qq(int i, int l, int r, int lind, int rind) {
     if (r < lind || r > rind) {
       return 1000000000;
     }
     if (lind <= l && r <= rind) {
       return seg[i];
     }
     int mid = (l + r) / 2;
     return min(qq(i * 2 + 1, l, mid, lind, rind),
                qq(i * 2 + 2, mid + 1, r, lind, rind));
   }
 };
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int n;
   cin >> n;
   vector<int> a(2 * n);
   for (int i = 0; i < n; i++) {
     cin >> a[i];
     a[i + n] = a[i];
   }
   seg_t t(a);
   vector<int> b(2 * n);
   for (int i = 0; i < n; i++) {
     int tmp = t.q(0, 0, 2 * n - 1, i, n * 2 - 1, (a[i] + 1) / 2);
     if (tmp == -1)
       b[i] = 1000000000;
     else
       b[i] = tmp;
     b[i + n] = b[i] + n;
   }
   seg_t tt(b);
   for (int i = 0; i < n; i++) {
     int tmp = tt.qq(0, 0, 2 * n - 1, i, n * 2 - 1);
     if (tmp >= 1000000000)
       cout << -1 << ' ';
     else
       cout << tmp - i << ' ';
   }
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using ll = long long;
 using ld = long double;
 using pii = pair<int, int>;
 int const N = 1e5 + 20, MAX = 7000 + 20;
 int n, q;
 bitset<MAX> bt[N];
 int a[MAX];
 vector<int> dv[MAX];
 bitset<MAX> save[MAX];
 void pre() {
   a[1] = 1;
   for (int i = 1; i < MAX; i++) {
     for (int j = 2 * i; j < MAX; j += i) a[j] ^= a[i], dv[j].push_back(i);
     dv[i].push_back(i);
   }
   for (int i = 1; i < MAX; i++) {
     for (int j = 1; i * j < MAX; j++) {
       if (a[j]) save[i][i * j] = 1;
     }
   }
 }
 int main() {
   pre();
   scanf( d d  , &n, &q);
   while (q--) {
     int tp, x, y, z, v;
     scanf( d  , &tp);
     if (tp == 1) {
       scanf( d d  , &x, &v);
       x--;
       bt[x].reset();
       for (int u : dv[v]) bt[x][u] = 1;
     } else if (tp == 2) {
       scanf( d d d  , &x, &y, &z);
       x--, y--, z--;
       bt[x] = (bt[y] ^ bt[z]);
     } else if (tp == 3) {
       scanf( d d d  , &x, &y, &z);
       x--, y--, z--;
       bt[x] = (bt[y] & bt[z]);
     } else if (tp == 4) {
       scanf( d d  , &x, &v);
       x--;
       bitset<MAX> tmp = (bt[x] & save[v]);
       putchar('0' + (tmp.count() & 1));
     }
   }
   putchar('
');
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 int k;
 vector<pair<long double, long double> > vp;
 const long double PI = 2 * acos(0.0);
 bool check(long double r) {
   vector<pair<long double, int> > events;
   for (int i = 0; i < n; ++i) {
     long double ang = atan2(vp[i].second, vp[i].first);
     long double d =
         sqrt(vp[i].first * vp[i].first + vp[i].second * vp[i].second);
     if (d > 2 * r) continue;
     long double alph = (PI - acos(1 - (d * d) / (2 * (r * r)))) / 2;
     long double ang_in = ang - alph;
     long double ang_out = ang + alph;
     if (ang_in < 0) {
       ang_in += 2 * PI;
       ang_out += 2 * PI;
     }
     events.emplace_back(ang_in, 1);
     events.emplace_back(ang_out, -1);
     events.emplace_back(ang_in + 2 * PI, 1);
     events.emplace_back(ang_out + 2 * PI, -1);
   }
   sort(events.begin(), events.end());
   int ck = 0;
   for (int i = 0; i < (int)events.size(); ++i) {
     ck += events[i].second;
     if (ck >= k) return true;
   }
   return false;
 }
 int main() {
   cout.setf(ios::fixed);
   cout << setprecision(10);
   cin >> n;
   cin >> k;
   for (int i = 0; i < n; ++i) {
     int first, second;
     cin >> first >> second;
     vp.emplace_back(first, second);
   }
   long double l = 0;
   long double r = 2e5;
   while (r - l > 1e-6) {
     long double mid = (l + r) / 2;
     if (check(mid)) {
       r = mid;
     } else {
       l = mid;
     }
   }
   cout << l << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long check(long long x) {
   long long i = 0, ans = 0;
   while (x > 0) {
     if ((x & (1)) == 1) {
       ans = max(ans, i);
     }
     x = x >> 1;
     i++;
   }
   return ans;
 }
 void solve() {
   long long n;
   cin >> n;
   long long a[n + 1];
   map<long long, long long> mp;
   for (long long i = 0; i < n; i++) {
     cin >> a[i];
     mp[check(a[i])]++;
   }
   long long ans = 0;
   for (auto x : mp) {
     if (x.second > 1) ans += ((x.second) * (x.second - 1)) / 2;
   }
   cout << ans << endl;
   return;
 }
 int main() {
   int t;
   cin >> t;
   while (t--) {
     solve();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int cnt = 0;
 vector<int> ans;
 vector<vector<int> > adj;
 void dfs(int u, int col) {
   if (ans[u] != -1) return;
   ans[u] = col;
   for (int i = 0; i < adj[u].size(); ++i) dfs(adj[u][i], col);
 }
 char conv(int first) {
   if (first == 0) return 'b';
   if (first == 1) return 'a';
   if (first == 2) return 'c';
 }
 int main() {
   cout.setf(ios::fixed);
   cout.precision(7);
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int n, m;
   cin >> n >> m;
   adj = vector<vector<int> >(n);
   vector<int> deg(n, 0);
   for (int asdf = 0; asdf < m; ++asdf) {
     int first, second;
     cin >> first >> second;
     --first;
     --second;
     adj[first].push_back(second);
     adj[second].push_back(first);
     ++deg[first];
     ++deg[second];
   }
   ans = vector<int>(n, -1);
   int qt = 0;
   for (int i = 0; i < n; ++i)
     if (deg[i] == n - 1) {
       ans[i] = 0;
       ++qt;
     }
   for (int i = 0; i < n; ++i)
     if (ans[i] == -1) {
       ++cnt;
       dfs(i, cnt);
     }
   bool ok = true;
   if (cnt >= 3) ok = false;
   int n1 = 0, m1 = 0, n2 = 0, m2 = 0;
   for (int i = 0; i < n; ++i) {
     if (ans[i] == 1) {
       ++n1;
       m1 += deg[i] - qt;
     } else if (ans[i] == 2) {
       ++n2;
       m2 += deg[i] - qt;
     }
   }
   if (n1 * (n1 - 1) != m1) ok = false;
   if (n2 * (n2 - 1) != m2) ok = false;
   if (not ok)
     cout <<  No
 ;
   else {
     cout <<  Yes
 ;
     for (int i = 0; i < n; ++i) cout << conv(ans[i]);
     cout << '
';
   }
 }


#include <bits/stdc++.h>
 typedef std::function<long long(long long)> fun;
 class Map {
   int n, w, r;
   std::vector<int> A, B;
   std::function<int(long long)> lower, upper;
   std::vector<long long> who;
   std::vector<int> val;
   void find_array(std::vector<int> &a, const std::vector<long long> &S, fun f,
                   fun g) {
     a.resize(1 << r);
     std::vector<std::list<long long> > set(1 << r);
     std::vector<int> m(1 << (r + 1));
     std::vector<int> ind;
     for (long long x : S) {
       if (set[f(x)].empty()) ind.push_back(f(x));
       set[f(x)].push_back(x);
     }
     std::sort(ind.begin(), ind.end(),
               [&](int x, int y) { return set[x].size() > set[y].size(); });
     for (int i : ind) {
       a[i] = 0;
       for (int j = 0; j < r; ++j) {
         int ex0 = 0, ex1 = 0;
         for (long long y : set[i])
           ex0 += m[(1 << (j + 1)) + ((y & ((1 << (j + 1)) - 1)) ^ a[i])],
               ex1 += m[(1 << (j + 1)) +
                        ((y & ((1 << (j + 1)) - 1)) ^ (a[i] | (1 << j)))];
         if (ex1 < ex0) a[i] |= (1 << j);
       }
       for (long long y : set[i]) {
         int v = (g(y) ^ a[i]);
         for (int j = 0; j < r; ++j)
           m[(1 << (r - j)) + v]++, v = v & ((1 << (r - 1 - j)) - 1);
       }
     }
   }

  public:
   Map() {}
   Map(const std::vector<long long> &S, int word) { init(S, word); }
   int operator()(long long x) { return lower(x) ^ B[upper(x) ^ A[lower(x)]]; }
   int size() { return (1 << r); }
   bool have(long long x) { return who[(*this)(x)] == x; }
   int &operator[](long long i) { return val[(*this)(i)]; }
   void init(const std::vector<long long> &S, int word) {
     n = (int)S.size();
     w = word;
     r = std::max(w / 2, (int)std::log2(n) + 3) + 1;
     assert(*std::min_element(S.begin(), S.end()) >= 0);
     assert(*std::max_element(S.begin(), S.end()) < (1ll << word));
     lower = [&](long long x) { return x & ((1 << r) - 1); };
     upper = [&](long long x) { return x >> (w - r); };
     find_array(A, S, lower, upper);
     auto f2 = [&](long long x) { return upper(x) ^ A[lower(x)]; };
     auto &g2 = lower;
     find_array(B, S, f2, g2);
     who.resize(1 << r, -1);
     for (long long x : S) who[(*this)(x)] = x;
     val.resize(1 << r);
   }
 };
 void make_unique(std::vector<long long> &A) {
   std::sort(A.begin(), A.end());
   A.resize(std::unique(A.begin(), A.end()) - A.begin());
 }
 int main() {
   std::ios_base::sync_with_stdio(false);
   std::cin.tie(0);
   int n, k;
   std::cin >> n >> k;
   std::vector<int> A(n);
   long long pref = 0;
   std::vector<long long> values;
   values.push_back(pref);
   for (int i = 0; i < n; ++i) {
     std::cin >> A[i];
     pref += A[i];
     values.push_back(pref);
   }
   make_unique(values);
   long long min = *std::min_element(values.begin(), values.end());
   std::vector<long long> lower, upper;
   for (long long x : values)
     lower.push_back((x - min) & ((1 << 24) - 1)),
         upper.push_back((x - min) >> 24);
   make_unique(lower);
   make_unique(upper);
   Map ml(lower, 24);
   Map mu(upper, 24);
   std::vector<long long> vals;
   auto kto = [&](long long x) {
     if (!ml.have((x - min) & ((1 << 24) - 1)) || !mu.have((x - min) >> 24))
       return -1ll;
     return ml((x - min) & ((1 << 24) - 1)) +
            1ll * ml.size() * mu((x - min) >> 24);
   };
   for (long long x : values) vals.push_back(kto(x));
   make_unique(vals);
   Map map(vals, 40);
   long long ans = 0;
   pref = 0;
   map[kto(pref)]++;
   for (int i = 0; i < n; ++i) {
     pref += A[i];
     long long pow = 1;
     while (std::abs(pow) < 1000000000ll * 100000ll + 5ll) {
       long long want = (pref - pow);
       if (want >= min && want <= min + (1ll << 48)) {
         if (kto(want) != -1 && map.have(kto(want))) {
           ans += map[kto(want)];
         }
       }
       pow *= k;
       if (pow == 1) break;
     }
     map[kto(pref)]++;
   }
   std::cout << ans <<
 ;
   return 0;
 }