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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mod = 1000000007;

int main() {

  ll N;
  cin >> N;
  vector<ll> A(N, 0);
  vector<ll> B(N, 0);

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

  ll ans = 0;
  B[N - 1] = A[N - 1];

  for (ll i = 0; i < N - 1; ++i) {
    B[N - 2 - i] = (B[N - 1 - i] + A[N - 2 - i]) % mod;
  }

  /*
      for(int i=0;i<N;++i){
          cout<<B[i]<<" ";
      }
      cout<<endl;
  */
  for (ll i = 0; i < N - 1; ++i) {
    // cout<<A[i]<<":"<<B[N-1-i]<<endl;

    ans = (ans + A[i] * B[i + 1]) % mod;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mod = 1000000007;

int main() {

  ll N;
  cin >> N;
  ll A[N];

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

  ll ans = 0;

  for (ll i = 0; i < N - 1; ++i) {
    for (ll j = i + 1; j < N; ++j) {
      ll tmp = A[i] * A[j] % mod;
      ans = (ans + tmp) % mod;
    }
  }
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  long long n, x = 1e9 + 7, sum = 0;
  cin >> n;
  long long a[n], b[n];

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  for (int i = n - 2; i >= 0; i--)
    a[i] += a[i + 1];
  for (int i = 0; i < n - 1; i++) {
    sum += ((a[i + 1] % x) * (b[i] % x)) % x;
    sum %= x;
  }

  cout << sum % x << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

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

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

  long long n, x = 1e9 + 7, sum = 0;
  cin >> n;
  long long a[n];

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = i - 1; j >= 0; j--)
      sum += ((a[i] % x) * (a[j] % x)) % x;
  }
  cout << sum % x << "\\n";

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

#include <bits/stdc++.h>
#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) a.size()
#define re return
#define MP make_pair
#define pb push_back
#define pii pair<int, int>
#define se second
#define fi first
using namespace std;
const int MOD = 1e9 + 7;
int ans;
int n, a[200005], sum[200005];
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sum[n - 1] = a[n - 1];
  for (int i = n - 2; i > 0; i--)
    sum[i] = (a[i] + sum[i + 1]) % MOD;
  // for(int i=1;i<n;i++) cout<<i<<':'<<sum[i]<<"\\n";
  for (int i = 0; i + 1 < n; i++) {
    int cur = a[i] * sum[i + 1] % MOD;
    ans = (ans + cur) % MOD;
  }
  cout << ans;
  re 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) a.size()
#define re return
#define MP make_pair
#define pb push_back
#define pii pair<int, int>
#define se second
#define fi first
using namespace std;
const int MOD = 1e9 + 7;
int ans;
int n, a[200005];
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i + 1 < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int cur = a[i] * a[j] % MOD;
      ans = (ans + cur) % MOD;
    }
  }
  cout << ans;
  re 0;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int a[maxn];
int sum[maxn];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  sum[n + 1] = 0;
  for (int i = n; i >= 2; i--) {
    sum[i] = (sum[i + 1] + a[i]) % mod;
  }
  int ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    // cout<<sum[i+1]<<endl;
    ans = (ans + a[i] * sum[i + 1]) % mod;
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int a[maxn];
int sum[maxn];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  sum[n + 1] = 0;
  for (int i = n; i >= 2; i--) {
    sum[i] = (sum[i + 1] + a[i]) % mod;
  }
  int ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    // cout<<sum[i+1]<<endl;
    ans = (ans + a[i] * sum[i + 1]) % mod;
  }
  cout << ans << endl;

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

/*----- || Hare Krishna || -----*/

/*  "WHY DO WE FALL, BRUCE?"  */

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#define ll long long
#define endl '\\n'
#define elif else if
#define pb push_back
#define pf push_front
#define PI 3.1415926535897932384
#define MOD 1000000007
using namespace std;

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

string s;
int t;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int n;
  cin >> n;
  ll int ar[n + 1];

  ll pre[n + 1];
  pre[0] = 0;

  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
    pre[i] = (pre[i - 1] % MOD + ar[i] % MOD) % MOD;
  }

  ll ans = 0;

  for (int i = 1; i <= n; i++) {
    ans = (ans + MOD + (ar[i] * pre[i - 1]) % MOD) % MOD;
  }

  cout << ans;
}


Error: TLE

Fixed submission:

/*----- || Hare Krishna || -----*/

/*  "WHY DO WE FALL, BRUCE?"  */

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#define ll long long
#define endl '\\n'
#define elif else if
#define pb push_back
#define pf push_front
#define PI 3.1415926535897932384
#define MOD 1000000007
using namespace std;

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

string s;
int t;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int n;
  cin >> n;
  ll int ar[n];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = ((ans + MOD) + (ar[i] * ar[j]) % MOD) % MOD;
    }
  }
  cout << ans;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define MAX 100
#define THOU 1000
#define FIVEMAX 100000
#define NINEMAX 1000000000
#define TWEMAX 1000000000000
#define rep(i, n) for (int i = 0; i < n; i++)
#define drep(i, n) for (int i = n - 1; i >= 0; i--)
#define arep(i, a, n) for (int i = a; i < n; i++)
#define darep(i, a, n) for (int i = n, i >= a; i--)

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

  // ll a[2*FIVEMAX+1];
  // ll s[2*FIVEMAX+1];

  int n;

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

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

  ll nine = NINEMAX + 7;
  ll amari = 0;
  for (int i = 0; i < n; i++) {
    ll b = (s[n] - s[i + 1]) % nine;
    amari += b * (a[i] % nine) % nine;
    amari = amari % nine;
  }

  cout << amari << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
#define MAX 100
#define THOU 1000
#define FIVEMAX 100000
#define NINEMAX 1000000000
#define TWEMAX 1000000000000
#define rep(i, n) for (int i = 0; i < n; i++)
#define drep(i, n) for (int i = n - 1; i >= 0; i--)
#define arep(i, a, n) for (int i = a; i < n; i++)
#define darep(i, a, n) for (int i = n, i >= a; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string str;
  vector<int> v;
  map<string, int> m;
  pair<int, int> p;
  // ll a[2*FIVEMAX+1];
  // ll s[2*FIVEMAX+1];

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

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

  ll nine = NINEMAX + 7;
  ll amari = 0;
  for (int i = 0; i < n; i++) {
    ll b = (s[n] - s[i + 1]) % nine;
    amari += b * (a[i] % nine) % nine;
    amari = amari % nine;
  }

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

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

const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll s = 0;
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    s += a[i];
    s %= MOD;
  }

  for (int i = 0; i < n; ++i) {
    s -= a[i];
    if (s < 0)
      s += MOD;

    ans += a[i] * s;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll 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]) % MOD);
      ans %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

/*Hatsune Miku 4ever!*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _for(i, a, b) for (int i = (a); i < b; i++)
#define _rep(i, a, b) for (int i = (a); i > b; i--)
#define INF 0x3f3f3f3f
#define mod 1000000007
#define lowbit(x) ((x) & (-x))
#define pb push_back
#define MIKU 39
#define Design ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define debug() printf("Miku Check OK!\\n")
#define maxn 200039

struct pres {
  // 数组长度
  ll n;
  ll a[maxn];
  ll s[maxn];
  void getsum() {
    _for(i, 1, n + 1) {
      s[i] = s[i - 1] + a[i];
      s[i] %= mod;
    }
  }
  ll asksum(ll l, ll r) {
    if (l > r)
      return 0;
    return (s[r] - s[l - 1] + mod) % mod;
  }
} P;

int main() {
  scanf("%d", &P.n);
  _for(i, 1, P.n + 1) scanf("%lld", &P.a[i]);
  P.getsum();
  ll ans = 0;
  _for(i, 1, P.n) {
    ans += P.a[i] * P.asksum(i + 1, P.n);
    ans %= mod;
  }
  printf("%lld", ans);
  return 0;
}

Error: WA

Fixed submission:

/*Hatsune Miku 4ever!*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _for(i, a, b) for (int i = (a); i < b; i++)
#define _rep(i, a, b) for (int i = (a); i > b; i--)
#define INF 0x3f3f3f3f
#define mod 1000000007
#define lowbit(x) ((x) & (-x))
#define pb push_back
#define MIKU 39
#define Design ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define debug() printf("Miku Check OK!\\n")
#define maxn 10003

struct pres {
  // 数组长度
  ll n;
  ll a[maxn];
  ll s[maxn];
  void getsum() { _for(i, 1, n + 1) s[i] = s[i - 1] + a[i]; }
  ll asksum(ll l, ll r) {
    if (l > r)
      return 0;
    return s[r] - s[l - 1];
  }
} P;

int main() {
  scanf("%d", &P.n);
  _for(i, 1, P.n + 1) scanf("%lld", &P.a[i]);
  P.getsum();
  ll ans = 0;
  _for(i, 1, P.n) {
    ans += P.a[i] * P.asksum(i + 1, P.n);
    ans %= mod;
  }
  printf("%lld", ans);
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  ll n;
  cin >> n;
  ll a[n];
  ll i, j;
  ll s = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s = s + a[i];
  }

  ll ans = 0;
  for (i = 0; i < n; i++) {
    s = s - a[i];
    ans = ans + (s % MOD * a[i] % MOD) % MOD;
  }
  cout << ans % MOD << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

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

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

  ll sum = 0;
  for (i = 0; i < n - 1; i++) {
    for (ll j = i + 1; j < n; j++) {
      ll p = a[i] * a[j];
      sum = (sum + p) % MOD;
    }
  }
  cout << sum << endl;

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

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

#define mod 1000000007
int main() {
  long int n, i;
  cin >> n;

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

  long long ans = 0;
  for (i = 0; i < n; ++i) {
    pre = pre - A[i];
    long long temp = (((pre % 1000000007) * (A[i] % 1000000007)) % 1000000007);

    ans = (ans % 1000000007 + temp % 1000000007) % 1000000007;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {

  long int n;
  cin >> n;

  unsigned long int A[n];
  long int i;

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

  unsigned long long tot = 0;
  for (i = 0; i < n; i++) {
    for (long int j = i + 1; j < n; ++j) {

      long long temp = ((A[i] % 1000000007) * (A[j] % 1000000007)) % 1000000007;
      tot = (tot + temp) % 1000000007;
    }
  }

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

#include <iostream>

using namespace std;

int mod = 1000000000 + 7;

int main() {

  int n;
  cin >> n;
  long long int a[n];
  long long int ans = 0;
  long long int 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) % mod;
    ans %= mod;
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int mod = 1000000000 + 7;

int main() {

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

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

    long long int sum = 0;
    for (int j = i + 1; j < n; j++) {

      sum += a[j];
      if (sum >= mod) {

        sum %= mod;
      }
    }
    ans += (a[i] * sum) % mod;
    if (ans >= mod) {

      ans %= 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;
  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];
    sum %= 1000000007;
  }
  for (int i = 0; i < n; i++) {
    sum -= a[i];
    if (sum < 0)
      sum += 1000000007;
    ans += a[i] * sum;
    ans %= 1000000007;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  long long sum = 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++) {
      sum += a[i] * a[j];
      sum %= 1000000007;
    }
  }
  cout << sum << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;
#define MOD 1000000007
int main() {
  long long sum = 0, a[200005], csum[200005];
  int n;
  cin >> n;
  csum[0] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    csum[i] = (csum[i - 1] + a[i]) % MOD;
  }

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

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  long long sum, a[200005];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    scanf("%lld", &a[i]);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += (a[i] * a[j]) % 1000000007;
    }
    sum %= 1000000007;
  }
  cout << sum << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define pb push_back
#define fo(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define int long long
#define Mod 1000000007
#define MAX 4294967296 // 2^32
const int M = 1e9 + 7;
#define ip pair<int, int>
#define test(t)                                                                \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)

using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n];
  int ans = 0;
  int sum = 0;

  fo(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  fo(i, n) {
    sum -= a[i];
    ans += ((sum % Mod) * (a[i] % Mod)) % Mod;
  }

  cout << ans % Mod;
}

signed main() {

  // std::string binary = std::bitset<8>(n).to_string();
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define fo(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define int long long
#define Mod 1000000007
#define MAX 4294967296 // 2^32
const int M = 1e9 + 7;
#define ip pair<int, int>
#define test(t)                                                                \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)

using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n];
  int ans = 0;
  fo(i, n) cin >> a[i];
  fo(i, n) {
    for (int j = i + 1; j < n; j++)
      ans = (ans + (a[i] * a[j]) % Mod) % Mod;
  }

  cout << ans;
}

signed main() {

  // std::string binary = std::bitset<8>(n).to_string();
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll n;
  ll M = 1000000007;
  cin >> n;
  ll A[n];
  ll B[n];
  ll ans = 0;
  for (ll i = 0; i < n; i++)
    cin >> A[i];
  B[n - 1] = A[n - 1];
  for (ll i = n - 2; i >= 0; i--) {
    B[i] = (A[i] + B[i + 1]) % M;
  }
  for (ll i = 0; i < n - 1; i++) {
    ans = (ans + ((A[i] % M) * (B[i + 1] % M)) % M) % M;
  }
  cout << ans << "\\n";
}


Error: TLE

Fixed submission:

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

int main() {
  ll n;
  ll M = 1000000007;
  cin >> n;
  ll A[n];
  ll ans = 0;
  for (ll i = 0; i < n; i++)
    cin >> A[i];
  for (ll i = 0; i < n; i++) {
    for (ll j = i + 1; j < n; j++) {
      ans = (ans + (A[i] * A[j]) % M) % M;
    }
  }
  cout << ans << "\\n";
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
long long int n, arr[N], cs[N];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  long long int ans = 0, mod = 1e9 + 7, sum = arr[0];
  for (int i = 1; i < n; i++) {
    ans += sum * arr[i] % mod;
    ans %= mod;
    sum += arr[i];
    sum %= mod;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long int n, arr[N], cs[N];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  long long int ans = 0, mod = 1e9 + 7, sum = arr[0];
  for (int i = 1; i < n; i++) {
    ans += sum * arr[i] % mod;
    sum += arr[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  for (int i = 0; i < N - 1; i++) {
    sum = (sum - A[i]) % MOD;
    if (sum < 0)
      sum = sum + MOD;
    ans += sum * A[i] % MOD;
    ans = ans % MOD;
    // cout << ans << endl;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ll N, MOD = 1000000007, ans = 0;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      ans = ans % MOD;
      ans += A[i] * A[j] % MOD;
      // cout << ans << endl;
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
#define ll long long int
#define ii int
#define du double
#define jmp "\\n"
#define vl vector<ll>
#define vvl vector<vl>
#define pb push_back
#define printv(v)                                                              \\
  for (auto x : v)                                                             \\
    cout << x << " ";                                                          \\
  cout << jmp;
#define vi vector<int>
#define vb vector<bool>
#define SORT(v) sort(v.begin(), v.end())
#define REV(x) reverse(x.begin(), x.end())
#define all(x) x.begin(), x.end()
#define SET(x, a) memset(x, a, sizeof(x))
#define si(x) x.size()
#define ff first
#define ss second
#define iin insert
#define deb(x) cout << "test " << #x << "=" << x << jmp
#define deb2(x, y)                                                             \\
  cout << "test " << #x << "=" << x << "," << #y << "=" << y << jmp
using namespace std;
const ll nax = 1e5 + 5;
const int M = 1e9 + 7;
ll mod(ll x) { return ((x % M + M) % M); }

ll add(ll a, ll b) { return mod(mod(a) + mod(b)); }

ll mul(ll a, ll b) { return mod(mod(a) * mod(b)); }

void solve() {
  ll sum = 0, ans = 0, n;
  cin >> n;
  ll a[n];
  for (auto &x : a)
    cin >> x, sum += x;
  ll pre[n];
  pre[0] = a[0];
  for (ll i = 1; i < n; i++)
    pre[i] = add(pre[i - 1], a[i]);
  for (ll i = 0; i < n; i++) {
    ll temp = mul(a[i], sum - pre[i]);
    ans = add(ans, temp);
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
#define ll long long int
#define ii int
#define du double
#define jmp "\\n"
#define vl vector<ll>
#define vvl vector<vl>
#define pb push_back
#define printv(v)                                                              \\
  for (auto x : v)                                                             \\
    cout << x << " ";                                                          \\
  cout << jmp;
#define vi vector<int>
#define vb vector<bool>
#define SORT(v) sort(v.begin(), v.end())
#define REV(x) reverse(x.begin(), x.end())
#define all(x) x.begin(), x.end()
#define SET(x, a) memset(x, a, sizeof(x))
#define si(x) x.size()
#define ff first
#define ss second
#define iin insert
#define deb(x) cout << "test " << #x << "=" << x << jmp
#define deb2(x, y)                                                             \\
  cout << "test " << #x << "=" << x << "," << #y << "=" << y << jmp
using namespace std;
const ll nax = 1e9 + 7;
void solve() {
  ll n;
  cin >> n;
  vl a(n);
  for (auto &x : a)
    cin >> x;
  ll sum = 0;
  for (ll i = 0; i < n - 1; i++) {
    for (ll j = i + 1; j < n; j++) {

      ll temp = a[i] * a[j];
      if (temp > nax)
        temp %= nax;
      sum = (sum + temp);
      if (sum > nax)
        sum %= nax;
    }
  }
  cout << sum % nax;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}