1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#define allr(a) (a).rbegin(), (a).rend()
#define F first
#define S second
#define pb push_back
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
/*
#ifndef ONLINE_JUDGE
    #include <cpp-dump.hpp>
#endif
*/
constexpr ll mod = 1e9+7;

ll power(ll a, ll b){
    ll res = 1;
    while(b){
        if(b&1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

/*
ll fact[300001];
ll C(ll n, ll k){
    if(k < 0 || k > n) return 0;
    return fact[n] * power(fact[k], mod-2) % mod * power(fact[n-k], mod-2) % mod;
}
*/

void dzik77() {

    int n,k,t; cin >> n >> k >> t;
    string s; cin >> s;
    vector<int> p1(n+1), p2(n+1);
    for (int i = 1; i <= n; i++){
        p1[i] = p1[i-1] + (s[i-1] == '1');
        p2[i] = p2[i-1] + (s[i-1] == '2');
    }
    int ans = -1;
    if(p1[n] <= k) ans = n-max(p2[n] - (k - p1[n]),0);
    for (int i = 1; i <= n-t-t; i++){
        for (int seg_s = 1; i + t + t + seg_s - 1 <= n; seg_s++){
            int s = p1[n] - (p1[i+t+seg_s-1] - p1[i+t-1]) + (p2[i+t-1] - p2[i-1]) + (p2[i+t+t+seg_s-1] - p2[i+t+seg_s-1]);
            int left = p2[n] - (p2[i+t+t+seg_s-1] - p2[i-1]);
            if(s <= k) ans = max(ans, n-(t+t+seg_s) - max(left - (k-s), 0));
        }
    }
    cout << ans << '\n';

}

int32_t main()
{

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

    /*
    fact[0] = 1;
    for (int i = 1; i < 300001; i++){
        fact[i] = fact[i-1] * i % mod;
    }
    */

    int t = 1;
    //cin >> t;
    while(t--)
		dzik77();

    return 0;
}