#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
int n;
int ta[N + 7];
int tb[N + 7];
long long m;
int mod = 1e9 + 7;
const long long MM = 1e9;
const int M = 12e6 + 7;
int dpo[M];
int dp[M];
int kp;
int len = 0;
char s[10007];
int T[2007];
void wczytaj() {
  cin >> s;
  int l = 0;
  while (s[l]) l++;
  len = 1 + ((l - 1) / 9);
  for (int i = 0; s[i]; ++i) {
    T[(l - 1 - i) / 9] *= 10;
    T[(l - 1 - i) / 9] += s[i] - '0';
  }
}
int dziel(int x) {
  long long r = 0;
  for (int i = len - 1; i >= 0; --i) {
    int wyn = (MM * r + T[i]) / x;
    r = (MM * r + T[i]) % x;
    T[i] = wyn;
  }
  while (len > 1 && T[len - 1] == 0) len--;
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  ta[1] = 1;
  for (int i = 2; i <= n; ++i) cin >> ta[i];
  for (int i = 1; i <= n; ++i) cin >> tb[i];
  wczytaj();
  dp[0] = 1;
  kp = 0;
  for (int i = 1; i <= n; ++i) {
    int prz = 0;
    if (ta[i] != 1) prz = dziel(ta[i]);
    int nkp = -1;
    for (int j = 0; ta[i] * j + prz <= kp; ++j) {
      dpo[j] = dp[ta[i] * j + prz];
      nkp = j;
    }
    if (nkp == -1) {
      cout << 0 << endl;
      return 0;
    }
    kp = nkp;
    for (int j = 1; j <= tb[i]; ++j) dpo[kp + j] = 0;
    kp += tb[i];
    for (int j = 1; j <= kp; ++j) dpo[j] = (dpo[j] + dpo[j - 1]) % mod;
    for (int j = 0; j <= kp; ++j) {
      dp[j] = dpo[j];
      if (j >= tb[i] + 1) dp[j] += mod - dpo[j - tb[i] - 1];
      dp[j] %= mod;
    }
  }
  if (len == 1 && T[0] <= kp)
    cout << dp[T[0]] << endl;
  else
    cout << 0 << endl;
  return 0;
}
