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:
import sys
sys.setrecursionlimit(10**6)
t = int(input())
for _ in range(t):
    a,b,c,d = map(int,input().split())

    if a < b or b > d:
        print("No")
        continue
    if b == d:
        if c >= a:
            print("Yes")
        elif a - ((a-c-1)//b+1)*b < 0:
            print("No")
        else:
            print("Yes")
        continue
    if c >= b:
        print("Yes")
        continue

    count = 0
    s = set()
    check = True
    while count < 3*10**5:
        x = max((a-c-1)//b,0)+1
        a -= x*b
        if a < 0:
            check = False
            break
        if a in s:
            break
        s.add(a)
        a += d
        count += 1
    if check and count < 3*10**5:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
t = int(input())
for _ in range(t):
    a,b,c,d = map(int,input().split())

    if a < b or b > d:
        print("No")
        continue
    if b == d:
        if c >= a:
            print("Yes")
        elif a - ((a-c-1)//b+1)*b < 0:
            print("No")
        else:
            print("Yes")
        continue
    if c >= b:
        print("Yes")
        continue

    count = 0
    s = set()
    check = True
    while count < 3*10**5:
        x = max((a-c-1)//b,0)+1
        a -= x*b
        if a < 0:
            check = False
            break
        if a in s:
            break
        s.add(a)
        a += d
        count += 1
    if check:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
t = int(input())
for _ in range(t):
    a,b,c,d = map(int,input().split())

    if a < b or b > d:
        print("No")
        continue
    if b == d:
        if c >= a:
            print("Yes")
        elif a - ((a-c-1)//b+1)*b < 0:
            print("No")
        else:
            print("Yes")
        continue
    if c >= b:
        print("Yes")
        continue

    count = 0
    s = set()
    check = True
    while count < 10**5:
        x = max((a-c-1)//b,0)+1
        a -= x*b
        if a < 0:
            check = False
            break
        if a in s:
            break
        s.add(a)
        a += d
        count += 1
    if check:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
from math import gcd

def solve(a,b,c,d):
  
    if a < b:
        return False
    if d < b:
        return False

    g = gcd(b,d)
    m = b - (b-a-1)%g - 1
    print(m)
    return m <= c

T = int(input())
for _ in range(T):
    print('Yes' if solve(*map(int,input().split())) else 'No')

Submission status: Wrong Answer

Solution code:
def solve(P):
    A, B, C, D = P
    if C >= B-1:
        return True
    if A<B or D<B:
        return False
    g = gcd(B,D)
    return B + A%g - g <= C

from math import gcd

T = int(input())
for _ in range(T):
    P = map(int, input().split())
    print("Yes" if solve(P) else "No")

Submission status: Wrong Answer

Solution code:
from math import gcd

t = int(input())
queries = [tuple(int(x) for x in input().split()) for _ in range(t)]
for a, b, c, d in queries:
    if a < b:
        print("No")
        continue
    if b > d:
        print("No")
        continue
    if b - c <= 1:
        print("Yes")
        continue

    g = gcd(b, d)
    if c < a + ((b - a) // g) * g:
        print("No")
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math
import decimal

ctx = decimal.Context(prec=1, rounding=decimal.ROUND_CEILING)

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

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

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

    if c >= b:
        print('Yes')
        continue

    g = gcd(b, d)
    r = a % g
    # FYI: https://stackoverflow.com/questions/2795946/getting-ceil-of-decimal-in-python
    #_max = (int(((decimal.Decimal(b, context=ctx) - decimal.Decimal(r, context=ctx)) / decimal.Decimal(g, context=ctx)).to_integral_exact(context=ctx)) * g) + r - g

    # math.ceilは精度不足でエラーになる: https://cocoinit23.com/math-floor-ceil-error/
    _max = (int(math.ceil((b - r) / g)) * g) + r - g

    # OK: (a + b - 1) // b: https://nariagari-igakusei.com/cpp-division-round-up/
    #_max = ((b - r + g - 1)//g) * g + r - g
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math

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

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

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

    if c >= b:
        print('Yes')
        continue

    g = gcd(b, d)
    r = a % g
    #_max = ((math.ceil((b - r) / g)) * g) + r - g
    _max = (int(-(-((b - r) / g)//1)) * g) + r - g
    #_max = ((b - r + g - 1)//g) * g + r - g
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math

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

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

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

    if c >= b:
        print('Yes')
        continue

    g = gcd(b, d)
    r = a % g
    _max = int(math.ceil((b - r) / g) - 1) * g + r
    #_max = ((math.ceil((b - r) / g)) * g) + r - g
    #_max = ((b - r + g - 1)//g) * g + r - g
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math

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

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

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

    if c >= b:
        print('Yes')
        continue

    g = gcd(b, d)
    r = a % g
    _max = (math.ceil((b - r) / g) - 1) * g + r
    #_max = ((math.ceil((b - r) / g)) * g) + r - g
    #_max = ((b - r + g - 1)//g) * g + r - g
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math

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

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

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

    if c >= b:
        print('Yes')
        continue

    g = gcd(b, d)
    r = a % g
    #_max = (math.ceil((b - r) / g) - 1) * g + r
    _max = ((math.ceil((b - r) / g)) * g) + r - g
    #_max = ((b - r + g - 1)//g) * g + r - g
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math

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

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

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

    if c >= b:
        print('Yes')
        continue

    g = gcd(b, d)
    r = a % g
    #_max = (math.ceil((b - r) / g) - 1) * g + r
    _max = (math.ceil((b - r) / g)) * g + r - g
    #_max = ((b - r + g - 1)//g) * g + r - g
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math

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

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

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

    if c >= b-1:
        print('Yes')
        continue

    g = gcd(b, d)
    r = a % g
    _max = (math.ceil((b - r) / g) - 1) * g + r
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math

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

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

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

    if c >= b:
        print('Yes')
        continue

    g = gcd(b, d)
    r = a % g
    _max = (math.ceil((b - r) / g) - 1) * g + r
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
def solve():
  T = int(input())
  ans = ['No']*T
  for i in range(T):
    A,B,C,D = map(int, input().split())
    if A<B:
      continue
    now = A-(-(-(A-C)//B))*B
    if now<0:
      continue
    if D<B:
      continue
    if D%B==0:
      ans[i] = 'Yes'
      continue
    if C>=B:
      ans[i] = 'Yes'
      continue
    p = (C-now)//((D-B)%B)+1
    if p<(B-now)/((D-B)%B):
      continue
    ans[i] = 'Yes'
  return ans
print(*solve(),sep='\n')

Submission status: Wrong Answer

Solution code:
def solve():
  T = int(input())
  ans = ['No']*T
  for i in range(T):
    A,B,C,D = map(int, input().split())
    if A<B:
      continue
    now = A-(-(-(A-C)//B))*B
    if now<0:
      continue
    if D<B:
      continue
    if D%B==0:
      ans[i] = 'Yes'
      continue
    if C>=B:
      continue
    p = (C-now)//((D-B)%B)+1
    if p<(B-now)/((D-B)%B):
      continue
    ans[i] = 'Yes'
  return ans
print(*solve(),sep='\n')

Submission status: Wrong Answer

Solution code:
def solve():
  T = int(input())
  ans = ['No']*T
  for i in range(T):
    A,B,C,D = map(int, input().split())
    if A<B:
      continue
    now = A-(-(-(A-C)//B))*B
    if now<0:
      continue
    if D<B:
      continue
    if D%B==0:
      ans[i] = 'Yes'
      continue
    p = (C-now)//((D-B)%B)+1
    if p<(B-now)/((D-B)%B):
      continue
    ans[i] = 'Yes'
  return ans
print(*solve(),sep='\n')

Submission status: Wrong Answer

Solution code:
def solve():
  T = int(input())
  ans = ['No']*T
  for i in range(T):
    A,B,C,D = map(int, input().split())
    if A<B:
      continue
    now = A-(-(-(A-C)//B))*B
    if now<0:
      continue
    if D<B:
      continue
    if D==B:
      ans[i] = 'Yes'
      continue
    p = (C-now)//(D-B)+1
    if p<(B-now)/(D-B):
      continue
    ans[i] = 'Yes'
  return ans
print(*solve(),sep='\n')

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

for i in range(t):
    a,b,c,d=abcd[i]
    if a<b:
        print("No")
    elif d<b:
        print("No")
    else:
        if a>=c:
            last=(a-c)%b
            if d%b==0:
                if last==0:
                    print("Yes")
                elif last+c<b:
                    print("No")
                else:
                    print("Yes")
            else:
                gc=math.gcd(b,d)
                if gc!=1:
                    last%=gc
                else:
                    last=1
                if last==0:
                    print("Yes")
                elif last+c<b:
                    print("No")
                else:
                    print("Yes")
        else:
            print("Yes")

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 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 main():
    t = I()
    A = []
    for _ in range(t):
        a, b, c, d = LI()
        if a < b:
            ans = 'No'
        elif b > d:
            ans = 'No'
        elif c >= b:
            ans = 'Yes'
        else:
            if a % b + d < b:
                ans = 'No'
                A.append(ans)
                continue
            if d % b > 0:
                shou = (c - a % b) // (d % b)
            else:
                shou = 0
            # print()
            # print(a, b, c,d)
            # print('shou: ', shou)
            # print('d % b: ', d % b)
            # print('a % b: ', a % b)
            if c < shou * (d % b) + a % b + (d % b) < b:
                ans = 'No'
            else:
                ans = 'Yes'
            # print()
        A.append(ans)
    for a in A:
        print(a)
main()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

def sub(a,b,c,d):
    x1 = a - max(1, (a - (c+1))//b) * b
    if d<b:
        ans = "No"
    elif a<b:
        ans = "No"
    elif d%b==0:
        if x1>=b:
            ans = "Yes"
        else:
            ans = "No"
    else:
        k = gcd(d,b)
        x2 = x1 - (x1 - (c+1))//k * k
        if x2>=b:
            ans = "Yes"
        else:
            ans = "No"
    return ans

t = int(input())
ans = []
for i in range(t):
    a,b,c,d = map(int, input().split())
    ans.append(sub(a,b,c,d))
write("\n".join(ans))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
T = int(input())

for _ in range(T):
    a, b, c, d = map(int, input().split())
    if b > a or b > d:
        flg = False
    else:
        if b - 1 <= c:
            flg = True
        elif a % b > c:
            flg = False
        else:
            g = gcd(d, b)
            if (-a) % b // g * g + a % b <= c: 
                flg = True
            else:
                flg = False

    if flg:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
 
YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=0):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.size=len(ls)+1
                self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def __str__(self):
        return  str(self.edges)
 
    def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append(x)
        v=[-1]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==-1:
                    q.append(nb)
                    v[nb]=func(v[c],nb,d)
        return v
 
    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.size
        self.ETout=[-1]*self.size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]
 
class SparseTable: # O(N log N) for init, O(1) for query(l,r)
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1
 
        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    # return func of [l,r)
    def query(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))])
    
    # return index of which val[i] = func of v among [l,r)
    def query_id(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]):
            b=a
        return b
    
    def __str__(self):
        return str(self.table[0])
 
    def print(self):
        for i in self.table:
            print(*i)
 
class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]
 
    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo
 
show_flg=False
show_flg=True
ans=0

T=I()

for _ in range(T):
    a,b,c,d=LI()
    z=[]
    night=a
    ans='Yes'
    while True:
        day=night
        k=max(1,(day-c)//b)
        day-=b*k
        night=day+d if day<=c else day
        
        if (day,night) in z:
            z+=[(day,night)]
            break
        
        z+=[(day,night)]
        
        if day<0 or len(z)>10**3:
            ans='No'
            break
    print(ans)#,z[:20])

Submission status: Wrong Answer

Solution code:
from fractions import gcd
t = int(input())
ans = ['Yes']*t
for i in range(t):
    a,b,c,d = map(int,input().split())
    if d < b:
        ans[i] = 'No'
    elif a < b:
        ans[i] = 'No'
    elif d%b == 0:
        if c < a%b < b:
            ans[i] = 'No'
    else:
        if (1+(c-a%b)//(d%b))*(d%b) < b-a%b:
            ans[i] = 'No'
print("\n".join(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def ringo(A, B, C, D):
    if A < B:  # 初手売り切れ
        return "No"
    if B > D:  # どんどん減る
        return "No"
    if A <= C:
        return "Yes"
    else:
        # 初めて[0, C]となるとき->buy
        tmp = A - C
        buy = B * ((tmp + B - 1) // B)
        if A - buy < 0:
            return "No"
        if D % B == 0:
            return "Yes"
        # 初項ai, 公差dの等差数列が[C+1, B)の範囲に来るとNG
        # c+1-ai+d <= nd <= B-ai+dを満たす整数nが存在するとNG
        ai = A - buy
        d = D % B
        left = (C + 1 - ai + d + d - 1) // d
        right = (B - 1 - ai + d) // d
        if left <= right:
            return "No"
        else:
            return "Yes"


if __name__ == "__main__":
    T = int(input())
    ans = [ringo(*map(int, input().split())) for _ in range(T)]
    print(*ans, sep="\n")

Submission status: Wrong Answer

Solution code:
def ringo(A, B, C, D):
    if A < B:  # 初手売り切れ
        return "No"
    if B > D:  # どんどん減る
        return "No"
    if A <= C:
        return "Yes"
    else:
        # 初めて[0, C]となるとき->buy
        tmp = A - C
        buy = B * ((tmp + B - 1) // B)
        if A - buy < 0:
            return "No"
        if D % B == 0:
            return "Yes"
        # 初項ai, 公差dの等差数列が[C+1, B)の範囲に来るとNG
        # c+1-ai+d <= nd <= B-ai+dを満たす整数nが存在するとNG
        ai = A - buy
        d = D % B
        left = (C + 1 - ai + d + d - 1) // d
        right = (B - 1 - ai + d) // d
        print(ai, d)
        print(left, right)
        if left <= right:
            return "No"
        else:
            return "Yes"


if __name__ == "__main__":
    T = int(input())
    ans = [ringo(*map(int, input().split())) for _ in range(T)]
    print(*ans, sep="\n")

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    t = int(input())

    from math import ceil

    for i in range(t):
        a, b, c, d = list(map(int, readline().split()))
        if a >= b and d >= b:
                x = a % b
                y = d % b
                if y == 0:
                    if x <= c:
                        z = x + d
                    else:
                        z = x
                else:
                    z = y * ceil((c + 1 - x) / y) + x
                if z >= b:
                    print('Yes')
                    continue
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    t = int(input())

    from math import ceil

    for i in range(t):
        a, b, c, d = list(map(int, readline().split()))
        if a >= b and d >= b:
            if c >= b:
                print('Yes')
                continue
            else:
                x = a % b
                y = d % b
                if y == 0:
                    if x <= c:
                        z = x + d
                    else:
                        z = x
                else:
                    z = y * ceil((c + 1 - x) / y) + x
                if z >= b:
                    print('Yes')
                    continue
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions
t = int(input())
al = []
for i in range(t):
    a,b,c,d = map(int,input().split())
    if b > d:
        al.append("No")
    else:
        if b > a:
            al.append("No")
        else:
            if b-1 <= c:
                al.append("Yes")
            else:
                if a % b > c:
                    al.append("No")
                else:
                    yo = d%b
                    now = a%b
                    if yo == 0:
                        al.append("Yes")
                    elif now == 0:
                        g = fractions.gcd(b,yo)
                        if (b-1)//g == (c+1)//g:
                            if b-1 == c+1:
                                if (c+1) % g == 0:
                                    al.append("No")
                                else:
                                    al.append("Yes")
                            else:
                                if (c+1) % g == 0:
                                    al.append("No")
                                else:
                                    al.append("Yes")
                        else:
                            al.append("No")
                    else:
                        g = fractions.gcd(yo,now)
                        g = fractions.gcd(g,b)
                        if (b-1)//g == (c+1)//g:
                            if b-1 == c+1:
                                if (c+1) % g == 0:
                                    al.append("No")
                                else:
                                    al.append("Yes")
                            else:
                                if (c+1) % g == 0:
                                    al.append("No")
                                else:
                                    al.append("Yes")
                        else:
                            al.append("No")
for i in al:
    print(i)