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

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep01(i, n) for (int i = 0; i < (n) + 1; i++)
#define rep10(i, n) for (int i = 1; i < (n); i++)
#define rep11(i, n) for (int i = 1; i < (n) + 1; i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
typedef struct {
  int x;
  int y;
} Pos;
using namespace std;

int main() {
  int sum = 0;
  ll ans = 0;
  const int MOD = 1000000007;

  int n;
  cin >> n;

  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
    sum %= MOD;
  }

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

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep01(i, n) for (int i = 0; i < (n) + 1; i++)
#define rep10(i, n) for (int i = 1; i < (n); i++)
#define rep11(i, n) for (int i = 1; i < (n) + 1; i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
typedef struct {
  int x;
  int y;
} Pos;
using namespace std;

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];
      if (sum >= (ll)1000000007)
        sum = sum % (ll)1000000007;
    }
  }

  cout << sum << endl;

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

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

#define MOD 1000000007

// C function for extended Euclidean Algorithm (used to
// find modular inverse.
ll gcdExtended(ll a, ll b, ll *x, ll *y) {
  // Base Case
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }

  ll x1, y1; // To store results of recursive call
  ll gcd = gcdExtended(b % a, a, &x1, &y1);

  // Update x and y using results of recursive
  // call
  *x = y1 - (b / a) * x1;
  *y = x1;

  return gcd;
}

// Function to find modulo inverse of b. It returns
// -1 when inverse doesn't
ll modInverse(ll b, ll m) {
  ll x, y; // used in extended GCD algorithm
  ll g = gcdExtended(b, m, &x, &y);

  // Return -1 if b and m are not co-prime
  if (g != 1)
    return -1;

  // m is added to handle negative x
  return (x % m + m) % m;
}

// Function to compute a/b under modlo m
ll modDivide(ll a, ll b, ll m) {
  a = a % m;
  int inv = modInverse(b, m);
  if (inv == -1) {
    cout << "masuk" << endl;
    return a;
  } else {
    // cout << inv << " " << a << " " << m << endl;
    return (inv * a) % m;
  }
}

int main() {
  int n;
  cin >> n;
  ll data[n + 5];
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> data[i];
    cnt += data[i];
    cnt %= MOD;
  }

  cnt = (cnt * cnt);

  ll res = 0;
  for (int i = 0; i < n; i++) {
    res += (data[i] * data[i]);
    res %= MOD;
  }

  cout << modDivide((cnt - res) % MOD, 2, MOD) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long

#define MOD 1000000007
int main() {
  int n;
  cin >> n;
  ll data[n + 5];
  for (int i = 0; i < n; i++) {
    cin >> data[i];
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += (data[i] * data[j]);
      ans %= MOD;
    }
  }

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

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(), (c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x) cerr << #x << " = " << (x) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);
  ll N;
  cin >> N;
  ll A[N];
  ll sum_a = 0;
  REP(i, N) {
    cin >> A[i];
    sum_a += A[i];
  }
  ll ans = 0;
  REP(i, N - 1) {
    sum_a -= A[i];
    ans += (sum_a % MOD) * (A[i] % MOD);
    ans = ans % MOD;
  }
  cout << ans << "\\n";
}

Error: TLE

Fixed submission:

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(), (c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x) cerr << #x << " = " << (x) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);
  ll N;
  cin >> N;
  ll A[N];
  REP(i, N) {
    cin >> A[i];
    A[i] = A[i] % MOD;
  }
  ll ans = 0;
  REP(i, N - 1) {
    FOR(j, i + 1, N) {
      ans += A[i] * A[j] % MOD;
      ans = ans % MOD;
    }
  }
  cout << ans << "\\n";
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
// #define t ll t;cin>>t;while(t--)
#define nn cout << endl;
#define ff(a, n) for (ll i = a; i < n; i++)
#define cY cout << "YES\\n"
#define cN cout << "NO\\n"
#define cy cout << "Yes\\n"
#define cn cout << "No\\n"
#define sc second
#define fs first
#define c(a) cout << a << endl
const ll m = 1000000007;
ll mod(ll a, ll b) {
  a = a % m;
  b = b % m;
  return (a * b) % m;
}
ll modd(ll a) { return a % m; }
void solve() {
  ll n;
  cin >> n;
  ll a[n];
  ff(0, n) cin >> a[i];
  ll ans = 0;
  ll x = 0;
  for (ll i = 0; i < n; i++) {
    ans += modd(mod(a[i], x));
    x = (modd(x) + modd(a[i])) % m;
  }
  ans = ans % m;
  cout << ans;
}

int main() { solve(); }
/*




*/


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
// #define t ll t;cin>>t;while(t--)
#define nn cout << endl;
#define ff(a, n) for (ll i = a; i < n; i++)
#define cY cout << "YES\\n"
#define cN cout << "NO\\n"
#define cy cout << "Yes\\n"
#define cn cout << "No\\n"
#define sc second
#define fs first
#define c(a) cout << a << endl
const ll m = 1000000007;
ll mod(ll a, ll b) {
  a = a % m;
  b = b % m;
  return (a * b) % m;
}
ll modd(ll a) { return a % m; }
void solve() {
  ll n;
  cin >> n;
  ll a[n];
  ff(0, n) cin >> a[i];
  ll ans = 0;
  for (ll i = 0; i < n - 1; i++) {
    for (ll j = i + 1; j < n; j++) {
      ans += modd(mod(a[i], a[j]));
    }
  }
  ans = ans % m;
  cout << ans;
}

int main() { solve(); }
/*
4
141421356 17320508 22360679 244949



*/
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int MOD = 1000000007;
  int N;
  LL ans = 0;
  LL sum = 0, suma;

  cin >> N;
  vector<LL> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }

  for (int i = 0; i < N - 1; i++) {
    sum -= vec.at(i);
    suma = sum % MOD;
    ans += vec.at(i) * suma;
    ans = ans % MOD;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int MOD = 1000000007;
  int N;
  LL ans = 0;

  cin >> N;
  vector<LL> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      ans += (vec.at(i) * vec.at(j)) % MOD;
    }
    ans = ans % MOD;
  }

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

#include <bits/stdc++.h>
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long int
using namespace std;
int mod = 1e9 + 7;

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio;

  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int sum = 0;
  vector<int> suffix(n, 0);
  suffix[n - 1] = arr[n - 1] % mod;
  for (int i = n - 2; i >= 0; i--) {
    suffix[i] = (suffix[i + 1] + arr[i]) % mod;
  }
  for (int i = 0; i < n - 1; i++)
    sum = (sum + (suffix[i + 1] * arr[i]) % mod) % mod;
  cout << sum % mod;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl "\\n"
#define int long long int
using namespace std;
int mod = 1e9 + 7;

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio;

  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 - 1; i++)
    for (int j = i + 1; j < n; j++)
      sum = (sum + (arr[i] * arr[j])) % mod;

  cout << sum;
  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 FOR(i, m, n) for (int i = m; i < n; i++)
#define MOD 1000000007
#define MAX 100010
#define aout(a)                                                                \\
  REP(i, sizeof(a)) cout << a[i] << " ";                                       \\
  cout << endl;
#define vout(v)                                                                \\
  REP(i, v, size()) cout << v[i] << " ";                                       \\
  cout << endl;
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  ll ans = 0;
  vector<ll> sum(N - 1);
  sum[0] = A[0];
  FOR(i, 1, N - 1) { sum[i] = (sum[i - 1] + A[i]) % MOD; }
  REP(i, N - 1) {
    int tmp = (A[i + 1] * sum[i]) % MOD;
    ans = (ans + tmp) % MOD;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define MOD 1000000007
#define MAX 100010
#define aout(a)                                                                \\
  REP(i, sizeof(a)) cout << a[i] << " ";                                       \\
  cout << endl;
#define vout(v)                                                                \\
  REP(i, v, size()) cout << v[i] << " ";                                       \\
  cout << endl;
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  ll ans = 0;

  FOR(i, 0, N - 1) {
    FOR(j, i + 1, N) { ans = (ans + ((A[i] * A[j]) % MOD)) % MOD; }
  }
  cout << ans;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
// #include<iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxv = 200005;
const int inf = 1e9 + 7;
int ar[maxv];
int main() {
  int n;
  ll sum = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
    sum += ar[i];
    sum %= inf;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    sum -= ar[i];
    if (sum < 0)
      sum += inf;
    ans += ar[i] * sum;
    ans %= inf;
  }
  printf("%lld\\n", ans);
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
// #include<iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxv = 100005;
const int inf = 1e9 + 7;
int ar[maxv];
int main() {
  int n;
  ll sum = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
    sum += ar[i];
    sum %= inf;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    sum -= ar[i];
    if (sum < 0)
      sum += inf;
    ans += ar[i] * sum;
    ans %= inf;
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

void solve() {

  int n;
  cin >> n;

  vector<int> a(n);

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

  int ans = 0;
  int x = 0;

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

  cout << ans;
}
int main() {

  int y;

  y = 1;
  // cin>>y ;

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

Error: TLE

Fixed submission:

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

void solve() {

  int n;

  cin >> n;

  ll arr[n];

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

  ll sum = 0;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += arr[i] * arr[j] % 1000000007;
    }
  }

  cout << sum % 1000000007;
}

int main() {

  int y;

  y = 1;
  // cin>>y ;

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

#include <bits/stdc++.h>
#define ll long long int
#define Y printf("YES\\n")
#define N printf("NO\\n")
#define pb push_back
#define tp make_tuple
#define srt(a) sort(a.begin(), a.end())
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) scanf("%lld%lld", &a, &b)
#define sc3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define pr(a) printf("%lld\\n", a)
#define r0 return 0
#define pi acos(-1)

using namespace std;

int main() {
  ll n, m, i, j, k, x, y, z, t;

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  cin >> n;

  m = 1e9 + 7;

  ll a[n + 5];

  ll sum = 0, ans = 0;

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

    ans += sum * a[i];

    ans %= m;

    sum += a[i];

    sum %= m;
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define Y printf("YES\\n")
#define N printf("NO\\n")
#define pb push_back
#define tp make_tuple
#define srt(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())
#define sc(a) scanf("%lld", &a)
#define sc2(a, b) scanf("%lld%lld", &a, &b)
#define sc3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define pr(a) printf("%lld\\n", a)
#define r0 return 0
#define pi acos(-1)

using namespace std;

int main() {
  ll n, m, i, j, k, x, y, z, t;

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  ll sum = 0;
  ll mod = 1e9 + 7;

  cin >> n;

  ll a[n + 5];

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

  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      k = (a[i] * a[j]) % mod;
      sum += k;

      sum %= mod;
    }
  }

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

// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
using namespace std;
int main() {
  int n, i, j, x;
  long long int ans = 0, a[200014], b[200014];
  b[0] = 0;
  cin >> n;
  long long int MOD = 1000000007;

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

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


Error: TLE

Fixed submission:

// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
using namespace std;
int main() {
  int n, i, j;
  long long int ans = 0, a[1000010];
  cin >> n;
  long long int MOD = 1000000007;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      if (a[i] * a[j] >= 1000000007) {
        ans += a[i] * a[j] % 1000000007;
        ans = ans % MOD;
      } else {
        ans += a[i] * a[j];
      }
    }
  }
  cout << ans << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, n, a) for (int i = n; i >= a; i--)
#define endl '\\n'
#define eps 0.000000001
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
using namespace std;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
int n;
ll a[maxn], pre[maxn];
int main() {
  int n;
  cin >> n;
  pre[0] = pre[1] = 0;
  rep(i, 1, n) cin >> a[i], pre[i + 1] = (pre[i] + a[i]) % mod;
  ll sum = 0;
  rep(i, 1, n) {
    ll cur = (pre[i] * a[i]) % mod;
    sum = (sum + cur) % mod;
  }
  cout << sum << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, n, a) for (int i = n; i >= a; i--)
#define endl '\\n'
#define eps 0.000000001
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
#define IO                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
using namespace std;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
int n;
ll a[maxn], pre[maxn];
int main() {
  int n;
  cin >> n;
  pre[0] = pre[1] = 0;
  rep(i, 1, n) cin >> a[i], pre[i + 1] = (pre[i] + a[i]) % mod;
  ll sum = 0;
  rep(i, 1, n) {
    ll cur = (pre[i] * a[i]) % mod;
    sum = (sum + cur) % mod;
  }
  cout << sum << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vec vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define inf 1e18
#define no_of_test(x)                                                          \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
const int mod = 1e9 + 7;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //	no_of_test(x)
  {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int pre[n + 1];
    pre[n] = 0;
    for (int i = n - 1; i >= 0; i--) {
      pre[i] = ((pre[i + 1] + a[i]) % mod);
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum = sum % mod + (((a[i] % mod) * (pre[i + 1] % mod)) % mod);
    }
    cout << sum << '\\n';
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 1e18
const int mod = 1e9 + 7;

int32_t main() {

  {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int a[n];
    int sum = 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++) {
        sum = (sum + (a[i] * a[j])) % mod;
      }
      // sum+=a[i]*a[i+1];
    }
    cout << sum << "\\n";
  }
  return 0;
}