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())
N-=1
a,b=0,abs(b-a)
#上下をn回とすると、0<=n<=N//2
if d*N<b:
  print('No')
  exit()
  
for i in range(N//2+1):
  e=b-(N-i*2)*d
  f=b-(N-i*2)*c
  if e<=(d-c)*i and (c-d)*i<=f:
    print('Yes')
    exit()
print('No')

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
P = [A + (N-1-i)*D - C*i for i in reversed(range(-N+1,N))]
Q = [A + (N-1-i)*C - D*i for i in reversed(range(-N+1,N))]
for p, q in zip(P,Q):
    if q <= B <= p:
        print("YES")
        exit()
print("NO")

Submission status: Wrong Answer

Solution code:
from bisect import *
N, A, B, C, D = map(int, input().split())
P = [A + (N-1-i)*D - C*i for i in reversed(range(-N+1,N))]
Q = [A + (N-1-i)*C - D*i for i in reversed(range(-N+1,N))]
j = bisect_left(P,B)
if B >= Q[j]:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
def main():
    n, a, b, c, d = map(int, input().split())
    last = abs(a-b)
    if (n-1)*d < last:
        print("NO")
    else:
        f = False
        for i in range(n):
            p = d*i
            q = (n-1 - i)//2 * (d-c)
            if (n-1 - i) % 2 == 1:
                if q < c:
                    if p + c - q <= last <= p + d + q:
                        f = True
                    if p - d - q <= last <= p - c + q:
                        f = True
                else:
                    if p - d - q <= last <= p + d + q:
                        f = True
            else:
                if p - q <= last <= p + q:
                    f = True
        if f:
            print("YES")
        else:
            print("NO")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, a, b, c, d = map(int, input().split())
    last = abs(a-b)
    if (n-1)*d < last:
        print("NO")
    else:
        f = False
        for i in range(n):
            p = d*i
            q = (n-1 - i)//2 * (d-c)
            if (n-1 - i) % 2 == 1:
                if p + c - q <= last <= p + d + q:
                    f = True
                if p - d - q <= last <= p - c + q:
                    f = True
            else:
                if p - q <= last <= p + q:
                    f = True
        if f:
            print("YES")
        else:
            print("NO")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, a, b, c, d = map(int, input().split())
    last = abs(a-b)
    if (n-1)*d < last:
        print("NO")
    else:
        f = False
        for i in range(n):
            p = d*i
            q = (n-1 - i)//2 * (d-c)
            if (n-1 - i) % 2 == 1:
                if p + c <= last <= p + d + q:
                    f = True
                if p - d <= last <= p - c + q:
                    f = True
            else:
                if p - q <= last <= p + q:
                    f = True
        if f:
            print("YES")
        else:
            print("NO")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, a, b, c, d = map(int, input().split())
    last = abs(a-b)
    if (n-1)*d < last:
        print("NO")
    else:
        f = False
        for i in range(n):
            p = d*i
            q = (n-1 - i)//2 * (d-c)
            if (n-1 - i) % 2 == 1:
                if p + c <= last <= p + d + q:
                    f = True
                if p - d <= last <= p - c + q:
                    f = True
            else:
                if p <= last <= p + q:
                    f = True
        if f:
            print("YES")
        else:
            print("NO")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n, a, b, c, d = map(int, input().split())
    last = abs(a-b)
    if (n-1)*d < last:
        print("NO")
    else:
        f = False
        for i in range(n):
            p = d*i
            q = (n-1 - i)//2 * (d-c)
            if (n-1 - i) % 2 == 1:
                if p + c <= last <= p + d + q:
                    f = True
            else:
                if p <= last <= p + q:
                    f = True
        if f:
            print("YES")
        else:
            print("NO")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

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

X = abs(B - A)
n = N - 1

# n回で絶対値Xを作れるか

if n * C <= X <= n * D:
  print("YES")
  exit(0)

# n * Cより小さい数を作る必要があるため、Cを何回使うかを基準に考える
for i in range(n):
#  rest_1 = abs(X - C * i)
  rest_2 = X + C * i
  # 絶対値restを残り使える数で作れるか
  useful_num = n - i # 残り使える数
  # 残りの数を割って、C <= 商 <= Dに収まるなら作れる
#  if (C <= (rest_1 // useful_num) <= D) or (C <= (rest_2 // useful_num) <= D):
  if (C <= (rest_2 // useful_num) <= D):
#    print("i",i,"rest_2",rest_2,"useful_num",useful_num)
#    print("rest_2 // useful_num",rest_2 // useful_num)
    print("YES")
    break
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
#agc17-b
n,a,b,c,d=map(int,input().split())
ans='NO'
maxi=a+d*(n-1)
mini=a+c*(n-1)
if mini<b<maxi:
    print('YES')

else:
    for i in range(1,n):
        maxi=maxi-d-c
        mini=mini-c-d
        if mini<b<maxi:
            ans='YES'
            break

    print(ans)

Submission status: Wrong Answer

Solution code:
#agc17-b
n,a,b,c,d=map(int,input().split())
ans='NO'
maxi=a+d*(n-1)
mini=a+c*(n-1)
if mini<b<maxi:
    print('YES')
    exit()
for i in range(1,n):
    maxi=maxi-d-c
    mini=mini-c-d
    if mini<b<maxi:
        ans='YES'
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

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

	n-=1
	x=abs(b-a)

	ans="NO"

	for i in range(n):
		r=(n-i)*d-c*i
		l=(n-i)*c-d*i
		#print(l,x,r)
		if l<=x<=r:
			ans="Yes"
			#print(l,x,r)
			break
		elif l<0:
			break

	print(ans)





if __name__ == "__main__":
	main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

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

    x = int((b-a+d*(n-1))/(c+d))
    if x < 0:
        print('NO')
        return
    z = c * x - d * (n-1-x)
    if z <= b - a <= z + (d-c) * (n-1):
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

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

    x = max(0,int((b-a+d*(n-1))/(c+d)))
    z = c * x - d * (n-1-x)
    if z <= b - a <= z + (d-c) * (n-1):
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

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

    x = int((b-a+d*(n-1))/(c+d))
    z = c * x - d * (n-1-x)
    if z <= b - a <= z + (d-c) * (n-1):
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

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

    x = int((b-a+d*(n-1))/(c+d))
    z = c * x - d * (n-1-x)
    if z <= b - a <= z + (d-c) * (n-1):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

S = A - B - D * (N - 1)
if S > 0:
    print("NO")
else:
    X = (-S) % (C+D)
    if X <= (D-C) * (N-1):
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
# mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


def main():
    N, A, B, C, D = read_values()

    K = (A - B + (N - 1) * D) // (C + D)
    M = A + (N - K - 1) * D - K * C
    m = A + (N - K - 1) * C - K * D
    print("YES" if 0 <= K <= N and m <= B <= M else "NO")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
# mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


def main():
    N, A, B, C, D = read_values()

    K = (A - B + (N - 1) * D) // (C + D)
    M = A + (N - K - 1) * D - K * C
    m = A + (N - K - 1) * C - K * D
    print("YES" if K < N and m <= B <= M else "NO")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
# mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


def main():
    N, A, B, C, D = read_values()

    K = (A - B + (N - 1) * D) // (C + D)
    M = A + (N - K - 1) * D - K * C
    m = A + (N - K - 1) * C - K * D
    print("YES" if m <= B <= M else "NO")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
# mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


def main():
    N, A, B, C, D = read_values()

    K = (A - B + (N - 1) * D - 1) // (C + D) + 1
    M = A + (N - 1) * D - K * (C + D)
    m = A + (N - 1) * C - K * (C + D)
    print("YES" if m <= B <= M else "NO")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
# mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


def main():
    N, A, B, C, D = read_values()

    M = A + (N - 1) * D
    W = 0
    for n in range(N):
        if M < B:
            print("NO")
            return

        if M - W <= B <= M:
            print("YES")
            return
        
        M -= D + C
        W += D - C

    print("NO")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def check():
    if N%2==1 or C<=(N-2)*(D+A-B)//N:
        return 'YES'
    return 'NO'
print(check())

Submission status: Wrong Answer

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

def check():
    if N%2==1 or C<=(N-2)*(D+B-A)//N:
        return 'YES'
    return 'NO'
print(check())

Submission status: Wrong Answer

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

def check():
    if N%2==1 or C<=(D-C*(N//2 -1)):
        return 'YES'
    return 'NO'
print(check())

Submission status: Wrong Answer

Solution code:
print('YES')

Submission status: Wrong Answer

Solution code:
import bisect

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

number.sort()
data=[number[i][0] for i in range(0,2*N)]
m=data[0]
M=data[-1]

if C!=D:
    x=B-A
    if x in data:
        print('YES')
    else:
        if x<m or M<x:
            print('NO')
        else:
            l=bisect.bisect_left(data,x)-1
            if number[l][1]=='-' and number[l+1][1]=='+':
                if (data[l],'+') in number or (data[l+1],'-') in number:
                    print('YES')
                else:
                    print('NO')
            else:
                print('YES')
else:
    x=B-A
    if x in data:
        print('YES')
    else:
        print('NO')

Submission status: Wrong Answer

Solution code:
import bisect

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

number.sort()
data=[number[i][0] for i in range(0,2*N)]
m=data[0]
M=data[-1]

if C!=D:
    x=B-A
    if x in data:
        print('YES')
    else:
        if x<m or M<x:
            print('NO')
        else:
            l=bisect.bisect_left(data,x)-1
            if number[l][1]=='-' and number[l+1][1]=='+':
                print('NO')
            else:
                print('YES')
else:
    x=B-A
    if x in data:
        print('YES')
    else:
        print('NO')

Submission status: Wrong Answer

Solution code:
import bisect

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

number.sort()
m=min(number[i][0] for i in range(len(number)))
M=max(number[i][0] for i in range(len(number)))

x=B-A
if x in number:
    print('YES')
else:
    if x<m or M<x:
        print('No')
    else:
        A=[number[i][0] for i in range(0,2*N-2)]
        l=bisect.bisect_left(A,x)-1
        if number[l][1]=='-' and number[l+1][1]=='+':
            print('NO')
        else:
            print('YES')

Submission status: Wrong Answer

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

ans = 'NO'
task = [(A, A)]
for i in range(N):
    list_str = []
    list_end = []
    #
    for task_str, task_end in task:
        list_str.append(task_str - C)
        list_end.append(task_str - B)
        list_str.append(task_str + B)
        list_end.append(task_str + C)
    #
    task_tmp = []
    list_str.sort(key=lambda x: -x)
    list_end.sort(key=lambda x: -x)
    state = 0
    while len(list_str) > 0 or len(list_end) > 0:
        if len(list_str) == 0:
            task_end = list_end.pop()
            if state == 1:
                task_tmp.append((task_str, task_end))
            state = 0
        elif len(list_end) == 0:
            task_str = list_str.pop()
            state = 1
        else:
            if list_str[-1] < list_end[-1]:
                task_str = list_str.pop()
                state = 1
            else:
                task_end = list_end.pop()
                if state == 1:
                    task_tmp.append((task_str, task_end))
                state = 0
    #
    for task_str, task_end in task_tmp:
        if task_str <= B <= task_end:
            ans = 'YES'
    if ans == 'YES': break
    task = list(task_tmp)

print(ans)

Submission status: Wrong Answer

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

ans = "NO"
for i in range(N):
    high = i * D - (N - i - 1) * C
    low = i * C - (N - i - 1) * D
    print(i, N-i-1, low, high)
    if low <= B <= high:
        ans = "YES"
print(ans)

Submission status: Wrong Answer

Solution code:
N, A, B, C, D = map(int, input().split())
S = abs(A - B)
if (N - 1) * D < S:
    print('NO')
    exit()
if N % 2 == 1 or C <= S <= D:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

ans = "NO"
B -= A
for i in range(N):
    num = i*D - (N-1-i)*D
    if num-i*(D-C) <= 0 <= num+(N-i-1)*(D-C):
        ans = "YES"
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n,a,b,c,d=map(int,input().split())
if n%2==1:
  if a-(n-1)*d<=b<=a+(n-1)*d:
    print('YES')
  else:
    print('NO')
else:
  if a-(n-1)*d<=b<=a-c or a+c<=b<=a+(n-1)*d:
    print('YES')
  else:
    print('NO')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

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


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


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

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


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


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

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


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


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

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


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


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

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


def calc_n_plus(required_diff, max_diff, min_diff, n):
    return (required_diff + n * max_diff) // (max_diff + min_diff)


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

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


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


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
x = 0
y = 0
def no():
  print("NO")
  exit(0)
if B < A: A, B = B, A
x += -((A - B) // D)
y = abs(B - x * D - A)
#print(x * D, B, A - B, x)
#print(y)
if A == B and (C != 0) and (N % 2 == 0): no()
if y > B - ((B - A) // D) * D - A:
  y = B - ((B - A) // D) * D - A
  x = (B - A) // D
if x >= N: no()
if C <= (B - A) <= D and N == 3:
  print("YES")
  exit(0)
if y:
  if D - C == 0 : no()
  x += (y // (D - C)) * 2
  #print(x, y)
  if x >= N: no()

#print(x)
#print(x, dp)
t = (N - 1 - x)
#print(t)
if C == 0: t = 0
if t % 2:
  if t == 1: no()
  if D - C == 0: no()
  if -(-C // (D - C)) > t: no()
print("YES")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
x = 0
y = 0
def no():
  print("NO")
  exit(0)
if B < A: A, B = B, A
x += -((A - B) // D)
y = abs(B - x * D - A)
#print(x * D, B, A - B, x)
#print(y)
if A == B and (C != 0) and (N % 2 == 0): no()
if y > B - ((B - A) // D) * D - A:
  y = B - ((B - A) // D) * D - A
  x = (B - A) // D
if x >= N: no()
if C <= (B - A) <= D and N == 3:
  print("YES")
  exit(0)
if y:
  if D - C == 0 : no()
  x += -(-y // (D - C)) * 2
  if x >= N: no()

#print(x)
#print(x, dp)
t = (N - 1 - x)
#print(t)
if C == 0: t = 0
if t % 2:
  if t == 1: no()
  if D - C == 0: no()
  if -(-C // (D - C)) > t: no()
print("YES")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
x = 0
y = 0
def no():
  print("NO")
  exit(0)
if B < A: A, B = B, A
x += -((A - B) // D)
y = abs(B - x * D - A)
#print(x * D, B, A - B, x)
#print(y)
if y > B - ((B - A) // D) * D - A:
  y = B - ((B - A) // D) * D - A
  x = (B - A) // D
if x >= N: no()
if C <= (B - A) <= D and N == 3:
  print("YES")
  exit(0)
if y:
  if D - C == 0 : no()
  x += -(-y // (D - C)) * 2
  if x >= N: no()

#print(x)
#print(x, dp)
t = (N - 1 - x)
#print(t)
if C == 0: t = 0
if t % 2:
  if t == 1: no()
  if D - C == 0: no()
  if -(-C // (D - C)) > t: no()
print("YES")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
x = 0
y = 0
def no():
  print("NO")
  exit(0)
if B < A: A, B = B, A
x += -((A - B) // D)
y = abs(B - x * D - A)
#print(x * D, B, A - B, x)
#print(y)
if x >= N: no()
if C <= (B - A) <= D and N == 3:
  print("YES")
  exit(0)
if y:
  if D - C == 0 : no()
  x += -(-y // (D - C)) * 2
  if x >= N: no()

#print(x)
#print(x, dp)
t = (N - 1 - x)
#print(t)
if C == 0: t = 0
if t % 2:
  if t == 1: no()
  if D - C == 0: no()
  if -(-C // (D - C)) > t: no()
print("YES")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
x = 0
y = 0
def no():
  print("NO")
  exit(0)
if B < A: A, B = B, A
x += -((A - B) // D)
y = abs(B - x * D - A)
#print(x * D, B, A - B, x)
#print(y)
if x >= N: no()
if y:
  if D - C == 0 : no()
  x += -(-y // (D - C)) * 2
  if x >= N: no()

#print(x)
#print(x, dp)
t = (N - 1 - x)
#print(t)
if C == 0: t = 0
if t % 2:
  if t == 1: no()
  if D - C == 0: no()
  if -(-C // (D - C)) > t: no()
print("YES")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
x = 0
y = 0
def no():
  print("NO")
  exit(0)
if B < A: A, B = B, A
x += -((A - B) // D)
y = abs(B - x * D - A)
#print(x * D, B, A - B, x)
#print(y)
if x >= N: no()
if y:
  if D - C == 0 : no()
  x += -(-y // (D - C)) * 2
  if x >= N: no()

#print(x)
#print(x, dp)
t = (N - 1 - x)
#print(t)
if t % 2:
  if t == 1: no()
  if D - C == 0: no()
  if -(-C // (D - C)) > t: no()
print("YES")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, A, B, C, D = map(int, input().split())
x = 0
y = 0
def no():
  print("NO")
  exit(0)
if B < A: A, B = B, A
x += -((A - B) // D)
y = abs(B - x * D - A)
#print(x * D, B, A - B,)
#print(y)
if y:
  if D - C == 0 : no()
  x += -(-y // (D - C)) * 2
  if x >= N: no()

#print(x)
if x == -1:
  if C <= abs(B - dp[-2]) <= D:
    x = N - 1
  else: no()
#print(x, dp)
t = (N - 1 - x)
#print(t)
if t % 2:
  if t == 1: no()
  if D - C == 0: no()
  if -(-C // (D - C)) > t: no()
print("YES")

Submission status: Wrong Answer

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

dp = [0] * N
dp[0] = A
dp[-1] = B
x = -1
def no():
  print("NO")
  exit(0)
if B < A: A, B = B, A
for i in range(N - 2):
  if dp[i] < B:
    dp[i + 1] = dp[i] + D
  else:
    #print(dp[i], (i - 1) * (D - C), B)
    f = abs(dp[i] - (i - 1) * (D - C))
    #print(f)
    if abs(B - dp[i]) <= f:
      x = i
      dp[i] = B
    else:
      if D - C == 0: no()
      x = i + -(-abs(abs(B - dp[i]) - f) // (D - C)) * 2
      if x >= N: no()
      dp[x] = B
    break
#print(x)
if x == -1:
  if C <= abs(B - dp[-2]) <= D:
    x = N - 1
  else: no()
#print(x, dp)
t = (N - 1 - x)
#print(t)
if t % 2:
  if t == 1: no()
  if D - C == 0: no()
  if -(-C // (D - C)) > t: no()
print("YES")

Submission status: Wrong Answer

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

dp = [0] * N
dp[0] = A
dp[-1] = B
x = -1
def no():
  print("NO")
  exit(0)
if B < A: A, B = B, A
for i in range(N - 2):
  if dp[i] < B:
    dp[i + 1] = dp[i] + D
  else:
    #print(dp[i], (i - 1) * (D - C), B)
    f = abs(dp[i] - (i - 1) * (D - C))
    if f <= B:
      x = i
      dp[i] = B
    else:
      if D - C == 0: no()
      x = i + -(-abs(B - f) // (D - C)) * 2
      if x >= N: no()
      dp[x] = B
    break
if x == -1:
  if C <= abs(B - dp[-2]) <= D:
    x = N - 1
  else: no()
#print(x, dp[x])
t = (N - 1 - x)
#print(t)
if t % 2:
  if t == 1: no()
  if D - C == 0: no()
  if -(-C // (D - C)) > t: no()
print("YES")

Submission status: Wrong Answer

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

dp = [0] * N
dp[0] = A
dp[-1] = B
x = -1
def no():
  print("NO")
  exit(0)
if B < A: A, B = B, A
for i in range(N - 2):
  if dp[i] < B:
    dp[i + 1] = dp[i] + D
  else:
    #print(dp[i], (i - 1) * (D - C), B)
    f = abs(dp[i] - (i - 1) * (D - C))
    if f <= B:
      x = i
      dp[i] = B
    else:
      if D - C == 0: no()
      x = i + -(-abs(B - f) // (D - C)) * 2
      if x >= N: no()
      dp[x] = B
    break
if x == -1: no()
#print(x, dp[x])
t = (N - 1 - x)
#print(t)
if t % 2:
  if t == 1: no()
  if D - C == 0: no()
  if -(-C // (D - C)) > t: no()
print("YES")

Submission status: Wrong Answer

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

dp = [0] * N
dp[0] = A
dp[-1] = B
x = -1
def no():
  print("NO")
  exit(0)
if B < A: A, B = B, A
for i in range(N - 2):
  if dp[i] < B:
    dp[i + 1] = dp[i] + D
  else:
    #print(dp[i], (i - 1) * (D - C), B)
    f = abs(dp[i] - (i - 1) * (D - C))
    if f <= B:
      x = i
      dp[i] = B
    else:
      if D - C == 0: no()
      x = i + -(-abs(B - f) // (D - C)) * 2
      if x >= N: no()
      dp[x] = B
    break

#print(x, dp[x])
t = (N - 1 - x)
#print(t)
if t % 2:
  if t == 1: no()
  if D - C == 0: no()
  if -(-C // (D - C)) > t: no()
print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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