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

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  ll res = 0;
  cin >> n;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    ll j = n / i - 1;
    ll k = i - 1;
    if (k != 0 && n / k == n % k)
      res += k;
    if (n / j == n % j)
      res += j;
  }
  cout << res << endl;

  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  ll res = 0;
  cin >> n;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    ll j = n / i - 1;
    ll k = i - 1;
    if (k != 0 && n / k == n % k)
      res += k;
    if (j != 0 && n / j == n % j)
      res += j;
  }
  cout << res << endl;

  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ROUNDUP(divisor, dividend) (divisor + (dividend - 1)) / dividend
long long int n, ans = 0;
std::vector<long long int> v;

std::vector<long long int> enum_div(long long int n) {
  std::vector<long long int> ret;
  for (long long int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i != 1 && i * i != n)
        ret.push_back(n / i);
    }
  }
  ret.push_back(n);
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  cin >> n;
  v = enum_div(n);
  for (long long int i = 1; i < v.size(); i++) {
    if (floor(n / (v[i] - 1)) == n % (v[i] - 1))
      ans += (v[i] - 1);
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ROUNDUP(divisor, dividend) (divisor + (dividend - 1)) / dividend
long long int n, ans = 0;
std::vector<long long int> v;

std::vector<long long int> enum_div(long long int n) {
  std::vector<long long int> ret;
  for (long long int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i != 1 && i * i != n)
        ret.push_back(n / i);
    }
  }
  ret.push_back(n);
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {
  cin >> n;
  v = enum_div(n);
  for (long long int i = 0; i < v.size(); i++) {
    if (v[i] - 1 == 0)
      continue;
    if (floor(n / (v[i] - 1)) == n % (v[i] - 1))
      ans += (v[i] - 1);
  }
  cout << ans << endl;
}
Problem p03050 (C++)

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

void solve() {
  long long n;
  scanf("%lld", &n);
  long long ans = 0;
  for (long long i = 1; i * i <= n; ++i) {
    if (n % i)
      continue;
    if (i > 1 && n % (i - 1) == n / (i - 1))
      ans += i - 1;
    if (n % (n / i - 1) == n / (n / i - 1))
      ans += n / i - 1;
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; // scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

void solve() {
  long long n;
  scanf("%lld", &n);
  long long ans = 0;
  for (long long i = 1; i * i <= n; ++i) {
    if (n % i)
      continue;
    if (i > 1 && n % (i - 1) == n / (i - 1))
      ans += i - 1;
    if (n / i > 1 && n % (n / i - 1) == n / (n / i - 1))
      ans += n / i - 1;
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; // scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
Problem p03050 (C++)

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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll answer = 0;
  for (ll i = 1; i * i <= n; ++i) {
    const ll m = (n - i) / i;
    if (n % m == n / m) {
      answer += m;
    }
  }
  cout << answer << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll answer = 0;
  for (ll i = 1; i * i <= n; ++i) {
    const ll m = (n - i) / i;
    if (m != 0 && n % m == n / m) {
      answer += m;
    }
  }
  cout << answer << endl;
  return 0;
}
Problem p03050 (C++)

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

ll solve() {
  ll N, ans, m2;
  ans = 0;
  cin >> N;
  m2 = 0;
  /*
  for (ll m = 2; m <= N; ++m) {
      if (N > m * m) continue;
      if (N / m == N % m) {
          m2 = N / m;
          cout << N << " = " << m << " * " << m2 << " + " << m2 << endl;
          //break;
      }
  }
  if (m2 == 0) {
      return 0;
  }
  */
  m2 = (ll)pow(N, 0.5) + 1;

  for (ll m = 1; m <= m2; ++m) {
    if (N % m == 0) {
      ll b = N / m - 1;
      if (N / b == N % b) {
        ans += b;
      }
    }
  }
  return ans;
}

int main() { cout << solve() << endl; }


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

ll solve() {
  ll N, ans, m2;
  ans = 0;
  cin >> N;
  m2 = 0;
  /*
  for (ll m = 2; m <= N; ++m) {
      if (N > m * m) continue;
      if (N / m == N % m) {
          m2 = N / m;
          cout << N << " = " << m << " * " << m2 << " + " << m2 << endl;
          //break;
      }
  }
  if (m2 == 0) {
      return 0;
  }
  */
  m2 = (ll)pow(N, 0.5) + 1;

  for (ll m = 1; m <= m2; ++m) {
    if (N % m == 0) {
      ll b = N / m - 1;
      if (b != 0) {
        if (N / b == N % b) {
          ans += b;
        }
      }
    }
  }
  return ans;
}

int main() { cout << solve() << endl; }
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int MAXN = 1e4 + 5, MAXM = 2e5 + 5, BOUND = 1e7, MOD = 1e9 + 7,
          INF = 0x3f3f3f3f, base = 10000;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-9;
#define mid l + ((r - l) >> 1)
#define lson o << 1, l, m
#define rson o << 1 | 1, m + 1, r
#define lc(x) ch[x][0]
#define pii pair<int, int>
#define vi vector<int>
#define RR register int
#define rc(x) ch[x][1]
#define rep(i, a, b) for (RR i = (a); i <= (b); ++i)
#define random(a, b) ((a) + rand() % ((b) - (a) + 1))
ll n, ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  ll m;
  rep(i, 2, sqrt(n)) {
    if (n % i == 0) {
      m = i - 1;
      if (n / m == n / i)
        ans += m;
      ll tmp = n / i;
      if (tmp == i)
        continue;
      m = tmp - 1;
      if (n / m == n / tmp)
        ans += m;
    }
  }
  if (n / (n - 1) == 1)
    ans += n - 1;
  cout << ans << '\n';
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int MAXN = 1e4 + 5, MAXM = 2e5 + 5, BOUND = 1e7, MOD = 1e9 + 7,
          INF = 0x3f3f3f3f, base = 10000;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-9;
#define mid l + ((r - l) >> 1)
#define lson o << 1, l, m
#define rson o << 1 | 1, m + 1, r
#define lc(x) ch[x][0]
#define pii pair<int, int>
#define vi vector<int>
#define RR register int
#define rc(x) ch[x][1]
#define rep(i, a, b) for (RR i = (a); i <= (b); ++i)
#define random(a, b) ((a) + rand() % ((b) - (a) + 1))
ll n, ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  ll m;
  rep(i, 2, sqrt(n)) {
    if (n % i == 0) {
      m = i - 1;
      if (n / m == n / i)
        ans += m;
      ll tmp = n / i;
      if (tmp == i)
        continue;
      m = tmp - 1;
      if (n / m == n / tmp)
        ans += m;
    }
  }
  if (n > 1 && n / (n - 1) == 1)
    ans += n - 1;
  cout << ans << '\n';
  return 0;
}
Problem p03050 (C++)

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

using namespace std;

typedef long long ll;
typedef vector<ll> VL;
typedef pair<ll, ll> PLL;
#define pb push_back
#define F first
#define S second
#define fr(i, x, y) for (ll i = x; i < y; i++)
#define frr(i, x, y) for (ll i = x - 1; i >= y; i--)
#define inf 10000000000000000
const ll mod = 998244353;

void solve() {
  ll n;
  cin >> n;
  ll sum = 0;
  fr(i, 1, n + 1) {
    if (n / i == (n % i)) {
      sum += i;
    }
  }
  cout << sum << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> VL;
typedef pair<ll, ll> PLL;
#define pb push_back
#define F first
#define S second
#define fr(i, x, y) for (ll i = x; i < y; i++)
#define frr(i, x, y) for (ll i = x - 1; i >= y; i--)
#define inf 10000000000000000
const ll mod = 998244353;

void solve() {
  ll n;
  cin >> n;
  ll sum = 0;
  for (ll i = 1; i * i <= n; i++) {
    if ((n % i == 0)) {
      ll x = n / i;
      if (x - 1 > i) {
        sum += (x - 1);
      }
      // x--;
      // sum+=x;
    }
  }
  cout << sum << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

  auto result = 0ll;
  for (auto i = 1ll; i * i <= N; ++i) {
    if ((N - i) % i == 0 && (N % ((N - i) / i)) == i) {
      result += (N - i) / i;
    }
  }

  cout << result << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

  auto result = 0ll;
  for (auto i = 1ll; i * i <= N; ++i) {
    if ((N - i) > 0 && (N - i) % i == 0 && (N % ((N - i) / i)) == i) {
      result += (N - i) / i;
    }
  }

  cout << result << endl;

  return 0;
}
Problem p03050 (C++)

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template <typename T> vector<T> make_v(size_t a, T b) {
  return vector<T>(a, b);
}
template <typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

bool check(ll n, ll x) { return n % x == n / x; }

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


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template <typename T> vector<T> make_v(size_t a, T b) {
  return vector<T>(a, b);
}
template <typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

bool check(ll n, ll x) { return n % x == n / x; }

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

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define lint long long
#define ll long long
#define pq priority_queue
long long INF = 1e10;
#define pii pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
/******************************define*********************************/

/*****************************functions********************************/

/****************************main function*****************************/
int main(void) {
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll n = 1; n <= sqrt(N); n++) {
    if (N % n == 0) {
      if (n != 1) {
        if (N / (n - 1) == N % (n - 1))
          ans += n - 1;
      }
      if (N * n / (N - n) == N % (N / n - 1))
        ans += N / n - 1;
    }
  }

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

Fixed submission:

#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define lint long long
#define ll long long
#define pq priority_queue
long long INF = 1e10;
#define pii pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
/******************************define*********************************/

/*****************************functions********************************/

/****************************main function*****************************/
int main(void) {
  ll N;
  cin >> N;
  ll ans = 0;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (ll n = 1; n <= sqrt(N); n++) {
    if (N % n == 0) {
      if (n != 1) {
        if (N / (n - 1) == N % (n - 1))
          ans += n - 1;
      }
      if (N * n / (N - n) == N % (N / n - 1))
        ans += N / n - 1;
    }
  }

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

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template <typename T> vector<T> make_v(size_t a, T b) {
  return vector<T>(a, b);
}
template <typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

bool check(ll n, ll x) { return n % x == n / x; }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (check(n, i)) {
        ans += i;
      }
      ll x = n / i - 1;
      if (x != i && check(n, x)) {
        ans += x;
      }
    }
  }
  cout << ans << endl;
  /*
  for (ll i = 1; i <= n; i++) {
      if (n % i == n / i) {
          cout << n / i << " " << i << endl;
          cout << n / (i + 1) * i + n / (i + 1) << endl;
          ans -= i;
      }
  }
  dump(ans);
  //*/
  return 0;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template <typename T> vector<T> make_v(size_t a, T b) {
  return vector<T>(a, b);
}
template <typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

bool check(ll n, ll x) {
  if (x == 0)
    return false;
  return n % x == n / x;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (check(n, i)) {
        ans += i;
      }
      ll x = n / i - 1;
      if (x != i && check(n, x)) {
        ans += x;
      }
    }
  }
  cout << ans << endl;
  /*
  for (ll i = 1; i <= n; i++) {
      if (n % i == n / i) {
          cout << n / i << " " << i << endl;
          cout << n / (i + 1) * i + n / (i + 1) << endl;
          ans -= i;
      }
  }
  dump(ans);
  //*/
  return 0;
}
Problem p03050 (C++)

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

typedef long long ll;

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

  sum = (ll)0;
  for (ll m = 1; m * m <= N; m++) {
    ll t = N / m - 1;
    if (N / t == N % t) {
      sum += t;
    }
  }

  cout << sum << endl;
  return 0;
}

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

typedef long long ll;

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

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

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

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

typedef long long ll;
typedef pair<ll, ll> P;

vector<P> prifac(ll n) {
  vector<P> ret;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        cnt++;
        n /= i;
      }
      ret.push_back(P(i, cnt));
    }
  }
  if (n > 1)
    ret.push_back(P(n, 1));
  return ret;
}

vector<ll> divisors(ll n) {
  vector<P> vec = prifac(n);
  vector<ll> ret;
  ret.push_back(1);
  for (int i = 0; i < vec.size(); i++) {
    P p = vec[i];
    int m = ret.size();
    for (int j = 0; j < m; j++) {
      ll t = ret[j];
      for (int k = 0; k < p.second; k++) {
        t *= p.first;
        ret.push_back(t);
      }
    }
  }
  return ret;
}

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

  vector<ll> vec = divisors(n);
  ll ret = 0;
  for (int i = 0; i < vec.size(); i++) {
    if (n / vec[i] + 2 <= vec[i])
      ret += vec[i] - 1;
  }
  cout << ret << endl;
}


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

typedef long long ll;
typedef pair<ll, ll> P;

vector<P> prifac(ll n) {
  vector<P> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int cnt = 0;
      while (n % i == 0) {
        cnt++;
        n /= i;
      }
      ret.push_back(P(i, cnt));
    }
  }
  if (n > 1)
    ret.push_back(P(n, 1));
  return ret;
}

vector<ll> divisors(ll n) {
  vector<P> vec = prifac(n);
  vector<ll> ret;
  ret.push_back(1);
  for (int i = 0; i < vec.size(); i++) {
    P p = vec[i];
    int m = ret.size();
    for (int j = 0; j < m; j++) {
      ll t = ret[j];
      for (int k = 0; k < p.second; k++) {
        t *= p.first;
        ret.push_back(t);
      }
    }
  }
  return ret;
}

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

  vector<ll> vec = divisors(n);
  ll ret = 0;
  for (int i = 0; i < vec.size(); i++) {
    if (n / vec[i] + 2 <= vec[i])
      ret += vec[i] - 1;
  }
  cout << ret << endl;
}
Problem p03050 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
lim = int(N**0.5) + 1
ans = 0
for i in range(1, lim + 1):
    m = N // i
    quotient = N // m
    while m != 0:
        remainder = N % m
        if N // m != quotient or remainder > i:
            break
        if quotient == remainder:
            ans += m
            break
        m -= 1
print(ans)


Fixed submission:
N = int(input())
lim = int(N**0.5)
ans = 0
for i in range(1, lim + 1):
    m = N // i
    quotient = N // m
    while m != 0:
        remainder = N % m
        if N // m != quotient or remainder > i:
            break
        if quotient == remainder:
            ans += m
            break
        m -= 1
print(ans)
Problem p03050 (Python)

Buggy submission (status: Runtime Error):
import math

N = int(input())
ans = 0
for i in range(1, int(math.sqrt(N)) + 2):
    if N % i:
        continue
    m = N // i - 1
    if N // m == N % m:
        ans += m
print(ans)


Fixed submission:
import math

N = int(input())
ans = 0
for i in range(1, int(math.sqrt(N)) + 2):
    if N % i:
        continue
    m = N // i - 1
    if m <= 0:
        continue
    if N // m == N % m:
        ans += m
print(ans)
Problem p03050 (Python)

Buggy submission (status: Runtime Error):
n = int(input())

ans = 0

for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
        m = n // i - 1
        if n % m == n // m:
            ans += m

print(ans)


Fixed submission:
n = int(input())

ans = 0

for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
        m = n // i - 1
        if m > 0 and n % m == n // m:
            ans += m

print(ans)
Problem p03050 (C++)

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

#if __has_include("print.hpp")
#include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;

vector<ll> enumeration(ll n) {
  vector<ll> result;
  for (ll i = 1; i <= pow(n, 0.5) + 1; i++) {
    if (n % i == 0) {
      result.push_back(i);
      result.push_back(n / i);
    }
  }
  sort(ALL(result));
  return result;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<ll> yakusu = enumeration(n);
  ll res = 0;
  yakusu.erase(yakusu.begin());
  for (auto a : yakusu) {
    if (n % (a - 1) == n / (a - 1))
      res += a - 1;
  }
  cout << res << endl;
}


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

#if __has_include("print.hpp")
#include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;

vector<ll> enumeration(ll n) {
  vector<ll> result;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      result.push_back(i);
      result.push_back(n / i);
    }
  }
  sort(ALL(result));
  return result;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<ll> yakusu = enumeration(n);
  ll res = 0;
  yakusu.erase(yakusu.begin());
  for (auto a : yakusu) {
    if (n % (a - 1) == n / (a - 1))
      res += a - 1;
  }
  cout << res << endl;
}
Problem p03050 (C++)

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

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

  long long ans = 0;
  for (long long i = 1; i <= std::sqrt(n); ++i) {
    if (0 == n % i) {
      long long divisor = n / i - 1;
      if (n / divisor == n % divisor) {
        ans += divisor;
      }
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


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

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

  long long ans = 0;
  for (long long i = 1; i <= std::sqrt(n); ++i) {
    if (0 == n % i) {
      long long divisor = n / i - 1;
      if (0 != divisor && n / divisor == n % divisor) {
        ans += divisor;
      }
    }
  }

  std::cout << ans << std::endl;

  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
typedef pair<int, int> P;
// typedef long long int ll;

int ans;

signed main() {

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


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X)                                                                 \
  {}
#define ARDEB(i, X)                                                            \
  {}
#define END                                                                    \
  {}
#endif
typedef pair<int, int> P;
// typedef long long int ll;

int ans;

signed main() {

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FLASH                                                                  \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define FILEIO                                                                 \
  freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin);                  \
  freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);

using namespace std;

int n, m;

signed main() {

  FLASH

  cin >> n;
  int ans = n - 1;
  for (int i = 2; (i - 1) * (i - 1) <= n; i++) {
    if (n % i != 0)
      continue;
    int x = n % (i - 1);

    if (n == i * x)
      ans += i - 1;
    if (i * i == n)
      continue;

    x = n % (n / i - 1);
    if (n == (n / i) * x)
      ans += n / i - 1;
  }

  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
#define FLASH                                                                  \
  cin.tie(0);                                                                  \
  cout.tie(0);                                                                 \
  ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i, a, b) for (int i = a; i < b; i++)
#define mod 1000000007
#define FILEIO                                                                 \
  freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin);                  \
  freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);

using namespace std;

int n, m;

signed main() {

  FLASH

  cin >> n;
  int ans = n - 1;
  if (n == 2)
    return cout << 0, 0;

  for (int i = 2; i * i <= n; i++) {
    if (n % i != 0)
      continue;
    int x = n % (i - 1);

    if (n == i * x)
      ans += i - 1;
    if (i * i == n)
      continue;

    x = n % (n / i - 1);
    if (n == (n / i) * x)
      ans += n / i - 1;
  }

  cout << ans;
}
Problem p03050 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;
ll n;

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

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;
ll n;

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

Buggy submission (status: Runtime Error):
n = int(input())

ans = 0
for i in range(1, int(n**0.5) + 1):
    if n % i == 0 and n // (i - 1) == n % (i - 1):
        ans += i - 1
    m = n // i - 1
    if m > 0 and n % i == 0 and n // m == n % m:
        ans += m
print(ans)


Fixed submission:
n = int(input())

ans = 0
for i in range(1, int(n**0.5) + 1):
    if i > 1 and n % i == 0 and n // (i - 1) == n % (i - 1):
        ans += i - 1
    m = n // i - 1
    if m > 0 and n % i == 0 and n // m == n % m:
        ans += m
print(ans)
Problem p03050 (Python)

Buggy submission (status: Runtime Error):
n = int(input())

ans = 0
for i in range(1, int(n**0.5) + 1):
    m = n // i - 1
    if n % i == 0 and n // m == n % m:
        ans += m
print(ans)


Fixed submission:
n = int(input())

ans = 0
for i in range(1, int(n**0.5) + 1):
    m = n // i - 1
    if m > 0 and n % i == 0 and n // m == n % m:
        ans += m
print(ans)
Problem p03050 (C++)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// const ll mod = 1000000007;
set<ll> good;

int main() {
  // cout.precision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll a = 1; a * a <= N; a++) {
    ll delta = N - a;
    if (delta % a != 0)
      continue;
    ll m = delta / a;
    if ((N / m) == (N % m))
      ans += m;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// const ll mod = 1000000007;
set<ll> good;

int main() {
  // cout.precision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll a = 1; a * a <= N; a++) {
    ll delta = N - a;
    if (delta % a != 0)
      continue;
    ll m = delta / a;
    if (m == 0)
      continue;
    if ((N / m) == (N % m))
      ans += m;
  }
  cout << ans << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= n; ++i) {
    if (n % i)
      continue;
    ll tmp = n / (i + 1) + 1;
    ll up = n / i;
    if (up - 1 >= tmp)
      ans += up - 1;
    else
      break;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i <= sqrt(n); ++i) {
    if (n % i)
      continue;
    ll tmp = n / (i + 1) + 1;
    ll up = n / i;
    if (up - 1 >= tmp)
      ans += up - 1;
    else
      break;
  }
  cout << ans << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll(i) = 0; i < (n); ++(i))
#define print(a) cout << (a) << endl

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll(i) = 0; i < (n); ++(i))
#define print(a) cout << (a) << endl

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

Buggy submission (status: Runtime Error):
n = int(input())

ans = 0
for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
        m = n // i - 1
        if n // m == n % m:
            ans += m

print(ans)


Fixed submission:
n = int(input())

ans = 0
for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
        m = n // i - 1
        if m != 0 and n // m == n % m:
            ans += m

print(ans)
Problem p03050 (C++)

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

void solve(long long N) {
  // cout << N << endl;
  ll ans = 0;
  for (ll x = 1; x < N; ++x) {
    if ((N - x) % x == 0 && x < (N - x) / x) {
      // cout << x << endl;
      ans += (N - x) / x;
    }
  }
  cout << ans << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


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

void solve(long long N) {
  // cout << N << endl;
  ll ans = 0;
  for (ll x = 1; x * x < N - x; ++x) {
    if ((N - x) % x == 0) {
      // cout << x << endl;
      ans += (N - x) / x;
    }
  }
  cout << ans << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}
Problem p03050 (C++)

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

using namespace std;

typedef long long ll;

int main() {
  ll n;
  ll cnt = 0;

  // vector<ll> ans;

  cin >> n;

  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ll v = n / i - 1;
      if (v > i)
        cnt += v;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
  ll n;
  ll cnt = 0;

  // vector<ll> ans;

  cin >> n;

  for (int i = 1; i <= 1000000; i++) {
    if (n % i == 0) {
      ll v = n / i - 1;
      if (v > i)
        cnt += v;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\n'
#define sz(x) (int)x.size()
#define all(a) (a.begin(), a.end())
#define ff first
#define ss second
#define pii pair<int, int>
#define lcm(a, b) (a * b) / __gcd(a, b)
using namespace std;

inline void solve() {
  int n, sum = 0;
  cin >> n;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      int k = n / i - 1;
      if (n / k == n % k)
        sum += k;
    }
  }
  cout << sum << endl;
}

signed main() {
  int n = 1; // cin>>n;
  while (n--)
    solve();
  return 0;
}


Fixed submission:
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\n'
#define sz(x) (int)x.size()
#define all(a) (a.begin(), a.end())
#define ff first
#define ss second
#define pii pair<int, int>
#define lcm(a, b) (a * b) / __gcd(a, b)
using namespace std;

inline void solve() {
  int n, sum = 0;
  cin >> n;
  if (n > 2)
    sum = n - 1;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      int k = n / i - 1;
      if (n / k == n % k)
        sum += k;
    }
  }
  cout << sum << endl;
}

signed main() {
  int n = 1; // cin>>n;
  while (n--)
    solve();
  return 0;
}
Problem p03050 (C++)

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

class range {
private:
  struct I {
    int x;
    int operator*() { return x; }
    bool operator!=(I &lhs) { return x < lhs.x; }
    void operator++() { ++x; }
  };
  I i, n;

public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  I &begin() { return i; }
  I &end() { return n; }
};

int main() {
  ll N;
  cin >> N;
  ll res = 0;
  for (ll k = 1; k <= N; ++k) {
    if (k * k > N)
      break;

    ll mhi = N / k;
    ll lo = 1, hi = mhi;
    while (hi - lo > 1) {
      ll mid = (lo + hi) / 2;
      if (N / mid != k)
        lo = mid;
      else
        hi = mid;
    }
    ll mlo = hi;

    ll llo = (N - k + (mhi - 1)) / mhi;
    ll lhi = (N - k) / mlo;

    for (ll el = llo; el <= lhi; ++el) {
      if ((N - k) % el != 0)
        continue;
      ll m = (N - k) / el;
      // assert(N % m == k);
      // assert(N / m == k);
      if (N % m == k && N / m == k)
        res += m;
    }
  }
  cout << res << endl;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <set>
#include <sstream>
#include <vector>
using namespace std;
using ll = long long;

class range {
private:
  struct I {
    int x;
    int operator*() { return x; }
    bool operator!=(I &lhs) { return x < lhs.x; }
    void operator++() { ++x; }
  };
  I i, n;

public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  I &begin() { return i; }
  I &end() { return n; }
};

int main() {
  ll N;
  cin >> N;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }

  ll res = 0;
  for (ll k = 1; k <= N; ++k) {
    if (k * k > N)
      break;

    ll mhi = N / k;
    ll lo = 1, hi = mhi;
    while (hi - lo > 1) {
      ll mid = (lo + hi) / 2;
      if (N / mid != k)
        lo = mid;
      else
        hi = mid;
    }
    ll mlo = hi;

    ll llo = (N - k + (mhi - 1)) / mhi;
    ll lhi = (N - k) / mlo;

    for (ll el = llo; el <= lhi; ++el) {
      if ((N - k) % el != 0)
        continue;
      ll m = (N - k) / el;
      // assert(N % m == k);
      // assert(N / m == k);
      if (N % m == k && N / m == k)
        res += m;
    }
  }
  cout << res << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

#define MP make_pair
#define EACH(i, c) for (auto i : c)
#define SORT(c) sort((c).begin(), (c).end())

#define ALL(a) (a).begin(), (a).end()

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

  LL N;
  cin >> N;

  LL ret = 0;
  LL a = sqrt(N);
  FOR(i, 1, a + 1) {
    LL tmp = (N - i) / i;
    if (N / tmp == N % tmp)
      ret += tmp;
    // if(ret == 2499686339916LL)
    // cerr << i << endl;
  }

  cout << ret << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

#define MP make_pair
#define EACH(i, c) for (auto i : c)
#define SORT(c) sort((c).begin(), (c).end())

#define ALL(a) (a).begin(), (a).end()

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

  LL N;
  cin >> N;

  LL ret = 0;
  LL a = sqrt(N);
  FOR(i, 1, a + 1) {
    LL tmp = (N - i) / i;
    if (tmp && N / tmp == N % tmp)
      ret += tmp;
    // if(ret == 2499686339916LL)
    // cerr << i << endl;
  }

  cout << ret << endl;

  return 0;
}
Problem p03050 (C++)

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

int main() {
  int64_t N, ans = 0;
  cin >> N;
  for (int x = 1; x <= sqrt(N); x++) {
    if (N % x == 0) {
      int64_t a = (N / x) - 1;
      if (N / a == N % a)
        ans += a;
    }
  }
  cout << ans << endl;
}


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

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

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

using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  ll sum = 0;

  ll i = 1;
  for (; i * i < n; i++) {
    if (n / i == n % i)
      sum += i;
  }

  for (; i >= 1; i--) {
    ll tmp = (n - i);
    ll m = tmp / i;
    if (tmp % i)
      continue;
    if (n / m == n % m)
      sum += m;
  }
  cout << sum << endl;
}

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

using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  ll sum = 0;

  ll i = 1;
  for (; i * i < n; i++) {
    if (n / i == n % i)
      sum += i;
  }

  for (; i >= 1; i--) {
    ll tmp = (n - i);
    if (tmp == 0)
      continue;
    ll m = tmp / i;
    if (tmp % i)
      continue;
    if (n / m == n % m)
      sum += m;
  }
  cout << sum << endl;
}
Problem p03050 (C++)

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

int main() {
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  long long prv = n;
  long long ans = 0;
  for (long long x = 1; x * x <= n; x++) {
    long long start = prv, end = n / (x + 1) + 1;
    prv = min(end, start) - 1;
    if (start < end)
      continue;
    //		cout << start << " " << end << endl;
    swap(start, end);
    --start;
    ++end;
    while (end - start > 1) {
      long long mid = (end + start) >> 1;
      if (n % mid < x)
        end = mid;
      else
        start = mid;
    }
    if (n % start == x)
      ans += start;
    //		cout << n << " " << x << " " << start << " " << n / start << " " << n
    //% start << endl;
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  long long prv = n;
  long long ans = 0;
  for (long long x = 1; x * x <= n; x++) {
    long long start = prv, end = n / (x + 1) + 1;
    prv = min(end, start) - 1;
    if (start < end)
      continue;
    //		cout << start << " " << end << endl;
    swap(start, end);
    --start;
    ++end;
    while (end - start > 1) {
      long long mid = (end + start) >> 1;
      if (n % mid < x)
        end = mid;
      else
        start = mid;
    }
    if (n % start == x)
      ans += start;
    //		cout << n << " " << x << " " << start << " " << n / start << " " << n
    //% start << endl;
  }
  cout << ans << endl;

  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 all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const long long LINF = 8931145141919364364, LMOD = 998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

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


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const long long LINF = 8931145141919364364, LMOD = 998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

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