Today, the bookstore owner has a store open for customers.length minutes.  Every minute, some number of customers (customers[i]) enter the store, and all those customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy.  If the bookstore owner is grumpy on the i-th minute, grumpy[i] = 1, otherwise grumpy[i] = 0.  When the bookstore owner is grumpy, the customers of that minute are not satisfied, otherwise they are satisfied.
The bookstore owner knows a secret technique to keep themselves not grumpy for X minutes straight, but can only use it once.
Return the maximum number of customers that can be satisfied throughout the day.
 
Example 1:
Input: customers = [1,0,1,2,1,1,7,5], grumpy = [0,1,0,1,0,1,0,1], X = 3
Output: 16
Explanation: The bookstore owner keeps themselves not grumpy for the last 3 minutes. 
The maximum number of customers that can be satisfied = 1 + 1 + 1 + 1 + 7 + 5 = 16.

 
Note:

1 <= X <= customers.length == grumpy.length <= 20000
0 <= customers[i] <= 1000
0 <= grumpy[i] <= 1

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

def _disabled_input(*args, **kwargs):
    raise RuntimeError("input() is disabled in callable mode")
builtins.input = _disabled_input

ns = {"__name__": "__judge__"}  # prevent if __name__ == "__main__" blocks
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "class Solution:\n    def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:\n        #happy owner means happy customer as well \n        happy_owner_cust = 0 \n        \n        for pos in range(len(customers)):\n            if grumpy[pos] == 0: #happy owner \n                happy_owner_cust += customers[pos]\n                customers[pos] = 0 \n        \n        \n        #then build upon using the grumpy owner power. \n        \n        calming_owner_cust = 0 \n        best_calmed_cust = 0 \n        \n        for end in range(len(customers)): \n            calming_owner_cust += customers[end]\n  \n            \n            \n            if end >= X: #subtract out the extra calming technique from the owner \n                calming_owner_cust -= customers[end - X]\n                \n            best_calmed_cust = max(best_calmed_cust, calming_owner_cust)\n            \n            \n            \n            \n        return happy_owner_cust + best_calmed_cust\n    \n# #TRY 8/10/2020 \n# class Solution:\n#     def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:\n#         #Input: Customers[i] how many customers enter for that exact minute \n            \n#         #Constraint \n#         #owner -> opens store up to customers.len()\n#         #Every minute there are customers entering the store. And all those customers leave after the end of the minute \n        \n#         #If owner is grumpy on i-th minute grumpy[i] = 1 else grumpy[i] = 0. When the bookstore owner is angry \n#         #The customers of that minute aren't satisfied else if owner isn't grumpy then customers are happy. \n        \n#        # Bookstore owner can be NOT angry for X minutes but can use it ONLY once. \n       \n#         #WANT: max number of customers that are happy throughout the day. \n        \n        \n#         minutes_opened = len(customers) \n#         customer_happy_time = 0 \n        \n#         #Try to basically keep your grumpy minutes down based on the highest number of customers there are. \n        \n#         start = 0 \n#         end = 0 \n#         rush_hour = collections.deque() #this is based on the most amount of customers. \n#         calm_owner = collections.deque()\n#         #Our best number of customer being happy will be based on the largest amount of customers\n#         #That's our best bet. \n#         while end < minutes_opened: \n#             if customers[end] == 0: #No Customers go in owner can be angry \n#                 end += 1 \n#                 continue \n                \n#             cur_happy_time += customers[end]\n#             if grumpy[end] == 1: #owner angry = customer angry: Just try calming here then. \n                \n                \n                \n#             rush_hour.append(end)\n\n# class Solution():\n#     def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:\n#         m = s = tmp = 0\n#         for i in range(len(customers)):\n#             if not grumpy[i]: \n#                 s += customers[i]                # sum of satisfied customers\n#                 customers[i] = 0 \n#             else: tmp += customers[i]            # sum of grumpy customers \n#             if i>=X: tmp -= customers[i-X]       # remove the leftmost element to keep the sliding window with # of X\n#             m = max(m, tmp)                      # max # of satisfied grumpy customers with a secret technique\n#         return s+m\n    \n    \n# class Solution:\n#     def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:\n#         # Part 1 requires counting how many customers\n#         # are already satisfied, and removing them\n#         # from the customer list.\n#         #These customers are those who didn't have to fight with the owner to be happy.\n#         already_satisfied = 0\n#         for i in range(len(grumpy)):\n#             if grumpy[i] == 0: #He's happy so add the customer. \n#                 already_satisfied += customers[i]\n#                 customers[i] = 0 #set you back to zero to not visit you. When doing the offset for the window \n        \n#         # Part 2 requires finding the optimal number\n#         # of unhappy customers we can make happy.\n#         best_we_can_make_satisfied = 0\n#         current_satisfied = 0\n#         for i, customers_at_time in enumerate(customers):\n#             # if customers[i] == 0: CAN'T DO THIS CUZ WE'RE NOT UPDATING THE WINDOW THEN AT THIS POINT (I.E THE START WINDOW)\n#             #     continue\n#             #Add the customer so far\n#             current_satisfied += customers_at_time # Add current to rolling total\n#             if i >= X: # We need to remove some from the rolling total #We need to update and try the grumpy intervals to block out owner from \n#                 #Being grumpy so we can add these happy customers but at this point\n#                 #There's too much calming power used by owner so we need to remove the beginning window of the current_satisifed. \n#                 current_satisfied -= customers[i - X]\n#             best_we_can_make_satisfied = max(best_we_can_make_satisfied, current_satisfied)\n        \n#         # The answer is the sum of the solutions for the 2 parts.\n#         return already_satisfied + best_we_can_make_satisfied\n    \n    \nclass Solution:\n    def maxSatisfied(self, customers: List[int], grumpy: List[int], X: int) -> int:\n        always_happy = 0  \n        for pos in range(len(customers)): \n            if grumpy[pos] == 0: \n                always_happy += customers[pos]\n                customers[pos] = 0 \n                \n        happy_use = 0 \n        cur_happy_customers = 0 \n \n        for pos in range(len(customers)): \n            cur_happy_customers += customers[pos]\n            \n            if pos >= X: \n                cur_happy_customers -= customers[pos - X]\n                \n            \n            happy_use = max(happy_use, cur_happy_customers)\n            \n        return always_happy + happy_use "
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'maxSatisfied'
if _fn_name:
    if "Solution" in ns:
        try:
            _obj = ns["Solution"]()
            if hasattr(_obj, _fn_name):
                _target = getattr(_obj, _fn_name)
        except Exception:
            _target = None
    if _target is None and _fn_name in ns and callable(ns[_fn_name]):
        _target = ns[_fn_name]
# Fallback: if there's exactly one user-defined function, use it
if _target is None:
    _cands = [v for k, v in ns.items() if callable(v) and getattr(v, "__module__", "") in ("__judge__", "__main__")]
    _user_funcs = [c for c in _cands if getattr(c, "__name__", "").startswith("_") is False]
    if len(_user_funcs) == 1:
        _target = _user_funcs[0]
if _target is None:
    raise RuntimeError(f"Could not resolve callable '{_fn_name}'")

_raw = sys.stdin.read().strip()
if _raw:
    _parsed = json.loads(_raw)
    if isinstance(_parsed, dict):
        _kwargs = _parsed.get("kwargs", {})
        _args = _parsed.get("args", [])
    else:
        _args, _kwargs = _parsed, {}
else:
    _args, _kwargs = [], {}
if not isinstance(_args, (list, tuple)):
    _args = [_args]
_res = _target(*_args, **_kwargs)
try:
    sys.stdout.write(repr(_res) + "\n")
except Exception:
    pass

```

Measured memory_bytes: 5622