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

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <math.h>    // sqrt
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

ll mod = 1000000007;

int main() {
  int N;
  cin >> N;
  vll data(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> data[i];
  }
  vll sum(N, 0);
  ll ans = 0, suma = 0;
  for (int i = 0; i < N; i++) {
    suma += data[i];
    suma %= mod;
    sum[i] = suma;
  }
  for (int i = 0; i < N - 1; i++) {
    ll b = sum[N - 1] - sum[i];
    if (b < 0) {
      b += mod;
    }
    ll a = data[i] * b % mod;
    ans += a;
    ans %= mod;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <math.h>    // sqrt
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

ll mod = 1000000007;

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

#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define MN 200000
#define ll long long

int main() {
  int n;
  cin >> n;
  ll c;
  ll r = 0;
  ll m = 0;
  for (int i = 0; i < n; i++) {
    cin >> c;
    m = ((c * c) % MOD + m) % MOD;
    r = (c % MOD + r) % MOD;
  }
  r = (r * r) % MOD;
  r = (r - m + MOD) % MOD;
  r *= (MOD + 1) / 2;
  r %= MOD;
  cout << r;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define MN 200000
#define ll long long
ll ar[MN];

int main() {
  int n;
  cin >> n;
  ll c;
  for (int i = 0; i < n; i++) {
    cin >> c;
    ar[i] = c;
  }
  long long r = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      r = (r % MOD + ((long long)ar[i] * ar[j]) % MOD) % MOD;
    }
  }
  cout << r;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

#include <cmath>

#include <cstdlib>

#include <utility>

#include <cstdio>

#define vii vector<pair<int, int>>

#define vi vector<int>

#define INF 1000000007

#define ff first

#define ss second

#define lli long long int

#define ulli unsigned long long int

using namespace std;

int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);

  int n;

  cin >> n;

  vi v(n);

  for (int i = 0; i < n; i++)

    cin >> v[i];

  ulli sum = 0, ans = 0;

  for (int i = 0; i < n; i++)

    ans += v[i] % INF;

  for (int i = 0; i < n; i++) {

    ans -= v[i] % INF;

    sum += ((v[i] % INF) * (ans % INF)) % INF;
  }

  cout << sum % INF << endl;

  // cout<<12839201%INF;
}

Error: TLE

Fixed submission:

#include <iostream>

#include <vector>

#include <string>

#include <algorithm>

#include <cmath>

#include <cstdlib>

#include <utility>

#include <cstdio>

#define vii vector<pair<int, int>>

#define vi vector<int>

#define INF 1000000007

#define ff first

#define ss second

#define lli long long int

#define ulli unsigned long long int

using namespace std;

int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(NULL);

  int n;

  cin >> n;

  vi v(n);

  for (int i = 0; i < n; i++)

    cin >> v[i];

  ulli sum = 0, ans = 0;

  for (int i = 0; i < n; i++) {

    ans = 0;

    for (int j = i + 1; j < n; j++) {

      ans += (v[j] % INF);
    }

    ans = ans % INF;

    sum += ((v[i] % INF) * (ans)) % INF;
  }

  cout << sum % INF << endl;

  // cout<<12839201%INF;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

int main() {
  long long k = 1000000007;
  long long N;
  long long A[200001] = {0};
  long long sum = 0;
  long long s_tmp;
  long long tmp_sum = 0;

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

  for (int i = 1; i < N; i++) {
    tmp_sum += A[i];
  }
  // cout << "sum = " << sum << "\\n";

  for (int i = 0; i < N - 1; i++) {
    s_tmp = (A[i] * (tmp_sum % k));
    s_tmp = s_tmp % k;
    sum += s_tmp;
    sum = sum % k;
    tmp_sum -= A[i + 1];
    // cout << "sum = " << sum << "\\n";
    // cout << "tmp = " << tmp_sum << "\\n";
  }
  cout << sum % k << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  long long k = 1000000000 + 7;
  long long N;
  long long A[200000] = {0};
  long long sum = 0;
  long long tmp;

  cin >> 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++) {
      // cout << "A[" << i << "] * A[" << j << "] = ";
      tmp = A[i] * A[j];
      // cout << tmp << "\\n";
      sum += tmp % k;
    }
  }
  cout << sum % k << "\\n";
  return 0;
}
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 long ans = 0;

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

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

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e9 + 7;

int main()

{
  int n;
  cin >> n;
  long long arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int sum = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {

      int k = ((arr[i]) * (arr[j])) % N;
      sum = (sum % N + k) % N;
    }
  }
  cout << sum;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

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

const ll MOD = 1e9 + 7;

ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0)
    res += m;
  return res;
}

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


Error: WA

Fixed submission:

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

int main() {
  string s, t;
  cin >> s >> t;
  ll ans = s.size();
  rep(i, s.size() - t.size() + 1) {
    string tmp = s.substr(i, t.size());
    ll cnt = 0;
    rep(j, t.size()) if (tmp[j] != t[j]) cnt++;
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
const ll mod = 1000000000 + 7; // 10^9

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N + 1);
  B[0] = 0;
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
    B[i + 1] = (A[i] + B[i]) % mod;
  }
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    ans += A[i] * ((B[N] - B[i + 1] + mod) % mod) % mod;
    ans %= mod;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;

const ll mod = 1000000000 + 7; // 10^9

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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

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

#define pb push_back
#define all(a) begin(a), end(a)
#define deb(x) cout << #x << " = " << x << endl
#define debu(x, y)                                                             \\
  cout << "( " << #x << ", " << #y << " ) = ( " << x << ", " << y << " )"      \\
       << endl
#define int long long

typedef long long ll;
ll mod = 1000000007;

template <typename T> vector<T> readVector(int n) {
  vector<T> res(n);
  for (int i = 0; i < n; i++)
    cin >> res[i];
  return res;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tt = 1;
  // cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<int> mark(n);
    mark[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--) {
      mark[i] = (mark[i + 1] + a[i]) % mod;
    }
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
      ans = (ans + (a[i] * mark[i + 1]) % mod) % mod;
    }
    cout << ans % mod;
  }
  return 0;
}


Error: TLE

Fixed submission:

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

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

#define pb push_back
#define all(a) begin(a), end(a)
#define deb(x) cout << #x << " = " << x << endl
#define debu(x, y)                                                             \\
  cout << "( " << #x << ", " << #y << " ) = ( " << x << ", " << y << " )"      \\
       << endl
#define int long long

typedef long long ll;
ll mod = 1000000007;

template <typename T> vector<T> readVector(int n) {
  vector<T> res(n);
  for (int i = 0; i < n; i++)
    cin >> res[i];
  return res;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tt = 1;
  // cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int 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 % mod;
  }
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\\n"
#define pb push_back
#define sq(a) (a) * (a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << '=' << (x) << endl;
#define debugv(v)                                                              \\
  cerr << #v << " : ";                                                         \\
  for (auto x : v)                                                             \\
    cerr << x << ' ';                                                          \\
  cerr << endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll exp(ll x, ll n, ll mod) {
  ll result = 1;
  while (n) {
    if (n & 1)
      result = (result * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return result;
}

const ll M = 1e9 + 7;

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

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

  ll ans = 0, sum = a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    ans = (ans + (a[i] * sum) % M) % M;
    sum = (sum + a[i]) % M;
  }

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

Error: TLE

Fixed submission:

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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\\n"
#define pb push_back
#define sq(a) (a) * (a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << '=' << (x) << endl;
#define debugv(v)                                                              \\
  cerr << #v << " : ";                                                         \\
  for (auto x : v)                                                             \\
    cerr << x << ' ';                                                          \\
  cerr << endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll exp(ll x, ll n, ll mod) {
  ll result = 1;
  while (n) {
    if (n & 1)
      result = (result * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return result;
}

const ll M = 1e9 + 7;

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

      int n;
  cin >> n;

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

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

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define UNIQUE(v)                                                              \\
  v.erase(unique(v.begin(), v.end()), v.end()) // sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main() {
  int n;
  cin >> n;
  const ll MOD = 1'000'000'007;
  vector<ll> A(n);
  ll sum = 0;
  rep(i, n) {
    cin >> A[i];
    sum += A[i];
  }
  ll ans = 0;
  rep(i, n) {
    sum -= A[i];
    ll tmp = sum % MOD;
    tmp = (tmp * A[i]) % MOD;
    ans = (ans + tmp) % 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 < n; i++)

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
long long a[1000000];
long long mod = 1000000007;
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum = sum + a[i];
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    sum = sum - a[i];
    ans = ans % mod + (sum % mod) * (a[i] % mod) % mod;
    ans = ans % mod;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
long long a[100000];
long long mod = 1000000007;
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum = sum + a[i];
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    sum = sum - a[i];
    ans = ans % mod + (sum % mod) * (a[i] % mod) % mod;
    ans = ans % mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define MODULO 1000000007

int main() {
  int n;
  cin >> n;
  long int *v = (long int *)malloc(n * sizeof(long int));
  long int *sumP = (long int *)malloc((n - 1) * sizeof(long int));

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

  sumP[n - 2] = v[n - 1];
  for (int i = n - 3; i >= 0; i--) {
    long int aux = ((sumP[i + 1] % MODULO) + (v[i + 1] % MODULO)) % MODULO;
    sumP[i] = aux;
  }

  long int sum = 0;
  for (int i = 0; i < n - 1; i++) {
    long int prod = ((v[i] % (MODULO)) * (sumP[i] % (MODULO))) % MODULO;
    sum = ((prod % MODULO) + (sum % MODULO)) % MODULO;
  }

  cout << sum;
}

Error: TLE

Fixed submission:

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

#define MODULO 1000000007

int main() {
  int n;
  cin >> n;
  vector<long int> v(n);
  vector<long int> sumP(n - 1);

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

  sumP.insert(sumP.begin(), v[n - 1]);
  for (int i = n - 2; i > 0; i--) {
    long int aux = ((sumP[0] % MODULO) + (v[i] % MODULO)) % MODULO;
    sumP.insert(sumP.begin(), aux);
  }

  long int sum = 0;
  for (int i = 0; i < n - 1; i++) {
    long int prod = ((v[i] % (MODULO)) * (sumP[i] % (MODULO))) % MODULO;
    sum = ((prod % MODULO) + (sum % MODULO)) % MODULO;
  }

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


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
#define mx 100000000
#define pb push_back
#define mp make_pair
#define YES cout << "YES\\n";
#define Yes cout << "Yes\\n";
#define NO cout << "NO\\n";
#define No cout << "No\\n";
#define all(v) (v).begin(), (v).end()

ll md = 1e9 + 7;
ll __gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return __gcd(b, a % b);
}
ll poww(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1) {
      res *= a;
      res %= md;
    }
    a *= a;
    a %= md;
    b >>= 1;
  }
  return res;
}
void ainp(int arr[], int n) {
  for (int i = 0; i < n; i++)
    cin >> arr[i];
}

const ll N = 3e5 + 5;

void fun() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

signed main() {
  fun();
  int t;
  // cin>>t;
  t = 1;
  while (t--) {
    int n, i, j;
    ll sum = 0, csum = 0, p = 0;
    cin >> n;
    int a[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
      csum += a[i];
      csum %= md;
    }
    for (i = 0; i < n; i++) {
      csum -= a[i];
      if (csum < 0)
        csum += md;
      sum += ((a[i] % md) * (csum % md) % md);
      sum %= md;
    }
    cout << sum;
  }
}


Error: TLE

Fixed submission:


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
#define mx 100000000
#define pb push_back
#define mp make_pair
#define YES cout << "YES\\n";
#define Yes cout << "Yes\\n";
#define NO cout << "NO\\n";
#define No cout << "No\\n";
#define all(v) (v).begin(), (v).end()

ll md = 1e9 + 7;
ll __gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return __gcd(b, a % b);
}
ll poww(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1) {
      res *= a;
      res %= md;
    }
    a *= a;
    a %= md;
    b >>= 1;
  }
  return res;
}
void ainp(int arr[], int n) {
  for (int i = 0; i < n; i++)
    cin >> arr[i];
}

const ll N = 3e5 + 5;

void fun() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

signed main() {
  fun();
  int t;
  // cin>>t;
  t = 1;
  while (t--) {
    int n, i, j;
    ll sum = 0;
    cin >> n;
    int a[n];
    ainp(a, n);
    for (i = 0; i < n; i++) {
      for (j = i + 1; j < n; j++) {
        sum += ((1LL * (a[i] % md) * (a[j] % md)) % md);
        sum %= md;
      }
    }
    cout << sum;
  }
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;
using pii = pair<int, int>;
template <class T> using v = vector<T>;
template <class T> using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

int main() {
  ll mod = 1000000007;
  ll ans = 0, k = 0;
  int N;
  cin >> N;
  v<ll> A(N), B(N + 1, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    B[i + 1] = B[i] + A[i];
  }

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

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

Error: TLE

Fixed submission:

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

using ll = long long;
using pii = pair<int, int>;
template <class T> using v = vector<T>;
template <class T> using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

int main() {
  ll mod = 1000000007;
  ll ans = 0;
  int N;
  scanf("%d", &N);
  v<ll> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%ld", &A[i]);
  }

  for (int i = 0; i < N - 1; i++) {
    if (A[i] == 0) {
      continue;
    }
    for (int j = i + 1; j < N; j++) {
      ll k = A[i] * A[j];
      k = k % mod;
      ans += k;
      ans = ans % mod;
    }
  }

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