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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cmath>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
typedef vector<ll> V;
typedef vector<V> VV;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INFLL = 1LL << 60;
const int INF = 1 << 28;
void solve(int a) { cout << (a ? "Yes" : "No") << endl; }
int main() {
  ll n;
  long long ans = 0LL;
  cin >> n;
  for (int i = 1; i <= sqrt(n) + 3; i++) {
    if (n % i == 0) {
      if (i == n % ((n / i) - 1)) {
        ans += ((n / i) - 1);
      }
      //	cout<<((n/i)-1)<<endl;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
typedef vector<ll> V;
typedef vector<V> VV;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INFLL = 1LL << 60;
const int INF = 1 << 28;
void solve(int a) { cout << (a ? "Yes" : "No") << endl; }
int main() {
  ll n;
  long long ans = 0LL;
  cin >> n;
  for (int i = 1; i <= sqrt(n) + 3; i++) {
    if (n % i == 0) {
      if (n / i > 1) {
        if (i == n % ((n / i) - 1)) {
          ans += ((n / i) - 1);
        }
      }
      //	cout<<((n/i)-1)<<endl;
    }
  }
  cout << ans << endl;
}
Problem p03050 (C++)

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

using namespace std;

int main() {
  long long n;
  cin >> n;

  long long res = 0;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0 && n / (n / i - 1) == i) {
      res += n / i - 1;
    }
  }

  cout << res << endl;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  long long n;
  cin >> n;

  long long res = 0;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0 && n / i - 1 > 0 && n / (n / i - 1) == i) {
      res += n / i - 1;
    }
  }

  cout << res << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9 + 7;

vector<ll> comdiv(ll x) {
  vector<ll> res;
  stack<ll> big;
  for (ll i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      res.push_back(i);
      big.push(x / i);
    }
  }
  while (!big.empty()) {
    res.push_back(big.top());
    big.pop();
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> li = comdiv(n);
  ll ans = 0;
  li.erase(li.begin());
  for (auto p : li) {
    p--;
    if ((n / p) == n % p)
      ans += p;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9 + 7;

vector<ll> comdiv(ll x) {
  vector<ll> res;
  stack<ll> big;
  for (ll i = 1; i * i <= x; i++) {
    if (x % i == 0) {
      res.push_back(i);
      big.push(x / i);
    }
  }
  while (!big.empty()) {
    res.push_back(big.top());
    big.pop();
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> li = comdiv(n);
  ll ans = 0;
  if (n == 1) {
    cout << ans << endl;
    return 0;
  }
  li.erase(li.begin());
  for (auto p : li) {
    p--;
    if ((n / p) == n % p)
      ans += p;
  }
  cout << ans << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)), t.end())
#define doublecout(a) cout << fixed << setprecision(10) << a << endl;
typedef long long ll;
using namespace std;
const ll mod = 1000000007, mod9 = 1000000009;
template <class T> inline T lcm(T a, T b) { return (a * b / __gcd(a, b)); }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, num = 1, ans = 0;
  cin >> n;
  while (num * num < n) {
    num++;
  }
  for (ll i = 1; i <= num; i++) {
    ll niko = n - i;
    if (n % (niko / i) == i) {
      ans += (niko / i);
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)), t.end())
#define doublecout(a) cout << fixed << setprecision(10) << a << endl;
typedef long long ll;
using namespace std;
const ll mod = 1000000007, mod9 = 1000000009;
template <class T> inline T lcm(T a, T b) { return (a * b / __gcd(a, b)); }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, num = 1, ans = 0;
  cin >> n;
  while (num * num < n) {
    num++;
  }
  for (ll i = 1; i <= num; i++) {
    ll niko = (n - i) / i;
    if (niko) {
      if (n % niko == i) {
        ans += niko;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <vector>
#define FORi(N) for (int i = 0; i < N; ++i)
#define FORj(N) for (int j = 0; j < N; ++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m, ll n) {
  if (n == 0)
    return abs(m);
  return (gcd(n, m % n));
}
void putYN(bool b) {
  if (b) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

int main() {
  ull N;
  cin >> N;
  ull num = 0;
  for (ull i = 1; i < sqrt(N); ++i) {
    if (N % i == 0) {
      // ull ii=N/i;
      if (N % (i - 1) == N / (i - 1))
        num += i - 1;
      // if(i>1)num+=i-1;
    }
  }
  cout << num << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <vector>
#define FORi(N) for (int i = 0; i < N; ++i)
#define FORj(N) for (int j = 0; j < N; ++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m, ll n) {
  if (n == 0)
    return abs(m);
  return (gcd(n, m % n));
}
void putYN(bool b) {
  if (b) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

int main() {
  ull N;
  cin >> N;
  ull num = 0;
  for (ull i = 1; i < sqrt(N); ++i) {
    if (N % i == 0) {
      ull ii = N / i;
      // if(ii>3)num+=ii-1;//,cout<<ii-1<<endl;
      if (N % (ii - 1) == N / (ii - 1))
        num += ii - 1;
      // if(i>1)num+=i-1;
    }
  }
  cout << num << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num) {
  register int ch, neg = 0;
  while (!isdigit(ch = getchar()))
    if (ch == '-')
      neg = 1;
  num = ch & 15;
  while (isdigit(ch = getchar()))
    num = num * 10 + (ch & 15);
  if (neg)
    num = -num;
}

ll N, ans = 0;
int sqrtN;

int main() {
  getint(N), sqrtN = (int)sqrt((double)N);
  for (register int i = 2; i <= sqrtN; i++)
    if (N % i == 0) {
      const ll j = N / i;
      if (N / (i - 1) == j)
        ans += i - 1;
      if (N / (j - 1) == i)
        ans += j - 1;
    }
  if (N / (N - 1) == 1)
    ans += N - 1;
  return printf("%lld\n", ans), 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num) {
  register int ch, neg = 0;
  while (!isdigit(ch = getchar()))
    if (ch == '-')
      neg = 1;
  num = ch & 15;
  while (isdigit(ch = getchar()))
    num = num * 10 + (ch & 15);
  if (neg)
    num = -num;
}

ll N, ans = 0;
int sqrtN;

int main() {
  getint(N), sqrtN = (int)sqrt((double)N);
  for (register int i = 2; i <= sqrtN; i++)
    if (N % i == 0) {
      const ll j = N / i;
      if (N / (i - 1) == j)
        ans += i - 1;
      if (N / (j - 1) == i)
        ans += j - 1;
    }
  if (N > 1 && N / (N - 1) == 1)
    ans += N - 1;
  return printf("%lld\n", ans), 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
// #define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int lcm(int x, int y) { return x / gcd(x, y) * y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n;
  cin >> n;

  ll sum = 0;
  for (ll r = 1; r * r <= n; r++) {
    if (n % r != 0)
      continue;
    ll m = n / r - 1;
    if ((n / m) == (n % m))
      sum += m;
  }

  cout << sum << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
// #define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int lcm(int x, int y) { return x / gcd(x, y) * y; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n;
  cin >> n;

  ll sum = 0;
  for (ll r = 1; r * r <= n; r++) {
    if (n % r != 0)
      continue;
    ll m = n / r - 1;
    if (m > 0 && (n / m) == (n % m))
      sum += m;
  }

  cout << sum << endl;

  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> mp;
#define inf 1e9

int main() {
  ll n;
  cin >> n;
  ll res = 0;
  for (ll i = 1; i * i <= n; i++) {
    if ((n - i) % i == 0) {
      ll tmp = (n - i) / i;
      if (n / tmp == n % tmp)
        res += tmp;
      // cout<<i<<' '<<(n-i)/i<<endl;
    }
  }
  cout << res << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> mp;
#define inf 1e9

int main() {
  ll n;
  cin >> n;
  ll res = 0;
  for (ll i = 1; i * i <= n; i++) {
    if ((n - i) % i == 0) {
      ll tmp = (n - i) / i;
      if (tmp == 0)
        break;
      if (n / tmp == n % tmp)
        res += tmp;
      // cout<<i<<' '<<(n-i)/i<<endl;
    }
  }
  cout << res << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"
#ifdef DEBUG
#define dump(v) cerr << "[" #v << ":" << (v) << "]" << endl;
#else
#define dump(v)
#endif
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
const ll MOD = (1e9 + 7);
const ll INF = (1e9 + 123456789);
const ll INFL = (INF * INF);
inline ll addm(ll a, ll b, ll m = MOD) { return ((a + b) % m); }
inline ll subm(ll a, ll b, ll m = MOD) { return (((a - b) % m + m) % m); }
inline ll mulm(ll a, ll b, ll m = MOD) { return ((a * b) % m); }
ll powm(ll a, ll b, ll m = MOD) {
  ll ret = (!b) ? 1 : powm(a, b / 2, m);
  return (!b) ? 1 : mulm(mulm(ret, ret, m), b % 2 ? a : 1, m);
}
ll inv(ll x, ll m = MOD) { return powm(x, m - 2, m); }

void solve() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll d = 1; d * d <= N; d++) {
    if (N % d == 0) {
      ll m = d - 1;
      if (m > 0 && N / m == N % m)
        ans += m;
      m = N / d - 1;
      if (N / m == N % m)
        ans += m;
    }
  }
  cout << ans << endl;
}

int main() {
  cin.sync_with_stdio(0);
  cin.tie(NULL);
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"
#ifdef DEBUG
#define dump(v) cerr << "[" #v << ":" << (v) << "]" << endl;
#else
#define dump(v)
#endif
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
const ll MOD = (1e9 + 7);
const ll INF = (1e9 + 123456789);
const ll INFL = (INF * INF);
inline ll addm(ll a, ll b, ll m = MOD) { return ((a + b) % m); }
inline ll subm(ll a, ll b, ll m = MOD) { return (((a - b) % m + m) % m); }
inline ll mulm(ll a, ll b, ll m = MOD) { return ((a * b) % m); }
ll powm(ll a, ll b, ll m = MOD) {
  ll ret = (!b) ? 1 : powm(a, b / 2, m);
  return (!b) ? 1 : mulm(mulm(ret, ret, m), b % 2 ? a : 1, m);
}
ll inv(ll x, ll m = MOD) { return powm(x, m - 2, m); }

void solve() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll d = 1; d * d <= N; d++) {
    if (N % d == 0) {
      ll m = d - 1;
      if (m > 0 && N / m == N % m)
        ans += m;
      m = N / d - 1;
      if (m > 0 && N / m == N % m)
        ans += m;
    }
  }
  cout << ans << endl;
}

int main() {
  cin.sync_with_stdio(0);
  cin.tie(NULL);
  solve();
  return 0;
}
Problem p03050 (C++)

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

signed main() {

  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      int t = n / i - 1;
      if (n / t == n % t)
        ans += t;
    }
  }
  cout << ans << endl;

  return 0;
}


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

signed main() {

  int n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      int t = n / i - 1;
      if (n / t == n % t)
        ans += t;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p03050 (C++)

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main() {
  ll N;
  cin >> N;

  ll sum = 0;
  for (ll i = 1; i * i <= N; ++i) {
    {
      ll a = N / i;
      ll b = N % i;
      if (a == b)
        sum += i;
    }
    {
      ll a = (N - i) / i;
      if (N / a == N % a)
        sum += a;
    }
  }
  cout << sum << endl;
  return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main() {
  ll N;
  cin >> N;

  ll sum = 0;
  for (ll i = 1; i * i <= N; ++i) {
    {
      ll a = N / i;
      ll b = N % i;
      if (a == b)
        sum += i;
    }
    {
      ll a = (N - i) / i;
      if (a != 0) {
        if (N / a == N % a)
          sum += a;
      }
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p03050 (C++)

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

constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
using ll = long long int;
using ull = unsigned long long int;

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      ll s = 0;
      s = N / i - 1;
      if (N / s == N % s)
        ans += s;
      if (i != 1 && i * i != N) {
        s = N / (N / i) - 1;
        if (N / s == N % s)
          ans += s;
      }
    }
  }
  cout << ans << endl;
}


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

constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
using ll = long long int;
using ull = unsigned long long int;

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      ll s = 0;
      s = N / i - 1;
      if (N / s == N % s)
        ans += s;
      if (i != 1 && i * i != N) {
        s = N / (N / i) - 1;
        if (N / s == N % s)
          ans += s;
      }
    }
  }
  cout << ans << endl;
}
Problem p03050 (C++)

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

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i, j, k) for (int i = j; i < k; i++)
#define f(n) fr(i, 0, n)
#define f1(n) fr(i, 1, n + 1)
#define ms(i) memset(i, 0, sizeof(i));
#define ms1(i) memset(i, -1, sizeof(i));
#define bg begin()
#define ed end()
#define pii pair<int, int>

int main() {
  ll n;
  while (cin >> n) {
    // ll ans = 0;
    // ll last= 0;
    set<ll> st;
    st.insert(n - 1);
    for (ll i = 2; i <= sqrt(n); i++) {
      if (n % i == 0) {
        st.insert(i - 1);
        st.insert(n / i - 1);
      }
    }
    ll ans = 0;
    for (auto i : st) {
      if (n / i == n % i) {
        ans += i;
      }
    }
    cout << ans << endl;
  }
}

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

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i, j, k) for (int i = j; i < k; i++)
#define f(n) fr(i, 0, n)
#define f1(n) fr(i, 1, n + 1)
#define ms(i) memset(i, 0, sizeof(i));
#define ms1(i) memset(i, -1, sizeof(i));
#define bg begin()
#define ed end()
#define pii pair<int, int>

int main() {
  ll n;
  while (cin >> n) {
    // ll ans = 0;
    // ll last= 0;
    set<ll> st;
    st.insert(n - 1);
    for (ll i = 2; i <= sqrt(n); i++) {
      if (n % i == 0) {
        st.insert(i - 1);
        st.insert(n / i - 1);
      }
    }
    ll ans = 0;
    for (auto i : st) {
      if (i == 0)
        continue;
      if (n / i == n % i) {
        ans += i;
      }
    }
    cout << ans << endl;
  }
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

vector<ll> divisor(ll n) {
  vector<ll> res{n};
  ll div = 2;
  while (div * div <= n) {
    if (n % div == 0) {
      res.emplace_back(div);
      if (div != 1 and div * div != n)
        res.emplace_back(n / div);
    }
    div++;
  }

  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;

  ll ans = 0;
  for (ll d : divisor(N)) {
    if (N / (d - 1) == N % (d - 1)) {
      ans += d - 1;
      // cout << d-1 << endl;
    }
  }

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

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template <class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

vector<ll> divisor(ll n) {
  vector<ll> res{n};
  ll div = 2;
  while (div * div <= n) {
    if (n % div == 0) {
      res.emplace_back(div);
      if (div != 1 and div * div != n)
        res.emplace_back(n / div);
    }
    div++;
  }

  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;

  ll ans = 0;
  for (ll d : divisor(N)) {
    if (d - 1 <= 0)
      continue;
    if (N / (d - 1) == N % (d - 1)) {
      ans += d - 1;
      // cout << d-1 << endl;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p03050 (C++)

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

int main() {
  long long N, cnt = 0;
  cin >> N;
  for (int a = 1; a <= N; a++) {
    if (N % a == 0 && N / a - 1 > a) {
      cnt += N / a - 1;
    }
  }
  cout << cnt << endl;
}

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

int main() {
  long long N, cnt = 0;
  cin >> N;
  for (int a = 1; a <= sqrt(N); a++) {
    if (N % a == 0 && N / a - 1 > a) {
      cnt += N / a - 1;
    }
  }
  cout << cnt << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
//
//  main.cpp
//  DivRem Number
//
//  Created by Dong Truong on 7/18/19.
//  Copyright © 2019 Dong Truong. All rights reserved.
//

#include <cmath>
#include <fstream>
#include <iostream>
#include <stdio.h>

using namespace std;
#define long long long

long n;
void nhap() {
  cin >> n;
  long i = sqrt(n), kq = 0;
  for (int i = 1; i <= sqrt(n); ++i)
    if (n % i == 0) {
      long m = n / i - 1;
      long k = (m + 1) * (n / m);
      if (k == n)
        kq += m;
    }
  cout << kq;
}
int main(int argc, const char *argv[]) {
  // freopen("a.inp","r",stdin);
  nhap();
  return 0;
}


Fixed submission:
//
//  main.cpp
//  DivRem Number
//
//  Created by Dong Truong on 7/18/19.
//  Copyright © 2019 Dong Truong. All rights reserved.
//

#include <cmath>
#include <fstream>
#include <iostream>
#include <stdio.h>

using namespace std;
#define long long long

long n;
void nhap() {
  cin >> n;
  long i = sqrt(n), kq = 0;
  for (int i = 1; i <= sqrt(n); ++i)
    if (n % i == 0) {
      long m = n / i - 1;
      if (m == 0)
        continue;
      long k = (m + 1) * (n / m);
      if (k == n)
        kq += m;
    }
  cout << kq;
}
int main(int argc, const char *argv[]) {
  // freopen("a.inp","r",stdin);
  nhap();
  return 0;
}
Problem p03050 (C++)

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

using namespace std;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  long long n;
  cin >> n;

  long long tot = 0;
  long long m;
  for (long long i = 2; i <= sqrt(n); ++i) {

    if (n % i == 0) {
      //    cout << "i is " << i << "\n";
      m = i - 1;
      //    cout << "m is " << m << "\n";
      if (n / m == n % m) {
        tot += m;
      }
      if (i == n / i)
        continue;
      m = n / i - 1;
      if (n / m == n % m) {
        tot += m;
      }
    }
  }
  m = n - 1;
  if (n % m == n / m) {
    tot += m;
  }

  cout << tot << "\n";

  return 0;
}

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

using namespace std;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  long long n;
  cin >> n;

  long long tot = 0;
  long long m;
  for (long long i = 2; i <= sqrt(n); ++i) {

    if (n % i == 0) {
      //    cout << "i is " << i << "\n";
      m = i - 1;
      //    cout << "m is " << m << "\n";
      if (n / m == n % m) {
        tot += m;
      }
      if (i == n / i)
        continue;
      m = n / i - 1;
      if (n / m == n % m) {
        tot += m;
      }
    }
  }
  m = n - 1;
  if (m > 0)
    if (n % m == n / m) {
      tot += m;
    }

  cout << tot << "\n";

  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
// priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 330030;
#define rep(i, begin, end)                                                     \
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod = 1e9 + 7;
using namespace std;

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

  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ll x, y;
      x = i - 1;
      y = n / i - 1;
      if (n / x == n % x)
        ans += x;
      if (n % y == n / y)
        ans += y;
    }
  }
  if (n / (n - 1) == 1)
    ans += n - 1;
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
// priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 330030;
#define rep(i, begin, end)                                                     \
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod = 1e9 + 7;
using namespace std;

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

  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ll x, y;
      x = i - 1;
      y = n / i - 1;
      if (n / x == n % x)
        ans += x;
      if (n % y == n / y)
        ans += y;
    }
  }
  if (n == 1) {
    cout << "0";
    return 0;
  }
  if (n / (n - 1) == 1)
    ans += n - 1;
  cout << ans;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0 && i != 1) {
      if (ll(n / (i - 1)) == n % (i - 1))
        ans += i - 1;
      if (i * i != n) {
        ll a = n / i;
        if (ll(n / (a - 1)) == n % (a - 1))
          ans += a - 1;
      }
    }
    if (i == 1) {
      ll a = n / i;
      if (ll(n / (a - 1)) == n % (a - 1))
        ans += a - 1;
    }
  }
  dunk(ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  ll ans = 0;
  if (n == 1) {
    dunk(0);
    return 0;
  }
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0 && i != 1) {
      if (ll(n / (i - 1)) == n % (i - 1))
        ans += i - 1;
      if (i * i != n) {
        ll a = n / i;
        if (ll(n / (a - 1)) == n % (a - 1))
          ans += a - 1;
      }
    }
    if (i == 1) {
      ll a = n / i;
      if (ll(n / (a - 1)) == n % (a - 1))
        ans += a - 1;
    }
  }
  dunk(ans);
  return 0;
}
Problem p03050 (C++)

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

long long int N, ans;

int main() {
  cin >> N;
  for (int i = 0; i <= sqrt(N); i++) {
    if (N % (i + 1) == 0) {
      if (i && (i + 1) * (N / i) == N)
        ans += i;
      if (i && i == N / i)
        continue;
      if ((N / (i + 1)) * (N / (N / (i + 1) - 1)) == N)
        ans += N / (i + 1) - 1;
    }
  }
  cout << ans << endl;
}

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

long long int N, ans;

int main() {
  cin >> N;
  for (int i = 0; i <= sqrt(N); i++) {
    if (N % (i + 1) == 0) {
      if (i && (i + 1) * (N / i) == N)
        ans += i;
      if (i && i == N / i)
        continue;
      if (N / (i + 1) - 1 && (N / (i + 1)) * (N / (N / (i + 1) - 1)) == N)
        ans += N / (i + 1) - 1;
    }
  }
  cout << ans << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <complex>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;

int main() {
  ll N;
  cin >> N;

  vector<ll> v;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0)
      v.push_back(i);
  }

  ll ans = 0;
  for (auto &e : v) {
    ll f = N / e - 1;
    if (N % f == N / f) {
      ans += f;
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <assert.h>
#include <complex>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;

int main() {
  ll N;
  cin >> N;

  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }

  vector<ll> v;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0)
      v.push_back(i);
  }

  ll ans = 0;
  for (auto &e : v) {
    ll f = N / e - 1;
    if (N % f == N / f) {
      ans += f;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03050 (C++)

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

int main(void) {
  unsigned long long N;
  unsigned long long ans = 0;
  std::cin >> N;

  for (unsigned long long i = 1; i <= N; i++) {
    if (N / i == N % i) {
      ans += i;
    }
  }

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


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

int main(void) {
  unsigned long long N;
  unsigned long long ans = 0;
  std::cin >> N;

  for (unsigned long long i = 1; i <= std::pow(N / 2, 0.6); i++) {
    unsigned long long t = N / i - 1;
    if (N / t == N % t) {
      ans += t;
    }
  }

  std::cout << ans << std::endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 1000000000
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
#define meM(y, a) memset(y, a, sizeof y)
#define sC(a) scanf("%d", &a)
#define alL(a) a.begin(), a.end()
#define prll(a, sz)                                                            \
  cout << a[0];                                                                \
  for (ll i = 1; i < sz; i++)                                                  \
    cout << " " << a[i];                                                       \
  cout << endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<ll, ll> pi;
typedef pair<ll, ll> pll;
// ll fx[]={0,0,1,-1};
// ll fy[]={1,-1,0,0};
// ll gx[]={0,0,1,1,1,-1,-1,-1};
// ll gy[]={1,-1,0,1,-1,0,1,-1};
const ll N = 100010;
ll n;
ll check(ll b) {
  if (b - 1 == 0)
    return 0;
  if (n % (b - 1) == 0)
    return 0;
  return b - 1;
}
int main() {
  IOS;
  cin >> n;
  ll res = 0;
  ll sq = sqrt(n);
  for (ll i = 1; i <= sq; i++) {

    ll b = (n / i) - 1;
    if (n % b == n / b) {
      res += b;
      //            cout<<"b = "<<b<<endl;
    }
  }
  cout << res << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 1000000000
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
#define meM(y, a) memset(y, a, sizeof y)
#define sC(a) scanf("%d", &a)
#define alL(a) a.begin(), a.end()
#define prll(a, sz)                                                            \
  cout << a[0];                                                                \
  for (ll i = 1; i < sz; i++)                                                  \
    cout << " " << a[i];                                                       \
  cout << endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<ll, ll> pi;
typedef pair<ll, ll> pll;
// ll fx[]={0,0,1,-1};
// ll fy[]={1,-1,0,0};
// ll gx[]={0,0,1,1,1,-1,-1,-1};
// ll gy[]={1,-1,0,1,-1,0,1,-1};
const ll N = 100010;
ll n;
ll check(ll b) {
  if (b - 1 == 0)
    return 0;
  if (n % (b - 1) == 0)
    return 0;
  return b - 1;
}
int main() {
  IOS;
  cin >> n;
  ll res = 0;
  ll sq = sqrt(n);
  for (ll i = 1; i <= sq; i++) {

    ll b = (n / i) - 1;
    if (b == 0)
      continue;
    if (n % b == n / b) {
      res += b;
      //            cout<<"b = "<<b<<endl;
    }
  }
  cout << res << endl;
}
Problem p03050 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n, ans;
int main() {
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    ll quotient, remainder;
    quotient = n / i;
    remainder = n % i;
    if (quotient == remainder)
      ans += i;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n, ans;
int main() {
  cin >> n;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ll m = n / i - 1;
      if (m > i)
        ans += m;
    }
  }
  cout << ans << endl;
}
Problem p03050 (C++)

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

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define REP2(i, d, n) for (int i = (d); i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define CLR(a) memset((a), 0, sizeof(a))
#define MCLR(a) memset((a), -1, sizeof(a))
#define RANGE(x, y, maxX, maxY)                                                \
  (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int, int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[] = {1, 0, -1, 0}, DY[] = {0, -1, 0, 1};

void solve(long long N) {
  LL ans = 0;
  for (LL i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      LL j = N / i - 1;

      if (i != 1 && i * i != N && N / (i - 1) == N % (i - 1)) {
        ans += (i - 1);
      }

      if (N / j == N % j) {
        ans += j;
      }
    }
  }

  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define REP2(i, d, n) for (int i = (d); i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define CLR(a) memset((a), 0, sizeof(a))
#define MCLR(a) memset((a), -1, sizeof(a))
#define RANGE(x, y, maxX, maxY)                                                \
  (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int, int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[] = {1, 0, -1, 0}, DY[] = {0, -1, 0, 1};

void solve(long long N) {
  if (N == 1) {
    cout << 0 << endl;
    return;
  }

  LL ans = 0;
  for (LL i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      LL j = N / i - 1;

      if (i != 1 && i * i != N && N / (i - 1) == N % (i - 1)) {
        ans += (i - 1);
      }

      if (N / j == N % j) {
        ans += j;
      }
    }
  }

  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long, long long>
#define all(a) a.begin(), a.end()
#define INF 10000000000000000
#define endl '\n'
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      int tmp = i - 1, tmp2 = n / i - 1;
      if (tmp != 0)
        if (n % tmp == n / tmp)
          ans += tmp;
      if (n % tmp2 == n / tmp2)
        ans += tmp2;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long, long long>
#define all(a) a.begin(), a.end()
#define INF 10000000000000000
#define endl '\n'
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      int tmp = i - 1, tmp2 = n / i - 1;
      if (tmp != 0)
        if (n % tmp == n / tmp)
          ans += tmp;
      if (tmp2 != 0)
        if (n % tmp2 == n / tmp2)
          ans += tmp2;
    }
  }
  cout << ans << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

vector<ll> fac;

void fact(ll n) {
  for (ll x = 1; x * x <= n; x++) {
    if (n % x == 0) {
      fac.push_back(x);

      if (n / x != x)
        fac.push_back(n / x);
    }
  }
  sort(fac.begin(), fac.end(), greater<ll>());
}

int main() {
  ll n, ans = 0;
  cin >> n;
  fact(n);

  for (int i = 0; i < n; i++) {
    ll m = fac[i] - 1;
    if (n / m == n % m)
      ans += m;
    else
      break;
  }

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

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

vector<ll> fac;

void fact(ll n) {
  for (ll x = 1; x * x <= n; x++) {
    if (n % x == 0) {
      fac.push_back(x);

      if (n / x != x)
        fac.push_back(n / x);
    }
  }
  sort(fac.begin(), fac.end(), greater<ll>());
}

int main() {
  ll n, ans = 0;
  cin >> n;
  fact(n);

  for (int i = 0; i < n; i++) {
    ll m = fac[i] - 1;
    if (m == 0)
      continue;
    if (n / m == n % m)
      ans += m;
    else
      break;
  }

  cout << ans << endl;
  return 0;
}
Problem p03050 (C++)

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

int main() {
  long long N;
  cin >> N;

  long long max = floor(sqrt(N * 1.0));
  long long count = 0;

  for (int i = 1; i < max + 1; ++i) {
    long long a = N / i - 1;
    if ((N - i) % i == 0 && N / a == N % a)
      count += (N - i) / i;
  }

  cout << count << endl;
}

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

int main() {
  long long N;
  cin >> N;

  long long max = floor(sqrt(N * 1.0));
  long long count = 0;

  for (int i = 1; i < max + 1; ++i) {
    long long a = N / i - 1;
    if (a && (N - i) % i == 0 && N / a == N % a)
      count += (N - i) / i;
  }

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

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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL << 60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
        x = n/m
        m+x = n
}*/

signed main() {
  int n;
  cin >> n;

  int ans = 0;
  rep(i, 1, n / i + 1) {
    if ((n - i) % i == 0) {
      int t = (n - i) / i;
      if (n / t == n % t)
        ans += (n - i) / i;
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL << 60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
        x = n/m
        m+x = n
}*/

signed main() {
  int n;
  cin >> n;

  int ans = 0;
  rep(i, 1, n / i + 1) {
    if ((n - i) % i == 0) {
      int t = (n - i) / i;
      if (t == 0)
        continue;
      if (n / t == n % t)
        ans += (n - i) / i;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, N) for (i = 0; i < N; i++)
#define MAX_I INT_MAX      // 1e9
#define MIN_I INT_MIN      //-1e9
#define MAX_UI UINT_MAX    // 1e9
#define MAX_LL LLONG_MAX   // 1e18
#define MIN_LL LLONG_MIN   //-1e18
#define MAX_ULL ULLONG_MAX // 1e19
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<char, char> PCC;
typedef pair<ll, ll> PLL;
typedef pair<char, int> PCI;
typedef pair<int, char> PIC;
typedef pair<ll, int> PLI;
typedef pair<int, ll> PIL;
typedef pair<ll, char> PLC;
typedef pair<char, ll> PCL;
int M = 10;
map<ll, vector<ll>> memo;

int main(void) {
  ll N;
  cin >> N;
  ll sum = 0;
  for (int i = 1; i <= sqrt(N); i++) {
    if (N % i != 0)
      continue;
    ll n = N / i - 1;
    ll m = i - 1;
    if (N / n == N % n)
      sum += n;
    if (m != 0 && n != m && N / m == N % m)
      sum += m;
  }
  cout << sum << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, N) for (i = 0; i < N; i++)
#define MAX_I INT_MAX      // 1e9
#define MIN_I INT_MIN      //-1e9
#define MAX_UI UINT_MAX    // 1e9
#define MAX_LL LLONG_MAX   // 1e18
#define MIN_LL LLONG_MIN   //-1e18
#define MAX_ULL ULLONG_MAX // 1e19
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<char, char> PCC;
typedef pair<ll, ll> PLL;
typedef pair<char, int> PCI;
typedef pair<int, char> PIC;
typedef pair<ll, int> PLI;
typedef pair<int, ll> PIL;
typedef pair<ll, char> PLC;
typedef pair<char, ll> PCL;
int M = 10;
map<ll, vector<ll>> memo;

int main(void) {
  ll N;
  cin >> N;
  ll sum = 0;
  for (int i = 1; i <= sqrt(N); i++) {
    if (N % i != 0)
      continue;
    ll n = N / i - 1;
    ll m = i - 1;
    if (n != 0 && N / n == N % n)
      sum += n;
    if (m != 0 && n != m && N / m == N % m)
      sum += m;
  }
  cout << sum << endl;
  return 0;
}