Advertisement
Guest User

Untitled

a guest
Jun 12th, 2016
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <set>
  5. #include <map>
  6. #include <stack>
  7. #include <cmath>
  8. #include <queue>
  9. #include <deque>
  10. #include <cassert>
  11. #include <string>
  12. #include <iomanip>
  13. using namespace std;
  14.  
  15. #define INF 1000000000
  16. #define lint long long
  17. #define mp make_pair
  18. #define pb push_back
  19. #define MOD 1000000007
  20.  
  21. int a[100005];
  22. int main()
  23. {
  24.     int n;
  25.     scanf("%d", &n);
  26.  
  27.     for (int i = 1; i <= n; ++i)
  28.     {
  29.         scanf("%d", &a[i]);
  30.     }
  31.  
  32.     int ans = a[1];
  33.     int sumOfProducts = a[1];
  34.     for (int i = 2; i <= n; ++i)
  35.     {
  36.         ans = (ans + ans*1ll*a[i] + a[i] + sumOfProducts * 1ll * a[i]) % MOD;
  37.         sumOfProducts = (sumOfProducts + sumOfProducts * 1ll * a[i] + a[i]) % MOD;
  38.     }
  39.  
  40.     printf("%d", ans);
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement