def METHOD_NAME(resources, increase_by, max_resource, keep_the_same):
    if keep_the_same:
        return resources
    else:
        requests = bitmath.parse_string_unsafe(resources.requests["memory"])
        limits = bitmath.parse_string_unsafe(resources.limits["memory"])
        increase_by = bitmath.parse_string_unsafe(increase_by)
        requests = min((increase_by + requests), max_resource)
        limits = max(requests, limits)
        formatted_request = requests.format("{value:.0f}{unit}").rstrip("B")
        formatted_limit = limits.format("{value:.0f}{unit}").rstrip("B")
        return ResourceRequirements(
            limits={"memory": (str(formatted_limit))},
            requests={"memory": (str(formatted_request))},
        )