#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return {i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const int N = 3e5 + 7;
int n;
int rat[N];
int ile[N];
int tab[N];
const int M = 12e6 + 7;
char s[10017];
int m[2007];
const int mod = 1e9 + 7;
int dpo[M];
int dpn[M];
void fail() {
  printf("0\n");
  exit(0);
}
void dziel() {
  int len = strlen(s);
  int poz = 0;
  const int K = 9;
  for (int i = len - 1; i >= K; i -= K) {
    int war = 0;
    for (int j = K - 1; j >= 0; --j) {
      war *= 10;
      war += s[i - j] - '0';
    }
    m[poz++] = war;
  }
  int pot = 1;
  for (int i = 0; i < K; ++i) pot *= 10;
  for (int i = 1; i <= n; ++i) {
    if (rat[i] != 1) {
      long long rr = 0;
      for (int j = poz - 1; j >= 0; --j) {
        rr *= pot;
        int nv = (rr + m[j]) / rat[i];
        rr = (rr + m[j]) % rat[i];
        m[j] = nv;
      }
      tab[i - 1] = rr;
      while (poz > 0 && m[poz - 1] == 0) poz--;
      if (poz == 0) break;
    }
  }
  if (poz > 1) fail();
  tab[n] = m[0];
}
int main() {
  scanf("%d", &n);
  rat[1] = 1;
  for (int i = 2; i <= n; ++i) scanf("%d", rat + i);
  for (int i = 1; i <= n; ++i) scanf("%d", ile + i);
  for (int i = 0; i <= 10; ++i) s[i] = '0';
  scanf("%s", s + 10);
  dziel();
  debug() << range(tab + 1, tab + n + 1);
  int ogr = 0;
  dpo[0] = 1;
  for (int i = 0; i < n; ++i) {
    int nogr = -1;
    for (int k = tab[i]; k <= ogr; k += rat[i + 1]) {
      int l = (k - tab[i]) / rat[i + 1];
      nogr = l;
      dpn[l] = dpo[k];
    }
    if (nogr == -1) fail();
    nogr += ile[i + 1];
    long long sum = 0;
    for (int j = 0; j <= nogr; ++j) {
      sum += dpn[j];
      if (j >= ile[i + 1] + 1) sum += mod - dpn[j - ile[i + 1] - 1];
      sum %= mod;
      dpo[j] = sum;
    }
    for (int j = 0; j <= nogr; ++j) dpn[j] = 0;
    ogr = nogr;
  }
  if (tab[n] > ogr) fail();
  printf("%d\n", dpo[tab[n]]);
  return 0;
}
