fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. ll n,dp[100005][2],a[100005],b[100005],ans = 0;
  5. const ll mod = 1e9 + 7;
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  9. memset(dp, 0, sizeof dp);
  10. cin >> n;
  11. for(int i = 1; i <= n; i++)
  12. cin >> a[i];
  13. for(int i = 2; i <= n; i++)
  14. cin >> b[i];
  15. dp[0][0] = 1;
  16. dp[0][1] = 0;
  17. for(int i = 1; i <= n; i++)
  18. {
  19. dp[i][0] = (dp[i-1][0]*(a[i] + b[i])%mod + dp[i-1][1]*(a[i]+b[i]-1)%mod)%mod;
  20. dp[i][1] = (dp[i-1][0]*b[i]%mod + dp[i-1][1]*b[i+1]%mod)%mod;
  21. cout << dp[i][0] << ' ' << dp[i][1] << '\n';
  22. }
  23. ans = dp[n][0] + dp[n][1];
  24. ans%=mod;
  25. cout << ans;
  26. }
  27.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
1