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

#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: TLE

Fixed submission:

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

int main() {

  int N;
  int64_t n = 0;
  int i, j;

  cin >> N;

  int64_t a[N];

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

  for (i = 0; i < N; i++) {
    for (j = i + 1; j < N; j++) {
      n = n + a[i] * a[j] % (1000000000 + 7);
    }
  }
  cout << n % (1000000000 + 7) << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  vector<int64_t> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  int64_t sum = 0, p = 0;
  for (int i = 0; i < n - 1; i++) {
    p = (p + vec.at(n - 1 - i)) % 1000000007;
    sum += (vec.at(n - 2 - i) * p) % 1000000007;
  }

  cout << sum % 1000000007 << endl;
}

Error: TLE

Fixed submission:

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

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

// copied from https://atcoder.jp/contests/abc177/submissions/16358885

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

int main(void) {
  int N;
  cin >> N;
  int A[N];
  ll B[N + 1];
  int mod = 1000000007;

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

  long ans = 0;

  // i について全探索する
  for (int i = 0; i < N; i++) {
    // 累積和を使ってA[i+1] + ... + A[N] を求める
    long long sum = (B[N] - B[i + 1]) % mod;

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

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


Error: TLE

Fixed submission:

#include <iostream>
#pragma GCC optimize("Ofast")
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ll long long
inline int roundup(int a, int b) { return (((a + (b - 1)) / b)); }
using namespace std;

signed main(void) {
  long n, A[200000];
  long sum;
  cin >> n;
  for (int i = 0; i < n; ++i)
    scanf("%ld", &A[i]);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      sum += ((A[j] % 1000000007) * (A[i] % 1000000007));
      sum = sum % 1000000007;
    }
  }

  cout << sum << "\\n";
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pl pair<ll, ll>
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define vl vector<ll>
#define N 100005
#define mod 1000000007

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

Error: TLE

Fixed submission:

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pl pair<ll, ll>
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define vl vector<ll>
#define N 100005
#define mod 1000000007

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

/**
 *    author:  yoseph
 *    created: 09.09.2020 19:42:20
 **/
#include <bits/stdc++.h>
using namespace std;

const long M = 1000000007;

#if 0
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	
	long long ans = 0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			ans = (ans % M + (v[i] % M * v[j] % M) % M) % M;
		}
	}
	cout << ans << "\\n";

	return 0;
}
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long sum = 0;
  vector<int> A(n);
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    sum += A[i];
    sum %= M;
  }

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    sum -= A[i];
    if (sum < 0)
      sum += M;
    ans += A[i] * sum;
    ans %= M;
  }
  cout << ans << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

/**
 *    author:  yoseph
 *    created: 09.09.2020 19:42:20
 **/
#include <bits/stdc++.h>
using namespace std;

const long M = 1000000007;

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

  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = (ans % M + (v[i] % M * v[j] % M) % M) % M;
    }
  }
  cout << ans << "\\n";

  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 < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define _GLIBCXX_DEBUG

template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

typedef long long ll;
const ll MOD = 1000000007;
const int max_n = 200010;
ll a[max_n], s[max_n];
int n;

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

  ll ans = 0;
  rep(i, n) { s[i + 1] = s[i] + a[i]; }

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

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

Error: TLE

Fixed submission:

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

template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

typedef long long ll;
const ll MOD = 1000000007;
const int max_n = 200010;
ll a[max_n];
int n;

int main() {
  cin >> 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 %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
const ll mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;

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

  ll ans = 0;

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

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
ll mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  ll ans = 0;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define vv vector<ll>
#define MAX 105000
#define rr pow(10, 9) + 7
#define fr(i, x) for (int i = 0; i < x; i++)
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {

  if (a.first == b.first)
    return a.second < b.second;
  return (a.first < b.first);
}
ll ar[MAX];
void divisor() {
  for (int i = 1; i <= MAX; i++) {
    for (int j = i; j <= MAX; j += i) {
      ar[j]++;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll f = pow(10, 9) + 7;
  ll n, x, c = 0, y, m;
  cin >> n;
  vector<ll> a, b;
  for (ll i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x % f);
  }
  b.push_back(a[n - 1]);
  for (ll i = 1; i < n; i++) {
    b.push_back(b[i - 1] + a[n - i - 1]);
  }
  // cout << endl;
  for (ll i = 0; i < n - 1; i++) {
    c += (a[i] % f) * (b[n - i - 2] % f);
    c = c % f;
  }
  cout << c << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define vv vector<ll>
#define MAX 105000
#define rr pow(10, 9) + 7
#define fr(i, x) for (int i = 0; i < x; i++)
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {

  if (a.first == b.first)
    return a.second < b.second;
  return (a.first < b.first);
}
ll ar[MAX];
void divisor() {
  for (int i = 1; i <= MAX; i++) {
    for (int j = i; j <= MAX; j += i) {
      ar[j]++;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll d, ns, nt, r = INT_MAX;

  ll n, x, c = 0;
  cin >> n;
  vector<ll> a;
  ll f = pow(10, 9) + 7;
  cin >> x;
  a.push_back(x);
  for (ll i = 1; i < n; i++) {
    cin >> x;
    a.push_back(x % f);
    for (int j = 0; j < i; j++) {
      c += ((a[i] % f) * (a[j] % f));
      c = c % f;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int
modPow(long long int a,
       long long int n) { // 繰り返し自乗法(a^n mod p)。計算量 O(logN)
  long long int p = pow(10, 9) + 7; // 任意のp(素数) modのやつで使える
  if (n == 0) {
    return 1;
  }
  if (n == 1) {
    return a % p;
  }
  if (n % 2 == 1) {
    return (a * modPow(a, n - 1)) % p;
  }
  long long t = modPow(a, n / 2);
  return (t * t) % p;
}

int main() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  vector<long long int> b(n - 1);
  long long int res = 0;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    sum = (sum + a.at(i)) % mod;
  }
  for (int i = 0; i < n - 1; i++) {
    b.at(i) = (sum - a.at(i)) % mod;
    sum -= a.at(i);
    // cout << b.at(i) << endl;
    if (b.at(i) < 0) {
      b.at(i) += mod;
    }
  }

  long long int tmp = 0;
  for (int i = 0; i < n - 1; i++) {
    tmp = (a.at(i) * b.at(i)) % mod;
    res = (res + tmp) % mod;
    /*
    for(int j = i + 1; j < n; j++){
        tmp = a.at(i) * a.at(j) % mod;
        res = (res + tmp) % mod;
    }
    */
  }
  cout << res << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int
modPow(long long int a,
       long long int n) { // 繰り返し自乗法(a^n mod p)。計算量 O(logN)
  long long int p = pow(10, 9) + 7; // 任意のp(素数) modのやつで使える
  if (n == 0) {
    return 1;
  }
  if (n == 1) {
    return a % p;
  }
  if (n % 2 == 1) {
    return (a * modPow(a, n - 1)) % p;
  }
  long long t = modPow(a, n / 2);
  return (t * t) % p;
}

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;

typedef tree<long long, null_type, less<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;

// defines
typedef long long ll;
typedef long double ld;
const long long MOD = (long long)(1e9 + 7); //(int)(1e9 + 7); //998244353;

ll a, b, c, n, m, k;

ll t = 1;

void solve() {
  cin >> n;
  vector<ll> v(n);
  ll sum = 0LL;
  for (ll i = 0; i < n; i++)
    cin >> v[i], sum += v[i];
  ll ans = 0LL;
  for (ll i = 0; i < n - 1; i++) {
    sum -= v[i];
    ans += ((v[i] * (sum % MOD)) % MOD);
    ans %= MOD;
  }
  cout << ans;
  if (t > 0)
    cout << "\\n";
}

int32_t main() {
#ifdef ONPC
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  // cin>>t;
  while (t--) {
    solve();
  }
  // cout<<sum;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;

typedef tree<long long, null_type, less<long long>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;

// defines
typedef long long ll;
typedef long double ld;
const long long MOD = (long long)(1e9 + 7); //(int)(1e9 + 7); //998244353;

ll a, b, c, n, m, k;

ll t = 1;

void solve() {
  cin >> n;
  vector<ll> v(n);
  for (ll i = 0; i < n; i++)
    cin >> v[i];

  ll ans = 0LL;
  for (ll i = 0; i < n - 1; i++) {
    for (ll j = i + 1; j < n; j++)
      ans += ((v[i] * v[j]) % MOD), ans %= MOD;
  }
  cout << ans;
  if (t > 0)
    cout << "\\n";
}

int32_t main() {
#ifdef ONPC
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  // cin>>t;
  while (t--) {
    solve();
  }
  // cout<<sum;

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rrep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void) {

  // vector<vector<char>> maze(h, vector<char>(w));
  // vector<vector<ll>> warp(h, vector<ll>(w, INF));

  ll n;
  cin >> n;
  vector<ll> a(n);
  ll res = 0;
  ll su = 0;

  rep(i, n) {
    ll e;
    cin >> e;
    a.at(i) = e;
    su += e;
  }

  rep(i, n - 1) {
    ll k = a.at(i);
    su -= k;
    res += (su % MOD * k % MOD) % MOD;
  }

  cout << res % MOD << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rrep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void) {

  // vector<vector<char>> maze(h, vector<char>(w));
  // vector<vector<ll>> warp(h, vector<ll>(w, INF));

  int n;
  cin >> n;
  vector<int> a(n);
  int res = 0;

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

  rep(i, n - 1) {
    int k = a.at(i);
    int j;
    rrep(j, i + 1, n) {
      res += (k % MOD * a.at(j) % MOD) % MOD;
      res %= MOD;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define mo 1000000007
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  long long a[n];
  long long pro = 0, sum = 0, sum1 = 0;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    sum1 += a[i];
  }
  for (int i = 0; i < n; ++i) {
    pro += a[i];
    sum += ((a[i] % mo) * ((sum1 - pro) % mo)) % mo;
    sum %= mo;
  }
  cout << sum;
  return 0;
}

Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
#define take                                                                   \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout);                                          \\
  freopen("error.txt", "w", stderr);
#define speed ios_base::sync_with_stdio(false);
#define int long long
#define endl "\\n"
#define maxi 10000007
int maxo = 1e9 + 7;
int sum = 0;
#define rof(i, a, b) for (int i = a; i < b; i++)
void solve(int a[], int i, int s, int p, int n) {
  if (s == 2) {
    sum = sum % maxo + p % maxo;
    return;
  }
  for (int j = i; j < n; j++) {
    solve(a, j + 1, s + 1, ((p % maxo) * a[j] % maxo) % maxo, n);
  }
}
int32_t main() {
  speed
      // take
      int n;
  cin >> n;
  int a[n];
  int sum1 = 0;
  int sum2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum1 += a[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    sum2 += a[i];
    ans = ((a[i] % maxo) * ((sum1 - sum2) % maxo)) % maxo + ans % maxo;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define take                                                                   \\
  freopen("input.txt", "r", stdin);                                            \\
  freopen("output.txt", "w", stdout);                                          \\
  freopen("error.txt", "w", stderr);
#define speed ios_base::sync_with_stdio(false);
#define int long long
#define endl "\\n"
#define maxi 10000007
int maxo = 1e9 + 7;
int sum = 0;
#define rof(i, a, b) for (int i = a; i < b; i++)
void solve(int a[], int i, int s, int p, int n) {
  if (s == 2) {
    sum = sum % maxo + p % maxo;
    return;
  }
  for (int j = i; j < n; j++) {
    solve(a, j + 1, s + 1, ((p % maxo) * a[j] % maxo) % maxo, n);
  }
}
int32_t main() {
  speed
      // take
      int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  solve(a, 0, 0, 1, n);
  cout << sum;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define mod 1000000007
int main() {

  int n;
  cin >> n;
  long long a[n];
  long long pre[n + 2];
  long long pre2[n + 2], pre3[n + 2];

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

  for (int i = 0; i <= n; i++)
    pre[i] = 0, pre2[i] = 0, pre3[i] = 0;

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

  for (int i = 1; i <= n; i++) {
    pre2[i] = pre[n] - pre[i];

    pre2[i] = pre2[i] % mod;
    a[i - 1] = a[i - 1] % mod;

    pre2[i] = pre2[i] * a[i - 1];

    pre2[i] = pre2[i] % mod;
  }

  for (int i = 1; i <= n; i++) {
    sum = sum + pre2[i];
    sum = sum % mod;
  }

  cout << sum << endl;
}

Error: TLE

Fixed submission:

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

#define mod 1000000007
int main() {

  int n;
  cin >> n;
  long long a[n];

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

  for (int i = 0; i + 1 < n; i++) {
    for (int j = i + 1; j < n; j++) {
      sum = sum + ((1LL * (a[i] % mod) * (a[j] % mod))) % mod;
      sum = sum % mod;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
typedef long long ll;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef set<int> SI;
typedef map<string, int> MSI;
typedef map<int, int> MII;
typedef pair<ll, ll> PLL;
typedef pair<ll, pair<ll, ll>> PLLL;

#define flash                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define MP make_pair
#define PB push_back
#define FF first
#define SS second
#define mod 1000000007
#define test                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)

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

  return;
}

int main() {
  flash;

  // test
  // {
  // 	solve();
  // }
  solve();

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
typedef long long ll;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef set<int> SI;
typedef map<string, int> MSI;
typedef map<int, int> MII;
typedef pair<ll, ll> PLL;
typedef pair<ll, pair<ll, ll>> PLLL;

#define flash                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
#define MP make_pair
#define PB push_back
#define FF first
#define SS second
#define mod 1000000007
#define test                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)

void solve() {
  ll n;
  cin >> n;
  ll arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  ll s = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ll x = (arr[i] * arr[j]) % mod;
      s += (x + mod) % mod;
    }
  }
  cout << (s + mod) % mod;

  return;
}

int main() {
  flash;

  // test
  // {
  // 	solve();
  // }
  solve();

  return 0;
}