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

#include <bits/stdc++.h>
const unsigned int M = 1000000007;
using namespace std;
int main() {

  long long int n, sum = 0, ans = 0;
  cin >> n;
  long long int a[n], i;

  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  for (i = 0; i < n; i++) {
    sum -= a[i];
    ans += ((sum % M) * (a[i] % M)) % M;
  }
  cout << ans % M;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
const unsigned int M = 1000000007;
using namespace std;
int main() {

  long long int n, sum = 0;
  cin >> n;
  long long int a[n], i, j;

  for (i = 0; i < n; i++)
    cin >> a[i];
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      sum = (sum % M + ((a[i] % M) * (a[j] % M)) % M) % M;
    }
    sum = sum % M;
  }
  cout << sum % M;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
constexpr ll mod = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];
  ll sum = 0;
  for (int i = 0; i < n; ++i)
    sum += a[i];
  // cout<<sum<<endl;

  ll res = 0;
  rep(i, n) {
    sum -= a[i];
    res += (sum % mod) * a[i];
    res %= mod;
  }
  cout << res << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
constexpr ll mod = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];
  ll 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;
    }
  }
  // res %= mod;
  cout << res << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<long long> S(N + 1, 0);
  int mod = 1000000007;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    S[i + 1] = S[i] + A[i];
  }
  long long ans = 0;

  for (int i = 0; i < N; i++) {
    long long sum = (S[N] - S[i + 1]) % mod;
    ans += A[i] * sum;
    ans %= mod;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int N;
  vector<int> A(N);
  vector<long long> S(N + 1, 0);
  int mod = 1000000007;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    S[i + 1] = S[i] + A[i];
  }
  long long ans = 0;

  for (int i = 0; i < N; i++) {
    long long sum = (S[N] - S[i + 1]) % mod;
    ans += A[i] * sum;
    ans %= mod;
  }
  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 = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  int ans = 0;
  int x = 0;
  rep(i, n) {
    ans = ((ll)ans + (ll)a.at(i) * x) % mod;
    x = (x + a.at(i)) % mod;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

using namespace std;
int main() {
  // Your code here!
  long long n;
  cin >> n;
  vector<long long> moji(n);
  rep(i, n) cin >> moji.at(i);
  long long sum = 0;
  for (long long i = 0; i < n - 1; i++) {
    for (long long j = i + 1; j < n; j++) {
      sum += moji.at(i) * moji.at(j);
      sum = sum % (1000000000 + 7);
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
using ll = long long int;
ll a[200001];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

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

  ll sum = 0;
  for (int i = 0; i < n - 1; i++) {
    sum = (sum + a[i] * ((totalsum - a[i]) % MOD) % MOD) % MOD;
    totalsum -= a[i];
  }
  cout << sum << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
using ll = long long int;
ll a[200001];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

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

  ll sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      sum = (sum + a[i] * a[j]) % MOD;
    }
  }
  cout << sum << '\\n';
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <memory>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  ll mod = 1000000007;
  vector<ll> A(N);
  vector<ll> sums(N + 1);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
    sums[i + 1] = (sums[i] + A[i]) % mod;
  }
  ll res = 0;
  for (ll i = 0; i < N - 1; i++) {
    ll sum;
    if (sums[N] - sums[i + 1] < 0) {
      sum = sums[N] - sums[i + 1] + mod;
    } else {
      sum = sums[N] - sums[i + 1];
    }
    res += (A[i] * sum) % mod;
  }
  cout << res % mod << endl;
}

Error: TLE

Fixed submission:

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

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

// Atcoder 177C
#include <bits/stdc++.h>
#define endl "\\n"
#define int long long
using namespace std;

int MOD = 1000000007;

int32_t main() {
  int n;
  cin >> n;
  int arr[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum = (sum + arr[i]) % MOD;
  }
  int answer = 0;
  for (int i = 0; i < n; i++) {
    sum = (sum - arr[i]);
    if (sum < 0)
      sum += MOD;
    answer = (answer + (arr[i] * sum) % MOD) % MOD;
  }
  cout << answer << endl;
  return 0;
}

Error: TLE

Fixed submission:

// Atcoder 177
#include <bits/stdc++.h>
#define endl "\\n"
#define int long long
using namespace std;

int MOD = 1000000007;

int32_t main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      sum = (sum + (arr[i] * arr[j]) % MOD) % MOD;
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>    // circle math ( sin, con, sinh
#include <iomanip>  // input output manipulation
#include <iostream> // input output stream, cin cout( console in console out)
#include <stdio.h>  // standard input output
#include <string>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep3(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ll long long

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

int main() {
  ll N;     // 変数の宣言
  cin >> N; // 標準入力
  vector<ll> A(N);
  ll sum = 0;
  ll mod = 1000000007;
  rep(i, N) {
    cin >> A.at(i);
    sum += A[i];
    sum %= mod;
  }
  ll ans = 0;

  rep(i, N) {
    sum -= A[i];
    if (sum < 0)
      sum = sum + mod;

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

  cout << setprecision(12) << ans << endl; // 標準出力
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>    // circle math ( sin, con, sinh
#include <iomanip>  // input output manipulation
#include <iostream> // input output stream, cin cout( console in console out)
#include <stdio.h>  // standard input output
#include <string>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep3(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ll long long

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

int main() {
  ll N;     // 変数の宣言
  cin >> N; // 標準入力
  vector<ll> A(N);
  rep(i, N) cin >> A.at(i);
  ll ans = 0;
  ll mod = 1000000007;
  rep(i, N) {
    rep3(j, i + 1, N) {

      ans = ans + ((A.at(i) * A.at(j)) % mod);
      if (ans >= mod) {
        ans = ans % mod;
      }
    }
  }
  cout << setprecision(12) << ans << endl; // 標準出力
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define V vector<int>
#define VLL vector<long long>
#define VV vector<vector<int>>
#define be(x) begin(x), end(x)
#define For(a) for (int i = 0; i < a; i++)
#define Forin(a, b) for (int j = a; j < b; j++)
#define len(a) a.size()
#define pb push_back
#define mp make_pair
#define Um unordered_map
#define S unordered_set
#define mod 1000000007
using namespace std;
ll findProductSum(ll A[], ll n) {
  ll sum = 0, result = 0;
  for (ll i = 0; i < n; i++)
    sum = sum + A[i];
  for (int i = 0; i < n; i++) {
    sum -= A[i];
    result += ((A[i] % mod) * (sum % mod)) % mod;
  }
  return result % mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll n;
  cin >> n;
  ll a[n];
  For(n) cin >> a[i];
  cout << findProductSum(a, n) << "\\n";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define V vector<int>
#define VLL vector<long long>
#define VV vector<vector<int>>
#define be(x) begin(x), end(x)
#define For(a) for (int i = 0; i < a; i++)
#define Forin(a, b) for (int j = a; j < b; j++)
#define len(a) a.size()
#define pb push_back
#define mp make_pair
#define Um unordered_map
#define S unordered_set

ll solve();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  /*int t;
  cin>>t;
  while(t--)
  {
      //solve();
      //solve();cout<<"\\n";
      //cout<<"Case #"<<tc<<": "<<solve()<<endl;
      cout<<solve()<<endl;
  }*/
  cout << solve() << "\\n";
  return 0;
}
ll solve() {
  ll n;
  cin >> n;
  VLL v(n);
  For(n) cin >> v[i];
  ll sum = 0;
  For(n) {
    Forin(i + 1, n) {
      sum += ((v[i] % 1000000007) * (v[j] % 1000000007)) % 1000000007;
    }
  }
  return sum % 1000000007;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using int64 = long long;

struct aaa {
  aaa() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} aaa;

int main() {
  int n;
  cin >> n;
  vector<int64> a(n);
  vector<int64> sum(n + 1, 0);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int64 mod = 1e9 + 7;
  for (int i = n - 1; i >= 0; i--) {
    sum[i] = sum[i + 1] + a[i];
    sum[i] %= mod;
  }

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using int64 = long long;

struct aaa {
  aaa() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} aaa;

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

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

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

long long ara[2000009];
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("in.txt","r",stdin);
  long long i, j, n, sum = 0;
  long long M = 1000000007;

  scanf("%lld", &n);

  for (i = 1; i <= n; i++) {
    scanf("%lld", &ara[i]);
    sum += ara[i];
    sum %= M;
  }
  long long total = 0;
  for (i = 1; i < n; i++) {
    sum -= ara[i];
    if (sum < 0)
      sum += M;
    total += (sum * (ara[i] % M)) % M;
  }
  total = (total % M);

  printf("%lld\\n", total);

  return 0;
}


Error: TLE

Fixed submission:

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

long long ara[20000099];
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("in.txt","r",stdin);
  long long i, j, n, sum = 0;
  long long M = 1000000007;

  scanf("%lld", &n);

  for (i = 1; i <= n; i++) {
    scanf("%lld", &ara[i]);
  }

  for (i = 1; i < n; i++) {
    for (j = i + 1; j <= n; j++) {
      sum += ((ara[i] % M) * (ara[j] % M)) % M;
    }
  }
  sum = (sum % M);
  printf("%lld\\n", sum);

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

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long int
#define double long double
const int MOD = 1e9 + 7;

void solve() {
  int n;
  cin >> n;
  int arr[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    sum -= arr[i];
    // int temp = ((sum % MOD) * arr[i]) % MOD;
    // sum = ((sum % MOD) + (temp));
    ans += (sum % MOD) * arr[i];
    ans %= MOD;
  }
  cout << ans << endl;
}

int32_t main() {
  IOS;
#ifndef ONLINE_JUDGE

  freopen("input.txt", "r", stdin);

  freopen("output.txt", "w", stdout);
#endif

  solve();
}

Error: TLE

Fixed submission:

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

#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long
#define double long double
const int MOD = 1e9 + 7;

void solve() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += ((arr[i]) * (arr[j])) % MOD;
    }
  }
  cout << ans % MOD << endl;
}

int32_t main() {
  IOS;
#ifndef ONLINE_JUDGE

  freopen("input.txt", "r", stdin);

  freopen("output.txt", "w", stdout);
#endif

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

#include <bits/stdc++.h>

#define ll long long int
#define ull unsigned long long int
#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5 + 5;

int main() {

  IO;

  int n;
  cin >> n;
  ll ans = 0;
  vector<ll> v(n), dp(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  dp[0] = v[0];
  for (int i = 1; i < n; ++i) {
    dp[i] = v[i] + dp[i - 1];
  }

  for (int i = 1; i < n; ++i) {
    ans += ((dp[i - 1] % INF) * (v[i] % INF)) % INF;
  }
  cout << ans % INF;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define ll long long int
#define ull unsigned long long int
#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5 + 5;

int main() {

  IO;

  int n;
  cin >> n;
  ll ans = 0;
  vector<ll> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }

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

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

typedef long long int lli;

const long long int m = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;

  lli a, x;
  cin >> x;
  lli s = 0;
  lli sp = 0;
  s = (s % m + x % m) % m;

  for (int i = 2; i <= n; i++) {
    cin >> x;
    sp = (sp % m + ((s % m * x % m) % m) % m) % m;
    s = (s % m + x % m) % m;
  }
  cout << sp << endl;
}


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 s = 0;
  for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
      s = (s + (a[i] * a[j])) % 1000000007;

  cout << s << endl;

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

#include <bits/stdc++.h>
#define sc(x) scanf("%d", &x)
#define sc2(x, y) scanf("%d%d", &x, &y)
#define scs(x) scanf("%s", x)
#define pr(x) printf("%d", x)
#define prn(x) printf("%d\\n", x)
#define memc(x, y) memcpy(&x, &y, sizeof(x))
#define mems(x, y) memset(x, y, sizeof(x))
#define fli() freopen("in.txt", "r", stdin)
#define flo() freopen("out.txt", "w", stdout)
#define rep(i, v) for (int i = 0; i < v; i++)
#define repe(i, v) for (int i = 0; i <= v; i++)
#define Rep(i, x, v) for (int i = x; i < v; i++)
#define Repe(i, x, v) for (int i = x; i <= v; i++)
#define repv(i, x) for (auto i = x.begin(); i != x.end(); i++)
#define reprv(i, x) for (auto i = x.rbegin(); i != x.rend(); i++)
#define dbg(x) cout << #x << " : " << x << endl
#define pb push_back
#define bl putchar('\\n')
#define gcc getchar()
#define pcc putchar
#define si size
#define fi first
#define se second
#define MAX 300000
typedef long long ll;
typedef unsigned long long ull;
typedef std::vector<int> vi;
typedef std::pair<int, int> ii;
using namespace std;

long long int cm_sum[MAX] = {0};
long long int MM = 1000000000 + 7;

int main() {
  // fli();
  int n;
  long long int a[MAX];
  long long int ans = 0;
  mems(cm_sum, 0);
  sc(n);
  rep(i, n) {
    cin >> a[i];
    if (i) {
      cm_sum[i] = (cm_sum[i - 1] + a[i]) % MM;
      ans += (cm_sum[i - 1] % MM * a[i] % MM) % MM;
      ans %= MM;
      // cout<<(cm_sum[i-1]) << " with " << a[i] << " : "<<((cm_sum[i-1]%MM *
      // a[i]%MM) % MM)<<endl;
    } else {
      cm_sum[i] = a[i];
    }
  }
  // bl;
  // rep(i,n){
  //   cout<<cm_sum[i]<<' ';
  // }
  // bl;

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


Error: 0

Time elapsed: 0.034713 s.


Fixed submission:

//                                 Alisher_2211
#include <bits/stdc++.h>
#define long long long
#define all(vc) vc.begin(), vc.end()
#define allr(vc) vc.rbegin(), vc.rend()
#define pb push_back
#define fi first
#define se second
#define pi pair<long, long>
#define lcm(a, b) (a * b) / __gcd(a, b)
using namespace std;
const long N = 100100;
void read() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
long dp[N];
void solve() {
  long n;
  cin >> n;
  vector<long> v(n);
  for (auto &i : v)
    cin >> i;
  dp[0] = v[0];
  for (int i = 1; i < n; ++i) {
    dp[i] = dp[i - 1] + v[i];
    dp[i] %= 1000000007;
  }
  long ans = 0;
  for (int i = 1; i < n; ++i) {
    ans += v[i] * dp[i - 1];
    ans %= 1000000007;
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long T = 1;
  // cin >> T;
  while (T--) {
    solve();
    cout << '\\n';
  }
  cerr << "\\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\\n";
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int n;
  long a[200020];
  long mod = 1000000007;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  long long x = 0;
  for (int i = 0; i < n; i++) {
    ans = (ans + a[i] * x) % mod;
    x = (x + a[i]) % mod;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n;
  long a[20020];
  long mod = 1000000007;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  long long x = 0;
  for (int i = 0; i < n; i++) {
    ans = (ans + a[i] * x) % mod;
    x = (x + a[i]) % mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int N;
  cin >> N;
  vector<ll> B(N + 1, 0);
  vector<ll> v(N);
  rep(i, N) {
    cin >> v[i];
    B[i + 1] = B[i] + v[i];
  }
  int MOD = 1000000007;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll sum = (B[N] - B[i + 1]) % MOD;
    ans += (v[i] * sum) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int N;
  cin >> N;
  vector<ll> v(N + 1);
  rep(i, N) { cin >> v[i]; }
  int MOD = 1000000007;
  int sum = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      sum = (sum + (v[i] * v[j]) % MOD);
      sum %= MOD;
    }
  }
  cout << sum << 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 < (n); i++)
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  const ll k = 1e9 + 7;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }

  ll sum_2 = 0;
  rep(i, n) {
    sum -= (ll)a[i];
    sum_2 += (ll)(sum % k) * (ll)(a[i] % k);
    sum_2 %= k;
  }
  ll ans = sum_2 % k;

  cout << ans << endl;
  // cout << k << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll cnt = 0;
  const ll k = 1e9 + 7;
  for (int i = 0; i <= n - 2; i++) {
    for (int j = i + 1; j < n; j++) {
      cnt += ((ll)a[i] * (ll)a[j]) % k;
    }
  }
  ll ans = cnt % k;
  cout << ans << endl;
  return 0;
}