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



Sample input:
5 1 5 2 4


Sample output:
YES

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#AGC17 B

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')

Submission status: Accepted

Solution code:
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"
            #print(m1,m2)
            break
    else:
        if a + m2 <= b and b <= a + m1:
            ans = "YES"
            #print(m1,m2)
            break
print(ans)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

#右端がでかくしても一般性を失わない
# if A > B:
#     A, B = B, A

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
#!usr/bin/env python3
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

#A
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

#B
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

#C
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

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
N, A, B, C, D = map(int,input().split())
# k回正の方向に, N-k-1回負の方向に移動する
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")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# python template for atcoder1
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
# 入力
N, A, B, C, D = map(int, input().split())

# 左から右を引いた値が非負であるものの個数がm とすると負であるものの個数を N - 1 - m である。
# 各 m について一番右にBをかけるか判定する
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)

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:

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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
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')

Submission status: Accepted

Solution code:
######
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)

Submission status: Accepted

Solution code:
# coding:utf-8

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)
    # print(base)
    # print(b, near)

    l = base[near - 1]
    r = base[near]
    x = l if b - l <= r - b else r
    # print(l, r, x)
    if n % 2:
        tmp = ((n + 1) // 2 - 1) * (d - c)
        # print(tmp)
        if x - tmp <= b <= x + tmp:
            res = 'YES'
        else:
            res = 'NO'
    else:
        tmp = (n // 2 - 1) * (d - c) + (d - c) // 2
        # print(tmp)
        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())

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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()

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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")

Submission status: Accepted

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

# マイナス方向に遷移する回数iを全通り試す
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')

Submission status: Accepted

Solution code:
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"

Submission status: Accepted

Solution code:
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"

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
#!/usr/bin/env 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"

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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()

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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')