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

#include <bits/stdc++.h>

#define ull unsigned long long
#define ll long long

using namespace std;

ll m = 1e9 + 7;

ll mod(ll a, ll b) { return ((a % b) + b) % b; }

ll modmulti(ll a, ll b) { return mod(mod(a, m) * mod(b, m), m); }

ll modsum(ll a, ll b) { return mod(mod(a, m) + mod(b, m), m); }

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

  ull ans = 0, n;
  cin >> n;
  vector<ull> v(n + 1);
  vector<ull> s(n + 1);
  for (ull i = 1; i <= n; i++) {
    cin >> v[i];
    s[i] = modsum(s[i - 1], v[i]);
    if (s[i] >= m)
      s[i] %= m;
  }
  for (ull i = 1; i <= n - 1; i++) {
    ans = modsum(ans, modmulti(v[i], s[n] - s[i]));
    if (ans >= m)
      ans %= m;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define MOD (ull)(1e9 + 7)
#define ull unsigned long long
#define ll long long

using namespace std;

long long modmul(long long a, long long b, long long mod) {
  long long res = 0; // Initialize result

  // Update a if it is more than
  // or equal to mod
  a %= mod;

  while (b) {
    // If b is odd, add a with result
    if (b & 1)
      res = (res + a) % mod;

    // Here we assume that doing 2*a
    // doesn't cause overflow
    a = (2 * a) % mod;

    b >>= 1; // b = b / 2
  }

  return res;
}

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

  ull ans = 0;
  int n;
  cin >> n;
  vector<int> v(n + 1);
  vector<ull> s(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    s[i] = s[i - 1] + v[i];
    if (s[i] >= MOD)
      s[i] %= MOD;
  }
  for (int i = 1; i <= n - 1; i++) {
    ans += modmul(v[i], s[n] - s[i], MOD);
    ans %= 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++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(), i.end()
using namespace std;
const long long INF = 1e9 + 7;
const string alp = "abcdefghijklmnopqrstuvwxyz"; // 26
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
// const ll MOD=998244353LL;
// const ll MOD=1777777777LL;

int main() {
  ll N;
  cin >> N;
  ll a[N];
  ll sum = 0;
  rep(i, N) {
    cin >> a[i];
    sum += a[i];
    sum %= INF;
  }
  ll ans = 0;
  for (int i = 0; i < N - 1; i++) {
    sum -= a[i];
    if (sum < 0)
      sum += INF;
    ans += (sum * a[i]);
    ans %= INF;
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(), i.end()
using namespace std;
const long long INF = 1e9 + 7;
const string alp = "abcdefghijklmnopqrstuvwxyz"; // 26
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
// const ll MOD=998244353LL;
// const ll MOD=1777777777LL;

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

#include <bits/stdc++.h>
using namespace std;
#define m 1000000007
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  ll i, j, sum = 0, x = 0;
  ll a[n];
  for (ll i; i < n; i++) {
    cin >> a[i];
    sum = sum + a[i];
  }
  for (ll i = 0; i < n - 1; i++) {
    sum = sum - a[i];
    x = x + sum % m * a[i] % m;
    x = x % m;
  }
  cout << x;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define m 1000000007
int main() {
  ll n;
  cin >> n;
  ll a[n];
  ll i, j, sum = 0;

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

  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      sum = (sum % m + ((a[i] % m) * (a[j] % m)) % m) % m;
    }
  }
  cout << sum;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long lint;
const lint N = 2e5 + 5, mod = 1e9 + 7;
lint n, a[N];

int main() {
#ifdef LOCAL
  freopen("input", "r", stdin);
#endif

  scanf("%lld", &n);

  for (int i = 0; i < n; i++)
    scanf("%lld", &a[i]);

  lint sum = a[n - 1], ans = 0;

  for (int i = n - 2; i >= 0; i--) {
    int add = (a[i] * sum) % mod;
    ans = (ans + add) % mod;
    sum = (sum + a[i]) % mod;
  }

  printf("%lld\\n", ans);

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long lint;
const lint N = 1e5 + 5, mod = 1e9 + 7;
lint n, a[N];

int main() {
#ifdef LOCAL
  freopen("input", "r", stdin);
#endif

  scanf("%lld", &n);

  for (int i = 0; i < n; i++)
    scanf("%lld", &a[i]);

  lint sum = a[n - 1], ans = 0;

  for (int i = n - 2; i >= 0; i--) {
    int add = (a[i] * sum) % mod;
    ans = (ans + add) % mod;
    sum = (sum + a[i]) % mod;
  }

  printf("%lld\\n", ans);

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

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

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \\
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \\
            c i) {
sim > struct rge {
  c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<long long> v(n);
  long long sum = 0;
  for (long long &i : v)
    cin >> i;
  vector<long long> suf(n, 0);
  suf[n - 1] = v[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    suf[i] = (v[i] + suf[i + 1] % mod) % mod;
  }
  for (int i = 0; i < n - 1; i++) {
    sum = (sum % mod + suf[i + 1] % mod * v[i] % mod) % mod;
  }

  cout << sum << "\\n";
}


Error: TLE

Fixed submission:

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

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \\
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \\
            c i) {
sim > struct rge {
  c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<long long> v(n);
  long long sum = 0;
  for (long long &i : v)
    cin >> i;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      sum = (sum % mod + (v[i] % mod * v[j] % mod)) % mod;
    }
  }
  cout << sum << "\\n";
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

  ll result = 0;
  //   for (ll i = 0; i < N - 1; i++) {
  //     ll sum = 0;

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

  cout << result << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

  cout << result << endl;

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

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

int n;
long long a[200005];
const long long MOD = (long long)(1e9) + 7;

void solve() {
  long long subsum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    subsum = (subsum + a[i]) % MOD;
  }

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    subsum = (subsum - a[i] + MOD) % MOD;
    ans = (ans + (a[i]) * subsum % MOD) % MOD;
  }
  cout << ans << '\\n';
}

int main() {
  // int t; cin >> t;
  // while(t--)
  solve();
}

Error: 0

Fixed submission:

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

int n;
long long a[100005];
const long long MOD = (long long)(1e9) + 7;

void solve() {
  long long subsum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    subsum = (subsum + a[i]) % MOD;
  }

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    subsum = (subsum - a[i] + MOD) % MOD;
    ans = (ans + (a[i]) * subsum % MOD) % MOD;
  }
  cout << ans << '\\n';
}

int main() {
  // int t; cin >> t;
  // while(t--)
  solve();
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

/*******************************************************************
 * 		Author : yash1402_
 **
 ******************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

#define MOD 1000000007

void solve() {
  ll n;
  cin >> n;
  vll v(n);

  for (auto &i : v)
    cin >> i;

  ll s = 0, ans = 0;

  for (ll i = 0; i < n; i++) {
    s = s + v[i];
  }

  for (ll i = 0; i < n - 1; i++) {
    s -= v[i];
    ans = (ans + (((v[i] % MOD) * (s % MOD)) % MOD)) % MOD;
  }

  cout << ans << "\\n";
}

int main() {
  ll T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
}


Error: TLE

Fixed submission:

/*******************************************************************
 * 		Author : yash1402_
 **
 ******************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

#define MOD 1000000007

void solve() {
  ll n;
  cin >> n;
  vll v(n);

  for (auto &i : v)
    cin >> i;

  ll s = 0;
  for (ll i = 0; i < n; i++) {
    for (ll j = i + 1; j < n; j++) {
      s = (s + v[i] * v[j]) % MOD;
    }
  }

  cout << s << "\\n";
}

int main() {
  ll T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long x(long long n, long long m) {
  long long N;
  if ((n - m) >= 0)
    N = n - m;
  else
    N = 1000000007 + n - m;
  return N;
}
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a.at(i);
  long long s = 0;
  for (int i = 0; i < n; i++) {
    s += a.at(i);
    s = s % 1000000007;
  }
  long long ans = 0;
  for (int i = 0; i < (n - 1); i++) {
    s = x(s, a.at(i));
    long long p = s * a.at(i);
    ans += p;
    ans = ans % 1000000007;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a.at(i);
  long long sum = 0;
  int c = 0;
  for (int i = 0; i < (n - 1); i++) {
    for (int j = (i + 1); j < n; j++) {
      long long p = a.at(i) * a.at(j);
      sum += p;
      c++;
      if (c == 9) {
        sum = sum % 1000000007;
        c = 0;
      }
    }
  }
  sum = sum % 1000000007;
  cout << sum << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  vector<unsigned long long> X(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = N - 1; i > 0; i--) {
    X[i] = A[i];
    if (i < N - 1)
      X[i] += X[i + 1];
    X[i] %= 1000000007;
  }
  long long sum = 0;
  for (int i = 0; i < N - 1; i++) {

    long long num = A[i] * X[i + 1] % 1000000007;
    sum += num;
  }
  sum %= 1000000007;
  cout << sum;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  long long sum = 0;
  for (int i = 0; i < N - 1; i++) {
    for (long long j = i + 1; j < N; j++) {
      long long num = A[i] * A[j] % 1000000007;
      sum += num;
    }
  }
  sum %= 1000000007;
  cout << sum;
  return 0;
}
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 (int i = 0; i < (int)(n); i++)
#define IN(type, n)                                                            \\
  type n;                                                                      \\
  cin >> n

int main() {
  IN(ll, N);
  vector<ll> A(N);
  ll mod = 1000000007;
  REP(i, N) {
    IN(ll, tmp);
    tmp %= mod;
    A.at(i) = tmp;
  }

  ll ans = 0;
  ll sum = A.at(N - 1);
  for (int i = N - 2; i >= 0; --i) {
    ans += sum * A.at(i);
    ans %= mod;
    sum += A.at(i);
    sum %= mod;
  }
  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 (int i = 0; i < (int)(n); i++)
#define IN(type, n)                                                            \\
  type n;                                                                      \\
  cin >> n

int main() {
  IN(ll, N);
  vector<ll> A(N);
  ll mod = 1000000007;
  REP(i, N) {
    IN(ll, tmp);
    tmp %= mod;
    A.at(i) = tmp;
  }

  ll ans = 0;
  REP(i, N - 1) {
    for (int j = i + 1; j < N; ++j) {
      ans += A.at(i) * A.at(j);
      ans %= mod;
    }
  }
  cout << ans << endl;

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

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll s1 = 0, s2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s1 += a[i];
    s2 += (a[i] * a[i]);
    s1 %= mod;
    s2 %= mod;
  }
  ll res = (s1 * s1 - s2);
  res %= mod;
  while (res < 0)
    res += mod;
  ll ans;
  if (res % 2)
    ans = (res + mod) / 2;
  else
    ans = res / 2;

  cout << ans << '\\n';
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll res = 0;
  for (int i = 0; i < n - 1; i++) {
    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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
int main() {
  ll n;
  cin >> n;
  ll arr[n];
  for (ll &i : arr)
    cin >> i;
  ll sum = 0;
  for (ll i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++)
      sum = (sum + (arr[i] * arr[j]) % mod) % mod;
  }
  cout << sum;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#define int long long

using namespace std;

const int N = 2e5 + 10;
const int MOD = 1e9 + 7;

int a[N];

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

  int sum = 0;
  for (int i = 1; i <= n; ++i)
    cin >> a[i], sum += a[i];

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

  cout << ans << '\\n';

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#define int long long

using namespace std;

const int MOD = 1e9 + 7;
const int N = 2e5 + 10;

int a[N];

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

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

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

  cout << ans % MOD << '\\n';

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

#define _GLIBCXX_DEBUG
#define LIM 1000000007
#include <cstdint>
#include <iostream>
#include <vector>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;

int main(void) {
  int n;
  cin >> n;
  vi a(n), s(n + 1);
  for (i64 &x : a)
    cin >> x;
  for (int i = n - 1; i > 0; i--) {
    s[i] = a[i] + s[i + 1];
    if (s[i] >= LIM)
      s[i] %= LIM;
  }
  i64 sum = 0;
  for (int i = 0; i < n - 1; i++) {
    sum += a[i] * s[i + 1];
    if (sum >= LIM)
      sum %= LIM;
  }
  cout << sum << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#define LIM 1000000007
#include <cstdint>
#include <iostream>
#include <vector>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;

int main(void) {
  int n;
  cin >> n;
  vi a(n);
  for (i64 &x : a)
    cin >> x;
  i64 sum = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      i64 m = a[i] * a[j];
      if (m >= LIM)
        m %= LIM;
      sum += m;
      if (sum >= LIM)
        sum %= LIM;
    }
  }
  cout << sum << '\\n';
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  // int d, t, s;

  // cin >> d >> t >> s;

  // it had better to use double or calculate as multiplier
  //  if (d / s < t)
  //  {
  //      cout << "Yes" << endl;
  //  }
  //  else if (d / s == t && d % s == 0)
  //  {
  //      cout << "Yes" << endl;
  //  }
  //  else
  //  {
  //      cout << "No" << endl;
  //  }

  // string s, t;
  // cin >> s >> t;

  // int sum = 0, tmp;
  // for (int i = 0; i < s.length() - t.length() + 1; i++)
  // {
  //     tmp = 0;
  //     for (int j = 0; j < t.length(); j++)
  //     {

  //         if (s[i + j] == t[j])
  //         {
  //             tmp++;
  //         }
  //     }
  //     if (sum < tmp)
  //     {
  //         sum = tmp;
  //     }
  // }
  // cout << t.length() - sum << endl;
  int mod = 1000000007;
  int n;
  cin >> n;
  vector<int> v(n);
  vector<long long> sum(n + 1, 0);

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

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

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

Error: TLE

Fixed submission:

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  vector<long long> v;
  int n;
  long long sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long num;
    cin >> num;
    v.push_back(num);
  }

  for (auto i = 0; i < v.size() - 1; i++) {

    for (auto j = i + 1; j < v.size(); j++) {
      sum += v[i] * v[j];
      if (1000000007 < sum) {
        sum = sum % 1000000007;
      }
    }
  }

  cout << sum << endl;

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

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

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

    m = (m - a[i] + mod) % mod;

    ma = a[i] * m + ma;
    ma = ma % 1000000007;
  }

  cout << ma;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, a[1000], ma = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i < n; i++)
    for (int j = i + 1; j <= n; j++)
      ma = a[i] * a[j] + ma;

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

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

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

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

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;

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

  long long int ans = 0;
  long long int mo = 1000000007;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i; j < n - 1; j++) {
      ans += (a.at(i) % mo) * (a.at(j + 1) % mo);
      ans = ans % mo;
    }
  }

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

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

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

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += s * a[i];
    ans %= 1000000007;
    s += a[i];
    s %= 1000000007;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  ll s = 0;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll ans = 0;
  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;
}