#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while (((c = getchar()) == ' ') || c == '\n')
    ;
  x = c;
}
const int mod = 1e9 + 7;
string st;
int n, m, i, j, a[300005], b[300005], f[300005], g[300005];
int v[10005], lv;
int divi(int x) {
  int i;
  long long s = 0;
  for (i = lv; i >= 0; i--) {
    s = s * 100000000 + v[i];
    int z = s / x;
    s -= 1ll * z * x;
    v[i] = z;
  }
  while (lv > 0 && !v[lv]) lv--;
  return s;
}
int main() {
  ios_base::sync_with_stdio(false);
  ;
  cin >> n;
  for (((i)) = (1); ((i)) <= ((n - 1)); ((i))++) cin >> a[i];
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) cin >> b[i];
  cin >> st;
  reverse((st).begin(), (st).end());
  while (st.size() % 8 != 0) st.push_back('0');
  for (((i)) = (0); ((i)) <= (((int)(st.size() / 8)) - 1); ((i))++) {
    for (j = 7; j >= 0; j--) v[i] = v[i] * 10 + (st[i * 8 + j] - '0');
  }
  lv = st.size() / 8 - 1;
  f[0] = 1;
  int len = 0;
  for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
    for (((j)) = (1); ((j)) <= ((len)); ((j))++) f[j] = (f[j] + f[j - 1]) % mod;
    int c;
    if (i < n) {
      if (a[i] != 1)
        c = divi(a[i]);
      else
        c = 0;
      for (j = 0; j * a[i] + c - b[i] <= len; j++) {
        int l = max(0, j * a[i] + c - b[i]);
        int r = min(len, j * a[i] + c);
        if (l <= r) {
          g[j] = (f[r] + mod - (l == 0 ? 0 : f[l - 1])) % mod;
        } else
          g[j] = 0;
      }
      if (len + b[i] - c < 0) {
        puts("0");
        return 0;
      }
      len = (len + b[i] - c) / a[i];
      memcpy(f, g, sizeof(f[0]) * (len + 1));
    } else {
      c = 0;
      if (lv > 0) {
        puts("0");
        return 0;
      }
      c = v[0];
      int l = max(0, c - b[i]);
      int r = min(len, c);
      if (l > r)
        puts("0");
      else {
        printf("%d\n", (f[r] + mod - (l == 0 ? 0 : f[l - 1])) % mod);
      }
    }
  }
  return 0;
}
