alexjercan/bugnet huggingface dataset:
Problem p02571 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(void) {

  string s, t;
  cin >> s >> t;
  int n = (int)s.size() - (int)t.size();
  if (n == 0)
    n = 1;
  int d[n] = {0};

  for (int i = 0; i < n; i++) {
    // d.push_back(0);
    for (int j = 0; j < (int)t.size(); j++) {
      if (s[i + j] != t[j]) {
        d[i]++;
      }
    }
  }

  // sort(d.begin(), d.end());
  sort(d, d + n);

  cout << d[0] << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(void) {

  string s, t;
  cin >> s >> t;
  vector<int> d;

  for (int i = 0; i < (int)s.size() - (int)t.size(); i++) {
    d.push_back(0);
    for (int j = 0; j < (int)t.size(); j++) {
      if (s[i + j] != t[j]) {
        d[i]++;
      }
    }
  }

  sort(d.begin(), d.end());

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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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--)
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   // 最大値を求める
#define MIN(x) *min_element(ALL(x))   // 最小値を求める
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 // πの値
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  ll sum = 0;
  ll ans = 0;
  vector<ll> data(N);
  REP(i, N) {
    cin >> data[i];
    sum += data[i];
  }
  REP(i, N - 1) {
    sum -= data[i];
    ans += data[i] * (sum % MOD);
    ans %= MOD;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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--)
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   // 最大値を求める
#define MIN(x) *min_element(ALL(x))   // 最小値を求める
// 定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 // πの値
// 略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, s;
  cin >> N;
  ll ans = 0;
  vector<ll> data(N);
  REP(i, N) {
    cin >> s;
    if (s != 0)
      data[i] = s;
    else
      continue;
  }
  REP(i, data.size()) {
    ll sum = 0;
    REP(j, data.size() - 1 - i) { sum += data[i + j + 1]; }
    ans += data[i] * (sum % MOD);
    ans %= MOD;
  }
  cout << ans;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#define M 1000000007
int main() {
  long long a[200000], i, n, j, s = 0, su = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s = (s + a[i]) % M;
  }
  for (i = 0; i < n; i++) {
    s -= a[i];
    s += M;
    s %= M;
    su += (a[i] * s) % M;
    su %= M;
  }
  cout << su;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
#define M 1000000007
int main() {
  long long a[100000], i, n, j, s = 0, su = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
    s %= M;
  }
  for (i = 0; i < n; i++) {
    s -= a[i];
    s %= M;
    su += (a[i] * s);
    su %= M;
  }
  cout << su % M;
}
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);
  vector<long long> b(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i + 1] = b[i] + a[i];
  }
  int mod = 1000000007;
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    long long sum = (b[n] - b[i + 1]) % mod;
    ans += a[i] * sum;
    ans %= mod;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  int mod = 1000000007;
  cin >> n;
  long long int a[n];
  long long int ans = 0;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans = (ans + a[i] * a[j]) % mod;
    }
  }
  cout << ans << endl;
  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 < (n); i++)
#define all(v) begin(v), end(v)
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll cnt = 0;
  ll mod = 1e9 + 7;
  rep(i, n) {
    cin >> a[i];
    cnt += a[i];
    cnt %= mod;
  }
  ll ans = 0;
  rep(i, n - 1) {
    cnt -= a[i];
    if (cnt < 0)
      cnt += mod;
    ans += (a[i] * cnt) % 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 < (n); i++)
#define all(v) begin(v), end(v)
using ll = long long;

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

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mpp make_pair
#define vll vector<ll>
#define mll unordered_map<ll, ll>
#define endl "\\n"
#define debug(x) cout << #x << "=" << x << "\\n"
#define fo(i, a, x) for (ll i = a; i < x; ++i)
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
using namespace std;

ll M = 1000000007;

void solve() {
  ll n;
  cin >> n;
  vll arr(n);
  fo(i, 0, n) { cin >> arr[i]; }
  vll suff(n);
  suff[n - 1] = 0;
  for (int i = n - 2; i >= 0; i--) {
    suff[i] = suff[i + 1] + arr[i + 1];
  }
  ll ans = 0;
  fo(i, 0, n) { ans = ans % M + (arr[i] % M * (suff[i] % M) % M) % M; }
  cout << ans << endl;
}

int main() {
  fastio;
  // #ifndef ONLINE_JUDGE
  //     freopen("input.txt", "r", stdin);
  //     freopen("output.txt", "w", stdout);
  // #endif
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mpp make_pair
#define vll vector<ll>
#define mll unordered_map<ll, ll>
#define endl "\\n"
#define debug(x) cout << #x << "=" << x << "\\n"
#define fo(i, a, x) for (ll i = a; i < x; ++i)
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
using namespace std;

ll M = 1000000007;

void solve() {
  ll n;
  cin >> n;
  vll arr(n);
  ll sum = 0;
  fo(i, 0, n) {
    cin >> arr[i];
    sum += arr[i];
  }
  ll ans = 0;
  fo(i, 0, n) {
    fo(j, i + 1, n) {
      if (arr[i] == 1) {
        ans = ans % M + (sum - 1) % M;
        break;
      } else if (arr[i] == 0)
        break;

      ans = ans % M + (arr[i] % M * arr[j] % M) % M;
    }
  }
  cout << ans << endl;
}

int main() {
  fastio;
  // #ifndef ONLINE_JUDGE
  //     freopen("input.txt", "r", stdin);
  //     freopen("output.txt", "w", stdout);
  // #endif
  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  long long suf[n], a[n], s = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long sum = 0, mod = 1e9 + 7;
  for (int i = n - 1; i >= 0; i--) {
    s += a[i];
    suf[i] = s % mod;
  }

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long long sum = 0, mod = 1e9 + 7;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      long long c = a[i] % mod, d = a[j] % mod;
      // long long c=a[i],d=a[j];
      sum += (c * d) % mod;
    }
  }
  cout << sum % mod;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll sum = 0, mod = 1000000007;
  int N;
  cin >> N;
  ll A[N];
  rep(i, N) cin >> A[i];
  ll sareru = 0;

  for (int k = N - 2; k >= 0; k--) {
    sareru += A[k + 1];
    sum += (A[k] * (sareru % mod)) % mod;
  }

  // rep(j,N){
  //   littlesum = 0
  //   for(int k = j+1; k<N ; k++){
  //     littlesum += (A[j] * A[k]) % mod;
  //   }
  //   sum += (A[j] * littlesum) % mod;
  // }
  cout << sum % mod << 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>;

int main() {
  ll sum = 0, mod = 1000000007;
  int N;
  cin >> N;
  ll A[N];
  rep(i, N) cin >> A[i];
  rep(i, N) A[i] %= mod;

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

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

int main() {
  int n;
  long long int ans = 0, mod = 1000000007;
  cin >> n;
  long long int a[n], b[n + 1];
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  b[n] = 0;
  for (int i = n - 1; i >= 0; --i) {
    b[i] = (b[i + 1] + a[i]) % mod;
  }

  for (int i = 0; i < n - 1; ++i) {
    ans = (ans + (a[i] * b[i + 1]) % mod) % mod;
  }
  cout << ans << '\\n';
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  long long int ans = 0, mod = 1000000007;
  cin >> n;
  long long int a[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) {
      ans = (ans + (a[i] * a[j]) % mod) % mod;
    }
  }
  cout << ans << '\\n';
}
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 ll = long long;
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
    sum %= mod;
  }
  ll ans = 0;
  ll q = 0;
  ll p = 0;
  rep(i, n - 1) {
    sum -= a[i];
    if (sum < 0)
      sum += mod;
    ans += (a[i] * sum) % mod;
  }
  cout << ans % mod;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll sum = 0;
  ll d = 1e9 + 7;
  rep(i, n) {
    for (int j = i + 1; j < n; j++) {
      a[i] %= d;
      a[j] %= d;
      sum += a[i] * a[j];
      sum %= d;
    }
  }

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

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

int main() {
  ll MOD = 1000000007;
  ll N;
  cin >> N;

  vector<ll> A(N, 0);
  ll Aadd = 0;
  rep(i, N) {
    cin >> A[i];
    Aadd += A[i];
  }
  sort(A.begin(), A.end());
  ll sum = 0;
  for (ll i = 0; i < N - 1; i++) {
    Aadd -= A[i];
    sum += ((A[i] % MOD) * (Aadd % MOD)) % MOD;
    sum %= MOD;
  }
  cout << sum << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ll MOD = 1000000007;
  int N;
  cin >> N;

  vector<ll> A(N, 0);
  rep(i, N) { cin >> A[i]; }
  sort(A.begin(), A.end());

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

#include <algorithm>
#include <bits/stdc++.h>
#include <queue>
#include <string>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i > 0; i--)
#define FOR(i, j, n) for (int i = j; i < n; i++)

typedef long long ll;
const ll MOD = 1000000007; // 10^9+7
const ll INF = 100000000;

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

  vector<ll> a(n + 1, 0);
  vector<ll> b(n + 1, 0);

  rep(i, n) {
    cin >> a[i];
    a[i] %= MOD;
  }
  repr(i, n) b[i] = (a[i] + b[i + 1]) % MOD;
  // rep(i,n) cout << b[i] << endl;

  ll ans = 0;

  rep(i, n - 1) {
    ans = (ans + (a[i] * b[i + 1]) % MOD) % MOD;
    // cout << ans << endl;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <queue>
#include <string>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i > 0; i--)
#define FOR(i, j, n) for (int i = j; i < n; i++)

typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 100000000;

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

  vector<int64_t> a(n);
  rep(i, n) cin >> a[i];

  rep(i, n) a[i] %= MOD;

  int64_t ans = 0;

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

  cout << ans << endl;

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

/*Anup Ghosh*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi acos(-1)
#define ull unsigned long long
#define nl printf("\\n")
#define MAXN 1000005
#define mod 1000000007
#define gcd(a, b) __gcd(a, b)
#define pb push_back
#define fio()                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define sp(n) fixed << setprecision(n)
int main() {
  fio();
  int n, i;
  cin >> n;
  int a[n];
  ll sum = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    sum %= mod;
  }
  ll ans = 0;
  for (i = 0; i < n; i++) {
    sum -= a[i];
    if (sum < 0)
      sum += mod;
    ans += a[i] * sum;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;
#define mod 1000000007

void solve() {
  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 += (a[i] % mod * a[j] % mod);
      ans %= mod;
    }
  }
  cout << ans << endl;
}
int main() {
  // int t; cin >> t; while(t--)
  solve();

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

#include <bits/stdc++.h>
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;
  for (int i = 0; i < N; i++) {
    sum -= A[i];
    if (sum < 0)
      sum += mod;

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


Error: WA

Fixed submission:

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

int power(int a, int b) {
  int p = 1, i;
  for (i = 1; i <= b; i++)
    p *= a;
  return p;
}
int main() {
  int t, n[100005], i, res, j, mod;
  long long int sum;
  mod = power(10, 9) + 7;
  cin >> t;
  while (t--) {
    for (i = 0; i < t; i++)
      cin >> n[i];
  }
  for (i = 0; i < t; i++) {
    for (j = i + 1; j < t - 1; j++) {
      sum += ((n[i] % mod) * (n[j] % mod)) % mod;
    }
  }
  cout << sum << '\\n';
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
ID: sstfmsc1
TASK: milk2
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define forin(i, n) for (int i = 0; i < (int)n; ++i)
#define MAXN 50000
#define INF 1000000
typedef long long ll;
const char nl = '\\n';
ll MOD = (ll)(1e9 + 7);

void solve() {
  int n;
  cin >> n;

  vector<ll> a(n);
  ll suma = 0;
  forin(i, n) {
    cin >> a[i];
    suma += a[i];
  }

  ll ans = 0;
  forin(i, n) {
    suma -= a[i];
    // cout << suma << nl;
    // cout << ( ( a[i] % MOD ) * ( suma % MOD ) ) % MOD << nl;
    ans = (ans + ((a[i] % MOD) * (suma % MOD)) % MOD) % MOD;

    // cout << ans << nl << nl;
  }

  cout << ans << nl;
  return;
}

int main() {
  // freopen("milk2.in", "r", stdin);
  // freopen("milk2.out", "w", stdout);
  IOS
 
    solve();

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
typedef long long LL;
LL s[200005];
long long mod(long long x, long long y) {
  long long a = x / y;
  return x - a * y;
}
int main() {
  int n;
  while (~scanf("%d", &n)) {
    LL sum = 0;
    for (int i = 0; i < n; i++) {
      scanf("%lld", &s[i]);
      if (i >= 1) {
        for (int j = i - 1; j >= 0; j--) {
          sum = sum + s[i] * s[j];
          sum = mod(sum, 1000000007);
        }
      }
    }
    printf("%lld\\n", sum);
  }
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
long long n, a[200010];
const int mod = 1000000007;
int main() {
  int n;
  cin >> n;
  long long s = 0, sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  for (int i = 1; i <= n; i++) {
    sum -= a[i];
    s = (((a[i] % mod) * (sum % mod) % mod) + s) % mod;
  }
  cout << s << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
long long n, a[200001];
const int mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  long long s = 0;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++) {
    long long sum = 0;
    for (int j = i + 1; j <= n; j++)
      sum = (sum + a[j]) % mod;
    s = (s + ((a[i] % mod) * sum) % mod) % mod;
  }
  cout << s << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const ll MOD = 1'000'000'007;

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

  int ans = 0;
  int x = 0;

  rep(i, n) {
    ans = (ans + (ll)a[i] * x) % MOD;
    x = (x + a[i]) % 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 = 1000000007;

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

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

  cout << sum % MOD << endl;

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

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for (ll i = 0; i < n; i++)

#ifdef DEBUG
#define DBG(fmt, ...) fprintf(stderr, fmt "\\n", ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

int main() {
  std::cout << std::fixed << std::setprecision(10);

  ll N;

  cin >> N;

  vector<ll> array(N);
  REP(i, N) { cin >> array[i]; }

  vector<ll> sums(N);
  sums[N - 1] = array[N - 1];
  for (int i = N - 2; i >= 0; i--) {
    sums[i] = (sums[i + 1] + array[i]) % MOD;
  }

  ll ans = 0;
  for (int i = 0; i < N - 1; i++) {
    ans += (sums[i + 1] * array[i]) % MOD;
    ans = ans % MOD;
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for (ll i = 0; i < n; i++)

#ifdef DEBUG
#define DBG(fmt, ...) fprintf(stderr, fmt "\\n", ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

int main() {
  std::cout << std::fixed << std::setprecision(10);

  ll N;

  cin >> N;

  vector<ll> array(N);
  REP(i, N) { cin >> array[i]; }

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

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

#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

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

int main() {

  long long N;
  vector<long long> arr;
  cin >> N;
  long long M = 1000000007;
  long long sum = 0;

  for (int i = 0; i < N; ++i) {
    long long tmp;
    cin >> tmp;
    // tmp %= M;
    sum += tmp;
    // sum %= M;
    arr.push_back(tmp);
  }
  long long ans = 0;
  for (int i = 0; i < N - 1; ++i) {
    long long A = arr[i];
    sum -= A;
    // sum %= M;
    ans += (sum % M) * A % M;
    ans %= M;
  }
  // ans %=M;

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

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

int main() {

  int N;
  vector<long long> arr;
  cin >> N;
  long long M = 1000000007;
  // 1000000007
  // 437235829
  // 2437235843

  for (int i = 0; i < N; ++i) {
    long long tmp;
    cin >> tmp;
    // tmp %= M;
    arr.push_back(tmp);
  }
  long long ans = 0;
  for (int i = 0; i < N - 1; ++i) {
    for (int j = i + 1; j < N; ++j) {
      long long A, B;
      A = arr[i];
      B = arr[j];
      ans = ans + (A * B % M);
      ans %= M;
    }
  }
  // ans %=M;

  cout << ans << endl;

  return 0;
}