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):
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):
n, a, b, c, d = map(int, input().split())
for m in range(n):
    if c * (n - 1 - m) - d * m <= b - a <= -c * m + (n - 1 - m) * d:
        print("YES")
        exit()

print("NO")

Solution (Python):
N, A, B, C, D = [int(_) for _ in input().split()]
distance = abs(A - B)
for i in range(N):
    if -D * i + C * (N - 1 - i) <= distance <= -C * i + D * (N - 1 - i):
        print('YES')
        exit()
print('NO')

Solution (Python):
n, a, b, c, d = map(int, input().split())
diff_ab = abs(b-a)
diff_cd = d - c
mod = c + d
mod_ab = diff_ab % mod
MAX = d * (n-1)
MAX_mod = MAX % mod
MIN_mod = (c * (n-1)) % mod
if MAX >= diff_ab:
    if diff_cd * (n-1) + 1 >= mod:
        print("YES")
    else:
        if MAX_mod >= MIN_mod:
            if MIN_mod <= mod_ab <= MAX_mod:
                print("YES")
            else:
                print("NO")
        else:
            if mod_ab >= MIN_mod or mod_ab <= MAX_mod:
                print("YES")
            else:
                print("NO")

else:
    print("NO")

Solution (Python):
n, a, b, c, d = map(int, input().split())
diff_ab = abs(b-a)
diff_cd = d - c
mod = c + d
mod_ab = diff_ab % mod
MAX = d * (n-1)
MAX_mod = MAX % mod
MIN_mod = (c * (n-1)) % mod
if MAX >= diff_ab:
    if diff_cd * (n-1) + 1 >= mod:
        print("YES")
    else:
        if MAX_mod >= MIN_mod:
            if mod_ab <= MAX_mod and mod_ab >= MIN_mod:
                print("YES")
            else:
                print("NO")
        else:
            if mod_ab >= MIN_mod or mod_ab <= MAX_mod:
                print("YES")
            else:
                print("NO")
        
else:
    print("NO")

Solution (Python):
import sys
N,A,B,C,D=map(int,input().split())
h=B-A
for K in range(N):
    s=C*K-D*(N-1-K)
    t=D*K-C*(N-1-K)
    if s<=h<=t:
        print('YES')
        sys.exit()
print('NO')

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
N, A, B, C, D = inpl()
for k in range(N+1):
    j = N-1-k
    if D*k - C*j >= B-A >= C*k - D*j:
        print('YES')
        break
else:
    print('NO')

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
N, A, B, C, D = inpl()
for k in range(N+1):
    j = N-1-k
    if D*k - C*j >= B-A >= C*k - D*j:
        print('YES')
        break
else:
    print('NO')

Solution (Python):

import sys
input = sys.stdin.readline

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

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

    print("NO")

if __name__ == '__main__':
    main()

Solution (Python):
N,A,B,C,D=map(int,input().split())
for i in range(N):
  if A+i*C-(N-i-1)*D<=B<=A+i*D-(N-i-1)*C:
    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-1-i) - D*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())

res = 0
r = b-a
for k in range(1,n):
    s1 = k*c - d *(n-1-k)
    t1 = k*c - c *(n-1-k)
    if s1 <= r and r <= t1:
        res = 1
        break
    
    s1 = k*d - d *(n-1-k)
    t1 = k*d - c *(n-1-k)
    if s1 <= r and r <= t1:
        res = 1
        break

if res == 1:
    print("YES")
else:
    print("NO")

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

res = 0
r = b-a
for k in range(1,n):
    s1 = k*c - d *(n-1-k)
    t1 = k*c - c *(n-1-k)
    if s1 <= r and r <= t1:
        res = 1
        break
    
    s1 = k*d - d *(n-1-k)
    t1 = k*d - c *(n-1-k)
    if s1 <= r and r <= t1:
        res = 1
        break

if res == 1:
    print("YES")
else:
    print("NO")

Solution (Python):
n,a,b,c,d = map(int,input().split())
for p in range(n-1):
    q = n - 1 - p
    b_min = p * c - q * d
    b_max = p * d - q * c
    if b_min <= b - a <= b_max:
        print('YES')
        exit()
print('NO')

Solution (Python):

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

def check(m):
    return c*(n-1-m)-d*m<=b-a<=-1*c*m+(n-1-m)*d

for m in range(n):
    if check(m):
        print("YES")
        exit()
print("NO")

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


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

Solution (Python):
n, a, b, c, d=map(int, raw_input().split())
diff=max(a, b)-min(a, b)
for i in range(n-1):
	if i*c-(n-1-i)*d<=diff<=i*d-(n-1-i)*c:
		print "YES"
		quit()
print "NO"

Solution (Python):
n, a, b, c, d=map(int, raw_input().split())
diff=max(a, b)-min(a, b)
for i in range(n):
	if i*c-(n-1-i)*d<=diff<=i*d-(n-1-i)*c:
		print "YES"
		quit()
print "NO"

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

sys.setrecursionlimit(10**5) 
 
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

for m in range(n-1):
    if -d*m+c*(n-1-m) <= b-a <= -c*m+d*(n-1-m):
        exist = True
        
if exist:
    print("YES")
else:
    print("NO")

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

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

print('NO')

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,A,B,C,D = inpl()
N -= 1
dist = abs(B-A)

if dist > D*(N-1):
    print('NO')
else:
    if N%2 == 0:
        for i in range(N//2+1):
            mid = i*(C+D)
            if abs(dist-mid) <= N*(D-C)/2:
                print('YES')
                sys.exit()
        print('NO')
    else:
        for i in range(N//2+1):
            mid = (i+1/2)*(C+D)
            if abs(dist-mid) <= N*(D-C)/2:
                print('YES')
                sys.exit()
        print('NO')

Solution (Python):
ai = lambda: list(map(int, input().split()))

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

for k in range(n):
    if a + k*c - d*(n-1-k) <= b <= a + k*d - c*(n-1-k):
        print('YES')
        break
else:
    print('NO')

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

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

Solution (Python):
N, A, B, C, D = map(int, input().split())
lb, ub = A, A
for _ in range(1, N):
    if (lb + ub) / 2 < B:
        lb, ub = lb + C, ub + D
    else:
        lb, ub = lb - D, ub - C
if lb <= B <= ub:
    print('YES')
else:
    print('NO')

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

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

Solution (Python):
n, a, b, c, d = map(int, input().split())
a, b = 0, b - a
segs = [[-d * (n - 1), -c * (n - 1)]]
for _ in range(n - 1):
	segs.append([segs[-1][0] + c + d, segs[-1][1] + c + d])
ok = False
for i in range(n):
	if segs[i][0] <= b <= segs[i][1]:
		ok = True
if ok:
	print("YES")
else:
	print("NO")

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

Solution (Python):


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

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

diff = B - A
flag = False

for i in range(N):
    rem = N - i - 1
    if C * i - D * rem <= diff <= D * i - C * rem:
        flag = True

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

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B, C, D):

    B -= A
    A = 0
    M = N - 1
    for i in range(N):
        u = i * D - (M-i) * C
        l = i * C - (M-i) * D
        if l <= B <= u:
            return 'YES'

    return 'NO'


def main():
    N, A, B, C, D = read_int_n()
    print(slv(N, A, B, C, D))


if __name__ == '__main__':
    main()

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B, C, D):

    B -= A
    A = 0
    M = N - 1
    for i in range(N):
        u = i * D - (M-i) * C
        l = i * C - (M-i) * D
        if l <= B <= u:
            return 'YES'

    return 'NO'


def main():
    N, A, B, C, D = read_int_n()
    print(slv(N, A, B, C, D))


if __name__ == '__main__':
    main()

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

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


if __name__ == '__main__':
    main()

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

for i in range(N):
  if i*C - (N-i-1)*D <= abs(B-A) <= i*D - (N-i-1)*C:
    ans=True
    break
if ans:
  print("YES")
else:
  print("NO")

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

Solution (Python):
N, A, B, C, D = [int(_) for _ in input().split()]

dAB = B - A
dCD = (D - C) / 2
m = (C + D) / 2

x = A
v = 0
for i in range(2, N + 1):
    if x < B:
        x += m
    else:
        x -= m
    v += dCD

if x - v <= B <= x + v:
    print("YES")
else:
    print("NO")

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

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

if __name__ == '__main__':
    print(main())

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

div = abs(B-A)
if (div > D*(N-1)):
    print("NO")
    exit()
check = div // C
upcount = check + (N-1-check) // 2
downcount = N-1 - upcount


if (N-1) % 2 == 0:
    ans = div % (2*C)
    if (ans <= upcount*(D-C)) or (ans >= 2*C - (downcount-1)*(D-C)):
        print("YES")
    else:
        print("NO")
else:
    ans = (div - C) % (2*C)
    if (ans <= upcount*(D-C)) or (ans >= 2*C - (downcount-1)*(D-C)):
        print("YES")
    else:
        print("NO")

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

for i in range(n):
  u= i * d - (n-1-i)*c
  l= i * c - (n-1-i)*d
  if a+l<= b <=a+u or a-u<=b<=a-l:
      print('YES')
      break
else:
  print('NO')

Solution (Python):
if __name__ == "__main__":
    N, A, B, C, D = map(int, input().split())
    
    
    rest = N - 2

    for k in range(rest + 1):
        
        l = rest + 1 - k
        left = A + C * k - l * D
        right = A + D * k - l * C
        
        if left <= B and B <= right:
            print("YES")
            exit(0)
    print("NO")

Solution (Python):


import sys, math, copy




HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n, a, b, c, d = map(int, input().split())
    diff = b - a
    for m in range(n):
        mi = -d * m + c * (n - 1 - m)
        ma = -c * m + d * (n - 1 - m)
        if mi <= diff <= ma:
            return True
    return False

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

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

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

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

ok = 0
B -= A; B = abs(B)
k = N-1
if B <= k*D:
    if (k-1)*(D-C) >= 2*C:
        ok = 1
    else:
        r = k*(D-C)
        sp = 2*C - (k-1)*(D-C)
        if k % 2 == 1:
            
            if sp//2 <= B and (B-sp//2) % (sp + r) <= r:
                ok = 1
        else:
            
            if B <= r//2 or (B-r//2-sp) % (sp + r) <= r:
                ok = 1
print('YES' if ok else 'NO')

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    N, A, B, C, D = map(int, input().split())
    B -= A
    for i in range(N):
        j = N - i - 1
        large1 = C * i
        small1 = D * j
        small = large1 - small1

        large2 = D * i
        small2 = C * j
        large = large2 - small2
        if small <= B <= large:
            print("YES")
            return
    print("NO")


if __name__ == '__main__':
    main()

Solution (Python):
input1 = list(map(int,input("").split(" ")))
N = input1[0]
A = input1[1]
B = input1[2]
C = input1[3]
D = input1[4]

flag = False
for x in range(N-1):
	y = N -1 - x
	if (C*y - D*x) <= (B-A) and (B-A) <= -1*C*x + y*D:
		flag = True
		break

if flag == True:
	print('YES')
else:
	print('NO')

Solution (Python):
def moderate_differences_2():
	n, a, b, c, d = map(int, raw_input().split(" "))
	
	
	
	
	for m in range(0, n):
		max_sum = m*(-c)+(n-1-m)*(d)
		min_sum = m*(-d)+(n-1-m)*(c)
		if (b-a)>=min_sum and (b-a)<=max_sum:
			print "YES"
			return
	print "NO"

if __name__ == "__main__":
	moderate_differences_2()

Solution (Python):
N,A,B,C,D=map(int,input().split())
ans=0
for i in range(N):
  if C*i-D*(N-1-i)<= B-A<= D*i-C*(N-1-i): ans=1

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

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




succeed = False
for m in range(N):
    if C * (N - 1 - m) - D * m <= B - A <= -C * m + (N - 1 - m) * D:
        succeed = True
        break

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

Solution (Python):









import sys, re

def solve(N, A, B, C, D):
  for i in range(N):
    upper = i * D - (N - 1 - i) * C
    lower = i * C - (N - 1 - i) * D
    if lower <= B - A and B - A <= upper:
      return True
  return False

for line in sys.stdin:
  words = re.split(r'\s+', line.strip())
  N, A, B, C, D = [int(w) for w in words]  
  result = solve(N, A, B, C, D)
  print('YES' if result else 'NO')

Solution (Python):



import sys, re

def solve(args):
  N = args[0]
  A = args[1]
  B = args[2]
  C = args[3]
  D = args[4]
  for i in range(N):
    upper = i * D - (N - 1 - i) * C
    lower = i * C - (N - 1 - i) * D
    if lower <= B - A and B - A <= upper:
      return True
  return False

for line in sys.stdin:
  words = re.split(r'\s+', line.strip())
  args  = [int(w) for w in words]  
  print('YES' if solve(args) else 'NO')

Solution (Python):
N,A,B,C,D = map(int,input().split())
flag = D * (N - 1)
B -= A
if D - C == 0:
	if A == B:
		print("YES")
	else:
		print("NO")
elif N % 2 == 1:
	if (B % (C + D) <= (N - 1) * (D - C) / 2 or abs(B % (C + D) - (C + D)) <= (N - 1) * (D - C) / 2) and B <= flag and B >= -flag:
		print("YES")
	else:
		print("NO")
else:
	if abs(B % (C + D) - (D + C) / 2) <= (N - 1) * (D - C) / 2 and B <= flag and B >= -flag:
		print("YES")
	else:
		print("NO")

Solution (Python):
def solve(n, a, b, c, d):
    if d == 0:
        return a == b
    t = n - 1
    ab = abs(a - b)
    if ab > d * t:
        return False
    return (ab - c * t) % (c + d) <= (d - c) * t


print('YES' if solve(*map(int, input().split())) else 'NO')

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

flag = False
for k in range(1,n-1):
    if(k*c-(n-1-k)*d <= b-a and b-a <= k*d-(n-1-k)*c):
        flag = True
if(flag): print("YES")
else: print("NO")

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

answer_flag = False
for i in range(N):
    if (C*(N-1-i)-D*i<=(B-A)) and ((B-A)<=-C*i+D*(N-1-i)):
        answer_flag = True
        break

if answer_flag==True:
    print("YES")
else:
    print("NO")

Solution (Python):


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

a = abs(A - B)
b = abs(D - C)
l = 0
r = 0
p = 0

for i in range(N-1):
    if p < a:
        p += C
        r += b
    else:
        p -= C
        l += b
        
if p <= a:
    print('YES' if p+r >= a else 'NO')
else:
    print('YES' if p-l <= a else 'NO')

Solution (Python):
def f():
    n, a, b, c, d = list(map(int, input().split(" ")))
    h = abs(b-a)
    for m in range(n):
        if c*m-d*(n-m-1)<=h<=d*m - c*(n-m-1):
            print("YES")
            return
    print("NO")

f()

Solution (Python):
n, a, b, c, d = map(int, raw_input().split())
if a > b: a, b = b, a
for i in xrange(n - 1):
    mn = -d * i + c * (n - 1 - i)
    mx = -c * i + d * (n - 1 - i)
    if mn <= b - a <= mx:
        print "YES"
        exit()
print "NO"

Solution (Python):
N, A, B, C, D = list(map(int, input().split()))
isYes = False
for k in range(N-1):
	if k*C-(N-1-k)*D <= B-A and B-A <= k*D-(N-1-k)*C:
		isYes = True
		break
if isYes:
	print("YES")
else:
	print("NO")

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


diff = B - A

is_ok = False
for k in range(N - 1):
    min = k * C - (N - 1 - k) * D
    max = k * D - (N - 1 - k) * C
    if min <= diff and diff <= max:
        is_ok = True
        break

if is_ok:
    print('YES')
else:
    print('NO')

Solution (Python):
n, a, b, c, d = map(int, raw_input().split())
dd = b - a
n -= 1
if dd < 0:
  dd = -dd


def get(n, c, d):
  l = -1
  r = n
  while l + 1 < r:
    mid = (l + r) / 2
    if mid * c - (n - mid) * d >= 0:
      r = mid
    else:
      l = mid
  return l if l >= 0 else 0

l = get(n, c, d)

ok = False

for i in range(l, n + 1):
  ll = i * c - (n - i) * d
  rr = i * d - (n - i) * c
  
  if ll <= dd and rr >= dd:
    
    ok = True
  if ll > dd:
    break

if ok:
  print('YES')
else:
  print('NO')

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

def foo():
    for i in range(N):
        hoge = C * (N - 1 - i) - D * i <= B - A
        fuga = B - A <= -C * i + (N - 1 - i) * D
        
        yield hoge and fuga

print('YES' if any(foo()) else 'NO')

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


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

Solution (Python):
N,A,B,C,D=map(int,input().split())
N=N-1
l=[]
for i in range(0,N+1):
    l.append(range(i*C-(N-i)*D,i*D-(N-i)*C+1))

for _ in l:
    if B-A in _:
        print("YES")
        break
else:
    print("NO")

Solution (Python):

import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

def solve():
    N, A, B, C, D = map(int, raw_input().split()) 
    A, B = 0, B - A
    if B < 0: B *= -1
    M = N - 1

    for i in xrange(N):
        if C*(M - i) - D*i <= B <= D*(M - i) - C*i:
            return True

    return False

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

Solution (Python):
N,A,B,C,D = map(int, raw_input().rstrip().split(' '))
diff = abs(B-A)
r = False

m = N-1
for k in xrange(1, 1+m):
    hi = k*D - (m-k)*C
    lo = k*C - (m-k)*D
    if lo <= diff <= hi:
        r = True
        break

print 'YES' if r else 'NO'

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







num = abs(B-A)
ans = False
for i in range(N-1, N):
    if(i%2==1):
        for j in range(i//2+1, i+1):
            if(j*C-(i-j)*D<=num and num<=j*D-(i-j)*C):
                ans = True
    else:
        for j in range(i//2, i+1):
            if(j*C-(i-j)*D<=num and num<= j*D-(i-j)*C):
                ans = True
if(ans):
    print("YES")
else:
    print("NO")

Solution (Python):


import sys
import math
import itertools

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










diff = D-C
target_diff = abs(A-B)
odd_or_evens = (N-1) % 2
upper_raw_count = int(math.ceil(float(target_diff) / D))
upper_count = (upper_raw_count + (upper_raw_count + odd_or_evens) % 2)
upper = upper_count * D
lower_raw_count = int(math.floor(float(target_diff) / D))
lower_count = (lower_raw_count - (lower_raw_count + odd_or_evens) % 2 )
lower = lower_count * D








if target_diff > (N-2) * D:
    print("NO")
else:
    
    
    
    
    if (
            (upper - (upper_count + (N-1)) // 2 * diff) <= target_diff
    ) or (
        (lower + ((N-1-lower_count) // 2) * diff) >= target_diff):
        print("YES")
    else:
        print("NO")

exit(0)

Solution (Python):

import math

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

	for i in range(N):
		plus_band = calcBand(i, C, D)
		minus_band = calcBand(N - i - 1, C, D)
		total_band = (plus_band[0] - minus_band[1], plus_band[1] - minus_band[0])

		if total_band[0] <= B - A <= total_band[1]:
			print("YES")
			break
	else:
		print("NO")

def calcBand(n_band, C, D):
	return((C * n_band, D * n_band))

if __name__ == '__main__':
	main()

Solution (Python):
if __name__ == '__main__':
    N, A, B, C, D = list(map(int, input().split()))
    if C + D == 0:
        if A == B:
            print("YES")
        else:
            print("NO")
    else:
        average_c_d = (C + D) / 2

        range_c_d = (D - C) / 2

        ul = A - average_c_d * (N - 1)

        target_index = round((B - ul) / (C + D))

        if target_index < 0:
            target_index = 0
        elif N - 1 < target_index:
            target_index = N - 1

        under = ul + (C + D) * target_index - range_c_d * (N - 1)
        upper = ul + (C + D) * target_index + range_c_d * (N - 1)

        if under <= B <= upper:
            print("YES")
        else:
            print("NO")

Solution (Python):

import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

def solve():
    N, A, B, C, D = map(int, raw_input().split()) 
    A, B = 0, B - A
    if B < 0: B *= -1
    M = N - 1

    for i in xrange(0, N, 2):
        if C*(M - i) <= B <= (D - C)*((i + 1)/2) + D*(M - i):
            return True

    for i in xrange(N):
        if C*(M - i) - D*i <= B <= D*(M - i) - C*i:
            return True

    return False

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

Solution (Python):
N,A,B,C,D=[int(i) for i in input().split()]
diff=B-A

found=False
for i in range(N):
    j=N-1-i
    left=i*C-j*D
    right=i*D-j*C
    if left<=diff and diff<=right:
        print("YES")
        found=True
        break
if not(found):
    print("NO")

Solution (Python):
def main():
    n, a, b, c, d = [int(_) for _ in raw_input().split()]
    x0 = int(round((b - a) / (c + d) * 1.0 + (n - 1) / 2.0))
    for x in xrange(max(0, x0 - 2), min(x0 + 3, n - 1)):
        m1 = a + c * x
        M1 = a + d * x
        m2 = b - c * (x - n + 1)
        M2 = b - d * (x - n + 1)
        if max(m1, m2) <= min(M1, M2):
            return True
    return False


if __name__ == '__main__':
    print("YES" if main() else "NO")

Solution (Python):
import sys

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

n -= 1;

u_lim = a + n * d;
l_lim = a + n * c;

for i in range(n):
	if b >= l_lim and b <= u_lim:
		print("YES")
		sys.exit(0)
	u_lim = u_lim - c - d;
	l_lim = l_lim - c - d;
print("NO")

Solution (Python):
N,left,right,up,down=map(int,raw_input().split())
diff=abs(left-right)
def maxmin(plus,minus):
    upper=plus*(up)-minus*(down)
    under=plus*(down)-minus*(up)
    return sorted([upper,under])[::-1]
upper=N-1
under=0
flag=False
while upper>=under and not flag:
    mid=(upper+under)/2
    m=maxmin(mid,N-mid-1)
    if m[1]<=diff<=m[0]:
        flag=True
    if diff>=m[0]:
        under=mid+1
    if diff<=m[1]:
        upper=mid-1
print "YES" if flag else "NO"

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N, A, B, C, D = map(int, input().split())
diff = B - A
if diff < 0:
    diff *= -1

def can_reach(k, M):
    if k < 0:
        return False
    mx = M * D
    mn = M * C
    m = (M - k) // 2

    mx -= (D + C) * m
    mn -= (D + C) * m

    
    return mn <= diff <= mx

flag = False
if N % 2 == 1:
    for k in range(0, N+1, 2):
        if can_reach(k, N - 1):
            flag = True
else:
    for k in range(1, N+1, 2):
        if can_reach(k, N - 1):
            flag = True
if flag:
    print("YES")
else:
    print("NO")

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

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

judge = "null"
for i in range(N):
	mx = D * i - C * (N - 1 - i)
	mn = C * i - D * (N - 1 - i)
	if mx >= B - A and mn <= B - A:
		print("YES")
		judge = "yes"
		break

if judge == "null":
	print("NO")

Solution (Python):
import sys

def diff(N,A,B,C,D):
    mini = (B+(N-1)*D-A)/(C+D)
    for i in range(int(mini), N-1):
        lower_bound = A + i*C - (N-i-1)*D
        upper_bound = A + i*D - (N-i-1)*C
        
        if lower_bound <= B and B <= upper_bound:
            return True
        elif B < lower_bound:
            return False

str = sys.stdin.readline().strip() 
N,A,B,C,D = map(int,str.strip().split(" "))
print("YES" if diff(N,A,B,C,D) else "NO")

Solution (Python):



from __future__ import division, print_function
import sys


def main():
    n, a, b, c, d = map(int, sys.stdin.readline().strip().split(" "))
    m = n - 1
    diff = b - a

    for i in range(m):
        j = m - i
        plus_min = c * i
        plus_max = d * i
        minus_min = -c * j
        minus_max = -d * j
        minimum = plus_min + minus_max
        maximum = plus_max + minus_min
        if minimum <= diff <= maximum:
            print("YES")
            break
    else:
        print("NO")


if __name__ == '__main__':
    main()

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

ans = False
l = 0
r = n - 1
cnt = 0
while cnt <= 20:
    m = (l + r) // 2
    if b < a + m * c - (n - 1 - m) * d:
        r = m
    elif a + m * d - (n - 1 - m) * c < b:
        l = m
    else:
        ans = True
        break
    cnt += 1
print('YES' if ans else 'NO')

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

ans = False
for m in range(n):
    if a + m * c - (n - 1 - m) * d <= b <= a + m * d - (n - 1 - m) * c:
        ans = True
        break

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

Solution (Python):

N,A,B,C,D= list(map(int,input().split()))
def nibun(func ,min_ ,max_ ):
    left = min_
    right= max_
    while not(left==right):
        mid = (left+right) //2
        tmp = func(mid)
        if tmp:
            right = mid
        else:
            left = mid+1
    return left

X = abs(A-B)
def calc(n):
    m = N-n-1
    min_val = -D*n +C*m
    max_val = -C*n +D*m
    return min_val , max_val

def check(n):
    return calc(n)[0] <=X


n= (nibun(check,0,N))
print("YES" if calc(n)[0]<=abs(A-B) and calc(n)[1]>=abs(A-B)else "NO")

Solution (Python):
import sys




def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve_it0(n, a, b, c, d):
    p = [[0]]
    for i in range(1, n):
        q = set()
        for x in p[-1]:
            for k in range(c, d + 1):
                q.add(x - k)
                q.add(x + k)
        p.append(sorted(q))
    for l in p:
        print(l)
    if b - a in p[-1]:
        return 'YES'
    return 'NO'


def solve_it1(n, a, b, c, d):
    x = b - a
    for i in range(n + 1):
        left = - i * d + (n - 1 - i) * c
        right = - i * c + (n - 1 - i) * d
        if left <= x <= right:
            return 'YES'
    return 'NO'


def solve():
    n, a, b, c, d = read_int_list()
    res1 = solve_it1(n, a, b, c, d)
    
    
    return res1


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()