prithivMLmods/Coder-Stat huggingface dataset:
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define endl '\n'

const ll MOD = 1000000007;

int main() {
  int n;
  scanf("%d", &n);
  vector<ll> a(n);
  for (ll &i : a)
    scanf("%lld", &i);
  ll ans = 0;
  for (ll i : a) {
    ans += i;
    ans = ans % MOD;
  }
  ans *= ans;
  ans = ans % MOD;
  for (ll i : a) {
    ans -= i * i;
    while (ans < 0)
      ans += MOD;
    ans = ans % MOD;
  }
  ans *= 500000004;
  ans = ans % MOD;
  printf("%lld", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define endl '\n'

const ll MOD = 1000000007;

int main() {
  int n;
  scanf("%d", &n);
  vector<ll> a(n);
  for (ll &i : a)
    scanf("%lld", &i);
  ll ans = 0;
  for (ll i : a) {
    ans += i;
    ans = ans % MOD;
  }
  ans *= ans;
  ans = ans % MOD;
  for (ll i : a) {
    ans -= i * i;
    if (ans < 0) {
      ll temp = (-ans + MOD - 1) / MOD;
      ans += temp * MOD;
    }
    ans = ans % MOD;
  }
  ans *= 500000004;
  ans = ans % MOD;
  printf("%lld", ans);
  return 0;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;

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

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;

int main() {
  ll n, sum = 0, summ = 0, a[300005];
  cin >> n;
  rep(i, n) { cin >> a[i]; }
  rep(i, n - 1) {
    summ += a[n - 1 - i];
    summ %= mod;
    sum += (a[n - 2 - i] * summ) % mod;
    sum %= mod;
  }
  cout << sum;
}
Problem p02572 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

long long a[100005], pref[100005], res = 0;
int main() {
  int n, mod = 1000000007;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pref[i] = a[i] + pref[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    res += ((pref[i - 1] % mod) * (a[i] % mod)) % mod;
  }
  cout << res % mod;
}

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

long long a[200005], pref[200005], res = 0;
int main() {
  int n, mod = 1000000007;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pref[i] = a[i] + pref[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    res += ((pref[i - 1] % mod) * (a[i] % mod)) % mod;
  }
  cout << res % mod;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

const int MOD = 1000000007;

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

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

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int ans = 0;
  long long int sum = 0;
  for (int i = n - 1; i > 0; i--) {
    sum += a[i];
    sum %= MOD;
    ans += a[i - 1] * sum % MOD;
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);

  long long sum = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += (long long)a.at(i) * a.at(j);
      sum = sum % 1000000007;
    }
  }

  cout << sum << endl;

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);

  long long sum = 0;
  long long u = 0;
  for (int i = n - 1; i > 0; i--) {
    u += a.at(i);
    u = u % 1000000007;
    sum += u * a.at(i - 1);
    sum = sum % 1000000007;
  }

  cout << sum << endl;

  return 0;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define endl '\n'
#define pb push_back
const int N = 1e5 + 1;
const int INF = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += (A[i] * A[j]);
      ans = ans % INF;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define endl '\n'
#define pb push_back
const int N = 1e5 + 1;
const int INF = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  int ans = 0;
  int x = 1;
  int p[n];
  p[0] = A[0];
  for (int i = 1; i < n; i++) {
    p[i] = (A[i] + p[i - 1]) % INF;
  }
  for (int i = 1; i < n; i++) {
    ans += (A[i] * p[i - 1]);
    ans %= INF;
  }
  cout << ans << endl;
}
Problem p02572 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
s = 0
for i in range(n):
    for j in range(i + 1, n):
        s += a[i] * a[j]
        s %= 1000000007
print(s % 1000000007)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
s1 = sum(a)
s2 = 0
ans = 0
for i in range(n - 1):
    s2 += a[i]
    ans += a[i] * (s1 - s2)
print(ans % 1000000007)
Problem p02572 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

const ll inf = 1000000007;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}

ll a[100005], sum[100005];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = (ans + a[i] * ((sum[n] - sum[i]) % inf) % inf) % inf;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

const ll inf = 1000000007;

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}

ll a[200005], sum[200005];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = (ans + a[i] * ((sum[n] - sum[i]) % inf) % inf) % inf;
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const int mod = 1e9 + 7;

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const int mod = 1e9 + 7;

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define pci pair < char, int
#define mii map<int, int>
#define mll map<long long int, long long int>
#define mci map<char, int>
#define umii unordered_map<int, int>
#define umll unordered_map<long long int, long long int>
#define umci unordered_map<char, int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
// ll visit[100001]={0};
// vector<ll> adj[1000001];

int main() {
  IOS;
  int t;
  t = 1; // cin>>t;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++)
      cin >> a[i];
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
      for (ll j = i + 1; j < n; j++) {
        ans = (ans + (a[i] * a[j]) % mod) % mod;
      }
    }
    cout << ans;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define pci pair < char, int
#define mii map<int, int>
#define mll map<long long int, long long int>
#define mci map<char, int>
#define umii unordered_map<int, int>
#define umll unordered_map<long long int, long long int>
#define umci unordered_map<char, int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
// ll visit[100001]={0};
// vector<ll> adj[1000001];

int main() {
  IOS;
  int t;
  t = 1; // cin>>t;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++)
      cin >> a[i];
    ll ans = 0;
    ll suf[n];
    suf[n - 1] = a[n - 1];
    for (ll j = n - 2; j >= 0; j--) {
      suf[j] = (a[j] + suf[j + 1]) % mod;
    }
    for (ll i = 0; i < n - 1; i++) {
      ans = (ans + (a[i] * suf[i + 1]) % mod) % mod;
    }
    cout << ans;
  }

  return 0;
}
Problem p02572 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<int, pii> viii;
typedef vector<pll> vll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vector<vl>> vvvl;
ll mod = 1e9 + 7;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll i, j, n, sum = 0;
  cin >> n;
  vl a;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum = (sum + a[i]) % mod;
  }
  ll ans = 0, curr = 0;
  for (i = 0; i < n; i++) {
    curr = (curr + a[i]) % mod;
    ans = (ans + (((sum - curr + mod) % mod) * a[i]) % mod) % mod;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<int, pii> viii;
typedef vector<pll> vll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vector<vl>> vvvl;
ll mod = 1e9 + 7;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll i, j, n, sum = 0;
  cin >> n;
  vl a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum = (sum + a[i]) % mod;
  }
  ll ans = 0, curr = 0;
  for (i = 0; i < n; i++) {
    curr = (curr + a[i]) % mod;
    ans = (ans + (((sum - curr + mod) % mod) * a[i]) % mod) % mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <fstream>
#include <iostream>

#define rep(a) for (int i = 0; i < a; i++)
#define E << endl;
#define Mode 1000000007
#define F freopen("in.txt", "r", stdin);
using namespace std;

int main() {
  // F;
  int ar[20005];
  int tem[20005];
  int n;
  cin >> n;
  rep(n) cin >> ar[i];

  long long sum = 0;
  rep(n) {
    sum += ar[i];
    tem[i] = sum;
  }
  long long ans = 0;
  rep(n - 1) {
    long long tempsum = tem[n - 1] - tem[i];
    tempsum %= Mode;

    // cout<<"just adition "<<tempsum<<endl;

    tempsum *= ar[i];

    tempsum %= Mode;

    ans += tempsum;
    ans %= Mode;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <cstring>
#include <fstream>
#include <iostream>

#define rep(a) for (int i = 0; i < a; i++)
#define E << endl;
#define Mode 1000000007
#define F freopen("in.txt", "r", stdin);
using namespace std;

int main() {
  // F;
  int ar[200005];
  long long tem[200005];
  int n;
  cin >> n;
  rep(n) cin >> ar[i];

  long long sum = 0;
  rep(n) {
    sum += ar[i];
    tem[i] = sum;
  }
  long long ans = 0;
  rep(n - 1) {
    long long tempsum = tem[n - 1] - tem[i];
    tempsum %= Mode;

    // cout<<"just adition "<<tempsum<<endl;

    tempsum *= ar[i];

    tempsum %= Mode;

    ans += tempsum;
    ans %= Mode;
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;

ll A[100010];
int main() {
  int N;
  cin >> N;
  ll sum = 0;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans = (ans + (sum % mod) * A[i]) % mod;
    sum += A[i];
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;

ll A[200010];
int main() {
  int N;
  cin >> N;
  ll sum = 0;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans = (ans + (sum % mod) * A[i]) % mod;
    sum += A[i];
  }
  cout << ans << endl;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  long long ans = 0;
  int n;
  cin >> n;

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

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

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  long long ans = 0;
  int n;
  cin >> n;

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

  long long b[n + 1] = {};
  for (int i = n - 1; i >= 0; i--) {
    b[i] = b[i + 1] + a[i];
    b[i] = b[i] % 1000000007;
  }

  for (int i = 0; i < n; i++) {
    ans += b[i + 1] * a[i];
    ans = ans % 1000000007;
  }
  cout << ans << endl;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1000000007;
using ll = long long;

int main() {

  int N;
  cin >> N;

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

  ll ans = 0;
  ll temp;
  for (int i = 0; i < N - 1; i++) {
    temp = 0;
    for (int j = i + 1; j < N; j++) {
      temp += A.at(j);
    }
    temp %= MOD;
    ans += A.at(i) * temp % MOD;
  }
  ans %= MOD;
  cout << ans << endl;
}

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

const int MOD = 1000000007;
using ll = long long;

int main() {

  int N;
  cin >> N;

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

  ll ans = 0;
  ll temp;
  for (int i = 1; i < N; i++) {
    temp += A.at(i - 1);
    temp %= MOD;
    ans += A.at(i) * temp % MOD;
  }
  ans %= MOD;
  cout << ans << endl;
}
Problem p02572 (C++)

Buggy submission (status: 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;
  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;
}

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;
  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;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
  ll n;
  ll r = 1e9 + 7;
  cin >> n;
  ll arr[n];
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    cin >> arr[i];
    for (ll j = 0; j < i; j++) {
      sum += (arr[i] * arr[j]) % r;
    }
  }

  cout << sum % r;
  return 0;
}


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

int main() {
  ll n;
  ll r = 1e9 + 7;
  cin >> n;
  ll arr[n];
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    ll temp;
    cin >> temp;
    if (i == 0)
      arr[i] = temp;
    else {
      sum += (temp * arr[i - 1]) % r;
      arr[i] = (arr[i - 1] % r + temp % r) % r;
    }
  }

  cout << sum % r;
  return 0;
}
Problem p02572 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
const ll m = 1e9 + 7;
using namespace std;
ll add(ll i, ll j) { return ((i % m) + (j % m)) % m; }
ll mod(ll i, ll j) { return ((i % m) * (j % m)) % m; }
int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  vector<ll> presum(n);
  v[n] = 0;
  presum[n] = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    v[i] = v[i] % m;
  }
  for (int i = n - 1; i >= 0; i--) {
    presum[i] = add(presum[i + 1], v[i + 1]);
  }
  ll ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    ans += mod(presum[i], v[i]);
    ans %= m;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
const ll m = 1e9 + 7;
using namespace std;
ll add(ll i, ll j) { return ((i % m) + (j % m)) % m; }
ll mod(ll i, ll j) { return ((i % m) * (j % m)) % m; }
int main() {
  int n;
  cin >> n;
  vector<ll> v(n + 1, 0);
  vector<ll> presum(n + 1, 0);
  v[n] = 0;
  presum[n] = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    v[i] = v[i] % m;
  }
  for (int i = n - 1; i >= 0; i--) {
    presum[i] = add(presum[i + 1], v[i + 1]);
  }
  ll ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    ans += mod(presum[i], v[i]);
    ans %= m;
  }
  cout << ans << endl;
}
Problem p02572 (C++)

Buggy submission (status: 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;
  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;
}

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;
  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;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, b, n) for (int i = (b); i < (n); i++)
using namespace std;
using ll = long long;
const ll M = 1000000007;

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

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, b, n) for (int i = (b); i < (n); i++)
using namespace std;
using ll = long long;
const ll M = 1000000007;

int main() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> a(n + 10);
  vector<ll> s(n + 10);
  rep(i, n) {
    cin >> a[i];
    s[i + 1] += s[i] + a[i];
    s[i + 1] %= M;
  }
  rep(i, n - 1) {
    if (s[n] - s[i + 1] < 0)
      ans += a[i] * (s[n] - s[i + 1] + M);
    else
      ans += a[i] * (s[n] - s[i + 1]);
    ans %= M;
  }
  cout << ans << endl;
}
Problem p02572 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define fast                                                                   \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
const ll Mod = (1e9 + 7) * 2;

int n;
ll a[100010];
ll sum, ans;

int main() {
  fast;

  cin >> n;

  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    sum %= Mod;

    ans += Mod - a[i] * a[i] % Mod;
    ans %= Mod;
  }

  ans += sum * sum % Mod;
  ans %= Mod;

  cout << ans / 2;
}

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

#define fast                                                                   \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
const ll Mod = (1e9 + 7) * 2;

int n;
ll a[200010];
ll sum, ans;

int main() {
  fast;

  cin >> n;

  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
    sum %= Mod;

    ans += Mod - a[i] * a[i] % Mod;
    ans %= Mod;
  }

  ans += sum * sum % Mod;
  ans %= Mod;

  cout << ans / 2;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)

using namespace std;
using ll = long long;

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


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

using namespace std;
using ll = long long;

int main() {
  ll mod = 7 + 1e9;
  ll n, ans = 0;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) {
    cin >> a[i];
    if (i != 0)
      b[i] += b[i - 1] + a[i];
  }
  rep(i, n) {
    ll k = a[i] * ((b[n - 1] - b[i]) % mod) % mod;
    ans += k;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
using namespace std;

int main() {
  long long n;
  cin >> n;
  vector<long long> av(n);
  long long suma = 0;
  for (auto &a : av) {
    cin >> a;
    suma += a;
  }

  long long ret = 0;
  for (long long i = 0; i < n - 1; ++i) {
    suma -= av[i];
    if (1000000007 < suma) {
      long long tempa = suma;
      while (1000000007 < tempa) {
        ret += av[i] * 1000000007;
        ret %= 1000000007;
        tempa -= 1000000007;
      }
      ret += av[i] * tempa;
      ret %= 1000000007;
    } else {
      ret += av[i] * suma;
      ret %= 1000000007;
    }
  }

  cout << ret << endl;

  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;

int main() {
  long long n;
  cin >> n;
  vector<long long> av(n);
  long long suma = 0;
  for (auto &a : av) {
    cin >> a;
    suma += a;
  }

  long long ret = 0;
  for (long long i = 0; i < n - 1; ++i) {
    suma -= av[i];
    long long tempa = suma % 1000000007;
    ret += av[i] * tempa;
    ret %= 1000000007;
  }

  cout << ret << endl;

  return 0;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
int main() {
  LL n, ans = 0;
  cin >> n;
  vector<LL> a(n);
  for (LL i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += (a[i] % MOD) * (a[j] % MOD);
      ans %= MOD;
    }
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
int main() {
  LL n, ans = 0;
  cin >> n;
  vector<LL> a(n);
  for (LL i = 0; i < n; i++)
    cin >> a[i];
  LL subSum = 0;
  for (int i = 0; i < n - 1; i++) {
    subSum += a[i];
    subSum %= MOD;
    ans += subSum * a[i + 1];
    ans %= MOD;
  }
  cout << ans;
}
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define MOD 1000000007
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> ans(n, 0);
  unsigned long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> ans[i];
  }

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

  cout << sum;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define MOD 1000000007
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<unsigned long long> ans(n, 0);
  unsigned long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> ans[i];
  }
  unsigned long long check = 0;
  for (int i = 0; i < n; i++) {
    sum = (sum + (ans[i] * check) % MOD) % MOD;
    check = (check + ans[i]) % MOD;
  }

  cout << sum;
  return 0;
}
Problem p02572 (Python)

Buggy submission (status: Time Limit Exceeded):
def main():
    import sys

    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        ans += sum(list(map(lambda x: A[i] * x, A[i + 1 :])))
    print(ans % (10**9 + 7))


main()


Fixed submission:
def main():
    import sys

    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    all_num = sum(A)
    for i in range(N, 1, -1):
        all_num -= A[i - 1]
        ans += A[i - 1] * all_num
    print(ans % (10**9 + 7))


main()
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

const ll MM = 1e9 + 7;
int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll &i : A)
    cin >> i;
  ll count = 0;
  for (ll i = 0; i < N - 1; i++)
    for (ll j = i + 1; j < N; j++) {
      count += (A[i] * A[j]) % MM;
      count %= MM;
    }
  cout << count << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

const ll MM = 1e9 + 7;
int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll &i : A)
    cin >> i;
  ll sum = 0, count = 0;
  vector<ll> B(N);

  for (ll j = N - 1; j >= 0; j--) {
    //  cout << j << endl;
    sum += A[j] % MM;
    sum %= MM;
    B[j] = sum;
  }

  for (ll i = 0; i < N - 1; i++) {
    count += (A[i] * B[i + 1]) % MM;
    count %= MM;
  }

  cout << count << endl;
}
Problem p02572 (C++)

Buggy submission (status: 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("%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;
}


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("%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;
}
Problem p02572 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3
N = int(input())
A = list(map(int, input().split()))

mod = 10**9 + 7
ans = 0
for i in range(N - 1):
    ans += (A[i] * (sum(A[i + 1 :]) % mod)) % mod
    ans = ans % mod
print(ans)


Fixed submission:
#!/usr/bin/env python3
N = int(input())
A = list(map(int, input().split()))

mod = 10**9 + 7

s = sum(A) ** 2

a = 0
for i in A:
    a += i**2

ans = (s - a) // 2
ans = ans % mod

print(ans)
Problem p02572 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02572 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans += a[i] * sum(a[i + 1 :])

print(ans % (10**9 + 7))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
r = [0] * (n + 1)
for i, v in enumerate(a, start=1):
    r[i] = v + r[i - 1]

for i in range(n - 1):
    ans += a[i + 1] * r[i + 1]

print(ans % (10**9 + 7))
Problem p02572 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, sum = 0;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (i < j) {
        sum += a[i] * a[j];
        sum = sum % 1000000007;
      }
    }
  }
  cout << sum << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, sum = 0;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int x = 0;
  for (long long int i = 0; i < n; i++) {
    // for(long long int j=i+1;j<n;j++)
    //	{
    //	if(i<j)
    //	{
    sum = (sum + ((long long int)a[i] * x)) % 1000000007;
    x = (x + a[i]) % 1000000007;

    //	}
    //}
  }
  cout << sum << endl;
  return 0;
}
Problem p02573 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i, a, b) for (int i = a; i <= b; i++)

void dfs(vector<vector<int>> &arr, vector<int> &vis, int curr, int col) {
  queue<int> q;
  q.push(curr);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    if (vis[now] != 0)
      continue;
    vis[now] = col;
    for (auto i : arr[now]) {
      if (vis[i] == 0)
        q.push(i);
      // cerr<<i<<" ";
    }
    // cerr<<endl;
  }
}

void solve(int test_case) {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    cout << 1;
    return;
  }
  vector<vector<int>> arr(n, vector<int>(10000));
  while (m--) {
    int f, t;
    cin >> f >> t;
    f--, t--;
    arr[f].PUB(t);
    arr[t].PUB(f);
  }
  vector<int> vis(n, 0);
  int col = 1;
  for (int i = 0; i < n; i++)
    if (vis[i] == 0)
      dfs(arr, vis, i, col++);
  vector<int> cols(col, 0);
  int ans = 0;
  for (int i : vis) {
    if (i != 0)
      cols[i]++, ans = max(ans, cols[i]);
  }
  // for(int i:cols)cerr<<i<<" ";
  cout << ans;
}

int main() {

  ////// FILE BASED IO////
  // freopen("in", "r", stdin);
  // freopen("out", "w", stdout);
  ///////////////

  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  // cin>>t;
  REP(i, 1, t) { solve(i); }
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i, a, b) for (int i = a; i <= b; i++)

void dfs(vector<vector<int>> &arr, vector<int> &vis, int curr, int col) {
  queue<int> q;
  q.push(curr);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    if (vis[now] != 0)
      continue;
    vis[now] = col;
    for (auto i : arr[now]) {
      if (vis[i] == 0)
        q.push(i);
      // cerr<<i<<" ";
    }
    // cerr<<endl;
  }
}

void solve(int test_case) {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    cout << 1;
    return;
  }
  vector<vector<int>> arr(n, vector<int>());
  while (m--) {
    int f, t;
    cin >> f >> t;
    f--, t--;
    arr[f].PUB(t);
    arr[t].PUB(f);
  }
  vector<int> vis(n, 0);
  int col = 1;
  for (int i = 0; i < n; i++)
    if (vis[i] == 0)
      dfs(arr, vis, i, col++);
  vector<int> cols(col, 0);
  int ans = 0;
  for (int i : vis) {
    if (i != 0)
      cols[i]++, ans = max(ans, cols[i]);
  }
  // for(int i:cols)cerr<<i<<" ";
  cout << ans;
}

int main() {

  ////// FILE BASED IO////
  // freopen("in", "r", stdin);
  // freopen("out", "w", stdout);
  ///////////////

  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  // cin>>t;
  REP(i, 1, t) { solve(i); }
}
Problem p02573 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define fr(n, x) for (ll n = 0; n < x; n++)
#define pf(x) cout << x << '\n'
const ll mx = 1e5 + 4;
const ll mod = 1e9 + 7;
#pragma GCC optimize("O3")

vll graph[mx];
bool vis[mx] = {0};
ll res = 0;

void dfs(ll node) {
  vis[node] = 1;
  queue<ll> bfs;
  bfs.push(node);
  while (!bfs.empty()) {
    ll top = bfs.front();
    bfs.pop();
    res++;
    for (auto j : graph[top]) {
      if (!vis[j]) {
        bfs.push(j);
        vis[j] = 1;
      }
    }
  }
}

int main() {

  ll x, y;
  cin >> x >> y;
  set<pair<ll, ll>> edg;

  fr(n, y) {
    ll a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  ll mx = 0;
  for (ll n = 1; n <= x; n++) {
    if (!vis[n]) {
      res = 0;
      dfs(n);
      mx = max(mx, res);
      // cout << res << ' ' << n << '\n';
    }
  }
  cout << mx;
}


Fixed submission:
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define fr(n, x) for (ll n = 0; n < x; n++)
#define pf(x) cout << x << '\n'
const ll mx = 3e5 + 4;
const ll mod = 1e9 + 7;
#pragma GCC optimize("O3")

vll graph[mx];
bool vis[mx] = {0};
ll res = 0;

void dfs(ll node) {
  vis[node] = 1;
  queue<ll> bfs;
  bfs.push(node);
  while (!bfs.empty()) {
    ll top = bfs.front();
    bfs.pop();
    res++;
    for (auto j : graph[top]) {
      if (!vis[j]) {
        bfs.push(j);
        vis[j] = 1;
      }
    }
  }
}

int main() {

  ll x, y;
  cin >> x >> y;
  set<pair<ll, ll>> edg;

  fr(n, y) {
    ll a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  ll mx = 0;
  for (ll n = 1; n <= x; n++) {
    if (!vis[n]) {
      res = 0;
      dfs(n);
      mx = max(mx, res);
      // cout << res << ' ' << n << '\n';
    }
  }
  cout << mx;
}
Problem p02573 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
const int N = 1e5 + 5;

typedef long long ll;
int father[N];
int height[N];
int people[N];

int find(int x) {
  if (x != father[x])
    father[x] = find(father[x]);

  return father[x];
}

// 合并并返回合并后的祖先序号
void Union(int x, int y) {
  x = find(x);
  y = find(y);

  if (height[x] > height[y]) {
    father[y] = x;

    // 两者祖先相同时，实际没发生合并，只考虑祖先不同的情况
    if (x != y)
      people[x] += people[y];
  } else {
    father[x] = y;

    // 两者祖先相同时，实际没发生合并，只考虑祖先不同的情况
    if (x != y)
      people[y] += people[x];

    if (height[x] == height[y]) // 树高相同时让父节点的树高值加一
      height[y] += 1;
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    father[i] = i;
    height[i] = 0;
    people[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    Union(a, b);
  }
  int cnt = 1;
  for (int i = 1; i <= n; i++)
    if (people[i] > cnt)
      cnt = people[i];
  cout << cnt;
}


Fixed submission:
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
const int N = 2e5 + 5;

typedef long long ll;
int father[N];
int height[N];
int people[N];

int find(int x) {
  if (x != father[x])
    father[x] = find(father[x]);

  return father[x];
}

// 合并并返回合并后的祖先序号
void Union(int x, int y) {
  x = find(x);
  y = find(y);

  if (height[x] > height[y]) {
    father[y] = x;

    // 两者祖先相同时，实际没发生合并，只考虑祖先不同的情况
    if (x != y)
      people[x] += people[y];
  } else {
    father[x] = y;

    // 两者祖先相同时，实际没发生合并，只考虑祖先不同的情况
    if (x != y)
      people[y] += people[x];

    if (height[x] == height[y]) // 树高相同时让父节点的树高值加一
      height[y] += 1;
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    father[i] = i;
    height[i] = 0;
    people[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    Union(a, b);
  }
  int cnt = 1;
  for (int i = 1; i <= n; i++)
    if (people[i] > cnt)
      cnt = people[i];
  cout << cnt;
}
Problem p02573 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int back(int tree[], int start) {
  int root;
  if (tree[start] == -1)
    return start;
  root = back(tree, tree[start]);
  tree[start] = root;
  return root;
}

int main() {
  int n, m;
  cin >> n >> m;
  int h1[n], h2[n];
  rep(i, n) {
    h1[i] = -1;
    h2[i] = 0;
  }
  int a, b, aroot, broot;
  rep(i, m) {
    cin >> a >> b;
    aroot = back(h1, a);
    broot = back(h1, b);
    if (aroot != broot)
      h1[aroot] = broot;
  }
  rep(i, n) h2[back(h1, i)]++;
  int mm = 0;
  rep(i, n) mm = max(mm, h2[i]);
  cout << mm;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int back(int tree[], int start) {
  int root;
  if (tree[start] == -1)
    return start;
  root = back(tree, tree[start]);
  tree[start] = root;
  return root;
}

int main() {
  int n, m;
  cin >> n >> m;
  int h1[n], h2[n];
  rep(i, n) {
    h1[i] = -1;
    h2[i] = 0;
  }
  int a, b, aroot, broot;
  rep(i, m) {
    cin >> a >> b;
    a--;
    b--;
    aroot = back(h1, a);
    broot = back(h1, b);
    if (aroot != broot)
      h1[aroot] = broot;
  }
  rep(i, n) h2[back(h1, i)]++;
  int mm = 0;
  rep(i, n) mm = max(mm, h2[i]);
  cout << mm;
  return 0;
}
Problem p02573 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define M 1000000007
vector<ll> adj[20000];
ll vis[20000];

void dfs(ll node, vector<ll> &v) {
  vis[node] = 1;
  v.push_back(node);
  for (ll child : adj[node]) {
    if (vis[child] == 0)
      dfs(child, v);
  }
}

int main() {

#ifndef ONLINE_JUDGE

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

#endif

  fastio;

  ll n, m, u, v;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    vis[i] = 0;
    adj[i].clear();
  }
  while (m--) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  ll res = INT_MIN;
  for (int i = 1; i <= n; ++i) {
    if (vis[i] == 0) {
      vector<ll> v;
      dfs(i, v);
      res = max(res, (ll)v.size());
      v.clear();
    }
  }

  cout << res;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define M 1000000007
vector<ll> adj[200006];
ll vis[200006];

void dfs(ll node, vector<ll> &v) {
  vis[node] = 1;
  v.push_back(node);
  for (ll child : adj[node]) {
    if (vis[child] == 0)
      dfs(child, v);
  }
}

int main() {

#ifndef ONLINE_JUDGE

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

#endif

  fastio;

  ll n, m, u, v;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    vis[i] = 0;
    adj[i].clear();
  }
  while (m--) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  ll res = INT_MIN;
  for (int i = 1; i <= n; ++i) {
    if (vis[i] == 0) {
      vector<ll> v;
      dfs(i, v);
      res = max(res, (ll)v.size());
      v.clear();
    }
  }

  cout << res;

  return 0;
}