Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str


def calc_min_max(n_plus, n_minus, min_diff, max_diff):
    min_val = n_plus * min_diff - n_minus * max_diff
    max_val = n_plus * max_diff - n_minus * min_diff
    return min_val, max_val


def loc_in_range(init_val, end_val, min_val, max_val):
    in_max = (init_val + max_val) >= end_val
    in_min = (init_val + min_val) <= end_val
    if in_max and in_min:
        return True
    elif in_max:
        return 'lower'
    return 'higher'


def update_n_plus_minus(n_plus, n_minus, n_max, n_min, loc):
    if loc == 'higher':
        diff = (n_max - n_plus) // 2
        if (n_max - n_plus) == 1:
            diff = 1
        return (
            n_plus + diff, 
            n_minus - diff,
            n_max,
            n_plus,
        )
    diff = (n_plus - n_min) // 2
    if (n_plus - n_min) == 1:
        diff = 1
    return (
        n_plus - diff,
        n_minus + diff,
        n_plus,
        n_min,
    )


def binary_search(N, init_val, end_val, min_diff, max_diff):
    n_plus = (N - 1) // 2
    n_minus = (N - 1) - n_plus
    min_val, max_val = calc_min_max(n_plus, n_minus, min_diff, max_diff)
    n_max, n_min = N - 1, 0
    loc = loc_in_range(init_val, end_val, min_val, max_val)
    while loc in ['lower', 'higher']:
        new_n_plus, new_n_minus, n_max, n_min = update_n_plus_minus(
            n_plus, n_minus, n_max, n_min, loc
        )
        if new_n_plus == n_plus:
            return False
        n_plus, n_minus = new_n_plus, new_n_minus
        min_val, max_val = calc_min_max(n_plus, n_minus, min_diff, max_diff)
        loc = loc_in_range(init_val, end_val, min_val, max_val)
    return True


def solve(N: int, A: int, B: int, C: int, D: int):
    res = binary_search(N, A, B, C, D)
    print([NO, YES][res])
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(N, A, B, C, D)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str


def calc_n_plus(required_diff, max_diff, min_diff, n):
    if (max_diff == 0) & (min_diff == 0):
        return 0
    return min(
        (required_diff + n * max_diff) // (max_diff + min_diff),
        n
    )


def check_in_max(required_diff, max_diff, min_diff, n, n_plus):
    max_val = n_plus * (min_diff + max_diff) - n * min_diff
    return required_diff <= max_val


# min_val = i * (min_diff + max_diff) - N * max_diff
# max_val = i * (min_diff + max_diff) - N * min_diff


def solve(N: int, A: int, B: int, C: int, D: int):
    n_plus = calc_n_plus(abs(B - A), D, C, N - 1)
    res = check_in_max(abs(B - A), D, C, N - 1, n_plus)
    print([NO, YES][res])
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(N, A, B, C, D)

if __name__ == '__main__':
    main()