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

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

typedef long long ll;
typedef unsigned long long ull;

#define F first
#define S second
#define ALL(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define INT_MAXI 2147483647
#define INT_MINI -2147483648
#define REV(a) reverse(a.begin(), a.end())
#define NP(a) next_permutation(a.begin(), a.end())

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

ll dt[200005];
ll sum[200005];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // cout<<"input"<<endl;freopen("input.txt","r",stdin);
  // cout<<"output"<<endl;freopen("output.txt","w",stdout);
  int n;
  cin >> n;

  ll modu = 1e9 + 7;

  FORN(i, 1, n) { cin >> dt[i]; }
  sum[n] = dt[n];
  for (int i = n - 1; i >= 2; i--) {
    sum[i] = (sum[i + 1] + dt[i]) % modu;
  }

  ll tot = 0;
  for (int i = 1; i <= n - 1; i++) {
    ll x = (dt[i] * sum[i + 1]) % modu;
    tot = (tot + x) % modu;
  }

  cout << tot << endl;
}


Error: TLE

Fixed submission:

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

typedef long long ll;
typedef unsigned long long ull;

#define F first
#define S second
#define ALL(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define INT_MAXI 2147483647
#define INT_MINI -2147483648
#define REV(a) reverse(a.begin(), a.end())
#define NP(a) next_permutation(a.begin(), a.end())

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // cout<<"input"<<endl;freopen("input.txt","r",stdin);
  // cout<<"output"<<endl;freopen("output.txt","w",stdout);

  ll dt[200005];

  int n;
  cin >> n;
  FORN(i, 1, n)
  cin >> dt[i];

  ll sum = 0;

  ll modu = 1000000007;
  FORN(i, 1, n - 1) {
    FORN(j, i + 1, n) {
      ll x = (dt[i] % modu * dt[j] % modu) % modu;
      // cout<<x<<endl;
      sum = (sum + x) % modu;
    }
  }
  cout << sum << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
// #include<stdio.h>
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define ll long long int
#define f(i, a, b) for (int i = a; i < b; i++)
#define fr(i, a, b) for (int i = a; i >= b; i--)
#define l long int
#define endl '\\n'
#define pb push_back
#define pf pop.front()

using namespace std;
ll MOD = 1e9 + 7;
int main() {
  FAST l n, i, j;
  cin >> n;
  ll a[n], ans = 0, sum = 0, s = 0;

  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  // s=a[0];
  for (i = 0; i < n - 1; i++) {
    s = a[i];
    sum -= s;
    ans = (ans + (a[i] % MOD) * (sum % MOD) % MOD) % MOD;
  }
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// #include<stdio.h>
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define ll long long int
#define f(i, a, b) for (int i = a; i < b; i++)
#define fr(i, a, b) for (int i = a; i >= b; i--)
#define l long int
#define endl '\\n'
#define pb push_back
#define pf pop.front()

using namespace std;
ll MOD = 1e9 + 7;
int main() {
  FAST l n, i, j;
  cin >> n;
  ll a[n], ans = 0;

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

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

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

#define ll long long int
#define mod (1000000007)

int main() {
  ll n;
  cin >> n;
  ll ar[n + 1];
  ll ans = 0, sum = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> ar[i];
    ans += (sum * ar[i]) % mod;
    sum = (sum + ar[i]) % mod;
  }
  cout << ans % mod << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long int
#define mod (1000000007)

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

#include <iostream>

#define mod (1000000007)
using namespace std;
int main(void) {
  long long n;
  cin >> n;

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

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

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <iostream>

#define MOD (1000000007)
using namespace std;
int main(void) {
  long long n;
  cin >> n;

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

  long long sum = 0;
  for (long long i = 0; i < n - 1; i++) {
    for (long long j = i + 1; j < n; j++) {
      sum += a[i] % MOD * a[j] % MOD;
      if (sum > MOD) {
        sum -= MOD;
      }
    }
  }

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

#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
using P = pair<int, int>;

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

  ll ans = 0;
  vector<ll> SS(N);

  ll s = 0;
  for (int i = N - 1; i >= 1; i--) {
    s += A[i];

    SS[i] = s % 1'000'000'007LL;
  }

  for (int i = 0; i < N - 1; i++) {
    ans += A[i] * SS[i + 1];
    ans %= 1'000'000'007LL;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
using P = pair<int, int>;

int main() {
  ll 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++) {
      ans += A[i] * A[j];
      if (ans > 1'000'000'007LL)
        ans %= 1'000'000'007LL;
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
#define int long long
#define mp make_pair
#define pb push_back
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * ((b) / gcd(a, b)))
#define pi 3.14159265358979323846
#define mod 1000000007
#define reus                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
int32_t main() {
  reus;

  //	#ifndef ONLINE_JUDGE
  //	freopen("input.txt", "r", stdin);
  //	freopen("output.txt", "w", stdout);
  //	#endif

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
#define int long long
#define mp make_pair
#define pb push_back
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * ((b) / gcd(a, b)))
#define mod 1000000007
#define pi 3.14159265358979323846
#define reus                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
int32_t main() {
  reus;

  //	#ifndef ONLINE_JUDGE
  //	freopen("input.txt", "r", stdin);
  //	freopen("output.txt", "w", stdout);
  //	#endif

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


// Problem: C - Sum of product of pairs
// Contest: AtCoder - AtCoder Beginner Contest 177
// URL: https://atcoder.jp/contests/abc177/tasks/abc177_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define FAST_IO                                                                \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long int
#define mp make_pair
#define pb push_back
#define p pair
#define vt vector
#define F first
#define S second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
#define endl "\\n"
#define db1(x) cout << #x << " = " << x << '\\n';
#define db2(v)                                                                 \\
  for (auto &x : v)                                                            \\
    cout << x << " ";
#define umap unordered_map
#define uset unordered_set
#define MOD 1000000007
using namespace std;

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

Error: TLE

Fixed submission:


// Problem: C - Sum of product of pairs
// Contest: AtCoder - AtCoder Beginner Contest 177
// URL: https://atcoder.jp/contests/abc177/tasks/abc177_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define FAST_IO                                                                \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long int
#define mp make_pair
#define pb push_back
#define p pair
#define vt vector
#define F first
#define S second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()
#define endl "\\n"
#define db1(x) cout << #x << " = " << x << '\\n';
#define db2(v)                                                                 \\
  for (auto &x : v)                                                            \\
    cout << x << " ";
#define umap unordered_map
#define uset unordered_set
#define MOD 1000000007
using namespace std;

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL
int n;
vector<ll> a;
vector<ll> asum;

int main() {
  ll ans;

  cin >> n;

  a.resize(n);
  asum.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ans = 0;
  asum[n - 1] = a[n - 1];
  // printf("asum[%d] = %lld\\n", n-1, asum[n-1]);
  for (int i = n - 2; i > 0; i--) {
    asum[i] = a[i] + asum[i + 1];
    asum[i] %= MOD;
    // printf("asum[%d] = %lld\\n", i, asum[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    // printf("a[%d](%lld) * asum[%d](%lld)\\n", i, a[i], i+1, asum[i+1]);
    ans += a[i] * asum[i + 1];
    ans %= MOD;
  }

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL
int n;
vector<ll> a;

int main() {
  ll ans;

  cin >> n;

  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; 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>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
int n, a[200005], bc[200005], ans = 0;
signed main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = n; i >= 1; i--)
    bc[i] = a[i] + bc[i + 1], bc[i] %= mod;
  for (int i = 1; i <= n; i++) {
    ans += (a[i] * bc[i + 1]);
    ans %= mod;
  }
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
int n, a[100005], bc[100005], ans = 0;
signed main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = n; i >= 1; i--)
    bc[i] = a[i] + bc[i + 1], bc[i] %= mod;
  for (int i = 1; i <= n; i++) {
    ans += (a[i] * bc[i + 1]);
    ans %= mod;
  }
  cout << ans;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
  unsigned long long n, ans = 0, mod = 1000000007;
  cin >> n;
  vector<unsigned long long> a(n);
  unsigned long long po = 0, tot = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a.at(i);
    po += (a.at(i) * a.at(i)) % mod;
    tot += a.at(i);
  }
  tot %= mod;
  po %= mod;
  ans = (tot * tot) - po;
  ans %= mod;
  // 2で割る (逆元を用いる)
  // ans /= 2 を mod 1000000007で行うとこうなる
  ans *= (mod + 1) / 2;
  ans %= mod;
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

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

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

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

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

  long long ans = 0, MOD = 1000000007, tmpSum = 0, piledSum[n];

  // 累積和
  piledSum[n - 1] = a[n - 1];
  // cout << piledSum[n-1] << endl;
  for (int i = n - 2; i >= 0; i--) {
    piledSum[i] = piledSum[i + 1] + a[i];
    // cout << piledSum[i] << endl;
  }

  for (int i = 0; i < n - 1; i++) {

    // cout << "a[i]: " << a[i]%MOD << ", 累積和: " << piledSum[i+1] << ", ans:"
    // << ans <<endl;
    ans += ((a[i] % MOD) * (piledSum[i + 1] % MOD)) % MOD;
    ans = ans % MOD;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

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

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

  long long ans = 0, MOD = 1000000007;

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

      // cout << "a[i]%:" << a[i]%MOD << " a[j]%: " << a[j]%MOD <<endl;
      ans += ((a[i] % MOD) * (a[j] % MOD)) % MOD;
      ans = ans % MOD;
      if (ans < 0) {
        ans += MOD;
      }

      // cout << " i:" << i << " j:" << j << " ans:" << ans <<endl;
    }
  }

  cout << ans << endl;

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

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

#define INF 1e9
#define PI 3.141592653589793238
#define N 1000000010
#define mod 1000000007
typedef long long ll;

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

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

  return 0;
}

Error: TLE

Fixed submission:

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

#define INF 1e9
#define PI 3.141592653589793238
#define N 1000000010
#define mod 1000000007
typedef long long ll;

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

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

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

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

#define ll long long int
#define mod 1000000007

/*
cout<<"\\ndebugging\\n";
*/

int main() {
  ios_base::sync_with_stdio(false); // Fast I/O
  cin.tie(NULL);

  ll t, n, i, j;
  cin >> n;
  vector<ll> a;
  ll x;
  for (i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  ll sum = 0, sumall = 0;
  for (i = n - 2; i >= 0; i--) {
    sumall = (sumall + a[i + 1]) % mod;
    sum = (sum + (a[i] * sumall) % mod) % mod;
  }
  cout << sum;
  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long int
#define mod 1000000007

/*
cout<<"\\ndebugging\\n";
*/

int main() {
  ios_base::sync_with_stdio(false); // Fast I/O
  cin.tie(NULL);

  ll t, n, i, j;
  cin >> n;
  vector<ll> a;
  ll x;
  for (i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  ll sum = 0;
  for (int i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      sum = (sum % mod + (a[i] * a[j]) % mod) % mod;
    }
  }
  cout << sum;
  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 rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
const long long INF = 1LL << 60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
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)rep2(j, i+1, N)
  // {
  //     ll a = A[i]%MOD;
  //     ll b = A[j]%MOD;
  //     ll c = (a*b)%MOD;
  //     ans += c;
  //     ans %= MOD;
  // }
  // ll sub = 0;
  // rep2(i, 1, N)
  // {
  //     sub += A[i];
  // }
  // sub %= MOD;
  // rep(i, N-1)
  // {

  //     ans += ((A[i]*sub)%MOD);
  //     sub -= A[i+1];
  //     sub %= MOD;
  // }
  // cout << ans << endl;
  vector<ll> S(N);
  S[0] = 0;
  S[1] = A[0];
  rep2(i, 2, N) {
    S[i] = (S[i - 1] + A[i - 1]) % MOD;
    // cout << S[i] << endl;
  }
  rep2(i, 0, N - 1) {
    ll x = A[i + 1] * S[i + 1];
    ans += (x % MOD);
  }
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
const long long INF = 1LL << 60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
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) rep2(j, i + 1, N) {
    ll a = A[i] % MOD;
    ll b = A[j] % MOD;
    ll c = (a * b) % MOD;
    ans += c;
    ans %= MOD;
  }
  cout << ans << endl;

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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define REP_REV(i, a, b) for (int i = a; i >= b; i--)
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;

ll MOD = 1e9 + 7;

struct Rect {
  ll x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  ll area() { return (x2 - x1) * (y2 - y1); }
};

Rect intersect(Rect p, Rect q) {
  Rect inter;
  inter.x1 = max(p.x1, q.x1);
  inter.y1 = max(p.y1, q.y1);
  inter.x2 = min(p.x2, q.x2);
  inter.y2 = min(p.y2, q.y2);
  if (inter.x1 >= inter.x2 || inter.y1 >= inter.y2) {
    Rect empty;
    return empty;
  }
  return inter;
}

bool iscovered(int x, int y, int x1, int y1, int x2, int y2) {
  return (x <= x2 && x >= x1 && y <= y2 && y >= y1);
}

void solve() {
  ll n;
  cin >> n;
  vl a(n);
  REP(i, 0, n - 1) cin >> a[i];
  ll sum = 0;
  REP(i, 0, n - 1) sum += a[i];
  ll ans = 0;
  REP(i, 0, n - 1) {
    sum -= a[i];
    ans += (sum % MOD * a[i]) % MOD;
    ans %= MOD;
  }
  cout << ans;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  // freopen("billboard.in", "r", stdin);
  // freopen("billboard.out", "w", stdout);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  // ll t; cin >> t;
  // while (t--)
  solve();
  return 0;
}

Error: TLE

Fixed submission:

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define REP_REV(i, a, b) for (int i = a; i >= b; i--)
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;

void solve() {
  ll n;
  cin >> n;
  vl a(n);
  ll mod = 1e9 + 7;
  unsigned long long ans = 0;
  REP(i, 0, n - 1) cin >> a[i];
  REP(i, 0, n - 1) {
    REP(j, i + 1, n - 1) { ans += (a[i] * a[j]) % mod; }
  }
  cout << ans % mod;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  // freopen("measurement.in", "r", stdin);
  // freopen("measurement.out", "w", stdout);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  // ll t;
  // cin >> t;
  // while (t--) {
  solve();
  //}
  return 0;
}