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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
#define dump(x) cerr << #x << " = " << (x) << endl;
#else
#define dump(x) ; // 何もしない文
#endif

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SZ(x) ((int)(x).size()) // unsignedのサイズをint型に変換
#define pb push_back
#define eb emplace_back

// #define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T> std::string printVector(const std::vector<T> &data) {
  std::stringstream ss;
  std::ostream_iterator<T> out_it(ss, ", ");
  ss << "[";
  std::copy(data.begin(), data.end() - 1, out_it);
  ss << data.back() << "]";
  return ss.str();
}

const int MOD = 1e9 + 7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL N;
  cin >> N;
  LL ans = 0;
  for (LL i = 1; i * i <= N; i++) {
    if ((N - i) % i != 0)
      continue;
    LL tmp = (N - i) / i;
    if (N / tmp == N % tmp) {
      ans += tmp;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
#define dump(x) cerr << #x << " = " << (x) << endl;
#else
#define dump(x) ; // 何もしない文
#endif

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SZ(x) ((int)(x).size()) // unsignedのサイズをint型に変換
#define pb push_back
#define eb emplace_back

// #define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T> std::string printVector(const std::vector<T> &data) {
  std::stringstream ss;
  std::ostream_iterator<T> out_it(ss, ", ");
  ss << "[";
  std::copy(data.begin(), data.end() - 1, out_it);
  ss << data.back() << "]";
  return ss.str();
}

const int MOD = 1e9 + 7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  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) % i != 0)
      continue;
    LL tmp = (N - i) / i;
    if (N / tmp == N % tmp) {
      ans += tmp;
    }
  }
  cout << ans << endl;
}
Problem p03050 (C++)

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

int main() {
  long long n, p, ans = 0;
  cin >> n;
  p = sqrt(n);
  for (long long i = 1; i <= p; ++i)
    if (n % i == 0) {
      if (n / (i - 1) * i == n)
        ans += i - 1;
      if (i * i != n) {
        long long k = n / i;
        if (n / (k - 1) * k == n)
          ans += k - 1;
      }
    }
  cout << ans << endl;
  return 0;
}

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define elif else if
using namespace std;
int a, c = 0;
signed main() {
  cin >> a;
  int b = sqrt(a);
  for (int i = 1; i < b + 1; i++) {
    if (a % i == 0) {
      if (i > 1 && a / (i - 1) == a % (i - 1)) {
        c += i - 1;
      }
      if (a / (a / i - 1) == a % (a / i - 1)) {
        c += a / i - 1;
      }
    }
  }
  cout << c;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define elif else if
using namespace std;
int a, c = 0;
signed main() {
  cin >> a;
  if (a == 1) {
    cout << 0;
    return 0;
  }
  int b = sqrt(a);
  for (int i = 1; i < b + 1; i++) {
    if (a % i == 0) {
      if (i > 1 && a / (i - 1) == a % (i - 1)) {
        c += i - 1;
      }
      if (a / (a / i - 1) == a % (a / i - 1)) {
        c += a / i - 1;
      }
    }
  }
  cout << c;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>

#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i)                                                             \
  cout << fixed << setprecision(i) // coutの浮動小数出力の桁数設定
using namespace std;

int main() {
  int64 nn, tmp, ans = 0;
  cin >> nn;
  set<int64> memo;
  for (int64 ii = 2; ii <= sqrt(nn); ii++) {
    if (nn % ii == 0) {
      memo.insert(ii);
      memo.insert(nn / ii);
    }
  }
  memo.insert(nn);
  for (auto ite = memo.begin(); ite != memo.end(); ite++) {
    tmp = *ite;
    tmp--;
    if (nn % tmp == nn / tmp) {
      ans += tmp;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>

#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i)                                                             \
  cout << fixed << setprecision(i) // coutの浮動小数出力の桁数設定
using namespace std;

int main() {
  int64 nn, tmp, ans = 0;
  cin >> nn;
  if (nn == 1) {
    cout << 0 << endl;
    return 0;
  }
  set<int64> memo;
  for (int64 ii = 2; ii <= sqrt(nn); ii++) {
    if (nn % ii == 0) {
      memo.insert(ii);
      memo.insert(nn / ii);
    }
  }
  memo.insert(nn);
  for (auto ite = memo.begin(); ite != memo.end(); ite++) {
    tmp = *ite;
    tmp--;
    if (nn % tmp == nn / tmp) {
      ans += tmp;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03050 (C++)

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

#define M_PI 3.14159265358979323846 // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<int, int> P;
typedef tuple<int, int, int> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a, n) for (ll a = 0; a < n; a++)
#define repi(a, b, n) for (ll a = b; a < n; a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;

ll gcd(ll a, ll b) {
  while (b)
    a %= b, swap(a, b);
  return abs(a);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  ll n;
  cin >> n;
  // n/m >= m ならば
  // n/m = n % m とはならない
  // n >= m*m はチェック不要
  // while(i*i <= n) 不要
  // i > sqrt(n)
  // 36
  // 36-3 / 11 = 3
  // 36-4 / 8 = 4
  // t = n - i;
  // n/i == t/i;
  // n / i = n % i

  double u = sqrt(n) + 1;
  ll ut = (ll)u;
  ll sum = 0;
  for (ll i = ut; i > 0; i--) {
    auto opm = n - i;
    if (opm % i == 0) {
      auto m = opm / i;
      if (n / m == n % m) {
        sum += m;
      }
    }
  }
  cout << sum << endl;
  return 0;
}


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

#define M_PI 3.14159265358979323846 // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<int, int> P;
typedef tuple<int, int, int> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a, n) for (ll a = 0; a < n; a++)
#define repi(a, b, n) for (ll a = b; a < n; a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;

ll gcd(ll a, ll b) {
  while (b)
    a %= b, swap(a, b);
  return abs(a);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  ll n;
  cin >> n;
  // n/m >= m ならば
  // n/m = n % m とはならない
  // n >= m*m はチェック不要
  // while(i*i <= n) 不要
  // i > sqrt(n)
  // 36
  // 36-3 / 11 = 3
  // 36-4 / 8 = 4
  // t = n - i;
  // n/i == t/i;
  // n / i = n % i

  double u = sqrt(n) + 1;
  ll ut = (ll)u;
  ll sum = 0;
  for (ll i = ut; i > 0; i--) {
    auto opm = n - i;
    if (opm % i == 0) {
      auto m = opm / i;
      if (m > 0) {
        if (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;

int main() {
  long n;
  long t;
  cin >> n;
  long ans = 0;
  for (long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      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;

int main() {
  long n;
  long t;
  cin >> n;
  long ans = 0;
  if (n == 1) {
    ans = 0;
  } else {
    for (long i = 1; i * i <= n; i++) {
      if (n % i == 0) {
        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 <iostream>
using namespace std;
using ll = long long int;

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

Fixed submission:
#include <iostream>
using namespace std;
using ll = long long int;

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

Buggy submission (status: Runtime Error):
#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
  long long ans = 0;
  long long n;
  cin >> n;
  long long fav;
  long long k;
  k = sqrt(n);
  for (long long i = 1; i <= k; i++) {
    if ((n - i) % i == 0) {
      fav = (n - i) / i;
      if (n / fav == n % fav) {
        ans += fav;
        // cout << ans << " " << fav << " " << i <<  endl;
        // cout << n / fav << " " << n % fav << endl;
      }
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
  long long ans = 0;
  long long n;
  cin >> n;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  long long fav;
  long long k;
  k = sqrt(n);
  for (long long i = 1; i <= k; i++) {
    if ((n - i) % i == 0) {
      fav = (n - i) / i;
      if (n / fav == n % fav) {
        ans += fav;
        // cout << ans << " " << fav << " " << i <<  endl;
        // cout << n / fav << " " << n % fav << endl;
      }
    }
  }
  cout << ans << endl;
}
Problem p03050 (C++)

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

vll divisors(ll n) {
  vll res;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      res.push_back(i);
      if (n / i != i)
        res.push_back(n / i);
    }
  }
  return res;
}

int main() {
  ll N;
  cin >> N;
  vll res = divisors(N);
  ll ans = 0;
  int M = res.size();
  for (int i = 0; i < M; ++i) {
    if (N / res[i] < res[i] - 1)
      ans += res[i] - 1;
  }
  cout << ans << endl;
  return 0;
}

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

vll divisors(ll n) {
  vll res;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      res.push_back(i);
      if (n / i != i)
        res.push_back(n / i);
    }
  }
  return res;
}

int main() {
  ll N;
  cin >> N;
  vll res = divisors(N);
  ll ans = 0;
  int M = res.size();
  for (int i = 0; i < M; ++i) {
    if (N / res[i] < res[i] - 1)
      ans += res[i] - 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p03050 (C++)

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define all(x) (x).begin(), (x).end()
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
//}}}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0 && n / (n / i - 1) == n % (n / i - 1))
      sum += n / i - 1;
  }
  cout << sum << '\n';
  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define all(x) (x).begin(), (x).end()
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
//}}}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 1; i * i < n; ++i) {
    if (n % i == 0 && n / (n / i - 1) == n % (n / i - 1))
      sum += n / i - 1;
  }
  cout << sum << '\n';
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define RREP(i, a, b) for (int(i) = (a)-1; (i) >= (b); --(i))
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
using namespace std;
typedef long long ll;

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

  ll ans = 0; // お気に入りの数の総和
  for (ll i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      // (Nの約数)-1が候補
      // 大きい方の約数だけ
      ll m = N / i - 1;
      if (N / m == N % m)
        ans += m;
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define RREP(i, a, b) for (int(i) = (a)-1; (i) >= (b); --(i))
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
using namespace std;
typedef long long ll;

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

  ll ans = 0; // お気に入りの数の総和
  for (ll i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      // (Nの約数)-1が候補
      // 大きい方の約数だけ
      ll m = N / i - 1;
      if (m != 0 && N / m == N % m)
        ans += m;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define RANGE(i, x, n) for (ll i = x; i < n; ++i)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

void accelerate() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  accelerate();

  ll N;
  cin >> N;
  ll ans = 0;
  for (ll x = 2; x * x <= N; ++x) {
    if (N % x == 0) {
      ll m = x - 1;
      if (N / (m + 1) == N / m)
        ans += m;

      if (x * x != N) {
        ll m = N / x - 1;
        if (N / (m + 1) == N / m)
          ans += m;
      }
    }
  }
  if (N / (N - 1) == 1)
    ans += N - 1;
  cout << ans << endl;
}


Fixed submission:
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define RANGE(i, x, n) for (ll i = x; i < n; ++i)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

void accelerate() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main() {
  accelerate();

  ll N;
  cin >> N;
  ll ans = 0;
  for (ll x = 2; x * x <= N; ++x) {
    if (N % x == 0) {
      ll m = x - 1;
      if (N / (m + 1) == N / m)
        ans += m;

      if (x * x != N) {
        ll m = N / x - 1;
        if (N / (m + 1) == N / m)
          ans += m;
      }
    }
  }
  if (N != 1 && N / (N - 1) == 1)
    ans += N - 1;
  cout << ans << endl;
}
Problem p03050 (C++)

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

#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

//////////////////////////////////////////////////

int main() {
  i64 N;
  cin >> N;
  i64 ret = 0LL;
  for (i64 i = 1; i * i <= N; i++) {
    i64 k = (N - i) / i;
    if (N / k == N % k)
      ret += k;
  }
  cout << ret << endl;
  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>
#include <sstream>

#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

//////////////////////////////////////////////////

int main() {
  i64 N;
  cin >> N;
  i64 ret = 0LL;
  for (i64 i = 1; i * i <= N; i++) {
    i64 k = (N - i) / i;
    if (k == 0)
      continue;
    if (N / k == N % k)
      ret += k;
  }
  cout << ret << endl;
  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll k = 1; k <= sqrtl(n); k++) {
    ll nn = n - k;
    if (nn % k == 0) {
      // cout<<nn/k<<endl;
      ll j = nn / k;
      if ((n % j) == (n / j)) {
        ans += j;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll k = 1; k <= sqrtl(n); k++) {
    if (k != 0) {
      ll nn = n - k;
      if (nn % k == 0) {
        // cout<<nn/k<<endl;
        ll j = nn / k;
        if (j != 0) {
          if ((n % j) == (n / j)) {
            ans += j;
          }
        }
      }
    }
  }

  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, ans = 0, fav;
  cin >> n;
  for (long long i = 1; i * i <= n; i++) {
    if ((n - i) % i == 0) {
      fav = (n - i) / i;
      if ((n / fav) == (n % fav))
        ans += fav;
    }
  }
  cout << ans << endl;
}


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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 998244353
#define MAX 100
#define INF 800000000

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 998244353
#define MAX 100
#define INF 800000000

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

// 約数の列挙O(√n)
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1LL; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i)
        res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> v = divisor(n);

  ll ans = 0;
  for (int i = 0; i < v.size(); i++) {
    ll m = v[i] - 1;
    if (n / m == n % m)
      ans += m;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

// 約数の列挙O(√n)
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1LL; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i)
        res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> v = divisor(n);

  ll ans = 0;
  for (int i = 0; i < v.size(); i++) {
    ll m = v[i] - 1;
    if (m <= 0)
      continue;
    if (n / m == n % m)
      ans += m;
  }
  cout << ans << endl;
}
Problem p03050 (C++)

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

long long n;
int cnt = 0;

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


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

long long n;
int cnt = 0;

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

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
long long n;
bool check(long long x) {
  long long m = x - 1;
  return (m + 1) * (n / m) == n;
}
int main() {
  scanf("%lld", &n);
  long long ans = 0;
  for (long long i = 2; i <= sqrt(n); i++)
    if (n % i == 0) {
      if (check(i))
        ans += i - 1;
      if (i * i != n && check(n / i))
        ans += n / i - 1;
    }
  if (check(n))
    ans += n - 1;
  printf("%lld", ans);
  return 0;
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
long long n;
bool check(long long x) {
  long long m = x - 1;
  return (m + 1) * (n / m) == n;
}
int main() {
  scanf("%lld", &n);
  long long ans = 0;
  for (long long i = 2; i <= sqrt(n); i++)
    if (n % i == 0) {
      if (check(i))
        ans += i - 1;
      if (i * i != n && check(n / i))
        ans += n / i - 1;
    }
  if (n != 1 && check(n))
    ans += n - 1;
  printf("%lld", ans);
  return 0;
}
Problem p03050 (C++)

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

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for (ll i = a; i < b; i++)

typedef long long ll;

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

  vector<ll> v;

  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      v.pb(i);
      if (n != i * i)
        v.pb(n / i);
    }
  }
  v.pb(n);
  ll ans = 0;
  for (auto X : v) {
    ll temp = X - 1;
    if (n % temp == floor(n / temp))
      ans += temp;
  }
  cout << ans;
}


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

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for (ll i = a; i < b; i++)

typedef long long ll;

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

  if (n == 1) {
    cout << 0;
    return 0;
  }
  vector<ll> v;

  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      v.pb(i);
      if (n != i * i)
        v.pb(n / i);
    }
  }
  v.pb(n);
  ll ans = 0;
  for (auto X : v) {
    ll temp = X - 1;
    if (n % temp == floor(n / temp))
      ans += temp;
  }
  cout << ans;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int ans = 0, i, k;
  for (i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      k = n / i - 1;
      if (n / k == n % k)
        ans += k;
      if (n / i != i && i > 1) {
        k = i - 1;
        if (n / k == n % k)
          ans += k;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

ll n;

int main(void) {
  scanf("%lld", &n);
  ll ans = 0;
  for (ll i = 1LL; i * i <= n; i++) {
    if (n % i == 0LL) {
      ll val = n / i - 1LL;
      if (n % val != n / val)
        continue;
      ans += (n / i) - 1LL;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

ll n;

int main(void) {
  scanf("%lld", &n);
  ll ans = 0;
  for (ll i = 1LL; i * i <= n; i++) {
    if (n % i == 0LL) {
      ll val = n / i - 1LL;
      if (val == 0LL)
        continue;
      if (n % val != n / val)
        continue;
      ans += (n / i) - 1LL;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03050 (C++)

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

int main() {

  long long n, i;

  long long k = 0;

  vector<long long> a;

  cin >> n;

  for (i = 1; i * i <= n; i = i + 1) {

    if (n % i == 0) {

      a.push_back(i - 1);

      a.push_back((n / i) - 1);
    }
  }

  for (i = 1; i < a.size(); i = i + 1) {

    if (n / a.at(i) == n % a.at(i))
      k += a.at(i);
  }

  cout << k << endl;

  return 0;
}

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

int main() {

  long long n, i;

  long long k = 0;

  vector<long long> a;

  cin >> n;

  for (i = 1; i * i <= n; i = i + 1) {

    if (n % i == 0) {

      a.push_back(i - 1);

      a.push_back((n / i) - 1);
    }
  }

  for (i = 1; i < a.size() && a.at(i) != 0; i = i + 1) {

    if (n / a.at(i) == n % a.at(i))
      k += a.at(i);
  }

  cout << k << endl;

  return 0;
}
Problem p03050 (C++)

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

using namespace std;

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

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

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

  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;

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

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 1; i * i <= n; i++) {
    ll a = (n - i) / i;
    if (a != 0 && n / a != n % a)
      continue;
    ans += a;
  }
  cout << ans << endl;
  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;
  cin >> N;
  ll ans = 0;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      if (N / ((N - i) / i) == N % ((N - i) / i)) {
        ans += (N - i) / i;
      }
    }
  }

  cout << ans << endl;
}


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

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i, s, n) for (ll(i) = (s); (i) < (n); ++(i))
#define rep(i, n) reps(i, 0, n)
#define reptr(i, n) for (ll(i) = (n); (i) >= 0; --(i))
#define All(x) (x).begin(), (x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define pi pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const ll MOD = 1e9 + 7;
using namespace std;

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


Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i, s, n) for (ll(i) = (s); (i) < (n); ++(i))
#define rep(i, n) reps(i, 0, n)
#define reptr(i, n) for (ll(i) = (n); (i) >= 0; --(i))
#define All(x) (x).begin(), (x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define pi pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const ll MOD = 1e9 + 7;
using namespace std;

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

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

ll n, ans, x, y;

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

  cin >> n;
  for (int i = 1; i <= sqrt(n); i++) {
    x = i + 1;
    if (n % x == 0) {
      if (n / i == n / x)
        ans += i;
      y = n / x;
      y--;
      if (y > 0) {
        if (n / y == n / (y + 1))
          ans += y;
      }
    }
  }
  if (n / (n - 1) == 1 && n % (n - 1) == 1)
    ans += n - 1;
  cout << ans;
  return 0;
}

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

ll n, ans, x, y;

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

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1 << 30
#define LINF 1LL << 62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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++) {
    ll tmp = n / i - 1;
    if (n % i == 0 && (i == n / tmp))
      ans += tmp;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1 << 30
#define LINF 1LL << 62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

ll N, S;

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


Fixed submission:
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

ll N, S;

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

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T>
constexpr T inf =
    numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity()
                                    : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop)                                                    \
  for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto &a, const auto &b) { return a.key < b.key; }

struct InitCpp {
  InitCpp() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  }
} initCpp;

signed main() {
  i64 n;
  cin >> n;
  i64 a = 0;
  for (i64 r = 1; r * r <= n; ++r) {
    if (n / r == n % r) {
      a += r;
    }
    i64 q = (n - 1) / r;
    if (q != r && n / q == n % q) {
      a += q;
    }
  }
  cout << a << endl;
}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T>
constexpr T inf =
    numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity()
                                    : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop)                                                    \
  for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto &a, const auto &b) { return a.key < b.key; }

struct InitCpp {
  InitCpp() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  }
} initCpp;

signed main() {
  i64 n;
  cin >> n;
  i64 a = 0;
  for (i64 r = 1; r * r <= n; ++r) {
    if (n / r == n % r) {
      a += r;
    }
    i64 q = (n - 1) / r;
    if (q > 0 && q != r && n / q == n % q) {
      a += q;
    }
  }
  cout << a << endl;
}
Problem p03050 (C++)

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

int main() {
  ll n;
  cin >> n;
  ll root = pow(n, 0.5);

  ll sum = 0;
  for (int i = 1; i <= root; i++) {
    if (n % i == 0) {
      ll like = n / i - 1;
      ll ans = n / like;
      ll remain = n % like;
      if (ans == remain)
        sum += like;
      like = i;
      ans = n / like;
      remain = n % like;
      if (ans == remain)
        sum += like;
    }
  }
  cout << sum << endl;
}


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

int main() {
  ll n;
  cin >> n;
  ll root = pow(n, 0.5);
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  ll sum = 0;
  for (int i = 1; i <= root; i++) {
    if (n % i == 0) {
      ll like = n / i - 1;
      ll ans = n / like;
      ll remain = n % like;
      if (ans == remain)
        sum += like;
      like = i;
      ans = n / like;
      remain = n % like;
      if (ans == remain)
        sum += like;
    }
  }
  cout << sum << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

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

  ll ans = 0;

  ll root = sqrt(n);

  repd(i, 1, root + 1) {
    if (n % i == 0) {
      ll temp = n / i - 1;
      if (n / temp == n % temp) {
        ans += temp;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

template <typename T> void output(T a, int precision) {
  if (precision > 0) {
    cout << setprecision(precision) << a << "\n";
  } else {
    cout << a << "\n";
  }
}

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

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

  ll ans = 0;

  ll root = sqrt(n);

  repd(i, 1, root + 1) {
    if (n % i == 0) {
      ll temp = n / i - 1;
      if (temp == 0) {
        break;
      }
      if (n / temp == n % temp) {
        ans += temp;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

template <typename T> void output(T a, int precision) {
  if (precision > 0) {
    cout << setprecision(precision) << a << "\n";
  } else {
    cout << a << "\n";
  }
}

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  ll flor = sqrt(n); // 商と余りが一致する可能性があるのはここから
  for (ll i = n / flor; i >= 1; i--) {
    ll d = (n - i) / i;
    if ((n - i) % i == 0 &&
        n / d == i) { // i余らせて割り切れる && 割り切れた数で割るとiになる
      ans += ((n - i) / i);
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  ll flor = sqrt(n); // 商と余りが一致する可能性があるのはここから
  for (ll i = n / flor; i >= 1; i--) {
    ll d = (n - i) / i;
    if (d == 0)
      continue;
    if ((n - i) % i == 0 &&
        n / d == i) { // i余らせて割り切れる && 割り切れた数で割るとiになる
      ans += ((n - i) / i);
    }
  }
  cout << ans << endl;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):

// D - DivRem Number

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

  ll ans = 0;

  for (ll q = 1; q * q <= N; q++) {
    ll r = q;
    if ((N - r) % q == 0) {
      ll m = (N - r) / q;
      if (N % m == r) {
        ans += (N - q) / q;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:

// D - DivRem Number

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

  ll ans = 0;

  for (ll q = 1; q * q < N; q++) {
    ll r = q;
    if ((N - r) % q == 0) {
      ll m = (N - r) / q;
      if (N % m == r) {
        ans += (N - q) / q;
      }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03050 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(), a.end()
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
const long long MOD = 1000000007, INF = 1e17;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//******************************************************************************
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
  t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(), a.end()
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
const long long MOD = 1000000007, INF = 1e17;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//******************************************************************************
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
  t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

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) % i == 0) {
      int t = (N - i) / i;
      if (N / t == N % t)
        ans += t;
    }
  }
  cout << ans << endl;
}
Problem p03050 (C++)

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

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

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

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