Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it.
Return the number of nice sub-arrays.
 
Example 1:
Input: nums = [1,1,2,1,1], k = 3
Output: 2
Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1].

Example 2:
Input: nums = [2,4,6], k = 1
Output: 0
Explanation: There is no odd numbers in the array.

Example 3:
Input: nums = [2,2,2,1,2,2,1,2,2,2], k = 2
Output: 16

 
Constraints:

1 <= nums.length <= 50000
1 <= nums[i] <= 10^5
1 <= k <= nums.length

```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 numberOfSubarrays(self, nums: List[int], k: int) -> int:\n        n = len(nums)\n        # Corner cases\n        if k > n:\n            return 0\n        \n        # We will use 4 pointers: p1, p2, p3, p4\n        # p1 will initially start at -1. It will always point to the \\"previous\\" odd number\n        # that we DONT want to include the in the current count\n        # p2 will point to the first odd number that we want to count\n        # p3 will point the the kth odd number starting from p2\'s odd number\n        # p4 will point to the next odd number after p3 if it exists, else will point to n\n        # Given p1, p2, p3, p4, the number of nice subarrays in this window equals (p2-p1)*(p4-p3)\n        # After that, we set p1 to p2, p3 to p4. Then move p4 (if you can) to the next odd number, and move\n        # p2 to the next odd number. Do this until you can\'t move p4 anymore.\n        ans = 0\n        p1 = p2 = p3 = p4 = -1\n        while p4 < n:\n            # Move p2 to the next odd number\n            p2 += 1\n            while p2 < n and nums[p2] % 2 == 0:\n                p2 += 1\n                if p2 == n:\n                    return ans\n            # p2 now points to the 1st odd number\n            # Now move p3 to the kth odd number (Note that for k=1 p3 coincides with p2)\n            # For the first time the loop is executed, we find the k-th 1 by moving forward one index at a time.\n            # For the second loop onward, we simply set p3 to p4. Also note that because we entered the loop,\n            # p4 < n, hence p4 must point to a 1, hence we can simply set p3 to p4.\n            if p4 == -1:\n                p3 = p2\n                remaining = k-1\n                while p3 < n and remaining:\n                    p3 += 1\n                    if p3 == n:\n                        return ans\n                    if nums[p3] % 2 == 1:\n                        remaining -= 1\n            else:\n                p3 = p4\n            # p3 now points to the kth odd number\n            # Now move p4 to the next odd number\n            p4 = p3 + 1 # p3 is at most n-1, because we would have returned otherwise.\n            while p4 < n:\n                if nums[p4] % 2 == 1:\n                    break\n                p4 += 1\n            # p4 is now either n or the next odd number after p3\n            # Now compute the number of nice subarrays in this window and add to ans\n            ans += (p2-p1)*(p4-p3)\n            # To set up for the next round, set p1 to p2\n            p1 = p2\n        return ans\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'numberOfSubarrays'
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: 5714