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

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

const int MOD = 1e9 + 7;

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

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

  vector<long long> cumsum(N);
  cumsum[0] = A[0];

  for (int i = 1; i < N; ++i) {
    cumsum[i] = cumsum[i - 1] + A[i];
    cumsum[i] %= MOD;
  }

  long long res = 0;
  for (int i = 0; i < N - 1; ++i) {
    res += cumsum[i] * A[i + 1];
    res %= MOD;
  }

  cout << res << endl;
}

Error: TLE

Fixed submission:

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

const int MOD = 1e9 + 7;

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

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

  bool flag = false;
  long long res = 0;

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

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

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int P = 1000000007;
int n, i, a[200005];
i64 tot, ans;
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  for (i = n; i > 0; --i) {
    ans = (ans + tot * a[i]) % P;
    tot = (tot + a[i]) % P;
  }
  printf("%lld", ans);
}

Error: WA

Fixed submission:

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

#include <cstdio>
#include <iostream>

using namespace std;

#define S_MOD 1000000007

void main_body(void) {
  int N;
  long long A[200000];
  long long total = 0;
  long long ans = 0;

  cin >> N;

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

    total += A[i];
  }

  for (int i = 0; i < (N - 1); i++) {
    total -= A[i];

    ans += (total % S_MOD) * A[i];
    ans %= S_MOD;
  }

  cout << ans << endl;

  return;
}

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

  if (argc > 1) {
    c = atoi(argv[1]);
  } else {
    c = 1;
  }

  for (int i = 0; i < c; i++) {
    main_body();
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

void main_body(void) {
  int N;
  long long A[200000];
  long long ans = 0;

  cin >> N;

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

    for (int j = 0; j < i; j++) {
      ans += A[i] * A[j];
      ans %= 1000000007;
    }
  }

  cout << ans << endl;

  return;
}

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

  if (argc > 1) {
    c = atoi(argv[1]);
  } else {
    c = 1;
  }

  for (int i = 0; i < c; i++) {
    main_body();
  }

  return 0;
}
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>
using namespace std;
using namespace __gnu_pbds;
#define input freopen("input.txt", "r", stdin);
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main() {
  ll n, ans = 0, sum = 0;
  cin >> n;
  ll a[n];
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  for (ll i = n - 2; i >= 0; i--) {
    ll x = a[i];
    sum = (sum + a[i + 1]) % mod;
    ll prc = x * sum % mod;
    ans = (ans + prc) % mod;
  }
  cout << ans;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define input freopen("input.txt", "r", stdin);
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main() {
  ll n, ans = 0;
  cin >> n;
  ll a[n];
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  for (ll i = 0; i < n - 1; i++) {
    for (ll j = i + 1; j < n; j++) {
      ll prc = (a[i] * a[j]) % mod;
      ans = (ans + prc) % mod;
    }
  }
  cout << ans;
}
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 _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int n;
  cin >> n;
  vector<long> a(n);
  for (long &x : a) {
    cin >> x;
  }
  vector<long> b(n, 0);
  for (int i = n - 2; i >= 0; i--) {
    b.at(i) = (b.at(i + 1) + a.at(i + 1)) % (1000000000 + 7);
  }
  long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a.at(i) % (1000000000 + 7) * b.at(i) % (1000000000 + 7);
    sum = sum % (1000000000 + 7);
  }
  cout << sum << 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 _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

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

#include <algorithm>
#include <iostream>
#define MOD 1000000007
using namespace std;
int main() {
  int n;
  int i, j;
  unsigned long ans;

  cin >> n;
  unsigned long *a = new unsigned long[n];
  unsigned long total = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    total = (total + a[i]) % MOD;
  }

  unsigned long tmp;
  unsigned long tmp2;
  ans = 0;
  for (i = 0; i < n; i++) {
    if (a[i] > total) {
      total = MOD + total - a[i];
    } else {
      total = total - a[i];
    }
    tmp2 = (a[i] * total) % MOD;
    ans = ans + tmp2;
    ans = ans % MOD;
  }

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#define MOD 1000000007
using namespace std;
int main() {
  int n;
  int i, j;
  unsigned long ans;

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

  unsigned long tmp;
  ans = 0;
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      tmp = a[i] * a[j];
      tmp = tmp % MOD;
      ans = ans + tmp;
      ans = ans % MOD;
    }
  }

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

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORa(i, a, b) for (int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a, n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define UP(s) transform(s.begin(), s.end(), s.begin(), ::toupper)

//-------------------------------------------------------//

ll MOD = 1e9 + 7;

int main() {
  ll n, c, sum = 0, ans = 0;
  cin >> n;

  FOR(i, n) {
    cin >> c;
    ans = (ans + c * sum) % MOD;
    sum = (sum + c) % MOD;
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORa(i, a, b) for (int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a, n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define UP(s) transform(s.begin(), s.end(), s.begin(), ::toupper)

//-------------------------------------------------------//

ll MOD = 1e9 + 7;

int main() {
  ll n, ans = 0;
  cin >> n;

  vector<ll> v(n);
  FOR(i, n) cin >> v[i];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      ans = (ans + (v[i] * v[j]) % MOD) % MOD;
    }
  }

  cout << ans << endl;

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

#include <iostream>

int main() {
  unsigned long long N;
  unsigned long long result = 0, temp, sum = 0;

  std::cin >> N;
  for (int i = 0; i < N; i++) {
    std::cin >> temp;
    result += temp * sum;
    result %= 1000000007;
    sum += temp;
    sum %= 1000000007;
  }

  std::cout << result << std::endl;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

int main() {
  unsigned long long N;
  std::vector<unsigned long long> nums;
  unsigned long long result = 0, temp;

  std::cin >> N;
  for (int i = 0; i < N; i++) {
    std::cin >> temp;
    nums.push_back(temp);
  }

  for (int j = 1; j < N; j++) {
    temp = 0;

    for (int i = 0; i < j; i++) {
      temp += nums[i];
    }

    result += temp * nums[j];
    while (result > 1000000007)
      result -= 1000000007;
  }

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

#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll x = 1e9 + 7;
  vector<ll> sum_A(N);
  ll sum_a = 0;
  for (int i = 0; i < N; i++) {
    ll tmp;
    cin >> tmp;
    A[i] = tmp % x;
    sum_a += A[i];
  }
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    sum_a -= A[i];
    ll tmp_x = sum_a % x;
    sum += (A[i] * tmp_x) % x;
  }

  cout << sum % x << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll x = 1e9 + 7;
  for (int i = 0; i < N; i++) {
    ll tmp;
    cin >> tmp;
    A[i] = tmp;
  }
  ll sum = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      sum += (A[i] * A[j]) % x;
    }
  }

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

// 177 c 求乘积之和
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 6;
long long sl[MAX], sz[MAX];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> sl[i];
    sz[i] = (sz[i - 1] + sl[i]);
  }
  long long ans = 0;
  for (int j = 1; j <= n; j++) {
    ans += (sl[j] % 1000000007) * ((sz[n] - sz[j]) % 1000000007);
    ans %= 1000000007;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

// 177 c 求乘积之和
#include <bits/stdc++.h>
using namespace std;
const int MAX = 20e5 + 6;
long long sl[MAX];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &sl[i]);
  }
  long long ans = 0;
  for (int j = 1; j <= n - 1; j++) {
    for (int k = j + 1; k <= n; k++) {
      ans += sl[j] * sl[k];
      if (ans >= 1000000007) {
        ans %= 1000000007;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

int main() {
  int64_t N;

  std::cin >> N;
  std::vector<int64_t> A;
  std::vector<int64_t> B;
  for (int64_t n = 0; n < N; ++n) {
    int64_t a;
    std::cin >> a;
    A.emplace_back(a);
  }

  int64_t v = 0;
  for (int64_t n = N - 1; n >= 1; --n) {
    v += A[n];
    v = v % 1000000007ull;
    B.emplace_back(v);
  }

  std::reverse(B.begin(), B.end());

  v = 0;
  for (int64_t n = 0; n < N - 1; ++n) {
    v += A[n] * B[n];
    v = v % 1000000007ull;
  }
  std::cout << v << std::endl;

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

int main() {
  int64_t N;

  std::cin >> N;
  std::vector<int64_t> A;
  std::vector<int64_t> B;
  for (int64_t n = 0; n < N; ++n) {
    int64_t a;
    std::cin >> a;
    A.emplace_back(a);
  }

  int64_t v = 0;
  for (int64_t n = N - 1; n >= 1; --n) {
    v += A[n];
    B.emplace_back(v);
  }

  std::reverse(B.begin(), B.end());

  v = 0;
  for (int64_t n = 0; n < N - 1; ++n) {
    v += A[n] * B[n];
    v %= v % 1000000007;
  }
  std::cout << v << std::endl;

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

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

int main() { // main_program
  int N;
  int64_t sum = 0;
  int64_t kei = 0;
  cin >> N;
  vector<int> A(N);
  vector<int64_t> B(N);

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    B.at(i) = A.at(i) % 1000000007;
  }

  for (int i = N - 1; i > 0; i--) {
    kei += B.at(i);
    kei %= 1000000007;
    sum += (B.at(i - 1) * kei);
    sum %= 1000000007;
  }

  cout << sum << endl;
}

Error: TLE

Fixed submission:

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

int main() { // main_program
  int N;
  int64_t sum = 0;
  cin >> N;
  vector<int> A(N);
  vector<int64_t> B(N);

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    B.at(i) = A.at(i) % 1000000007;
  }

  for (int i = 0; i < N; i++) {
    int64_t kei = 0;
    for (int l = i + 1; l < N; l++) {
      kei += B.at(l);
    }
    kei %= 1000000007;
    sum += (B.at(i) * kei);
    sum %= 1000000007;
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long s1 = 0, s = 0, n, i, j, x, y, m = 1000000007, ans = 0;
  cin >> n;
  long long a[n + 3];

  for (i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  for (i = 0; i < n; i++) {
    s1 += a[i];
    x = s - s1;
    y = ((a[i] % m) * (x % m)) % m;
    ans = ((ans % m) + (y % m)) % m;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> m1;
int main() {
  long long n, i, j, x, y, m = 1000000007, ans = 0;
  cin >> n;
  long long a[n + 3];

  for (i = 0; i < n; i++)
    cin >> a[i];
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (m1[make_pair(i, j)] == 0) {
        x = ((a[i] % m) * (a[j] % m)) % m;
        m1[make_pair(i, j)] = x;
        ans = ((ans % m) + (x % m));

      } else {
        ans = ((ans % m) + (m1[make_pair(i, j)] % m));
      }
    }
  }
  cout << ans << endl;
}
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++)
using ll = long long;

const ll mod = 1000000007;

int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];
  ll ans = 0;
  ll s = 0;
  rep(i, n - 1) { s = (s + a[i + 1]) % mod; }
  rep(i, n - 1) {
    ans += (s * a[i]) % mod;
    s -= a[i + 1];
    if (s < 0)
      s += mod;
  }
  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++)
using ll = long long;

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

/*----------------------------------------------------*
 * लेखक --> अमित सिंह
 * संस्थान --> राष्ट्रीय प्रौद्योगिकी संस्थान, कुरुक्षेत्र
 *-----------------------------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define w(t)                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define fo(i, n) for (int i = 0; i < n; i++)
#define endl "\\n"
#define MOD 1000000007
void Tez() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  Tez();
  int n;
  cin >> n;
  ll a[n];
  fo(i, n) cin >> a[i];
  ll ans = 0;
  ll arr[n - 1];
  ll sum = 0;
  for (int i = 0; i < n; i++)
    sum = (sum + a[i]) % MOD;
  for (int i = 0; i < n - 1; i++) {
    arr[i] = ((sum - a[i]) % MOD + MOD) % MOD;
    // arr[i]=sum-a[i];
    sum = arr[i];
  }
  for (int i = 0; i < n - 1; i++) {
    ans = (ans + a[i] * arr[i]) % MOD;
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

/*----------------------------------------------------*
 * लेखक --> अमित सिंह
 * संस्थान --> राष्ट्रीय प्रौद्योगिकी संस्थान, कुरुक्षेत्र
 *-----------------------------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define w(t)                                                                   \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define fo(i, n) for (int i = 0; i < n; i++)
#define endl "\\n"
#define MOD 1000000007
void Tez() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  Tez();
  int n;
  cin >> n;
  ll a[n];
  fo(i, n) cin >> a[i];
  ll ans = 0;
  fo(i, n - 1) {
    for (int j = i + 1; j < n; j++) {
      ans = (ans + (a[i] * a[j]) % MOD) % MOD;
    }
  }
  cout << ans;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a[1000007], ans, qz[1000007];
const ll N = 1000000007;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] %= N;
    qz[i] = a[i];
  }

  for (int i = 2; i <= n; i++) {
    qz[i] += qz[i - 1] % N;
    qz[i] %= N;
  }

  for (int i = n; i >= 3; i--) {
    ans += ((a[i] % N) * (qz[i - 1] % N)) % N;
  }
  ans += (a[1] % N) * (a[2] % N);
  ans %= N;
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
typedef long long ll;
using namespace std;

const long long MOD = 1000000007;

void solve(long long N, std::vector<long long> A) {
  long long res = 0;
  vector<long long> B(N);
  fill(B.begin(), B.end(), 0);

  B[N - 1] = A[N - 1];
  for (int i = N - 2; i >= 0; i--) {
    B[i] += (B[i + 1] + A[i]) % MOD;
  }
  // REP(i, N) cout << "," << B[i];
  // cout << endl;

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

  cout << res % MOD << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
typedef long long ll;
using namespace std;

const long long MOD = 1000000007;

void solve(long long N, std::vector<long long> A) {
  long long res = 0;
  REP(i, N) {
    for (int j = i + 1; j < N; j++) {
      res += (A[i] * A[j]) % MOD;
    }
  }
  cout << res % MOD << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}