Problem:
IOIOI
問題
整数
n
(1 ≤
n
) に対し,
n
+ 1 個の
I
と
n
個の
O
を
I
から始めて交互に並べてできる文字列を
P
n
とする.ここで
I
と
O
はそれぞれ英大文字のアイとオーである.
P
1
IOI
P
2
IOIOI
P
3
IOIOIOI
.
.
.
P
n
IOIOIO ... OI
(
O
が
n
個)
図 1-1 本問で考える文字列
P
n
整数
n
と, I と O のみからなる文字列
s
が与えられた時,
s
の中に
P
n
が何ヶ所含まれているかを出力するプログラムを作成せよ.
例
n
が 1,
s
が
OOIOIOIOIIOII
の場合,
P
1
は
IOI
であり,下図 1-2 に示した 4ヶ所に含まれている.よって,出力は 4 である.
OO
IOI
OIOIIOII
OOIO
IOI
OIIOII
OOIOIO
IOI
IOII
OOIOIOIOI
IOI
I
図 1-2
n
が 1,
s
が
OOIOIOIOIIOII
の場合の例
n
が 2,
s
が
OOIOIOIOIIOII
の場合,
P
2
は
IOIOI
であり,下図 1-3 に示した 2ヶ所に含まれている.よって,出力は 2 である.
OO
IOIOI
OIIOII
OOIO
IOIOI
IOII
図 1-3
n
が 2,
s
が
OOIOIOIOIIOII
の場合の例
入力
入力は複数のデータセットからなる．各データセットは以下の形式で与えられる．
1 行目には整数
n
(1 ≤
n
≤ 1000000) が書かれている.
2 行目には整数
m
(1 ≤
m
≤ 1000000) が書かれている.
m
は
s
の文字数を表す.
3 行目には文字列
s
が書かれている.
s
は
I
と
O
のみからなる.
全ての採点用データで, 2
n
+ 1 ≤
m
である.採点用データのうち, 配点の 50% 分については,
n
≤ 100,
m
≤ 10000 を満たす.
n
が 0 のとき入力の終了を示す. データセットの数は 10 を超えない．
出力
データセットごとに,文字列
s
に文字列
P
n
が何ヶ所含まれるかを表す 1 つの整数を1 行に出力する.
s
に
P
n
が含まれていない場合は,整数として
0
を出力せよ.
入出力例
入力例
1
13
OOIOIOIOIIOII
2
13
OOIOIOIOIIOII
0
出力例
4
2
上記問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include<utility>
#include<set>
#include<deque>
#include <unordered_map>
#include<string>
#include<cmath>

using namespace std;


int main() {
	while (true) {
		int m, n;
		cin >> m >> n;
		if (m == 0) {
			break;
		}
		string S;
		cin >> S;
		int M = 2 * m + 1;
		int co = 0;
		int z = 0;
		int p = -1;
		int ans = 0;
		for (int i = 0; i < n; i++) {

			if (S[i] == 'I' and p == -1) {
				co += 1;
				if (co >= M) {
					ans += 1;

				}
			}
			else if (S[i] == 'O' and p == 1 and co > 0) {
				co += 1;
			}
			else {
				co = 0;
				p = -1;
			}

			if (S[i] == 'I') {
				p = 1;
				if (co == 0) {
					co = 1;
				}
			}
			else {
				p = -1;
			}
		}
		cout << ans << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 5128
final_rank: 4

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)

template<class T>
using vi = vector<T>;

template<class T>
using vii = vector<vi<T>>;

template<class T>
using viii = vector<vii<T>>;

using pii = pair<int, int>;

int main()
{
    int n, m;
    string s;
    while (cin >> n, n) {
        cin >> m >> s;
        string t = "I";
        rep(i, n) t += "OI";
        t += "#" + s;
        int lt = t.size();
        vi<int> z(lt);
        int idx = 1, len = 0;
        while (idx < lt) {
            while (t[len] == t[idx + len]) len++;
            if (len == 0) {
                idx++;
                continue;
            }
            z[idx] = len;
            int k = 1;
            while (k + z[k] < len) {
                z[idx + k] = z[k];
                k++;
            }
            idx += k;
            len -= k;
        }

        int ans = 0;
        rep(i, lt) if (z[i] == 2 * n + 1) ans++;
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 9204
final_rank: 12

code_snippet: //#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint mod = 1e9 + 7;
#define all(x) begin(x), end(x)
#define bitcount(n) __builtin_popcountll((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzll(x))
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, r) for(int i = int(l); i < int(r); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--)
constexpr int inf9 = 1e9; constexpr lint inf18 = 1e18;
inline void Yes(bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void array_output(itr start, itr goal){ for(auto i = start; i != goal; i++) cout << (i == start ? "" : " ") << (*i); cout << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(b) return gcd(b, a % b); else return a; }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; }
inline int has(lint i, int j){ return (i >> j) & 1; }
int dy[4] = {1, 0, -1, 0}; int dx[4] = {0, 1, 0, -1};
bool is_inside(lint y, lint x, lint H, lint W){ return (0 <= y && y < H && 0 <= x && x < W); }

struct io_init {
    io_init() {
        cin.tie(nullptr); cout.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }
} io_init;

void solve(){
    int n, m;
    string s;
    cin >> n;
    if(n == 0) exit(0);
    cin >> m >> s;
    
    vector<int> ioi;
    rep(i, m - 2){
        if(s.substr(i, 3) == "IOI"){
            ioi.push_back(i);
        }
    }
    
    int len = 0, ans = 0;
    rep(i, ioi.size()){
        if(i > 0 && ioi[i - 1] + 2 == ioi[i]){
            len++;
        }else{
            len = 1;
        }
        if(len >= n){
            ans++;
        }
    }
    
    cout << ans << endl;
}

int main(){
    while(true) solve();
}
accuracy: 1
time_ms: 10
memory_kb: 7144
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
//typedef long long ll;
typedef int ll;
typedef pair<ll, ll> P;
const long long INF = 1e9;
template <typename T>
void input_arr(vector<T>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i];
	}
}
template <typename T, typename Q>
void input_arr(vector<pair<T, Q>>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i].first >> A[i].second;
	}
}
template <typename T>
void input_arr(vector<vector<T>>& A, ll H, ll W) {
	for (ll i = 0; i < H; i++) {
		for (ll j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
}
int main() {
    ll N; cin >> N;
    while (N != 0) {
        ll M; cin >> M;
        string S; cin >> S;
        vector<ll>A;
        bool check = false;
        char ch = 'c';
        ll num = 0;
        for (ll i = 0; i < M; i++) {
            if (i == 0) {
                ch = S[i];
                if (ch == 'I') {
                    num++;
                    check = true;
                }
                continue;
            }
            if (!check) {
                ch = S[i];
                if (S[i] == 'I') {
                    check = true;
                    num = 1;
                }
                continue;
            }
            if (ch != S[i] && check) {
                num++;
                ch = S[i];
                continue;
            }
            if (ch == S[i] && check) {
                ch = S[i];
                A.push_back(num);
                if (S[i] == 'I') num = 1;
                else {
                    check = false;
                    num = 0;
                }
            }
        }
        for (ll &i : A) {
            i = (i - 1) / 2;
        }
        ll ans = 0;
        for (ll i : A) {
            ans += max(i - N + 1, 0);
        }
        cout << ans << endl;
        cin >> N;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 5060
final_rank: 2

code_snippet: #define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<list>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<sstream>
#include<regex>
#include<random>
using namespace std;
#define int long long
#define uint unsigned long long
const int mod=1e9+7;
const int Mod=998244353;
const int inf=mod*mod;
const double eps=1e-9;
signed main(){
	int n,m;
	string s;
	while(cin>>n,n){
		cin>>m>>s;
		int tmp=0,ans=0;
		for(int i=0;i<m;i++){
			if(tmp%2==0&&s[i]=='I')
				tmp++;
			else if(s[i]=='I')
				tmp=1;
			else if(tmp%2==1&&s[i]=='O')
				tmp++;
			else
				tmp=0;
			if(tmp%2==1&&tmp>=2*n+1)
				ans++;
		}
		cout<<ans<<endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 4924
final_rank: 1

code_snippet: #include<iostream>

using namespace std;

int main()
{
	while (true)
	{
		int n;
		cin >> n;
		if (n == 0)
			break;
		string pn = "IOI";
		for (int i = 1; i < n; i++)
			pn += "OI";
		int m;
		cin >> m;
		string s;
		cin >> s;
		int bound = m - pn.size();
		int ans = 0;
		for (int i = 0; i <= bound; i++)
			ans += s.substr(i, pn.size()) == pn;
		cout << ans << endl;
	}

	//system("pause");
}
accuracy: 1
time_ms: 180
memory_kb: 3948
final_rank: 17

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

int main()
{
  while(1){
  int n, m;
  cin >> n;
  if(n==0) return 0;
  cin >> m;
  string s;
  cin >> s;
  int out = 0;
  int i = 0;
  while (i < m)
  {
 //   cout << i << endl;
    if (s[i] == 'I')
    {
      int cnt = 0;
      i++;
      while (1)
      {
        if (s[i] == 'O' && s[i + 1] == 'I')
        {
          cnt++;
          i += 2;
        }
        else
        {
          if (cnt >= n)
            out += cnt - n + 1;
          break;
        }
      }
    }
    else
      i++;
  }
  cout << out << endl;
  }
}
accuracy: 1
time_ms: 20
memory_kb: 3772
final_rank: 5

code_snippet: #include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i, n) for(ll i=n-1;i>=0;--i)
#define rep1(i, n) for(ll i=1; i<=n; ++i)
#define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr)
#define ALL(a) (a).begin(),(a).end()

template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

using namespace std;
using ll  = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;

const ll MOD  = 998244353;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const double PI = 3.1415926535897932384626;

ll mod(ll a, ll m){return (a + m) % m;}

int main(){
    ll n;
    while(cin >> n){
        if(!n)break;

        ll m;
        string s;
        cin >> m >> s;

        string pn = "";
        rep(i, 2*n+1){
            if(i%2)pn += "O";
            else pn += "I";
        }

        ll ans = 0;
        string t = "";
        rep(i, m){
            if(t.size() >= 2*n + 1)t.erase(t.begin());
            t.push_back(s[i]);

            if(t == pn)ans++;
        }

        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 160
memory_kb: 3812
final_rank: 16

code_snippet: #pragma region Macros
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define drep(i,n) for(ll i = n-1;i >= 0;i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'
#define overload2(_1, _2, name, ...) name
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define VEC(type, name, size)\
    vector<type> name(size);\
    IN(name)
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w)\
    vector<vector<type>> name(h, vector<type>(w));\
    IN(name)
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)\
    vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
using namespace std;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define si(c) (int)(c).size()
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DBL(...)\
    double __VA_ARGS__;\
    IN(__VA_ARGS__)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T> void scan(vector<T> &);
template <class T> void scan(vector<T> &a) {
    for(auto &i : a) scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) {
    scan(head);
    IN(tail...);
}
template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
vi iota(int n) {
    vi a(n);
    iota(all(a), 0);
    return a;
}
template <typename T> vi iota(vector<T> &a, bool greater = false) {
    vi res(a.size());
    iota(all(res), 0);
    sort(all(res), [&](int i, int j) {
        if(greater) return a[i] > a[j];
        return a[i] < a[j];
    });
    return res;
}
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
template <class T> T POW(T x, int n) {
    T res = 1;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
vector<pll> factor(ll x) {
    vector<pll> ans;
    for(ll i = 2; i * i <= x; i++)
        if(x % i == 0) {
            ans.push_back({i, 1});
            while((x /= i) % i == 0) ans.back().second++;
        }
    if(x != 1) ans.push_back({x, 1});
    return ans;
}
template <class T> vector<T> divisor(T x) {
    vector<T> ans;
    for(T i = 1; i * i <= x; i++)
        if(x % i == 0) {
            ans.pb(i);
            if(i * i != x) ans.pb(x / i);
        }
    return ans;
}
template <typename T> void zip(vector<T> &x) {
    vector<T> y = x;
    sort(all(y));
    for(int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); }
}
int popcount(ll x) { return __builtin_popcountll(x); }
int in() {
    int x;
    cin >> x;
    return x;
}
ll lin() {
    unsigned long long x;
    cin >> x;
    return x;
}
#define i128 __int128_t
#define ull unsigned long long int
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(15);
    }
} setup_io;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" :", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
// #define LOCAL
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#pragma endregion
//#include<atcoder/all>
//using namespace atcoder;
int main(){
    // //dp[i][j]:iまでみて(iつかう),最後がjの時の最大値
    // if(s[i] != j)dp[i][j] = 0;
    // else dp[i][j] = dp[i-1][j^1]+1;
    for(;;){
        INT(m);
        if(!m)return 0;
        INT(n);
        STR(tmp);
        vector<int> s(tmp.size()+1);
        rep(i,n){
            auto c = tmp[i];
            if(c == 'I')s[i] = 1;
            else s[i] = 0;
        }
        vector dp(n+1,vector<int>(2));
        rep(i,n)rep(j,2){
            if(s[i] != j)dp[i][j] = 0;
            else{
                dp[i][j] = 1;
                if(i)dp[i][j] += dp[i-1][j^1];
            }
        }
        // trace(dp);
        int ret = 0;
        rep(i,n){
            if(s[i] == 1){
                // trace(dp[i][1]);
                if(dp[i][1] >= m*2+1)ret++;
            }
        }
        cout << ret << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 62624
final_rank: 20

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int rec(int i,string &s,vector<int> &memo){
    if(memo[i]!=-1)return memo[i];
    if(i+1<s.size()&&s[i+1]!=s[i])return memo[i]=rec(i+1,s,memo)+1;
    return memo[i]=1;
}

int main(){
    while(1){
    INT(n);
    if(n==0)return 0;
    INT(m);
    string s;
    cin>>s;
    vector<int> memo(m,-1);
    int ans=0;
    rep(i,m){
        if(s[i]=='I')ans+=(rec(i,s,memo)>=2*n+1);
    }
    out(ans);
    }
}
accuracy: 1
time_ms: 20
memory_kb: 9380
final_rank: 14

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;

        int len;
        string s;
        cin >> len >> s;
        s += "XX";
        vector<int> a;
        for(int i=0; i<len; i++){
            if(s[i] == 'I'){
                int count = 0;
                while(s[i+1]=='O' and s[i+2]=='I'){
                    count++;
                    i += 2;
                }
                a.push_back(count);
            }
        }
        int ans = 0;
        for(int i: a){
            ans += max(0, i-n+1);
        }
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5080
final_rank: 3

code_snippet: #include <bits/stdc++.h>

using namespace std;

int N, M;

int main() {
	int curPos, cnt;
	string allType, target, str;

	allType = "I";
	for (int i = 1; i <= 1000000; ++i) {
		allType += "OI";
	}

	while (cin >> N, N) {
		cin >> M >> str;
		target = allType.substr(0, 1 + 2 * N);
		cnt = 0;
		curPos = str.find(target);
		while (curPos != string::npos) {
			++cnt;
			curPos = str.find(target, curPos + 1);
		}
		cout << cnt << endl;
	}
	
	return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 6816
final_rank: 15

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

int main() {
    while (cin) {
        int n;
        cin >> n;
        if (n == 0) break;

        int m;
        string s;
        cin >> m >> s;

        int i = 0;
        int ans = 0;
        while (i < m) {
            if (s[i] == 'I') {
                int j = i;
                for (; j < m; j++) {
                    if ((j - i) & 1) {
                        if (s[j] == 'O')
                            continue;
                        else
                            break;
                    } else {
                        if (s[j] == 'I')
                            continue;
                        else
                            break;
                    }
                }
                int count = j - i;
                if(count & 1){
                    count /= 2;
                } else {
                    count--;
                    count /= 2;
                }
                ans += max(0, count - n + 1);
                // cout << j << " " << max(0, count - n + 1) << endl;
                i = j;
                i--;
            }
            i++;
        }
        cout << ans << endl;
    }
}

/*
1
50
IOOIOOOIIOIIIIIIIOOIOIOIOOOIIIOIIIOIIIOOOOOIIIOIIO

6
*/
accuracy: 1
time_ms: 20
memory_kb: 3908
final_rank: 8

code_snippet: #include <bits/stdc++.h>
//typedef
//-------------------------#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
 
 
using namespace std;
 
//conversion
//------------------------------------------
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(); }
inline int readInt() { int x; scanf("%d", &x); return x; }
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
 
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
 
class UnionFind {
public:
    vector <int> par; 
    vector <int> siz; 

    UnionFind(int sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(int sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
 
    int root(int x) { 
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
 
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }
 
    bool issame(int x, int y) { 
        return root(x) == root(y);
    }
 
    int size(int x) { 
        return siz[root(x)];
    }
};
 
 
ll modPow(ll x, ll n, ll mod = MOD){
    if(n <= 0) return 1;
    ll res = 1;
    while(n){
        if(n&1) res = (res * x)%mod;
 
        res %= mod;
        x = x * x %mod;
        n >>= 1;
    }
    return res;
}
 
#define SIEVE_SIZE 5000000+10
bool sieve[SIEVE_SIZE];
void makeSieve(){
    for(int i=0; i<SIEVE_SIZE; ++i) sieve[i] = true;
    sieve[0] = sieve[1] = false;
    for(int i=2; i*i<SIEVE_SIZE; ++i) if(sieve[i]) for(int j=2; i*j<SIEVE_SIZE; ++j) sieve[i*j] = false;
}
 
bool isprime(ll n){
    if(n == 0 || n == 1) return false;
    for(ll i=2; i*i<=n; ++i) if(n%i==0) return false;
    return true;
}
 
const int MAX = 2000010;
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
// 負の数にも対応した mod (a = -11 とかでも OK) 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
 
// 逆元計算 (ここでは a と m が互いに素であることが必要)
long long modinv(long long a, long long m) {
    long long x, y;
    extGCD(a, m, x, y);
    return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので
}
ll GCD(ll a, ll b){
    
    if(b == 0) return a;
    return GCD(b, a%b);
}

template< unsigned mod >
struct RollingHash {
  vector< unsigned > hashed, power;

  inline unsigned mul(unsigned a, unsigned b) const {
    unsigned long long x = (unsigned long long) a * b;
    unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
    asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod));
    return m;
  }

  RollingHash(const string &s, unsigned base = 10007) {
    int sz = (int) s.size();
    hashed.assign(sz + 1, 0);
    power.assign(sz + 1, 0);
    power[0] = 1;
    for(int i = 0; i < sz; i++) {
      power[i + 1] = mul(power[i], base);
      hashed[i + 1] = mul(hashed[i], base) + s[i];
      if(hashed[i + 1] >= mod) hashed[i + 1] -= mod;
    }
  }

  unsigned get(int l, int r) const {
    unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
    if(ret >= mod) ret -= mod;
    return ret;
  }

  unsigned connect(unsigned h1, int h2, int h2len) const {
    unsigned ret = mul(h1, power[h2len]) + h2;
    if(ret >= mod) ret -= mod;
    return ret;
  }

  int LCP(const RollingHash< mod > &b, int l1, int r1, int l2, int r2) {
    int len = min(r1 - l1, r2 - l2);
    int low = -1, high = len + 1;
    while(high - low > 1) {
      int mid = (low + high) / 2;
      if(get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid;
      else high = mid;
    }
    return (low);
  }
};

using RH = RollingHash< 1000000007 >;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);

    int n, m; 
    while(cin >> n, n){
        cin >> m;
    string s; cin >> s;
    RH rh(s);

    int ans = 0;
    string t="";
    for(int i=0; i<n; i++){
        t += "IO";
    }
    t += "I";

    RH rh2(t);

    for(int i=0; i+t.size()<=s.size(); i++){
        if(rh.get(i, i+t.size()) == rh2.get(0, t.size())) ans++;
    }
    cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 11824
final_rank: 13

code_snippet: #include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	for (int h = 0; h < 10; h++) {
		long long n, m, a = 0, sum = 0, ans = 0; string s; cin >> n;
		if(n==0){
		    return 0;
		}
		cin>>m>>s;
		int test[123456] = { 0 };
		for (int h = 0; h < m - 2; h++) {
			if (s[h] == 'I' && s[h + 1] == 'O' && s[h + 2] == 'I') {
				sum++; h += 1;
			}
			else if (sum != 0) {
				test[a] = sum;
				a++; sum = 0;
			}
		}
		test[a] = sum;
		a++;

		for (int h = 0; h < a; h++) {
			if (test[h] >= n) {
				ans += test[h] - n + 1;
			}
		}
		cout << ans << endl;
	}
}
accuracy: 1
time_ms: 20
memory_kb: 4468
final_rank: 11

code_snippet: #include <iostream>
#include <string>
using namespace std;

int main(){
  int ans = 0;
  int n;
  cin >> n;
  while(n != 0){
    int m;
    cin >> m;
    string s;
    cin >> s;
    string see = "I";
    for(int i = 0; i < n; i++){
      string temp = "OI";

      see = see+temp;
    }
    int ans =  0;
    string sn = s.substr( 0 , n*2);
    for(int i = 0; i < m - n*2 ; i ++){
      sn = s.substr(i , n*2+1);
      if(sn == see)ans++;
    }
    
  cout << ans << endl;
    cin >> n;
  }


 
}
accuracy: 1
time_ms: 200
memory_kb: 3924
final_rank: 19

code_snippet: #include<iostream>
#include<string>
using namespace std;

int main()
{
    int n, m;
    string s, t, u;

    while( cin >> n )
    {
        s = "I";
        u = "";
        if( !n )
            break;

        for( int i = 0; i < n; i++ )
            s += "OI";

        cin >> m;

        cin >> t;
        
        int cnt = 0, i = 0;
        while( i < m )
        {
            u = t.substr( i, s.size() );
            if( s == u )
                cnt++;
            i++;
        }
        cout << cnt << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 190
memory_kb: 3820
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P,P> PP;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()


int main() {
    int n;
    while(cin >> n, n){
        int m, cnt = 0, len = 0;
        string s;
        cin >> m >> s;
        s.push_back('#');
        REP(i,m+1){
            if(len%2==0 && s[i]=='I'){
                len++;
            }
            else if(len%2==1 && s[i]=='O'){
                len++;
            }
            else if(len > 0){
                cnt += max(0, (len-1)/2 - n + 1);
                len = 0;
                if(s[i]=='I')len++;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3912
final_rank: 9

code_snippet: #include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>

using namespace std;


int N, M;
string s;

int main() {

	while (cin >> N, N)
	{
		cin >> M >> s;

		int ren = 0;
		bool frag = false;
		int ans = 0;
		vector<int> a;
		int k = 0;
		a.push_back(0);

		for (int i = 0; i < M; i++) {

			if (frag) {
				if (s[i] == 'O' && s[i + 1] == 'I') {
					ren++;

					a[k] = max(a[k], ren - N + 1);

					i++;
				}
				else {

					k++;
					a.push_back(0);
					ren = 0;
					frag = false;
				}
			}

			if (s[i] == 'I') {
				frag = true;
			}

			
		}

		for (int i = 0; i < k; i++) {
			ans += a[i];
		}


		cout << ans << endl;

	}


	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3856
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int m;
	string s;
	int i;
	int cnt;
	vector<int>v;
	int flg;
	int sum;
	int x;
	while(1){
		cin>>n;
		if(n==0)	break;
		cin>>m;
		cin>>s;
		v.clear();
		i=0;
		cnt=0;
		while(s.size()-1>i){
			flg=0;
			if(s[i]=='I'){
				if(s[i+1]=='O'){
					if(s[i+2]=='I'){
						cnt++;
						flg=1;
						i+=2;
					}
				} 
			}
			if(flg==0){
				if(cnt!=0){
					v.push_back(cnt);
				}
				cnt=0;
				i++;
			}
		}
		/* for(i=0;i<v.size();i++){
			cout<<v[i]<<endl;
		} */
		sum=0;
		for(i=0;i<v.size();i++){
			if(v[i]+1-n>=0){
				sum+=v[i]+1-n;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3840
final_rank: 6