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

/**
 *	@file: C.cpp
 *	@author: Huy Le
 *	@created: 2020-08-29 19:25
 **/

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

#define ll long long
#define ld long double
#define sz(x) (int)(x).size()
const char newl = '\\n';

void DEBUGLOCAL() { cerr << ")" << newl; }
template <class A, class... B> void DEBUGLOCAL(A argc, B... argv) {
  cerr << argc;
  if (sizeof...(argv))
    cerr << ", ";
  DEBUGLOCAL(argv...);
}
#ifdef _DEBUG
#define dbg(...)                                                               \\
  cerr << "LINE(" << __LINE__ << ") [" << __FUNCTION__ << "] -> ("             \\
       << #__VA_ARGS__ << "): (",                                              \\
      DEBUGLOCAL(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

int ts;
int n;
const ll MOD = 1e9 + 7;
const int mxN = 2e5 + 5;
ll a[mxN];
ll dp[mxN];

void solve() {
  cin >> n;
  ll sum = 0;

  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i] % MOD;
    dp[i] = sum % MOD;
  }
  ll ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    ans += a[i] * dp[i - 1] % MOD;
    ans %= MOD;
  }
  cout << ans << newl;
}

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

  //++i,cout << "Case #" << i << ": ",
  solve();
}


Error: TLE

Fixed submission:

/**
 *	@file: C.cpp
 *	@author: Huy Le
 *	@created: 2020-08-29 19:25
 **/

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

#define ll long long
#define ld long double
#define sz(x) (int)(x).size()
const char newl = '\\n';

void DEBUGLOCAL() { cerr << ")" << newl; }
template <class A, class... B> void DEBUGLOCAL(A argc, B... argv) {
  cerr << argc;
  if (sizeof...(argv))
    cerr << ", ";
  DEBUGLOCAL(argv...);
}
#ifdef _DEBUG
#define dbg(...)                                                               \\
  cerr << "LINE(" << __LINE__ << ") [" << __FUNCTION__ << "] -> ("             \\
       << #__VA_ARGS__ << "): (",                                              \\
      DEBUGLOCAL(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

int ts;
int n;
const ll MOD = 1e9 + 7;
const int mxN = 2e5 + 5;
ll a[mxN];
ll dp[mxN];

void solve() {
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  for (int i = 1; i < n; ++i) {
    ll tmp = 0;
    for (int j = 0; j < i; ++j) {
      tmp += a[i] * a[j] % MOD;
      tmp %= MOD;
    }
    dp[i] = (tmp + dp[i - 1]) % MOD;
    dp[i] %= MOD;
  }
  cout << dp[n - 1] << newl;
}

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

  //++i,cout << "Case #" << i << ": ",
  solve();
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto &&a : (x))
#define _overload3(_1, _2, _3, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) for (ll i = (a); i < (n); ++i)
#define rep(...) _overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template <typename T> inline void print(const T &x) { cout << x << "\\n"; }
template <typename T> inline bool chmax(T &a, const T &b) {
  if (a < b)
    a = b;
  return a < b;
}
template <typename T> inline bool chmin(T &a, const T &b) {
  if (a > b)
    a = b;
  return a > b;
}
struct Init {
  Init() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  }
} init;

int main() {
  ll n;
  cin >> n;
  vi a(n);
  ll s = 0;
  rep(i, n) {
    cin >> a[i];
    s += a[i];
    s %= MOD;
  }
  ll ans = 0;
  rep(i, n - 1) {
    s -= a[i];
    if (s < 0)
      s += MOD;
    ans += a[i] * s;
    ans %= MOD;
  }
  print(ans);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto &&a : (x))
#define _overload3(_1, _2, _3, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) for (ll i = (a); i < (n); ++i)
#define rep(...) _overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template <typename T> inline void print(const T &x) { cout << x << "\\n"; }
template <typename T> inline bool chmax(T &a, const T &b) {
  if (a < b)
    a = b;
  return a < b;
}
template <typename T> inline bool chmin(T &a, const T &b) {
  if (a > b)
    a = b;
  return a > b;
}
struct Init {
  Init() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  }
} init;

int main() {
  ll n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  rep(i, n - 1) {
    rep(j, i + 1, n) {
      ans += a[i] * a[j];
      ans %= MOD;
    }
  }
  print(ans);
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long N;
long long A[2 * 100000 + 1];
const long long mod = 1000000000 + 7;
int main() {
  long long sum = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    sum += A[i];
  }
  sum %= mod;
  sum = (sum * sum) % mod;
  for (int i = 0; i < N; i++) {
    sum -= (A[i] * A[i]) % mod;
  }
  if (sum % 2 != 0)
    sum += mod;
  sum /= 2;
  sum %= mod;
  if (sum < 0)
    sum += mod;
  cout << sum << endl;
}

Error: TLE

Fixed submission:

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

long long N;
long long A[2 * 100000 + 1];
int main() {
  int sum = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      sum = (sum + A[i] * A[j]) % (1000000000 + 7);
    }
  }
  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 < (int)(n); i++)
using namespace std;
using ll = long long;

int main() {
  unsigned long long int n;
  cin >> n;
  unsigned long long int a[n];
  unsigned long long int mod = pow(10, 9) + 7;
  rep(i, n) {
    cin >> a[i];
    if (a[i] >= mod) {
      a[i] %= mod;
    }
  }
  // rep(i,n){
  //     cout<<a[i]<<endl;
  // }
  unsigned long long int ans = 0;
  unsigned long long int sum = 0;

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

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 main() {
  unsigned long long int n;
  cin >> n;
  unsigned long long int a[n];
  unsigned long long int mod = pow(10, 9) + 7;
  rep(i, n) {
    cin >> a[i];
    if (a[i] >= mod) {
      a[i] %= mod;
    }
  }
  // rep(i,n){
  //     cout<<a[i]<<endl;
  // }
  unsigned long long int ans = 0;

  for (unsigned long long int i = 0; i < n - 1; i++) {
    for (unsigned long long int j = i + 1; j < n; j++) {
      unsigned long long int tmp = a[i] * a[j];
      ans += tmp;
      ans %= mod;
      // cout<<ans<<endl;
    }
  }
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int mod = 1e9 + 7;

long long mult(long long first, long long second) {
  return (((first % mod) * (second % mod)) % mod);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long ans = 0;
  vector<long long> second(n);
  second[n - 1] = a[n - 1];
  for (int i = n - 1; i >= 2; --i) {
    second[i - 1] = a[i - 1] + second[i];
  }
  second[n - 1] = a[n - 1];
  //    second[]
  //   for(long long s : second){
  //        cout << s << " ";
  //    }
  for (int i = 1; i < n; ++i) {
    ans = (ans % mod + mult(a[i - 1], second[i]) % mod) % mod;
  }
  //    ans = (ans%mod + )
  // cout << "ANS? " << ans << endl;
  //    cout << endl;
  //    ans = 0;
  //    for(int i = 0; i < n; ++i){
  //        for(int j = i + 1; j < n; ++j){
  //            ans = (ans%mod + mult(a[i],a[j])%mod)%mod;
  //        }
  //    }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

const int mod = 1e9 + 7;

long long mult(long long first, long long second) {
  return (((first % mod) * (second % mod)) % mod);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<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 + mult(a[i], a[j]) % mod) % mod;
    }
  }
  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
#define int long long
  int N, sum = 0;
  cin >> N;
  int MOD = 1000000007;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
    sum %= MOD;
  }
  int ans = 0;
  for (int i = 0; i < N - 1; i++) {
    sum -= A.at(i) - MOD;
    sum %= MOD;
    ans += sum * A.at(i);
    ans %= MOD;
  }
  cout << ans << endl;
}

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;
  unsigned long long a[n + 10];
  rep(i, n) cin >> a[i];

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

  cout << ans % 1000000007ULL << endl;

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

#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long a[200005];
int main() {
  int n;
  scanf("%d", &n);
  long long tot1 = 0, tot2 = 0;
  for (int i = 1; i <= n; ++i)
    scanf("%lld", &a[i]), tot1 += a[i], tot2 += a[i] * a[i] % mod;
  tot1 %= mod;
  tot2 %= mod;
  long long ans = tot1 * tot1 % mod;
  ans = (ans - tot2) % mod + mod;
  printf("%lld\\n", ans * 500000004 % mod);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long a[100005];
int main() {
  int n;
  scanf("%d", &n);
  long long tot1 = 0, tot2 = 0;
  for (int i = 1; i <= n; ++i)
    scanf("%lld", &a[i]), tot1 += a[i], tot2 += a[i] * a[i] % mod;
  tot1 %= mod;
  tot2 %= mod;
  long long ans = tot1 * tot1 % mod;
  ans = (ans - tot2) % mod + mod;
  printf("%lld\\n", ans * 500000004 % mod);
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#define rep(i, p) for (long long int i = 0; i < p; i++)
#define reep(i, p) for (long long int i = 1; i <= p; i++)
#define ll long long

using namespace std;

int main() {

  ll int N;
  cin >> N;
  ll int sum = 0;
  ll int M;
  M = 1000000007;
  vector<ll int> A(N);
  rep(i, N) {
    cin >> A[i];
    sum = (sum + A[i]) % M;
  }
  ll int ans = 0;
  ll int syo;
  rep(i, N - 1) {
    sum = sum - A[i] % M;
    if (sum < 0)
      sum += M;
    ans = (ans + (sum * A[i]) % M) % M;
    // cout << ans << endl;
  }
  cout << ans;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>

#define rep(i, p) for (long long int i = 0; i < p; i++)
#define reep(i, p) for (long long int i = 1; i <= p; i++)
#define ll long long

using namespace std;

int main() {

  ll int N;
  cin >> N;
  vector<ll int> A(N);
  rep(i, N) { cin >> A[i]; }
  ll int ans = 0;
  ll int syo;
  ll int M;
  M = 1000000007;

  rep(i, N - 1) {
    for (long long int j = i + 1; j < N; j++) {
      syo = A[i] % M;
      syo = (syo * A[j]) % M;
      ans = (ans + syo) % M;
      // cout << ans << endl;
    }
  }
  cout << ans;

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < ((int)n); i++)
typedef pair<int, int> P;
using ll = long long;
const int INF = 1e9;
const ll mod = 1e9 + 7;

int main() {
  ll n, all = 0, ans = 0;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    all += a[i];
  }
  rep(i, n - 1) {
    all -= a[i];

    ans += (a[i] % mod) * (all % mod);
    ans %= mod;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < ((int)n); i++)
typedef pair<int, int> P;
using ll = long long;
const int INF = 1e9;
const ll mod = 1e9 + 7;

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

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

using ll = long long;
// print(fixed << setprecision(10));
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repk(i, n, k) for (ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9 + 7;

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  ll ans = 0, sum = 0;
  rep(i, n) {
    cin >> a[i];
    ans = (ans + (a[i] * sum) % MOD) % MOD;
    sum += a[i];
    if (sum > MOD)
      sum %= MOD;
  }
  print(ans);
  return 0;
}

Error: TLE

Fixed submission:

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

using ll = long long;
// print(fixed << setprecision(10));
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repk(i, n, k) for (ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9 + 7;

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

  ll n;
  cin >> n;
  vector<ll> a(n), sum(1, 0);
  ll ans = 0, cnt = 0;
  rep(i, n) {
    cin >> a[i];
    for (auto s : sum)
      ans = (ans + (a[i] * s) % MOD) % MOD;
    if (sum[cnt] + a[i] >= MOD) {
      cnt++;
      sum.emplace_back(a[i]);
    } else
      sum[cnt] += a[i];
  }
  print(ans);
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int nmax = 2e5;
const int mod = 1e9 + 7;

int main() {
  int n, a[nmax + 1], s[nmax + 1], ans = 0;
  cin >> n;
  s[0] = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    s[i] = (s[i - 1] + a[i]) % mod;
  }
  for (int i = 1; i <= n; ++i) {
    int sum = s[n] - s[i] < 0 ? s[n] - s[i] + mod : s[n] - s[i];
    int to_add = ((long long)a[i] * (long long)sum) % (long long)mod;
    ans = (ans + to_add) % mod;
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int i64;

const int nmax = 2e5;
const int mod = 1e9 + 7;

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

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  int64_t ans = 0;

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  int64_t x = A.at(0) % (1000000007);

  for (int i = 1; i < N; i++) {
    ans += (A.at(i) * x);
    ans %= (1000000007);
    x += A.at(i);
    x %= (1'000'000'007);
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  int64_t ans = 0;

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);

    for (int j = 0; j < i; j++) {
      ans += (A.at(i) * A.at(j));
      ans %= (1000000007);
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
const unsigned int M = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  vector<long long> B(n + 1, 0);
  long ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    B[i + 1] = B[i] + A[i];
  }
  for (int i = 0; i < n; i++) {
    long long sum = (B[n] - B[i + 1]) % M;
    ans += A[i] * sum;
    ans %= M;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const unsigned int M = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<unsigned long long int> A(n);
  unsigned long long int ans = 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++) {
      ans += A[i] * A[j];
      if (ans > M) {
        ans = ans % M;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

// Code by : h_mm

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define ull unsigned long long
#define ll long long
#define t                                                                      \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
ll mod = 1000000007;
using namespace std;

int main(void) {
  int n;
  cin >> n;
  ll a[n], b[n];
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    sum %= mod;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    sum -= a[i];
    if (sum < 0)
      sum += mod;
    ans += a[i] * (sum);
    ans %= mod;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

// Code by : h_mm

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define ull unsigned long long
#define ll long long
#define t                                                                      \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
using namespace std;

int main(void) {
  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; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += ((a[i] % 1000000006) * (a[j] % 1000000006)) % (1000000007);
    }
  }
  cout << ans % 1000000007;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#define onlycc                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#define MOD 1000000007
using namespace std;

typedef long long ll;

ll a[200000], n, e, square;

ll mod(ll a, int b) {
  if (b == 1)
    return a;
  if (b == 0)
    return 1;

  ll tmp = mod(a, b / 2);
  if (b % 2 == 1)
    return (((tmp * tmp) % MOD) * a) % MOD;
  else
    return (tmp * tmp) % MOD;
}

int main() {
  onlycc;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  if (n == 1) {
    cout << a[0] % MOD;
    return 0;
  }

  for (int i = 0; i < n; i++)
    e = (e % MOD + a[i] % MOD) % MOD;

  e = (e % MOD * e % MOD) % MOD;

  for (int i = 0; i < n; i++)
    square = ((square % MOD) + ((a[i] % MOD * a[i] % MOD) % MOD)) % MOD;

  cout << ((e % MOD - square % MOD + MOD) % MOD) * mod(2, MOD - 2) % MOD;

  return 0;
}


Error: TLE

Fixed submission:

#define onlycc                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#include <algorithm>
#include <iostream>
#include <string>
#define MOD 1000000007
using namespace std;

typedef long long ll;

ll a[200000], n, ret;

int main() {
  onlycc;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];

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

  cout << ret;

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

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

const int mod = 1e9 + 7;

using ll = long long;

int solve(const vector<ll> &A, ll n) {
  ll sum = A[0];
  ll res = 0;
  for (int i = 1; i < n; i++) {
    res = (res + (sum * A[i]) % mod) % mod;
    sum = (sum + A[i]) % mod;
  }
  return res;
}
int32_t main() {
  ll n;
  cin >> n;
  vector<ll> arr(n);
  for (ll &i : arr)
    cin >> i;
  cout << solve(arr, n) << '\\n';
}


Error: TLE

Fixed submission:

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

const int mod = 1e9 + 7;

using ll = long long;

/* int findProductSum(vector<ll>& A, ll n) */
/* { */
/*     ll array_sum = 0; */
/*     for (ll i = 0; i < n; i++) array_sum = (array_sum + A[i]) % mod; */

/*     ll array_sum_square = (array_sum * array_sum) % mod; */

/*     ll individual_square_sum = 0; */
/*     for (ll i = 0; i < n; i++) individual_square_sum = (individual_square_sum
 * + A[i]*A[i]) % mod; */

/*     return (array_sum_square - individual_square_sum) / 2; */
/* } */

int32_t main() {
  ll n;
  cin >> n;
  vector<ll> arr(n);
  for (ll &i : arr)
    cin >> i;
  /* cout << findProductSum(arr, n) << '\\n'; */
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      sum = (sum + (arr[i] * arr[j]) % mod) % mod;
    }
  }
  cout << sum << '\\n';
}