Problem:
D : Hopping Hearts / こころぴょんぴょん
問題文
N
羽のうさぎが長さ
L−1
の平均台の上にいる。
i
番目のうさぎの初期位置は整数
x_i
であり、
0 ≤ x_{i} \lt x_{i+1} ≤ L−1
を満たす。座標は右に進むほど大きくなる。任意の
i
番目のうさぎは、任意の回数だけ、ちょうど距離
a_i
だけ右方向にジャンプ(すなわち、
x_i
から
x_i+a_i
へ移動)することができる。ただし別のうさぎを飛び越えること、
−1
以下または
L
以上の位置に入ることはできない。また、同時にジャンプしていられるのは高々
1
羽であり、ある座標に存在できるうさぎの数も高々
1
羽である。
初期状態から始めてジャンプを任意の回数繰り返したあとの
x_{0}, …, x_{N−1}
の状態として、あり得るものは何通りあるか。
1\,000\,000\,007
で割った余りで求めよ。
入力
入力は以下の形式で与えられる。
N
L
x_{0}
…
x_{N−1}
a_{0}
…
a_{N−1}
制約
入力はすべて整数である
1 \≤ N \≤ 5\,000
N \≤ L \≤ 5\,000
0 \≤ x_{i} \lt x_{i+1} \≤ L−1
0 \≤ a_{i} \≤ L−1
出力
答えを1行で出力せよ。
サンプル
サンプル入力1
1 3
0
1
サンプル出力1
3
1/0でうさぎがいる/いないを表現すれば、100, 010, 001 の
3
通りである。
サンプル入力2
2 4
0 1
1 2
サンプル出力2
4
1100, 1001, 0101, 0011 の
4
通りである。
サンプル入力3
10 50
0 1 2 3 4 5 6 7 8 9
1 1 1 1 1 1 1 1 1 1
サンプル出力3
272278100
二項係数
C(50,10) = 10\,272\,278\,170
であり、それを
1\,000\,000\,007
で割ったあまりは
272\,278\,100
である。

Submitted solutions:

code_snippet: #define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007; 
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}







int main(){
    int N, L; std::cin >> N >> L;
    //dp[i][j] := i番目の兎までを見る。jまでしか進めない
    //但し i -> i&1して圧縮
    std::vector<std::vector<int>> dp(2, std::vector<int>(L, 0));
    for(int i(0); i < L; ++i) dp[0][i] = 1;
    std::vector<int> x(N), a(N);
    for(int i(0); i < N; ++i) std::cin >> x[i];
    for(int i(0); i < N; ++i) std::cin >> a[i];
    for(int i(0); i < N; ++i){
        int cur(i & 1), nxt(!cur);
        for(int j(x[i]); j < L; j += a[i]){
            if(!j) dp[nxt][j] = dp[cur][j];//x[0] = 0のとき
            else dp[nxt][j] += dp[cur][j-1];
            dp[nxt][j] %= MOD;
            if(!a[i]) break;
        }

        for(int j(x[i]); j < L-1; ++j){
            dp[nxt][j+1] = (dp[nxt][j+1] + dp[nxt][j]) % MOD;
        }
        std::fill(std::begin(dp[cur]), std::end(dp[cur]), 0);
    }
    std::cout << dp[N&1][L-1] << std::endl;
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3452
final_rank: 1

code_snippet: #include<iostream>
#include<iomanip>
#include<vector>
#include<math.h>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<cmath>
#include<ctime>
#include<bitset>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
using ll = long long;
using vec = vector<ll>;
using Graph = vector<vec>;
using Pair = pair<ll,ll>;

void debug1(vec v){for(auto x:v)cout << x << ' ';cout << endl;}
void debug2(vector<Pair> v){for(auto x:v)cout << '(' << x.first << ',' << x.second << ')' << endl;}
void debug3(Graph v){rep(i,0,v.size()-1)debug1(v[i]);cout << endl;}

vec x(5009),a(5009);

ll mod = 1000000007;

int main(){
    ll n,l;    
    cin >> n >> l;
  
    rep(i,0,n-1)cin >> x[i];
    rep(i,0,n-1)cin >> a[i];
    x[n] = l;
    Graph dp(n+1,vec(l+1));
    vec sum(l+1);
    sum[l] = 1;
    for(int i=n-1;i>=0;i--){
        if(a[i] == 0){
            dp[i][x[i]] = (sum[l]-sum[x[i]] + mod) % mod;
            sum[0] = dp[i][0];
            rep(j,1,l)sum[j] = (sum[j-1] + dp[i][j]) % mod;
            continue;
        }
        for(int j=x[i];j<l;j++){

            if( (j-x[i]) % a[i] != 0)continue;
            dp[i][j] = (sum[l]-sum[j] + mod) % mod;
        }
        sum[0] = dp[i][0];
        rep(j,1,l)sum[j] = (sum[j-1] + dp[i][j]) % mod;
    }
    cout << sum[l] << endl;
}
accuracy: 1
time_ms: 420
memory_kb: 198840
final_rank: 18

code_snippet: #include<iostream>
#include<iomanip>
#include<vector>
#include<math.h>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<cmath>
#include<ctime>
#include<bitset>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
using ll = long long;
using vec = vector<ll>;
using Graph = vector<vec>;
vec x(5009),a(5009);

ll mod = 1000000007;

int main(){
    ll n,l;    
    cin >> n >> l;
  
    rep(i,0,n-1)cin >> x[i];
    rep(i,0,n-1)cin >> a[i];
    x[n] = l;
    Graph dp(5009,vec(5009));
    vec sum(5009);
    sum[l] = 1;
    for(int i=n-1;i>=0;i--){
        for(int j=x[i];j<l;j++){
            if( (j-x[i]) % a[i] != 0)continue;
            dp[i][j] = (sum[l]-sum[j] + mod) % mod;
        }
        sum[0] = dp[i][0];
        rep(j,1,l)sum[j] = (sum[j-1] + dp[i][j]) % mod;
    }
    cout << sum[l] << endl;
}
accuracy: 0.075
time_ms: 60
memory_kb: 199616
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll N, L;
    cin >> N >> L;
    vector<int> x(N),a(N);
    for(int i = 0; i < N; i++) cin >> x[i];
    for(int i = 0; i < N; i++) cin >> a[i];
    vector<vector<pair<int,ll>>> point(N);
    
    for(int i = x[0]; i < L&&a[0]!=0; i+=a[0]) point[0].push_back(make_pair(i,(i-x[0])/a[0]+1));
    if(a[0] == 0) point[0].push_back(make_pair(x[0],1));
    
    for(int i = 1; i < N; i++){
        int checking = 0;
        for(int now_x = x[i]; now_x < L&&a[i] != 0; now_x+=a[i]){
            while(checking+1 < (int)point[i-1].size()&&point[i-1][checking+1].first < now_x) checking++;
            if(point[i].size() != 0){
                point[i].push_back(make_pair(now_x,(point[i-1][checking].second + point[i][point[i].size()-1].second)%1000000007));
            }
            else{
                point[i].push_back(make_pair(now_x,point[i-1][checking].second%1000000007));
            }
        }
        if(a[i] == 0){
            while(checking+1 < (int)point[i-1].size()&&point[i-1][checking+1].first < x[i]) checking++;
            point[i].push_back(make_pair(x[i],point[i-1][checking].second));
        }
        
        
    }
    cout << point[N-1][point[N-1].size()-1].second << endl;
    for(int i = 0; i < N; i++){
        //for(auto z: point[i]) cout << z.first << " " << z.second << endl;
        //cout << endl;
    }
}
accuracy: 1
time_ms: 90
memory_kb: 173756
final_rank: 11

code_snippet: #include <bits/stdc++.h>

using namespace std;

using ll = long  long;

#define rep(i, n) for(int i=0; i<n; i++)
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vector<T>>;

const double eps = 1e-10;

int bit_width(ll x) {
  int ans = 0;
  while((1LL<<ans)-1 < x) ans++;
  return ans;
}
/*
struct mint {
  int MOD = 1'000'000'007;
  int val;
  mint(int val): val(val % MOD) {};
  
  mint operator+(mint a) const {
    return {(val + a.val) % MOD};
  }
};
 */
int MOD = 1'000'000'007;

int main() {
  cout << fixed << setprecision(15);
  // ---
  int N, L;
  cin >> N >> L;
  vec<int> x(N), a(N);
  rep(i, N) cin >> x[i];
  rep(i, N) cin >> a[i];
  vvec<int> dp(N, vec<int>(L, 0));
  if(a[0] != 0) {
    for(int i=x[0]; i<L; i+=a[0]) {
      dp[0][i] = 1;
    }
  } else {
    dp[0][x[0]] = 1;
  }
  vec<int> last_sum(L, 0);
  for(int i=1; i<N; i++) {
    last_sum.assign(L, 0);
    rep(j,L) {
      if(j ==0) last_sum[j] = dp[i-1][j];
      else last_sum[j] = (last_sum[j-1] + dp[i-1][j]) % MOD;
    }
//    vec<mint> sum(available.size(), 0);
//    vec<int> available;
if(a[i] != 0) {
  for (int j = x[i]; j < L; j += a[i]) {
//      available.push_back(j);
    dp[i][j] = (dp[i][j] + last_sum[j - 1]) % MOD;
  }
} else {
  dp[i][x[i]] = (dp[i][x[i]] + last_sum[x[i] - 1]) % MOD;
}
  }
  int ans = 0;
  rep(i, L) {
    ans = (ans + dp[N-1][i]) % MOD;
  }
  cout << ans << endl;
  /*
  rep(i, N) {
    rep(j, L){
      cout << dp[i][j].val << " ";
    }
    cout << endl;
  }
   */
  
}
accuracy: 1
time_ms: 210
memory_kb: 101216
final_rank: 10

code_snippet: /*＿＿＿＿＿＿
　　 ||　　　　  　|
　　 ||ACはこちらへ|
　　 ||　　　　  　|
　　 ||￣￣￣￣￣￣ 
∧_∧||
(`･ω･||
（ つ||０
　uｰu*/
#include <bits/stdc++.h>
using namespace std;
//output and debug
template <class T> using V = vector<T>;
template <class T, class U> 
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}
template <class T> ostream& operator<<(ostream& os,const V<T>& v) {
    os << "[";
    bool f = false;
    for (auto d : v) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "]";
}
template <class T> ostream& operator<<(ostream& os,const set<T>& s) {
    os << "{";
    bool f = false;
    for (auto d : s) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "}";
}
template <class T> ostream& operator<<(ostream& os, const multiset<T>& s) {
    os << "{";
    bool f = false;
    for (auto d : s) {
        if (f) os << ", ";
        f = true;
        os << d;
    }
    return os << "}";
}
template <class T, class U>
ostream& operator<<(ostream& os, const map<T, U>& s) {
    os << "{";
    bool f = false;
    for (auto p : s) {
        if (f) os << ", ";
        f = true;
        os << p.first << ": " << p.second;
    }
    return os << "}";
}
template<class T, class... Ts>
void o(const T& a, const Ts&... b){
    cout << a;
    (cout << ... << (cout << ' ', b));
    cout << '\n';
}
#ifdef LOCAL
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        o(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif
// input
template<class... T>
void in(T&... a){
    (cin >> ... >> a);
}
template<class T> void in(vector<T>& a){ for(auto&& i : a) in(i); }
template<class T, class L> void in(pair<T, L>& p){ in(p.first); in(p.second); }
template<class T> void in(T& a){ cin >> a; }

#define rep1(n)          for(ll i = 0; i < n; ++i)
#define rep2(i, n)       for(ll i = 0; i < n; ++i)
#define rep3(i, j, n)    for(ll i = j; i < n; ++i)
#define overload3(a, b, c,  e, ...) e
#define rep(...) overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(i,n) for(ll i = n-1;i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using ll = long long ;
using ld = long double;
using pa = pair<ll,ll>;
using t2 = tuple<ll,ll>;
using tu = tuple<ll,ll,ll>;
using vi = vector<ll>;
using vs = vector<string>;
using vp = vector<pa>;
using vvi = vector<vi>;
using vvp = vector<vp>;
using vvvi = vector<vvi>;
using v4 = vector<vvvi>;
using vt = vector<tu>;
const ll INF = (1ll << 29);
const ll inf = INF*INF;
const int dh[4]={1,-1,0,0};
const int dw[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};
const int dx[4]={0,0,1,-1};
const string mv = "DURL";
void Yes(bool i = true){ return o(i?"Yes":"No"); }

//reversed priority_queue
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
//const ll mod = 998244353;
const ll mod = 1000000007;

void chmod(ll &x,ll y){
	y %= mod;
	x = (x+y+mod)%mod;
	return;
}

int main(){
	ll n,l;
    in(n,l);
    vi x(n),a(n);
    in(x);
    in(a);
    vi dp(l+1,0);
    dp[l] = 1;
    rrep(i,n){
        vi np(l+1,0);
        vi sp(l+1,0);
        rrep(x,l) sp[x] = dp[x+1] + sp[x+1],sp[x] %= mod;
        if(a[i] == 0) np[x[i]] = sp[x[i]];
        else for(ll j = x[i];j < l+1; j += a[i]){
            np[j] = sp[j];
        }
        swap(np,dp);
    }
    ll ans = 0;
    rep(i,l+1) chmod(ans,dp[i]);
    o(ans);
}
accuracy: 1
time_ms: 100
memory_kb: 3628
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;

template<typename T>
bool chmin(T &a, const T &b){
    if (a <= b) return false;
    a = b;
    return true;
}


template<typename T>
bool chmax(T &a, const T &b){
    if (a >= b) return false;
    a = b;
    return true;
}

const ll mod = 1'000'000'007;

ll add(ll a, ll b){
    a += b;
    if (a >= mod) a -= mod;
    return a;
}

ll sub(ll a, ll b){
    a -= b;
    if (a < 0) a += mod;
    return a;
}

void solve(){
    int n, l; cin >> n >> l;
    vector<int> x(n), a(n);
    rep(i,0,n) cin >> x[i];
    rep(i,0,n) cin >> a[i];
    vector<ll> dp(l,0);
    for (int ix = x[n-1]; ix < l; ix += a[n-1]){
        dp[ix] = 1;
        if (a[n-1] == 0) break;
    }
    for (int i = n-2; i >= 0; i--){
        vector<ll> rui(l+1,0);
        for (int j = l-1; j >= 0; j--){
            rui[j] = add(rui[j+1],dp[j]);
        }
        vector<ll> ep(l,0);
        for (int ix = x[i]; ix < l; ix += a[i]){
            ep[ix] = rui[ix+1];
            if (a[i] == 0) break;
        }
        swap(dp,ep);
    }
    ll ans = 0;
    rep(i,0,l){
        ans = add(ans,dp[i]);
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    solve();
}
accuracy: 1
time_ms: 50
memory_kb: 3592
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define rrep(i, s, t) for(ll i = (ll)(t) - 1; i >= (ll)(s); i--)
#define all(x) begin(x), end(x)
#define TT template<typename T>
TT using vec = vector<T>;
TT using minheap = priority_queue<T, vector<T>, greater<T>>;
TT using maxheap = priority_queue<T>;

struct io_setup {
    io_setup() {
        ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        cout << fixed << setprecision(15);
    }
} io_setup;


TT bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; }
TT bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; }

TT int LB(vector<T>& v, T x) { return lower_bound(all(v), x) - begin(v);}
TT int UB(vector<T>& v, T x) { return upper_bound(all(v), x) - begin(v);}

const int MOD=1'000'000'007;

int main(){
    int N,L;
    cin>>N>>L;
    vector<int>X(N),A(N);
    for(int i=0;i<N;i++)cin>>X[i];
    for(int i=0;i<N;i++)cin>>A[i];
    vector<ll>dp(L),S(L+1);
    if(A[0]==0)dp[X[0]]=1;
    else{
        for(int i=X[0];i<L;i+=A[0])dp[i]=1;
    }
    for(int i=0;i<L;i++){
        S[i+1]=S[i]+dp[i];
        S[i+1]%=MOD;
    }
    for(int i=1;i<N;i++){
        vector<ll>dp2(L),S2(L+1);
        if(A[i]==0){
            dp2[X[i]]=S[X[i]];
        }else{
            for(int j=X[i];j<L;j+=A[i]){
                dp2[j]=S[j];
            }
        }
        for(int j=0;j<L;j++){
            S2[j+1]=S2[j]+dp2[j];
            S2[j+1]%=MOD;
        }
        swap(dp,dp2);
        swap(S,S2);
    }
    ll ans=0;
    for(int i=0;i<L;i++){
        ans+=dp[i];
        ans%=MOD;
    }
    cout<<ans<<"\n";
}
accuracy: 1
time_ms: 80
memory_kb: 3596
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define all(a) (a).begin(), (a).end()

ll mod = 1'000'000'007;

int main(){
    int n,l;
    cin >> n >> l;
    vector<int> x(n),a(n);
    rep(i,0,n) cin >> x[i];
    rep(i,0,n) cin >> a[i];
    rep(i,0,n){
        x[i]++;
    }

    vector<ll> dp(l+1,0);
    dp[0] = 1;

    rep(i,0,n){
        vector<ll> next(l+1,0);
        rep(j,0,l){
            dp[j+1] += dp[j];
            dp[j+1] %= mod;
        }

        rep(j,1,l+1){
            if(a[i] == 0){
                if(j == x[i]) next[j] = dp[j-1];
            }else{
                if(j < x[i] || (j - x[i]) % a[i] != 0) continue;
                next[j] = dp[j - 1];
            }
        }
        dp = next;
    }

    rep(i, 0, l){
        dp[i+1] += dp[i];
        dp[i+1] %= mod;
    }

    cout << dp[l] << endl;
}
accuracy: 1
time_ms: 310
memory_kb: 3560
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
using ll = long long;
using ld = long double;
const ll INF = (1ll<<61) - 1;
template<class T> bool chmax(T &a,T b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}

template<class T> bool chmin(T &a,T b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
#define all(p) p.begin(),p.end()
const int mod = 1'000'000'007;
struct mint{
    ll x;
    mint(ll x_=0):x(x_%mod){
        if(x<0) x+=mod;
    }
    friend mint operator+(mint a,mint b){return a.x+b.x;}
    friend mint operator*(mint a,mint b){return a.x*b.x;}
    friend mint operator-(mint a,mint b){return a.x-b.x;}
    friend mint & operator+=(mint &a,mint b){return a=a.x+b.x;}
    friend mint & operator*=(mint &a,mint b){return a=a.x*b.x;}
    friend mint & operator-=(mint &a,mint b){return a=a.x-b.x;}
};
int main(){
    ll N,L;
    cin>>N>>L;
    vector<ll> X(N);
    rep(i,0,N) cin>>X[i];
    vector<ll> A(N);
    rep(i,0,N) cin>>A[i];
    vector<mint> dp(L);
    mint S=1;
    for(int i=N-1;i>=0;i--){
        vector<mint> n_dp(L);
        int ind=X[i];
        if(A[i]==0){
            n_dp[ind]=S;
        }
        else while(true){
            n_dp[ind]=S;
            if(L<=ind+A[i]) break;
            rep(k,0,A[i]){
                S-=dp[++ind];
            }
        }
        swap(n_dp,dp);
        S=0;
        for(auto x:dp) S+=x;
    }
    cout<<S.x<<"\n";
}
accuracy: 1
time_ms: 120
memory_kb: 3500
final_rank: 6

code_snippet: #include <bits/stdc++.h>

using namespace std;
#define ll long long


const ll M = 1000000007;

int main(){
    int n,l; cin >> n >> l;
    vector<ll> x(n), a(n);
    for(int i = 0; i < n; i++) cin >> x[i];
    for(int i = 0; i < n; i++) cin >> a[i];
    vector cnt(n, vector<ll>(l, 0));
    if(a[n-1] == 0) cnt[n-1][x[n-1]] = 1;
    else {
        for(int k = x[n-1]; k < l; k++){
            if((k-x[n-1])%a[n-1] == 0) cnt[n-1][k] = 1;
        }

    }
    for(int i = n-2; i >= 0; i--){
        vector<ll> cur(l+1, 0);
        for(int k = l-1; k >= 0; k--){
            cur[k] = ((cur[k+1] + cnt[i+1][k]) % M + M)%M;
        }
        if(a[i] == 0) cnt[i][x[i]] = cur[x[i]+1]; 
        else {
            for(int k = x[i]; k < l; k++){
                if((k-x[i])%a[i] == 0) cnt[i][k] = cur[k+1];
            }

        }
    }
    ll ans = 0;
    for(int k = 0; k < l; k++){
        ans = ((ans + cnt[0][k]) % M + M) % M; 
        // cout << cnt[0][k] << " ";
    }

    cout << ans << '\n';
    return 0;
}
accuracy: 1
time_ms: 280
memory_kb: 198652
final_rank: 17

code_snippet: #include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1ll << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

#define chmod(a, b) a = (a + b) % MOD
ll n, l, dp[5100][5100], x[5100], a[5100];
int main(){
    cin >> n >> l;
    REP(i, n)cin >> x[i];
    REP(i, n)cin >> a[i];
    dp[0][0] = 1;
    REP(i, l){
        REP(j, n + 1){
            if (i < l) chmod(dp[i + 1][j], dp[i][j]);
            if (j < n and x[j] <= i){
                if(a[j] == 0){
                    if(i == x[j]) chmod(dp[i + 1][j + 1], dp[i][j]);
                }
                else if((i - x[j]) % a[j] == 0) chmod(dp[i + 1][j + 1], dp[i][j]);
                
            } 
            //cout << i << " " << j << " " << dp[i][j] << endl;
        }
    }
    cout << dp[l][n] << endl;
}
accuracy: 1
time_ms: 140
memory_kb: 204104
final_rank: 14

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
 
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
 
#define MOD 1000000007
 
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-8, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集    
typedef string::const_iterator State;
ll GCD(ll a, ll b){
  return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
  return a/GCD(a, b) * b;
}
template< int mod >
struct ModInt {
  int x;
 
  ModInt() : x(0) {}
 
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
 
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
 
  ModInt operator-() const { return ModInt(-x); }
 
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
 
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
 
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
 
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
  bool operator==(const ModInt &p) const { return x == p.x; }
 
  bool operator!=(const ModInt &p) const { return x != p.x; }
 
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
 
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
 
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
 
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
 
  static int get_mod() { return mod; }
};
 
using modint = ModInt< 1000000007 >;
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;
 
  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
 
  inline T fact(int k) const { return _fact[k]; }
 
  inline T rfact(int k) const { return _rfact[k]; }
 
  inline T inv(int k) const { return _inv[k]; }
 
  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }
 
  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
 
  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};
 
ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  if(x == 0) return 0;
  while(n) {
    if(n&1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
} 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
template<typename T> 
struct BIT{
  int N;
  std::vector<T> node;
  BIT(){}
  BIT(int n){
    N = n;
    node.resize(N+10);
  }
  void build(int n) {
    N = n;
    node.resize(N+10);
  }
  /* a: 1-indexed */
  void add(int a, T x){
    for(int i=a; i<(int)node.size(); i += i & -i) node[i] += x;
  }

  /* [1, a] */
  T sum(int a){
    T res = 0;
    for(int x=a; x>0; x -= x & -x) res += node[x];
    return res;
  }

  /* [l, r] */
  T rangesum(int l, int r){
    return sum(r) - sum(l-1);
  }

  /* 
    a1+a2+...+aw >= valとなるような最小のwを返す
    @verify https://codeforces.com/contest/992/problem/E
  */
  int lower_bound(T val) {
    if(val < 0) return 0;

    int res = 0;
    int n = 1; 
    while (n < N) n *= 2;

    T tv=0;
    for (int k = n; k > 0; k /= 2) {
      if(res + k < N && node[res + k] < val){
        val -= node[res+k];
        res += k;
      }
    }
    return res+1; 
  }
};

struct UnionFind{
  std::vector<int> par;
  std::vector<int> siz;

  UnionFind(int sz_): par(sz_), siz(sz_) {
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  void init(int sz_){
    par.resize(sz_);
    siz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  int root(int x){
    if(x == par[x]) return x;
    return par[x] = root(par[x]);
  }

  bool merge(int x, int y){
    x = root(x), y = root(y);
    if(x == y) return false;
    if(siz[x] < siz[y]) std::swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(int x, int y){
    return root(x) == root(y);
  }

  int size(int x){
    return siz[root(x)];
  }
};
struct RollingHash{

    using ull = unsigned long long;
    const ull mod = (1ULL << 61) - 1;
    const ull MASK30 = (1ULL << 30) - 1;
    const ull MASK31 = (1ULL << 31) - 1;

    const ull MASK61 = mod;

    ull base;
    int n;
    vector<ull> hash, pow;

    RollingHash(const string &s)
    {
        random_device rnd;
        mt19937_64 mt(rnd());
        base = 1001;
        
        n = (int)s.size();
        hash.assign(n+1, 0);
        pow.assign(n+1, 1);
        
        for(int i=0; i<n; i++){
            hash[i+1] = calc_mod(mul(hash[i], base) + s[i]);
            pow[i+1] = calc_mod(mul(pow[i], base));
        }
    }

    ull calc_mod(ull x){
        ull xu = x >> 61;
        ull xd = x & MASK61;
        ull res = xu + xd;
        if(res >= mod) res -= mod;
        return res;
    }

    ull mul(ull a, ull b){
        ull au = a >> 31;
        ull ad = a & MASK31;
        ull bu = b >> 31;
        ull bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        ull midu = mid >> 30;
        ull midd = mid & MASK30;
        return calc_mod(au * bu * 2 + midu + (midd << 31) + ad * bd);
    }

    //[l,r)のハッシュ値
    inline ull get(int l, int r){
        ull res = calc_mod(hash[r] + mod*3-mul(hash[l], pow[r-l]));
        return res;
    }
    //string tのハッシュ値
    inline ull get(string t){
        ull res = 0;
        for(int i=0; i<t.size(); i++){
            res = calc_mod(mul(res, base)+t[i]);
        }
        return res;
    }
    //string s中のtの数をカウント
    inline int count(string t) {
        if(t.size() > n) return 0;
        auto hs = get(t);
        int res = 0;
        for(int i=0; i<n-t.size()+1; i++){
            if(get(i, i+t.size()) == hs) res++; 
        }
        return res;
    }

    /* 
        concat 
        @verify https://codeforces.com/problemset/problem/514/C
    */
    inline ull concat(ull h1, ull h2, int h2len){
      return calc_mod(h2 + mul(h1, pow[h2len]));
    }

    // LCPを求める S[a:] T[b:]
    inline int LCP(int a, int b){
        int len = min((int)hash.size()-a, (int)hash.size()-b);
        
        int lb = -1, ub = len;
        while(ub-lb>1){
            int mid = (lb+ub)/2;

            if(get(a, a+mid) == get(b, b+mid)) lb = mid;
            else ub = mid;
        }
        return lb;
    }
};
modint dp[5010][5010];
int main() {  
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  
  int N, L; cin >> N >> L;
  vector<int> x(N), a(N);
  REP(i,N) {
    cin >> x[i];
  }
  REP(i,N) {
    cin >> a[i];
  }
  for(int i=x[N-1]; i<L; i+=a[N-1]) {
    dp[N-1][i] = 1;
    if(a[N-1] == 0) break;
  }
  for(int i=N-2; i>=0; i--) {
    vector<modint> cums(L+1);
    REP(j,L) cums[j+1] = cums[j] + dp[i+1][j];
    for(int j=x[i]; j<L; j+=a[i]) {
      //今のウサギがjにいる場合
      dp[i][j] += cums[L] - cums[j+1];
      if(a[i] == 0) break;
    }

  }
  modint ans = 0;
  REP(i,L) ans += dp[0][i];
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 101548
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b; 
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int dp[5005][5005];

signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,l;
  cin>>n>>l;
  int x[n],a[n];
  rep(i,n) cin>>x[i];
  rep(i,n) cin>>a[i];
  
  dp[0][x[0]]=1;
  for(int i=x[0]+1;i<l;i++){
    if(a[0]!=0 &&  (i-x[0])%a[0]==0) dp[0][i]=dp[0][i-a[0]]+1;
    else dp[0][i]=dp[0][i-1];
    //cout<<dp[0][i]<<" "<<endl;
  }
    
  repi(i,1,n){
    dp[i][x[i]]=dp[i-1][x[i]-1];
    for(int j=x[i]+1;j<l;j++){
      
      if(a[i]!=0 &&  (j-x[i])%a[i]==0) dp[i][j]=dp[i][j-a[i]]+dp[i-1][j-1];
      else dp[i][j]=dp[i][j-1];
      dp[i][j]%=MOD;
    }
  }
  /*rep(i,n){
    rep(j,l){
      cout<<dp[i][j]<<" ";
    }
    cout<<endl;
    }*/
  cout<<dp[n-1][l-1]<<endl;   
    
  return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 198184
final_rank: 12

code_snippet: #include<bits/stdc++.h>

#define int ll
#define rep(i, N) for(int i = 0; i < N; i++)
#define per(i, N) for(int i = N-1; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define TakAo(ans) ans ? cout << "Takahashi\n" : cout << "Aoki\n"
#define YesNo(ans) ans ? cout << "Yes\n" : cout << "No\n"
#define yesno(ans) ans ? cout << "yes\n" : cout << "no\n"
#define YESNO(ans) ans ? cout << "YES\n" : cout << "NO\n"
#define equal(f1, f2) (abs(f1 - f2) <= EPS)
#define endl '\n'
#define fi first
#define se second
#define mkpr make_pair
#define mktpl make_tuple

using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using Tpl = tuple<int, int, int>;
using vvec = vector<vector<int>>;
using vvvec = vector<vector<vector<int>>>;

const ld EPS = 1e-8;
const ld Pi = acos(-1);
const ll INF = 1e9+10;
//const int MOD = 998244353;
const int MOD = 1e9+7;
const int NIL = -1;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};

ll cel(ll a, ll b){ return b ? (a + b - 1) / b : 1; }
ll Gcd(ll a, ll b){ return b ? Gcd(b, a % b) : a; }
ll Lcm(ll a, ll b){ return a / Gcd(a, b) * b; }
ll sq(ll a){ return a * a; }
ll cube(ll a){ return a * a * a; }
ll powi(ll a, ll b){ ll res = 1; rep(i, b) res *= a; return res; }
template<class T> bool chmin(T &a, T b){ if(a > b){ a = b; return 1;} return 0; }
template<class T> bool chmax(T &a, T b){ if(a < b){ a = b; return 1;} return 0; }

void Main(){
	int N, L; cin >> N >> L;
	vector<int> x(N), a(N);
	rep(i, N) cin >> x[i];
	rep(i, N) cin >> a[i];

	vvec dp(N+1, vector<int>(L+1, 0));
	
	dp[N][L] = 1;

	per(i, N){
		for(int j = x[i]; j <= L; j++){
			dp[i][x[i] + (cel(j - x[i], a[i]) - 1) * a[i]] += dp[i+1][j];
			dp[i][x[i] + (cel(j - x[i], a[i]) - 1) * a[i]] %= MOD;
		}
		if(a[i]){
			for(int j = L; j >= x[i] + a[i]; j--)
				dp[i][j - a[i]] = (dp[i][j - a[i]] + dp[i][j]) % MOD;
		}
	}

	ll ans = 0;
	rep(i, L+1) ans = (ans + dp[0][i]) % MOD;

	cout << ans << endl;
}

signed main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 198544
final_rank: 16

code_snippet: #include<bits/stdc++.h>
#define rep(i,a,...) for(long long i = (a)*(strlen(#__VA_ARGS__)!=0);i<(long long)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(long long i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(long long)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
    ll modpow(ll x, ll b,ll mod=MOD){
        ll res = 1;
        while(b){
            if(b&1)res = res * x % mod;
            x = x * x % mod;
            b>>=1;
        }
        return res;
    }

    ll modinv(ll x){
        return modpow(x, MOD-2);
    }

    bool was_output = false;

    void print();
    template <class t> void print(const vector<t> &);
    template <class t, class u> void print(const pair<t, u> &);
    template <class t> void print(const t&);
    template <class Head, class... Tail> void print(const Head&, const Tail&...);

    template <class t> void println(const vector<vector<t>>&);
    template <class t> void println(const vector<t>&);
    template <class t> void println(const t&);
    template <class Head, class... Tail> void println(const Head&, const Tail&...);
    void println();
    void newline();

    void print(){
        return;
    }

    template <class t>
    void print(const vector<t>&x){
        for(const t&i:x)print(i);
    }
    template <class t, class u>
    void print(const pair<t,u>&p){
        print(p.first);
        print(p.second);
    }
    template <class t>
    void print(const t&x){
        if(was_output)cout<<" ";
        cout<<x;
        was_output = true;
    }
    template <class Head, class... Tail>
    void print(const Head&head,const Tail&...tail){
        print(head);
        print(tail...);
    }

    template<class t>
    void println(const vector<vector<t>>&x){
        for(vector<t> i:x)println(i);
    }
    template<class t>
    void println(const vector<t>&x){
        for(const t&i:x)print(i);
        println();
    }
    template <class t>
    void println(const t&x){
        print(x);
        println();
    }
    void println(){
        if(was_output){
            cout << endl;
            was_output = false;
        }
    }
    template <class Head, class... Tail>
    void println(const Head&head,const Tail&...tail){
        print(head);
        println(tail...);
    }

    void newline(){
        was_output = true;
        println();
    }

    template<class t>
    istream& operator>>(istream&is, vector<t>&x){
        for(auto &i:x)is >> i;
        return is;
    }

    template<class t, class u>
    istream& operator>>(istream&is, pair<t, u>&x){
        is >> x.first >> x.second;
        return is;
    }

    template<class t>
    ostream& operator<<(ostream&os, vector<t> &v){
        os << "{";
        for(t &i:v){
            os << i << ", ";
        }
        os << "}";
        return os;
    }

    template<class t = long long>
    t in(){
        t res; cin >> res; return res;
    }

    template<class t>
    vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
        sort(line.begin(),line.end(),comp);
        return line;
    }

    template<class t>
    vector<t> reversed(vector<t> line){
        reverse(line.begin(),line.end());
        return line;
    }
    string reversed(string str){
        reverse(str.begin(),str.end());
        return str;
    }

    long long gcd(long long a,long long b){
        while(b){
            a %= b;
            swap(a,b);
        }
        return a;
    }

    long long lcm(long long a,long long b){
        return a / gcd(a,b) * b;
    }

    class output_initializer{
    public:
        output_initializer(){
            ios::sync_with_stdio(false);
            cin.tie(nullptr);
            cout << setprecision(20);
        }
    };output_initializer OUTPUT_INITIALIZER_INSTANCE = output_initializer();
}

using namespace templates;

template <class T>
vector<T> make_vector(int n,T init){
    return vector<T>(n,init);
}

template <class... tail>
auto make_vector(int n, tail... args){
    return vector<decltype(make_vector(args...))>(n,make_vector(args...));
}

template<long long mod>
class modint{
	public:
	int x;
		modint(int a){x=a%mod;if(x<0)x+=mod;}
		modint(){x=0;}

		modint pow(long long a){
			modint res(1), b(x);
			while(a){
				if(a&1)res*=b;
				b*=b;
				a>>=1;
			}
			return res;
		}

		modint inv(){return pow(mod-2);}

		modint& operator+=(modint a){x=(x+a.x)%mod;return *this;}
		modint& operator-=(modint a){x=x-a.x;if(x<0)x+=mod;return *this;}
    modint& operator*=(modint a){x=(long long)x*a.x%mod;return *this;}
    modint& operator/=(modint a){x=(long long)x*a.inv().x%mod;return *this;}

		modint operator+(modint a){return modint(x)+=a;}
		modint operator-(modint a){return modint(x)-=a;}
		modint operator*(modint a){return modint(x)*=a;}
		modint operator/(modint a){return modint(x)/=a;}

		modint operator-(){return modint(x);}

		bool operator==(const modint a){return x == a.x;}
		bool operator<(const modint a){return x < a.x;}
		bool operator>(const modint a){return x > a.x;}
};

template<long long mod>
ostream& operator<<(ostream& os, const modint<mod>& a){
	os << a.x;
	return os;
}

using mint = modint<MOD>;

mint func(){
    int n = in();
    int l = in();
    vector<int> xs(n);
    vector<int> as(n);
    foreach(i,xs)i=in();
    foreach(i,as)i=in();
    vvector<mint> dp(n+1,vector<mint>(l+2));
    vvector<bool> used(n+1,vector<bool>(l+2,false));
    vvector<mint> dp2(n+1,vector<mint>(l+2));
    vvector<bool> used2(n+1,vector<bool>(l+2,false));
    method(rec,mint,int p,int r){
        if(p==-1)return 1;
        if(as[p]){
            r = (r - xs[p]) / as[p] * as[p] + xs[p];
        }
        if(xs[p]>r)return 0;
        if(used[p][r])return dp[p][r];
        used[p][r] = true;
        mint &it = dp[p][r];
        method(rec2,mint,int p,int r){
            if(xs[p] > r)return 0;
            if(used2[p][r])return dp2[p][r];
            used2[p][r] = true;
            mint &it = dp2[p][r];
            return it = rec2(p,r-as[p]) + rec(p-1,r-1);
        };
        if(as[p]){
            it = rec2(p,r);
        }else{
            it = rec(p-1,r-1);
        }
        return it;
    };
    return rec(n-1,l-1);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    println(func());
    return 0;
}
accuracy: 1
time_ms: 220
memory_kb: 206832
final_rank: 15

code_snippet: #include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1000000007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N, L;
	vector<int> x, a;
	vector<int> dp;
	
	cin>>N>>L;
	
	x.resize(N);
	a.resize(N);
	dp.resize(L);
	
	for(int i = 0; i < N; i++){
		cin>>x[i];
	}
	
	for(int i = 0; i < N; i++){
		cin>>a[i];
	}
	
	for(int i = 0; i < N; i++){
		vector<int> ndp(dp.size());
		
		for(int j = 0, s = (i==0); j < L; j++){
			if(a[i] == 0) {
				if(j == x[i]) {
					ndp[j] = s;
				}
			} else if(x[i] <= j && (j - x[i]) % a[i] == 0) {
				ndp[j] = s;
			}
			s += dp[j];
			s %= MOD;
		}
		
		swap(ndp, dp);
	}
	
	int ans = 0;
	for(int i = 0; i < dp.size(); i++){
		ans += dp[i];
		ans %= MOD;
	}
	
	cout<<ans<<endl;
	
	return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 3524
final_rank: 7

code_snippet: #line 2 "/home/yuruhiya/programming/library/template/template.cpp"
#include <bits/stdc++.h>
#line 4 "/home/yuruhiya/programming/library/template/constants.cpp"
#include <string_view>
#line 7 "/home/yuruhiya/programming/library/template/constants.cpp"

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rfor(i, m, n) for (int i = (m); i >= (n); --i)
#define unless(c) if (!(c))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define range_it(a, l, r) (a).begin() + (l), (a).begin() + (r)

using namespace std;
using ll = long long;
using LD = long double;
using VB = vector<bool>;
using VVB = vector<VB>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VS = vector<string>;
using VD = vector<LD>;
using PII = pair<int, int>;
using VP = vector<PII>;
using PLL = pair<ll, ll>;
using VPL = vector<PLL>;
template <class T> using PQ = priority_queue<T>;
template <class T> using PQS = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000000;
constexpr long long inf_ll = 1000000000000000000ll, MOD = 1000000007;
constexpr long double PI = 3.14159265358979323846, EPS = 1e-12;
namespace CharacterClass {
	constexpr string_view
	    digit = "0123456789",
	    xdigit = "0123456789ABCDEFabcdef", lower = "abcdefghijklmnopqrstuvwxyz",
	    upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
	    alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	    alnum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
	    word = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz",
	    punct = R"(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)",
	    graph =
	        R"(!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~)",
	    print =
	        R"( !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~)",
	    blank = " \t", space = " \t\n\r\f\v";
}  // namespace CharacterClass
#line 7 "/home/yuruhiya/programming/library/template/Input.cpp"
using namespace std;

#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#define fwrite_unlocked fwrite
#define fflush_unlocked fflush
#endif
class Scanner {
	static int gc() {
		return getchar_unlocked();
	}
	static char next_char() {
		char c;
		read(c);
		return c;
	}
	template <class T> static void read(T& v) {
		cin >> v;
	}
	static void read(char& v) {
		while (isspace(v = gc()))
			;
	}
	static void read(bool& v) {
		v = next_char() != '0';
	}
	static void read(string& v) {
		v.clear();
		for (char c = next_char(); !isspace(c); c = gc()) v += c;
	}
	static void read(int& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void read(long long& v) {
		v = 0;
		bool neg = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c); c = gc()) v = v * 10 + (c - '0');
		if (neg) v = -v;
	}
	static void read(double& v) {
		v = 0;
		double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	static void read(long double& v) {
		v = 0;
		long double dp = 1;
		bool neg = false, after_dp = false;
		char c = next_char();
		if (c == '-') {
			neg = true;
			c = gc();
		}
		for (; isdigit(c) || c == '.'; c = gc()) {
			if (c == '.') {
				after_dp = true;
			} else if (after_dp) {
				v += (c - '0') * (dp *= 0.1);
			} else {
				v = v * 10 + (c - '0');
			}
		}
		if (neg) v = -v;
	}
	template <class T, class U> static void read(pair<T, U>& v) {
		read(v.first);
		read(v.second);
	}
	template <class T> static void read(vector<T>& v) {
		for (auto& e : v) read(e);
	}
	template <size_t N = 0, class T> static void read_tuple_impl(T& v) {
		if constexpr (N < tuple_size_v<T>) {
			read(get<N>(v));
			read_tuple_impl<N + 1>(v);
		}
	}
	template <class... T> static void read(tuple<T...>& v) {
		read_tuple_impl(v);
	}
	struct ReadVectorHelper {
		size_t n;
		ReadVectorHelper(size_t _n) : n(_n) {}
		template <class T> operator vector<T>() {
			vector<T> v(n);
			read(v);
			return v;
		}
	};
	struct Read2DVectorHelper {
		size_t n, m;
		Read2DVectorHelper(const pair<size_t, size_t>& nm) : n(nm.first), m(nm.second) {}
		template <class T> operator vector<vector<T>>() {
			vector<vector<T>> v(n, vector<T>(m));
			read(v);
			return v;
		}
	};

public:
	string read_line() const {
		string v;
		for (char c = gc(); c != '\n' && c != '\0'; c = gc()) v += c;
		return v;
	}
	template <class T> T read() const {
		T v;
		read(v);
		return v;
	}
	template <class T> vector<T> read_vector(size_t n) const {
		vector<T> a(n);
		read(a);
		return a;
	}
	template <class T> operator T() const {
		return read<T>();
	}
	int operator--(int) const {
		return read<int>() - 1;
	}
	ReadVectorHelper operator[](size_t n) const {
		return ReadVectorHelper(n);
	}
	Read2DVectorHelper operator[](const pair<size_t, size_t>& nm) const {
		return Read2DVectorHelper(nm);
	}
	void operator()() const {}
	template <class H, class... T> void operator()(H&& h, T&&... t) const {
		read(h);
		operator()(forward<T>(t)...);
	}

private:
	template <template <class...> class, class...> struct Multiple;
	template <template <class...> class V, class Head, class... Tail>
	struct Multiple<V, Head, Tail...> {
		template <class... Args> using vec = V<vector<Head>, Args...>;
		using type = typename Multiple<vec, Tail...>::type;
	};
	template <template <class...> class V> struct Multiple<V> { using type = V<>; };
	template <class... T> using multiple_t = typename Multiple<tuple, T...>::type;
	template <size_t N = 0, class T> void multiple_impl(T& t) const {
		if constexpr (N < tuple_size_v<T>) {
			auto& vec = get<N>(t);
			using V = typename remove_reference_t<decltype(vec)>::value_type;
			vec.push_back(read<V>());
			multiple_impl<N + 1>(t);
		}
	}

public:
	template <class... T> auto multiple(size_t h) const {
		multiple_t<T...> result;
		while (h--) multiple_impl(result);
		return result;
	}
} in;
#define inputs(T, ...) \
	T __VA_ARGS__;     \
	in(__VA_ARGS__)
#define ini(...) inputs(int, __VA_ARGS__)
#define inl(...) inputs(long long, __VA_ARGS__)
#define ins(...) inputs(string, __VA_ARGS__)
#line 7 "/home/yuruhiya/programming/library/template/Output.cpp"
#include <charconv>
#line 10 "/home/yuruhiya/programming/library/template/Output.cpp"
using namespace std;

struct BoolStr {
	const char *t, *f;
	BoolStr(const char* _t, const char* _f) : t(_t), f(_f) {}
} Yes("Yes", "No"), yes("yes", "no"), YES("YES", "NO"), Int("1", "0");
struct DivStr {
	const char *d, *l;
	DivStr(const char* _d, const char* _l) : d(_d), l(_l) {}
} spc(" ", "\n"), no_spc("", "\n"), end_line("\n", "\n"), comma(",", "\n"),
    no_endl(" ", "");
class Output {
	BoolStr B{Yes};
	DivStr D{spc};

public:
	void put(int v) const {
		char buf[12]{};
		if (auto [ptr, e] = to_chars(begin(buf), end(buf), v); e == errc{}) {
			fwrite(buf, sizeof(char), ptr - buf, stdout);
		} else {
			assert(false);
		}
	}
	void put(long long v) const {
		char buf[21]{};
		if (auto [ptr, e] = to_chars(begin(buf), end(buf), v); e == errc{}) {
			fwrite(buf, sizeof(char), ptr - buf, stdout);
		} else {
			assert(false);
		}
	}
	void put(bool v) const {
		put(v ? B.t : B.f);
	}
	void put(vector<bool>::reference v) const {
		put(v ? B.t : B.f);
	}
	void put(char v) const {
		putchar_unlocked(v);
	}
	void put(const char* v) const {
		fwrite_unlocked(v, 1, strlen(v), stdout);
	}
	void put(double v) const {
		printf("%.20f", v);
	}
	void put(long double v) const {
		printf("%.20Lf", v);
	}
	template <class T> void put(const T& v) const {
		cout << v;
	}
	template <class T, class U> void put(const pair<T, U>& v) const {
		put(v.first);
		put(D.d);
		put(v.second);
	}
	template <class InputIterater>
	void put_range(const InputIterater& begin, const InputIterater& end) const {
		for (InputIterater i = begin; i != end; ++i) {
			if (i != begin) put(D.d);
			put(*i);
		}
	}
	template <class T> void put(const vector<T>& v) const {
		put_range(v.begin(), v.end());
	}
	template <class T, size_t N> void put(const array<T, N>& v) const {
		put_range(v.begin(), v.end());
	}
	template <class T> void put(const vector<vector<T>>& v) const {
		for (size_t i = 0; i < v.size(); ++i) {
			if (i) put(D.l);
			put(v[i]);
		}
	}

	Output() = default;
	Output(const BoolStr& _boolstr, const DivStr& _divstr) : B(_boolstr), D(_divstr) {}
	Output& operator()() {
		put(D.l);
		return *this;
	}
	template <class H> Output& operator()(H&& h) {
		put(h);
		put(D.l);
		return *this;
	}
	template <class H, class... T> Output& operator()(H&& h, T&&... t) {
		put(h);
		put(D.d);
		return operator()(forward<T>(t)...);
	}
	template <class InputIterator>
	Output& range(const InputIterator& begin, const InputIterator& end) {
		put_range(begin, end);
		put(D.l);
		return *this;
	}
	template <class T> Output& range(const T& a) {
		range(a.begin(), a.end());
		return *this;
	}
	template <class... T> void exit(T&&... t) {
		operator()(forward<T>(t)...);
		std::exit(EXIT_SUCCESS);
	}
	Output& flush() {
		fflush_unlocked(stdout);
		return *this;
	}
	Output& set(const BoolStr& b) {
		B = b;
		return *this;
	}
	Output& set(const DivStr& d) {
		D = d;
		return *this;
	}
	Output& set(const char* t, const char* f) {
		B = BoolStr(t, f);
		return *this;
	}
} out;
#line 3 "/home/yuruhiya/programming/library/template/Step.cpp"
using namespace std;

template <class T> struct Step {
	using value_type = T;

	class iterator {
		value_type a, b, c;

	public:
		constexpr iterator() : a(value_type()), b(value_type()), c(value_type()) {}
		constexpr iterator(value_type _b, value_type _c, value_type _s)
		    : a(_b), b(_c), c(_s) {}
		constexpr iterator& operator++() {
			--b;
			a += c;
			return *this;
		}
		constexpr iterator operator++(int) {
			iterator tmp = *this;
			--b;
			a += c;
			return tmp;
		}
		constexpr const value_type& operator*() const {
			return a;
		}
		constexpr const value_type* operator->() const {
			return &a;
		}
		constexpr bool operator==(const iterator& i) const {
			return b == i.b;
		}
		constexpr bool operator!=(const iterator& i) const {
			return !(b == i.b);
		}
		constexpr value_type start() const {
			return a;
		}
		constexpr value_type size() const {
			return b;
		}
		constexpr value_type step() const {
			return c;
		}
	};
	constexpr Step(value_type b, value_type c, value_type s) : be(b, c, s) {}
	constexpr iterator begin() const {
		return be;
	}
	constexpr iterator end() const {
		return en;
	}
	constexpr value_type start() const {
		return be.start();
	}
	constexpr value_type size() const {
		return be.size();
	}
	constexpr value_type step() const {
		return be.step();
	}
	constexpr value_type sum() const {
		return start() * size() + step() * (size() * (size() - 1) / 2);
	}
	operator vector<value_type>() const {
		return to_a();
	}
	auto to_a() const {
		vector<value_type> result;
		result.reserve(size());
		for (auto i : *this) {
			result.push_back(i);
		}
		return result;
	}

private:
	iterator be, en;
};
template <class T> constexpr auto step(T a) {
	return Step<T>(0, a, 1);
}
template <class T> constexpr auto step(T a, T b) {
	return Step<T>(a, b - a, 1);
}
template <class T> constexpr auto step(T a, T b, T c) {
	return Step<T>(a, a < b ? (b - a - 1) / c + 1 : 0, c);
}
#line 8 "/home/yuruhiya/programming/library/template/Ruby.cpp"
using namespace std;

template <class F> struct Callable {
	F func;
	Callable(const F& f) : func(f) {}
};
template <class T, class F> auto operator|(const T& v, const Callable<F>& c) {
	return c.func(v);
}

struct Sort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const Sort_impl& c) {
		sort(begin(v), end(v));
		return v;
	}
} Sort;
struct SortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v),
			     [&](const auto& i, const auto& j) { return f(i) < f(j); });
			return v;
		});
	}
} SortBy;
struct RSort_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(rbegin(v), rend(v), f);
			return v;
		});
	}
	template <class T> friend auto operator|(T v, [[maybe_unused]] const RSort_impl& c) {
		sort(rbegin(v), rend(v));
		return v;
	}
} RSort;
struct RSortBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			sort(begin(v), end(v),
			     [&](const auto& i, const auto& j) { return f(i) > f(j); });
			return v;
		});
	}
} RSortBy;
struct Reverse_impl {
	template <class T> friend auto operator|(T v, const Reverse_impl& c) {
		reverse(begin(v), end(v));
		return v;
	}
} Reverse;
struct Unique_impl {
	template <class T> friend auto operator|(T v, const Unique_impl& c) {
		v.erase(unique(begin(v), end(v), end(v)));
		return v;
	}
} Unique;
struct Uniq_impl {
	template <class T> friend auto operator|(T v, const Uniq_impl& c) {
		sort(begin(v), end(v));
		v.erase(unique(begin(v), end(v)), end(v));
		return v;
	}
} Uniq;
struct Rotate_impl {
	auto operator()(int&& left) {
		return Callable([&](auto v) {
			int s = static_cast<int>(size(v));
			assert(-s <= left && left <= s);
			if (0 <= left) {
				rotate(begin(v), begin(v) + left, end(v));
			} else {
				rotate(begin(v), end(v) + left, end(v));
			}
			return v;
		});
	}
} Rotate;
struct Max_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) { return *max_element(begin(v), end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Max_impl& c) {
		return *max_element(begin(v), end(v));
	}
} Max;
struct Min_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) { return *min_element(begin(v), end(v), f); });
	}
	template <class T> friend auto operator|(T v, const Min_impl& c) {
		return *min_element(begin(v), end(v));
	}
} Min;
struct MaxPos_impl {
	template <class T> friend auto operator|(T v, const MaxPos_impl& c) {
		return max_element(begin(v), end(v)) - begin(v);
	}
} MaxPos;
struct MinPos_impl {
	template <class T> friend auto operator|(T v, const MinPos_impl& c) {
		return min_element(begin(v), end(v)) - begin(v);
	}
} MinPos;
struct MaxBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_it = begin(v);
			auto max_val = f(*max_it);
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_it = it;
					max_val = val;
				}
			}
			return *max_it;
		});
	}
} MaxBy;
struct MinBy_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_it = begin(v);
			auto min_val = f(*min_it);
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_it = it;
					min_val = val;
				}
			}
			return *min_it;
		});
	}
} MinBy;
struct MaxOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto max_val = f(*begin(v));
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); max_val < val) {
					max_val = val;
				}
			}
			return max_val;
		});
	}
} MaxOf;
struct MinOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			auto min_val = f(*begin(v));
			for (auto it = next(begin(v)); it != end(v); ++it) {
				if (auto val = f(*it); min_val > val) {
					min_val = val;
				}
			}
			return min_val;
		});
	}
} MinOf;
struct Count_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return count(begin(v), end(v), val); });
	}
} Count;
struct CountIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return count_if(begin(v), end(v), f); });
	}
} CountIf;
struct Index_impl {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find(begin(v), end(v), val);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
} Index;
struct IndexIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> optional<int> {
			auto result = find_if(begin(v), end(v), f);
			return result != end(v) ? optional(result - begin(v)) : nullopt;
		});
	}
} IndexIf;
struct FindIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) -> optional<typename decltype(v)::value_type> {
			auto result = find_if(begin(v), end(v), f);
			return result != end(v) ? optional(*result) : nullopt;
		});
	}
} FindIf;
struct Sum_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			return accumulate(next(begin(v)), end(v), f(*begin(v)),
			                  [&](const auto& a, const auto& b) { return a + f(b); });
		});
	}
	template <class T> friend auto operator|(T v, const Sum_impl& c) {
		return accumulate(begin(v), end(v), typename T::value_type{});
	}
} Sum;
struct Includes {
	template <class V> auto operator()(const V& val) {
		return Callable([&](auto v) { return find(begin(v), end(v), val) != end(v); });
	}
} Includes;
struct IncludesIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) { return find_if(begin(v), end(v), f) != end(v); });
	}
} IncludesIf;
struct RemoveIf_impl {
	template <class F> auto operator()(const F& f) {
		return Callable([&](auto v) {
			v.erase(remove_if(begin(v), end(v), f), end(v));
			return v;
		});
	}
} RemoveIf;
struct Each_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				f(i);
			}
		});
	}
} Each;
struct Select_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using value_type = typename decltype(v)::value_type;
			vector<value_type> result;
			for (const auto& i : v) {
				if (f(i)) result.push_back(i);
			}
			return result;
		});
	}
} Select;
struct Map_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			using result_type = invoke_result_t<F, typename decltype(v)::value_type>;
			vector<result_type> result;
			result.reserve(size(v));
			for (const auto& i : v) {
				result.push_back(f(i));
			}
			return result;
		});
	}
} Map;
struct Indexed_impl {
	template <class T> friend auto operator|(const T& v, Indexed_impl& c) {
		using value_type = typename T::value_type;
		vector<pair<value_type, int>> result;
		result.reserve(size(v));
		int index = 0;
		for (const auto& i : v) {
			result.emplace_back(i, index++);
		}
		return result;
	}
} Indexed;
struct AllOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (!f(i)) return false;
			}
			return true;
		});
	}
} AllOf;
struct AnyOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return true;
			}
			return false;
		});
	}
} AnyOf;
struct NoneOf_impl {
	template <class F> auto operator()(F&& f) {
		return Callable([&](auto v) {
			for (const auto& i : v) {
				if (f(i)) return false;
			}
			return true;
		});
	}
} NoneOf;

struct Tally_impl {
	template <class F> auto operator()(size_t max_val) {
		return Callable([&](auto v) {
			vector<size_t> result(max_val);
			for (const auto& i : v) {
				result[static_cast<size_t>(i)]++;
			}
			return result;
		});
	}
	template <class T, class value_type = typename T::value_type>
	friend auto operator|(const T& v, Tally_impl& c) {
		map<value_type, size_t> result;
		for (const auto& i : v) {
			result[i]++;
		}
		return result;
	}
} Tally;

template <class T> auto operator*(const vector<T>& a, size_t n) {
	T result;
	for (size_t i = 0; i < n; ++i) {
		result.insert(result.end(), a.begin(), a.end());
	}
	return result;
}
auto operator*(string a, size_t n) {
	string result;
	for (size_t i = 0; i < n; ++i) {
		result += a;
	}
	return result;
}
template <class T, class U> auto& operator<<(vector<T>& a, const U& b) {
	a.insert(a.end(), all(b));
	return a;
}
template <class T> auto& operator<<(string& a, const T& b) {
	a.insert(a.end(), all(b));
	return a;
}
template <class T, class U> auto operator+(vector<T> a, const U& b) {
	a << b;
	return a;
}
template <class T> auto operator+(string a, const T& b) {
	a << b;
	return a;
}
#line 7 "/home/yuruhiya/programming/library/template/functions.cpp"
using namespace std;

template <class T = long long> constexpr T TEN(size_t n) {
	T result = 1;
	for (size_t i = 0; i < n; ++i) result *= 10;
	return result;
}
template <class T, class U,
          enable_if_t<is_integral_v<T> && is_integral_v<U>, nullptr_t> = nullptr>
constexpr auto div_ceil(T n, U m) {
	return (n + m - 1) / m;
}
template <class T, class U> constexpr auto div_ceil2(T n, U m) {
	return div_ceil(n, m) * m;
}
template <class T> constexpr T triangle(T n) {
	return (n & 1) ? (n + 1) / 2 * n : n / 2 * (n + 1);
}
template <class T> constexpr T nC2(T n) {
	return (n & 1) ? (n - 1) / 2 * n : n / 2 * (n - 1);
}
template <class T, class U> constexpr auto middle(const T& l, const U& r) {
	return l + (r - l) / 2;
}
template <class T, class U, class V>
constexpr bool in_range(const T& v, const U& lower, const V& upper) {
	return lower <= v && v < upper;
}
template <class T, enable_if_t<is_integral_v<T>, nullptr_t> = nullptr>
constexpr bool is_square(T n) {
	T s = sqrt(n);
	return s * s == n || (s + 1) * (s + 1) == n;
}
template <class T = long long> constexpr T BIT(int b) {
	return T(1) << b;
}
template <class T, class U, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
constexpr T Pow(T a, U n) {
	assert(n >= 0);
	T result = 1;
	while (n > 0) {
		if (n & 1) {
			result *= a;
			n--;
		} else {
			a *= a;
			n >>= 1;
		}
	}
	return result;
}
template <class T, class U, enable_if_t<is_integral_v<U>, nullptr_t> = nullptr>
constexpr T Powmod(T a, U n, T mod) {
	assert(n >= 0);
	if (a > mod) a %= mod;
	T result = 1;
	while (n > 0) {
		if (n & 1) {
			result = result * a % mod;
			n--;
		} else {
			a = a * a % mod;
			n >>= 1;
		}
	}
	return result;
}
template <class T> bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> int sz(const T& v) {
	return v.size();
}
template <class T, class U> int lower_index(const T& a, const U& v) {
	return lower_bound(all(a), v) - a.begin();
}
template <class T, class U> int upper_index(const T& a, const U& v) {
	return upper_bound(all(a), v) - a.begin();
}
template <class T> auto Slice(const T& v, size_t i, size_t len) {
	return i < v.size() ? T(v.begin() + i, v.begin() + min(i + len, v.size())) : T();
}
template <class T, class U = typename T::value_type> U Gcdv(const T& v) {
	return accumulate(next(v.begin()), v.end(), U(*v.begin()), gcd<U, U>);
}
template <class T, class U = typename T::value_type> U Lcmv(const T& v) {
	return accumulate(next(v.begin()), v.end(), U(*v.begin()), lcm<U, U>);
}
namespace internal {
	template <class T, size_t N> auto make_vector(vector<int>& sizes, const T& init) {
		if constexpr (N == 1) {
			return vector(sizes[0], init);
		} else {
			int size = sizes[N - 1];
			sizes.pop_back();
			return vector(size, make_vector<T, N - 1>(sizes, init));
		}
	}
}  // namespace internal
template <class T, size_t N>
auto make_vector(const int (&sizes)[N], const T& init = T()) {
	vector s(rbegin(sizes), rend(sizes));
	return internal::make_vector<T, N>(s, init);
}
#line 9 "/home/yuruhiya/programming/library/template/template.cpp"
#if __has_include(<library/dump.hpp>)
#include <library/dump.hpp>
#define LOCAL
#else
#define dump(...) ((void)0)
#endif

template <class T> constexpr T oj_local(const T& oj, const T& local) {
#ifndef LOCAL
	return oj;
#else
	return local;
#endif
}
#line 5 "/home/yuruhiya/programming/library/Math/modint.cpp"
using namespace std;

template <int MOD> struct modint {
	using T = long long;
	T n;
	constexpr modint(const T x = 0) : n(x % MOD) {
		if (n < 0) n += MOD;
	}
	constexpr int get_mod() const {
		return MOD;
	}
	constexpr modint operator+() const {
		return *this;
	}
	constexpr modint operator-() const {
		return n ? MOD - n : 0;
	}
	constexpr modint& operator++() {
		if (MOD <= ++n) n = 0;
		return *this;
	}
	constexpr modint& operator--() {
		if (n <= 0) n = MOD;
		n--;
		return *this;
	}
	constexpr modint operator++(int) {
		modint t = *this;
		++*this;
		return t;
	}
	constexpr modint operator--(int) {
		modint t = *this;
		--*this;
		return t;
	}
	constexpr modint next() const {
		return ++modint(*this);
	}
	constexpr modint pred() const {
		return --modint(*this);
	}
	constexpr modint operator+(const modint& m) const {
		return modint(*this) += m;
	}
	constexpr modint operator-(const modint& m) const {
		return modint(*this) -= m;
	}
	constexpr modint operator*(const modint& m) const {
		return modint(*this) *= m;
	}
	constexpr modint operator/(const modint& m) const {
		return modint(*this) /= m;
	}
	constexpr modint& operator+=(const modint& m) {
		n += m.n;
		if (n >= MOD) n -= MOD;
		return *this;
	}
	constexpr modint& operator-=(const modint& m) {
		n -= m.n;
		if (n < 0) n += MOD;
		return *this;
	}
	constexpr modint& operator*=(const modint& m) {
		n = n * m.n % MOD;
		return *this;
	}
	constexpr modint& operator/=(const modint& m) {
		T a = m.n, b = MOD, u = 1, v = 0;
		while (b) {
			T t = a / b;
			a -= t * b;
			swap(a, b);
			u -= t * v;
			swap(u, v);
		}
		n = n * u % MOD;
		if (n < 0) n += MOD;
		return *this;
	}
	constexpr bool operator==(const modint& m) const {
		return n == m.n;
	}
	constexpr bool operator!=(const modint& m) const {
		return n != m.n;
	}
	template <class M> constexpr modint pow(M m) const {
		if (0 <= m) {
			modint t = n, result = 1;
			while (m > 0) {
				if (m & 1) {
					result *= t;
					m--;
				} else {
					t *= t;
					m >>= 1;
				}
			}
			return result;
		} else {
			return (modint(1) / n).pow(-m);
		}
	}
	template <class M> constexpr modint operator^(M m) const {
		return pow(m);
	}
	friend ostream& operator<<(ostream& os, const modint<MOD>& m) {
		return os << m.n;
	}
	friend istream& operator>>(istream& is, modint<MOD>& m) {
		long long x;
		cin >> x;
		m = modint(x);
		return is;
	}
};
using mint = modint<1000000007>;
using VM = vector<mint>;
mint operator""_m(unsigned long long n) {
	return n;
}
#line 3 "a.cpp"

int main() {
	ini(n, l);
	VI x = in[n], a = in[n];
	reverse(all(x));
	reverse(all(a));

	auto dp = make_vector({n, l}, 0_m);
	rrep(i, l) {
		dp[0][i] = i + 1 < l ? dp[0][i + 1] : 0;
		if (i >= x[0] && a[0] ? ((i - x[0]) % a[0] == 0) : (i == x[0])) {
			dp[0][i]++;
		}
	}

	FOR(i, 1, n) {
		rrep(j, l - 1) {
			dp[i][j] = dp[i][j + 1];
			if (x[i] <= j && a[i] ? ((j - x[i]) % a[i] == 0) : (j == x[i])) {
				dp[i][j] += dp[i - 1][j + 1];
			}
		}
	}

	out(dp.back()[0]);
}
accuracy: 1
time_ms: 100
memory_kb: 198528
final_rank: 13

code_snippet: #include<iostream>
#include<vector>
using namespace std;
const int mod = 1e9 + 7;

int main(){
    int n, l;
    cin >> n >> l;
    vector<int> x(n), a(n);
    for(int i = 0; i < n; i++)  cin >> x[n-1-i];
    for(int i = 0; i < n; i++)  cin >> a[n-1-i];
    vector<vector<int>> dp(2, vector<int>(l+1, 0));
    for(int j = x[0]; j < l; j += a[0]){
        dp[0][j] = 1;
        if(a[0] == 0)   break;
    }
    for(int j = l-1; j >= 0; j--)  dp[0][j] = (dp[0][j] + dp[0][j+1])%mod;
    for(int i = 1; i < n; i++){
        fill(dp[i%2].begin(), dp[i%2].end(), 0);
        for(int j = x[i]; j < l; j += a[i]){
            dp[i%2][j] = dp[(i+1)%2][j+1];
            if(a[i] == 0)   break;
        } 
        for(int j = l-1; j >= 0; j--)   dp[i%2][j] = (dp[i%2][j] + dp[i%2][j+1])%mod;
    }
    cout << dp[(n+1)%2][0] << endl;
    return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 3244
final_rank: 5

code_snippet: #include<iostream>
#include<vector>
using namespace std;
const int mod = 1e9 + 7;

int main(){
    int n, l;
    cin >> n >> l;
    vector<int> x(n), a(n);
    for(int i = 0; i < n; i++)  cin >> x[n-1-i];
    for(int i = 0; i < n; i++)  cin >> a[n-1-i];
    vector<vector<int>> dp(2, vector<int>(l+1, 0));
    for(int j = x[0]; j < l; j += a[0]){
        dp[0][j] = 1;
        if(a[0] == 0)   break;
    }
    for(int j = l-1; j >= 0; j--)  dp[0][j] = (dp[0][j] + dp[0][j+1])%mod;
    for(int i = 1; i < n; i++){
        for(int j = x[i]; j < l; j += a[i]){
            dp[i%2][j] = dp[(i+1)%2][j+1];
            if(a[i] == 0)   break;
        } 
        for(int j = l-1; j >= 0; j--)   dp[i%2][j] = (dp[i%2][j] + dp[i%2][j+1])%mod;
    }
    cout << dp[(n+1)%2][0] << endl;
    return 0;
}
accuracy: 0.15
time_ms: 100
memory_kb: 3188
final_rank: 19