#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 300000;
const int MAXEQ = 20;
const int MAXHAVESUM = 300000;
const int MAXLEN = 10000;
const int MOD = 1000000007;
const int BASE = 1000000000;
const int BASELG10 = 9;
typedef struct C {
  int l, r, sum, rat, need;
} C;
int n;
int rat[MAXN];
int have[MAXN];
char s[MAXLEN + 1];
int slen;
int need[(MAXLEN + BASELG10 - 1) / BASELG10], needlen;
C c[MAXN];
int nc;
int dp[MAXHAVESUM + 1], dpmx;
int dpsum[MAXHAVESUM + 2];
int dv(int by) {
  long long rem = 0;
  for (int i = needlen - 1; i >= 0; --i) {
    rem = rem * BASE + need[i];
    need[i] = rem / by;
    rem %= by;
  }
  while (needlen > 0 && need[needlen - 1] == 0) --needlen;
  return rem;
}
int solve() {
  {
    needlen = 1;
    need[0] = 0;
    int t = 1;
    for (int i = (0); i < (slen); ++i) {
      if (t == BASE) need[needlen++] = 0, t = 1;
      need[needlen - 1] += t * (s[slen - i - 1] - '0');
      t *= 10;
    }
  }
  nc = 1;
  c[0].l = c[0].r = 0, c[0].sum = have[0], c[0].rat = 0;
  for (int i = (1); i < (n); ++i) {
    if (rat[i] == 1) {
      c[nc - 1].r = i, c[nc - 1].sum += have[i];
      continue;
    }
    c[nc].l = c[nc].r = i, c[nc].sum = have[i], c[nc].rat = rat[i], ++nc;
  }
  for (int i = (0); i < (nc - 1); ++i) c[i].need = dv(c[i + 1].rat);
  if (needlen > 1)
    return 0;
  else
    c[nc - 1].need = needlen == 0 ? 0 : need[0];
  dpmx = 0;
  dp[0] = 1;
  for (int i = (0); i < (nc); ++i) {
    for (int j = (c[i].l); j <= (c[i].r); ++j) {
      for (int k = (0); k < (have[j]); ++k) dp[++dpmx] = 0;
      dpsum[0] = 0;
      for (int k = (0); k <= (dpmx); ++k)
        if ((dpsum[k + 1] = dpsum[k] + dp[k]) >= MOD) dpsum[k + 1] -= MOD;
      for (int k = dpmx; k >= 0; --k)
        if ((dp[k] = dpsum[k + 1] - dpsum[max(0, k - have[j])]) < 0)
          dp[k] += MOD;
    }
    if (dpmx < c[i].need) return 0;
    if (i + 1 < nc) {
      dpmx = (dpmx - c[i].need) / c[i + 1].rat;
      for (int k = (0); k <= (dpmx); ++k)
        dp[k] = dp[c[i].need + k * c[i + 1].rat];
    }
  }
  return dp[c[nc - 1].need];
}
void run() {
  scanf("%d", &n);
  rat[0] = 0;
  for (int i = (1); i < (n); ++i) scanf("%d", &rat[i]);
  for (int i = (0); i < (n); ++i) scanf("%d", &have[i]);
  scanf("%s", s);
  slen = strlen(s);
  printf("%d\n", solve());
}
int main() {
  run();
  return 0;
}
