Problem: There are n types of coins in Byteland. Conveniently, the denomination of the coin type k divides the denomination of the coin type k + 1, the denomination of the coin type 1 equals 1 tugrick. The ratio of the denominations of coin types k + 1 and k equals ak. It is known that for each x there are at most 20 coin types of denomination x.

Byteasar has bk coins of type k with him, and he needs to pay exactly m tugricks. It is known that Byteasar never has more than 3·105 coins with him. Byteasar want to know how many ways there are to pay exactly m tugricks. Two ways are different if there is an integer k such that the amount of coins of type k differs in these two ways. As all Byteland citizens, Byteasar wants to know the number of ways modulo 109 + 7.

Input

The first line contains single integer n (1 ≤ n ≤ 3·105) — the number of coin types.

The second line contains n - 1 integers a1, a2, ..., an - 1 (1 ≤ ak ≤ 109) — the ratios between the coin types denominations. It is guaranteed that for each x there are at most 20 coin types of denomination x.

The third line contains n non-negative integers b1, b2, ..., bn — the number of coins of each type Byteasar has. It is guaranteed that the sum of these integers doesn't exceed 3·105.

The fourth line contains single integer m (0 ≤ m < 1010000) — the amount in tugricks Byteasar needs to pay.

Output

Print single integer — the number of ways to pay exactly m tugricks modulo 109 + 7.

Examples

Input

1

4
2


Output

1


Input

2
1
4 4
2


Output

3


Input

3
3 3
10 10 10
17


Output

6

Note

In the first example Byteasar has 4 coins of denomination 1, and he has to pay 2 tugricks. There is only one way.

In the second example Byteasar has 4 coins of each of two different types of denomination 1, he has to pay 2 tugricks. There are 3 ways: pay one coin of the first type and one coin of the other, pay two coins of the first type, and pay two coins of the second type.

In the third example the denominations are equal to 1, 3, 9.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
void getre() {
  int x = 0;
  printf("%d\n", 1 / x);
}
void gettle() {
  int res = 1;
  while (1) res <<= 1;
  printf("%d\n", res);
}
template <typename T, typename S>
inline bool upmin(T &a, const S &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename S>
inline bool upmax(T &a, const S &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename N, typename PN>
inline N flo(N a, PN b) {
  return a >= 0 ? a / b : -((-a - 1) / b) - 1;
}
template <typename N, typename PN>
inline N cei(N a, PN b) {
  return a > 0 ? (a - 1) / b + 1 : -(-a / b);
}
template <typename N>
N gcd(N a, N b) {
  return b ? gcd(b, a % b) : a;
}
template <typename N>
inline int sgn(N a) {
  return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
inline void gn(long long &x) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, x = 0) : (x = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= sg;
}
inline void gn(int &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(unsigned long long &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gn(long double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gs(char *s) { scanf("%s", s); }
inline void gc(char &c) {
  while ((c = getchar()) > 126 || c < 33)
    ;
}
inline void pc(char c) { putchar(c); }
inline long long sqr(long long a) { return a * a; }
inline double sqrf(double a) { return a * a; }
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979323846264338327950288L;
const double eps = 1e-6;
const int mo = 1e9 + 7;
int qp(int a, long long b) {
  int n = 1;
  do {
    if (b & 1) n = 1ll * n * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return n;
}
class Bignum {
 private:
  vector<int> a;
  void clear() {
    a.resize(1);
    a[0] = 0;
  }
  void set(int n) {
    if (clear(), n) {
      int t;
      a.clear();
      while (n) a.push_back(n - (t = n / 10000) * 10000), n = t;
    }
  }
  void set(long long n) {
    if (clear(), n) {
      long long t;
      a.clear();
      while (n) a.push_back(n - (t = n / 10000) * 10000), n = t;
    }
  }
  void clearzero() {
    int l = a.size();
    while (l > 1 && a[l - 1] == 0) l--;
    a.resize(l);
  }
  void set(char *st) {
    char c;
    vector<int> s;
    a.clear();
    while (((c = *(st++)) < '0' || c > '9'))
      ;
    s.push_back(c - '0');
    while ((c = *(st++)) >= '0' && c <= '9') s.push_back(c - '0');
    int l = s.size();
    for (int i = l - 1; i - 3 >= 0; i -= 4)
      a.push_back(s[i] + s[i - 1] * 10 + s[i - 2] * 100 + s[i - 3] * 1000);
    if (l & 3) {
      int tmp = 0;
      for (int i = 0; i < (l & 3); i++) tmp = tmp * 10 + s[i];
      a.push_back(tmp);
    }
    clearzero();
  }

 public:
  Bignum() { clear(); }
  Bignum(int n) { set(n); }
  Bignum(long long n) { set(n); }
  Bignum(char *s) { set(s); }
  Bignum &operator=(int a) {
    set(a);
    return *this;
  }
  Bignum &operator=(long long a) {
    set(a);
    return *this;
  }
  Bignum &operator=(char *s) {
    set(s);
    return *this;
  }
  int size() const {
    if (a.back() >= 1000)
      return a.size() << 2;
    else if (a.back() >= 100)
      return (a.size() << 2) - 1;
    else if (a.back() >= 10)
      return (a.size() << 2) - 2;
    else
      return (a.size() << 2) - 3;
  }
  long long toint() const {
    long long ans = 0;
    for (int i = int(a.size()) - 1; i >= 0; i--) ans = ans * 10000 + a[i];
    return ans;
  }
  int tostr(char *s) const {
    int tot = 0;
    for (unsigned int i = 0; i < a.size(); i++)
      if (i + 1 == a.size()) {
        int x = a[i];
        while (x) s[tot++] = '0' + x % 10, x /= 10;
      } else {
        int x = a[i];
        for (int j = 0; j < 4; j++) s[tot++] = '0' + x % 10, x /= 10;
      }
    if (tot == 0) s[tot++] = '0';
    for (int i = 0, j = tot - 1; i < j; i++, j--) swap(s[i], s[j]);
    s[tot] = 0;
    return tot;
  }
  int toarr(int *s) const {
    int tot = 0;
    for (unsigned int i = 0; i < a.size(); i++)
      if (i + 1 == a.size()) {
        int x = a[i];
        while (x) s[tot++] = x % 10, x /= 10;
      } else {
        int x = a[i];
        for (int j = 0; j < 4; j++) s[tot++] = x % 10, x /= 10;
      }
    if (tot == 0) s[tot++] = 0;
    return tot;
  }
  int comp(const Bignum &x) const {
    if (a.size() < x.a.size()) return 1;
    if (a.size() > x.a.size()) return -1;
    for (int i = a.size() - 1; i >= 0; i--)
      if (a[i] < x.a[i])
        return 1;
      else if (a[i] > x.a[i])
        return -1;
    return 0;
  }
  bool operator<(const Bignum &x) const { return comp(x) == 1; }
  bool operator>(const Bignum &x) const { return comp(x) == -1; }
  bool operator<=(const Bignum &x) const { return comp(x) != -1; }
  bool operator>=(const Bignum &x) const { return comp(x) != 1; }
  bool operator!=(const Bignum &x) const { return comp(x) != 0; }
  bool operator==(const Bignum &x) const { return comp(x) == 0; }
  Bignum &operator+=(const Bignum &x) {
    int l = max(a.size(), x.a.size()) + 1;
    a.resize(l);
    for (unsigned int i = 0; i < x.a.size(); i++) a[i] += x.a[i];
    for (int i = 0; i < l; i++)
      if (a[i] >= 10000) a[i] -= 10000, a[i + 1]++;
    clearzero();
    return *this;
  }
  Bignum &operator-=(const Bignum &x) {
    for (unsigned int i = 0; i < x.a.size(); i++) a[i] -= x.a[i];
    for (unsigned int i = 0; i < a.size(); i++)
      if (a[i] < 0) a[i] += 10000, a[i + 1]--;
    clearzero();
    return *this;
  }
  Bignum operator+(const Bignum &x) const {
    Bignum y = *this;
    y += x;
    return y;
  }
  Bignum operator-(const Bignum &x) const {
    Bignum y = *this;
    y -= x;
    return y;
  }
  Bignum operator*(const Bignum &x) const {
    int l = a.size() + x.a.size();
    Bignum z;
    z.a.clear();
    vector<long long> tmp;
    tmp.resize(l);
    for (unsigned int i = 0; i < x.a.size(); i++)
      for (unsigned int j = 0; j < a.size(); j++) tmp[i + j] += x.a[i] * a[j];
    for (int i = 0; i < l; i++) {
      long long t = tmp[i] / 10000;
      z.a.push_back(int(tmp[i] - t * 10000));
      t ? tmp[i + 1] += t : 0;
    }
    z.clearzero();
    return z;
  }
  Bignum operator*(long long x) const {
    if (x >= 10000) return *this * Bignum(x);
    int l = a.size() + 2;
    Bignum z;
    z.a.resize(l);
    for (unsigned int i = 0; i < a.size(); i++) z.a[i] = a[i] * x;
    for (int i = 0, t; i < l; i++)
      z.a[i + 1] += (t = z.a[i] / 10000), z.a[i] -= t * 10000;
    z.clearzero();
    return z;
  }
  friend Bignum operator*(long long x, const Bignum &a) { return a * x; }
  Bignum &operator*=(long long x) { return *this = *this * x; }
  Bignum &operator*=(const Bignum &x) { return *this = *this * x; }
  Bignum operator/(const Bignum &x) const {
    Bignum b = *this, q, tmp;
    q.a.resize(b.a.size());
    for (int i = int(b.a.size()) - int(x.a.size()); b >= x;
         i--, b.clearzero()) {
      tmp.a.assign(b.a.begin() + i, b.a.end());
      int l = 0, r = 10000 - 1, m;
      while (l <= r) {
        m = (l + r) >> 1;
        if (x * m <= tmp)
          l = m + 1;
        else
          r = m - 1;
      }
      for (unsigned int j = 0; j < tmp.a.size(); j++) b.a[j + i] = 0;
      q.a[i] = r;
      tmp -= x * r;
      for (unsigned int j = 0; j < tmp.a.size(); j++) b.a[j + i] = tmp.a[j];
    }
    q.clearzero();
    return q;
  }
  Bignum operator%(const Bignum &x) const { return *this - *this / x * x; }
  Bignum &operator/=(const Bignum &x) { return *this = *this / x; }
  Bignum &operator%=(const Bignum &x) { return *this = *this % x; }
  Bignum &operator/=(long long x) {
    if (x > (1ll << 40))
      return *this /= Bignum(x);
    else {
      if (x == 1) return *this;
      long long cur = 0;
      for (int i = int(a.size()) - 1; i >= 0; i--) {
        cur = cur * 10000 + a[i];
        a[i] = cur / x;
        cur %= x;
      }
      clearzero();
      return *this;
    }
  }
  Bignum operator/(long long x) const {
    if (x > (1ll << 40))
      return *this / Bignum(x);
    else {
      Bignum y = *this;
      y /= x;
      return y;
    }
  }
  long long operator%(long long x) const {
    if (x > (1ll << 40))
      return (*this % Bignum(x)).toint();
    else {
      if (x == 1) return 0;
      long long ans = 0;
      for (int i = int(a.size()) - 1; i >= 0; i--)
        ans = (ans * 10000 + a[i]) % x;
      return ans;
    }
  }
  int operator%(int x) const { return int(operator%((long long)x)); }
  Bignum &operator%=(long long x) {
    if (x > (1ll << 40))
      return *this %= Bignum(x);
    else
      return *this = *this % x;
  }
  int to2(int *s) const {
    int tot = 0;
    vector<unsigned long long> t;
    for (unsigned int i = 0; i < a.size(); i++)
      t.push_back((unsigned long long)a[i]);
    while (!t.empty()) {
      for (int i = int(t.size()) - 1; i >= 0; i--) {
        unsigned long long r = t[i] >> 32;
        if (i == 0) {
          s[tot++] = int(t[i] & 0xffffffff);
        } else {
          t[i - 1] += (t[i] & ((unsigned long long)0xffffffff)) * 10000;
        }
        t[i] = r;
      }
      while (!t.empty() && t.back() == 0) t.pop_back();
    }
    return tot;
  }
  bool input() {
    char c;
    vector<int> s;
    a.clear();
    while (((c = getchar()) < '0' || c > '9') && c != EOF)
      ;
    if (c == EOF) {
      a.push_back(0);
      return 0;
    }
    s.push_back(c - '0');
    while ((c = getchar()) >= '0' && c <= '9') s.push_back(c - '0');
    int l = s.size();
    for (int i = l - 1; i - 3 >= 0; i -= 4)
      a.push_back(s[i] + s[i - 1] * 10 + s[i - 2] * 100 + s[i - 3] * 1000);
    if (l & 3) {
      int tmp = 0;
      for (int i = 0; i < (l & 3); i++) tmp = tmp * 10 + s[i];
      a.push_back(tmp);
    }
    clearzero();
    return 1;
  }
  void output() const {
    for (int i = int(a.size()) - 1; i >= 0; i--)
      if (i == int(a.size()) - 1)
        printf("%d", a[i]);
      else
        printf("%04d", a[i]);
  }
  void outputln() const {
    output();
    putchar('\n');
  }
  friend Bignum max(const Bignum &a, const Bignum &b) { return a > b ? a : b; }
  friend Bignum min(const Bignum &a, const Bignum &b) { return a < b ? a : b; }
};
int n;
int a[333333];
int b[333333];
int r[333333];
int num[33333];
int len;
int dv(int m) {
  long long cur = 0;
  for (int i = len - 1; i >= 0; i--) {
    cur = cur * 10 + num[i];
    num[i] = cur / m;
    cur = cur % m;
  }
  while (len >= 1 && num[len - 1] == 0) len--;
  return cur;
}
int f[3333333];
int fne[3333333];
int tmpf[3333333];
void mulpo(int d) {
  for (int i = (len), _ed = (len + d); i < _ed; i++) f[i] = 0;
  for (int i = (1), _ed = (len + d); i < _ed; i++)
    (((f[i]) = ((f[i]) + (f[i - 1])) % mo) < 0 ? (f[i]) += mo : (f[i]));
  for (int i = len + d - 1; i >= 0; i--) {
    int su = f[i] - (i - d - 1 < 0 ? 0 : f[i - d - 1]);
    f[i] = su;
    (((f[i]) = ((f[i]) + (0)) % mo) < 0 ? (f[i]) += mo : (f[i]));
  }
  len += d;
}
Bignum rd;
int main() {
  gn(n);
  for (int i = (1), _ed = (n); i < _ed; i++) {
    gn(a[i]);
  }
  a[n] = 2e9;
  for (int i = (1), _ed = (n + 1); i < _ed; i++) {
    gn(b[i]);
  }
  rd.input();
  int cur = 1;
  int start = 1;
  for (int i = (1), _ed = (n + 1); i < _ed; i++) {
    cur *= a[i];
    if (i == n || 1ll * cur * a[i + 1] > 1e9) {
      int rr = rd % cur;
      rd /= cur;
      for (int j = (start), _ed = (i + 1); j < _ed; j++) {
        r[j] = rr % a[j];
        rr /= a[j];
      }
      cur = 1;
      start = i + 1;
    }
  }
  f[0] = 1;
  len = 1;
  for (int i = (1), _ed = (n + 1); i < _ed; i++)
    if (i == 1 || a[i - 1] != 1) {
      int j = i + 1;
      while (j <= n && a[j - 1] == 1) j++;
      j--;
      for (int k = (i), _ed = (j + 1); k < _ed; k++) mulpo(b[k]);
      int t, tt;
      for (t = r[j], tt = 0; t < len; t += a[j], tt++) {
        fne[tt] = f[t];
      }
      len = tt;
      for (int k = (0), _ed = (len); k < _ed; k++) f[k] = fne[k];
    }
  printf("%d\n", len >= 1 ? f[0] : 0);
  return 0;
}