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


#include <bits/stdc++.h>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#define endl "\\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
constexpr int MOD = 1000000007;

int main() {
  std::ios::sync_with_stdio(false);
  long N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> sum(N);
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (ll i = N - 2; i >= 0; i--) {
    sum[i] = (sum[i + 1] + A[i + 1]) % MOD;
    // cerr << sum[i] << endl;
  }

  ll total = 0;
  for (size_t i = 0; i < N - 1; i++) {
    total += (A[i] * sum[i]) % MOD;
    total %= MOD;
  }
  cout << total << endl;
  return 0;
}


Error: TLE

Fixed submission:


#include <bits/stdc++.h>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#define endl "\\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;

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

  int64_t ans = 0;

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

  cout << ans << '\\n';
  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<long long> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);

  vector<long long> S(N);
  S.at(N - 1) = 0;
  for (int i = 0; i < N - 1; i++)
    S.at(N - 2 - i) = (S.at(N - 1 - i) + A.at(N - 1 - i)) % 1000000007;

  long long ans = 0, plus;
  for (int i = 0; i < N - 1; i++) {
    plus = (A.at(i) * S.at(i)) % 1000000007;
    ans = (ans + plus) % 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 ans = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      long long plus = A.at(i) * A.at(j);
      plus %= 1000000007;
      ans += plus;
      ans %= 1000000007;
    }
  }
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
typedef map<ll, ll> mp;
typedef pair<int, int> pii;
typedef vector<ll> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;

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);
  int m = 1000000007;
  int n;
  cin >> n;
  vi a(n);
  fo(i, n) cin >> a[i];
  ll sum = 0, sum1 = 0;
  // vi temp;
  for (int i = 0; i < n; i++) {
    sum1 += a[i];
    sum1 %= m;
  }

  for (int i = 0; i < a.size(); i++) {
    sum1 -= a[i];
    if (sum1 < 0)
      sum1 += m;
    sum += a[i] * sum1;
    sum %= m;
  }
  cout << sum << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
typedef map<ll, ll> mp;
typedef pair<int, int> pii;
typedef vector<ll> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;

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);
  int m = 1000000007;
  int n;
  cin >> n;
  vi a(n);
  fo(i, n) cin >> a[i];
  int sum = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum = ((sum) % m + (a[i] * a[j]) % m) % m;
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define int long long int
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n, m) for (int i = n; i >= m; i--)
#define mod 1000000007
#define float long double
#define pb push_back
#define mp make_pair
#define print(v1)                                                              \\
  rep(i, 0, v1.size()) { cout << v1[i] << " "; }                               \\
  cout << "\\n";
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
int modulo(int n, int m = 1000000007) {
  if (n < 0) {
    return (m - abs(n) % m) % m;
  } else
    return n % m;
}
void solve() {
  int n, total = 0, final = 0;
  cin >> n;
  vector<int> v1(n), v2(n + 1);
  rep(i, 0, n) {
    cin >> v1[i];
    total += (v1[i]);
  }
  v2[0] = 0;
  int x = 0;
  rep(i, 1, n + 1) {
    x += v1[i - 1];
    v2[i] = ((total) - (x));
  }
  // v2[i]=((total%mod)-(v1[i-1]%mod)-(v2[i-1]%mod))%mod;
  // print(v2);
  rep(i, 0, n - 1) {
    final += ((v1[i]) * (v2[i + 1] % mod)) % mod;
    final %= mod;
  }
  cout << final % mod;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\\n";
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n, m) for (int i = n; i >= m; i--)
#define mod 1000000007
#define float long double
#define pb push_back
#define mp make_pair
#define print(v1)                                                              \\
  rep(i, 0, v1.size()) { cout << v1[i] << " "; }                               \\
  cout << "\\n";
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
int modulo(int n, int m = 1000000007) {
  if (n < 0) {
    return (m - abs(n) % m) % m;
  } else
    return n % m;
}
void solve() {
  int n, total = 0;
  cin >> n;
  vector<int> v1(n);
  rep(i, 0, n) cin >> v1[i];
  rep(i, 0, n - 1) {
    rep(j, i + 1, n) {
      total += (((v1[j] % mod) * (v1[i] % mod)) % mod);
      total %= mod;
    }
  }
  cout << total;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
  // #endif
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\\n";
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define int long long
#define N 200010
#define M 1010

using namespace std;
const int mod = 1e9 + 7;
int sum[N], a[N], n;

int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch))
    f |= (ch == '-'), ch = getchar();
  while (isdigit(ch))
    s = s * 10 + (ch ^ 48), ch = getchar();
  return f ? -s : s;
}

signed main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read(), sum[i] = (sum[i - 1] + a[i]) % mod;
  int ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    int xx = (sum[n] - sum[i] + mod) % mod;
    ans = (ans + (a[i] * xx) % mod) % mod;
  }
  cout << ans << "\\n";
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define int long long
#define N 100010
#define M 1010

using namespace std;
const int mod = 1e9 + 7;
int sum[N], a[N], n;

int read() {
  int s = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch))
    f |= (ch == '-'), ch = getchar();
  while (isdigit(ch))
    s = s * 10 + (ch ^ 48), ch = getchar();
  return f ? -s : s;
}

signed main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read(), sum[i] = (sum[i - 1] + a[i]) % mod;
  int ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    int xx = (sum[n] - sum[i] + mod) % mod;
    ans = (ans + (a[i] * xx) % mod) % mod;
  }
  cout << ans << "\\n";
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  ll n;

  cin >> n;

  ll arr[n];

  ll arr1[n];

  ll mod = 1e9 + 7;

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

  for (ll i = 1; i < n; i++) {
    arr1[i] = (arr1[i] + arr1[i - 1]);
  }

  ll z = arr1[n - 1];

  ll sum = 0;

  for (ll i = 0; i < n - 1; i++) {
    ll temp = (z - arr1[i]) % mod;

    temp = (temp * arr[i]) % mod;

    sum = (sum + temp) % mod;
  }

  cout << sum % mod;
}


Error: TLE

Fixed submission:

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

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

  ll n;

  // cin >> n;

  scanf("%lld", &n);

  ll arr[n];

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

    scanf("%lld", &arr[i]);
  }

  ll sum = 0;

  ll mod = 1000000007;

  for (ll i = 0; i < n - 1; i++) {
    for (ll j = i + 1; j < n; j++) {
      sum = (sum + ((arr[i] % mod) * (arr[j] % mod)) % mod) % mod;
    }
  }

  printf("%lld", sum);

  // cout << sum;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int p = 1000000007;
long long s[200003], ans, q[200003];
int n, m;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &s[i]);
    q[i] = (s[i] + q[i - 1]) % p;
  }
  for (int i = 2; i <= n; ++i) {
    ans = (ans + (s[i] * (q[i - 1]) % p) % p) % p;
  }
  printf("%lld\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

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

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

void solve() {
  // int n;
  // cin>>n;
  // int a[n];
  // for(int i=0;i<n;i++){
  //     cin>>a[i];
  // }
}
long long mul(long long a, long long b, long long m) {
  long long res = 0;
  while (b) {
    if (b & 1)
      res = (res + a) % m;
    a = (2 * a) % m;
    b = b / 2;
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // int t;
  // cin>>t;
  // while(t--){
  //     solve();
  // }
  int n;
  cin >> n;
  long long m = 1e9 + 7;
  long long a[n];
  long long prefixsum[n];
  cin >> a[0];
  prefixsum[0] = a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    prefixsum[i] = prefixsum[i - 1] + a[i];
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    ans += mul(a[i], prefixsum[n - 1] - prefixsum[i], m);
    ans = ans % m;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

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

void solve() {
  // int n;
  // cin>>n;
  // int a[n];
  // for(int i=0;i<n;i++){
  //     cin>>a[i];
  // }
}
long long mul(long long a, long long b, long long m) {
  long long res = 0;
  while (b) {
    if (b & 1)
      res = (res + a) % m;
    a = (2 * a) % m;
    b = b / 2;
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // int t;
  // cin>>t;
  // while(t--){
  //     solve();
  // }
  int n;
  cin >> n;
  long long m = 1e9 + 7;
  long long a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += mul(a[i], a[j], m);
      // cout<<ans<<" ";
      ans = ans % m;
    }
  }
  cout << ans;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
using namespace std;
unsigned long long a[200001];
unsigned long long b[200001];
int main() {
  fastio int N;
  unsigned long long ans = 0;
  cin >> N;
  for (int i = 1; i <= N; i++)
    cin >> a[i];
  b[1] = a[1];
  for (int i = 2; i <= N; i++) {
    b[i] = a[i] + b[i - 1];
  }
  for (int i = 1; i < N; i++) {
    ans += ((a[i] % 1000000007) * ((b[N] - b[i]) % 1000000007)) % 1000000007;
    ans %= 1000000007;
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);
using namespace std;
long long a[200001];
int main() {
  fastio int N;
  long long ans = 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++) {
      ans += a[i] * a[j];
      ans %= 1000000007;
    }
  }
  cout << ans;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long i, j, m = 0, n, sum = 0;
  const long int k = 1000000007;

  cin >> n;
  vector<long long> a;
  for (i = 0; i < n; i++) {
    cin >> j;
    a.push_back(j);
    sum = sum + a[i];
  }
  for (i = 0; i < n - 1; i++) {
    sum = sum - a[i];
    m = m + (((sum % k) * (a[i] % k)) % k);
    m %= k;
  }
  cout << m << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  unsigned long long n, i, a[200005], j;
  const unsigned int M = 1000000007;
  unsigned long long f = 0;
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> a[i];
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {

      f = (f + (a[i] * a[j])) % M;
    }
  }
  cout << f << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(), v.end()

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<ll> s(N);
  ll ans = 0;
  rep(i, N) {
    cin >> A.at(i);
    if (i == 0) {
      s.at(i) = A.at(i);
    } else {
      s.at(i) += s.at(i - 1) + A.at(i);
    }
  }
  rep(i, N) {
    ll sum = (s.at(N - 1) - s.at(i)) % mod;
    ans += A.at(i) * sum;
    ans %= mod;
  }
  cout << ans << endl;
}


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 inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(), v.end()
int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  ll b;
  rep(i, N) { cin >> a.at(i); }
  ll 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);
      ans %= mod;
    }
  }
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  long long X = 0;

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    A.at(i) = A.at(i) % 1000000007;
    X += A.at(i);
    X = X % 1000000007;
  }
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    X -= A.at(i);
    if (X < 0)
      X += 1000000007;
    sum += A.at(i) * X;
    sum = sum % 1000000007;
  }
  cout << sum << endl;
}


Error: TLE

Fixed submission:

#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.at(i);
    A.at(i) = A.at(i) % 1000000007;
  }
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      long long seki = A.at(i) * A.at(j);
      seki = seki % 1000000007;
      sum += seki;
      sum = sum % 1000000007;
    }
  }
  cout << sum << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define faster                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pi acos(-1.0)
#define nl '\\n'

/// Library
#define mem(a, b) memset(a, b, sizeof(a))
#define all(a) a.begin(), a.end()
#define Sort(x) sort(x.begin(), x.end())
#define Reverse(x) reverse(x.begin(), x.end())
#define SortA(ar, s) sort(ar, ar + s)
#define SortD(ar, s) sort(ar, ar + s, greater<int>())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * (b / gcd(a, b)))
#define sq(x) (x) * (x)

#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min(a, min(b, min(c, d)))
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max(a, max(b, max(c, d)))
#define ABS(x) ((x) < 0 ? -(x) : (x))
#define pb push_back
#define mod 1000000007
#define end printf("\\n")
#define yes printf("YES\\n")
#define no printf("NO\\n")

/// data type
typedef long long int ll;
typedef unsigned long long int llu;

int main() {
  faster ll n;
  cin >> n;
  ll a[n + 2], i, ans = 0, sum = 0;
  ll mx = 1e9 + 7;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    sum %= mx;
  }

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

    ans += a[i] * sum;
    ans %= mx;
  }
  cout << ans << nl;
  return 0;
}


Error: TLE

Fixed submission:

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

#define faster                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define pi acos(-1.0)
#define nl '\\n'

/// Library
#define mem(a, b) memset(a, b, sizeof(a))
#define all(a) a.begin(), a.end()
#define Sort(x) sort(x.begin(), x.end())
#define Reverse(x) reverse(x.begin(), x.end())
#define SortA(ar, s) sort(ar, ar + s)
#define SortD(ar, s) sort(ar, ar + s, greater<int>())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * (b / gcd(a, b)))
#define sq(x) (x) * (x)

#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min(a, min(b, min(c, d)))
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max(a, max(b, max(c, d)))
#define ABS(x) ((x) < 0 ? -(x) : (x))
#define pb push_back
#define mod 1000000007
#define end printf("\\n")
#define yes printf("YES\\n")
#define no printf("NO\\n")

/// data type
typedef long long int ll;
typedef unsigned long long int llu;

int main() {
  faster ll n, sum = 0, x;
  cin >> n;
  ll A[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++) {
      x = (A[i] * A[j]);
      sum += x;
      sum %= mod;
    }
  }
  cout << sum << nl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < ll(b); i++)
#define repr(i, a, b) for (ll i = a; i >= ll(b); i--)
#define endl "\\n"
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define INF 1e9
#define DEBUG(x) cout << "debug: " << x << endl

const int MOD = 1000000007;

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

  ll ans = 0;
  rep(i, 0, n) {
    ll t = b[n] - b[i + 1];
    t %= MOD;
    ans += a[i] * t;
    ans %= MOD;
  }

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


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < ll(b); i++)
#define repr(i, a, b) for (ll i = a; i >= ll(b); i--)
#define endl "\\n"
#define ALL(x) x.begin(), x.end()
#define ALLR(x) x.rbegin(), x.rend()
#define INF 1e9
#define DEBUG(x) cout << "debug: " << x << endl

const int MOD = 1000000007;

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

  ll ans = 0;
  rep(i, 0, n) {
    ll t = b[n] - b[i + 1];
    t %= MOD;
    ans += a[i] * t;
    ans %= MOD;
  }

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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

#define INF 1000000007

int main() {
  long long int N = 0, count = 0;
  cin >> N;
  vector<long long int> box(N);
  for (int i = 0; i < N; i++) {
    cin >> box.at(i);
    count += box.at(i);
    count = count % INF;
  }
  // cout << count << endl;
  long long int answer = 0, now = 0;
  for (int i = 0; i < N - 1; i++) {
    // cout << box.at(i) << endl;
    count = count - box.at(i);
    if (count < 0) {
      count += INF;
    }
    now = box.at(i) * count;
    // cout << a << " " << now << endl;
    answer += now;
    answer = answer % INF;
  }
  cout << answer << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

#define INF 1000000007

int main() {
  long long int N = 0;
  cin >> N;
  vector<long long int> box(N);
  for (int i = 0; i < N; i++) {
    cin >> box.at(i);
  }
  long long int answer = 0, now = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      now = (box.at(i) * box.at(j)) % INF;
      answer += now;
      answer = answer % INF;
    }
  }
  cout << answer % INF << endl;
}