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


#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 )- 1<=N-i-1 and C<=target%C+D<=D:
      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 )- 1<=N-i and C<=target%C+D<=D:
      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  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):
  target=abs(target)
  if target>0:
    if  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
  if target>=D:
    target-=D 
  elif target>=C:
    target-=C
    
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  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
  if target>=D:
    target-=D 
  elif target>=C:
    target-=C
    
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  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
  target-=D
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):
  if target>0:
    if  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
  target-=D
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())
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:
        print("NO")

Submission status: Wrong Answer

Solution code:
"test"
N,A,B,C,D = map(int,input().split())
if N % 2 == 1:
    d1 = (N-3)*(D-C)
    con1 = -d1 <= B - A <= d1
    d2 = 2*(N-3)
    con2 = -d2*C <= B - A <= d2*D
    if con1 or con2:
        print("YES")
    else:
        print("NO")
    exit()
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: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Solution code:
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
import random
random.seed()
print "NO"

Submission status: Wrong Answer

Solution code:
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
import random
random.seed()
print "YES"

Submission status: Wrong Answer

Solution code:
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
# hello
import random
random.seed()
if random.randint(0, 2) > 0: print "YES"
else: print "NO"

Submission status: Wrong Answer

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

s =abs(b-a)
cd=abs(c-d)
x=0
for i in range(n//2):
  if (n-1 - i*2) * c <= s <= (n-1 - i*2) * d + x:
    print('YES')
    break
  x+=cd
else:
  print('NO')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
if N > 30 and D > 1:
	flag = 10 **9
else:
	flag = pow(D,N -1)
B -= A
if N % 2 == 1:
	if (B % (C + D) <= (N - 1) * (D - C) / 2 or abs(B % (C + D) - (C + D)) <= (N - 1) * (D - C) / 2) and B <= flag and B >= -flag:
		print("YES")
	else:
		print("NO")
else:
	if (B + (D + C) / 2) % (C + D) <= (N - 1) * (D - C) / 2 : #and B <= flag and B >= -flagor (B + (D + C) / 2) % (C + D) <= (N - 1) *  (D - C) / 2)
		print("YES")
	else:
		print("NO")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
if N > 30 and D > 1:
	flag = 10 **9
else:
	flag = pow(D,N -1)
B -= A
if N % 2 == 1:
	if (B % (C + D) <= (N - 1) * (D - C) / 2 or abs(B % (C + D) - (C + D)) <= (N - 1) * (D - C) / 2) and B <= flag and B >= -flag:
		print("YES")
	else:
		print("NO")
else:
	if (B - (D + C) / 2) % (C + D) <= (N - 1) * (D - C) / 2 : #and B <= flag and B >= -flagor (B + (D + C) / 2) % (C + D) <= (N - 1) *  (D - C) / 2)
		print("YES")
	else:
		print("NO")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
if N > 30 and D > 1:
	flag = 10 **9
else:
	flag = pow(D,N -1)
B -= A
if N % 2 == 1:
	if (B % (C + D) <= (N - 1) * (D - C) / 2 or abs(B % (C + D) - (C + D)) <= (N - 1) * (D - C) / 2) and B <= flag and B >= -flag:
		print("YES")
	else:
		print("NO")
else:
	if ((B - (D + C) / 2) % (C + D) <= (N - 1) * (D - C) / 2 or (B + (D + C) / 2) % (C + D) <= (N - 1) *  (D - C) / 2): #and B <= flag and B >= -flag
		print("YES")
	else:
		print("NO")

Submission status: Wrong Answer

Solution code:
def solve(n, a, b, c, d):
    return d == 0
    if d == 0:
        return a == b
    t = n - 1
    return (b - a - c * t) % (c + d) <= (d - c) * t


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

Submission status: Wrong Answer

Solution code:
def solve(n, a, b, c, d):
    if d == 0:
        return a == b
    t = n - 1
    return (b - a - c * t) % (c + d) <= (d - c) * t


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

Submission status: Wrong Answer

Solution code:
def solve(n, a, b, c, d):
    if d == 0:
        return a == b
    t = n - 1
    ex = (d - c) * t
    cd = c + d
    return (b - a + (ex - (t & 1) * cd) // 2) % cd <= ex


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

Submission status: Wrong Answer

Solution code:
def solve(n, a, b, c, d):
    if d == 0:
        return a == b
    t = n - 1
    ex = (d - c) * t
    cd = c + d
    return (b - a + (ex + (t & 1) * cd) / 2) % cd <= ex


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

Submission status: Wrong Answer

Solution code:
def solve(n, a, b, c, d):
    if d == 0:
        return a == b
    t = n - 1
    ex = (d - c) * t
    cd = c + d
    return (abs(b - a) + ex / 2 - (t & 1) * cd / 2) % cd <= ex


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

Submission status: Wrong Answer

Solution code:
def solve(n, a, b, c, d):
    if d == 0:
        return a == b
    t = n - 1
    ex = (d - c) * t
    cd = c + d
    return (b - a + ex / 2 - (t & 1) * cd / 2) % cd <= ex


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

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
if N > 30 and D > 1:
	flag = 10 **9
else:
	flag = pow(D,N -1)
B -= A
if N % 2 == 1:
	if (B % (C + D) <= (N - 1) * (D - C) / 2 or abs(B % (C + D) - (C + D)) <= (N - 1) * (D - C) / 2) and B <= flag and B >= -flag:
		print("YES")
	else:
		print("NO")
else:
	if ((B - (D + C) / 2) % (C + D) <= (N - 1) * (D - C) / 2 or (B + (D + C) / 2) % (C + D) <= (N - 1) *  (D - C)/2)and B <= flag and B >= -flag:
		print("NO")
	else:
		print("Yes")

Submission status: Wrong Answer

Solution code:
N,A,B,C,D = map(int,input().split())
if N > 30 and D > 1:
	flag = 10 **9
else:
	flag = pow(D,N -1)
B -= A
if N % 2 == 1:
	if (B % (C + D) <= (N - 1) * (D - C) / 2 or abs(B % (C + D) - (C + D)) <= (N - 1) * (D - C) / 2) and B <= flag and B >= -flag:
		print("YES")
	else:
		print("NO")
else:
	if ((B - (D + C) / 2) % (C + D) <= (N - 1) * (D - C) / 2 or (B + (D + C) / 2) % (C + D) <= (N - 1) *  (D - C)/2)and B <= flag and B >= -flag:
		print("YES")
	else:
		print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

l = get(n, c, d)

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

a = abs(A - B)
b = abs(D - C)
d1 = 0
d2 = 0
p = 0

for i in range(N-1):
    if p < a:
        p += C
        d1 += 1
    else:
        p -= C
        d2 += 1
print('YES' if p < a - b * d1 or p < a + b * d2  else 'NO')

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N,A,B,C,D=map(int,input().split())
if B<A:
	A,B=B,A
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, x, y = egcd(b % a, a)
        return (g, y - (b // a) * x, x)
if C==0 and D==0:
    if A==B:
        print("YES")
    else:
        print("NO")
    exit()
elif C==0 or D==0:
    if D==0:
        C,D=D,C
    if (B-A)%D==0 and abs(B-A)//D<N:
        print("YES")
    else:
        print("NO")
    exit()
else:
        (g,x,y)=egcd(C,D)
        if (B-A)%g!=0:
            print("YES")
            exit()
        times=(B-A)//g
        #xC+yD=B-A
        x*=times
        y*=times
#        x+=D*alpha
#        y-=C*alpha
        C//=g
        D//=g
        alphamin=-10**100
        alphamax=10**100
        while alphamax-alphamin>1:
            mid=alphamin+(alphamax-alphamin)//2
            if abs(x+mid*D)+abs(y-mid*C)>abs(x+mid*D+D)+abs(y-mid*C-C):
                alphamin=mid
            else:
                alphamax=mid
        x=x+alphamax*D
        y=y-alphamax*C
        a=list(range(-50,50))
        if any(abs(x+i*D)+abs(y-C*i)<N and (abs(x+i*D)+abs(y-i*C))%2!=N%2 for i in a):
            print("YES")
        else:
            print("NO")
        exit()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N,A,B,C,D=map(int,input().split())
if B<A:
	A,B=B,A
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, x, y = egcd(b % a, a)
        return (g, y - (b // a) * x, x)
if C==0 and D==0:
    if A==B:
        print("YES")
    else:
        print("NO")
    exit()
elif C==0 or D==0:
    if D==0:
        C,D=D,C
    if (B-A)%D==0 and abs(B-A)//D<N:
        print("YES")
    else:
        print("NO")
    exit()
else:
        (g,x,y)=egcd(C,D)
        if (B-A)%g!=0:
            print("NO")
            exit()
        times=(B-A)//g
        #xC+yD=B-A
        x*=times
        y*=times
#        x+=D*alpha
#        y-=C*alpha
        C//=g
        D//=g
        alphamin=-10**100
        alphamax=10**100
        while alphamax-alphamin>1:
            mid=alphamin+(alphamax-alphamin)//2
            if abs(x+mid*D)+abs(y-mid*C)>abs(x+mid*D+D)+abs(y-mid*C-C):
                alphamin=mid
            else:
                alphamax=mid
        x=x+alphamax*D
        y=y-alphamax*C
        a=list(range(-50,50))
        if any(abs(x+i*D)+abs(y-C*i)<N and (abs(x+i*D)+abs(y-i*C))%2!=N%2 for i in a):
            print("YES")
        else:
            print("NO")
        exit()

Submission status: Wrong Answer

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