#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 600000+10;
const double PI = acos(-1);
struct Complex {
    double x, y;
    Complex(double x=0.0, double y=0.0) : x(x), y(y) {}
    Complex operator + (const Complex &b) const {
        return Complex(x+b.x, y+b.y);
    }
    Complex operator - (const Complex &b) const {
        return Complex(x-b.x, y-b.y);
    }
    Complex operator * (const Complex &b) const{
        return Complex(x * b.x - y * b.y, x * b.y + y * b.x);
    }
} x1[N<<2], x2[N<<2];
void change(Complex y[], int len) {
    for(int i=1,j=len/2;i<len-1;i++){
        if(i<j) swap(y[i], y[j]);
        int k=len/2;
        while (j>=k) {
            j-=k; k/=2;
        }
        if(j<k) j+=k;
    }
}
void fft(Complex y[], int len, int on){
    change(y, len);
    for(int h=2;h<=len;h<<=1) {
        Complex wn(cos(-on*2*PI/h), sin(-on*2*PI/h));
        for(int j=0;j<len;j+=h){
            Complex w(1,0);
            for(int k=j;k<j+h/2;k++) {
                Complex u=y[k];
                Complex t=w*y[k+h/2];
                y[k]=u+t;
                y[k+h/2]=u-t;
                w=w*wn;
            }
        }
    }
    if (on==-1) for(int i=0;i<len;i++) y[i].x /= len;
}
void mul(LL *p, int& dp, LL* q, int& dq) {
    int len=1;
    while(len<=dp+dq) len<<=1;
    for(int i=0;i<dp;i++) x1[i]=Complex(p[i],0);
    for(int i=dp;i<len;i++) x1[i]=Complex(0,0);
    for(int i=0;i<dq;i++) x2[i]=Complex(q[i],0);
    for(int i=dq;i<len;i++) x2[i]=Complex(0,0);
    fft(x1,len,1);
    fft(x2,len,1);
    for(int i=0;i<len;i++) {
        x1[i]=x1[i]*x2[i];
    }
    fft(x1,len,-1);
    for(int i=0;i<=200002;i++){
        //printf("%.4f\n", x1[i].x);
        p[i]=round(x1[i]);
    }
    dp+=dq;
}

LL n,m;int q;

int a[N],b[N];
namespace Min{
    LL f[N<<1],g[N<<1];
    LL s1[N], s2[N], s3[N];
    void gen1() {
        memset(f,0,sizeof(f)); memset(g,0,sizeof(g));
        for(int i=1;i<=n;i++) f[a[i]] ++;
        for(int i=1;i<m;i++) g[min(b[i],b[i+1])] ++;
        int dp=100000,dq=100000;
        mul(f,dp,g,dq); s1[0]=0;
        for(int i=1;i<=200000;i++) s1[i]=s1[i-1]+f[i];
    }
    void gen2() {
        memset(f,0,sizeof(f)); memset(g,0,sizeof(g));
        for(int i=1;i<n;i++) f[min(a[i],a[i+1])] ++;
        for(int i=1;i<=m;i++) g[b[i]] ++;
        int dp=100000,dq=100000;
        mul(f,dp,g,dq); s2[0]=0;
        for(int i=1;i<=200000;i++) s2[i]=s2[i-1]+f[i];
    }
    void gen3() {
        memset(f,0,sizeof(f)); memset(g,0,sizeof(g));
        for(int i=1;i<n;i++) f[min(a[i],a[i+1])] ++;
        for(int i=1;i<m;i++) g[min(b[i],b[i+1])] ++;
        int dp=100000,dq=100000;
        mul(f,dp,g,dq); s3[0]=0;
        for(int i=1;i<=200000;i++) s3[i]=s3[i-1]+f[i];
    }
}
namespace Max{
    LL f[N<<1],g[N<<1];
    LL s1[N], s2[N], s3[N], s4[N];
    void gen1() {
        memset(f,0,sizeof(f)); memset(g,0,sizeof(g));
        for(int i=1;i<=n;i++) f[a[i]] ++;
        for(int i=1;i<m;i++) g[max(b[i],b[i+1])] ++;
        int dp=100000,dq=100000;
        mul(f,dp,g,dq);
        s1[0]=0;
        for(int i=1;i<=200000;i++) s1[i]=s1[i-1]+f[i];
    }
    void gen2() {
        memset(f,0,sizeof(f)); memset(g,0,sizeof(g));
        for(int i=1;i<n;i++) f[max(a[i],a[i+1])] ++;
        for(int i=1;i<=m;i++) g[b[i]] ++;
        int dp=100000,dq=100000;
        mul(f,dp,g,dq);
        s2[0]=0;
        for(int i=1;i<=200000;i++) s2[i]=s2[i-1]+f[i];
    }
    void gen3() {
        memset(f,0,sizeof(f)); memset(g,0,sizeof(g));
        for(int i=1;i<n;i++) f[max(a[i],a[i+1])] ++;
        for(int i=1;i<m;i++) g[max(b[i],b[i+1])] ++;
        int dp=100000,dq=100000;
    /*
    printf("f\n");
        for(int i=0;i<7;i++) printf("%d ", f[i]); printf("\n");
    printf("g\n");
        for(int i=0;i<7;i++) printf("%d ", g[i]); printf("\n");
    */
        mul(f,dp,g,dq);
    //printf("m\n");
        //for(int i=0;i<7;i++) printf("%d ", f[i]); printf("\n");
        s3[0]=0;
        for(int i=1;i<=200000;i++) s3[i]=s3[i-1]+f[i];
    }
    void gen4() {
        memset(f,0,sizeof(f)); memset(g,0,sizeof(g));
        for(int i=1;i<=n;i++) f[a[i]] ++;
        for(int i=1;i<=m;i++) g[b[i]] ++;
        int dp=100000,dq=100000;
        mul(f,dp,g,dq);
        s4[0]=0;
        for(int i=1;i<=200000;i++) s4[i]=s4[i-1]+f[i];
    }
}

int main() {
    scanf("%lld%lld%d", &n,&m,&q);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=m;i++){
        scanf("%d",&b[i]);
    }
    Min::gen1(); Min::gen2(); Min::gen3();
    Max::gen1(); Max::gen2(); Max::gen3(); Max::gen4();
    //printf("# %d\n", Max::s3[4]);
    while(q--) {
        int x; scanf("%d",&x);
        LL ans1 = (1LL*n*(m-1) - Min::s1[x-1]) + (1LL*(n-1)*m - Min::s2[x-1]) - (1LL*n*m - Max::s4[x-1]) - (1LL*(n-1)*(m-1) - Min::s3[x-1]);
        LL ans2 = Max::s1[x-1] + Max::s2[x-1] - Max::s4[x-1] - Max::s3[x-1];
        printf("%lld\n", ans2-ans1);
    }
}


#include <bits/stdc++.h>
using namespace std;
int dig(int n)
{
    int sum = 0;
    while(n)
    {
        sum++;
        n/=10;
    }
    return sum;
}
int main()
{
    int T;
    cin>>T;
    int ar[6];
    int p;
    for(int i=0;i<6;i++)
    {
        cin>>p;
        ar[i] = p;
    }
    int q;
    cin>>q;
    int n;
    cin>>n;
    int dp[T];
    int sum=0;
    sum+=9;
    if(T>9)
    dp[0] = 9;
    for(int i=1;i<T;i++)
    {
        if(sum+((10*i)+9)<=T)
        {
        dp[i] = (10*i)+9;
        sum+=dp[i];
        }
        else if(sum+((10*i)+6)<=T)
        {
        dp[i] = (10*i)+6;
        sum+=dp[i];
        }
        else if(sum+((10*i)+3)<=T)
        {
        dp[i] = (10*i)+3;
        sum+=dp[i];
        }
        else if(sum>T)
        {
            int dif = sum-T;
            for(int j=1;j>=0;j--)
            if(diff<=dp[j])
            {
                dp[j]-=diff;
                sum-=diff;
                break;
            }
        }
    }
    int fortune = 0;
    for(int i=0;i<T;i++)
    {
        int d = dig(dp[i]);
        if((dp[i]%10)%3==0)
        {
            fortune+=((dp[i]%10)/3)*(dig(dp[i])-1);
        }
    }
    cout<<fortune<<endl;
    return 0;
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

template <int M>
struct MInt {
  unsigned int v;
  MInt() : v(0) {}
  MInt(const long long x) : v(x >= 0 ? x % M : x % M + M) {}
  static constexpr int get_mod() { return M; }
  static void set_mod(const int divisor) { assert(divisor == M); }
  static void init(const int x = 10000000) {
    inv(x, true);
    fact(x);
    fact_inv(x);
  }
  static MInt inv(const int n, const bool init = false) {
    // assert(0 <= n && n < M && std::__gcd(n, M) == 1);
    static std::vector<MInt> inverse{0, 1};
    const int prev = inverse.size();
    if (n < prev) {
      return inverse[n];
    } else if (init) {
      // "n!" and "M" must be disjoint.
      inverse.resize(n + 1);
      for (int i = prev; i <= n; ++i) {
        inverse[i] = -inverse[M % i] * (M / i);
      }
      return inverse[n];
    }
    int u = 1, v = 0;
    for (unsigned int a = n, b = M; b;) {
      const unsigned int q = a / b;
      std::swap(a -= q * b, b);
      std::swap(u -= q * v, v);
    }
    return u;
  }
  static MInt fact(const int n) {
    static std::vector<MInt> factorial{1};
    const int prev = factorial.size();
    if (n >= prev) {
      factorial.resize(n + 1);
      for (int i = prev; i <= n; ++i) {
        factorial[i] = factorial[i - 1] * i;
      }
    }
    return factorial[n];
  }
  static MInt fact_inv(const int n) {
    static std::vector<MInt> f_inv{1};
    const int prev = f_inv.size();
    if (n >= prev) {
      f_inv.resize(n + 1);
      f_inv[n] = inv(fact(n).v);
      for (int i = n; i > prev; --i) {
        f_inv[i - 1] = f_inv[i] * i;
      }
    }
    return f_inv[n];
  }
  static MInt nCk(const int n, const int k) {
    if (n < 0 || n < k || k < 0) return 0;
    return fact(n) * (n - k < k ? fact_inv(k) * fact_inv(n - k) :
                                  fact_inv(n - k) * fact_inv(k));
  }
  static MInt nPk(const int n, const int k) {
    return n < 0 || n < k || k < 0 ? 0 : fact(n) * fact_inv(n - k);
  }
  static MInt nHk(const int n, const int k) {
    return n < 0 || k < 0 ? 0 : (k == 0 ? 1 : nCk(n + k - 1, k));
  }
  static MInt large_nCk(long long n, const int k) {
    if (n < 0 || n < k || k < 0) return 0;
    inv(k, true);
    MInt res = 1;
    for (int i = 1; i <= k; ++i) {
      res *= inv(i) * n--;
    }
    return res;
  }
  MInt pow(long long exponent) const {
    MInt res = 1, tmp = *this;
    for (; exponent > 0; exponent >>= 1) {
      if (exponent & 1) res *= tmp;
      tmp *= tmp;
    }
    return res;
  }
  MInt& operator+=(const MInt& x) {
    if ((v += x.v) >= M) v -= M;
    return *this;
  }
  MInt& operator-=(const MInt& x) {
    if ((v += M - x.v) >= M) v -= M;
    return *this;
  }
  MInt& operator*=(const MInt& x) {
    v = static_cast<unsigned long long>(v) * x.v % M;
    return *this;
  }
  MInt& operator/=(const MInt& x) { return *this *= inv(x.v); }
  bool operator==(const MInt& x) const { return v == x.v; }
  bool operator!=(const MInt& x) const { return v != x.v; }
  bool operator<(const MInt& x) const { return v < x.v; }
  bool operator<=(const MInt& x) const { return v <= x.v; }
  bool operator>(const MInt& x) const { return v > x.v; }
  bool operator>=(const MInt& x) const { return v >= x.v; }
  MInt& operator++() {
    if (++v == M) v = 0;
    return *this;
  }
  MInt operator++(int) {
    const MInt res = *this;
    ++*this;
    return res;
  }
  MInt& operator--() {
    v = (v == 0 ? M - 1 : v - 1);
    return *this;
  }
  MInt operator--(int) {
    const MInt res = *this;
    --*this;
    return res;
  }
  MInt operator+() const { return *this; }
  MInt operator-() const { return MInt(v ? M - v : 0); }
  MInt operator+(const MInt& x) const { return MInt(*this) += x; }
  MInt operator-(const MInt& x) const { return MInt(*this) -= x; }
  MInt operator*(const MInt& x) const { return MInt(*this) *= x; }
  MInt operator/(const MInt& x) const { return MInt(*this) /= x; }
  friend std::ostream& operator<<(std::ostream& os, const MInt& x) {
    return os << x.v;
  }
  friend std::istream& operator>>(std::istream& is, MInt& x) {
    long long v;
    is >> v;
    x = MInt(v);
    return is;
  }
};
using ModInt = MInt<MOD>;

std::vector<int> prime_sieve(const int n, const bool get_only_prime) {
  std::vector<int> smallest_prime_factor(n + 1), prime;
  std::iota(smallest_prime_factor.begin(), smallest_prime_factor.end(), 0);
  for (int i = 2; i <= n; ++i) {
    if (smallest_prime_factor[i] == i) prime.emplace_back(i);
    for (const int p : prime) {
      if (i * p > n || p > smallest_prime_factor[i]) break;
      smallest_prime_factor[i * p] = p;
    }
  }
  return get_only_prime ? prime : smallest_prime_factor;
}

struct Divisor {
  const std::vector<int> smallest_prime_factor;

  explicit Divisor(const int n)
      : smallest_prime_factor(prime_sieve(n, false)) {}

  std::vector<int> query(int n) const {
    std::vector<int> res{1};
    while (n > 1) {
      const int prime_factor = smallest_prime_factor[n], d = res.size();
      int tmp = 1;
      for (; n % prime_factor == 0; n /= prime_factor) {
        tmp *= prime_factor;
        for (int i = 0; i < d; ++i) {
          res.emplace_back(res[i] * tmp);
        }
      }
    }
    // std::sort(res.begin(), res.end());
    return res;
  }
};

std::vector<int> mobius_mu_init(const int n) {
  std::vector<bool> is_prime(n + 1, true);
  is_prime[0] = false;
  if (n >= 1) is_prime[1] = false;
  std::vector<int> mu(n + 1, 1);
  mu[0] = 0;
  for (int i = 2; i <= n; ++i) {
    if (is_prime[i]) {
      mu[i] = -mu[i];
      for (int j = i * 2; j <= n; j += i) {
        is_prime[j] = false;
        mu[j] = ((j / i) % i == 0 ? 0 : -mu[j]);
      }
    }
  }
  return mu;
}

// https://oeis.org/A229223
ModInt g(int n, int k) {
  const int m = min(n, k);
  vector<ModInt> dp(m + 1, 0);
  dp[0] = 1;
  while (n--) {
    vector<ModInt> nxt(m + 1, 0);
    REP(i, m + 1) {
      if (i > 0) nxt[i] += dp[i] * (i - 1);
      if (i + 1 <= m) nxt[i + 1] += dp[i];
    }
    dp.swap(nxt);
  }
  return accumulate(ALL(dp), ModInt(0));
}

template <typename T>
std::vector<std::vector<T>> stirling_number_of_the_second_kind_init(
    const int n, const int k) {
  std::vector<std::vector<T>> s(n + 1, std::vector<T>(k + 1, 0));
  s[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= i && j <= k; ++j) {
      s[i][j] = s[i - 1][j - 1] + s[i - 1][j] * j;
    }
  }
  return s;
}

int main() {
  int n, k; cin >> n >> k;
  if (n == 1 || k == 1) {
    cout << 1 << '\n';
    return 0;
  }
  const Divisor divisor(n);
  const vector<int> mu = mobius_mu_init(n);
  const auto s = stirling_number_of_the_second_kind_init<ModInt>(n - 1, k);
  vector<ModInt> f(n + 1, 0);
  FOR(i, 1, n + 1) f[i] = accumulate(s[i - 1].begin(), s[i - 1].begin() + (min(i - 1, k - 1) + 1), ModInt(0));
  FOR(i, 2, n + 1) f[i - 2] = f[i];
  f.resize(n - 1);
  ModInt ans = 0;
  FOR(i, 1, n) {
    for (int j : divisor.query(i)) {
      const int seg = i / j;
      ModInt ways = 0;
      REP(x, seg) ways += ModInt::nCk(seg - 1, x) * f[x];  // f[x + 2]
      ans += ways * mu[j];
    }
  }
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
template<class C>constexpr int sz(const C&c){return int(c.size());}
using ll=long long;constexpr const char nl='\n',sp=' ';

using ld = long double;
const ld EPS = 1e-9;
using Point = pair<ld, ld>;
#define x first
#define y second
using Polygon = pair<int, vector<Point>>;
#define index first
#define points second
using Group = vector<Polygon>;
using Operation = pair<Group, Group>;
using Sequence = vector<Operation>;
#define input first
#define output second

template <class T> bool lt(const T &a, const T &b) { return a < b - T(EPS); }
template <class T> bool le(const T &a, const T &b) { return !lt(b, a); }
template <class T> bool gt(const T &a, const T &b) { return lt(b, a); }
template <class T> bool ge(const T &a, const T &b) { return !lt(a, b); }
template <class T> bool eq(const T &a, const T &b) { return !lt(a, b) && !lt(b, a); }
template <class T> bool ne(const T &a, const T &b) { return lt(a, b) || lt(b, a); }

bool ltX(const Point &a, const Point &b) {
    return lt(a.x, b.x);
}

bool ltY(const Point &a, const Point &b) {
    return lt(a.y, b.y);
}

bool eqPoint(const Point &a, const Point &b) {
    return eq(a.x, b.x) && eq(a.y, b.y);
}

ld dist(const Point &a, const Point &b) {
    ld dx = a.x - b.x, dy = a.y - b.y;
    return sqrt(dx * dx + dy * dy);
}

int ccw(const Point &a, const Point &b, const Point &c) {
    ld a2 = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
    if (lt(a2, ld(0))) return -1;
    else if (gt(a2, ld(0))) return +1;
    else return 0;
}

ld area2(const Point &a, const Point &b, const Point &c) {
    return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}

ld area2(const Polygon &P) {
    ld ret = 0;
    for (int i = 0; i < sz(P.points); i++) ret += area2(Point(0, 0), P.points[i], P.points[(i + 1) % sz(P.points)]);
    return ret;
}

Sequence reverseSeq(const Sequence &seq) {
    Sequence ret(seq);
    reverse(ret.begin(), ret.end());
    for (auto &&op : ret) op.input.swap(op.output);
    return ret;
}

int index = 1;

Polygon makeRect(ld minX, ld minY, ld maxX, ld maxY) {
    Polygon r;
    r.index = index++;
    r.points.emplace_back(minX, minY);
    r.points.emplace_back(maxX, minY);
    r.points.emplace_back(maxX, maxY);
    r.points.emplace_back(minX, maxY);
    return r;
}

Sequence rectToSquare(const Polygon &src, const Polygon &square) {
    Sequence seq;
    ld minX = min_element(src.points.begin(), src.points.end(), ltX)->x;
    ld maxX = max_element(src.points.begin(), src.points.end(), ltX)->x;
    ld minY = min_element(src.points.begin(), src.points.end(), ltY)->y;
    ld maxY = max_element(src.points.begin(), src.points.end(), ltY)->y;
    ld curWidth = maxX - minX;
    ld curHeight = maxY - minY;
    ld len = square.points[2].x;
    Polygon st = src;
    for (auto &&p : st.points) {
        p.x -= minX;
        p.y -= minY;
    }
    Polygon cur = makeRect(0, 0, curWidth, curHeight);
    seq.emplace_back(Group{st}, Group{cur});
    if (lt(curWidth, curHeight)) {
        swap(curWidth, curHeight);
        Polygon rot1 = makeRect(0, 0, curWidth, curHeight);
        Polygon rot2 = rot1;
        rot1.index = cur.index;
        rotate(rot1.points.begin(), rot1.points.begin() + 3, rot1.points.end());
        seq.emplace_back(Group{rot1}, Group{rot2});
        cur = rot2;
    }
    while (gt(curWidth, 2 * len)) {
        Polygon left = makeRect(0, 0, curWidth / 2, curHeight);
        Polygon right = makeRect(curWidth / 2, 0, curWidth, curHeight);
        seq.emplace_back(Group{cur}, Group{left, right});
        curWidth /= 2;
        curHeight *= 2;
        cur = makeRect(0, 0, curWidth, curHeight);
        Polygon bottom = makeRect(0, 0, curWidth, curHeight / 2);
        bottom.index = left.index;
        Polygon top = makeRect(0, curHeight / 2, curWidth, curHeight);
        top.index = right.index;
        seq.emplace_back(Group{bottom, top}, Group{cur});
    }
    if (ne(curWidth, len)) {
        Point p(len, curHeight);
        Point q(curWidth - len, 0);
        Point r(curWidth - len, len - curHeight);
        Polygon a{index++, {cur.points[0], q, r}};
        Polygon b{index++, {cur.points[0], p, cur.points[3]}};
        Polygon c{index++, {q, cur.points[1], cur.points[2], p, r}};
        seq.emplace_back(Group{cur}, Group{a, b, c});
        cur = makeRect(0, 0, len, len);
        p = Point(0, len - curHeight);
        q = Point(len, curHeight);
        r = Point(len - (curWidth - len), curHeight);
        Polygon d{a.index, {r, q, cur.points[2]}};
        Polygon e{b.index, {p, cur.points[2], cur.points[3]}};
        Polygon f{c.index, {cur.points[0], cur.points[1], q, r, p}};
        seq.emplace_back(Group{d, e, f}, Group{cur});
    }
    seq.emplace_back(Group{cur}, Group{square});
    return seq;
}

Sequence rectToRect(const Polygon &src, const Polygon &target) {
    ld len = sqrt(area2(src) / 2);
    Polygon square = makeRect(0, 0, len, len);
    Sequence A = rectToSquare(src, square), B = reverseSeq(rectToSquare(target, square));
    A.insert(A.end(), B.begin(), B.end());
    return A;
}

pair<Sequence, Polygon> triToArbRect(const Polygon &tri) {
    Sequence seq;
    vector<ld> lens;
    for (int i = 0; i < sz(tri.points); i++) lens.push_back(dist(tri.points[i], tri.points[(i + 1) % sz(tri.points)]));
    int ind = max_element(lens.begin(), lens.end(), lt<ld>) - lens.begin();
    ld base = lens[ind], height = area2(tri) / base;
    ld tx = lens[(ind + sz(lens) - 1) % sz(lens)];
    tx = sqrt(tx * tx - height * height);
    Polygon st;
    st.index = tri.index;
    st.points.emplace_back(0, 0);
    st.points.emplace_back(base, 0);
    st.points.emplace_back(tx, height);
    Polygon cur = st;
    cur.index = index++;
    rotate(st.points.begin(), st.points.begin() + (sz(st.points) - ind) % sz(st.points), st.points.end());
    seq.emplace_back(Group{st}, Group{cur});
    ld base1 = tx / 2, base2 = (base - tx) / 2;
    Point p(tx - base1, height / 2);
    Point q(tx, height / 2);
    Point r(tx + base2, height / 2);
    Polygon a{index++, {p, q, cur.points[2]}};
    Polygon b{index++, {q, r, cur.points[2]}};
    Polygon c{index++, {cur.points[0], cur.points[1], r, p}};
    seq.emplace_back(Group{cur}, Group{a, b, c});
    cur = makeRect(0, 0, base, height / 2);
    p = Point(base1, height / 2);
    r = Point(base - base2, height / 2);
    Polygon d{a.index, {p, cur.points[3], cur.points[0]}};
    Polygon e{b.index, {cur.points[2], r, cur.points[1]}};
    Polygon f{c.index, {cur.points[0], cur.points[1], r, p}};
    seq.emplace_back(Group{d, e, f}, Group{cur});
    return make_pair(seq, cur);
}

Sequence triToSquare(const Polygon &src, const Polygon &target) {
    Sequence A, B;
    Polygon rect;
    tie(A, rect) = triToArbRect(src);
    B = rectToSquare(rect, target);
    A.insert(A.end(), B.begin(), B.end());
    return A;
}

bool valid(const Point &a, const Point &b, const Point &c, const Polygon &P) {
    for (auto &&p : P.points) if (ccw(a, b, p) == 1 && ccw(b, c, p) == 1 && ccw(c, a, p) == 1) return false;
    return true;
}

pair<Sequence, Polygon> polyToArbSquare(const Polygon &P) {
    Sequence seq;
    Group tris;
    Polygon cur = P;
    while (sz(cur.points) > 2) {
        for (int i = 0; i < sz(cur.points); i++) {
            Point p = cur.points[i], q = cur.points[(i + 1) % sz(cur.points)], r = cur.points[(i + 2) % sz(cur.points)];
            if (ccw(p, q, r) == 1 && valid(p, q, r, cur)) {
                tris.emplace_back(index++, vector<Point>{p, q, r});
                cur.points.erase(cur.points.begin() + (i + 1) % sz(cur.points));
                break;
            }
        }
    }
    seq.emplace_back(Group{P}, tris);
    Polygon merged;
    merged.index = -1;
    ld totArea = 0;
    for (auto &&tri : tris) {
        ld a = area2(tri) / 2, len = sqrt(a);
        totArea += a;
        Polygon square = makeRect(0, 0, len, len);
        Sequence A = triToSquare(tri, square);
        seq.insert(seq.end(), A.begin(), A.end());
        if (merged.index == -1) merged = square;
        else {
            ld len = sqrt(totArea);
            Polygon bottom = makeRect(0, 0, len, a / len);
            Polygon top = makeRect(0, a / len, len, totArea / len);
            Sequence B = reverseSeq(rectToSquare(bottom, square)), C = reverseSeq(rectToSquare(top, merged));
            seq.insert(seq.end(), B.begin(), B.end());
            seq.insert(seq.end(), C.begin(), C.end());
            merged = makeRect(0, 0, len, len);
            seq.emplace_back(Group{bottom, top}, Group{merged});
        }
    }
    return make_pair(seq, merged);
}

Sequence polyToPoly(const Polygon &src, const Polygon &target) {
    Sequence A, B;
    Polygon SA, SB;
    tie(A, SA) = polyToArbSquare(src);
    tie(B, SB) = polyToArbSquare(target);
    B = reverseSeq(B);
    A.emplace_back(Group{SA}, Group{SB});
    A.insert(A.end(), B.begin(), B.end());
    return A;
}

Polygon readPolygon() {
    Polygon ret;
    ret.index = index++;
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
        int x, y;
        cin >> x >> y;
        ret.points.emplace_back(x, y);
    }
    return ret;
}

void writeSeq(const Polygon &S, const Sequence &seq) {
    vector<int> indexToId(index, -1);
    int curId = 0;
    auto addId = [&] (const Polygon &P) {
        return indexToId[P.index] = curId++;
    };
    auto removeId = [&] (const Polygon &P) {
        int ret = indexToId[P.index];
        assert(ret != -1);
        indexToId[P.index] = -1;
        return ret;
    };
    auto writePolygon = [&] (const Polygon &P) {
        cout << sz(P.points);
        for (auto &&p : P.points) cout << sp << fixed << setprecision(9) << p.x << sp << p.y;
        cout << nl;
    };
    auto writeOp = [&] (const Operation &op) {
        if (sz(op.output) == 1) {
            cout << "tape" << nl;
            cout << sz(op.input);
            for (auto &&P : op.input) cout << sp << removeId(P);
            cout << nl;
            for (auto &&P : op.input) writePolygon(P);
            writePolygon(op.output[0]);
            addId(op.output[0]);
        } else {
            cout << "scissors" << nl;
            cout << removeId(op.input[0]) << sp << sz(op.output) << nl;
            for (auto &&P : op.output) {
                writePolygon(P);
                addId(P);
            }
        }
    };
    addId(S);
    for (auto &&op : seq) writeOp(op);
}

int main() {
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    // freopen("err.txt", "w", stderr);
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    Polygon S = readPolygon(), T = readPolygon();
    Sequence A = polyToPoly(S, T);
    writeSeq(S, A);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#define LL long long
#define ull unsigned long long
using namespace std;
const int N=110;
const ull INF = -1;

int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(LL x){
    if(x>9) print(x/10);
    putchar(x%10+'0');
}

int G,n,m;
int a[N],k[N],b[N][N];
int l[N],c[N][N];
ull dp[N][N][N];
ull tp[N][N];
int cnt;

int nxt[N],go[N][2];
void KMP(int len,int *s){
	int j=0;
	for(int i=2;i<=len;++i){
		while(j>0&&s[j+1]!=s[i]) j=nxt[j];
		if(s[j+1]==s[i]) ++j;
		nxt[i]=j;
	}
	go[len][0]=go[len][1];
	for(int i=0;i<len;++i){
		for(int h=0;h<=1;++h){
			if(h==s[i+1]) go[i][h]=i+1;
			else go[i][h]=go[nxt[i]][h];
		}
	}
}
bool sol(int row){
	bool re=0;
	for(int st=0;st<=cnt;++st){
		fill_n(tp[0],N*N,INF);
		tp[0][st]=0;
		for(int it=1;it<=k[row];++it){
			int h=b[row][it];
			for(int i=0;i<=cnt;++i){
				if(tp[it-1][i]>=INF) {
					continue;
				}
				for(int j=0;j<=cnt;++j){
					ull w=dp[h][i][j];
					if(w<INF) tp[it][j]=min(tp[it][j],tp[it-1][i]+w);
				}
			}
		}
		for(int ed=0;ed<=cnt;++ed){
			if(dp[a[row]][st][ed]>tp[k[row]][ed]){
				dp[a[row]][st][ed]=tp[k[row]][ed];
				re=1;
			}
		}
	}
	return re;
}
int main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	scanf("%d%d%d",&G,&n,&m);
	assert(m == 1);
	for(int i=1;i<=n;++i){
		scanf("%d%d",&a[i],&k[i]);
		for(int j=1;j<=k[i];++j){
			scanf("%d",&b[i][j]);
		}
	}
	for(int i=1;i<=m;++i){
		scanf("%d",&l[i]);
		for(int j=1;j<=l[i];++j){
			scanf("%d",&c[i][j]);
		}
	}
	KMP(l[1],c[1]);
	cnt=l[1];
	fill_n(dp[0][0], N*N*N, INF);
	for(int i=0;i<=cnt;++i){
		for(int h=0;h<=1;++h){
			dp[h][i][go[i][h]]=1;
		}
	}

	for(bool flag=1;flag;){
		flag=0;
		for(int i=1;i<=n;++i) flag|=sol(i);
	}
	for(int i=2;i<G;++i) {
        ull ans=INF;
        for(int j=0;j<cnt;++j)
            ans=min(ans,dp[i][0][j]);
        if(ans<INF) cout<<"NO " <<ans<<endl;
		else cout<<"YES"<<endl;
    }
    return 0;
}
/*
6 6 1
2 2 0 1
3 3 2 0 0
3 2 1 3
4 4 0 3 1 2
5 2 2 1
5 1 5
2 1 1

*/


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <cstdio>
//#include <iomanip>//"cout<<fixed<<setprecision(n)<<sth<<endl;"
//#include <string>//"reverse(s's it,s's it)"
//#include <functional>//"greater<T>" "sort(a,a+n,greater<int>());""
//#include <cmath>//"abs" "sqrt"
//#include <numeric>//"accumulate(inputit,inputit,init,(optional) object)"
//#include <algorithm>//"lower_bound(it,it,v)" "next_permutation(a,a+n)"
//"reverse(v's it,v's it)"(v: vector)
using namespace std;
#define pb push_back//also for STRING
#define fi first
#define sc second
#define mp make_pair
#define is insert
#define ps push//TMP//stack,(priority) queue,
#define fr front//TMP//queue//for priority, use top().
typedef long long ll;//not necessarily
typedef pair<int,int> pii;
//Add other types in the same way.
const ll M=1000000007;//can be changed
ll mod(ll a){	return (a+M)%M;	}//M can be a variable
void plmod(ll &a,ll b){	a=(a+b+M)%M;	return;	}
void mnmod(ll &a,ll b){	a=(a-b+M)%M;	return;	}
void mlmod(ll &a,ll b){	a=(a*b)%M;  	return;	}
//Caution! you may need sth larger than "+M"!
void chmax(int &a,int b){	a=max(a,b);	return;	}
void chmin(int &a,int b){	a=min(a,b);	return;	}
//These 2 could be better in long long

#define MAX_N 300

ll c[MAX_N+1][MAX_N+1];

ll C(int x,int y){
	if(x>=y) return c[x][y];
	else return 0;
}

int main(){
	int n,a[MAX_N];
	ll dp[2][MAX_N],fact[MAX_N];
	scanf("%d",&n);
	fact[0]=1;
	for(int i=1;i<=n;++i) fact[i]=mod(fact[i-1]*(ll)i);
	c[0][0]=1;
	for(int i=0;i<=n;++i){
		c[i+1][0]=1;
		c[i+1][i+1]=1;
		for(int j=1;j<=i;++j) c[i+1][j]=mod(c[i][j-1]+c[i][j]);
	}
	for(int i=0;i<n;++i) scanf("%d",&a[i]);
	vector<int> v;
	bool f[MAX_N];
	fill(f,f+n,false);
	for(int i=0;i<n;++i) if(!f[i]){
		f[i]=true;
		v.pb(1);
		for(int j=i+1;j<n;++j) if(((ll)sqrt((ll)a[i]*(ll)a[j]))*((ll)sqrt((ll)a[i]*(ll)a[j]))==(ll)a[i]*(ll)a[j]){
			f[j]=true;
			++*(v.rbegin());
		}
	}
	//for(int i=0;i<v.size();++i) printf(" %d",v[i]);
	//printf("\n\n");
	int s=v[0];
	for(int j=0;j<s-1;++j) dp[0][j]=0;
	dp[0][s-1]=fact[s];
	//for test
	//for(int j=0;j<s;++j) printf(" %d",dp[0][j]);
	//printf("\n");
	for(int i=0;i<v.size()-1;++i){
		fill(dp[(i+1)%2],dp[(i+1)%2]+(s+v[i+1]),0);
		for(int j=0;j<s-i;++j){
			if(dp[i%2][j]==0) continue;
			for(int g=1;g<=min(v[i+1],s+1);++g) for(int d=0;d<=min(j,g);++d){
				plmod(dp[(i+1)%2][j-d+v[i+1]-g],mod(mod(mod(dp[i%2][j]*fact[v[i+1]])*mod(c[j][d]*C(s+1-j,g-d)))*c[v[i+1]-1][g-1]));
			}
		}
		//for test
		//for(int j=0;j<s+v[i+1];++j) printf(" %d",dp[(i+1)%2][j]);
		//printf("\n");
		s+=v[i+1];
	}
	cout<<dp[(v.size()-1)%2][0])<<endl;
}


//#define DEBUG
//#define USEPB_DS
#define USETR1
#define CPPELEVEN
#define GPP

/*
 * temp.cpp
 *
 *  Created on: 2012-7-18
 *      Author: BSBandme
 */
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#if __cplusplus < 201500L
#include <bits/stdc++.h>
#else
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
#include <list>
#include <iomanip>
#include <cmath>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <climits>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>
#include <tuple>
#endif

using namespace std;

#ifndef CPPELEVEN
#ifdef USETR1
#include <tr1/unordered_map>
#include <tr1/unordered_set>
using namespace tr1;
#endif
#else
#include <unordered_map>
#include <unordered_set>
#endif

#ifdef USEPB_DS
#include <ext/pb_ds/priority_queue.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// binomial_heap_tag, rc_binomial_heap_tag, thin_heap_tag, binary_heap_tag
typedef __gnu_pbds::priority_queue<int, greater<int>, pairing_heap_tag> pq_type;
// splay_tree_tag, ov_tree_tag
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> tree_type;
#endif

#define mpr make_pair
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef map<string, int> mpsi;
typedef map<double, int> mpdi;
typedef map<int, int> mpii;

const double pi = acos(0.0) * 2.0;
const long double eps = 1e-10;
const int step[8][2] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 1 }, {
		1, 1 }, { 1, -1 }, { -1, -1 } };

template<class T> inline T abs1(T a) {
	return a < 0 ? -a : a;
}

#ifndef CPPELEVEN
template <class T> inline T max1(T a, T b) { return b < a ? a : b; }
template <class T> inline T max1(T a, T b, T c) { return max1(max1(a, b), c); }
template <class T> inline T max1(T a, T b, T c, T d) { return max1(max1(a, b, c), d); }
template <class T> inline T max1(T a, T b, T c, T d, T e) { return max1(max1(a, b, c, d), e); }
template <class T> inline T min1(T a, T b) { return a < b ? a : b; }
template <class T> inline T min1(T a, T b, T c) { return min1(min1(a, b), c); }
template <class T> inline T min1(T a, T b, T c, T d) { return min1(min1(a, b, c), d); }
template <class T> inline T min1(T a, T b, T c, T d, T e) { return min1(min1(a, b, c, d), e); }
#else
template<typename t, typename t1>
t min1(t a, t1 b) {
	return a < b ? a : b;
}
template<typename t, typename ... arg>
t min1(t a, arg ... arr) {
	return min1(a, min1(arr...));
}
template<typename t, typename t1>
t max1(t a, t1 b) {
	return a > b ? a : b;
}
template<typename t, typename ... arg>
t max1(t a, arg ... arr) {
	return max1(a, max1(arr...));
}
#endif

inline int jud(double a, double b) {
	if (abs(a) < eps && abs(b) < eps)
		return 0;
	else if (abs1(a - b) / max(abs1(a), abs1(b)) < eps) return 0;
	if (a < b) return -1;
	return 1;
}
template<typename t> inline int jud(t a, t b) {
	if (a < b) return -1;
	if (a == b) return 0;
	return 1;
}

// f_lb == 1代表返回相同的一串的左边界，f_small == 1代表返回如果没有寻找的值返回小的数
template<typename it, typename t1>
inline int RangeFind(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1) {
	if (na == 0) return 0;
	int be = 0, en = na - 1;
	if (*a <= *(a + na - 1)) {
		if (f_lb == 0)
			while (be < en) {
				int mid = (be + en + 1) / 2;
				if (jud(*(a + mid), val) != 1)
					be = mid;
				else
					en = mid - 1;
			}
		else
			while (be < en) {
				int mid = (be + en) / 2;
				if (jud(*(a + mid), val) != -1)
					en = mid;
				else
					be = mid + 1;
			}
		if (f_small && jud(*(a + be), val) == 1) be--;
		if (!f_small && jud(*(a + be), val) == -1) be++;
	} else {
		if (f_lb)
			while (be < en) {
				int mid = (be + en + 1) / 2;
				if (jud(*(a + mid), val) != -1)
					be = mid;
				else
					en = mid - 1;
			}
		else
			while (be < en) {
				int mid = (be + en) / 2;
				if (jud(*(a + mid), val) != 1)
					en = mid;
				else
					be = mid + 1;
			}
		if (!f_small && jud(*(a + be), val) == -1) be--;
		if (f_small && jud(*(a + be), val) == 1) be++;
	}
	return be;
}

template<class T> inline T lowb(T num) {
	return num & (-num);
}
#ifdef GPP
inline int bitnum(ui nValue) {
	return __builtin_popcount(nValue);
}
inline int bitnum(int nValue) {
	return __builtin_popcount(nValue);
}
inline int bitnum(ull nValue) {
	return __builtin_popcountll(nValue);
}
inline int bitnum(ll nValue) {
	return __builtin_popcountll(nValue);
}
inline int bitmaxl(ui a) {
	if (a == 0) return 0;
	return 32 - __builtin_clz(a);
}
inline int bitmaxl(int a) {
	if (a == 0) return 0;
	return 32 - __builtin_clz(a);
}
inline int bitmaxl(ull a) {
	if (a == 0) return 0;
	return 64 - __builtin_clzll(a);
}
inline int bitmaxl(ll a) {
	if (a == 0) return 0;
	return 64 - __builtin_clzll(a);
}
#else
#endif

long long pow(long long n, long long m, long long mod = 0) {
	if (m < 0) return 0;
	long long ans = 1;
	long long k = n;
	while (m) {
		if (m & 1) {
			ans *= k;
			if (mod) ans %= mod;
		}
		k *= k;
		if (mod) k %= mod;
		m >>= 1;
	}
	return ans;
}

#define  MOD 1000000007
template<class t1, class t2>
inline void add(t1 &a, t2 b, int mod = -1) {
	if (mod == -1) mod = MOD;
	a += b;
	while (a >= mod)
		a -= mod;
	while (a < 0)
		a += mod;
}
template<class t>
void output1(t arr) {
	for (int i = 0; i < (int) arr.size(); i++)
		cerr << arr[i] << ' ';
	cerr << endl;
}
template<class t>
void output2(t arr) {
	for (int i = 0; i < (int) arr.size(); i++)
		output1(arr[i]);
}

//....................密..........封..........线..........下..........禁..........止..........hack...............................................

const int mod = 998244353;
const int maxn = 2001000;
ll fac[maxn], invfac[maxn];
int n, m;

ll c(int a, int b) {
	if (b > a) return 0;
	return fac[a] * invfac[b] % mod * invfac[a - b] % mod;
}

ll GetB(int n, int a) {
	return c(n - a + m - 1, m - 1) * c(n + m, a) % mod * fac[a] % mod * fac[n - a] % mod *
			pow(c(n + m, m) * fac[n] % mod, mod - 2, mod) % mod;
}

ll GetAll() {
	ll ans = 0, multi = 1;
	for (int i = 0; i <= n; i++) {
		ans += m * pow(n + m - i, mod - 2, mod) % mod * multi % mod * (i + 1) % mod;
		multi = multi * (n - i) % mod * pow(n + m - i, mod - 2, mod) % mod;
	}
	return ans;
}

int main() {

//............................不要再忘了检查maxn大小了！！！！BSBandme你个SB！！！！...................................................

	ios_base::sync_with_stdio(0);
#ifdef DEBUG //......................................................................................................
	freopen("input.txt", "r", stdin);
#endif //...........................................................................................................

	scanf("%d%d", &n, &m);
	fac[0] = 1;
	for (int i = 1; i < maxn; i++) {
		fac[i] = fac[i - 1] * i % mod;
	}
	invfac[maxn - 1] = pow(fac[maxn - 1], mod - 2, mod);
	for (int j = maxn - 2; j >= 0; j--) {
		invfac[j] = invfac[j + 1] * (j + 1) % mod;
	}

	ll ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		ll flag = 1;
		if ((i - (n - 1)) % 2) flag = mod - 1;
		ans += flag * c(n, i) % mod * pow((mod + 1 - GetB(n, i)) % mod, mod - 2, mod);
		ans %= mod;
	}
	cout << ans * GetAll() % mod << endl;

	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <sstream>
#include <algorithm>

using namespace std;

typedef long long int ll;

string s;
ll n = 16;

vector<ll> w;
vector<ll> z;

vector<pair<ll, ll>> le;

void merge(ll l, ll r, stringstream& ss) {
    if (r - l <= 1) {
        return;
    }

    ll m = (l + r) / 2;
    merge(l, m, ss);
    merge(m, r, ss);

    ll i = l;
    ll j = m;

    vector<ll> c;

    while (i < m && j < r) {
        if (w[i] < w[j]) {
            ss << 0;
            c.push_back(w[i]);
            i += 1;
        } else {
            ss << 1;
            c.push_back(w[j]);
            j += 1;
        }
    }

    while (i < m) {
        c.push_back(w[i]);
        i += 1;
    }

    while (j < r) {
        c.push_back(w[j]);
        j += 1;
    }

    for (ll i = l; i < r; i++) {
        w[i] = c[i - l];
    }

    return;
}

bool match(ll l, ll r, ll& k) {
    if (r - l <= 1) {
        return true;
    }

    ll m = (l + r) / 2;
    match(l, m, k);
    match(m, r, k);

    ll i = l;
    ll j = m;

    vector<ll> c;

    while (i < m && j < r && k < s.size()) {
        if (s[k++] == '0') {
            le.push_back({z[i], z[j]});
            c.push_back(z[i]);
            i += 1;
        } else {
            le.push_back({z[j], z[i]});
            c.push_back(z[j]);
            j += 1;
        }
    }

    bool res = i >= m || j >= r;

    while (i < m) {
        c.push_back(z[i]);
        i += 1;
    }

    while (j < r) {
        c.push_back(z[j]);
        j += 1;
    }

    for (ll i = l; i < r; i++) {
        z[i] = c[i - l];
    }

    return res;
}

vector<ll> gen_ans() {
    vector<set<ll>> e(n);
    vector<set<ll>> g(n);

    for (auto [u, v] : le) {
        e[u].insert(v);
        g[v].insert(u);
    }

    vector<ll> a(n);
    ll b = 1;

    vector<ll> q;
    for (ll i = 0; i < n; i++) {
        if (!g[i].empty()) {
            continue;
        }
        q.push_back(i);
    }

    for (ll i = 0; i < q.size(); i++) {
        ll u = q[i];
        a[u] = b++;

        for (auto v : e[u]) {
            g[v].erase(u);
            if (!g[v].empty()) {
                continue;
            }
            q.push_back(v);
        }
    }

    return a;
}

ll ask(ll x) {
    n = x;
    le = vector<pair<ll, ll>>();
    z = vector<ll>(n);

    ll k = 0;
    for (ll i = 0; i < n; i++) {
        z[i] = i;
    }

    bool succ = match(0, n, k);
    ll res = 0;
    if (!succ) {
        res = 1;
    } else if (k < s.size()) {
        res = -1;
    }

    return res;
}

ll bin(ll l, ll r) {
    while (r - l > 1) {
        ll m = (l + r) / 2;
        ll res = ask(m);

        if (!res) {
            return m;
        }

        if (res > 0) {
            r = m;
        } else {
            l = m;
        }
    }

    return -1;
}

int main() {
    if (false) {
        ll n = 100'000;
        w = vector<ll>(n);

        if (true) {
            for (ll i = 0; i < n; i++) {
                w[i] = i;
            }

            srand(time(0));
            for (ll tt = 0; tt < 1'000; tt++) {
                ll i = rand() % n;
                ll j = rand() % n;

                swap(w[i], w[j]);
            }
        } else {
            // w = {1, 17, 19, 12, 18, 20, 15, 14, 16, 13, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            w = {19, 16, 1, 15, 17, 12, 14, 18, 13, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            n = w.size();
        }

        stringstream ss;
        merge(0, n, ss);
        s = ss.str();
        cerr << ss.str() << endl;

//        stringstream ts;
//        for (auto e : w) {
//            ts << e << " ";
//        }
//        cerr << ts.str() << endl;
//        return 0;
    } else {
        cin >> s;
    }

//    s = "10011010010010011100010";

    vector<ll> a;

    if (false) {
        for (ll tt = 2; tt <= 1'000; tt++) {
            n = tt;
            le = vector<pair<ll, ll>>();
            z = vector<ll>(n);

            ll k = 0;
            for (ll i = 0; i < n; i++) {
                z[i] = i;
            }
            bool succ = match(0, n, k);
            ll res = 0;
            if (!succ) {
                res = 1;
            } else if (k < s.size()) {
                res = -1;
            }
            cerr << n << ": " << res << endl;
            if (succ && s.size() == k) {
                a = gen_ans();
            }
        }
    } else {
        ll x = bin(2, 100'000 + 1);
        ask(x);
        a = gen_ans();
    }

    stringstream ss;
    ss << a.size() << endl;
    for (auto e : a) {
        ss << e << " ";
    }
    cout << ss.str() << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int pos[22];
double score[22][2];

int n,Nfire,Nelec,Nice;
int Rfire,Relec,Rice;
int DamFire,DamElec;

int lower,upper;
double ret = 0;

double scoring(vector< pair<double,int> > v,int cord,int typ) {
  double low,high;
  if (!typ) {
    low = cord - sqrt(Rfire * Rfire - 1);
    high = cord + sqrt(Rfire * Rfire - 1);
  }
  else {
    low = cord - sqrt(Relec * Relec - 1);
    high = cord + sqrt(Relec * Relec - 1);
  }
  v.push_back(make_pair(low,-8));
  v.push_back(make_pair(high,-8));
  sort(v.begin(),v.end());

  int delta = 0,able = 0;
  double ans = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i].second != -8) delta += v[i].second;
    if (able && i) ans += (v[i].first - v[i - 1].first) * (delta + 1);
    if (v[i].second == -8) able ^= 1;
  }
  if (typ) ans *= DamElec; else ans *= DamFire;
  return ans;
}

void attempt2(int idx,int sofar,double get) {
  if (idx >= n && sofar == Nelec) {
    ret = max(ret,get);
    return;
  }
  if (pos[idx] == 2) attempt2(idx + 1,sofar,get); else {
    attempt2(idx + 1,sofar,get + score[idx][0]); // put a fire tower
    if (sofar < Nelec) attempt2(idx + 1,sofar + 1,get + score[idx][1]); // put an elec tower
  }
}

void update() {
  vector< pair<double,int> > v;
  for (int i = 0; i < n; i++) if (pos[i] == 2) {
    int cord = (i < lower) ? i : i - lower;
    v.push_back(make_pair(cord - sqrt(Rice * Rice - 1),1));
    v.push_back(make_pair(cord + sqrt(Rice * Rice - 1),-1));
  }
  for (int i = 0; i < n; i++) if (pos[i] != 2) {
    int cord = (i < lower) ? i : i - lower;
    score[i][0] = scoring(v,cord,0);
    score[i][1] = scoring(v,cord,1);
  }
  attempt(0,0,0.0);
}

void attempt(int idx,int sofar) {
  if (idx >= n) {
    if (sofar == Nice) update();
    return;
  }

  attempt(idx + 1,sofar);
  if (sofar < Nice) {
    pos[idx] = 2;
    attempt(idx + 1,sofar + 1);
    pos[idx] = -1;
  }
}

int main() {
  scanf("%d %d %d", &Nfire, &Nelec, &Nice);
  n = Nfire + Nelec + Nice;
  scanf("%d %d %d", &Rfire, &Relec, &Rice);
  scanf("%d %d", &DamFire, &DamElec);
  memset(pos,-1,sizeof(pos));
  lower = n/2;  upper = n - n/2;
  attempt(0,0);
  printf("%.6lf\n", ret);
}


#include <bits/stdc++.h>
#define MAXN 205
#define MAXE 5005
#define XX first
#define YY second
#define INF 100000000
using namespace std;
typedef pair <int, int> pii;

int src, snk, nNode, nEdge;
int fin[MAXN], pre[MAXN], dist[MAXN];
int cap[MAXE], cost[MAXE], next[MAXE], to[MAXE], from[MAXE];

inline void init(int _src, int _snk, int nodes){
    memset(fin, -1, sizeof(fin));
    nNode=nodes, nEdge=0;
    src=_src, snk=_snk;
}

inline void addEdge(int u, int v, int _cap, int _cost){
    from[nEdge]=u, to[nEdge]=v, cap[nEdge]=_cap, cost[nEdge]=_cost;
    next[nEdge]=fin[u], fin[u]=nEdge++;
    from[nEdge]=v, to[nEdge]=u, cap[nEdge]=0, cost[nEdge]=-(_cost);
    next[nEdge]=fin[v], fin[v]=nEdge++;
}

bool bellman(){
    int iter, u, v, i;
    bool flag=true;
    memset(dist, 0x7f, sizeof(dist));
    memset(pre, -1, sizeof(pre));
    dist[src]=0;
    for(iter=1; iter<nNode && flag; iter++){
        flag=false;
        for(u=0; u<nNode; u++){
            for(i=fin[u]; i>=0; i=next[i]){
                v=to[i];
                if(cap[i] && dist[v]>dist[u]+cost[i]){
                    dist[v]=dist[u]+cost[i];
                    pre[v]=i;
                    flag=true;
                }
            }
        }
    }
    return (dist[snk]<INF);
}

int mcmf(int &fcost){
    int netflow, i, bot, u;
    netflow=fcost=0;
    while(bellman()){
        bot=INF;
        for(u=pre[snk]; u>=0; u=pre[from[u]]) bot=min(bot, cap[u]);
        for(u=pre[snk]; u>=0; u=pre[from[u]]){
            cap[u]-=bot;
            cap[u^1]+=bot;
            fcost+=bot*cost[u];
        }
        netflow+=bot;
    }
    return netflow;
}

char str[105];
int b[105];
vector < pii > v;
int main(){
    int n;
    scanf("%d", &n);
    scanf("%s", str);
    for(int i=0; i<n; i++) scanf("%d", &b[i]);
    int sum=0;
    for(int i=0; i<n; i++) sum+=b[i];
    init(0, n+26+(n>>1)+1, n+26+(n>>1)+2);
    for(int i=1; i<=n; i++){
        addEdge(0, i, 1, 0);
        addEdge(i, n+1+str[i-1]-'a', 1, b[i-1]);
    }
    v.push_back(pii(-1, -1));
    for(int i=0, j=n-1; i<j; i++, j--){
        v.push_back(pii(i, j));
    }
    for(int i=1; i<v.size(); i++){
        for(int j=1; j<=26; j++){
            if((str[v[i].XX]-'a'+1)!=j && (str[v[i].YY]-'a'+1)!=j){
                addEdge(n+j, n+26+i, 1, 0);
            }
        }
        if(str[v[i].XX]!=str[v[i].YY]){
            addEdge(v[i].XX+1, n+26+i, 1, 0);
            addEdge(v[i].YY+1, n+26+i, 1, 0);
        }
        else{
            if(b[v[i].XX]>b[v[i].YY]){
                addEdge(v[i].XX+1, n+26+i, 1, 0);
            }
            else addEdge(v[i].YY+1, n+26+i, 1, 0);
        }
        addEdge(n+26+i, n+26+(n>>1)+1, 2, 0);
    }
    int cost;
    assert(mcmf(cost)==n);
    printf("%d\n", sum-cost);
    return 0;
}


#include<bits/stdc++.h
using namespace std;
int main()
{
	string a;
	cin>>a;
	if(a.size<10) cout<<"YES";
	else cout<<"NO";
	return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long double ld;
typedef complex<ld> co;
const ld eps=1e-8;
const ld maxD=1e6;
ld ccw(co a, co b) {
	return (b*conj(a)).Y;
}
int ar(co x) {
	if (x.Y>=0&&x.X<0) return 1;
	if (x.X>=0&&x.Y>0) return 2;
	if (x.Y<=0&&x.X>0) return 3;
	return 4;
}
bool cp(co p1, co p2) {
	if (ar(p1)!=ar(p2)) return ar(p1)>ar(p2);
	return ccw(p2, p1)<0;
}
struct hp_t {
	co a, b;
	hp_t(co p1, co p2) {
		a=p1;
		b=(p2-p1)/abs(p2-p1);
	}
	ld d(co p) const {
		return ccw(b, p-a);
	}
	bool operator<(const hp_t& o) const {
		if (abs(b-o.b)<eps){
			return d(o.a)<-eps;
		}
		return cp(b, o.b);
	}
	bool operator==(const hp_t& o) {
		return abs(b-o.b)<eps;
	}
};
co getI(hp_t a, hp_t b) {
	ld c=ccw(a.b, b.b);
	assert(!(abs(c)<eps));
	return ccw(b.a, b.b)*a.b/c+ccw(a.b, a.a)*b.b/c;
}
vector<co> getHPI(vector<hp_t> hp) {
	hp.push_back({{-maxD, -maxD}, {maxD, -maxD}});
	hp.push_back({{maxD, -maxD}, {maxD, maxD}});
	hp.push_back({{maxD, maxD}, {-maxD, maxD}});
	hp.push_back({{-maxD, maxD}, {-maxD, -maxD}});
	sort(hp.begin(), hp.end());
	hp.erase(unique(hp.begin(), hp.end()), hp.end());
	int del=0;
	vector<co> p;
	for (int i=1;i<(int)hp.size();i++){
		while ((int)p.size()>del&&hp[i].d(p.back())<eps) p.pop_back();
		while ((int)p.size()>del&&hp[i].d(p[del])<eps) del++;
		if (del==(int)p.size()&&ccw(hp[p.size()].b, hp[i].b)<eps) return {};
		co np=getI(hp[i], hp[p.size()]);
		if (hp[del].d(np)>-eps){
			p.push_back(np);
			hp[p.size()]=hp[i];
		}
	}
	rotate(p.begin(), p.begin()+del, p.end());
	rotate(hp.begin(), hp.begin()+del, hp.begin()+p.size()+1);
	p.resize((int)p.size()-del);
	if (p.empty()) return p;
	p.push_back(getI(hp[0], hp[p.size()]));
	return p;
}
bool cp2(co p1, co p2) {
	if (ar(p1)!=ar(p2)) return ar(p1)<ar(p2);
	return ccw(p2, p1)>0;
}

void solve(){
	int n;
	scanf("%d", &n);
	vector<co> ps;
	int xx,yy;
	scanf("%d %d", &xx, &yy);
	co x={(ld)xx, (ld)yy};
	for (int i=1;i<n;i++){
		scanf("%d %d", &xx, &yy);
		ps.push_back({(ld)xx, (ld)yy});
		ps.back()-=x;
	}
	sort(ps.begin(), ps.end(), cp2);
	vector<hp_t> hps;
	for (int i=0;i<(int)ps.size();i++){
		co t=ps[i];
		co nt=ps[(i+1)%(int)ps.size()];
		if (abs(ccw(t, nt))<eps){
			printf("0\n");
			return;
		}
		if (ccw(t, nt)>0){
			hps.push_back({t+x, nt+x});
		}
		else{
			hps.push_back({nt+x, t+x});
		}
	}
	int i2=0;
	for (int i=0;i<(int)ps.size();i++){
		int ct=0;
		while (i2==i||(ccw(ps[i], ps[i2])<eps)){
			if (i2!=i){
				if (abs(ccw(ps[i], ps[i2]))<eps){
					printf("0\n");
					return;
				}
			}
			i2++;
			i2=i2%(int)ps.size();
			ct++;
			if (ct>2*n){
				break;
			}
		}
		if (ct>2*n){
			i2=(i+2)%(int)ps.size();
			continue;
		}
		hps.push_back({ps[i]+x, ps[i2]+x});
		int e=(i2+(int)ps.size()-1)%(int)ps.size();
		if (e!=i){
			hps.push_back({ps[e]+x, ps[i]+x});
		}
	}
	auto it=getHPI(hps);
	ld A=0;
	for (int i=0;i<(int)it.size();i++){
		co t=it[i];
		co ne=it[(i+1)%(int)it.size()];
		A+=(t*conj(ne)).Y;
	}
	printf("%.18f\n", (double)(abs(A)/(ld)2));
}

int main(){
	int tcs;
	scanf("%d", &tcs);
	for (int tc=0;tc<tcs;tc++){
		solve();
	}
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,x[SZ],y[SZ];
vector<pii> A,B; pii g;
pii operator + (pii a,pii b)
{return pii(a.fi+b.fi,a.se+b.se);}
pii operator - (pii a,pii b)
{return pii(a.fi-b.fi,a.se-b.se);}
ll operator * (pii a,pii b)
{return a.fi*(ll)b.se-a.se*(ll)b.fi;}
ll len(pii x) {return x.fi*(ll)x.fi+x.se*(ll)x.se;}
bool cmp_g(pii a,pii b)
{
	if(a==g) return b!=g;
	if(b==g) return 0;
	long double aa=atan2l(a.se-g.se,a.fi-g.fi),
	bb=atan2l(b.se-g.se,b.fi-g.fi);
	if(fabsl(aa-bb)>1e-10)
	    return aa<bb;
	return len(a-g)<len(b-g);
}
ll cross(pii p0,pii p1,pii p2)
{return (p1-p0)*(p2-p0);}
vector<pii> graham(vector<pii> v)
{
	vector<pii> s; g=pii(2e9,2e9);
	for(auto r:v) g=min(g,r);
	sort(v.begin(),v.end(),cmp_g);
	v.erase(unique(v.begin(),v.end()),v.end());
	pii st[SZ]; int sn=0;
	for(auto x:v)
	{
		while(sn>=2&&(x-st[sn-1])*(st[sn]-st[sn-1])>=0)
			--sn;
		st[++sn]=x;
	}
	for(int i=1;i<=sn;++i)
		s.pb(st[i]);
	return s;
}
bool in(pii a,pii b,pii c,pii z)
{
	return abs(cross(a,b,c))
	==abs(cross(a,b,z))
	+abs(cross(b,c,z))
	+abs(cross(a,c,z));
}
#define WIN {puts("Ani"); return 0;}
bool chk(pii a,pii b,pii c)
{
	ll t=cross(a,b,c);
	if(t>0) return 0;
	if(t==0)
		return min(a.fi,c.fi)<=b.fi
		&&b.fi<=max(a.fi,c.fi)
		&&min(a.se,c.se)<=b.se
		&&b.se<=max(a.se,c.se);
	return 1;
}
int nr(vector<pii>& v,pii p)
{
	int n=v.size();
	if(n==1)
	{
		if(p!=v[0]) return -1;
		return 0;
	}
	if(n==2)
	{
		if(min(v[0].fi,v[1].fi)<=p.fi
		&&p.fi<=max(v[0].fi,v[1].fi)
		&&min(v[0].se,v[1].se)<=p.se
		&&p.se<=max(v[0].se,v[1].se)
		&&(p-v[0])*(v[1]-v[0])==0)
			return 0;
		return -1;
	}
//	cerr<<"QAQ"<<cross(v[0],p,v[1])<<"ww\n";
	if(!chk(v[0],p,v[1])) return -1;
	if(!chk(v[n-1],p,v[0])) return -1;
//	cross(v[0],p,v[1])>0) return -1;
//	if(cross(v[0],p,v[n-1])<0) return -1;
//	cerr<<"++\n";
	int i=2,j=n-1,g=n-1;
	while(i<=j)
	{
		int m=(i+j)>>1;
		if(cross(v[0],p,v[m])>0)
			g=m,j=m-1;
		else i=j+1;
	}
//	cerr<<"--\n";
	if(!chk(v[g-1],p,v[g])) return -1;
	return g;
}
int main()
{
	scanf("%d",&n);
	bool z=0;
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",x+i,y+i);
		z|=x[i]==0&&y[i]==0;
		if((x[i]%2==1)||(y[i]%2==1))
			B.pb(pii(x[i],y[i]));
		else A.pb(pii(x[i],y[i]));
	}
	if(!B.size())
	{
		puts("Borna");
		return 0;
	}
	if(!z) A.pb(pii(0,0));
	vector<pii> G=graham(A);
	int gn=G.size();
	if(G.size()<=1) WIN
//	for(auto t:G)
//		cerr<<t.fi<<','<<t.se<<" ";cerr<<"\n";
//	cerr<<"??\n";
	static vector<pii> eA[SZ],eB[SZ];
	set<pii> sG;
	for(auto t:G) sG.insert(t);
	for(auto t:A) if(!sG.count(t))
	{
		int g=nr(G,t);
		if(g==-1) throw "GG";
		set<int> tc;
		for(int j=-30;j<=30;++j)
			tc.insert(((g+j)%gn+gn)%gn);
		for(int j=-30;j<=30;++j)
			tc.insert(((0+j)%gn+gn)%gn);
		int ww=-1;
		for(auto w:tc)
			if(in(G[w],G[(w+1)%gn],G[(w+2)%gn],t))
				ww=w;
		if(ww==-1) continue;
		int www=ww;
		set<int> sc;
		sc.insert(ww);
		while(1)
		{
			ww=(ww+1)%gn;
			if(sc.count(ww)) break;
			if(!in(G[ww],G[(ww+1)%gn],G[(ww+2)%gn],t))
				break;
			sc.insert(ww);
		}
		ww=www;
		while(1)
		{
			ww=(ww+gn-1)%gn;
			if(sc.count(ww)) break;
			if(!in(G[ww],G[(ww+1)%gn],G[(ww+2)%gn],t))
				break;
			sc.insert(ww);
		}
		if(sc.size()>=4) throw "GG";
		for(auto w:sc)
			eA[w].pb(t);
	}
	for(auto t:B)
	{
		int g=nr(G,t);
//		cerr<<t.fi<<','<<t.se<<"??\n";
		if(g==-1) WIN
		set<int> tc;
		for(int j=-30;j<=30;++j)
			tc.insert(((g+j)%gn+gn)%gn);
		for(int j=-30;j<=30;++j)
			tc.insert(((0+j)%gn+gn)%gn);
		int ww=-1;
		for(auto w:tc)
			if(in(G[w],G[(w+1)%gn],G[(w+2)%gn],t))
				ww=w;
		if(ww==-1) continue;
		int www=ww;
		set<int> sc;
		sc.insert(ww);
		while(1)
		{
			ww=(ww+1)%gn;
			if(sc.count(ww)) break;
			if(!in(G[ww],G[(ww+1)%gn],G[(ww+2)%gn],t))
				break;
			sc.insert(ww);
		}
		ww=www;
		while(1)
		{
			ww=(ww+gn-1)%gn;
			if(sc.count(ww)) break;
			if(!in(G[ww],G[(ww+1)%gn],G[(ww+2)%gn],t))
				break;
			sc.insert(ww);
		}
		if(sc.size()>=4) throw "GG";
		for(auto w:sc)
			eB[w].pb(t);
	}
//	cerr<<"++\n";
	for(int i=0;i<gn;++i) if(G[(i+1)%gn]!=pii(0,0))
	{
//		cout<<G[i].fi<<","<<G[i].se<<"\n";
//		cout<<G[(i+1)%gn].fi<<","<<G[(i+1)%gn].se<<"\n";
//		cout<<G[(i+2)%gn].fi<<","<<G[(i+2)%gn].se<<"\n";
		vector<pii> v;
		v.pb(G[i]); v.pb(G[(i+2)%gn]);
		for(auto t:eA[i]) v.pb(t);
		v=graham(v);
//		cerr<<v.size()<<"??\n";
		for(auto h:eB[i])
		{
//			cerr<<h.fi<<","<<h.se<<"\n";
			if(nr(v,h)==-1) WIN
		}
	}
	puts("Borna");
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
using namespace std;
int main()
{
    int k,a[100][100],i,j,s[1000],z,m,n,h;
    while(cin>>k)
    {
        for(i=1;i<k;i++)
        {
            for(j=1;j<k;j++)
            {
                a[i][j]=i*j;
            }
        }

        for(i=1;i<k;i++)
        {
            for(j=1;j<k;j++)
            {
                z=a[i][j];
                m=0;
                if(j!=1)
                cout<<" ";
                while(z>k)
                {
                    n=z%k;

                    s[m++]=n;
                    z=z/k;

                }

                s[m++]=z;
                for(h=m-1;h>=0;h--)
                cout<<s[h];
                //printf("%d",s[h]);
                memset(s,0,sizeof(h));

            }
            cout<<endl;
        }
    }
    return 0;
}


#include<cstdio>
int n;
int main(){
    while(scanf("%d",&n)==1)printf("%d\n",int(double(x)/2.0+0.5));
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

double dp[51][5001];

bool check (int *f, int *s, double *p, int n, int r, double K){

  for(int i = n - 1; i >= 0; i--) {
    //cout << endl;
    for(int j = 0; j <= r; j++) {
      if(j + f[i] <= r) {
        dp[i][j] = p[i]*(f[i] + dp[i + 1][j + f[i]]);
        if(j + s[i] <= r)
          dp[i][j] += (1 - p[i])*(s[i] + dp[i + 1][j + s[i]]);
        else
          dp[i][j] += (1 - p[i])*(s[i] + K);
      } else {
        dp[i][j] = K;
      }
      dp[i][j] = min(dp[i][j], K);
    }
  }

  //cout << endl;
  if(K <= dp[0][0])
    return true;
  else
    return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int n, r, *f, *s;
  double *p;
  cin >> n >> r;
  for(int j = 0; j <= r; j++) {
    dp[n][j] = 0;
  }
  f = new int[n]; s = new int [n];
  p = new double [n];

  for(int i = 0; i < n; i++) {
    cin >> f[i] >> s[i] >> p[i];
    p[i] /= 100;
  }

  double left = 0, right = 1e8;
  int count = 0;
  while(abs(left - right) / max(1, left) >= 1e-9) {
    count++;
    if(check(f, s, p, n, r, (left + right ) / 2.0)) {
      left = (left + right) / 2;
    } else {
      right = (left + right) / 2;
    }
  }

  cout << fixed << setprecision(10) << left << endl;
  return 0;
}


#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>

#define MAXX 3000111

long long l,r,z;
int i,j,k,ans;
short p;
std::vector<short>prm;
std::vector<int>to;
short dp[MAXX];
bool done[MAXX];

void dfs(long long now,char cnt)
{
    to.push_back(now);
    for(;cnt<prm.size() && now*prm[cnt]<=r;++cnt)
        dfs(now*prm[cnt],cnt);
}

int main()
{
    prm.reserve(29);
    to.reserve(MAXX);
    scanf("%I64d %I64d %hd",&l,&r,&p);
    for(i=2;i<p;++i)
    {
        for(j=2;j*j<=i;++j)
            if(i%j==0)
                break;
        if(j*j>i)
            prm.push_back(i);
    }
    dfs(1,0);
    std::sort(to.begin(),to.end());
    memset(dp,0x3f,sizeof(dp));
    dp[0]=0;
    for(i=2;i<p;++i)
        for(j=0,k=1;j<to.size();++j)
        {
            for(z=((long long)to[j])*i;k<to.size() && to[k]<z;++k);
            if(to[k]==z && dp[k]>dp[j]+1)
            {
                dp[k]=dp[j]+1;
                if(i+dp[k]<=p)
                    done[k]=true;
            }
        }
    r=std::min(r,to.back());
    for(i=std::lower_bound(to.begin(),to.end(),l)-to.begin();to[i]<=r;++i)
        if(done[i])
            ++ans;
    printf("%d\n",ans);
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
const int inf=1000000002,N=200100;
#define mp make_pair
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<(int)n;i++)
int a[N],r[N],sa[N],h[N],ans[N],L[N],R[N],_l[N],_r[N],C[N],n,t,cnt,Q;
pair<pii,int> c[N];vector<pii> q[N];vector<int> q1[N],q2[N];set<pii> p;
void deal(int i,int w,int *a) {
	for (typeof(p.end()) it=p.upper_bound(mp(h[i]+1,-1));it!=p.end();p.erase(it++)) a[it->second]=i+w;}
int A(int x){int s=0;for(;x;x-=x&-x)s+=C[x];return s;}
void M(int x){for(;x<=t;x+=x&-x)C[x]++;}
int main() {
	scanf("%d",&n);
	rep(i,n) scanf("%d",&a[i]);
	rep(i,n-1) a[i]=a[i+1]-a[i],a[i+n]=-a[i];a[n-1]=-inf+1;a[(t=n+n)-1]=-inf+2;
	rep(i,t) r[i]=a[i]+=inf;
	for (int d=1;d<t;d+=d) {
		rep(i,t) c[i]=mp(mp(r[i],r[i+d]),i);sort(c,c+t);cnt=r[c[0].second]=0;
		rep(i,t-1) r[c[i+1].second]=(cnt+=(c[i].first!=c[i+1].first));
		if (cnt==t) break;
	}
	rep(i,t) sa[r[i]]=i;
	for (int k=0,i=0,j;i<t;h[r[i++]]=k,k=max(k-1,0)) if (r[i]!=0)for (j=sa[r[i]-1];a[j+k]==a[i+k];k++);
	h[t]=-1;
	scanf("%d",&Q);rep(i,Q) scanf("%d%d",L+i,R+i),--L[i],--R[i],q[r[L[i]+n]].push_back(mp(R[i]-L[i],i));
	rep(i,t+1) {deal(i,-1,_r);rep(j,q[i].size())p.insert(q[i][j]);}
	for (int i=t-1;i>=0;i--) {rep(j,q[i].size())p.insert(q[i][j]);deal(i,0,_l);}
	rep(i,Q) q1[_l[i]].push_back(i),q2[_r[i]].push_back(i),L[i]=max(2*L[i]-R[i],0);
	rep(i,t) {
		rep(j,q1[i].size()) {int d=q1[i][j];ans[d]-=A(n)-A(R[d]+1)+A(L[d]);}
		M(sa[i]+1);
		rep(j,q2[i].size()) {int d=q2[i][j];ans[d]+=A(n)-A(R[d]+1)+A(L[d]);}
	}
	rep(i,Q) printf("%d\n",ans[i]);
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#pragma GCC optimize(2)
#pragma GCC optimize(3)

using namespace std;

template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x > y ? y : x;}

typedef long long ll;

const int INF = 0x3f3f3f3f;

#define DEBUG(x) std::cerr << #x << " = " << x << std::endl

template <typename T> void read (T &x) {
	x = 0; bool f = 1; char ch;w
	do {ch = getchar(); if (ch == '-') f = 0;} while (ch > '9' || ch < '0');
	do {x = x * 10 + ch - '0'; ch = getchar();} while (ch >= '0' && ch <= '9');
	x = f ? x : -x;
}

template <typename T> void write (T x) {
	if (x < 0) x = ~x + 1, putchar ('-');
	if (x > 9) write (x / 10);
	putchar (x % 10 + '0');
}

const int N = 4e5 + 7;

int n, m, e, E, rt, mxsz, tot, sz[N], tmpH[N], head[N];
ll ans[N];
bool vis[N];

struct EDGE {
	int a, b, to, nxt;
} tmpE[N << 1], edge[N << 1];

struct Point {
	ll x, y;
	Point(ll X = 0, ll Y = 0) {
		x = X; y = Y;
	}
	friend Point operator + (Point a, Point b) {
		return Point(a.x + b.x, a.y + b.y);
	}
	friend Point operator - (Point a, Point b) {
		return Point(a.x - b.x, a.y - b.y);
	}
	friend bool operator <= (Point a, Point b) {
		return a.y * b.x <= a.x * b.y;
	}
} stk[N*10], A[N], B[N], All[N*10];
 inline bool cmp(Point a, Point b) {
	return a.x < b.x || (a.x == b.x && a.y > b.y);
}

struct Hull {
	Point *s; int T;
	inline void clear() {
		T = 0;
	}
	inline void push(Point a) {
		s[++T] = a;
	}
	inline void build() {
		sort(s + 1, s + T + 1, cmp);
		int top = 0;
		for(int i = 1; i <= T; i++) {
			if(i > 1 && s[i].x == s[i - 1].x) continue;
			while(top > 1 && (stk[top] - stk[top - 1]) <= (s[i] - stk[top - 1])) top -- ;
			stk[++top] = s[i];
		}
		for(int i = 1; i <= top; i++) s[i] = stk[i];
		T = top;
	}
	inline void merge(Hull a, Hull b) {
		int i = 1, j = 1; push(a.s[1] + b.s[1]);
		while(i < a.T || j < b.T) {
			if(i < a.T && (b.s[j + 1] - b.s[j]) <= (a.s[i + 1] - a.s[i])) i ++ ;
			else if(j < b.T && (a.s[i + 1] - a.s[i]) <= (b.s[j + 1] - b.s[j])) j ++ ;
			push(a.s[i] + b.s[j]);
		}
	}
	inline void query() {
		int o = 1;
		for(int i = 0; i < m; i++) {
			while(o < T && i * s[o + 1].x + s[o + 1].y >= i * s[o].x + s[o].y) o ++ ;
			ans[i] = i * s[o].x + s[o].y;
		}
	}
} a, b, all;

inline void Addedge(int u, int v, int a, int b) {
	tmpE[++e].to = v;
	tmpE[e].nxt = tmpH[u];
	tmpE[e].a = a;
	tmpE[e].b = b;
	tmpH[u] = e;
}

inline void addedge(int u, int v, int a, int b) {
	edge[++E].to = v;
	edge[E].nxt = head[u];
	edge[E].a = a;
	edge[E].b = b;
	head[u] = E;
}

inline void rebuild(int u, int f) {
	int ff = 0;
	for(int i = tmpH[u]; i; i = tmpE[i].nxt) {
		int v = tmpE[i].to, a = tmpE[i].a, b = tmpE[i].b;
		if(v == f) continue;
		if(!ff) {
			addedge(u, v, a, b);
			addedge(v, u, a, b);
			ff = u;
		} else {
			int tmp = ++tot;
			addedge(ff, tmp, 0, 0); addedge(tmp, ff, 0, 0);
			addedge(tmp, v, a, b); addedge(v, tmp, a, b);
			ff = tmp;
		}
		rebuild(v, u);
	}
}

inline void findroot(int u, int fa, int sum) {
	sz[u] = 1;
	for(int i = head[u]; i; i = edge[i].nxt) {
		int v = edge[i].to;
		if(v == fa || vis[i >> 1]) continue;
		findroot(v, u, sum); sz[u] += sz[v];
		int tmp = min(sz[v], sum - sz[v]);
		if(tmp > mxsz) mxsz = tmp, rt = i;
	}
}

inline void getdis(int u, int f, Hull &H, ll A, ll B) {
	if(u <= n) H.push(Point(A, B));
	for(int i = head[u]; i; i = edge[i].nxt) {
		int v = edge[i].to, aa = edge[i].a, bb = edge[i].b;
		if(v == f || vis[i >> 1]) continue;
		getdis(v, u, H, A + aa, B + bb);
	}
}

inline void divide(int u, int sum) {
	mxsz = -INF; rt = 0; findroot(u, 0, sum);
	if(mxsz == -INF) return;
	vis[rt >> 1] = true; a.clear(); b.clear();
	getdis(edge[rt].to, 0, a, edge[rt].a, edge[rt].b);
	getdis(edge[rt ^ 1].to, 0, b, 0, 0);
	a.push((Point)(0, 0)); b.push((Point)(0, 0));
	a.build(); b.build(); all.merge(a, b);
	int now = rt, size = sum - sz[edge[now].to];
	divide(edge[now].to, sz[edge[now].to]);
	divide(edge[now ^ 1].to, size);
}

int main() {
	all.s = All; a.s = A; b.s = B;
	read(n); read(m); tot = n; E = 1;
	for(int i = 1, u, v, a, b; i < n; i++) {
		read(u); read(v); read(a); read(b);
		Addedge(u, v, a, b);
		Addedge(v, u, a, b);
	}
	rebuild(1, 0); divide(1, tot);
	all.build(); all.query();
	for(int i = 0; i < m; i++) printf("%lld ", ans[i]);
	return 0;
}


#include "library.h"
using namespace std;

int n,m;
int tt[61][61][61];
int agg[61][61];
int inv[150];
const int mod = 1000000007;

void solve()
{
    for (int i = 1; i <= 140; i++) inv[i] = modInv(i, mod);

    re(n,m);

    for (int ops = 0; ops <= n; ops++) {
        int mc = ops;
        tt[ops][0][0] = 1;
        for (int cutl = 0; cutl < ops; cutl++) {
            int cut = cutl+1;

            for (int toto = cutl*2; toto <= ops-1; toto++) {
                long long poss = 0;
                for (int left = cutl; left <= toto-cutl; left++) {
                    if (!tt[left][cutl][left]) break;
                    int right = toto-left;
                    long long right_poss = (2ll * agg[right][cutl+1] + tt[right][cutl][right]) % mod;
                    long long bposs = (tt[left][cutl][left] * right_poss) % mod;
                    poss = (bposs+poss)%mod;
                }

                for (int po = ops-toto-1; po >= 0; po--) {
                    for (int pc = mc-cut; pc >= 0; pc--) {
                        int lim = min( (mc-pc)/cut, (ops-po)/(toto+1) );

                        int comb = (poss * 1ll * tt[ops][pc][po]) % mod;

                        for (int hm = 1; hm <= lim; hm++) {
                            int& dest = tt[ops][pc + cut*hm][po + (toto+1)*hm];
                            dest = (dest + comb) % mod;

                            comb = (comb * 1ll * (poss+hm)) % mod;
                            comb = (comb * 1ll * inv[hm+1]) % mod;
                        }
                    }
                }
            }
        }

        for (int cut = ops; cut >= 0; cut--) {
            agg[ops][cut] = (tt[ops][cut][ops] + agg[ops][cut+1]) % mod;
        }
    }

    ps(tt[n][m-1][n]);
}


#include<cstdio>
#include<cmath>
#include<stdlib.h>
#include<map>
#include<set>
#include<time.h>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define eps 1e-8
#define SIZE 100005
long long mod=1e9+7;
int phi[SIZE];
void geteular()
{
    int i, j;
    memset(phi, 0, sizeof(phi));
    phi[1] = 1;
    for(int i = 2; i < SIZE; i++)
    {
        if(!phi[i])
        {
            for(j = i; j < SIZE; j+=i)
            {
                if(!phi[j]) phi[j] = j;
                phi[j] = phi[j] / i * (i-1);
            }
        }
    }
}
//扩展欧几里得
//ax+by=d;
//x'=x+b/d;
//y'=y-a/d;
//a,b要求非负!
long long d,x,y;
long long exgcd(long long a,long long b,long long &x,long long &y)
{
    if(b==0)
    {
        x=1;
        y=0;
        return a;
    }
    else
    {
        long long ret=exgcd(b,a%b,x,y);
        long long temp=x;
        x=y;
        y=temp-a/b*y;
        return ret;
    }
}
long long inv(long long n,long long mod)
{
    d=exgcd(n,mod,x,y);
    x=(x%mod+mod)%mod;
    if(d==1)
        return x;
    return -1;//无逆元
}
long long ck[SIZE];
int num[SIZE];
int n,k,q;
void init()
{
    geteular();
    long long fz=1;
    long long fm=1;
    ck[k]=1;
    for(int i=k+1;i<=100000;i++)
    {
        fz=fz*i%mod;
        fm=fm*(i-k)%mod;
        ck[i]=fz*inv(fm,mod)%mod;
    }
}
int main()
{
    scanf("%d%d%d",&n,&k,&q);
    init();
    for(int i=0;i<n;i++)
    {
        int a;
        scanf("%d",&a);
        for(int j=1;j*j<=a;j++)
        {
            if(a%j==0)
            {
                num[j]++;
                if(j*j==a)
                    ;
                else
                    num[a/j]++;
            }
        }
    }
    long long ans=0;
    for(int i=1;i<=100000;i++)
    {
        ans=ans+ck[num[i]]*phi[i];
        ans%=mod;
    }
//    printf("%d\n",ans);
//    for(int i=1;i<=20;i++)
//        printf("%d ",num[i]);
//    printf("\n");
    for(int i=0;i<q;i++)
    {
        int a;
        scanf("%d",&a);
        for(int j=1;j*j<=a;j++)
        {
            if(a%j==0)
            {
                ans=ans-ck[num[j]]*phi[j];
                num[j]++;
                ans=ans+ck[num[j]]*phi[j];
                if(j*j==a)
                    ;
                else
                {
                    ans=ans-ck[num[a/j]]*phi[a/j];
                    num[a/j]++;
                    ans=ans+ck[num[a/j]]*phi[a/j];
                }
            }
            ans=ans%mod;
        }
        ans=ans%mod;
        printf("%I64d\n",(ans+mod)%mod);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 5005
int n,m,k,dp[N][N]={{1}};
const int mod=998244353;
int pown(int a,int b){
	int res=1,x=a%mod;
	while(b)res=b&1?res*x%mod:res,x=x*x%mod,b>>=1;
	return res;
}
signed main(){
	scanf("%lld%lld%lld",&n,&m,&k);
    for(int i=1;i<=k;i++)
        for(int j=1;j<=i;j++)
            dp[i][j]=(dp[i-1][j]*j+dp[i-1][j-1]*(n-j+1))%mod;
    int ans=0,cur=1,p=pown(m,mod-2);
    for(int i=0;i<=k;i++)
        ans=(ans+dp[k][i]*cur)%mod,cur=cur*p%mod;
    printf("%lld",ans);
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#define max 5002
#define md 1000000007
char str1[max];
char str2[max];
using namespace std;

int lcs(){
    int x,y,i,j,ans=0;
    x=strlen(str1);
    y=strlen(str2);
    int c[x+1][y+1];
    for(i=0;i<=x;i++)
    c[i][0]=0;
    for(i=0;i<=y;i++)
    c[0][i]=0;
    for(i=1;i<=x;i++){
        for(j=1;j<=y;j++){
            if(str1[i-1]==str2[j-1])
                c[i][j]=c[i-1][j-1]+1 + c[i-1][j];
            else
                c[i][j]=c[i-1][j];
        }
    }
    for(i=1;i<=y;i++) ans=(ans+c[x][i])%md;
    return ans;
}

int main(){
    int x,y,c;
    gets(str2);
    gets(str1);
    x=strlen(str1);
    y=strlen(str2);
    c=lcs();
    cout<<c<<endl;
    //cin>>x;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<set>
using namespace std;

string a,b;
int n;
int next[1000010];

void change()
{
  for(int i=0;i<n-1;i++)
  {
    if(b[i] == 'W') b[i] = 'E';
    else if(b[i] == 'S') b[i] = 'N';
    else if(b[i] == 'N') b[i] = 'S';
    else if(b[i] == 'E') b[i] = 'W';
  }
  reverse(b.begin(),b.end());
  return;
}

void NEXT()
{
  for(int i=1;i<n-1;i++)
  {
    int j=i;
    while(j>0)
    {
      j=next[j];
      if(b[j]==b[i])
      {
        next[i+1]=j+1;
        break;
      }
    }
  }
  return;
}

void kmp()
{
  int j=0;
  for(int i=0;i<n-1;i++)
  {
    while(j && b[j+1]!=a[i])
      j=next[j];
    if(b[j+1]==a[i])
      j++;
  }
  if(j == 0) printf("YES\n");
  else printf("NO\n");
}

int main()
{
  scanf("%d",&n);
  cin>>a>>b;
  change();
  NEXT();
  kmp();
}


#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <fstream>
#include <map>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#pragma comment(linker,"/STACK:268435456")

int m[60][60];
int w[60][60];
int a[60],i,j,k,n;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin>>n;
    for (i=0;i<n;i++)
    {
        cin>>a[i];
        m[0][i] = a[i];
    }
    for (i=0;i<n;i++)
    {
        for (j=0;j<i;j++)
            w[i][j] = 999999;

        for (j=i;j<n;j++)
            cin>>w[i][j];

        for (j=n;j<60;j++)
            w[i][j] = 999999;
    }
    w[n][n-1] = 0;
    for (k=0;k<300000;k++)
    {

        memset(m,0,sizeof(m));

        for (i=0;i<n;i++)
        {
            m[0][i] = a[i];
        }

        for (i=0;i<n;i++)
        {
            for (j=i;j<n;j++)
            {
                if (m[i][j]>=w[i][j])
                {
                    if (k==0)
                    {
                        if ((j>i && m[i+1][j]+m[i][j]>=w[i+1][j]) || j==n-1)
                            m[i+1][j] += m[i][j];
                        else
                            m[i+1][j+1] += m[i][j];
                    }
                    else
                    {
                        if ((rand()%2==0 && j>i) || j==n-1)
                            m[i+1][j] += m[i][j];
                        else
                            m[i+1][j+1] += m[i][j];
                    }
                }
            }
        }
        if (m[n][n-1]>0 || m[n][n-2]>0 || m[n][n]>0)
        {
            cout<<"Cerealguy";
            return 0;
        }
        /*
        for (i=0;i<n;i++)
        {
            for (j=i;j<n;j++)
            {
                cout<<m[i][j]<<" ";
            }
            cout<<endl;
        }
        */
    }
    if (m[n][n-1]>0 || m[n][n-2]>0 || m[n][n]>0)
        cout<<"Cerealguy";
    else
        cout<<"Fat Rat";

    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<stdlib.h>
#include<ctime>
#include<string>
#include<cmath>
#include<algorithm>
#include<complex>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LL long long
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef pair<int,int> pa;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
LL f[30][300010],ans,fac[300010],inv[300010];
int n,k,MO,s,a[55],S[1000010];
LL pw(LL x,int y){
	LL t=1;
	for (;y;y>>=1){
		if (y&1) t=t*x%MO;
		x=x*x%MO;
	}
	return t;
}
int main(){
	scanf("%d%d%d",&n,&k,&MO);
	if (n%2==0) return cout<<pw(k,n)<<endl;
	fac[0]=1;
	FOR(i,1,n) fac[i]=fac[i-1]*i%MO;
	inv[n]=pw(fac[n],MO-2);
	FORD(i,n-1,0) inv[i]=inv[i+1]*(i+1)%MO;
	int t=n;
	FOR(i,0,20){
		if (t&1) a[++s]=1<<i;
		t>>=1;
	}
	f[0][(1<<s)-1]=1;
	FOR(i,0,(1<<s)-1)
		FOR(j,0,s-1)
			if ((i>>j)&1) S[i]+=a[j+1];
	FOR(i,0,k-1)
		FOR(j,0,(1<<s)-1)
			if (f[i][j]){
				for (int k=j;k>=0;k=(k==0)?-1:(k-1)&j){
					(f[i+1][j^k]+=f[i][j]*inv[S[k]])%=MO;
				}
			}
	ans=(pw(k,n)-f[k][0]*fac[n])%MO;
	cout<<(ans+MO)%MO<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define NN 300100
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
using INT = long long;
using pii = pair<int, int>;

int p[NN];
INT dp[NN][2];
int vst[NN];
vector<int> ans;
int N;
int val, flag = 1;
void calc(int n){
	if(dp[n][0] == val){
		if(n > 2 && min(dp[n - 2][1], dp[n - 2][1]) == val - max(p[n], p[n - 1])){
			if(!vst[n - 1]) {
				int V = min(p[n - 1], p[n]);
				if(V) ans.push_back(n - 1);
				vst[n - 1] = 1;
				val -= V;
				if(!val) return ;
				p[n - 1] -= V; p[n] -= V;
			}
			if(n != N) {
				if(!vst[n]) {
					int V = min(p[n + 1], p[n]);
					if(V) ans.push_back(n);
					vst[n] = 1;
					val -= V;
					if(!val) return ;
					p[n + 1] -= V; p[n] -= V;
				}
			}
			if(!vst[n - 2]){
				int V = min(p[n - 2], p[n - 1]);
				if(V) ans.push_back(n - 2);
				vst[n - 2] = 1;
				val -= V;
				p[n - 2] -= V; p[n - 1] -= V;
			}
			return ;
		}
		if(n > 1) {
			if(!vst[n - 1]) {
				int V = min(p[n - 1], p[n]);
				if(V) ans.push_back(n - 1);
				vst[n - 1] = 1;
				val -= V;
				if(!val) return ;
				p[n - 1] -= V; p[n] -= V;
			}
		}
		if(n != N) {
			if(!vst[n]){
				int V = min(p[n + 1], p[n]);
				if(V)ans.push_back(n);
				vst[n] = 1;
				val -= V;
				p[n + 1] -= V; p[n] -= V;
			}
		}
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	ios_base :: sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> p[i];
	for(int i = 1; i <= n; i++) for(int j = 0; j < 2; j++) dp[i][j] = inf;
	dp[1][0] = p[1], dp[1][1] = 0;
	for(int i = 2; i <= n; i++){
		dp[i][0] = min(dp[i - 1][1], dp[i - 1][0]) + p[i];
		if(i >= 2) dp[i][0] = min(dp[i][0], min(dp[i - 2][0], dp[i - 2][1]) + max(p[i], p[i - 1]));
		dp[i][1] = dp[i - 1][0];
	}
	val = min(dp[n][1], dp[n][0]);
//	for(int i = 1; i <= n; i++) cout << dp[i][0]<<" "<<dp[i][1]<<endl;
	N = n;
	while(val) {
//		cout << val << " "<< n<<endl;
		calc(n);
		n -= flag;
		flag = 1;
	}
	cout << ans.size() <<endl;
	for(int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
	cout << endl;
	return 0;
}


#include <iostream>
#define int long long int
using namespace std;

const int maxN = 5e4 + 226;

int N, _time[maxN][7], ct, covered, arr[maxN], narr[maxN], currentMinus[maxN];

signed main(){
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> arr[i];
	}
	if(N % 7 == 0){
		int ans = 0;
		for(int i = 0; i < N; i++){
			if((i % 7) == 6) continue;
			if((arr[i] -  1) * (N) + i < (arr[ans] - 1) * (N) + i) ans = i;
		}
		cout << ans + 1 << endl;
		return 0;
	}
	for(int t = 0; t < 7 * N; t++){
		if(t % 7 == 6) continue;
		currentMinus[t % N]++;
		_time[t % N][currentMinus[t % N]] = t;
		cout << "_time[" << t % N << "][" << currentMinus[t % N] << "] = " << t << endl;
	}
	for(int i = 0; i < N; i++) _time[i][0] = +i - N;
	int ans = 0;
	int ti, ta;
	for(int i = 0; i < N; i++){
		//cout << "arr[" << i << "] = " << arr[i] << endl;
		//cout << "time[" << i << "][" << arr[i] % 6 << "] = " << _time[i][arr[i] % 6] << endl;
		//cout << "Time for " << i << ": " << arr[i] / 6 * (7 * N) + _time[i][arr[i] % 6] << endl;
		ti = arr[i] / 6 * (7 * N) + _time[i][arr[i] % 6];
		if(arr[i] % 6 == 0) ti = (arr[i] - 6) / 6 * (7 * N) + _time[i][6];

		ta = arr[ans] / 6 * (7 * N) + _time[i][arr[_ans] % 6];
		if(arr[ans] % 6 == 0) ta = (arr[ans] - 6) / 6 * (7 * N) + _time[ans][6];

		if(ti < ta) ans = i;
	}
	cout << ans + 1 << endl;
}


#define filesfl 0
#define consolefl 01
#define fname "sufpref"
//evgenstf - batya

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <cassert>
#include <stdint.h>

#include <cmath>
#include <algorithm>

#include <set>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <queue>
#include <stack>
#include <bitset>

#define forn(i, n) for (ll i = 0; i < n; ++ i)
#define fornn(i, q, n) for (ll i = q; i < n; ++ i)
#define rforn(i, n) for (ll i = n; i >= 0; i --)
#define rfornn(i, m, n) for (ll i = m; i >= n; i --)

#define endl "\n"
#define inb push_back
#define outb pop_back
#define X first
#define Y second
#define Z third
#define mk make_pair
#define _i "%d"
#define _ll "%I64d"
#define pii pair<ll, ll>
#define times clock() * 1.0 / CLOCKS_PER_SEC
#define all(v) v.begin(), v.end()

#define nsc(n) scanf("%d", &n)
#define nmsc(n, m) scanf("%d%d", &n, &m)

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

const ll inf = 1e9 + 5;
const ll linf = 5e18 + 5;
const ld eps = 1e-9;

const ll dd = 2e5 + 7;
const ll maxn = 2e3 + 10;

const ll mod = 1e9 + 7;

using namespace std;

int a[dd];
int qwe[dd];
int used[dd];
int timer = 1;

int main() {
	ios_base::sync_with_stdio(0);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	if (filesfl) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	else {
		if (!consolefl) {
			freopen(fname".in", "r", stdin);
			freopen(fname".out", "w", stdout);
		}
	}
#endif
	int n, m;
	cin >> n >> m;
	forn(i, n)
		cin >> a[i];
	sort(a, a + n);
	vector<pair<int, int> > qwe;
	forn(j, m){
		int b, t;
		cin >> b >> t;
		qwe.inb(mk(b - t, b + t));
	}
	sort(qwe.begin(), qwe.end());
	int l = 0;
	int r = 0;
	set<pair<int, int> > asd, asd1;
	int cnt = 0;
	forn(i, n){
		while (r < qwe.size() && qwe[r].X <= a[i]){
			asd.insert(mk(qwe[r].Y, qwe[r].X));
			asd1.insert(mk(qwe[r].X, qwe[r].Y));
			r ++;
		}
		vector<pair<int, int> > bad;
		for (auto ind = asd.begin(); ind != asd.end(); ind ++){
			if (ind -> X < a[i])
				bad.inb(*ind);
		}
		forn(j, bad.size())
			asd.erase(bad[j]);

		if (asd.size()){
			auto qq = asd.begin();
			asd.erase(qq), cnt ++;
		}
	}
	cout << cnt;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<vector>
#include<list>
using namespace std;
const int nmax=111000;
long long a,b;
int k;
int chia_het;
int f[nmax];
int dem=0;
long long ans;
int giam_a(){
    long long a_old=a;
    int value=0;
    for (int cs=2;cs<=k;cs++){
        int subtract= a_old%cs;
        if (subtract>value && (a-subtract>=b)) value=subtract;
    }
    if (value==0) value=1;
    a-=value;
    dem++;
    f[dem]=value;
    return 0;
}
int chu_ky;
bool   ton_tai_chu_ky(){
    // dinh nghia su ton tai chu chu ky la mot do dai >=20 den 39 duoc lap lai it nhat 3 lan
    if (dem<20*3) return false;
    for (chu_ky=20;chu_ky<=300;){
            bool check_chu_ky=true;
            if (dem<3*chu_ky) break;
            for (int cs=0;cs<chu_ky;cs++){
                if ((f[dem-cs]!=f[dem-cs-chu_ky])||(f[dem-cs]!=f[dem-cs-chu_ky-chu_ky])) {
                    check_chu_ky=false;
                    break;
                }
            }
            if (check_chu_ky) return true;
            chu_ky++;
    }
    return false;
}
long long tinh_tong_chu_ky(){
    long long value=0LL;
    for (int cs=0;cs<chu_ky;cs++) value+=(long long)f[dem-cs];
    return value;
}
int solve(){
    long long tong_chu_ky=tinh_tong_chu_ky();
    long long so_lan= (a-b)/tong_chu_ky;
    so_lan--;
    if (so_lan<0) so_lan=0LL;
    ans+=so_lan*((long long) chu_ky);
    a-=so_lan* tong_chu_ky;
    while (a>b){
        giam_a();
        ans++;
    }
    return 0;
}
int main() {
    cin>>a>>b>>k;
    ans=0LL;
    while (a>b){
        giam_a();
        ans++;
        //cout<<ans<<" ||"<<a<<endl;
        if (ton_tai_chu_ky()) break;
    }
    if (a>b){
        solve();
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
using lint = long long;
using pi = pair<int, int>;

int n;
struct rect{
	int sx, ex, sy, ey, idx;
}a[MAXN];

auto cmp1 = [](const rect &a, const rect &b){
	if(a.sx != b.sx) return a.sx < b.sx;
	if(a.ex != b.ex) return a.ex < b.ex;
	return a.idx < b.idx;
};

auto cmp2 = [](const rect &a, const rect &b){
	if(a.ex != b.ex) return a.ex < b.ex;
	if(a.sx != b.sx) return a.sx < b.sx;
	return a.idx < b.idx;
};

auto cmp3 = [](const rect &a, const rect &b){
	if(a.sy != b.sy) return a.sy < b.sy;
	if(a.ey != b.ey) return a.ey < b.ey;
	return a.idx < b.idx;
};

auto cmp4 = [](const rect &a, const rect &b){
	if(a.ey != b.ey) return a.ey < b.ey;
	if(a.sy != b.sy) return a.sy < b.sy;
	return a.idx < b.idx;
};

bool dfs(
set<rect, decltype(cmp1)> &s0,
set<rect, decltype(cmp2)> &s1,
set<rect, decltype(cmp3)> &s2,
set<rect, decltype(cmp4)> &s3
){
	if(s0.size() == 1) return true;
	auto itr0 = s0.begin(); int arg0 = -1e9;
	auto itr1 = s1.begin(); int arg1 = 2e9;
	auto itr2 = s2.begin(); int arg2 = -1e9;
	auto itr3 = s3.begin(); int arg3 = 2e9;
	for(int i = 0; i + 1 < s0.size(); i++){
		arg0 = max(arg0, itr0->ex);
		arg1 = min(arg1, itr1->sx);
		arg2 = max(arg2, itr2->ey);
		arg3 = min(arg3, itr3->sy);
		itr0++; itr1++; itr2++; itr3++;
		vector<rect> split;
		if(arg0 <= itr0->sx){
			itr0 = s0.begin();
			for(int j = 0; j <= i; j++) split.push_back(*itr0++);
		}
		else if(arg1 >= itr1->ex){
			itr1 = s1.begin();
			for(int j = 0; j <= i; j++) split.push_back(*itr1++);
		}
		else if(arg2 <= itr2->sy){
			itr2 = s2.begin();
			for(int j = 0; j <= i; j++) split.push_back(*itr2++);
		}
		else if(arg3 >= itr3->ey){
			itr3 = s3.begin();
			for(int j = 0; j <= i; j++) split.push_back(*itr3++);
		}
		if(split.size()){
			set<rect, decltype(cmp1)> ss0(cmp1);
			set<rect, decltype(cmp2)> ss1(cmp2);
			set<rect, decltype(cmp3)> ss2(cmp3);
			set<rect, decltype(cmp4)> ss3(cmp4);
			for(auto &i : split){
				ss0.insert(i); ss1.insert(i); ss2.insert(i); ss3.insert(i);
				s0.erase(i); s1.erase(i); s2.erase(i); s3.erase(i);
			}
			return dfs(s0, s1, s2, s3) && dfs(ss0, ss1, ss2, ss3);
		}
	}
	return false;
}

int main(){
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		a[i].idx = i;
		scanf("%d %d %d %d",&a[i].sx,&a[i].sy,&a[i].ex,&a[i].ey);
	}
	set<rect, decltype(cmp1)> s1(cmp1);
	set<rect, decltype(cmp2)> s2(cmp2);
	set<rect, decltype(cmp3)> s3(cmp3);
	set<rect, decltype(cmp4)> s4(cmp4);
	for(int i=0; i<n; i++){
		s1.insert(a[i]);
		s2.insert(a[i]);
		s3.insert(a[i]);
		s4.insert(a[i]);
	}
	puts(dfs(s1, s2, s3, s4) ? "YES" : "NO");
}


#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	#define sz 233
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(register int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cout<<(clock()-t)/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

const int m=50;

struct Mat
{
	db a[m+m+3][m+m+3];
	Mat(){memset(a,0,sizeof(a));}
	const Mat operator * (const Mat &x) const
	{
		Mat ret;
		rep(i,1,m+m) rep(k,1,m+m) rep(j,1,m+m) ret.a[i][j]+=a[i][k]*x.a[k][j];
		return ret;
	}
};

Mat ksm(Mat x,int y)
{
	Mat ret; rep(i,1,m+m) ret.a[i][i]=1;
	for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;
	return ret;
}

int n;db p;
db P[sz],pp[sz];

void work(db *F,db *G,int n)
{
	static db f[sz][50],g[sz][50];
	memset(f,0,sizeof(f)),memset(g,0,sizeof(g));
	rep(i,1,min(m,n+1)) f[1][i]=F[i],g[1][i]=G[i];
	rep(i,2,n) rep(j,1,min(n-i+2,m))
	{
		rep(k,j+1,m)
		{
			db w=(j==n-i+2?pp[j]:P[j]);
			if (i==n) w=(j==1?p:1-p);
			f[i][j]+=f[i-1][k]*w;
			g[i][j]+=w*(g[i-1][k]+f[i-1][k]*j);
		}
		db w;
		if (j==2) w=1-p;
		else if (j==1) w=0;
		else if (j!=n-i+2) w=pp[j];
		else w=pp[j-1]*pp[j-1];
		f[i][j]+=f[i-1][1]*w;
		g[i][j]+=w*(g[i-1][1]+f[i-1][1]*j);
	}
	db ans=0;
	rep(i,1,m) ans+=g[n][i];
	printf("%.5lf\n",ans);
}

db tmp1[sz],tmp2[sz],tmp3[sz],tmp4[sz],f[sz],g[sz];
Mat x,y;

int main()
{
	file();
	read(n,p),p/=1e9;
	if (n==1) return printf("%.5lf\n",p+2*(1-p)),0;
	P[1]=p,P[2]=1-p+p*p; rep(i,3,m) P[i]=P[i-1]*P[i-1];
	pp[2]=1-p; rep(i,3,m) { pp[i]=pp[2]; rep(j,2,i-1) pp[i]*=P[j]; }
	rep(i,1,min(m,n)) tmp1[i]=P[i],tmp2[i]=P[i]*i; if (n+1<=m) tmp1[n+1]=pp[n+1],tmp2[n+1]=pp[n+1]*(n+1);
	if (n<=200) return work(tmp1,tmp2,n),0;
	rep(i,1,m) tmp3[i]=tmp1[i]; rep(i,1,m) tmp3[i+m]=tmp2[i];
	rep(j,1,m)
	{
		rep(k,j+1,m)
		{
			db w=P[j];
			x.a[k][j]=w;
			x.a[k][j+m]=j*w;
			x.a[k+m][j+m]=w;
//			f[i][j]+=f[i-1][k]*w;
//			g[i][j]+=w*(g[i-1][k]+f[i-1][k]*j);
		}
		db w=pp[j];
		x.a[1][j]=w;
		x.a[1][j+m]=j*w;
		x.a[1+m][j+m]=w;
//		f[i][j]+=f[i-1][1]*w;
//		g[i][j]+=w*(g[i-1][1]+f[i-1][1]*j);
	}
	y=ksm(x,n-150);
	rep(k,1,m+m) rep(j,1,m+m) tmp4[j]+=tmp3[k]*y.a[k][j];
	rep(i,1,m) f[i]=tmp4[i],g[i]=tmp4[i+m];
	work(f,g,150);
	return 0;
}


#pragma GCC optimize("O3")
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <iostream>
#include <iterator>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <ctime>
#include <cstring>
#include <stack>
#include <ctime>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

//#include <ext/pb_ds/assoc_container.hpp>

#define fi first
#define se second
#define th third

#define en "\n"
#define sqrt(n) sqrt((long double) n)
#define all(c) (c).begin() , (c).end()
#define MOD 1000000007
#define mem0(a) memset(a,0,sizeof(a))
#define FAST() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define elif else if
#define int long long
#define SORT(x) sort(all(x))
#define REVERSE(x) reverse(all(x))

using namespace std;

template<class A, class B, class C> struct Triple { A first; B second; C third;
    bool operator<(const Triple& t) const { if (fi != t.fi) return fi < fi.st; if (se != t.se) return se < t.se; return th < t.th; } };

int gcd(int a,int b){
    while (a && b)
        if (a>b) a=a%b; else b=b%a;
    return a+b;
}

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef set<int> seti;
typedef long double ld;
typedef pair<ld, ld> pdd;
typedef Triple<int, int, int> TIII;

const double EPS=0.000000001;
const double INFD32=1000000000;
const ll INF64=1000000000000000000;
const int INF32=1000000000;

#define maxN 5010

int md=998244353;

int arr[maxN],cnt[maxN];

int ver[maxN][maxN];

int A[maxN];

int bp(int x,int p){
    int res=1;
    while (p) {
        if (p%2) res*=x;
      //  res%=md;
        x*=x;
        //x%=md;
        p/=2;
    }
    return res;
}

int F[maxN][maxN];

int f(int x,int y){
    if (x>y) return 0;
    int res=x;
    res*=A[y];
    //res%=md;
    return res;
}

int suf_sum[maxN];

int pref[maxN];

signed main(void){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for (int i=1; i<=n; ++i) A[i]=bp(i,md-2);
    for (int i=0; i<maxN; ++i)
        for (int j=i; j<maxN; ++j)
            F[i][j]=f(i,j);
    for (int i=1; i<=n; ++i){
        cin>>arr[i];
        cnt[arr[i]]++;
    }
    for (int i=1; i<=n; ++i)
        pref[i]=pref[i-1]+cnt[i];
    for (int i=1; i<=n; ++i){
        ver[1][i]=f(cnt[i],n);
    }
    int ans=0;
    for (int k=2; k<=n; ++k){
        for (int i=1; i<=n; ++i)
            suf_sum[i]=(suf_sum[i-1]+ver[k-1][i]);
        for (int i=n; i>0; --i){
            if (cnt[i]>1)
                ans+=F[cnt[i]-1][n-k+1]*ver[k-1][i];
            //ans%=md;
            ver[k][i]=suf_sum[i-1]*F[cnt[i]][n-k+1];
        }
    }
    cout<<ans<<en;
    return 0;
}


#include<iostream>
#include<cstring>
#include<map>
#include<assert.h>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
const ll mod2=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

VI pos[10];
int cnt;
ll pw[15],s[15];
ll cnt2,n;
int ans;
int query(int fixpre,ll val) {
	ll ans=0;
	rep(d,0,7) {
		ll offset=(val-fixpre*pw[d])%mod2;
		if (offset<0) offset+=mod2;
		int p=lower_bound(all(pos[d]),mod2-offset)-pos[d].begin();
		ans=(ans+s[d]+offset*SZ(pos[d])-mod2*(SZ(pos[d])-p))%mod;
	}
	return ans;
}

void dfs(int val,int d) {
	int x=(cnt-val+mod2)%mod2;
	pos[d].pb(x); cnt++;
	s[d]+=x;
	if (d==6) return;
	rep(i,0,10) dfs(val*10+i,d+1);
}

void dfs2(ll val) {
	if (val*1000000+999999<=n&&val*10000000>n) {
		ans=(ans+query(val,cnt2+1))%mod;
		cnt2+=cnt;
	} else {
		cnt2++;
		ans=(ans+((cnt2-val)%mod2+mod2)%mod2)%mod;
		rep(i,val?0:1,10) {
			if (val*10+i<=n) dfs2(val*10+i);
		}
	}
}

int main() {
	dfs(0,0);
	rep(i,0,7) sort(all(pos[i]));
	pw[0]=1;
	rep(i,1,13) pw[i]=pw[i-1]*10;
	scanf("%lld",&n);
	cnt2=-1;
	dfs2(0);
	printf("%d\n",ans);
}


#include<bits/stdc++.h>
#define P 1000000007
#define ll long long
#define N 5005
using namespace std;
int n,a,b,s[N],sz[N],C[N][N],Ans;char c[N];
int to[N*N],fr[N*N],nxt[N*N],fst[N],l;
int st[N],top,bl[N],cnt,dfn[N],low[N],clk;
vector<int>p[N],v[N],e[N];
struct T
{
	int x,y;
}d[N];
int cmp(T a,T b)
{
	return a.x<b.x;
}

void link(int x,int y)
{
	to[++l]=y;fr[l]=x;nxt[l]=fst[x];fst[x]=l;
}
void dfs(int x)
{
	low[x]=dfn[x]=++clk;
	st[++top]=x;
	for (int i=fst[x];i;i=nxt[i])
		if (!dfn[to[i]])
		{
			dfs(to[i]);
			low[i]=min(low[i],low[to[i]]);
		}
		else if (!bl[to[i]])
			low[i]=min(low[i],low[to[i]]);
	if (low[x]==dfn[x])
	{
		cnt++;
		while(st[top]!=x)
		{
			p[cnt].push_back(st[top]);
			bl[st[top--]]=cnt;
		}
		p[cnt].push_back(st[top]);
		bl[st[top--]]=cnt;
	}
}
int _to[N*N],_nxt[N*N],_fst[N],_l,rd[N];
void lk(int x,int y)
{
	_to[++_l]=y;_nxt[_l]=_fst[x];_fst[x]=_l;rd[y]++;
}
void work(int x)
{
	rd[x]=-1;
	for (int i=_fst[x];i;i=_nxt[i])
	{
		rd[_to[i]]--;
		if (rd[_to[i]]==0)
		{
			int tmp=__gcd(sz[x],sz[_to[i]]);
			vector<int>tp;tp.clear();
			for (int j=0;j<tmp;j++)tp.push_back(0);
			for (int j=0;j<sz[x];j++)
				if (e[x][j]) tp[j%tmp]=1;
			for (int j=0;j<sz[_to[i]];j++)
				if (tp[j%tmp]) e[_to[i]][j]=1;
			work(_to[i]);
		}
	}
}
int bit[1000005];
void add(int x)
{
	x++;
	for (;x<=1000000;x+=x&-x)
		bit[x]++;
}
int qry(int x)
{
	x++;
	int ans=0;
	for (;x;x-=x&-x)
		ans+=bit[x];
	return ans;
}
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for (int i=1;i<=n;i++)
	{
		scanf("%s",c+1);
		for (int j=1;j<=n;j++)
		{
			if (c[j]=='1')
				link(i,j);
		}
	}
	for (int i=1;i<=n;i++)
		if (!dfn[i])
			dfs(i);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&s[i]);
		sz[bl[i]]=__gcd(sz[bl[i]],s[i]);
		scanf("%s",c+1);
		for (int j=1;j<=s[i];j++)
		{
			v[i].push_back(c[j]=='1');
			d[i].x+=c[j]=='1';
		}
	}
	for (int i=1;i<=cnt;i++)
	{
		for (int j=0;j<sz[i];j++)
			e[i].push_back(0);
		for (int j=0;j<p[i].size();j++)
		{
			for (int k=0;k<v[p[i][j]].size();k++)
			if (v[p[i][j]][k])
				e[i][k%sz[i]]=1;
		}
	}
	for (int i=1;i<=l;i++)
	{
		if (bl[fr[i]]!=bl[to[i]])
			lk(bl[fr[i]],bl[to[i]]);
	}
	for (int i=1;i<=cnt;i++)
		if (rd[i]==0) work(i);

	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<s[i];j++)
			if (v[i][j]||e[bl[i]][j%sz[bl[i]]]) d[i].y++;
	}
	sort(d+1,d+n+1,cmp);
	C[0][0]=1;
	for (int i=1;i<=n;i++)
	{
		C[i][0]=1;
		for (int j=1;j<=i;j++)
		{
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%P;
		}
	}
	/*
	for (int i=1;i<=n;i++)
	{
		printf("%d %d\n",d[i].x,d[i].y);
	}
	*/
	for (int i=1;i<=n;i++)
	{
		//cout<<i<<endl;
		if (i>=b)
		{
			if (i<=a)Ans+=C[i-1][b-1];
			else
			{
				int u=qry(d[i].y),v=i-1-u;
				//cout<<u<<' '<<v<<endl;
				for (int j=0;j<=u&&j<b;j++)
				{
					if (v+j+1<=a)
						Ans=(Ans+(ll)C[u][j]*C[v][b-j-1])%P;
				}
			}
		}
		add(d[i].x);
	//printf("%d\n",Ans);
	}
	printf("%d\n",Ans);
}


#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
using namespace std;
const int inf=0x7fffffff;
const double eps=1e-10;
const double pi=acos(-1.0);
//char buf[1<<15],*S=buf,*T=buf;
//char getch(){return S==T&&(T=(S=buf)+fread(buf,1,1<<15,stdin),S==T)?0:*S++;}
inline int read(){
	int x=0,f=1;char ch;ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}
	if(f)return x;else return -x;
}
const int N=2e6+10;
const int mod=1e9+7;
int n,a[N];
int cnt[N],mx[N];
int ans=1;
bool used[N];
int prime[N],val[N];
void Lin_Sie(){
	used[1]=1;
	for(int i=2;i<N;i++){
		if(!used[i])prime[++prime[0]]=i,val[i]=i;
		for(int j=0;j<=prime[0]&&1ll*i*prime[j]<N;j++){
			used[i*prime[j]]=1;
			val[i*prime[j]]=prime[j];
			if(i%prime[j]==0)break;
		}
	}
}
int main()
{
	n=read();Lin_Sie();
	for(int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+n+1);
 	for(int i=n;i>=1;i--){
 		if(!cnt[a[i]])cnt[a[i]]++,mx[a[i]]=1,ans=(1ll*ans*a[i])%mod;
 		else{
 	    int v=--a[i];
 	    while(v!=1){
    		int u=val[v],ls=0;
    		while(v%u==0)v/=u,ls++;
    		if(cnt[u]<ls){
    			for(int j=cnt[u]+1;j<=ls;j++)ans=(1ll*ans*u)%mod;
    			cnt[u]=ls;mx[u]=1;
				}
				else if(cnt[u]==ls)mx[u]++;
 			}
 		}
 	}
	for(int i=1;i<=n;i++){
		int v=a[i],flag=0;
		while(v!=1){
			int u=val[v],ls=0;
			while(v%u==0)v/=u,ls++;
			if(cnt[u]==ls&&mx[u]==1)flag=1;
		}
		if(!flag){ans++;break;}
	}
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	for(int i=21;i<=50;i++)
		cout<<((min(k,25)+k)mod(2+k%3) > 0)? 1: 0<<endl;
	return 0;
}