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

#include <iostream>

using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll a[n];
  ll sum[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];

  sum[n - 1] = 0;
  for (int i = n - 2; i >= 0; --i) {
    sum[i] = (sum[i + 1] + a[i + 1]) % 1000000007;
  }

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

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll ans = 0L;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      ans = (ans + a[i] * a[j]) % 1000000007;
    }
  }

  cout << ans << 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;

  // Search for all i
  for (int i = 0; i < N; i++) {
    // Update the values of A[i+1] ... A[N]
    sum -= A[i];
    if (sum < 0)
      sum += mod;

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

  cout << ans << endl;
}

Error: 0

Fixed submission:

// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
#define nl "\\n"
#define vd " "
#define fo(a, b, c) for (i = a; i <= b; i += c)
#define Fo(a, b, c) for (i = a; i >= b; i -= c)
#define pb push_back
#define ins insert
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define tc(T) while (T--)
#define vec vector
#define p(f) cout << f << nl;
ll T;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  //  cin >> T;
  // tc(T)
  // {
  ll n, mx = 0, i, q, p, j, k, w, l, m, x = 2, y = 1, cc = 0, pp = 0, flag = 0,
        klag = 0, blag = 0, count = 0, sum = 0;
  string s, s2;
  bool ok = 1;
  cin >> n;
  ll a[n - 1];
  fo(0, n - 1, 1) {
    cin >> a[i];
    sum += a[i];
  }
  fo(0, n - 2, 1) {
    mx += a[i];
    count += (a[i] * (sum - mx)) % 1000000007;
  }
  cout << count << nl;
  //  }
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>

using namespace std;

const int sz = 1000000007;

int main() {
  int n;
  cin >> n;
  long long arr[n];
  long long pref[n];

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

  pref[0] = arr[0];
  for (int i = 1; i < n; i++) {
    pref[i] = pref[i - 1] + arr[i];
  }

  long long sum = 0;
  for (int i = 1; i < n; i++) {
    sum += (((pref[i - 1] % sz) * (arr[i] % sz)) % sz);
  }

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

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

const int sz = 1000000007;

int main() {
  int n;
  cin >> n;
  long long arr[n];

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

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

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i, n) for (int i = 0; i < n; i++)
#define fp(i, k, n) for (int i = k; i <= n; i++)
#define fr(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define dbg(x) cout << (#x) << " is " << (x) << '\\n'
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define mems(x) memset(x, 0, sizeof(x))
#define all(a) a.begin(), a.end()

/*---------------------------------------------------------------------------------------------------*/
void solve() {
  int n;
  cin >> n;

  int a[n], sum[n];

  cin >> a[0];
  sum[0] = a[0];

  fp(i, 1, n - 1) {
    cin >> a[i];
    sum[i] = a[i] + sum[i - 1];
    // sum[i] %= mod;
  }

  int ans = 0;

  f(i, n) {
    int curr = sum[n - 1] - sum[i];
    curr %= mod;

    curr *= a[i];
    curr %= mod;
    ans += curr;
  }

  cout << ans % mod;
}

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i, n) for (int i = 0; i < n; i++)
#define fp(i, k, n) for (int i = k; i <= n; i++)
#define fr(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define dbg(x) cout << (#x) << " is " << (x) << '\\n'
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define mems(x) memset(x, 0, sizeof(x))
#define all(a) a.begin(), a.end()

/*---------------------------------------------------------------------------------------------------*/
void solve() {
  int n;
  cin >> n;

  int a[n];
  f(i, n) cin >> a[i];

  int ans = 0;

  f(i, n - 1) {
    fp(j, i + 1, n - 1) { ans += (a[i] * a[j]) % mod; }
  }

  cout << ans % mod;
}

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

#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define M 1000000007
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<ll> b(n, 0);
  b[n - 1] = (a[n - 1]) % M;
  for (int i = n - 2; i >= 0; i--) {
    b[i] = ((b[i + 1] % M) + (a[i] % M)) % M;
  }
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    ll k = ((b[i] % M) - (a[i] % M) + M) % M;
    sum = ((sum % M) + ((a[i] % M) * (k % M)) % M) % M;
  }
  cout << sum << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define M 1000000007
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll sum = 0;
  for (int i = 0; i < n - 1; i++) {
    ll m1 = 0;
    for (int j = i + 1; j < n; j++) {
      if (m1 > M) {
        m1 %= M;
      }
      m1 += ((a[i] % M) * (a[j] % M)) % M;
    }
    sum = (sum + m1) % M;
  }
  cout << sum << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define endl '\\n'
#define pb push_back
const int N = 1e5 + 1;
const int INF = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  int ans = 0;
  int x = 1;
  int p[n];
  p[0] = A[0];
  for (int i = 1; i < n; i++) {
    p[i] = (A[i] + p[i - 1]) % INF;
  }
  for (int i = 1; i < n; i++) {
    ans += (A[i] * p[i - 1]);
    ans %= INF;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define endl '\\n'
#define pb push_back
const int N = 1e5 + 1;
const int INF = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += (A[i] * A[j]);
      ans = ans % INF;
    }
  }
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

#define vi vector<int>
#define vii vector<vector<int>>
#define ll long long int
const int mod = 1e9 + 7;
void testcase() {
  ll n;
  cin >> n;
  ll ar[n + 1];
  // ll t[n + 1] = {0};
  ll sum = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> ar[i];
    // t[i] = (ar[i] % mod + t[i - 1] % mod) % mod;
    sum = (sum % mod + ar[i] % mod) % mod;
  }
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    // cout << t[n - i] << " ";
    sum = (sum % mod - ar[i] % mod) % mod;
    if (sum < 0) {
      sum += mod;
    }
    ans = (ans % mod + (ar[i] % mod * sum % mod) % mod) % mod;
  }
  cout << ans << "\\n";
}

int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  testcase();
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

#define vi vector<int>
#define vii vector<vector<int>>
const int mod = 1e9 + 7;
void testcase() {
  long long int n;
  cin >> n;
  long long int ar[n];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = (ans % mod + (ar[i] % mod * ar[j] % mod) % mod) % mod;
    }
  }
  cout << ans << " ";
}

int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  testcase();
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t total = 0;
  int64_t a[200010];
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  int64_t b = 0;
  for (int i = 0; i < N; i++) {
    total += b * a[i] % 1000000007;
    b += a[i];
    b %= 1000000007;
  }
  cout << total % 1000000007 << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t total = 0;
  int64_t a[200010];
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    for (int u = i + 1; u < N; u++) {
      if (a[i] * a[u] >= 1000000007)
        total += a[i] * a[u] % 1000000007;
      else
        total += a[i] * a[u];
      if (total >= 1000000007)
        total = total % 1000000007;
    }
  }
  // if(total>=1000000007) cout<<total%1000000007<<endl;
  cout << total << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1e9 + 7;
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);
  cout.tie(0);

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

  ll sum1 = 0;

  for (int i = 0; i < n - 1; i++) {
    sum = sum - a[i];

    sum1 = sum1 + ((sum % mod) * (a[i] % mod)) % mod;
    sum1 = sum1 % mod;
  }

  cout << sum1;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
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);
  cout.tie(0);

  ll mod = 1e9 + 7;
  ll n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];

  ll sum = 0;

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

      sum = ((sum % mod) + (p % mod)) % mod;
    }
  }
  cout << sum;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<int, pii> viii;
typedef vector<pll> vll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vector<vl>> vvvl;
ll mod = 1e9 + 7;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll i, j, n, sum = 0;
  cin >> n;
  vl a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum = (sum + a[i]) % mod;
  }
  ll ans = 0, curr = 0;
  for (i = 0; i < n; i++) {
    curr = (curr + a[i]) % mod;
    ans = (ans + (((sum - curr + mod) % mod) * a[i]) % mod) % mod;
  }
  cout << ans << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<int, pii> viii;
typedef vector<pll> vll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vector<vl>> vvvl;
ll mod = 1e9 + 7;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll i, j, n, sum = 0;
  cin >> n;
  vl a;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum = (sum + a[i]) % mod;
  }
  ll ans = 0, curr = 0;
  for (i = 0; i < n; i++) {
    curr = (curr + a[i]) % mod;
    ans = (ans + (((sum - curr + mod) % mod) * a[i]) % mod) % mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  ll A[200005];
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  ll out = 0;
  ll su = 0;
  for (int i = 0; i < N; i++) {
    if (i > 0)
      su = (su + A[i - 1]) % (1000000007);
    out = (out + (A[i] * su)) % (1000000007);
  }
  cout << out << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

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

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define pci pair < char, int
#define mii map<int, int>
#define mll map<long long int, long long int>
#define mci map<char, int>
#define umii unordered_map<int, int>
#define umll unordered_map<long long int, long long int>
#define umci unordered_map<char, int>
#define F first
#define S second
#define pb push_back
#define endl '\\n'
#define mod 1000000007
using namespace std;
// ll visit[100001]={0};
// vector<ll> adj[1000001];

int main() {
  IOS;
  int t;
  t = 1; // cin>>t;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++)
      cin >> a[i];
    ll ans = 0;
    ll suf[n];
    suf[n - 1] = a[n - 1];
    for (ll j = n - 2; j >= 0; j--) {
      suf[j] = (a[j] + suf[j + 1]) % mod;
    }
    for (ll i = 0; i < n - 1; i++) {
      ans = (ans + (a[i] * suf[i + 1]) % mod) % mod;
    }
    cout << ans;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define pci pair < char, int
#define mii map<int, int>
#define mll map<long long int, long long int>
#define mci map<char, int>
#define umii unordered_map<int, int>
#define umll unordered_map<long long int, long long int>
#define umci unordered_map<char, int>
#define F first
#define S second
#define pb push_back
#define endl '\\n'
#define mod 1000000007
using namespace std;
// ll visit[100001]={0};
// vector<ll> adj[1000001];

int main() {
  IOS;
  int t;
  t = 1; // cin>>t;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++)
      cin >> a[i];
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
      for (ll 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;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const int mod = 1e9 + 7;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const int mod = 1e9 + 7;

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

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

int main(void) {
  int N;
  cin >> N;
  vector<unsigned long long> A(N);

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

  unsigned long long sum{0};

  unsigned long long sum_j{0};
  for (int j{1}; j < N; ++j) {
    sum_j += A[j];
  }

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

  cout << sum << endl;
}


Error: TLE

Fixed submission:

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

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

  long sum{0};

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

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

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

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

  vector<ll> A(N);
  ll ans = 0;
  ll sum = 0;
  ll seki = 0;
  ll mod = 1000000007;

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

  for (ll i = 0; i < N; i++) {
    sum += A.at(i);
  }

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

Error: TLE

Fixed submission:

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

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

  vector<ll> A(N);
  ll ans = 0;
  ll seki = 0;
  ll mod = 0;

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

  for (ll i = 0; i < N; i++) {
    for (ll j = i + 1; j < N; j++) {
      seki = A.at(i) * A.at(j);
      mod = seki % 1000000007;
      ans += mod;
      //    cout << mod << endl;
    }
  }

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

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

typedef long long ll;
#define MOD1 1000000007
#define MOD2 1000000009
#define FOR(a, b) for (int i = a; i < b; i++)
#define nl "\\n"

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

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


Error: TLE

Fixed submission:

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

typedef long long ll;
#define MOD1 1000000007
#define MOD2 1000000009
#define FOR(a, b) for (int i = a; i < b; i++)
#define nl "\\n"

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

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

#include <iostream>
using namespace std;

int main() {
  long long ans = 0;
  int n;
  cin >> n;

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

  long long b[n + 1] = {};
  for (int i = n - 1; i >= 0; i--) {
    b[i] = b[i + 1] + a[i];
    b[i] = b[i] % 1000000007;
  }

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long long ans = 0;
  int n;
  cin >> n;

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

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

int main() {
  long long n;

  cin >> n;

  vector<long long> a(n);

  long long sum = 0;

  long long MOD = 1000000007;
  long long ans = 0;

  rep(i, n) {
    cin >> a.at(i);
    ans += a.at(i);
    ans %= MOD;
  }
  // cout << ans << endl;

  for (int i = 0; i < n; i++) {
    ans -= a.at(i);
    if (ans < 0)
      ans += MOD;
    sum += (a.at(i) * ans);
    sum %= MOD;
  }

  cout << sum;
}


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() {
  long long n;

  cin >> n;

  vector<long long> a(n);

  long long sum = 0;

  long long MOD = 1000000007;

  rep(i, n) { cin >> a.at(i); }

  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += (a.at(i) * a.at(j)) % MOD;
    }
  }

  cout << sum % MOD;
}