alexjercan/bugnet huggingface dataset:
Problem p00461 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
string base = "IOI";
int main() {
  int n;
  while (cin >> n, n) {
    int gar;
    cin >> gar;
    string hoge;
    cin >> hoge;
    string key = "IOI";
    rep(i, n - 1) key += "OI";
    bool flag = true;
    int ans = 0;
    int gotisa = 0;
    while (flag) {
      int var = (int)hoge.find(key, gotisa);
      if (var == -1)
        break;
      gotisa = var + 1;
      ans++;
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
string base = "IOI";
int main() {
  int n;
  while (cin >> n, n) {
    int gar;
    cin >> gar;
    string hoge;
    cin >> hoge;
    string key = "IOI";
    rep(i, n - 1) key += "OI";
    bool flag = true;
    int ans = 0;
    while (flag) {
      int var = (int)hoge.find(key);
      if (var == -1) {
        break;
      }
      rep(i, var) hoge.erase(hoge.begin() + 1);
      ans++;
    }
    cout << ans << endl;
  }
}
Problem p00461 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <vector>
using namespace std;

int main() {
  while (true) {
    int n, m;
    cin >> n;
    if (n == 0)
      break;
    cin >> m;
    string s;
    cin >> s;
    //        for(int i=0;i<m;i++){
    //            cout<<i<<"_"<<s[i]<<" ";
    //        }
    //        cout<<endl;
    int i = 0, j = 0, ans = 0;
    for (i = 0; i < m - n;) {
      if (s[i] == 'O') {
        i++;
        continue;
      }
      int t = 1;
      for (j = i; j < 2 * n + 1 + i; j++) {
        if ((j - i) % 2 == 0 && s[j] != 'I') {
          // cout<<"i: "<<i<<"   j: "<<j<<endl;
          t = 0;
          i = j + 1;
          break;
        }
        if ((j - i) % 2 == 1 && s[j] != 'O') {
          // cout<<"i: "<<i<<"   j: "<<j<<endl;
          t = 0;
          i = j;
          break;
        }
      }
      int q;
      if (t == 1) {
        // cout<<"i : "<<i<<endl;
        ans++;
        for (q = j; q < m - 2; q += 2) {

          if (s[q] != 'O' || s[q + 1] != 'I')
            break;
          ans++;
          // cout<<"q "<<q<<endl;
        }
        i = q;
      }

      // cout<<"i : "<<i<<endl;
    }
    cout << ans << endl;
    // cout<<"***********************"<<endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <vector>
using namespace std;

int main() {
  while (true) {
    int n, m;
    cin >> n;
    if (n == 0)
      break;
    cin >> m;
    string s;
    cin >> s;
    int i = 0, j = 0, ans = 0;
    for (i = 0; i < m - n;) {
      if (s[i] == 'O') {
        i++;
        continue;
      }
      int t = 1;
      for (j = i; j < 2 * n + 1 + i; j++) {
        if ((j - i) % 2 == 0 && s[j] != 'I') {
          // cout<<"1  s[j]: "<<s[j]<<"   "<<j<<endl;
          t = 0;
          if (j > 1)
            i = j + 1;
          break;
        }
        if ((j - i) % 2 == 1 && s[j] != 'O') {
          // cout<<"2  s[j]: "<<s[j]<<"   "<<j<<endl;
          t = 0;
          if (j > 1)
            i = j;
          break;
        }
      }
      int q;
      if (t == 1) {
        // cout<<"i : "<<i<<endl;
        ans++;
        for (q = j; q < m - 2; q += 2) {

          if (s[q] != 'O' || s[q + 1] != 'I')
            break;
          ans++;
        }
        i = q;
      }

      // cout<<"i : "<<i<<endl;
    }
    cout << ans << endl;
    // cout<<"***********************"<<endl;
  }
}
Problem p00461 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int n, index_s, num, ans;
string s;

void init() { index_s = ans = 0; }

void find() {
  int pos = 0, pass = 0;
  string ss = "OI";

  while (1) {
    if (pos == 2) {
      pos = 0;
      pass++;
    }
    if (s[index_s] != ss[pos])
      break;
    pos++;
    index_s++;
  }
  ans += max(0, pass - n + 1);
}

void solve() {
  while (index_s < num) {
    if (s[index_s++] == 'I')
      find();
  }
}

int main() {
  while (cin >> n && n) {
    init();
    cin >> num >> s;
    solve();
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

string make(int n) {
  string out = "IOI";
  for (int i = 1; i < n; i++)
    out += "OI";
  return out;
}

int match(string str, string p, int i) {
  for (int j = 0; j < p.length(); j++) {
    if (str[i + j] != p[j])
      return 0;
  }
  return 1;
}

int main() {

  int in;
  while (cin >> in && in) {
    int num, sum = 0;
    cin >> num;
    string p = make(in);
    string str;
    cin >> str;
    for (int i = 0; i < num; i++) {
      if (match(str, p, i))
        sum++;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p00461 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long int lli;
using namespace std;

int main() {
  int n, m, cnt;
  while (cin >> n && n != 0) {
    cin >> m;
    string P = "";
    cnt = 0;
    for (int i = 0; i < 2 * n + 1; ++i) {
      if (i % 2 == 0) {
        P += 'I';
      } else {
        P += 'O';
      }
    }
    string str;
    cin >> str;
    vector<int> vi(str.size());
    for (int i = m - 1; i > 1; --i) {
      if (str[i] == 'I' && str[i - 1] == 'O' && str[i - 2] == 'I') {
        vi[i - 2] = vi[i] + 1;
      }
    }
    for (int i = 0; i < str.size(); ++i) {
      if (vi[i] >= n) {
        ++cnt;
      }
    }
    cout << cnt << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long int lli;
using namespace std;

int main() {
  int n, m, cnt;
  while (cin >> n && n != 0) {
    cin >> m;
    string P = "";
    cnt = 0;
    for (int i = 0; i < 2 * n + 1; ++i) {
      if (i % 2 == 0) {
        P += 'I';
      } else {
        P += 'O';
      }
    }
    // cout << P << "\\n";
    string str;
    cin >> str;
    for (int i = 0; i < str.size(); ++i) {
      int j;
      int n = i + 1;
      bool flag = true;
      bool k = true;
      if (str[i] == 'I' && i + P.size() - 1 < str.size()) {
        for (j = 0; j < P.size() && i + j < str.size(); ++j) {
          if (k && j != 0 && str[i + j] == 'I') {
            n = i + j;
            k = false;
          }
          if (P[j] != str[i + j]) {
            flag = false;
            break;
          }
        }
      } else {
        flag = false;
      }
      if (flag) {
        // cout << i << "\\n";
        ++cnt;
      }
      i = n - 1;
    }
    cout << cnt << "\\n";
  }
  return 0;
}
Problem p00461 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int n, m;
    string s;
    cin >> n >> m >> s;

    if (n == 0) {
      break;
    }

    int ni, start = 0, ans = 0;
    for (int i = 0; i < m; i++) {
      if (s[i] == s[i + 1] && i > 0) {
        if (s[i] != s[i - 1] && s[i - 1] != s[i - 2]) {
          int longs = i - start;
          if (s[start + 1] == 'I') {
            ni = longs - longs / 2;
          } else {
            ni = longs / 2;
          }
          if (ni > n) {
            ans += ni - n;
          }
          start = i;
        } else
          start = i;
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

  int ans = 0, nex = 0;
  for (int i = 0; i < m; i++) {
    if (s[i] == s[i + 1]) {
      if (i > 2) {
        if (s[i] != s[i - 1]) {
          nex = i;
          i = (i + 1 - nex) - (i + 1 - nex) / 2;
          ans = ans + i - n;
        } else
          nex = i;
      } else
        nex = i;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p00461 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int n, m;
  char input;
  while (cin >> n, n) {
    int situ = -1, cnt = -1, ans = 0;
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> input;
    AGAIN:
      if (situ != 0 && input == 'I') {
        cnt++;
        situ = 0;
      } else if (situ != 1 && input == 'O') {
        situ = 1;
      } else {
        if (cnt - n + 1 > 0) {
          ans += cnt - n + 1;
        }
        cnt = -1;
        situ = -1;
        goto AGAIN;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
using namespace std;

#define StrSize 2000001
char str[StrSize], c;

int main() {
  deque<int> cnt;
  memset(str, 'O', StrSize);
  for (int i = 0; i < StrSize; i += 2) {
    str[i] = 'I';
  }
  cnt.push_back(0);

  for (int i = 0; i < 10; i++)
    printf("%c ", str[i]);
  puts("");

  int n, m;
  int pushcnt, popcnt;
  while (cin >> n, n) {
    cin >> m;
    int ans = 0;
    for (int i = 0; i < m; i++) {
      cin >> c;
      pushcnt = 0;
      popcnt = 0;
      for (int j = 0; j < cnt.size(); j++) {
        if (str[cnt[j]] == c) {
          if (cnt[j] == 0) {
            pushcnt++;
          }
          cnt[j]++;
          if (cnt[j] == 2 * n + 1) {
            popcnt++;
            ans++;
          }
        } else if (cnt[j] != 0) {
          popcnt++;
        }
      }
      for (int j = 0; j < pushcnt; j++)
        cnt.push_back(0);
      for (int j = 0; j < popcnt; j++)
        cnt.pop_front();
      // for(int j=0;j<cnt.size();j++) printf("%d ",cnt[j]); puts("");
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00461 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, l;
  while (cin >> n, n) {
    cin >> l;
    string str;
    cin >> str;

    int mode = 0;
    int chain = 0;
    int ans = 0;
    for (int i = 0; i < str.size(); ++i) {
      if (str[i] == 'I') {
        switch (mode) {
        case 0:
          mode = 1;
          break;
        case 1:
          chain = 0;
          break;
        case 2:
          if (++chain >= n) {
            ++ans;
            --chain;
          }
          mode = 1;
          break;
        }
      } else {
        switch (mode) {
        case 0:
          break;
        case 1:
          mode = 2;
          break;
        case 2:
          mode = 0;
          chain = 0;
          break;
        }
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, l;
  while (cin >> n >> l, n || l) {
    string str;
    cin >> str;

    int mode = 0;
    int chain = 0;
    int ans = 0;
    for (int i = 0; i < str.size(); ++i) {
      if (str[i] == 'I') {
        switch (mode) {
        case 0:
          mode = 1;
          break;
        case 1:
          chain = 0;
          break;
        case 2:
          if (++chain >= n) {
            ++ans;
            --chain;
          }
          mode = 1;
          break;
        }
      } else {
        switch (mode) {
        case 0:
          break;
        case 1:
          mode = 2;
          break;
        case 2:
          mode = 0;
          chain = 0;
          break;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00461 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n - 1)

const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
  int n, m;
  string str;

  while (cin >> n, n) {
    cin >> m >> str;
    str += "  ";
    int pos = 0, count = 0, sum = 0;

    while (pos < m) {
      if (str[pos] == 'I') {
        count = 0;
        while (str[pos + 1] == 'O' && str[pos + 2] == 'I') {
          count++;
          pos += 2;
        }
        sum += count >= n ? count - n + 1 : 0;
      }
      pos++;
    }

    cout << sum << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n - 1)

const double EPS = 1e-10;
const double PI = acos(-1.0);

string IO(int n) {
  string str = "I";

  REP(i, n) { str += "OI"; }

  return str;
}

int main() {
  int n, m, count, pos;
  string str, org;

  while (cin >> n, n) {
    cin >> m >> str;
    count = 0;

    org = IO(n);

    while ((pos = str.find(org)) != string::npos) {
      count++;
      while (str[pos + 2 * n] == 'O' && str[pos + 2 * n + 1] == 'I') {
        count++;
        pos += 2;
      }
      str = str.substr(pos + 1);
    }

    cout << count << endl;
  }

  return 0;
}
Problem p00461 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int n, m;
string s;

int main() {
  while (cin >> n) {
    if (!n)
      return 0;
    cin >> m >> s;
    int a = 0, b = 0;
    for (int i = 0; i < m; i++) {
      if (s[i] == 'I' && b % 2 == 0 || s[i] == 'O' && b % 2 == 1)
        b++;
      else {
        if (s[i] == 'I')
          b = 1;
        else
          b = 0;
      }
      if (b % 2 == 1 && b >= 2 * n + 1)
        a++;
    }
    cout << a << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int n, m;
string s;

int main() {
  while (cin >> n) {
    if (!n)
      return 0;
    cin >> m >> s;
    int a = 0;
    string t = "I";
    for (int i = 0; i < n; i++)
      t += "OI";
    while (s.find(t) != string::npos) {
      s = s.substr(s.find(t) + 1);
      a++;
    }
    cout << a << endl;
  }
}
Problem p00461 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n, m, cnt, ioi[1000005];
  string s;
  while (1) {
    for (int i = 0; i < 1000005; i++)
      ioi[i] = 0;
    cnt = 0;
    cin >> n;
    if (!n)
      break;
    cin >> m >> s;
    for (int i = s.size() - 3; i >= 0; i--) {
      if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I')
        ioi[i] = ioi[i + 2] + 1;
    }
    for (int i = 0; i < 1000005; i++) {
      if (ioi[i] >= n)
        cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n, m, cnt;
  string s, ioi;
  while (1) {
    ioi = "I";
    cnt = 0;
    cin >> n;
    if (!n)
      break;
    cin >> m >> s;
    for (int i = 0; i < n; i++)
      ioi += "OI";
    s += "      ";
    while (1) {
      int index = s.find(ioi);
      if (index == -1)
        break;
      s = s.substr(index + 2);
      cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00461 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cctype>    // require tolower, toupper
#include <cfloat>
#include <climits>
#include <cmath>   // require fabs
#include <cstdio>  // require scanf printf
#include <cstdlib> // require abs exit atof atoi
#include <cstring> // require memset
#include <ctime>   // require srand
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main() {
  //	cut here before submit
  //	freopen ("testcase.IOIOI", "r", stdin );
  int n;
  while (scanf("%d", &n), n) {
    int m;
    scanf("%d", &m);
    string s = "";
    cin >> s;
    string search = "";
    rep(i, n) { search += "IO"; } // end rep
    search += 'I';
    //		cerr << search << endl;
    int res = 0;
    rep(i, m) {
      if (s[i] == 'O')
        continue;
      if (s[i] == 'I' && i + 1 < m && s[i + 1] != 'O')
        continue;
      string sub = s.substr(i, 2 * n + 1);
      if (sub == search) {
        res++;
      } // end if
    }   // end rep
    printf("%d\\n", res);
  } // en drep

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cctype>    // require tolower, toupper
#include <cfloat>
#include <climits>
#include <cmath>   // require fabs
#include <cstdio>  // require scanf printf
#include <cstdlib> // require abs exit atof atoi
#include <cstring> // require memset
#include <ctime>   // require srand
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main() {
  //	cut here before submit
  //	freopen ("testcase.IOIOI", "r", stdin );
  int n;
  while (scanf("%d", &n), n) {
    int m;
    scanf("%d", &m);
    string s = "";
    cin >> s;
    string search = "";
    rep(i, n) { search += "IO"; } // end rep
    search += 'I';
    //		cerr << search << endl;
    int res = 0;
    rep(i, m) {
      if (s[i] == 'O')
        continue;
      if (s[i] == 'I' && i + 1 < m && s[i + 1] != 'O')
        continue;
      string sub = s.substr(i);
      if (sub.find(search) != string::npos) {
        res++;
      } // end if
    }   // end rep
    printf("%d\\n", res);
  } // en drep

  return 0;
}
Problem p00461 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {

  int n;
  int m;
  string s;
  while (cin >> n, n != 0) {
    cin >> m >> s;
    int p[1000001] = {0};
    int f = 1;
    for (int i = 0; i < m; i++) {
      if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') {
        for (int j = 1; j <= f; j++)
          p[j]++;
        f++;
        i++;
      } else {
        f = 1;
      }
    }

    cout << p[n] << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {

  int n;
  int m;
  string s;
  while (cin >> n, n != 0) {
    cin >> m >> s;
    int p[100] = {0};
    int f = 1;
    for (int i = 0; i < m; i++) {
      if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') {
        for (int j = 1; j <= f; j++)
          p[j]++;
        f++;
        i++;
      } else {
        f = 1;
      }
    }

    cout << p[n] << endl;
  }
}