Problem:
 Score : 400 points    Problem Statement There are N squares in a row.
The leftmost square contains the integer A , and the rightmost contains the integer B . The other squares are empty.  Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:   For any two adjacent squares, the (absolute) difference of the two integers in those squares is between C and D (inclusive).   As long as the condition is satisfied, it is allowed to use arbitrarily large or small integers to fill the squares.
Determine whether it is possible to fill the squares under the condition.      Constraints  3 \leq N \leq 500000  0 \leq A \leq 10^9  0 \leq B \leq 10^9  0 \leq C \leq D \leq 10^9  All input values are integers.         Input Input is given from Standard Input in the following format:  N  A  B  C  D       Output Print YES if it is possible to fill the squares under the condition; print NO otherwise.        Sample Input 1 5 1 5 2 4      Sample Output 1 YES  For example, fill the squares with the following integers: 1 , -1 , 3 , 7 , 5 , from left to right.       Sample Input 2 4 7 6 4 5      Sample Output 2 NO       Sample Input 3 48792 105960835 681218449 90629745 90632170      Sample Output 3 NO       Sample Input 4 491995 412925347 825318103 59999126 59999339      Sample Output 4 YES

Solution (Python):
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
for i in range(N - 1):
  r = D * (N - i - 1) + A
  l = C * (N - i - 1) + A

  r -= C * i
  l -= D * i
  
  if B in range(l, r + 1):
    print("YES")
    exit(0)
print("NO")

Solution (Python):
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    N, A, B, C, D = LI()
    for i in range(N-1):
        low = A + i*C - (N-1-i)*D
        up = A + i*D - (N-1-i)*C
        if low<=B<=up:
            print("YES")
            return
    print("NO")
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

Solution (Python):
N, A, B, C, D = map(int, input().split())

X = abs(A - B)

result = "NO"
for i in range(N):
    X_min = i * C - ((N - 1 - i) * D)
    X_max = i * D - ((N - 1 - i) * C)
    if X_min <= X <= X_max:
        result = "YES"
        break

print(result)

Solution (Python):
N, A, B, C, D = map(int, input().split())
E = B - A
for m in range(N):
  if C*(N-1-m) - D*m <= E <= -C*m + (N-1-m)*D:
    print("YES")
    break
else:
  print("NO")

Solution (Python):

import sys

YES = "YES"  
NO = "NO"  


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






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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = int(next(tokens))  
    B = int(next(tokens))  
    C = int(next(tokens))  
    D = int(next(tokens))  
    solve(N, A, B, C, D)

if __name__ == '__main__':
    main()

Solution (Python):
n,a,b,c,d = map(int,input().split())
x = abs(a-b)
c,d = min(c,d),max(c,d)
for i in range((n+1)//2):
  j = n-i-1
  if c*j-d*i<=x<=d*j-c*i:
    print("YES")
    exit()
print("NO")

Solution (Python):
N,A,B,C,D = map(int,input().split())
x = B-A
flag = 0
for i in range(1,N+1):
    if -(N-i)*D+(i-1)*C<=x<=-(N-i)*C+(i-1)*D:
        flag = 1
        break
if flag==1:
    print("YES")
else:
    print("NO")

Solution (Python):
N, A, B, C, D = map(int, input().split())
ans = False
for i in range(N):
  inc = i
  dec = N-1-i
  
  if A + inc * C - dec * D <= B <= A + inc * D - dec * C:
    ans = True
print('YES' if ans else 'NO')

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, A, B, C, D = MAP()


B = abs(A - B)
for i in range(N):
    
    j = N - i - 1
    
    mn = C * i - D * j
    
    mx = D * i - C * j
    
    if mn <= B <= mx:
        YES()
        exit()
NO()

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, A, B, C, D = MAP()
B -= A

l = D - C + 1
b = C * 2 - 1
mx = D
l += (D-C) * (N-2)
b = max(b - (D-C) * (N-2), 0)
mx *= N - 1

B += mx
mod = l + b
if B < 0 or B > mx*2:
    NO()
    exit()
if B % mod < l:
    YES()
else:
    NO()

Solution (Python):
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) 
rs = lambda: stdin.readline().rstrip()  

N, A, B, C, D = rl()

bool = False
diff = B - A
for i in range(N):
    j = N-1-i
    
    if C*i-D*j <= diff <= D*i-C*j:
        bool = True
        break

print('YES' if bool else 'NO')

Solution (Python):
n,a,b,c,d=map(int,input().split())
for i in range(n-1):
  if i*c-(n-1-i)*d<=b-a<=i*d-(n-1-i)*c:print("YES");exit()
print("NO")

Solution (Python):
n,a,b,c,d=map(int,input().split())
e=abs(b-a)
if c+d+e==0:
    print("YES")
    exit()
upper=(e+(n-1)*d)//(c+d)
lower=(e+(n-1)*c)//(c+d)
if upper==lower:
    if (e+(n-1)*c) % (c+d) == 0 and 0<=lower and (e+(n-1)*c)/(c+d) <= n-1 and e <= (n-1)*max([c,d]):
        print("YES")
    else:
        print("NO")
else:
  if 0<=lower and (e+(n-1)*c)/(c+d) <= n-1 and e <= (n-1)*max([c,d]):
	    print("YES")
  else:
        print("NO")

Solution (Python):
N, A, B, C, D = map(int, input().split())
if A > B:
    A, B = B, A

flag = False
diff = B-A
d = 0
for i in range(0, N, 2):
    if i > 0:
        d += D-C
    j = N-1 - i
    if diff == d and j % 2 == 0:
        flag == True
        break
    if j == 0:
        break

    k = abs(diff - d) / j
    if (k >= C and k <= D) or (abs(diff-d) >= C and abs(diff-d) <= D and j % 2 == 1):
        flag = True
        break
    k = abs(diff + d) / j
    if (k >= C and k <= D) or (diff+d >= C and diff+d <= D and j % 2 == 1):
        flag = True
        break

if flag:
    print("YES")
else:
    print("NO")

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,a,b,c,d=map(int,input().split())
    for k in range(n): 
        L=a+k*c-(n-k-1)*d
        R=a+k*d-(n-k-1)*c
        if(L<=b<=R):
            print("YES")
            return
    print("NO")
resolve()

Solution (Python):
n, a, b, m, M = map(int, input().split())
n -= 1
l, r = -1, n + 1
while r - l > 1:
	mid = (l + r) // 2
	t = (n - 2 * mid) * (m + M)
	if abs(t - 2 * (b - a)) <= n * (M - m):
		print("YES")
		exit()
	if t > 2 * (b - a):
		l = mid
	else:
		r = mid
print("NO")

Solution (Python):
n,a,b,m,M=map(int,input().split())
print("YES" if any((n-i-1)*m-i*M<=b-a<=-i*m+(n-i-1)*M for i in range(n)) else "NO")

Solution (Python):
n, a, b, c, d = map(int, input().split())

cnt = n - 1
diff = abs(a-b)

for i in range(cnt+1):
    plus_cnt = i
    minus_cnt = cnt - i
    plus_range = [c*plus_cnt, d*plus_cnt]
    minus_range = [c*minus_cnt, d*minus_cnt]
    ran = [plus_range[0] - minus_range[1], plus_range[1] - minus_range[0]]
    if ran[0] <= diff and diff <= ran[1]:
        print("YES")
        exit()
print("NO")

Solution (Python):


def solve() -> bool:
    n, a, b, c, d = map(int, input().split())
    return any((n - 1 - m) * c - m * d <= b - a <= (n - 1 - m) * d - m * c for m in range(n - 1))


print('YES' if solve() else 'NO')

Solution (Python):
N, A, B, C, D = map(int, input().split())

def solve() :
    if N % 2 == 0 :
        l = (N // 2) * C - (N // 2) * D
        r = (N // 2) * D - (N // 2) * C
        for _ in range(N // 2 + 1) :
            if A + l <= B <= A + r :
                return 'YES'
            if A - r <= B <= A - l :
                return 'YES'
            l += C + D
            r += C + D
            
    else :
        l = (N // 2 + 1) * C - (N // 2) * D
        r = (N // 2 + 1) * D - (N // 2) * C
        for _ in range(N // 2 + 1) :
            if A + l <= B <= A + r :
                return 'YES'
            if A - r <= B <= A - l :
                return 'YES'
            l += C + D
            r += C + D
            
    return 'NO'
    
N -= 1    
print(solve())

Solution (Python):
def main():
    N, A, B, dmin, dmax = [int(n) for n in input().split()]
    diff = B - A
    i = N-1
    for i in range(N):
        plusmin = dmin*i
        plusmax = dmax*i
        minusmin = dmin * (N-1-i)
        minusmax = dmax*(N-1-i)
        left = plusmin - minusmax
        right = -minusmin + plusmax
        if left <= diff <= right:
            print("YES")
            return
    print("NO")
main()

Solution (Python):
n,a,b,c,d=map(int,input().split())
b=abs(b-a);flag=False
for i in range(1,n+1):
  ma=d*(i-1)-c*(n-i)
  mi=c*(i-1)-d*(n-i)
  if mi<=b and ma>=b:
    flag=True
print("YES" if flag else "NO")

Solution (Python):
def solve():
    N, A, B, C, D = map(int, input().split())

    H = abs(A - B)

    if D == 0:
        return (H == 0)

    mi = C * (N - 1)
    ma = D * (N - 1)

    if H > ma:
        return False

    return ((H - mi) % (C + D) <= (ma - mi))

if solve():
    print("YES")
else:
    print("NO")

Solution (Python):
n, a, b, c, d = map(int, input().split())

a, b = 0, abs(b-a)
if b > (n-1) * d:
    print('NO')
    exit()
if (n-1) * c <= b <= (n-1) * d:
    print('YES')
    exit()

if c == d:
    if b % c == 0 and b // c <= n-1:
        print('YES')
    else:
        print('NO')
    exit()

if (b//d) % 2 == (n-1)%2:
    diff1 = b - (b//d) * d
    if (diff1 - 1) // (d-c) + 1 <= (n-1 - (b//d)) // 2:
        print('YES')
        exit()
else:
    diff1 = b - (b//d - 1) * d
    if (diff1 - 1) // (d-c) + 1 <= (n-1 - (b//d - 1)) // 2:
        print('YES')
        exit()

if (((b-1)//c)+1) % 2 == (n-1)%2:
    diff2 = (((b-1)//c)+1) * c - b
    if (diff2-1) // (d-c) + 1 <= (n-1 - (((b-1)//c)+1)) // 2:
        print('YES')
        exit()
else:
    diff2 = (((b-1)//c)+2) * c - b
    if (diff2-1) // (d-c) + 1 <= (n-1 - (((b-1)//c)+2)) // 2:
        print('YES')
        exit()

print('NO')

Solution (Python):
N,A,B,C,D=map(int,input().split())
X=B-A

for i in range(N-1):
    if (D*(-N+1+i)+C*(i))<=X and X<=(C*(-N+1+i)+D*(i)):
        print("YES")
        exit()
print("NO")

Solution (Python):
def ascending_range(i):
    return (a+c*i, a+d*i)

def descendable_range(i, m, M):
    j = n-1-i
    floor = b+c*j
    ceil = b+d*j
    return not (m > ceil or M < floor)

def solve_local(i):
    return descendable_range(i, *ascending_range(i))

n, a, b, c, d = map(int, input().split())

print("YES" if any(solve_local(i) for i in range(n)) else "NO")

Solution (Python):
N,A,B,C,D = map(int,input().split())

for i in range(N):
  if (N-1-i)*C-i*D <= abs(B-A) <= (N-1-i)*D-i*C:
    print('YES')
    exit()
print('NO')

Solution (Python):

import sys

N,A,B,C,D = map(int,input().split())
num = abs(A-B)
nmax = (N-1) * D
nmin = (N-1) * C
flag = False

for i in range(N-1):

    if nmax >= num and num >= nmin:
        flag = True
        break

    nmax -= D + C
    nmin -= C + D

if flag:
    print ("YES")
else:
    print ("NO")

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left
import random
from itertools import permutations, accumulate, combinations
import sys
import string


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 998244353



n, a, b, c, d = LI()
for add_cnt in range(n):
    subtract_cnt = n - 1 - add_cnt
    min_val = add_cnt * c - subtract_cnt * d
    max_val = add_cnt * d - subtract_cnt * c
    if min_val <= b - a <= max_val:
        print('YES')
        break
else:
    print('NO')

Solution (Python):
n,a,b,c,d = map(int,input().split())
lo,hi = -d*(n-1), -c*(n-1)
for _ in range(n):
  if lo <= a-b <= hi:
    print("YES")
    break
  lo += c+d
  hi += c+d
else:
  print("NO")

Solution (Python):
n,a,b,c,d=map(int,input().split());print('NYOE S'[any(c*i-d*(~i+n)<=b-a<=d*i-c*(~i+n)for i in range(n))::2])

Solution (Python):
n,a,b,c,d=map(int,input().split());print('NYOE S'[any(c*i-d*(~i+n)<=b-a<=d*i-c*(~i+n)for i in range(n))::2])

Solution (Python):
n,a,b,c,d=map(int,input().split())
f=0
for i in range(n):f|=i*c-(~i+n)*d<=b-a<=i*d-(~i+n)*c
print('NYOE S'[f::2])

Solution (Python):
n,a,b,c,d=map(int,input().split())
for i in range(n-1):
    if c*i-d*(n-1-i)<=abs(a-b)<=d*i-c*(n-1-i):
        print("YES")
        break
else:
    print("NO")

Solution (Python):
N, A, B, C, D = map(int, input().split())

S = B - A
ans = False
for m in range(N):
    n = N - 1 - m
    if C * m - D * n <= S <= D * m - C * n:
        ans = True
print('YES' if ans else 'NO')

Solution (Python):
N, A, B, C, D = map(int, input().split())
for i in range(N):
  if -D * i + C * (N - 1 - i) <= B - A <= -C * i + D * (N - 1 - i):
    print('YES')
    break
else:
  print('NO')

Solution (Python):
N, A, B, C, D = map(int, input().split())

ans = 'NO'
for n in range(N+1):
    if A + n*C - (N-1-n)*D <= B <= A + n*D - (N-1-n)*C:
        ans = 'YES'
        break
print(ans)

Solution (Python):
import math
N,A,B,C,D = (map(int,input().split(" ")))
size = N - 1
diff = A - B
upper = D * size
bottom = C * size

ans = "NO"
for _ in range(N - 1):
    if bottom <= diff <= upper:
        ans = "YES"
        break
    bottom -=(C+D)
    upper -=(C+D)
print(ans)

Solution (Python):
n,a,b,c,d = map(int, input().split())

for i in range(n):
    if d*i-c*(n-1-i) >= b-a >= c*i-d*(n-1-i):
        print('YES')
        exit()
print('NO')

Solution (Python):
N,A,B,C,D = map(int,input().split())
dif = abs(A-B)
for i in range(N):
    if (i)*C-(N-i-1)*D <= dif <= (i)*D-(N-i-1)*C:
        print("YES")
        exit()
print("NO")

Solution (Python):
N,A,B,C,D=map(int,input().split())
l,r=0,N
for i in range(N-1):
    a=A+i*C-(N-1-i)*D
    b=A+i*D-(N-1-i)*C
    if B>=a and B<=b:
        print("YES")
        exit()
print("NO")

Solution (Python):
N, A, B, C, D = map(int, input().split())
if D == 0:
    if A == B:
        print('YES')
    else:
        print('NO')
    exit()

else:
    for i in range(N):
        if C * (N - 1 - i) - D * i <= B - A <= -C * i + (N - 1 - i) * D:
            print('YES')
            exit()
    print('NO')

Solution (Python):
n,a,b,c,d = map(int,input().split())
b = abs(b-a)
t = False
for m in range(n):
    if c*(n-1-m)-d*m <= b and b <= -c*m + (n-1-m)*d:
        t = True
        break

if t:
    print("YES")
else:
    print("NO")

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,a,b,c,d = LI()

f = defaultdict(list)
lst = []
s,t = 0,n-1
for _ in range(n):
    lst.append((a+s*c-t*d,a+s*d-t*c))
    s += 1
    t -= 1
for i,j in lst:
    if i <= b <= j:
        print('YES')
        quit()
print('NO')

Solution (Python):
N,a,b,c,d = map(int,input().split())
n = N - 1
ans = "NO"
for i in range(n+1):
    m1 = i*d - (n-i)*c
    m2 = -1*(n-i)*d + i*c
    if m1 <= m2:
        if a + m1 <= b and b <= a+ m2:
            ans = "YES"
            
            break
    else:
        if a + m2 <= b and b <= a + m1:
            ans = "YES"
            
            break
print(ans)

Solution (Python):
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N, A, B, C, D = map(int, input().split())

    A, B = min(A, B), max(A, B)
    diff = B - A

    for plus in range(N):
        if C * (N - 1 - plus) - D * plus <= diff<= -C * plus + D * (N - 1 - plus):
            print('YES')
            return

    print('NO')

sol()

Solution (Python):
import sys
input = sys.stdin.readline



import numpy as np

N,A,B,C,D = map(int,input().split())


rng = np.arange(N,dtype=np.int64)
upper = D*rng - C*rng[::-1]
lower = C*rng - D*rng[::-1]

answer = 'YES' if ((lower <= B-A) & (B-A <= upper)).any() else 'NO'
print(answer)

Solution (Python):
N, A, B, C, D = map(int, input().split())





k = (B - A + (N - 1) * D) // (C + D)

if k >= (B - A + (N - 1) * C) / (C + D) and N - 1 >= k >= 0:
    print ('YES')
else:
    print ('NO')

Solution (Python):
N, A, B, C, D = map(int, input().split())


if A > B:
    A, B = B, A

for k in range(N):
    if k * C - (N - 1 - k) * D <= B - A <= k * D - (N - 1 - k) * C:
        print ('YES')
        exit()
print ('NO')

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, A, B, C, D = list(map(int, sys.stdin.readline().split()))


ok = False

for k in range(N):
    top = D * (N - 1 - k) - C * k
    bottom = C * (N - 1 - k) - D * k
    ok |= bottom <= B - A <= top
if ok:
    print('YES')
else:
    print('NO')

Solution (Python):
import sys
n,a,b,c,d=map(int,input().split())
for i in range(n-1):
  if (n-1-i)*d-i*c>=a-b and (n-1-i)*c-i*d<=a-b:
    print('YES')
    sys.exit()
print('NO')

Solution (Python):
N,A,B,C,D=map(int,input().split())
if A>B:
    A,B=B,A
N-=1
if N%2==1:
    m=[[A+C,A+D],[A-D,A-C]]
    N-=1
else:
    m=[[A,A]]
    
flag=0
e=D-C

for MIN,MAX in m:
    if MIN<=B<=MAX:
        flag=1
        break
    if MIN>B:
        MAX,MIN=MIN,MAX
    MAX=abs(MAX-MIN)
    b=abs(B-MIN)
    MIN=0
    n=N//2
    p=[b-n*e,b+n*e]
    for i in range(n+1):
        if p[1]<MIN:
            break
        elif MAX<p[0]:
            MIN+=2*C
            MAX+=2*D
            p[0]+=e
            p[1]-=e
        else:
            flag=1
            break

print(["NO","YES"][flag])

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n = I()
    b = LI()
    ans = []
    for j in range(n):
        for i in range(len(b))[::-1]:
            if b[i] == i+1:
                x = b.pop(i)
                ans.append(x)
                break
    if b:
        print(-1)
    else:
        print(*ans[::-1],sep = "\n")
    return


def B():
    n,a,b,c,d = LI()
    s = S()
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    k = b
    while b < d:
        if s[b+1] == ".":
            b += 1
        else:
            if s[b+2] == "
                print("No")
                return
            b += 2
    b = k
    if c < d:
        while a < c:
            if s[a+1] == ".":
                a += 1
            else:
                if s[a+2] == "
                    print("No")
                    return
                a += 2
        print("Yes")
    else:
        for i in range(b-1,d):
            if s[i:i+3].count(".") == 3:
                print("Yes")
                return
        print("No")
    return


def C():
    n,a,b,c,d = LI()
    if abs(b-a) > (n-1)*d:
        print("NO")
        return
    if 2*c <= (n-1)*(d-c):
        print("YES")
        return
    mi = a-(n-1)*d
    m = c+d
    f = 1+(n-1)*(d-c)
    if f >= m:
        print("YES")
        return
    if (b-mi)%m < f:
        print("YES")
    else:
        print("NO")
    return


def D():
    n = I()

    return


def E():
    n = I()

    return


def F():
    n = I()

    return


if __name__ == "__main__":
    C()

Solution (Python):
N,A,B,C,D = map(int,input().split())
ans = False
E = abs(B-A)
for i in range(N):
    j = N-1-i
    m = C*i - D*j
    M = D*i - C*j
    ans = m<=E<=M
    if ans:break
print("YES" if ans else "NO")

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n, a, b, c, d = li()

exist = False
mx = n - 1

for i in range(n):
    if a + i*c - (mx-i)*d <= b <= a + i*d - (mx-i)*c:
        exist = True
        break

print("YES" if exist else "NO")

Solution (Python):
N, A, B, C, D = map(int, input().split())
for i in range(N):
    if -D*i + C*(N-1-i) <= B - A <= D*(N-1-i) - C*i: print('YES'); break;
else:
    print('NO')

Solution (Python):
n,a,b,c,d=map(int,input().split())
a,b=min(a,b),max(a,b)
pl1=b-d
pr1=b-c
pl2=b+c
pr2=b+d
flag=False
for i in range((n-2)//2+1):
  j=(n-2)-i*2
  al=a+j*c+i*(c-d)
  ar=a+j*d+i*(d-c)
  if (al<pl1 and pl1<=ar) or pl1<=al<=pr1:
    flag=True
    break
  if (al<pl2 and pl2<=ar) or pl2<=al<=pr2:
    flag=True
    break
if flag==True:
  print('YES')
else:
  print('NO')

Solution (Python):
N,A,B,C,D=map(int,input().split())
b=[D+D,C+C,D-C]
b2=[D,C,-C,-D]
def solve(s,e,b,n):
    while True:
        if abs(e-s)>b[0]*n//2:
            return False
        if b[2]*n//2>=abs(e-s) or b[1]*n//2<=abs(e-s)<=b[0]*n//2:
            return True
        n-=2
        if n<0:
            return False
        if s+b[0]<e:
            s+=b[0]
        elif s+b[1]<=e:
            s=e
        elif s<e:
            s+=b[1]
        elif s-b[0]>e:
            s-=b[0]
        elif s-b[1]>=e:
            s=e
        else:
            s-=b[1]
if N%2==0:
    for d in b2:
        a=solve(A,B+d,b,N-2)
        if a==True:
            break
else:
    a=solve(A,B,b,N-1)
print(['NO','YES'][a])

Solution (Python):
def main():
    N, A, B, C, D = map(int, input().split())
    diff = B - A
    for i in range(N-1):
        if -D * i + C * (N-1-i) <= diff <= -C * i + D * (N-1-i):
            print("YES")
            return
    print("NO")


if __name__ == "__main__":
    main()

Solution (Python):
N,A,B,C,D = list(map(int,input().split()))

E = B-A

flag=False

for i in range(N):
    if E>=i*C-(N-i-1)*D and E<=i*D-(N-i-1)*C:
        flag=True

if flag:
    print("YES")
else:
    print("NO")

Solution (Python):
N,A,B,C,D = map(int,input().split())
for m in range(N-1):
    if C*(N-1-m) - D*m <= B-A <= -C*m + (N-1-m)*D:
        print("YES")
        exit()
print("NO")

Solution (Python):
def between(l,c,r):
    return l<=c and c<=r

N,A,B,C,D=[int(i) for i in input().split()]
ul = [A + D*i for i in range(N)]
dl = [A + C*i for i in range(N)]
ur = [B + D*i for i in range(N)][::-1]
dr = [B + C*i for i in range(N)][::-1]
res = False
for i in range(N):
    if between(dl[i], ur[i], ul[i]) or between(dl[i], dr[i], ul[i]):
        res=True
print("YES" if res else "NO")

Solution (Python):
N,A,B,C,D=[int(i) for i in input().split()]
ul = [A + D*i for i in range(N)]
dl = [A + C*i for i in range(N)]
ur = [B + D*i for i in range(N)][::-1]
dr = [B + C*i for i in range(N)][::-1]
res = False
for i in range(N):
    if (dl[i]<= ur[i] and ur[i]<=ul[i]) or (dl[i]<=dr[i] and dr[i]<=ul[i]):
        res=True
print("YES" if res else "NO")

Solution (Python):
N, A, B, C, D = map(int,input().split())

for k in range(N):
    if C*k-(N-k-1)*D <= B-A <= D*k-(N-k-1)*C:
        print("YES")
        exit(0)
print("NO")

Solution (Python):


import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, A, B, C, D = map(int, input().split())


def check(m):
    return C*(N-1-m)-D*m <= B-A <= -C*m+(N-1-m)*D


for m in range(N):
    if check(m):
        print("YES")
        break
else:
    print("NO")

Solution (Python):
n, a, b, c, d = [int(item) for item in input().split()]

u, l = 0, 0
while n > 1:
    if b <= a + u + (n-1) * d and b >= a + l + (n-1) * c:
        print("YES")
        exit()
    if b <= a + u + (n-1) * -c and b >= a + l + (n-1) * -d:
        print("YES")
        exit()
    n -= 2
    u += d - c
    l -= d - c
print("NO")

Solution (Python):
n,a,b,c,d=map(int,input().split())
ans=False
for k in range(n):
    if a+k*c-(n-1-k)*d<=b<=a+k*d-(n-1-k)*c:
        ans=True or ans
print('YES' if ans else 'NO')

Solution (Python):

N, A, B, C, D = map(int, input().split())



ans = (
    'YES' if any(
        A + C * m - D * (N - 1 - m) <= B <= A + D * m - C * (N - 1 - m)
        for m in range(N)
    ) else
    'NO'
)


print(ans)

Solution (Python):
n, a, b, c, d = map(int, input().split())

for i in range(n):
    if c*(n-i-1)-d*i <= b-a and b-a <= d*(n-i-1)-c*i:
        print("YES")
        exit()
print("NO")

Solution (Python):

N, A, B, C, D = map(int,input().split())

for i in range(N-1):
    if C * (N-i-1) - D * i <= (B - A) <= D * (N-i-1) - C * i:
        print("YES")
        exit()

print("NO")

Solution (Python):
n, a, b, c, d = map(int, input().split())
flag = False
for i in range(n):
    s = c*(n-1-i) - d*i
    t = d*(n-1-i) - c*i
    if s <= b-a <= t:
        flag = True
        break
print("YES" if flag else "NO")

Solution (Python):
n, a, b, c, d = map(int, input().split())

is_inb = False
ul, ur, dl, dr = a, a, a, a
for i in range(1, n):
  ul, ur = ul + c, ur + d
  dl, dr = dl - d, dr - c
  if ul - (n - i - 1) * d <= b <= ur - (n - i - 1) * c or dl + (n - i - 1) * c <= b <= dr + (n - i - 1) * d:
    print('YES')
    is_inb = True
    break

if not is_inb:
  print('NO')

Solution (Python):


n,a,b,c,d=map(int,input().split())
for i in range(n):
    x,y=(a+c*i,a+d*i)
    j=n-i-1
    z,w=(b+c*j,b+d*j)
    if x<=z<=y or x<=w<=y:
        print('YES')
        break
else:
    print('NO')

Solution (Python):

N,A,B,C,D = map(int,input().split())
ans = "NO"
for k in range(N-1):
    if k*C - (N-1-k)*D <= B-A <= k*D - (N-1-k)*C:
        ans = "YES"
        break
print(ans)

Solution (Python):


import sys
from bisect import bisect_left, bisect_right

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, a, b, c, d = LI()

    base = [-INF]
    if n % 2:
        base += list(reversed([a - (2 * c + d - c) * i for i in range(1, (n + 1) // 2)])) + [a + (2 * c + d - c) * i for i in range((n + 1) // 2)]
    else:
        base += list(reversed([a - (d + c) // 2 - (2 * c + d - c) * i for i in range(n // 2)])) + [a + (d + c) // 2 + (2 * c + d - c) * i for i in range(n // 2)]
    base += [INF]

    near = bisect_left(base, b)
    
    

    l = base[near - 1]
    r = base[near]
    x = l if b - l <= r - b else r
    
    if n % 2:
        tmp = ((n + 1) // 2 - 1) * (d - c)
        
        if x - tmp <= b <= x + tmp:
            res = 'YES'
        else:
            res = 'NO'
    else:
        tmp = (n // 2 - 1) * (d - c) + (d - c) // 2
        
        if (d - c) % 2:
            if a <= b:
                if x - tmp <= b <= x + tmp + 1:
                    res = 'YES'
                else:
                    res = 'NO'
            else:
                if x - tmp - 1 <= b <= x + tmp:
                    res = 'YES'
                else:
                    res = 'NO'
        else:
            if x - tmp <= b <= x + tmp:
                res = 'YES'
            else:
                res = 'NO'

    return res


print(main())

Solution (Python):
import math
def solve():
  n,a,b,c,d = (int(i) for i in input().split())
  if a > b: a,b = b,a
  ans = 'NO'
  for i in range(n):
    if a+ i*c -(n-i-1)*d <= b <= a + i * d - (n - i - 1) * c:
     ans ='YES'
  return ans
if __name__ == '__main__':
  print(solve())

Solution (Python):
n, a, b, c, d = map(int, input().split())
if a > b:
    a, b = b, a

for k in range(n):
    if a + k * c - (n - k - 1) * d <= b <= a + k * d - (n - k - 1) * c:
        print("YES")
        exit()

print("NO")

Solution (Python):
N,A,B,C,D = map(int, input().split())

n = N-1

found = False

B = abs(A-B)
for i in range(0, n+1):
    if C*(n-i)-D*(i) <= B <= D*(n-i)-C*(i):
        found = True
        break

if found:
    print("YES")
else:
    print("NO")

Solution (Python):
n, a, b, c, d = map(int, input().split())
n -= 1
k = abs(b-a)
if k > n*d:
    print("NO")
elif k >= n*c:
    print("YES")
else:
    i = -(-(n*c-k)//(2*c))
    haba = k - (n-2*i)*c
    if haba <= (d-c)*(n-i):
        print("YES")
    else:
        j = i-1
        haba = (n-2*j)*c - k
        if haba <= (d-c)*j:
            print("YES")
        else:
            print("NO")