Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- created: 2023-03-02-02.24.59
- ***/
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
- #define ll long long
- #define all(we) we.begin(),we.end()
- #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
- #define nl '\n'
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- test
- {
- ll n,m,i,j,k,l,mod=1e9+7;
- cin>>n;
- ll p[n+4]={0},s[n+4]={0};
- ll a[n+4];
- for(i=1;i<=n;i++)
- {
- cin>>a[i];
- p[i]=p[i-1]+a[i];
- p[i]%=mod;
- }
- for(i=n-1;i>0;i--)
- {
- m=(a[i]*(p[n]-p[i]+mod)%mod)%mod;
- s[i]=s[i+1]+m;
- s[i]%=mod;
- }
- l=0;
- for(i=1;i<n-1;i++)
- {
- l+=(a[i]*s[i+1])%mod;
- l%=mod;
- }
- cout<<l<<nl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement