#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, i;
   cin >> n;
   string s;
   map<char, int> m;
   for (i = 0; i < n; i++) {
     cin >> s;
     m[s[0]]++;
   }
   int ans = 0, f1, f2;
   for (auto it = m.begin(); it != m.end(); it++) {
     f1 = it->second / 2;
     f2 = it->second - f1;
     ans += f1 * (f1 - 1) / 2 + f2 * (f2 - 1) / 2;
   }
   cout << ans << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int Read() {
   int x = 0;
   char ch = getchar();
   while (!isdigit(ch)) ch = getchar();
   while (isdigit(ch)) x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
   return x;
 }
 void Write(int x) {
   if (x < 0) putchar('-'), x = -x;
   if (x == 0) putchar('0');
   int stk[55], tp = 0;
   while (x) stk[++tp] = x % 10, x /= 10;
   for (int i = tp; i; i--) putchar(stk[i] + '0');
 }
 int Add(int a, int b) {
   return (a + b >= 998244353) ? a + b - 998244353 : a + b;
 }
 int Dec(int a, int b) { return (a - b < 0) ? a - b + 998244353 : a - b; }
 int mul(int a, int b) { return 1ll * a * b % 998244353; }
 unsigned int qpow(unsigned int a, int b) {
   unsigned int res = 1;
   for (; b; b >>= 1, a = mul(a, a))
     if (b & 1) res = mul(res, a);
   return res;
 }
 namespace NTT {
 int sz;
 unsigned int w[2500005], w_mf[2500005];
 int mf(int x) { return (1ll * x << 32) / 998244353; }
 void init(int n) {
   for (sz = 2; sz < n; sz <<= 1)
     ;
   unsigned int pr = qpow(3, (998244353 - 1) / sz);
   w[sz / 2] = 1;
   w_mf[sz / 2] = mf(1);
   for (int i = 1; i <= sz / 2; i++)
     w[sz / 2 + i] = mul(w[sz / 2 + i - 1], pr),
                w_mf[sz / 2 + i] = mf(w[sz / 2 + i]);
   for (int i = sz / 2 - 1; i; i--) w[i] = w[i << 1], w_mf[i] = w_mf[i << 1];
 }
 void ntt(vector<unsigned int>& A, int L) {
   for (int d = L >> 1; d; d >>= 1)
     for (int i = 0; i < L; i += (d << 1))
       for (int j = 0; j < d; j++) {
         unsigned int x = A[i + j] + A[i + d + j];
         if (x >= 998244353 * 2) x -= 998244353 * 2;
         long long t = A[i + j] + 998244353 * 2 - A[i + d + j],
                   q = t * w_mf[d + j] >> 32, y = t * w[d + j] - q * 998244353;
         A[i + j] = x;
         A[i + d + j] = y;
       }
   for (int i = 0; i < L; i++)
     if (A[i] >= 998244353) A[i] -= 998244353;
 }
 void intt(vector<unsigned int>& A, int L) {
   for (int d = 1; d < L; d <<= 1)
     for (int i = 0; i < L; i += (d << 1))
       for (int j = 0; j < d; j++) {
         unsigned int x = A[i + j];
         if (x >= 998244353 * 2) x -= 998244353 * 2;
         long long t = A[i + d + j], q = t * w_mf[d + j] >> 32,
                   y = t * w[d + j] - q * 998244353;
         A[i + j] = x + y, A[i + d + j] = x + 2 * 998244353 - y;
       }
   int k = __builtin_ctz(L);
   reverse(A.begin() + 1, A.end());
   for (int i = 0; i < L; i++) {
     long long m = -A[i] & (L - 1);
     A[i] = (A[i] + m * 998244353) >> k;
     if (A[i] >= 998244353) A[i] -= 998244353;
   }
 }
 }  // namespace NTT
 struct poly {
   vector<unsigned int> a;
   poly(int d = 0, int t = 0) {
     a.resize(d + 1);
     a[d] = t;
   }
   int deg() { return a.size() - 1; }
   unsigned int& operator[](const int& b) { return a[b]; }
   poly extend(int x) {
     poly c = *this;
     c.a.resize(x + 1);
     return c;
   }
   void resize(int x) { a.resize(x); }
   int size() { return a.size(); }
   void Get(int n) {
     a.resize(n + 1);
     for (int i = 0; i <= n; i++) a[i] = Read();
   }
   void Print(int n) {
     for (int i = 0; i <= n; i++) Write(a[i]), putchar(' ');
     puts(  );
   }
   friend poly operator*(poly A, poly B) {
     int n = A.deg() + B.deg() + 1, lim = 2;
     for (; lim < n; lim <<= 1)
       ;
     NTT::init(lim);
     A.resize(lim);
     B.resize(lim);
     NTT::ntt(A.a, lim);
     NTT::ntt(B.a, lim);
     for (int i = 0; i < lim; i++) A[i] = mul(A[i], B[i]);
     NTT::intt(A.a, lim);
     return A.extend(n - 1);
   }
   poly inv(poly A) {
     int n = A.a.size(), lim = 2;
     if (n == 1) return A[0] = qpow(A[0], 998244353 - 2), A;
     poly B = A;
     B.resize((n + 1) >> 1);
     B = inv(B);
     for (; lim < (n << 1); lim <<= 1)
       ;
     NTT::init(lim);
     A.resize(lim), B.resize(lim), NTT::ntt(A.a, lim);
     NTT::ntt(B.a, lim);
     for (int i = 0; i < lim; i++) A[i] = mul(Dec(2, mul(A[i], B[i])), B[i]);
     NTT::intt(A.a, lim);
     return A.extend(n - 1);
   }
   poly getinv() { return inv(*this); }
   poly getdao() {
     poly A = *this, B;
     int n = A.a.size();
     B.resize(n);
     for (int i = 1; i < n; i++) B[i - 1] = mul(A[i], i);
     B[n - 1] = 0;
     return B;
   }
   poly getjf() {
     poly A = *this, B;
     int n = A.a.size();
     B.resize(n);
     for (int i = 1; i < n; i++) B[i] = mul(A[i - 1], qpow(i, 998244353 - 2));
     B[0] = 0;
     return B;
   }
   poly getln() {
     poly A = *this;
     return (A.getdao() * A.getinv()).extend(A.deg()).getjf();
   }
   poly exp(poly A) {
     int n = A.a.size();
     if (n == 1) return A[0] = 1, A;
     poly B = A;
     B.resize((n + 1) >> 1);
     B = exp(B);
     poly C = B.getln();
     C.resize(n);
     for (int i = 0; i < n; i++) C[i] = Dec(A[i], C[i]);
     ++C[0];
     return (B * C).extend(n - 1);
   }
   poly getexp() { return exp(*this); }
   poly getmi(int k) {
     poly A = *this;
     int n = A.a.size();
     poly B = A.getln();
     for (int i = 0; i < n; i++) B[i] = mul(B[i], k);
     return B.getexp();
   }
   poly sqrt(poly A) {
     int n = A.size(), lim = 2;
     if (n == 1) return A[0] = 1, A;
     poly B = A;
     B.resize((n + 1) >> 1);
     B = sqrt(B);
     poly C = A.extend(n - 1), D = B.getinv();
     for (; lim < (n << 1); lim <<= 1)
       ;
     NTT::init(lim);
     B.resize(lim), C.resize(lim), D.resize(lim), NTT::ntt(B.a, lim);
     NTT::ntt(C.a, lim);
     NTT::ntt(D.a, lim);
     for (int i = 0; i < lim; i++)
       B[i] = mul(Add(B[i], mul(C[i], D[i])), 499122177);
     NTT::intt(B.a, lim);
     return B.extend(n - 1);
   }
   poly getsqrt() { return sqrt(*this); }
 };
 signed main() {
   int n = Read(), k = Read();
   poly A, B;
   A.resize(k * 3), B.resize(k * 3);
   A[0] = 1;
   A[1] = 6;
   A[2] = 1;
   A = A.getsqrt();
   B = A.getinv();
   ++A[1];
   ++A[0];
   for (int i = 0; i <= k; i++) A[i] = 1ll * A[i] * 499122177 % 998244353;
   A = A.getmi(n + 1);
   A = (A * B).extend(k * 3);
   for (int i = 1; i <= k; i++) {
     if (i <= n)
       printf( %d  , A[i]);
     else
       printf( %d  , 0);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   long long n, d, a, b;
   cin >> n >> d >> a >> b;
   vector<pair<long long, int> > v(n);
   for (int i = 0; i < n; i++) {
     long long x, y;
     cin >> x >> y;
     v[i].first = x * a + y * b;
     v[i].second = i + 1;
   }
   sort(v.begin(), v.end());
   int ans = 0, sum = 0, pos = 0;
   for (int i = 0; i < n; i++) {
     if (sum + v[i].first <= d) {
       sum += v[i].first;
       ans++;
       pos = i;
     }
   }
   cout << ans << endl;
   if (ans)
     for (int i = 0; i <= pos; i++) cout << v[i].second << ' ';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int t;
   long long x, y, p, q;
   cin >> t;
   while (t--) {
     cin >> x >> y >> p >> q;
     long long l = 0, h = 1e9, ans = -1, mid, a, b;
     while (l <= h) {
       mid = (l + h) / 2;
       a = p * mid;
       b = q * mid;
       if (b >= y && a >= x && b - a >= y - x) {
         ans = b - y;
         h = mid - 1;
       } else
         l = mid + 1;
     }
     cout << ans << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long int mod = 1e9 + 7;
 const long long int N = 2 * (1e5);
 const long long int maxo = 1e14;
 const long long int inf = 1e17;
 int main(int argc, char const *argv[]) {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long int x0, y0, ax, ay, bx, by;
   cin >> x0 >> y0 >> ax >> ay >> bx >> by;
   long long int xs, ys, t;
   cin >> xs >> ys >> t;
   vector<pair<long long int, long long int> > v;
   v.push_back({x0, y0});
   for (long long int i = 0; i < 100; i++) {
     if (v.back().first > (inf - bx) / (ax)) break;
     if (v.back().second > (inf - by) / ay) break;
     long long int x1 = v.back().first * ax + bx;
     long long int y1 = v.back().second * ay + by;
     v.push_back({x1, y1});
   }
   long long int n = v.size();
   long long int ans = 0;
   for (long long int l = 0; l < n; l++) {
     for (long long int r = l; r < n; r++) {
       long long int d1 = abs(xs - v[l].first) + abs(ys - v[l].second);
       long long int d2 = abs(xs - v[r].first) + abs(v[r].second - ys);
       long long int len =
           abs(v[l].first - v[r].first) + abs(v[l].second - v[r].second);
       if (d1 + len <= t) {
         ans = max(ans, r - l + 1);
       }
       if (d2 + len <= t) {
         ans = max(ans, r - l + 1);
       }
     }
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 void setIO(string name =   ) {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   if (int((name).size())) {
     freopen((name +  .in ).c_str(),  r , stdin);
     freopen((name +  .out ).c_str(),  w , stdout);
   }
 }
 long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
 long long mcm(long long a, long long b) { return (a * b) / gcd(a, b); }
 bool prime(long long n, long long i) {
   if (i > sqrt(n)) return true;
   if (n % i == 0)
     return false;
   else
     return prime(n, i + 1);
 }
 struct compii {
   bool operator()(const pair<int, int> &a, const pair<int, int> &b) {
     if (a.first == a.second) return a.second < b.second;
     return a.first > b.first;
   }
 };
 bool comp(int a, int b) { return a > b; }
 int dx[] = {1, 0, -1, 0};
 int dy[] = {0, 1, 0, -1};
 const int mod = 1e9 + 7;
 const long long inf = 1e18;
 bool check(string a, string b) {
   if (a ==  rock  and b ==  scissors ) return true;
   if (a ==  paper  and b ==  rock ) return true;
   if (a ==  scissors  and b ==  paper ) return true;
   return false;
 }
 void solve() {
   string first, m, second;
   cin >> first >> m >> second;
   if (check(first, m) and check(first, second))
     cout <<  F ;
   else if (check(m, second) and check(m, first))
     cout <<  M ;
   else if (check(second, first) and check(second, m))
     cout <<  S ;
   else
     cout <<  ? ;
 }
 int main() {
   setIO(  );
   int t = 1;
   while (t-- > 0) solve();
   return 0;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 const int adj[8][2] = {{-1, 0},  {0, -1}, {1, 0}, {0, 1},
                        {-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
 const long long int LLINF = 9e18;
 const int INF = 2e9;
 const int MOD = 1e9 + 7;
 const double EPS = 1e-10;
 const double PI = acos(-1);
 const int SIZE = 100011;
 int N;
 int cnt[SIZE];
 map<string, int> Mp;
 string ts[8] = { S ,  M ,  L ,  XL ,  XXL ,  XXXL };
 string s;
 struct edge {
   int v, f, c, u;
 };
 vector<edge> E[SIZE];
 int st[SIZE], lvl[SIZE];
 void init() {
   for (int i = 0; i < SIZE; i++) {
     cnt[i] = 0;
     E[i].clear();
   }
 }
 void addedge(int a, int b, int ca, int cb) {
   edge A = {a, 0, ca, (int)E[a].size()};
   edge B = {b, 0, cb, (int)E[b].size()};
   E[a].push_back(B);
   E[b].push_back(A);
 }
 bool BFS(int S, int T) {
   memset(lvl, -1, sizeof(lvl));
   queue<int> q;
   q.push(S);
   lvl[S] = 0;
   while (!q.empty()) {
     int indx = q.front();
     q.pop();
     for (unsigned int i = 0; i < E[indx].size(); i++) {
       edge &t = E[indx][i];
       int idx = t.v;
       if (lvl[idx] < 0 && t.c > t.f) {
         lvl[idx] = lvl[indx] + 1;
         q.push(idx);
       }
     }
   }
   return lvl[T] >= 0;
 }
 int DFS(int indx, int T, int flow) {
   if (indx == T) return flow;
   for (int &i = st[indx]; i < (int)E[indx].size(); i++) {
     edge &t = E[indx][i];
     int idx = t.v;
     if (lvl[idx] == lvl[indx] + 1 && t.c > t.f) {
       int cur = min(flow, t.c - t.f);
       int ret = DFS(idx, T, cur);
       if (ret > 0) {
         t.f += ret;
         E[t.v][t.u].f -= ret;
         return ret;
       }
     }
   }
   return 0;
 }
 int Dinic(int S, int T) {
   int ret = 0;
   while (BFS(S, T)) {
     memset(st, 0, sizeof(st));
     while (int flow = DFS(S, T, INF)) {
       ret += flow;
     }
   }
   return ret;
 }
 int main() {
   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int S = 0, T = SIZE - 1, a;
   init();
   for (int i = 1; i <= 6; i++) {
     cin >> a;
     Mp[ts[i - 1]] = i;
     addedge(i, T, 0, a);
   }
   cin >> N;
   for (int i = 1; i <= N; i++) {
     cin >> s;
     s +=  , ;
     string temp =   ;
     for (unsigned int j = 0; j < s.size(); j++) {
       if (s[j] == ',') {
         addedge(i + 6, Mp[temp], 0, 1);
         temp.clear();
         cnt[i + 6]++;
       } else
         temp.push_back(s[j]);
     }
     addedge(S, i + 6, 0, 1);
   }
   int ans = Dinic(S, T);
   if (ans != N)
     cout <<  NO  << endl;
   else {
     cout <<  YES  << endl;
     for (int i = 1; i <= N; i++) {
       edge t1, t2;
       if (cnt[i + 6] == 1) {
         t1 = E[i + 6][0];
         cout << ts[t1.v - 1] << endl;
       } else {
         t1 = E[i + 6][0];
         t2 = E[i + 6][1];
         if (t1.f == 1)
           cout << ts[t1.v - 1] << endl;
         else if (t2.f == 1)
           cout << ts[t2.v - 1] << endl;
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[101];
 int b[101];
 int storage[200001];
 int storage2[200001];
 int* value = storage + 100000;
 int* prevalue = storage2 + 100000;
 int n, k;
 int main() {
   scanf( %d%d , &n, &k);
   int gtzero = 0, lezero = 0;
   for (int i = 0; i < n; i++) scanf( %d , &a[i]);
   for (int i = 0; i < n; i++) scanf( %d , &b[i]), b[i] *= k;
   for (int i = 0; i < n; i++) {
     b[i] = a[i] - b[i];
     if (b[i] > 0)
       gtzero += b[i];
     else
       lezero += b[i];
   }
   for (int i = 0; i < sizeof(storage) / sizeof(int); i++) {
     storage[i] = -19200000;
     storage2[i] = -19200000;
   }
   value[0] = prevalue[0] = 0;
   for (int i = 0; i < n; i++) {
     int C = b[i];
     for (int j = -10000; j <= 10000; j++) {
       value[j] = max(prevalue[j], prevalue[j - b[i]] + a[i]);
     }
     memcpy(storage2, storage, sizeof(storage));
   }
   if (value[0] > 0)
     printf( %d
 , value[0]);
   else
     printf( -1
 );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 500005;
 const int maxx = 1000005;
 int n, x, y, q, l, r;
 int a[N];
 struct Tree {
   int ans, m, tag;
 } tr[maxx * 6];
 void pushdown(int rt) {
   int lson = rt << 1;
   int rson = rt << 1 | 1;
   tr[lson].m += tr[rt].tag;
   tr[rson].m += tr[rt].tag;
   tr[lson].tag += tr[rt].tag;
   tr[rson].tag += tr[rt].tag;
   tr[rt].tag = 0;
 }
 void updata(int rt) {
   int lson = rt << 1;
   int rson = rt << 1 | 1;
   if (tr[lson].m == tr[rson].m) {
     tr[rt].m = tr[lson].m;
     tr[rt].ans = tr[lson].ans + tr[rson].ans;
   } else if (tr[lson].m < tr[rson].m) {
     tr[rt].m = tr[lson].m;
     tr[rt].ans = tr[lson].ans;
   } else {
     tr[rt].m = tr[rson].m;
     tr[rt].ans = tr[rson].ans;
   }
 }
 void change(int rt, int l, int r, int cl, int cr, int C) {
   if (cl <= l && r <= cr) {
     tr[rt].m += C;
     tr[rt].tag += C;
     return;
   }
   pushdown(rt);
   int mid = (l + r) >> 1;
   if (cl <= mid) change(rt << 1, l, mid, cl, cr, C);
   if (cr > mid) change(rt << 1 | 1, mid + 1, r, cl, cr, C);
   updata(rt);
 }
 void change2(int rt, int l, int r, int x, int C) {
   if (l == r) {
     tr[rt].ans += C;
     return;
   }
   pushdown(rt);
   int mid = (l + r) >> 1;
   if (x <= mid) change2(rt << 1, l, mid, x, C);
   if (x > mid) change2(rt << 1 | 1, mid + 1, r, x, C);
   updata(rt);
 }
 int query(int rt, int l, int r, int ql, int qr) {
   if (ql <= l && r <= qr) {
     if (tr[rt].m == 1) return tr[rt].ans;
     return 0;
   }
   pushdown(rt);
   int mid = (l + r) >> 1, summ = 0;
   if (ql <= mid) summ += query(rt << 1, l, mid, ql, qr);
   if (qr > mid) summ += query(rt << 1 | 1, mid + 1, r, ql, qr);
   updata(rt);
   return summ;
 }
 int main() {
   scanf( %d %d , &n, &q);
   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);
   a[0] = maxx;
   a[n + 1] = 0;
   for (int i = 1; i <= n; ++i) change2(1, 0, maxx, a[i], 1);
   for (int i = 1; i <= n + 1; ++i) {
     int l = a[i - 1];
     int r = a[i];
     if (l == r) continue;
     if (l > r) swap(l, r);
     change(1, 0, maxx, l, r - 1, 1);
   }
   for (int i = 1; i <= q; ++i) {
     scanf( %d %d , &x, &y);
     l = a[x];
     r = a[x + 1];
     if (l != r) {
       if (l > r) swap(l, r);
       change(1, 0, maxx, l, r - 1, -1);
     }
     l = a[x - 1];
     r = a[x];
     if (l != r) {
       if (l > r) swap(l, r);
       change(1, 0, maxx, l, r - 1, -1);
     }
     change2(1, 0, maxx, a[x], -1);
     change2(1, 0, maxx, y, 1);
     a[x] = y;
     l = a[x];
     r = a[x + 1];
     if (l != r) {
       if (l > r) swap(l, r);
       change(1, 0, maxx, l, r - 1, 1);
     }
     l = a[x - 1];
     r = a[x];
     if (l != r) {
       if (l > r) swap(l, r);
       change(1, 0, maxx, l, r - 1, 1);
     }
     printf( %d
 , query(1, 0, maxx, 1, maxx - 1));
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using ll = long long;
 const int inf = 1e9 + 7;
 const ll longinf = 1LL << 60;
 const ll mod = 1e9 + 7;
 int main() {
   int h, w, n, q;
   cin >> h >> w >> n >> q;
   vector<int> v[h];
   for (int i = (int)(0); i < (int)(n); ++i) {
     int x, y;
     cin >> x >> y;
     --x;
     --y;
     v[x].push_back(y);
   }
   for (int i = (int)(0); i < (int)(h); ++i) sort(v[i].begin(), v[i].end());
   vector<ll> ok;
   ok.push_back(-longinf);
   ok.push_back(longinf);
   for (int i = (int)(0); i < (int)(q); ++i) {
     int x;
     cin >> x;
     --x;
     ok.push_back(x);
   }
   sort(ok.begin(), ok.end());
   ll pl = 0, pr = 0;
   ll dp[2][202020];
   for (int i = (int)(0); i < (int)(2); ++i)
     for (int j = (int)(0); j < (int)(202020); ++j) dp[i][j] = longinf;
   dp[0][1] = dp[1][1] = 0;
   if (v[0].size()) {
     pl = v[0][0];
     pr = v[0].back();
     dp[0][1] = 2 * pr - pl;
     dp[1][1] = pr;
   }
   int maxh = 1;
   for (int i = (int)(1); i < (int)(h); ++i) {
     if (v[i].empty()) {
       dp[0][i + 1] = dp[0][i] + 1;
       dp[1][i + 1] = dp[1][i] + 1;
       continue;
     }
     int nl = v[i][0], nr = v[i].back();
     auto itr = lower_bound(ok.begin(), ok.end(), pl);
     dp[0][i + 1] = min(dp[0][i + 1], dp[0][i] + abs(*itr - pl) +
                                          abs(nr - *itr) + abs(nr - nl) + 1);
     dp[1][i + 1] = min(dp[1][i + 1], dp[0][i] + abs(*itr - pl) +
                                          abs(nl - *itr) + abs(nr - nl) + 1);
     --itr;
     dp[0][i + 1] = min(dp[0][i + 1], dp[0][i] + abs(*itr - pl) +
                                          abs(nr - *itr) + abs(nr - nl) + 1);
     dp[1][i + 1] = min(dp[1][i + 1], dp[0][i] + abs(*itr - pl) +
                                          abs(nl - *itr) + abs(nr - nl) + 1);
     itr = lower_bound(ok.begin(), ok.end(), pr);
     dp[0][i + 1] = min(dp[0][i + 1], dp[1][i] + abs(*itr - pr) +
                                          abs(nr - *itr) + abs(nr - nl) + 1);
     dp[1][i + 1] = min(dp[1][i + 1], dp[1][i] + abs(*itr - pr) +
                                          abs(nl - *itr) + abs(nr - nl) + 1);
     --itr;
     dp[0][i + 1] = min(dp[0][i + 1], dp[1][i] + abs(*itr - pr) +
                                          abs(nr - *itr) + abs(nr - nl) + 1);
     dp[1][i + 1] = min(dp[1][i + 1], dp[1][i] + abs(*itr - pr) +
                                          abs(nl - *itr) + abs(nr - nl) + 1);
     pl = nl;
     pr = nr;
     maxh = max(i + 1, maxh);
   }
   cout << min(dp[0][maxh], dp[1][maxh]) << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   int cnt = 0;
   cin >> n;
   string a;
   for (int i = 0; i < n; i++) {
     cin >> a;
     if (a ==  Tetrahedron )
       cnt += 4;
     else if (a ==  Cube )
       cnt += 6;
     else if (a ==  Octahedron )
       cnt += 8;
     else if (a ==  Dodecahedron )
       cnt += 12;
     else
       cnt += 20;
   }
   cout << cnt;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 #pragma comment(linker,  /STACK:20000000 )
 string problem_name =  a ;
 void init() { freopen((problem_name +  .in ).c_str(),  rt , stdin); }
 long long res = 0;
 int ms[300100];
 int len;
 void mul(int val) {
   int p = 0;
   for (int i = 0; i < 300000; i++) {
     p += ms[i] *= val;
     ms[i] = p % 10;
     p /= 10;
   }
 }
 int main() {
   string s;
   cin >> s;
   vector<int> u(255, 0);
   res = 1;
   int zero = 0;
   long long col = 10;
   int c = 0;
   int c2 = 0;
   for (int i = 0; i < int((s).size()); i++) {
     if (s[i] == '?') {
       c++;
     } else if (isalpha(s[i])) {
       if (u[s[i]]) continue;
       u[s[i]] = 1;
       if (col <= 0) {
         res = 0;
         zero = 1;
         break;
       }
       c2++;
       col--;
     }
   }
   if (zero) {
     cout << 0;
     return 0;
   }
   if (c) {
     if (s[0] == '?')
       ms[c - 1] = 9;
     else
       ms[c] = 1;
   } else
     ms[0] = 1;
   if (c2) {
     for (int i = 10; i > 10 - c2; i--) {
       if (i == 10 && isalpha(s[0]))
         mul(9);
       else
         mul(i);
     }
   }
   int len = 300000;
   while (!ms[len]) len--;
   for (int i = len; i >= 0; i--) printf( %d , ms[i]);
   return 0;
 }


#include <bits/stdc++.h>
 const long long mod = 1e9 + 7;
 using namespace std;
 const long long N = 102;
 const long long M = 1e4 + 2;
 long long dp[N][M], c[N][N], cnt[N];
 signed main() {
   long long n, i, j, k, l, ans = 0, type = 0;
   cin >> n;
   dp[0][0] = 1;
   c[0][0] = 1;
   for (i = 1; i <= n; i++) {
     cin >> j;
     if (!cnt[j]) {
       type++;
     }
     cnt[j]++;
     for (l = i; l >= 1; l--) {
       for (k = 10000; k >= j; k--) {
         dp[l][k] += dp[l - 1][k - j];
         if (dp[l][k] > mod) {
           dp[l][k] -= mod;
         }
       }
     }
   }
   if (type <= 2) {
     cout << n;
     return 0;
   }
   for (i = 1; i <= 100; i++) {
     for (j = 0; j <= i; j++) {
       c[j][i] = c[j][i - 1];
       if (j) {
         c[j][i] += c[j - 1][i - 1];
       }
       c[j][i] %= mod;
     }
   }
   for (i = 1; i <= 100; i++) {
     for (j = 1; j <= cnt[i]; j++) {
       if (c[j][cnt[i]] == dp[j][i * j]) {
         ans = max(ans, j);
       }
     }
   }
   cout << ans;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int dx[] = {0, 1, -1, 0, 1, -1, -1, 1};
 const int dy[] = {-1, 0, 0, 1, 1, 1, -1, -1};
 const int N = 0;
 const int MOD = 0;
 const int INF = 1e9 + 10;
 const long long int LLINF = 1e18 + 10;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int n, m;
   cin >> n >> m;
   int v[10010];
   int l, r, x;
   for (int i = 1; i <= n; i++) {
     cin >> v[i];
   }
   int aux;
   bool mudou;
   int cnt = 0;
   while (m--) {
     cin >> l >> r >> x;
     aux = x - l;
     cnt = 0;
     for (int i = l; i <= r; i++) {
       if (v[i] < v[x]) cnt++;
     }
     if (cnt == aux)
       cout <<  Yes
 ;
     else
       cout <<  No
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   int suma = 0, sumg = 0, a, g;
   char *arr = new char[n];
   for (int i = 0; i < n; i++) {
     scanf( %d %d , &a, &g);
     if (abs(suma + a - sumg) < abs(sumg + g - suma)) {
       suma += a;
       arr[i] = 'A';
     } else {
       sumg += g;
       arr[i] = 'G';
     }
   }
   if (abs(suma - sumg) > 500)
     cout <<  -1 ;
   else
     for (int i = 0; i < n; i++) cout << arr[i];
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool isPowerOfTwo(int x) { return (x && !(x & (x - 1))); }
 bool is_prime(int n) {
   if (n == 1) return false;
   for (int i = 2; i <= sqrt(n); i++) {
     if (n % i == 0) {
       return false;
     }
   }
   return true;
 }
 void solve() {
   int n;
   cin >> n;
   long long int a, b;
   cin >> a >> b;
   set<long long int> st;
   st.insert(a);
   st.insert(b);
   for (int i = 2; i * i <= a; i++) {
     if (a % i == 0) {
       st.insert(i);
       st.insert(a / i);
     }
   }
   for (int i = 2; i * i <= b; i++) {
     if (b % i == 0) {
       st.insert(i);
       st.insert(b / i);
     }
   }
   map<pair<long long int, long long int>, long long int> ch;
   ch[{a, b}]++;
   for (int i = 1; i < n; i++) {
     cin >> a >> b;
     if (ch[{a, b}] >= 1) continue;
     ch[{a, b}]++;
     for (auto it = st.begin(); it != st.end();) {
       long long int k = *it;
       if (a % k == 0 || b % k == 0) {
         it++;
       } else {
         it = st.erase(it++);
       }
     }
   }
   if (st.empty())
     cout <<  -1 ;
   else
     cout << (*st.begin());
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int t = 1;
   while (t--) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using int64 = long long;
 int64 bit_count(int64 n) {
   int64 a{};
   while (n) {
     a += 1;
     n >>= 1;
   }
   return a;
 }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(nullptr);
   int T;
   cin >> T;
   while (T--) {
     int64 n, m;
     cin >> n >> m;
     vector<int64> P(m);
     for (auto &p : P) cin >> p;
     auto s = accumulate(begin(P), end(P), 0ll);
     if (s < n) {
       cout << -1 << '
';
       continue;
     }
     vector<int64> F(65);
     for (auto p : P) F[bit_count(p) - 1]++;
     int64 ans{};
     for (int i = 0, j = -1; i < 64; i++) {
       if (j >= 0 and F[i]) {
         ans += i - j;
         j = -1;
         F[i]--;
       }
       if (n & (1 << i)) {
         if (F[i]) {
           F[i]--;
         } else {
           if (j == -1) j = i;
         }
       }
       F[i + 1] += F[i] / 2;
     }
     cout << ans << '
';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   scanf( %d , &n);
   for (int i = 1; i <= n; i++) {
     if (i == 1)
       printf( 14
 );
     else {
       if (i == 2)
         printf( 16
 );
       else
         printf( %lld
 , (1LL * i * (i + 1) * (i + 1) - (i - 1)));
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma GCC optimize( Ofast,no-stack-protector )
 #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )
 #pragma GCC target( avx,tune=native )
 using namespace std;
 const int inf = 0x3f3f3f3f;
 const double eps = 1e-6;
 const int mod = 1000000007;
 inline string getstr(string &s, int l, int r) {
   string ret =   ;
   for (int i = l; i <= r; i++) ret.push_back(s[i]);
   return ret;
 }
 int modpow(int x, int y, int md = mod) {
   if (y == 0) return 1;
   int ret = modpow(x, y >> 1, md);
   ret = (long long)ret * ret % md;
   if (y & 1) ret = (long long)ret * x % md;
   return ret;
 }
 int n, m, t, ans;
 int a[10001];
 int cnt[10005];
 int in[11];
 inline int calc(int use) {
   int ret = 1;
   for (int i = 1; i <= use; i++) {
     ret = (long long)ret * cnt[in[i]] % mod;
   }
   return ret;
 }
 void dfs(int use, int last, bitset<128> now) {
   ans += calc(use);
   if (ans >= mod) ans -= mod;
   for (int i = last + 1; i <= m / 2; i++) {
     if (cnt[i]) {
       if (now[i] || now[m - i]) continue;
       bitset<128> bs =
           now | (now >> i) | (now << i) | (now >> (m - i)) | (now << (m - i));
       in[use + 1] = i;
       dfs(use + 1, i, bs);
     }
   }
 }
 bitset<128> bs;
 int main() {
   bs.reset();
   bs.set(0);
   cin >> n >> m >> t;
   for (int i = 0; i < t; i++) cin >> a[i], cnt[min(m - a[i] % m, a[i] % m)]++;
   dfs(0, 0, bs);
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   ;
   long long t;
   cin >> t;
   while (t--) {
     int n;
     string a, b;
     cin >> n >> a >> b;
     vector<int> res;
     for (int i = 0; i < n; i++) {
       if (a[i] != b[i]) {
         if (i != 0) res.push_back(i + 1);
         res.push_back(1);
         if (i != 0) res.push_back(i + 1);
       }
     }
     cout << res.size() <<    ;
     for (int x : res) {
       cout << x <<    ;
     }
     cout << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX = 2 * 1e5 + 5;
 const int INF = 1e9;
 const int MOD = 1e9 + 7;
 int N, K, A[MAX], table[20][MAX];
 int main() {
   cin >> N >> K;
   for (int i = 0; i < (N); ++i) cin >> A[i];
   for (int i = 0; i < (N); ++i) table[0][i] = A[i];
   vector<int> b(N, 0);
   for (int i = 0; i < (N); ++i) {
     for (int j = 0; j < (19); ++j) {
       table[j + 1][i] = table[j][i] / 2;
       b[i]++;
       if (table[j + 1][i] == 0) break;
     }
   }
   map<int, int> m, cost;
   int ans = INF;
   for (int i = 0; i < (20); ++i) {
     for (int j = 0; j < (N); ++j) {
       if (b[j] < i) continue;
       int num = table[i][j];
       m[num]++;
       cost[num] += i;
       if (m[num] >= K) ans = min(ans, cost[num]);
     }
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int r, g, b, ck, maximum = 0, temp;
   scanf( %d %d %d , &r, &g, &b);
   if (r % 2 == 1) r++;
   r = r / 2;
   if (g % 2 == 1) g++;
   g = g / 2;
   if (b % 2 == 1) b++;
   b = b / 2;
   temp = 27 + r * 3;
   if (temp > maximum) maximum = temp;
   temp = 28 + g * 3;
   if (temp > maximum) maximum = temp;
   temp = 29 + b * 3;
   if (temp > maximum) maximum = temp;
   printf( %d
 , maximum);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string s;
   cin >> s;
   for (int i = 0; i < s.size(); i++) {
     for (char a = 'a'; a <= 'z'; a++) {
       string t =   ;
       for (int j = 0; j < i; j++) {
         t += s[j];
       }
       t += a;
       for (int j = i; j < s.size(); j++) {
         t += s[j];
       }
       string r = t;
       reverse(t.begin(), t.end());
       if (r == t) {
         cout << r;
         return 0;
       }
     }
   }
   for (char a = 'a'; a <= 'z'; a++) {
     string t = s;
     t += a;
     string r = t;
     reverse(t.begin(), t.end());
     if (r == t) {
       cout << r;
       return 0;
     }
   }
   cout <<  NA ;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline void output(long long int x) {
   if (x % 2)
     cout << x / 2 <<
 ;
   else
     cout << x / 2 - 1 <<
 ;
   return;
 }
 long long int N, K;
 int main() {
   cin >> N >> K;
   if (N >= K)
     output(K);
   else {
     if ((N << 1) - 1 < K)
       cout << 0 <<
 ;
     else
       output(N - (K - N) + 2);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 5005;
 const int mod = 1000000007;
 int n, a, b, k;
 int dp[N][N];
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   cin >> n >> a >> b >> k;
   for (long long i = 1; i <= n; ++i) {
     dp[0][i] = i;
   }
   for (int trip = 1; trip <= k; trip++) {
     for (int floor = 1; floor <= n; floor++) {
       int d = abs(b - floor);
       dp[trip][floor] = dp[trip - 1][min(n, floor + d - 1)] -
                         dp[trip - 1][max(0, floor - d)] - dp[trip - 1][floor] +
                         dp[trip - 1][floor - 1];
       while (dp[trip][floor] < 0) dp[trip][floor] += mod;
       dp[trip][floor] %= mod;
       dp[trip][floor] = (dp[trip][floor] + dp[trip][floor - 1]) % mod;
     }
   }
   cout << (dp[k][a] - dp[k][a - 1] + mod) % mod;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int mdc(int a, int b) { return !b ? a : mdc(b, a % b); }
 int main() {
   int n, m, x, y, a, b, p, d, x1, y1, x2, y2;
   cin >> n >> m >> x >> y >> a >> b;
   d = mdc(a, b);
   a /= d;
   b /= d;
   p = min(n / a, m / b);
   a *= p;
   b *= p;
   if (x + a / 2 > n) {
     x2 = n;
     x1 = n - a;
   } else if (x - a / 2 < 0) {
     x1 = 0;
     x2 = a;
   } else {
     x2 = x + a / 2;
     x1 = x2 - a;
   }
   if (y + b / 2 > m) {
     y2 = m;
     y1 = m - b;
   } else if (y - b / 2 < 0) {
     y1 = 0;
     y2 = b;
   } else {
     y2 = y + b / 2;
     y1 = y2 - b;
   }
   cout << x1 <<     << y1 <<     << x2 <<     << y2 << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long MOD = 1e9 + 7;
 const long long N = 3e5 + 10;
 long long pow(long long a, long long b, long long m) {
   long long ans = 1;
   while (b) {
     if (b & 1) ans = (ans * a) % m;
     b /= 2;
     a = (a * a) % m;
   }
   return ans;
 }
 long long y[5], m[5];
 long long h, a, d;
 int32_t main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   for (long long i = 1; i <= 3; i++) {
     cin >> y[i];
   }
   for (long long i = 1; i <= 3; i++) {
     cin >> m[i];
   }
   cin >> h >> a >> d;
   long long mn = 1e18;
   for (long long i = y[1]; i <= 1000; i++) {
     for (long long j = y[2]; j <= 201; j++) {
       for (long long k = y[3]; k <= 201; k++) {
         long long z = (i - y[1]) * h + (j - y[2]) * a + (k - y[3]) * d;
         if (j <= m[3]) {
           continue;
         } else if (k >= m[2]) {
           mn = min(mn, z);
         } else {
           long long sec_to_take_yong =
               (m[1] / (j - m[3])) + (m[1] % (j - m[3]) != 0);
           long long sec_to_take_m = (i / (m[2] - k)) + (i % (m[2] - k) != 0);
           if (sec_to_take_yong < sec_to_take_m) mn = min(mn, z);
         }
       }
     }
   }
   cout << mn << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 float distance(long long x, long long y, long long a, long long b) {
   return sqrt((x - y) * (x - y) + (a - b) * (a - b));
 }
 int32_t main() {
   float n, x1, y1, x2, y2;
   cin >> n >> x1 >> y1 >> x2 >> y2;
   if ((x1 == x2 && (x1 == n || x1 == 0)) ||
       (y1 == y2 && (y1 == 0 || y2 == n))) {
     cout << abs(x1 - x2) + abs(y1 - y2);
     return 0;
   }
   long long path1 = 0, path2 = 0;
   if (abs(x1 - x2) == n) {
     path1 = 2 * n - (y1 + y2);
     path2 = y1 + y2;
     cout << (path1 > path2 ? path2 : path1) + n;
     return 0;
   }
   if (abs(y1 - y2) == n) {
     path1 = 2 * n - (x1 + x2);
     path2 = x1 + x2;
     cout << (path1 > path2 ? path2 : path1) + n;
     return 0;
   }
   cout << abs(x1 - x2) + abs(y2 - y1);
 }


#include <bits/stdc++.h>
 using namespace std;
 const int mod = 998244353;
 const int maxn = 1e3 + 10;
 int n, m, mp[maxn][maxn], cnt, dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
 bool vis[maxn][maxn];
 vector<int> ans;
 void dfs(int x, int y) {
   if (vis[x][y] || x <= 0 || x > n || y <= 0 || y > m) return;
   vis[x][y] = 1, ++cnt;
   for (int i = 0; i < 4; ++i)
     if (!(mp[x][y] & (1 << i))) dfs(x + dx[i], y + dy[i]);
 }
 void solve() {
   scanf( %d%d , &n, &m);
   for (int i = 1; i <= n; ++i)
     for (int j = 1; j <= m; ++j) scanf( %d , &mp[i][j]);
   for (int i = 1; i <= n; ++i)
     for (int j = 1; j <= m; ++j)
       if (!vis[i][j]) cnt = 0, dfs(i, j), ans.push_back(cnt);
   sort(ans.begin(), ans.end());
   for (int i = ans.size() - 1; ~i; --i) printf( %d  , ans[i]);
 }
 int main() {
   solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, t;
 char v[500010];
 vector<pair<int, int> > inter;
 int memo[500010];
 int calcula(int ind) {
   int res = 0;
   int x = ind;
   int ini = 0;
   int fim = 0;
   bool erro = false;
   int lh = -1;
   inter.clear();
   for (int i = 0; i < (n); i++) {
     if (v[i] == 'H') {
       x--;
       lh = i;
     } else if (v[i] == 'S') {
       x++;
     }
     if (x == -1 && !erro) {
       ini = i;
       erro = true;
     }
     if (x == 0 && erro) {
       if (i < n && v[i + 1] == 'H') continue;
       inter.push_back(make_pair(ini, i));
       erro = false;
     }
   }
   if (x < 0) return false;
   if ((int)inter.size() == 0) {
     if (lh < t) return true;
     return false;
   }
   int i = 0;
   res = inter[0].first;
   fim = max(lh, inter[(int)inter.size() - 1].second);
   memo[inter.size()] = 0;
   int next;
   for (int i = (int)inter.size() - 1; i >= 0; i--) {
     if (i + 1 < (int)inter.size()) {
       next = inter[i + 1].first - 1;
     } else {
       next = fim;
     }
     memo[i] = min((inter[i].second - inter[i].first + 1) * 3 - 2 + memo[i + 1] +
                       (next - inter[i].second),
                   (fim - inter[i].first + 1) * 2 - 1);
   }
   res += memo[0];
   if (res <= t) return true;
   return false;
 }
 int main() {
   scanf( %d %d , &n, &t);
   for (int i = 0; i < (n); i++) {
     scanf(  %c , &v[i]);
   }
   int inicio = 0;
   int fim = n;
   int res = -1;
   while (1) {
     if (inicio > fim) break;
     int meio = (inicio + fim) / 2;
     if (calcula(meio)) {
       res = meio;
       fim = meio - 1;
     } else {
       inicio = meio + 1;
     }
   }
   printf( %d
 , res);
   return 0;
 }


#include <bits/stdc++.h>
 int main() {
   int t = 1, i, n;
   scanf( %d , &n);
   for (i = 1; i <= n - 1; i++) {
     t = (t + i - 1) % n + 1;
     printf( %d  , t);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct Point {
   int x, y;
   Point(int x = 0, int y = 0) : x(x), y(y) {}
   Point operator-(const Point z) const { return Point(x - z.x, y - z.y); }
   friend long long Cross(Point a, Point b) {
     return 1ll * a.x * b.y - 1ll * a.y * b.x;
   }
 } a[2010], b[2010];
 bool f[2010];
 char ch[2010];
 int main(int argc, char const *argv[]) {
   int n;
   cin >> n;
   for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;
   cin >> ch;
   int p = 0;
   for (int i = 1; i < n; i++)
     if (a[i].y < a[p].y || a[i].y == a[p].y && a[i].x < a[p].x) p = i;
   f[p] = 1;
   cout << p + 1 << ' ';
   for (int i = 0; !i || ch[i - 1]; i++) {
     int x = -1;
     for (int j = 0; j < n; j++)
       if (!f[j]) {
         if (x == -1)
           x = j;
         else if (ch[i] == 'L')
           if (Cross(a[j] - a[p], a[x] - a[p]) > 0)
             x = j;
           else
             ;
         else if (Cross(a[j] - a[p], a[x] - a[p]) < 0)
           x = j;
       }
     cout << x + 1 << ' ';
     f[x] = 1;
     p = x;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 typedef pair<int, int> pii;
 typedef long long ll;
 typedef unsigned long long ull;
 template <typename T>
 bool umax(T& a, const T& b) {
   return b <= a ? false : (a = b, true);
 }
 template <typename T>
 bool umin(T& a, const T& b) {
   return b >= a ? false : (a = b, true);
 }
 template <typename T>
 void V2A(T a[], const vector<T>& b) {
   for (int i = 0; i < b.size(); i++) a[i] = b[i];
 }
 template <typename T>
 void A2V(vector<T>& a, const T b[]) {
   for (int i = 0; i < a.size(); i++) a[i] = b[i];
 }
 const double PI = acos(-1.0);
 const int INF = 1e9 + 7;
 const int maxn = 2e3 + 7;
 bool plot[maxn][maxn];
 int r[maxn][maxn];
 int n, m, k;
 int check(int row, int col) {
   if (col >= 0 && col < m) return true;
   return false;
 }
 int main() {
   cin >> n >> m >> k;
   for (int i = 0; i < k; i++) {
     int x, y;
     scanf( %d%d , &x, &y);
     x--;
     y--;
     if (!plot[x][y]) {
       printf( %d %d
 , x + 1, y + 1);
       plot[x][y] = true;
       continue;
     }
     for (int d = 1; d <= 3; d++) {
       int Max = min(n, x + d + 1);
       for (int row = max(0, x - d); row < Max; row++) {
         int t = d - abs(x - row), col1 = y - t, col2 = y + t;
         if (check(row, col1)) umax(r[x][y], r[row][col1] - d);
         if (check(row, col2)) umax(r[x][y], r[row][col2] - d);
       }
     }
     for (int d = r[x][y] + 1;; d++) {
       int Max = min(n, x + d + 1);
       bool ok = false;
       for (int row = max(0, x - d); row < Max; row++) {
         int t = d - abs(x - row), col1 = y - t, col2 = y + t;
         if (check(row, col1) && !plot[row][col1]) {
           ok = true;
           printf( %d %d
 , row + 1, col1 + 1);
           plot[row][col1] = true;
           break;
         }
         if (check(row, col2) && !plot[row][col2]) {
           ok = true;
           printf( %d %d
 , row + 1, col2 + 1);
           plot[row][col2] = true;
           break;
         }
       }
       if (ok) {
         r[x][y] = d - 1;
         break;
       }
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct node {
   int p, q;
 } a[1009];
 bool cmp(node a, node b) {
   if (a.p != b.p) return a.p < b.p;
   if (a.p == b.p) return a.q > b.q;
 }
 int main() {
   int m, n, i;
   scanf( %d%d , &m, &n);
   for (i = 1; i <= n; i++) {
     scanf( %d%d , &a[i].p, &a[i].q);
   }
   sort(a + 1, a + 1 + n, cmp);
   int sum = m;
   for (i = 1; i <= n; i++) {
     if (sum > a[i].p)
       sum += a[i].q;
     else
       break;
   }
   if (i == n + 1)
     printf( YES
 );
   else
     printf( NO
 );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   string s;
   cin >> s;
   int len = s.size();
   cout << s[0];
   int flag = 0;
   for (int i = 1; i < len; i++) {
     if (s[i] == 'd' && s[i + 1] == 'o' && s[i + 2] == 't' &&
         (i + 2 != len - 1)) {
       cout <<  . ;
       i += 2;
     } else if (s[i] == 'a' && s[i + 1] == 't' && flag == 0) {
       cout <<  @ ;
       i++;
       flag = 1;
     } else
       cout << s[i];
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.tie(nullptr);
   cerr.tie(nullptr);
   long long n, k, a, z = 0;
   cin >> n >> k;
   vector<int> x(n), c(n);
   for (int i = 0; i < n; i++) cin >> x[i];
   cin >> a;
   for (int i = 0; i < n; i++) cin >> c[i];
   multiset<int> ms;
   for (int i = 0; i < n; i++) {
     ms.insert(c[i]);
     while (k < x[i]) {
       if (ms.size() == 0) {
         cout <<  -1
 ;
         return 0;
       } else {
         k += a;
         z += *ms.begin();
         ms.erase(ms.begin());
       }
     }
   }
   cout << z << '
';
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 1e9 * 2;
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int t;
   cin >> t;
   while (t--) {
     int n;
     cin >> n;
     string s;
     cin >> s;
     int l = 0, r = n - 1;
     while (l <= n && s[l] == '0') l++;
     while (r >= 0 && s[r] == '0') r--;
     int ans;
     if (l > r)
       ans = n;
     else
       ans = max(r + 1, n - l) * 2;
     cout << ans <<
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 #pragma comment(linker,  /stack:200000000 )
 #pragma GCC optimize( Ofast )
 #pragma GCC target( \n      sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )
 #pragma GCC optimize( -ffloat-store )
 const long long INF = 0xFFFFFFFFFFFFFFFL;
 const long long N = 1e9 + 7;
 vector<long long> pri;
 void yo(int n) {
   bool prime[n + 1];
   memset(prime, true, sizeof(prime));
   for (int p = 2; p * p <= n; p++) {
     if (prime[p] == true) {
       for (int i = p * p; i <= n; i += p) prime[i] = false;
     }
   }
   for (int p = 2; p <= n; p++)
     if (prime[p]) pri.push_back(p);
 }
 void solve() {
   long long n;
   cin >> n;
   for (long long i = 1; i < 1001; i++) {
     if (!binary_search((pri).begin(), (pri).end(), n * i + 1)) {
       cout << i;
       return;
     }
   }
 }
 int32_t main(int32_t argc, char **argv) {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   yo(1000003);
   long long t;
   t = 1;
   while (t--) solve();
   cerr <<

        <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
        <<  ms
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n, k;
   scanf( %d%d , &n, &k);
   int mat[n + 1][n + 1];
   for (int i = 1; i <= n; i++) {
     for (int j = 1; j <= n; j++) mat[i][j] = 0;
   }
   int br = 0;
   for (int i = 1; i <= n; i += 2) {
     for (int j = 1, x = i; j <= n && x <= n; j++, x++) {
       mat[x][j] = 1;
       br++;
     }
   }
   for (int i = 3; i <= n; i += 2) {
     for (int h = 1, j = i; h <= n && j <= n; h++, j++) {
       mat[h][j] = 1;
       br++;
     }
   }
   if (br < k) {
     printf( NO );
     return 0;
   }
   printf( YES
 );
   for (int i = 1; i <= n; i++) {
     for (int j = 1; j <= n; j++) {
       if (k > 0) {
         if (mat[i][j]) {
           printf( L );
           k--;
         } else
           printf( S );
       } else
         printf( S );
     }
     printf(
 );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   int a = 1;
   int b = 2;
   bool ok = true;
   int k;
   for (int i = 0; i < n; i++) {
     cin >> k;
     if (k != a && k != b) {
       ok = false;
     } else {
       if (b == 3 && a == 1) {
         a = min(2, k);
         b = max(2, k);
       } else if (b == 2 && a == 1) {
         a = min(3, k);
         b = max(3, k);
       } else if (b == 3 && a == 2) {
         a = min(1, k);
         b = max(1, k);
       }
     }
   }
   if (ok) {
     cout <<  YES ;
   } else {
     cout <<  NO ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 5, M = 20;
 int n, m, a[N], b[M], ans[M];
 set<vector<int> > use[M + 1];
 void find(int y, vector<int>& current) {
   if (y == m) {
     for (int i = 0; i < n; i++)
       if (a[i] != current[i]) return;
     for (int i = 0; i < n; i++) {
       for (int j = 0; j < m; j++) cout <<  .* [(bool)(ans[j] & (1 << i))];
       cout << endl;
     }
     exit(0);
   }
   if (use[y].find(current) != use[y].end()) return;
   for (int i = 0; i < (1 << n); i++) {
     if ((((((((i << 1) | i) ^ i) >> 1) >> 0)) & 1) +
             (((((((i << 1) | i) ^ i) >> 1) >> 1)) & 1) +
             (((((((i << 1) | i) ^ i) >> 1) >> 2)) & 1) +
             (((((((i << 1) | i) ^ i) >> 1) >> 3)) & 1) +
             (((((((i << 1) | i) ^ i) >> 1) >> 4)) & 1) !=
         b[y])
       continue;
     ans[y] = i;
     vector<int> newCur = current;
     bool flag = true;
     for (int j = 0; j < n; j++) {
       if (ans[y] & (1 << j) && (!y || !(ans[y - 1] & (1 << j)))) newCur[j]++;
       if (newCur[j] > a[j] || newCur[j] < a[j] - ((m - y) / 2)) {
         flag = false;
         break;
       }
     }
     if (flag) find(y + 1, newCur);
   }
   use[y].insert(current);
 }
 int main() {
   cin >> n >> m;
   for (int i = 0; i < n; i++) cin >> a[i];
   for (int i = 0; i < m; i++) cin >> b[i];
   vector<int> c(n + 1, 0);
   find(0, c);
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1100;
 int n;
 char s[maxn + 10];
 int data[maxn + 10];
 int dp[maxn + 10][2];
 int main() {
   cin >> n;
   getchar();
   gets(s);
   int i;
   for (i = 0; s[i]; i++) data[i] = s[i] - '0';
   if (i == 1)
     printf( 0
 );
   else {
     int ans1 = 0, ans2 = 0;
     for (int j = 0; j < i; j++) {
       if ((j & 1) != data[j]) ans1++;
     }
     for (int j = 0; j < i; j++) {
       if ((j & 1) == data[j]) ans2++;
     }
     printf( %d
 , min(ans1, ans2));
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 200005;
 const int D = 30;
 struct node {
   int a, b;
 };
 vector<int> road[N], h[N];
 vector<node> q[N];
 int n, m, t, fa[N][D + 1], w[N][D + 1], head[N], sum[N], ans[N], g[N];
 int cnt, tot, dep[N], id[N], size[N], c[N];
 int lowbit(int x) { return x & -x; }
 void update(int x) {
   for (int i = x; i <= n; i += lowbit(i)) {
     c[i] += 1;
   }
 }
 int check(int x) {
   int tmp = 0;
   for (int i = x; i >= 1; i -= lowbit(i)) {
     tmp += c[i];
   }
   return tmp;
 }
 struct edge {
   int to, nxt;
 } e[N * 2];
 void add(int u, int v) {
   cnt++;
   e[cnt].nxt = head[u];
   e[cnt].to = v;
   head[u] = cnt;
 }
 void dfs1(int u, int deep) {
   dep[u] = deep;
   id[u] = ++tot;
   size[u] = 1;
   for (int i = head[u]; i; i = e[i].nxt) {
     int v = e[i].to;
     if (v == fa[u][0]) continue;
     dfs1(v, deep + 1);
     size[u] += size[v];
   }
 }
 void dfs2(int u) {
   g[u] = u;
   for (int i = 0; i < h[u].size(); i++) {
     if (dep[h[u][i]] < dep[g[u]]) g[u] = h[u][i];
   }
   for (int i = head[u]; i; i = e[i].nxt) {
     int v = e[i].to;
     if (v == fa[u][0]) continue;
     dfs2(v);
     if (dep[g[v]] < dep[g[u]]) g[u] = g[v];
   }
   w[u][0] = g[u];
 }
 int lca(int x, int y) {
   if (dep[x] < dep[y]) swap(x, y);
   for (int i = D; i >= 0; i--) {
     if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
   }
   if (x == y) return x;
   for (int i = D; i >= 0; i--) {
     if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
   }
   return fa[x][0];
 }
 node work(int x, int LCA) {
   if (x == LCA) return (node){x, 0};
   int tmp = 0;
   for (int i = D; i >= 0; i--)
     if (dep[w[x][i]] > dep[LCA]) x = w[x][i], tmp += (1 << i);
   if (w[x][0] == x) return (node){x, -1};
   return (node){x, tmp};
 }
 int main() {
   scanf( %d , &n);
   for (int i = 2; i <= n; i++) {
     scanf( %d , &fa[i][0]);
     add(fa[i][0], i);
     add(i, fa[i][0]);
   }
   dfs1(1, 1);
   for (int i = 1; i <= D; i++)
     for (int j = 1; j <= n; j++) {
       fa[j][i] = fa[fa[j][i - 1]][i - 1];
     }
   scanf( %d , &m);
   for (int i = 1; i <= m; i++) {
     int x, y;
     scanf( %d%d , &x, &y);
     int c = lca(x, y);
     if (id[x] > id[y]) swap(x, y);
     road[id[x]].push_back(id[y]);
     if (dep[c] < dep[x]) h[x].push_back(c);
     if (dep[c] < dep[y]) h[y].push_back(c);
   }
   dfs2(1);
   for (int i = 1; i <= n; i++) {
   }
   for (int i = 1; i <= D; i++)
     for (int j = 1; j <= n; j++) {
       w[j][i] = w[w[j][i - 1]][i - 1];
     }
   scanf( %d , &t);
   for (int i = 1; i <= t; i++) {
     int x, y;
     scanf( %d%d , &x, &y);
     int c = lca(x, y);
     node A = work(x, c);
     node B = work(y, c);
     if (A.b == -1 || B.b == -1) {
       ans[i] = -1;
       continue;
     }
     if (x == c || y == c) {
       ans[i] = A.b + B.b + 1;
       continue;
     }
     ans[i] = A.b + B.b + 2;
     x = A.a;
     y = B.a;
     if (id[x] > id[y]) swap(x, y);
     q[id[x] - 1].push_back((node){y, -i});
     q[id[x] + size[x] - 1].push_back((node){y, i});
   }
   for (int i = 1; i <= n; i++) {
     for (int j = 0; j < road[i].size(); j++) update(road[i][j]);
     for (int j = 0; j < q[i].size(); j++) {
       int num = (q[i][j].b > 0 ? 1 : -1);
       int x = q[i][j].a;
       int y = q[i][j].b * num;
       sum[y] += num * (check(id[x] + size[x] - 1) - check(id[x] - 1));
     }
   }
   for (int i = 1; i <= t; i++) {
     printf( %d
 , ans[i] - (sum[i] > 0));
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct prog {
   int i;
   int cmp;
 } a[100005];
 int ans[100005];
 bool cmp(prog a, prog b) {
   if (a.cmp == b.cmp)
     return a.i < b.i;
   else
     return a.cmp < b.cmp;
 }
 int main() {
   int n, m;
   while (cin >> n >> m) {
     priority_queue<prog> q;
     int i, j;
     for (i = 0; i < m; i++) {
       a[i].i = i + 1;
       a[i].cmp = (int)fabs((m + 1) / 2.0 - i - 1);
     }
     sort(a, a + m, cmp);
     for (i = 0; i < n; i++) {
       int k = i % m;
       cout << a[k].i << endl;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxN = 3e5 + 11, maxlg = 2e1;
 typedef int i_N[maxN];
 typedef long long l_N[maxN];
 int N, M, Q, par[maxN][maxlg], umax[maxN][maxlg], umin[maxN][maxlg];
 vector<int> adj[maxN], pos[maxN];
 vector<pair<int, int> > query[maxN];
 pair<int, int> edge[maxN];
 i_N P, depth, mark, F;
 l_N cnt, sum, mus, ans;
 int lg(int x) {
   for (int i = maxlg; i; i--)
     if ((1 << i) <= x) return i;
   return (1 - 1);
 }
 int get_root(int u) {
   if (P[u] < (1 - 1)) return u;
   return P[u] = get_root(P[u]);
 }
 void join(int u, int v) {
   if (P[u] > P[v]) swap(P[u], P[v]);
   P[u] += P[v];
   P[v] = u;
 }
 void dfs(int u) {
   for (int i = 1, x = lg(depth[u]); i <= x; i++) {
     par[u][i] = par[par[u][i - 1]][i - 1];
     umax[u][i] = max(umax[u][i - 1], umax[par[u][i - 1]][i - 1]);
     umin[u][i] = min(umin[u][i - 1], umin[par[u][i - 1]][i - 1]);
   }
   for (int i = (1 - 1); i < (int)adj[u].size(); i++) {
     int v = adj[u][i];
     if (par[v][(1 - 1)]) continue;
     par[v][(1 - 1)] = u;
     umax[v][(1 - 1)] = max(u, v);
     umin[v][(1 - 1)] = min(u, v);
     depth[v] = depth[u] + 1;
     dfs(v);
   }
 }
 void get(int u, int v, int& x, int& y) {
   if (depth[u] < depth[v]) swap(u, v);
   for (int i = lg(depth[u]); i >= (1 - 1); i--)
     if (depth[u] - (1 << i) >= depth[v]) {
       x = min(x, umin[u][i]);
       y = max(y, umax[u][i]);
       u = par[u][i];
     }
   for (int i = lg(depth[u]); i >= (1 - 1); i--)
     if (par[u][i] != par[v][i]) {
       x = min(x, min(umin[u][i], umin[v][i]));
       y = max(y, max(umax[u][i], umax[v][i]));
       u = par[u][i];
       v = par[v][i];
     }
   if (u != v) {
     x = min(x, min(umin[u][(1 - 1)], umin[v][(1 - 1)]));
     y = max(y, max(umax[u][(1 - 1)], umax[v][(1 - 1)]));
   }
 }
 void update(long long* bit, int x, int v) {
   for (int i = x; i <= N; i |= i + 1) bit[i] += v;
 }
 long long get_bit(long long* bit, int x) {
   long long res = (1 - 1);
   for (int i = x; i >= 1; i = (i & (i + 1)) - 1) res += bit[i];
   return res;
 }
 long long get_bit(long long* bit, int l, int r) {
   return get_bit(bit, r) - get_bit(bit, l - 1);
 }
 int main() {
   scanf( %d %d
 , &N, &M);
   for (int i = 1; i <= M; i++) {
     int u, v;
     scanf( %d %d
 , &u, &v);
     edge[i] = pair<int, int>(u, v);
   }
   memset(P, -1, sizeof(P));
   for (int i = 1; i <= M; i++) {
     int u = edge[i].first, v = edge[i].second;
     int r1 = get_root(u), r2 = get_root(v);
     if (r1 != r2) {
       mark[i] = 1;
       join(r1, r2);
       adj[u].push_back(v);
       adj[v].push_back(u);
     }
   }
   for (int u = 1; u <= N; u++)
     if (!par[u][(1 - 1)]) {
       par[u][(1 - 1)] = -1;
       dfs(u);
     }
   for (int i = 1; i <= M; i++)
     if (!mark[i]) {
       int u = edge[i].first, v = edge[i].second;
       int x = 1e9, y = (1 - 1);
       get(u, v, x, y);
       F[x] = y;
     }
   F[N + 1] = N + 1;
   for (int i = N; i >= 1; i--) {
     if (F[i] == (1 - 1))
       F[i] = F[i + 1];
     else
       F[i] = min(F[i], F[i + 1]);
     pos[F[i]].push_back(i);
   }
   scanf( %d
 , &Q);
   for (int i = 1; i <= Q; i++) {
     int l, r;
     scanf( %d %d
 , &l, &r);
     query[r].push_back(pair<int, int>(l, i));
   }
   for (int i = 1; i <= N; i++) {
     update(cnt, i, 1);
     update(sum, i, i - 1);
     for (int j = (1 - 1); j < (int)pos[i].size(); j++) {
       int p = pos[i][j];
       update(cnt, p, -1);
       update(sum, p, 1 - p);
       update(mus, p, i - p);
     }
     for (int j = (1 - 1); j < (int)query[i].size(); j++) {
       int r = i, l = query[i][j].first, id = query[i][j].second;
       long long C = get_bit(cnt, l, r);
       long long S = get_bit(sum, l, r);
       long long T = get_bit(mus, l, r);
       ans[id] += C * i - S + T;
     }
   }
   for (int i = 1; i <= Q; i++) printf( %I64d
 , ans[i]);
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T, class L>
 bool smax(T& x, L y) {
   return x < y ? (x = y, 1) : 0;
 }
 template <class T, class L>
 bool smin(T& x, L y) {
   return x > y ? (x = y, 1) : 0;
 }
 const int maxn = 16;
 int n, a[maxn], b[maxn][maxn], ex, x[maxn];
 bool mark[maxn];
 vector<vector<int> > all;
 vector<int> todo;
 int fond(int x) {
   for (int i = 0; i < n * n; i++)
     if (!mark[i] && a[i] == x) return i;
   return -1;
 }
 void back(int s = 0) {
   if (s == n) {
     for (int i = 0, sum = 0; i < n; i++, sum = 0) {
       for (int j = 0; j < n; j++) sum += b[j][i];
       if (sum != ex) return;
     }
     {
       int sum = 0;
       for (int i = 0; i < n; i++) sum += b[i][i];
       if (sum != ex) return;
     }
     {
       int sum = 0;
       for (int i = 0; i < n; i++) sum += b[i][n - i - 1];
       if (sum != ex) return;
     }
     for (int i = 0; i < n; i++, cout << '
')
       for (int j = 0; j < n; j++) cout << b[i][j] << ' ';
     exit(0);
   }
   if (s == n - 1) {
     fill(b[n - 1], b[n - 1] + n, ex);
     for (int i = 0; i < n - 1; i++)
       for (int j = 0; j < n; j++) b[n - 1][j] -= b[i][j];
     int i = 0;
     for (int tmp; i < n; i++)
       if (~(tmp = fond(b[n - 1][i])))
         mark[tmp] = 1, todo.push_back(tmp);
       else
         break;
     if (i == n) back(n);
     for (auto x : todo) mark[x] = 0;
     todo.clear();
   }
   for (auto v : all) {
     bool reval = 1;
     for (auto x : v)
       if (mark[x]) {
         reval = 0;
         break;
       }
     if (!reval) continue;
     do {
       for (int i = 0; i < n; i++) b[s][i] = a[v[i]], mark[v[i]] = 1;
       back(s + 1);
       for (int i = 0; i < n; i++) mark[v[i]] = 0;
     } while (next_permutation(v.begin(), v.end()));
   }
 }
 void tof(int idx) {
   if (idx == 4 && x[0] + x[1] + x[2] + x[3] != ex) return;
   if (idx == 8 && x[4] + x[5] + x[6] + x[7] != ex) return;
   if (idx == 12 && x[8] + x[9] + x[10] + x[11] != ex) return;
   if (idx == 16 && x[12] + x[13] + x[14] + x[15] != ex) return;
   if (idx == 13 && x[0] + x[4] + x[8] + x[12] != ex) return;
   if (idx == 14 && x[1] + x[5] + x[9] + x[13] != ex) return;
   if (idx == 15 && x[2] + x[6] + x[10] + x[14] != ex) return;
   if (idx == 16 && x[3] + x[7] + x[11] + x[15] != ex) return;
   if (idx == 13 && x[3] + x[6] + x[9] + x[12] != ex) return;
   if (idx == 16 && x[0] + x[5] + x[10] + x[15] != ex) return;
   if (idx == 16) {
     for (int i = 0; i < n; i++, cout << '
')
       for (int j = 0; j < n; j++) cout << x[i * 4 + j] << ' ';
     exit(0);
   }
   for (int i = 0; !(i >> 4); ++i)
     if (!mark[i]) {
       x[idx] = a[i], mark[i] = 1;
       tof(idx + 1);
       mark[i] = 0;
     }
 }
 int main() {
   srand(time(0));
   ios::sync_with_stdio(0), cin.tie();
   cin >> n;
   for (int i = 0; i < n * n; i++) cin >> a[i], ex += a[i];
   random_shuffle(a, a + n * n);
   ex /= n;
   cout << ex << '
';
   if (n < 4) {
     for (int i = 0; i < 1 << n * n; i++)
       if (__builtin_popcount(i) == n) {
         int sum = 0;
         for (int j = 0; j < n * n; j++) sum += (i >> j & 1) * a[j];
         if (sum == ex) {
           all.push_back({});
           for (int j = 0; j < n * n; j++)
             if (i >> j & 1) all.back().push_back(j);
           sort(all.back().begin(), all.back().end());
         }
       }
     return back(), 0;
   }
   tof(0);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 set<pair<pair<int, int>, pair<int, int> > > s;
 vector<int> ed[2][300000];
 int n, m, k;
 int a[300000], b[300000];
 long long ans[300000];
 bool add(int x, int y, int dx, int dy) {
   pair<pair<int, int>, pair<int, int> > g =
       make_pair(make_pair(x, y), make_pair(dx, dy));
   if (s.find(g) != s.end()) return false;
   s.insert(g);
   return true;
 }
 void go(int x, int y, int dx, int dy, long long t) {
   int tt = 1;
   int d = x - y + m;
   if (dx - dy != 0) {
     tt = 0;
     d = x + y;
   }
   bool f = add(x, y, dx, dy);
   if (!f) return;
   for (int j = 0; j < ed[tt][d].size(); j++) {
     int kx = a[ed[tt][d][j]];
     int ky = b[ed[tt][d][j]];
     kx = kx - x;
     ky = ky - y;
     kx = kx / dx;
     ky = ky / dy;
     int g = ed[tt][d][j];
     if (ans[g] != -1) continue;
     ans[g] = t + min(kx, ky);
   }
   if (dx == 1 && dy == 1) {
     int v = min(n - x, m - y);
     x += v;
     y += v;
     if (x == n && y == m) return;
     if (y == m)
       go(x, y, 1, -1, t + v);
     else
       go(x, y, -1, 1, t + v);
   }
   if (dx == -1 && dy == -1) {
     int v = min(x, y);
     x -= v;
     y -= v;
     if (x == 0 && y == 0) return;
     if (y == 0)
       go(x, y, -1, 1, t + v);
     else
       go(x, y, 1, -1, t + v);
   }
   if (dx == 1 && dy == -1) {
     int v = min(n - x, y);
     x += v;
     y -= v;
     if (x == n && y == 0) return;
     if (y == 0)
       go(x, y, 1, 1, t + v);
     else
       go(x, y, -1, -1, t + v);
   }
   if (dx == -1 && dy == 1) {
     int v = min(x, m - y);
     x -= v;
     y += v;
     if (x == 0 && y == m) return;
     if (x == 0)
       go(x, y, 1, 1, t + v);
     else
       go(x, y, -1, -1, t + v);
   }
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cin >> n >> m >> k;
   for (int i = 1; i <= k; i++) ans[i] = -1;
   for (int i = 1; i <= k; i++) {
     cin >> a[i] >> b[i];
     ed[0][a[i] + b[i]].push_back(i);
     ed[1][a[i] - b[i] + m].push_back(i);
   }
   go(0, 0, 1, 1, 0);
   for (int i = 1; i <= k; i++) cout << ans[i] <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline long long read() {
   char ch = getchar();
   long long x = 0, f = 1;
   while (ch < '0' || ch > '9') f = ch == '-' ? -1 : 1, ch = getchar();
   while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
   return x * f;
 }
 int main(int argc, char *argv[]) {
   ios::sync_with_stdio(false);
   cin.tie(0);
   long long base = (1LL << 7) - 1;
   long long res = 0, cur;
   printf( ? );
   for (long long i = (1); i <= (100); i += (1)) printf(  %lld , i);
   putchar('
');
   fflush(stdout);
   cur = read();
   res += (cur >> 7) << 7;
   printf( ? );
   for (long long i = (1); i <= (100); i += (1)) printf(  %lld , i << 7);
   putchar('
');
   fflush(stdout);
   cur = read();
   res += cur & base;
   printf( ! %lld
 , res);
   fflush(stdout);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAX = 205, MAXL = 1 << 20;
 char qq[MAXL];
 char s[MAX][MAX];
 pair<int, int> kamo[MAX][MAX];
 vector<pair<int, int> > R[MAX][MAX];
 int indeg[MAX][MAX];
 int cik[MAX][MAX];
 int imacik[MAX * MAX][10];
 int brred, brstup;
 int pr[10], ps[10];
 int bio[MAX][MAX];
 int dokle[MAX][MAX];
 int imaq[MAXL][10];
 int brc = 1;
 int Vani(int red, int stup) {
   return red < 0 || red >= brred || stup < 0 || stup >= brstup;
 }
 void Osisaj() {
   queue<pair<int, int> > Q;
   for (int i = 0; i < brred; i++)
     for (int j = 0; j < brstup; j++)
       if (!indeg[i][j]) Q.push(pair<int, int>(i, j));
   for (; !Q.empty();) {
     pair<int, int> tmp = Q.front();
     bio[tmp.first][tmp.second] = 1;
     Q.pop();
     pair<int, int> nn = kamo[tmp.first][tmp.second];
     indeg[nn.first][nn.second]--;
     if (!indeg[nn.first][nn.second]) Q.push(nn);
   }
   for (int i = 0; i < brred; i++) {
     for (int j = 0; j < brstup; j++) {
       if (!bio[i][j]) {
         int sz = 0;
         for (pair<int, int> tmp = pair<int, int>(i, j);
              tmp != pair<int, int>(i, j) || !sz;
              sz++, tmp = kamo[tmp.first][tmp.second]) {
           bio[tmp.first][tmp.second] = 1;
           cik[tmp.first][tmp.second] = brc;
           imacik[brc][s[tmp.first][tmp.second] - '0'] = 1;
         }
         brc++;
       }
     }
   }
 }
 int Rijesi() {
   queue<pair<int, int> > Q;
   memset(dokle, 0, sizeof dokle);
   int len = (int)strlen(qq);
   for (int i = 0; i <= len; i++)
     for (int j = 0; j < 10; j++) imaq[i][j] = 0;
   for (int i = len - 1; i >= 0; i--) {
     imaq[i][qq[i] - '0'] = 1;
     for (int j = 0; j < 10; j++) imaq[i][j] |= imaq[i + 1][j];
   }
   for (int i = 0; i < brred; i++)
     for (int j = 0; j < brstup; j++) {
       indeg[i][j] = (int)R[i][j].size();
       if (!indeg[i][j]) Q.push(pair<int, int>(i, j));
     }
   for (; !Q.empty();) {
     pair<int, int> tmp = Q.front();
     Q.pop();
     int nd = dokle[tmp.first][tmp.second];
     if (s[tmp.first][tmp.second] == qq[nd]) nd++;
     if (nd == len) return 1;
     pair<int, int> nn = kamo[tmp.first][tmp.second];
     dokle[nn.first][nn.second] = max(dokle[nn.first][nn.second], nd);
     indeg[nn.first][nn.second]--;
     if (!indeg[nn.first][nn.second]) Q.push(nn);
   }
   for (int i = 0; i < brred; i++) {
     for (int j = 0; j < brstup; j++) {
       if (cik[i][j]) {
         int da = 1;
         int indc = cik[i][j];
         for (int k = 0; k < 10; k++)
           if (!imacik[indc][k] && imaq[dokle[i][j]][k]) da = 0;
         if (da) return 1;
       }
     }
   }
   return 0;
 }
 int main() {
   int brq;
   scanf( %d%d%d , &brred, &brstup, &brq);
   for (int i = 0; i < brred; i++) scanf( %s , s[i]);
   for (int i = 0; i < 10; i++) scanf( %d%d , &pr[i], &ps[i]);
   for (int i = 0; i < brred; i++) {
     for (int j = 0; j < brstup; j++) {
       int nr = i + pr[s[i][j] - '0'];
       int ns = j + ps[s[i][j] - '0'];
       if (Vani(nr, ns))
         kamo[i][j] = pair<int, int>(i, j);
       else
         kamo[i][j] = pair<int, int>(nr, ns);
       indeg[kamo[i][j].first][kamo[i][j].second]++;
       R[kamo[i][j].first][kamo[i][j].second].push_back(pair<int, int>(i, j));
     }
   }
   Osisaj();
   for (int i = 0; i < brq; i++) {
     scanf( %s , qq);
     printf( %s
 , Rijesi() ?  YES  :  NO );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 struct Segtree {
   int N;
   vector<T> seg, lazy;
   Segtree(int _n) : N(_n) {
     seg.resize(4 * N, 0);
     lazy.resize(4 * N, 0);
   }
   T join(T x, T y) { return max(x, y); }
   void push(int x, int s, int e) {
     if (!lazy[x]) return;
     seg[x] = max(seg[x], lazy[x]);
     if (s != e) {
       lazy[2 * x] = max(lazy[2 * x], lazy[x]);
       lazy[2 * x + 1] = max(lazy[2 * x + 1], lazy[x]);
     }
     lazy[x] = 0;
   }
   void build(int x, int s, int e) {
     if (s == e) {
       seg[x] = 0;
       return;
     }
     int mid = (s + e) >> 1;
     build(2 * x, s, mid);
     build(2 * x + 1, mid + 1, e);
     seg[x] = join(seg[2 * x], seg[2 * x + 1]);
   }
   void update(int x, int s, int e, int l, int r, T val) {
     push(x, s, e);
     if (s > r || e < l) return;
     if (s >= l && e <= r) {
       lazy[x] = val;
       push(x, s, e);
       return;
     }
     int mid = (s + e) >> 1;
     update(2 * x, s, mid, l, r, val);
     update(2 * x + 1, mid + 1, e, l, r, val);
     seg[x] = join(seg[2 * x], seg[2 * x + 1]);
   }
   T query(int x, int s, int e, int l, int r) {
     push(x, s, e);
     if (e < l || s > r) return 0;
     if (s >= l && e <= r) {
       return seg[x];
     }
     int mid = (s + e) >> 1;
     return join(query(2 * x, s, mid, l, r), query(2 * x + 1, mid + 1, e, l, r));
   }
   void update(int l, int r, T val) { update(1, 0, N - 1, l, r, val); }
   T query(int l, int r) { return query(1, 0, N - 1, l, r); }
 };
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int n, q;
   cin >> n >> q;
   vector<int> x(q), y(q), d(q), cc(1, 0);
   for (int i = 0; i < q; ++i) {
     char c;
     cin >> x[i] >> y[i] >> c;
     d[i] = (c == 'U');
     cc.push_back(x[i]);
     cc.push_back(y[i]);
     cc.push_back(n + 1 - x[i]);
     cc.push_back(n + 1 - y[i]);
   }
   sort(cc.begin(), cc.end());
   cc.erase(unique(cc.begin(), cc.end()), cc.end());
   Segtree<int> left(cc.size() + 1), up(cc.size() + 1);
   for (int i = 0; i < q; ++i) {
     x[i] = lower_bound(cc.begin(), cc.end(), x[i]) - cc.begin();
     y[i] = lower_bound(cc.begin(), cc.end(), y[i]) - cc.begin();
     if (d[i]) {
       int id = up.query(y[i], y[i]);
       up.update(y[i], y[i], y[i]);
       cout << cc[y[i]] - cc[id] << '
';
       id = lower_bound(cc.begin(), cc.end(), n + 1 - cc[id]) - cc.begin();
       y[i] = lower_bound(cc.begin(), cc.end(), n + 1 - cc[y[i]]) - cc.begin();
       left.update(y[i], id, x[i]);
     } else {
       int id = left.query(x[i], x[i]);
       left.update(x[i], x[i], x[i]);
       cout << cc[x[i]] - cc[id] << '
';
       id = lower_bound(cc.begin(), cc.end(), n + 1 - cc[id]) - cc.begin();
       x[i] = lower_bound(cc.begin(), cc.end(), n + 1 - cc[x[i]]) - cc.begin();
       up.update(x[i], id, y[i]);
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 void addmod(int &a, long long b) {
   a = (a + b);
   if (a >= 1000000007) a -= 1000000007;
 }
 void mulmod(int &a, long long b) { a = (a * b) % 1000000007; }
 template <class T>
 bool domin(T &a, const T &b) {
   return a > b ? a = b, 1 : 0;
 }
 template <class T>
 bool domax(T &a, const T &b) {
   return a < b ? a = b, 1 : 0;
 }
 int gi() {
   int a;
   scanf( %d , &a);
   return a;
 }
 long long gll() {
   long long a;
   scanf( %lld , &a);
   return a;
 }
 int n;
 namespace treap {
 struct treap {
   int val, size, lazy;
   long long rnd;
   treap *l, *r;
   treap()
       : val(0),
         size(0),
         lazy(0),
         rnd((((long long)rand()) << 32) | rand()),
         l(NULL),
         r(NULL) {}
   treap(int val)
       : val(val),
         size(1),
         lazy(0),
         rnd((((long long)rand()) << 32) | rand()),
         l(NULL),
         r(NULL) {}
   void push() {
     if (lazy == 0) return;
     val += lazy;
     if (l != NULL) l->lazy += lazy;
     if (r != NULL) r->lazy += lazy;
     lazy = 0;
   }
   void updateSz() {
     size = 1;
     if (l != NULL) size += l->size;
     if (r != NULL) size += r->size;
   }
 };
 typedef treap *ptreap;
 ptreap root = NULL;
 void split(ptreap tp, int key, ptreap &l, ptreap &r) {
   if (tp == NULL) {
     l = NULL, r = NULL;
     return;
   }
   tp->push();
   if (tp->val < key)
     l = tp, split(tp->r, key, tp->r, r);
   else
     r = tp, split(tp->l, key, l, tp->l);
   if (l != NULL) l->updateSz();
   if (r != NULL) r->updateSz();
 }
 pair<ptreap, ptreap> split(int v) {
   ptreap l, r;
   split(root, v, l, r);
   return {l, r};
 }
 pair<ptreap, ptreap> split(ptreap tp, int v) {
   ptreap l, r;
   split(tp, v, l, r);
   return {l, r};
 }
 void insert(ptreap &tp, ptreap v) {
   if (tp == NULL) {
     tp = v;
     return;
   }
   tp->push();
   if (v->rnd < tp->rnd)
     insert(v->val > tp->val ? tp->r : tp->l, v);
   else
     split(tp, v->val, v->l, v->r), tp = v;
   tp->updateSz();
 }
 void insert(int v) {
   ptreap tp = new treap(v);
   insert(root, tp);
 }
 void merge(ptreap &t, ptreap l, ptreap r) {
   if (l != NULL) l->push();
   if (r != NULL) r->push();
   if (l == NULL || r == NULL)
     t = (l == NULL ? r : l);
   else if (l->rnd > r->rnd)
     t = l, merge(t->r, l->r, r);
   else
     t = r, merge(t->l, l, r->l);
   if (t != NULL) t->updateSz();
 }
 void erase(ptreap &tp, int v) {
   if (tp == NULL) return;
   tp->push();
   if (v == tp->val) {
     merge(tp, tp->l, tp->r);
   } else {
     erase(v < tp->val ? tp->l : tp->r, v);
     tp->updateSz();
   }
 }
 int getmin(ptreap tp) {
   if (tp == NULL) return 0;
   tp->push();
   return tp->l == NULL ? tp->val : getmin(tp->l);
 }
 int getmax(ptreap tp) {
   if (tp == NULL) return 0;
   tp->push();
   return tp->r == NULL ? tp->val : getmax(tp->r);
 }
 void recalc(ptreap tp) {
   if (tp == NULL) return;
   tp->push();
   recalc(tp->l);
   recalc(tp->r);
   tp->updateSz();
 }
 void debug(ptreap &tp) {
   if (tp == NULL) return;
   tp->push();
   if (tp->l != NULL) debug(tp->l);
   cout <<        << tp->val <<  :  << tp->rnd <<  :  << tp->size << endl;
   if (tp->r != NULL) debug(tp->r);
 }
 }  // namespace treap
 int main() {
   n = gi();
   for (int i = 0; i < n; i++) {
     int l = gi(), r = gi();
     auto v = treap::split(l);
     auto v2 = treap::split(v.second, r);
     if (v2.first != NULL) v2.first->lazy++;
     if (v2.second != NULL) {
       auto v = treap::getmin(v2.second);
       treap::erase(v2.second, v);
     }
     treap::merge(treap::root, v.first, v2.first);
     treap::merge(treap::root, treap::root, v2.second);
     treap::insert(l);
   }
   cout << treap::root->size << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 1e5 + 10;
 int l = 1, r = 0;
 int a[MAXN], b[MAXN], now[MAXN], num[MAXN << 1], cnt[MAXN], ans[MAXN];
 map<int, int> ms;
 struct Change {
   int p, x, y;
 } c[MAXN];
 struct Query {
   int l, r, t, id;
   bool operator<(const Query &A) const {
     if (b[l] == b[A.l]) return b[r] == b[A.r] ? t < A.t : b[r] < b[A.r];
     return b[l] < b[A.l];
   }
 } q[MAXN];
 void update(int x, int d) {
   int &y = num[x];
   if (y > 0) cnt[y]--;
   y += d;
   if (y > 0) cnt[y]++;
 }
 void modify(int p, int d) {
   if (l <= p && p <= r) {
     update(a[p], -1);
     update(d, 1);
   }
   a[p] = d;
 }
 int get() {
   for (int i = 1;; i++) {
     if (!cnt[i]) return i;
   }
 }
 int main() {
   int n, m, id = 0, Time = 0, sz = 0;
   scanf( %d%d , &n, &m);
   int B = 2000;
   for (int i = 1; i <= n; i++) {
     scanf( %d , &a[i]);
     int &t = ms[a[i]];
     if (!t) t = ++sz;
     now[i] = a[i] = t;
     b[i] = i / B + 1;
   }
   while (m--) {
     int op, x, y;
     scanf( %d%d%d , &op, &x, &y);
     if (op == 1)
       q[++id] = (Query){x, y, Time, id};
     else {
       int &t = ms[y];
       if (!t) t = ++sz;
       c[++Time] = (Change){x, y = t, now[x]};
       now[x] = y;
     }
   }
   sort(q + 1, q + id + 1);
   int v = 0;
   for (int i = 1; i <= id; i++) {
     while (v < q[i].t) modify(c[v + 1].p, c[v + 1].x), v++;
     while (v > q[i].t) modify(c[v].p, c[v].y), v--;
     while (l < q[i].l) update(a[l], -1), l++;
     while (l > q[i].l) update(a[l - 1], 1), l--;
     while (r < q[i].r) update(a[r + 1], 1), r++;
     while (r > q[i].r) update(a[r], -1), r--;
     ans[q[i].id] = get();
   }
   for (int i = 1; i <= id; i++) {
     printf( %d
 , ans[i]);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long double PI = 4.0 * atan(1.0);
 void EnchomSolve() {
   int l;
   long double L;
   long double ans = 0.0;
   long double area;
   long double height;
   long double help, help2;
   scanf( %d , &l);
   L = (long double)l;
   help = L / sqrt(3.0);
   height = sqrt(L * L - help * help);
   help = (sqrt(3.0) / 2.0) * L;
   area = (help * L) / 2.0;
   ans += area * height / 3.0;
   scanf( %d , &l);
   L = (long double)l;
   help = (sqrt(2.0) / 2.0) * L;
   height = sqrt(L * L - help * help);
   area = L * L;
   ans += area * height / 3.0;
   scanf( %d , &l);
   L = (long double)l;
   help = L / (sqrt(2.0 - 2.0 * cos(72.0 * PI / 180.0)));
   height = sqrt(L * L - help * help);
   help2 = sqrt(help * help - (L / 2.0) * (L / 2.0));
   area = L * help2 / 2.0;
   area *= 5.0;
   ans += area * height / 3.0;
   printf( %.10f
 , (double)ans);
   return;
 }
 int main() {
   EnchomSolve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int a, b, c;
   cin >> a >> b >> c;
   int x = min(a, b / 2);
   int y = min(x, c / 4);
   cout << y * 7;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct EDGE {
   int to, next, w, co;
 } e[100000];
 int head[100], top, vis[100000];
 void add(int u, int v, int w, int co) {
   e[top].to = v;
   e[top].w = w;
   e[top].co = co;
   e[top].next = head[u];
   head[u] = top++;
 }
 struct _ {
   int max_flow, co;
 };
 int dis[100], vvis[100], prep[100], pree[100];
 queue<int> q;
 deque<int> node;
 void spfa(int s) {
   memset(dis, 63, sizeof(dis));
   memset(vvis, 0, sizeof(vvis));
   dis[s] = 0;
   q.push(s);
   int i;
   while (!q.empty()) {
     s = q.front();
     q.pop();
     vvis[s] = 0;
     int i;
     for (i = head[s]; ~i; i = e[i].next) {
       if (!e[i].w) continue;
       if (dis[s] + e[i].co < dis[e[i].to]) {
         dis[e[i].to] = dis[s] + e[i].co;
         pree[e[i].to] = i;
         prep[e[i].to] = s;
         if (vvis[e[i].to]) continue;
         vvis[e[i].to] = 1;
         q.push(e[i].to);
       }
     }
   }
 }
 _ dfs(int s, int t, int rest) {
   int flow = 998244353, co = 0;
   int temp = t;
   _ rv;
   while (t != s) {
     flow = min(flow, e[pree[t]].w);
     co += e[pree[t]].co;
     t = prep[t];
   }
   if (co > 0) flow = min(flow, rest / co);
   if (flow == 0) return rv = (_){0, 0};
   t = temp;
   while (t != s) {
     temp = pree[t];
     e[temp].w -= flow;
     e[temp ^ 1].w += flow;
     t = prep[t];
   }
   rv = (_){flow, co};
   return rv;
 }
 long long EK(int s, int t, int rest) {
   long long sum = 0;
   _ _;
   while (1) {
     spfa(s);
     if (dis[t] > 998244353) break;
     _ = dfs(s, t, rest);
     if (_.max_flow == 0) break;
     sum += _.max_flow;
     rest -= _.max_flow * _.co;
   }
   return sum;
 }
 int main() {
   memset(head, 255, sizeof(head));
   int n, k;
   scanf( %d%d , &n, &k);
   int i, j, t;
   for (i = 1; i <= n; i++) {
     for (j = 1; j <= n; j++) {
       scanf( %d , &t);
       if (t) {
         add(i, j, t, 0);
         add(j, i, 0, 0);
         add(i, j, k, 1);
         add(j, i, 0, -1);
       }
     }
   }
   long long ans = EK(1, n, k);
   printf( %lld
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct station {
   int pos, price;
 } a[200003];
 int T[800008], d, n, m;
 long long cnt;
 bool comp(station A, station B) { return (A.pos < B.pos); }
 void Build_MinIT(int, int, int);
 int Find_Min(int, int, int, int, int);
 int main() {
   scanf( %d %d %d , &d, &n, &m);
   for (int i = 1; i <= m; i++) scanf( %d %d , &a[i].pos, &a[i].price);
   sort(a + 1, a + 1 + m, comp);
   a[++m].pos = d;
   for (int i = 1; i <= m; i++) {
     if (a[i].pos - a[i - 1].pos > n) {
       cout << -1;
       return 0;
     }
   }
   if (n >= d) {
     cout << 0;
     return 0;
   }
   a[200002].price = 1E+9;
   Build_MinIT(1, m, 1);
   int i = 0, j = 1, t = n;
   while (j <= m) {
     while (a[i].price < a[j].price && a[j].pos - a[i].pos <= n && j <= m) j++;
     if (a[j].pos - a[i].pos <= n) {
       cnt += (long long)(a[j].pos - (a[i].pos + t)) * a[i].price;
       t = 0;
       i = j++;
     } else {
       int k = Find_Min(i + 1, j - 1, 1, m, 1);
       cnt += (long long)(n - t) * a[i].price;
       t = a[i].pos + n - a[k].pos;
       i = k;
     }
   }
   cout << cnt;
   return 0;
 }
 void Build_MinIT(int L, int R, int v) {
   if (L == R) {
     T[v] = L;
     return;
   }
   int m = (L + R) / 2;
   Build_MinIT(L, m, v * 2);
   Build_MinIT(m + 1, R, v * 2 + 1);
   T[v] = (a[T[v * 2]].price < a[T[v * 2 + 1]].price ? T[v * 2] : T[v * 2 + 1]);
 }
 int Find_Min(int l, int r, int L, int R, int v) {
   if (l > r) return 200002;
   if (l == L && r == R) return T[v];
   int m = (L + R) / 2;
   int x = Find_Min(l, min(r, m), L, m, v * 2),
       y = Find_Min(max(l, m + 1), r, m + 1, R, v * 2 + 1);
   return (a[x].price < a[y].price ? x : y);
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   double lo = 0.0, hi = 10000000.0;
   for (int i = 1; i <= n; i++) {
     int sta;
     cin >> sta;
     lo = max(lo, (double)10.0 * sta / i);
     hi = min(hi, (double)10.0 * (sta + 1) / i);
   }
   int nextlo = floor(lo * (n + 1) / 10.0);
   int nexthi = ceil(hi * (n + 1) / 10.0);
   if (nextlo + 1 >= nexthi) {
     cout <<  unique  << endl << nextlo << endl;
   } else {
     cout <<  not unique  << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 #pragma comment(linker,  /stack:102400000,102400000 )
 using namespace std;
 int lowbit(int x) { return (x & -x); }
 template <class T_>
 T_ f_abs(T_ x) {
   return x < 0 ? -x : x;
 }
 template <class T_>
 T_ f_max(T_ a, T_ b) {
   return a > b ? a : b;
 }
 template <class T_>
 T_ f_min(T_ a, T_ b) {
   return a < b ? a : b;
 }
 template <class T_>
 void chkmax(T_ &a, T_ b) {
   if (a == -1 || a < b) a = b;
 }
 template <class T_>
 void chkmin(T_ &a, T_ b) {
   if (a == -1 || a > b) a = b;
 }
 template <class T_>
 T_ gcd(T_ a, T_ b) {
   while (T_ t = a % b) a = b, b = t;
   return b;
 }
 template <class T_>
 void f_swap(T_ &a, T_ &b) {
   T_ t = a;
   a = b;
   b = t;
 }
 const double eps = 1e-9;
 const int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1},
           dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
 const int inf = 0x7fffffff;
 const int mod = 1000000007;
 const int N = 100003;
 const int MAXV = 100003;
 int n, m, cnt, who[N], dsu[N];
 bool vis[N], tree[N << 2];
 vector<pair<int, int> > vt[N], qu[N];
 struct Oper {
   int tp, x, y;
   bool tag;
   Oper() {}
   Oper(int tp_, int x_, int y_) {
     tp = tp_;
     x = x_;
     y = y_;
   }
 } op[N];
 struct Edge {
   int to, next;
 } edg[MAXV << 1];
 int total, idx, root, first[MAXV];
 int siz[MAXV];
 int dep[MAXV];
 int top[MAXV];
 int fa[MAXV];
 int son[MAXV];
 int id[MAXV];
 void Dfs_1(int u) {
   int e, v, i;
   siz[u] = 1;
   son[u] = 0;
   for (e = 0; e < (int)vt[u].size(); ++e) {
     v = vt[u][e].first;
     i = vt[u][e].second;
     op[i].tag = !vis[v];
   }
   vis[u] = true;
   for (e = first[u]; ~e; e = edg[e].next) {
     v = edg[e].to;
     if (v != fa[u]) {
       fa[v] = u;
       dep[v] = dep[u] + 1;
       Dfs_1(v);
       if (son[u] == 0 || siz[v] > siz[son[u]]) son[u] = v;
       siz[u] += siz[v];
     }
   }
   for (e = 0; e < (int)vt[u].size(); ++e) {
     v = vt[u][e].first;
     i = vt[u][e].second;
     if (op[i].tag && !vis[v]) op[i].tag = false;
   }
 }
 void Dfs_2(int u, int tp) {
   id[u] = ++idx;
   top[u] = tp;
   if (son[u] != 0) Dfs_2(son[u], top[u]);
   for (int e = first[u]; ~e; e = edg[e].next) {
     int v = edg[e].to;
     if (v != son[u] && v != fa[u]) Dfs_2(v, v);
   }
 }
 void BuildChain() {
   Dfs_1(root);
   Dfs_2(root, root);
 }
 void Build(int l, int r, int root) {
   tree[root] = false;
   if (l == r) return;
   int mid = ((l + r) >> 1);
   Build(l, mid, (root << 1));
   Build(mid + 1, r, (root << 1 | 1));
 }
 void Update(int p, int l, int r, int root) {
   if (l == r) {
     tree[root] = true;
     return;
   }
   int mid = ((l + r) >> 1);
   if (p <= mid)
     Update(p, l, mid, (root << 1));
   else
     Update(p, mid + 1, r, (root << 1 | 1));
   tree[root] = (tree[(root << 1)] && tree[(root << 1 | 1)]);
 }
 bool Query(int L, int R, int l, int r, int root) {
   if (L <= l && r <= R) return tree[root];
   int mid = ((l + r) >> 1);
   bool res = true;
   if (L <= mid) res = (res && Query(L, R, l, mid, (root << 1)));
   if (R > mid) res = (res && Query(L, R, mid + 1, r, (root << 1 | 1)));
   return res;
 }
 bool FindChain(int u, int v) {
   int u_top = top[u], v_top = top[v], L, R;
   while (u_top != v_top) {
     if (dep[u_top] < dep[v_top]) {
       f_swap(u_top, v_top);
       f_swap(u, v);
     }
     L = id[u_top];
     R = id[u];
     if (!Query(L, R, 1, idx, 1)) return false;
     u = fa[u_top];
     u_top = top[u];
   }
   if (u != v) {
     if (dep[u] > dep[v]) f_swap(u, v);
     L = id[son[u]];
     R = id[v];
     if (!Query(L, R, 1, idx, 1)) return false;
   }
   return true;
 }
 void addedge(int from, int to) {
   edg[total].to = to;
   edg[total].next = first[from];
   first[from] = total++;
 }
 void Init() {
   cnt = 0;
   root = n + 1;
   total = idx = fa[root] = dep[root] = 0;
   for (int i = 1; i <= n + 1; ++i) {
     first[i] = -1;
     dsu[i] = i;
     vt[i].clear();
     vis[i] = false;
   }
 }
 void GetData() {
   int tp, x, y;
   for (int i = 0; i < m; ++i) {
     scanf( %d%d , &tp, &x);
     if (tp != 2) scanf( %d , &y);
     if (tp == 1) {
       dsu[x] = y;
       addedge(y, x);
     } else if (tp == 2) {
       y = -1;
       who[++cnt] = x;
       qu[cnt].clear();
     } else {
       vt[x].push_back(make_pair(who[y], i));
       qu[y].push_back(make_pair(x, i));
     }
     op[i] = Oper(tp, x, y);
   }
 }
 void Solve() {
   int i, j, tp, p;
   bool flag;
   for (i = 1; i <= n; ++i) {
     if (dsu[i] == i) addedge(n + 1, i);
   }
   BuildChain();
   Build(1, idx, 1);
   for (i = cnt = 0; i < m; ++i) {
     tp = op[i].tp;
     if (tp == 1)
       Update(id[op[i].x], 1, idx, 1);
     else if (tp == 2) {
       ++cnt;
       for (j = 0; j < (int)qu[cnt].size(); ++j) {
         p = qu[cnt][j].second;
         if (op[p].tag)
           flag = FindChain(who[cnt], qu[cnt][j].first);
         else
           flag = false;
         vis[p] = flag;
       }
     }
   }
   for (i = 0; i < m; ++i) {
     if (op[i].tp == 3) puts(vis[i] ?  YES  :  NO );
   }
 }
 int main() {
   while (~scanf( %d%d , &n, &m)) {
     Init();
     GetData();
     Solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int arr[111];
 int main() {
   int n;
   scanf( %d , &n);
   arr[0] = 0;
   for (int i = (1); i < (n + 1); ++i) scanf( %d , &arr[i]);
   int ans = 0;
   if (n % 2 == 0 || n == 1) {
     printf( -1
 );
     return 0;
   }
   for (int i = n; i >= 1; i -= 2) {
     int tmp = max(arr[i], arr[i - 1]);
     ans += tmp;
     arr[i] = arr[i - 1] = 0;
     arr[(i - 1) / 2] = max(0, arr[(i - 1) / 2] - tmp);
   }
   printf( %d
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 namespace {};
 int sgn(int x) { return x >= 0 ? 1 : -1; }
 int arr[200001];
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n, k;
   cin >> n >> k;
   for (int i = 0; i < n; i++) {
     cin >> arr[i];
     arr[i] = sgn(arr[i]);
     if (arr[i] == -1) k--;
   }
   if (k < 0) {
     cout <<  -1
 ;
     return 0;
   }
   vector<pair<int, int>> segs;
   int flips = 0;
   int curr = 1, c = 0;
   for (int i = 0; i < n; i++) {
     if (arr[i] == curr)
       c++;
     else {
       flips++;
       if (curr == 1 && i - c > 0) segs.emplace_back(c, -2);
       c = 1;
       curr = arr[i];
     }
   }
   for (auto seg : segs) {
     ;
   }
   sort(segs.begin(), segs.end());
   ;
   for (auto seg : segs) {
     if (seg.first > k) break;
     k -= seg.first;
     flips += seg.second;
   }
   if (curr == 1 && c > 0) {
     if (k >= c) flips--;
   }
   if (flips < 0) flips = 0;
   cout << flips << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct info {
   long long fs, sm, id;
 } bd[100001];
 int cmp(info a, info b) { return a.fs < b.fs; }
 int main() {
   ios_base::sync_with_stdio(0);
   long long int i, j, x, n, cnt = 0, m, y, k, ans = 0, cf, cm, a, rr1 = 0, l, r,
                             md, r1, r2, xxx, flg;
   cin >> n >> a >> cf >> cm >> m;
   long long in[n + 1], bs[n + 1];
   for (i = 1; i <= n; i++) {
     cin >> in[i];
     bd[i].fs = a - in[i];
     bd[i].id = i;
     bs[i] = a - in[i];
   }
   sort(bd + 1, bd + 1 + n, cmp);
   sort(bs + 1, bs + 1 + n);
   for (i = 2; i <= n; i++) {
     bd[i].fs += bd[i - 1].fs;
   }
   bd[n].sm = 0;
   for (i = n - 1; i >= 1; i--) {
     x = abs(in[bd[i + 1].id] - in[bd[i].id]);
     bd[i].sm = bd[i + 1].sm + x * (n - i);
   }
   bd[0].fs = bd[0].id = 0;
   bd[0].sm = (a - in[bd[1].id]) * n + bd[1].sm;
   for (i = 1; i <= n; i++) {
     if (bs[i] > 0) break;
     cnt++;
   }
   ans = cnt * cf + cm * in[bd[n].id];
   for (i = n; i >= 0; i--) {
     x = m;
     y = cnt * cf;
     rr1 = cnt;
     flg = 0;
     if (x >= bd[i].fs) {
       flg = 1;
       y = i * cf;
       x -= bd[i].fs;
       rr1 = i;
     }
     l = i;
     r = n;
     while (r - l > 1) {
       md = (l + r) / 2;
       if (bd[md].sm > x)
         l = md;
       else
         r = md;
     }
     if (bd[l].sm <= x && i != 0) r = l;
     x -= bd[r].sm;
     if (r == i && flg) {
       if (i == n) {
         y = a * cm + n * cf;
         if (ans <= y) {
           ans = y;
           r1 = n;
           r2 = n + 1;
         }
       } else {
         y += cm * (min(a, in[bd[r].id] + x / (n - r)));
         if (ans <= y) {
           ans = y;
           r1 = i;
           xxx = min(a, in[bd[r].id] + x / (n - r));
           r2 = i + 1;
         }
       }
       continue;
     }
     if (r - 1 > 0)
       y += cm * (min(a, min(in[bd[r - 1].id], in[bd[r].id] + x / (n - r + 1))));
     else
       y += cm * (min(a, in[bd[r].id] + x / (n - r + 1)));
     if (y >= ans) {
       ans = y;
       r1 = rr1;
       r2 = r;
       if (r - 1 > 0)
         xxx = min(a, min(in[bd[r - 1].id], in[bd[r].id] + x / (n - r + 1)));
       else
         xxx = min(a, in[bd[r].id] + x / (n - r + 1));
     }
   }
   for (i = 1; i <= r1; i++) {
     in[bd[i].id] = a;
   }
   for (i = r2; i <= n; i++) {
     in[bd[i].id] = xxx;
   }
   cout << ans << endl;
   for (i = 1; i <= n; i++) cout << in[i] <<    ;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int t;
   cin >> t;
   while (t--) {
     int n;
     cin >> n;
     vector<long long int> a(n);
     vector<long long int> b(n);
     for (int i = 0; i < n; i++) {
       cin >> a[i];
     }
     for (int i = 0; i < n; i++) {
       cin >> b[i];
     }
     long long int cnt = 0;
     long long int min_a = *min_element(a.begin(), a.end());
     long long int min_b = *min_element(b.begin(), b.end());
     for (int i = 0; i < n; i++) {
       if (a[i] > min_a && b[i] > min_b) {
         long long int num;
         num = min(a[i] - min_a, b[i] - min_b);
         cnt += num;
         a[i] -= num;
         b[i] -= num;
       }
     }
     for (int i = 0; i < n; i++) {
       cnt += (a[i] - min_a);
       cnt += (b[i] - min_b);
     }
     cout << cnt << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename A, typename B>
 string to_string(pair<A, B> p);
 template <typename A, typename B, typename C>
 string to_string(tuple<A, B, C> p);
 template <typename A, typename B, typename C, typename D>
 string to_string(tuple<A, B, C, D> p);
 string to_string(const string& s) { return ' ' + s + ' '; }
 string to_string(const char* s) { return to_string((string)s); }
 string to_string(bool b) { return (b ?  true  :  false ); }
 string to_string(vector<bool> v) {
   bool first = true;
   string res =  { ;
   for (int i = 0; i < static_cast<int>(v.size()); i++) {
     if (!first) {
       res +=  ,  ;
     }
     first = false;
     res += to_string(v[i]);
   }
   res +=  } ;
   return res;
 }
 template <size_t N>
 string to_string(bitset<N> v) {
   string res =   ;
   for (size_t i = 0; i < N; i++) {
     res += static_cast<char>('0' + v[i]);
   }
   return res;
 }
 template <typename A>
 string to_string(A v) {
   bool first = true;
   string res =  { ;
   for (const auto& x : v) {
     if (!first) {
       res +=  ,  ;
     }
     first = false;
     res += to_string(x);
   }
   res +=  } ;
   return res;
 }
 template <typename A, typename B>
 string to_string(pair<A, B> p) {
   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;
 }
 template <typename A, typename B, typename C>
 string to_string(tuple<A, B, C> p) {
   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +
          to_string(get<2>(p)) +  ) ;
 }
 template <typename A, typename B, typename C, typename D>
 string to_string(tuple<A, B, C, D> p) {
   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +
          to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;
 }
 void debug_out() { cerr << endl; }
 template <typename Head, typename... Tail>
 void debug_out(Head H, Tail... T) {
   cerr <<     << to_string(H);
   debug_out(T...);
 }
 class dsu {
  public:
   vector<int> p;
   int n;
   dsu(int _n) : n(_n) {
     p.resize(n);
     iota(p.begin(), p.end(), 0);
   }
   inline int get(int x) { return (x == p[x] ? x : (p[x] = get(p[x]))); }
   inline bool unite(int x, int y) {
     x = get(x);
     y = get(y);
     if (x != y) {
       p[x] = y;
       return true;
     }
     return false;
   }
 };
 const int MAX = 100010;
 int bound[MAX];
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int tt;
   cin >> tt;
   assert(1 <= tt && tt <= 1000);
   int x = 0;
   while (tt--) {
     int n;
     cin >> n;
     if (n == 0) {
       continue;
     }
     assert(n >= 1);
     vector<int> v(n);
     for (int i = 0; i < n; i++) {
       cin >> v[i];
     }
     sort(v.begin(), v.end());
     v.resize(unique(v.begin(), v.end()) - v.begin());
     n = (int)v.size();
     for (int i = 0; i < n - 1; i++) {
       assert(v[i] < v[i + 1]);
     }
     assert(0 <= v[0]);
     assert(v[n - 1] <= 100000);
     {
       int ptr = -1;
       for (int val = 0; val < MAX; val++) {
         if (ptr + 1 < n && v[ptr + 1] == val) {
           ++ptr;
         }
         bound[val] = ptr;
       }
     }
     vector<vector<int>> who(1, vector<int>(n, -1));
     vector<dsu> d(1, dsu(n + 1));
     vector<bool> seen;
     for (int i = n - 1; i >= 0; i--) {
       int start = 0;
       int j = 0;
       while (start < i) {
         if (j == (int)who.size()) {
           who.emplace_back(n, -1);
           d.emplace_back(n + 1);
         }
         int finish = i - 1;
         int tmp = who[j][i];
         if (tmp != -1) {
           int val = v[i] - (v[tmp] - v[i]);
           finish = (val < 0 ? -1 : bound[val]);
         }
         if (start <= finish) {
           int pos = d[j].get(start);
           while (pos <= finish) {
             who[j][pos] = i;
             d[j].unite(pos, pos + 1);
             pos = d[j].get(pos);
           }
           start = finish + 1;
         }
         ++j;
       }
       int g = 0;
       while (g < (int)who.size() && who[g][i] != -1) {
         ++g;
       }
       if (g >= (int)seen.size()) {
         seen.resize(g + 1);
       }
       seen[g] = true;
     }
     int g = 0;
     while (g < (int)seen.size() && seen[g]) {
       ++g;
     }
     x ^= g;
     42;
   }
   cout << (x > 0 ?  YES  :  NO ) << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1e5 + 5;
 long long n, num;
 long long a[maxn];
 long long vis[maxn];
 priority_queue<long long> pq;
 void fnd(long long x) {
   if (vis[a[x]] == 0) {
     vis[a[x]] = 1;
     num++;
     fnd(a[x]);
   } else
     return;
 }
 int main() {
   cin >> n;
   for (int i = 1; i <= n; i++) {
     cin >> a[i];
   }
   memset(vis, 0, sizeof(vis));
   for (int i = 1; i <= n; i++) {
     num = 1;
     if (vis[i] == 0) {
       vis[i] = 1;
       fnd(i);
       pq.push(num);
     }
   }
   long long t = pq.top();
   pq.pop();
   if (!pq.size()) {
     cout << t * t << endl;
   } else {
     t += pq.top();
     pq.pop();
     long long ans = t * t;
     while (pq.size()) {
       t = pq.top();
       pq.pop();
       ans += t * t;
     }
     cout << ans << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxN = 1e5 + 5;
 vector<int> adj[maxN];
 int s[maxN], par[maxN];
 void dfs(int n, int p) {
   par[n] = p;
   for (int i = int(0); i < int((int)adj[n].size()); i++) {
     if (adj[n][i] != p) dfs(adj[n][i], n);
   }
 }
 int main() {
   ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0),
       cout.precision(15);
   int n, tmp;
   cin >> n;
   for (int i = int(0); i < int(n - 1); i++) {
     cin >> tmp;
     tmp -= 1;
     adj[tmp].push_back(i + 1);
   }
   dfs(0, -1);
   for (int i = int(0); i < int(n); i++) {
     cin >> s[i];
   }
   long long ans = s[0];
   for (int i = int(0); i < int(n); i++) {
     if (s[i] == -1) {
       int n = i, tt = s[par[i]];
       int mini = 2000000000;
       for (int j = int(0); j < int((int)adj[n].size()); j++) {
         if (s[adj[n][j]] < tt) {
           cout << -1;
           return 0;
         }
         mini = min(mini, s[adj[n][j]] - tt);
       }
       if (mini != 2000000000) ans += mini;
       for (int j = int(0); j < int((int)adj[n].size()); j++) {
         ans += s[adj[n][j]] - tt - mini;
       }
     }
   }
   cout << ans;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = 1000000001;
 const long double EPS = 1e-9;
 const int MOD = 1000000007;
 const long long LLINF = 1000000000000000001;
 const int maxn = 1042;
 int n;
 int a[maxn];
 char ans[maxn][maxn];
 bool good[maxn];
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cin >> n;
   for (int i = 1; i <= n; i++) {
     cin >> a[i];
     for (int j = 1; j <= n; j++) ans[i][j] = '.';
   }
   bool none = true;
   for (int i = 1; i <= n; i++)
     if (a[i] != i) none = false;
   if (none)
     cout << n << '
';
   else {
     cout << n - 1 << '
';
     int mostleft = 1;
     while (a[mostleft] == mostleft) {
       good[mostleft] = true;
       mostleft++;
     }
     int row = 1;
     int z = mostleft;
     good[z] = true;
     z = a[z];
     while (!good[z]) {
       good[z] = true;
       char mirror = (z < a[z]) ? '/' : '\';
       ans[row][z] = mirror;
       ans[row][a[z]] = mirror;
       row++;
       z = a[z];
     }
     good[z] = true;
     for (int i = mostleft + 1; i <= n; i++) {
       if (a[i] != i && !good[i]) {
         int firstrow = row;
         z = i;
         while (a[z] > z) z = a[z];
         z = a[z];
         good[z] = true;
         row++;
         z = a[z];
         while (!good[z]) {
           good[z] = true;
           char mirror = (z < a[z]) ? '/' : '\';
           ans[row][z] = mirror;
           ans[row][a[z]] = mirror;
           row++;
           z = a[z];
         }
         ans[row - 1][mostleft] = '\';
         ans[firstrow][mostleft] = '/';
         ans[firstrow][a[z]] = '/';
       }
     }
   }
   for (int i = 1; i <= n; i++) {
     for (int j = 1; j <= n; j++) cout << ans[i][j];
     cout << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   int h[n];
   for (int i = 0; i < n; i++) cin >> h[i];
   int max;
   int a[n];
   a[n - 1] = 0;
   max = h[n - 1];
   for (int i = n - 2; i >= 0; i--) {
     if (h[i] > max) {
       a[i] = 0;
       max = h[i];
     } else {
       a[i] = max - h[i] + 1;
     }
   }
   for (int i = 0; i < n; i++) {
     printf( %d  , a[i]);
   }
   printf(
 );
   return 0;
 }