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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  /* Input */
  long int N;
  cin >> N;

  vector<long int> A(N);
  rep(i, N) { cin >> A.at(i); }

  /* Main Logic */
  long long int sum = 0;
  long long int mod = 1000000007;

  long long int allSum = 0;
  for (int i = 0; i < N; i++) {
    allSum = (allSum + A.at(i)) % mod;
  }

  for (int i = 0; i < N - 1; i++) {
    allSum = allSum - A.at(i);
    if (allSum < 0)
      allSum = allSum + mod;

    sum = sum + ((A.at(i) * allSum) % mod);
  }

  long long int ans = sum % mod;
  /* Output */
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  /* Input */
  int N;
  cin >> N;

  vector<long int> A(N);
  rep(i, N) { cin >> A.at(i); }

  /* Main Logic */
  long int sum = 0;
  long int mod = 1000000007;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      sum = (sum + ((A.at(i) * A.at(j)) % mod)) % mod;
    }
  }
  int ans = sum % mod;
  /* Output */
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <math.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];

  ll sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }
  ll ans = 0;
  ll tmp1 = 0;
  ll tmp2 = 0;
  for (int i = 0; i < n - 1; i++) {
    sum -= a[i];
    tmp1 = sum % (1000000000 + 7);
    tmp2 = a[i] % (1000000000 + 7);
    ans += tmp1 * tmp2;
    ans = ans % (1000000000 + 7);
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <math.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];

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

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


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

int main() {
  int n;
  cin >> n;
  int val;
  vector<long long> v;
  int i;
  for (i = 0; i < n; i++) {
    cin >> val;
    v.push_back(val);
  }
  int long long ans = 0;
  int j;
  long long sum = 0;
  for (i = 0; i < n; i++) {
    sum = sum + v[i];
  }
  for (i = 0; i < n; i++) {
    sum = sum - v[i];
    ans = (ans + ((sum) % 1000000007 * (v[i] % 1000000007)) % 1000000007) %
          1000000007;
  }
  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:


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

int main() {
  int n;
  cin >> n;
  int val;
  vector<long long> v;
  int i;
  for (i = 0; i < n; i++) {
    cin >> val;
    v.push_back(val);
  }
  int long long ans = 0;
  int j;
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      ans = (ans + (v[i] * v[j])) % 1000000007;
    }
  }
  cout << ans;

  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<ll, ll>;
#define rep(i, n)                                                              \\
  ;                                                                            \\
  for (ll i = 0; i < (ll)n; i++)

int main() {
  ll n;
  cin >> n;
  ll mod = (ll)1e9 + 7;
  vector<ll> A(n), B(n + 1, 0);

  rep(i, n) {
    cin >> A[i];
    B[i + 1] = B[i] + A[i];
  }

  ll ans = 0;

  rep(i, n) {
    ll sum = (B[n] - B[i + 1]) % mod;
    ans += A[i] * sum;
    ans %= mod;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n)                                                              \\
  ;                                                                            \\
  for (int64_t i = 0; i < (ll)n; i++)

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

  rep(i, n - 1) {
    int64_t a = A[i];
    for (int64_t j = i + 1; j < n; j++) {
      int64_t k = a * A[j];
      k %= (int64_t)(1e9) + 7;
      ans += k;
      ans %= (int64_t)(1e9) + 7;
    }
  }
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define PI acos(-1)
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll mod = 1e9 + 7;

int main() {
  fast_io

      int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define PI acos(-1)
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll mod = 1e9 + 7;

int main() {
  fast_io

      int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

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

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  int64_t total = 0;
  int64_t at = 0;
  int mod = 1000000007;

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = N - 1; i > 0; i--) {
    at += A.at(i);
    at = at % mod;
    total += A.at(i - 1) * at % mod;
    total = total % mod;
  }
  cout << total << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  int64_t total = 0;
  int mod = 1000000007;

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    for (int j = 0; j < i; j++) {
      total += (A.at(i) * A.at(j)) % mod;
      total = total % mod;
    }
  }
  cout << total << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<long long> pref(n);
  for (int i = 0; i < n; i++) {
    if (i == 0)
      pref[i] = a[i];
    else
      pref[i] = pref[i - 1] + a[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[i] * ((pref[n - 1] - pref[i]) % mod) % mod;
    ans %= mod;
  }
  cout << ans << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += 1ll * a[i] * a[j] % mod;
      ans %= mod;
    }
  }
  cout << ans << "\\n";
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long int ull;
#define base 31
#define MOD 1000000007
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORs(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define __FOR(i, a, b, k) for (int i = a; i <= b; i += k)
#define __REP(i, a, b, k) for (int i = a; i < b; i += k)
#define pb push_back
#define _io                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define Read_ freopen("input.inp", "r", stdin)
#define Write_ freopen("output.out", "w", stdout);
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define fi first
#define se second
#define mp make_pair
#define N 200005
ull n, a[N], sum[N];
ull res;
int main() {
  _io;
  cin >> n;
  FOR(i, 1, n) cin >> a[i];
  sum[1] = a[1];
  FOR(i, 2, n) sum[i] = sum[i - 1] + a[i];
  // FOR(i,1,n) cout<<sum[i]<<" ";
  res = 0;
  ull mod = 1000000007;
  FOR(i, 1, n) {
    ull x = ((a[i] % mod) * ((sum[n] - sum[i]) % mod)) % mod;
    res += (x % (mod));
  }
  cout << res % mod;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long int ull;
#define base 31
#define MOD 1000000007
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORs(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define __FOR(i, a, b, k) for (int i = a; i <= b; i += k)
#define __REP(i, a, b, k) for (int i = a; i < b; i += k)
#define pb push_back
#define _io                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define Read_ freopen("input.inp", "r", stdin)
#define Write_ freopen("output.out", "w", stdout);
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;
#define fi first
#define se second
#define mp make_pair
#define N 100005
ull n, a[N], sum[N];
ull res;
int main() {
  _io;
  cin >> n;
  FOR(i, 1, n) cin >> a[i];
  sum[1] = a[1];
  FOR(i, 2, n) sum[i] = sum[i - 1] + a[i];
  // FOR(i,1,n) cout<<sum[i]<<" ";
  res = 0;
  ull mod = 1000000007;
  FOR(i, 1, n) {
    ull x = ((a[i] % mod) * ((sum[n] - sum[i]) % mod)) % mod;
    res += (x % (mod));
  }
  cout << res % mod;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  long long a[n];
  long long ans = 0;
  const int mod = 1000000007;
  long long sum = 0;
  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 += a[i] * sum;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
inline long long qr() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long mul(long long x, long long y) {
  int ans = 0;
  while (y) {
    if (y & 1)
      ans = (ans + x) % mod;
    y >>= 1;
    x = (x + x) % mod;
  }
  return ans;
}
int n;
const int maxn = 2e5 + 10;
long long a[maxn];
long long b[maxn];
long long ans;
int main() {
  n = qr();
  for (register int i = 1; i <= n; i++) {
    a[i] = qr();
    b[i] = (b[i] + b[i - 1] + a[i]);
  }
  for (register int i = 1; i < n; i++) {
    ans = (ans + mul(a[i], b[n] - b[i]) % mod) % mod;
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
inline long long qr() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long mul(long long x, long long y) {
  int ans = 0;
  while (y) {
    if (y & 1)
      ans = (ans + x) % mod;
    y >>= 1;
    x = (x + x) % mod;
  }
}
int n;
const int maxn = 2e5 + 10;
long long a[maxn];
long long b[maxn];
long long ans;
int main() {
  n = qr();
  for (register int i = 1; i <= n; i++) {
    a[i] = qr();
    b[i] = (b[i] + b[i - 1] + a[i]);
  }
  for (register int i = 1; i < n; i++) {
    ans = (ans + mul(a[i], b[n] - b[i]) % mod) % mod;
  }
  cout << ans;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  long long int A[200001], count = 0, ans = 0;
  long long int mod = 1000000007;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];

  for (int i = N - 1; i > 0; i--) {
    count = (count + A[i]) % mod;
    ans = (ans + count * A[i - 1]) % mod;
  }

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


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define empb emplace_back
#define mp make_pair
#define F first
#define S second
#define endl "\\n"
#define vii vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define mapii map<int, int>
#define mapll map<ll, ll>
#define all(a) a.begin(), a.end()
#define test                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define prec(n) fixed << setprecision(n)
#define ItsFun                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define mod 1000000007

// int minimumChar(string S1, string S2) {
//     int n = S1.size(), m = S2.size();

//     int ans = INT_MAX;
//     for (int i = 0; i < m - n + 1; i++) {
//         int minRemovedChar = 0;
//         for (int j = 0; j < n; j++) {
//             if (S1[j] != S2[i + j]) {
//                 minRemovedChar++;
//             }
//         }
//         ans = min(minRemovedChar, ans);
//     }
//     return ans;
// }

ll pairMultiply(vll &a, ll n) {
  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    for (ll j = i + 1; j < n; ++j) {
      ans += a[i] * a[j];
      ans %= mod;
    }
  }
  return ans;
}

int main() {
  ItsFun;

  ll n;
  cin >> n;
  vll a(n);

  for (auto &i : a)
    cin >> i;

  cout << pairMultiply(a, n) << "\\n";

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

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

int main() {
  long long n;
  cin >> n;
  long long a[n], b[n] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[0] = a[0];
    if (0 < i) {
      b[i] += b[i - 1] + a[i];
      b[i] %= 1000000007;
    }
  }
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    ans += a[i] * b[i - 1];
    ans %= 1000000007;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long M = 1e9 + 7;
  int n;
  cin >> n;
  int a[n];
  long long total = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    total += a[i];
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    total -= a[i];
    ans += ((a[i] % M) * (total % M)) % M;
  }
  ans = ans % M;
  cout << ans << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long M = 1e9 + 7;
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long long ans;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += ((a[i] % M) * (a[j] % M)) % M;
    }
  }
  ans = ans % M;
  cout << ans << '\\n';
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int64_t mod = 1e9 + 7;

int64_t solve1(int n, vector<int64_t> a) {
  int64_t res = 0;
  vector<int64_t> csum(n + 1, 0);
  csum[0] = 0;
  for (size_t i = 0; i < n; i++) {
    csum[i + 1] = csum[i] + a[i];
  }
  for (size_t i = 0; i < n; i++) {
    int64_t sum = (csum[n] - csum[i + 1]) % mod;
    res += a[i] * sum;
    res %= mod;
  }
  return res;
}

int64_t solve2(int n, vector<int64_t> a) {
  int64_t res = 0;
  for (size_t i = 0; i < n; i++) {
    for (size_t j = i + 1; j < n; j++) {
      res += a[i] * a[j];
      res %= mod;
    }
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<int64_t> a(n);
  for (auto &i : a)
    cin >> i;
  // printf("solve1: %lld\\nsolve2: %lld\\n", solve1(n, a), solve2(n, a));
  cout << solve1(n, a) << endl;
}


Error: TLE

Fixed submission:

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

const int64_t mod = 1e9 + 7;

int64_t solve1(int n, vector<int64_t> a) {}

int64_t solve2(int n, vector<int64_t> a) {
  int64_t res = 0;
  for (size_t i = 0; i < n; i++) {
    for (size_t j = i + 1; j < n; j++) {
      res += a[i] * a[j];
      res %= mod;
    }
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<int64_t> a(n);
  for (auto &i : a)
    cin >> i;
  cout << solve2(n, a) << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdlib.h>
#include <string>
#include <vector>

#define PI 3.14159265358979
#define MOD 1000000007

// fixed << setprecision(15) <<

using namespace std;

int main(void) {
  long long int n, m, max;
  int i, j;
  int e[200000];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> e[i];
  }
  max = 0;
  m = 0;
  for (i = n - 1; i > 0; i--) {
    m += e[i];
    m %= MOD;
    max += e[i - 1] * m;
    max %= MOD;
  }
  cout << max << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stdlib.h>
#include <string>
#include <vector>

#define PI 3.14159265358979
#define MOD 1000000007

// fixed << setprecision(15) <<

using namespace std;

int main(void) {
  long long int n, m, max;
  int i, j;
  int e[200000];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> e[i];
  }
  max = 0;
  for (i = 0; i < n - 1; i++) {
    m = 0;
    for (j = i + 1; j < n; j++) {
      m += e[j];
    }
    max += e[i] * (m % MOD);
    max %= MOD;
  }
  cout << max << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

int main() {
  int N;
  long long int A[200001], count = 0, ans = 0;
  long long int mod = 1000000007;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];

  for (int i = N - 1; i > 0; i--) {
    count = (count + A[i]) % mod;
    ans = (ans + count * A[i - 1]) % mod;
  }

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

Error: TLE

Fixed submission:

#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

int main() {
  int N;
  long long int A[200001], ans = 0;
  cin >> N;
  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++) {
      ans += (A[i] * A[j]) % 1000000007;
      if (ans > 1000000007)
        ans %= 1000000007;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define pb push_back
#define M 1000000007
unordered_map<ll, ll> mp;

int main() {
  fastIO ll n;
  cin >> n;
  ll v[n + 1];
  for (ll i = 1; i <= n; i++) {
    cin >> v[i];
  }
  ll suf[n + 2];
  suf[n + 1] = 0;
  for (int i = n; i >= 1; i--)
    suf[i] = (v[i] + suf[i + 1]) % M;
  ll res = 0;
  for (ll i = 1; i <= n; i++) {
    ll x = (v[i] * suf[i + 1]) % M;
    res = (res + x) % M;
  }
  cout << res;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define pb push_back
#define M 1000000007
unordered_map<ll, ll> mp;

int main() {
  fastIO ll n;
  cin >> n;
  vector<ll> v;
  for (ll i = 0; i < n; i++) {
    ll e;
    cin >> e;
    v.pb(e);
  }
  ll res = 0;
  for (ll i = 0; i < n; i++) {
    for (ll j = i + 1; j < n; j++) {
      ll x = (v[i] * v[j]) % M;
      res = (res + x) % M;
    }
  }
  cout << res;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] %= INF;
    sum += A[i];
    sum %= INF;
  }

  ll ans = 0;
  for (int i = N - 1; i > 0; i--) {
    sum -= A[i];
    sum %= INF;
    if (sum < 0)
      ans += INF;
    ll temp = sum * A[i];
    temp %= INF;
    ans += temp;
    ans %= INF;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] %= INF;
  }

  ll ans = 0;
  for (int i = 0; i < N - 1; i++) {
    if (A[i] == 0)
      continue;
    for (int j = i + 1; j < N; j++) {
      ll temp = A[i] * A[j];
      temp %= INF;
      ans += temp;
      ans %= INF;
    }
  }
  cout << ans << endl;
  return 0;
}