Problem:


Score : 600 points

Problem Statement

Ringo Mart, a convenience store, sells apple juice.

On the opening day of Ringo Mart, there were A cans of juice in stock in the morning.
Snuke buys B cans of juice here every day in the daytime.
Then, the manager checks the number of cans of juice remaining in stock every night.
If there are C or less cans, D new cans will be added to the stock by the next morning.

Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them.
Nobody besides Snuke buy juice at this store.

Note that each test case in this problem consists of T queries.

Constraints

1 \leq T \leq 300

1 \leq A, B, C, D \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T

In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.

Output

Print T lines. The i-th line should contain Yes if Snuke can buy apple juice indefinitely in the i-th query; No otherwise.

Sample Input 1

14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985

Sample Output 1

No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes

In the first query, the number of cans of juice in stock changes as follows: (D represents daytime and N represents night.)

9
→D 2
→N 11
→D 4
→N 13
→D 6
→N 6
→D x

In the second query, the number of cans of juice in stock changes as follows:

9
→D 2
→N 11
→D 4
→N 13
→D 6
→N 15
→D 8
→N 8
→D 1
→N 10
→D 3
→N 12
→D 5
→N 14
→D 7
→N 7
→D 0
→N 9
→D 2
→N 11
→D …

and so on, thus Snuke can buy juice indefinitely.

Sample Input 2

24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1

Sample Output 2

No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No



Sample input:
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985


Sample output:
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes

Submission status: Wrong Answer

Solution code:
T = int(input())
A, B, C, D = (
    zip(*(map(int, input().split()) for _ in range(T))) if T else
    ((), (), (), ())
)

# B > A または B > D ならばNoであることは明らか
# そうでない場合、 在庫がCより大きくBより小さくなることがあるかを判定すればよい
ans = '\n'.join(
    'Yes' if (
        b <= a and
        b <= d and
        (
            c >= b or
            d % b == 0 and a % b <= c or
            d % b > 0 and a % b + ((c - a % b) // (d % b) + 1) * (d % b) >= b
        )
    ) else
    'No'
    for a, b, c, d in zip(A, B, C, D)
)

print(ans)

Submission status: Wrong Answer

Solution code:
T = int(input())
A, B, C, D = (
    zip(*(map(int, input().split()) for _ in range(T))) if T else
    ((), (), (), ())
)

# B > A または B > D ならばNoであることは明らか
# そうでない場合、 在庫がCより大きくBより小さくなることがあるかを判定すればよい
ans = '\n'.join(
    'Yes' if (
        b <= a and
        b <= d and
        (
            b <= c or
            b == d and (a <= b + c or a >= 2 * b) or
            b < d and a + ((b + c - a) // (d - b) + 1) * (d - b) >= 2 * b
        )
    ) else
    'No'
    for a, b, c, d in zip(A, B, C, D)
)

print(ans)

Submission status: Wrong Answer

Solution code:
T = int(input())
A, B, C, D = (
    zip(*(map(int, input().split()) for _ in range(T))) if T else
    ((), (), (), ())
)

# B > A または B > D ならばNoであることは明らか
# そうでない場合、 在庫がCより大きくBより小さくなることがあるかを判定すればよい
ans = '\n'.join(
    'Yes' if (
        b <= a and
        b <= d and
        (
            b == d and (a <= b + c or a >= 2 * b) or
            b < d and a + ((b + c - a) // (d - b) + 1) * (d - b) >= 2 * b
        )
    ) else
    'No'
    for a, b, c, d in zip(A, B, C, D)
)

print(ans)

Submission status: Wrong Answer

Solution code:
T = int(input())
A, B, C, D = (
    zip(*(map(int, input().split()) for _ in range(T))) if T else
    ((), (), (), ())
)

# B > A または B > D ならばNoであることは明らか
# そうでない場合、 在庫がCより大きくBより小さくなることがあるかを判定すればよい
ans = '\n'.join(
    'Yes' if (
        b <= a and
        b <= d and
        (
            b == d and (A <= B + C or A >= 2 * B) or
            b < d and a + ((b + c - a) // (d - b) + 1) * (d - b) >= 2 * b
        )
    ) else
    'No'
    for a, b, c, d in zip(A, B, C, D)
)

print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

n=int(input())
for _ in range(n):
  a,b,c,d=map(int,input().split())
  if a%b>c or b>d:
    print('No')
  else:
    if b==d:
      print('Yes')
    elif a%b+d==a:
      print('Yes')
    else:
      if c+gcd(b,d)>=b:
        print('Yes')
      else:
        print('No')

Submission status: Wrong Answer

Solution code:
t = int(input())
for i in range(t):
    a,b,c,d = map(int,input().split())
    dx = d%b
    if a<b:
        print('No')
    elif d<b:
        print('No')
    elif c>=b:
        print('Yes')
    elif a%b>c:
        print('No')
    elif dx==0:
        print('Yes')
    else:
        n = (c-a%b)//dx
        if a%b + dx*(n+1) <b:
            print('No')
        else:
            print('Yes')

Submission status: Wrong Answer

Solution code:
t = int(input())
for i in range(t):
    a,b,c,d = map(int,input().split())
    dx = d%b
    if c>=b:
        print('Yes')
    elif a%b>c:
        print('No')
    elif dx==0:
        print('Yes')
    else:
        n = (c-a%b)//dx
        if a%b + dx*(n+1) <b:
            print('No')
        else:
            print('Yes')

Submission status: Wrong Answer

Solution code:
T = int(input())
ABCD = [list(map(int, input().split())) for _ in range(T)]

from fractions import gcd

for a,b,c,d in ABCD:
  if b-1<=c:
    print('Yes')
    continue
  else:
    l = gcd(b,d)
    a = a % b
    if (a + ((b-a-1)//l)*l) <= c and (a - (a//l)*l)+d>=b:
      print('Yes')
    else:
      print('No')

Submission status: Wrong Answer

Solution code:
t=int(input())
for i in range(t):
  a,b,c,d=map(int,input().split())
  if a<b:
    print("No")
  elif d<=b:
    if d<b:
      print("No")
    else:
      if a-(a//b)*b<=c:
        if b>=c:
          print("Yes")
        else:
          print("No")
      else:
        print("No")
  else:
    if a>b+c:
      p=0
    else:
      p= (c+b-a)//(d-b) +1
    if (a+(d-b)*p)%b<=c:
      if d>b+c:
        p=0
      else:
        p= (c+b-d)//(d-b) +1
      if (d+(d-b)*p)%b<=c:
        print("Yes")
      else:
        print("No")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
t=int(input())
for i in range(t):
  a,b,c,d=map(int,input().split())
  if a<b:
    print("No")
  elif d<=b:
    if d<b:
      print("No")
    else:
      if a-(a//b)*b<=c:
        print("Yes")
      else:
        print("No")
  else:
    if a>b+c:
      p=0
    else:
      p= (c+b-a)//(d-b) +1
    if (a+(d-b)*p)%b<=c:
      if d>b+c:
        p=0
      else:
        p= (c+b-d)//(d-b) +1
      if (d+(d-b)*p)%b<=c:
        print("Yes")
      else:
        print("No")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
t=int(input())
for i in range(t):
  a,b,c,d=map(int,input().split())
  if a<b:
    print("No")
  elif d<=b:
    if d<b:
      print("No")
    else:
      if a-(a//b)*b<=c:
        print("Yes")
      else:
        print("No")
  else:
    if a>b+c:
      p=0
    else:
      p= (c+b-a)//(d-b) +1
    if (a+(d-b)*p)%b<=c:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
t=int(input())
for i in range(t):
  a,b,c,d=map(int,input().split())
  if a<b:
    print("No")
  elif d<=b:
    if d<b:
      print("No")
    else:
      if a-(a//b)*b<=c:
        print("Yes")
      else:
        print("No")
  else:
    p= (c+b-a)//(d-b) +1
    if (a+(d-b)*p)%b<=c:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
t=int(input())
for i in range(t):
  a,b,c,d=map(int,input().split())
  if a<b:
    print("No")
  elif d<=b:
    if d<b:
      print("No")
    else:
      if a-(a//b)*b<=c:
        print("Yes")
      else:
        print("No")
  else:
    p= (c+b-a)//(d-b) +1
    if a+(d-b)*p>=2*b:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
t=int(input())
for i in range(t):
  a,b,c,d=map(int,input().split())
  if d<=b:
    if d<b:
      print("No")
    else:
      if a-(a//b)*b<=c:
        print("Yes")
      else:
        print("No")
  else:
    p= (c+b-a)//(d-b) +1
    if a+(d-b)*p>=2*b:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
from collections import*
t=int(input())

def loop(a,b,c,d):
    l=deque([a])
    while True:
        if l[-1]>=b:
            l.append(l[-1]-b)
        else:
            return "No"
        if l[-1]<=c:
            l.append(l[-1]+d)
        if len(l)>100000:
            return "Yes"
            break
    

for i in range(t):
    a,b,c,d=map(int,input().split())
    print(loop(a,b,c,d))

Submission status: Wrong Answer

Solution code:
from collections import*
t=int(input())

def loop(a,b,c,d):
    if a>100000:
        l=deque([a%b+3*b])
    else:
        l=deque([a])
    while True:
        if l[-1]>=b:
            l.append(l[-1]-b)
        else:
            return "No"
        if l[-1]<=c:
            l.append(l[-1]+d)
        if len(l)>1000:
            return "Yes"
            break
    

for i in range(t):
    a,b,c,d=map(int,input().split())
    print(loop(a,b,c,d))

Submission status: Wrong Answer

Solution code:
t = int(input())
query = [tuple(map(int, input().split())) for _ in range(t)]
def gcd(x, y):
    if y == 0: return x
    return gcd(y, x % y)
for a, b, c, d in query:
    g = gcd(b, d)
    r = a % g
    if b <= ((c - r)//g + 1) * g: print('Yes')
    else: print('No')

Submission status: Wrong Answer

Solution code:
T = int(input())

def gcd (a: int,b: int) -> int:
    if a < b: a,b = b,a
    return a if b == 0 else gcd(b,a%b)
def lcm (a: int,b: int) -> int:
    return a // gcd(a,b) * b


for i in range(T):
    A,B,C,D = map(int,input().split(" "))
    g = gcd(B,D)
    if C >= ((B - g) + (A % g)):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
t = int(input())
for _ in range(t):
  a, b, c, d = map(int, input().split())
  if a>b and a%b <= c and d>b:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
from fractions import gcd

T = int(input())

OUTPUT = []
for t in range(T):
    A,B,C,D = map(int,input().split())
    if A//B>=1 and D-B>=0:
        if C>=B:
            OUTPUT.append("Yes")
        else:
            DIFF = gcd(D-B,B)
            START = (A%B-min([B,C]))
            START = START%DIFF if START>=0 else (START%DIFF)*(-1)
            K = (DIFF%B)+START
            if B-min([B,C]) > K and K > C-min([B,C]):
                OUTPUT.append("No")
            else:
                OUTPUT.append("Yes")
    else:
        OUTPUT.append("No")
    
for o in OUTPUT:
    print(o)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

T = int(input())

OUTPUT = []
for t in range(T):
    A,B,C,D = map(int,input().split())
    if A//B>=1 and D-B>=0:
        DIFF = gcd(D-B,B)
        START = (A%B-min([B,C]))
        START = (START%DIFF)-DIFF if START>=0 else (START%DIFF)*(-1)
        K = (DIFF%B)+START
        if B-min([B,C]) > K and K > C-min([B,C]):
            OUTPUT.append("No")
        else:
            OUTPUT.append("Yes")
    else:
        OUTPUT.append("No")
    
for o in OUTPUT:
    print(o)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

T = int(input())

OUTPUT = []
for t in range(T):
    A,B,C,D = map(int,input().split())
    if A//B>=1 and D-B>=0:
        DIFF = gcd(D-B,B)
        START = (A%B-min([B,C]))
        START = START%DIFF if START>=0 else (START%DIFF)*(-1)
        K = (DIFF%B)+START
        if B-min([B,C]) > K and K > C-min([B,C]):
            OUTPUT.append("No")
        else:
            OUTPUT.append("Yes")
    else:
        OUTPUT.append("No")
    
for o in OUTPUT:
    print(o)

Submission status: Wrong Answer

Solution code:
n = int(input())
for _ in range(n):
	a,b,c,d = (int(i) for i in input().split())
	if a<b or b>d or c<a%b: print("No")
	else:
		if b==d: print("Yes")
		else:
			e = a-((a-c+1)//b+1)*b
			if (c-e)//(d-b)==(c-e)/(d-b):
				if c+d>=2*b: print("Yes")
				else: print("No")
			elif int((c-e)/(d-b))+1<(b-e)/(d-b): print("No")
			else: print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
for _ in range(n):
	a,b,c,d = (int(i) for i in input().split())
	if a<b or b>d or c<a%b: print("No")
	else:
		if b==d: print("Yes")
		else:
			e = a-((a-c+1)//b+1)*b
			if int((c-e)/(d-b))+1<(b-e)/(d-b): print("No")
			else: print("Yes")

Submission status: Wrong Answer

Solution code:
T = int(input())
A,B,C,D=[0]*T,[0]*T,[0]*T,[0]*T
for i in range(T):
    A[i],B[i],C[i],D[i]=map(int,input().split())
ans = 'Yes'
inpval = [A,B,C,D]
[a,b,c,d]=[list(filter(lambda x:1<=x<=10**18,y)) for y in inpval]

if ((1<=T<=300)
and(len(a)==len(b)==len(c)==len(d)==T)):
    
    for i in range(T):
        if (A[i] < B[i]):
            ans = 'No'
        elif (B[i] > D[i]):
            ans = 'No'
        elif (C[i]>=B[i]):
            ans = 'Yes'
        else:
            for j in range(B[i]):
                A[i] = (A[i]+D[i])%B[i]
                #A[i] += D[i]
                if (A[i] > C[i]-1):    
                #if ((A[i]%B[i])>C[i])and((A[i]%B[i])!=C[i]):
                    print(A[i],B[i],C[i],D[i])
                    ans = 'No'
                    break
        print(ans)

Submission status: Wrong Answer

Solution code:
t = int(input())
for i in range(t):
    a, b, c, d = map(int, input().split())
    if a>=b and c >=b-1 and d>=b:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
t = int(input())
for i in range(t):
    a, b, c, d = map(int, input().split())
    if a>=b and a%b<=c and a%b+d>=b:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
t = int(input())
for i in range(t):
    a, b, c, d = map(int, input().split())
    if (a>=b and c >=b-1) and d>=b:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
t = int(input())
a, b, c, d = map(int, input().split())
for i in range(t):
    if a>=b and c >=b-1 and d>=b:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
t = int(input())
a, b, c, d = map(int, input().split())
for i in range(t):
    if a>=b and c >=b and d>=b:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    t = I()
    aa = [LI() for _ in range(t)]
    rr = []
    for a,b,c,d in aa:
        if a < b or d < b:
            rr.append('No')
            continue
        if c >= b:
            rr.append('Yes')
            continue
        g = fractions.gcd(b, d)
        if g == 1:
            if b - c > 1:
                rr.append('No')
            else:
                rr.append('Yes')
            continue
        t = (a + d - c) % g
        if t == 0:
            t = g
        if b - c - t > 1:
            rr.append('No')
        else:
            rr.append('Yes')

    return '\n'.join(rr)




print(main())

Submission status: Wrong Answer

Solution code:
#!/usr/local/bin/python
# -*- coding: utf-8 -*-


def solve(x):
    x1 = x[0]
    x2 = x[1]
    x3 = x[2]
    x4 = x[3]

    x11 = x1 % x2
    x41 = x4 % x2

    if x1 < x2:
        return False

    if x1 == x2:
        if x4 < x2:
            return False
        else:
            return True

    if x4 < x2:
        return False
    
    while True:
        a = x11 + x41
        if a == x11:
            if x11 <= x3:
                return True
            else:
                return False
        if a > x3 and a < x2:
            return False
        if a < x3 and a > x2:  
            return False
        if a >= x3 and a >= x2:
            return True
        x11 = a

num = int(input())

s = []
for i in xrange(num):
    a, b, c, d = map(int, raw_input().split(' '))
    q = [a, b, c, d]
    s.append(q)

for i in s:
    if solve(i):
        print "yes"
    else:
        print "no"

Submission status: Wrong Answer

Solution code:
test_cases = input()

for test_case in range(test_cases):
	A, B, C, D = map(int, raw_input().split(' '))

	last_take = max(1, (A - C + B - 1) // B)
	A -= last_take * B

	if A < 0 or B > D:
		print "No"
	elif B == D or B <= C: 
		print "Yes"
	else:
		printed = False

		for i in range(10000):
			x = (C - A) // (D - B) + 1
			A += (D - B) * x
			last_take = max(1, (A - C + B - 1) // B)
			A -= last_take * B

			if A < 0:
				print "No"
				printed = True
				break
			
		if printed is False:
			print "Yes"

Submission status: Wrong Answer

Solution code:
test_cases = input()

for test_case in range(test_cases):
	A, B, C, D = map(int, raw_input().split(' '))

	last_take = max(1, (A - C + B - 1) / B)
	A -= last_take * B

	if B <= D and A >= 0:
		printed = False

		if B == D or B <= C:
			print "Yes"
			printed = True
		else:
			print "No"

		# if printed is False:
		# 	for i in range(10000):
		# 		x = (C - A) / (D - B) + 1
		# 		A += (D - B) * x
		# 		last_take = max(1, (A - C + B - 1) / B)
		# 		A -= last_take * B

		# 		if A < 0:
		# 			print "No"
		# 			printed = True
		# 			break
			
		#you're doing jumps with size D - B
		# if printed is False:
		# 	print "Yes"
	else:
		print "No"

Submission status: Wrong Answer

Solution code:
test_cases = input()

for test_case in range(test_cases):
	A, B, C, D = map(int, raw_input().split(' '))

	last_take = max(1, (A - C + B - 1) / B)
	A -= last_take * B

	if B <= D and A >= 0:
		printed = False

		if B == D:
			print "Yes"
			printed = True

		if printed is False:
			for i in range(10000):
				x = (C - A) / (D - B) + 1
				A += (D - B) * x
				last_take = max(1, (A - C + B - 1) / B)
				A -= last_take * B
				
				if A < 0:
					print "No"
					printed = True
					break
			
		#you're doing jumps with size D - B
		if printed is False:
			print "Yes"
	else:
		print "No"

Submission status: Wrong Answer

Solution code:
test_cases = input()

for test_case in range(test_cases):
	A, B, C, D = map(int, raw_input().split(' '))

	last_take = max(1, (A - C + B - 1) / B)
	A -= last_take * B

	if B <= D and A >= 0:
		printed = False

		if B == D:
			print "Yes"
			printed = True

		if printed is False:
			for i in range(10000):
				x = (C - A) / (D - B) + 1
				A += (D - B) * x
				A -= B
				if A < 0:
					print "No"
					printed = True
					break
			
		#you're doing jumps with size D - B
		if printed is False:
			print "Yes"
	else:
		print "No"

Submission status: Wrong Answer

Solution code:
test_cases = input()

for test_case in range(test_cases):
	A, B, C, D = map(int, raw_input().split(' '))


	last_take = (A - C + B - 1) / B
	A -= last_take * B

	if B <= D and A >= 0:
		printed = False

		if B == D:
			print "Yes"
			printed = True

		if printed is False:
			for i in range(100000):
				x = (C - A) / (D - B) + 1
				A += (D - B) * x
				A -= B
				if A < 0:
					print "No"
					printed = True
					break
			
		#you're doing jumps with size D - B
		if printed is False:
			print "Yes"
	else:
		print "No"

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n=int(input())
for i in range(n):
  a,b,c,d=map(int,input().split())
  g = gcd(b,d)
  print('Yes' if (b//g-1)*g+(a % b)%g<=c else 'No')

Submission status: Wrong Answer

Solution code:
Q = int(input())
qs = []
for _ in range(Q):
	qs.append(list(map(int, input().split())))

for q in qs:
	a, b, c, d = q[0], q[1], q[2], q[3]
	if a < b or b > d:
		print("No")
	elif b <= c:
		print("Yes")
	elif d % b == 0:
		if a % b > c:
			print("No")
		else:
			print("Yes")
	else:
		a = a % b
		d = d % b
		if a > c:
			print("No")
		elif (a + ((c - a) // d) * d + d) % b <= c:
			print("Yes")
		else:
			print("No")

Submission status: Wrong Answer

Solution code:
Q = int(input())
qs = []
for _ in range(Q):
	qs.append(list(map(int, input().split())))

for q in qs:
	a, b, c, d = q[0], q[1], q[2], q[3]
	if a < b or b > d:
		print("No")
	elif b <= c:
		print("Yes")
	elif d % b == 0:
		if a % b > c:
			print("No")
		else:
			print("Yes")
	else:
		a = a % b
		d = d % b
		if (a + ((c - a) // d) * d + d) % b <= c:
			print("Yes")
		else:
			print("No")

Submission status: Wrong Answer

Solution code:
Q = int(input())
qs = []
for _ in range(Q):
	qs.append(list(map(int, input().split())))

for q in qs:
	a, b, c, d = q[0], q[1], q[2], q[3]
	if a < b or b > d:
		print("No")
	elif d % b == 0:
		if a % b > c:
			print("No")
		else:
			print("Yes")
	else:
		a = a % b
		d = d % b
		if (a + ((c - a) // d) * d + d) % b <= c % b:
			print("Yes")
		else:
			print("No")

Submission status: Wrong Answer

Solution code:
Q = int(input())
qs = []
for _ in range(Q):
	qs.append(list(map(int, input().split())))

for q in qs:
	a, b, c, d = q[0], q[1], q[2], q[3]
	if a < b or b > d:
		print("No")
	elif d % b == 0:
		if a % b > c:
			print("No")
		else:
			print("Yes")
	else:
		a = a % b
		d = d % b
		if (a + ((c - a) // d) * d + d) % b <= c:
			print("Yes")
		else:
			print("No")

Submission status: Wrong Answer

Solution code:
from fractions import gcd

Q = int(input())
qs = []
for _ in range(Q):
	qs.append(list(map(int, input().split())))

for q in qs:
	a, b, c, d = q[0], q[1], q[2], q[3]
	if a < b or b > d:
		print("No")
	elif b == d:
		if a % b > c:
			print("No")
		else:
			print("Yes")
	else:
		if (c - a) % gcd(b, d) == 0:
			print("Yes")
		else:
			print("No")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
t=int(input())
for i in range(t):
    a,b,c,d=map(int,input().split())
    if a<b or d<b or a-b*(a//b)>c:
        print('No')
    elif c>=b:
        print('Yes')
    else:
        syoki=a-b*(a//b)
        sabun=d-b*(d//b)
        if sabun==0:
            print('Yes')
            continue
        z=sabun*(b//sabun+1)-b
        if z!=0 and syoki-z*(syoki//z-1)<b-c:
            print('No')
        else:
            print('Yes')

Submission status: Wrong Answer

Solution code:
import fractions


def run(t, a, b, c, d):
    ret = []
    for i in range(t):
        ret.append(check(a[i], b[i], c[i], d[i]))
    return ret


def check(a, b, c, d):
    if a < b:
        return 'No'
    if d < b:
        return 'No'
    if c < b:
        g = fractions.gcd(b, d)
        amodb = a % b
        print(a, b, c, d, g)
        if g == 1:
            if b - 1 > c:
                return 'No'
        elif g == b:
            if amodb > c:
                return 'No'
        else:
            if (b - g) > c:
                return 'No'
    return 'Yes'


def read_line():
    t = int(input())
    a = []
    b = []
    c = []
    d = []
    for i in range(t):
        at, bt, ct, dt = list(map(int, input().split()))
        a.append(at)
        b.append(bt)
        c.append(ct)
        d.append(dt)
    return (t, a, b, c, d)


def main():
    t, a, b, c, d = read_line()
    ret = run(t, a, b, c, d)
    for i in range(t):
        print(ret[i])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions


def run(t, a, b, c, d):
    ret = []
    for i in range(t):
        ret.append(check(a[i], b[i], c[i], d[i]))
    return ret


def check(a, b, c, d):
    if a < b:
        return 'No'
    if d < b:
        return 'No'
    if c < b:
        g = fractions.gcd(b, d)
        if g == 1:
            if b - 1 > c:
                return 'No'
        else:
            if (b - g) > c:
                return 'No'
    return 'Yes'


def read_line():
    t = int(input())
    a = []
    b = []
    c = []
    d = []
    for i in range(t):
        at, bt, ct, dt = list(map(int, input().split()))
        a.append(at)
        b.append(bt)
        c.append(ct)
        d.append(dt)
    return (t, a, b, c, d)


def main():
    t, a, b, c, d = read_line()
    ret = run(t, a, b, c, d)
    for i in range(t):
        print(ret[i])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
t = int(input())
abcd_list = [[int(i) for i in input().split()] for _ in range(t)]

for i in range(len(abcd_list)):
    a, b, c, d = abcd_list[i]
    _a = a
    is_ok = True
    for j in range(10000):
        if b > a:
            is_ok = False
            break
        if b > d:
            is_ok = False
            break
        if c > b:
            is_ok = True
            break
            
        if _a - b > c:
            _a -= (((_a - c) // b) - 1) * b
        _a -= b
        if _a < 0:
            is_ok = False
            break
        if _a <= c:
            _a += d
    if is_ok:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
t = int(input())
a = []
b = []
c = []
d = []
for k in range(t):
    aa,bb,cc,dd = list(map(int,input().split()))
    a.append(aa)
    b.append(bb)
    c.append(cc)
    d.append(dd)

aa = a
bb = b
cc = c
dd = d

def check(a,b,c,d):
    if a < b:
        ans = 'No'
        return ans
    if b > d:
        ans = 'No'
        return ans
    else:
        if c >= b:
            ans = 'Yes'
            return ans
    ans = 'Yes'
    rec = []
    for k in range(100):
        temp = int(np.mod(a + k * d,b))
        if temp > c:
            ans = 'No'
            break
        if temp in rec:
            break
        rec.append(temp)
    return ans

for a,b,c,d in zip(aa,bb,cc,dd):
    print(check(a,b,c,d))

Submission status: Wrong Answer

Solution code:
import numpy as np
t = int(input())
a = []
b = []
c = []
d = []
for k in range(t):
    aa,bb,cc,dd = list(map(int,input().split()))
    a.append(aa)
    b.append(bb)
    c.append(cc)
    d.append(dd)

aa = a
bb = b
cc = c
dd = d

def check(a,b,c,d):
    if a < b:
        ans = 'No'
        return ans
    if b > d:
        ans = 'No'
        return ans
    else:
        if c > b:
            ans = 'Yes'
            return ans
    ans = 'Yes'
    rec = []
    for k in range(100):
        temp = int(np.mod(a + k * d,b))
        if temp > c:
            ans = 'No'
            break
        if temp in rec:
            break
        rec.append(temp)
    return ans

for a,b,c,d in zip(aa,bb,cc,dd):
    print(check(a,b,c,d))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 本番中には解けなかった。最初の3つの場合分けはできたが、
# その後に混乱して手がつけられなかった
#
# 解説pdf https://img.atcoder.jp/agc026/editorial.pdf を見た
#
# 個数の遷移をmod Bで考える。
#   最初は A mod B個。
#   B個の購入した後も A mod B個で変わらず。
#   D個入荷すると    (A + D) mod B個。
# つまり、入荷するたびに、
# A からスタートして (A + D) mod B, (A + 2D) mod B, ... (A + nD) mod Bと遷移していく。
# 
# その最大値 (A + nD) mod B が、C を超える場合、次 B を引くと 個数が負になってしまうので No。
# 逆に (A + nD) mod B が、C 以下であれば、Yes。
#
# 解説PDFの、「また，(B/g − 1) × inv(D/g, B/g) 回 D を足したときにこの上界が達成できます」
# 以降については理解できていない。
#



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


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


# def extgcd(a, b):
#     """ ax * by = gcd(a, b)の解(x, y)を求める。
#     x, y, gcd(a, b)を返す。
#     """
#     d = a
#     if b != 0:
#         d, y, x = extgcd(b, a % b)
#         y -= (a // b) * x
#     else:
#         x = 1
#         y = 0
#     return x, y, d


def solve(A, B, C, D):
    if B > A:
        return "No"
    if B > D:
        return "No"
    if B <= C:
        return "Yes"

    g = gcd(B, D)
#    if B - g + (A % g) > C:
    if (B - g + A) % g > C:
        return "No"
    else:
        return "Yes"


T = int(input())
for t in range(T):
    A, B, C, D = map(int, input().split())
    print(solve(A, B, C, D))

Submission status: Wrong Answer

Solution code:
N=int(input())
for i in range(N):
    A,B,C,D = list(map(int,input().split(" ")))
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    if(C+1>B or B>D or B>A):
        print("No")
    else:
        for i in range(B // gcd(B, D)):
            if(A+i*D)%B>C:
                print("No")
                break
        else:
            print("Yes")

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    a = min(x,y)
    b = max(x,y)
    if a == 1 or a==0:
        return(1)
    else:
        r = b%a
        if r==0:
            return(a)
        else:
            return(gcd(a,r))
N=int(input())
def solve(a,b,c,d):
    if b>d:
        return("No")
    if b>a:
        return("No")
    if b<=c:
        return("Yes")
    if b==d:
        if a<=b+c:
            return("Yes")
        else:
            x=b+c-(b+c-a)%b
            if x<b:
                return("No")
    g = gcd(d-b,b)
    x = (a-b-c-1)%g + b+c+1
    if x-b>=b:
        return("Yes")
    else:
        return("No")
for _ in range(N):
    a,b,c,d=map(int,input().split())
    print(solve(a,b,c,d))

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    a = min(x,y)
    b = max(x,y)
    if a == 1 or a==0:
        return(1)
    else:
        r = b%a
        if r==0:
            return(a)
        else:
            return(gcd(a,r))
N=int(input())
def solve(a,b,c,d):
    if b>d:
        return("No")
    if b>a:
        return("No")
    if b<=c:
        return("Yes")
    if c+1>=b:
        return("Yes")
    if b==d:
        if a<=b+c:
            return("Yes")
        else:
            x=b+c-(b+c-a)%b
            if x<b:
                return("No")
    g = gcd(d-b,b)
    x = (a-b-c-1)%g + b+c+1
    if x-b>=b:
        return("Yes")
    else:
        return("No")
for _ in range(N):
    a,b,c,d=map(int,input().split())
    print(solve(a,b,c,d))

Submission status: Wrong Answer

Solution code:
import math
def LI(): return list(map(int, input().split()))

def check(a, b, c, d):
    if a < b or b > d:
        return False
    if c >= b:
        return True
    k = math.ceil((a-c)/b)
    k = (a-c)//b
    #print(k)
    #print((a-c)//b)
    #print(a)
    #print(k*b)
    first = a - k*b
    if first > c:
        first -= b
    #print(first)
    if first < 0:
        #print("c")
        return False
    sub = d%b
    if sub == 0:
        #print("d")
        return True
    first = first % sub
    s = set([first])
    while True:
        n = int(((c-first)/sub)) + 1
        next_first = (first + n*sub - b)
        if next_first < 0:
            return False
        next_first = next_first % sub
        if next_first in s:
            #print("e")
            return True
        s.add(next_first)
        first = next_first


t = int(input())
q = []
for i in range(t):
    a, b, c, d = LI()
    q.append(check(a,b,c,d))
for i in q:
    if i:
        print("Yes")
    else:
        print("No")