alexjercan/bugnet huggingface dataset:
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (i = 0; i < n; i++)
#define foreach(c, itr)                                                        \\
  for (__typeof(c)::iterator itr = c.begin(); itr != c.end(); itr++)
typedef long long ll;
const ll mod = 1000000000 + 7;
ll i, j;
ll kong = 0;

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

  ll n;
  cin >> n;
  ll a[n + 1];
  ll sum = 0;
  rep(i, n) {
    cin >> a[i];
    sum = (sum + a[i]) % mod;
  }
  ll ans = 0;
  for (i = 0; i < n; i++) {
    sum -= a[i];
    if (sum < 0)
      sum += mod;
    ll x = a[i] * sum;
    x %= mod;
    ans += x;
    ans %= mod;
  }
  ans %= mod;
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (i = 0; i < n; i++)
#define foreach(c, itr)                                                        \\
  for (__typeof(c)::iterator itr = c.begin(); itr != c.end(); itr++)
typedef long long ll;
const ll mod = 1000000000 + 7;
ll i, j;

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

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

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7, N = 2 * 1e5 + 10;
ll n;
ll a[N], q[N];
ll sum = 0;
int main() {
  q[0] = 0;
  a[0] = 0;
  cin >> n; // 输入n
  for (int i = 1; i <= n; i++) {
    cin >> a[i];                    // 输入所有的数
    a[i] %= mod;                    // 然后先mod,原数组;
    q[i] = (q[i - 1] + a[i]) % mod; // 前缀和数组
    sum = (sum + (a[i] * q[i - 1] % mod)) % mod;
  }
  cout << sum;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7, N = 2 * 1e5 + 10;
ll n;
ll a[N];
ll sum = 0;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] %= mod;
    if (i > 1) {
      for (int j = i - 1; j >= 1; j--) {
        sum += (a[i] * a[j] % mod);
        sum %= mod;
      }
    }
  }
  cout << sum;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <new>
#include <queue>
#include <stack>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define loop(i, x, z) for (int i = x; i < z; i++)
using ll = long long int;
#define mod 1000000007
/*bool cmp(pair<ll,ll>a,pair<ll,ll>b){
return a.second<b.second;
}*/
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  loop(i, 0, n) { cin >> a[i]; }
  long long ans = 0;
  vector<int> dp(n, 0);
  dp[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 1; i--) {
    dp[i] = dp[i + 1] + a[i];
    dp[i] = dp[i] % mod;
  }
  loop(i, 0, n - 1) {
    ans += (ll)a[i] * dp[i + 1];
    ans = ans % mod;
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <new>
#include <queue>
#include <stack>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define loop(i, x, z) for (int i = x; i < z; i++)
using ll = long long int;
#define mod 1000000007
/*bool cmp(pair<ll,ll>a,pair<ll,ll>b){
return a.second<b.second;
}*/
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  loop(i, 0, n) { cin >> a[i]; }
  long long ans = 0;
  loop(i, 0, n - 1) {
    loop(j, i + 1, n) {
      ans += (ll)a[i] * a[j];
      ans = ans % mod;
    }
  }
  cout << ans;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long A[int(2e5) + 5];
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> A[i];
  }
  long long alsum = 0, sum = 0;
  for (int i = 1; i <= n; ++i) {
    alsum += A[i];
  }
  long long less = 0;
  for (int i = 1; i <= n - 1; ++i) {
    less += A[i];
    sum += A[i] % mod * ((alsum - less) % mod);
    sum %= mod;
  }
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long A[int(2e5) + 5];
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> A[i];
  }
  long long sum = 0;
  for (int i = 1; i <= n - 1; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      sum += A[i] * A[j];
      sum %= int(1e9) + 7;
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define Bye return 0
#define ll long long
const ll M = 1e9 + 7;
const ll SIZE = 2e5 + 1;
vector<ll> ps(SIZE, 0);
int e;

int scan() {
  scanf("%d", &e);
  return e;
}

void solve() {
  ll n, res = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    ps[i] = (ps[i - 1] + scan()) % M;
    res = (res % M + (e * ps[i - 1]) % M) % M;
  }
  cout << res << endl;
}

int main() {
  solve();
  Bye;
}

Error: TLE

Fixed submission:

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

#define Bye return 0
#define ll long long
const ll MAX = 1e9 + 7;

void solve() {
  ll n;
  cin >> n;
  ll a[n];
  memset(a, 0, sizeof a);
  for (int i = 0; i < n; i++)
    cin >> a[i];

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

int main() {
  solve();
  Bye;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
int main() {
  ll mod = 1000000007;
  ll ans = 0;
  ll N, inp, sum, zizyo;
  sum = 0;
  cin >> N;
  rep(i, N) {
    cin >> inp;
    ans = (ans + sum * inp) % mod;
    sum = (sum + inp) % mod;
  }

  cout << ans;
  cin >> N;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
int main() {
  ll mod = 1000000007;
  ll ans = 0;
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) { cin >> A[i]; }
  rep(i, N - 1) {
    for (ll j = i + 1; j < N; j++) {
      ans = (ans + (A[i] * A[j])) % mod;
    }
  }

  cout << ans;
  cin >> N;

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

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
  const ll mod = 1000000007;
  ll N;
  cin >> N;
  vl A(N), sum(N + 1);
  rep(i, N) { cin >> A[i]; }
  sum[0] = 0;
  rep(i, N) { sum[i + 1] = sum[i] + A[i]; }

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


Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
  const ll mod = 1000000007;
  ll N;
  cin >> N;
  vl A(N);
  rep(i, N) { cin >> A[i]; }

  ll ans = 0;
  rep(i, N - 1) {
    for (ll j = i + 1; j < N; j++) {
      ll aq = A[i] / 100000;
      ll ar = A[i] % 100000;
      ll bq = A[j] / 100000;
      ll br = A[j] % 100000;

      // ans += (A[j]*aq%mod * 100000 + A[j]*ar%mod) % mod;
      ans += A[i] * A[j] % mod;
      ans %= mod;
    }
  }
  cout << ans;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
typedef long long ll;

const ll MOD = 1e9 + 7;
const int maxn = 2e5 + 5;
using namespace std;

ll a[maxn], n, sum[maxn], ans;

int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", a + i);
    sum[i] = (a[i] + sum[i - 1]) % MOD;
  }

  for (int i = 2; i <= n; i++) {
    ans = (ans + a[i] * sum[i - 1] % MOD) % MOD;
  }
  printf("%lld\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
typedef long long ll;

const ll MOD = 1e9 + 7;
const int maxn = 1e5 + 5;
using namespace std;

ll a[maxn], n, sum[maxn], ans;

int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", a + i);
    sum[i] = a[i] + sum[i - 1];
  }

  for (int i = 2; i <= n; i++) {
    ans = (ans + a[i] * sum[i - 1] % MOD) % MOD;
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;
const ll MOD = (ll)1e9 + 7;

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

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

  ll comSum[N];
  comSum[N - 1] = 0;
  for (ll i = N - 2; i >= 0; i--) {
    comSum[i] = comSum[i + 1] + A[i + 1];
    comSum[i] %= MOD;
  }

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

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

Error: TLE

Fixed submission:

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

using ll = long long;
const ll MOD = 1e9 + 7;

// 初項ini, 項差diff, 項数numの等差数列の和
template <typename T> T sumUpArithmeticProgression(T ini, T diff, T num) {
  return num * ((T)2 * ini + (num - (T)1) * diff) / (T)2;
}

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

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

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

  cout << sum << endl;

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

#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int main() {

  long long int N, i, sum, ans;
  cin >> N;
  long long int a[N], b[N];
  sum = 0;

  for (i = 0; i < N; i++) {
    cin >> a[i];
    if (i == 0) {
      b[i] = a[i];
    } else {
      b[i] = (b[i - 1] + a[i]) % ((long long int)pow(10, 9) + 7);
    }
  }

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

  cout << sum;

  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int main() {

  long long int N, i, j, sum, ans;
  cin >> N;
  long long int a[N];
  sum = 0;

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

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

  cout << sum;

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

#include <stdio.h>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
const int MOD = 1e9 + 7;
int main(void) {
  int N, A[200000], cusum = 0, total = 0;
  if (!scanf("%d", &N))
    return -1;
  rep(i, N) {
    if (!scanf("%d", &A[i]))
      return -1;
    cusum = (1l * cusum + A[i]) % MOD;
  }
  rep(i, N) {
    cusum -= A[i];
    if (cusum < 0) {
      cusum += MOD;
    }
    total = (1l * total + 1l * A[i] * cusum % MOD) % MOD;
  }
  return printf("%d\\n", total), 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
const int MOD = 1e9 + 7;
int main(void) {
  int N, A[200000], total = 0;
  if (!scanf("%d", &N))
    return -1;
  rep(i, N) {
    if (!scanf("%d", &A[i]))
      return -1;
  }
  rep(i, N - 1) {
    int j = i + 1;
    while (j < N) {
      total += 1l * A[i] * A[j++] % MOD;
      total %= MOD;
    }
  }
  return printf("%d\\n", total), 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define f(i, a, b) for (i = a; i < b; i++)
typedef vector<int> vi;

int main() {
  int n, i;
  cin >> n;
  long long mod = 1000000007;
  vi a(n);
  long long sum = 0, ans = 0;
  f(i, 0, n) {
    cin >> a[i];
    sum += a[i];
  }
  i = 0;
  int j = 0;
  f(i, 0, n - 1) {
    sum = (sum - a[i]);
    ans += ((sum % mod) * (a[i] % mod)) % mod;
    ans %= mod;
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define f(i, a, b) for (i = a; i < b; i++)
typedef vector<int> vi;

int main() {
  int n, i;
  cin >> n;
  long long mod = 1000000007;
  vi a(n);
  f(i, 0, n) { cin >> a[i]; }
  i = 0;
  int j = 0;
  long long sum = 0;
  f(i, 0, n - 1) {
    f(j, i + 1, n) {
      sum += ((a[i] % mod) * (a[j] % mod)) % mod;
      sum = sum % mod;
    }
  }
  cout << sum << endl;

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

#include <iostream>
using namespace std;
int main(void) {
  int i, j, k, n, MOD = 1000000007;
  long long int a[200000], sum, ans, c;

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

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

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

Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>
#define mod 1000000007

using namespace std;
long long add_mod(long long a, long long b) {
  long long re = (a % mod) + (b % mod);
  return re % mod;
}
long long mul_mod(long long a, long long b) {
  long long re = (a % mod) * (b % mod);
  return re % mod;
}

// return = a - b;
long long sub_mod(long long a, long long b) {
  long long re;
  if (a % mod < b % mod) {
    re = (a % mod) + mod - (b % mod);
  } else {
    re = (a % mod) - (b % mod);
  }
  return re;
}

int main(void) {
  int n;
  cin >> n;
  long long a[n + 1];
  long long b[n + 1];
  for (int i = 1; i < n + 1; i++)
    b[i] = 0;
  b[0] = 0;
  long long all = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
    b[i] = add_mod(a[i], b[i - 1]);
    all = add_mod(a[i], all);
  }
  long long ans, w;
  ans = 0;
  w = 0;
  long long sa;
  for (int i = 1; i < n; i++) {
    sa = sub_mod(all, b[i]);
    w = mul_mod(sa, a[i]);
    ans = add_mod(w, ans);
  }

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define mod 1000000007

using namespace std;
long long add_mod(long long a, long long b) {
  long long re = (a % mod) + (b % mod);
  return re % mod;
}
long long mul_mod(long long a, long long b) {
  long long re = (a % mod) * (b % mod);
  return re % mod;
}

int main(void) {
  int n;
  cin >> n;
  long long a[n + 1];
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  long long ans, w;
  ans = 0;
  w = 0;
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j < n + 1; j++) {
      w = mul_mod(a[i], a[j]);
      // cout<<"a[i] = "<<a[i]<<",  a[j] = "<<a[j]<<endl;
      // cout<<"j = "<<j<<", w = "<<w<<endl;
      ans = add_mod(w, ans);
    }
    // cout<<"i = "<<i<<",  ans = "<<ans<<endl;
  }

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

// Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
#define ios                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long
#define endl '\\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const ll m = 1e9 + 7;
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  return (a.second < b.second);
}

int main() {
  ios;
  int n;
  cin >> n;
  ll a[n];
  ll sum[n + 1] = {};
  ll s = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = n - 1; i >= 0; i--)
    sum[i] += sum[i + 1] + a[i];
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    a[i] %= m;
    sum[i + 1] %= m;
    s += (a[i] * sum[i + 1]) % m;
    s %= m;
  }
  cout << s << endl;
}


Error: TLE

Fixed submission:

// Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
#define ios                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define ll long long
#define endl '\\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const ll m = 1e9 + 7;
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
  return (a.second < b.second);
}

int main() {
  ios;
  int n;
  cin >> n;
  ll a[n];
  ll 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 = (sum % m) + ((a[i] % m) * (a[j] % m)) % m;
    }
  }
  cout << sum << endl;
}
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;
#define div 1000000007

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b;
  ll sum = 0;

  rep(i, n) {
    cin >> a[i];
    sum += a[i];
    if (div <= sum) {
      sum = sum % div;
    }
    b.emplace_back(sum);
  }
  ll ans = 0;
  rep(i, n - 1) { ans = (ans + a[n - 1 - i] * b[n - 2 - i]) % div; }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b;
  rep(i, n) cin >> a[i];
  ll sum = 0;
  rep(i, n) {
    sum += a[n - i - 1];
    sum = sum % div;
    b.insert(b.begin(), sum);
  }

  ll ans = 0;
  rep(i, n - 1) { ans = (ans + a[i] * b[i + 1]) % div; }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;
long long n, a[300006], s, sum = 0, sum1 = 0;
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    sum1 += (a[i] * sum);
    sum1 %= 1000000007;
    sum += a[i];
    sum %= 1000000007;
  }
  /*sort(a+1,a+n);
  for(int i=1;i<=n;++i)
  {
          s=sqrt(a[i])+1;
          for(int j=1;j<=s;++j)
          {
                  if(a[j]>s)
                  break;
                  if(a[i]%a[j]==0&&a[i]!=a[j])
                  sum+=a[i];
          }
  }*/
  printf("%lld", sum1 % 1000000007);
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;
long long n, a[100006], s, sum = 0, sum1;
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    sum1 += (a[i] * sum);
    sum1 %= 1000000007;
    sum += a[i] % 1000000007;
  }
  /*sort(a+1,a+n);
  for(int i=1;i<=n;++i)
  {
          s=sqrt(a[i])+1;
          for(int j=1;j<=s;++j)
          {
                  if(a[j]>s)
                  break;
                  if(a[i]%a[j]==0&&a[i]!=a[j])
                  sum+=a[i];
          }
  }*/
  printf("%lld", sum1 % 1000000007);
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for (int i = (a); i > (b); i--)
typedef long long ll;
const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  ll sum = 0;
  FOR(i, 0, n) {
    cin >> arr[i];
    sum = (sum + arr[i]) % mod;
  }

  vector<ll> suff(n);
  ll d = 0;

  ll ans = 0;
  FOR(i, 0, n) {
    d = (d + arr[i]) % mod;
    suff[i] = (sum - d) % mod;
    if (suff[i] < 0)
      suff[i] = (suff[i] + mod) % mod;
    ans = (ans + (arr[i] % mod * suff[i] % mod) % mod) % mod;
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for (int i = (a); i > (b); i--)
typedef long long ll;
const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  FOR(i, 0, n) { cin >> arr[i]; }
  ll sum = 0;
  FOR(i, 0, n) {
    FOR(j, i + 1, n) {
      sum = (sum + (arr[i] % mod * arr[j] % mod) % mod) % mod;
    }
  }
  cout << sum << 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;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N + 1, 0);
  int mod = 1000000007;
  ll ans = 0;

  rep(i, N) {
    cin >> A.at(i);
    B.at(i + 1) = B.at(i) + A.at(i);
  }
  rep(i, N) {
    ll sum = (B.at(N) - B.at(i + 1)) % mod;

    ans += A.at(i) * sum;
    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)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A.at(i);
  ll sum = 0;

  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      sum += A.at(i) * A.at(j);
      sum %= 1000000007;
    }
  }
  cout << sum << endl;
  return 0;
}