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: Runtime Error

Solution code:
import math

# input
J = list(map(int, input().split()))

def juice(A_int, A, B, C, D):
    if A < B:
        ans = 'No'
        return ans
    if A <= B + C:
        if D == B:
            ans = 'Yes'
            return ans
        if D < B:
            ans = 'No'
            return ans
        l = math.floor((B + C - A) / (D - B) + 1)
        A = A + l * (D - B) # AをB+Cより大きくする
        print(l, A)
        if A in A_int:
            ans = 'Yes'
            return ans
        A_int.add(A)
        return juice(A_int, A, B, C, D)
    else:
        k = math.ceil((A - C) / B)
        A = A - k * B
        print(k, A)
        if A < 0:
            ans = 'No'
            return ans
        if (A + D) in A_int:
            ans = 'Yes'
            return ans 
        A_int.add(A + D)
        return juice(A_int, A + D, B, C, D)

A_int = set([J[0]])
A = J[0]
B = J[1]
C = J[2]
D = J[3]
print(juice(A_int, A, B, C, D))

Submission status: Runtime Error

Solution code:

T = int(input())
for i in range(T) :
    A,B,C,D = map(int,input().split())
    a1 = A-B
    d = D-B
    P = (C+d-a1)/d
    Q = (B+d-a1)/d
    PP = int(P)
    QQ = int(Q)
    if a1 > 0 :
        if P == PP :
            if (QQ - PP == 0) or (QQ - PP == 1) :
                print("Yes")
            else :
                print("No")
        elif QQ - PP == 0 :
            print("Yes")
        else :
            print("No")
    else :
        print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
for i in range(n):
	m = map(int, input().split())
	if m[0] >= m[1] and m[2] >= m[1] and m[3] >= m[1]:
		print("Yes")
	else:
		print("No")

Submission status: Runtime Error

Solution code:
t = int(input())
a = [0 for i in range(t)]
b = [0 for i in range(t)]
c = [0 for i in range(t)]
d = [0 for i in range(t)]
for i in range(t):
    a[i], b[i], c[i], d[i] = map(int, input().split())
for i in range(t):
    count = 0
    m_set = set()
    if a[i] - b[i] > c[i]:
        m_set.add([a[i] - b[i] for j in range((a[i]-c[i]) // b[i])])
        tmp = a[i] - b[i] * ((a[i]-c[i]) // b[i] - 1)
    else:
        tmp = a[i]
    while count < 10000:
        m_set.add(tmp)
        if tmp < b[i]:
            print('No')
            break
        tmp -= b[i]
        if tmp <= c[i]:
            tmp += d[i]
            if tmp - b[i] > c[i]:
                m_set.add([tmp - b[i] for j in range((tmp-c[i]) // b[i])])
                tmp = tmp - b[i] * ((tmp-c[i]) // b[i] - 1)
        s1 = set()
        s1.add(tmp)
        if s1.issubset(m_set):
            print('Yes')
            break
        # print(tmp)
        count += 1
    if count == 10000:
        print('Yes')

Submission status: Runtime Error

Solution code:
N=int(input())
def upfunc(b,c,d,x):
    if (x-b-c)%b==0:
        return(b+c)
    else:
        return((x-b-c)%b + c)
def downfunc(b,c,d,x):
    if b==d:
        return(x)
    else:
        if (x-b-c)%(d-b) != 0:
            return((x-b-c)%(d-b) + b+c)
        else:
            return(d+c)
def simulate(b,c,d,x):
    if x>b+c:
        return(upfunc(b,c,d,x))
    else:
        return(downfunc(b,c,d,x))
def solve(a,b,c,d):
    if b==d:
        if a<=b+c:
            return("Yes")
        else:
            x=b+c-(b+c-a)%b
            if x<b:
                return("No")
    if b>d:
        return("No")
    if b>a:
        return("No")
    if b<=c:
        return("Yes")
    if c+1>=b:
        return("Yes")
    
    import math as m
    g = m.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: Runtime Error

Solution code:
N=int(input())
def upfunc(b,c,d,x):
    if (x-b-c)%b==0:
        return(b+c)
    else:
        return((x-b-c)%b + c)
def downfunc(b,c,d,x):
    if b==d:
        return(x)
    else:
        if (x-b-c)%(d-b) != 0:
            return((x-b-c)%(d-b) + b+c)
        else:
            return(d+c)
def simulate(b,c,d,x):
    if x>b+c:
        return(upfunc(b,c,d,x))
    else:
        return(downfunc(b,c,d,x))
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")
    import math as m
    g = m.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: Runtime Error

Solution code:
def main():
    import math

    def lcm(x, y):
        return (x * y) // math.gcd(x, y)
    N = int(input())
    ABCD = [list(map(int, input().split())) for i in range(N)]
    for A,B,C,D in ABCD:
        # 在庫が買う本数以下 or 在庫追加が買う本数以下
        if A < B or D < B:
            print("No")
            continue

        A %= B
        # 在庫が買う本数以下になり、補給出来ない
        if C < A:
            print("No")
            continue
        if B == D:
            print("Yes")
            continue

        flag = True
        #print((B-A-1)%(D-B) ,">", (B-1)-(C+1))
        if (B-A-1)%(math.gcd(D,B)) <= (B-1)-(C+1):
            flag = False
        
        print("Yes" if flag else "No")


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:



aa=int(input())
N=[0 for i in range(aa)]
for i in range(aa):
  bb=input()
  #print(b)
  N[i]=bb.split()


def so(p,q):
  for i in range(min(p,q),0,-1):
    if p%i==0 and q%i==0:
      return i


#print(so(11,5))

def aaa(n):

  a=int(N[n][0])
  b=int(N[n][1])
  c=int(N[n][2])
  d=int(N[n][3])

  e=a-a//b*b
  f=d-d//b*b
  

  s=so(e,f)


  if a<b or d<b :
    return "No"
  
  elif b<=c :
    return "Yes"
  else:
  
    if f!=0 :
      ss=b//s*s

      if ss>c:
        return "No"
          
    

        #print(e)
        #print(f)
  #print("while")
    else:
      if e>c :
        return "No"

  return "Yes"

for i in range(aa):
  print(aaa(i))

Submission status: Runtime Error

Solution code:
T = int(input())
check = 0
while check <= T:
    A, B, C, D = map(int, input().split())
    check += 1
    if A < B or B * 2 > C + D:
        print('no')
    else:
        print('yes')

Submission status: Runtime Error

Solution code:



aa=int(input())
N=[0 for i in range(aa)]
for i in range(aa):
  bb=input()
  #print(b)
  N[i]=bb.split()


def so(p,q):
  for i in range(min(p,q),0,-1):
    if p%i==0 and q%i==0:
      return i


def aaa(n):

  a=int(N[n][0])
  b=int(N[n][1])
  c=int(N[n][2])
  d=int(N[n][3])

  e=a-a//b*b
  f=d-d//b*b
  

  s=so(e,f)


  if a<b or d<b :
    return "No"
  
  elif b<=c :
    return "Yes"
  else:
  
    if f!=0 :
      g=(b-e)//f
      e=e+(f+1)*g
      while e>=b:
        e-=s
      if e>c:
        return "No"
          
    

        #print(e)
        #print(f)
  #print("while")
    else:
      if e>c :
        return "No"

  return "Yes"

for i in range(aa):
  print(aaa(i))

Submission status: Runtime Error

Solution code:
from sys import stdin

stdin = open('sample.txt')

def spam(A, B, C, D):
    if A < B:
            print('No')
            return
    # elif B <= C:
    #     print('Yes')
    #     return

    a = A % B
    for i in range(10000):
        if a <= C:
            a += D
        if a < B:
            print('No')
            return
        a -= B
    print('Yes')


def main():
    T = int(stdin.readline().rstrip())
    for _ in range(T):
        A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]
        spam(A, B, C, D)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
T = int(input())
for i in range(T) :
    A,B,C,D = map(int,input().split())
    a1 = A-B
    d = D-B
    P = (C+d-a1)/d
    Q = (B+d-a1)/d
    PP = math.floor(P)
    QQ = math.floor((Q))
    if PP == QQ :
        print("Yes")
    else :
        print("No")

Submission status: Runtime Error

Solution code:



aa=int(input())
N=[0 for i in range(aa)]
for i in range(aa):
  bb=input()
  #print(b)
  N[i]=bb.split()


def so(p,q):
  for i in range(min(p,q),0,-1):
    if p%i==0 and q%i==0:
      return i


def aaa(n):

  a=int(N[n][0])
  b=int(N[n][1])
  c=int(N[n][2])
  d=int(N[n][3])

  e=a-a//b*b
  f=d-d//b*b
  

  s=so(e,f)


  if a<b or d<b :
    return "No"
  
  elif b<=c :
    return "Yes"
  else:
  
    if f!=0 :
      g=(b-e)//f
      e=e+f*g
      while e>c:
        if e<b :
          return "No"
          
        e-=s

        #print(e)
        #print(f)
  #print("while")
    else:
      if e>c :
        return "No"

  return "Yes"

for i in range(aa):
  print(aaa(i))

Submission status: Runtime Error

Solution code:
import math
T = int(input())
for i in range(T) :
    A,B,C,D = map(int,input().split())
    a1 = A-B
    d = D-B
    P = (C+d-a1)/d
    Q = (B+d-a1)/d
    PP = math.floor(P)
    QQ = math.floor((Q))
    if P != PP :
        if PP != QQ :
            print("No")
    else :
        print("Yes")

Submission status: Runtime Error

Solution code:



aa=int(input())
N=[0 for i in range(aa)]
for i in range(aa):
  bb=input()
  #print(b)
  N[i]=bb.split()


def so(p,q):
  for i in range(min(p,q),0,-1):
    if p%i=0 and q%i=0:
      return i


def aaa(n):

  a=int(N[n][0])
  b=int(N[n][1])
  c=int(N[n][2])
  d=int(N[n][3])

  e=a-a//b*b
  f=d-d//b*b
  

  s=so(e,f)


  if a<b or d<b :
    return "No"
  
  elif b<=c :
    return "Yes"
  else:
  
    if f!=0 :
      g=(b-e)//f
      e=e+f*g
      while e>c:
        if e<b :
          return "No"
          
        e-=s

        #print(e)
        #print(f)
  #print("while")
    else:
      if e>c :
        return "No"

  return "Yes"

for i in range(aa):
  print(aaa(i))

Submission status: Runtime Error

Solution code:
import math

T = int(input())

for _ in range(T):
    A, B, C, D = map(int, input().split())
    if (A < B) or (D < B):
        print('No')
        continue
    elif (C+1 >= B):
        print('Yes')
        continue
    else:
        s_res = A % B
        s_k = int((C + 1 - s_res - 0.1) // B + 1)
        X = math.gcd(B, (D%B))
        if X == 1:
            print('No')
            continue
        else:
            s_0 = s_k * B + s_res
            if (s_0 - (C+1)) % X > (B-C-2):
                print('Yes')
            else:
                print('No')

Submission status: Runtime Error

Solution code:
from math import floor
import sys
sys.setrecursionlimit(500000)
T = int(input())
for i in range(T):
    A,B,C,D = map(int,input().split())
    if B > D:
        print("No")
    else:
        memo = {}
        def buy(A):
            if A < B:
                return False
            else:
                if A % B > C:
                    return False
                else:
                    A = floor((C-A%B)/B)*B+A%B+D%B
                    if A not in memo:
                        memo[A] = 0
                        return buy(A)
                    else:
                        return(True)
        
        if buy(A):
            print("Yes")
        else:
            print("No")

Submission status: Runtime Error

Solution code:
from math import floor
import sys
sys.setrecursionlimit(500000)
T = int(input())
for i in range(T):
    if B > D:
        print("No")
    else:
        memo = {}
        def buy(A):
            if A < B:
                return False
            else:
                if A % B > C:
                    return False
                else:
                    A = floor((C-A%B)/B)*B+A%B+D%B
                    if A not in memo:
                        memo[A] = 0
                        return buy(A)
                    else:
                        return(True)
        A,B,C,D = map(int,input().split())
        if buy(A):
            print("Yes")
        else:
            print("No")

Submission status: Runtime Error

Solution code:
from math import floor
import sys
sys.setrecursionlimit(500000)
T = int(input())
for i in range(T):
    memo = {}
    def buy(A):
        if A < B:
            return False
        else:
            if A % B > C:
                return False
            else:
                A = floor((C-A%B)/B)*B+A%B+D%B
                if A not in memo:
                    memo[A] = 0
                    return buy(A)
                else:
                    return(True)
    A,B,C,D = map(int,input().split())
    if B > D:
        print("No")
    else:
        if buy(A):
            print("Yes")
        else:
            print("No")

Submission status: Runtime Error

Solution code:
from math import floor
import sys
sys.setrecursionlimit(5000000)
T = int(input())
for i in range(T):
    memo = {}
    def buy(A):
        if A < B:
            return False
        else:
            if A % B > C:
                return False
            else:
                A = floor((C-A%B)/B)*B+A%B+D
                if A not in memo:
                    memo[A] = 0
                    return buy(A)
                else:
                    return(True)
    A,B,C,D = map(int,input().split())
    if B > D:
        print("No")
    else:
        if buy(A):
            print("Yes")
        else:
            print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math import floor
T = int(input())
for i in range(T):
    memo = {}
    def buy(A):
        if A < B:
            return False
        else:
            if A % B > C:
                return False
            else:
                A = floor((C-A%B)/B)*B+A%B+D
                if A not in memo:
                    memo[A] = 0
                    return buy(A)
                else:
                    return(True)
    A,B,C,D = map(int,input().split())
    if B > D:
        print("No")
    else:
        if buy(A):
            print("Yes")
        else:
            print("No")

Submission status: Runtime Error

Solution code:
T = Int(input())
for i in range(T):
    a = Int(input())
    b = Int(input())
    c = Int(input())
    d = Int(input())
    current = a
    flag = True
    memo =[]
    if b > c:
        while(1):
            #print(current)
            if current < b:
                flag = False
                break
            current %= b
            #print(current)
            if current <= c:
                current += d
            if current in memo:
                break
            memo.append(current)
    print("Yes" if flag == True else "No")

Submission status: Runtime Error

Solution code:
from math import floor
T = int(input())
for i in range(T):
    memo = {}
    def buy(A):
        if A < B:
            return False
        else:
            if A % B > C:
                return False
            else:
                A = floor((C-A%B)/B)*B+A%B+D
                if A not in memo:
                    memo[A] = 0
                    return buy(A)
                else:
                    return(True)
    A,B,C,D = map(int,input().split())
    if buy(A):
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

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

for row in matrix:
    a, b, c, d = row
    bc_diff = b - c
    if not False in [i % bc_diff == 0 for i in row]:
        a, b, c, d = [i // bc_diff for i in row]

    if a < b:
        print('No')
    elif a % b > c:
        print('No')
    elif b == d:
        if a % b <= c:
            print('Yes')
        else:
            print('No')
    elif b == c:
        if b <= (d - 1):
            print('Yes')
        else:
            print('No')
    elif b < c:
        if b > d:
            print('No')
        else:
            print('Yes')
    elif (b - c) == 1:
        if b <= d:
            print('Yes')
        else:
            print('No')
    elif (b - c) >= (d - b):
        print('No')
    else:
        print('Yes')

Submission status: Runtime Error

Solution code:
T=int(input())

for cnt in range(T):
  A,B,C,D=map(int,input().split())
  if(B > D or A < B):
    print("No")
    continue
  if(B <= C):
    print("Yes")
    continue

  A = A % B + B
  Zaiko = A
  i = 0
  while(i < 100):
    Zaiko = Zaiko - B
    #print(Zaiko)
    if(Zaiko < 0):
      print("No")
      break
    if(Zaiko <= C):
      Zaiko += D
      Zaiko = Zaiko % B + B
    if(Zaiko in lista ):
      print("Yes")
      break
    lista.append(Zaiko)
    i += 1
    if(i == 100):
      if(C >= B - D):
        print("Yes")
      else:
        print("No")
  #print(A,B,C,D)

Submission status: Runtime Error

Solution code:
t = input()
result = []
hist = []
for i in range(int(t)):
	data = input().split()
	a = int(data[0])
	b = int(data[1])
	c = int(data[2])
	d = int(data[3])
	hist.clear()
	while True:
		if a < b:
			result.append("No")
			break
		n = int((a / b))
		a -= b * n
		if a <= c:
			a += d
		if a in hist:
			result.append("Yes")
			break
		else:
			if len(hist) < 50:
				if min(hist) > a:
					result.append("No")
					break
			hist.append(a)
		if (len(hist) == 5) & (b < d) & (b < c):
			result.append("Yes")
			break
for i in range(int(t)):
	print(result[i])

Submission status: Runtime Error

Solution code:
import math

T=int(input())
Juice=[None]*T
for i in range(T):
    Juice[i]=list(map(int,input().split()))

#A最初の在庫,Bすぬけ君が買う本数,C以下の場合D追加


#A→A%B
def juicecheck(i):
    A=Juice[i][0]
    B=Juice[i][1]
    C=Juice[i][2]
    D=Juice[i][3]

    if A<B:
        print("No")
        return
    elif B>D:
        print("No")
        return
    elif B<C:
        print("Yes")
        return
    else:
        x=A%B
        y=D%B

        z=math.gcd(B,y)

        for i in range(C+1,B):
            if i%z==x%z:
                print("No")
                return

        print("Yes")
        return
                


        #(x+n*y)%B==[C+1,B)となるnがあれば"No"

for i in range(T):
    juicecheck(i)

Submission status: Runtime Error

Solution code:
t = int(input())
res = []
for i in range(t):
    a,b,c,d = list(map(int, input().split()))
    m = -((-c+a%b)//(d-b))
    k = a%b+m*(d-b)
    if a%b>c or a<b or b>d:
        res.append('No')
    elif k>c and k<b:
        res.append('No')
    else:
        res.append('Yes')
for j in range(t):
    print(res[j])

Submission status: Runtime Error

Solution code:
N = int(input())
inp = [int(i) for i in input().split()]

a = inp[0]
b = inp[1]
c = inp[2]
d = inp[3]

def checking(A,B,C,D):
    X = A
    Y = A

    while X >= B:
        Y = X - B
        if Y <= C:
            X = Y + D
        else:
            X = Y

        if X == A:
            res = "No"
            break

    if X<=B:
        7res = "Yes"

    return res

print(checking(a,b,c,d))

Submission status: Runtime Error

Solution code:
t = input()
result = []
hist = []
for i in range(int(t)):
	data = input().split()
	a = int(data[0])
	b = int(data[1])
	c = int(data[2])
	d = int(data[3])
	hist.clear()
	while True:
		if a < b:
			result.append("No")
			break
		n = int((a / b))
		a -= b * n
		if a <= c:
			a += d
		if a in hist:
			result.append("Yes")
			break
		else:
			hist.append(a)
		if (len(hist) > 5) && (b < d):
			result.append("Yes")
			break
for i in range(int(t)):
	print(result[i])

Submission status: Runtime Error

Solution code:



aa=int(input())
N=[0 for i in range(aa)]
for i in range(aa):
  bb=input()
  #print(b)
  N[i]=bb.split()




for i in range(aa):

  a=int(N[i][0])
  b=int(N[i][1])
  c=int(N[i][2])
  d=int(N[i][3])

  e=a-a//b*b
  f=d-d//b*b
  

  h=0 #YES=0 NO=1


  if a<b or d<b :
    h=1
  else:

  
    if f!=0 :
      while e<b:
        if e>c :
          h=1
          
        e+=f
        if h=1:
          break
        #print(e)
        #print(f)
  #print("while")
    else:
      if e>c :
        h=1

  

  if h==1:
    print("No")
  else:
    print("Yes")

Submission status: Runtime Error

Solution code:
import math
T = int(input())

for _ in range(T):
    A, B, C, D = map(int, input().split())
    #print("----", _, A, B, C, D)
    if A < B:
        print("No")
        continue
    
    if C < A%B < B:
        print("No")
        continue
    
    if D % B == 0:
        print("Yes")
        continue
    
    if D < B:
        print("No")
        continue
    
    if C+(math.gcd(B,D)) < B:
        print("No")
        continue
    
    print("Yes")

Submission status: Runtime Error

Solution code:
import math

def judge(a,b,c,d):
    bd_gcd=math.gcd(b,d)
    if a >= b:
        if   ( b<= c+1 and b<= d)  \
          or ( b>c and (d%b ==0    \
                      or (b%bd_gcd==0 and d%bd_gcd==0 and b-c <=bd_gcd and bd_gcd > 1 ) )  \
                   and a%b <= c ):
            return("Yes")
    return("No")

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

Submission status: Runtime Error

Solution code:
import math

T = int(input())
for i in range(T):
    a, b, c, d = list(map(int, input().split()))

    if a < b:
        print("No")
        continue

    if b > d:
        print("No")
        continue

    if c >= b: # d >= b
        print("Yes")
        continue

    diff = d % b
    if diff == 0:
        if a % b <= c:
            print("Yes")
            continue
        else:
            print("No")
            continue

    g = math.gcd(b, diff)

    init_mod = c % b

    base_mod = init_mod % g
    if b + base_mod - g > c:
        print("No")
    else:
        print("Yes")

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(100000)

T = int(input())
for i in range(T):
	A, B, C, D = list(map(int, input().split()))
	memo = set()
	def dfs(x):
		x -= B
		if x < 0:
			return 0
		x -= B*(x // B)
		if x <= C:
			x += D
		if x in memo:
			return 1			
		memo.add(x)
		return dfs(x)
	if dfs(A):
		print("Yes")
	else:
		print("No")

Submission status: Runtime Error

Solution code:
import math

t = int(input())
abcd = []
for i in range(t):
    abcd.append(list(map(int, input().split())))

for i in range(t):
    if abcd[i][0] < abcd[i][1]:
        print("No")
    elif abcd[i][1] > abcd[i][3]:
        print("No")
    elif abcd[i][3] % abcd[i][1] == 0:
        if abcd[i][0] % abcd[i][1] > abcd[i][2]:
            print("No")
        else:
            print("Yes")
    else:
        gcd = math.gcd(abcd[i][1], abcd[i][3])
        if abcd[i][1] - gcd <= abcd[i][2]:
            print("Yes")
        else:
            print("No")

Submission status: Runtime Error

Solution code:
T=int(input())

for cnt in range(T):
  A,B,C,D=map(int,input().split())
  if(B > D or A < B):
    print("No")
    continue
  if(B <= C):
    print("Yes")
    continue

  A = A % B + B
  Zaiko = A
  lista = []
  i = 0
  while(i < 1000):
    Zaiko = Zaiko - B
    #print(Zaiko)
    if(Zaiko < 0):
      print("No")
      break
    if(Zaiko <= C):
      Zaiko += D
      Zaiko = Zaiko % B + B
    if(Zaiko in lista ):
      print("Yes")
      break
    lista.append(Zaiko)
    ZaikoMin = min(Zaiko, ZaikoMin)
    i += 1
    if(i == 1000):
      print("Yes")
  #print(A,B,C,D)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math

def isok(a,b,c,d):
    if a < b:
        print('No')
        return
    g= math.gcd(d, b)
    r=((c-a%g)//g)*g+a%g
#    print(r)
    if r+g-b < 0:
        print('No')
    else:
        print('Yes')
    

T=int(input())

for _ in range(T):
    a,b,c,d = list(map(int,input().split()))
    isok(a,b,c,d)

Submission status: Runtime Error

Solution code:
import math

def main():
	t = int(input())
	qs = [list(map(int, input().split())) for _ in range(t)]
	for q in qs:
		sub(q)

def sub(q):
	a, b, c, d = q
	if d - b < 0:
		print("No")
		return
	
	if a - b < 0:
		print("No")
		return

	if b > c:
		gcd_bd = math.gcd(d, b)
		i = - 10
		while True:
			if 0 < gcd_bd * i + (a - c) % gcd_bd < b - c:
				print("No")
				return
			elif gcd_bd * i + (a - c) % gcd_bd >= b - c:
				print("Yes")
				return
			i += 1
				
	print("Yes")
	return
	
if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
T = int(input())
for i in range(T):
	A, B, C, D = list(map(int, input().split()))
	memo = set()
	def dfs(x):
		x -= B
		if x < 0:
			return 0
		x -= B*(x // B)
		if x <= C:
			x += D
		if x in memo:
			return 1			
		memo.add(x)
		return dfs(x)
	if dfs(A):
		print("Yes")
	else:
		print("No")

Submission status: Runtime Error

Solution code:
import math

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

    if a < b:
        print("No")
        continue

    if b > d:
        print("No")
        continue

    if c >= b: # d >= b
        print("Yes")
        continue

    diff = d % b
    if diff == 0:
        if a % b <= c:
            print("Yes")
            continue
        else:
            print("No")
            continue

    gcd = math.gcd(b, diff)

    init_mod = c % b

    base_mod = init_mod % gcd
    if b + base_mod - gcd > c:
        print("No")
    else:
        print("Yes")

Submission status: Runtime Error

Solution code:
T = int(input())
A = list()
B = list()
C = list()
D = list()
for i in range(T):
    a,b,c,d = input().split()
    A.append(int(a))
    B.append(int(b))
    C.append(int(c))
    D.append(int(d))

for i in range(T):
    if D >= B and A%B < C:
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
T = int(input())
for i in range(T):
	A, B, C, D = list(map(int, input().split()))
	memo = set()
	def dfs(x):
		x -= B
		if x < 0:
			return 0
		x -= B*(x // B)
		if x <= C:
			x += D
		if x in memo:
			return 1			
		memo.add(x)
		return dfs(x)
	if dfs(A):
		print("YES")
	else:
		print("NO")

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import math

def main():
	t = int(input())
	qs = [list(map(int, input().split())) for _ in range(t)]
	for q in qs:
		sub(q)

def sub(q):
	a, b, c, d = q
	if d - b < 0:
		print("No")
		return
	
	if a - b < 0:
		print("No")
		return

	if b > c:
		gcd_bd = math.gcd(d, b)
		i = - 10
		while True:
			#print(i)
			#print(gcd_bd, gcd_bd * i + (a - c))
			if 0 < gcd_bd * i + (a - c) % gcd_bd < b - c:
				print("No")
				return
			elif gcd_bd * i + (a - c) % gcd_bd >= b - c:
				print("Yes")
				return
			i += 1
				

	print("Yes")
	return
	
if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
T = int(input())
A = list()
B = list()
C = list()
D = list()
for i in range(T):
    K = list(map(int, input().split()))
    a,b,c,d = K
    A = A.append(a)
    B = B.append(b)
    C = C.append(c)
    D = D.append(d)

for i in range(T):
    if D >= B and A%B < C:
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
T = int(input())
A = list()
B = list()
C = list()
D = list()
for i in range(T):
    K = list(map(int, input().split()))
    a,b,c,d = K
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)

for i in range(T):
    if D >= B and A%B < C:
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
import math
T = int(input())
for _ in range(T):
  A, B, C, D = map(int, input().split())
  if B > D or B > A:
    print('No')
    continue
  if C >= B - 1:
    print('Yes')
    continue
  a = A % B
  step = math.gcd(B, D)
  k = (B - a + step - 1) // step - 1
  if C - a < k * step:
    print('No')
  else:
    print('Yes')

Submission status: Runtime Error

Solution code:
import math
n=int(input())
for _ in range(n):
    a,b,c,d=map(int,input().split())
    if d<b:
        print("No")
        continue
    elif a<b:
        print("No")
        continue
    g=math.gcd(b,d)
    h=1
    if 1+h>c:
        print("No")
        continue
    print("Yes")

Submission status: Runtime Error

Solution code:
import math
n=int(input())
for _ in range(n):
    a,b,c,d=map(int,input().split())
    if d<b:
        print("No")
        continue
    elif a<b:
        print("No")
        continue
    g=math.gcd(b,d)
    h=int((b-1-1)/g)*g
    if a%b+h>c:
        print("No")
        continue
    print("Yes")

Submission status: Runtime Error

Solution code:
import math
n=int(input())
for _ in range(n):
    a,b,c,d=map(int,input().split())
    if d<b:
        print("No")
        continue
    elif a<b:
        print("No")
        continue
    g=math.gcd(b,d)
    h=1
    if a%b+h>c:
        print("No")
        continue
    print("Yes")