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

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF{1001002003004005006}; // ll = 9*LLINF
constexpr int INTINF{1000000000};        // int = 2*INTINF

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

template <typename T> void maxs(T &x, T &&y) { x = std::max(x, y); }
template <typename T> void maxs(T &x, T &y) { x = std::max(x, y); }

template <typename T> void mins(T &x, T &&y) { x = std::min(x, y); }
template <typename T> void mins(T &x, T &y) { x = std::min(x, y); }

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

  ull N;
  cin >> N;

  ull digit_sum{};
  ull n = N;
  while (n > 0) {
    digit_sum += N % 10;
    n /= 10;
  }
  if (N % digit_sum) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
  }
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF{1001002003004005006}; // ll = 9*LLINF
constexpr int INTINF{1000000000};        // int = 2*INTINF

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

template <typename T> void maxs(T &x, T &&y) { x = std::max(x, y); }
template <typename T> void maxs(T &x, T &y) { x = std::max(x, y); }

template <typename T> void mins(T &x, T &&y) { x = std::min(x, y); }
template <typename T> void mins(T &x, T &y) { x = std::min(x, y); }

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

  ull N;
  cin >> N;

  ull digit_sum{};
  ull n = N;
  while (n > 0) {
    digit_sum += (n % 10);
    n /= 10;
  }
  if (N % digit_sum) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
  }
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;

int main() {

  int n, s = 0;
  cin >> n;
  int t = n;
  for (int i = 0; i < 9; i++) {
    s += n % 10;
    n /= 10;
  }
  if (t % s == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;

int main() {

  int n, s = 0;
  cin >> n;
  int t = n;
  for (int i = 0; i < 10; i++) {
    s += n % 10;
    n /= 10;
  }
  if (t % s == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
Problem p03316 (C++)

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

int main() {
  ll n, s = 0;
  cin >> n;
  ll m = n;
  while (n) {
    s += n % 10;
  }
  if (m % s) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
  }
  return 0;
}

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

int main() {
  ll n, s = 0;
  cin >> n;
  ll m = n;
  while (n) {
    s += n % 10;
    n /= 10;
  }
  if (m % s) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
  }
  return 0;
}
Problem p03316 (C++)

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

int main() {
  int N;
  int a = 0;
  cin >> N;
  int I = N;
  int i = 1;
  while (i < 10) {
    a += I % 10;
    I = I / 10;
    i++;
  }
  if (N % a == 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


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

int main() {
  int N;
  int a = 0;
  cin >> N;
  int I = N;
  int i = 1;
  while (i < 15) {
    a += I % 10;
    I = I / 10;
    i++;
  }
  if (N % a == 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
Problem p03316 (C++)

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

int main() {
  int n;
  int sum = 0;
  scanf("%d", &n);

  int temp = n;

  while (temp > 0) {
    sum += n % 10;
    temp /= 10;
  }
  if (n % sum == 0) {
    puts("Yes\n");
  } else
    puts("No\n");
  return 0;
}


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

int main() {
  int n;
  int sum = 0;
  scanf("%d", &n);

  int temp = n;

  while (temp > 0) {
    sum += temp % 10;
    temp /= 10;
  }
  if (n % sum == 0) {
    puts("Yes\n");
  } else
    puts("No\n");
  return 0;
}
Problem p03316 (C++)

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

int main(void) {
  long long N;
  int S, x;
  cin >> N;
  for (int i = 0; i < 9; i++) {
    x = N;
    for (int j = 0; j < i; j++) {
      x /= 10;
    }
    S += x % 10;
  }
  if (N % S == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

int main(void) {
  long long N;
  int S, x;
  cin >> N;
  for (int i = 0; i < 10; i++) {
    x = N;
    for (int j = 0; j < i; j++) {
      x /= 10;
    }
    S += x % 10;
  }
  if (N % S == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p03316 (C++)

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

int main() {
  int n;
  cin >> n;
  int a = 0, b = n;
  for (int i = 0; i < n; i++) {
    a += b % 10;
    b /= 10;
  }
  cout << (n % a == 0 ? "Yes" : "No") << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  int a = 0, b = n;
  while (b != 0) {
    a += b % 10;
    b /= 10;
  }
  cout << (n % a == 0 ? "Yes" : "No") << endl;
  return 0;
}
Problem p03316 (C++)

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

int s(long long i) {
  int a = i % 10;
  while (i > 10) {
    i /= 10;
    a += (i % 10);
  };

  return a;
}

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

  if (N % s(N) == 0) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>

int s(long long i) {
  int a = i % 10;
  while (i >= 10) {
    i /= 10;
    a += (i % 10);
  };

  return a;
}

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

  if (N % s(N) == 0) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }

  return 0;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const int INF = INT_MAX, MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  int m = n;
  int digit = 0, div = 10;
  rep(i, 9) {
    digit += n % div;
    n = n / div;
  }
  if (m % digit == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  int m = n;
  int digit = 0, div = 10;
  rep(i, 10) {
    digit += n % div;
    n = n / div;
  }
  if (m % digit == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main() {
  int N;
  cin >> N;
  int tmp = N;
  int s = 0;
  while (1) {
    s += tmp / 10;
    if (tmp / 10 == 0)
      break;
    tmp %= 10;
  }
  if (N % tmp == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main() {
  int N;
  cin >> N;
  string n = to_string(N);
  int tmp = 0;
  rep(i, n.size()) { tmp += int(n[i] - '0'); }
  if (N % tmp == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p03316 (C++)

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

using namespace std;

int main() {
  int N;
  cin >> N;
  int sum = 0;
  int tmp = N;
  while (tmp > 0) {
    sum += tmp % 10;
    tmp /= 10;
  }
  if (N % tmp == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  int sum = 0;
  int tmp = N;
  while (tmp > 0) {
    sum += tmp % 10;
    tmp /= 10;
  }
  if (N % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p03316 (Python)

Buggy submission (status: Runtime Error):
N = input().strip()
print("Yes" if N % sum(map(int, N)) == 0 else "No")


Fixed submission:
N = input().strip()
print("Yes" if int(N) % sum(map(int, N)) == 0 else "No")
Problem p03316 (Python)

Buggy submission (status: Runtime Error):
N = input()
S = 0
for i in range(len(N)):
    S += int(N[i])
if N % S == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
N = input()
S = 0
for i in range(len(N)):
    S += int(N[i])
if int(N) % S == 0:
    print("Yes")
else:
    print("No")
Problem p03316 (Python)

Buggy submission (status: Runtime Error):
N = input()
if int(N) % sum([int(N[i] for i in range(len(N)))]) == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
N = input()
if int(N) % sum([int(N[i]) for i in range(len(N))]) == 0:
    print("Yes")
else:
    print("No")
Problem p03316 (C++)

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

using namespace std;

int main() {
  int a;
  cin >> a;
  int sum = 0;
  int i = a;
  while (i > 0) {
    sum += (a % 10);
    i /= 10;
  }
  if (a % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

using namespace std;

int main() {
  int a;
  cin >> a;
  int sum = 0;
  int i = a;
  while (i > 0) {
    sum += (i % 10);
    i /= 10;
  }
  if (a % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03316 (C++)

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

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

#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
// #pragma GCC optimize ("-O3")
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x)
#endif
const int INF = 1e9;
const LL LINF = 1e16;
const LL MOD = 1000000007;
const double PI = acos(-1.0);
int DX[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int DY[8] = {1, -1, 0, 0, 1, -1, 1, -1};

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

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

  LL N;
  cin >> N;

  LL n = N;
  LL p = 0;
  while (n) {
    p += n % 10;
    p /= 10;
  }

  cout << (N % p == 0 ? "Yes" : "No") << endl;

  return 0;
}


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

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

#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
// #pragma GCC optimize ("-O3")
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x)
#endif
const int INF = 1e9;
const LL LINF = 1e16;
const LL MOD = 1000000007;
const double PI = acos(-1.0);
int DX[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int DY[8] = {1, -1, 0, 0, 1, -1, 1, -1};

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

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

  LL N;
  cin >> N;

  LL n = N;
  LL p = 0;
  while (n) {
    p += n % 10;
    n /= 10;
  }

  cout << (N % p == 0 ? "Yes" : "No") << endl;

  return 0;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repf(i, a, b) for (int i = (a); i < (b); i++)
#define repi(i, a, b) for (int i = (a); i <= (b); i++)
#define repr(i, a, b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

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

  int Sn = 0;
  int tmp = 0;
  while (tmp > 0) {
    Sn += tmp % 10;
    tmp /= 10;
  }

  cout << (N % Sn == 0 ? "Yes" : "No") << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repf(i, a, b) for (int i = (a); i < (b); i++)
#define repi(i, a, b) for (int i = (a); i <= (b); i++)
#define repr(i, a, b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

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

  int Sn = 0;
  int tmp = N;
  while (tmp > 0) {
    Sn += tmp % 10;
    tmp /= 10;
  }

  cout << (N % Sn == 0 ? "Yes" : "No") << endl;
}
Problem p03316 (C++)

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

int main() {
  long N, S = 0, n;
  cin >> N;
  n = N;
  while (N > 0) {
    S += n % 10;
    n /= 10;
  }
  cout << (N % S ? "No" : "Yes") << endl;
  return 0;
}


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

int main() {
  long N, S = 0, n;
  cin >> N;
  n = N;
  while (n > 0) {
    S += n % 10;
    n /= 10;
  }
  cout << (N % S ? "No" : "Yes") << endl;
  return 0;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
#include <vector>
// #include <stack>
// #include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";

int main() {

  int N;
  cin >> N;

  if (N == 1)
    cout << ans_Yes;
  else {
    int base = 1;
    int Sn = 0;
    while (base < N) {
      base = base * 10;
      Sn += (N % base) / (base / 10);
    }

    if (N % Sn == 0)
      cout << ans_Yes;
    else
      cout << ans_No;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
#include <vector>
// #include <stack>
// #include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";

int main() {

  int N;
  cin >> N;

  if (N == 1)
    cout << ans_Yes;
  else {
    int base = 1;
    int Sn = 0;
    while (base <= N) {
      base = base * 10;
      Sn += (N % base) / (base / 10);
    }

    if (N % Sn == 0)
      cout << ans_Yes;
    else
      cout << ans_No;
  }
}
Problem p03316 (C++)

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

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

  for (int i = 0; i < 10; i++) {
    ans += s % 10;
    s /= 10;
  }

  if (n % ans == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main() {
  int n, ans = 0, s;
  cin >> n;
  s = n;
  for (int i = 0; i < 10; i++) {
    ans += s % 10;
    s /= 10;
  }

  if (n % ans == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03316 (C++)

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

int s(int n) {
  int ans = 0;
  while (n != 0) {
    ans += n % 10;
    ans /= 10;
  }

  return ans;
}

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

  if (n % s(n) == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int s(int n) {
  int ans = 0;
  while (n != 0) {
    ans += n % 10;
    n /= 10;
  }

  return ans;
}

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

  if (n % s(n) == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#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 <utility>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ans = 0, tmp = n;
  while (tmp) {
    ans += tmp % 10;
    tmp /= 10;
  }
  if (n % tmp == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#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 <utility>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ans = 0, tmp = n;
  while (tmp) {
    ans += tmp % 10;
    tmp /= 10;
  }
  if (n % ans == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03316 (C++)

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

int func(int n) {
  int res = 0;
  for (int i = 1; i < 10; ++i) {
    res += n % 10;
    n /= 10;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  if (n % func(n) == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int func(int n) {
  if (n < 10)
    return n;
  return n % 10 + func(n / 10);
}

int main() {
  int n;
  cin >> n;
  if (n % func(n) == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03316 (C++)

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

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

  while (n >= 10) {
    ans += n % 10;
    n /= 10;
  }

  if (n % ans == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

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

  int a = n;

  while (a > 0) {
    ans += a % 10;
    a /= 10;
  }

  if (n % ans == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int k = N;
  int sum = 0;
  for (int i = 0; i < 10; i++) {
    sum = k % 10;
    k /= 10;
  }
  if (N % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int k = N;
  int sum = 0;
  while (k) {
    sum += k % 10;
    k /= 10;
  }
  if (N % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03316 (C++)

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

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

#define mem(dp, a) memset(dp, a, sizeof dp)
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define pi 3.14159265359
ll INF = 1e18 + 10;
ll MOD = 1000000007;

int sumd(ll n) {
  int d = 0;
  while (n > 0) {
    d += (n % 10);
    n /= 10;
  }
  return n;
}
int main() {
  ll n;
  cin >> n;
  int d = sumd(n);
  if (n % d == 0)
    cout << "Yes";
  else
    cout << "No";
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

#define mem(dp, a) memset(dp, a, sizeof dp)
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define pi 3.14159265359
ll INF = 1e18 + 10;
ll MOD = 1000000007;

int sumd(ll n) {
  int d = 0;
  while (n > 0) {
    d += (n % 10);
    n /= 10;
  }
  return d;
}
int main() {
  ll n;
  cin >> n;
  int d = sumd(n);
  if (n % d == 0)
    cout << "Yes";
  else
    cout << "No";
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c = 0;
  cin >> a;
  b = a;
  while (a) {
    c += a % 10;
    a /= 10;
  }
  if (b % a)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c = 0;
  cin >> a;
  b = a;
  while (a) {
    c += a % 10;
    a /= 10;
  }
  if (b % c)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)

using namespace std;
typedef long long int lli;
// const int MAX=;

int main() {
  int N;
  cin >> N;
  int S = 0, x = N;
  rep(i, 10) {
    S = S + (N % 10);
    x = x / 10;
  }
  if (N % S == 0)
    cout << "Yes";
  else
    cout << "No";
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)

using namespace std;
typedef long long int lli;
// const int MAX=;

int main() {
  int N;
  cin >> N;
  int S = 0, x = N;
  rep(i, 10) {
    if (x == 0)
      break;
    S = S + (x % 10);
    x = x / 10;
  }
  if (N % S == 0)
    cout << "Yes";
  else
    cout << "No";
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int sum = 0;
  int temp = n;
  while (temp > 0) {
    sum += n % 10;
    temp /= 10;
  }
  if (n % sum == 0)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int sum = 0;
  int temp = n;
  while (temp > 0) {
    sum += temp % 10;
    temp /= 10;
  }
  if (n % sum == 0)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
int main() {
  int n, s = 0, t;
  std::cin >> n;
  t = n;
  while (t > 0) {
    s += n % 10;
    t /= 10;
  }
  std::cout << (n % s ? "No" : "Yes");
}

Fixed submission:
#include <iostream>
int main() {
  int n, s = 0, t;
  std::cin >> n;
  t = n;
  while (t > 0) {
    s += t % 10;
    t /= 10;
  }
  std::cout << (n % s ? "No" : "Yes");
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

constexpr int MOD = 1000000007;

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

template <class T = int> T in() {
  T x;
  cin >> x;
  return (x);
}
template <class T = int> void out(T x) { cout << (x) << endl; }

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

void solve() {

  int N;
  cin >> N;

  int sum = 0;

  int init = N;

  do {
    sum += N % 10;
    N /= 10;
  } while (N >= 10);

  Yes(init % sum == 0);

  return;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  solve();

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

constexpr int MOD = 1000000007;

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

template <class T = int> T in() {
  T x;
  cin >> x;
  return (x);
}
template <class T = int> void out(T x) { cout << (x) << endl; }

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

void solve() {

  int N;
  cin >> N;

  int sum = 0;

  int init = N;

  do {
    sum += N % 10;
    N = (N - N % 10) / 10;
  } while (N > 0);

  Yes(init % sum == 0);

  return;
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  solve();

  return 0;
}
Problem p03316 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

#define vvint(vec, n, m, l) vector<vector<int>> vec(n, vector<int>(m, l));
#define vvll(vec, n, m, l) vector<vector<ll>> vec(n, vector<ll>(m, l));
#define vint vector<int>;
#define pint pair<int, int>;
#define rep(i, a) for (int i = 0; i < (a); i++)
#define all(x) (x).begin(), (x).end()
#define debug system("pause")
#define ret return 0

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

  ll n;
  cin >> n;
  ll tmp = n;
  int keta = 0;
  int sum = 0;
  while (n != 0) {
    sum += n % 10;
    n / 10;
    keta++;
  }
  if (tmp % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  ret;
}

Fixed submission:
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

#define vvint(vec, n, m, l) vector<vector<int>> vec(n, vector<int>(m, l));
#define vvll(vec, n, m, l) vector<vector<ll>> vec(n, vector<ll>(m, l));
#define vint vector<int>;
#define pint pair<int, int>;
#define rep(i, a) for (int i = 0; i < (a); i++)
#define all(x) (x).begin(), (x).end()
#define debug system("pause")
#define ret return 0

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

  ll n;
  cin >> n;
  ll tmp = n;
  int keta = 0;
  int sum = 0;
  while (n != 0) {
    sum += n % 10;
    n /= 10;
    keta++;
  }
  if (tmp % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  ret;
}
Problem p03316 (C++)

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

int main() {
  int N;
  cin >> N;
  int sum;
  sum = 0;
  int tmp = N;

  while (tmp > 0) {
    sum += tmp % 10;
    tmp / 10;
  }

  if (N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

int main() {
  int N;
  cin >> N;
  int sum;
  sum = 0;
  int tmp = N;

  while (tmp > 0) {
    sum += tmp % 10;
    tmp /= 10;
  }

  if (N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03316 (C++)

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

int main() {
  long long int N;
  long long int n;
  int y = 0;
  int z;
  cin >> N;
  n = N;
  long long int x = 1;
  for (int i = 1; i < 10; i++) {
    z = N % (x * 10);
    y += z / x;
    N -= z;
    x *= 10;
  }
  if (n % y == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

int main() {
  long long int N;
  long long int n;
  int y = 0;
  int z;
  cin >> N;
  n = N;
  long long int x = 1;
  for (int i = 1; i < 11; i++) {
    z = N % (x * 10);
    y += z / x;
    N -= z;
    x *= 10;
  }
  if (n % y == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll mod = 1000000007;

int digitsum(int a) {
  int sum = 0;
  if (a != 0) {
    sum += a % 10;
    a = a / 10;
  }
  return sum;
}

void solve() {
  int n;
  cin >> n;
  if (n % digitsum(n) == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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


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

int digitsum(int a) {
  int sum = 0;
  while (a != 0) {
    sum += a % 10;
    a = a / 10;
  }
  return sum;
}

void solve() {
  int n;
  cin >> n;
  if (n % digitsum(n) == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 1e9 + 7
#define rep(i, n) for (int i = 0; i < n; i++)
#define NO cout << "NO" << endl;
#define YES cout << "YES" << endl;
#define No cout << "No" << endl;
#define Yes cout << "Yes" << endl;
#define all(a) a.begin(), a.end()
#define P pair<int, int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
// おまじない
// UnionFind

const int maxn = 100000;

int main() {

  int n;
  cin >> n;
  int digsum = 0;
  int subn = n;
  while (subn > 0) {
    digsum += n % 10;
    subn = subn / 10;
  }
  if (n % digsum == 0) {
    Yes;
  } else {
    No;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 1e9 + 7
#define rep(i, n) for (int i = 0; i < n; i++)
#define NO cout << "NO" << endl;
#define YES cout << "YES" << endl;
#define No cout << "No" << endl;
#define Yes cout << "Yes" << endl;
#define all(a) a.begin(), a.end()
#define P pair<int, int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
// おまじない
// UnionFind

const int maxn = 100000;

int main() {

  int n;
  cin >> n;
  int digsum = 0;
  int subn = n;
  while (subn > 0) {
    digsum += subn % 10;
    subn = subn / 10;
  }
  if (n % digsum == 0) {
    Yes;
  } else {
    No;
  }

  return 0;
}
Problem p03316 (C++)

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

int main() {
  int N, s, sum = 0;
  cin >> N;
  s = N;
  while (s > 0) {
    s = s % 10;
    sum += s;
    s /= 10;
  }
  if (N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
  int N, s, sum = 0;
  cin >> N;
  s = N;
  while (s != 0) {
    int a;
    a = s % 10;
    sum += a;
    s /= 10;
  }
  if (N % sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03316 (C++)

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

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

  int sum = 0;
  int tmp = n;

  rep(i, 9) {
    int bit = n % 10;
    sum += bit;
    n /= 10;
  }

  tmp % sum == 0 ? cout << "Yes" << endl : cout << "No" << endl;
}

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

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

  int sum = 0;
  int tmp = n;

  rep(i, 10) {
    int bit = n % 10;
    sum += bit;
    n /= 10;
  }

  tmp % sum == 0 ? cout << "Yes" << endl : cout << "No" << endl;
}
Problem p03316 (C++)

Buggy submission (status: Runtime Error):
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {

  string N;
  long long sum = 0;

  cin >> N;

  for (int i = 0; i < N.size(); i++) {
    sum += atoi((char *)N[i]);
  }

  long long v;
  std::istringstream iss1(N);
  iss1 >> v;

  if (v % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Fixed submission:
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {

  string N;
  long long sum = 0;

  cin >> N;

  for (int i = 0; i < N.size(); i++) {
    char c[2] = {0};
    c[0] = N[i];
    sum += atoi(c);
  }

  long long v;
  std::istringstream iss1(N);
  iss1 >> v;

  if (v % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
Problem p03316 (C++)

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

int main() {
  //
  string str;
  long long num;
  long long sum = 0;

  cin >> num >> str;

  for (int i = 0; i < str.size(); i++) {
    sum += str.at(i) - '0';
  }

  if (num % sum == 0)
    cout << "Yes";
  else
    cout << "No";
}


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

int main() {
  //
  string str;
  long long num;
  long long sum = 0;

  cin >> num;
  str = to_string(num);
  for (int i = 0; i < str.size(); i++) {
    sum += str.at(i) - '0';
  }

  if (num % sum == 0)
    cout << "Yes";
  else
    cout << "No";
}
Problem p03316 (C++)

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int tmp = 0;
  int m = n;

  while (n) {
    tmp = n % 2;
    n /= 10;
  }

  if (m % tmp == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int tmp = 0;
  int m = n;

  while (n) {
    tmp += n % 10;
    n /= 10;
  }

  if (m % tmp == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p03316 (C++)

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

int main() {
  string N;
  cin >> N;
  int S = 0;
  for (int i = 0; i < N.size(), i++;) {
    S += N[i] - '0';
  }
  if (stoi(N) % S == 0) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}

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

int main() {
  string N;
  cin >> N;
  int S = 0;
  for (int i = 0; i < N.size(); i++) {
    S += N[i] - '0';
  }
  if (stoi(N) % S == 0) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}
Problem p03317 (C++)

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

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  if (n == k) {
    cout << 1 << endl;
    return 0;
  }
  int min_num = 1e6;
  int min_p = 0;
  rep(i, n) {
    cin >> a[i];
    if (min_num > a[i]) {
      min_num = a[i];
      min_p = i;
    }
  }
  int lp = min_p;
  int rp = min_p;
  int ans = 0;
  bool continue_flg = true;
  while (1) {
    if (lp <= 0) {
      break;
    }
    continue_flg = true;
    for (int i = lp; i >= lp - k + 1; i--) {
      if (a[i] != min_num)
        continue_flg = false;
    }
    if (continue_flg)
      continue;
    ans++;
    lp -= k - 1;
  }
  while (1) {
    if (n - 1 <= rp) {
      break;
    }
    continue_flg = true;
    for (int i = rp; i <= rp + k - 1; i++) {
      if (a[i] != min_num)
        continue_flg = false;
    }
    if (continue_flg)
      continue;
    ans++;
    rp += k - 1;
  }
  cout << ans << endl;
  return 0;
}

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

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

int main() {
  int n, k;
  cin >> n >> k;
  if ((n - k) % (k - 1) == 0)
    cout << (n - k) / (k - 1) + 1 << endl;
  else
    cout << (n - k) / (k - 1) + 2 << endl;
  return 0;
}
Problem p03317 (C++)

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

int CX(int A, int B) {
  int t = 0;
  if (A % B == 0) {
    t += A / B;
  } else {
    t++;
    t += A / B;
  }
  return t;
}

int main(void) {

  int N, K;
  cin >> N >> K;
  int tempN = N;
  int data[N];
  int minplace;
  int i;
  int R, L;
  for (i = 0; i < N; i++) {
    cin >> data[i];
    if (data[i] == 1) {
      minplace = i;
      if (i > N / 2) { // 左寄りにする
        i = N - i;
      }
      L = i;
      R = N - i - 1;
    }
  }
  int ans = 1;
  ans += CX(N - K, K - 1);
  // if(minplace<K){
  //     ans++;
  //     N-=K;
  //     //cout << N<< endl;
  //     ans+=CX(N,K-1);
  //     // while(N>0){
  //     //     ans++;
  //     //     N-=(K-1);
  //     // }

  // }else{
  //     // ans++;
  //     // L-=K-1;
  //     // while(L>0){
  //     //     ans++;
  //     //     L-=K-1;
  //     // }
  //     // ans++;
  //     // R-=K-1;
  //     // while(R>0){
  //     //     ans++;
  //     //     R-=K-1;
  //     // }
  //     ans++;
  //     N-=K;
  //     //cout << N<< endl;
  //     ans+=CX(N,K-1);

  // }

  // cout << minplace<<endl;
  cout << ans << endl;

  return 0;
}

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

int CX(int A, int B) {
  int t = 0;
  if (A % B == 0) {
    t += A / B;
  } else {
    t++;
    t += A / B;
  }
  return t;
}

int main(void) {

  int N, K;
  cin >> N >> K;
  int tempN = N;
  int data[N];
  int minplace;
  int i;
  int R, L;
  // for(i=0;i<N;i++){
  //     cin>>data[i];
  //     if(data[i]==1){
  //         minplace=i;
  //         if(i>N/2){//左寄りにする
  //             i = N-i;
  //         }
  //         L=i;
  //         R=N-i-1;
  //     }
  // }
  int ans = 1;
  ans += CX(N - K, K - 1);
  // if(minplace<K){
  //     ans++;
  //     N-=K;
  //     //cout << N<< endl;
  //     ans+=CX(N,K-1);
  //     // while(N>0){
  //     //     ans++;
  //     //     N-=(K-1);
  //     // }

  // }else{
  //     // ans++;
  //     // L-=K-1;
  //     // while(L>0){
  //     //     ans++;
  //     //     L-=K-1;
  //     // }
  //     // ans++;
  //     // R-=K-1;
  //     // while(R>0){
  //     //     ans++;
  //     //     R-=K-1;
  //     // }
  //     ans++;
  //     N-=K;
  //     //cout << N<< endl;
  //     ans+=CX(N,K-1);

  // }

  // cout << minplace<<endl;
  cout << ans << endl;

  return 0;
}
Problem p03317 (C++)

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

using namespace std;

const int MAXN = 10000;
int A[MAXN + 1];

int main() {
  int n, k, mn = MAXN;
  scanf("%d%d", &n, &k);

  for (int i = 1; i <= n; i++)
    scanf("%d", &A[i]);
  int pos;
  for (int i = 1; i <= n; i++)
    if (A[i] == 1)
      pos = i;

  for (int i = 0; i < k; i++) {
    int sum = ((pos - (i + 1)) + k - 2) / (k - 1);
    sum += (n - pos + i + k - 2) / (k - 1);
    mn = min(mn, sum);
  }

  printf("%d", mn);
  return 0;
}


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

using namespace std;

const int MAXN = 100000;
int A[MAXN + 1];

int main() {
  int n, k, mn = MAXN;
  scanf("%d%d", &n, &k);

  for (int i = 1; i <= n; i++)
    scanf("%d", &A[i]);
  int pos;
  for (int i = 1; i <= n; i++)
    if (A[i] == 1)
      pos = i;

  for (int i = 0; i < k; i++) {
    int sum = ((pos - (i + 1)) + k - 2) / (k - 1);
    sum += (n - pos + i + k - 2) / (k - 1);
    mn = min(mn, sum);
  }

  printf("%d", mn);
  return 0;
}
Problem p03317 (C++)

Buggy submission (status: Runtime Error):

#include <iostream>

using namespace std;

int main() {
  int N, K, A[8], times = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  times++;
  N -= K;

  while (N > 0) {
    times++;
    N -= (K - 1);
  }

  cout << times;
  return 0;
}

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int N, K, A[99999], times = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  times++;
  N -= K;

  while (N > 0) {
    times++;
    N -= (K - 1);
  }

  cout << times;
  return 0;
}
Problem p03317 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int, int> P; // d, v
const int max_n = 300;
const int INF = 1e6;
struct edge {
  int from, to, cost;
};
bool comp(const edge &e1, const edge &e2) { return e1.cost < e2.cost; }
int n, ml, md, k;
vector<edge> G[max_n];
int dist[max_n];
int dist2[max_n];
edge es[max_n];
int a, b, c;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> dist[i];
  }
  ll ans = 1 + (n - k + k - 2) / (k - 1);
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int, int> P; // d, v
const int max_n = 300;
const int INF = 1e6;
struct edge {
  int from, to, cost;
};
bool comp(const edge &e1, const edge &e2) { return e1.cost < e2.cost; }
int n, ml, md, k;
vector<edge> G[max_n];
int dist[max_n];
int dist2[max_n];
edge es[max_n];
int a, b, c;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
  }
  ll ans = 1 + (n - k + k - 2) / (k - 1);
  cout << ans << endl;
  return 0;
}
Problem p03317 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define MOD 1000000007
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define int long long
#define ALL(A) A.begin(), A.end()
using vi = vector<int>;
using vii = vector<vi>;
signed main() {
  int N, K, Q;
  cin >> N >> K;
  rep(i, 0, N) {
    int X;
    cin >> X;
    if (X == 1) {
      Q = i + 1;
      break;
    }
  }
  cout << (Q - 4 + K) / (K - 2) + (N - Q + K - 3) / (K - 2) << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define MOD 1000000007
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define int long long
#define ALL(A) A.begin(), A.end()
using vi = vector<int>;
using vii = vector<vi>;
signed main() {
  int N, K, Q;
  cin >> N >> K;
  rep(i, 0, N) {
    int X;
    cin >> X;
    if (X == 1) {
      Q = i + 1;
      break;
    }
  }
  int X = (Q - 3 + K) / (K - 1);
  int Y = max(X * (K - 1) + 1, Q);
  cout << X + (N - Y + K - 2) / (K - 1) << endl;
}