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

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

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

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

  long long ans = 0;
  long long sum = 0;
  long long kari = 0;

  for (int i = 0; i < N; i++)
    sum += A[i];

  for (int i = 0; i < N; i++) {
    sum -= A[i];
    kari = sum % 1000000007;
    ans += A[i] * kari;
    ans %= 1000000007;
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

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

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

  long long ans = 0;
  long long sum = 0;
  long long kari = 0;

  for (int i = 0; i < N; i++) {
    sum = 0;
    kari = 0;
    for (int j = 0; j < N - i; j++) {
      sum += A[i + j + 1];
      sum %= 1000000007;
    }
    kari = A[i] * sum;
    kari %= 1000000007;
    ans += kari;
    ans %= 1000000007;
  }

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

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

int main() {
  ll MOD = 1000000007;
  ll N;
  cin >> N;
  // cout << "N = " << N << endl;
  vector<ll> A(N, 0);
  vector<ll> B(N + 1, 0);
  ll sum = 0;
  rep(i, N) {
    cin >> A[i];
#if 1
    B[i + 1] = B[i] + A[i];
#else
    if (i != 0) {
      sum += A[i];
    }
#endif
  }

#if 1

#else
  vector<ll> Sumv(N - 1, 0);
  rep(i, N - 1) {
    if (i == 0) {
      Sumv[i] = sum % MOD;
    } else {
      Sumv[i] = (Sumv[i - 1] - A[i]) % MOD;
    }
    // cout << "Sumv[" << i << "] = " << Sumv[i] << endl;
  }
#endif
  ll ans = 0;
  rep(i, N - 1) {
#if 1
    ll sumt = (B[N] - B[i + 1]) % MOD;
    ans += A[i] * sumt;
#else
    ans += A[i] * Sumv[i];
#endif
    ans %= MOD;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  ll MOD = pow(10, 9) + 7;
  ll N;
  cin >> N;
  vector<ll> A(N, 0);
  rep(i, N) {
    ll tmp;
    cin >> tmp;
    A[i] = tmp;
  }
  ll ans = 0;
  for (int i = 0; i < (N - 1); ++i) {
    for (int j = i + 1; j < N; ++j) {
      // cout << "A[i] = " << A[i] << ",A[j] = " << A[j] << ", tmp =" << A[i] *
      // A[j] << endl;
      ll tmp1 = A[i] % MOD;
      ll tmp2 = A[j] % MOD;
      // cout << "tmp1 = " << tmp1 << ",tmp2 = " << tmp2 << endl;
      ll tmp = (tmp1 * tmp2) % MOD;
      // cout << "tmp = " << tmp << endl;
      ans = (ans + tmp) % MOD;
    }
  }
  cout << ans << 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 REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()

int64_t N;
vector<int64_t> A;

int64_t MOD = MOD = 1000000007;

int main() {
  std::cout << std::fixed << std::setprecision(20);

  cin >> N;

  A = vector<int64_t>(N, 0);

  REP(i, N) { cin >> A[i]; }

  int64_t x = 0;
  REP(i, N) {
    x += A[i];
    x %= MOD;
  }

  int64_t ans = 0;
  REP(i, N - 1) {
    x = x - A[i];
    x %= MOD;
    if (x < 0) {
      x += MOD;
    }
    ans += A[i] * x;
    ans %= MOD;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

#define ALL(v) v.begin(), v.end()

int64_t N;
vector<int64_t> A;

int64_t MOD = MOD = 1000000007;

int main() {
  std::cout << std::fixed << std::setprecision(20);

  cin >> N;

  A = vector<int64_t>(N, 0);

  REP(i, N) { cin >> A[i]; }

  int64_t ans = 0;
  REP(i, N - 1) {
    int64_t t = 0;
    FOR(j, i + 1, N) {
      t += A[j];
      t %= MOD;
    }
    t %= MOD;
    ans += A[i] * t;
    ans %= MOD;
  }

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

#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int S;
  cin >> S;
  vector<long long> a(S);
  long long sum = 0;
  for (int i = 0; i < S; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int i;
  long long total = 0;
  long long M = 1000000007;

  for (i = 0; i < S - 1; i++) {
    sum -= a[i];
    total += (sum % M * a[i]) % M;
    total %= M;
  }
  cout << total << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int S;
  cin >> S;
  vector<long long> a(S);
  for (int i = 0; i < S; i++) {
    cin >> a[i];
  }
  long long i, j;
  long long total = 0;
  long long M = 1000000007;

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

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
long long a[200001], d[200001];
long long mod = 1000000007;
int main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    d[i] = (d[i - 1] + a[i]) % mod;
  }
  long long sum = 0;
  for (long long i = n; i >= 2; i--) {
    sum = (sum + (a[i] * d[i - 1]) % mod) % mod;
  }
  printf("%lld\\n", sum % mod);
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
long long a[200001];
long long mod = 1000000007;
int main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  long long sum = 0;
  for (long long i = 1; i <= n; i++) {
    long long tot = 0;
    for (long long j = i + 1; j <= n; j++) {
      tot = (tot + a[j]) % mod;
    }
    sum = (sum + (a[i] * tot) % mod) % mod;
  }
  printf("%lld\\n", sum % mod);
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

int main() {
  int64_t N, count;
  cin >> N;
  count = 0;
  vector<int64_t> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    while (vec.at(i) > 200000014) {
      vec.at(i) -= 1000000007;
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      count += vec.at(i) * vec.at(j);
      while (count > 200000014)
        count -= 1000000007;
      while (count < 0)
        count += 1000000007;
    }
  }
  for (int i = 0; i < N; i++) {
    count -= vec.at(i) * vec.at(i);
    while (count < 0)
      count += 1000000007;
  }
  count = count * 0.5;

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

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

#define N 200000
#define MOD 1000000007

int main() {

  int n, list[N];
  long long s = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> list[i];
    s += list[i];
  }

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

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


Error: TLE

Fixed submission:

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

#define N 200000

int main() {

  unsigned int s = 0, n, list[N];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> list[i];
  }

  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      s += ((unsigned long)list[i] * list[j]) % 1000000007;
      s %= 1000000007;
    }
  }

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

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

#define mod 1000000007
using ll = long long;

int main() {

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

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

  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

#define mod 1000000007
using ll = long long;

int main() {

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

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

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

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

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];
  }
  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    sum -= a[i];
    ll msum = sum % mod;
    ll pro = msum * a[i];
    pro %= mod;
    ans += pro;
  }
  cout << ans % mod << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;
using ll = long long;

const ll mod = 1000000007;

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

#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[n];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    sum -= a[i];
    ans += ((sum % mod) * a[i]) % mod;
    ans = ans % mod;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = (ans % mod + (a[i] % mod * a[j] % mod) % mod) % mod;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

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

#define GO                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long int

const int maxr = 2e5 + 5;

int arr[maxr], prefix[maxr];
const int M = 1e9 + 7;
int32_t main() {
  GO;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  prefix[0] = arr[0];
  for (int i = 1; i < n; i++) {
    prefix[i] = arr[i] + prefix[i - 1];
    prefix[i] %= M;
  }
  int ans = 0;
  for (int i = n - 2; i >= 0; i--) {
    ans += (prefix[i] * arr[i + 1]);
    ans %= M;
  }
  cout << ans << endl;
  return 0;
}

//!

Error: 0

Fixed submission:

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

#define GO                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;

int arr[maxr], prefix[maxr];
const int M = 1e9 + 7;
int32_t main() {
  GO;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  prefix[0] = arr[0];
  for (int i = 1; i < n; i++) {
    prefix[i] = arr[i] + prefix[i - 1];
    prefix[i] %= M;
  }
  int ans = 0;
  for (int i = n - 2; i >= 0; i--) {
    ans += (prefix[i] * arr[i + 1]);
    ans %= M;
  }
  cout << ans << 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(0);
  cout.tie(0);
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  long long n;
  cin >> n;
  long long mod = 1e9 + 7;
  vector<long long> a(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> ps(n - 1, 0);
  ps[n - 2] = a[n - 1];
  for (int i = n - 2; i > 0; i--) {
    ps[i - 1] = (ps[i] + a[i]) % mod;
  }
  long long sm = 0;
  for (int i = 0; i < n - 1; i++) {
    long long prod = (a[i] * ps[i]) % mod;
    sm = (sm + prod) % mod;
    // for(int j = i+1; j < n; j++){
    //     long long prod = (a[i]*a[j])%mod;
    //     sm = (sm + prod)%mod;
    // }
  }
  cout << sm << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  long long n;
  cin >> n;
  long long mod = 1e9 + 7;
  vector<long long> a(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> ps;
  ps.push_back(a[n - 1]);
  for (int i = n - 2; i > 0; i--) {
    long long ls = ps[0];
    ps.insert(ps.begin(), (ls + a[i]) % mod);
  }
  long long sm = 0;
  for (int i = 0; i < n - 1; i++) {
    long long prod = (a[i] * ps[i]) % mod;
    sm = (sm + prod) % mod;
    // for(int j = i+1; j < n; j++){
    //     long long prod = (a[i]*a[j])%mod;
    //     sm = (sm + prod)%mod;
    // }
  }
  cout << sm << 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);
typedef long long ll;

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

  fastio;

  int n;
  cin >> n;
  ll arr[n], sum = 0, prod = 0, mod = 1000000007;

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

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

  cout << prod;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);
typedef long long ll;

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

  fastio;

  int n;
  cin >> n;

  ll arr[n], sum = 0;

  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (i > 0)
      sum += ((arr[0] % 1000000007) * (arr[i] % 1000000007)) % 1000000007;
  }

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

  cout << sum % 1000000007;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#define Mod 1000000007
using namespace std;
long long ans, n, a[200001], k[200001];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i], k[i] = (a[i] + k[i - 1]) % Mod;
  k[0] = 0;
  for (int i = 1; i <= n; i++) {
    ans = (ans + (k[i - 1] * a[i]) % Mod) % Mod;
  }
  cout << ans % Mod;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#define Mod 1000000007
using namespace std;
long long ans, n, a[200001];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i], a[i] %= Mod;
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++)
      ans = (ans % Mod + (a[i] % Mod) * (a[j] % Mod) % Mod) % Mod;
  }
  cout << ans % Mod;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

int main() {
  // freopen("input.in","r",stdin);
  // freopen("output.in","w",stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll i, j, n, k, sum(0);
  ll val = 1e9 + 7, temp(0), temp2(0);
  cin >> n;
  vector<ll> v(n), s(n + 1, 0);
  for (i = 0; i < n; i++) {
    cin >> v[i];
    temp += v[i];
    s[i + 1] = temp;
  }
  for (i = 0; i < n - 1; i++) {
    temp2 += (v[i] * ((s[n] - s[i + 1]) % val)) % val;
  }
  cout << temp2 % val;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

int main() {
  // freopen("input.in","r",stdin);
  // freopen("output.in","w",stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll i, j, n, k, sum(0);
  ll val = 1e9 + 7;
  cin >> n;
  vector<ll> v(n);
  for (auto &it : v)
    cin >> it;
  for (i = 0; i < n - 1; i++) {
    if (v[i]) {
      for (j = i + 1; j < n; j++) {
        sum += (v[j] * v[i]) % val;
        sum %= val;
      }
    }
  }
  cout << sum;

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

#include <bits/stdc++.h>
using namespace std;
long long sum[200005];
int main() {
  long long mod = 1000000007;
  long long n;
  cin >> n;
  long long a[n];
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    sum = sum % mod;
  }

  long long pum = sum;
  long long rum = 0;
  for (long long i = 0; i < n - 1; i++) {
    // cout<<sum[n-1]<<" "<<sum[i]<<" "<<a[i]<<endl;

    pum = pum - a[i];
    if (pum < 0)
      pum += mod;
    rum += (a[i] * pum);
    rum = rum % mod;
  }
  cout << rum;
}


Error: WA

Fixed submission:

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

long long sum[100006];
int main() {
  long long mod = 1000000007;
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sum[0] = a[0] % mod;
  for (long long i = 1; i < n; i++) {
    sum[i] = (a[i] + sum[i - 1]);
  }
  long long pum = 0;
  for (long long i = 0; i < n - 1; i++) {
    // cout<<sum[n-1]<<" "<<sum[i]<<" "<<a[i]<<endl;
    long long k = 1;
    k = (k * a[i]) % mod;
    k = (k * (sum[n - 1] - sum[i])) % mod;
    pum = (pum + k) % mod;
  }
  cout << pum;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#define N 1000000007
long long a[1000000];
int main() {
  int n;
  cin >> n;
  long long m[10000000];
  for (int i = 1; i <= n; i++) {

    cin >> a[i];
    m[i] = (m[i - 1] + a[i]);
  }
  long long sum = 0;
  for (int i = 3; i <= n; i++) {
    /*
    long long a=(m[i]-m[i-1])%N;
    long long b=(m[n-1]-m[i])%N;
//		cout<<i+1<<":   a-"<<a<<"  b-"<<b<<endl;
    long long q=(a*b)%N;
    sum+=q%N;
    sum=sum%N;
    */
    sum += (a[i] % N) * (m[i - 1] % N) % N;
    sum %= N;
  }

  sum += (a[1] % N) * (a[2] % N);
  sum %= N;
  cout << sum;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
#define N 1000000007
long long a[100000];
int main() {
  int n;
  cin >> n;
  long long m[200000];
  for (int i = 1; i <= n; i++) {

    cin >> a[i];
    m[i] = (m[i - 1] + a[i]);
  }
  long long sum = 0;
  for (int i = 3; i <= n; i++) {
    /*
    long long a=(m[i]-m[i-1])%N;
    long long b=(m[n-1]-m[i])%N;
//		cout<<i+1<<":   a-"<<a<<"  b-"<<b<<endl;
    long long q=(a*b)%N;
    sum+=q%N;
    sum=sum%N;
    */
    sum += (a[i] % N) * (m[i - 1] % N) % N;
    sum %= N;
  }

  sum += (a[1] % N) * (a[2] % N);
  sum %= N;
  cout << sum;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#define N 1000000007
long long a[10000000];
long long m[20000000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {

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

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
#define N 1000000007
long long a[100000];
int main() {
  int n;
  cin >> n;
  long long m[200000];
  cin >> a[0];
  m[0] = a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    m[i] = (m[i - 1] + a[i]);
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    long long x = m[n - 1] - m[i];
    sum += (x * a[i]) % N;
    sum = sum % N;
  }
  cout << sum;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repab(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define pb push_back
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
#define endl "\\n"

typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//--//--//--//--//--//--//--//--//--//--//--//

int main() {
  int n;
  ll ans = 0;
  cin >> n;
  vec<ll> a(n);
  vec<ll> s(n + 1, 0);

  rep(i, n) {
    cin >> a[i];
    s[i + 1] = s[i] + a[i];
  }
  rep(i, n) { ans += a[i] * ((s[n] - s[i + 1]) % MOD) % MOD; }
  cout << ans % MOD << endl;
}

Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repab(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define pb push_back
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()
#define endl "\\n"

typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//--//--//--//--//--//--//--//--//--//--//--//

int main() {
  int n;
  ll ans = 0;
  vec<ll> a(n);
  vec<ll> s(n + 1, 0);

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

#include <iostream>
#include <vector>
using namespace std;
int MOD = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<long long> b(n + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i + 1] = a[i] + b[i];
  }

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

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
long long MOD = 1000000007;
int main() {
  int n;
  cin >> n;
  long long m;
  vector<long long> a;
  for (int i = 0; i < n; i++) {
    cin >> m;
    a.push_back(m);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = (ans + ((a[i] * a[j]) % MOD)) % MOD;
    }
  }
  cout << ans << endl;
  return 0;
}