while (readline()) {
  let weight = readline().split(" ").map(Number);
  let num = readline().split(" ").map(Number);
  let res = new Set([0]);// 用数组会超时
  for (let i = 0; i < weight.length; i++) {
    let tmp = [...res]
    for (let j = 1; j <= num[i]; j++) {
      tmp.forEach((item) => {
        res.add(item + j * weight[i])
      });
    }
  }
  print(res.size);
}