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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for (int i = 0; i < n; i++)

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

ll beki(ll a, ll b) {
  ll tmp = 1;
  REP(i, b) tmp *= a;
  return tmp;
}

ll K;
queue<ll> que;
ll ans[100010];
ll num = 0;
ll nowNum = 0;

int main() {

  cin >> K;

  // queに1の桁をつめる
  for (ll i = 1; i <= 9; i++) {
    que.push(i);
    ans[num] = i;
    num++;
    nowNum++;
  }

  // queにつまってるやつまでのをやるまでやる
  while (true) {
    // n回めはn桁のものをn+1桁にする
    for (ll i = 0; i < nowNum; i++) {
      for (ll j = -1; j <= 1; j++) {
        // ここで0、1、2とかを後ろにつける
        ll a = que.front();
        ll b = a % 10;

        if (b == 0 && j == -1)
          continue;
        if (b == 9 && j == 1)
          continue;
        que.push(a * 10 + b + j);
        ans[num] = a * 10 + b + j;
        num++;
        if (num == K) {
          cout << ans[K - 1] << endl;
          // REP(i, K) {
          //     cout << ans[i] << endl;
          // }
          return 0;
        }
      }
      que.pop();
    }

    // 最後にもどす
    nowNum = num - nowNum;
  }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for (int i = 0; i < n; i++)

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

ll beki(ll a, ll b) {
  ll tmp = 1;
  REP(i, b) tmp *= a;
  return tmp;
}

ll K;
queue<ll> que;
ll ans[100010];
ll num = 0;
ll nowNum = 0;

int main() {

  cin >> K;
  if (K <= 9) {
    cout << K << endl;
    return 0;
  }
  // queに1の桁をつめる
  for (ll i = 1; i <= 9; i++) {
    que.push(i);
    ans[num] = i;
    num++;
    nowNum++;
  }

  // queにつまってるやつまでのをやるまでやる
  while (true) {
    // n回めはn桁のものをn+1桁にする
    for (ll i = 0; i < nowNum; i++) {
      for (ll j = -1; j <= 1; j++) {
        // ここで0、1、2とかを後ろにつける
        ll a = que.front();
        ll b = a % 10;

        if (b == 0 && j == -1)
          continue;
        if (b == 9 && j == 1)
          continue;
        que.push(a * 10 + b + j);
        ans[num] = a * 10 + b + j;
        num++;
        if (num == K) {
          cout << ans[K - 1] << endl;
          // REP(i, K) {
          //     cout << ans[i] << endl;
          // }
          return 0;
        }
      }
      que.pop();
    }

    // 最後にもどす
    nowNum = num - nowNum;
  }
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
#define M 100005
int sl[M], mp[M], vs[M];
char S[M];
inline void rd(int &l) {
  l = 0;
  int f = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-')
      f = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    l = l * 10 + ch - '0';
    ch = getchar();
  }
  if (f)
    l = -l;
}
int main() {
  int N, K, C, tp = 1;
  rd(N);
  rd(K);
  rd(C);
  scanf("%s", S + 1);
  for (int i = 1; i <= N; ++i)
    mp[i] = (S[i] == 'x');
  for (int i = 1; i <= K; ++i) {
    while (tp <= N && mp[tp])
      ++tp;
    sl[i] = tp;
    tp += C + 1;
  }
  if (K && sl[K]) {
    tp = N;
    for (int i = K; i; --i) {
      while (tp && mp[tp])
        --tp;
      vs[i] = tp;
      // printf("%d %d\n",sl[i],vs[i]);
      tp -= C + 1;
    }
    for (int i = 1; i <= K; ++i)
      if (vs[i] == sl[i])
        printf("%d\n", vs[i]);
  }
  // getchar();
  // getchar();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
#define M 200005
int sl[M], mp[M], vs[M];
char S[M];
inline void rd(int &l) {
  l = 0;
  int f = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-')
      f = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    l = l * 10 + ch - '0';
    ch = getchar();
  }
  if (f)
    l = -l;
}
int main() {
  int N, K, C, tp = 1;
  rd(N);
  rd(K);
  rd(C);
  scanf("%s", S + 1);
  for (int i = 1; i <= N; ++i)
    mp[i] = (S[i] == 'x');
  for (int i = 1; i <= K; ++i) {
    while (tp <= N && mp[tp])
      ++tp;
    sl[i] = tp;
    tp += C + 1;
  }
  if (K && sl[K]) {
    tp = N;
    for (int i = K; i; --i) {
      while (tp && mp[tp])
        --tp;
      vs[i] = tp;
      // printf("%d %d\n",sl[i],vs[i]);
      tp -= C + 1;
    }
    for (int i = 1; i <= K; ++i)
      if (vs[i] == sl[i])
        printf("%d\n", vs[i]);
  }
  // getchar();
  // getchar();
  return 0;
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for (int V = S; V < E; V++)
#define ford(V, S, E) for (int V = S; V >= E; V--)
#define fore(E, X) for (auto &E : X)
#define println(X) cout << X << endl
#define printe(X)                                                              \
  for (auto &E : X)                                                            \
    cout << E << " ";                                                          \
  cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int L[200001], R[200001];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  int wd = 0, cd = 0;
  forl(i, 0, n) {
    if (cd) {
      cd--;
      continue;
    }
    if (s[i] != 'o')
      continue;
    L[wd++] = i;
    cd = c;
  }
  wd = k - 1, cd = 0;
  ford(i, n - 1, 0) {
    if (cd) {
      cd--;
      continue;
    }
    if (s[i] != 'o')
      continue;
    R[wd--] = i;
    cd = c;
  }
  vector<int> ans;
  forl(i, 0, k) {
    if (R[i] == L[i])
      ans.push_back(R[i] + 1);
  }
  printe(ans);
}


Fixed submission:
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for (int V = S; V < E; V++)
#define ford(V, S, E) for (int V = S; V >= E; V--)
#define fore(E, X) for (auto &E : X)
#define println(X) cout << X << endl
#define printe(X)                                                              \
  for (auto &E : X)                                                            \
    cout << E << " ";                                                          \
  cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int L[200001], R[200001];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  int wd = 0, cd = 0;
  forl(i, 0, n) {
    if (cd) {
      cd--;
      continue;
    }
    if (s[i] != 'o')
      continue;
    L[wd++] = i;
    cd = c;
  }
  wd = k - 1, cd = 0;
  ford(i, n - 1, 0) {
    if (cd) {
      cd--;
      continue;
    }
    if (s[i] != 'o' or wd < 0)
      continue;
    R[wd--] = i;
    cd = c;
  }
  vector<int> ans;
  forl(i, 0, k) {
    if (R[i] == L[i])
      ans.push_back(R[i] + 1);
  }
  printe(ans);
}
Problem p02721 (C++)

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

#define ll long long
#define ld long double
#define F first
#define S second

// #define ONLINE_JUDGE 1

using namespace std;

const int mod = 1e9 + 7;
const int MAX = 100001;

void pr(vector<int> v) {
  for (int x : v) {
    cout << x << " ";
  }
  cout << "\n";
}

void solve() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> lf(n);
  vector<int> rt(n);
  int t = 1;
  int p = -MAX;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      int d = i - p;
      if (d > c) {
        lf[i] = t++;
        p = i;
      }
      if (t > k)
        break;
    }
  }
  reverse(s.begin(), s.end());
  t = k;
  p = -MAX;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      int d = i - p;
      if (d > c) {
        rt[i] = t--;
        p = i;
      }
      // if(t > k) break;
    }
  }
  reverse(rt.begin(), rt.end());
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (rt[i] == lf[i] && rt[i] > 0) {
      cout << i + 1 << "\n";
    }
  }
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}

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

#define ll long long
#define ld long double
#define F first
#define S second

#define ONLINE_JUDGE 1

using namespace std;

const int mod = 1e9 + 7;
const int MAX = 100001;

void pr(vector<int> v) {
  for (int x : v) {
    cout << x << " ";
  }
  cout << "\n";
}

void solve() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> lf(n);
  vector<int> rt(n);
  int t = 1;
  int p = -MAX;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      int d = i - p;
      if (d > c) {
        lf[i] = t++;
        p = i;
      }
      if (t > k)
        break;
    }
  }
  reverse(s.begin(), s.end());
  t = k;
  p = -MAX;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      int d = i - p;
      if (d > c) {
        rt[i] = t--;
        p = i;
      }
      // if(t > k) break;
    }
  }
  reverse(rt.begin(), rt.end());
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (rt[i] == lf[i] && rt[i] > 0) {
      cout << i + 1 << "\n";
    }
  }
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

char s[100010];
int a[100010], l[100010], r[100010], b[100010];
int n, k, c;

int main() {
  scanf("%d%d%d", &n, &k, &c);
  scanf("%s", s);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'x')
      a[i + 1] = 0;
    else
      a[i + 1] = 1;
  }
  for (int i = 1; i <= c + 1; i++)
    l[i] = a[i];
  for (int i = c + 2; i <= n; i++) {
    l[i] = l[i - 1];
    if (a[i] == 1) {
      l[i] = max(l[i], l[i - c - 1] + 1);
    }
  }
  int ans = l[n];
  if (ans > k)
    return 0;
  for (int i = n; i >= n - c - 1 && i >= 1; i--)
    r[i] = ans;
  for (int i = n - c - 1; i >= 1; i--) {
    r[i] = r[i + 1];
    if (a[i] == 1) {
      r[i] = min(r[i], r[i + c + 1] - 1);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (l[i] == r[i]) {
      b[l[i]]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (l[i] == r[i]) {
      if (b[l[i]] == 1)
        printf("%d\n", i);
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

char s[200010];
int a[200010], l[200010], r[200010], b[200010];
int n, k, c;

int main() {
  scanf("%d%d%d", &n, &k, &c);
  scanf("%s", s);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'x')
      a[i + 1] = 0;
    else
      a[i + 1] = 1;
  }
  for (int i = 1; i <= c + 1; i++)
    l[i] = a[i];
  for (int i = c + 2; i <= n; i++) {
    l[i] = l[i - 1];
    if (a[i] == 1) {
      l[i] = max(l[i], l[i - c - 1] + 1);
    }
  }
  int ans = l[n];
  if (ans > k)
    return 0;
  for (int i = n; i >= n - c - 1 && i >= 1; i--)
    r[i] = ans;
  for (int i = n - c - 1; i >= 1; i--) {
    r[i] = r[i + 1];
    if (a[i] == 1) {
      r[i] = min(r[i], r[i + c + 1] - 1);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (l[i] == r[i]) {
      b[l[i]]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (l[i] == r[i]) {
      if (b[l[i]] == 1)
        printf("%d\n", i);
    }
  }
  return 0;
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 1e5 + 5;
bool valid[maxn];
int l_minn[maxn], r_minn[maxn];
int main() {
  int n, k, c;
  scanf("%d%d%d", &n, &k, &c);
  char s;
  scanf("%c", &s);
  for (int i = 1; i <= n; i++) {
    scanf("%c", &s);
    valid[i] = (s == 'o');
  }
  int cur = -c;
  for (int i = 1; i <= k; i++) {
    for (int j = cur + c + 1; j <= n; j++)
      if (valid[j]) {
        l_minn[i] = j;
        cur = j;
        break;
      }
  }
  reverse(valid + 1, valid + n + 1);
  cur = -c;
  for (int i = 1; i <= k; i++) {
    for (int j = cur + c + 1; j <= n; j++)
      if (valid[j]) {
        r_minn[i] = n + 1 - j;
        cur = j;
        break;
      }
  }
  reverse(r_minn + 1, r_minn + k + 1);
  for (int i = 1; i <= k; i++)
    if (l_minn[i] == r_minn[i] && l_minn[i])
      printf("%d\n", l_minn[i]);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 2e5 + 5;
bool valid[maxn];
int l_minn[maxn], r_minn[maxn];
int main() {
  int n, k, c;
  scanf("%d%d%d", &n, &k, &c);
  char s;
  scanf("%c", &s);
  for (int i = 1; i <= n; i++) {
    scanf("%c", &s);
    valid[i] = (s == 'o');
  }
  int cur = -c;
  for (int i = 1; i <= k; i++) {
    for (int j = cur + c + 1; j <= n; j++)
      if (valid[j]) {
        l_minn[i] = j;
        cur = j;
        break;
      }
  }
  reverse(valid + 1, valid + n + 1);
  cur = -c;
  for (int i = 1; i <= k; i++) {
    for (int j = cur + c + 1; j <= n; j++)
      if (valid[j]) {
        r_minn[i] = n + 1 - j;
        cur = j;
        break;
      }
  }
  reverse(r_minn + 1, r_minn + k + 1);
  for (int i = 1; i <= k; i++)
    if (l_minn[i] == r_minn[i] && l_minn[i])
      printf("%d\n", l_minn[i]);
  return 0;
}
Problem p02721 (C++)

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

int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> a(2e5, 0), b(2e5, 0);
  for (int i = 0, cur = 0; i < n; i++) {
    if (s[i] == 'o') {
      a[cur++] = i;
      i += c;
    }
  }
  for (int i = n - 1, cur = k - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      b[cur--] = i;
      i -= c;
    }
  }
  for (int i = 0; i < k; i++) {
    if (a[i] == b[i])
      cout << a[i] + 1 << endl;
  }
}

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

int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  int a[200000];
  int b[200000];
  for (int i = 0, cur = 0; i < n; i++) {
    if (s[i] == 'o') {
      a[cur++] = i;
      i += c;
    }
  }
  for (int i = n - 1, cur = k - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      b[cur--] = i;
      i -= c;
    }
  }
  for (int i = 0; i < k; i++) {
    if (a[i] == b[i])
      cout << a[i] + 1 << endl;
  }
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <sstream>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
typedef stringstream ss;
const int mii = numeric_limits<int>::min();
const int mai = numeric_limits<int>::max();
const ll mil = numeric_limits<long long>::min();
const ll mal = numeric_limits<long long>::max();

#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define RREP(i, a, b) for (int i = a; i >= b; --i)
#define PB(x) push_back(x)

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

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

  vi l(k);
  vi r(k);

  int cc = 0;

  int kc = 0;
  REP(i, 0, n - 1 && kc < k) {
    if (cc > 0) {
      cc--;
      continue;
    }

    if (s[i] == 'o') {
      l[kc] = i;
      ++kc;
      cc = c;
    }
  }

  kc = k - 1;
  cc = 0;
  RREP(i, n - 1, 0 && kc < k) {
    if (cc > 0) {
      cc--;
      continue;
    }

    if (s[i] == 'o') {
      r[kc] = i;
      kc--;
      cc = c;
    }
  }

  REP(i, 0, k - 1) {
    if (l[i] == r[i])
      cout << l[i] + 1 << endl;
  }
}

Fixed submission:
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <sstream>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
typedef stringstream ss;
const int mii = numeric_limits<int>::min();
const int mai = numeric_limits<int>::max();
const ll mil = numeric_limits<long long>::min();
const ll mal = numeric_limits<long long>::max();

#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define RREP(i, a, b) for (int i = a; i >= b; --i)
#define PB(x) push_back(x)

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

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

  vi l(k);
  vi r(k);

  int cc = 0;

  int kc = 0;
  REP(i, 0, n - 1 && kc < k) {
    if (cc > 0) {
      cc--;
      continue;
    }

    if (s[i] == 'o') {
      l[kc] = i;
      ++kc;
      cc = c;
    }
  }

  kc = k - 1;
  cc = 0;
  RREP(i, n - 1, 0 && kc >= 0) {
    if (cc > 0) {
      cc--;
      continue;
    }

    if (s[i] == 'o') {
      r[kc] = i;
      kc--;
      cc = c;
    }
  }

  REP(i, 0, k - 1) {
    if (l[i] == r[i])
      cout << l[i] + 1 << endl;
  }
}
Problem p02721 (C++)

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

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

Buggy submission (status: Runtime Error):
#include <cstdio>
int n, k, c, f[100003][2];
char s[200003];
int main() {
  scanf("%d%d%d%s", &n, &k, &c, s + 1);
  int i, j = 0;
  for (i = 1; i <= n; i++) {
    if (s[i] == 'o' && i > j)
      f[i][0] = f[i - 1][0] + 1, j = i + c;
    else
      f[i][0] = f[i - 1][0];
  }
  j = n + 1;
  for (i = n; i >= 1; i--) {
    if (s[i] == 'o' && i < j)
      f[i][1] = f[i + 1][1] + 1, j = i - c;
    else
      f[i][1] = f[i + 1][1];
  }
  for (int i = 1; i <= n; i++)
    if (f[i - 1][0] + 1 + f[i + 1][1] == k)
      printf("%d\n", i);
  return 0;
}

Fixed submission:
#include <cstdio>
int n, k, c, f[200003][2];
char s[200003];
int main() {
  scanf("%d%d%d%s", &n, &k, &c, s + 1);
  int i, j = 0;
  for (i = 1; i <= n; i++) {
    if (s[i] == 'o' && i > j)
      f[i][0] = f[i - 1][0] + 1, j = i + c;
    else
      f[i][0] = f[i - 1][0];
  }
  j = n + 1;
  for (i = n; i >= 1; i--) {
    if (s[i] == 'o' && i < j)
      f[i][1] = f[i + 1][1] + 1, j = i - c;
    else
      f[i][1] = f[i + 1][1];
  }
  for (int i = 1; i <= n; i++)
    if (f[i - 1][0] + 1 + f[i + 1][1] == k)
      printf("%d\n", i);
  return 0;
}
Problem p02721 (C++)

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;

int l[200010];
int r[200010];

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

  int num = 0;
  int now = 0;
  while (now < n) {
    if (s[now] == 'o') {
      l[++num] = now;
      now += c + 1;
    } else {
      now++;
    }
  }

  num = k;
  now = n - 1;
  while (now >= 0) {
    if (s[now] == 'o') {
      r[num--] = now;
      now -= c + 1;
    } else {
      now--;
    }
  }

  for (int i = 1; i <= k; ++i) {
    if (l[i] == r[i]) {
      cout << l[i] + 1 << endl;
    }
  }
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;

int l[200010];
int r[200010];

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

  int num = 0;
  int now = 0;
  while (now < n) {
    if (s[now] == 'o') {
      l[++num] = now;
      now += c + 1;
    } else {
      now++;
    }
  }

  num = k;
  now = n - 1;
  while (now >= 0) {
    if (s[now] == 'o') {
      r[num--] = now;
      if (num <= 0)
        break;
      now -= c + 1;
    } else {
      now--;
    }
  }

  for (int i = 1; i <= k; ++i) {
    if (l[i] == r[i]) {
      cout << l[i] + 1 << endl;
    }
  }
}
Problem p02721 (C++)

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

signed main() {
  int n, k, c;
  bool isWorkDays[200000];
  cin >> n >> k >> c;
  for (int i = 0; i < n; i++) {
    char charaWork;
    cin >> charaWork;
    isWorkDays[i] = (charaWork == 'o');
  }

  int holiday = c;

  int needsWorkAfter[100000];
  int needsWorkBefore[100000];
  int day = k - 1;
  for (int i = n - 1; i >= 0 || day >= 0; i--) {
    if (isWorkDays[i]) {
      needsWorkBefore[day] = i;
      i -= holiday;
      day--;
    }
  }

  day = 0;
  for (int i = 0; i < n || day < k; i++) {
    if (isWorkDays[i]) {
      needsWorkAfter[day] = i;
      i += holiday;
      day++;
    }
  }

  for (int i = 0; i < k; i++) {
    if (needsWorkAfter[i] == needsWorkBefore[i]) {
      cout << needsWorkAfter[i] + 1 << endl;
    }
  }
  return 0;
}


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

signed main() {
  int n, k, c;
  bool isWorkDays[200000];
  cin >> n >> k >> c;
  for (int i = 0; i < n; i++) {
    char charaWork;
    cin >> charaWork;
    isWorkDays[i] = (charaWork == 'o');
  }

  int holiday = c;

  int needsWorkAfter[200000];
  int needsWorkBefore[200000];
  int day = k - 1;
  for (int i = n - 1; i >= 0 || day >= 0; i--) {
    if (isWorkDays[i]) {
      needsWorkBefore[day] = i;
      i -= holiday;
      day--;
    }
  }

  day = 0;
  for (int i = 0; i < n || day < k; i++) {
    if (isWorkDays[i]) {
      needsWorkAfter[day] = i;
      i += holiday;
      day++;
    }
  }

  for (int i = 0; i < k; i++) {
    if (needsWorkAfter[i] == needsWorkBefore[i]) {
      cout << needsWorkAfter[i] + 1 << endl;
    }
  }
  return 0;
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

const int MAXS = 100010;
char str[MAXS];

int main() {
  int N;
  int K;
  int C;

  scanf("%d %d %d", &N, &K, &C);
  scanf("%s", str);

  vector<int> best(N);
  vector<int> slack(N, K);

  ++C;
  for (int i = 0; i < N; ++i) {
    if (i) {
      best[i] = max(best[i], best[i - 1]);
    }

    if (str[i] == 'o') {
      int preMax = 0;

      if (i - C >= 0) {
        preMax = best[i - C];
      }

      best[i] = max(best[i], preMax + 1);
    }
  }

  for (int i = N - 1; i >= 0; --i) {
    if (str[i] == 'o') {
      if (i - C >= 0) {
        slack[i - C] = min(slack[i - C], slack[i] - 1);
      }
    }

    if (i) {
      slack[i - 1] = min(slack[i - 1], slack[i]);
    }
  }

  // for (int i = 0; i < N; ++i) {
  //     cout << best[i] << " ";
  // }

  // cout << endl;

  // for (int i = 0; i < N; ++i) {
  //     cout << slack[i] << " ";
  // }

  // cout << endl;

  unordered_map<int, int> critCount;

  for (int i = 0; i < N; ++i) {
    if (slack[i] == best[i] && str[i] == 'o') {
      ++critCount[best[i]];
    }
  }

  for (int i = 0; i < N; ++i) {
    if (slack[i] == best[i] && str[i] == 'o' && critCount[best[i]] == 1) {
      cout << i + 1 << endl;
      ;
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

const int MAXS = 300010;
char str[MAXS];

int main() {
  int N;
  int K;
  int C;

  scanf("%d %d %d", &N, &K, &C);
  scanf("%s", str);

  vector<int> best(N);
  vector<int> slack(N, K);

  ++C;
  for (int i = 0; i < N; ++i) {
    if (i) {
      best[i] = max(best[i], best[i - 1]);
    }

    if (str[i] == 'o') {
      int preMax = 0;

      if (i - C >= 0) {
        preMax = best[i - C];
      }

      best[i] = max(best[i], preMax + 1);
    }
  }

  for (int i = N - 1; i >= 0; --i) {
    if (str[i] == 'o') {
      if (i - C >= 0) {
        slack[i - C] = min(slack[i - C], slack[i] - 1);
      }
    }

    if (i) {
      slack[i - 1] = min(slack[i - 1], slack[i]);
    }
  }

  // for (int i = 0; i < N; ++i) {
  //     cout << best[i] << " ";
  // }

  // cout << endl;

  // for (int i = 0; i < N; ++i) {
  //     cout << slack[i] << " ";
  // }

  // cout << endl;

  unordered_map<int, int> critCount;

  for (int i = 0; i < N; ++i) {
    if (slack[i] == best[i] && str[i] == 'o') {
      ++critCount[best[i]];
    }
  }

  for (int i = 0; i < N; ++i) {
    if (slack[i] == best[i] && str[i] == 'o' && critCount[best[i]] == 1) {
      cout << i + 1 << endl;
      ;
    }
  }

  return 0;
}
Problem p02721 (C++)

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

using namespace std;

const int N = 2e5 + 7;

int pre[N];
int n, m, k;
string s;
vector<int> ans;

int dp[N];

int solve(int i) {
  if (i >= n)
    return 0;
  if (dp[i] != -1)
    return dp[i];
  if (s[i] == 'o') {
    return 1 + solve(i + k + 1);
  }
  return dp[i] = solve(i + 1);
}

int main() {
  memset(dp, -1, sizeof dp);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("in.in" , "r" , stdin) ;

  cin >> n >> m >> k;
  cin >> s;

  for (int i = 0; i < n; i++) {
    solve(i);
  }

  int l = -1, sum = 0;
  for (int i = 0; i < n; i++) {
    pre[i] = sum;
    if (i <= l)
      continue;
    if (s[i] == 'o') {
      sum++;
      l = i + k;
    }
    pre[i] = sum;
  }
  int r = n + N;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      int leftix = min(i - 1, r - k - 1);
      int right = solve(i + 1);
      int left = (leftix < 0 ? 0 : pre[leftix]);
      if (right + left < m) {
        ans.push_back(i + 1);
      }
      if (solve(i) > solve(r))
        r = i;
    }
  }
  reverse(ans.begin(), ans.end());
  for (auto u : ans) {
    cout << u << "\n";
  }
  return 0;
}

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

using namespace std;

const int N = 2e5 + 7;

int pre[N];
int n, m, k;
string s;
vector<int> ans;

int dp[N];

int solve(int i) {
  if (i >= n)
    return 0;
  if (dp[i] != -1)
    return dp[i];
  if (s[i] == 'o') {
    return dp[i] = 1 + solve(i + k + 1);
  }
  return dp[i] = solve(i + 1);
}

int main() {
  memset(dp, -1, sizeof dp);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("in.in" , "r" , stdin) ;

  cin >> n >> m >> k;
  cin >> s;

  for (int i = 0; i < n; i++) {
    solve(i);
  }

  int l = -1, sum = 0;
  for (int i = 0; i < n; i++) {
    pre[i] = sum;
    if (i <= l)
      continue;
    if (s[i] == 'o') {
      sum++;
      l = i + k;
    }
    pre[i] = sum;
  }
  int r = n + N;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'o') {
      int leftix = min(i - 1, r - k - 1);
      int right = solve(i + 1);
      int left = (leftix < 0 ? 0 : pre[leftix]);
      if (right + left < m) {
        ans.push_back(i + 1);
      }
      if (solve(i) > solve(r))
        r = i;
    }
  }
  reverse(ans.begin(), ans.end());
  for (auto u : ans) {
    cout << u << "\n";
  }
  return 0;
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long n, k, c;
string s;
long long l[100100], r[100100];
vector<int> v;
int main() {
  cin >> n >> k >> c;
  cin >> s;
  long long sum = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == 'o') {
      sum++;
      v.push_back(i);
      i += c;
    }
  if (sum > k)
    return 0;
  if (s[0] == 'o')
    l[0] = 1;
  for (int i = 1; i < s.size(); i++) {
    if (i >= c + 1)
      l[i] = max(l[i - 1], l[i - c - 1] + (s[i] == 'o'));
    else
      l[i] = max(l[i - 1], (long long)(s[i] == 'o'));
  }
  for (int i = s.size() - 1; i >= 0; i--) {
    if (i + c + 1 < s.size())
      r[i] = max(r[i + 1], r[i + c + 1] + (s[i] == 'o'));
    else
      r[i] = max(r[i + 1], (long long)(s[i] == 'o'));
  }
  vector<int> ans;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] == 0 && sum != +r[v[i] + 1])
      cout << (v[i] + 1) << endl;
    else if (v[i] == s.size() - 1 && sum != l[v[i] - 1])
      cout << v[i] + 1 << endl;
    else if (sum != l[v[i] - 1] + r[v[i] + 1])
      cout << (v[i] + 1) << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long n, k, c;
string s;
long long l[200100], r[200100];
vector<int> v;
int main() {
  cin >> n >> k >> c;
  cin >> s;
  long long sum = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == 'o') {
      sum++;
      v.push_back(i);
      i += c;
    }
  if (sum > k)
    return 0;
  if (s[0] == 'o')
    l[0] = 1;
  for (int i = 1; i < s.size(); i++) {
    if (i >= c + 1)
      l[i] = max(l[i - 1], l[i - c - 1] + (s[i] == 'o'));
    else
      l[i] = max(l[i - 1], (long long)(s[i] == 'o'));
  }
  for (int i = s.size() - 1; i >= 0; i--) {
    if (i + c + 1 < s.size())
      r[i] = max(r[i + 1], r[i + c + 1] + (s[i] == 'o'));
    else
      r[i] = max(r[i + 1], (long long)(s[i] == 'o'));
  }
  vector<int> ans;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] == 0 && sum != +r[v[i] + 1])
      cout << (v[i] + 1) << endl;
    else if (v[i] == s.size() - 1 && sum != l[v[i] - 1])
      cout << v[i] + 1 << endl;
    else if (sum != l[v[i] - 1] + r[v[i] + 1])
      cout << (v[i] + 1) << endl;
  }
}
Problem p02721 (C++)

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

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

  int backcount = k;
  vector<int> v(n);
  for (int i = n - 1; i >= 0; i--) {
    if (s.at(i) == 'o') {
      v.at(backcount) = i;
      backcount--;
      i -= c;
    }
    if (backcount == 0) {
      break;
    }
    if (i < 0) {
      return 0;
    }
  }

  int frontcount = 1;
  for (int i = 0; i < n; i++) {
    if (s.at(i) == 'o') {
      if (v.at(frontcount) == i) {
        cout << i + 1 << endl;
      }
      frontcount++;
      i += c;
    }
  }
  return 0;
}

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

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

  int backcount = k;
  vector<int> v(n + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (s.at(i) == 'o') {
      v.at(backcount) = i;
      backcount--;
      i -= c;
    }
    if (backcount == 0) {
      break;
    }
    if (i < 0) {
      return 0;
    }
  }

  int frontcount = 1;
  for (int i = 0; i < n; i++) {
    if (s.at(i) == 'o') {
      if (v.at(frontcount) == i) {
        cout << i + 1 << endl;
      }
      frontcount++;
      i += c;
    }
  }
  return 0;
}
Problem p02721 (C++)

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

typedef long long ll;

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, K, C;
  cin >> N >> K >> C;

  string s;
  cin >> s;

  vector<int> dp(N + 1);
  dp[N] = 0;
  for (int i(N - 1); i >= 0; --i) {
    dp[i] = dp[i + 1];
    if (s[i] == 'o')
      dp[i] = max(dp[i], 1 + dp[min(N, i + C + 1)]);
  }

  int l(0);
  while (l < N and K > 0) {
    int r = l;
    int cnt(0);
    while (r < N and dp[r] >= K) {
      cnt += s[r++] == 'o';
    }
    if (cnt == 1)
      for (int i(l); i < r; ++i)
        if (s[i] == 'o') {
          cout << i + 1 << '\n';
          break;
        }
    --K;
    for (int i(l); i < r; ++i)
      if (s[i] == 'o') {
        l = i + C + 1;
        break;
      }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size())

typedef long long ll;

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, K, C;
  cin >> N >> K >> C;

  string s;
  cin >> s;

  vector<int> dp(N + 1);
  dp[N] = 0;
  for (int i(N - 1); i >= 0; --i) {
    dp[i] = dp[i + 1];
    if (s[i] == 'o')
      dp[i] = max(dp[i], 1 + dp[min(N, i + C + 1)]);
  }

  int l(0);
  while (l < N and K > 0) {
    int r = l;
    int cnt(0);
    while (r < N and dp[r] >= K and cnt <= 1) {
      cnt += s[r++] == 'o';
    }
    if (cnt == 1)
      for (int i(l); i < r; ++i)
        if (s[i] == 'o') {
          cout << i + 1 << '\n';
          break;
        }
    --K;
    for (int i(l); i < r; ++i)
      if (s[i] == 'o') {
        l = i + C + 1;
        break;
      }
  }
}
Problem p02721 (C++)

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

#define x first
#define y second
#define pb push_back
#define mp make_pair

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int INF = 1000000009;
const int MAXN = 2 * 100 * 1000;

char tab[MAXN + 3];
int ff[2 * MAXN + 3], bb[2 * MAXN + 3];

int main() {
  int n, k, c;
  scanf("%d %d %d", &n, &k, &c);
  scanf("%s", tab + 1);
  for (int i = n; i >= 1; i--)
    if (tab[i] == 'o')
      ff[i] = 1 + ff[min(n + 1, i + c + 1)];
    else
      ff[i] = ff[i + 1];
  vector<int> ans;
  int last = -c;
  for (int i = 1; i <= n; i++) {
    if (tab[i] == 'o') {
      if (bb[last] + ff[max(i + 1, last + c + 1)] < k)
        ans.pb(i);
      if (i > last + c) {
        bb[i] = bb[max(last, 0)] + 1;
        last = i;
      }
    }
  }

  for (auto a : ans)
    printf("%d\n", a);

  return 0;
}

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

#define x first
#define y second
#define pb push_back
#define mp make_pair

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int INF = 1000000009;
const int MAXN = 2 * 100 * 1000;

char tab[MAXN + 3];
int ff[2 * MAXN + 3], bb[2 * MAXN + 3];

int main() {
  int n, k, c;
  scanf("%d %d %d", &n, &k, &c);
  scanf("%s", tab + 1);
  for (int i = n; i >= 1; i--)
    if (tab[i] == 'o')
      ff[i] = 1 + ff[min(n + 1, i + c + 1)];
    else
      ff[i] = ff[i + 1];
  vector<int> ans;
  int last = -c;
  for (int i = 1; i <= n; i++) {
    if (tab[i] == 'o') {
      if (bb[max(last, 0)] + ff[max(i + 1, last + c + 1)] < k)
        ans.pb(i);
      if (i > last + c) {
        bb[i] = bb[max(last, 0)] + 1;
        last = i;
      }
    }
  }

  for (auto a : ans)
    printf("%d\n", a);

  return 0;
}
Problem p02721 (C++)

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD = 1e9 + 7;

int n, t, c, pos, vis[100010], sz = 0;
string s;
vector<int> v;

int main() {
  cin >> n >> t >> c >> s;
  pos = 0;
  while (s[pos] == 'x')
    pos++;
  while (pos < n) {
    sz++;
    vis[pos] = sz;
    pos += c + 1;
    while (pos < n && s[pos] == 'x')
      pos++;
  }
  pos = n - 1;
  while (s[pos] == 'x')
    pos--;
  while (pos >= 0) {
    v.pb(pos);
    pos -= c + 1;
    while (pos >= 0 && s[pos] == 'x')
      pos--;
  }
  reverse(v.begin(), v.end());
  rep(i, n) {
    if (vis[i] == 0)
      continue;
    int cur = vis[i] - 1, pos = upper_bound(v.begin(), v.end(), i) - v.begin();
    if (cur + v.size() - pos < t)
      cout << i + 1 << endl;
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD = 1e9 + 7;

int n, t, c, pos, vis[200010], sz = 0;
string s;
vector<int> v;

int main() {
  cin >> n >> t >> c >> s;
  pos = 0;
  while (s[pos] == 'x')
    pos++;
  while (pos < n) {
    sz++;
    vis[pos] = sz;
    pos += c + 1;
    while (pos < n && s[pos] == 'x')
      pos++;
  }
  pos = n - 1;
  while (s[pos] == 'x')
    pos--;
  while (pos >= 0) {
    v.pb(pos);
    pos -= c + 1;
    while (pos >= 0 && s[pos] == 'x')
      pos--;
  }
  reverse(v.begin(), v.end());
  rep(i, n) {
    if (vis[i] == 0)
      continue;
    int cur = vis[i] - 1, pos = upper_bound(v.begin(), v.end(), i) - v.begin();
    if (cur + v.size() - pos < t)
      cout << i + 1 << endl;
  }
  return 0;
}
Problem p02721 (Python)

Buggy submission (status: Runtime Error):
N, K, C = map(int, input().split())
S = input()
L = []
R = []
L_index = 0
L_count = 0
R_index = N - 1
R_count = K - 1

while L_index < N and L_count < K:
    if S[L_index] == "o":
        L.append(L_index)
        L_index += C + 1
        L_count += 1
    else:
        L_index += 1
while R_index >= 0 and R_count >= 0:
    if S[R_index] == "o":
        R.append(R_index)
        R_index -= C - 1
        R_count -= 1
    else:
        R_index -= 1

work_day = set(L) & set(R)
for w_day in work_day:
    print(w_day + 1)


Fixed submission:
n, k, c = map(int, input().split())
s = input()
l = [-1] * k
r = [-1] * k
nowl = 0
indl = 0
while nowl < n and indl < k:
    for i in range(nowl, n):
        if s[i] == "o":
            l[indl] = i
            nowl = i + c + 1
            indl += 1
            break
nowr = n - 1
indr = k - 1
while nowr >= 0 and indr >= 0:
    for i in range(nowr, -1, -1):
        if s[i] == "o":
            r[indr] = i
            nowr = i - c - 1
            indr -= 1
            break
for i in range(k):
    if l[i] == r[i]:
        print(l[i] + 1)
Problem p02721 (Python)

Buggy submission (status: Runtime Error):
#!/usr/bin/env python3
n, k, c = map(int, input().split())
s = input()

if c == 0:
    if s.cnt("o") == k:
        print(*range(1, n + 1), sep="\n")
    exit()

left = []
i = 0
while i < n:
    if s[i] == "o":
        left.append(i)
        i += c
    i += 1

right = []
i = n - 1
while i >= 0:
    if s[i] == "o":
        right.append(i)
        i -= c
    i -= 1
right.reverse()
for i in range(len(left)):
    if left[i] == right[i]:
        print(left[i] + 1)


Fixed submission:
#!/usr/bin/env python3
n, k, c = map(int, input().split())
s = input()

if c == 0:
    if s.count("o") == k:
        for i in range(n):
            if s[i] == "o":
                print(i + 1)
    exit()

left = []
i = 0
while i < n:
    if s[i] == "o":
        left.append(i)
        i += c
    i += 1

right = []
i = n - 1
while i >= 0:
    if s[i] == "o":
        right.append(i)
        i -= c
    i -= 1
right.reverse()
for i in range(len(left)):
    if left[i] == right[i]:
        print(left[i] + 1)
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
int a[maxn], b[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  int num = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      a[num++] = i;
      i += c;
    }
  }
  num = k - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (num < 0)
      break;
    if (s[i] == 'o') {
      b[num--] = i;
      i -= c;
    }
  }
  for (int i = 0; i < k; i++)
    if (a[i] == b[i])
      cout << a[i] + 1 << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
int a[maxn], b[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  int n, k, c;
  string s;
  cin >> n >> k >> c >> s;
  int num = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      a[num++] = i;
      i += c;
    }
  }
  num = k - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (num < 0)
      break;
    if (s[i] == 'o') {
      b[num--] = i;
      i -= c;
    }
  }
  for (int i = 0; i < k; i++)
    if (a[i] == b[i])
      cout << a[i] + 1 << endl;
  return 0;
}
Problem p02721 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <random>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1LL << 60;

ll n, k, c, l[100010], r[100010];
string s;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k >> c >> s;

  for (int i = 0; i < n; ++i) {
    if (s[i] == 'o') {
      l[i + 1]++;
      i += c;
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == 'o') {
      r[i]++;
      i -= c;
    }
  }
  REP(i, n) l[i + 1] += l[i];
  for (int i = n; i >= 1; --i)
    r[i - 1] += r[i];

  // check:
  for (int i = 0; i < n; ++i) {
    if (l[i] + r[i + 1] < k) {
      cout << i + 1 << '\n';
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <random>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
constexpr ll INF = 1LL << 60;

ll n, k, c, l[200010], r[200010];
string s;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k >> c >> s;

  for (int i = 0; i < n; ++i) {
    if (s[i] == 'o') {
      l[i + 1]++;
      i += c;
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == 'o') {
      r[i]++;
      i -= c;
    }
  }
  REP(i, n) l[i + 1] += l[i];
  for (int i = n; i >= 1; --i)
    r[i - 1] += r[i];

  // check:
  for (int i = 0; i < n; ++i) {
    if (l[i] + r[i + 1] < k) {
      cout << i + 1 << '\n';
    }
  }
  return 0;
}
Problem p02721 (C++)

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

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

  string s;
  cin >> s;

  vector<int> a, b;

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

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

  for (int i = 0; i < k; i++) {
    if (a[i] == b[i - k - 1])
      cout << i + 1 << endl;
  }

  return 0;
}

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

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

  string s;
  cin >> s;

  vector<int> a, b;

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

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

  for (int i = 0; i < k; i++) {
    if (a[i] == b[k - i - 1])
      cout << a[i] + 1 << endl;
  }

  return 0;
}
Problem p02721 (C++)

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

#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)

using namespace std;

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

  int N, K, C;
  string S;
  cin >> N >> K >> C >> S;

  vector<int> dp(N + 1);
  dp[N] = 0;

  RREP(i, N) {
    if (S[i] == 'x') {
      dp[i] = dp[i + 1];
    } else {
      int j = i + C + 1;
      dp[i] = max(dp[i + 1], 1 + (j < N ? dp[j] : 0));
    }
  }

  int i = 0;
  while (i < N) {
    int first_o = -1;
    int next_i = -1;
    while (dp[i] >= K) {
      if (S[i] == 'o') {
        if (first_o == -1) {
          first_o = i;
          next_i = first_o + C + 1;
        } else {
          first_o = -1;
          break;
        }
      }
      ++i;
    }
    if (first_o != -1) {
      cout << (first_o + 1) << '\n'; // 1-based indexing
    }
    i = next_i;
    --K;
  }
  cout << flush;

  return 0;
}


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

#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)

using namespace std;

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

  int N, K, C;
  string S;
  cin >> N >> K >> C >> S;

  vector<int> dp(N + 1);
  dp[N] = 0;

  RREP(i, N) {
    if (S[i] == 'x') {
      dp[i] = dp[i + 1];
    } else {
      int j = i + C + 1;
      dp[i] = max(dp[i + 1], 1 + (j < N ? dp[j] : 0));
    }
  }

  int i = 0;
  while (K > 0) {
    int first_o = -1;
    int next_i = -1;
    while (dp[i] >= K) {
      if (S[i] == 'o') {
        if (first_o == -1) {
          first_o = i;
          next_i = first_o + C + 1;
        } else {
          first_o = -1;
          break;
        }
      }
      ++i;
    }
    if (first_o != -1) {
      cout << (first_o + 1) << '\n'; // 1-based indexing
    }
    i = next_i;
    --K;
  }
  cout << flush;

  return 0;
}
Problem p02721 (C++)

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

using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

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

  freopen("a.txt", "r", stdin);

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

  vector<int> good;

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

  n = good.size();
  vector<int> dp(n);

  for (int i = n - 1; i >= 0; --i) {
    int it = upper_bound(good.begin(), good.end(), good[i] + c) - good.begin();
    if (it < good.size()) {
      dp[i] = dp[it] + 1;
    } else {
      dp[i] = 1;
    }
  }

  int when = -1e9, cnt = 0;

  for (int i = 0; i < n; ++i) {
    int L = upper_bound(good.begin(), good.end(), when + c) - good.begin();
    L = max(L, i + 1);
    int add = 0;
    if (L < good.size())
      add = dp[L];
    if (add + cnt < k) {
      cout << good[i] + 1 << "\n";
    }
    if (good[i] > when + c) {
      when = good[i];
      cnt++;
    }
  }

  return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

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

  // freopen("a.txt", "r", stdin);

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

  vector<int> good;

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

  n = good.size();
  vector<int> dp(n);

  for (int i = n - 1; i >= 0; --i) {
    int it = upper_bound(good.begin(), good.end(), good[i] + c) - good.begin();
    if (it < good.size()) {
      dp[i] = dp[it] + 1;
    } else {
      dp[i] = 1;
    }
  }

  int when = -1e9, cnt = 0;

  for (int i = 0; i < n; ++i) {
    int L = upper_bound(good.begin(), good.end(), when + c) - good.begin();
    L = max(L, i + 1);
    int add = 0;
    if (L < good.size())
      add = dp[L];
    if (add + cnt < k) {
      cout << good[i] + 1 << "\n";
    }
    if (good[i] > when + c) {
      when = good[i];
      cnt++;
    }
  }

  return 0;
}