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

/*
Author: Hrujul Thumar
*/
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define vi vector<int>
#define whilet()                                                               \\
  int t;                                                                       \\
  scanf("%d", &t);                                                             \\
  while (t--)
#define vp vector<pair<int, int>, int>
#define pb push_back
#define mii map<int, int>
#define pii pair<int, int>
#define msi map<string, int>
#define psi pair<string, int>
#define mpi map<pair<int, int>, int>
#define fo(i, l, u) for (i = l; i < u; i++)
#define rfo(i, l, u) for (i = l; i >= u; i--)
#define ef else if
#define MOD 1000000007
#define endl '\\n'
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pi 3.141592653589793238
const long long MAX_SIZE = 1000000000;
using namespace std;

signed main() {
  fastio int n;
  cin >> n;
  int a[n];
  int ans = 0;
  int pre[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i != 0)
      pre[i] = pre[i - 1] % MOD + a[i] % MOD;
    else
      pre[i] = a[i];
  }
  for (int i = n - 1; i >= 1; i--) {
    ans = ans % MOD + ((a[i] % MOD) * (pre[i - 1]) % MOD) % MOD;
    // cout<<pre[i-1]<<" "<<ans<<endl;
  }
  cout << ans % MOD << endl;
}


Error: TLE

Fixed submission:

/*
Author: Hrujul Thumar
*/
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define vi vector<int>
#define whilet()                                                               \\
  int t;                                                                       \\
  scanf("%d", &t);                                                             \\
  while (t--)
#define vp vector<pair<int, int>, int>
#define pb push_back
#define mii map<int, int>
#define pii pair<int, int>
#define msi map<string, int>
#define psi pair<string, int>
#define mpi map<pair<int, int>, int>
#define fo(i, l, u) for (i = l; i < u; i++)
#define rfo(i, l, u) for (i = l; i >= u; i--)
#define ef else if
#define MOD 1000000007
#define endl '\\n'
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pi 3.141592653589793238
const long long MAX_SIZE = 1000000000;
using namespace std;

signed main() {
  fastio int n;
  cin >> n;
  int a[n];
  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 = ans % MOD + (a[i] % MOD * a[j] % MOD) % MOD;
    }
  }
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n, i, j, k;
  cin >> n;
  ll ar[n], br[n];
  for (i = 0; i < n; i++)
    cin >> ar[i];
  br[n - 1] = ar[n - 1];
  for (i = n - 2; i >= 0; i--) {
    br[i] = ar[i] + br[i + 1];
  }
  ll ans = 0;
  ll m = 1000000007;
  for (i = n - 2; i >= 0; i--) {
    ans = ((ans % m) + ((ar[i] % m) * (br[i + 1] % m)) % m) % m;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll n, i, j, k;
  cin >> n;
  ll ar[n];
  for (i = 0; i < n; i++)
    cin >> ar[i];
  ll ans = 0;
  ll m = 1000000007;
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      ans = ((ans % m) + ((((ar[i] % m)) * (ar[j] % m)) % m)) % m;
    }
  }
  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 < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
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;
  ll total = 0;
  rep(i, N) total += A[i];
  rep(i, N) {
    total -= A[i];
    ans += (A[i] * (total % mod)) % mod;
    ans %= mod;
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}

  mint operator-() const { return mint(-x); }

  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }

  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }

  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }

  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }

  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }

  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }

  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }

  mint &operator/=(const mint a) { return (*this) *= a.inv(); }

  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  int N;
  cin >> N;
  vector<mint> A(N);
  rep(i, N) {
    int a;
    cin >> a;
    A[i] = mint(a);
  }

  mint ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      ans += A[i] * A[j];
    }
  }
  cout << ans.x << 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 < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  rep(i, N) { cin >> A.at(i); }

  int64_t ans = 0;

  int64_t sum_rest = 0;
  for (int i = 0; i < N; i++) {
    sum_rest += A.at(i);
    sum_rest %= 1000000007LL;
  }

  rep(i, N - 1) {
    if (sum_rest >= A.at(i)) {
      sum_rest -= A.at(i);
    } else {
      sum_rest += 1000000007LL - A.at(i);
    }
    ans += A.at(i) * sum_rest % 1000000007LL;
    ans %= 1000000007LL;
  } // end rep i
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  rep(i, N) { cin >> A.at(i); }

  int64_t ans = 0;

  rep(i, N - 1) {
    int64_t sum = 0LL;
    for (int j = i + 1; j < N; j++) {
      sum += A.at(j);
    } // end for j
    sum %= 1000000007LL;
    ans += A.at(i) * sum % 1000000007LL;
    ans %= 1000000007LL;
  } // end rep i
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <math.h>
#include <stdio.h>
int main() {
  long long int i, n, s = 0, ans = 0, a[200009], m = 1e9 + 7;
  scanf("%lld", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    ans += s * a[i];
    ans %= m;
    s += a[i];
    s %= m;
  }
  printf("%lld", ans);
}

Error: 0

Fixed submission:

#include <math.h>
#include <stdio.h>
int main() {
  long long int i, n, a[20000], s1 = 0, m = 1e9 + 7, ans = 0, s = 0;
  scanf("%lld", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    s += a[i];
  }
  for (i = 0; i < n; i++) {
    s1 += a[i];
    ans += ((a[i] % m) * (s - s1) % m) % m;
    ans %= m;
  }
  printf("%lld\\n", ans);
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
using namespace std;
ll mx = 1e9 + 7;
void solve() {
  ll n;
  cin >> n;
  ll a, sum = 0, p = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a;
    sum += a * p;
    p += a;
    p = p % mx;
    sum = sum % mx;
  }

  cout << sum << endl;
}

int main() {
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
using namespace std;
ll mx = 1e9 + 7;
void solve() {
  ll n;
  cin >> n;
  ll a[n], sum = 0, p;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    a[i] = a[i] % mx;
  }
  for (ll i = 0; i < n - 1; i++) {
    for (ll j = i + 1; j < n; j++) {
      p = a[i] * a[j];
      p = p % mx;
      sum += p;
      sum = sum % mx;
    }
  }
  cout << sum << endl;
}

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

#include <bits/stdc++.h>
using namespace std;
// void dfs(unordered_map<int,unordered_set<int>>&m,int st)
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  long long int t;
  int mod = 1000000007;

  int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int pa[n];
  long long int c = 0;
  for (int i = 0; i < n; i++) {
    c += a[i];
    pa[i] = c;
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    long long int ff = (c - pa[i]) % mod;
    long long int ss = (a[i] * ff) % mod;
    ans = (ans + ss) % mod;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// void dfs(unordered_map<int,unordered_set<int>>&m,int st)
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  long long int t;
  int mod = 1000000007;

  int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int pa[n];
  long long int c = 0;
  for (int i = 0; i < n; i++) {
    c += a[i];
    pa[i] = c;
  }
  long long int 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;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define p 1000000007
int main() {
  // your code goes here
  int n;
  cin >> n;
  long long a[n], sum = 0, res = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  for (long long i = n - 1; i >= 0; i--) {
    sum -= a[i];
    res += ((sum % p) * a[i]);
    res %= p;
  }
  cout << res;
  return 0;
}

Error: TLE

Fixed submission:

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

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

void solve(long long N, std::vector<long long> A) {
  vector<long long> cumsum(N + 1, 0);
  ll ans = 0;
  for (ll i = 0; i < N; ++i) {
    cumsum[i + 1] = cumsum[i] + A[i];
  }
  for (ll i = 0; i < N; ++i) {
    ans += A[i] * ((cumsum[N] - cumsum[i + 1]) % MOD);
    ans %= MOD;
  }
  cout << ans << endl;
  return;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Error: WA

Fixed submission:

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

void solve(long long N, std::vector<long long> A) {
  ll i = 0;
  ll ans = 0;
  while (i < N - 1) {
    for (ll j = i + 1; j < N * N; ++j) {
      ans += A[i] % MOD * A[j] % MOD;
      ans = ans % MOD;
    }
    i++;
  }
  cout << ans % MOD << endl;
  return;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define loop(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF = 0x3f3f3f40;
const long long mod = 1e9 + 7;
const long double PI = acos(0);
// }}} End Header
int main() {
  ll n, ans = 0, sum = 0;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  rep(i, n - 1) {
    sum -= a[i];
    ll t = ((a[i] % mod) * (sum % mod));
    ans += t;
    ans %= mod;
  }
  cout << ans << endl;
  // cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define loop(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF = 0x3f3f3f40;
const long long mod = 1e9 + 7;
const long double PI = acos(0);
// }}} End Header
int main() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n - 1) {
    loop(j, i + 1, n) {
      ll t = (a[i] * a[j]) % mod;
      ans += t;
      ans %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
  ll n;
  ll m = 1000000007;
  cin >> n;
  ll a[n];
  ll p[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll res = 0;
  p[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    p[i] = (p[i + 1] + a[i]) % m;
  }
  for (int i = 0; i < n - 1; i++) {
    res = (res % m + (a[i] * p[i + 1]) % m) % m;
  }
  cout << res;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
  ll n;
  ll m = 1000000007;
  cin >> n;
  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 = (res % m + (a[i] * a[j]) % m) % m;
    }
  }
  cout << res;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

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

  mint ans = 0;
  ll s = asum;
  for (int i = 0; i < N - 1; i++) {
    s -= A.at(i);
    ans += mint(s) * A.at(i);
  }
  cout << ans.x << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  int N;
  cin >> N;
  vector<mint> A(N);
  ll a;
  for (int i = 0; i < N; i++) {
    cin >> a;
    A.at(i) = a;
  }

  mint ans = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      ans += A.at(i) * A.at(j);
    }
  }
  cout << ans.x << endl;

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

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

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

  int mod = 7 + pow(10, 9);
  unsigned long long ans = 0;

  int sum = 0;
  long long a = 0;
  for (int i = 0; i < N; i++) {
    cin >> a;
    ans = (ans + (a * sum) % mod) % mod;
    sum = (sum + a) % mod;
  }
  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);
  int div = 7 + pow(10, 9);
  unsigned long long sum = 0;

  int a = 0;
  for (int i = 0; i < N; i++) {
    cin >> a;
    A.at(i) = a;
    for (int k = 0; k < i; k++) {
      sum += (A.at(k) * a) % div;
    }
  }
  sum = sum % div;
  cout << sum << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int sum = 0;
  long long int arr[n];
  long long int main = 0;
  long long int mod = 1000000007;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  for (int i = 0; i < n; i++) {
    sum = sum - arr[i];
    main += (arr[i] % mod * (sum % mod)) % mod;
  }
  cout << main % mod << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long int n;
  cin >> n;
  long long int arr[n];
  long long int sum = 0;
  int M = 1000000007;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum = (sum % M + ((arr[i] % M) * (arr[j] % M)) % M) % M;
    }
  }
  cout << sum % M << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define pai 3.1415926535897932384

using namespace std;
using ll = long long;
using P = pair<int, int>;

#define MOD 1000000007;

int main(int argc, const char *argv[]) {

  int N;
  ll A[200000];
  ll AA[200000];

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (i == 0)
      AA[i] = A[i];
    else
      AA[i] = (A[i] + AA[i - 1]) % MOD;
  }

  ll Ans = 0;
  for (int i = 0; i < N; i++) {
    Ans += (AA[i] * A[i]) % MOD;
    Ans = (Ans - A[i] * A[i]) % MOD;
    if (Ans < 0)
      Ans += MOD;
  }

  cout << Ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define pai 3.1415926535897932384

using namespace std;
using ll = long long;
using P = pair<int, int>;

#define MAX_MOD 1000000007;

int main(int argc, const char *argv[]) {

  ll Ans = 0;
  int N;
  int A[200000];

  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 += A[i] * A[j];
      Ans = Ans % MAX_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;

int main() {
  int n;
  cin >> n;
  ll a[n], pref[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  pref[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; i--)
    pref[i] = a[i] + pref[i + 1];

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

#include <bits/stdc++.h>
// #define INF 1e9
using namespace std;
long long int arr[200001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;
  long long int total = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    total += arr[i] % 1000000007;
    total %= 1000000007;
  }
  long long int sum = 0;
  long long int m_sum = 0;
  for (int i = 0; i < n; i++) {
    m_sum += arr[i];
    m_sum = m_sum % 1000000007;
    sum = sum + arr[i] * (total - m_sum) % 1000000007;
    if (sum < 0)
      sum += 1000000007;
    sum = sum % 1000000007;
  }
  cout << sum % 1000000007;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// #define INF 1e9
using namespace std;

// 자동 정렬은 ctrl k f
// 주석은 ctrl k c
// 주석 해제는 ctrl k u
//  int gcd(int a, int b){
//  	while(b!=0){
//  		int r= a%b;
//  		a=b;
//  		b=r;
//  	}
//  	return a;
//  }
//  int lcm(int a, int b){
//  	return a*b/gcd(a,b);
//  }
long long int arr[200001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    // arr[i] %= 1000000007;
  }
  long long int sum = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += arr[i] % 1000000007 * arr[j] % 1000000007;
    }
  }
  cout << sum % 1000000007;

  return 0;
}