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

#include <bits/stdc++.h>

using namespace std;

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

  long long int num = 10e8 + 7;
  int t;
  while (cin >> t) {
    vector<long long> v;
    while (t--) {
      long long tmp;
      cin >> tmp;
      v.push_back(tmp);
    }
    long long sum = 0;
    vector<long long> pre;
    long long rec = 0;
    for (int i = 1; i < v.size(); i++) {
      rec += v[i];
    }
    for (int i = 1; i < v.size(); i++) {
      pre.push_back(rec);
      rec -= v[i];
    }
    for (int i = 0; i < v.size() - 1; i++) {
      long long tmp = (v[i] % num) * (pre[i] % num);
      tmp %= num;
      sum += tmp;
    }
    sum = sum % num;
    cout << sum << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  long long int num = 10e8 + 7;
  int t;
  while (cin >> t) {
    vector<long long> v;
    while (t--) {
      long long tmp;
      cin >> tmp;
      v.push_back(tmp);
    }
    long long sum = 0;
    for (int i = 0; i < v.size(); i++) {
      for (int j = i + 1; j < v.size(); j++) {
        long long tmp = v[i] * v[j];
        tmp = tmp % num;
        sum += tmp;
      }
    }
    sum %= num;
    cout << sum << endl;
  }

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

#include <bits/stdc++.h>
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.at(i);
    sum += A.at(i);
    sum %= mod;
  }

  long ans = 0;

  for (int i = 0; i < n; i++) {
    sum -= A.at(i);
    if (sum < 0)
      sum += mod;

    ans += A.at(i) * sum;
    ans %= mod;
  }
  cout << ans << endl;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)


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

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

int main() {
  int N;

  cin >> N;

  vector<Bint> A(N);

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

  Bint ret1 = 0, ret2 = 0;

  for (int i = 0; i < N; ++i) {
    ret1 += A[i];
    ret2 += A[i] * A[i];
  }

  cout << ((ret1 * ret1 - ret2) / 2) % 1000000007 << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;

  cin >> N;

  vector<ll> A(N);

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

  ll ret = 0;

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

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

  // i について全探索する
  for (int i = 0; i < N; i++) {
    // A[i+1] ... A[N] の値を更新する
    sum -= A[i];
    if (sum < 0)
      sum += mod;

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

  cout << ans << endl;
}

Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

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

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

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

int main() {
  long long n, c = 0, d = 0, b;
  b = 1000000007;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    if (a.at(i) >= b)
      a.at(i) -= b;
    if (i > 0) {
      c += a.at(i);
      if (c >= b)
        c -= b;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    d += a.at(i) * c;
    d = d % b;
    c -= a.at(i + 1);
    if (c < 0)
      c += b;
  }
  cout << d;
}


Error: TLE

Fixed submission:

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

int main() {
  long long n, c = 0, d = 0, b;
  b = 1000000007;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      d += a.at(i) * a.at(j);
      d = d % b;
    }
  }
  cout << d;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long

using namespace std;

const ll mod = 1e9 + 7;

int main() {
  int N;

  cin >> N;

  vector<ll int> A(N + 3), B(N + 3, 0);

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

  ll ans = 0;

  for (int i = N - 2; i > 0; i--) {
    B[i] = (B[i] + B[i + 1]) % mod;
    ;
  }

  for (int i = 1; i < N; i++) {
    ans = (ans + (B[i] * A[i - 1]) % mod) % mod;
  }

  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

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

#define ll long long

using namespace std;

const ll mod = 1e9 + 7;

int main() {
  int N;

  cin >> N;

  vector<ll int> A(N + 3);

  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll ans = 0;
  for (int i = 0; i < N - 1; i++) {
    ll x = A[i] % mod;
    for (int j = i + 1; j < N; j++) {
      ll y = A[j] % mod;
      ans = (ans + (x * y) % mod) % mod;
    }
  }

  cout << ans << endl;

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

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const int mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdoutn

int main() {
  IO;
  ll n{}, ans{}, res{};
  cin >> n;
  vector<ll> v(n);
  For(i, 0, n) {
    cin >> v[i];
    res += v[i];
    res %= mod;
  }
  For(i, 0, n) {
    res -= v[i];
    if (res < 0)
      res += mod;
    ans += v[i] * res;
    ans %= mod;
  }
  cout << ans << '\\n';
  //	system("pause");
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const ll mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdoutn

int main() {
  IO;
  int n{};
  cin >> n;
  vector<ll> v(n);
  For(i, 0, n) cin >> v[i];
  ll ans{};
  For(i, 0, n) {
    For(j, i + 1, n) { ans += (v[i] * v[j]) % mod; }
  }
  cout << ans % mod << '\\n';
  //	system("pause");
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long mod = 1e9 + 7;

int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  long long ans = 0;
  long long sum = 0;
  long long sum2 = 0;

  for (int i = 0; i < N; i++) {
    sum2 = (sum2 + A[i] * A[i]) % (2 * mod);
    sum = (sum + A[i]) % (2 * mod);
  }

  ans = (sum * sum - sum2) % (2 * mod) / 2;

  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

long long mod = 1e9 + 7;

int main() {
  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 + A[i] * A[j] % mod) % mod;
    }
  }

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

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

#define ll long long
#define MOD 1000000007
const int maxn = 200005;
int N;
ll A[maxn];

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

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

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

Error: TLE

Fixed submission:

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

#define MOD 1000000007
const int maxn = 200005;
int N;
long long A[maxn];

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

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

  long long sum = 0;
  for (int i = 0; i < N - 1; i++) {
    long long tmp = 0;
    for (int j = i + 1; j < N; j++) {
      tmp += A[j];
    }
    tmp %= MOD;
    sum += A[i] * tmp;
    sum %= MOD;
  }
  cout << sum << "\\n";
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define M 1000000007
#define MM 998244353
#define PI 3.14159265
using namespace std;

int main() {
  long long int n, sum = 0, prosum = 0;
  cin >> n;
  long long int a[n];

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

  for (long long int i = 0; i < n; i++) {
    sum = sum - a[i];
    prosum += (sum % M * a[i] % M) % M;
  }

  prosum = prosum % M;

  cout << prosum;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define M 1000000007
#define MM 998244353
#define PI 3.14159265
using namespace std;

int main() {
  long long int n, sum = 0, pro = 0;
  cin >> n;
  long long int a[n];

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

  for (long long int i = 0; i < n - 1; i++) {
    for (long long int j = i + 1; j < n; j++) {
      pro = ((a[i] % M) * (a[j] % M)) % M;
      sum = (sum % M + pro % M) % M;
    }
  }

  cout << sum;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
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;
  for (int i = 0; i < N; i++) {
    sum -= A[i];
    if (sum < 0)
      sum += mod;

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

  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T> inline void read(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF)
    return;
  while (c != '-' && (c < '0' || c > '9'))
    c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9')
    ret = ret * 10 + (c - '0');
  ret *= sgn;
  return;
}
inline void outi(int x) {
  if (x > 9)
    outi(x / 10);
  putchar(x % 10 + '0');
}
inline void outl(ll x) {
  if (x > 9)
    outl(x / 10);
  putchar(x % 10 + '0');
}

int n;
const int N = 2e5 + 7;
const int mod = 1e9 + 7;
ll a[N];
typedef long long ll;
ll sum = 0, res, ans[N];
int main() {
  read(n);
  read(a[1]);
  ans[1] = a[1];
  for (int i = 2; i <= n; i++) {
    read(a[i]);
    ans[i] = (ans[i - 1] % mod + a[i] % mod) % mod;
  }
  for (int i = 1; i <= n - 1; i++) {
    res = ((a[i] % mod) * (ans[n] % mod - ans[i] % mod + mod) % mod) % mod;
    sum += res % mod;
  }
  printf("%lld", sum % mod);
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T> inline void read(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF)
    return;
  while (c != '-' && (c < '0' || c > '9'))
    c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9')
    ret = ret * 10 + (c - '0');
  ret *= sgn;
  return;
}
inline void outi(int x) {
  if (x > 9)
    outi(x / 10);
  putchar(x % 10 + '0');
}
inline void outl(ll x) {
  if (x > 9)
    outl(x / 10);
  putchar(x % 10 + '0');
}

int n;
const int N = 2e5 + 7;
const int mod = 1e9 + 7;
ll a[N];
typedef long long ll;
ll sum = 0, res;
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(a[i]);
  }
  for (int i = 1; i <= n - 1; i++) {
    for (int j = i + 1; j <= n; j++) {
      res = ((a[i] % mod) * (a[j] % mod)) % mod;
      sum = ((sum % mod) + (res % mod)) % mod;
    }
  }
  printf("%lld", sum % mod);
}
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++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  int a[n];
  int sum = 0;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
    sum %= MOD;
  }
  int ans = 0;
  rep(i, n) {
    sum -= a[i];
    while (sum < 0)
      sum += MOD;
    ans += a[i] * (sum);
    ans %= MOD;
    while (ans < 0)
      ans += MOD;
  }
  if (ans < 0)
    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 < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  int a[n];
  int sum = 0;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
    sum %= MOD;
  }
  int ans = 0;
  rep(i, n) {
    sum -= a[i];
    while (sum < 0)
      ans += MOD;
    ans += a[i] * (sum);
    ans %= MOD;
    while (ans < 0)
      ans += MOD;
  }
  if (ans < 0)
    ans += MOD;
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, answer = 0, i;
  cin >> N;
  vector<long> A(N);
  for (i = 0; i < N; i++) {
    cin >> A[i];
  }
  long long B = 0, C;
  for (i = 1; i < N; i++) {
    B += A[i];
  }
  C = B % 1000000007;
  answer += C * A[0];
  answer = answer % 1000000007;

  for (i = 1; i < N - 1; i++) {
    B -= A[i];
    C = B % 1000000007;
    answer += C * A[i];
    answer = answer % 1000000007;
  }

  cout << answer;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, answer = 0, i, j;
  cin >> N;
  vector<long> A(N);
  for (i = 0; i < N; i++) {
    cin >> A[i];
  }
  long long B = 0;
  for (i = 0; i < N - 1; i++) {
    for (j = i + 1; j < N; j++) {
      B += A[j];
    }
    B = B % 1000000007;
    answer += B * A[i];
    answer = answer % 1000000007;
    B = 0;
  }

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

#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (long long &ai : a)
    cin >> ai;
  long long ret = 0;
  int mod = 1e9 + 7;

  // for (int i = 0; i < n - 1; ++i) {
  //   for (int j = i + 1; j < n; ++j) {
  //     long long aiaj = a[i] * a[j];
  //     aiaj %= mod;
  //     ret += aiaj;
  //     ret %= mod;
  //   }
  // }

  vector<long long> postfix(n);
  postfix[n - 2] = a[n - 1];
  for (int i = n - 2; i > 0; --i) {
    postfix[i - 1] = a[i] + postfix[i];
    postfix[i - 1] %= mod;
  }

  // for (auto el : postfix) {
  //   cout << el << endl;
  // }
  // cout << endl;

  ret = 0;
  for (int i = 0; i < n; ++i) {
    //
    ret += a[i] * postfix[i];
    ret %= mod;
  }
  cout << ret << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (long long &ai : a)
    cin >> ai;
  long long ret = 0;
  int mod = 1e9 + 7;

  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      long long aiaj = a[i] * a[j];
      aiaj %= mod;
      ret += aiaj;
      ret %= mod;
    }
  }
  cout << ret << endl;
  return 0;
}

// int main() {
//   int n;
//   cin >> n;
//   vector<long long> a(n);
//   for (long long& ai : a) cin >> ai;
//   long long ret = 1;
//   int mod = 1e9 + 7;

//   for (int ai : a) {
//     ret *= ai;
//     ret %= mod;
//     if (ai == 0) {
//       ret = 0;
//       break;
//     }
//   }
//   cout << ret << endl;
//   return 0;
// }
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define EPS 0.000000001 // 1e-9
#define pii pair<int, int>
using namespace std;
int32_t main() {
  IOS;
  int n, s = 0, p = 1000000000 + 7;
  cin >> n;
  int a[n + 1], b[n + 1];
  cin >> a[1];
  b[1] = a[1];
  for (int i = 2; i <= n; i++) {
    cin >> b[i];
    a[i] = a[i - 1] + b[i];
  }
  for (int i = 1; i <= n - 1; i++) {
    s += ((((a[n] - a[i]) % p) * b[i]) % p);
    s = s % p;
  }
  cout << s << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define EPS 0.000000001 // 1e-9
#define pii pair<int, int>
using namespace std;
int32_t main() {
  IOS;
  int n, s = 0, p = 1000000000 + 7;
  cin >> n;
  int 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++) {
      // int k=((a[i]%p)*(a[j]%p))%p;
      // int k=a[i]*a[j];

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

#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)

int main() {
  fastio;
  long long n, i, j, sum = 0, mul = 0;
  long long M = 1000000007;
  static long long ara[200003];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> ara[i];
  }
  for (i = n - 2; i >= 0; i--) {
    sum = ((sum % M) + (ara[i + 1] % M)) % M;
    mul = ((mul % M) + ((ara[i] % M) * (sum % M)) % M) % M;
  }
  cout << mul << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <string>
using namespace std;
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)

int main() {
  fastio;
  long long n, i, j, sum = 0;
  long long M = 1000000007;
  static long long ara[200003];
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> ara[i];
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++)
      sum = ((sum % M) + ((ara[i] % M) * (ara[j] % M)) % M) % M;
  }
  cout << sum << "\\n";
  return 0;
}