#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 50 + 5, maxL = (1 << 20) + 10;
 int N, L;
 char s[maxn][25];
 bool vis[maxL];
 long double F[maxL], R[25];
 long long dask[maxL];
 bool check(int tt, int k) {
   if (dask[tt] & (1LL << k))
     return false;
   else
     return true;
 }
 long double dfs(int tt, int g) {
   if (g == 0) return 0.0;
   if (vis[tt]) return F[tt];
   long double ret = 0.0;
   long double step = L - g + 1;
   for (int i = 0; i < L; i++) {
     if ((1 << i) & tt) continue;
     int nt = (1 << i) | tt;
     int wq = __builtin_popcountll(dask[nt] ^ dask[tt]);
     ret += step * R[g] * wq;
     ret += dfs(nt, g - 1);
   }
   vis[tt] = true;
   F[tt] = ret;
   return ret;
 }
 void Prepare() {
   memset(dask, 0, sizeof(dask));
   for (int i = (1), _i = (N); i <= _i; i++)
     for (int j = (i + 1), _j = (N); j <= _j; j++) {
       int same = 0;
       for (int k = 0; k < L; k++)
         if (s[i][k] == s[j][k]) same |= (1 << k);
       dask[same] |= (1LL << j) | (1LL << i);
     }
   for (int i = (1 << L) - 1; i; i--)
     for (int k = 0; k < L; k++)
       if (i & (1 << k)) dask[i ^ (1 << k)] |= dask[i];
 }
 int main() {
   for (; scanf('%d', &N) != EOF;) {
     for (int i = (1), _i = (N); i <= _i; i++) scanf('%s', s[i]);
     L = strlen(s[1]);
     int gg = L;
     R[L] = 1.0 / (long double)L;
     for (int i = (L - 1), _i = (1); i >= _i; i--) {
       gg--;
       R[i] = R[i + 1] / (long double)gg;
     }
     memset(vis, 0, sizeof(vis));
     long double ans = 0.0;
     Prepare();
     ans = dfs(0, L);
     ans /= (long double)N;
     printf('%.15lf
', (double)ans);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int tot, n;
 int vis[110];
 int p[110];
 int dp[2][262144], cs[110][262144], pre[110][262144];
 int have[100];
 int a[110], b[110];
 string print(int sta) {
   string x = '';
   for (int i = tot - 1; i >= 0; i--) {
     if (sta & (1 << i))
       x += '1';
     else
       x += '0';
   }
   return x;
 }
 int main() {
   for (int i = 2; i <= 59; i++) {
     if (!vis[i]) p[tot++] = i;
     for (int j = i; j <= 59; j += i) vis[j] = 1;
   }
   for (int i = 1; i <= 59; i++) {
     for (int j = 0; j < tot; j++) {
       if (i % p[j] == 0) have[i] |= (1 << j);
     }
   }
   scanf('%d', &n);
   for (int i = 1; i <= n; i++) {
     scanf('%d', &a[i]);
   }
   memset(dp, 0x3f, sizeof(dp));
   dp[0][0] = 0;
   register int tmp;
   register int nowt = 1, pret = 0;
   for (int i = 1; i <= n; i++) {
     for (int sta = 0; sta < (1 << tot); sta++) {
       dp[nowt][sta] = 0x3f3f3f3f;
       for (int j = 1; j <= 59; j++) {
         if ((have[j] & sta) != have[j]) continue;
         tmp = dp[pret][have[j] ^ sta] + abs(j - a[i]);
         if (tmp < dp[nowt][sta]) {
           dp[nowt][sta] = tmp;
           pre[i][sta] = have[j] ^ sta;
           cs[i][sta] = j;
         }
       }
     }
     nowt ^= 1;
     pret ^= 1;
   }
   int mi = 0x3f3f3f3f;
   for (int i = 0; i < (1 << tot); i++) {
     mi = min(mi, dp[pret][i]);
   }
   int pp;
   for (int i = 0; i < (1 << tot); i++) {
     if (mi == dp[pret][i]) {
       pp = i;
       for (int now = n; now >= 1; now--) {
         b[now] = cs[now][pp];
         pp = pre[now][pp];
       }
       for (int now = 1; now <= n; now++) {
         printf('%d ', b[now]);
       }
       puts('');
       return 0;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 void read(long long a = 0) {
   freopen('in', 'r', stdin);
   if (a) freopen('out', 'w', stdout);
 }
 long long a[100009 * 10], b[100009 * 10];
 long long n, m;
 bool bs(long long num) {
   bool vis[100009 * 10] = {};
   long long space = 0;
   for (int i = num; i >= 0; i--) {
     if (a[i] && !vis[a[i]]) {
       vis[a[i]] = 1;
       space += b[a[i] - 1];
     } else {
       space--;
       space = max(space, 0ll);
     }
   }
   for (int i = 1; i <= m; i++)
     if (!vis[i]) return 0;
   if (space == 0)
     return 1;
   else
     return 0;
 }
 int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   cin >> n >> m;
   for (int i = 0; i < n; i++) cin >> a[i];
   for (int i = 0; i < m; i++) cin >> b[i];
   long long lo = 0, hi = n + 1;
   while (lo < hi) {
     long long mid = (lo + hi - 1) >> 1;
     if (bs(mid))
       hi = mid;
     else
       lo = mid + 1;
   }
   if (hi == n + 1)
     cout << '-1';
   else
     cout << hi + 1;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long mod = 1e9 + 9;
 const int N = 4040;
 int n, w, b;
 long long fac[N], f[N][N], inv[N];
 long long qpow(long long x, long long p) {
   long long res = 1ll;
   while (p) {
     if (p & 1) {
       res = (res * x) % mod;
     }
     x = (x * x) % mod;
     p >>= 1;
   }
   return res;
 }
 long long INV(long long k) { return qpow(k, mod - 2); }
 long long calc(int x, int y) {
   return fac[x] * inv[y] % mod * inv[x - y] % mod;
 }
 void init() {
   fac[0] = 1ll;
   inv[0] = 1ll;
   for (int i = 1; i < N; i++) {
     fac[i] = (fac[i - 1] * 1ll * i) % mod;
     inv[i] = INV(fac[i]);
   }
 }
 int main() {
   scanf('%d%d%d', &n, &w, &b);
   init();
   for (int i = 1; i <= n; i++) {
     for (int j = i; j < N; j++) {
       f[i][j] = (fac[j] * calc(j - 1, i - 1)) % mod;
     }
   }
   long long ans = 0;
   for (int i = 1; i < n - 1; i++) {
     ans =
         (ans + f[n - i][w] * f[i][b] % mod * (1ll * n - 1ll * i - 1ll) % mod) %
         mod;
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long f(string s, long long m) {
   map<char, long long> a;
   map<char, long long>::iterator ii;
   long long i;
   for (i = 0; i < s.size(); i++) {
     a[s[i]]++;
   }
   long long best = 0;
   for (ii = a.begin(); ii != a.end(); ii++) best = max(best, ii->second);
   long long p = s.size();
   if (best == p && m == 1) return p - 1;
   return min(p, best + m);
 }
 int main() {
   string s1, s2, s3;
   long long n;
   cin >> n;
   cin >> s1 >> s2 >> s3;
   if (f(s1, n) > f(s2, n) && f(s1, n) > f(s3, n)) {
     cout << 'Kuro';
     return 0;
   }
   if (f(s2, n) > f(s1, n) && f(s2, n) > f(s3, n)) {
     cout << 'Shiro';
     return 0;
   }
   if (f(s3, n) > f(s1, n) && f(s3, n) > f(s2, n)) {
     cout << 'Katie';
     return 0;
   }
   cout << 'Draw';
   return 0;
 }


#include <bits/stdc++.h>
 template <class T>
 void rd(T &x) {
   x = 0;
   int f = 1;
   char c;
   while (!isdigit(c = getchar()))
     if (c == '-') f = -1;
   do {
     x = (x << 3) + (x << 1) + (c ^ 48);
   } while (isdigit(c = getchar()));
   x *= f;
 }
 using namespace std;
 const int N = 1e5 + 5;
 int n, dp[N], s[N], p[N], cnt, tp;
 map<int, int> Map[N];
 int main() {
   rd(n);
   for (int i = 1; i <= n; i++) {
     int v, c, l, r;
     rd(v), rd(c), rd(l), rd(r);
     if (r + c <= 1e5 && (!l || Map[l].find(r + c) != Map[l].end())) {
       int t = Map[l][r + c];
       dp[i] = dp[t] + v;
       p[i] = t;
       if (!r && dp[i] > dp[tp]) tp = i;
       if (dp[i] > dp[Map[l + c][r]]) Map[l + c][r] = i;
     }
   }
   while (tp) s[++cnt] = tp, tp = p[tp];
   printf('%d
', cnt);
   for (; cnt > 0; cnt--) printf('%d ', s[cnt]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, k, v1, v2, L;
 bool can(double m) {
   double bus = 0, nbus = 0;
   for (int i = 0; i < (n + k - 1) / k; i++) {
     if (i == 0)
       bus += m * v2;
     else
       bus += m * v1;
     nbus += m * v1;
     if (bus > L) return false;
     double sb = (bus - nbus) / (v1 + v2);
     bus += sb * v1;
     nbus += sb * v1;
   }
   return true;
 }
 int main() {
   scanf('%d%d%d%d%d', &n, &L, &v1, &v2, &k);
   double l = 0, r = (double)L / v2, m;
   for (int i = 0; i < 100; i++) {
     m = (l + r) / 2.0;
     if (can(m))
       l = m;
     else
       r = m;
   }
   printf('%.12f', m + (L - m * v2) / v1);
 }


#include <bits/stdc++.h>
 using namespace std;
 inline long long Calc(const int &x) {
   long long res = 0;
   for (long long i = 1; i <= x; i *= 10) res += x - i + 1;
   return res;
 }
 inline long long CalcSum(const int &x) {
   long long res = 0;
   for (long long i = 1; i <= x; i *= 10)
     res += 1ll * (x - i + 1) * (x - i + 2) / 2;
   return res;
 }
 inline int Pos(const int &x, const int &k) {
   stringstream ss;
   ss << x;
   string s;
   ss >> s;
   return s[k - 1] - '0';
 }
 inline int Solve(long long k) {
   int l = 1, r = 1000000000;
   while (l <= r) {
     int mid = (l + r) / 2;
     if (CalcSum(mid) >= k)
       r = mid - 1;
     else
       l = mid + 1;
   }
   k = k - CalcSum(r);
   int block = l;
   l = 1;
   r = block;
   while (l <= r) {
     int mid = (l + r) / 2;
     if (Calc(mid) >= k)
       r = mid - 1;
     else
       l = mid + 1;
   }
   return Pos(l, k - Calc(r));
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int q;
   cin >> q;
   while (q--) {
     long long k;
     cin >> k;
     cout << Solve(k) << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 const int INF = 1e9;
 using namespace std;
 void dfs(int v, int p, vector<vector<int> > &graph, vector<int> &sz) {
   sz[v] = 1;
   for (auto u : graph[v])
     if (u != p) {
       dfs(u, v, graph, sz);
       sz[v] += sz[u];
     }
 }
 void dfs(int v, int p, vector<vector<int> > &graph, vector<int> &c, int C) {
   c[v] = C;
   for (auto u : graph[v])
     if (u != p) {
       dfs(u, v, graph, c, C);
     }
 }
 signed main() {
   int n;
   cin >> n;
   vector<vector<int> > graph(n);
   for (int i = 0; i < n - 1; i++) {
     int a, b;
     cin >> a >> b;
     a--, b--;
     graph[a].push_back(b);
     graph[b].push_back(a);
   }
   vector<int> sz(n);
   dfs(0, 0, graph, sz);
   vector<int> cen;
   long long ans = 0;
   for (int i = 0; i < n; i++) {
     if ((n - sz[i]) * 2 <= n) {
       int t = 1;
       for (auto u : graph[i]) {
         if (sz[u] < sz[i]) {
           if (2 * sz[u] <= n) continue;
           t = 0;
         }
       }
       if (t) cen.push_back(i);
     }
   }
   for (int i = 0; i < n; i++) {
     ans += 2 * min(sz[i], n - sz[i]);
   }
   cout << ans << '
';
   if (cen.size() == 2) {
     int v = cen[0], u = cen[1];
     vector<int> c(n);
     dfs(v, u, graph, c, 0);
     dfs(u, v, graph, c, 1);
     vector<int> p0, p1;
     for (int i = 0; i < n; i++) {
       if (c[i] == 0) p0.push_back(i);
       if (c[i] == 1) p1.push_back(i);
     }
     vector<int> ans(n);
     for (int i = 0; i < n / 2; i++) {
       ans[p0[i]] = p1[i];
       ans[p1[i]] = p0[i];
     }
     for (int i = 0; i < n; i++) {
       cout << ans[i] + 1 << ' ';
     }
     return 0;
   } else {
     dfs(cen[0], cen[0], graph, sz);
     int C = 0, idC = 0;
     vector<int> c(n);
     c[cen[0]] = -1;
     int maxsz = 0;
     for (auto u : graph[cen[0]]) {
       dfs(u, cen[0], graph, c, C);
       maxsz = max(maxsz, sz[u]);
       if (maxsz == sz[u]) idC = C;
       C++;
     }
     vector<pair<int, int> > q;
     for (int i = 0; i < n; i++) {
       if (i != cen[0] && c[i] != idC) q.push_back({c[i], i});
     }
     for (int i = 0; i < n; i++) {
       if (i != cen[0] && c[i] == idC) q.push_back({INF, i});
     }
     q.push_back({INF + 1, cen[0]});
     sort((q).begin(), (q).end());
     vector<int> ans(n);
     for (int i = 0; i < n; i++) {
       ans[q[i].second] = q[(i + maxsz) % q.size()].second;
     }
     for (int i = 0; i < n; i++) {
       assert(c[ans[i]] != c[i]);
       cout << ans[i] + 1 << ' ';
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 1e5;
 int n;
 double a[MAXN], b[4], t;
 int main() {
   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   cin >> n;
   b[3] = 1;
   for (int i = 1; i <= n; i++) {
     cin >> t;
     b[0] += t;
     b[1]++;
     if (b[1] * b[2] <= b[0] * b[3]) b[2] = b[0], b[3] = b[1];
   }
   cout << fixed << setprecision(10) << b[2] / b[3] << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 0x0f0f0f0f;
 template <class S, class T>
 inline pair<S, T> MP(S a, T b) {
   return make_pair(a, b);
 }
 template <class T>
 inline auto LX(T &X) -> decltype((X.first)) {
   return X.first;
 }
 template <class T>
 inline auto LX(const T &X) -> const decltype((X.first)) {
   return X.first;
 }
 template <class T>
 inline auto RX(T &X) -> decltype((X.second)) {
   return X.second;
 }
 template <class T>
 inline auto RX(const T &X) -> const decltype((X.second)) {
   return X.second;
 }
 template <class T>
 inline void RST(T &a) {
   memset(a, 0, sizeof(a));
 }
 template <class T>
 inline void RST1(T &a) {
   memset(a, -1, sizeof(a));
 }
 template <class T>
 inline void SINF(T &a) {
   memset(a, 0x0f, sizeof(a));
 }
 template <class S, class T>
 inline void RST(S &a, T b) {
   fill((T *)a, (T *)a + (sizeof(a) / sizeof(b)), b);
 }
 template <class T>
 inline void CLR(T &a) {
   a.clear();
 }
 template <class S, class T>
 inline void CPY(S &a, T &b) {
   memcpy(a, b, sizeof(a));
 }
 template <class S, class T>
 inline bool chkmin(S &a, T b) {
   return b < a ? a = b, 1 : 0;
 }
 template <class S, class T>
 inline bool chkmax(S &a, T b) {
   return a < b ? a = b, 1 : 0;
 }
 template <class T>
 inline T sqr(T x) {
   return x * x;
 }
 template <class T>
 inline int SZ(T &a) {
   return (int)(a.size());
 }
 template <class T>
 inline bool EPT(T &a) {
   return a.empty();
 }
 template <class T>
 inline auto FRT(T &a) -> decltype((a.front())) {
   return a.front();
 }
 template <class T>
 inline auto FRT(const T &a) -> const decltype((a.front())) {
   return a.front();
 }
 template <class T>
 inline auto BK(T &a) -> decltype(a.back()) & {
   return a.back();
 }
 template <class T>
 inline auto BK(const T &a) -> const decltype((a.back())) {
   return a.back();
 }
 template <class T>
 inline auto TOP(T &a) -> decltype((a.top())) {
   return a.top();
 }
 template <class T>
 inline auto TOP(const T &a) -> const decltype((a.top())) {
   return a.top();
 }
 int n, m, f[1010], g[1010], cnt;
 char buf[1010];
 double ans;
 void solve(int *c, int n, int m) {
   int s = 0;
   for (int i = 1; i <= n; i++)
     if (c[i]) {
       s += c[i] - 1, ans += (double)s * (m - c[i]);
       if (!c[i + 1] || c[i + 1] < c[i]) s = 0;
     }
   s = 0;
   for (int i = 1; i <= n; i++)
     if (c[i]) {
       ans += (double)s * (c[i] - 1);
       s += m - c[i];
       if (!c[i + 1] || c[i + 1] > c[i]) s = 0;
     }
 }
 int main() {
   scanf('%d%d', &n, &m);
   for (int i = 1; i <= n; i++) {
     scanf('%s', buf + 1);
     for (int j = 1; j <= m; j++)
       if (buf[j] == 'X') f[i] = j, g[j] = i, cnt++;
   }
   solve(f, n, m);
   solve(g, m, n);
   ans *= 2;
   for (int i = 1; i <= n; i++)
     for (int j = 1; j <= i; j++)
       ans += 1. * (m - (f[i] ? 1 : 0)) * (m - (f[j] ? 1 : 0)) * (i - j);
   for (int i = 1; i <= m; i++)
     for (int j = 1; j <= i; j++)
       ans += 1. * (n - (g[i] ? 1 : 0)) * (n - (g[j] ? 1 : 0)) * (i - j);
   ans *= 2;
   ans /= sqr((double)n * m - cnt);
   printf('%.10lf
', ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int arr[101][1001];
 int n, m;
 int g[101][101];
 vector<int> col[1001];
 set<int> row[101];
 bool ans[101][101];
 int main() {
   scanf('%d', &n), scanf('%d', &m);
   for (int i = 0; i < m; ++i) {
     int x, y;
     scanf('%d', &x), scanf('%d', &y);
     g[x][y] = g[y][x] = 1;
   }
   for (int i = 1; i <= n; ++i) g[i][i] = true;
   for (int i = 1; i <= n; ++i) {
     for (int j = i + 1; j <= n; ++j) {
       if (g[i][j] && !ans[i][j]) {
         for (int k = 0; k < 1001; ++k)
           if (col[k].size() == 0) {
             arr[i][k] = i;
             arr[j][k] = j;
             col[k].push_back(i), col[k].push_back(j);
             break;
           } else {
             bool ok = true;
             for (int l = 0; l < col[k].size(); ++l) {
               int cur = col[k][l];
               if (!g[cur][i] || !g[cur][j]) {
                 ok = false;
                 break;
               }
             }
             if (ok) {
               arr[i][k] = i;
               arr[j][k] = j;
               for (int l = 0; l < col[k].size(); ++l) {
                 int cur = col[k][l];
                 ans[cur][i] = ans[i][cur] = ans[j][cur] = ans[cur][j] = true;
               }
               col[k].push_back(i), col[k].push_back(j);
               break;
             }
           }
         ans[i][j] = true;
         ans[j][i] = true;
       }
     }
   }
   for (int i = 0; i < 1001; ++i)
     for (int j = 0; j < col[i].size(); ++j) row[col[i][j]].insert(i);
   for (int i = 1; i < 101; ++i)
     if (row[i].size() == 0) {
       for (int j = 0; j < 1001; ++j)
         if (col[j].size() == 0) {
           col[j].push_back(i);
           row[i].insert(j);
           break;
         }
     }
   for (int i = 1; i <= n; ++i) {
     printf('%d
', row[i].size());
     for (set<int>::iterator it = row[i].begin(); it != row[i].end(); ++it)
       printf('%d %d
', i, (*it) + 1);
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, p1, p2;
   cin >> n;
   cin >> p1;
   int a1[p1];
   for (int i = 0; i < p1; i++) cin >> a1[i];
   cin >> p2;
   int a2[p2];
   for (int i = 0; i < p2; i++) cin >> a2[i];
   sort(a1, a1 + p1);
   sort(a2, a2 + p2);
   vector<int>::iterator it;
   vector<int> res(100);
   it = set_union(a1, a1 + p1, a2, a2 + p2, res.begin());
   res.resize(it - res.begin());
   if (res.size() == n)
     cout << 'I become the guy.';
   else
     cout << 'Oh, my keyboard!';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 int v[5], p[5];
 int cnt[5], add[5];
 int getMaxScr(int acc, int tot) {
   int MaxScr;
   for (int i = 0; i < 6; i++) {
     int t = 1 << i;
     if (tot >= t * acc) MaxScr = (i + 1) * 500;
   }
   return MaxScr;
 }
 bool ok(int m) {
   int vScr = 0, pScr = 0;
   for (int i = 0; i < 5; i++) {
     int MaxScr = getMaxScr(cnt[i] + m * add[i], n + m);
     if (v[i] != -1) vScr += MaxScr / 250 * (250 - v[i]);
     if (p[i] != -1) pScr += MaxScr / 250 * (250 - p[i]);
   }
   return vScr > pScr;
 }
 int main() {
   cin >> n;
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < 5; j++) {
       int t;
       cin >> t;
       if (i == 0) v[j] = t;
       if (i == 1) p[j] = t;
       if (t != -1) cnt[j]++;
     }
   }
   for (int i = 0; i < 5; i++)
     if (v[i] != -1 && p[i] != -1 && p[i] < v[i]) add[i] = 1;
   int ans = 0;
   while (!ok(ans) && ans < 100000) ans++;
   cout << (ans == 100000 ? -1 : ans) << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long big = 1000000007;
 unsigned long long gcd(unsigned long long a, unsigned long long b) {
   if (a == 0) return b;
   return gcd(b % a, a);
 }
 string getbin(unsigned long long x) {
   if (x == 0) return '0';
   string ret = '';
   while (x != 0) {
     ret = (char)('0' + x % 2) + ret;
     x /= 2;
   }
   return ret;
 }
 unsigned long long getdec(string b) {
   unsigned long long ret = 0;
   for (int i = 0; i < b.size(); i += 1) {
     ret *= 2;
     ret += b[i] - '0';
   }
   return ret;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int t;
   cin >> t;
   while (t--) {
     long long n;
     cin >> n;
     long long s = 0;
     vector<int> a(n);
     for (int i = 0; i < n; i += 1) cin >> a[i], s += a[i];
     bool b = false;
     for (int i = 0; !b && i < n; i += 1) {
       if (a[i] > s / 2) b = true;
     }
     if (b)
       cout << 'T';
     else if (s % 2 == 0)
       cout << 'HL';
     else
       cout << 'T';
     cout << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline long long read() {
   long long x = 0, f = 0;
   char ch = getchar();
   for (; ch < '0' || ch > '9'; ch = getchar()) f ^= (ch == '-');
   for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
   return f ? -x : x;
 }
 const long long maxn = 200050;
 long long n, head[maxn], cnt = 0, siz[maxn], dep[maxn];
 long long ans = 0, qwq = 0;
 struct node {
   long long to, nxt;
 } e[maxn * 2];
 inline void add(long long u, long long v) {
   e[++cnt].to = v;
   e[cnt].nxt = head[u];
   head[u] = cnt;
 }
 void dfs(long long u, long long f, long long d) {
   siz[u] = 1;
   dep[u] = d;
   for (long long i = head[u]; i; i = e[i].nxt) {
     long long v = e[i].to;
     if (v == f) continue;
     dfs(v, u, d + 1);
     siz[u] += siz[v];
   }
 }
 signed main() {
   n = read();
   for (long long i = 1, a, b; i < n; ++i) {
     a = read();
     b = read();
     add(a, b);
     add(b, a);
   }
   dfs(1, 0, 0);
   for (long long i = 1; i <= n; ++i) {
     ans += siz[i] * (n - siz[i]);
     if (dep[i] & 1) ++qwq;
   }
   ans += qwq * (n - qwq);
   printf('%lld
', ans / 2);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2e5 + 5;
 long double p[N], k[N];
 int par[N];
 vector<int> v[N];
 bool vstd[N];
 void dfs(int node) {
   if (vstd[node]) return;
   vstd[node] = true;
   for (auto u : v[node]) {
     if (u != par[node]) {
       k[node] += p[u];
       par[u] = node;
       dfs(u);
     }
   }
   return;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cout << fixed << setprecision(6);
   int n;
   cin >> n;
   long double tmp = 0.0;
   for (int i = 0; i < n; i++) {
     cin >> p[i];
     p[i] = 1.0 - p[i];
     tmp += p[i];
   }
   for (int i = 1; i < n; i++) {
     int a, b;
     cin >> a >> b;
     v[a].push_back(b);
     v[b].push_back(a);
   }
   long double pmt = 0.0;
   dfs(0);
   for (int i = 0; i < n; i++) pmt += k[i] * p[i];
   int q;
   cin >> q;
   while (q--) {
     int node;
     cin >> node;
     tmp -= p[node];
     pmt -= k[node] * p[node];
     if (node) {
       pmt -= k[par[node]] * p[par[node]];
       k[par[node]] -= p[node];
     }
     cin >> p[node];
     p[node] = 1.0 - p[node];
     tmp += p[node];
     if (node) k[par[node]] += p[node];
     pmt += k[node] * p[node];
     if (node) pmt += k[par[node]] * p[par[node]];
     cout << tmp - pmt << '
';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   char next;
   long long int neg = 0, pos = 0;
   cin >> next;
   bool estado = false;
   string orden = '';
   while (next != '=') {
     if (next == ' ') {
       cin >> next;
     }
     if (next == '-') {
       estado = true;
       cin >> next;
     }
     if (next == '+') {
       estado = false;
       cin >> next;
     }
     if (next == '?') {
       if (estado) {
         orden += '-';
         neg++;
       } else {
         orden += '+';
         pos++;
       }
     }
     cin >> next;
   }
   long long int num;
   cin >> num;
   long long int coefs[neg + pos];
   if ((neg > ((pos - 1) * num)) || ((pos - neg * num) > num)) {
     cout << 'Impossible';
     return 0;
   }
   long long int valpos = 0, valneg = 0;
   cout << 'Possible' << endl;
   if (neg == 0) {
     long long int cv = trunc(num / pos);
     long long int sum = 0;
     for (int i = 0; i < pos; i++) {
       coefs[i] = cv;
     }
     sum = cv * pos - num;
     if (sum != 0) {
       for (int i = 0; i < pos; i++) {
         coefs[i]++;
         sum++;
         if (sum == 0) break;
       }
     }
     cout << coefs[0];
     for (int i = 1; i < pos; i++) {
       cout << ' + ' << coefs[i];
     }
     cout << ' = ' << num;
     return 0;
   }
   if (pos - 1 > neg) {
     valpos = 1;
     valneg = trunc((pos - 1) / neg);
   } else {
     valneg = 1;
     valpos = trunc(neg / (pos - 1));
   }
   int ref;
   for (int i = 0; i < orden.size(); i++) {
     if (orden[i] == '-') {
       coefs[i] = -valneg;
     } else
       coefs[i] = valpos;
   }
   coefs[0] = num;
   long long int suma = 0;
   for (int i = 0; i < neg + pos; i++) {
     suma += coefs[i];
   }
   suma -= num;
   if (suma < 0) {
     for (int i = 1; i < neg + pos; i++) {
       if (coefs[i] > 0 && (abs(coefs[i]) < num)) {
         coefs[i]++;
         suma++;
       }
       if (suma == 0) break;
     }
   }
   if (suma > 0) {
     for (int i = 1; i < neg + pos; i++) {
       if (coefs[i] < 0 && (abs(coefs[i]) < num)) {
         coefs[i]--;
         suma--;
       }
       if (suma == 0) break;
     }
   }
   for (int i = 1; i < neg + pos; i++) {
     if (abs(coefs[i]) > num) {
       if (coefs[i] < 0) {
         suma += -num - coefs[i];
         coefs[i] = -num;
       } else {
         suma += num - coefs[i];
         coefs[i] = num;
       }
     }
   }
   if (suma > 0) {
     coefs[0] -= suma;
     suma -= suma;
   }
   if (suma < 0) {
     coefs[0] += suma;
     suma -= suma;
   }
   cout << coefs[0];
   for (int i = 1; i < pos + neg; i++) {
     if (coefs[i] < 0)
       cout << ' - ' << abs(coefs[i]);
     else
       cout << ' + ' << coefs[i];
   }
   cout << ' = ' << suma + num;
   return 0;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 const int N = 405;
 char mp[30], s[N], a[5], b[5];
 int L, n, m, e[N][N], nxd[30], nxs[30], flg[30], lim[N], tmp[N], mx[2];
 vector<int> ans;
 bool chk(int pos, int v, int x, bool ff) {
   if (lim[pos] != -1 && lim[pos] != flg[v]) return 0;
   for (int i = 1; i <= n; i++)
     if (e[x][i] && e[x][i + n]) return 0;
   for (int i = 1; i <= n; i++) tmp[i] = (e[x][i] ? 0 : (e[x][i + n] ? 1 : -1));
   if (ff) {
     for (int i = 1; i <= n; i++) {
       if (pos + i > n) break;
       int t = max(lim[pos + i], tmp[pos + i]);
       if (t == -1) break;
       if (mx[t] < s[pos + i] - 'a' + 1) return 0;
       if (mx[t] > s[pos + i] - 'a' + 1) break;
     }
   }
   for (int i = 1; i <= n; i++) {
     lim[i] = max(lim[i], tmp[i]);
   }
   return 1;
 }
 int main() {
   scanf('%s', mp + 1);
   L = strlen(mp + 1);
   memset(lim, -1, sizeof(lim));
   memset(mx, -1, sizeof(mx));
   for (int i = 1; i <= L; i++) {
     flg[i] = mp[i] == 'V';
     mx[flg[i]] = i;
   }
   for (int i = 1; i <= L; i++)
     for (int j = i + 1; j <= L; j++)
       if (flg[i] != flg[j]) {
         nxd[i] = j;
         break;
       }
   for (int i = 1; i <= L; i++)
     for (int j = i + 1; j <= L; j++)
       if (flg[i] == flg[j]) {
         nxs[i] = j;
         break;
       }
   cin >> n >> m;
   for (int i = 1; i <= m; i++) {
     int x, y;
     scanf('%d%s%d%s', &x, a, &y, b);
     int a1 = a[0] == 'V', b1 = b[0] == 'V';
     e[x + a1 * n][y + b1 * n] = 1;
     e[y + !b1 * n][x + !a1 * n] = 1;
   }
   scanf('%s', s + 1);
   for (int k = 1; k <= n * 2; k++)
     for (int i = 1; i <= n * 2; i++)
       for (int j = 1; j <= n * 2; j++) e[i][j] |= (e[i][k] & e[k][j]);
   bool ff = 1;
   for (int i = 1; i <= n; i++) {
     int mn = ff ? s[i] - 'a' + 1 : 1;
     if (chk(i, mn, i + flg[mn] * n, ff)) {
       ans.push_back(mn);
     } else if (mn < L && flg[mn] == flg[mn + 1] &&
                chk(i, mn + 1, i + flg[mn + 1] * n, 0)) {
       ans.push_back(mn + 1), ff = 0;
     } else if (nxd[mn] && chk(i, nxd[mn], i + flg[nxd[mn]] * n, 0)) {
       ans.push_back(nxd[mn]), ff = 0;
     } else if (nxs[mn] && nxs[mn] > nxd[mn] &&
                chk(i, nxs[mn], i + flg[nxs[mn]] * n, 0)) {
       ans.push_back(nxs[mn]), ff = 0;
     } else {
       return puts('-1'), 0;
     }
   }
   for (int i = 0; i <= n - 1; i++) printf('%c', ans[i] + 'a' - 1);
   puts('');
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const double eps(1e-8);
 char s[1000010];
 int n, m, a, b;
 vector<int> vec[1000010];
 vector<int> p[1000010];
 int x[1000010], y[1000010], sum[1000010], ans[1000010];
 int Lowbit(int x) { return x & (-x); }
 void Update(int pos, int val) {
   while (pos > 0) {
     sum[pos] += val;
     pos -= Lowbit(pos);
   }
 }
 int Query(int pos) {
   int ret = 0;
   while (pos <= n) {
     ret += sum[pos];
     pos += Lowbit(pos);
   }
   return ret;
 }
 void Add(int l, int r, int val) {
   Update(r, val);
   Update(l - 1, -val);
 }
 int main() {
   scanf('%s', s + 1);
   for (n = 1; s[n]; n++)
     ;
   n--;
   scanf('%d', &m);
   for (int i = 1; i <= m; i++) {
     scanf('%d%d', &a, &b);
     vec[b].push_back(a);
     p[b].push_back(i);
   }
   int len = 0;
   for (int i = 1; i <= n; i++) {
     len++;
     if (s[i] == '(')
       x[len] = 0;
     else
       x[len] = 1;
     y[len] = i;
     if (len >= 2 && x[len] == 1 && x[len - 1] == 0) {
       Add(1, y[len - 1], 2);
       len -= 2;
     }
     for (int j = 0; j < (int)vec[i].size(); j++) {
       int tmp = vec[i][j];
       ans[p[i][j]] = Query(tmp);
     }
   }
   for (int i = 1; i <= m; i++) printf('%d
', ans[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int t;
   cin >> t;
   while (t--) {
     int a, b, c, min_cost, min_a, min_b, min_c;
     cin >> a >> b >> c;
     if (b % a == 0 && c % b == 0) {
       cout << 0 << endl;
       cout << a << ' ' << b << ' ' << c << endl;
     } else {
       min_cost = 10000000;
       int max = 2 * c;
       for (int i = 1; i < max; i++)
         for (int j = i; j < max; j += i)
           for (int k = j; k < max; k += j)
             if (k % j == 0 && j % i == 0) {
               int cost = abs(a - i) + abs(b - j) + abs(c - k);
               if (cost < min_cost) {
                 min_cost = cost;
                 min_a = i;
                 min_b = j;
                 min_c = k;
               }
             }
       cout << min_cost << endl;
       cout << min_a << ' ' << min_b << ' ' << min_c << endl;
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 100010;
 vector<pair<long long, int>> adj[10 * MAXN];
 long long dist[10 * MAXN];
 int par[10 * MAXN];
 int go1(int idx, int l, int r, int ds) {
   if (idx > 1) {
     int par = idx / 2;
     adj[par + ds].push_back({0, idx + ds});
   }
   if (l == r) {
     adj[idx + ds].push_back({0, l});
     return idx;
   }
   int m = (l + r) / 2;
   int ret =
       max(idx, max(go1(2 * idx, l, m, ds), go1(2 * idx + 1, m + 1, r, ds)));
   return ret;
 }
 void go2(int idx, int l, int r, int ds) {
   for (int i = l; i < (r + 1); ++i) {
     adj[i].push_back({0, idx + ds});
   }
   if (r > l) {
     int m = (l + r) / 2;
     go2(2 * idx, l, m, ds);
     go2(2 * idx + 1, m + 1, r, ds);
   }
 }
 void go3(int idx, int x, int y, int l, int r, function<void(int)> f) {
   if (y < l || x > r) return;
   if (x >= l && y <= r) {
     f(idx);
     return;
   }
   int m = (x + y) / 2;
   go3(2 * idx, x, m, l, r, f);
   go3(2 * idx + 1, m + 1, y, l, r, f);
 }
 void dijsktra(int src) {
   memset(dist, 0x3f3f3f3f, sizeof(dist));
   dist[src] = 0;
   par[src] = src;
   priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                  greater<pair<long long, int>>>
       pq;
   pq.push({dist[src], src});
   while (!pq.empty()) {
     int u = pq.top().second;
     long long l = pq.top().first;
     pq.pop();
     if (dist[u] == l) {
       for (auto p : adj[u]) {
         long long ndist = l + p.first;
         if (ndist < dist[p.second]) {
           dist[p.second] = ndist;
           par[p.second] = u;
           pq.push({dist[p.second], p.second});
         }
       }
     }
   }
 }
 int main() {
   int n, m, src;
   scanf(' %d %d', &(n), &(m));
   scanf(' %d', &(src));
   --src;
   int ds1 = n - 1 + 5;
   int ds2 = go1(1, 0, n - 1, ds1) + ds1 + 5;
   go2(1, 0, n - 1, ds2);
   while (m--) {
     int tp;
     scanf(' %d', &(tp));
     if (tp == 1) {
       int u, v, w;
       scanf(' %d %d', &(u), &(v));
       scanf(' %d', &(w));
       adj[u - 1].push_back({w, v - 1});
     } else {
       int vtx, l, r, w;
       scanf(' %d %d', &(vtx), &(l));
       scanf(' %d %d', &(r), &(w));
       --l;
       --r;
       --vtx;
       go3(1, 0, n - 1, l, r, [ds1, ds2, tp, w, vtx](int idx) {
         if (tp == 2) {
           adj[vtx].push_back({w, idx + ds1});
         } else {
           adj[idx + ds2].push_back({w, vtx});
         }
       });
     }
   }
   dijsktra(src);
   for (int i = 0; i < (n); ++i)
     printf('%lld%c', (dist[i] == 0x3f3f3f3f3f3f3f3fll ? -1 : dist[i]),
            '
'[i == n - 1]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 pair<long long, long long> a[300001];
 long long n, k, s, m;
 bool b[300001];
 inline long long read() {
   long long sum = 0, x = 1;
   char ch = getchar();
   while (ch < '0' || ch > '9') {
     if (ch == '-') x = -1;
     ch = getchar();
   }
   while (ch >= '0' && ch <= '9') {
     sum = sum * 10 + ch - '0';
     ch = getchar();
   }
   return sum * x;
 }
 inline void write(long long x) {
   if (x < 0) {
     putchar('-');
     x = -x;
   }
   if (x > 9) write(x / 10);
   putchar(x % 10 + '0');
   return;
 }
 inline bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
   return a.first > b.first;
 }
 signed main() {
   n = read();
   k = read();
   for (register long long i = 1; i <= n; ++i) a[i].second = i;
   for (m = 1; m <= n; ++m) {
     for (register long long j = m * 2; j <= n; j += m) ++a[j].first;
     s += a[m].first;
     if (s >= k) break;
   }
   if (s < k) {
     puts('No');
     return 0;
   }
   sort(a + 1, a + m, cmp);
   long long t = m;
   for (register long long i = 1; i <= m; ++i) {
     if (a[i].second > m / 2 && s - a[i].first >= k) {
       s -= a[i].first;
       b[a[i].second] = true;
       t--;
     }
     if (s == k) break;
   }
   puts('Yes');
   write(t);
   putchar('
');
   for (register long long i = 1; i <= m; ++i)
     if (!b[i]) {
       write(i);
       putchar(' ');
     }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int te;
   cin >> te;
   while (te--) {
     int n, m, x, ji = 0, ou = 0;
     cin >> n >> m;
     for (int i = 0; i < n; ++i) {
       cin >> x;
       if (x & 1)
         ji++;
       else
         ou++;
     }
     if (ji == 0) {
       puts('No');
       continue;
     }
     ji--;
     m--;
     int q = min(m / 2 * 2, ji / 2 * 2);
     m -= q;
     ou -= m;
     if (ou < 0)
       puts('No');
     else
       puts('Yes');
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int s0, t0, t1, n, m, Next[500000 + 5];
 char s[500000 + 5], t[500000 + 5];
 void GetNext() {
   Next[0] = -1;
   int j = 0, k = -1;
   while (j < m) {
     if (!~k || t[j] == t[k])
       Next[++j] = ++k;
     else
       k = Next[k];
   }
 }
 int main() {
   scanf('%s%s', s, t);
   n = strlen(s), m = strlen(t);
   GetNext();
   for (int i = 0; s[i]; i++) s0 += s[i] == '0';
   for (int i = 0; t[i]; i++) t0 += t[i] == '0';
   for (int i = Next[m]; t[i]; i++) t1 += t[i] == '0';
   int A = t0, B = m - t0, l = m - Next[m], step = 0;
   while (A + t1 <= s0 && B + l - t1 <= n - s0) A += t1, B += l - t1, step++;
   if (t0 <= s0 && m - t0 <= n - s0) {
     printf('%s', t);
     for (int i = 0; i < step; i++) printf('%s', t + Next[m]);
     for (int i = s0 - A; i; i--) putchar('0');
     for (int i = n - s0 - B; i; i--) putchar('1');
     puts('');
   } else
     printf('%s
', s);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1000 * 100 + 10;
 vector<int> g[maxn];
 int a[maxn], b[maxn];
 bool p[maxn];
 int n, m;
 void input() {
   cin >> n >> m;
   for (int i = 0; i < m; i++) {
     int u, v;
     cin >> u >> v;
     u--, v--;
     g[u].push_back(v);
     g[v].push_back(u);
   }
   for (int i = 0; i < n; i++) cin >> a[i];
 }
 void bfs(int v) {
   queue<int> q;
   q.push(v);
   while (!q.empty()) {
     p[q.front()] = true;
     int u = q.front();
     b[u]++;
     for (int i = 0; i < g[u].size(); i++) {
       b[g[u][i]]++;
       if (b[g[u][i]] == a[g[u][i]]) q.push(g[u][i]);
     }
     q.pop();
   }
 }
 int main() {
   input();
   for (int i = 0; i < n; i++)
     if (b[i] == a[i]) bfs(i);
   int ans = 0;
   for (int i = 0; i < n; i++) ans += p[i];
   cout << ans << endl;
   ;
   for (int i = 0; i < n; i++)
     if (p[i]) cout << i + 1 << ' ';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long mod = 1000000007;
 int main() {
   string s;
   cin >> s;
   int k;
   cin >> k;
   unordered_set<string> st;
   for (int i = 0; i < k; i++) {
     string temp;
     cin >> temp;
     st.insert(temp);
     string temp2 = '';
     temp2 = temp2 + temp[1];
     temp2 = temp2 + temp[0];
     st.insert(temp2);
   }
   vector<pair<char, int> > arr;
   for (int i = 0; i < s.size(); i++) {
     int count = 1;
     int j = i + 1;
     while (j < s.size() && s[j] == s[i]) {
       count++;
       j++;
     }
     arr.push_back(make_pair(s[i], count));
     i = j - 1;
   }
   int ans = 0;
   for (int i = 0; i < arr.size() - 1; i++) {
     string temp = '';
     temp = temp + arr[i].first;
     temp = temp + arr[i + 1].first;
     if (st.find(temp) != st.end()) {
       int c1 = arr[i].second, c2 = arr[i + 1].second;
       int j = i + 2;
       while (j < s.size()) {
         if (arr[j].first == arr[i].first)
           c1 += arr[j].second;
         else if (arr[j].first == arr[i + 1].first)
           c2 += arr[j].second;
         else
           break;
         j++;
       }
       ans += min(c1, c2);
       i = j - 1;
     }
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, x, y;
 long long dp[10000005];
 int main(void) {
   scanf('%lld%lld%lld', &n, &x, &y);
   dp[1] = x;
   for (int i = 2; i <= n; ++i) {
     if (i & 1) {
       dp[i] = min(dp[i - 1] + x, dp[(i + 1) >> 1] + x + y);
     } else
       dp[i] = min(dp[i - 1] + x, dp[i >> 1] + y);
   }
   printf('%lld
', dp[n]);
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, nn, sum;
 vector<double> q;
 double x, ans, anss;
 int main() {
   scanf('%d', &n);
   sum = 0;
   for (int i = 1; i <= 2 * n; i++) {
     scanf('%lf', &x);
     ans += (x - floor(x));
     if (floor(x) == ceil(x)) sum++;
   }
   if (sum > n) n = n * 2 - sum;
   sum = min(sum, n);
   anss = 10000000;
   for (int i = n - sum; i <= n; i++) anss = min(anss, fabs(ans - i));
   printf('%.3lf', anss);
 }


#include <bits/stdc++.h>
 using namespace std;
 struct TnT {
   int k, f;
 } T[111];
 bool cmp(TnT a, TnT b) {
   if (a.f == b.f) return a.k < b.k;
   return a.f < b.f;
 }
 map<int, int> t;
 int main() {
   ios::sync_with_stdio(false);
   int n, m, ans = -1;
   cin >> n >> m;
   for (int i = 0; i < m; i++) cin >> T[i].k >> T[i].f;
   sort(T, T + m, cmp);
   for (int k = 1; k <= 100; k++) {
     int cnt = 1;
     for (int i = 1; i <= 110; i += k) {
       for (int j = i; j <= i + k - 1; j++) t[j] = cnt;
       cnt++;
     }
     int flag = 1;
     for (int i = 0; i < m; i++) {
       if (t[T[i].k] != T[i].f) flag = 0;
     }
     if (flag) {
       if (ans == -1)
         ans = t[n];
       else if (ans != t[n]) {
         cout << -1 << endl;
         return 0;
       }
     }
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool distinct(int n) {
   set<int> a;
   int i, c = 0;
   while (n > 0) {
     int d = n % 10;
     a.insert(d);
     n /= 10;
   }
   int l = a.size();
   for (int i = 0; i <= l - 1; i++) {
     c++;
   }
   if (c == 4) {
     return true;
   } else {
     return false;
   }
 }
 int main() {
   int y;
   cin >> y;
   for (int i = y; i <= 10000; i++) {
     if (i > y) {
       if (distinct(i)) {
         cout << i;
         break;
       }
     }
   }
   return 0;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 char A[2005][2005], B[2005][2005];
 int last_valid;
 pair<int, int> lb[26], ub[26];
 bool ans;
 void _clear(int n, int m) {
   for (int i = 0; i < 26; ++i) {
     lb[i] = make_pair(INT_MAX, INT_MAX);
     ub[i] = make_pair(INT_MIN, INT_MIN);
   }
   for (int i = 0; i < n; ++i) {
     for (int j = 0; j < m; ++j) {
       B[i][j] = '.';
     }
   }
   ans = true;
   last_valid = -1;
 }
 void _populate(int n, int m) {
   for (int i = 0; i < n; ++i) {
     for (int j = 0; j < m; ++j) {
       if (A[i][j] == '.') continue;
       char c = A[i][j] - 'a';
       lb[c].first = min(lb[c].first, i);
       lb[c].second = min(lb[c].second, j);
       ub[c].first = max(ub[c].first, i);
       ub[c].second = max(ub[c].second, j);
     }
   }
 }
 void _regenerate() {
   for (int i = 0; i < 26; ++i) {
     if (lb[i].first != INT_MAX) {
       last_valid = i;
       if (lb[i].first == ub[i].first) {
         int x = lb[i].first;
         for (int j = lb[i].second; j <= ub[i].second; ++j) B[x][j] = i + 'a';
       } else if (lb[i].second == ub[i].second) {
         int x = lb[i].second;
         for (int j = lb[i].first; j <= ub[i].first; ++j) B[j][x] = i + 'a';
       } else
         ans = false;
     }
   }
 }
 void _compare(int n, int m) {
   for (int i = 0; i < n; ++i) {
     for (int j = 0; j < m; ++j) {
       if (A[i][j] != B[i][j]) ans = false;
     }
   }
 }
 void _print() {
   if (!ans) {
     cout << 'NO' << endl;
     return;
   }
   cout << 'YES' << endl;
   cout << last_valid + 1 << endl;
   for (int i = 0; i <= last_valid; ++i) {
     if (lb[i].first != INT_MAX) {
       cout << lb[i].first + 1 << ' ' << lb[i].second + 1 << ' '
            << ub[i].first + 1 << ' ' << ub[i].second + 1 << endl;
     } else {
       int x = last_valid;
       cout << lb[x].first + 1 << ' ' << lb[x].second + 1 << ' '
            << ub[x].first + 1 << ' ' << ub[x].second + 1 << endl;
     }
   }
 }
 void _debug(int n, int m) {
   for (int i = 0; i < n; ++i) {
     for (int j = 0; j < m; ++j) cout << A[i][j] << ' ';
     cout << endl;
   }
   cout << endl;
   for (int i = 0; i < n; ++i) {
     for (int j = 0; j < m; ++j) cout << B[i][j] << ' ';
     cout << endl;
   }
   cout << endl;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cout.tie(0);
   cin.tie(0);
   int t, n, m, i, j, k, x, y, z, a, b, c;
   cin >> t;
   while (t--) {
     cin >> n >> m;
     for (i = 0; i < n; ++i) cin >> A[i];
     _clear(n, m);
     _populate(n, m);
     _regenerate();
     _compare(n, m);
     _print();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 string s;
 long long dp[200011];
 const long long Mod = 1e9 + 7;
 long long f[200011][3];
 long long power(long long x, long long n) {
   if (n < 0) return 0;
   if (n == 0) return 1;
   if (n % 2 == 0) return power(x * x % Mod, n / 2);
   return x * power(x * x % Mod, n / 2) % Mod;
 }
 int main() {
   cin >> n;
   cin >> s;
   s = '.' + s;
   int c = 0;
   for (int i = n; i >= 1; i--) {
     if (s[i] == '?') c++;
   }
   long long cnt1 = 0;
   long long cnt2 = 0;
   for (int i = 1; i <= n; i++) {
     if (s[i] == 'b') {
       f[i][0] += cnt1;
       f[i][1] += cnt2;
     }
     if (s[i] == '?') {
       f[i][1] += cnt1;
       f[i][2] += cnt2;
     }
     if (s[i] == 'a') {
       cnt1++;
     }
     if (s[i] == '?') cnt2++;
   }
   for (int i = 1; i <= n; i++) {
     for (int j = 0; j <= 2; j++) (f[i][j] += f[i - 1][j]) %= Mod;
   }
   long long ans = 0;
   for (int i = 1; i <= n; i++) {
     if (s[i] == 'c') {
       ans += f[i - 1][0] * power(3, c);
       ans %= Mod;
       ans += f[i - 1][1] * power(3, c - 1);
       ans %= Mod;
       ans += f[i - 1][2] * power(3, c - 2);
       ans %= Mod;
     }
     if (s[i] == '?') {
       ans += f[i - 1][0] * power(3, c - 1);
       ans %= Mod;
       ans += f[i - 1][1] * power(3, c - 2);
       ans %= Mod;
       ans += f[i - 1][2] * power(3, c - 3);
       ans %= Mod;
     }
   }
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, x[1042], y[1042];
 double eps = 0.00000001;
 int dist2(int x1, int y1, int x2, int y2) {
   return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
 }
 double dist(double x1, double y1, double x2, double y2) {
   return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
 }
 int cross(int a, int b, int c) {
   return (x[a] - x[b]) * (y[c] - y[b]) - (x[c] - x[b]) * (y[a] - y[b]);
 }
 bool acute(int a, int b, int c) {
   if (cross(a, b, c) == 0) {
     return 0;
   }
   int dAB = dist2(x[a], y[a], x[b], y[b]);
   int dBC = dist2(x[b], y[b], x[c], y[c]);
   int dAC = dist2(x[a], y[a], x[c], y[c]);
   if (dAB >= dBC + dAC) {
     return 0;
   }
   if (dAC >= dBC + dAB) {
     return 0;
   }
   if (dBC >= dAC + dAB) {
     return 0;
   }
   return 1;
 }
 bool r(int a, int b, int c) {
   int dAB = dist2(x[a], y[a], x[b], y[b]);
   int dBC = dist2(x[b], y[b], x[c], y[c]);
   int dAC = dist2(x[a], y[a], x[c], y[c]);
   if (dAB == dBC + dAC) {
     return 1;
   }
   if (dAC == dBC + dAB) {
     return 1;
   }
   if (dBC == dAC + dAB) {
     return 1;
   }
   return 0;
 }
 bool covered(double cx, double cy, double t) {
   for (int i = 0; i < n; i++) {
     if (dist(cx, cy, x[i], y[i]) < t) {
       return 1;
     }
   }
   return 0;
 }
 pair<double, double> getCirC(int a, int b, int c) {
   int dx1 = x[a] - x[b], dx2 = x[b] - x[c], dx3 = x[c] - x[a];
   int dy1 = y[a] - y[b], dy2 = y[b] - y[c], dy3 = y[c] - y[a];
   double xc1 = (x[a] + x[b]) / 2., xc2 = (x[b] + x[c]) / 2.,
          xc3 = (x[c] + x[a]) / 2.;
   double yc1 = (y[a] + y[b]) / 2., yc2 = (y[b] + y[c]) / 2.,
          yc3 = (y[c] + y[a]) / 2.;
   if (dy1 == 0) {
     swap(dx1, dx3);
     swap(dy1, dy3);
     swap(xc1, xc3);
     swap(yc1, yc3);
   }
   if (dy2 == 0) {
     swap(dx2, dx3);
     swap(dy2, dy3);
     swap(xc2, xc3);
     swap(yc2, yc3);
   }
   double n1 = -1. * dx1 / (double)dy1, n2 = -1. * dx2 / (double)dy2;
   double x = (yc2 - yc1 + n1 * xc1 - n2 * xc2) / (n1 - n2);
   double y = n1 * (x - xc1) + yc1;
   return make_pair(x, y);
 }
 int main() {
   cin >> n;
   for (int i = 0; i < n; i++) {
     cin >> x[i] >> y[i];
   }
   double ans = -1;
   for (int i = 0; i < n; i++) {
     for (int j = i + 1; j < n; j++) {
       for (int k = j + 1; k < n; k++) {
         if (acute(i, j, k)) {
           pair<double, double> crr = getCirC(i, j, k);
           double px = crr.first, py = crr.second;
           double d = dist(px, py, x[i], y[i]);
           if (!covered(px, py, d - eps)) {
             ans = max(ans, d);
           }
         }
       }
     }
   }
   for (int i = 0; i < n; i++) {
     for (int j = i + 1; j < n; j++) {
       vector<int> ids;
       ids.clear();
       for (int k = 0; k < n; k++) {
         if (k == i || k == j) {
           continue;
         }
         if (dist2(x[i], y[i], x[k], y[k]) != dist2(x[j], y[j], x[k], y[k])) {
           continue;
         }
         if (!r(i, j, k)) {
           continue;
         }
         ids.push_back(k);
       }
       if (ids.size() < 2) {
         continue;
       }
       int k = ids[0];
       int cc = ids[1];
       double px = (x[i] + x[j] + x[k] + x[cc]) / 4.;
       double py = (y[i] + y[j] + y[k] + y[cc]) / 4.;
       double d = dist(x[i], y[i], px, py);
       if (!covered(px, py, d - eps)) {
         ans = max(ans, d);
       }
     }
   }
   cout << ans << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> vec[100010];
 long long a[100010];
 long long s;
 int n;
 long long dfs(int f, int u, long long val) {
   int sz = vec[u].size(), v;
   long long ret = 0, mv = ((long long)1e18), tmp;
   if (sz == 1 && vec[u][0] == f)
     return (a[u] = ((val) < (a[u]) ? (val) : (a[u])));
   if (u != 1)
     val = val / (sz - 1) * (sz - 1) / (sz - 1);
   else
     val = val / sz * sz / sz;
   for (int i = 0; i < sz; i++) {
     v = vec[u][i];
     if (v == f) continue;
     tmp = dfs(u, v, val);
     mv = ((mv) < (tmp) ? (mv) : (tmp));
   }
   while (true) {
     tmp = mv;
     for (int i = 0; i < sz; i++) {
       v = vec[u][i];
       if (v == f) continue;
       if (a[v] > tmp) tmp = ((dfs(u, v, mv)) < (tmp) ? (dfs(u, v, mv)) : (tmp));
     }
     if (tmp == mv)
       break;
     else
       mv = tmp;
   }
   for (int i = 0; i < sz; i++)
     if (vec[u][i] != f) ret += a[vec[u][i]];
   return a[u] = ret;
 }
 int main() {
   scanf('%d', &n);
   for (int i = 1; i <= n; i++) scanf('%I64d', a + i), s += a[i];
   for (int i = 1; i < n; i++) {
     int u, v;
     scanf('%d%d', &u, &v);
     vec[u].push_back(v);
     vec[v].push_back(u);
   }
   long long ret = dfs(0, 1, ((long long)1e18));
   cout << s - ret << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int dx[] = {0, 0, 1, -1};
 int dy[] = {1, -1, 0, 0};
 template <class T>
 inline void smin(T &a, T b) {
   if (a > b) a = b;
 }
 template <class T>
 inline void smax(T &a, T b) {
   if (a < b) a = b;
 }
 int qf, qb, q[11111111];
 long long res[555], a[555][555], dst[555][555];
 int r[555], first[555];
 int main() {
   int N, ii, i, j, nn, u, st;
   scanf('%d', &N);
   for (i = 0; i < N; i++)
     for (j = 0; j < N; j++) scanf('%I64d', &dst[i][j]);
   for (i = 0; i < N; i++) {
     scanf('%d', r + i);
     r[i]--;
   }
   nn = 0;
   for (ii = N - 1; ii >= 0; ii--) {
     st = r[ii];
     for (i = 0; i < nn; i++) {
       for (j = 0; j < nn; j++) {
         smin(dst[st][first[j]], dst[st][first[i]] + dst[first[i]][first[j]]);
         smin(dst[first[j]][st], dst[first[j]][first[i]] + dst[first[i]][st]);
       }
     }
     for (i = 0; i < nn; i++)
       for (j = 0; j < nn; j++)
         smin(dst[first[i]][first[j]], dst[first[i]][st] + dst[st][first[j]]);
     first[nn++] = st;
     res[ii] = 0;
     for (i = 0; i < nn; i++)
       for (j = 0; j < nn; j++) res[ii] += dst[first[i]][first[j]];
   }
   for (i = 0; i < N; i++) {
     if (i) printf(' ');
     printf('%I64d', res[i]);
   }
   puts('');
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 400005;
 int n, q, K, m, i, j, k, h[N], t[N], num, fa[N], s[N], id[N], size[N], son[N],
     tp[N], dep[N], head[N], adj[N * 2], nxt[N * 2], p[N], cnt, stk[N], top,
     g[N], Head[N], Adj[N * 2], Nxt[N * 2], l, f[N];
 void dfs(int x, int dad) {
   size[x] = 1;
   for (int y = head[x]; y; y = nxt[y])
     if (adj[y] != dad) {
       dep[adj[y]] = dep[x] + 1;
       fa[adj[y]] = x;
       dfs(adj[y], x);
       size[x] += size[adj[y]];
       if (!son[x] || size[adj[y]] > size[son[x]]) son[x] = adj[y];
     }
 }
 void Dfs(int x, int dad) {
   id[x] = ++i;
   if (son[x]) {
     tp[son[x]] = tp[x];
     Dfs(son[x], x);
   }
   for (int y = head[x]; y; y = nxt[y])
     if (adj[y] != dad && adj[y] != son[x]) {
       tp[adj[y]] = adj[y];
       Dfs(adj[y], x);
     }
 }
 int lca(int a, int b) {
   while (tp[a] != tp[b]) {
     if (dep[tp[a]] < dep[tp[b]]) swap(a, b);
     a = fa[tp[a]];
   }
   return dep[a] < dep[b] ? a : b;
 }
 int dis(int a, int b) { return dep[a] + dep[b] - 2 * dep[lca(a, b)]; }
 bool cmp(int a, int b) { return id[a] < id[b]; }
 void addedge(int u, int v) {
   Adj[++l] = v;
   Nxt[l] = Head[u];
   Head[u] = l;
   Adj[++l] = u;
   Nxt[l] = Head[v];
   Head[v] = l;
 }
 void dzx(int x, int dad) {
   if (s[x])
     f[x] = x;
   else
     f[x] = 0;
   for (int y = Head[x], a, b; y; y = Nxt[y])
     if (Adj[y] != dad) {
       dzx(Adj[y], x);
       if (f[Adj[y]] && (!f[x] ||
                         1ll * (a = dis(f[Adj[y]], x) - 1) / s[f[Adj[y]]] <
                             1ll * (b = dis(f[x], x) - 1) / s[f[x]] ||
                         1ll * (a = dis(f[Adj[y]], x) - 1) / s[f[Adj[y]]] ==
                                 1ll * (b = dis(f[x], x) - 1) / s[f[x]] &&
                             h[f[Adj[y]]] < h[f[x]]))
         f[x] = f[Adj[y]];
     }
   if (s[x]) f[x] = x;
 }
 void phh(int x, int dad, int u) {
   int a, b;
   if (u) {
     if (u && (!f[x] ||
               1ll * (a = dis(u, x) - 1) / s[u] <
                   1ll * (b = dis(f[x], x) - 1) / s[f[x]] ||
               1ll * (a = dis(u, x) - 1) / s[u] ==
                       1ll * (b = dis(f[x], x) - 1) / s[f[x]] &&
                   h[u] < h[f[x]]))
       f[x] = u;
   }
   if (s[x]) f[x] = x;
   for (int y = Head[x]; y; y = Nxt[y])
     if (Adj[y] != dad) phh(Adj[y], x, f[x]);
   Head[x] = 0;
 }
 int main() {
   scanf('%d', &n);
   for (i = 1; i < n; ++i) {
     scanf('%d%d', &j, &k);
     adj[i * 2 - 1] = k;
     nxt[i * 2 - 1] = head[j];
     head[j] = i * 2 - 1;
     adj[i * 2] = j;
     nxt[i * 2] = head[k];
     head[k] = i * 2;
   }
   dfs(1, -1);
   tp[1] = 1;
   i = 0;
   Dfs(1, -1);
   scanf('%d', &q);
   while (q--) {
     if (n == 10) {
       for (i = 1; i <= n; ++i) Head[i] = h[i] = s[i] = g[i] = t[i] = p[i] = 0;
     }
     scanf('%d%d', &K, &m);
     num = 0;
     for (i = 1; i <= K; ++i) {
       scanf('%d%d', &j, &k);
       s[j] = k;
       h[j] = i;
       t[++num] = j;
     }
     for (i = 1; i <= m; ++i) {
       scanf('%d', &j);
       g[i] = t[++num] = j;
     }
     t[++num] = 1;
     sort(t + 1, t + 1 + num, cmp);
     cnt = 0;
     for (i = 1; i <= num; i = j) {
       for (j = i; j <= num && t[i] == t[j]; ++j)
         ;
       p[++cnt] = t[i];
     }
     if (cnt == 1) {
       puts('1');
       continue;
     }
     l = 0;
     stk[1] = p[1], stk[2] = p[2];
     top = 2;
     for (i = 3; i <= cnt; ++i) {
       while (top > 1 && dep[lca(stk[top], p[i])] <= dep[stk[top - 1]]) {
         addedge(stk[top - 1], stk[top]);
         --top;
       }
       if ((j = lca(p[i], stk[top])) == stk[top])
         stk[++top] = p[i];
       else {
         addedge(j, stk[top]);
         stk[top] = j;
         stk[++top] = p[i];
       }
     }
     while (top > 1) {
       addedge(stk[top - 1], stk[top]);
       --top;
     }
     dzx(1, -1);
     phh(1, -1, 0);
     for (i = 1; i <= m; ++i) printf('%d ', h[f[g[i]]]);
     puts('');
     for (i = 1; i <= cnt; ++i) s[p[i]] = 0;
   }
   return 0;
 }


#include<bits/stdc++.h>
 #define pairs pair<int,int>
 #define loop(i,a,n) for(int i=a;i<n;i++)
 #define m_p make_pair
 #define fi first
 #define se second
 #define pb push_back
 #define ll long long
 #define all(v) v.begin(),v.end()
 using namespace std;
 //vector<ll> siz;
 /*ll indes(ll i,ll right){
     ll val=siz[i];
     ll left=0;
     ll ans=-1;
     while(left<=right){
         ll mid=(left+right)/2;
         if(2*siz[mid]<=val){
             ans=mid;
             left=mid+1;
         }
         else
         {
             right=mid-1;
         }

     }
     return ans;
 }*/
 map<pairs,bool> mp;

 void solve(){
 ll n,k;
 cin>>n>>k;
 vector<ll> vec(n);
 vector<pairs> range(n);
 loop(i,0,n){
     cin>>vec[i];
 }
 range[0].fi=vec[0];
 range[0].se=vec[0];
 range[n-1].fi=vec[n-1];
 range[n-1].se=vec[n-1];
 for(ll i=1;i<n-1;i++){
   ll a=range[i-1].fi;
   ll b=range[i-1].se;
   ll c= b+k-1;
   ll d=a-(k-1);
   range[i].fi=max(d,vec[i]);
   range[i].se=min(c,vec[i]+(k-1));
 }

 loop(i,1,n){
   ll a=range[i-1].fi;
   ll b=range[i-1].se;
   ll c=range[i].fi;
   ll d=range[i].se;

   if(a-k>=d||b+k<=c){
       cout<<'NO';
       return;
   }

 }
 cout<<'YES';
 return;
 }
 int main(){
     int test=1;
     cin>>test;
     while(test--){
         solve();
         cout<<endl;
     }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int Mod = 1e9 + 7;
 int main() {
   long long N, M, ans = 0, Last = 0;
   scanf('%I64d%I64d', &N, &M);
   long long Min = min(N, M);
   for (long long i = 1, j; i <= Min; i = j + 1) {
     j = min(N / (N / i), M);
     long long tmp;
     if (j & 1LL)
       tmp = ((j + 1) / 2 % Mod) * (j % Mod) % Mod;
     else
       tmp = (j / 2 % Mod) * ((j + 1) % Mod) % Mod;
     ans =
         (ans + (N / i) % Mod * (((tmp - Last) % Mod + Mod) % Mod) % Mod) % Mod;
     Last = tmp;
   }
   ans = (((N % Mod) * (M % Mod) - ans) % Mod + Mod) % Mod;
   printf('%I64d', ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2E5 + 10, mod = 1E9 + 7, M = 1E6 + 10, lim = 1E6;
 int n, m, a[N], s[N], ans[N];
 struct node {
   int l, r, num;
 } p[N];
 vector<int> f[M];
 int pos[M];
 inline int cmp(node x, node y) { return x.r < y.r; }
 struct sgtree {
   int l, r, sum;
 } t[N << 2];
 inline int ksm(int x, int y) {
   return y == 1
              ? x
              : 1ll * ksm(1ll * x * x % mod, y >> 1) * ((y & 1) ? x : 1) % mod;
 }
 inline void pl(int l = 1, int r = n, int x = 1) {
   t[x] = (sgtree){l, r, 1};
   if (l == r) return;
   int mid = l + r >> 1;
   pl(l, mid, x << 1);
   pl(mid + 1, r, x << 1 | 1);
 }
 inline void modify(int l, int r, int v, int x = 1) {
   if (l == t[x].l && r == t[x].r) {
     t[x].sum = 1ll * t[x].sum * v % mod;
     return;
   }
   int mid = t[x].l + t[x].r >> 1;
   if (r <= mid)
     modify(l, r, v, x << 1);
   else if (l > mid)
     modify(l, r, v, x << 1 | 1);
   else
     modify(l, mid, v, x << 1), modify(mid + 1, r, v, x << 1 | 1);
 }
 inline void insert(int v, int x) {
   for (int i = 0; i < f[v].size(); i++) {
     modify(pos[f[v][i]] + 1, x,
            1ll * ksm(f[v][i], mod - 2) * (f[v][i] - 1) % mod);
     pos[f[v][i]] = x;
   }
 }
 inline int query(int l, int x = 1) {
   if (t[x].l == t[x].r) return t[x].sum;
   int mid = t[x].l + t[x].r >> 1;
   return 1ll * t[x].sum * (l <= mid ? query(l, x << 1) : query(l, x << 1 | 1)) %
          mod;
 }
 inline int sol(int l, int r) {
   return 1ll * s[r] * ksm(s[l - 1], mod - 2) % mod * query(l) % mod;
 }
 int main() {
   scanf('%d', &n);
   s[0] = 1;
   for (int i = 1; i <= n; i++) {
     scanf('%d', &a[i]);
     s[i] = 1ll * s[i - 1] * a[i] % mod;
   }
   scanf('%d', &m);
   pl();
   for (int i = 1; i <= m; i++) {
     scanf('%d%d', &p[i].l, &p[i].r);
     p[i].num = i;
   }
   sort(p + 1, p + 1 + m, cmp);
   int now = 1;
   for (int i = 2; i <= lim; i++)
     if (!f[i].size())
       for (int j = 1; i * j <= lim; j++) f[i * j].push_back(i);
   for (int i = 1; i <= n; i++) {
     insert(a[i], i);
     while (now <= m && p[now].r == i) {
       ans[p[now].num] = sol(p[now].l, p[now].r);
       now++;
     }
   }
   for (int i = 1; i <= m; i++) printf('%d
', ans[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long fact[1000010];
 long long m = 1e9 + 7;
 long long me(long long a, long long b, long long m) {
   long long ans = 1;
   while (b > 0) {
     if (b % 2 == 1) {
       ans = (ans % m * a % m) % m;
     }
     a = (a * a) % m;
     b /= 2;
   }
   return ans % m;
 }
 bool check(long long x, long long a, long long b) {
   while (x > 0) {
     int dg = x % 10;
     if (dg != a && dg != b) return false;
     x /= 10;
   }
   return true;
 }
 long long ncr(long long n, long long r) {
   long long fn = fact[n];
   long long tf = fact[r] * fact[n - r];
   tf = tf % m;
   tf = me(tf, m - 2, m);
   fn = (tf % m * fn % m) % m;
   return fn % m;
 }
 int main() {
   fact[0] = 1;
   for (long long i = 1; i <= 1000001; i++) {
     fact[i] = (fact[i - 1] * i) % m;
   }
   int n, a, b;
   cin >> a >> b >> n;
   if (a == b) {
     if (check(n * a, a, b)) {
       cout << '1
';
     } else
       cout << '0
';
     return 0;
   }
   long long ans = 0;
   for (long long i = 0; i <= n; i++) {
     long long tmp = i * a + (n - i) * b;
     if (check(tmp, a, b)) {
       ans += ncr(n, i);
       ans %= m;
     }
   }
   cout << ans << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   while (cin >> n) {
     string s;
     cin >> s;
     string res = '';
     for (int i = 0; i < n; i++) {
       if (s[i] <= '1')
         continue;
       else {
         if (s[i] == '4')
           res += '3', res += '2', res += '2';
         else {
           if (s[i] == '6')
             res += '5', res += '3';
           else {
             if (s[i] == '8')
               res += '7', res += '2', res += '2', res += '2';
             else {
               if (s[i] == '9')
                 res += '3', res += '3', res += '2', res += '7';
               else
                 res += s[i];
             }
           }
         }
       }
     }
     sort(res.begin(), res.end());
     reverse(res.begin(), res.end());
     cout << res << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long int t;
   cin >> t;
   while (t--) {
     long long int i, j, n, ans = 0, k1, k2;
     cin >> n;
     long long int arr[n];
     vector<vector<long long int> > vec(26);
     for (i = 0; i < n; i++) {
       cin >> arr[i];
       vec[arr[i] - 1].push_back(i);
     }
     long long int dp1[n][26], dp2[n][26];
     for (i = 0; i < n; i++)
       for (j = 0; j < 26; j++) {
         dp1[i][j] = 0;
         dp2[i][j] = 0;
       }
     dp1[0][arr[0] - 1]++;
     for (i = 1; i < n; i++) {
       for (j = 0; j < 26; j++)
         if (arr[i] == j + 1)
           dp1[i][j] += dp1[i - 1][j] + 1;
         else
           dp1[i][j] += dp1[i - 1][j];
     }
     dp2[n - 1][arr[n - 1] - 1]++;
     for (i = n - 2; i >= 0; i--) {
       for (j = 0; j < 26; j++)
         if (arr[i] == j + 1)
           dp2[i][j] += dp2[i + 1][j] + 1;
         else
           dp2[i][j] += dp2[i + 1][j];
     }
     for (i = 0; i < 26; i++) {
       long long int dd = vec[i].size();
       ans = max(ans, dd);
     }
     for (i = 0; i < 26; i++) {
       for (k1 = 0; k1 < vec[i].size(); k1++) {
         for (k2 = k1; k2 < vec[i].size(); k2++) {
           long long int d1 = vec[i][k1], d2 = vec[i][k2];
           for (j = 0; j < 26; j++)
             if (i != j)
               ans = max(ans, k2 - k1 + 1 + 2 * min(dp1[d1][j], dp2[d2][j]));
         }
       }
     }
     cout << ans << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX = 500005;
 long long a[MAX], pre[MAX], suf[MAX], t;
 int main() {
   int ans = -1, pos = 0, n;
   scanf('%d', &n);
   for (register int i = 1; i <= n; i++) {
     scanf('%lld', &a[i]);
     pre[i] = pre[i - 1] | a[i];
   }
   for (register int i = n; i >= 1; i--) suf[i] = suf[i + 1] | a[i];
   for (register int i = 1; i <= n; i++) {
     t = pre[i - 1] | suf[i + 1];
     if ((a[i] | t) - t > ans) {
       ans = (a[i] | t) - t;
       pos = i;
     }
   }
   printf('%lld ', a[pos]);
   for (register int i = 1; i <= n; i++)
     if (i != pos) printf('%lld ', a[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 priority_queue<pair<int, string> > all[10010];
 int main() {
   int n, m;
   cin >> n >> m;
   string name;
   int reg, sc;
   for (int i = 0; i < n; i++) {
     cin >> name >> reg >> sc;
     all[reg].push(make_pair(sc, name));
   }
   for (int i = 1; i <= m; i++) {
     int tt[4];
     int tool = 0;
     pair<int, string> p[4];
     while (all[i].size()) {
       p[tool] = all[i].top();
       all[i].pop();
       tt[tool++] = p[tool].first;
       if (tool == 3) break;
     }
     if (tool == 2) {
       cout << p[0].second << ' ' << p[1].second << endl;
     } else {
       if (p[0].first == p[2].first || p[1].first == p[2].first) {
         cout << '?' << endl;
       } else {
         cout << p[0].second << ' ' << p[1].second << endl;
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n = 1009;
 int LG2(int N) {
   int ans = 0;
   while (N) {
     N >>= 1;
     ans++;
   }
   return ans - 1;
 }
 int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int n;
   cin >> n;
   map<string, int> M;
   int o = 1;
   vector<long long> v(n);
   vector<string> vv(n);
   int ans = 0;
   for (int i = 0; i < (n); i++) {
     string s;
     cin >> s;
     ans += s.length();
     vv[i] = s;
     if (M[s]) {
       v[i] = M[s];
     } else {
       M[s] = o;
       v[i] = o;
       o++;
     }
   }
   ans += n - 1;
   int L = ans;
   for (int f = 0; f < n; f++) {
     int len = 0;
     vector<long long> p;
     for (int l = f; l < n; l++) {
       len += vv[l].length();
       if (l > f) len++;
       p.push_back(v[l]);
       int pL = l - f + 1;
       int cntP = 0;
       for (int i = l + 1; i < n; i++) {
         int o = i + pL - 1;
         if (o > n) continue;
         int c = 0;
         bool b = 1;
         for (int j = i; j <= o; j++) {
           if (v[j] == p[c]) {
           } else {
             b = 0;
             break;
           }
           c++;
         }
         if (b) {
           cntP++;
           i = o;
         }
       }
       if (!cntP) continue;
       int rB = (len - pL) * (cntP + 1);
       ans = min(ans, L - rB);
     }
   }
   cout << ans;
   return 0;
 }


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

 int get(int i){
     cout << '? ' << i+1 << endl;
     cout.flush();
     int a; cin >> a;
     int b;
     if(i == 0) b = INF;
     else{
         cout << '? ' << i << endl;
         cout.flush();
         cin >> b;
     }
     return b-a;
 }

 int main(){
     // freopen('input.txt', 'r', stdin);
     // freopen('output.txt', 'w', stdout);
     ios_base::sync_with_stdio(false);
     cin.tie(0);
     int n; cin >> n;
     if(n == 1){
         cout << '! ' << 1 << endl;
         cout.flush();
         return 0;
     }
     if(get(1) < 0){
         cout << '! ' << 1 << endl;
         cout.flush();
         return 0;
     }
     if(get(n-1) > 0){
         cout << '! ' << n << endl;
         cout.flush();
         return 0;
     }
     int lo = 0, hi = n-1;
     while(lo < hi){
         int mid = lo+(hi-lo)/2;
         if(get(mid) > 0) lo = mid+1;
         else hi = mid;
     }
     cout << '! ' << lo << endl;
     cout.flush();
 }


#include <bits/stdc++.h>
 using namespace std;
 int N, M;
 int timew, cnt;
 stack<int> si;
 int low[2000005], dep[2000005], siz[2000005], dfn[2000005], nex[2000005],
     las[2000005], Arrive[2000005], st[2000005], cnt1;
 bool isin[2000005];
 void jt(int xx, int yy) {
   cnt++;
   nex[cnt] = las[xx];
   las[xx] = cnt;
   Arrive[cnt] = yy;
 }
 void tarjan(int noww) {
   timew++;
   low[noww] = dfn[noww] = timew;
   si.push(noww);
   isin[noww] = true;
   for (int i = las[noww]; i; i = nex[i]) {
     if (!dfn[Arrive[i]]) {
       tarjan(Arrive[i]);
       low[noww] = min(low[noww], low[Arrive[i]]);
     } else if (isin[Arrive[i]])
       low[noww] = min(low[noww], dfn[Arrive[i]]);
   }
   if (low[noww] == dfn[noww]) {
     cnt1++;
     int k = -1;
     while (k != noww) {
       k = si.top();
       si.pop();
       isin[k] = false;
       st[k] = cnt1;
       siz[cnt1]++;
     }
   }
 }
 void Clear() {
   cnt = 0;
   cnt1 = 0;
   timew = 0;
   for (int i = 1; i <= N; i++)
     las[i] = dep[i] = st[i] = siz[i] = dfn[i] = low[i] = dep[i] = 0;
 }
 int main() {
   int T;
   scanf('%d', &T);
   while (T--) {
     scanf('%d%d', &N, &M);
     Clear();
     for (int i = 1; i <= M; i++) {
       int u, v;
       scanf('%d%d', &u, &v);
       if (u != v) jt(u, v);
     }
     for (int i = 1; i <= N; i++)
       if (!dfn[i]) tarjan(i);
     if (siz[st[1]] == N) {
       puts('No');
       continue;
     }
     for (int i = 1; i <= N; i++)
       for (int j = las[i]; j; j = nex[j])
         if (st[i] != st[Arrive[j]]) dep[st[i]]++;
     bool flag = false;
     for (int i = 1; i <= cnt1; i++) {
       if (!dep[i] && siz[i]) {
         flag = true;
         puts('Yes');
         vector<int> ans[2];
         for (int j = 1; j <= N; j++) ans[st[j] == i].push_back(j);
         printf('%d %d
', ans[1].size(), ans[0].size());
         for (auto &i : ans[1]) printf('%d ', i);
         cout << '
';
         for (auto &i : ans[0]) printf('%d ', i);
         cout << '
';
         break;
       }
     }
     if (!flag) puts('No');
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e6;
 const int inf = 1e9 + 100;
 int a[N + 100], b[N + 100];
 vector<pair<int, int> > mon[N + 100];
 int tree[N * 4 + 100], lazy[N * 4 + 100];
 void build(int v, int tl, int tr) {
   if (tl == tr) {
     tree[v] = -b[tl + 1];
     return;
   }
   int tm = (tl + tr) / 2;
   build(v * 2, tl, tm);
   build(v * 2 + 1, tm + 1, tr);
   tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
 }
 void push(int v) {
   tree[v * 2] += lazy[v];
   tree[v * 2 + 1] += lazy[v];
   lazy[v * 2] += lazy[v];
   lazy[v * 2 + 1] += lazy[v];
   lazy[v] = 0;
 }
 void update(int v, int tl, int tr, int l, int r, int addend) {
   if (l > r) {
     return;
   }
   if (tl == l && tr == r) {
     tree[v] += addend;
     lazy[v] += addend;
     return;
   }
   push(v);
   int tm = (tl + tr) / 2;
   update(v * 2, tl, tm, l, min(r, tm), addend);
   update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, addend);
   tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
 }
 int query(int v, int tl, int tr, int l, int r) {
   if (l > r) {
     return -inf;
   }
   if (tl == l && tr == r) {
     return tree[v];
   }
   push(v);
   int tm = (tl + tr) / 2;
   return max(query(v * 2, tl, tm, l, min(r, tm)),
              query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
 }
 int main() {
   for (int i = 1; i <= N + 1; i++) {
     a[i] = b[i] = inf;
   }
   int n, m, p;
   scanf('%d%d%d', &n, &m, &p);
   for (int i = 1; i <= n; i++) {
     int cur, cost;
     scanf('%d%d', &cur, &cost);
     a[cur] = min(cost, a[cur]);
   }
   int mx = 0;
   for (int i = 1; i <= m; i++) {
     int cur, cost;
     scanf('%d%d', &cur, &cost);
     b[cur] = min(cost, b[cur]);
     mx = max(mx, cur);
   }
   for (int i = 1; i <= p; i++) {
     int x, y, z;
     scanf('%d%d%d', &x, &y, &z);
     mon[x].push_back(make_pair(y, z));
   }
   for (int i = 1; i <= N; i++) {
     sort(mon[i].begin(), mon[i].end());
   }
   for (int i = N; i > 0; i--) {
     a[i] = min(a[i], a[i + 1]);
     b[i] = min(b[i], b[i + 1]);
   }
   build(1, 1, N);
   int ans = -a[1] - b[1];
   int total = 0;
   for (int i = 1; i <= N; i++) {
     if (a[i + 1] == inf) {
       break;
     }
     for (auto it : mon[i]) {
       update(1, 1, N, it.first, N, it.second);
       ans = max(ans, query(1, 1, N, 1, mx - 1) - a[i + 1]);
     }
   }
   printf('%d
', ans);
 }


#include <bits/stdc++.h>
 using namespace std;
 char s[500][500];
 int di[4] = {-1, 1, 0, 0};
 int dj[4] = {0, 0, -1, 1};
 typedef int int2d[500][500];
 int2d p[26];
 int2d d;
 struct Pos {
   int r, c;
   Pos(int r = 0, int c = 0) : r(r), c(c) {}
   void init(int r, int c) {
     this->r = r;
     this->c = c;
   }
   bool operator<(const Pos& p) const {
     int d1 = d[r][c], d2 = d[p.r][p.c];
     return d1 < d2 || d1 == d2 && (r < p.r || r == p.r && c < p.c);
   }
 } wh[27];
 int n, m;
 bool isDigit(char c) { return c >= '0' && c <= '9'; }
 set<Pos> heap;
 void calc(int i, int j, int2d& par) {
   memset(d, 127, sizeof(d));
   d[i][j] = 0;
   heap.insert(Pos(i, j));
   while (!heap.empty()) {
     Pos p = *heap.begin();
     heap.erase(heap.begin());
     char ch = s[p.r][p.c];
     if (!isDigit(ch) && ch != s[i][j]) {
       continue;
     }
     int cost = (isDigit(ch) ? ch - '0' : 1) + d[p.r][p.c];
     for (int dir = 0; dir < 4; dir++) {
       int r = p.r + di[dir], c = p.c + dj[dir];
       if (r >= 0 && c >= 0 && r < n && c < m && s[r][c] != '#') {
         if (d[r][c] > cost) {
           heap.erase(Pos(r, c));
           d[r][c] = cost;
           heap.insert(Pos(r, c));
           par[r][c] = dir;
         }
       }
     }
   }
 }
 char sm[10000];
 int main() {
   int k;
   cin >> 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] >= 'a' && s[i][j] <= 'z') {
         wh[s[i][j] - 'a'].init(i, j);
         calc(i, j, p[s[i][j] - 'a']);
       }
     }
   }
   int r, c;
   int r2, c2;
   scanf('%d %d %s %d %d', &r, &c, sm, &r2, &c2);
   r--, c--;
   r2--, c2--;
   calc(r2, c2, p[26]);
   int len = strlen(sm);
   for (int i = 0; i < len && k;) {
     char ch = s[r][c];
     if (ch == sm[i]) {
       i++;
       continue;
     }
     int cost = (isDigit(ch) ? ch - '0' : 1);
     int dir = p[sm[i] - 'a'][r][c];
     if (cost > k) {
       k = 0;
       break;
     }
     k -= cost;
     r -= di[dir];
     c -= dj[dir];
   }
   while (k > 0 && (r != r2 || c != c2)) {
     char ch = s[r][c];
     int cost = (isDigit(ch) ? ch - '0' : 1);
     if (cost > k) {
       k = cost;
       exit(1);
       break;
     }
     k -= cost;
     int dir = p[26][r][c];
     r -= di[dir];
     c -= dj[dir];
   }
   printf('%d %d
', r + 1, c + 1);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 T abs(T x) {
   return x > 0 ? x : -x;
 }
 const int tt = 75;
 int n;
 int m;
 int x[100];
 int y[100];
 int z[100];
 vector<int> v;
 vector<int> w[300];
 int res[301][301][2];
 int was[301][301][2];
 map<int, int> num;
 int f[300];
 int calc() {
   vector<pair<int, int> > v;
   for (int i = 0; i < n; i++)
     if (z[i]) {
       v.push_back(make_pair(x[i], 1));
       v.push_back(make_pair(x[i] + y[i], -1));
     } else {
       v.push_back(make_pair(x[i] - y[i], 1));
       v.push_back(make_pair(x[i], -1));
     }
   sort((v).begin(), (v).end());
   int cur = 0, bal = 0;
   for (int i = 0; i + 1 < 2 * n; i++) {
     bal += v[i].second;
     if (bal) cur += v[i + 1].first - v[i].first;
   }
   return cur;
 }
 int go(int i, int j, int t) {
   if (j < i) {
     t = 0;
     j = i;
   }
   if (i == ((int)(v).size())) return 0;
   if (was[i][j][t]) return res[i][j][t];
   was[i][j][t] = 1;
   int cur = go(i + 1, j, t);
   if ((!t || i < j) && f[i] > j)
     cur = max(cur, go((t ? j : i) + 1, f[i], 0) + (v[f[i]] - v[j]));
   for (int k = 0; k < ((int)(w[i]).size()); k++)
     if (w[i][k] > j)
       cur = max(cur, go((t ? j : i) + 1, w[i][k], 1) + (v[w[i][k]] - v[j]));
   return res[i][j][t] = cur;
 }
 int main() {
   scanf('%d', &n);
   for (int i = 0; i < n; i++) {
     scanf('%d%d', &x[i], &y[i]);
     v.push_back(x[i] - y[i]);
     v.push_back(x[i]);
     v.push_back(x[i] + y[i]);
   }
   sort((v).begin(), (v).end());
   v.resize(unique((v).begin(), (v).end()) - v.begin());
   for (int i = 0; i < ((int)(v).size()); i++) num[v[i]] = i;
   for (int i = 0; i < n; i++) {
     int a = num[x[i] - y[i]];
     int b = num[x[i]];
     int c = num[x[i] + y[i]];
     f[b] = c;
     w[a].push_back(b);
   }
   printf('%d
', go(0, 0, 0));
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main()
 {
      ios_base :: sync_with_stdio(false); cin.tie(NULL);
      int t ; cin >> t ; while(t--)
      {
          int a , b ; cin >> a >> b ;
    a-=b ;
    while(b--) cout << 'a' ;
    string d = 'cba' ;
    for(int i = 0 ; i < a ; i++)
    {
        cout << d[i % 3] ;
    }
    cout << endl ;
      }

 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, m, rr[10][10];
 long long func(long long), dp[(1 << 21)];
 map<long long, pair<long long, long long> > mr;
 long long check(long long i, long long j) {
   return (abs(mr[i].first - mr[j].first) + abs(mr[i].second - mr[j].second)) ==
          3;
 }
 int main() {
   scanf('%lld %lld', &n, &m);
   if (n > m) swap(n, m);
   if (n * m <= 21) {
     long long x = 0;
     for (int i = 0; i < n; i++)
       for (int j = 0; j < m; j++) {
         mr[x++] = make_pair(i, j);
       }
     memset(dp, -1, sizeof(dp));
     cout << func(0);
   } else {
     long long ans = 0;
     if (n == 1) {
       ans += m - m % 6;
       m = m % 6;
       ans += (m >= 3 ? 2 * (m - 3) : 0);
     } else
       ans = n * m - (n * m) % 2;
     cout << ans << '
';
   }
 }
 long long func(long long mask) {
   if (dp[mask] != -1) return dp[mask];
   long long ans = 0;
   for (int i = 0; i < n * m; i++) {
     for (int j = i + 1; j < n * m; j++) {
       if ((mask & (1 << i)) == 0 && (mask & (1 << j)) == 0 && check(i, j)) {
         ans = max(ans, 2 + func(mask | (1 << i) | (1 << j)));
       }
     }
   }
   return dp[mask] = ans;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool f(int n, int h, int c, int t) {
   return (2 * n + 1ll) * abs(1ll * n * (h + c - 2 * t) + t - c) <=
          (2 * n - 1ll) * (1ll * n * (h + c - 2 * t) + h - t);
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(NULL);
   long long t = 1;
   cin >> t;
   while (t--) {
     int h, c, t;
     cin >> h >> c >> t;
     if (2 * t <= h + c)
       cout << '2'
            << '
';
     else {
       int a = h - t;
       int b = 2 * t - c - h;
       int k = 2 * (a / b) + 1;
       long long val1 =
           abs(k / 2 * 1ll * c + (k + 1) / 2 * 1ll * h - t * 1ll * k);
       long long val2 = abs((k + 2) / 2 * 1ll * c + (k + 3) / 2 * 1ll * h -
                            t * 1ll * (k + 2));
       if (val1 * (k + 2) <= val2 * k)
         cout << k << '
';
       else
         cout << k + 2 << '
';
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 #define sim template < class c
 #define ris return * this
 #define dor > debug & operator <<
 #define eni(x) sim > typename \n   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
 sim > struct rge { c b, e; };
 sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
 sim > auto dud(c* x) -> decltype(cerr << *x, 0);
 sim > char dud(...);
 struct debug {
 #ifndef ONLINE_JUDGE
 ~debug() { cerr << endl; }
 eni(!=) cerr << boolalpha << i; ris; }
 eni(==) ris << range(begin(i), end(i)); }
 sim, class b dor(pair < b, c > d) {
   ris << '(' << d.first << ', ' << d.second << ')';
 }
 sim dor(rge<c> d) {
   *this << '[';
   for (auto it = d.b; it != d.e; ++it)
     *this << ', ' + 2 * (it == d.b) << *it;
   ris << ']';
 }
 #else
 sim dor(const c&) { ris; }
 #endif
 };
 #define imie(...) ' [' << #__VA_ARGS__ ': ' << (__VA_ARGS__) << '] '

 #define ll long long

 const ll mod = 998244353;

 long long power(long long x, ll y, ll p)
 {
     long long res = 1; // Initialize result

     x = x % p; // Update x if it is more than or
     // equal to p

     while (y > 0)
     {

         // If y is odd, multiply x with result
         if (y & 1)
             res = (res * x) % p;

         // y must be even now
         y = y >> 1; // y = y/2
         x = (x * x) % p;
     }
     return res;
 }

 // Returns n^(-1) mod p
 long long modInverse(long long n, int p)
 {
     return power(n, p - 2, p);
 }

 // Returns nCr % p using Fermat's little
 // theorem.
 long long nCrModPFermat(long long n,int r, int p)
 {
     // If n<r, then nCr should return 0
     if (n < r)
         return 0;
     // Base case
     if (r == 0)
         return 1;

     // Fill factorial array so that we
     // can find all factorial of r, n
     // and n-r
     long long fac[n + 1];
     fac[0] = 1;
     for (int i = 1; i <= n; i++)
         fac[i] = (fac[i - 1] * i) % p;

     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
 }

 void test_case() {
     ll n;
     cin >> n;
     string s;
     cin >> s;
     ll cnt = 0, cnt2 = 0, tmp = 0;
     for(ll i = 0; i < n; ++i) {
         if(s[i] == '0') {
             cnt2 = cnt2 + (tmp) / 2;
             tmp = 0;
             cnt++;
         } else {
             tmp++;
         }
     }
     cnt2 = cnt2 + (tmp) / 2;
     cout << nCrModPFermat(cnt + cnt2, cnt, mod) << endl;
 }

 int main()
 {
     ll T;
     cin >> T;
     for(ll i = 1; i <= T; ++i) {
         test_case();
     }
     return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize(2)
 using namespace std;
 int rd() {
   int k = 0;
   char c = getchar();
   while (c > '9' || c < '0') c = getchar();
   while (c >= '0' && c <= '9') k = k * 10 + c - '0', c = getchar();
   return k;
 }
 const int N = 300000, M = 600001;
 int T, x, y, f[M], sx[M], sy[M];
 long long ans;
 vector<pair<int, int> > v[M << 1];
 map<pair<int, int>, int> mp;
 pair<int, int> p;
 int F(int x) {
   while (x != f[x]) x = f[x];
   return x;
 }
 void Add(int x, int l, int r, int s, int t, pair<int, int> p) {
   if (s <= l && r <= t) {
     v[x].push_back(p);
     return;
   }
   if (s <= ((l + r) >> 1)) Add((x << 1), l, ((l + r) >> 1), s, t, p);
   if (((l + r) >> 1) < t) Add((x << 1 | 1), ((l + r) >> 1) + 1, r, s, t, p);
 }
 void Solve(int x, int l, int r) {
   long long pre = ans;
   stack<int> S;
   for (int i = 0; i < v[x].size(); ++i) {
     int a = F(v[x][i].first), b = F(v[x][i].second + N);
     if (a == b) continue;
     if (sx[a] + sy[a] > sx[b] + sy[b]) {
       int t = a;
       a = b, b = t;
     }
     ans -= (long long)sx[a] * sy[a] + (long long)sx[b] * sy[b],
         f[a] = b, sx[b] += sx[a], sy[b] += sy[a];
     ans += (long long)sx[b] * sy[b], S.push(a);
   }
   if (l == r)
     printf('%lld ', ans);
   else
     Solve((x << 1), l, ((l + r) >> 1)),
         Solve((x << 1 | 1), ((l + r) >> 1) + 1, r);
   while (!S.empty()) {
     int t = S.top(), z = f[t];
     S.pop(), f[t] = t, sx[z] -= sx[t], sy[z] -= sy[t];
   }
   ans = pre;
 }
 int main() {
   T = rd();
   for (int i = 1; i <= T; ++i) {
     x = rd(), y = rd(), p = make_pair(x, y);
     if (mp.count(p))
       Add(1, 1, T, mp[p], i - 1, p), mp.erase(p);
     else
       mp[p] = i;
   }
   for (auto t : mp) Add(1, 1, T, t.second, T, t.first);
   for (int i = 1; i <= N; ++i) sx[f[i] = i] = 1;
   for (int i = N + 1; i < M; ++i) sy[f[i] = i] = 1;
   Solve(1, 1, T);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<long long> adj[100007][2];
 long long ecnt[100007][2] = {0};
 long long ss[100007] = {0};
 long long sum = 0;
 long long n, m, q;
 int main() {
   cin >> n >> m;
   for (long long i = 0; i < m; i++) {
     long long a, b;
     cin >> a >> b;
     --a;
     --b;
     if (a > b) swap(a, b);
     adj[a][0].push_back(b);
     adj[b][1].push_back(a);
     ecnt[a][0]++;
     ecnt[b][1]++;
   }
   for (long long i = 0; i < n; i++) {
     ss[i] = ecnt[i][0] * ecnt[i][1];
     sum += ss[i];
   }
   cin >> q;
   cout << sum << endl;
   while (q--) {
     long long v;
     cin >> v;
     --v;
     sum -= ss[v];
     ss[v] = 0;
     ecnt[v][1] += ecnt[v][0];
     ecnt[v][0] = 0;
     for (auto i : adj[v][0]) {
       sum -= ecnt[i][0] * ecnt[i][1];
       ecnt[i][1]--;
       ecnt[i][0]++;
       sum += ecnt[i][0] * ecnt[i][1];
       ss[i] = ecnt[i][0] * ecnt[i][1];
       adj[i][0].push_back(v);
     }
     adj[v][0].clear();
     cout << sum << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2e5 + 5;
 int maxdp[27];
 int dp[N];
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n;
   string str;
   cin >> n >> str;
   for (int i = 0; i < n; ++i) {
     for (int c = 26; c > str[i] - 'a'; --c)
       maxdp[str[i] - 'a'] = max(maxdp[c] + 1, maxdp[str[i] - 'a']);
     dp[i] = maxdp[str[i] - 'a'];
   }
   cout << *max_element(dp, dp + n) << endl;
   for (int i = 0; i < n; ++i) {
     cout << dp[i] << ' ';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int SIZE = 1e2 + 5;
 int main() {
   int n, m, c;
   string s[SIZE], extract, f;
   c = 0, f = 'acef';
   cin >> n >> m;
   for (int i = 0; i < n; i++) cin >> s[i];
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < m; j++) {
       extract.push_back(s[i][j]);
       extract.push_back(s[i + 1][j]);
       extract.push_back(s[i][j + 1]);
       extract.push_back(s[i + 1][j + 1]);
       sort(extract.begin(), extract.end());
       if (extract == f) c++;
       extract.clear();
     }
   }
   cout << c << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1e6 + 7;
 pair<int, pair<int, int> > A[maxn];
 map<int, int> X;
 map<int, int> Y;
 int Hx[maxn], Hy[maxn];
 int ans[maxn];
 int fa[maxn];
 int fi(int u) {
   if (fa[u] == u) return u;
   return fa[u] = fi(fa[u]);
 }
 void un(int u, int v) {
   int p1 = fi(u), p2 = fi(v);
   if (p1 != p2) fa[p1] = p2;
 }
 int main() {
   int n, m;
   scanf('%d%d', &n, &m);
   for (int i = 0; i < n * m; i++) {
     fa[i] = i;
     scanf('%d', &A[i].first);
     A[i].second.first = i / m;
     A[i].second.second = i % m;
   }
   int j = -1;
   sort(A, A + n * m);
   for (int i = 0; i < n * m; i++) {
     if (i != n * m - 1 && A[i].first == A[i + 1].first) continue;
     for (int k = j + 1; k <= i; k++) {
       int p = A[k].second.first * m + A[k].second.second;
       int x = A[k].second.first, y = A[k].second.second;
       Hx[x] = p;
       Hy[y] = p;
     }
     for (int k = j + 1; k <= i; k++) {
       int p = A[k].second.first * m + A[k].second.second;
       int x = A[k].second.first, y = A[k].second.second;
       un(Hx[x], p);
       un(Hy[y], p);
     }
     for (int k = j + 1; k <= i; k++) {
       int p = A[k].second.first * m + A[k].second.second;
       int x = A[k].second.first, y = A[k].second.second;
       int pa = fi(p);
       ans[pa] = max(ans[pa], max(X[x], Y[y]) + 1);
     }
     for (int k = j + 1; k <= i; k++) {
       int p = A[k].second.first * m + A[k].second.second;
       int x = A[k].second.first, y = A[k].second.second;
       X[x] = max(X[x], ans[fi(p)]);
       Y[y] = max(Y[y], ans[fi(p)]);
     }
     j = i;
   }
   for (int i = 0; i < n * m; i++) {
     printf('%d ', ans[fi(i)]);
     if (i % m == m - 1) printf('
');
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int n;
 vector<int> adj[100005], stx, sty;
 long long mx = 0ll, ans[100005];
 int sz[100005], par[100005];
 pair<int, int> centroid = {0, 0};
 bool cmp(int u, int v) { return sz[u] < sz[v]; }
 void dfs(int nw, int bf) {
   par[nw] = bf;
   sz[nw] = 1;
   for (int nx : adj[nw])
     if (nx != bf) {
       dfs(nx, nw);
       sz[nw] += sz[nx];
     }
   sort(adj[nw].begin(), adj[nw].end(), cmp);
   mx += 2 * min(sz[nw], n - sz[nw]);
   centroid = max(centroid, {min(sz[nw], n - sz[nw]), nw});
 }
 void get_subtree(int nw, int bf, vector<int> &v) {
   v.push_back(nw);
   for (int nx : adj[nw])
     if (nx != bf) get_subtree(nx, nw, v);
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   cin >> n;
   for (int u, v, i = 1; i < n; i++) {
     cin >> u >> v;
     adj[u].push_back(v);
     adj[v].push_back(u);
   }
   dfs(1, 0);
   int x = centroid.second, y = par[x];
   if (sz[x] * 2 > n) swap(x, y);
   get_subtree(x, y, stx);
   get_subtree(y, x, sty);
   for (int i = 0; i < stx.size(); i++) {
     ans[stx[i]] = sty[i];
     ans[sty[sty.size() - stx.size() + i]] = stx[i];
   }
   for (int i = 0; i < sty.size() - stx.size(); i++)
     ans[sty[i]] = sty[stx.size() + i];
   cout << mx << endl;
   for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int a, b;
 bool temp = false;
 int main() {
   cin >> a;
   for (b = 1; b <= 500; b++)
     if ((b * (b + 1)) / 2 == a) {
       temp = true;
       break;
     }
   if (temp)
     cout << 'YES';
   else
     cout << 'NO';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int inf = 1e5 + 9, lg = 20;
 int n, q, timer = 1;
 vector<int> adj[inf], level[inf];
 int depth[inf], in[inf], out[inf], parent[inf][lg];
 void dfs(int u, int par) {
   in[u] = timer++;
   level[depth[u]].push_back(in[u]);
   for (auto v : adj[u])
     if (v != par) parent[v][0] = u, depth[v] = depth[u] + 1, dfs(v, u);
   out[u] = timer++;
 }
 int KthParent(int u, int k) {
   for (int j = lg - 1; j >= 0; j--)
     if (k & (1ll << j)) u = parent[u][j];
   return u;
 }
 int CntLevelInSubtree(int u, int h) {
   return upper_bound(level[h].begin(), level[h].end(), out[u]) -
          lower_bound(level[h].begin(), level[h].end(), in[u]);
 }
 int main() {
   cin >> n;
   for (int i = 1; i <= n; i++) {
     int tmp;
     cin >> tmp;
     if (tmp) adj[tmp].push_back(i), adj[i].push_back(tmp);
   }
   for (int i = 1; i <= n; i++)
     if (!in[i]) dfs(i, 0);
   for (int j = 1; j < lg; j++)
     for (int i = 1; i <= n; i++) parent[i][j] = parent[parent[i][j - 1]][j - 1];
   cin >> q;
   while (q--) {
     int v, p;
     cin >> v >> p;
     if (depth[v] < p) {
       cout << 0 << ' ';
       continue;
     }
     int u = KthParent(v, p);
     cout << CntLevelInSubtree(u, depth[v]) - 1 << ' ';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 1e9 + 7;
 const int maxn = 1000000 + 5;
 int f[maxn], inv[maxn], finv[maxn];
 void init() {
   inv[1] = 1;
   for (int i = 2; i < maxn; i++)
     inv[i] = (mod - mod / i) * 1ll * inv[mod % i] % mod;
   f[0] = finv[0] = 1;
   for (int i = 1; i < maxn; i++) {
     f[i] = f[i - 1] * 1ll * i % mod;
     finv[i] = finv[i - 1] * 1ll * inv[i] % mod;
   }
 }
 int C(int n, int m) {
   if (m < 0 || m > n) return 0;
   return f[n] * 1ll * finv[n - m] % mod * finv[m] % mod;
 }
 long long qpow(long long x, long long n) {
   long long r = 1;
   while (n > 0) {
     if (n & 1) r = r * x % mod;
     n >>= 1;
     x = x * x % mod;
   }
   return r;
 }
 long long T(long long n, long long k) {
   if (k == n) return 1;
   return k * qpow(n, n - k - 1) % mod;
 }
 int n, m, a, b;
 int main() {
   init();
   cin >> n >> m >> a >> b;
   long long ans = 0;
   for (int i = 1; i < n; i++) {
     long long tot = 1ll * C(m - 1, i - 1) * C(n - 2, i - 1) % mod * f[i - 1] %
                     mod * qpow(m, n - i - 1) % mod * T(n, i + 1) % mod;
     ans += tot;
     if (ans >= mod) ans -= mod;
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long int func1(long long int i) {
   long long int m = i;
   return i * (i + 1) * (2 * i + 1) / 6 - (m + m + 2) * i * (i + 1) / 2 +
          (m + m + 1 + m * m) * i;
 }
 long long int func2(long long int x, long long int i) {
   return x * (i + i * i - i * (i + 1) / 2);
 }
 int main() {
   long long int inp, tem, ans = 0, tem2;
   cin >> inp;
   vector<pair<long long int, long long int> > v;
   bool flag = 0;
   for (int i = 0; i < 100000000; i++)
     if (ans > 0) ans += 1;
   ans = 0;
   for (long long int i = 1; func1(i) <= inp; i++) {
     tem = inp - func1(i);
     if (!tem) {
       flag = 1;
       v.push_back(make_pair(i, i));
     } else {
       tem2 = func2(1, i);
       if (tem % tem2 == 0) v.push_back(make_pair(i, i + tem / tem2));
     }
   }
   if (!flag)
     cout << 2 * v.size();
   else
     cout << 2 * v.size() - 1;
   cout << '
';
   for (int i = 0; i < v.size(); i++)
     cout << v[i].first << ' ' << v[i].second << '
';
   int i = v.size() - 1;
   if (flag) i--;
   for (; i >= 0; i--) cout << v[i].second << ' ' << v[i].first << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string a, b;
   int k = 0, l = 0, n;
   cin >> a >> b;
   n = a.size();
   for (int i = 0; i < n; i++) {
     if (a[i] == '4' && b[i] == '7') {
       k++;
     } else if (a[i] == '7' && b[i] == '4') {
       l++;
     }
   }
   int p = max(k, l);
   cout << p << endl;
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize('O3')
 #pragma GCC target('sse4')
 using namespace std;
 template <class T>
 T gcd(T a, T b) {
   return ((b == 0) ? a : gcd(b, a % b));
 }
 void solve() {
   int n, k;
   long long x;
   cin >> n >> k >> x;
   string s;
   cin >> s;
   x--;
   int cnt = 0;
   vector<int> nm;
   for (int i = n - 1; i >= 0; i--) {
     if (s[i] == '*')
       cnt++;
     else {
       if (cnt) nm.push_back(cnt);
       cnt = 0;
     }
   }
   if (cnt) nm.push_back(cnt);
   int uwu = 0;
   vector<int> d;
   while (x > 0) {
     int cr = (nm[uwu++] * k) + 1;
     d.push_back(x % cr);
     x /= cr;
   }
   int ind = 0, lst = -1;
   string ans = '';
   for (int i = n - 1; i >= 0; i--) {
     if (s[i] == 'a')
       ans += 'a', lst = 1;
     else {
       if (!lst) continue;
       if (ind == (int)(d.size())) continue;
       for (int j = 0; j < (int)(d[ind]); j++) ans += 'b';
       ind++;
       lst = 0;
     }
   }
   reverse(ans.begin(), ans.end());
   cout << ans << '
';
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int t;
   cin >> t;
   while (t--) solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int tt;
   cin >> tt;
   while (tt--) {
     long long n, s, t;
     cin >> n >> s >> t;
     cout << max(n - s + 1, n - t + 1) << '
';
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 namespace runzhe2000 {
 const int INF = 1 << 29;
 int ft[100005], gt[100005], f[100005][10], g[100005][10], timer = 1, c[10],
                                                           sta[100005], top;
 char s[100005];
 bool insta[100005];
 struct node {
   int l, r, v;
 } no[100005];
 void del(int x) {
   no[no[x].l].r = no[x].r;
   no[no[x].r].l = no[x].l;
 }
 void main() {
   int n, q;
   scanf('%d%d%s', &n, &q, s + 1);
   for (int i = 1, v; i <= n; i++) {
     if (s[i] >= '0' && s[i] <= '9')
       v = s[i] - '0';
     else
       v = s[i] == '<' ? 11 : 10;
     no[i] = (node){i - 1, i + 1, v};
   }
   memset(ft, 63, sizeof(ft));
   memset(gt, 63, sizeof(gt));
   ++timer;
   ++n;
   no[n] = (node){n - 1, n + 1, 10};
   for (int l = 1; l <= n; l++)
     if (ft[l] > INF) {
       for (int cur = l, next, pos = 10; l <= cur && cur <= n;
            cur = next, ++timer) {
         if (timer < ft[cur]) {
           ft[cur] = timer;
           for (int i = 0; i < 10; i++) f[cur][i] = c[i];
         }
         if (no[cur].v < 10) {
           c[no[cur].v--]++;
           if (no[cur].v < 0) del(cur);
         } else {
           pos = no[cur].v;
         }
         next = pos == 11 ? no[cur].l : no[cur].r;
         if (no[cur].v > 9 && no[next].v > 9) del(cur);
         if (!insta[cur]) sta[++top] = cur, insta[cur] = 1;
         if (pos == 11) {
           for (; no[cur].l < sta[top] && sta[top] <= cur && top; --top) {
             gt[sta[top]] = ++timer;
             for (int i = 0; i < 10; i++) g[sta[top]][i] = c[i];
           }
         }
       }
     }
   for (; q--;) {
     int l, r;
     scanf('%d%d', &l, &r);
     if (ft[r + 1] < gt[l]) {
       for (int i = 0; i < 10; i++)
         printf('%d%c', f[r + 1][i] - f[l][i], i == 9 ? '
' : ' ');
     } else {
       for (int i = 0; i < 10; i++)
         printf('%d%c', g[l][i] - f[l][i], i == 9 ? '
' : ' ');
     }
   }
 }
 }  // namespace runzhe2000
 int main() { runzhe2000::main(); }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string s;
   cin >> s;
   int r = 0, b = 0, y = 0, g = 0;
   int len = s.size();
   for (int i = 0; i < len; i++) {
     if (s[i] == 'B')
       b = i % 4;
     else if (s[i] == 'G')
       g = i % 4;
     else if (s[i] == 'R')
       r = i % 4;
     else if (s[i] == 'Y')
       y = i % 4;
   }
   int w = 0, x = 0, yy = 0, z = 0, pos;
   for (int i = 0; i < len; i++) {
     if (s[i] == '!') {
       pos = i % 4;
       if (pos == r)
         w++;
       else if (pos == b)
         x++;
       else if (pos == y)
         yy++;
       else if (pos == g)
         z++;
     }
   }
   cout << w << ' ' << x << ' ' << yy << ' ' << z << endl;
   return 0;
 }


#include <bits/stdc++.h>
 int main() {
   unsigned short x;
   std::cin >> x;
   (x > 1) ? std::cout << x << ' ' << x : std::cout << -1;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, k, a[300005], b[300005];
 int main() {
   cin >> n >> k;
   k--;
   for (int i = 1; i <= n; i++) cin >> a[i];
   for (int i = 1; i < n; i++) b[i] = a[i + 1] - a[i];
   long long res = a[n] - a[1];
   sort(b + 1, b + n);
   for (int i = n - 1; i >= n - k; i--) res -= b[i];
   cout << res;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int T = 31;
 const int mod = 1000000007;
 const long long oo = 1LL << 60;
 long long N;
 int K;
 long long B[T][T];
 long long power[70];
 long long dp[70][T][T];
 bool bio[70];
 long long rot[T][T][T];
 long long mult(long long a, long long b) {
   if (a == 0) return 0;
   if (b >= oo / a + 1) return oo;
   return a * b;
 }
 void mult(long long A[T][T], long long B[T][T]) {
   static long long C[T][T];
   for (int i = (0); i < (T); ++i)
     for (int j = (0); j < (T); ++j) C[i][j] = 0;
   for (int i = (0); i < (T); ++i)
     for (int j = (0); j < (T); ++j)
       for (int k = (0); k < (T); ++k)
         C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;
   for (int i = (0); i < (T); ++i)
     for (int j = (0); j < (T); ++j) A[i][j] = C[i][j];
 }
 void rec(long long prefix, int n, long long A[T][T]) {
   long long lo = mult(prefix, power[n]);
   long long hi = lo + power[n] - 1;
   if (lo >= N) return;
   long long z = prefix % K;
   mult(A, rot[z]);
   if (n == 0) {
     mult(A, B);
   } else {
     bool memo = hi < N;
     auto AA = memo ? dp[n] : A;
     if (!bio[n] && memo)
       for (int i = (0); i < (T); ++i) AA[i][i] = 1;
     if (!bio[n] || !memo)
       for (int i = (0); i < (K); ++i) rec(prefix * K + i, n - 1, AA);
     if (memo) bio[n] = true, mult(A, AA);
   }
   mult(A, rot[(K - z) % K]);
 }
 int main() {
   scanf('%lld%d', &N, &K);
   for (int i = (0); i < (K); ++i) B[i][i] = 1;
   for (int i = (1); i < (K); ++i) B[i][0] = 1;
   B[K][0] = 1;
   B[K][K] = 1;
   for (int x = (0); x < (K); ++x)
     for (int i = (0); i < (K); ++i) rot[x][i][(i + x) % K] = 1;
   for (int x = (0); x < (K); ++x)
     for (int i = (K); i < (T); ++i) rot[x][i][i] = 1;
   static long long A[T][T];
   A[0][K] = 1;
   power[0] = 1;
   for (int i = (1); i < (70); ++i) power[i] = mult(power[i - 1], K);
   rec(0, 69, A);
   long long ans = 1;
   for (int i = (0); i < (K); ++i) ans = (ans + A[0][i]) % mod;
   printf('%lld
', ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base ::sync_with_stdio(false);
   cin.tie(NULL);
   int n, p, q;
   cin >> n;
   vector<pair<int, int>> v1;
   int x1, x2;
   for (size_t i = 0; i < n; i++) {
     cin >> x1 >> x2;
     v1.push_back(make_pair(x1, x2));
   }
   bool s = true;
   sort(v1.begin(), v1.end());
   for (size_t i = 0; i < n; i++) {
     if (v1[i].second > v1[i + 1].second && i + 1 < n) {
       s = false;
       break;
     }
   }
   if (s == true) {
     cout << 'Poor Alex';
   } else {
     cout << 'Happy Alex';
   }
   return 0;
 }


#include <bits/stdc++.h>
 int main() {
   int n;
   scanf('%d', &n);
   printf('%d', n % 2);
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> t;
 int n, x, i, j, h, sol, temp;
 int main() {
   ios::sync_with_stdio(false);
   cin >> n;
   for (i = 0; i < n; i++) {
     cin >> x;
     t.push_back(x);
   }
   cin >> h;
   sort(t.begin(), t.end());
   sol = 0;
   for (i = 0; i < n; i++) {
     temp = 1;
     for (j = i + 1; j < n; j++) {
       if (t[j] - t[i] <= h) temp++;
     }
     sol = max(sol, temp);
   }
   cout << sol << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 305;
 int n, m;
 class Point {
  public:
   long long x, y;
   Point() : x(0), y(0) {}
   Point(long long _x, long long _y) : x(_x), y(_y) {}
   void read() { scanf('%lld%lld', &x, &y); }
   Point operator+(const Point &o) const { return Point(x + o.x, y + o.y); }
   Point operator-(const Point &o) const { return Point(x - o.x, y - o.y); }
   long long operator*(const Point &o) const { return x * o.y - y * o.x; }
   bool operator<(const Point &o) const {
     int c = (y == 0 && x > 0) || (y > 0);
     int oc = (o.y == 0 && o.x > 0) || (o.y > 0);
     if (c != oc) return c > oc;
     return (*this) * o > 0;
   }
 } p[maxn];
 class Edge {
  public:
   Point w;
   int u, v;
   Edge() {}
   Edge(Point _w, int _u, int _v) : w(_w), u(_u), v(_v) {}
   bool operator<(const Edge &o) const { return w < o.w; }
 } e[maxn * maxn];
 long long dp[maxn][maxn][6];
 int main() {
   scanf('%d', &n);
   for (int i = 0; i < n; i++) p[i].read();
   for (int i = 0; i < n; i++)
     for (int j = i + 1; j < n; j++) {
       e[m++] = Edge(p[j] - p[i], i, j);
       e[m++] = Edge(p[i] - p[j], j, i);
     }
   sort(e, e + m);
   for (int i = 0; i < n; i++) dp[i][i][0] = 1;
   for (int i = 0; i < m; i++)
     for (int j = 0; j < n; j++)
       for (int k = 0; k < 5; k++) dp[j][e[i].v][k + 1] += dp[j][e[i].u][k];
   long long ans = 0;
   for (int i = 0; i < n; i++) ans += dp[i][i][5];
   printf('%lld
', ans);
   return 0;
 }