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

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define inf 1e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  ll n, sum = 0, ans = 0, a[200000] = {};
  cin >> n;
  REP(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  sum %= 1000000007;
  REP(i, n) {
    sum -= a[i];
    sum = (ll)(sum + 1e9 + 7) % (ll)(1e9 + 7);
    ans += a[i] * sum;
    if (ans >= 1000000007)
      ans %= 1000000007;
  }
  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> a(n);
  vector<ll> rui(n + 1, 0);
  rui[0] = 0;
  rep(i, n) {
    cin >> a[i];
    rui[i + 1] += a[i] + rui[i];
    rui[i + 1] %= MOD;
    // cout << rui[i + 1] << " ";
  }

  unsigned long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (i >= 1) {
      ans += (rui[i] * a[i]) % MOD;
      ans %= MOD;
    }
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

const ll MOD = 1000000007;

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

  unsigned long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += (a[i] * a[j]) % MOD;
      ans %= MOD;
    }
    // cout << ans << " ";
  }
  cout << ans;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int N = 2e5 + 5;
ll a[N];

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 200000 + 100;
const LL mod = (1e9) + 7;
LL a[N];

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

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  LL num = sum(n);
  cout << num << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = (1e9 + 7) * 2;
ll a[200005];
int main(int argc, char *argv[]) {
  int n;
  ll sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += ((sum - a[i]) % mod) * a[i];
    ans %= mod;
  }
  cout << ans / 2 << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = (1e9 + 7) * 2;
ll a[100005];
int main(int argc, char *argv[]) {
  int n;
  ll sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += ((sum - a[i]) % mod) * a[i];
    ans %= mod;
  }
  cout << ans / 2 << endl;

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

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  const ll p = 1000000007;
  ll ans = 0;
  ll b = a.at(0) % p;
  for (int i = 1; i < n; i++) {
    ans += (a.at(i) % p) * (b % p);
    ans %= p;
    b += a.at(i) % p;
    b %= p;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  const ll p = 1000000007;
  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += (a.at(i) % p) * (a.at(j) % p);
      ans %= p;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int __int128
using namespace std;
const int mod = 1e9 + 7;
int n, sum[1000005], a[1000005], ans;
inline int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}
inline void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
signed main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read();
  for (int i = 1; i <= n; i++)
    sum[i] = sum[i - 1] + a[i];
  for (int i = 1; i <= n; i++)
    ans = (ans + a[i] * (sum[n] - sum[i])) % mod;
  write(ans);
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define int __int128
using namespace std;
const int mod = 1e9 + 7;
int n, sum[100005], a[100005], ans;
inline int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}
inline void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
signed main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read();
  for (int i = 1; i <= n; i++)
    sum[i] = sum[i - 1] + a[i];
  for (int i = 1; i <= n; i++)
    ans = (ans + a[i] * (sum[n] - sum[i])) % mod;
  write(ans);
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll mod(ll x) {
  const ll d = 1e9 + 7;
  ll y = x % d;

  ll z = 0;
  if (y >= 0) {
    z = y - d;
  }
  if (y < 0) {
    z = y + d;
  }
  if (abs(y) > abs(z)) {
    return z;
  } else {
    return y;
  }
}

int main() {
  const ll d = 1e9 + 7;
  int N;
  cin >> N;
  vector<ll> A(N);
  for (ll &a : A) {
    cin >> a;
  }

  ll sum = 0;
  for (ll a : A) {
    sum += a;
    sum = mod(sum);
  }
  ll square = mod(sum * sum);
  ll diag = 0;
  for (auto i = 0; i < N; ++i) {
    diag += mod(A[i] * A[i]);
    diag = mod(diag);
  }
  ll y = square - diag >= 0 ? square - diag : square - diag + d;
  ll x = (y * (d + 1) / 2) % d;
  cout << x << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (auto &a : A) {
    cin >> a;
  }
  const ll mod = 1e9 + 7;

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

#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <string>
#include <type_traits>

using namespace std;

// long long func(long long a, long long b, long long c){
//     long long ret = 0;
//     a %= c;
//     while (b) {
//         if (b & 1){
//         	ret = (ret + a) % c;
//         }
//         a = (2 * a)%c;
//         b >>= 1;
//     }
//     return ret;
// }

int main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif

  int n, flag;
  long long summy = 0;
  long long som = 0;
  long long bruh = pow(10, 9) + 7;
  cin >> n;
  long long arr[n];

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

  for (int j = 1; j < n; j++) {
    som += arr[j - 1];
    // cout << som << endl;
    // summy += func(som, arr[j], bruh);
    summy += som % bruh * (arr[j] % bruh);
    summy = summy % bruh;
  }

  cout << summy << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <string>
#include <type_traits>

using namespace std;

// long long func(long long a, long long b, long long c){
//     long long ret = 0;
//     a %= c;
//     while (b) {
//         if (b & 1){
//         	ret = (ret + a) % c;
//         }
//         a = (2 * a)%c;
//         b >>= 1;
//     }
//     return ret;
// }

int main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif

  int n;
  long long summy = 0;
  long long som = 0;
  long long bruh = pow(10, 9) + 7;
  cin >> n;
  long long arr[n];

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

  for (int j = 0; j < n; j++) {
    som = 0;
    for (int k = 0; k < j; k++) {
      som += arr[k];
    }
    // cout << som << endl;
    // summy += func(som, arr[j], bruh);
    summy += som % bruh * (arr[j] % bruh);
    summy = summy % bruh;
  }

  cout << summy << endl;

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define M 1000000007

int main() {

  int n;
  cin >> n;
  vector<ll> a(n, 0);

  ll out = 0;
  ll total = 0;

  rep(i, n) {
    cin >> a[i];
    total += a[i];
    total %= M;
  }

  rep(i, n) {
    total -= a[i];
    if (total < 0)
      total += M;
    out += ((a[i] * total) % M);
    out %= M;
  }

  cout << out;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define M 1000000007

int main() {

  int n;
  cin >> n;
  vector<ll> a(n, 0);

  ll out = 0;

  rep(i, n) { cin >> a[i]; }
  sort(a.begin(), a.end());

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

  out = out % M;
  cout << out;

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

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define PI acos(-1.0)
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define MOD 1000000007
#define MOD1 998244353
#define ep 0.000000001
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, 1};
int dy4[] = {1, -1, 1, -1};
// #define fio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ll n;
  cin >> n;
  ll a[n + 1], s, sum = 0, p = 0, ans, q;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    sum %= MOD;
    p += ((a[i] * a[i]) % MOD);
    p = p % MOD;
  }
  s = sum * sum;
  s %= MOD;
  q = s - p;
  if (q < 0)
    q = MOD - (abs(q) % MOD);
  ll x = 1, b = 2, po = MOD - 2;
  b = (b % MOD);
  while (po > 0) {
    if (po & 1)
      x = (x * b) % MOD;
    po = po >> 1;
    b = (b * b) % MOD;
  }
  ans = ((q % MOD) * (x % MOD)) % MOD;
  cout << ans << endl;
  return 0;
}
// https://thebestoffersintheweb.com/redirect/57a764d042bf8/


Error: TLE

Fixed submission:

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define PI acos(-1.0)
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define MOD 1000000007
#define MOD1 998244353
#define ep 0.000000001
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, 1};
int dy4[] = {1, -1, 1, -1};
// #define fio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  int n;
  cin >> n;
  ull a[n + 1];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ull x, ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      x = a[i] * a[j];
      x = x % MOD;
      ans += x;
      ans = ans % MOD;
    }
  }
  cout << ans << endl;
  return 0;
}
// https://thebestoffersintheweb.com/redirect/57a764d042bf8/
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef long long ll;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, m, n) for (ll i = (m); i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back

int main() {

  ll n;
  cin >> n;

  vector<ll> data(n);
  rep(i, n) {
    ll tmp;
    cin >> tmp;
    data.at(i) = tmp;
  }

  ll answer = 0;

  ll tmp = 0;

  rep(i, n) {
    tmp += data.at(i);
    tmp %= MOD;
  }

  ll tmp2 = 0;

  rep(i, n) {
    ll nijo = (data.at(i) * data.at(i)) % MOD;
    tmp2 += nijo;
    tmp2 %= MOD;
  }

  answer = ((tmp * tmp) % MOD) - tmp2;

  if (answer < 0) {
    answer += MOD;
  }

  if (answer % 2 == 1) {
    answer += MOD;
  }

  cout << (answer / 2) % MOD << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef long long ll;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, m, n) for (ll i = (m); i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back

int main() {

  ll n;
  cin >> n;

  vector<ll> data(n);
  rep(i, n) {
    ll tmp;
    cin >> tmp;
    data.at(i) = tmp;
  }

  ll answer = 0;

  for (ll i = 0; i < n; i++) {
    for (ll j = i + 1; j < n; j++) {
      ll tmp = data.at(i) * data.at(j);
      tmp %= MOD;
      answer += tmp;
      answer %= MOD;
    }
  }

  cout << answer << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pi;
typedef pair<lld, lld> pl;
typedef pair<int, lld> pil;
typedef pair<lld, int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a, b) make_pair(a, b)
bool isrange(int y, int x, int n, int m) {
  if (0 <= y && y < n && 0 <= x && x < m)
    return true;
  return false;
}
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1},
    ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const lld mod = 1e9 + 7;
lld arr[222222];
int main(void) {
  int n;
  scanf("%d", &n);
  lld tot = 0;
  for (int e = 0; e < n; e++) {
    scanf("%lld", &arr[e]);
    tot = (tot + arr[e]) % mod;
  }
  lld ans = 0;
  for (int e = 0; e < n; e++) {
    tot = (tot - arr[e] + mod) % mod;
    ans = (ans + arr[e] * tot) % mod;
  }
  printf("%lld", ans);
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pi;
typedef pair<lld, lld> pl;
typedef pair<int, lld> pil;
typedef pair<lld, int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a, b) make_pair(a, b)
bool isrange(int y, int x, int n, int m) {
  if (0 <= y && y < n && 0 <= x && x < m)
    return true;
  return false;
}
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1},
    ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const lld mod = 1e9 + 7;
lld arr[222222];
int main(void) {
  int n;
  scanf("%lld", &n);
  lld tot = 0;
  for (int e = 0; e < n; e++) {
    scanf("%lld", &arr[e]);
    tot = (tot + arr[e]) % mod;
  }
  lld ans = 0;
  for (int e = 0; e < n; e++) {
    tot = (tot - arr[e] + mod) % mod;
    ans = (ans + arr[e] * tot) % mod;
  }
  printf("%lld", ans);
  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<int64_t> a(n);
  int64_t sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  int64_t wa = 0;
  for (int i = 0; i < n - 1; i++) {
    sum -= a.at(i);
    wa += a.at(i) * (sum % 1000000007);
    wa %= 1000000007;
  }
  cout << wa << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int64_t> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int64_t sum = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += a.at(i) * a.at(j);
      sum %= 1000000007;
    }
  }
  cout << sum << endl;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded


/**
 *    author        : Sudipta Banik Trisha
 *    created       : August 29, 2020 6:00 PM
 *    Problem Name  : C - Sum of product of pairs
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc177/tasks/abc177_c
 *    @genarated by : ai-virtual-assistant
 **/

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

int main() {
  ios_base::sync_with_stdio(false);

  ll n;
  cin >> n;

  ll arr[n + 1], sum = 0, total = 0;

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

  for (ll i = 0; i < n; i++) {
    sum = sum - arr[i];
    total = ((total % mod) + ((sum % mod) * arr[i]) % mod) % mod;
  }
  cout << total % mod << endl;

  return 0;
}


Error: TLE

Fixed submission:


/**
 *    author        : Sudipta Banik Trisha
 *    created       : August 29, 2020 6:00 PM
 *    Problem Name  : C - Sum of product of pairs
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc177/tasks/abc177_c
 *    @genarated by : ai-virtual-assistant
 **/

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

int main() {
  ios_base::sync_with_stdio(false);

  ll n;
  cin >> n;

  ll arr[n + 1];

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

  ll sum = 0;

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

  cout << sum % mod << endl;

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

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

#define INCANT                                                                 \\
  cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define out(a) cout << a << endl
#define PRINT(V)                                                               \\
  for (auto v : (V))                                                           \\
  cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> Asum(N);
  rep(i, N) cin >> A[i];
  ll sum = 0;
  for (int i = N - 1; i >= 1; i--) {
    sum = (sum + A[i]) % MOD;
    Asum[i] = sum;
  }
  ll ans = 0;
  rep(i, N - 1) { ans = (ans + (A[i] * Asum[i + 1]) % MOD) % MOD; }
  out(ans);
}
int main() {
  INCANT;
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

#define INCANT                                                                 \\
  cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define out(a) cout << a << endl
#define PRINT(V)                                                               \\
  for (auto v : (V))                                                           \\
  cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll ans = 0;
  rep(i, N - 1) {
    FOR(j, i + 1, N) { ans = (ans + (A[i] * A[j]) % MOD) % MOD; }
  }
  out(ans);
}
int main() {
  INCANT;
  solve();
  return 0;
}
Problem p02572 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define Vsort(a) sort(a.begin(), a.end())
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define ll long long
#define P pair<int, int>
using namespace std;

const ll mod = 1000000007;

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

Error: TLE

Fixed submission:

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

int main() {
  int n;
  ll int ans = 0, b = 0, c = 0, d = 0, count = 0;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      b = a[i];
      c = a[j];
      d = b * c;
      d %= 1000000007;
      ans += d;
    }
  }
  ans %= 1000000007;
  cout << ans << endl;
}