#pragma GCC target("avx2") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") #include using namespace std; const long long MOD = 1000000007; int main(){ int N; cin >> N; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } vector dp(N, 0); dp[0] = 1; vector> next(N); for (int i = 0; i < N; i++){ for (auto &P : next[i]){ dp[i] += P.second; if (i + P.first - 1 < N){ next[i + P.first - 1][P.first] += P.second; } } dp[i] %= MOD; if (i < N - 1 && A[i] != 1){ dp[i + 1] += dp[i]; if (dp[i + 1] >= MOD){ dp[i + 1] -= MOD; } } if (i + A[i] < N){ next[i + A[i]][A[i] + 1] += dp[i]; } } cout << dp[N - 1] << endl; }