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 = [0]*T
b = [0]*T
c = [0]*T
d = [0]*T

for i in range(T):
    s = input().rstrip().split(' ')
    a[i] = int(s[0])
    b[i] = int(s[1])
    c[i] = int(s[2])
    d[i] = int(s[3])

for i in range(T):
# for i in [0,1,2,3]:
    NoFlag=0
    print("i={}".format(i))
    if a[i] < b[i]:
        print("No")

    elif d[i] < b[i]:
        print("No")

    elif b[i] <= c[i]+1:
        print("Yes")
        
    else:
#         print(a[i])
#         a[i] = a[i] - ((a[i]-c[i]) // b[i]-1) *b[i]
        a[i] = a[i]%b[i] +b[i]
        for ii in range(c[i]):
            print(a[i])
            a[i] = a[i]-b[i]
            if a[i]<0:
                NoFlag=1
                print("No")
                break
            
            if a[i] <= c[i]:
                a[i] = a[i] + d[i]
#                 a[i] = a[i]%b[i] +b[i]
                a[i] = a[i] - ((a[i]-c[i]) // b[i]-1) *b[i]
            
        if NoFlag ==0:
            print("Yes")

Submission status: Wrong Answer

Solution code:
T = int(input())
for i in range(T):
    A, B, C, D = [int(i) for i in input().split()]
    memo = set()
    while True:
        if A in memo:
            print("Yes")
            break

        if A - B < 0:
            print("No")
            break

        if C - A + B < 0 and D - B == 0:
            print("No")
            break

        if D - B == 0:
            print("Yes")
            break

        if D - B < 0:
            print("No")
            break

        n = 1 + (C - A + B) // (D - B)
        r = (A - B) + n * (D - B)
        if r < B:
            print("No")
            break
        else:
            A = r % B
            memo.add(A)

    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
T = int(input())
for t in range(T):
    [a, b, c, d] = list(map(int, input().split()))
    if (a < b):
        print("No")
        continue
    if (d < b):
        print("No")
        continue
    if (b <= c):
        print("Yes")
        continue
    if ((a % b) > c):
        print("No")
        continue
    if (d % b == 0):
        print("Yes")
        continue
    if (c == b - 1):
        print("Yes")
        continue
    if (b % (d % b) == 0):
        k = (c - (a % b)) // (d % b)
        A = a % b + (k + 1) * (d % b)
        if (A % b > c):
            print("No")
        else:
            print("Yes")
        continue
        
    k = (c - (a % b)) // (d % b)
    A = a % b + (k + 1) * (d % b)
    print(k, A)
    if (A % b > c):
        print("No")
        continue
    
    ddb = (A % b - a + b) % b
    #print(ddb)
    k = (c - (a % b)) // ddb
    A = a % b + (k + 1) * ddb
    if (A % b > c):
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
T = int(input())
Data = [[int(i) for i in input().split()] for i in range(T)] 

for i in range(T):
  if Data[i][0] >= Data[i][1] and (Data[i][2]+1) >= Data[i][1] and Data[i][3] >= Data[i][1]:
    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())
    e=b*(max((a-c)//b,1))
    a-=e
    while a>c:
        a-=b
    if a<0:
        print('No')
        continue
    if d<b:
        print('No')
        continue
    if c<=b and d>b:
        """
        while a<=c:
            a+=(d-b)
        """
        a+=(d-b)*((c-a)//(d-b))
        while a<=c:
            a+=(d-b)
        if a<b:
            print('No')
            continue
        else:
            f=a-b
            ff=0
            for __ in range(10000):
                f+=(d-b)*((c-f)//(d-b))
                while f<=c:
                    f+=(d-b)
                if f<b:
                    print('No')
                    ff=1
                    break
                f=f-b
            if ff:continue
    print('Yes')

Submission status: Wrong Answer

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

for a,b,c,d in ABCD:
    if a < b:
        print('No')
        continue
    if d < b:
        print('No')
        continue
    tmp = a % b
    if tmp > c:
        print('No')
        continue
    if d % b == 0:
        print('Yes')
        continue
    if c >= b-1:
        print('Yes')
        continue
    if a%2 == 0 and b%2 == 0 and d %2 == 0 and b-c == 2:
        print('Yes')
        continue
    print('No')

Submission status: Wrong Answer

Solution code:
t=int(input())
for _ in range(t):
    a,b,c,d=map(int,input().split())
    e=b*(max((a-c)//b,1))
    a-=e
    while a>c:
        a-=b
    if a<0:
        print('No')
        continue
    if d<b:
        print('No')
        continue
    if c<=b and d>b:
        """
        while a<=c:
            a+=(d-b)
        """
        a+=(d-b)*((c-a)//(d-b))
        while a<=c:
            a+=(d-b)
        if a<b:
            print('No')
            continue
        else:
            f=a-b
            ff=0
            for __ in range(1000):
                f+=(d-b)*((c-f)//(d-b))
                while f<=c:
                    f+=(d-b)
                if f<b:
                    print('No')
                    ff=1
                    break
                f=f-b
            if ff:continue
    print('Yes')

Submission status: Wrong Answer

Solution code:
T = int(input())
for i in range(T):
	A, B, C, D = list(map(int, input().split()))
	if A < B:
		print("No")
	else:
		if D < B:
			print("No")
		else:
			if C >= B:
				print("Yes")
			else:
				x = A % B
				y = D % B
				z = B
				if y == 0:
					if x > C:
						print("No")
					else:
						print("Yes")

				else:
					if x > C:
						if (x - C) % y < z - C:
							print("No")
						else:
							print("Yes")
					else:
						if ((C - x) // y + 1) * y < z - x:
							print("No")
						else:
							print("Yes")

Submission status: Wrong Answer

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

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=gcd(B,y)

        if ((C+1)!=B) and (z==1 or (C+1)%z==B%z or (C+1)%z<=x%z<B%z or ( (C+1)%z>B%z and ((C+1)%z<=x%z or x%z<B%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: Wrong Answer

Solution code:
import numpy as np
if __name__ == "__main__":
    T = input().rstrip().split(' ')
    T = int(T[0])
    for t in range(T):
        line = input().rstrip().split(' ')
        A = int(line[0])
        B = int(line[1])
        C = int(line[2])
        D = int(line[3])
        init_A = A
        A_list = []
        flag = False
        while True:
            if A in A_list:
                flag = True
                break
            A_list.append(A)
            #
            if len(A_list) > 1000:
                flag = True
                break
            #
            if A < B:
                break
            mod = A % B
            q = int((A - mod) / B)
            A = mod
            for i in range(q-1):
                if A + B > C:
                    break
                A += B
            A_list.append(A + B)
            #n = np.floor((A-C)/B)
            #print(n)
            #A = A - n * B
            #print(f"night:{A}")
            if A <= C:
                A = A + D
        if flag:
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
T = int(input())

a = [0]*T
b = [0]*T
c = [0]*T
d = [0]*T

for i in range(T):
    s = input().rstrip().split(' ')
    a[i] = int(s[0])
    b[i] = int(s[1])
    c[i] = int(s[2])
    d[i] = int(s[3])


    

for i in range(T):
# for i in [0,1,2,3]:
    NoFlag=0
    print("i={}".format(i))
    if a[i] < b[i]:
        print("No")

    elif d[i] < b[i]:
        print("No")

    elif b[i] <= c[i]+1:
        print("Yes")
        
    else:
#         print(a[i])
        a[i] = a[i] - ((a[i]-c[i]) // b[i]-1) *b[i]
#         a[i] = a[i]%b[i] +b[i]
        for ii in range(c[i]):
            print(a[i])
            a[i] = a[i]-b[i]
            if a[i]<0:
                NoFlag=1
                print("No")
                break
            
            if a[i] <= c[i]:
                a[i] = a[i] + d[i]
#                 a[i] = a[i]%b[i] +b[i]
                a[i] = a[i] - ((a[i]-c[i]) // b[i]-1) *b[i]
            
        if NoFlag ==0:
            print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())

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

  flg = False
  s = [a]
  t = a % b
  h = c + d
  if( (a<b) or (d<b) or ( a > b and a%b > c) or ( d > b and ((a%b)+d)%b > c) or b > h or (a % d > c and b > c)):
    print("No")
  else:
    while (a >= b and d >= b):
      if(t > c):
        break
      else:
        t += d
        if(t in s):
          flg = True
          break
        else:
          s.append(t)
          t = t % b
    if(flg):
      print("Yes")
    else:
      print("No")

  #if( (a<b) or (d<b) or ( a > b and a%b > c) or ( d > b and ((a%b)+d)%b > c) or b > h or (a % d > c and b > c) or  (d %b > c and b > c) or (h % b > c and b > c)):
  del(s)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

  flg = False
  s = [a]
  t = a % b
  h = c + d
  if( (a<b) or (d<b) or ( a > b and a%b > c) or ( d > b and ((a%b)+d)%b > c) or b > h or (a % d > c and b > c) or  (d %b > c and b > c) or (h % b > c and b > c)):
    print("No")
  else:
    while (a >= b and d >= b):
      if(t > c):
        break
      else:
        t += d
        if(t in s):
          flg = True
          break
        else:
          s.append(t)
          t = t % b
    if(flg):
      print("Yes")
    else:
      print("No")

  del(s)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations
def inpl(): return map(int, input().split())

N = int(input())
for _ in range(N):
    A, B, C, D = inpl()
    if A < B:
        print("No")
        continue
    if A > C:
        A = A + ((C-A)//B)*B
    if A < 0:
        print("No")
        continue

    E = D-B
    if E < 0:
        print("No")
        continue
    if E == 0:
        print("Yes")
        continue
    A = A%E
    print("No" if A + (B-1-A)//E*E > C else "Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
from copy import deepcopy

ans=("")
t=int(input())
h=[]
for i in range(t):
    w=list(map(int,input().split()))
    h.append(w)
for i in range(t):
    a=h[i][0]
    b=h[i][1]
    c=h[i][2]
    d=h[i][3]
    f=a-b
    if(f<0):
        print("No")
        continue
    if(b==d):
        if(f>c):print("No")
        else:print("Yes")
        continue
    if(d-b==c):
        print("Yes")
        continue
    if(d-b>c):
        if(a-d<=c):
            print("Yes")
            continue
        else:
            print("No")
            continue   
    if(d-b<0):
        print("No")
        continue  
    e=int(math.ceil((b-f)/(d-b)))
    f+=(e-1)*(d-b)
    if(f<=c):ans=("Yes")
    else:ans=("No")
    print(ans)
    continue

Submission status: Wrong Answer

Solution code:
t = int(raw_input())
for _ in xrange(t):
    a,b,c,d = map(int, raw_input().strip().split())
    if (a<b):
        print "No"
    else:
        val = a-b
        x = c-val
        y = b-val
        #print x,y
        if b==d:
            if val >= 0 and val<=c:
                print "Yes"
            else:
                print "No"
        # if >x and <y
        else:
            xx = d-b
            if xx<0:
                print "No"
            else:
                m = xx
                q = x / (xx)
                #print xx,q
                xx *= q
                xx+=m
                if xx < y:
                    print "No"
                else:
                    print "Yes"

Submission status: Wrong Answer

Solution code:
T = int(input())

for i in range(T):
  apple = list(map(int, input().split(" ")))
  if apple[0] < apple[1]:
    print("No")
  elif apple[1] > apple[3]:
    print("No")
  else:
    A = apple[0] % apple[1]
    B = apple[3] % apple[1]
    if A > apple[2]:
      print("No")
    elif B == 0:
      if A <= apple[2]:
        print("Yes")
      else:
        print("No")
    else:
      C = (apple[2] - A) // B
      if A + (B * (C + 1)) > apple[2] and A + (B * (C + 1)) < apple[1]:
        print("No")
      else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
#A = 初期値　B = 一日の購入　C = 乳化のボーダー　D =在庫の増やす数

#A > B
#D % B >= B - C

size = int(input())
data = []
flag = 0

for i in range(size):
    ip = input().split()
    data = []
    for j in ip:
        data.append(int(j))
    #定義
    buf = []
#    print(store,buy,bord,charge,buf)
    #最初の処理
    data[0] = data[0] % data[1]
    if data[0] > data[3]:
        flag = 1
    #定常処理
    while data[0] not in buf:
        buf.append(data[0])
        data[0] = (data[0] + data[3]) % data[1]
        if data[0] > data[3]:
            flag = 1
            break
 #   print(buf)
    if flag == 1:
        print("No")
        flag = 0
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
t=int(input())
for _ in range(t):
    a,b,c,d=map(int,input().split())
    e=b*(max((a-c)//b,1))
    a-=e
    while a>c:
        a-=b
    if a<0:
        print('No')
        continue
    if d<b:
        print('No')
        continue
    if c<=b and d>b:
        """
        while a<=c:
            a+=(d-b)
        """
        a+=(d-b)*((c-a-10)//(d-b))
        while a<=c:
            a+=(d-b)
        while a-(d-b)>c:
            a-=(d-b)
        if a<b:
            print('No')
            continue
    print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())

def check_unique(list_tmp):
    L1 = len(list_tmp)
    L2 = len(list(set(list_tmp)))
    if L1 == L2:
        return True
    else:
        return False

def test(A,B,C,D):
    bottles = A
    bottles_log = []
    while bottles >0:
        bottles_log.append(bottles%B)
        print(bottles)
        
        if check_unique(bottles_log):
            if bottles >= B:
                bottles = bottles -(bottles//B) * B
                if bottles <= C :
                    bottles += D 
            else:
                return("No")
            
        else:
            return("Yes")
        
    return("No")

for i in range (N):
    A,B,C,D =  map(int,input().split())
    print(test(A,B,C,D))

Submission status: Wrong Answer

Solution code:
t = int(raw_input())
for _ in xrange(t):
    a,b,c,d = map(int, raw_input().strip().split())
    if (a<b):
        print "No"
    elif a==b:
        if d>=a:
            print "Yes"
        else:
            print "No"
    else:
        val = a-b
        x = c-val
        y = b-val
        #print x,y
        if b==d:
            if val >= 0 and val<=c:
                print "Yes"
            else:
                print "No"
        # if >x and <y
        else:
            xx = d-b
            if xx<0:
                print "No"
            else:
                m = xx
                q = x / (xx)
                #print xx,q
                xx *= q
                xx+=m
                if xx < y:
                    print "No"
                else:
                    print "Yes"

Submission status: Wrong Answer

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

T = int(input())
L = []

for i in range(T):
     L.append(list(map(int, input().split())))
P=0
F=0
for i in range(T):
     A=L[i]
     #print(A)
     P=A[0]
     X = P%A[1]
     if A[0]<A[1]:
         F=1
         print("No")
     elif (X>A[2]) and (F==0):
         F=1
         print("No")
     elif (A[2]+A[3]<A[0]) and (F==0):
         F=1
         print("No")
     P=X+A[3]
     for i in range(10000):
         P=P-A[1]
         if (P<0) and (F==0):
             F=1
             print("No")
             break;
         if P<=A[2]:
             P = P+A[3]
     if F==0:
         print("Yes")
     P=0
     F=0

Submission status: Wrong Answer

Solution code:
t=int(input())
for _ in range(t):
    a,b,c,d=map(int,input().split())
    e=b*(max((a-c)//b,1))
    a-=e
    while a>c:
        a-=b
    if a<0:
        print('No')
        continue
    if d<b:
        print('No')
        continue
    if c<=b and d>b:
        """
        while a<=c:
            a+=(d-b)
        """
        a+=(d-b)*((c-a-10)//(d-b))
        while a<=c:
            a+=(d-b)
        if a<b:
            print('No')
            continue
    print('Yes')

Submission status: Wrong Answer

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




  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-=f

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

  return "Yes"

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

Submission status: Wrong Answer

Solution code:
T = int(input())

counT = 0

def main():
    a = list(map(int,input().split()))
    A = a[0]
    B = a[1]
    C = a[2]
    D = a[3]

    #print(A,B,C,D)
    if A < B:
        return 0

    if B <= C and B <= D:
        return 1
    
    if B > D:
        return 0

    A = A % B

    count = 0

    while A  <  B:
        #print(A)
        if A > C and A < B:
            return 0
        if B==D:
            return 1
        #print(C,C%(D-B),D-B)
        A += (D-B) * int( (C-A) / (D-B) + 1)
    return 1




while counT < T:
    if main() == 1:
        s = "Yes"
    else:
        s = "No"
    print(s)
    counT +=1

Submission status: Wrong Answer

Solution code:
T = int(input())

L = []
for i in range(0,T):
    L = list(map(int, input().split()))
    A = L[0]
    B = L[1]
    C = L[2]
    D = L[3]

    ans = "Yes"
    if A < B: #前提条件
        ans = "No"
    elif D < B: #前提条件
        ans = "No"
    elif B - C <= 1: #BとCの差が1より小さければ何が来てもOK
        ans = "Yes"
    elif A % B > C:
        ans = "No"
    elif D % B == 1 and B - C > 1:
        ans = "No"
    elif D % B != 0:
        if ((C -(A%B)) % (D % B)) == 0 and D % B == B - C:
            ans = "Yes"
        elif ((C -(A%B)) % (D % B)) == 0 and D % B != B - C:
            ans = "No"
        elif B - C > (C -(A%B)) % (D % B):
            ans = "No"

    print(ans)
    L = []

Submission status: Wrong Answer

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

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) > 900:
				if min(hist) > a:
					result.append("No")
					break
			if len(hist) > 1000:
				result.append("Yes")
				break
for i in range(int(t)):
	print(result[i])

Submission status: Wrong Answer

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

T = int(input())
L = []

for i in range(T):
     L.append(list(map(int, input().split())))
P=0
F=0
for i in range(T):
     A=L[i]
     #print(A)
     P=A[0]
     X = P%A[1]
     if A[0]<A[1]:
         F=1
         print("No")
     elif (X>A[2]) and (F==0):
         F=1
         print("No")
     elif (A[2]+A[3]<A[0]) and (F==0):
         F=1
         print("No")
     P=X+A[3]
     for i in range(100):
         P=P-A[1]
         if (P<0) and (F==0):
             F=1
             print("No")
             break;
         if P<=A[2]:
             P = P+A[3]
     if F==0:
         print("Yes")
     P=0
     F=0

Submission status: Wrong Answer

Solution code:
#A = 初期値　B = 一日の購入　C = 乳化のボーダー　D =在庫の増やす数

#A > B
#D % B >= B - C

size = int(input())
data = []
flag = 0

for i in range(size):
    ip = input().split()
    data = []
    for j in ip:
        data.append(int(j))
    #定義
    store = data[0]
    buy = data[1]
    bord = data[2]
    charge = data[3]
    buf = []
#    print(store,buy,bord,charge,buf)
    #最初の処理
    store = store % buy
    if store > bord:
        flag = 1
    #定常処理
    while store not in buf:
        buf.append(store)
        store = (store + charge) % buy
        if store > bord:
            flag = 1
            break
 #   print(buf)
    if flag == 1:
        print("No")
        flag = 0
    else:
        print("Yes")

Submission status: Wrong Answer

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) > 800:
				if min(hist) > a:
					result.append("No")
					break
			if len(hist) > 1000:
				result.append("Yes")
				break
for i in range(int(t)):
	print(result[i])

Submission status: Wrong Answer

Solution code:
T = int(input())
for i in range(T):
    a, b, c, d = map(int, input().split())
    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: Wrong Answer

Solution code:
t=int(input())
for _ in range(t):
    a,b,c,d=map(int,input().split())
    e=b*(max((a-c)//b,1))
    a-=e
    while a>c:
        a-=b
    if a<0:
        print('No')
        continue
    if d<b:
        print('No')
        continue
    if c<=b and d>b:
        """
        while a<=c:
            a+=(d-b)
        """
        a+=(d-b)*((c-a+d-b-1)//(d-b))
        while a<=c:
            a+=(d-b)
        if a<b:
            print('No')
            continue
    print('Yes')

Submission status: Wrong Answer

Solution code:
t = int(input())

for _ in range(t):
    a, b, c, d = map(int, input().split())
    cond = True
    
    if a < b or b > d or (a % b) > c:
        cond = False
        
    if b < d and b > (c + 1):
        tmp = (((c - (a % b)) // (d - b)) + 1) * (d - b) +  (a % b)
        if tmp > c and tmp < b:
            cond = False
        
    if cond:
        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())
    e=b*(max((a-c)//b,1))
    a-=e
    while a>c:
        a-=b
    if a<0:
        print('No')
        continue
    if d<b:
        print('No')
        continue
    if c<=b and d>b:
        """
        while a<=c:
            a+=(d-b)
        """
        a+=(d-b)*((c-a-1)//(d-b))
        while a<=c:
            a+=(d-b)
        if a<b:
            print('No')
            continue
    print('Yes')

Submission status: Wrong Answer

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) > 800:
				if min(hist) > a:
					result.append("No")
					break
			if len(hist) > 1000:
				result.append("Yes")
				break
		if (len(hist) == 5) & (b < d) & (b < c):
			result.append("Yes")
			break
for i in range(int(t)):
	print(result[i])

Submission status: Wrong Answer

Solution code:
t=int(input())
for _ in range(t):
    a,b,c,d=map(int,input().split())
    e=b*(max((a-c)//b,1))
    a-=e
    while a>c:
        a-=b
    if a<0:
        print('No')
        continue
    if d<b:
        print('No')
        continue
    if c<=b and d>b:
        """
        while a<=c:
            a+=(d-b)
        """
        a+=(d-b)*((c-a)//(d-b))
        while a<=c:
            a+=(d-b)
        if a<b:
            print('No')
            continue
    print('Yes')

Submission status: Wrong Answer

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) > 600:
				if min(hist) > a:
					result.append("No")
					break
			if len(hist) > 500:
				result.append("Yes")
				break
		if (len(hist) == 5) & (b < d) & (b < c):
			result.append("Yes")
			break
for i in range(int(t)):
	print(result[i])

Submission status: Wrong Answer

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

for a,b,c,d in ABCD:
    if a < b:
        print('No')
        continue
    if d < b:
        print('No')
        continue
    tmp = a % b
    if tmp > c:
        print('No')
        continue
    if d % b == 0:
        print('Yes')
        continue
    if c >= b:
        print('Yes')
        continue

    if b - c == 1:
        print('Yes')
        continue
    
    dp = [a]
    now = a
    for _ in range(c+2):
        if now < b:
            print('No')
            break
        now %= b
        print(now,end=' ')
        if now in dp:
            print('Yes')
            break
        if now > c:
            print('No')
            break
        dp.append(now)
        now += d

Submission status: Wrong Answer

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) > 150:
				if min(hist) > a:
					result.append("No")
					break
			if len(hist) > 200:
				result.append("Yes")
				break
		if (len(hist) == 5) & (b < d) & (b < c):
			result.append("Yes")
			break
for i in range(int(t)):
	print(result[i])

Submission status: Wrong Answer

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) > 70:
				if min(hist) > a:
					result.append("No")
					break
			if len(hist) > 100:
				result.append("Yes")
				break
		if (len(hist) == 5) & (b < d) & (b < c):
			result.append("Yes")
			break
for i in range(int(t)):
	print(result[i])

Submission status: Wrong Answer

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 bc_diff > 0:
        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')