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

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

int main() {
  const long long int mod = 1000000007;
  long int N;
  cin >> N;

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

  long long int sum1 = 0;
  long long int sum2 = 0;

  rep(i, N) {
    sum1 += A.at(i) % mod;
    sum2 += A.at(i) * A.at(i) % mod;
  }

  long long int sum = 0;
  sum = ((sum1 % mod) * (sum1 % mod) - sum2 % mod) % mod;

  if (sum < 0) {
    sum + mod;
  }
  cout << (sum * 500000004) % mod << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long int N;
  cin >> N;

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

  long long int sum = 0;

  rep(i, N - 1) {
    for (int j = i + 1; j < N; j++) {
      sum += (A.at(i) % (1000000007)) * (A.at(j) % (1000000007)) % 1000000007;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
#define FOUT(n, dist) cout << fixed << setprecision(n) << (dist);
#define BR cout << endl;
#define LEN(s) s.length();
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const ll mod = 1000000007;

ll powmod(ll x, ll y) {
  ll res = 1;
  for (ll i = 0; i < y; i++) {
    res = res * x % mod;
  }
  return res;
}

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

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

  long long int sum = 0, ans = 0, tem = 0;

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

  cout << sum << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
#define FOUT(n, dist) cout << fixed << setprecision(n) << (dist);
#define BR cout << endl;
#define LEN(s) s.length();
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const ll mod = 1000000007;

ll powmod(ll x, ll y) {
  ll res = 1;
  for (ll i = 0; i < y; i++) {
    res = res * x % mod;
  }
  return res;
}

double expect(int x) {
  double kitai, tem = 0;
  for (int i = 1; i <= x; i++) {
    tem += i;
  }
  kitai = tem / x;
  cout << kitai << endl;
  return kitai;
}

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

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

  ll sum = 0, ans = 0;

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

  cout << sum << endl;

  return 0;
}
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(nullptr);
  long int n;
  cin >> n;
  long long int *a;
  a = new long long int[n];
  long long int c = 0, sum = 0;
  long long int b = pow(10, 9) + 7;
  for (long int i = 0; i < n; i++) {
    cin >> a[i];
    c += sum * a[i];
    c = c % b;
    sum += a[i];
    sum = sum % b;
  }

  cout << c << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  long int n;
  cin >> n;
  long long int *a;
  a = new long long int[n];
  long long int c = 0;
  long long int b = pow(10, 9) + 7;
  for (long int i = 0; i < n; i++) {
    cin >> a[i];
    for (long long int j = 0; j < i; j++) {
      c += a[i] * a[j];
      c = c % b;
    }
  }
  cout << c << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long n, ans = 0, add = 0, two = 0, mod = 1000000007;
  cin >> n;
  vector<long long> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    add += A[i];
    add %= mod;
  }
  ans = add * add % mod;
  for (int i = 0; i < n; i++) {
    ans -= (long long)A[i] * A[i] % mod;
    if (ans < 0)
      ans += mod;
  }
  ans *= (mod + 1) / 2;
  ans %= mod;
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
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[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += A[i] * A[j];
      ans %= 1000000007;
    }
  }
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define MOD 1000000007

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

  ll sum = 0;
  for (int i = 0; i < N; i++) {
    sum += A[i];
    sum %= MOD;
  }

  ll ans = 0;
  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 <bits/stdc++.h>

using namespace std;

#define ll long long
#define MOD 1000000007

int main() {
  ll 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];
      ans %= MOD;
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define Max(x, y, z) max(x, max(y, z))
#define Min(x, y, z) min(x, min(y, z))
#define in auto &it
#define out auto it
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
const double pi = acos(-1);
#define err(x) cerr << #x << " = " << x << '\\n';
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
  fastio int n;
  cin >> n;
  ll ar[n];
  for (int i = 0; i < n; ++i)
    cin >> ar[i];
  vector<int> suf(n);
  suf[n - 1] = 0;
  suf[n - 2] = ar[n - 1] % mod;
  for (int i = n - 3; i >= 0; --i) {
    suf[i] = ((ar[i + 1]) % mod + (suf[i + 1]) % mod) % mod;
    // for(auto x:suf) cerr<<x<<" ";
    suf[i] %= mod;
  }
  ll ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    ans += ((ar[i] % mod) * (suf[i] % mod)) % mod;
    ans %= mod;
  }
  cout << (((ans % mod) + mod) % mod);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define Max(x, y, z) max(x, max(y, z))
#define Min(x, y, z) min(x, min(y, z))
#define in auto &it
#define out auto it
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
const double pi = acos(-1);
#define err(x) cerr << #x << " = " << x << '\\n';
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
  fastio
      // double d,t,s;
      // cin>>d>>t>>s;
      // if(d/s<=t) cout<<"Yes";
      // else cout<<"No";

      // string s,t;
      // cin>>s>>t;
      // int mi=INT_MAX;
      // for(int i=0;i<s.size()-t.size()+1;++i){
      // 	int cnt=0;
      // 	for(int j=0;j<t.size();++j){
      // 		if(s[i+j]!=t[j]) ++cnt;
      // 	}
      // 	mi=min(mi,cnt);
      // }
      // cout<<mi;

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

#include <iostream>
using namespace std;
#include <cmath>
long long int m = pow(10, 9) + 7;
int main() {
  long long int n;
  cin >> n;
  long long int flag = 0;
  long long int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    flag += arr[i];
  }
  long long int final_arr[n];
  for (int i = 0; i < n; i++) {
    final_arr[i] = flag - arr[i];
    flag -= arr[i];
  }
  long long int product = 0;
  for (int i = 0; i < n; i++) {
    product += (((arr[i] % m) * (final_arr[i] % m)) % m);
    product = product % m;
  }
  cout << product << endl;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
long long int m = pow(10, 9) + 7;
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long int product = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      product += (arr[i] * arr[j]);
      product = product % m;
    }
  }
  cout << product << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
const long long mod = 1000000007;
int main() {
  long long n, a[200005], i, j, s, m, total = 0, d[200005];
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    total += (a[i] % mod);
    total %= mod;
  }
  for (i = 1; i < n; i++) {
    d[i] = total - (a[i] % mod);
    d[i] = ((d[i] % mod) + mod) % mod;
    total = d[i];
  }
  total = 0;
  for (i = 1; i < n; i++) {
    total += (((a[i] % mod) * d[i]) % mod);
    total %= mod;
  }
  cout << total << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
const long long mod = 1000000007;
int main() {
  long long n, a[200005], i, j, s, m, total = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i < n; i++) {
    s = a[i] % mod;
    for (j = i + 1; j <= n; j++) {
      m = a[j] % mod;
      total += ((s * m) % mod);
      total %= mod;
    }
  }
  cout << total << endl;
  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;
const ll MOD = 1e9 + 7;

int main() {
  cin.tie(0)->sync_with_stdio(false);

  int 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];
    s[i + 1] %= MOD;
  }

  ll res = 0;
  REP(i, n - 1) {
    ll tmp = s[n] - s[i + 1];
    if (tmp < 0)
      tmp += MOD;
    res += a[i] * tmp;
    res %= MOD;
  }
  cout << res << '\\n';
  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;
const ll MOD = 1e9 + 7;

int main() {
  cin.tie(0)->sync_with_stdio(false);

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

  ll res = 0;
  REP(i, n) for (int j = i + 1; j < n; j++) {
    res += a[i] * a[j];
    res %= MOD;
  }
  cout << res << '\\n';
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

// vec[i]の範囲外エラー表示
#define _GLIBCXX_DEBUG
// includeとusing
#include <bits/stdc++.h>
using namespace std;
// 型名省略
using ll = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using pll = pair<ll, ll>;
// 定数
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
// マクロ
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define xrep(i, x, n) for (ll i = (ll)x; i < (ll)n; i++)
#define all(A) A.begin(), A.end()
// 入力
ll llin() {
  ll x;
  cin >> x;
  return x;
}
string stin() {
  string s;
  cin >> s;
  return s;
}
vl vlin(ll n) {
  vl a(n);
  rep(i, n) { cin >> a[i]; }
  return a;
}
// 正誤判定
void Yes(bool ans) { cout << (ans ? "Yes" : "No") << endl; }
void YES(bool ans) { cout << (ans ? "YES" : "NO") << endl; }

// main関数
int main() {
  ll n = llin();
  vl a(n);
  rep(i, n) { cin >> a[i]; }

  vl sum(n, a[0]);
  rep(i, n - 1) { sum[i + 1] = (sum[i] + a[i + 1]) % MOD; }
  ll ans = 0;
  rep(i, n - 1) {
    ans += (sum[i] * (a[i + 1])) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

// vec[i]の範囲外エラー表示
#define _GLIBCXX_DEBUG
// includeとusing
#include <bits/stdc++.h>
using namespace std;
// 型名省略
using ll = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using pll = pair<ll, ll>;
// 定数
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
// マクロ
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define xrep(i, x, n) for (ll i = (ll)x; i < (ll)n; i++)
#define all(A) A.begin(), A.end()
// 入力
ll llin() {
  ll x;
  cin >> x;
  return x;
}
string stin() {
  string s;
  cin >> s;
  return s;
}
vl vlin(ll n) {
  vl a(n);
  rep(i, n) { cin >> a[i]; }
  return a;
}
// 正誤判定
void Yes(bool ans) { cout << (ans ? "Yes" : "No") << endl; }
void YES(bool ans) { cout << (ans ? "YES" : "NO") << endl; }

// main関数
int main() {
  ll n = llin();
  vl a = vlin(n);
  ll ans = 0;
  rep(i, n) {
    xrep(j, i + 1, n) {
      ans += ((a[i] % MOD) * (a[j] % MOD)) % MOD;
      ans %= MOD;
    }
  }
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  int i;
  int64_t num = 0;
  int64_t num2 = 0;
  int64_t div = pow(10, 9) + 7;
  cin >> N;
  vector<int64_t> A(N);
  for (i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  for (i = 0; i < N; i++) {
    num += A.at(i);
  }
  num = num % (2 * div);
  num = num * num;
  for (i = 0; i < N; i++) {
    num2 = A.at(i) * A.at(i);
    num2 = num2 % (2 * div);
    num = num - num2;
    if (num < 0) {
      num += (2 * div);
    }
  }
  num = num / 2;
  num = num % div;

  cout << num << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  int i, j;
  int64_t num = 0;
  int64_t div = pow(10, 9) + 7;
  cin >> N;
  vector<int64_t> A(N);
  for (i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (i = 0; i < N - 1; i++) {
    for (j = i + 1; j < N; j++) {
      num += A.at(i) * A.at(j);
      num = num % div;
    }
  }

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

#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define MOD 1000000007
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> ans(n, 0);
  unsigned long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> ans[i];
  }
  unsigned long long check = 0;
  for (int i = 0; i < n; i++) {
    sum = (sum + (ans[i] * check) % MOD) % MOD;
    check = (check + ans[i]) % MOD;
  }

  cout << sum;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define MOD 1000000007
using namespace std;

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

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

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

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

ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0)
    res += m;
  return res;
}

int main() {
  ll N;
  cin >> N;

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

  ll ans = 0;

  for (ll i = 0; i < N; i++) {
    sum -= A[i];
    sum = mod(sum, MOD);
    ans += A[i] * sum;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ll N;
  cin >> N;

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

  ll ans = 0;

  for (ll i = 0; i < N; i++) {
    for (ll 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: Time Limit Exceeded

/* C - Sum of product of pairs */

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

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


Error: TLE

Fixed submission:

/* C - Sum of product of pairs */

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

int main() {
  int N;
  long long 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; i++) {
    for (int j = i + 1; j < N; j++) {
      ans += A.at(i) * A.at(j) % 1000000007;
      ans %= 1000000007;
    }
  }
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  vector<uint64_t> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  uint64_t sum;
  uint64_t suma = 0;
  uint64_t sums = 0;
  for (int i = 0; i < N; i++) {
    suma += a.at(i);
    suma = suma % 2000000014;
  }
  suma = suma * suma;
  for (int i = 0; i < N; i++) {
    sums += a.at(i) * a.at(i);
    sums = sums % 2000000014;
  }
  if (suma > sums) {
    sum = (suma - sums) / 2;
  } else {
    sum = (sums - suma) / 2;
  }
  sum = sum % 1000000007;
  cout << sum << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<uint64_t> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  uint64_t sum = 0;
  uint64_t sumj;
  for (int i = 0; i < N; i++) {
    sumj = 0;
    for (int j = i + 1; j < N; j++) {
      sumj += a.at(j);
      sumj = sumj % 1000000007;
    }
    sum += a.at(i) * sumj;
    sum = sum % 1000000007;
  }
  cout << sum << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <tuple>
#include <vector>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using ll = long long;
using P = pair<long long, long long>;
using MATRIX = vector<vector<ll>>;

long long sum[200001];
long long N;
long long a[200000];
const long long MOD = 1000000007;

int main() {
  cin >> N;
  rep(i, N) { cin >> a[i]; }
  sum[N] = 0;
  rep(i, N) {
    sum[N - i - 1] = sum[N - i] + a[N - i - 1];
    sum[N - i - 1] %= MOD;
  }
  long long ans = 0;
  rep(i, N) {
    ans += a[i] * sum[i + 1];
    ans %= MOD;
  }
  cout << ans << endl;
  // rep(i, N) {
  //   cout << sum[i] << " ";
  // }
  // cout << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <tuple>
#include <vector>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using ll = long long;
using P = pair<long long, long long>;
using MATRIX = vector<vector<ll>>;

long long sum[100001];
long long N;
long long a[100000];
const long long MOD = 1000000007;

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define debug(s, param) std::cerr << s << param << std::endl;

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
    sum %= MOD;
  }

  ll ans = 0;
  for (int i = 0; i < n - 1; ++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 <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define debug(s, param) std::cerr << s << param << std::endl;

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<long> 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] % MOD);
    }
  }
  cout << ans % MOD << endl;
  return 0;
}