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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<vector<int>> ans(2, vector<int>(k, -1));
  int cnt = 0;
  rep(i, n) {
    if (s[i] == 'x')
      continue;
    else {
      ans[0][cnt] = i;
      i += c;
      cnt++;
      if (cnt >= n)
        break;
    }
  }
  cnt = k - 1;
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == 'x')
      continue;
    else {
      ans[1][cnt] = i;
      i -= c;
      cnt--;
      if (cnt < 0)
        break;
    }
  }
  rep(i, k) {
    if (ans[0][i] == ans[1][i])
      cout << ans[0][i] + 1 << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<vector<int>> ans(2, vector<int>(k, -1));
  int cnt = 0;
  rep(i, n) {
    if (s[i] == 'x')
      continue;
    else {
      ans[0][cnt] = i;
      i += c;
      cnt++;
      if (cnt >= k)
        break;
    }
  }
  cnt = k - 1;
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == 'x')
      continue;
    else {
      ans[1][cnt] = i;
      i -= c;
      cnt--;
      if (cnt < 0)
        break;
    }
  }
  rep(i, k) {
    if (ans[0][i] == ans[1][i])
      cout << ans[0][i] + 1 << endl;
  }
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define VI vector<int>
#define pii pair<int, int>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = 1e5;
char S[MAXN + 10];
int dp[2][MAXN + 10];
int n, k, x;
int main() {
  scanf("%d %d %d", &n, &k, &x);
  scanf("%s", S);
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    if (S[i - 1] == 'x')
      dp[0][i] = dp[0][i - 1];
    else
      dp[0][i] = 1 + (i - x - 1 >= 0 ? dp[0][i - x - 1] : 0);
  }
  dp[1][n + 1] = 0;
  for (int i = n; i > 0; i--) {
    if (S[i - 1] == 'x')
      dp[1][i] = dp[1][i + 1];
    else
      dp[1][i] = 1 + (i + x + 1 <= n + 1 ? dp[1][i + x + 1] : 0);
  }
  // for(int i = 1; i <= n; i++) printf("%d ", dp[1][i]); printf("\n");
  for (int i = 0; i < n; i++) {
    if (dp[0][i] + dp[1][i + 2] < k)
      printf("%d\n", i + 1);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define VI vector<int>
#define pii pair<int, int>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = 2e5;
char S[MAXN + 10];
int dp[2][MAXN + 10];
int n, k, x;
int main() {
  scanf("%d %d %d", &n, &k, &x);
  scanf("%s", S);
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    if (S[i - 1] == 'x')
      dp[0][i] = dp[0][i - 1];
    else
      dp[0][i] = 1 + (i - x - 1 >= 0 ? dp[0][i - x - 1] : 0);
  }
  dp[1][n + 1] = 0;
  for (int i = n; i > 0; i--) {
    if (S[i - 1] == 'x')
      dp[1][i] = dp[1][i + 1];
    else
      dp[1][i] = 1 + (i + x + 1 <= n + 1 ? dp[1][i + x + 1] : 0);
  }
  // for(int i = 1; i <= n; i++) printf("%d ", dp[1][i]); printf("\n");
  for (int i = 0; i < n; i++) {
    if (dp[0][i] + dp[1][i + 2] < k)
      printf("%d\n", i + 1);
  }
  return 0;
}
Problem p02721 (C++)

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

int main() {
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;

  vector<int> left(k), right(k);
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      left[count] = i + 1;
      count += 1;
      i += c;
      if (count == k)
        break;
    }
  }
  count = k - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      right[count] = i + 1;
      count -= 1;
      i -= c;
      if (count == k)
        break;
    }
  }
  /*
  for(int i=0; i<k; i++) cout << left[i] << " ";
  cout << endl;
  for(int i=0; i<k; i++) cout << right[i] << " ";
  cout << endl;
  */
  for (int i = 0; i < k; i++) {
    if (left[i] == right[i])
      cout << left[i] << endl;
  }
  return 0;
}

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

int main() {
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;

  vector<int> left(k), right(k);
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      left[count] = i + 1;
      count += 1;
      i += c;
      if (count == k)
        break;
    }
  }
  count = k - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      right[count] = i + 1;
      count -= 1;
      i -= c;
      if (count == -1)
        break;
    }
  }
  /*
  for(int i=0; i<k; i++) cout << left[i] << " ";
  cout << endl;
  for(int i=0; i<k; i++) cout << right[i] << " ";
  cout << endl;
  */
  for (int i = 0; i < k; i++) {
    if (left[i] == right[i])
      cout << left[i] << endl;
  }
  return 0;
}
Problem p02721 (C++)

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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 998244353;

struct fast_io {
  fast_io() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
  };
} fio;

signed main() {
  cout << fixed << setprecision(10);

  int n, K, C;
  string s;
  vector<int> con1, con2, sum;
  vector<int> hoge1, hoge2;

  cin >> n >> K >> C;
  cin >> s;

  con1.resize(n + 1);
  con2.resize(n + 2);
  sum.resize(n + 1);
  hoge1.resize(n + 2, -1);
  hoge2.resize(n + 2, -1);

  for (int i = 0; i < n; i++) {
    sum[i + 1] = sum[i] + (s[i] == 'o');
  }

  for (int i = 1; i <= n; i++) {
    int b = i - C - 1;
    int c = 0;

    if (b >= 0)
      c = con1[b];

    con1[i] = max(con1[i - 1], (int)c + (s[i - 1] == 'o'));
    if (hoge1[con1[i]] == -1)
      hoge1[con1[i]] = i - 1;
  }

  for (int i = n; i >= 1; i--) {
    int b = i + C + 1;
    int c = 0;

    if (b <= n + 1)
      c = con2[b];

    con2[i] = max(con2[i + 1], (int)c + (s[i - 1] == 'o'));
    if (hoge2[K - con2[i]] == -1)
      hoge2[K - con2[i]] = i - 1;
  }

  // cout<<"con1 n = "<<con1[n]<<endl;

  for (int i = 1, x = 0; i <= K; i++) {
    // cout<<"i = "<<i<<" hoge "<<hoge1[i] <<" "<<hoge2[i-1]<<endl;
    if (hoge1[i] == hoge2[i - 1] && hoge1[i] != -1) {
      cout << hoge1[i] + 1 << endl;
    }
  }

  return 0;
}


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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 998244353;

struct fast_io {
  fast_io() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
  };
} fio;

signed main() {
  cout << fixed << setprecision(10);

  int n, K, C;
  string s;
  vector<int> con1, con2, sum;
  vector<int> hoge1, hoge2;

  cin >> n >> K >> C;
  cin >> s;

  con1.resize(n + 1);
  con2.resize(n + 2);
  sum.resize(n + 1);
  hoge1.resize(n + 2, -1);
  hoge2.resize(n + 2, -1);

  for (int i = 0; i < n; i++) {
    sum[i + 1] = sum[i] + (s[i] == 'o');
  }

  for (int i = 1; i <= n; i++) {
    int b = i - C - 1;
    int c = 0;

    if (b >= 0)
      c = con1[b];

    con1[i] = max(con1[i - 1], (int)c + (s[i - 1] == 'o'));
    if (hoge1[con1[i]] == -1)
      hoge1[con1[i]] = i - 1;
  }

  if (con1[n] > K) {
    return 0;
  }

  for (int i = n; i >= 1; i--) {
    int b = i + C + 1;
    int c = 0;

    if (b <= n + 1)
      c = con2[b];

    con2[i] = max(con2[i + 1], (int)c + (s[i - 1] == 'o'));
    if (hoge2[K - con2[i]] == -1)
      hoge2[K - con2[i]] = i - 1;
  }

  // cout<<"con1 n = "<<con1[n]<<endl;

  for (int i = 1, x = 0; i <= K; i++) {
    // cout<<"i = "<<i<<" hoge "<<hoge1[i] <<" "<<hoge2[i-1]<<endl;
    if (hoge1[i] == hoge2[i - 1] && hoge1[i] != -1) {
      cout << hoge1[i] + 1 << endl;
    }
  }

  return 0;
}
Problem p02721 (C++)

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

int main() {
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  vector<int> P, Q, ans;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      P.push_back(i + 1);
      i += c;
    }
  }
  reverse(s.begin(), s.end());
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      Q.push_back(n - i);
      i += c;
    }
  }

  if (P.size() != k || Q.size() != k) {
    return 0;
  }

  else {
    sort(P.begin(), P.end());
    sort(Q.begin(), Q.end());
    int i = 0, j = 0;
    while (i != P.size() || j != Q.size()) {
      if (P[i] > Q[j])
        j++;
      else if (P[i] == Q[j]) {
        ans.push_back(P[i]);
        i++, j++;
      } else
        i++;
    }
    rep(k, ans.size()) cout << ans[k] << endl;
  }
}

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

int main() {
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  vector<int> P, Q, ans;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      P.push_back(i + 1);
      i += c;
    }
  }
  reverse(s.begin(), s.end());
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      Q.push_back(n - i);
      i += c;
    }
  }

  if (P.size() != k || Q.size() != k) {
    return 0;
  }

  else {
    sort(P.begin(), P.end());
    sort(Q.begin(), Q.end());
    int i = 0, j = 0;
    while (i != P.size() && j != Q.size()) {
      if (P[i] > Q[j])
        j++;
      else if (P[i] == Q[j]) {
        ans.push_back(P[i]);
        i++, j++;
      } else
        i++;
    }
    rep(k, ans.size()) cout << ans[k] << endl;
  }
}
Problem p02721 (C++)

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

const ll maxs = 2e5 + 5;
const ll lmaxs = 20;
ll mod = 1e9 + 7;
ll oo = 1e15;

#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr);                                                            \
  cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre() {}

void solve() {
  ll n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<ll> a, b;
  for (ll i = 0; i < n; i++) {
    if (s[i] == 'o') {
      a.pb(i);
      i += c;
    }
  }
  for (ll i = n - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      b.pb(i);
      i -= c;
    }
  }
  // reverse(b.begin(),b.end());
  vector<ll> ANS;
  for (ll i = 0; i < k; i++) {
    if (a[i] == b[k - i - 1]) {
      ANS.pb(a[i] + 1);
    }
  }

  for (auto it : ANS)
    cout << it << endl;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input00.txt", "r", stdin);
#endif
  IOS;
  pre();
  ll T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}

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

const ll maxs = 2e5 + 5;
const ll lmaxs = 20;
ll mod = 1e9 + 7;
ll oo = 1e15;

#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr);                                                            \
  cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre() {}

void solve() {
  ll n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<ll> a, b;
  for (ll i = 0; i < n; i++) {
    if (s[i] == 'o') {
      a.pb(i);
      i += c;
    }
  }
  for (ll i = n - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      b.pb(i);
      i -= c;
    }
  }
  // reverse(b.begin(),b.end());
  vector<ll> ANS;
  for (ll i = 0; i < k; i++) {
    if (a[i] == b[k - i - 1]) {
      ANS.pb(a[i] + 1);
    }
  }

  for (auto it : ANS)
    cout << it << endl;
}

int main() {

  IOS;
  pre();
  ll T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
/*Code by Codercjh*/
#include <bits/stdc++.h>
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
using namespace std;
typedef long long ll;
template <typename T> inline void read(T &x) {
  char c = getchar();
  T fh = 0;
  bool f = false;
  while (!isdigit(c))
    f |= (c == '-'), c = getchar();
  while (isdigit(c))
    fh = (fh << 1) + (fh << 3) + (c ^ 48), c = getchar();
  x = f ? -fh : fh;
  return;
}
int n, k, c, cnt, ans;
char s[200005];
int l[200005], r[200005];
int main() {
  read(n), read(k), read(c);
  cin >> s + 1;
  fr(i, 1, n) if (s[i] == 'o') l[++cnt] = i, i += c;
  int cnt1 = k;
  rf(i, n, 1) if (s[i] == 'o') r[cnt1--] = i, i -= c;
  fr(i, 1, k) if (l[i] == r[i]) printf("%d\n", l[i]);
  return 0;
}


Fixed submission:
/*Code by Codercjh*/
#include <bits/stdc++.h>
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
using namespace std;
typedef long long ll;
template <typename T> inline void read(T &x) {
  char c = getchar();
  T fh = 0;
  bool f = false;
  while (!isdigit(c))
    f |= (c == '-'), c = getchar();
  while (isdigit(c))
    fh = (fh << 1) + (fh << 3) + (c ^ 48), c = getchar();
  x = f ? -fh : fh;
  return;
}
int n, k, c, cnt, ans;
char s[200005];
int l[200005], r[200005];
int main() {
  read(n), read(k), read(c);
  cin >> s + 1;
  fr(i, 1, n) if (s[i] == 'o') l[++cnt] = i, i += c;
  int cnt1 = k;
  rf(i, n, 1) {
    if (s[i] == 'o')
      r[cnt1--] = i, i -= c;
    if (!cnt1)
      break;
  }
  fr(i, 1, k) if (l[i] == r[i]) printf("%d\n", l[i]);
  return 0;
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

  int n, k, c;
  cin >> n >> k >> c;

  string s;
  cin >> s;

  vector<bool> ans(n, false); // 働かなくてもいい日はtrue
  vector<int> work;
  int prev = -c - 1;

  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      if (prev + c < i && work.size() < k) {
        work.push_back(i);
        prev = i;
      } else {
        ans[i] = true;
      }
    }
  }

  int idx = k - 1;
  prev = n + c + 1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'x')
      continue;
    if (i > work[idx]) {
      if (i + c < prev) {
        ans[work[idx]] = true;
        prev = i;
        idx--;
      }
    } else if (i == work[idx]) {
      idx--;
      prev = i;
    }
  }

  for (int i = 0; i < n; i++) {
    if (s[i] == 'o' && ans[i] == false) {
      cout << i + 1 << '\n';
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

  int n, k, c;
  cin >> n >> k >> c;

  string s;
  cin >> s;

  vector<bool> ans(n, false); // 働かなくてもいい日はtrue
  vector<int> work;
  int prev = -c - 1;

  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      if (prev + c < i && work.size() < k) {
        work.push_back(i);
        prev = i;
      } else {
        ans[i] = true;
      }
    }
  }

  int idx = k - 1;
  prev = n + c + 1;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'x')
      continue;
    if (i > work[idx]) {
      if (i + c < prev) {
        ans[work[idx]] = true;
        prev = i;
        idx--;
      }
    } else if (i == work[idx]) {
      idx--;
      prev = i;
    }

    if (idx == -1)
      break;
  }

  for (int i = 0; i < n; i++) {
    if (s[i] == 'o' && ans[i] == false) {
      cout << i + 1 << '\n';
    }
  }

  return 0;
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long LL;

const int maxn = 100000 + 10;
int L[maxn][2], R[maxn][2];
char str[maxn];

int main() {
  int i, j, n, K, C;
  scanf("%d%d%d", &n, &K, &C);
  scanf("%s", str + 1);
  for (i = 1; i <= n; i++) {
    if (str[i] == 'x') {
      L[i][0] = max(L[i - 1][0], L[i - 1][1]);
      L[i][1] = L[i][0];
    } else {
      L[i][0] = max(L[i - 1][0], L[i - 1][1]);
      int v = 0;
      if (i - C > 1)
        v = L[i - C - 1][1];
      L[i][1] = v + 1;
    }
    L[i][0] = max(L[i][0], L[i - 1][0]);
    L[i][1] = max(L[i][1], L[i - 1][1]);
    // printf("i=%d L0=%d L1=%d\n",i,L[i][0],L[i][1]);
  }
  for (i = n; i >= 1; i--) {
    if (str[i] == 'x') {
      R[i][0] = max(R[i + 1][0], R[i + 1][1]);
      R[i][1] = R[i][0];
    } else {
      R[i][0] = max(R[i + 1][0], R[i + 1][1]);
      int v = 0;
      if (i + C + 1 <= n)
        v = max(R[i + C + 1][1], R[i + C + 1][1]);
      R[i][1] = v + 1;
    }
    R[i][0] = max(R[i][0], R[i + 1][0]);
    R[i][1] = max(R[i][1], R[i + 1][1]);
    // printf("i=%d R0=%d R1=%d\n",i,R[i][0],R[i][1]);
  }

  for (i = 1; i <= n; i++) {
    if (str[i] == 'x')
      continue;
    if (L[i][0] + R[i][0] == K - 1)
      printf("%d\n", i);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long LL;

const int maxn = 200000 + 10;
int L[maxn][2], R[maxn][2];
char str[maxn];

int main() {
  int i, j, n, K, C;
  scanf("%d%d%d", &n, &K, &C);
  scanf("%s", str + 1);
  for (i = 1; i <= n; i++) {
    if (str[i] == 'x') {
      L[i][0] = max(L[i - 1][0], L[i - 1][1]);
      L[i][1] = L[i][0];
    } else {
      L[i][0] = max(L[i - 1][0], L[i - 1][1]);
      int v = 0;
      if (i - C > 1)
        v = L[i - C - 1][1];
      L[i][1] = v + 1;
    }
    L[i][0] = max(L[i][0], L[i - 1][0]);
    L[i][1] = max(L[i][1], L[i - 1][1]);
    // printf("i=%d L0=%d L1=%d\n",i,L[i][0],L[i][1]);
  }
  for (i = n; i >= 1; i--) {
    if (str[i] == 'x') {
      R[i][0] = max(R[i + 1][0], R[i + 1][1]);
      R[i][1] = R[i][0];
    } else {
      R[i][0] = max(R[i + 1][0], R[i + 1][1]);
      int v = 0;
      if (i + C + 1 <= n)
        v = max(R[i + C + 1][1], R[i + C + 1][1]);
      R[i][1] = v + 1;
    }
    R[i][0] = max(R[i][0], R[i + 1][0]);
    R[i][1] = max(R[i][1], R[i + 1][1]);
    // printf("i=%d R0=%d R1=%d\n",i,R[i][0],R[i][1]);
  }

  for (i = 1; i <= n; i++) {
    if (str[i] == 'x')
      continue;
    if (L[i][0] + R[i][0] == K - 1)
      printf("%d\n", i);
  }
  return 0;
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <stack>
using namespace std;
typedef long long ll;
ll n, k, c, lst;
bool flag;
string s;
ll cnt;
bool vis[100010];
stack<int> stk;
int main() {
  cin >> n >> k >> c;
  cin >> s;
  lst = -1;
  for (int i = 0; i < (int)(s.length()); i++) {
    if (s[i] == 'x' || lst >= i)
      continue;
    if (cnt >= k) {
      flag = 1;
      break;
    }
    lst = i + c;
    vis[i] = 1;
    cnt++;
  }
  if (flag) {
    return 0;
  }
  lst = s.length();
  for (int i = (int)s.length() - 1; i >= 0; i--) {
    if (s[i] == 'x' || lst <= i)
      continue;
    lst = i - c;
    if (vis[i]) {
      stk.push(i);
    }
  }
  while (!stk.empty()) {
    cout << stk.top() + 1 << endl;
    ;
    stk.pop();
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <stack>
using namespace std;
typedef long long ll;
ll n, k, c, lst;
bool flag;
string s;
ll cnt;
bool vis[200010];
stack<int> stk;
int main() {
  cin >> n >> k >> c;
  cin >> s;
  lst = -1;
  for (int i = 0; i < (int)(s.length()); i++) {
    if (s[i] == 'x' || lst >= i)
      continue;
    if (cnt >= k) {
      flag = 1;
      break;
    }
    lst = i + c;
    vis[i] = 1;
    cnt++;
  }
  if (flag) {
    return 0;
  }
  lst = s.length();
  for (int i = (int)s.length() - 1; i >= 0; i--) {
    if (s[i] == 'x' || lst <= i)
      continue;
    lst = i - c;
    if (vis[i]) {
      stk.push(i);
    }
  }
  while (!stk.empty()) {
    cout << stk.top() + 1 << endl;
    ;
    stk.pop();
  }
  return 0;
}
Problem p02721 (C++)

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

using namespace std;

vector<int> buf;

int main(int argc, char *argv[]) {
  int N, K, C;
  string s;
  cin >> N >> K >> C;
  cin >> s;

  buf.resize(K, -1);

  int num = K;
  int cur = N - 1;

  while (cur >= 0) {
    if (s[cur] == 'x') {
      --cur;
      continue;
    }

    buf[--num] = cur;
    if (num == 0) {
      break;
    }

    cur -= C + 1;
  }

  cur = 0;
  num = 0;

  while (cur < N) {
    if (s[cur] == 'x') {
      ++cur;
      continue;
    }

    if (buf[num++] == cur) {
      cout << cur + 1 << endl;
    }

    if (num == N) {
      break;
    }

    cur += C + 1;
  }
}


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

using namespace std;

vector<int> buf;

int main(int argc, char *argv[]) {
  int N, K, C;
  string s;
  cin >> N >> K >> C;
  cin >> s;

  buf.resize(K, -1);

  int num = K;
  int cur = N - 1;

  while (cur >= 0) {
    if (s[cur] == 'x') {
      --cur;
      continue;
    }

    buf[--num] = cur;
    if (num == 0) {
      break;
    }

    cur -= C + 1;
  }

  cur = 0;
  num = 0;

  while (cur < N) {
    if (s[cur] == 'x') {
      ++cur;
      continue;
    }

    if (buf[num++] == cur) {
      cout << cur + 1 << endl;
    }

    if (num == K) {
      break;
    }

    cur += C + 1;
  }
}
Problem p02721 (C++)

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

vector<int64_t> memo;

int64_t greedy(const string &s, int64_t index, int64_t C) {
  if (index >= s.size() || memo[index] != -1) {
    return memo[index];
  }

  for (int64_t i = index; i < s.size(); i++) {
    if (s[i] == 'o') {
      return memo[index] = (1 + greedy(s, i + C + 1, C));
    }
  }

  return memo[index] = 0;
}

int main() {
  int64_t N, K, C;
  string S;

  cin >> N >> K >> C >> S;
  memo.resize(N + 1, -1);

  vector<int64_t> ans;
  for (int64_t i = 0; i < S.size(); i++) {
    if (S[i] == 'x') {
      continue;
    }

    // S[i] == 'o'
    // ここが必須かどうか
    // S[i] = 'x'として判定してみる
    // ダメなら必須
    int64_t num = greedy(S, i + 1, C);
    if (num < K) {
      ans.push_back(i + 1);
    }

    // ここをオフにしない場合、絶対に選ぶのが得
    K--;
    i += C;
  }

  for (int64_t value : ans) {
    cout << value << endl;
  }
}

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

vector<int64_t> memo;

int64_t greedy(const string &s, int64_t index, int64_t C) {
  if (index >= s.size()) {
    return 0;
  }
  if (memo[index] != -1) {
    return memo[index];
  }

  for (int64_t i = index; i < s.size(); i++) {
    if (s[i] == 'o') {
      return memo[index] = (1 + greedy(s, i + C + 1, C));
    }
  }

  return memo[index] = 0;
}

int main() {
  int64_t N, K, C;
  string S;

  cin >> N >> K >> C >> S;
  memo.resize(N + 1, -1);

  vector<int64_t> ans;
  for (int64_t i = 0; i < S.size(); i++) {
    if (S[i] == 'x') {
      continue;
    }

    // S[i] == 'o'
    // ここが必須かどうか
    // S[i] = 'x'として判定してみる
    // ダメなら必須
    int64_t num = greedy(S, i + 1, C);
    if (num < K) {
      ans.push_back(i + 1);
    }

    // ここをオフにしない場合、絶対に選ぶのが得
    K--;
    i += C;
  }

  for (int64_t value : ans) {
    cout << value << endl;
  }
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int INF = 100000;
int main() {
  int N, K, C;
  cin >> N >> K >> C;
  string S;
  cin >> S;
  vector<int> G, G2;
  int p = -INF;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'o' && i > p + C) {
      G.push_back(i);
      p = i;
    }
    if (G.size() == K) {
      break;
    }
  }
  p = INF;
  for (int i = N - 1; i >= 0; i--) {
    if (S[i] == 'o' && i < p - C) {
      G2.push_back(i);
      p = i;
    }
    if (G2.size() == K) {
      break;
    }
  }
  reverse(G2.begin(), G2.end());
  for (int i = 0; i < K; i++) {
    if (G[i] == G2[i]) {
      cout << G[i] + 1 << endl;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000;
int main() {
  int N, K, C;
  cin >> N >> K >> C;
  string S;
  cin >> S;
  vector<int> G, G2;
  int p = -INF;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'o' && i > p + C) {
      G.push_back(i);
      p = i;
    }
    if (G.size() == K) {
      break;
    }
  }
  p = INF;
  for (int i = N - 1; i >= 0; i--) {
    if (S[i] == 'o' && i < p - C) {
      G2.push_back(i);
      p = i;
    }
    if (G2.size() == K) {
      break;
    }
  }
  reverse(G2.begin(), G2.end());
  for (int i = 0; i < K; i++) {
    if (G[i] == G2[i]) {
      cout << G[i] + 1 << endl;
    }
  }
}
Problem p02721 (C++)

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

int l[101010], r[101010];

int main() {
  int N, K, C;
  cin >> N >> K >> C;
  string S;
  cin >> S;

  int cur = 1;
  for (int i = 0; i < N; ++i) {
    if (S[i] == 'o') {
      l[i] = cur++;
      i += C;
    }
    if (cur > K)
      break;
  }

  cur = K;
  for (int i = N - 1; i >= 0; --i) {
    if (S[i] == 'o') {
      r[i] = cur--;
      i -= C;
    }
    if (cur < 0)
      break;
  }

  for (int i = 0; i < N; ++i) {
    // cout << l[i] << ", " << r[i] << endl;
    if (l[i] > 0 and l[i] == r[i]) {
      cout << i + 1 << endl;
    }
  }
}


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

int l[201010], r[201010];

int main() {
  int N, K, C;
  cin >> N >> K >> C;
  string S;
  cin >> S;

  int cur = 1;
  for (int i = 0; i < N; ++i) {
    if (S[i] == 'o') {
      l[i] = cur++;
      i += C;
    }
    if (cur > K)
      break;
  }

  cur = K;
  for (int i = N - 1; i >= 0; --i) {
    if (S[i] == 'o') {
      r[i] = cur--;
      i -= C;
    }
    if (cur < 0)
      break;
  }

  for (int i = 0; i < N; ++i) {
    // cout << l[i] << ", " << r[i] << endl;
    if (l[i] > 0 and l[i] == r[i]) {
      cout << i + 1 << endl;
    }
  }
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, c;
  vector<int> a, b;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++)
    if (s[i] == 'o') {
      a.push_back(i);
      i += c;
    };
  for (int i = n - 1; i > 0; i--)
    if (s[i] == 'o') {
      b.push_back(i);
      i -= c;
    };
  for (int i = 0; i < k; i++)
    if (a[i] == b[k - i - 1]) {
      cout << a[i] + 1 << '\n';
    };
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, c;
  vector<int> a, b;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++)
    if (s[i] == 'o') {
      a.push_back(i);
      i += c;
    };
  for (int i = n - 1; i >= 0; i--)
    if (s[i] == 'o') {
      b.push_back(i);
      i -= c;
    };
  for (int i = 0; i < k; i++)
    if (a[i] == b[k - i - 1]) {
      cout << a[i] + 1 << '\n';
    };
  return 0;
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
// const int mod=1e9+7;
const int mod = 998244353;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int maxn = 2e5 + 10;
const ll inf = 0x3f3f3f3f;
const int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

int l[maxn], r[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  int cnt = k - 1, mx = n;
  for (int i = s.length() - 1; i >= 0; i--)
    if (s[i] == 'o' && i < mx)
      r[cnt] = i, mx = i - c, cnt--;
  cnt = 0, mx = -1;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == 'o' && i > mx)
      l[cnt] = i, mx = i + c, cnt++;
  for (int i = 0; i < k; i++)
    if (l[i] == r[i])
      cout << l[i] + 1 << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
// const int mod=1e9+7;
const int mod = 998244353;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int maxn = 2e5 + 10;
const ll inf = 0x3f3f3f3f;
const int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

int l[maxn], r[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  int cnt = k - 1, mx = n;
  for (int i = s.length() - 1; i >= 0; i--)
    if (s[i] == 'o' && i < mx && cnt >= 0)
      r[cnt] = i, mx = i - c, cnt--;
  cnt = 0, mx = -1;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == 'o' && i > mx)
      l[cnt] = i, mx = i + c, cnt++;
  for (int i = 0; i < k; i++)
    if (l[i] == r[i])
      cout << l[i] + 1 << endl;
  return 0;
}
Problem p02721 (C++)

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

int main() {

  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  vector<int> ans1, ans2;

  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      ans1.push_back(i);
      i += c;
    }
  }

  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      ans2.push_back(i);
      i -= c;
    }
  }

  if (ans1.size() == k) {
    for (auto n : ans1) {
      if (find(ans2.begin(), ans2.end(), n) != ans2.end()) {
        cout << n + 1 << endl;
      }
    }
  }

  return 0;
}

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

int main() {

  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  vector<int> ans1, ans2;

  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      ans1.push_back(i);
      i += c;
    }
  }

  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      ans2.push_back(i);
      i -= c;
    }
  }

  if (ans1.size() == k) {
    for (auto n : ans1) {
      if (binary_search(ans2.rbegin(), ans2.rend(), n)) {
        cout << n + 1 << endl;
      }
    }
  }

  return 0;
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 110000;
char s[N];
int l[N], r[N];
int n, k, c;
int main() {
  scanf("%d%d%d%s", &n, &k, &c, s + 1);

  int i = 1, kk = 1;
  while (kk <= k) {
    if (s[i] == 'o')
      l[kk++] = i, i += c;
    ++i;
  }

  i = n, kk = k;
  while (kk) {
    if (s[i] == 'o')
      r[kk--] = i, i -= c;
    --i;
  }

  for (i = 1; i <= k; ++i)
    if (l[i] == r[i])
      printf("%d\n", l[i]);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 220000;
char s[N];
int l[N], r[N];
int n, k, c;
int main() {
  scanf("%d%d%d%s", &n, &k, &c, s + 1);

  int i = 1, kk = 1;
  while (kk <= k) {
    if (s[i] == 'o')
      l[kk++] = i, i += c;
    ++i;
  }

  i = n, kk = k;
  while (kk) {
    if (s[i] == 'o')
      r[kk--] = i, i -= c;
    --i;
  }

  for (i = 1; i <= k; ++i)
    if (l[i] == r[i])
      printf("%d\n", l[i]);

  return 0;
}
Problem p02722 (C++)

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

bool check(ll n, ll k) {
  if (n == 1)
    return true;
  if (n < k)
    return false;
  if (n % k == 0) {
    return check(n / k, k);
  } else {
    return check(n % k, k);
  }
}

vector<ll> get_div(ll n) {
  vector<ll> res;
  for (ll d = 2; d * d <= n; d++) {
    if (n % d == 0) {
      res.push_back(d);
      if (d < n / d) {
        res.push_back(n / d);
      }
    }
  }
  return res;
}

int main(void) {
  ll n;
  cin >> n;
  set<ll> res;
  auto divs = get_div(n);
  for (ll d : divs) {
    if (check(n, d))
      res.insert(d);
  }
  auto divs2 = get_div(n - 1);
  for (ll d : divs2) {
    if (check(n, d))
      res.insert(d);
  }
  if (check(n, n))
    res.insert(n);
  if (check(n, n - 1))
    res.insert(n - 1);
  cout << res.size() << endl;
  return 0;
}


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

bool check(ll n, ll k) {
  if (n == 1)
    return true;
  if (n < k)
    return false;
  if (n % k == 0) {
    return check(n / k, k);
  } else {
    return check(n % k, k);
  }
}

vector<ll> get_div(ll n) {
  vector<ll> res;
  for (ll d = 2; d * d <= n; d++) {
    if (n % d == 0) {
      res.push_back(d);
      if (d < n / d) {
        res.push_back(n / d);
      }
    }
  }
  return res;
}

int main(void) {
  ll n;
  cin >> n;
  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }
  set<ll> res;
  auto divs = get_div(n);
  for (ll d : divs) {
    if (check(n, d))
      res.insert(d);
  }
  auto divs2 = get_div(n - 1);
  for (ll d : divs2) {
    if (check(n, d))
      res.insert(d);
  }
  if (check(n, n))
    res.insert(n);
  if (check(n, n - 1))
    res.insert(n - 1);
  cout << res.size() << endl;
  return 0;
}
Problem p02722 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
vector<ll> enumDivisor(ll x) {
  vector<ll> res;
  for (int i = 1; i * i <= x; ++i) {
    if (x % i)
      continue;
    res.push_back(i);
    if (i * i != x)
      res.push_back(x / i);
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  ll n;
  cin >> n;
  int ans = 0;
  for (auto x : enumDivisor(n)) {
    if (x == 1)
      continue;
    ll tmp = n;
    while (tmp % x == 0)
      tmp /= x;
    if (tmp % x == 1)
      ++ans;
  }
  ans += enumDivisor(n - 1).size() - 1;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
vector<ll> enumDivisor(ll x) {
  vector<ll> res;
  for (ll i = 1; i * i <= x; ++i) {
    if (x % i)
      continue;
    res.push_back(i);
    if (i * i != x)
      res.push_back(x / i);
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  ll n;
  cin >> n;
  int ans = 0;
  for (auto x : enumDivisor(n)) {
    if (x == 1)
      continue;
    ll tmp = n;
    while (tmp % x == 0)
      tmp /= x;
    if (tmp % x == 1)
      ++ans;
  }
  ans += enumDivisor(n - 1).size() - 1;
  cout << ans << endl;
}
Problem p02722 (C++)

Buggy submission (status: Runtime Error):
// cout << "Case #" << k << ": ";
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int main() {
  ll n;
  cin >> n;
  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }
  ll ans = 0;
  auto res = divisor(n - 1);
  ans += res.size() - 1;
  res = divisor(n);
  for (auto e : res) {
    if (e == 1) {
      continue;
    }
    ll a = 1;
    while (n % (a * e) == 0) {
      a *= e;
    }
    ll m = n / a;
    if (m % e == 1) {
      ans++;
    }
  }
  cout << ans << endl;
}


Fixed submission:
// cout << "Case #" << k << ": ";
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int main() {
  ll n;
  cin >> n;
  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }
  ll ans = 0;
  auto res = divisor(n - 1);
  ans += res.size() - 1;
  res = divisor(n);
  for (auto e : res) {
    if (e == 1) {
      continue;
    }
    ll a = 1;
    while (n % (a * e) == 0) {
      a *= e;
      if (a * e == 0) {
        break;
      }
    }
    ll m = n / a;
    if (m % e == 1) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02722 (C++)

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

#define lli long long int
#define REP(i, s, n) for (int i = s; i < n; i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL << 50)
#define DEBUG 0
#define mp(a, b) make_pair(a, b)
#define SORT(V) sort(V.begin(), V.end())
#define PI (3.141592653589794)

set<lli> yaku(lli num) {
  set<lli> rtn;
  for (lli i = 1; i * i <= num; i++) {
    rtn.insert(i);
    rtn.insert(num / i);
  }
  return rtn;
}
bool ok(lli n, lli k) {
  if (n == 1)
    return true;
  if (n < k)
    return false;
  if (n % k == 0)
    return ok(n / k, k);
  else
    return ok(n % k, k);
}

void func(long long N) {
  set<lli> y = yaku(N);
  set<lli> yy = yaku(N - 1);

  lli cnt = 0;

  for (auto e : y) {
    if (e == 1)
      continue;
    if (ok(N, e))
      cnt++;
  }
  for (auto e : yy) {
    if (y.find(e) != y.end())
      continue;
    if (ok(N, e))
      cnt++;
  }
  cout << cnt << endl;
}

int main() {
  // cout << fixed << setprecision(5);

  long long N;
  scanf("%lld", &N);
  func(N);
  return 0;
}


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

#define lli long long int
#define REP(i, s, n) for (int i = s; i < n; i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL << 50)
#define DEBUG 0
#define mp(a, b) make_pair(a, b)
#define SORT(V) sort(V.begin(), V.end())
#define PI (3.141592653589794)

set<lli> yaku(lli num) {
  set<lli> rtn;
  for (lli i = 1; i * i <= num; i++) {
    if (num % i == 0) {
      rtn.insert(i);
      rtn.insert(num / i);
    }
  }
  return rtn;
}
bool ok(lli n, lli k) {
  if (n == 1)
    return true;
  if (n < k)
    return false;
  if (n % k == 0)
    return ok(n / k, k);
  else
    return ok(n % k, k);
}

void func(long long N) {
  set<lli> y = yaku(N);
  set<lli> yy = yaku(N - 1);

  lli cnt = 0;

  for (auto e : y) {
    if (e == 1)
      continue;
    if (ok(N, e))
      cnt++;
  }
  for (auto e : yy) {
    if (y.find(e) != y.end())
      continue;
    if (ok(N, e))
      cnt++;
  }
  cout << cnt << endl;
}

int main() {
  // cout << fixed << setprecision(5);

  long long N;
  scanf("%lld", &N);
  func(N);
  return 0;
}
Problem p02722 (C++)

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

int main() {
  ll n;
  cin >> n;
  vector<ll> g;

  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i != 1)
        g.push_back(i);
      if (n / i != i)
        g.push_back(n / i);
    }
  }
  for (ll i = 1; i * i <= n - 1; i++) {
    if ((n - 1) % i == 0) {
      if (i != 1)
        g.push_back(i);
      if ((n - 1) / i != i)
        g.push_back((n - 1) / i);
    }
  }

  int ans = 0;
  for (ll x : g) {
    ll dn = n;
    while (dn >= x) {
      if (dn % x == 0)
        dn /= x;
      else
        dn -= x;
    }
    if (dn == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  ll n;
  cin >> n;
  vector<ll> g;

  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i != 1)
        g.push_back(i);
      if (n / i != i)
        g.push_back(n / i);
    }
  }
  for (ll i = 1; i * i <= n - 1; i++) {
    if ((n - 1) % i == 0) {
      if (i != 1)
        g.push_back(i);
      if ((n - 1) / i != i)
        g.push_back((n - 1) / i);
    }
  }

  int ans = 0;
  for (ll x : g) {
    ll dn = n;
    while (dn >= x) {
      if (dn % x == 0)
        dn /= x;
      else
        dn %= x;
    }
    if (dn == 1)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02722 (C++)

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;

vector<pair<ll, ll>> factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 2; i * i <= n; ++i) {
    ll temp = n;
    if (temp % i)
      continue;
    while (temp % i == 0) {
      temp /= i;
    }
    if (temp % i == 1)
      ans++;
  }
  auto v = factorize(n - 1);
  ll yakusuu = 1;
  rep(i, v.size()) { yakusuu *= v[i].second + 1; }
  yakusuu--;
  ans += yakusuu + 1;
  cout << ans << endl;
  return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;

vector<pair<ll, ll>> factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i)
      continue;
    res.emplace_back(i, 0);
    while (n % i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1)
    res.emplace_back(n, 1);
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 2; i * i <= n; ++i) {
    ll temp = n;
    if (temp % i)
      continue;
    while (temp % i == 0) {
      temp /= i;
    }
    if (temp % i == 1)
      ans++;
  }
  auto v = factorize(n - 1);
  ll yakusuu = 1;
  rep(i, v.size()) { yakusuu *= v[i].second + 1; }
  yakusuu--;
  ans += yakusuu + 1;
  cout << ans << endl;
  return 0;
}
Problem p02722 (C++)

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

using namespace std;
using ll = long long;

int main() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> num;
  rep(k, 2) {
    n -= (ll)k;
    num.push_back(n);
    for (ll i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        num.push_back(i);
        if (i * i != n)
          num.push_back(n / i);
      }
    }
    n += k;
  }
  for (ll i : num) {
    ll a = n;
    while (a % i == 0)
      a /= i;
    if (a % i == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> num;
  rep(k, 2) {
    n -= (ll)k;
    if (n != 1)
      num.push_back(n);
    for (ll i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        num.push_back(i);
        if (i * i != n)
          num.push_back(n / i);
      }
    }
    n += k;
  }
  for (ll i : num) {
    ll a = n;
    while (a % i == 0)
      a /= i;
    if (a % i == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02722 (C++)

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
  ll n;
  cin >> n;
  set<ll> m;
  ll sq = sqrt(n);

  repd(i, 2, sq + 1) {
    if (n % i == 0) {
      m.insert(i);
      m.insert(n / i);
    }
    if ((n - 1) % i == 0) {
      m.insert(i);
      m.insert((n - 1) / i);
    }
  }

  m.insert(n - 1);
  m.insert(n);
  ll ans = 0;
  for (auto num : m) {
    ll temp = n;
    while (temp > 0) {
      if (temp % num == 0) {
        temp /= num;
      } else {
        temp %= num;
      }

      if (temp == 1) {
        ans++;
        break;
      } else if (temp < num) {
        if (temp < num) {
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
  ll n;
  cin >> n;
  set<ll> m;
  ll sq = sqrt(n);

  repd(i, 2, sq + 1) {
    if (n % i == 0) {
      m.insert(i);
      m.insert(n / i);
    }
    if ((n - 1) % i == 0) {
      m.insert(i);
      m.insert((n - 1) / i);
    }
  }

  m.insert(n - 1);
  m.insert(n);
  ll ans = 0;
  for (auto iter = m.begin(); iter != m.end(); iter++) {
    ll num = *iter;
    if (num == 1) {
      continue;
    }
    ll temp = n;
    while (temp > 0) {
      if (temp % num == 0) {
        temp /= num;
      } else {
        temp %= num;
      }

      if (temp == 1) {
        ans++;
        break;
      } else if (temp < num) {
        if (temp < num) {
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02722 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>

using namespace std;

typedef long long ll;
typedef double db;

ll mod = 1e9 + 7;

ll a[500][2];

int main() {
  ll n;
  int count = 0;
  cin >> n;
  ll s = 0;
  if (n == 2)
    s--;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 1) {
      if ((n - 1) / i == i)
        s++;
      else
        s += 2;

    } else if (n % i == 0) {
      a[count][0] = i;
      a[count][1] = n / i;
      count++;
    }
  }
  for (int j = 0; j < count; j++) {
    while (a[j][1] >= a[j][0]) {
      if (a[j][1] % a[j][0] == 1) {
        s++;
        break;
      } else if (a[j][1] % a[j][0] == 0)
        a[j][1] = a[j][1] / a[j][0];
      else
        break;
    }
    if (a[j][1] == 1)
      s++;
  }
  cout << s + 2;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>

using namespace std;

typedef long long ll;
typedef double db;

ll mod = 1e9 + 7;

ll a[10000][2];

int main() {
  ll n;
  int count = 0;
  cin >> n;
  ll s = 0;
  if (n == 2)
    s--;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 1) {
      if ((n - 1) / i == i)
        s++;
      else
        s += 2;

    } else if (n % i == 0) {
      a[count][0] = i;
      a[count][1] = n / i;
      count++;
    }
  }
  for (int j = 0; j < count; j++) {
    while (a[j][1] >= a[j][0]) {
      if (a[j][1] % a[j][0] == 1) {
        s++;
        break;
      } else if (a[j][1] % a[j][0] == 0)
        a[j][1] = a[j][1] / a[j][0];
      else
        break;
    }
    if (a[j][1] == 1)
      s++;
  }
  cout << s + 2;
  return 0;
}