fork(4) download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7.  
  8. #define fi first
  9. #define se second
  10. #define mp make_pair
  11. #define pb push_back
  12. #define fbo find_by_order
  13. #define ook order_of_key
  14.  
  15. typedef long long ll;
  16. typedef pair<ll,ll> ii;
  17. typedef vector<ll> vi;
  18. typedef long double ld;
  19. typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
  20. typedef set<ll>::iterator sit;
  21. typedef map<ll,ll>::iterator mit;
  22.  
  23. const int MOD = 1e9 + 7;
  24. int main()
  25. {
  26. ios_base::sync_with_stdio(0); cin.tie(0);
  27. int t; cin>>t;
  28. while(t--)
  29. {
  30. int n; cin>>n;
  31. vector<ll> a(n);
  32. for(int i=0;i<n;i++) cin>>a[i];
  33. ll ans = 0;
  34. for(int i=0;i<n;i++)
  35. {
  36. for(int j=i+1;j<n;j++)
  37. {
  38. ans = (ans + (a[i]*a[j])%MOD)%MOD;
  39. }
  40. }
  41. ans%=MOD;
  42. if(ans<=0) ans+=MOD;
  43. cout<<ans<<'\n';
  44. }
  45. }
  46.  
Time limit exceeded #stdin #stdout 5s 4444KB
stdin
Standard input is empty
stdout
Standard output is empty