#include <bits/stdc++.h>
 using namespace std;
 int N;
 char field[110][110];
 bool check_solution(bool do_print, bool swapped) {
   for (int r = 0; r < N; ++r) {
     int c;
     for (c = 0; c < N; ++c) {
       if (field[r][c] == '.') break;
     }
     if (c == N) return false;
     if (do_print) {
       if (swapped)
         printf( d d
 , c + 1, r + 1);
       else
         printf( d d
 , r + 1, c + 1);
     }
   }
   return true;
 }
 int main(void) {
   scanf( d , &N);
   for (int r = 0; r < N; ++r) scanf( s , field[r]);
   if (check_solution(false, false)) {
     check_solution(true, false);
   } else {
     for (int r = 0; r < N; ++r) {
       for (int c = r + 1; c < N; ++c) {
         swap(field[r][c], field[c][r]);
       }
     }
     if (check_solution(false, true))
       check_solution(true, true);
     else
       puts( -1 );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct nade {
   int pos, tag, sum, l, r;
 } tree[600005 * 2];
 int n;
 void puup(int x) {
   if (tree[x * 2].sum > tree[x * 2 + 1].sum) {
     tree[x].pos = tree[x * 2].pos;
     tree[x].sum = tree[x * 2].sum;
   } else {
     tree[x].pos = tree[x * 2 + 1].pos;
     tree[x].sum = tree[x * 2 + 1].sum;
   }
 }
 void pudo(int x) {
   tree[x * 2].tag += tree[x].tag;
   tree[x * 2].sum += tree[x].tag;
   tree[x * 2 + 1].tag += tree[x].tag;
   tree[x * 2 + 1].sum += tree[x].tag;
   tree[x].tag = 0;
 }
 void build(int x, int l, int r) {
   tree[x].l = l;
   tree[x].r = r;
   if (l == r) {
     tree[x].pos = l;
     return;
   }
   int mid = (l + r) / 2;
   build(x * 2, l, mid);
   build(x * 2 + 1, mid + 1, r);
   tree[x].pos = tree[x * 2].pos;
 }
 void add(int l, int r, int val, int x) {
   if (tree[x].l >= l && tree[x].r <= r) {
     tree[x].sum += val;
     tree[x].tag += val;
     return;
   }
   pudo(x);
   if (tree[x * 2].r >= l) add(l, r, val, x * 2);
   if (tree[x * 2 + 1].l <= r) add(l, r, val, x * 2 + 1);
   puup(x);
 }
 int l[200005], r[200005], v[200005];
 struct node {
   int x, u, d;
   bool b;
 } s[200005];
 bool cmp(node a, node b) {
   if (a.x != b.x) return a.x < b.x;
   return a.b < b.b;
 }
 int main() {
   scanf( d , &n);
   for (int i = 0; i < n; i++) {
     scanf( ddd , &l[i], &v[i], &r[i]);
     s[i * 2].x = l[i];
     s[i * 2].u = r[i];
     s[i * 2].d = v[i];
     s[i * 2].b = 0;
     s[i * 2 + 1].x = v[i];
     s[i * 2 + 1].u = r[i];
     s[i * 2 + 1].d = v[i];
     s[i * 2 + 1].b = 1;
   }
   build(1, 1, 3e5 + 1);
   sort(s, s + 2 * n, cmp);
   int ans = 0, ansp = 0, ansx = 0;
   for (int i = 0; i < n * 2; i++) {
     add(s[i].d, s[i].u, s[i].b ? -1 : 1, 1);
     if (tree[1].sum > ans) {
       ans = tree[1].sum;
       ansp = tree[1].pos;
       ansx = s[i].x;
     }
   }
   printf( d
 , ans);
   for (int i = 0; i < n; i++)
     if (l[i] <= ansx && ansx <= v[i] && v[i] <= ansp && ansp <= r[i])
       printf( d  , i + 1);
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 100500;
 const int infi = (1 << 30);
 const long long infl = (1LL << 62);
 const double eps = 1e-9;
 const long long mod = 1000000007LL;
 const double pi = acos(-1.0);
 int n, k;
 int a[maxn], c[maxn];
 int main() {
   cin >> n >> k;
   for (int i = 1; i < n; i++) a[i] = 1;
   a[0] = 0;
   for (int i = 0; i < k; i++) {
     for (int j = 0; j < n; j++) {
       int second = int(upper_bound(a, a + n, j - a[j] - 1) - a);
       if (second == n) second = n - 1;
       c[j] = second;
     }
     for (int j = 0; j < n; j++) {
       a[j] += a[c[j]];
     }
     for (int j = n - 1; j >= 0; --j) cout << n - c[j] <<    ;
     cout << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> divs[1000009];
 bool p[1000009];
 vector<int> primes;
 void pre() {
   for (int i = 2; i <= (1000000); ++i) {
     if (!p[i]) {
       primes.push_back(i);
       for (int j = i; j <= 1000000; j += i) divs[j].push_back(i), p[j] = true;
     }
   }
 }
 int L(int x, int p) {
   int s = (int)(divs[p]).size();
   int tot = (1 << s) - 1;
   long long ans = 0;
   for (int i = 1; i <= (tot); ++i) {
     int cnt = 0;
     int var = 1;
     for (int j = 0; j < (s); ++j)
       if (i & (1 << j)) cnt++, var *= divs[p][j];
     if (cnt  2)
       ans += x / var;
     else
       ans -= x / var;
   }
   return x - ans;
 }
 int main() {
   cin.sync_with_stdio(0);
   cin.tie(0);
   cin.exceptions(cin.failbit);
   pre();
   int q;
   cin >> q;
   for (int aa = 0; aa < (q); ++aa) {
     int x, p, k;
     cin >> x >> p >> k;
     if (p == 1)
       cout << k + x << '
';
     else {
       k += L(x, p);
       int l = 1, r = 1e8;
       while (l < r) {
         int m = (l + r) >> 1;
         if (L(m, p) >= k)
           r = m;
         else
           l = m + 1;
       }
       cout << l << '
';
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 class Solution {
  public:
   long long count(long long _m, long long _x) {
     if (_m < 3) {
       return max(0LL, _m);
     }
     m = _m;
     x = _x;
     vector<pair<long long, int>> cnts = factorize(m);
     long long res = 0;
     search(0, 1, cnts, res);
     return res;
   }

  private:
   map<long long, vector<pair<long long, int>>> fs;
   long long m, x;
   long long gcd(long long x, long long y) {
     while (x != 0) {
       y = x;
       swap(x, y);
     }
     return y;
   }
   vector<pair<long long, int>>& factorize(long long n) {
     if (fs.count(n) > 0) {
       return fs[n];
     }
     vector<pair<long long, int>>& res = fs[n];
     for (long long i = 2; i * i <= n; ++i) {
       int cnt = 0;
       while (n  i == 0) {
         ++cnt;
         n /= i;
       }
       if (cnt > 0) {
         res.emplace_back(i, cnt);
       }
     }
     if (n > 1) {
       res.emplace_back(n, 1);
     }
     return res;
   }
   void search(int i, long long dv, vector<pair<long long, int>>& cnts,
               long long& ans) {
     if (i >= cnts.size()) {
       vector<pair<long long, int>> dvcnts;
       dvcnts.reserve(cnts.size());
       for (auto& pc : cnts) {
         if (pc.second <= 1) {
           continue;
         }
         dvcnts.emplace_back(pc.first, pc.second - 1);
       }
       long long phi = dv;
       for (auto& pc : cnts) {
         long long p = pc.first;
         int c = pc.second;
         if (c == 0) {
           continue;
         }
         dvcnts = merge(dvcnts, factorize(p - 1));
         phi = phi - phi / p;
       }
       ans += phi / calcPeriod(x  dv, dv, dvcnts);
       return;
     }
     long long p = fs[m][i].first;
     long long n = fs[m][i].second;
     for (int j = 0; j <= n; ++j) {
       cnts[i].second = j;
       search(i + 1, dv, cnts, ans);
       dv *= p;
     }
   }
   vector<pair<long long, int>> merge(vector<pair<long long, int>>& list1,
                                      vector<pair<long long, int>>& list2) {
     vector<pair<long long, int>> res;
     res.reserve(list1.size() + list2.size());
     int n = list1.size(), m = list2.size();
     int i = 0, j = 0;
     while (i < n && j < m) {
       if (list1[i].first < list2[j].first) {
         res.emplace_back(list1[i].first, list1[i].second);
         ++i;
       } else if (list1[i].first > list2[j].first) {
         res.emplace_back(list2[j].first, list2[j].second);
         ++j;
       } else {
         res.emplace_back(list1[i].first, list1[i].second + list2[j].second);
         ++i;
         ++j;
       }
     }
     while (i < n) {
       res.emplace_back(list1[i].first, list1[i].second);
       ++i;
     }
     while (j < m) {
       res.emplace_back(list2[j].first, list2[j].second);
       ++j;
     }
     return res;
   }
   long long calcPeriod(long long x, long long mod,
                        vector<pair<long long, int>>& factors) {
     long long phi = 1;
     for (auto& pc : factors) {
       long long p = pc.first;
       int c = pc.second;
       for (int i = 0; i < c; ++i) {
         phi *= p;
       }
     }
     long long res = 1;
     for (auto& pc : factors) {
       long long p = pc.first;
       int c = pc.second;
       long long base = phi;
       for (int i = 0; i < c; ++i) {
         base /= p;
       }
       long long val = powM(x, base, mod);
       int j = c;
       for (int i = 1; i <= c; ++i) {
         if (val == 1) {
           j = i - 1;
           break;
         }
         val = powM(val, p, mod);
       }
       res *= powI(p, j);
     }
     return res;
   }
   long long mulM(long long a, long long b, long long m) {
     long long res = 0;
     while (b > 0) {
       if (b & 0x1) {
         res = (res + a)  m;
       }
       a = (a + a)  m;
       b >>= 1;
     }
     return res;
   }
   long long powM(long long x, long long e, long long m) {
     long long res = 1;
     while (e > 0) {
       if (e & 0x1) {
         res = mulM(res, x, m);
       }
       x = mulM(x, x, m);
       e >>= 1;
     }
     return res;
   }
   long long powI(long long x, long long e) {
     long long res = 1;
     for (int i = 0; i < e; ++i) {
       res *= x;
     }
     return res;
   }
 };
 int main(int argc, char** argv) {
   ios::sync_with_stdio(false);
   cin.tie(0);
   long long m, x;
   cin >> m >> x;
   Solution sol;
   cout << sol.count(m, x) << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 using ll = long long;
 ll dx[] = {0, 0, 1, -1};
 ll dy[] = {1, -1, 0, 0};
 void solve() {
   ll n;
   cin >> n;
   vector<ll> v(n);
   for (ll i = 0; i < (n); ++i) cin >> v[i];
   vector<pair<ll, ll>> aux(n);
   ll i = n - 1;
   stack<ll> s;
   while (i >= 0) {
     while (!s.empty() && s.top() < v[i]) s.pop();
     if (s.empty())
       aux[i].first = -1;
     else
       aux[i].first = s.top();
     s.push(v[i]);
     i--;
   }
   i = 0;
   while (!s.empty()) s.pop();
   while (i < n) {
     while (!s.empty() && s.top() < v[i]) s.pop();
     if (s.empty())
       aux[i].second = -1;
     else
       aux[i].second = s.top();
     s.push(v[i]), i++;
   }
   ll res = 0;
   for (ll i = 0; i < (n); ++i) {
     if (aux[i].first != -1) res = max(res, aux[i].first ^ v[i]);
     if (aux[i].second != -1) res = max(res, aux[i].second ^ v[i]);
   }
   cout << res <<
 ;
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   ;
   ll t = 1;
   while (t--) solve();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1010;
 void solve() {
   int n, m;
   cin >> n >> m;
   vector<vector<long long>> a =
       vector<vector<long long>>(n, vector<long long>(m, 0));
   for (int i = 0; i < n; ++i)
     for (int j = 0; j < m; ++j) cin >> a[i][j];
   vector<long long> col(m, 0), row(n, 0);
   for (int i = 0; i < m; ++i)
     for (int j = 0; j < n; ++j) col[i] += a[j][i];
   for (int i = 0; i < n; ++i)
     for (int j = 0; j < m; ++j) row[i] += a[i][j];
   vector<long long> x(m + 1), y(n + 1);
   long long mn = LLONG_MAX;
   long long ans = 0;
   int ansx = 0;
   for (int i = 0; i <= m; ++i) {
     long long curx = i * 4;
     for (int j = 0; j < m; ++j) {
       long long curpos = j * 4 + 2;
       long long dx = curx - curpos;
       x[i] += dx * dx * col[j];
     }
     if (x[i] < mn) {
       mn = x[i];
       ansx = i;
     }
   }
   ans += mn;
   mn = LLONG_MAX;
   int ansy = 0;
   for (int i = 0; i <= n; ++i) {
     int cury = i * 4;
     for (int j = 0; j < n; ++j) {
       long long curpos = j * 4 + 2;
       long long dy = cury - curpos;
       y[i] += dy * dy * row[j];
     }
     if (y[i] < mn) {
       mn = y[i];
       ansy = i;
     }
   }
   ans += mn;
   cout << ans << '
';
   cout << ansy << ' ' << ansx << '
';
 }
 int main(void) {
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int tc = 1;
   while (tc--) {
     solve();
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long inf = 1LL << 60;
 const long long md = 1e9 + 7;
 const long double eps = 1e-14;
 const int mx = 3010;
 int t[mx];
 void upd(int p) {
   for (++p; p < mx; p += p & -p) ++t[p];
 }
 int que(int p) {
   int res = 0;
   for (; p > 0; p -= p & -p) res += t[p];
   return res;
 }
 char zey[mx][mx];
 int le[mx][mx], ri[mx][mx];
 int solve(vector<int> &a, vector<int> &b) {
   int sz = a.size();
   if (sz == 0) return 0;
   int res = 0;
   fill(t, t + sz + 5, 0);
   vector<pair<int, int> > bb(sz);
   for (int i = (0); i < int(sz); ++i) bb[i] = pair<int, int>(i - b[i] + 1, i);
   sort(bb.begin(), bb.end());
   int ix = 0;
   for (int i = (0); i < int(sz); ++i) {
     while (ix < sz && bb[ix].first <= i) upd(bb[ix++].second);
     res += que(min(sz, i + a[i])) - i;
   }
   return res;
 }
 int main() {
   memset(t, 0, sizeof(t));
   int n, m;
   cin >> n >> m;
   for (int i = (0); i < int(n); ++i) scanf(  s  , zey[i]);
   for (int i = (0); i < int(n); ++i) {
     le[i][0] = zey[i][0] == 'z';
     ri[i][m - 1] = zey[i][m - 1] == 'z';
   }
   for (int i = (0); i < int(n); ++i)
     for (int j = (1); j < int(m); ++j)
       le[i][j] = zey[i][j] == 'z' ? 1 + le[i][j - 1] : 0;
   for (int i = (0); i < int(n); ++i)
     for (int j = (m - 1); j-- > int(0);)
       ri[i][j] = zey[i][j] == 'z' ? 1 + ri[i][j + 1] : 0;
   long long ans = 0;
   for (int s = (0); s < int(m + n - 1); ++s) {
     vector<int> a, b;
     for (int d = (max(0, s - m + 1)); d < int(min(n, s + 1)); ++d) {
       if (zey[d][s - d] == 'z') {
         a.push_back(le[d][s - d]);
         b.push_back(ri[d][s - d]);
       } else {
         ans += solve(a, b);
         a.clear();
         b.clear();
       }
     }
     ans += solve(a, b);
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 unsigned long long val(int i) { return i + 1; }
 unsigned long long pot1[100001], pot2[100001], prec1[10][100001],
     prec2[10][100001];
 int v[100000];
 struct Node {
   unsigned long long h1, h2;
   int flag;
   bool valid;
   int sz;
   Node() {
     sz = h1 = h2 = 0;
     flag = -1;
     valid = true;
   }
   Node(unsigned long long a, unsigned long long b, int c) {
     h1 = a;
     h2 = b;
     sz = c;
     flag = -1;
     valid = true;
   }
   Node(unsigned long long a, unsigned long long b, int c, bool d) {
     h1 = a;
     h2 = b;
     sz = c;
     valid = d;
     flag = -1;
   }
   void set(int c) { flag = c; }
   void reset() { flag = -1; }
   void update(int c) {
     if (c == -1) return;
     h1 = prec1[c][sz];
     h2 = prec2[c][sz];
   }
   bool operator!=(const Node& n) { return h1 != n.h1 || h2 != n.h2; }
 };
 Node st[400000];
 inline int left(int i) { return 2 * i + 1; }
 inline int right(int i) { return 2 * i + 2; }
 void initialize(int r, int beg, int end) {
   if (beg == end) {
     st[r] = Node(val(v[beg]), val(v[beg]), 1);
   } else {
     int h = (beg + end) / 2;
     initialize(left(r), beg, h);
     initialize(right(r), h + 1, end);
     st[r] = Node(
         (st[left(r)].h1 * pot1[st[right(r)].sz] + st[right(r)].h1)  1000000009,
         (st[left(r)].h2 * pot2[st[right(r)].sz] + st[right(r)].h2)  1000000007,
         st[left(r)].sz + st[right(r)].sz);
   }
 }
 void update(int r, int beg, int end, int qbeg, int qend, char c) {
   if (end < qbeg || beg > qend) {
     if (st[r].flag != -1) {
       st[r].update(st[r].flag);
       if (beg != end) {
         st[2 * r + 1].set(st[r].flag);
         st[2 * r + 2].set(st[r].flag);
       }
       st[r].reset();
     }
     return;
   }
   if (beg >= qbeg && end <= qend) {
     st[r].update(c);
     if (beg != end) {
       st[left(r)].set(c);
       st[right(r)].set(c);
     }
     st[r].reset();
   } else {
     int h = (beg + end) / 2;
     if (st[r].flag != -1) {
       st[r].update(st[r].flag);
       st[2 * r + 1].set(st[r].flag);
       st[2 * r + 2].set(st[r].flag);
       st[r].reset();
     }
     update(left(r), beg, h, qbeg, qend, c);
     update(right(r), h + 1, end, qbeg, qend, c);
     st[r] = Node(
         (st[left(r)].h1 * pot1[st[right(r)].sz] + st[right(r)].h1)  1000000009,
         (st[left(r)].h2 * pot2[st[right(r)].sz] + st[right(r)].h2)  1000000007,
         st[right(r)].sz + st[left(r)].sz);
   }
 }
 Node query(int r, int beg, int end, int qbeg, int qend) {
   if (end < qbeg || beg > qend) return Node(0, 0, false);
   if (beg >= qbeg && end <= qend) {
     if (st[r].flag != -1) {
       st[r].update(st[r].flag);
       if (beg != end) {
         st[left(r)].set(st[r].flag);
         st[right(r)].set(st[r].flag);
       }
       st[r].reset();
     }
     return st[r];
   } else {
     if (st[r].flag != -1) {
       st[r].update(st[r].flag);
       st[left(r)].set(st[r].flag);
       st[right(r)].set(st[r].flag);
       st[r].reset();
     }
     Node le = query(left(r), beg, (beg + end) / 2, qbeg, qend);
     Node ri = query(right(r), (beg + end) / 2 + 1, end, qbeg, qend);
     if (le.valid && ri.valid)
       return Node((le.h1 * pot1[ri.sz] + ri.h1)  1000000009,
                   (le.h2 * pot2[ri.sz] + ri.h2)  1000000007, le.sz + ri.sz);
     else if (le.valid)
       return le;
     else
       return ri;
   }
 }
 bool qquery(int r, int beg, int end, int qbeg, int qend, int d) {
   int sz = qend - qbeg + 1;
   if (sz <= d) return true;
   if (qbeg > qend) return 0;
   int sobra = sz  d;
   if (sobra) {
     if (query(r, beg, end, qbeg, qbeg + sobra - 1) !=
         query(r, beg, end, qend - sobra + 1, qend))
       return false;
   }
   qend -= sobra;
   sz = qend - qbeg + 1;
   int n = sz / d;
   if (sz == d) return true;
   if (n & 1) {
     int b0 = qbeg, b1 = qbeg + n / 2 * d, b2 = qbeg + (n / 2 + 1) * d;
     int e0 = b1 - 1, e1 = b2 - 1, e2 = qend;
     if (query(r, beg, end, b0, e0) != query(r, beg, end, b2, e2) ||
         query(r, beg, end, b0, b0 + d - 1) != query(r, beg, end, b1, e1))
       return false;
     return qquery(r, beg, end, b0, e0, d);
   } else {
     int b0 = qbeg, b1 = qbeg + (n + 1) / 2 * d;
     int e0 = b1 - 1, e1 = qend;
     if (query(r, beg, end, b0, e0) != query(r, beg, end, b1, e1)) return false;
     return qquery(r, beg, end, b0, e0, d);
   }
 }
 void precalc() {
   pot1[0] = 1;
   pot2[0] = 1;
   for (int i = 1; i <= 100000; i++) {
     pot1[i] = (pot1[i - 1] * 33)  1000000009;
     pot2[i] = (pot2[i - 1] * 33)  1000000007;
   }
   for (int i = 0; i < 10; i++) {
     prec1[i][0] = 0;
     prec2[i][0] = 0;
     for (int j = 1; j <= 100000; j++) {
       prec1[i][j] = (prec1[i][j - 1] * 33 + val(i))  1000000009;
       prec2[i][j] = (prec2[i][j - 1] * 33 + val(i))  1000000007;
     }
   }
 }
 int main(void) {
   int n, m, k;
   char s[100001];
   precalc();
   scanf( ddd , &n, &m, &k);
   scanf( s , s);
   for (int i = 0; i < n; i++) {
     v[i] = s[i] - '0';
   }
   initialize(0, 0, n - 1);
   for (int i = 0; i < m + k; i++) {
     int cmd;
     int l, r, x;
     scanf( dddd , &cmd, &l, &r, &x);
     if (cmd == 1) {
       l--;
       r--;
       update(0, 0, n - 1, l, r, x);
     } else {
       l--;
       r--;
       printf( s
 , qquery(0, 0, n - 1, l, r, x) ?  YES  :  NO );
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 100005, M = 500005;
 vector<int> gr[N], path, odd;
 pair<int, int> ed[M];
 bool us[M];
 void GetEulerCircuit(int u) {
   while (true) {
     while (!gr[u].empty() && us[gr[u].back()]) {
       gr[u].pop_back();
     }
     if (gr[u].empty()) {
       break;
     }
     us[gr[u].back()] = true;
     int v = u ^ ed[gr[u].back()].first ^ ed[gr[u].back()].second;
     gr[u].pop_back();
     GetEulerCircuit(v);
   }
   path.push_back(u);
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cout.tie(0);
   int n, m;
   scanf( d d  , &n, &m);
   for (int i = 0; i < m; i++) {
     int u, v;
     scanf( d d  , &u, &v);
     ed[i] = make_pair(u, v);
     gr[u].push_back(i);
     gr[v].push_back(i);
   }
   for (int u = 1; u <= n; u++) {
     if (gr[u].size()  2) {
       odd.push_back(u);
     }
   }
   for (int i = 0; i < odd.size(); i += 2) {
     int u = odd[i], v = odd[i + 1];
     ed[m] = make_pair(u, v);
     gr[u].push_back(m);
     gr[v].push_back(m);
     m++;
   }
   if (m  2) {
     ed[m] = make_pair(1, 1);
     gr[1].push_back(m);
     gr[1].push_back(m);
     m++;
   }
   GetEulerCircuit(1);
   for (int i = 0; i < m; i++) {
     int u = path[i], v = path[i + 1];
     if (i  2) {
       swap(u, v);
     }
     ed[i] = make_pair(u, v);
   }
   printf( d
 , m);
   for (int i = 0; i < m; i++) {
     int u = ed[i].first, v = ed[i].second;
     printf( d d
 , u, v);
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 inline void read(T &x) {
   x = 0;
   T f = 1;
   char c = getchar();
   for (; !isdigit(c); c = getchar())
     if (c == '-') f = -1;
   for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
   x *= f;
 }
 int main() {
   int n;
   read(n);
   for (int i = 1; i <= n; i++) {
     int x;
     read(x);
     cout << x / 6 + (x  6 == 0 ? 0 : 1) << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1e6;
 int q[maxn], fin, razbeg, jump, n;
 pair<int, int> ans[maxn];
 int sz = 0;
 int main() {
   cin >> n >> fin >> razbeg >> jump;
   for (int i = 0; i < n; i++) cin >> q[i];
   q[n] = 0;
   q[n + 1] = fin;
   n += 2;
   sort(q, q + n);
   int i = 0, now = 0;
   while (i < n - 1)
     if (i == n - 2) {
       if (fin - now > 0) ans[sz] = make_pair(0, fin - now), sz++;
       break;
     } else if (q[i + 1] - 1 - now < razbeg) {
       cout <<  IMPOSSIBLE ;
       return 0;
     } else {
       if (q[i + 1] - 1 - now > 0)
         ans[sz] = make_pair(0, q[i + 1] - 1 - now), sz++;
       now = q[i + 1] - 1;
       while (1) {
         i++;
         if (q[i] + 1 - now > jump) {
           cout <<  IMPOSSIBLE ;
           return 0;
         }
         if (i == n - 2) {
           ans[sz] = make_pair(1, q[i] + 1 - now), sz++, now = q[i] + 1;
           break;
         } else if (q[i + 1] - 1 - q[i] - 1 >= razbeg) {
           ans[sz] = make_pair(1, q[i] + 1 - now), sz++, now = q[i] + 1;
           break;
         }
       }
     }
   for (int i = 0; i < sz; i++)
     if (ans[i].first == 0)
       cout <<  RUN   << ans[i].second << '
';
     else
       cout <<  JUMP   << ans[i].second << '
';
 }


#include <bits/stdc++.h>
 using namespace std;
 long long n, q, c[100005], v[100005], f[100005];
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   cin >> n >> q;
   for (int i = 1; i <= n; i++) cin >> v[i];
   for (int i = 1; i <= n; i++) cin >> c[i];
   while (q--) {
     long long a, b, ans = 0, mx = 0, smx = 0;
     memset(f, -6, sizeof(f));
     cin >> a >> b;
     for (int i = 1; i <= n; i++) {
       long long cur = max(v[i] * b, f[c[i]] + v[i] * a);
       if (c[i] != mx)
         cur = max(cur, f[mx] + v[i] * b);
       else
         cur = max(cur, f[smx] + v[i] * b);
       if (cur > f[mx]) {
         if (mx != c[i]) smx = mx;
         mx = c[i];
       } else if (cur > f[smx] && c[i] != mx)
         smx = c[i];
       f[c[i]] = max(f[c[i]], cur);
       ans = max(ans, cur);
     }
     cout << ans << '
';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[4010][4010];
 int n, m;
 int u[4010], v[4010], sz[4010];
 int main() {
   scanf( dd , &n, &m);
   for (int i = 1; i <= m; i++) {
     scanf( dd , &u[i], &v[i]);
     a[u[i]][v[i]] = a[v[i]][u[i]] = 1;
     sz[u[i]]++;
     sz[v[i]]++;
   }
   int ans = 1e9;
   for (int i = 1; i <= m; i++) {
     int x = u[i], y = v[i];
     for (int j = i + 1; j <= m; j++) {
       int c = u[j], d = v[j];
       if (x == c && a[y][d] == 1) {
         ans = min(ans, sz[x] + sz[y] + sz[d] - 6);
       } else if (x == d && a[y][c] == 1) {
         ans = min(ans, sz[x] + sz[c] + sz[y] - 6);
       } else if (y == c && a[x][d] == 1) {
         ans = min(ans, sz[y] + sz[x] + sz[d] - 6);
       } else if (y == d && a[x][c] == 1) {
         ans = min(ans, sz[y] + sz[x] + sz[c] - 6);
       }
     }
   }
   if (ans == 1e9)
     cout << -1 << endl;
   else
     cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXK = 26;
 const long long MOD = 1e9 + 7;
 int last[MAXK], ord[MAXK];
 long long sum, dp[MAXK];
 void add(int c) {
   sum = (sum - dp[c] + MOD)  MOD;
   dp[c] = (dp[c] + sum + 1)  MOD;
   sum = (sum + dp[c])  MOD;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   int N, K;
   string S;
   cin >> N >> K >> S;
   memset((last), (-1), sizeof(last));
   sum = 0;
   for (int _n((int)S.size()), i(0); i < _n; i++) {
     int c = S[i] - 'a';
     last[c] = i;
     add(c);
   }
   iota(ord, ord + K, 0);
   sort(ord, ord + K, [](int a, int b) { return last[a] < last[b]; });
   for (int _n(N), i(0); i < _n; i++) {
     int c = ord[i  K];
     add(c);
   }
   cout << (sum + 1)  MOD << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 #pragma GCC optimize( Ofast )
 const int INF = 1e9 + 7;
 const long long INF2 = 1e15;
 void solve(void) {}
 int main(void) {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long n, l, r, ql, qr;
   cin >> n >> l >> r >> ql >> qr;
   vector<long long> v(n);
   for (int i = 0; i < n; i++) cin >> v[i];
   long long total = 0;
   vector<long long> left(n + 1), right(n + 1);
   for (long long i = 0; i < n; i++) {
     total += v[i] * l;
     left[i + 1] = total;
   }
   total = 0;
   for (long long i = n - 1; i >= 0; i--) {
     total += v[i] * r;
     right[i] = total;
   }
   long long ans = INF, current;
   for (long long i = 0; i <= n; i++) {
     long long a = i, b = n - i, change;
     current = INF;
     change = min(a, b);
     a -= change;
     b -= change;
     if (a) {
       a--;
       current = min(current, a * ql);
     } else if (b) {
       current = min(current, b * qr);
     } else {
       current = 0;
     }
     a = i, b = n - i;
     change = min(a, b);
     a -= change;
     b -= change;
     if (b) {
       b--;
       current = min(current, b * qr);
     } else if (a) {
       current = min(current, a * ql);
     } else {
       current = 0;
     }
     long long temp = 0;
     a = i, b = n - i;
     if (b) {
       b--;
       temp += qr * b;
     }
     if (a) {
       a--;
       temp += ql * a;
     }
     current = min(current, temp);
     ans = min(ans, current + left[i] + right[i]);
   }
   cout << ans << '
';
 }


#include <bits/stdc++.h>
 using namespace std;
 using namespace std;
 int main() {
   int n, k, q;
   cin >> n >> k >> q;
   vector<long long> vec(n + 1);
   vector<long long> pq;
   map<long long, long long> ar, ans, rev;
   for (int i = 1; i <= n; i++) cin >> vec[i], ar[i] = vec[i], rev[vec[i]] = i;
   while (q--) {
     int a, b;
     cin >> a >> b;
     if (a == 1) {
       pq.push_back(ar[b]);
       ans[b] = 1;
       if (pq.size() > k) {
         sort(pq.begin(), pq.end());
         long long dd = rev[pq[0]];
         ans[dd] = 0;
         pq.erase(pq.begin());
       }
     } else {
       if (ans[b]) {
         cout <<  YES
 ;
       } else
         cout <<  NO
 ;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline int lowbit(int x) { return x & -x; }
 inline int ABS(int x) { return x < 0 ? -x : x; }
 inline long long ABS(long long x) { return x < 0 ? -x : x; }
 inline void MAX(int &a, int b) {
   if (b > a) a = b;
 }
 inline void MAX(long long &a, long long b) {
   if (b > a) a = b;
 }
 inline void MIN(int &a, int b) {
   if (b < a) a = b;
 }
 inline void MIN(long long &a, long long b) {
   if (b < a) a = b;
 }
 inline void SUM(int &a, int b) { a = (a + b)  1000000007; }
 int fast(int x, int v) {
   int ans = 1;
   for (; v; v >>= 1, x = (long long)x * x  1000000007)
     if (v & 1) ans = (long long)ans * x  1000000007;
   return ans;
 }
 long long fast(long long x, long long v) {
   long long ans = 1;
   for (; v; v >>= 1, x = x * x  1000000007)
     if (v & 1) ans = ans * x  1000000007;
   return ans;
 }
 inline long long sqr(int x) { return x * x; }
 int n, a[300005], l, r, sum;
 long long pre[300005], ans;
 map<int, int> s;
 int main() {
   scanf( d , &n);
   for (int i = 1; i <= n; ++i) {
     scanf( d , a + i);
     pre[i] = pre[i - 1] + (a[i] < 0 ? 0 : a[i]);
     if (!s[a[i]]) s[a[i]] = i;
   }
   ans = -0x7f7f7f7f;
   for (int i = n; i >= 1; --i)
     if (s[a[i]] && s[a[i]] != i && pre[i - 1] - pre[s[a[i]]] + a[i] * 2 > ans) {
       ans = pre[i - 1] - pre[s[a[i]]] + a[i] * 2;
       l = s[a[i]];
       r = i;
     }
   for (int i = l + 1; i <= r - 1; ++i)
     if (a[i] < 0) ++sum;
   printf( extra d
 , ans, sum + l - 1 + n - r);
   for (int i = 1; i <= l - 1; ++i) printf( d  , i);
   for (int i = l + 1; i <= r - 1; ++i)
     if (a[i] < 0) printf( d  , i);
   for (int i = r + 1; i <= n; ++i) printf( d  , i);
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long INF = 9223372036854775807;
 const long long MOD = 1000000007;
 const long double PI = acos(-1);
 inline long long power(long long a, long long b, long long z = MOD) {
   long long res = 1;
   a = (a  z);
   while (b) {
     if (b & 1) res = (res * a)  z;
     a = (a * a)  z;
     b = b >> 1;
   }
   return res;
 }
 inline long long inverse(long long a, long long z = MOD) {
   return power(a, z - 2, z);
 }
 long long extend(long long a, long long b, long long &x, long long &y) {
   if (b == 0) {
     x = 1;
     y = 0;
     return a;
   }
   long long x1, y1;
   long long g = extend(b, a  b, x1, y1);
   x = y1;
   y = x1 - (a / b) * y1;
   return g;
 }
 inline long long mat_power(long long a, long long b, long long c, long long d,
                            long long n, long long z = MOD) {
   long long a0 = 1, b0 = 0, c0 = 0, d0 = 1;
   while (n) {
     if (n & 1) {
       long long a1 = a0, b1 = b0, c1 = c0, d1 = d0;
       a0 = (a1 * a + b1 * c)  z;
       b0 = (a1 * b + b1 * d)  z;
       c0 = (c1 * a + d1 * c)  z;
       d0 = (c1 * b + d1 * d)  z;
     }
     long long a1 = a, b1 = b, c1 = c, d1 = d;
     a = (a1 * a1 + b1 * c1)  z;
     b = (a1 * b1 + b1 * d1)  z;
     c = (c1 * a1 + d1 * c1)  z;
     d = (c1 * b1 + d1 * d1)  z;
     n = n >> 1;
   }
   return c0;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n, m;
   cin >> n >> m;
   int aray[n][m], arr[n][m];
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < m; j++) cin >> aray[i][j];
   }
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < m; j++) cin >> arr[i][j];
   }
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < m; j++) {
       if (aray[i][j] > arr[i][j]) swap(aray[i][j], arr[i][j]);
     }
   }
   for (int i = 0; i < n; i++) {
     for (int j = 1; j < m; j++) {
       if (aray[i][j] <= aray[i][j - 1] || arr[i][j] <= arr[i][j - 1]) {
         cout <<  Impossible
 ;
         return 0;
       }
     }
   }
   for (int j = 0; j < m; j++) {
     for (int i = 1; i < n; i++) {
       if (aray[i][j] <= aray[i - 1][j] || arr[i][j] <= arr[i - 1][j]) {
         cout <<  Impossible
 ;
         return 0;
       }
     }
   }
   cout <<  Possible
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   map<char, int> mp;
   mp['q'] = 9;
   mp['k'] = 0;
   mp['r'] = 5;
   mp['b'] = 3;
   mp['n'] = 3;
   mp['p'] = 1;
   int white = 0, black = 0;
   for (int i = 0; i < 8; i++) {
     for (int j = 0; j < 8; j++) {
       char x;
       cin >> x;
       if (x >= 'A' && x <= 'Z') white += mp[x + 32];
       if (x >= 'a' && x <= 'z') black += mp[x];
     }
   }
   if (white > black)
     cout <<  White  << endl;
   else if (white == black)
     cout <<  Draw  << endl;
   else
     cout <<  Black  << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int MAXN = 20;
 long long int dp[MAXN][MAXN];
 long long int tav[MAXN];
 long long int n;
 string s;
 long long int dtoc(char x) { return x - '0'; }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   tav[0] = 1;
   for (int i = 1; i < MAXN; i++) {
     tav[i] = 10 * tav[i - 1];
   }
   cin >> n;
   cin >> s;
   for (int i = 0; i <= n; i++) {
     for (int j = 0; j <= n; j++) {
       if (i) {
         dp[i][j] = dp[i - 1][j] + dtoc(s[2 * n - i - j]) * tav[i - 1];
       }
       if (j) {
         dp[i][j] =
             max(dp[i][j], dp[i][j - 1] + dtoc(s[2 * n - i - j]) * tav[j - 1]);
       }
     }
   }
   int i = n;
   int j = n;
   while (i > 0 || j > 0) {
     if (i && dp[i - 1][j] + dtoc(s[2 * n - i - j]) * tav[i - 1] == dp[i][j]) {
       i--;
       cout << 'H';
     } else {
       j--;
       cout << 'M';
     }
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int v[300123], n, ans, g[300123], f[300123], a, b, m, op;
 queue<int> q;
 int main() {
   ios_base::sync_with_stdio(0);
   cin >> n;
   for (int i = 1; i <= n; ++i) {
     cin >> v[i];
     if (~v[i])
       g[v[i]]++;
     else {
       g[0]++;
     }
   }
   ans = 1;
   for (int i = 1; i <= n; ++i) {
     if (g[i] == 0) {
       q.push(i);
       f[i] = 1;
     }
   }
   while (!q.empty()) {
     int u = q.front();
     q.pop();
     g[v[u]]--;
     if (g[v[u]] == 0) {
       f[v[u]] = f[u] + 1;
       q.push(v[u]);
       ans = max(ans, f[v[u]]);
     }
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   int t;
   cin >> t;
   for (int i = 0; i < t; i++) {
     int x;
     cin >> x;
     int ans = (x  10 - 1) * 10;
     ans += 1;
     if (x / 10 > 0) ans += 2;
     if (x / 100 > 0) ans += 3;
     if (x / 1000 > 0) ans += 4;
     cout << ans << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(NULL);
   cin.tie(0);
   cout.tie(0);
   int t;
   cin >> t;
   while (t--) {
     int a, b, c, m;
     cin >> a >> b >> c >> m;
     int len = a + b + c;
     int maxi = len - 3;
     int valMax = max(a, max(b, c));
     int mini = max(0, ((2 * valMax) - len - 1));
     if (m < mini || m > maxi)
       cout <<  NO
 ;
     else
       cout <<  YES
 ;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename A, typename B>
 ostream &operator<<(ostream &os, const pair<A, B> &p) {
   return os << '(' << p.first <<  ,   << p.second << ')';
 }
 template <typename T_container, typename T = typename enable_if<
                                     !is_same<T_container, string>::value,
                                     typename T_container::value_type>::type>
 ostream &operator<<(ostream &os, const T_container &v) {
   os << '{';
   string sep;
   for (const T &x : v) os << sep << x, sep =  ,  ;
   return os << '}';
 }
 void dbg_out() { cerr << endl; }
 template <typename Head, typename... Tail>
 void dbg_out(Head H, Tail... T) {
   cerr << ' ' << H;
   dbg_out(T...);
 }
 const int INF = 1 << 30;
 const int MOD = 1e9 + 7;
 const int MAXN = 2e5 + 5;
 string asignar(int n) {
   if (n == 0) return  S ;
   if (n == 1) return  M ;
   if (n == 2) return  L ;
   if (n == 3) return  XL ;
   if (n == 4) return  XXL ;
   if (n == 5) return  XXXL ;
 }
 int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   vector<int> stock(6);
   for (long long i = (0); i < (long long)(6); i++) cin >> stock[i];
   int n;
   cin >> n;
   vector<pair<pair<int, int>, int>> quiero(n);
   for (long long j = (0); j < (long long)(n); j++) {
     string s;
     cin >> s;
     string curr =   ;
     pair<int, int> x = make_pair(-1, -1);
     for (long long i = (0); i < (long long)(s.size()); i++) {
       if (s[i] != ',') {
         curr += s[i];
       } else {
         if (curr ==  S ) x.first = 0;
         if (curr ==  M ) x.first = 1;
         if (curr ==  L ) x.first = 2;
         if (curr ==  XL ) x.first = 3;
         if (curr ==  XXL ) x.first = 4;
         if (curr ==  XXXL ) x.first = 5;
         curr =   ;
       }
     }
     if (curr ==  S ) x.second = 0;
     if (curr ==  M ) x.second = 1;
     if (curr ==  L ) x.second = 2;
     if (curr ==  XL ) x.second = 3;
     if (curr ==  XXL ) x.second = 4;
     if (curr ==  XXXL ) x.second = 5;
     if (x.first == -1) x.first = x.second;
     if (x.first > x.second) swap(x.first, x.second);
     quiero[j] = make_pair(x, j);
   }
   sort((quiero).begin(), (quiero).end());
   ;
   vector<string> ans(n);
   for (long long i = (0); i < (long long)(n); i++) {
     if (stock[quiero[i].first.first] > 0) {
       ans[quiero[i].second] = asignar(quiero[i].first.first);
       stock[quiero[i].first.first]--;
     } else if (stock[quiero[i].first.second] > 0) {
       ans[quiero[i].second] = asignar(quiero[i].first.second);
       stock[quiero[i].first.second]--;
     } else {
       cout <<  NO
 ;
       return 0;
     }
   }
   cout <<  YES
 ;
   for (long long i = (0); i < (long long)(n); i++) cout << ans[i] <<
 ;
   cout <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 inline int in() {
   int x;
   scanf( d , &x);
   return x;
 }
 const int N = 1e6 + 7;
 int n, m, a[N], Q;
 long long SUM, psr[N], psl[N];
 int en[N], st[N];
 pair<int, long long> dpl[N], dpr[N];
 int solve(long long maax) {
   if (maax >= SUM) return 1;
   long long sum = 0, cur = 0;
   for (int i = 0; i < n; i++) {
     sum += a[i];
     while (sum > maax) {
       en[cur] = i - 1;
       sum -= a[cur];
       cur++;
     }
   }
   while (cur < n) en[cur++] = n - 1;
   sum = 0, cur = n - 1;
   for (int i = n - 1; i >= 0; i--) {
     sum += a[i];
     while (sum > maax) {
       st[cur] = i + 1;
       sum -= a[cur];
       cur--;
     }
   }
   while (cur >= 0) st[cur--] = 0;
   for (int i = 0; i < n; i++) {
     if (st[i] == 0)
       dpl[i] = {1, psl[i + 1]};
     else
       dpl[i] = dpl[st[i] - 1], dpl[i].first++;
   }
   for (int i = n - 1; i >= 0; --i) {
     if (en[i] == n - 1)
       dpr[i] = {1, psr[i]};
     else
       dpr[i] = dpr[en[i] + 1], dpr[i].first++;
   }
   int mn = dpr[0].first;
   for (int i = 1; i < n; i++)
     mn = min(mn, dpr[i].first + dpl[i - 1].first -
                      ((dpr[i].second + dpl[i - 1].second) <= maax));
   return mn;
 }
 int32_t main() {
   n = in(), Q = in();
   for (int i = 0; i < n; i++) {
     a[i] = in();
     SUM += a[i];
     psl[i + 1] = a[i] + psl[i];
   }
   for (int i = n - 1; i >= 0; --i) psr[i] = psr[i + 1] + a[i];
   while (Q--) {
     long long x;
     cin >> x;
     cout << solve(x) << '
';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int a[1005][1005], used[1005][1005];
 const int dx[4] = {0, 0, 1, -1};
 const int dy[4] = {1, -1, 0, 0};
 void DFS(int i, int j, int N, int M) {
   if (i == 0 || i == N + 1 || j == 0 || j == M + 1 || used[i][j]) return;
   used[i][j] = 1;
   for (int d = 0; d < 4; ++d)
     if (a[i + dx[d]][j + dy[d]] == 1) DFS(i + dx[d], j + dy[d], N, M);
 }
 int main() {
   int N, M;
   scanf( dd , &N, &M);
   int numberBlacks = 0;
   for (int i = 1; i <= N; ++i) {
     char s[1005];
     scanf( s , s + 1);
     for (int j = 1; j <= M; ++j)
       if (s[j] == '#') {
         a[i][j] = 1;
         ++numberBlacks;
       }
   }
   if (numberBlacks == 0) {
     printf( 0
 );
     return 0;
   }
   int emptyLines = 0;
   for (int i = 1; i <= N; ++i) {
     int cnt = 0, numberLineSegments = 0;
     for (int j = 1; j <= M; ++j) {
       cnt += a[i][j];
       if (a[i][j - 1] == 0 && a[i][j] == 1) ++numberLineSegments;
     }
     if (numberLineSegments > 1) {
       printf( -1
 );
       return 0;
     }
     if (cnt == 0) ++emptyLines;
   }
   int emptyColumns = 0;
   for (int j = 1; j <= M; ++j) {
     int cnt = 0, numberColumnSegments = 0;
     for (int i = 1; i <= N; ++i) {
       cnt += a[i][j];
       if (a[i - 1][j] == 0 && a[i][j] == 1) ++numberColumnSegments;
     }
     if (numberColumnSegments > 1) {
       printf( -1
 );
       return 0;
     }
     if (cnt == 0) ++emptyColumns;
   }
   if (emptyLines == 0 && emptyColumns > 0 ||
       emptyLines > 0 && emptyColumns == 0) {
     printf( -1
 );
     return 0;
   }
   int connectedComponents = 0;
   for (int i = 1; i <= N; ++i)
     for (int j = 1; j <= M; ++j)
       if (used[i][j] == 0 && a[i][j] == 1) {
         ++connectedComponents;
         DFS(i, j, N, M);
       }
   printf( d
 , connectedComponents);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <typename T>
 T scani(T &n) {
   n = 0;
   bool negative = false;
   char c = getchar();
   while (c < '0' || c > '9') {
     if (c == '-') negative = true;
     c = getchar();
   }
   while (c >= '0' && c <= '9') {
     n = n * 10 + c - 48;
     c = getchar();
   }
   if (negative) n = ~(n - 1);
   return n;
 }
 template <typename T>
 void write(T n, int type = true) {
   if (n < 0) {
     putchar('-');
     n = -n;
   }
   if (!n) {
     putchar('0');
     if (type == 32)
       putchar(' ');
     else if (type)
       putchar('
');
     return;
   }
   char buff[22];
   int len = 0;
   while (n) buff[len++] = n  10 + 48, n /= 10;
   for (int i = len - 1; i >= 0; i--) putchar(buff[i]);
   if (type == 32)
     putchar(' ');
   else if (type)
     putchar('
');
 }
 int scans(char *a) {
   int i = 0;
   char c = 0;
   while (c < 33) c = getchar();
   while (c > 33) {
     a[i++] = c;
     c = getchar();
   }
   a[i] = 0;
   return i;
 }
 const int N = 100005;
 int main() {
   int n, k;
   scani(n), scani(k);
   int ans;
   ans = (2 * n + k - 1) / k + (5 * n + k - 1) / k + (8 * n + k - 1) / k;
   write(ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 template <class T>
 inline bool uin(T& a, T b) {
   return a > b ? (a = b, true) : false;
 }
 template <class T>
 inline bool uax(T& a, T b) {
   return a < b ? (a = b, true) : false;
 }
 const int nax = 5123;
 pair<int, int> edge[nax];
 vector<int> g[nax];
 int col[nax];
 int N, M;
 bool cycle_found = false;
 int dfs_num[nax];
 void dfs(int v) {
   dfs_num[v] = 1;
   for (int i : g[v]) {
     int ch = edge[i].first ^ edge[i].second ^ v;
     if (dfs_num[ch] == 2) {
       continue;
     } else if (dfs_num[ch] == 1) {
       col[i] = 1;
       cycle_found = true;
       continue;
     }
     dfs(ch);
   }
   dfs_num[v] = 2;
 }
 int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cin >> N >> M;
   for (int u, v, i = 0; i < M; ++i) {
     cin >> u >> v;
     --u, --v;
     edge[i] = make_pair(u, v);
     g[u].push_back(i);
   }
   for (int i = 0; i < N; ++i)
     if (dfs_num[i] != 2) dfs(i);
   cout << (cycle_found ? 2 : 1) << '
';
   for (int i = 0; i < M; ++i) cout << col[i] + 1 <<
 [i == M - 1];
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m, mid, rt, res, a[200010], f[200010], sz[200010];
 vector<int> e[200010];
 void dfs(int u, int fa) {
   f[u] = sz[u] = 1;
   int m1 = 0, m2 = 0;
   for (auto v : e[u]) {
     if (v == fa) continue;
     dfs(v, u);
     sz[u] += sz[v];
     if (f[v] == sz[v])
       f[u] += f[v];
     else {
       if (f[v] > m1) swap(f[v], m1);
       if (f[v] > m2) swap(f[v], m2);
     }
   }
   f[u] = a[u] < mid ? 0 : f[u] + m1;
   res = max(res, f[u] + m2);
 }
 int main() {
   scanf( dd , &n, &m);
   for (int i = 1; i <= n; i++) scanf( d , &a[i]);
   for (int i = 1; i < n; i++) {
     int u, v;
     scanf( dd , &u, &v);
     e[u].push_back(v);
     e[v].push_back(u);
   }
   rt = min_element(a + 1, a + 1 + n) - a;
   int l = 0, r = 1000010, ans;
   while (l <= r) {
     mid = (l + r) >> 1;
     res = 0;
     dfs(rt, 0);
     if (res >= m)
       l = mid + 1, ans = mid;
     else
       r = mid - 1;
   }
   printf( d
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool used[10000005];
 int ans[105];
 bool comp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
   if (a.first.second == b.first.second) return a.first.first < b.first.first;
   return a.first.second < b.first.second;
 }
 void solve() {
   int N;
   cin >> N;
   vector<pair<pair<int, int>, int>> x(N);
   for (int i = 0; i < N; i++) {
     cin >> x[i].first.first >> x[i].first.second;
     x[i].second = i;
   }
   sort(x.begin(), x.end(), comp);
   for (int i = 0; i < N; i++) {
     for (int j = x[i].first.first; j < x[i].first.second + 1; j++) {
       if (!used[j]) {
         used[j] = true;
         ans[x[i].second] = j;
         break;
       }
     }
   }
   for (int i = 0; i < N; i++) {
     cout << ans[i] <<    ;
   }
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t = 1;
   while (t--) {
     solve();
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const long long MAXN = 200100, M = 1000000009;
 string s;
 long long n, ans = 0, a[MAXN], b[MAXN];
 void obra(long long v) {
   long long tc = 0, k = a[v];
   for (long long i = 0; i < n; i++) {
     b[i] = a[i] + k / n;
     if (i == v) b[i] -= a[i];
   }
   k = 14;
   for (long long i = 0; i < k; i++) {
     b[(v + 1 + i)  n]++;
   }
   for (long long i = 0; i < n; i++) {
     if (b[i]  2 == 0) {
       tc += b[i];
     }
   }
   if (ans < tc) ans = tc;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   n = 14;
   for (long long i = 0; i < n; i++) {
     cin >> a[i];
   }
   for (long long i = 0; i < n; i++) obra(i);
   cout << ans;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   int n;
   cin >> n;
   long long arr[n];
   for (int i = 0; i < n; i++) scanf( lld , &arr[i]);
   map<long long, int> mp;
   long long sum = 0;
   for (int i = n - 1; i >= 0; i--) {
     sum += arr[i];
     mp[sum] = i;
   }
   long long ans = 0;
   long long cnt = 0;
   for (int i = 0; i < n; i++) {
     cnt += arr[i];
     if (mp[cnt] > i && mp[cnt] != 0) {
       ans = max(cnt, ans);
     }
   }
   cout << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 using ll = long long;
 using ld = long double;
 template <typename T>
 T &chmin(T &a, const T &b) {
   return a = min(a, b);
 }
 template <typename T>
 T &chmax(T &a, const T &b) {
   return a = max(a, b);
 }
 template <typename T>
 T inf;
 template <>
 constexpr int inf<int> = 1e9;
 template <>
 constexpr ll inf<ll> = 1e18;
 template <>
 constexpr ld inf<ld> = 1e30;
 struct yes_no : numpunct<char> {
   string_type do_truename() const { return  Yes ; }
   string_type do_falsename() const { return  No ; }
 };
 int N, K;
 int A[501000];
 int main() {
   locale loc(locale(), new yes_no);
   cout << boolalpha;
   cout.imbue(loc);
   scanf( dd , &K, &N);
   for (int i = 0; i < (int)(N); i++) scanf( d , &A[i]);
   sort(A, A + N);
   set<pair<ll, ll>> index_value, value_index;
   for (int i = 0; i < (int)(N - 1); i++) {
     const int val = A[i + 1] - A[i];
     index_value.emplace(i, val);
     value_index.emplace(val, i);
   }
   index_value.emplace(-1, inf<ll>);
   index_value.emplace(N, inf<ll>);
   value_index.emplace(inf<ll>, -1);
   value_index.emplace(inf<ll>, N);
   ll res = 0;
   for (int loop = 0; loop < (int)(K); loop++) {
     int v, l, r;
     ll val, lval, rval;
     tie(val, v) = *begin(value_index);
     auto it = index_value.lower_bound(make_pair(v, val));
     tie(l, lval) = *prev(it);
     tie(r, rval) = *next(it);
     index_value.erase(make_pair(v, val));
     index_value.erase(make_pair(l, lval));
     index_value.erase(make_pair(r, rval));
     value_index.erase(make_pair(val, v));
     value_index.erase(make_pair(lval, l));
     value_index.erase(make_pair(rval, r));
     index_value.emplace(v, lval + rval - val);
     value_index.emplace(lval + rval - val, v);
     res += val;
   }
   cout << res << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 vector<int> childs[100000 + 1];
 long long s[100000 + 1];
 int p[100000 + 1];
 long long a[100000 + 1];
 bool flag = false;
 void fill(int v, long long prevsum) {
   if (s[v] != -1) {
     a[v] = s[v] - prevsum;
     if (a[v] < 0) flag = true;
     for (int i = 0; i < childs[v].size(); ++i) {
       fill(childs[v][i], s[v]);
     }
   } else {
     long long mi = 1000000001;
     for (int i = 0; i < childs[v].size(); ++i) {
       mi = min(mi, s[childs[v][i]]);
     }
     if (mi == 1000000001) mi = prevsum;
     a[v] = mi - prevsum;
     if (a[v] < 0) flag = true;
     for (int i = 0; i < childs[v].size(); ++i) {
       fill(childs[v][i], mi);
     }
   }
 }
 int main() {
   int n;
   cin >> n;
   for (int i = 0; i < n; ++i) {
     childs[i].clear();
   }
   for (int i = 2; i < n + 1; ++i) {
     cin >> p[i];
     childs[p[i]].push_back(i);
   }
   for (int i = 1; i < n + 1; ++i) {
     cin >> s[i];
   }
   fill(1, 0);
   if (flag)
     cout << -1 << endl;
   else {
     long long sum = 0;
     for (int i = 1; i < n + 1; ++i) {
       sum += a[i];
     }
     cout << sum << endl;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 string a, b;
 int i, ax, ay, bx, by;
 int main() {
   cin >> a >> b;
   for (i = 0; i < a.length(); i++)
     if (a[i] == '1')
       ax++;
     else
       ay++;
   for (i = 0; i <= b.length(); i++)
     if (b[i] == '1')
       bx++;
     else
       by++;
   if (ax  2 == 1) ax++;
   if (ax < bx)
     cout <<  NO ;
   else
     cout <<  YES ;
   return 0;
 }


#include <bits/stdc++.h>
 #pragma comment(linker, '/STACK:200000')
 const int INF = 1e9 + 7;
 const double EPS = 1e-6;
 const double pi = acos(-1);
 const int MOD = 1e9 + 7;
 const int N = 1e5 + 1000;
 using namespace std;
 double mid;
 struct node {
   int pos, val;
   node() { pos = val = 0; }
   node(int a, int b) {
     pos = a;
     val = b;
   }
   bool operator<(node a) const {
     if (val != a.val) return val < a.val;
     if (abs(mid - pos * 1.0) != abs(mid - a.pos * 1.0))
       return abs(mid - pos * 1.0) < abs(mid - a.pos * 1.0);
     return pos < a.pos;
   }
 };
 int n, m, ans[N];
 set<node> st;
 int main() {
   cin >> n >> m;
   mid = (m + 1) * 0.5;
   for (int i = 1; i <= m; i++) {
     st.insert(node(i, 0));
   }
   for (int i = 1; i <= n; i++) {
     auto it = *st.begin();
     st.erase(it);
     it.val++;
     ans[i] = it.pos;
     st.insert(it);
   }
   for (int i = 1; i <= n; i++) cout << ans[i] <<
 ;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, k, op;
 string tes;
 int main() {
   cin >> n >> k >> ws >> tes;
   op = 0;
   for (int i = 1; i < n; i++)
     if (tes.substr(0, i) == tes.substr(n - i, i)) op = i;
   cout << tes;
   tes = tes.substr(op, tes.length());
   for (int i = 1; i < k; i++) cout << tes;
   cout << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 char x[100100];
 long x2[100100];
 long mes[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 long wr = 0;
 long res, cur, repsmax = -1;
 long reps = 0;
 long tmp1, tmp2, tmp3;
 string s1;
 int compare(const void *a, const void *b) { return (*(long *)a - *(long *)b); }
 long check(long z) {
   if ((isdigit(x[z])) && (isdigit(x[z + 1])) && (isdigit(x[z + 3])) &&
       (isdigit(x[z + 4])) && (isdigit(x[z + 6])) && (isdigit(x[z + 7])) &&
       (isdigit(x[z + 8])) && (isdigit(x[z + 9]))) {
     if ((x[z + 2] == x[z + 5]) && (x[z + 2] == '-')) {
       tmp1 =
           ((long)(x[z]) - (long)('0')) * 10 + ((long)(x[z + 1]) - (long)('0'));
       tmp2 = ((long)(x[z + 3]) - (long)('0')) * 10 +
              ((long)(x[z + 4]) - (long)('0'));
       tmp3 = ((long)(x[z + 6]) - (long)('0')) * 1000 +
              ((long)(x[z + 7]) - (long)('0')) * 100 +
              (((long)(x[z + 8]) - (long)('0')) * 10) +
              ((long)(x[z + 9]) - (long)('0'));
       if ((tmp2 <= 12) && (tmp3 <= 2015) && (tmp3 >= 2013)) {
         if ((tmp1 <= mes[tmp2]) && (tmp2 != 0) && (tmp1 != 0)) {
           x2[wr++] = tmp1 + tmp2 * 100 + tmp3 * 10000;
         }
       }
     }
   }
   if ((!isdigit(x[z + 9])) && (x[z + 9] != '-')) {
     return -2;
   }
 }
 int main(int argc, char *argv[]) {
   scanf( s , &x);
   long j = 0;
   while (check(j++) > -2) {
   }
   qsort(x2, wr - 1, sizeof(long), compare);
   cur = x2[0];
   for (long j = 0; j < wr; j++) {
     if (cur == x2[j]) {
       reps++;
     } else {
       if (reps > repsmax) {
         repsmax = reps;
         res = cur;
       }
       cur = x2[j];
       reps = 1;
     }
   }
   if (reps > repsmax) {
     repsmax = reps;
     res = cur;
   }
   cur = x2[j];
   reps = 1;
   ldiv_t divresult1;
   divresult1 = ldiv(res, 100);
   if (divresult1.rem < 10) {
     cout <<  0 ;
   }
   cout << divresult1.rem <<  - ;
   ldiv_t divresult2;
   divresult2 = ldiv(res, 10000);
   if (((divresult2.rem - divresult1.rem) / 100) < 10) {
     cout <<  0 ;
   }
   cout << (divresult2.rem - divresult1.rem) / 100 <<  - ;
   ldiv_t divresult3;
   divresult3 = ldiv(res, 100000000);
   cout << (divresult3.rem - divresult2.rem) / 10000;
   return EXIT_SUCCESS;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 100005;
 int n, m;
 vector<pair<int, int> > e[N];
 vector<int> ans[2];
 bool fla[2], flag;
 int E[N], d[N];
 vector<int> cnt[2];
 void DFS(int first, int o, int res) {
   if (flag) return;
   d[first] = o;
   cnt[o].push_back(first);
   for (auto& i : e[first]) {
     if (flag) return;
     int second = (i.second + o)  2;
     if (d[i.first] == -1)
       DFS(i.first, second != res, res);
     else if (d[i.first] != (second != res))
       flag = true;
   }
 }
 void SOLVE(int res) {
   memset(d, -1, sizeof(d));
   flag = false;
   for (int i(1); i <= n; i++)
     if (d[i] == -1) {
       cnt[0].clear();
       cnt[1].clear();
       DFS(i, 0, res);
       if (flag) {
         fla[res] = true;
         return;
       }
       for (bool ___ = 1; ___; ___ = 0) {
         int mx = (cnt[1].size() < cnt[0].size());
         for (auto& i : cnt[mx]) ans[res].push_back(i);
       }
     }
 }
 int main() {
   n = ({
     long long first = 0;
     int n = 0, c = getchar();
     for (; !isdigit(c); c = getchar()) n = c == '-';
     for (; isdigit(c); c = getchar()) first = first * 10 + c - '0';
     n ? -first : first;
   }),
   m = ({
     long long first = 0;
     int n = 0, c = getchar();
     for (; !isdigit(c); c = getchar()) n = c == '-';
     for (; isdigit(c); c = getchar()) first = first * 10 + c - '0';
     n ? -first : first;
   });
   for (int i(1); i <= m; i++) {
     int first = ({
       long long first = 0;
       int n = 0, c = getchar();
       for (; !isdigit(c); c = getchar()) n = c == '-';
       for (; isdigit(c); c = getchar()) first = first * 10 + c - '0';
       n ? -first : first;
     }),
         second = ({
           long long first = 0;
           int n = 0, c = getchar();
           for (; !isdigit(c); c = getchar()) n = c == '-';
           for (; isdigit(c); c = getchar()) first = first * 10 + c - '0';
           n ? -first : first;
         });
     int c = ({
               char c = getchar();
               while (c == ' ' || c == '
') c = getchar();
               c;
             }) == 'R';
     e[first].push_back({second, c});
     e[second].push_back({first, c});
   }
   SOLVE(0);
   SOLVE(1);
   for (bool ___ = 1; ___; ___ = 0) {
     int res;
     if (fla[0] && fla[1])
       return cout << -1 <<
 , 0;
     else if (fla[0])
       res = 1;
     else if (fla[1])
       res = 0;
     else if (ans[0].size() < ans[1].size())
       res = 0;
     else
       res = 1;
     cout << ans[res].size() <<
 ;
     for (auto& i : ans[res]) cout << i <<    ;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 class BLongtailHedgehog {
  public:
   int N, M;
   vector<int> dist, deg_in, deg;
   vector<vector<int>> G;
   void input(std::istream& in, std::ostream& out) {
     ios_base::sync_with_stdio(false);
     in >> N >> M;
     dist = vector<int>(N, -1);
     deg_in = vector<int>(N, 0);
     deg = vector<int>(N, 0);
     G = vector<vector<int>>(N, vector<int>());
     for (int(i) = (0); (i) < (M); ++(i)) {
       int u, v;
       in >> u >> v;
       u--, v--;
       if (u > v) swap(u, v);
       G[u].push_back(v);
       deg_in[v]++, deg[u]++, deg[v]++;
     }
   }
   void bfs(int s) {
     queue<int> q;
     dist[s] = 1, q.push(s);
     while (!q.empty()) {
       int u = q.front();
       q.pop();
       for (auto v : G[u]) {
         deg_in[v]--;
         dist[v] = max(dist[v], dist[u] + 1);
         if (deg_in[v] == 0) {
           q.push(v);
         }
       }
     }
   }
   void solve(std::istream& in, std::ostream& out) {
     input(in, out);
     for (int(i) = (0); (i) < (N); ++(i)) {
       if (dist[i] == -1) bfs(i);
     }
     long long ans = 0;
     for (int(i) = (0); (i) < (N); ++(i)) ans = max(ans, 1LL * dist[i] * deg[i]);
     out << ans << '
';
   }
 };
 int main() {
   BLongtailHedgehog solver;
   std::istream& in(std::cin);
   std::ostream& out(std::cout);
   solver.solve(in, out);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 void hi() {
   static long long i = 0;
   cout <<  Check Point :   << ++i <<
 ;
   return;
 }
 signed main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   long long t;
   t = 1;
   while (t--) {
     string str;
     cin >> str;
     long long n = str.length();
     stack<char> stk;
     for (long long i = 0; i < n; i++) {
       if (!stk.empty() && ((stk.top() == '+' && str[i] == '+') ||
                            ((stk.top() == '-' && str[i] == '-')))) {
         stk.pop();
       } else {
         stk.push(str[i]);
       }
     }
     if (stk.empty()) {
       cout <<  Yes
            <<
 ;
     } else {
       cout <<  No
            <<
 ;
     }
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 400010;
 int gcds[N], a[N], b[N];
 int c[N], mx[N];
 int gcd(int a, int b) { return b ? gcd(b, a  b) : a; }
 int main() {
   int n;
   scanf( d , &n);
   for (int i = 1; i <= n; i++) {
     scanf( d , &a[i - 1]);
     gcds[i] = gcd(i, n);
   }
   long long ans = 0;
   for (int i = 1; i < n; i++) {
     if (n  i) continue;
     for (int j = 1; j <= n; j++) c[j] = c[j - 1] + (i == gcds[j]);
     for (int j = 0; j < i; j++) mx[j] = a[j];
     for (int j = i; j < n; j++) mx[j  i] = max(mx[j  i], a[j]);
     for (int j = 0; j < n; j++) b[j] = b[j + n] = mx[j  i] == a[j];
     for (int j = 2 * n - 2; j >= 0; j--)
       if (b[j]) b[j] += b[j + 1];
     for (int j = 0; j < n; j++) ans += c[min(n - 1, b[j])];
   }
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 long long int a[300000];
 int main() {
   long long int n, i, hei, bai;
   while (scanf( lld , &n) != EOF) {
     hei = bai = 0;
     for (i = 0; i < n; i++) {
       scanf( lld , &a[i]);
       if (i  2) {
         hei += (a[i] + 1) / 2;
         bai += a[i] / 2;
       } else {
         bai += (a[i] + 1) / 2;
         hei += a[i] / 2;
       }
     }
     printf( lld
 , bai < hei ? bai : hei);
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = INT_MAX;
 const long long INFL = LLONG_MAX;
 const int output_precision = 15;
 const long double pi = acos(-1);
 const bool debug = true;
 int N;
 int A[5];
 int check() {
   vector<int> B(4);
   for (int(i) = 1, j1234 = 4; (i) <= j1234; (i)++) B[i - 1] = A[i];
   sort(B.begin(), B.end());
   int x1 = B[0] + B[1] + B[2] + B[3];
   int x2 = 2 * (B[1] + B[2]);
   int x3 = 4 * (B[3] - B[0]);
   return x1 == x2 && x2 == x3;
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cout.precision(output_precision);
   cout << fixed;
   cout.tie(0);
   cin >> N;
   for (int(i) = 1, j1234 = N; (i) <= j1234; (i)++) cin >> A[i];
   if (N == 0) {
     cout <<  YES  << '
';
     cout << 1 << '
';
     cout << 1 << '
';
     cout << 3 << '
';
     cout << 3 << '
';
     return 0;
   }
   if (N == 1) {
     int a = A[1];
     cout <<  YES  << '
';
     cout << a << '
';
     cout << 3 * a << '
';
     cout << 3 * a << '
';
     return 0;
   }
   if (N == 2) {
     for (int(x) = 1, j1234 = 1500; (x) <= j1234; (x)++)
       for (int(y) = 1, j1234 = 1500; (y) <= j1234; (y)++) {
         A[3] = x;
         A[4] = y;
         if (check()) {
           cout <<  YES  << '
';
           cout << x << '
';
           cout << y << '
';
           return 0;
         }
       }
     cout <<  NO  << '
';
     return 0;
   }
   if (N == 3) {
     for (int(i) = 1, j1234 = 1500; (i) <= j1234; (i)++) {
       A[4] = i;
       if (check()) {
         cout <<  YES  << '
';
         cout << i << '
';
         return 0;
       }
     }
     cout <<  NO  << '
';
     return 0;
   }
   if (N == 4) {
     if (check()) {
       cout <<  YES  << '
';
     } else {
       cout <<  NO  << '
';
     }
     return 0;
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 void islam() {
   ios::sync_with_stdio(false);
   cin.tie(NULL);
 }
 void get(long long &x) { cin >> x; }
 class ghost {
  public:
   ghost() {
     get(n);
     for (int i = 0; i < n; i++) {
       get(arr[i]);
       s += arr[i];
     }
     s /= n;
   }
   void solve() {
     long long c = 0;
     for (int i = 0; i < n; i++) {
       c += s - arr[i];
       a += abs(c);
     }
   }
   void print() { cout << a; }

  private:
   long long n, s;
   long long arr[50000 + 10], a = 0;
 };
 int main() {
   islam();
   ghost x;
   x.solve();
   x.print();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 bool isAscending(const vector<int64_t>& vec) {
   for (int i = 1; i < vec.size(); ++i) {
     if (vec[i - 1] >= vec[i]) {
       return false;
     }
   }
   return true;
 }
 bool Requal(const vector<int64_t>& av, const vector<int64_t>& bv) {
   for (int i = 0; i < av.size(); ++i) {
     if (av[i] != bv[bv.size() - i - 1]) {
       return false;
     }
   }
   return true;
 }
 bool Equal(const vector<int64_t>& av, const vector<int64_t>& bv) {
   for (int i = 0; i < av.size(); ++i) {
     if (av[i] != bv[i]) {
       return false;
     }
   }
   return true;
 }
 int main() {
   std::ios_base::sync_with_stdio(false);
   std::cin.tie(nullptr);
   int len;
   cin >> len;
   vector<int64_t> av(len), bv(len);
   for (auto&& e : av) {
     cin >> e;
   }
   for (auto&& e : bv) {
     cin >> e;
   }
   if (len == 1) {
     if (av[0] == bv[0]) {
       cout <<  SMALL  << endl;
       cout << 0 << endl;
       cout << endl;
     } else {
       cout <<  IMPOSSIBLE  << endl;
     }
     return 0;
   }
   if (len == 2) {
     int64_t total = 0;
     vector<pair<char, int64_t>> buf;
     string res;
     if (av[0] > av[1]) {
       swap(av[0], av[1]);
       res += 'R';
     }
     while (1) {
       if (bv[0] > bv[1]) {
         swap(bv[0], bv[1]);
         buf.push_back({'R', 1});
       }
       if (bv[0] == av[0]) {
         if (bv[1] >= av[1] && ((bv[1] - av[1])  bv[0]) == 0) {
           buf.push_back({'P', (bv[1] - av[1]) / bv[0]});
           total += (bv[1] - av[1]) / bv[0];
         } else {
           total = -1;
         }
         break;
       }
       if (bv[0] == bv[1]) {
         total = -1;
         break;
       }
       buf.push_back({'P', bv[1] / bv[0]});
       bv[1] = bv[1]  bv[0];
       total += buf.back().second;
       if (bv[1] == 0) {
         bv[1] = bv[0];
         total--;
         buf.back().second--;
       }
     }
     if (total < 0) {
       cout <<  IMPOSSIBLE  << endl;
       return 0;
     }
     if (total > 200000) {
       cout <<  BIG  << endl;
       cout << total << endl;
     } else {
       cout <<  SMALL  << endl;
       for (auto it = buf.rbegin(); it != buf.rend(); ++it) {
         for (int i = 0; i < it->second; ++i) {
           res += it->first;
         }
       }
       cout << res.size() << endl;
       cout << res << endl;
     }
     return 0;
   }
   int64_t total = 0;
   string res;
   while (1) {
     if (Equal(av, bv)) {
       break;
     }
     if (Requal(av, bv)) {
       res += 'R';
       break;
     }
     if (bv[0] > bv[1]) {
       reverse(begin(bv), end(bv));
       res += 'R';
     }
     if (isAscending(bv) and bv[0] > 0) {
       for (int i = len; i-- > 1;) {
         bv[i] -= bv[i - 1];
       }
       res += 'P';
       ++total;
     } else {
       res =   ;
       break;
     }
   }
   if (res ==   ) {
     cout <<  IMPOSSIBLE  << endl;
   } else if (total > 200000) {
     cout <<  BIG  << endl;
     cout << total << endl;
   } else {
     cout <<  SMALL  << endl;
     reverse(begin(res), end(res));
     cout << res.size() << endl;
     cout << res << endl;
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 queue<int> fila;
 struct G {
   double d;
   int m, p, r;
 } g[250002];
 bool mk[250002];
 int a2[9000000];
 bool cmp2(int a, int b) { return g[a].d < g[b].d; }
 int pos = 0;
 int ind = 0;
 struct T {
   int m;
   int* e;
   void pdt(int a, int* b) { m = a, e = b; }
 } mas[2 * 250002];
 bool cmp(T a, T b) { return a.m < b.m; }
 int ls[4 * 250002];
 int s[4 * 250002][2];
 int r[4 * 250002];
 int build(int a, int b, int f) {
   int p = ind++;
   ls[p] = pos;
   r[p] = b;
   int i = ls[f];
   for (int i = ls[f]; a2[i] >= 0; i++) {
     if (g[a2[i]].m >= a && g[a2[i]].m <= b) a2[pos] = a2[i], pos++;
   }
   a2[pos] = -1;
   pos++;
   if (a != b)
     s[p][0] = build(a, (a + b) / 2, p),
     s[p][1] = build(((a + b) / 2) + 1, b, p);
   else
     s[p][0] = s[p][1] = -1;
   return p;
 }
 void get(int p, int power, int ray) {
   if (r[p] <= power) {
     for (int i = ls[p]; a2[i] >= 0; i++) {
       if (g[a2[i]].d <= ray + 1e-2) {
         if (!mk[a2[i]]) fila.push(a2[i]), mk[a2[i]] = true;
         ls[p] = i + 1;
       } else
         break;
     }
   } else {
     get(s[p][0], power, ray);
     if (power > r[s[p][0]]) get(s[p][1], power, ray);
   }
 }
 int main() {
   double x0, y0;
   int pp, rr, n;
   scanf( lf lf d d d , &x0, &y0, &pp, &rr, &n);
   int tot = 0;
   mas[tot++].pdt(pp, &pp);
   double x, y;
   for (int i = 0; i < n; i++) {
     scanf( lf lf d d d , &x, &y, &g[i].m, &g[i].p, &g[i].r);
     x -= x0;
     y -= y0;
     g[i].d = sqrt(x * x + y * y);
     mk[i] = false;
     a2[i] = i;
     mas[tot++].pdt(g[i].m, &g[i].m), mas[tot++].pdt(g[i].p, &g[i].p);
   }
   a2[n] = -1;
   sort(mas, mas + tot, cmp);
   int v = 1;
   int tmp = mas[0].m;
   *mas[0].e = v;
   for (int i = 1; i < tot; i++) {
     if (mas[i].m != tmp) v++;
     tmp = mas[i].m;
     *mas[i].e = v;
   }
   sort(a2, a2 + n, cmp2);
   r[0] = v;
   ls[0] = 0;
   ind = 1;
   pos = n + 1;
   if (n >= 2) s[0][0] = build(1, v / 2, 0), s[0][1] = build((v / 2) + 1, v, 0);
   get(0, pp, rr);
   int resp = 0;
   while (fila.size()) {
     resp++;
     int u = fila.front();
     fila.pop();
     get(0, g[u].p, g[u].r);
   }
   printf( d
 , resp);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int run(int n) {
   int i, a[n];
   for (i = 0; i < n; i++) cin >> a[i];
   sort(a, a + i);
   int ans = 0;
   int tempCount = 0;
   for (i = 0; i < n; i++) {
     tempCount++;
     if (a[i] == tempCount) {
       ans++;
       tempCount = 0;
     }
   }
   return ans;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int t;
   cin >> t;
   int n;
   while (t--) {
     cin >> n;
     cout << run(n) <<
 ;
   }
   return 0;
 }


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


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


#include <bits/stdc++.h>
 using namespace std;
 namespace io {
 template <typename T>
 inline void read(T &x) {
   bool flag = false;
   char c = getchar();
   while ((c < '0' || c > '9') && c != '-') c = getchar();
   c == '-' ? flag = true, x = 0 : x = c - '0';
   c = getchar();
   while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
   if (flag) x = -x;
 }
 template <typename T>
 inline void write(T x) {
   char st[10010];
   int cnt = 0;
   if (x < 0) x = -x, putchar('-');
   if (x == 0) putchar('0');
   while (x) {
     st[++cnt] = x  10 + 48;
     x /= 10;
   }
   while (cnt) {
     putchar(st[cnt--]);
   }
 }
 }  // namespace io
 using namespace io;
 int main() {
   int a, ans = 0;
   read(a);
   while (a) {
     ans += (a  8 == 1);
     a /= 8;
   }
   write(ans);
   puts(  );
   return 0;
 }


#include <bits/stdc++.h>
 const int N = 300010;
 const int MOD = 1e9 + 7;
 struct xxx {
   int id;
   char c;
 } s[N];
 std::string a, b, c;
 int gap, n;
 int sa[N], lcp[N], rank[N], tmp[N], bucket[N], cnt[N][3], ans[N], dp[19][N],
     fw[N];
 void update(int i, int v) {
   while (i < N) {
     fw[i] = (fw[i] + v)  MOD;
     i += i & -i;
   }
 }
 int query(int i) {
   int res = 0;
   while (i) {
     res = (res + fw[i])  MOD;
     i -= i & -i;
   }
   if (res < 0) res += MOD;
   return res;
 }
 int rmq(int f, int t) {
   int k = 31 - __builtin_clz(t - f + 1);
   int x = dp[k][f];
   int y = dp[k][t - (1 << k) + 1];
   if (lcp[x] < lcp[y]) return x;
   return y;
 }
 void solve(int f, int t, int h) {
   if (t - f + 1 < 3) return;
   int m = rmq(f, t - 1);
   int c0 = cnt[t][0] - cnt[f - 1][0];
   int c1 = cnt[t][1] - cnt[f - 1][1];
   int c2 = cnt[t][2] - cnt[f - 1][2];
   int v = lcp[m];
   int num = 1ll * c0 * c1  MOD * c2  MOD;
   update(v + 1, -num);
   update(h + 1, num);
   solve(f, m, v);
   solve(m + 1, t, v);
 }
 bool cmp2(int i, int j) {
   i += gap;
   j += gap;
   if (i < n && j < n) return rank[i] < rank[j];
   return i > j;
 }
 bool cmp(int i, int j) {
   if (rank[i] != rank[j]) return rank[i] < rank[j];
   i += gap;
   j += gap;
   if (i < n && j < n) return rank[i] < rank[j];
   return i > j;
 }
 int main() {
   std::cin >> a >> b >> c;
   int an = int(a.size()), bn = int(b.size()), cn = int(c.size());
   for (int i = 0; i < an; ++i) s[i].id = 0, s[i].c = a[i];
   for (int i = 0; i < bn; ++i) s[i + an + 1].id = 1, s[i + an + 1].c = b[i];
   for (int i = 0; i < cn; ++i)
     s[i + an + bn + 2].id = 2, s[i + an + bn + 2].c = c[i];
   s[an].c = 1;
   s[an + bn + 1].c = 2;
   n = an + bn + cn + 2;
   int rn = 255;
   for (int i = 0; i < n; ++i) {
     sa[i] = i;
     rank[i] = s[i].c;
   }
   for (gap = 1;; gap <<= 1) {
     int p = 0;
     for (int i = n - 1; i + gap >= n; --i) tmp[p++] = i;
     std::fill(bucket, bucket + rn, 0);
     for (int i = 0; i + gap < n; ++i) ++bucket[rank[i + gap]];
     for (int i = 1; i < rn; ++i) bucket[i] += bucket[i - 1];
     for (int i = 0; i + gap < n; ++i) tmp[--bucket[rank[i + gap]] + p] = i;
     std::fill(bucket, bucket + rn, 0);
     for (int i = 0; i < n; ++i) ++bucket[rank[i]];
     for (int i = 1; i < rn; ++i) bucket[i] += bucket[i - 1];
     for (int i = n - 1; i >= 0; --i) sa[--bucket[rank[tmp[i]]]] = tmp[i];
     tmp[0] = 0;
     for (int i = 1; i < n; ++i) tmp[i] = tmp[i - 1] + cmp(sa[i - 1], sa[i]);
     for (int i = 0; i < n; ++i) rank[sa[i]] = tmp[i];
     if (tmp[n - 1] == n - 1) break;
     rn = tmp[n - 1] + 1;
   }
   for (int i = 0, k = 0; i < n; ++i) {
     if (rank[i] == n - 1) continue;
     for (int j = sa[rank[i] + 1]; s[i + k].c == s[j + k].c;) ++k;
     lcp[rank[i]] = k;
     if (k) --k;
   }
   for (int i = 0; i < n - 1; ++i) dp[0][i] = i;
   for (int j = 1; 1 << j < n; ++j)
     for (int i = 0; i + (1 << j) - 1 < n - 1; ++i) {
       int x = dp[j - 1][i];
       int y = dp[j - 1][i + (1 << (j - 1))];
       dp[j][i] = lcp[x] < lcp[y] ? x : y;
     }
   assert(s[sa[0]].c == 1);
   assert(s[sa[1]].c == 2);
   for (int i = 2; i < n; ++i) {
     cnt[i][0] = cnt[i - 1][0];
     cnt[i][1] = cnt[i - 1][1];
     cnt[i][2] = cnt[i - 1][2];
     ++cnt[i][s[sa[i]].id];
   }
   int sz = std::min(an, std::min(bn, cn));
   solve(2, n - 1, 0);
   for (int i = 1; i <= sz; ++i) std::cout << query(i) << ' ';
 }


#include <bits/stdc++.h>
 #pragma comment(linker,  /STACK:1073741824 )
 using namespace std;
 const int N = 3e5 + 100;
 int col[N], d[N][2];
 vector<int> v[N];
 int main() {
 #pragma warning(disable : 4996)
   int n, m;
   scanf( dd , &n, &m);
   for (int i = 0; i < m; i++) {
     int a, b;
     scanf( dd , &a, &b);
     a--, b--;
     v[a].push_back(b);
     v[b].push_back(a);
   }
   queue<int> q;
   for (int i = 0; i < n; i++) {
     d[i][0] = v[i].size();
     if (d[i][0] > 1) q.push(i);
   }
   while (!q.empty()) {
     int node = q.front();
     q.pop();
     if (d[node][col[node]] > 1) {
       col[node] ^= 1;
       for (int to : v[node]) {
         d[to][col[node]]++;
         d[to][col[node] ^ 1]--;
         if (d[to][col[to]] > 1) q.push(to);
       }
     }
   }
   for (int i = 0; i < n; i++) printf( d , col[i]);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int maxn = 1000005;
 const long long mod = 1e9 + 7;
 const int N = 1e6;
 vector<int> rec[maxn];
 long long fac[maxn], ans;
 int n, m;
 int ord[maxn], bit;
 bool comp(int a, int b) { return rec[a][bit] < rec[b][bit]; }
 void mysort(int l, int r, int j) {
   if (l == r) return;
   bit = j;
   sort(ord + l, ord + r + 1, comp);
   int p = l;
   while (p <= r && rec[ord[p]][j] == -1) ++p;
   int cnt = 1;
   for (int i = l + 1; i < p; i++)
     if (rec[ord[i]][j - 1] == rec[ord[i - 1]][j - 1])
       ++cnt;
     else {
       (ans *= fac[cnt]) = mod;
       cnt = 1;
     }
   (ans *= fac[cnt]) = mod;
   int t = p;
   while (t <= r) {
     p = t;
     while (p <= r && rec[ord[p]][j] == rec[ord[t]][j]) ++p;
     mysort(t, p - 1, j + 1);
     t = p;
   }
 }
 int main() {
   fac[0] = 1ll;
   for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i  mod;
   scanf( d d , &n, &m);
   for (int i = 1; i <= m; i++) rec[i].push_back(0);
   for (int g, i = 1; i <= n; i++) {
     scanf( d , &g);
     for (int v, j = 1; j <= g; j++) scanf( d , &v), rec[v].push_back(i);
   }
   for (int i = 1; i <= m; i++) {
     sort(rec[i].begin(), rec[i].end());
     rec[i].push_back(-1);
     ord[i] = i;
   }
   ans = 1ll;
   mysort(1, m, 1);
   printf( lld
 , ans);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int Power(int base, int exp) {
   int ans = 1;
   while (exp > 0) {
     if (exp & 1) ans = (1LL * ans * base)  1000000007;
     exp = exp >> 1;
     base = (1LL * base * base)  1000000007;
   }
   return ans;
 }
 vector<map<long double, int> > p_CntS(2005);
 int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(NULL);
   cout.tie(NULL);
   long long int n;
   cin >> n;
   long double x[n], y[n];
   for (int i = 0; i < n; i += 1) cin >> x[i] >> y[i];
   long double slope;
   for (int p1 = 0; p1 < n; p1 += 1)
     for (int p2 = 0; p2 < n; p2 += 1) {
       if (p1 == p2) continue;
       slope = y[p2] - y[p1];
       if (x[p2] - x[p1] == 0)
         p_CntS[p1][600.0]++;
       else
         p_CntS[p1][300.0 + slope / (x[p2] - x[p1])]++;
     }
   long long int ans = (1LL * n * (n - 1) * (n - 2)) / 6, ans_ = 0;
   int cnt;
   for (int i = 0; i < n; i += 1) {
     map<long double, int>::iterator it = p_CntS[i].begin();
     while (it != p_CntS[i].end()) {
       cnt = (*it).second;
       ans_ += 1LL * cnt * (cnt - 1) / 2;
       it++;
     }
   }
   cout << ans - ans_ / 3 << '
';
 }


#include <bits/stdc++.h>
 int ans = 0;
 double H = 100, len = 100000;
 int F[110000], T[110000], FF[110000], TT[110000];
 bool vis[110000];
 int judge(bool fuck, double st, double t) {
   int ret = 0;
   int top, flo;
   double point = st;
   memset(vis, 0, sizeof(vis));
   while (point < len) {
     top = (int)ceil(point);
     flo = (int)floor(point);
     if (fuck) {
       if (T[top] < 0 || T[flo] < 0 || T[top] != T[flo]) {
         return -1;
       }
       if (vis[TT[top]] == 1) return -1;
       ret += T[top];
       vis[TT[top]] = 1;
       fuck = !fuck;
     } else {
       if (F[top] < 0 || F[flo] < 0 || F[top] != F[flo]) {
         return -1;
       }
       if (vis[FF[top]] == 1) return -1;
       ret += F[top];
       vis[FF[top]] = 1;
       fuck = !fuck;
     }
     point += t;
   }
   if (ans < ret) ans = ret;
   return ret;
 }
 int work() {
   int n, i, j, val, x, y;
   char c;
   double A, B, t;
   double hl, hr;
   scanf( lflfd , &hl, &hr, &n);
   memset(T, -1, sizeof(T));
   memset(F, -1, sizeof(F));
   for (i = 1; i <= n; i++) {
     scanf( d cdd , &val, &c, &x, &y);
     if (c == 'T') {
       for (j = x; j <= y; j++) T[j] = val, TT[j] = i;
     } else {
       for (j = x; j <= y; j++) F[j] = val, FF[j] = i;
     }
   }
   A = hl / H;
   B = hr / H;
   for (i = 0; i <= 100; i++) {
     if ((i & 1) == 0) {
       t = len / (A + B + i);
       judge(0, A * t, t);
     }
     if ((i & 1) == 1) {
       t = len / ((1 - A) + B + i);
       judge(1, (1 - A) * t, t);
     }
     if ((i & 1) == 1) {
       t = len / (A + (1 - B) + i);
       judge(0, A * t, t);
     }
     if ((i & 1) == 0) {
       t = len / ((1 - A) + (1 - B) + i);
       judge(1, (1 - A) * t, t);
     }
   }
   printf( d
 , ans);
   return 1;
 }
 int main() {
   work();
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct point {
   int x, y;
   point() {}
   point(int x, int y) : x(x), y(y) {}
 } p[1010];
 point operator-(const point &a, const point &b) {
   return point(a.x - b.x, a.y - b.y);
 }
 long long operator*(const point &a, const point &b) {
   return (long long)a.x * b.y - (long long)a.y * b.x;
 }
 int main() {
   int n, i, x, y, low, high;
   cin >> n;
   for (i = 0; i < n; i++) {
     cin >> x >> y;
     p[i] = point(x, y);
   }
   low = p[0].x;
   high = p[1].x;
   if (low > high) swap(low, high);
   p[n] = p[0];
   for (i = 0; i < n; i++) {
     while (low <= high && (p[i + 1] - p[i]) * (point(low, p[0].y) - p[i]) > 0)
       low++;
     while (low <= high && (p[i + 1] - p[i]) * (point(high, p[0].y) - p[i]) > 0)
       high--;
   }
   cout << high - low + 1 << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 500000;
 const long long minx = -0x5fffffffffffffff;
 struct nn {
   long long x, y;
   nn() { y = minx; }
 };
 int n, u, v;
 nn num[N];
 vector<int> node[N];
 long long dfs(int f, int x) {
   for (int i = 0; i < node[x].size(); i++) {
     if (node[x][i] == f) continue;
     long long r = dfs(x, node[x][i]);
     num[x].y += r;
   }
   return num[x].y;
 }
 long long dfs1(int f, int x, long long &ans) {
   long long m1 = minx;
   long long m2 = minx;
   for (int i = 0; i < node[x].size(); i++) {
     if (node[x][i] == f) continue;
     long long r = dfs1(x, node[x][i], ans);
     if (m1 < r) {
       m2 = m1;
       m1 = r;
     } else if (m2 < r) {
       m2 = r;
     }
   }
   if (m2 != minx) {
     if (ans < m1 + m2) ans = m1 + m2;
   }
   return m1 > num[x].y ? m1 : num[x].y;
 }
 int main() {
   long long ans;
   while (scanf( d , &n) != EOF) {
     ans = minx;
     for (int i = 0; i < N; i++) node[i].clear();
     for (int i = 1; i <= n; i++) {
       scanf( lld , &num[i].x);
       num[i].y = num[i].x;
     }
     for (int i = 0; i < n - 1; i++) {
       scanf( dd , &u, &v);
       node[u].push_back(v);
       node[v].push_back(u);
     }
     dfs(0, 1);
     dfs1(0, 1, ans);
     if (ans != minx)
       printf( lld
 , ans);
     else
       printf( Impossible
 );
   }
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios::sync_with_stdio(false);
   int n, k;
   cin >> n >> k;
   if (k > (n * n + 1) / 2) {
     cout <<  NO ;
     return 0;
   }
   cout <<  YES
 ;
   int tmp = 0;
   for (int i = 0; i < n; i++) {
     for (int j = 0; j < n; j++) {
       if (j  2 == i  2 && tmp != k) {
         cout << 'L';
         tmp++;
       } else
         cout << 'S';
     }
     cout << '
';
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 using namespace chrono;
 const int infinity = (int)1e9 + 42;
 const int64_t llInfinity = (int64_t)1e18 + 256;
 const int module = (int)1e9 + 7;
 const long double eps = 1e-8;
 mt19937_64 randGen(system_clock().now().time_since_epoch().count());
 inline void raiseError(string errorCode) {
   cerr <<  Error :   << errorCode << endl;
   exit(42);
 }
 inline int readAns(int req) {
   cout << req << endl;
   int q;
   cin >> q;
   if (q == 0) {
     exit(0);
   }
   return q;
 }
 signed main() {
   ios_base::sync_with_stdio(false);
   int m, n;
   cin >> m >> n;
   vector<int> v(n);
   for (int i = 0; i < n; i++) {
     v[i] = readAns(m) * -1;
   }
   int l = 1, r = m - 1;
   int p = 0;
   while (l != r) {
     int m = (l + r) / 2;
     int ans = readAns(m) * v[p];
     p++;
     p = n;
     if (ans < 0) {
       r = m - 1;
     } else {
       l = m + 1;
     }
   }
   readAns(l);
   assert(false);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   int n, m;
   string s, t;
   cin >> n >> m >> s >> t;
   bool can = false;
   if (s == t)
     can = true;
   else {
     if (n <= m + 1) {
       for (int i = 0; i < int(n); i++) {
         if (s[i] == '*') {
           if (s.substr(0, i) == t.substr(0, i) &&
               s.substr(i + 1, string::npos) ==
                   t.substr(m - (n - (i + 1)), string::npos))
             can = true;
         }
       }
     }
   }
   cout << (can ?  YES  :  NO ) << '
';
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 long long a[200001], b[200001], c[200001];
 int main() {
   long long n, ans = 0;
   cin >> n;
   for (int i = 0; i < n; i++) cin >> a[i];
   for (int i = 0; i < n; i++) cin >> b[i];
   for (int i = 0; i < n; i++) c[i] = a[i] - b[i];
   sort(c, c + n);
   for (int i = n - 1;; i--) {
     if (c[i] <= 0) break;
     int ans1 = &c[i] - upper_bound(c, c + n, 0 - c[i]);
     ans += ans1;
   }
   cout << ans << endl;
   return 0;
 }


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


#include <bits/stdc++.h>
 using namespace std;
 const int N = 2e5 + 10;
 unsigned long long preLef[N], preRig[N], sum[N], a[N];
 map<unsigned long long, unsigned long long> f, g;
 int n, m;
 unsigned long long Rand() {
   return (unsigned long long)rand() * rand() * rand() +
          (unsigned long long)rand() * rand() * rand();
 }
 int main() {
   srand(time(0));
   scanf( dd , &n, &m);
   for (int i = 0, l, r; i < n; ++i) {
     scanf( dd , &l, &r);
     unsigned long long t = Rand();
     a[l] ^= t;
     a[r + 1] ^= t;
     preLef[l] ^= t;
     preRig[r] ^= t;
   }
   for (int i = 1; i <= m + 1; ++i) {
     a[i] ^= a[i - 1];
     sum[i] = sum[i - 1] ^ a[i];
     preLef[i] ^= preLef[i - 1];
     preRig[i] ^= preRig[i - 1];
   }
   g[0] = 0;
   f[0] = 1;
   unsigned long long ans = 0;
   for (int i = 1; i <= m; ++i) {
     unsigned long long t = sum[i] ^ preLef[i];
     ans += f[t] * i - g[t];
     t = sum[i] ^ preRig[i];
     g[t] += i;
     ++f[t];
   }
   for (int i = 1, lf = 0; i <= m; ++i)
     if (!a[i])
       ans -= (unsigned long long)(i - lf + 1) * (i - lf) / 2;
     else
       lf = i;
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int N = 1e4 + 5;
 int n, a[N];
 int main() {
   ios ::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   if (fopen( main.in ,  r )) freopen( main.in ,  r , stdin);
   cin >> n;
   for (int i = 1; i <= n; i++) cin >> a[i];
   int cnt = 0;
   for (int i = 2; i < n; i++)
     if (a[i - 1] == 1 && a[i + 1] == 1 && a[i] == 0) a[i + 1] = 0, cnt++;
   cout << cnt;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 char s[10];
 int main() {
   int n, i, len;
   long long wi = 1, he = 1;
   scanf( d , &n);
   for (i = 1; i <= n; i++) {
     scanf( s , s);
     len = strlen(s);
     if (len == 4) {
       wi++;
       he++;
     } else if (!strcmp(s,  UL ) || !strcmp(s,  DR ))
       wi++;
     else if (!strcmp(s,  UR ) || !strcmp(s,  DL ))
       he++;
   }
   printf( extra
 , wi * he);
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 string rotate(string s, int off, int* a) {
   string new_s(s);
   for (int i = 0; i < 4; i++) new_s[a[(i + off)  4] - 1] = s[a[i] - 1];
   return new_s;
 }
 string rotate1(string s, int off) {
   int a[] = {1, 3, 5, 6};
   return rotate(s, off, a);
 }
 string rotate2(string s, int off) {
   int a[] = {2, 6, 4, 3};
   return rotate(s, off, a);
 }
 int main() {
   string s;
   cin >> s;
   sort(s.begin(), s.end());
   map<string, int> m;
   int ans = 0;
   do {
     bool flg = true;
     map<string, int> mm;
     for (int i = 0; i < 4; i++) {
       string b = rotate1(s, i);
       for (int j = 0; j < 4; j++) {
         string bb = rotate2(b, j);
         if (mm.find(bb) == mm.end())
           if (m.find(bb) != m.end()) flg = false;
         mm[bb] = m[bb] = 1;
       }
     }
     if (flg) ans++;
   } while (next_permutation(s.begin(), s.end()));
   cout << ans;
   return 0;
 }


 // Problem: A. Searching Local Minimum
 // Contest: Codeforces - Codeforces Round #700 (Div. 1)
 // URL: https://codeforces.com/contest/1479/problem/A
 // Memory Limit: 512 MB
 // Time Limit: 2000 ms
 // Powered by CP Editor (https://github.com/cpeditor/cpeditor)

 #include <iostream>
 #include <iosfwd>
 #include <iomanip>
 #include <cstdio>
 #include <cstring>
 #include <cstdlib>
 #include <ctime>
 #include <cmath>
 #include <cassert>
 #include <cctype>
 #include <climits>
 #include <vector>
 #include <bitset>
 #include <set>
 #include <queue>
 #include <math.h>
 #include <stack>
 #include <map>
 #include <deque>
 #include <string>
 #include <list>
 #include <iterator>
 #include <sstream>
 #include <complex>
 #include <fstream>
 #include <functional>
 #include <numeric>
 #include <utility>
 #include <algorithm>
 #include <assert.h>
 #include <unordered_map>
 #pragma GCC optimize ( -O3 )

 using namespace std;

 #define watch(x) cout << (#x) <<   =   << (x) << endl
 #define PI double(2 * acos(0.0))
 #define LL long long
 #define MOD 1000000007
 #define all(x) (x).begin(), (x).end()
 #define INF 1e15
 int query(int a, int n){
       if(a == 0 || a == n + 1){
             return 1e7;
       }
       cout <<  ?   << a << endl;
       int p;
       cin >> p;
       return p;
 }
 int helper(int a, int n){
       int left = a - 1;
       int right = a + 1;
       int mid = a;
       int p = query(left, n);
       int q = query(mid, n);
       int r = query(right, n);
       if(p > q && q < r){
             return 0;
       }
       if(p < q){
             return 2;
       }
       else{
             return 1;
       }
 }
 int main() {
       int n;
       cin >> n;
       int start = 1;
       int end = n;
       int ans = -1;
       while(start <= end){
             int mid = (start + end) / 2;
             int p = helper(mid, n);
             if(p == 0){
                   ans = mid;
                   break;
             }
             if(p == 1){
                   start = mid + 1;
             }else{
                   end = mid - 1;
             }
       }
       cout <<  !   << ans << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 const int INF = INT_MAX;
 const long long INFL = LLONG_MAX;
 const long double pi = acos(-1);
 class SumSegTree {
  private:
   vector<long long> sum, lazy;
   int N;
   void check_index(int i) {
     if (i < 0 || N <= i) {
       throw  index out of bound ;
     }
   }

  public:
   SumSegTree(int N) {
     this->N = 1;
     while (this->N < N) this->N <<= 1;
     this->sum.resize(this->N << 1);
     this->lazy.resize(this->N << 1);
   }
   long long get_sum(int l, int r) {
     check_index(l);
     check_index(r);
     return get_sum(l, r, 0, N - 1, 1);
   }
   void add(int l, int r, int val) {
     check_index(l);
     check_index(r);
     add(l, r, val, 0, N - 1, 1);
   }
   void delegate(int a, int b, int n) {
     sum[n] += (b - a + 1) * lazy[n];
     if (a < b) {
       lazy[n * 2] += lazy[n];
       lazy[n * 2 + 1] += lazy[n];
     }
     lazy[n] = 0;
   }
   long long get_sum(int l, int r, int a, int b, int n) {
     if (b < l || r < a) return 0;
     if (lazy[n] != 0) delegate(a, b, n);
     if (l <= a && b <= r) return sum[n];
     int m = (a + b) / 2;
     return get_sum(l, r, a, m, n * 2) + get_sum(l, r, m + 1, b, n * 2 + 1);
   }
   void add(int l, int r, long long val, int a, int b, int n) {
     if (b < l || r < a) return;
     if (l <= a && b <= r) {
       if (a == b)
         sum[n] += val;
       else
         lazy[n] += val;
     } else {
       int m = (a + b) / 2;
       if (lazy[n] != 0) delegate(a, b, n);
       sum[n] += (min(b, r) - max(a, l) + 1) * val;
       add(l, r, val, a, m, n * 2);
       add(l, r, val, m + 1, b, n * 2 + 1);
     }
   }
 };
 int N, M;
 vector<int> adj[300100];
 vector<pair<int, long long> > query[300100];
 SumSegTree segt(300005);
 long long ans[300100];
 void dfs(int u, int prev, int h) {
   for (int(i) = 0; (i) < (int((query[u]).size())); (i)++) {
     int dist = query[u][i].first;
     long long value = query[u][i].second;
     segt.add(h, min(N, h + dist), value);
   }
   ans[u] = segt.get_sum(h, h);
   for (int(i) = 0; (i) < (int((adj[u]).size())); (i)++) {
     int v = adj[u][i];
     if (v == prev) continue;
     dfs(v, u, h + 1);
   }
   for (int(i) = 0; (i) < (int((query[u]).size())); (i)++) {
     int dist = query[u][i].first;
     long long value = query[u][i].second;
     segt.add(h, min(N, h + dist), -value);
   }
 }
 int main() {
   ios_base::sync_with_stdio(0);
   cout.precision(15);
   cout << fixed;
   cout.tie(0);
   cin.tie(0);
   cin >> N;
   for (int(i) = 1; (i) <= (N - 1); (i)++) {
     int a, b;
     cin >> a >> b;
     adj[a].push_back(b);
     adj[b].push_back(a);
   }
   cin >> M;
   for (int(i) = 1; (i) <= (M); (i)++) {
     int v, d;
     long long x;
     cin >> v >> d >> x;
     query[v].push_back(make_pair(d, x));
   }
   dfs(1, 0, 0);
   for (int(i) = 1; (i) <= (N); (i)++)
     cout << ans[i] << (i + 1 <= N ? ' ' : '
');
 }


#include <bits/stdc++.h>
 using namespace std;
 int main() {
   ios::sync_with_stdio(false);
   pair<int, int> home, uni;
   cin >> home.first >> home.second >> uni.first >> uni.second;
   int count;
   cin >> count;
   int solution = 0;
   int64_t a, b, c;
   for (int i = 0; i < count; i++) {
     cin >> a >> b >> c;
     bool h_p = a * home.first + b * home.second + c > 0;
     bool u_p = a * uni.first + b * uni.second + c > 0;
     if ((h_p && !u_p) || (!h_p && u_p)) {
       solution++;
     }
   }
   cout << solution << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int main(void) {
   int n;
   char str[102][102];
   scanf( d , &n);
   bool row, col;
   row = col = false;
   for (int i = 0; i < n; i++) {
     scanf( s , str[i]);
     bool bolong = false;
     for (int j = 0; j < n; j++) {
       if (str[i][j] == '.') {
         bolong = true;
       }
     }
     if (!bolong) {
       row = true;
     }
   }
   if (!row) {
     for (int i = 0; i < n; i++) {
       for (int j = 0; j < n; j++) {
         if (str[i][j] == '.') {
           printf( d d
 , i + 1, j + 1);
           break;
         }
       }
     }
     return 0;
   }
   for (int i = 0; i < n; i++) {
     bool bolong = false;
     for (int j = 0; j < n; j++) {
       if (str[j][i] == '.') bolong = true;
     }
     if (!bolong) col = true;
   }
   if (!col) {
     for (int i = 0; i < n; i++) {
       for (int j = 0; j < n; j++) {
         if (str[j][i] == '.') {
           printf( d d
 , j + 1, i + 1);
           break;
         }
       }
     }
   } else
     printf( -1 );
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 mt19937_64 rng(
     (unsigned)chrono::system_clock::now().time_since_epoch().count());
 const long double error = 1e-7;
 const long double PI = acosl(-1);
 const int nmax = 2e5 + 10;
 int master[nmax];
 int sz[nmax];
 void init(int u) {
   master[u] = u;
   sz[u] = 1;
   return;
 }
 int fnd(int u) {
   if (master[u] == u) return u;
   return master[u] = fnd(master[u]);
 }
 bool unite(int u, int v) {
   u = fnd(u);
   v = fnd(v);
   if (u == v) return false;
   if (sz[u] < sz[v]) swap(u, v);
   sz[u] += sz[v];
   master[v] = u;
   return true;
 }
 int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   ;
   int n, m;
   cin >> n >> m;
   vector<long long int> A(n + 1), B(m + 1);
   for (int i = 1; i <= n; i++) {
     cin >> A[i];
   }
   for (int i = 1; i <= m; i++) {
     cin >> B[i];
   }
   vector<pair<long long int, pair<int, int>>> edges;
   long long int totcost = 0;
   for (int i = 1; i <= n; i++) {
     int k;
     cin >> k;
     for (int j = 0; j < k; j++) {
       int x;
       cin >> x;
       edges.emplace_back(A[i] + B[x], make_pair(i, n + x));
       totcost += A[i] + B[x];
     }
   }
   for (int i = 1; i <= n + m; i++) init(i);
   sort(edges.begin(), edges.end());
   reverse(edges.begin(), edges.end());
   long long int ans = 0;
   for (auto e : edges) {
     if (unite(e.second.first, e.second.second)) ans += e.first;
   }
   ans = totcost - ans;
   cout << ans << endl;
   return 0;
 }


#include <bits/stdc++.h>
 using namespace std;
 int L[100010];
 int P[100010][20];
 vector<int> pp[100010][20];
 int T[100010];
 vector<int> tt[100010];
 int arr[100010];
 vector<int> graph[100010];
 vector<int> fnc(vector<int> &a, vector<int> &b) {
   vector<int> ans;
   int aa = a.size(), bb = b.size(), i, j, shajib = 0;
   for (i = 0, j = 0; i + j < aa + bb && shajib < 10;) {
     if (i == aa) {
       ans.push_back(b[j]);
       j++;
       shajib++;
     } else if (j == bb) {
       ans.push_back(a[i]);
       i++;
       shajib++;
     } else {
       if (a[i] == b[j]) {
         i++;
       } else if (a[i] > b[j]) {
         ans.push_back(b[j]);
         j++;
         shajib++;
       } else {
         ans.push_back(a[i]);
         i++;
         shajib++;
       }
     }
   }
   return ans;
 }
 void dfs(int src, int par) {
   if (src == -1)
     L[par] = 1;
   else
     L[par] = L[src] + 1;
   T[par] = src;
   int len = graph[par].size();
   for (int i = 0; i < (int)graph[par].size(); i++) {
     int v = graph[par][i];
     if (v != src) {
       dfs(par, v);
     }
   }
 }
 vector<int> query(int n, int p, int q) {
   int log = 1, i, j, temp;
   if (L[p] < L[q]) {
     temp = q;
     q = p;
     p = temp;
   }
   log = log2(n);
   vector<int> os;
   os = fnc(os, tt[p]);
   for (j = log; j >= 0; j--) {
     if (L[p] - (1 << j) >= L[q]) {
       os = fnc(os, pp[p][j]);
       p = P[p][j];
     }
   }
   if (p == q) return os;
   os = fnc(os, tt[q]);
   for (j = log; j >= 0; j--) {
     if (P[p][j] != -1 && P[p][j] != P[q][j]) {
       os = fnc(os, pp[p][j]);
       os = fnc(os, pp[q][j]);
       p = P[p][j], q = P[q][j];
     }
   }
   os = fnc(os, pp[p][0]);
   return os;
 }
 void lca(int n) {
   memset(P, -1, sizeof(P));
   int i, j;
   for (i = 1; i <= n; i++) {
     P[i][0] = T[i];
     if (T[i] != -1) pp[i][0] = fnc(pp[i][0], tt[T[i]]);
   }
   for (j = 1; (1 << j) < n; j++) {
     for (i = 1; i <= n; i++) {
       if (P[i][j - 1] != -1) {
         P[i][j] = P[P[i][j - 1]][j - 1];
         pp[i][j] = fnc(pp[i][j], pp[P[i][j - 1]][j - 1]);
         pp[i][j] = fnc(pp[i][j], pp[i][j - 1]);
       }
     }
   }
 }
 int main() {
   int i, j, n, m, t, a, b, k, c;
   scanf( ddd , &n, &m, &k);
   for (i = 0; i < n - 1; i++) {
     scanf( dd , &a, &b);
     graph[a].push_back(b);
     graph[b].push_back(a);
   }
   for (i = 1; i <= m; i++) {
     scanf( d , &a);
     tt[a].push_back(i);
   }
   for (i = 1; i <= n; i++) {
     sort(tt[i].begin(), tt[i].end());
     a = tt[i].size();
     while (a > 10) {
       tt[i].pop_back();
       a--;
     }
   }
   dfs(-1, 1);
   lca(n);
   vector<int> os;
   for (i = 1; i <= k; i++) {
     scanf( ddd , &a, &b, &c);
     os = query(n, a, b);
     c = min(c, (int)os.size());
     a = 0;
     printf( d  , c);
     for (auto it = os.begin(); a < c && it != os.end(); a++, it++) {
       printf( d  , (*it));
     }
     printf(
 );
   }
 }


#include <bits/stdc++.h>
 using namespace std;
 int n, m;
 int a[107];
 map<string, int> f;
 vector<pair<int, string>> b;
 bool cmp(pair<int, string> u, pair<int, string> v) { return u.first > v.first; }
 int main() {
   cin >> n >> m;
   for (int i = 1; i <= n; i++) cin >> a[i];
   for (int i = 1; i <= m; i++) {
     string s;
     cin >> s;
     if (f[s] == 0)
       f[s] = 1;
     else
       f[s]++;
   }
   sort(a + 1, a + n + 1);
   for (map<string, int>::iterator it = f.begin(); it != f.end(); ++it) {
     b.push_back(make_pair(it->second, it->first));
   }
   sort(b.begin(), b.end(), cmp);
   long long minP = 0, maxP = 0;
   for (int i = 0; i < b.size(); i++) {
     minP += b[i].first * a[i + 1];
     maxP += b[i].first * a[n - i];
   }
   cout << minP <<     << maxP << endl;
 }


#include <bits/stdc++.h>
 using namespace std;
 struct node {
   long long cos, rlev;
   bool operator<(const node &a) const { return cos < a.cos; }
 } f[300005];
 int main() {
   int n, k;
   while (scanf( dd , &n, &k) != EOF) {
     for (int i = 1; i <= n; i++) {
       scanf( extra , &f[i].cos);
       f[i].rlev = i;
     }
     priority_queue<node> p;
     long long ans = 0;
     for (int i = 1; i <= k; i++) p.push(f[i]);
     for (int i = k + 1; i <= k + n; i++) {
       if (i <= n) p.push(f[i]);
       node now = p.top();
       p.pop();
       if (i >= now.rlev) {
         ans += (i - now.rlev) * now.cos;
         f[now.rlev].rlev = i;
       }
     }
     printf( extra
 , ans);
     for (int i = 1; i < n; i++) {
       printf( extra  , f[i].rlev);
     }
     printf( extra
 , f[n].rlev);
   }
   return 0;
 }