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
import numpy as np

n, k, t = [int(x) for x in input().split(' ')]
segments = np.array([int(x) for x in input()])


def calc():
    office_meets = np.cumsum(segments == 1)
    remote_meets = np.cumsum(segments == 2)
    free = np.cumsum(segments == 3)
    # print(office_meets)
    # print(remote_meets)
    # print(free)

    if office_meets[-1] <= k:  # nie oplaca sie jechac
        return free[-1] + min(remote_meets[-1], (k - office_meets[-1])) + office_meets[-1]

    result = -1

    for a in range(n):
        for b in range(a + t + t, n):
            #print("range", a, b)
            missing = office_meets[a + t - 1]\
                                + (office_meets[-1] - office_meets[b - t])\
                                + (remote_meets[a + t - 1] - (remote_meets[a - 1] if a > 0 else 0))\
                                + (remote_meets[b] - remote_meets[b - t])
            #print("missing", missing)
            if missing > k:
                continue
            remote = (remote_meets[a-1] if a > 0 else 0) + (remote_meets[-1] - remote_meets[b])
            can_still_miss = min(remote, k - missing)
            r = (free[a-1] if a > 0 else 0) + (free[-1] - free[b]) + can_still_miss
            #print("score", r)
            if r > result:
                result = r
    return result


print(calc())