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: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
e=abs(b-a)
if c*d==0 and a==b:
    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 lower <= n-1:
        print("YES")
    else:
        print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
e=b-a
upper=(e+(n-1)*d)/(c+d)
lower=(e+(n-1)*c)/(c+d)
if int(upper)==int(lower):
    if (e+(n-1)*c) % (c+d) == 0:
        print("YES")
    else:
        print("NO")
else:
    print("YES")

Submission status: Wrong Answer

Solution code:
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 j == 0:
        if diff == d:
            flag = True
        break
    k = abs(diff - d) / j
    if (k >= C and k <= D) or diff == d and j % 2 == 0:
        flag = True
        break

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

Submission status: Wrong Answer

Solution code:
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 j == 0:
        if diff == d:
            flag = True
        break
    k = abs(diff - d) / j
    if k >= C and k <= D:
        flag = True
        break

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

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
if A> B:
  A,B=B,A
if C>D:
  C,D=D,C
if B-A>D*(N-1):
  print("NO")
elif B-A>=C*(N-1):
  print("YES")
else:
  flag=False
  diff=B-A
  d=0
  for i in range(2,N,2):
    d+=D-C
    j= N-1 - i
    if j==0:
      if diff==d:
        flag=True
      break
    k=abs(diff - d) / j
    if k>=C and k<=D:
      flag=True
      break
    
  if flag:
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
if A> B:
  A,B=B,A
if C>D:
  C,D=D,C
if B-A>D*(N-1):
  print("NO")
elif B-A>=C*(N-1):
  print("YES")
else:
  flag=False
  diff=B-A
  d=0
  for i in range(2,N,2):
    diff=abs(diff-(D-C))
    j= N-1 - i
    if j==0:
      if diff==0:
        flag=True
      break
    k=diff / j
    if k>=C and k<=D:
      flag=True
      break
    
  if flag:
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

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

flag=False
diff=B-A
d=0
for i in range(0,N,2):
  d+=D-C
  j= N-1 - i
  if j==0:
    if diff==d:
      flag=True
    break
  k=abs(diff - d) / j
  if k>=C and k<=D:
    flag=True
    break
    
if flag:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
if A> B:
  A,B=B,A
if C>D:
  C,B=B,C
if B-A>D*(N-1):
  print("NO")
elif B-A>=C*(N-1):
  print("YES")
else:
  flag=False
  diff=B-A
  d=0
  for i in range(2,N,2):
    diff=abs(diff-(D-C))
    j= N-1 - i
    if j==0:
      if diff==0:
        flag=True
      break
    k=diff / j
    if k>=C and k<=D:
      flag=True
      break
    
  if flag:
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
if A> B:
  A,B=B,A
if C>D:
  C,B=B,C
if B-A>D*(N-1):
  print("NO")
elif B-A>=C*(N-1):
  print("YES")
else:
  flag=False
  diff=B-A
  d=0
  for i in range(2,N,2):
    d+=D-C
    j= N-1 - i
    if j==0:
      if diff==d:
        flag=True
      break
    k=abs(diff - d) / j
    if k>=C and k<=D:
      flag=True
      break
    
  if flag:
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D=map(int,input().split())
if A> B:
  A,B=B,A
if C>D:
  C,B=B,C
if B-A>D*(N-1):
  print("NO")
elif B-A>=C*(N-1):
  print("YES")
else:
  flag=False
  diff=B-A
  d=0
  for i in range(2,N,2):
    d+=D-C
    j= N-1 - i
    if j==0:
      if diff==d:
        flag=True
      break
    k=(diff - d) / j
    if k>=C and k<=D:
      flag=True
      break
    
  if flag:
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n, a, b, m, M = map(int, input().split())
n -= 1
if m + M == 0:
	if a == b:
		print("NO")
	else:
		print("YES")
	exit()
i = int(n / 2 + (b - a) / (m + M))
f = lambda j: abs((n - 2 * j) * (m + M) - 2 * (b - a)) <= n * (M - m)
if f(i) or f(i + 1):
	print("YES")
else:
	print("NO")

Submission status: Wrong Answer

Solution code:
'''
n+1個の区間
[(n-i)m-iM, -im+(n-i)M]  (i=0,1,...,n)
'''
n,a,b,m,M=map(int,input().split())
x=b-a
print("YES" if any((n-i)*m-i*M <= x <= -i*m+(n-i)*M for i in range(n+1)) else "NO")

Submission status: Wrong Answer

Solution code:
def solve() -> bool:
    from math import ceil
    n, a, b, c, d = map(int, input().split())

    diff = abs(a - b)
    if c == d:
        if (n - 1) % 2 == 0:
            return a == b
        else:
            return diff == c
    else:
        if diff > (n - 1) * d:
            return False
        elif (n - 1) * c <= diff:
            return True
        else:
            # 0<=diff<(n-1)*c
            if c * 3 > d:
                k_min = ceil(((n - 1) * c - diff) / (c * 3 - d))
                if 0 <= k_min <= (n - 1) // 2:
                    if (diff - (d - c) * k_min) <= (n - 1) * d - d * 2 * k_min:
                        return True
            return False


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

Submission status: Wrong Answer

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

if N % 2 == 0:
  if C <= abs(B-A)/(N-1) <= D:
    print('YES')
  else:
    print('NO')
else:
  if D-C <= abs(B-A)/(N-1)*2:
    print('YES')
  else:
    print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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: Wrong Answer

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):
    print ('YES')
else:
    print ('NO')

Submission status: Wrong Answer

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
    mi = a-(n-1)*d
    m = c+d
    f = n*(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: Wrong Answer

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 (n-1)*(d-c) >= 2*c:
        print("YES")
        return
    mi = a-(n-1)*d
    m = c+d
    f = n*(d-c)
    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: Wrong Answer

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 n*(d-c) >= 2*c:
        print("YES")
        return
    mi = a-(n-1)*d
    m = c+d
    f = n*(d-c)
    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: Wrong Answer

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*i - C*(N-1-i): print('YES'); break;
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
rem = N - 1; diff = abs(A - B);
if (rem % 2 == 0 and diff <= (rem // 2) * (D - C)) or (rem % 2 == 1 and D - ((rem + 1) // 2) * (D - C) <= diff):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
rem = N - 1; now = A; diff = abs(now - B) ; mode = 1 if A <= B else -1
while rem and D < diff:
    rem -= 1
    now += D * mode
    diff = abs(now - B)
if (rem % 2 == 0 and diff <= (rem // 2) * (D - C)) or (rem % 2 == 1 and D - ((rem + 1) // 2) * (D - C) <= diff):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
rem = N - 1; now = A; diff = abs(now - B) ; mode = 1 if A <= B else -1
while rem and D <= diff:
    rem -= 1
    now += D * mode
    diff = abs(now - B)
if (rem % 2 == 0 and diff <= (rem // 2) * (D - C)) or (rem % 2 == 1 and D - ((rem + 1) // 2) * (D - C) <= diff):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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=j*c+i*(c-d)
  ar=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: Wrong Answer

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: Wrong Answer

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) * -d and b <= a + l + (n-1) * -c:
        print("YES")
        exit()
    n -= 2
    u += d - c
    l -= d - c
print("NO")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

G=abs(B-A)
S=0
X=(D-C)

if N%2==0:
    if G<=D*(N-1) and ((G-D)%(2*D))<=((2*D)-(D*(N-1))):
        print("YES")
    else:
        print("NO")
else:
    if G%D<=((D-C)*((N-1)/2)) and G<=D*(N-1):
        print("YES")
    elif G%(2*D)>=(2*D-(N-1)*C) and G<=D*(N-1):
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

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

if c == d and abs(a-b)%d != 0:
    print("NO")
elif abs(a-b) > d*(n-1):
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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 == 1:
            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: Wrong Answer

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:
            return 'YES'
        else:
            return 'NO'
    else:
        tmp = (n // 2 - 1) * (d - c) + (d - c) // 2
        # print(tmp)
        if x - tmp <= b <= x + tmp:
            return 'YES'
        else:
            return 'NO'


print(main())

Submission status: Wrong Answer

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


#print("target:", abs(A-B))
#print("range: ", D-C)
#print("target is larger than D: " ,
#     abs(A-B)>D)
#target=abs(A-B)
#print("next target is: ", target-D)
#print("how many? : ", (target-D)//(D-C))

ans=False
def g(a,b,c,d,n):
  if (n-1)%2==0:
    target=abs(a-b) #スタートは0
    gain=d-c
    if ((n-1)//2)*gain>=target:
      return True
    else:
      return False
  else:
    target=abs(a-b)
    gain=d-c
    if target>d:
      if (n-2)//2 * gain >=target-d:
        return True
      else:
        return False
    elif target<c:
      if (n-2)//2 *gain >= c- target:
        return True
      else:
        return False
    elif c<=target<=d:
      return True
      
A,B=min(A,B),max(A,B)
target=B-A
pos=0
for i in range(N+1):
  if target>0:
    p=target//C
    if p<=N-i and C*p<=target<=D*p:
      print("YES")
      exit(0)
    p=target//D
    if p<=N-i and C*p<=target<=D*p:
      print("YES")
      exit(0)
    if  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
  if target >D:
    target-=D
  elif C <=target<=D:
    print("YES")
    exit(0)
  else:
    target=C-target

for i in range(N+1):
  if target>0:
    
    p=target//D
    if p<=N-i and C*p<=target<=D*p:
      print("YES")
      exit(0)
    if  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
  target-=C
  
print("NO")
exit(0)

Submission status: Wrong Answer

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


#print("target:", abs(A-B))
#print("range: ", D-C)
#print("target is larger than D: " ,
#     abs(A-B)>D)
#target=abs(A-B)
#print("next target is: ", target-D)
#print("how many? : ", (target-D)//(D-C))

ans=False
def g(a,b,c,d,n):
  if (n-1)%2==0:
    target=abs(a-b) #スタートは0
    gain=d-c
    if ((n-1)//2)*gain>=target:
      return True
    else:
      return False
  else:
    target=abs(a-b)
    gain=d-c
    if target>d:
      if (n-2)//2 * gain >=target-d:
        return True
      else:
        return False
    elif target<c:
      if (n-2)//2 *gain >= c- target:
        return True
      else:
        return False
    elif c<=target<=d:
      return True
      
A,B=min(A,B),max(A,B)
target=B-A
pos=0
for i in range(N+1):
  if target>0:
    p=target//C
    if p<=N-i and C*p<=target<=D*p:
      print("YES")
      exit(0)
    p=target//D
    if p<=N-i and C*p<=target<=D*p:
      print("YES")
      exit(0)
    if  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
  if target >D:
    target-=D
  elif C <=target<=D:
    print("YES")
    exit(0)
  else:
    target=C-target
print("NO")
exit(0)

Submission status: Wrong Answer

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


#print("target:", abs(A-B))
#print("range: ", D-C)
#print("target is larger than D: " ,
#     abs(A-B)>D)
#target=abs(A-B)
#print("next target is: ", target-D)
#print("how many? : ", (target-D)//(D-C))

ans=False
def g(a,b,c,d,n):
  if (n-1)%2==0:
    target=abs(a-b) #スタートは0
    gain=d-c
    if ((n-1)//2)*gain>=target:
      return True
    else:
      return False
  else:
    target=abs(a-b)
    gain=d-c
    if target>d:
      if (n-2)//2 * gain >=target-d:
        return True
      else:
        return False
    elif target<c:
      if (n-2)//2 *gain >= c- target:
        return True
      else:
        return False
    elif c<=target<=d:
      return True
      
A,B=min(A,B),max(A,B)
target=B-A
pos=0
print("NO")
exit(0)
for i in range(N+1):
  if target>0:
    p=target//C
    if p<=N-i and C*p<=target<=D*p:
      print("YES")
      exit(0)
    p=target//D
    if p<=N-i and C*p<=target<=D*p:
      print("YES")
      exit(0)
    if  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
  if target >D:
    target-=D
  elif C <=target<=D:
    print("YES")
    exit(0)
  else:
    target=C-target
print("NO")
exit(0)

Submission status: Wrong Answer

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


#print("target:", abs(A-B))
#print("range: ", D-C)
#print("target is larger than D: " ,
#     abs(A-B)>D)
#target=abs(A-B)
#print("next target is: ", target-D)
#print("how many? : ", (target-D)//(D-C))

ans=False
def g(a,b,c,d,n):
  if (n-1)%2==0:
    target=abs(a-b) #スタートは0
    gain=d-c
    if ((n-1)//2)*gain>=target:
      return True
    else:
      return False
  else:
    target=abs(a-b)
    gain=d-c
    if target>d:
      if (n-2)//2 * gain >=target-d:
        return True
      else:
        return False
    elif target<c:
      if (n-2)//2 *gain >= c- target:
        return True
      else:
        return False
    elif c<=target<=d:
      return True
      
A,B=min(A,B),max(A,B)
target=B-A
pos=0
print("NO")
exit(0)
for i in range(N+1):
  if target>0:
    p=target//C
    if p<=N-i and C*p<=target<=D*p:
      print("YES")
      exit(0)
    if  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
  if target >D:
    target-=D
  elif C <=target<=D:
    print("YES")
    exit(0)
  else:
    target=C-target
print("NO")
exit(0)      
  
if g(A,B,C,D,N):
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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


#print("target:", abs(A-B))
#print("range: ", D-C)
#print("target is larger than D: " ,
#     abs(A-B)>D)
#target=abs(A-B)
#print("next target is: ", target-D)
#print("how many? : ", (target-D)//(D-C))

ans=False
def g(a,b,c,d,n):
  if (n-1)%2==0:
    target=abs(a-b) #スタートは0
    gain=d-c
    if ((n-1)//2)*gain>=target:
      return True
    else:
      return False
  else:
    target=abs(a-b)
    gain=d-c
    if target>d:
      if (n-2)//2 * gain >=target-d:
        return True
      else:
        return False
    elif target<c:
      if (n-2)//2 *gain >= c- target:
        return True
      else:
        return False
    elif c<=target<=d:
      return True
      
A,B=min(A,B),max(A,B)
target=B-A
pos=0
for i in range(N+1):
  if target>0:
    p=target//C
    if p<=N-i and C*p<=target<=D*p:
      print("YES")
      exit(0)
    if  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
  if target >D:
    target-=D
  elif C <=target<=D:
    print("YES")
    exit(0)
  else:
    target=C-target
print("NO")
exit(0)      
  
if g(A,B,C,D,N):
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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


#print("target:", abs(A-B))
#print("range: ", D-C)
#print("target is larger than D: " ,
#     abs(A-B)>D)
#target=abs(A-B)
#print("next target is: ", target-D)
#print("how many? : ", (target-D)//(D-C))

ans=False
def g(a,b,c,d,n):
  if (n-1)%2==0:
    target=abs(a-b) #スタートは0
    gain=d-c
    if ((n-1)//2)*gain>=target:
      return True
    else:
      return False
  else:
    target=abs(a-b)
    gain=d-c
    if target>d:
      if (n-2)//2 * gain >=target-d:
        return True
      else:
        return False
    elif target<c:
      if (n-2)//2 *gain >= c- target:
        return True
      else:
        return False
    elif c<=target<=d:
      return True
      
A,B=min(A,B),max(A,B)
target=B-A
pos=0
print("NO")
for i in range(N+1):
  if target>0:
    if C*(N-i)<=target<=D*(N-i):
      print("YES")
      exit(0)
    if  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
  if target >D:
    target-=D
  elif C <=target<=D:
    print("YES")
    exit(0)
  else:
    target=C-target
print("NO")
exit(0)      
  
if g(A,B,C,D,N):
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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


#print("target:", abs(A-B))
#print("range: ", D-C)
#print("target is larger than D: " ,
#     abs(A-B)>D)
#target=abs(A-B)
#print("next target is: ", target-D)
#print("how many? : ", (target-D)//(D-C))

ans=False
def g(a,b,c,d,n):
  if (n-1)%2==0:
    target=abs(a-b) #スタートは0
    gain=d-c
    if ((n-1)//2)*gain>=target:
      return True
    else:
      return False
  else:
    target=abs(a-b)
    gain=d-c
    if target>d:
      if (n-2)//2 * gain >=target-d:
        return True
      else:
        return False
    elif target<c:
      if (n-2)//2 *gain >= c- target:
        return True
      else:
        return False
    elif c<=target<=d:
      return True
      
A,B=min(A,B),max(A,B)
target=B-A
pos=0
for i in range(N+1):
  if target>0:
    if C*(N-i)<=target<=D*(N-i):
      print("YES")
      exit(0)
    if  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
  if target >D:
    target-=D
  elif C <=target<=D:
    print("YES")
    exit(0)
  else:
    target=C-target
print("NO")
exit(0)      
  
if g(A,B,C,D,N):
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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


#print("target:", abs(A-B))
#print("range: ", D-C)
#print("target is larger than D: " ,
#     abs(A-B)>D)
#target=abs(A-B)
#print("next target is: ", target-D)
#print("how many? : ", (target-D)//(D-C))

ans=False
def g(a,b,c,d,n):
  if (n-1)%2==0:
    target=abs(a-b) #スタートは0
    gain=d-c
    if ((n-1)//2)*gain>=target:
      return True
    else:
      return False
  else:
    target=abs(a-b)
    gain=d-c
    if target>d:
      if (n-2)//2 * gain >=target-d:
        return True
      else:
        return False
    elif target<c:
      if (n-2)//2 *gain >= c- target:
        return True
      else:
        return False
    elif c<=target<=d:
      return True
      
A,B=min(A,B),max(A,B)
target=B-A
pos=0
for i in range(N+1):
  if target>0:
    if (target//C )<=N-i and target%C<=D-C:
      print("YES")
      exit(0)
    if  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
  if target >D:
    target-=D
  elif C <=target<=D:
    print("YES")
    exit(0)
  else:
    target=C-target
print("NO")
exit(0)      
  
if g(A,B,C,D,N):
  print("YES")
else:
  print("NO")