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;
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;
}