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

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define forn(i, n) for (int i = 0; i < n; i++)
#define mod 1000000007
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0)

void solve() {

  int n;
  cin >> n;
  int a[n];
  vector<int> b(n + 1, 0);

  forn(i, n) {
    cin >> a[i];
    b[i + 1] = b[i] + a[i];
  }
  // for (auto x : b)cout << x << endl;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int s = (b[n] - b[i + 1]) % mod;
    ans = (ans + ((a[i] % mod) * (s % mod)) % mod) % mod;
  }

  cout << ans << endl;
}

int32_t main() {

  fastio;

#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);
#endif

  // int t; cin >> t;/
  int t = 1;

  while (t--) {
    solve();
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define forn(i, n) for (int i = 0; i < n; i++)
#define mod 1000000007
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0)

void solve() {

  int n;
  cin >> n;
  int a[n];

  forn(i, n) cin >> a[i];

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

  cout << ans << endl;
}

int32_t main() {

  fastio;

#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);
#endif

  // int t; cin >> t;/
  int t = 1;

  while (t--) {
    solve();
  }

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

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
int main() {
  int N;
  cin >> N;
  long long int A[N];
  Bint sum = 0;
  Bint array_sum = 0;
  Bint mod = 1000000007;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
    array_sum += A[i] * A[i];
  }
  sum = sum * sum;
  cout << ((sum - array_sum) / 2) % mod;
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
int main() {
  long long int N;
  cin >> N;
  long long int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  long long int sum = 0;
  long long int mod = 1000000007;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      sum += A[i] * A[j];
      if (sum >= mod) {
        sum %= mod;
      }
    }
  }
  cout << sum;
  cout << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
const ll MOD = 1000000007;
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

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;
}
template <class T> T GCD(T a, T b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); }

using namespace std;
// #inculude <bits/stdc++.h>
#define int long long

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007LL
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

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;
}
template <class T> T GCD(T a, T b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); }

using namespace std;
// #inculude <bits/stdc++.h>
#define int long long

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

#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define endl "\\n"
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) x.begin(), x.end()
#define arr(x) x, x + n
#define trav(a, x) for (auto &a : x)
#define rall(x) x.rbegin(), x.rend()
#define ll long long int
#define pb push_back
#define vi vector<int>
#define pii pair<int, int>

using namespace std;

const int mod = 1e9 + 7;
const int N = 1e6 + 5;

void solve() {
  int n;
  cin >> n;
  int a[n];
  rep(i, 0, n) cin >> a[i];
  ll ans = 0, x = 0;
  rep(i, 0, n) {
    ans = (ans + a[i] * x) % mod;
    x = (x + a[i]) % mod;
  }
  cout << ans << endl;
  return;
}

int main() {

  FIO solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) x.begin(), x.end()
#define arrAll(x, n) (x, x + n)
#define trav(a, x) for (auto &a : x)
#define rall(x) x.rbegin(), x.rend()
#define endl "\\n"

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int mod = 1e9 + 7;
const int N = 1e6 + 5;

void solve() {
  int n;
  cin >> n;
  ll a[n];
  ll sum = 0;
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n - 1) {
    rep(j, i + 1, n) { sum += (a[i] * a[j]) % mod; }
  }
  cout << sum % mod << endl;
  return;
}

int main() { FIO solve(); }
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

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

#define ll long long

#define forn(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define pb push_back
#define sz(a) (int)a.size()

#define endl "\\n"
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
const int mod = 1e9 + 7;
int32_t main() {
  int n;
  cin >> n;
  int a[n];
  int s = 0;
  forn(i, n) {
    cin >> a[i];
    s += a[i];
  }
  int suffixsum[n];
  int k = 0;
  for (int i = 0; i < n; i++) {
    k += a[i];
    suffixsum[i] = (s - k) % mod;
  }
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int add = (a[i] * suffixsum[i]) % mod;
    ans = (ans + add) % mod;
  }
  cout << ans;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define N 100005
using namespace std;
const int m = 1e9 + 7;
long long n, b[N], rsum[N], qsum[N], t;
#define name "vd"
#define ini                                                                    \\
  freopen(name ".inp", "r", stdin);                                            \\
  freopen(name ".out", "w", stdout)
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
int main() {
  // ini;
  fastio;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    sum += b[i];
    sum %= m;
  }
  long long ans = 0;
  for (int i = n; i >= 1; i--) {
    ans += (b[i] * (sum - b[i])) % m;
    ans %= m;
  }
  cout << (ans / 2) % m << '\\n';
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

int main() {
  long long modular = 1000000007;

  size_t N = 0;

  std::cin >> N;

  std::vector<long long> numbers(N, 0);
  std::vector<long long> sums(N - 1, 0);

  for (auto &number : numbers) {
    std::cin >> number;
  }

  long long answer = 0;

  for (size_t index = 0; index < N - 1; ++index) {
    if (index == 0) {
      sums.at(index) = numbers.at(N - 1);

      continue;
    }

    sums.at(index) = (numbers.at(N - index - 1) + sums.at(index - 1)) % modular;

    sums.at(index) %= modular;
  }

  for (size_t index = 0; index < N - 1; ++index) {
    long long sum = 0;

    answer += (numbers.at(index) * sums.at(N - index - 2)) % modular;

    answer %= modular;
  }

  std::cout << answer << std::endl;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

int main() {
  long long modular = 1000000007;

  size_t N = 0;

  std::cin >> N;

  std::vector<long long> numbers(N, 0);

  for (auto &number : numbers) {
    std::cin >> number;
  }

  long long answer = 0;

  for (size_t index = 0; index < N - 1; ++index) {
    long long sum = 0;

    for (size_t subindex = index + 1; subindex < N; ++subindex) {
      sum += numbers.at(subindex) % modular;

      sum %= modular;
    }

    answer += (numbers.at(index) * sum) % modular;

    answer %= modular;
  }

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

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define prtarr(n, len)                                                         \\
  {                                                                            \\
    for (int i = 0; i < len; i++)                                              \\
      cout << n[i] << " ";                                                     \\
  }

using namespace std;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;
using namespace std;

int n;
vll lists;
int main() {
  // freopen("input.txt", "r", stdin) ;
  // freopen("output.txt", "w", stdout) ;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  vll dp(n, 0);
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    ll sub;
    cin >> sub;
    sum += sub;
    lists.pb(sub);
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0)
      dp[i] = sum;
    else
      dp[i] = (dp[i - 1] - lists[i - 1]);
  }
  for (int i = 0; i < n - 1; i++) {
    ans += ((dp[i + 1] % MOD) * lists[i]) % MOD;
  }
  cout << ans % MOD;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
const int p = 1000000007;
const int max = 200005;
long long t[max];
int main() {
  int a;
  scanf("%d", &a);
  for (int i = 0; i < a; i++) {
    scanf("%lld", &t[i]);
  }
  long long sum = 0;
  for (int i = 0; i < a - 1; i++) {
    for (int j = i + 1; j < a; j++) {
      long long s = t[i] * t[j];
      sum = (sum + s) % p;
    }
  }
  printf("%lld", sum);
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<long long> sum(n + 1, 0);
  int mod = 1e9 + 7;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum[i + 1] = sum[i] + a[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    long long add = 1;
    long long temp = sum[n] - sum[i + 1];
    temp %= mod;
    add *= a[i];
    add *= temp;
    ans += add;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<long long> sum(n + 1, 0);
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum[i + 1] = sum[i] + a[i];
  }
  for (int i = 0; i < n - 1; ++i) {
    long long add = 1;
    long long temp = sum[n] - sum[i + 1];
    while (temp >= (1e9 + 7)) {
      temp -= (1e9 + 7);
    }
    add *= a[i];
    add *= temp;
    ans += add;
    while (ans >= (1e9 + 7)) {
      ans -= (1e9 + 7);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

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

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

  int i, j;

  cin >> N;
  for (i = 0; i < N; i++) {
    ll ai;
    cin >> ai;
    A.push_back(ai);
  }

  ll S = 0;
  ll sum = 0;
  ll mod = 1000000000 + 7;
  for (j = 1; j < N; j++) {
    sum += A[j];
    sum = sum % mod;
  }

  for (i = 0; i < N - 1; i++) {
    S += A[i] * sum;
    S = S % mod;
    sum -= A[i + 1];
    if (sum < 0) {
      sum += mod;
    }
  }

  cout << S << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

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

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

  int i, j;

  cin >> N;
  for (i = 0; i < N; i++) {
    ll ai;
    cin >> ai;
    A.push_back(ai);
  }

  ll S;
  S = 0;

  for (i = 0; i < N - 1; i++) {
    for (j = i + 1; j < N; j++) {
      S += (A[i] * A[j]) % (1000000000 + 7);
      S = S % (1000000000 + 7);
    }
  }

  cout << S << endl;

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

#include <bits/stdc++.h>
#define ll long long int
#define ulli unsigned long long int
#define pb push_back
using namespace std;
ll BS(ll s[], ll q, ll n) {
  ll beg = 0, last = n;
  while (beg <= last) {
    ll mid = (beg + last) / 2;
    if (s[mid + 1] >= q && s[mid] < q)
      return mid + 1;
    else if (s[mid] < q)
      beg = mid + 1;
    else
      last = mid - 1;
  }
  return 0;
}
bool isprime(ll n) {
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;
  if (n % 2 == 0 || n % 3 == 0)
    return false;
  for (ll i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0)
      return false;
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // while(!cin.eof())
  int t;
  t = 1;
  ll mod = 1000000007;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n], s[n], ans = 0;

    for (ll i = 0; i < n; i++)
      cin >> a[i];
    s[n - 1] = a[n - 1];
    for (ll i = n - 2; i >= 0; i--)
      s[i] = (a[i] + s[i + 1]) % mod;

    for (ll i = 0; i < n - 1; i++)
      ans = (ans % mod + (a[i] % mod) * (s[i + 1] % mod) % mod) % mod;
    cout << ans;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ulli unsigned long long int
#define pb push_back
using namespace std;
ll BS(ll s[], ll q, ll n) {
  ll beg = 0, last = n;
  while (beg <= last) {
    ll mid = (beg + last) / 2;
    if (s[mid + 1] >= q && s[mid] < q)
      return mid + 1;
    else if (s[mid] < q)
      beg = mid + 1;
    else
      last = mid - 1;
  }
  return 0;
}
bool isprime(ll n) {
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;
  if (n % 2 == 0 || n % 3 == 0)
    return false;
  for (ll i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0)
      return false;
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // while(!cin.eof())
  int t;
  t = 1;
  ll mod = 1000000007;
  while (t--) {
    ll n, s = 0;
    cin >> n;
    ll a[n];
    // int l1=s.length(),l2=t.length(),cnt,mini=1000;
    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++)
        s = (s % mod + (a[i] % mod * a[j] % mod) % mod) % mod;
      // mini=min(cnt,mini);
    }
    cout << s;
  }
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int mod = 1000000007;
  int n;
  cin >> n;
  long long a[200010];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long sum = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum = (sum + (a[i] * a[j]) % mod) % mod;
    }
  }
  cout << sum << "\\n";
  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)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  /*
  rep(i,N) cin >> A[i];

  ll ans = 0;
  int mod = 1000000007;


  //累積和
  vector <ll> S(N);
  S.at(0) = A.at(0);
  for (int i = 1; i < N; i++){
    S.at(i) = (S.at(i - 1) + A.at(i)) % mod;
  }

  for (int i = 0; i < N - 1; i++){
    ans += (A.at(i) * (S.at(N - 1) - S.at(i)) % mod) % mod;
    ans %= mod;
  }

  cout << ans << endl;
*/

  vector<ll> B(N + 1, 0); // 累積和テーブル
  int mod = 1000000007;

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

  ll ans = 0;

  // iについて全探索
  for (int i = 0; i < N; i++) {
    // A[i+1] + ... + A[N]を求める
    ll 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 (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void) {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

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

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef pair<int, int> P;

int n;
ll a[200005];
ll mod = 1000000007;

int main() {
  cin >> n;
  rep(i, n) { cin >> a[i]; }
  ll ans = 0;
  ll sum = 0;
  rep(i, n) { sum += a[i]; }
  for (int i = 0; i < n; i++) {
    sum -= a[i];
    ans += ((a[i] % mod) * (sum % mod)) % mod;
    ans = ans % mod;
  }

  ans = ans % mod;
  cout << ans;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef pair<int, int> P;

int n;
ll a[200005];
ll mod = 1000000007;

int main() {
  cin >> n;
  rep(i, n) cin >> a[i];
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += ((a[i] % mod) * (a[j] % mod)) % mod;

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

#include <bits/stdc++.h>
#include <queue>
#include <set>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repsl(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl
#define readVarll(nam)                                                         \\
  ll nam;                                                                      \\
  cin >> nam

#define DEV_VAL 1000000007
ll mulbig(ll a, ll b) { return (a * b) % DEV_VAL; }

ll addbig(ll a, ll b) { return (a + b) % DEV_VAL; }

int main() {
  ll n;
  cin >> n;
  ll mydata[n];
  rep(i, n) cin >> mydata[i];

  ll ans = 0;
  ll tmpadd = mydata[0];
  reps(i, 1, n) {
    ans = addbig(ans, mulbig(tmpadd, mydata[i]));
    tmpadd = addbig(tmpadd, mydata[i]);
  }

  cout << fixed << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <queue>
#include <set>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repsl(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl
#define readVarll(nam)                                                         \\
  ll nam;                                                                      \\
  cin >> nam

#define DEV_VAL 1000000007
ll mulbig(ll a, ll b) { return (a * b) % DEV_VAL; }

ll addbig(ll a, ll b) { return (a + b) % DEV_VAL; }

int main() {
  ll n;
  cin >> n;
  ll mydata[n];
  rep(i, n) cin >> mydata[i];

  ll ans = 0;
  rep(i, n) {
    reps(j, i + 1, n) {
      ll tmp = mulbig(mydata[i], mydata[j]);
      ans = addbig(ans, tmp);
    }
  }

  cout << fixed << ans << endl;

  return 0;
}