from typing import Union
from typing import Sequence


def get_padding(kernel_size: Union[int, Sequence], stride: Union[int, Sequence]):
    """Calculates Padding Size from kernel_size and stride."""
    kh, kw = kernel_size if isinstance(kernel_size, Sequence) else (kernel_size,) * 2
    sh, sw = stride if isinstance(stride, Sequence) else (stride,) * 2
    pad_h = max(kh - sh, 0)
    pad_w = max(kw - sw, 0)
    return (
        pad_w - pad_w // 2,
        pad_w - pad_w // 2,
        pad_h - pad_h // 2,
        pad_h - pad_h // 2,
    )