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

#include <iostream>
#include <stdio.h>

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;

  cin >> n;

  vector<long long> arr(n);

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

  vector<long long> sum(n + 1);
  sum[0] = 0;

  for (int i = 0; i < n; i++) {
    sum[i + 1] = (sum[i] + arr[i]) % 1000000007;
  }

  long long ans = 0;

  for (int i = 0; i < n - 1; i++) {
    ans += ((arr[i] % 1000000007) * (sum[n] - sum[i + 1])) % 1000000007;
    ans = ans % 1000000007;
  }

  if (ans < 0)
    ans = ans + 1000000007;

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstring>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  vector<long long> arr(n);

  for (int i = 0; i < n; i++)
    cin >> arr[i];

  long long ans = 0;

  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = ans + (arr[i] * arr[j]) % 1000000007;
    }
  }

  long long ans1 = ans;

  while (1) {
    if (ans1 < 1000000007)
      break;
    ans1 = ans / 1000000007;
    ans = ans % 1000000007;
  }

  cout << ans << endl;

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

// A.cpp : このファイルには 'main'
// 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  const long long waru = 1000000007;
  cin >> n;

  vector<long long> a(n);
  long long ans = 0;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }

  for (int i = 0; i < n; i++) {
    // for (int j = i+1; j < n; j++) {
    //     ans += (a[i] * a[j]) % waru;

    //    ans = ans % waru;
    //}
    sum -= a[i];
    ans += (a[i] * (sum % waru)) % waru;
    ans %= waru;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

// A.cpp : このファイルには 'main'
// 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  const long long waru = 1000000007;
  cin >> n;

  vector<long long> a(n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += (a[i] * a[j]) % waru;

      ans = ans % waru;
    }
  }

  cout << ans << endl;

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

#include <iostream>
#define int long long

using namespace std;

const int Num = 2e5 + 10;
const int Mod = 1e9 + 7;

int a[Num];

signed main() {
  int n;
  cin >> n;

  int sum = 0;
  for (int i = 1; i <= n; ++i)
    cin >> a[i], sum += a[i];

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

  cout << ans << '\\n';

  return 0;
}


Error: 30

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  unsigned long long int sum = 0;
  cin >> n;

  unsigned long long int arr[n];

  for (int i = 0; i < n; i++)
    cin >> arr[i];

  for (int j = 0; j < n; j++) {
    for (int k = 1; k < n; k++) {
      sum = sum + arr[j] * arr[k];
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) for (int i = 0; i < n; i++)
void solve() {
  int n;
  cin >> n;
  lli a[n];
  lli sum = 0;
  lli mod = 1e9 + 7;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
    sum %= mod;
  }
  lli ans = 0;
  for (int i = 0; i < n; i++) {
    sum -= a[i];
    if (sum < 0)
      sum += mod;
    ans += (sum * a[i]);
    ans %= mod;
  }
  cout << ans << endl;
}
int main() {
  int t;
  // cin>>t;

  t = 1;
  while (t--) {
    solve();
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) for (int i = 0; i < n; i++)
void solve() {
  int n;
  cin >> n;
  lli a[n];
  rep(i, n) cin >> a[i];
  lli ans = 0;
  lli mod = 1e9 + 7;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = (ans + (a[i] * a[j]) % mod) % mod;
    }
  }
  cout << ans % mod << endl;
}
int main() {
  int t;
  // cin>>t;

  t = 1;
  while (t--) {
    solve();
  }
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1000000007;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, x;
  cin >> n;
  ll sum1 = 0, sum2 = 0;
  for (ll i = 0; i < n; i++) {
    cin >> x;
    sum1 = (sum1 + sum2 * x) % mod;
    sum2 = (sum2 + x) % mod;
  }
  cout << (sum1) % mod;

  return 0;
}

Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = 1000000007;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> d(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  ll sum = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum = (sum + d[i] * d[j]) % MOD;
    }
  }
  cout << (sum + MOD) % MOD;

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

#include <iostream>
#define ll long long

using namespace std;
int n;
const int NMAX = 200005;
const ll MOD = 1e9 + 7;
ll v[NMAX];
ll sp[NMAX];
ll s = 0;

int main() {
  cin >> n;
  sp[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    sp[i] = v[i];
    sp[i] += sp[i - 1];
    sp[i] %= MOD;
  }
  for (int i = 1; i <= n; i++) {
    int x = sp[i] - v[i];
    while (x <= 0)
      x += MOD;
    s += x * v[i];
    s %= MOD;
  }
  s %= MOD;
  cout << s;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#define ll long long

using namespace std;
int n;
const int NMAX = 200005;
const ll MOD = 1e9 + 7;
ll v[NMAX];
ll s = 0;

int main() {
  cin >> n >> v[1];
  for (int i = 2; i <= n; i++) {
    cin >> v[i];
    s += (ll)v[i] * v[1];
    s %= MOD;
  }
  s %= MOD;
  for (int i = 2; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      s += (ll)v[i] * v[j];
      s %= MOD;
    }
  }
  s %= MOD;
  cout << s;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
const ld pi = 3.14159265358979323846;
const ll mod = 1000000007;
const ll inf = 1LL << 60;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) { cin >> a[i]; }
  vector<ll> s(n + 1, 0); // 累積和
  rep(i, n) { s[i + 1] = s[i] + a[i]; }
  ll ans = 0;
  rep(i, n - 1) {
    ll sum = (s[n] - s[i + 1]) % mod;
    ans += a[i] * sum;
    ans %= mod;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
const ld pi = 3.14159265358979323846;
const ll mod = 1000000007;
const ll inf = 1LL << 60;

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

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

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

    if (sum - A[i] < 0) {
      ans = (ans + (A[i] % 1000000007) *
                       ((sum + 1000000007 - A[i]) % 1000000007) % 1000000007) %
            1000000007;
      sum = (sum + 1000000007 - A[i]) % 1000000007;
    } else {
      ans = (ans +
             (A[i] % 1000000007) * ((sum - A[i]) % 1000000007) % 1000000007) %
            1000000007;
      sum = (sum - A[i]) % 1000000007;
    }
  }

  cout << ans % 1000000007;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    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] % 1000000007;
      ans %= 1000000007;
    }
  }

  cout << ans % 1000000007;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)

using ll = long long;
#define int ll
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

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

  int n;
  cin >> n;

  vector<int> a(n + 2, 0);
  rep(i, n) { cin >> a[i]; }
  vector<int> cumsum(n + 2, 0);

  REP(i, 0, n) { cumsum[i + 1] = (cumsum[i] + a[i]) % mod; }
  int res = 0;
  rep(i, n - 1) {
    res += ((cumsum[n] - cumsum[i + 1] + mod) % mod) * a[i] % mod;
    res = res % mod;
  }

  cout << res << "\\n";
}

Error: 0

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)

using ll = long long;
#define int ll
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

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

  int a[10010];
  int n;
  cin >> n;
  rep(i, n) { cin >> a[i]; }

  int cumsum[10010] = {};

  REP(i, 0, n) { cumsum[i + 1] = (cumsum[i] + a[i]) % mod; }
  int res = 0;
  rep(i, n - 1) {
    res += a[i] * (cumsum[n] - cumsum[i + 1]) % mod;
    res %= mod;
  }
  cout << res << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define Imposter                                                               \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pb push_back
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set                                                            \\
  tree<ll, null_type, less_equal<ll>, rb_tree_tag,                             \\
       tree_order_statistics_node_update> // s.order_of_key(val)
                                          // *s.find_by_order(ind)
using namespace std;
#define f(n) for (ll i = 0; i < n; i++)
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define input(arr, n)                                                          \\
  for (ll i1 = 0; i1 < n; i1++)                                                \\
  cin >> arr[i1]
#define endl "\\n"
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(), x.end()
vector<int> cmp;
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void dfs(int i, vector<bool> &vis, vector<int> adj[]) {
  vis[i] = 1;
  cmp.pb(i);
  for (int child : adj[i]) {
    if (!vis[child])
      dfs(child, vis, adj);
  }
}
int main() {
  Imposter

      int t = 1;
  // cin>>t;
  while (t--) {
    ll p = 1e9 + 7;
    ll n;
    cin >> n;
    ll a[n];
    input(a, n);
    ll suff[n];
    suff[n - 1] = 0;
    for (int i = n - 2; i >= 0; i--) {
      suff[i] = (suff[i + 1] + a[i + 1]) % p;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ans = ((ans % p) + ((a[i] * suff[i]) % p)) % p;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#define ll long long int
ll mod = 1000000007;
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
ll findProductSum(ll A[], ll n) {
  ll product = 0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      product = ((product % mod) + (A[i] * A[j]) % mod) % mod;
  product = product % mod;
  return product;
}
// Driver code
int main() {
  ll n;
  cin >> n;
  ll A[n];
  for (int i = 0; i < n; i++)
    cin >> A[i];
  cout << findProductSum(A, n) % mod;
  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;
typedef long long ll;

const ll MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N), B(N);
  REP(i, N) {
    cin >> A[i];
    B[i] = A[i];
  }
  for (int i = N - 1; i > 0; i--) {
    B[i - 1] = (B[i - 1] + B[i]) % MOD;
  }

  ll ans = 0;
  for (int i = 0; i < N - 1; i++) {
    ans = (ans + (A[i] * B[i + 1] % MOD)) % MOD;
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

const ll MOD = 1000000007;

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

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

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

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

int mod = 1e9 + 7;

void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<ll> suffix(n + 1);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  for (int i = n - 1; i >= 0; --i) {
    suffix[i] = (v[i] + suffix[i + 1]) % mod;
  }
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = ((ans % mod) + (v[i] * suffix[i + 1] % mod) % mod);
  }
  cout << ans << '\\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}

Error: TLE

Fixed submission:

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

int mod = 1e9 + 7;

void solve() {
  int n;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      ll prod = v[i] * v[j] % mod;
      if (prod > mod)
        prod %= mod;
      ans = (ans + prod) % mod;
    }
  }
  cout << ans << '\\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  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++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define INF 1e9

using namespace std;

int N;

int main(void) {
  cin >> N;
  // vector<unsigned long long> A;
  vector<unsigned long long> A(N, 0ULL);
  rep(i, N) {
    cin >> A[i];
    // A.push_back(1000000000ULL);
  }

  unsigned long long sum = 0ULL;
  unsigned long long max = accumulate(A.begin(), A.end(), 0ULL);
  unsigned long long mod = (unsigned long long)pow(10, 9) + 7ULL;

  for (int i = 0; i < N - 1; i++) {
    max -= A[i];
    sum += (A[i] % mod) * (max % mod);
    sum %= mod;
  }

  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define INF 1e9

using namespace std;

int N;

int main(void) {
  cin >> N;
  vector<long long> A(N, 0);
  rep(i, N) { cin >> A[i]; }

  long long sum = 0;
  long long mod = pow(10, 9) + 7;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      sum += A[i] * A[j];
      sum %= mod;
    }
  }

  cout << sum << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \\
  {}
#define ARDEB(i, X)                                                            \\
  {}
#define END                                                                    \\
  {}
#endif
// typedef long long int ll;
typedef pair<int, int> P;
struct edge {
  int to, cost;
};
int ceil2(int a, int b) {
  if (a % b) {
    return a / b + 1;
  } else {
    return a / b;
  }
}
int n, k, ans, sum;
int a[211111];
signed main() {
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  sum %= MOD;
  rep(i, n) {
    sum -= a[i];
    sum = (sum + MOD) % MOD;
    ans += a[i] * sum;
    ans %= MOD;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \\
  {}
#define ARDEB(i, X)                                                            \\
  {}
#define END                                                                    \\
  {}
#endif
// typedef long long int ll;
typedef pair<int, int> P;
struct edge {
  int to, cost;
};
int ceil2(int a, int b) {
  if (a % b) {
    return a / b + 1;
  } else {
    return a / b;
  }
}
int n, k, ans, sum;
int a[111111];
signed main() {
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  rep(i, n) {
    sum -= a[i];
    ans += a[i] * sum;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

#define MAXX 500005
#define INF INT_MAX

#define PI 3.14159265358979323846264338327950

#define PB push_back
#define PF push_front
#define F first
#define S second

#define fixx(n) fixed << setprecision(n)

#define ll long long

#define mod 1000000007

int main() {
  FAST;
  int n;
  cin >> n;
  ll a[n + 6];
  ll x = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    x += a[i];
  }

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

Error: TLE

Fixed submission:

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

#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

#define MAXX 500005
#define INF INT_MAX

#define PI 3.14159265358979323846264338327950

#define PB push_back
#define PF push_front
#define F first
#define S second

#define fixx(n) fixed << setprecision(n)

#define ll long long

#define mod 1000000007

int main() {
  FAST;
  int n;
  cin >> n;
  ll a[n + 6];
  for (int i = 0; i < n; i++) {
    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]) % mod;
      ans %= mod;
    }
  }
  cout << ans;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#define endl "\\n"
#define SRK                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define EPS 1e-6
typedef long long ll;
using namespace std;

int main() {
  SRK;
  ll n, i, j;
  cin >> n;
  ll sum = 0, x;
  vector<ll> arr;
  ll arr1[n];
  for (i = 0; i < n; i++) {
    cin >> x;
    arr1[i] = x;
    arr.push_back(x);
  }
  reverse(arr.begin(), arr.end());
  for (i = 1; i < n; i++) {
    arr[i] += arr[i - 1];
  }
  for (i = n - 2, j = 0; j < n - 1; i--, j++) {
    sum += ((arr1[j] % (1000000000 + 7)) * (arr[i] % (1000000000 + 7))) %
           (1000000000 + 7);
  }
  cout << sum % (1000000000 + 7) << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cstring>
#include <iostream>
#define endl "\\n"
#define SRK                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define EPS 1e-6
typedef long long ll;
using namespace std;

int main() {
  SRK;
  ll n, i, j;
  cin >> n;
  ll sum = 0;
  ll arr[n];
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      sum += ((ll)(arr[i] * arr[j]) % (1000000000 + 7));
    }
  }
  cout << sum % (1000000000 + 7) << endl;
}