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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9 + 7)
#define INF (1LL << 60)
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep1(i, n) for (ll i = 1; i <= (n); i++)

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

// 最大公約数
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n) {
  ll s = sqrt(n);
  ll r = 0;
  for (ll i = 2; i <= s; i++) {
    if ((n % i) == 0) {
      r = 0;
      do {
        r++;
        n = n / i;
      } while ((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if (n > s) {
    prim.push_back({n, 1});
  }
}

void solve() {
  ll N;
  cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];
  reverse(a.begin(), a.end());
  ll ans = 0;
  vector<ll> w(N + 1, 0);
  rep(i, N) { w[i + 1] = (w[i] + a[i]) % MOD; }
  rep(i, N) {
    ans += (a[i] * w[i]) % MOD;
    ans %= MOD;
  }

  cout << ans << endl;
}

int main(void) {
  // ll t; cin >> t; rep(i, t)
  solve();
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9 + 7)
#define INF (1LL << 60)
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep1(i, n) for (ll i = 1; i <= (n); i++)

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

// 最大公約数
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n) {
  ll s = sqrt(n);
  ll r = 0;
  for (ll i = 2; i <= s; i++) {
    if ((n % i) == 0) {
      r = 0;
      do {
        r++;
        n = n / i;
      } while ((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if (n > s) {
    prim.push_back({n, 1});
  }
}

void solve() {
  ll N;
  cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];

  ll ans = 0;

  rep(i, N) {
    for (ll j = i + 1; j < N; j++) {
      ans += (a[i] * a[j]) % MOD;
      ans %= MOD;
    }
  }

  cout << ans << endl;
}

int main(void) {
  // ll t; cin >> t; rep(i, t)
  solve();
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define LL long long
LL module = 1000000007;
int main() {
  int N;
  scanf("%d", &N);

  LL sum = 0, ans = 0;
  LL val;
  while (N--) {
    scanf("%lld", &val);
    LL tmp = val * sum;
    tmp %= module;
    ans += tmp;
    ans %= module;
    sum += val;
    sum %= module;
  }

  printf("%lld\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define LL long long
LL A[10010];
LL module = 1000000007;
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%lld", A + i);
    A[i] %= module;
  }

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

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

const int mod = 1000000007;

class mint {
  long long x;

public:
  mint(long long 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;
  }

  friend ostream &operator<<(ostream &os, const mint &m) {
    os << m.x;
    return os;
  }
};

// ll mod = 1e9+7;

ll solve1(vector<ll> A, ll N) {
  ll sum = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      sum += (A[i] * A[j]) % mod;
      sum %= mod;
    }
  }
  return sum;
}

int main() {
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  mint zyowa = 0, sum = 0;
  for (int i = 0; i < N; i++) {
    zyowa += (A[i] * A[i]) % mod;
    sum += A[i];
    // zyowa %= mod;
    // sum %= mod;
    //  cerr << "zyowa: " << zyowa << endl;
    //  cerr << "sum: " << sum << endl;
  }

  mint ans = (sum * sum);
  ans = (ans - zyowa);
  ans /= 2;
  cout << ans << endl;

  // cout << solve1(A,N) << endl;
}


Error: TLE

Fixed submission:

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

ll mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

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

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

int main() {
  int64_t n, total = 0, a, t = pow(10, 9) + 7, ans = 0;
  cin >> n;
  vector<int64_t> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    total += vec.at(i);
  }

  for (int i = 0; i < n - 1; i++) {
    total -= vec.at(i);
    a = total % t;
    ans += vec.at(i) * a;
    ans = ans % t;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int64_t n, t = pow(10, 9) + 7, ans = 0;
  cin >> n;
  vector<int64_t> vec(n);
  for (int i = 0; i < n; i++)
    cin >> vec.at(i);

  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += vec.at(i) * vec.at(j);
      ans = ans % t;
    }
  }

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define BIG_PRIME 1000000007

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define BIG_PRIME 1000000007

#define rep(i, n) for (int i = 0; i < (n); ++i)
ll g_ll;
#define repll(n) for (g_ll = 0L; g_ll < (ll)(n); ++g_ll)
#define repll2(start, end) for (g_ll = (ll)(start); g_ll < (ll)(n); ++g_ll)

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

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

#include <bits/stdc++.h>

using namespace std;

long int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<long int> a(n);

  long int all = 0;

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

    all += a[i];
    all %= MOD;
  }

  long int ans = 0;

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

    if (all < 0)
      all += MOD;

    ans += (all * a[i]) % MOD;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long int> a(n);

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

  long int ans = 0;

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

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef pair<int, int> pi;
#define SQ(a) (a) * (a)
#define mod 1000000007
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define deb(x) cout << #x << " = " << x << '\\n'
#define deb2(x, y)                                                             \\
  cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\\n"

void solve() {
  int n;
  cin >> n;
  ll int a[n];
  ll int sum = 0;

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

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

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  solve();
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef pair<int, int> pi;
#define SQ(a) (a) * (a)
#define mod 1000000007
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define deb(x) cout << #x << " = " << x << '\\n'
#define deb2(x, y)                                                             \\
  cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\\n"

set<int> adj[10000005];
vector<bool> visited(1000005);

int mx;
void dfs(int node, int d) {
  d++;
  mx = max(mx, d);
  visited[node] = true;
  for (int u : adj[node]) {
    if (!visited[u]) {
      dfs(u, d);
    }
  }
}

void solve() {
  int n, m;
  cin >> n >> m;
  mx = 0;
  for (int i = 1; i <= n; i++) {
    visited[i] = 0;
  }
  while (m--) {
    int u, v;
    cin >> u >> v;
    adj[u].insert(v);
    adj[v].insert(u);
  }
  for (int i = 1; i <= n; i++) {
    if (!visited[i]) {
      dfs(i, 0);
    }
  }
  cout << mx;
}

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

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

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

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define ll long long

ll M = 1000000007;

void solve() {
  ll n;
  cin >> n;
  ll arr[n], sum = 0;
  for (ll i = 0; i < n; i++) {
    cin >> arr[i];
    sum = (sum + arr[i]) % M;
  }

  ll ans = 0, cur = 0;
  for (ll i = 0; i < n; i++) {
    sum = (sum - arr[i] + M) % M;
    ans = (ans + (sum * arr[i]) % M) % M;
  }

  cout << ans;
}

int main() {
  IOS ll t = 1;
  // cin>>t;
  for (ll i = 0; i < t; i++)
    solve();
  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long
#define endl "\\n"
#define FAST                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

ll gcdEx(ll a, ll b, ll *x, ll *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  ll x1, y1;
  ll gcd = gcdEx(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
ll moIn(ll b, ll m) {
  ll x, y;
  ll g = gcdEx(b, m, &x, &y);
  return (x % m + m) % m;
}
ll moDi(ll a, ll b, ll m) {
  a = a % m;
  ll inv = moIn(b, m);
  return (inv * a) % m;
}

void solve() {
  ll n, M = 1000000007;

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

  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    for (ll j = i + 1; j < n; j++) {
      sum = (sum % M + (a[i] % M * a[j] % M) % M) % M;
    }
  }
  cout << sum;
}

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

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n - 1; i >= 0; i--)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;

int N;
ll A[200020];
ll B[200020];
ll MOD = 1000000007;

int main() {
  cin >> N;
  rep(i, N) cin >> A[i];

  ll ans = 0;
  B[N - 1] = A[N - 1];
  rep_rev(i, N) { B[i - 1] = (B[i] + A[i - 1]) % MOD; }

  rep(i, N - 1) { ans += (A[i] * B[i + 1]) % MOD; }

  cout << ans % MOD << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;

int N;
ll A[200020];
ll MOD = 1000000007;

int main() {
  cin >> N;
  rep(i, N) cin >> A[i];

  ll ans = 0;

  rep(i, N - 1) {
    repi(j, i + 1, N) {
      ans += (A[i] * A[j]) % MOD;
      ans = ans % MOD;
    }
  }

  cout << ans % MOD << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define N 200005
#define mod 1000000007
using namespace std;
template <typename T> inline void in(T &x) {
  x = 0;
  char c = getchar();
  bool fu = 0;
  while (c < '0' || c > '9') {
    if (c == '-')
      fu = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
int n, a[N], sum[N], ans;
int main() {
  in(n);
  for (int i = 0; i < n; ++i)
    in(a[i]);
  sum[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; --i)
    sum[i] = (a[i] + sum[i + 1]) % mod;
  for (int i = 0; i < n - 1; ++i)
    ans = (ans + (1LL * a[i] * sum[i + 1] % mod)) % mod;
  printf("%d\\n", ans);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define N 100005
#define mod 1000000007
using namespace std;
template <typename T> inline void in(T &x) {
  x = 0;
  char c = getchar();
  bool fu = 0;
  while (c < '0' || c > '9') {
    if (c == '-')
      fu = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
int n, a[N], sum[N], ans;
int main() {
  in(n);
  for (int i = 0; i < n; ++i)
    in(a[i]);
  sum[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; --i)
    sum[i] = (a[i] + sum[i + 1]) % mod;
  for (int i = 0; i < n - 1; ++i)
    ans = (ans + (1LL * a[i] * sum[i + 1] % mod)) % mod;
  printf("%d\\n", ans);
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>

const int lens = 2e5 + 1;
const long long mod = 1e9 + 7;

long long a[lens], sum[lens];
int main() {
  int n;
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  for (int i = 1; i <= n; i++) {
    std::cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }

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


Error: TLE

Fixed submission:

#include <iostream>

const int lens = 2e5 + 1;
const long long mod = 1e9 + 7;

long long a[lens];
int main() {
  int n;
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  for (int i = 1; i <= n; i++) {
    std::cin >> a[i];
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve() {
  ll a;
  cin >> a;
  ll arr[a], sum[a], su = 0;
  for (ll i = 0; i < a; i++) {
    cin >> arr[i];
    sum[i] = su % 1000000007;
    su = (su % 1000000007) + (arr[i] % 1000000007);
  }
  ll ans = 0;
  for (int i = a - 1; i > -1; i--) {
    ans += ((arr[i] % 1000000007) * (sum[i] % 1000000007)) % 1000000007;
  }
  ans = ans % 1000000007;
  cout << ans;
}
int main() {
  ll bb = 1;
  // cin>>a;
  while (bb--) {
    solve();
  }
}

Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define debug2(x, y) cout << x << " " << y << "\\n"

ll const mod = 1e9 + 7;

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

  ll ans = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    ans = (ans + (arr[i] * sum) % mod) % mod;
    sum = (sum + arr[i]) % mod;
  }
  cout << ans << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ll long long
ll const mod = 1e9 + 7;

void generateC(vector<ll> arr, int start, vector<ll> &comb,
               vector<vector<ll>> &holdCombinations) {
  if (comb.size() == 2) {
    holdCombinations.push_back(comb);
    return;
  }
  for (int i = start; i < arr.size(); i++) {
    comb.push_back(arr[i]);
    generateC(arr, i + 1, comb, holdCombinations);
    comb.pop_back();
  }
}
int main() {
  ll n;
  cin >> n;
  vector<ll> arr(n, 0);
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  vector<vector<ll>> holdCombinations;
  vector<ll> comb;
  generateC(arr, 0, comb, holdCombinations);
  ll sop = 0, prod = 1;
  for (int i = 0; i < holdCombinations.size(); i++) {
    prod = 1;
    prod =
        (prod * (holdCombinations[i][0] * holdCombinations[i][1]) % mod) % mod;
    sop = sop + prod;
    sop = sop % mod;
  }
  cout << sop << "\\n";
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
using namespace std;
const int N = 200010;
const long long Mod = 1000000007;
long long a[N];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    scanf("%lld", &a[i]);
  long long ans = 0;
  long long sum = 0;

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

  for (int lab = n - 1; lab > 0; lab--) {
    ans = (ans + ((sum % Mod) * a[lab]) % Mod) % Mod;
    // cout<<ans<<" "<<a[lab]<<endl;
    sum -= a[lab - 1];
    // cout<<sum<<endl;
  }

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

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
const int N = 200010;
const int Mod = 1000000007;
long long a[N];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      long long temp = (a[i] * a[j]) % Mod;
      ans = (ans + temp) % Mod;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> a(n);
  rep(i, n) cin >> a[i];
  unsigned long long ans = 0;
  unsigned long long sumofA = 0;
  rep(i, n - 1) {
    sumofA += a[i];
    ans += (sumofA % (1000000007)) * a[i + 1];
    ans = ans % (1000000007);
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> a(n);
  rep(i, n) cin >> a[i];
  unsigned long long 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>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  long long sum = 0, cnt = 0;
  for (int i = 1; i < n; ++i)
    sum += a[i];
  cnt += a[0] % 1000000007 * (sum % 1000000007);
  for (int i = 1; i < n; ++i) {
    sum -= a[i];
    cnt += a[i] % 1000000007 * (sum % 1000000007);
    cnt %= 1000000007;
  }
  cnt %= 1000000007;
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  const int mod = 1e9 + 7;

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

  vector<ll> toSum(N);
  toSum[N - 1] = as[N - 1];
  for (int i = N - 2; i >= 0; --i) {
    toSum[i] = (as[i] % mod + toSum[i + 1] % mod) % mod;
  }

  ll sumOfMultiples = 0;
  for (int i = 0; i < N - 1; ++i) {
    sumOfMultiples += (as[i] % mod * toSum[i + 1] % mod) % mod;
    sumOfMultiples %= mod;
  }

  cout << sumOfMultiples << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<ll> as(N + 1);
  for (int i = 0; i < N; ++i) {
    cin >> as[i];
  }

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

  cout << sumOfMultiples << endl;

  return 0;
}