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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define reps(i, a, b) for (int i = a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
ll MOD = 1e9 + 7;

int mod(ll n) {
  n %= MOD;
  if (n < 0)
    n += MOD;

  return n;
}

int main() {
  int n;
  cin >> n;
  vector<ll> vec(n);
  rep(i, n) cin >> vec.at(i);
  ll ans = 0;
  vector<ll> culsum(n + 1, 0);
  reps(i, 1, n + 1) {
    culsum.at(i) = vec.at(i - 1) + culsum.at(i - 1);
    culsum.at(i) %= MOD;
  }
  rep(i, n - 1) {
    ans += vec.at(i) * mod(culsum.at(n) - culsum.at(i + 1));
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define reps(i, a, b) for (int i = a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
ll MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<ll> vec(n);
  rep(i, n) cin >> vec.at(i);
  ll ans = 0;
  rep(i, n) {
    reps(j, i + 1, n) {
      ans += vec.at(i) * vec.at(j);
      ans %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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


Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>

using namespace std;
constexpr int MOD = 1000000007;

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

  int n;
  cin >> n;

  vector<int64_t> a(n);
  vector<int64_t> am(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  am[0] = a[n - 1];
  am[0] %= MOD;
  for (int i = 1; i < n; ++i) {
    am[i] = am[i - 1] + a[n - i - 1];
    am[i] %= MOD;
  }

  int64_t ans = 0;

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

  cout << ans << '\\n';

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
constexpr int MOD = 1000000007;

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

  int n;
  cin >> n;

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

  int64_t ans = 0;

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

  cout << ans << '\\n';

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

/*Author:Copyrights: S7a2a7d
 Hardwork can always beat talent */

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define pb push_back
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repi(i, n) for (ll i = 1; i <= n; i++)
#define mem(arr, x) memset(arr, x, sizeof(arr))

#define mp make_pair
#define ff first
#define ss second

const double PI = 3.1415926535897932;
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int max(int a, int b) {
  if (a < b)
    return b;
  return a;
}

int main() {
  fast_io;
  int T = 1;
  // cin>>T;
  while (T--) {
    ll n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    vector<ll int> sums(n + 1, 0);
    for (int i = 0; i < n; i++) {
      sums[i + 1] = (sums[i] + a[i]);
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ll req = (sums[n] - sums[i + 1]) % mod;
      ans = ans + (ll)(a[i] * req);
      ans = ans % mod;
    }
    cout << ans << '\\n';
  }
}

Error: -8

Fixed submission:

/*Author:Copyrights: S7a2a7d
 Hardwork can always beat talent */

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define pb push_back
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repi(i, n) for (ll i = 1; i <= n; i++)
#define mem(arr, x) memset(arr, x, sizeof(arr))

#define mp make_pair
#define ff first
#define ss second

const double PI = 3.1415926535897932;
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); }
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int max(int a, int b) {
  if (a < b)
    return b;
  return a;
}

int main() {
  fast_io;
  int T = 1;
  // cin>>T;
  while (T--) {
    ll n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    vector<int> sums(n + 1, 0);
    for (int i = 0; i < n; i++) {
      sums[i + 1] = (sums[i] + a[i]) % mod;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ll req = (sums[n] - sums[i + 1]) % mod;
      ans = ans + (ll)a[i] % req;
      ans = ans % mod;
    }
    cout << ans << '\\n';
  }
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  // input
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  rep(i, N) { cin >> A.at(i); }
  // calc
  int64_t ans = 0;
  int64_t S = 0;
  for (int i = N - 2; i >= 0; i--) {
    S += A.at(i + 1);
    S %= P;
    ans += A.at(i) * S;
    ans %= P;
  }
  // output
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  // input
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  rep(i, N) { cin >> A.at(i); }
  // calc
  int64_t ans = 0;
  rep(i, N - 1) {
    for (int64_t j = i + 1; j < N; j++) {
      ans += A.at(i) * A.at(j);
      ans %= P;
    }
  }
  // output
  cout << ans << endl;
}
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;
using P = pair<int, int>;

const int MOD = 1e9 + 7;

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

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;
using P = pair<int, int>;

const int MOD = 1e9 + 7;

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

#include <iostream>
using namespace std;

int main(void) {
  int n;
  cin >> n;
  long int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int sum_1 = 0, sum_2 = 0;
  for (int i = 0; i < n; i++) {
    sum_1 += a[i];
  }
  sum_1 %= 1000000007;
  for (int i = 0; i < n; i++) {
    sum_1 -= a[i];
    if (sum_1 < 0)
      sum_1 += 1000000007;
    sum_2 = (sum_2 + a[i] * sum_1) % 1000000007;
  }
  cout << sum_2 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int n;
  cin >> n;
  long int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long int sum = 0;
  for (int i = 0; i < (n - 1); i++) {
    for (int j = i + 1; j < n; j++) {
      sum += a[i] * a[j] % 1000000007;
      sum = sum % (1000000007);
    }
  }

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

#include <iostream>
using namespace std;

int main(void) {

  int n;
  long long int a[200000];

  int i, j;

  unsigned long long int total, ans, mul;

  total = 0;
  ans = 0;

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

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

  cout << (ans % 1000000007);

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {

  int n;
  long long int a[200000];

  int i, j;

  long long int total;

  total = 0;

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

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

  cout << (total % 1000000007);

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

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

  ll ans = 0;

  for (int i = 0; i < N; i++) {
    sum -= A[i];
    ans += (A[i]) * (sum % (1000000000 + 7));
    ans %= (1000000000 + 7);
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

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

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

int main() {
  int n;
  cin >> n;

  vector<long> a(n);
  for (long &i : a) {
    cin >> i;
  }

  long long sum = 0;
  long long product = 0;
  int law = 1000000007;
  for (int j = 0; j < n; j++) {
    sum = (sum + a.at(j)) % law;
  }
  for (int i = 0; i < n - 1; i++) {
    sum = (sum - a.at(i)) % law;
    if (sum < 0)
      sum += law;
    product += a.at(i) * sum % law;
  }
  cout << product % law << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;

  vector<long> a(n);
  for (long &i : a) {
    cin >> i;
  }

  long sum = 0;
  long product = 0;
  int law = 1000000007;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum = (sum + a.at(j)) % law;
    }
    product += a.at(i) * sum % law;
    sum = 0;
  }
  cout << product % law << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <stdio.h>
#include <string.h>
#define mod 1000000007
using namespace std;

long long a[10010000];
long long h, n;

int main() {
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
    h += a[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    h -= a[i];
    ans = (ans + ((h) % mod * a[i]) % mod) % mod;
  }
  printf("%lld\\n", ans);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <stdio.h>
#include <string.h>
#define mod 1000000007
using namespace std;

long long a[100100];
long long h, n;

int main() {
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
    h += a[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    h -= a[i];
    ans = (ans + ((h) % mod * a[i]) % mod) % mod;
  }
  printf("%lld\\n", ans);
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

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

long long a[200005], pref[200005], res = 0;
int main() {
  int n, mod = 1000000007;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pref[i] = a[i] + pref[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    res += ((pref[i - 1] % mod) * (a[i] % mod)) % mod;
  }
  cout << res % mod;
}

Error: WA

Fixed submission:

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

long long a[100005], pref[100005], res = 0;
int main() {
  int n, mod = 1000000007;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pref[i] = a[i] + pref[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    res += ((pref[i - 1] % mod) * (a[i] % mod)) % mod;
  }
  cout << res % mod;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, n) for (long long i = 1; i < n; i++)
#define ll long long
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define PI acos(-1)
using P = pair<ll, ll>;

ll ketasu(ll a) {
  ll num = 1;
  while (a / 10) {
    num++;
    a /= 10;
  }
  return num;
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll kosuu(ll a) {
  ll sum = 0;
  for (ll i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      if (a != 1 && i * i != a) {
        sum += 2;
      } else {
        sum++;
      }
    }
  }
  return sum;
}

ll n;

vector<pair<ll, ll>> p;
void fs(ll a) {
  for (ll i = 2; i * i <= n; i++) {
    ll cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    p.emplace_back(i, cnt);
  }
  return;
}

ll di[] = {1, 0, -1, 0};
ll dj[] = {0, -1, 0, 1};
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<long long> B(N + 1, 0); // 累積和テーブル
  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;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define Rep(i, n) for (long long i = 1; i < n; i++)
#define ll long long
#include <cmath>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define PI acos(-1)
using P = pair<ll, ll>;

ll ketasu(ll a) {
  ll num = 1;
  while (a / 10) {
    num++;
    a /= 10;
  }
  return num;
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll kosuu(ll a) {
  ll sum = 0;
  for (ll i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      if (a != 1 && i * i != a) {
        sum += 2;
      } else {
        sum++;
      }
    }
  }
  return sum;
}

ll n;

vector<pair<ll, ll>> p;
void fs(ll a) {
  for (ll i = 2; i * i <= n; i++) {
    ll cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt++;
    }
    p.emplace_back(i, cnt);
  }
  return;
}

ll di[] = {1, 0, -1, 0};
ll dj[] = {0, -1, 0, 1};
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  const ll m = 1000000007;
  ll sum = 0;
  rep(i, n - 1) {
    for (ll j = i + 1; j <= n - 1; j++) {
      sum += a[i] * a[j];
      sum %= m;
    }
  }
  cout << sum << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

int main() {
  uint N;
  cin >> N;
  vector<ullong> A(N + 1);
  for (size_t i = 1; i < A.size(); ++i) {
    cin >> A[i];
  }

  ullong deno = ullong(1e9 + 7);
  vector<ullong> subSum(N + 1);
  subSum[A.size() - 1] = A[A.size() - 1];
  for (int j = A.size() - 2; j >= 2; --j) {
    subSum[j] = subSum[j + 1] + A[j];
    if (subSum[j] >= deno)
      subSum[j] %= deno;
  }

  ullong sum = 0;
  for (size_t i = 1; i <= N - 1; ++i) {
    ullong mul = A[i] * subSum[i + 1];
    if (mul >= deno)
      mul %= deno;
    sum = sum + mul;
    if (sum >= deno)
      sum %= deno;
  }

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

int main() {
  uint N;
  cin >> N;
  vector<ullong> A(N + 1);
  for (size_t i = 1; i < A.size(); ++i)
    cin >> A[i];

  ullong sum = 0;
  ullong deno = ullong(1e9 + 7);
  for (size_t i = 1; i <= N - 1; ++i) {
    for (size_t j = i + 1; j <= N; ++j) {
      ullong mul = A[i] * A[j];
      sum += mul;
      if (sum >= deno)
        sum %= deno;
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;

  long long ttttt = 0;
  vector<long long> A(200000);
  for (int a = 0; a < N; a++) {
    cin >> A.at(a);
    ttttt += A.at(a);
  }
  // long long hozon=ttttt;
  // sort(A.begin(),A.end());
  // long long amari=0;
  long long amari = 0;

  for (int p = 0; p < N - 1; p++) {
    long long hozon = 0;
    bool judge = 0;
    ttttt -= A.at(p);
    if (ttttt >= 1000000007) {
      hozon = ttttt;
      ttttt = ttttt % 1000000007;
      judge = 1;
    }
    amari += A.at(p) * ttttt;
    if (amari >= 1000000007) {
      // cout<<total<<"totalllll"<<endl;
      // amari+=total%1000000007;
      amari = amari % 1000000007;
      // cout<<amari<<"amari"<<endl;
    }
    if (judge) {
      ttttt = hozon;
    }
    // cout<<total<<"total"<<endl;
  }
  //  if(total>=1000000007){
  //     amari=amari%1000000007;

  //   }

  cout << amari;
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;

  vector<long long> A(200000);
  for (int a = 0; a < N; a++) {
    cin >> A.at(a);
  }
  // sort(A.begin(),A.end());
  // long long amari=0;
  long long total = 0;
  for (int p = 0; p < N - 1; p++) {
    for (int k = p + 1; k < N; k++) {
      total += A.at(p) * A.at(k);
      if (total >= 1000000007) {
        // cout<<total<<"totalllll"<<endl;
        // amari+=total%1000000007;
        total = total % 1000000007;
        // cout<<amari<<"amari"<<endl;
      }
      // cout<<total<<"total"<<endl;
    }
    //  if(total>=1000000007){
    //     amari=amari%1000000007;

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

#include <bits/stdc++.h>
#define ll long long
#define endl '\\n'
#define PI acos(-1)
#define sz 1095
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main() {
  RUN_FAST;
  cin.tie(nullptr);
  ll n, i, j;
  ll sum, mod = 1000000007, tmp1, str, tmp2;
  scanf("%lld", &n);
  ll arr1[n], arr2[n];
  for (i = 0; i < n; i++)
    scanf("%lld", &arr1[i]);
  for (i = 0; i < n; i++)
    arr2[i] = arr1[i];
  for (i = 1; i < n; i++)
    arr1[i] += arr1[i - 1];
  sum = 0;
  str = arr1[n - 1];
  for (i = 0; i < n; i++) {
    tmp1 = arr1[i];
    tmp2 = str - tmp1;

    tmp1 = arr2[i];
    tmp2 = ((tmp2 % mod) * (tmp1 % mod)) % mod;
    sum = ((sum % mod) + (tmp2 % mod)) % mod;
  }
  printf("%lld\\n", sum);
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define endl '\\n'
#define PI acos(-1)
#define sz 86029900
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main() {
  RUN_FAST;
  cin.tie(nullptr);
  ll n, i, j;
  ll sum, mod = 1000000007, tmp;
  scanf("%lld", &n);
  ll arr[n];
  for (i = 0; i < n; i++)
    scanf("%lld", &arr[i]);
  sum = 0;
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      tmp = arr[i] * arr[j];
      sum = ((sum % mod) + (tmp % mod)) % mod;
    }
  }
  printf("%lld\\n", sum);
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long

ll MOD = pow(10, 9) + 7;

int main() {
  ll N, ans = 0;
  cin >> N;
  vector<ll> A(N + 1), buf(N + 1);
  for (int i = 1; i <= N; ++i)
    cin >> A[i];
  /*
  for(int i = 1; i <= N-1; ++i){
      for(int j = i+1; j <= N; ++j){
          ll buf = A[i]*A[j] % MOD;
          ans += buf;
          ans %= MOD;
      }
  }
  */
  for (int i = N - 1; i >= 1; --i) {
    if (i == N - 1)
      buf[N - 1] = A[N];
    else
      buf[i] = (buf[i + 1] + A[i + 1]) % MOD;
  }
  for (int i = 1; i <= N - 1; ++i) {
    ans += (A[i] % MOD) * (buf[i] % MOD);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

#define ll long long

ll MOD = pow(10, 9) + 7;

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

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

const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  reverse(a.begin(), a.end());
  vector<long long> b(n);
  b.at(0) = a.at(0);
  for (int i = 1; i < n; i++) {
    b.at(i) = (b.at(i - 1) + a.at(i)) % mod;
  }
  reverse(b.begin(), b.end());
  reverse(a.begin(), a.end());

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

Error: TLE

Fixed submission:

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

const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      long long aa = a.at(i) * a.at(j) % mod;
      ans += aa;
      ans %= mod;
    }
  }
  cout << ans << endl;
}