alexjercan/bugnet huggingface dataset:
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<long long int>
#define pb push_back
#define f(i, x, n) for (i = x; i < n; i++)

#define mx 1000000007
ll prod(ll temp, ll x) {
  if (temp < x)
    swap(temp, x);
  if (x == 0)
    return 0;
  ll y = temp;
  for (ll i = 1; i < x; i++) {
    temp = (temp + y) % mx;
  }
  return temp;
}
void solve() {
  ll n;
  cin >> n;
  ll a[n];
  ll sum = 0;
  ll ans = 0;
  ll pref[n + 1];
  pref[0] = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    ans = (ans + (sum * a[i]) % mx) % mx;
    sum = (sum + a[i]) % mx;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--)
    solve();
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<long long int>
#define pb push_back
#define f(i, x, n) for (i = x; i < n; i++)

#define mx 1000000007
ll prod(ll temp, ll x) {
  if (temp < x)
    swap(temp, x);
  if (x == 0)
    return 0;
  ll y = temp;
  for (ll i = 1; i < x; i++) {
    temp = (temp + y) % mx;
  }
  return temp;
}
void solve() {
  ll n;
  cin >> n;
  ll a[n];
  ll sum = 0;
  ll ans = 0;
  ll pref[n + 1];
  pref[0] = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    sum = (sum + a[i]) % mx;
    pref[i + 1] = sum;
  }
  for (int i = 0; i < n; i++) {
    ans = (ans + prod(pref[i], a[i])) % mx;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--)
    solve();
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;
struct aaa {
  aaa() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(21);
  };
} aaa;
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
#define debug(v)                                                               \\
  { cerr << "\\033[1;36m[debug]\\033[m " << #v << " : " << v << endl; }

using int64 = long long;
int64 mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int64> a(n);
  vector<int64> csum(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int64 ans = 0;

  int64 res = 0;
  for (int i = n - 1; i >= 0; i--) {
    csum[i] = res;
    res += a[i] % mod;
    res %= mod;
  }
  for (int i = 0; i < n; i++) {
    ans += a[i] * csum[i] % mod;
  }
  ans %= mod;
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;
struct aaa {
  aaa() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(21);
  };
} aaa;
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
#define debug(v)                                                               \\
  { cerr << "\\033[1;36m[debug]\\033[m " << #v << " : " << v << endl; }

using int64 = long long;
int64 mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int64> a(n);
  vector<int64> csum(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int64 ans = 0;

  int64 res = 0;
  for (int i = n - 1; i >= 0; i--) {
    csum[i] = res % mod;
    res += a[i] % mod;
    debug(csum);
  }
  for (int i = 0; i < n; i++) {
    ans += a[i] * csum[i] % mod;
    debug(ans);
  }
  ans %= mod;
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef set<int> se;
typedef long long ll;
#define endl "\\n"

#define mod 1000000007

int main() {

  ll n;
  cin >> n;
  ll arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  ll sum[n];
  sum[n - 1] = arr[n - 1]; //
  for (int i = n - 2; i >= 0; i--)
    sum[i] = (sum[i + 1] + arr[i]) % mod;

  ll res = 0;
  for (int i = 0; i < n - 1; i++)
    res = (res % mod + (sum[i + 1] * arr[i]) % mod) % mod;

  cout << res << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef set<int> se;
#define endl "\\n"
#define for(i, a, b) for (long long int i = a; i < b; i++)

#define mod 1000000007

int main() {

  long long int n;
  cin >> n;
  long long int a[n];
  for (i, 0, n)
    cin >> a[i];
  long long int res = 0;

  for (i, 0, n - 1) {
    for (j, i + 1, n) {
      res = (res % mod) + (a[i] * a[j]) % mod;
    }
  }
  cout << res << endl;

  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for (auto &i : mp)

const int INF = 1001001001;
const ll MOD = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0;
  // for (int i = 0; i < a.size() - 1; i++) {
  //   for (int j = i + 1; j < a.size(); j++) {
  //     ans += a[i] * a[j];
  //     ans %= MOD;
  //   }
  // }
  // vector <int> s(n + 1, 0); // s[0] = 0 になる
  // string s[n + 1];
  // for (int i = 0; i < n; ++i) { s[i + 1] =  atoi(s[i].c_str()) + atoi(a[i]);
  // }
  // // reverse(s.begin(), s.end());
  // for (int i = 0; i < a.size() - 1; i++) {
  //   ans += a[i] * (stoi(s[n]) - stoi(s[i + 1]));
  //   ans %= MOD;
  // }

  vector<ll> s(n + 1, 0); // s[0] = 0 になる
  vector<ll> tmp(n);
  rep(i, n) tmp[i] = a[i];
  reverse(tmp.begin(), tmp.end());
  for (int i = 0; i < n; ++i) {
    s[i + 1] = (s[i] + (tmp[i] % MOD)) % MOD;
  }
  // for (int i = 0; i < n; ++i) { s[i + 1] = (s[i] + (a[i] % MOD)) % MOD; }
  for (int i = 0; i < n - 1; i++) {
    // ans += (a[i] % MOD) * (s[n] - s[i + 1]);
    ans += (a[i] % MOD) * (s[n - (i + 1)]);
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for (auto &i : mp)

const int INF = 1001001001;
const ll MOD = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0;
  for (int i = 0; i < a.size() - 1; i++) {
    for (int j = i + 1; j < a.size(); j++) {
      ans += a[i] * a[j];
      ans %= MOD;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
  //    ios_base::sync_with_stdio(false);
  //    cin.tie(0);
  int n;
  ll a[200005], sum;
  ll mod = 1e9 + 7;

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = (ans + a[i] * sum) % mod;
    sum += a[i];
    sum %= mod;
  }
  cout << ans;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

// required function
int findProductSum(int A[], int n) {
  int array_sum = 0;
  for (int i = 0; i < n; i++)
    array_sum = array_sum + A[i];

  int array_sum_square = array_sum * array_sum;
  int individual_square_sum = 0;
  for (int i = 0; i < n; i++)
    individual_square_sum += A[i] * A[i];

  return (array_sum_square - individual_square_sum) / 2;
}

// Driver code
int main() {
  long long int n, i, j;
  int arr[100000];
  cin >> n;

  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  cout << findProductSum(arr, n) << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  vector<uintmax_t> a;
  uintmax_t add_sum, r_sum = 0, divider = pow(10, 9) + 7;

  cin >> n;
  for (int i = 0; i < n; i++) {
    uintmax_t tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  sort(a.begin(), a.end());

  add_sum = a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    r_sum += a[i] * add_sum % divider;
    add_sum += a[i];
    r_sum %= divider;
    add_sum %= divider;
  }

  cout << r_sum << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  vector<uintmax_t> a;
  uintmax_t sum = 0, divider = pow(10, 9) + 7;

  cin >> n;
  for (int i = 0; i < n; i++) {
    uintmax_t tmp;
    cin >> tmp;
    a.push_back(tmp % divider);
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += a[i] * a[j];
      sum %= divider;
    }
  }
  cout << sum << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vb = vector<bool>;
using vs = vector<string>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const ld eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
#define TR(X)                                                                  \\
  ({                                                                           \\
    if (1)                                                                     \\
      cerr << "TR: " << (#X) << " = " << (X) << endl;                          \\
  })
#define modadd(a, b) (a + b) % (1000000007)
#define modmul(a, b) (a * b) % (1000000007)

int main() {
  cin.sync_with_stdio(0);

  vl in;
  ll n;
  cin >> n;
  ll l;
  FOR(i, 0, n) {
    cin >> l;
    in.pb(l);
  }

  ll tailsum = 0;
  ll sum = 0;

  FORD(i, 0, n - 1) {
    tailsum = modadd(tailsum, in[i + 1]);
    sum = modadd(sum, modmul(in[i], tailsum));
  }

  cout << sum << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vb = vector<bool>;
using vs = vector<string>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const ld eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
#define TR(X)                                                                  \\
  ({                                                                           \\
    if (1)                                                                     \\
      cerr << "TR: " << (#X) << " = " << (X) << endl;                          \\
  })
#define modadd(a, b) (a + b) % (1000000007)

int main() {
  cin.sync_with_stdio(0);

  vl in;
  ll n;
  cin >> n;
  ll l;
  FOR(i, 0, n) {
    cin >> l;
    in.pb(l);
  }

  ll sum = 0;

  FOR(i, 0, n - 1) {
    FOR(j, i + 1, n) { sum = modadd(sum, (in[i] * in[j])); }
  }

  cout << sum << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
typedef long long ll;
const int inf = 1e9;
using namespace std;
const ll mod = 1e9 + 7;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  ll n;
  cin >> n;
  ll a[n];
  for (ll i = 1; i <= n; i++)
    cin >> a[i];

  ll ans = 0;
  ll s = 0;
  for (int i = 1; i <= n; i++) {
    ans += s * a[i];
    s += a[i];
    s %= mod;
    ans %= mod;
  }
  cout << ans << '\\n';

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
const int inf = 1e9;
using namespace std;
const int mod = 1e9 + 7;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  ll n;
  cin >> n;
  ll a[n];
  for (ll i = 1; i <= n; i++)
    cin >> a[i];

  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    for (ll j = i + 1; j <= n; j++) {
      ans += a[i] * a[j];
      ans %= mod;
    }
  }
  cout << ans << '\\n';

  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007

int main(void) {
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    b[i] = a[i];

  b[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; i--)
    b[i] = (a[i] + b[i + 1]) % MOD;

  ll ans = 0, tmp;
  for (int i = 0; i < n - 1; i++) {
    tmp = a[i] * b[i + 1] % MOD;
    ans = (ans + tmp) % MOD;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007

int main(void) {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  ll ans = 0, tmp;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      tmp = a[i] * a[j] % MOD;
      ans = (ans + tmp) % MOD;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<ll> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vii;
const double pi = 2 * acos(0);

#define pf printf
#define sf scanf
#define pb(a) push_back(a)
#define mp make_pair
#define ff first
#define ss second
#define for0(i, n) for (ll i = 0; i < n; i++)
#define for1(i, n) for (ll i = 1; i <= n; i++)
#define forab(i, a, b) for (int i = a; i <= b; i++)
#define lcm(a, b) ((a) * ((b) / gcd(a, b)))
#define sq(a) (a) * (a)
#define endl "\\n"
#define abs(x) fabs(x)
#define all(v) v.begin(), v.end()
#define pcase(z, x) cout << "Case " << z << ": " << x << "\\n"
#define mod 1000000007
#define WakandaForever                                                         \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);

int main() {
  WakandaForever ll n, sum = 0;
  cin >> n;
  vi a(n), suf(n + 1);
  for0(i, n) cin >> a[i];
  suf[n] = 0;
  for (ll i = n - 1; i >= 0; i--) {
    suf[i] = (a[i] + suf[i + 1]) % mod;
  }
  for0(i, n) {
    ll x = (a[i] % mod * suf[i + 1] % mod) % mod;
    sum = (sum + x) % mod;
  }

  cout << sum << endl;

  return 0;
}


Error: TLE

Fixed submission:

// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<ll> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vii;
const double pi = 2 * acos(0);

#define pf printf
#define sf scanf
#define pb(a) push_back(a)
#define mp make_pair
#define ff first
#define ss second
#define for0(i, n) for (ll i = 0; i < n; i++)
#define for1(i, n) for (ll i = 1; i <= n; i++)
#define forab(i, a, b) for (int i = a; i <= b; i++)
#define lcm(a, b) ((a) * ((b) / gcd(a, b)))
#define sq(a) (a) * (a)
#define endl "\\n"
#define abs(x) fabs(x)
#define all(v) v.begin(), v.end()
#define pcase(z, x) cout << "Case " << z << ": " << x << "\\n"
#define mod 1000000007
#define WakandaForever                                                         \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);

int main() {
  WakandaForever ll n, sum = 0;
  cin >> n;
  vi a(n);
  for0(i, n) cin >> a[i];
  for0(i, n - 1) {
    for (int j = i + 1; j < n; j++) {
      ll x = ((a[i] % mod) * (a[j] % mod)) % mod;
      sum = (sum + x) % mod;
    }
  }
  cout << (sum + mod) % mod << endl;

  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) x.begin(), x.end()
using namespace std;
const int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> s(n);
  s[0] = a[0];
  ll ans = 0;
  for (int i = 1; i < n; ++i) {
    s[i] = s[i - 1] + a[i];
    s[i] %= MOD;
  }
  rep(i, n) {
    if (s[n - 1] - s[i] < 0)
      s[n - 1] += MOD;
    ans += a[i] * (s[n - 1] - s[i]);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) x.begin(), x.end()
using namespace std;
const int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<long long> a(n);
  rep(i, n) cin >> a[i];
  long long ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      ans += ((a[i] % MOD) * (a[j] % MOD)) % MOD;
      ans %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  int m = 1000000007;
  int n;
  cin >> n;

  vector<int> v(n);
  long long sumN = 0;
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
    sumN += v.at(i);
  }

  long long sum = 0;
  for (int i = 0; i < n - 1; i++) {
    sum += (sumN - v.at(i)) % m * (long long)v.at(i) % m;
    sumN -= (long long)v.at(i);
  }

  cout << sum % m << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int m = 1000000007;
  int n;
  cin >> n;

  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v.at(i);

  long long sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += (long long)v.at(i) * v.at(j) % m;
      sum %= m;
    }
  }

  cout << sum << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <fstream>
#include <iostream>

using namespace std;

int main() {
  int N, mod;
  long long ans = 0, sum = 0;
  cin >> N;
  long long A[N];
  mod = 1000000007;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  sum %= mod;
  for (int i = 0; i < N; i++) {
    sum -= A[i];
    if (sum < 0) {
      sum += mod;
    }
    ans += (sum * A[i]);
    ans %= mod;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <fstream>
#include <iostream>

using namespace std;

int main() {
  int N, mod;
  long long num_sum = 0, m;
  cin >> N;
  long long A[N];
  mod = 1000000007;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      m = (A[i] * A[j]) % mod;
      num_sum += m;
      num_sum %= mod;
    }
  }
  cout << num_sum << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define Mid ((l + r) / 2)
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define drep(i, a, b) for (int i = (a); i >= (b); --i)
#define file(a) freopen(#a ".in", "r", stdin), freopen(#a ".out", "w", stdout);
const int maxn = 2e5 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f;
int n, m, Q, K, T;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int a[maxn];
int dsum[maxn];

signed main() {
  // file(a);
  n = read();
  rep(i, 1, n) a[i] = read();
  dsum[n] = a[n];
  drep(i, n - 1, 1) dsum[i] = (dsum[i + 1] + a[i]) % mod;
  int ans = 0;
  rep(i, 1, n - 1) { ans = (ans + 1ll * a[i] * dsum[i + 1] % mod) % mod; }
  printf("%lld\\n", ans);

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define Mid ((l + r) / 2)
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define drep(i, a, b) for (int i = (a); i >= (b); --i)
#define file(a) freopen(#a ".in", "r", stdin), freopen(#a ".out", "w", stdout);
const int maxn = 1e5 + 5, mod = 1e9 + 7, inf = 0x3f3f3f3f;
int n, m, Q, K, T;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int a[maxn];
int dsum[maxn];

signed main() {
  // file(a);
  n = read();
  rep(i, 1, n) a[i] = read();
  dsum[n] = a[n];
  drep(i, n - 1, 1) dsum[i] = (dsum[i + 1] + a[i]) % mod;
  int ans = 0;
  rep(i, 1, n - 1) { ans = (ans + 1ll * a[i] * dsum[i + 1] % mod) % mod; }
  printf("%lld\\n", ans);

  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; // 最大値

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main() {
  ll n;
  cin >> n;
  vector<ll> A(n);

  ll ans = 0, res = 0;
  rep(i, n) {
    cin >> A[i];
    res += A[i];
  }

  rep(i, n) {
    res -= A[i];
    ll tmp = res % MOD;
    ans += tmp * A[i];
    ans %= MOD;
  }

  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; // 最大値

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main() {
  ll n;
  cin >> n;
  vector<ll> A(n);
  rep(i, n) cin >> A[i];

  ll ans = 0;
  rep(i, n) {
    for (int j = i + 1; j < n; j++) {
      ans += A[i] * A[j];
      ans %= MOD;
    }
  }

  cout << ans << endl;
  return 0;
}