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

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

int main() {
  int N;
  cin >> N;
  // cout << M << endl;*/

  vector<unsigned long long int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  unsigned long long int tmp_sum = 0;
  /*for(int i = 0; i < vec.size(); i++){
    tmp_sum = tmp_sum+vec.at(i);
  }*/

  unsigned long long int sum = 0;

  for (int i = 1; i < vec.size(); i++) {
    tmp_sum = (tmp_sum + vec.at(i - 1)) % 1000000007;
    sum = (sum + vec.at(i) * tmp_sum) % 1000000007;
  }

  cout << sum % 1000000007 << endl;
  /*for (int i = 0; i < vec.size(); i ++){
    cout << vec.at(i) << endl;
  }

  for (int i = 0; i < vec.size()-1; i ++){
    cout << vec.at(i) << " ";
  }
  cout << vec.at(vec.size() - 1) << endl;*/
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  // cout << M << endl;*/

  vector<unsigned long int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  unsigned long int sum = 0;

  for (int i = 0; i < vec.size(); i++) {
    for (int j = 0; j < i; j++) {
      sum = (sum + vec.at(i) * vec.at(j)) % 1000000007;
    }
  }

  cout << sum % 1000000007 << endl;
  /*for (int i = 0; i < vec.size(); i ++){
    cout << vec.at(i) << endl;
  }

  for (int i = 0; i < vec.size()-1; i ++){
    cout << vec.at(i) << " ";
  }
  cout << vec.at(vec.size() - 1) << endl;*/
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

// ABC177C -

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

typedef unsigned long long int ull;
typedef long long int ll;

#define MOD 1000000007

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

  ull sum = 0;
  ull psum[N];

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

  sum %= MOD;

  ull ans = 0;
  for (int i = 0; i < N - 1; i++) {
    ull temp = 0;
    if (sum > psum[i]) {
      temp = (sum - psum[i]) % MOD;
    } else {
      temp = (sum - psum[i] + MOD) % MOD;
    }
    ans += (A[i] * temp) % MOD;
  }

  ans %= MOD;
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

// ABC177C -

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

typedef unsigned long long int ull;
typedef long long int ll;

#define MOD 1000000007

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

  ull 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 <cmath>
#include <iostream>
#include <string>

using namespace std;

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

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

  const long modnum = pow(10, 9) + 7;
  long A_sum[N + 1];
  A_sum[N + 1] = 0;
  for (int i = 0; i <= N; i++) {
    A_sum[N - i] = (A_sum[N - i + 1] + A[N - i]) % modnum;
  }

  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    ans = ans + ((A[i] * A_sum[i + 1]) % modnum);
  }
  ans = ans % modnum;
  cout << ans << "\\n";
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <string>

using namespace std;

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

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

  const long modnum = pow(10, 9) + 7;
  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]) % modnum);
    }
  }
  ans = ans % modnum;
  cout << ans << "\\n";
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  vector<long long int> a(N);
  vector<long long int> b(N);
  long long int sum = 0;
  long long int x = 1000000007;
  for (int i = 0; i < N; i++) {
    long long int y;
    cin >> y;
    a[i] = y;
    sum += y;
    sum %= x;
    b[i] = sum;
  }
  sum = 0;

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

  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<long long int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  long long int sum = 0;
  long long int x = 1000000007;
  for (int i = 0; i < N; i++) {
    long long int s = 0;
    for (int j = i + 1; j < N; j++) {
      s += a[j];
    }
    s %= x;
    sum += a[i] * s % x;
    sum %= x;
  }
  cout << sum << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define mp make_pair
#define PI acos(-1)
using namespace std;
const int mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll i, j, k, x, y, z, m, t, n, b, c, d, a, l, r;
  cin >> n;
  vector<ll> v(n);
  for (ll i = 0; i < n; i++)
    cin >> v[i];
  vector<ll> cum(n);
  cum[0] = v[0];
  for (int i = 1; i < n; i++)
    cum[i] = cum[i - 1] + v[i];
  ll ans = 0;
  for (ll i = 0; i < n - 1; i++) {
    ll temp = (v[i] % mod) * ((cum[n - 1] - cum[i]) % mod);
    temp %= mod;
    ans = (ans + temp) % mod;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define mp make_pair
#define PI acos(-1)
using namespace std;
ll a[200005], mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll i, j, k, x, y, z, m, t, n, b, c, d, l, r;
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> a[i];
  ll sum = 0;
  for (i = 1; i <= n; i++) {
    for (j = i + 1; j <= n; j++) {
      sum += a[i] * a[j];
      sum %= mod;
    }
  }
  cout << sum << '\\n';
}
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 int;

const int MOD = 1000000007;

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

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

  vector<modint<MOD>> A(N, 0);
  rep(i, N) cin >> A[i].a;

  modint<MOD> sum = 0;
  for (int i = 1; i < N; i++) {
    sum += A[i];
  }

  modint<MOD> ans = 0;
  for (int i = 0; i < N - 1; i++) {
    ans += A[i] * sum;
    sum -= A[i + 1];
  }

  cout << ans.a;
}

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 int;

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

  vector<ll> A(N, 0);
  rep(i, N) cin >> A[i];

  ll ans = 0;
  rep(i, N) {
    for (int j = i + 1; j < N; j++) {
      ans += (A[i] % 1000000007) * (A[j] % 1000000007);
      ans %= 1000000007;
    }
  }
  cout << ans;
}
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;
typedef long long ll;

int main() {
  ll mod = 1e9 + 7;
  vector<ll> a;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll b;
    cin >> b;
    a.push_back(b % mod);
  }
  ll dp[n + 1];
  ll sum = (a[0] + a[1]) % mod;
  for (int i = 0; i <= n; i++)
    dp[i] = 0;
  dp[1] = a[0] * a[1] % mod;
  for (int i = 1; i < n - 1; i++) {
    dp[i + 1] = dp[i] + a[i + 1] * sum % mod;
    dp[i + 1] %= mod;
    sum += a[i + 1];
    sum %= mod;
  }
  cout << dp[n - 1];
}

Error: TLE

Fixed submission:

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

int main() {
  ll mod = 1e9 + 7;
  vector<ll> a;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll b;
    cin >> b;
    a.push_back(b % mod);
  }
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ll c = a[i] * a[j] % mod;
      sum += c;
      sum %= mod;
    }
  }
  cout << sum;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define F0R(i, a) for (int i = 0; i < (a); i++)
const int mod = 1e9 + 7;
const char nl = '\\n';

ll binpow(ll x, ll n) {
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return binpow(x * x % mod, n / 2);
  else
    return x * binpow(x, n - 1) % mod;
}

int main() {
#ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  ll tmp1 = 0, tmp2 = 0;
  F0R(i, n) {
    ll a;
    cin >> a;
    tmp1 = (tmp1 + a) % mod;
    tmp2 = (tmp2 + a * a % mod) % mod;
  }
  tmp1 = tmp1 * tmp1 % mod;
  cout << (tmp1 - tmp2 + mod) % mod * binpow(2, mod - 2) % mod << nl;
  return 0;
}

Error: TLE

Fixed submission:

/* bimillahir rahmanir rahim...
 * AUTHOR
 * mubin_akib */
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

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

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define REP(i, a, b) for (int i = a; i <= (b); ++i)
#define trav(a, x) for (auto &a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template <class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const char nl = '\\n';

ll binpow(ll x, ll n) {
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return binpow(x * x % mod, n / 2);
  else
    return x * binpow(x, n - 1) % mod;
}

ll solve() {
  ll n;
  cin >> n;
  ll tmp1 = 0, tmp2 = 0;
  F0R(i, n) {
    ll a;
    cin >> a;
    tmp1 = (tmp1 + a) % mod;
    tmp2 = (tmp2 + a * a % mod) % mod;
  }
  tmp1 = tmp1 * tmp1 % mod;
  cout << (tmp1 - tmp2 + mod) % mod * binpow(2, mod - 2) % mod << nl;
}

int main() {
#ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define iso                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
using namespace std;
int main() {
  iso ll n, s = 0, w = 0;
  cin >> n;
  vector<ll> vec;
  while (n--) {
    ll x;
    cin >> x;
    vec.push_back(x);
    s += x;
  }

  for (int i = 0; i < vec.size(); i++) {
    s -= vec[i];
    s %= 1000000007;
    w += s % 1000000007 * (vec[i] % 1000000007);
    w %= 1000000007;
    while (w < 0) {
      w += 1000000007;
    }
    w %= 1000000007;
  }
  cout << w << "\\n";

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define iso                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
using namespace std;
ll pref[10000000];
int main() {
  iso ll n, s = 0;
  cin >> n;
  vector<ll> vec;
  while (n--) {
    ll x;
    cin >> x;
    vec.push_back(x);
  }
  pref[0] = vec[0];
  for (int i = 1; i < vec.size(); i++) {
    pref[i] = (pref[i - 1] + vec[i]) % 1000000007;
  }
  for (int i = 0; i < vec.size(); i++) {
    s +=
        (vec[i] % 1000000007) * ((pref[vec.size() - 1] - pref[i]) % 1000000007);
    while (s < 0) {
      s += 1000000007;
    }
    s %= 1000000007;
  }
  cout << s << "\\n";

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

/* BABA JAGAAAAAA  */

#include <bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL)
#define l long
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9 + 3;

int main() {
  fast;
  // 3rd//
  ll n;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  ll sum[n];
  sum[n - 1] = v[n - 1];
  for (ll i = n - 2; i >= 0; i--) {
    sum[i] = (sum[i + 1] + v[i]) % mod;
  }
  ll ans = 0;
  for (ll i = 0; i < n - 1; i++) {
    ans = (ans % mod + (v[i] * sum[i + 1])) % mod;
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

/* BABA JAGAAAAAA  */

#include <bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define fast                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(NULL)
#define l long
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9 + 3;

int main() {
  fast;
  // 3rd//
  ll n;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  ll sum = 0;
  for (ll i = 0; i < n - 1; i++) {

    for (ll j = i + 1; j < n; j++) {
      ll mul = (v[i] % mod * v[j] % mod) % mod;
      sum = (sum % mod + mul % mod) % mod;
    }
  }
  cout << sum % mod << endl;

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

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int mod = 1000000007;
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
    sum %= mod;
  }

  long ans = 0;

  // i について全探索する
  for (int i = 0; i < N; i++) {
    // A[i+1] ... A[N] の値を更新する
    sum -= A[i];
    if (sum < 0)
      sum += mod;

    ans += A[i] * sum;
    ans %= mod;
  }

  cout << ans << endl;
}

Error: -11

Fixed submission:

#include <iostream>

int main() {
  const int MOD = 1000000007;
  int N, sum = 0;
  int A[N];
  std::cin >> N;
  for (int i = 0; i < N; i++)
    std::cin >> A[i];

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

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

ll mod(ll n) {
  if (n < 0)
    return n + 1000000007;
  else
    return n % 1000000007;
}

int main() {
  // ll n, sum = 0, d_sum = 0, ans = 0;
  // cin >> n;
  // rep(i, n)
  // {
  //     ll a;
  //     cin >> a;
  //     sum = mod(sum + a);
  //     d_sum = mod(d_sum + mod(a * a));
  // }
  // sum = mod(sum);
  // d_sum = mod(d_sum);

  // cout << mod(mod(mod(sum * sum) - d_sum) / 2) << endl;
  // return 0;
  ll n, sum = 0, ans = 0;
  cin >> n;
  ll a[n], b[n];
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
    sum = mod(sum);
  }

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

Error: TLE

Fixed submission:

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

ll mod(ll n) {
  if (n > 0)
    return n % 1000000007;
  else {
    while (n < 0)
      n += 1000000007;
    return n;
  }
}

int main() {
  // ll n, sum = 0, d_sum = 0, ans = 0;
  // cin >> n;
  // rep(i, n)
  // {
  //     ll a;
  //     cin >> a;
  //     sum = mod(sum + a);
  //     d_sum = mod(d_sum + mod(a * a));
  // }
  // sum = mod(sum);
  // d_sum = mod(d_sum);

  // cout << mod(mod(mod(sum * sum) - d_sum) / 2) << endl;
  // return 0;
  ll n, sum = 0, ans = 0;
  cin >> n;
  ll a[n], b[n];
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
    sum %= 1000000007;
  }

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

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  rep(i, n) cin >> a.at(i);
  long long sum = 0;
  rep(i, n) {
    sum += a.at(i);
    sum %= (1000000007 * 2);
  }
  long long sum_sq = 0;
  rep(i, n) {
    long long t;
    t = (a.at(i) * a.at(i)) % (1000000007 * 2);
    sum_sq += t;
    sum_sq %= (1000000007 * 2);
  }
  long long ans;
  ans = (sum * sum - sum_sq) / 2;
  if (ans < 0)
    ans += 1000000007;
  ans %= 1000000007;
  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;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  rep(i, n) cin >> a.at(i);
  long long 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);
      ;
      if (sum > 1000000007)
        sum %= 1000000007;
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define SPEED                                                                  \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long int
#define inf 999999999
#define maxn 100003
const ll mod = 1e9 + 7;
using namespace std;
void code() {
  ll n, sum = 0;
  cin >> n;
  ll ar[n];
  for (ll i = 0; i < n; ++i) {
    cin >> ar[i];
  }
  ll suffixarray[n];
  suffixarray[n - 1] = ar[n - 1];
  for (ll i = n - 2; i >= 0; --i) {
    suffixarray[i] = suffixarray[i + 1] + ar[i];
    suffixarray[i] = suffixarray[i] % mod;
  }
  ll ans = 0;
  for (ll i = 0; i < n - 1; i++) {
    sum = (suffixarray[i + 1] * ar[i]) % mod;
    ans += sum;
    ans %= mod;
  }
  cout << ans;
}
int main() {
  SPEED
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.out", "w", stdout);
#endif
  int t = 1;
  while (t--) {
    code();
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define SPEED                                                                  \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long int
#define inf 999999999
#define maxn 100003
const ll mod = 1e9 + 7;
using namespace std;
ll n, ar[maxn];
void code() {
  ll sum = 0;
  cin >> n;
  for (ll i = 0; i < n; ++i) {
    cin >> ar[i];
  }
  ll suffixarray[n];
  suffixarray[n - 1] = ar[n - 1];
  for (ll i = n - 2; i >= 0; --i) {
    suffixarray[i] = suffixarray[i + 1] + ar[i];
    suffixarray[i] = suffixarray[i] % mod;
  }
  ll ans = 0;
  for (ll i = 0; i < n - 1; i++) {
    sum = (suffixarray[i + 1] * ar[i]) % mod;
    ans += sum;
    ans %= mod;
  }
  cout << ans;
}
int main() {
  SPEED
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.out", "w", stdout);
#endif
  int t = 1;
  while (t--) {
    code();
  }
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 987654321
#define INT_MAX 2147483647
#define MIN(a, b) ((a) < (b) ? a : b)
#define MAX(a, b) ((a) > (b) ? a : b)

using namespace std;

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

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

  unsigned long int segsum, ret;
  segsum = 0;
  ret = 0;

  for (int i = N - 1; i > 0; i--) {
    segsum = (segsum + A[i]) % mod;
    ret = (ret % mod + (segsum * A[i - 1]) % mod) % mod;
  }
  cout << ret;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 987654321
#define INT_MAX 2147483647
#define MIN(a, b) ((a) < (b) ? a : b)
#define MAX(a, b) ((a) > (b) ? a : b)

using namespace std;

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

  int N;
  cin >> N;
  unsigned long int mod = 1000000007;
  vector<unsigned long int> A(N);
  vector<unsigned long int> seg(N - 1);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  for (int i = 1; i < N; i++) {
    unsigned long int sum = 0;
    for (int j = i; j < N; j++) {
      sum += A[j];
    }
    seg[i - 1] = sum % mod;
  }
  unsigned long int ret = 0;
  for (int i = 0; i < N - 1; i++) {
    ret += A[i] * seg[i];
    ret %= mod;
  }
  cout << ret;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define LL long long
#define N 1000001
#define NN 1001
using namespace std;
LL n, a[N];
LL mod = 1000000007;
int main() {
  cin >> n;
  long long s = 0, sum = 0;
  for (LL i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  for (LL i = 1; i <= n; i++) {
    sum -= a[i];
    s = (((a[i] % mod) * (sum % mod) % mod) + s) % mod;
  }
  cout << s << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define LL long long
#define N 100001
#define NN 1001
using namespace std;
LL i, j, n, sum, f = 1000000007;
LL a[N], b[N];
int main() {
  scanf("%lld", &n);
  for (i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  b[1] = a[1];
  for (i = 2; i <= n - 1; i++)
    b[i] = a[i] + b[i - 1];
  for (i = n; i >= 2; i--)
    sum += (a[i] * b[i - 1]) % f;
  printf("%lld", sum % f);
  return 0;
}
/*
 */