Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
        ARIJIT SUR
        @duke_knight
        @surcode
    @comeback
        IIT ISM
 */
#include <bits/stdc++.h>
#define SIZE 100008
#define mod (ll)(1e9 + 7)
#define INF 0x3f3f3f3f
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define abs(a) (a > 0 ? a : -a)
#define all(a) a.begin(), a.end()
#define vll vector<ll>
#define maxelem(a) *max_element(all(a))
#define minelem(a) *min_element(all(a))
#define pb push_back
#define pi pair<int, int>
#define sort(a) sort(all(a))
#define reverse(a) reverse(all(a))
#define input(a)                                                               \\
  {                                                                            \\
    for (int i1 = 0; i1 < a.size(); i1++)                                      \\
      cin >> a[i1];                                                            \\
  }
#define repf(i, a, b) for (i = a; i < b; i++)
#define repb(i, a, b) for (i = a; i >= b; i--)
#define display(a)                                                             \\
  {                                                                            \\
    for (int i1 = 0; i1 < a.size(); i1++)                                      \\
      cout << a[i1] << " ";                                                    \\
    cout << endl;                                                              \\
  }
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
typedef long long ll;
void solve() {
  int i, n;
  cin >> n;
  vll a(n + 1, 0);
  // a[0]=0;
  repf(i, 1, n + 1) cin >> a[i];
  ll b = 0;
  ll ans = 0;
  ans = ans + a[i] * b;
  repb(i, n, 1) {
    // ans = (ans%mod+((a[i]%mod)*(b%mod))%mod)%mod;
    ans = (ans + ((a[i] % mod) * (b % mod)) % mod) % mod;
    // cout<<ans<<"\\n";
    b += a[i];
  }
  cout << ans;
}
int main() {
  IOS int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

/*
        ARIJIT SUR
        @duke_knight
        @surcode
    @comeback
        IIT ISM
 */
#include <bits/stdc++.h>
#define SIZE 100008
#define mod (ll)(1e9 + 7)
#define INF 0x3f3f3f3f
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define abs(a) (a > 0 ? a : -a)
#define all(a) a.begin(), a.end()
#define maxelem(a) *max_element(all(a))
#define minelem(a) *min_element(all(a))
#define pb push_back
#define pi pair<int, int>
#define sort(a) sort(all(a))
#define reverse(a) reverse(all(a))
#define input(a)                                                               \\
  {                                                                            \\
    for (int i1 = 0; i1 < a.size(); i1++)                                      \\
      cin >> a[i1];                                                            \\
  }
#define display(a)                                                             \\
  {                                                                            \\
    for (int i1 = 0; i1 < a.size(); i1++)                                      \\
      cout << a[i1] << " ";                                                    \\
    cout << endl;                                                              \\
  }
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
using namespace std;
typedef long long ll;
void solve() {
  int n;
  cin >> n;
  ll sum = 0;
  vector<ll> a(n);
  input(a);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      sum = (sum + (a[i] * a[j]) % mod) % mod;
    }
  }
  cout << sum << endl;
}
int main() {
  IOS int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}