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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

def debug_print(s):
    pass
    # print(s, end="")

def solve2(A, B, C, D):
    def before_C(v):
        if v > C:
            tmp = v - ( (v - C) // B ) * B
            if tmp == C and tmp + B <= v:
                tmp += B
            return tmp
        else:
            return v
    if B > A:
        debug_print("(1)")
        return "No"
    if B > D:
        debug_print("(2)")
        return "No"
    if B <= C:
        debug_print("(3)")
        return "Yes"

    A = before_C(A)
    if B > A:
        debug_print("(4)")
        return "No"

    if A <= C:
        A -= B
        A += D

    seen = set()
    while True:
        A = before_C(A)
        if A < 0:
            return "No"
        if A <= C:
            A += D
        if A in seen:
            return "Yes"
        seen.add(A)

    return "unknown"

    gcd1 = gcd(B, D)
    gcd2 = gcd((A - B), (B - C))
    if gcd2 % gcd1 == 0:
        return "Yes"
    else:
        return "No"

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

    

def solve():
    A, B, C, D = map(int, input().split())
    return solve2(A, B, C, D)

    
T = int(input())
for t in range(T):
    print(solve())

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])
        A_list = []
        flag = False
        while True:
            if A in A_list:
                flag = True
                break
            A_list.append(A)
            if A < B:
                break
            A = A % B
            while (A <= C):
                A += B
            A_list.append(A)
            A = 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:
# 2
n = int(input())
a=[]
for i in range(n):
    a.append(list(map(int, input().split())))
# print(a)
for i in a:
    print('Yes' if i[0]>=i[1] & i[1]-1<=i[2] & i[1]<=i[3] else 'No')

Submission status: Wrong Answer

Solution code:
T = int(input())

for i in range(T):
  a, b, c, d = map(int, input().split())
  if d<b or a<b:
    print('No')
    continue
  if b-1<=c:
    print('Yes')
    continue
  if d%b<b-c:
    print('No')
    continue
  visited=[]
  while True:
    a = c+(a-c)%b
    if a>c and a<b:
      print('No')
      break
    elif a == c:
      if c in visited:
        print('Yes')
        break
      visited.append(a)
    else:
      a = a-b
      if a in visited:
        print('Yes')
        break
      visited.append(a)
    a+=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) > 5) & (b < d):
			result.append("Yes")
			break
for i in range(int(t)):
	print(result[i])

Submission status: Wrong Answer

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

for i in range(len(abcd_list)):
    a, b, c, d = abcd_list[i]
    _a = a
    is_ok = True
    for j in range(100000):
        if d < b:
            is_ok = False
            break
        if c >= b:
            is_ok = True
            break

        if _a - b > c:
            _a -= (((_a - c) // b) - 1) * b
        _a -= b
        if _a < 0:
            is_ok = False
            break
        if _a <= c:
            _a += d
    if is_ok:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

for query in queries:
    init = query[0] - query[1]
    d = query[3] - query[1]

    if init < 0:
        print('No')
        continue
    if d < 0:
        print('No')
        continue

    # for th
    if d == 0:
        if init > query[2]:
            if init >= query[1]:
                print('Yes')
            else:
                print('No')
        else:
            if init + query[3] >= query[1]:
                print('Yes')
            else:
                print('No')
    else:
        th = d * ((query[2] - init) // d) + d
        if th + init >= query[1]:
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
T=int(input())
for _ in range(T):
    a,b,c,d=map(int, input().split())
    A=[]
    while True:
        if a<b or b>d or a%b>c: 
            print("No")
            break
        elif b<=c+1 or b==d or a in A or len(A)==100:
            print("Yes")
            break
        else:
            if int((b+c-a)/(d-b)) != int((2*b-a)/(d-b)):
                print("No")
                break
            else:
                A.append(a)
                a = (int((2*b-a)/(d-b))+1)*(d-b)+a-b

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
T=int(input())
 
Query=[]
for i in range(T):
  Query.append(list(map(int,input().split())))
 
for i in range(T):
  count=0
  while(True):
    if Query[i][0]%Query[i][1]>Query[i][2] or Query[i][0]<Query[i][1]:
      print('No')
      break;
    Query[i][0]=Query[i][0]%Query[i][1] #昼
    if Query[i][0]<=Query[i][2]: #夜
      Query[i][0]+=Query[i][3]
    count+=1
    if count==300:
      print('Yes')
      break;

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) > 200:
			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(" "))
	if A < B:
		print("No")
		continue

	if D < B:
		print("No")
		continue

	if A > C:
		n = C + ((A - C) % B)
		if n != C:
			n -= B
		if n < 0:
			print("No")
			continue

	if C >= (B):
		print("Yes")
		continue

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

	c = (C // dif)
	#print(B//dif,C // dif)
	if (C % dif) == 0:
		if (C + dif) >= B:
			print("Yes")
		else:
			print("No")
	else:
		if (C - (C % dif)) + dif >= B:
			print("Yes")
		else:
			print("No")

Submission status: Wrong Answer

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


def check(a, b, c, d):
    if a < b:
        return 'No'
    if d < b:
        return 'No'
    if c < b:
        if a % b <= c:
            if d % b == 0:
                return 'Yes'
        if b % 2 == 1 or a % 2 == 1 or d % 2 == 1:
            if b - c > 1:
                return 'No'
        else:
            if b - c > 2:
                return 'No'
    return 'Yes'


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


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
T=int(input())

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 < 10000):
    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 == 10000):
      print("Yes")
  #print(A,B,C,D)

Submission status: Wrong Answer

Solution code:
T=int(input())

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

for i in range(T):
  count=0
  while(True):
    if Query[i][0]%Query[i][1]>Query[i][2]:
      print('No')
      break;
    Query[i][0]=Query[i][0]%Query[i][1] #昼
    if Query[i][0]<=Query[i][2]: #夜
      Query[i][0]+=Query[i][3]
    count+=1
    if count==300:
      print('Yes')
      break;

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

res = ['Yes' for i in range(T)]
for cnt in range(T):
    query = [A[cnt], B[cnt], C[cnt], D[cnt]]
    if query[0] % query[1] > query[2]:
        res[cnt] = 'No'
    else:
        hiru = []
        yoru = []
        hiru.append(query[0])
        yoru.append(query[0]%query[1])
        for i in range(10000):
            if yoru[-1] <= query[2]:
                hiru.append(yoru[-1] + query[3])
                if hiru[-1] >= query[1]:
                    yoru.append(hiru[-1]%query[1])
                else:
                    yoru.append(-1000)
            else:
                hiru.append(yoru[-1])
                if hiru[-1] >= query[1]:
                    yoru.append(hiru[-1]%query[1])
                else:
                    yoru.append(-1000)
                    
        if min(yoru) < 0:
            res[cnt] = 'No'
for i in range(T):
    print(res[i])

Submission status: Wrong Answer

Solution code:
import fractions

def judge(a,b,c,d):
    bd_gcd=fractions.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: Wrong Answer

Solution code:
n = int(input())
list = [map(int, input().split()) for i in range(n)]

def check(num):
    a, b, c, d = list[num]
    if b > d:
        return False
    if a < b:
        return False
    if a % b > c:
        return False
    if c < b and d != b:
        if (b - ( a % b ) - 1) // (d - b) != ((c - ( a % b ))) // (d - b):
            return False
    return True

for i in range(n):
    if check(i):
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
T = int(input())

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

for abcd in ABCD:
    a,b,c,d = abcd
    # 初日にダメになる
    if a < b:
        print("No")
    # 在庫補充が追いつかない
    elif d < b:
        print("No")
    # 補充タイミングが十分に早い
    elif c >= b:
        print("Yes")
    #elif b-c == 1:
    #    print("Yes")
    else:
        #print(" ",a,b,c,d,a%b,d%b)
        e = a%b
        f = d%b
        if f==0:
            if c<e<b:
                print("No")
            else:
                print("Yes") 
        else:
            if (((c-e)//f+1)*f+e) < b:
                print("No")
            else:
                print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())

inputs = [input().split(" ") for _ in range(N)]    


for input in inputs:
    # print(input)
    A = int(input[0])
    B = int(input[1])
    C = int(input[2])
    D = int(input[3])
    FLAG = True
    asa = A
    start_roop = None
    while FLAG:
        yoru = asa - B
        if start_roop is None:
            start_roop = yoru
        # print("yoru : {}. start_roop : {}".format(yoru, start_roop))
        if yoru != start_roop:
            if yoru < 0:
                print("No")
                FLAG = False
                break
            elif yoru <= C:
                
                yoru += D
        else:
            print("Yes")
            FLAG = False
            break

Submission status: Wrong Answer

Solution code:

T = int(input())
queries = [list(map(int, input().split())) for _ in range(T)]

for query in queries:
    init = query[0] - query[1]
    d = query[3] - query[1]

    if init < 0 or query[2] < init < query[1]:
        print('No')
        continue
    if d < 0:
        print('No')
        continue

    # for th
    if d == 0:
        if init > query[1]:
            if init >= query[1]:
                print('Yes')
            else:
                print('No')
        else:
            if init + query[3] >= query[1]:
                print('Yes')
            else:
                print('No')
    else:
        th = d * ((query[2] - init) // d) + d
        if th + init >= query[1]:
            print('Yes')
        else:
            print('No')

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])
        A_list = []
        flag = False
        while True:
            if A in A_list:
                flag = True
                break
            A_list.append(A)
            if A < B:
                break

            A = A % B
            while (A + B <= C):
                A += B
                #print(A)
            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:
N = int(input())

inputs = [input().split(" ") for _ in range(N)]    


for input in inputs:
    # print(input)
    A = int(input[0])
    B = int(input[1])
    C = int(input[2])
    D = int(input[3])
    FLAG = True
    asa = A
    start_roop = None
    while FLAG:
        yoru = asa - B
        if start_roop is None:
            start_roop = yoru
        # print("yoru : {}. start_roop : {}".format(yoru, start_roop))
        if yoru != start_roop:
            if yoru < 0:
                print("No")
                FLAG = False
                break
            elif yoru <= C:
                
                yoru += D
            print(yoru)
        else:
            print("Yes")
            FLAG = False
            break

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) > 100:
			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())
    cond = True
    
    if a < b or b > d or (a % b) > c:
        cond = False
    
    if b != d and b > c:
        if (b - c) > (d - b):
            cond = False
        else:
            tmp = (((c - (a % b)) // (d - b)) + 1) * (d - b) +  (a % b)
            if tmp > c:
                cond = False
        
    if cond:
        print('Yes')
    else:
        print('No')

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])
        A_list = []
        flag = False
        while True:
            if A in A_list:
                flag = True
                break
            A_list.append(A)
            if A < B:
                break

            A = A % B
            while (A + B <= C):
                A += B
                print(A)
            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())
c = [list(map(int,input().split())) for i in range(t)]
for i in range(t):
    mem1 = c[i][0] % c[i][1]
    mem2 = c[i][3] % c[i][1]
    mem3 = mem1
    cnt = 0
    while 1 :
        if c[i][0] < c[i][1]:
            print("No")
            break; 
        elif c[i][3] < c[i][1]:
            print("No")
            break;      
        elif mem2 == 0 & c[i][1] - c[i][2] > 1 & c[i][2] < mem1 < c[i][1]:
            print("No")    
            break;
        elif mem2 % 2 == 1 & c[i][1] - c[i][2] > 1:
            print("No")  
            break;
        elif mem2 % 2 == 0 & mem1 % 2 == 0 & c[i][1] - c[i][2] > 1 & (c[i][1]-1)%2 == 0:
            print("No")  
            break;
        elif mem2 % 2 == 0 & mem1 % 2 == 1 & c[i][1] - c[i][2] > 1 & (c[i][1]-1)%2 == 1:
            print("No")  
            break;
        else :
            print("Yes")
            break;

Submission status: Wrong Answer

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

def kou(x, y):
	if y > x:
		z = y
		y = x
		x = z
	while x % y != 0:
		x, y = y, x % y
	return y

def function(arr):
	if arr[0] < arr[1]:
		print('No')
	elif arr[1] - arr[2] <= 1:
		print('Yes')
	else:
		count = 0
		s = kou(arr[1], arr[3])
		for i in range(arr[2] + 1, arr[1]):
			if (arr[0] - i) % s == 0:
				count = 1

		if count == 1:
			print('No')
		else:
			print('Yes')

for i in range(t):
	function(a[i])

Submission status: Wrong Answer

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[i] >= B[i] and B[i] < C[i]:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:

N = int(input())

for i in range(N):
    a,b,c,d = map(int,input().split( ))
    if a < b:
        print("No")
    elif b == 1:
        print("Yes")
    else:
        if a > c:
            a = a % b
            while a <= c:
                a += b
        if d > c:
            d = d % b
            while d <= c:
                d += b
        ok = False
        store = a
        for i in range(a):
            store += -b
            if store < 0:
                break
            if store <= c:
                store += d
            if store == a:
                ok = True
                break
        if ok :
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

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

res = ['Yes' for i in range(T)]
for cnt in range(T):
    query = [A[cnt], B[cnt], C[cnt], D[cnt]]
    if query[0] % query[1] > query[2]:
        res[cnt] = 'No'
    else:
        hiru = []
        yoru = []
        hiru.append(query[0])
        yoru.append(query[0]%query[1])
        for i in range(10000):
            if yoru[-1] <= query[2]:
                hiru.append(yoru[-1] + query[3])
                if hiru[-1] > query[1]:
                    yoru.append(hiru[-1]%query[1])
                else:
                    yoru.append(-1000)
            else:
                hiru.append(yoru[-1])
                if hiru[-1] >= query[1]:
                    yoru.append(hiru[-1]%query[1])
                else:
                    yoru.append(-1000)
                    
        if min(yoru) < 0:
            res[cnt] = 'No'
for i in range(T):
    print(res[i])

Submission status: Wrong Answer

Solution code:
T = int(input())
for i in range(T):
	A,B,C,D = map(int,input().split(" "))
	if A < B:
		print("No")
		continue
	if D < B:
		print("No")
		continue

	if (A % B) > C:
		print("No")
		continue

	if C >= (B):
		print("Yes")
		continue

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

	c = (C // dif)
	#print(B//dif,C // dif)
	if (C % dif) == 0:
		if (C + dif) >= B:
			print("Yes")
		else:
			print("No")
	else:
		if (C - (C % dif)) + dif >= B:
			print("Yes")
		else:
			print("No")

Submission status: Wrong Answer

Solution code:
Y = "Yes"
N = "No"
T = int(input())
for _ in range(T):
	A, B, C, D = [int(x) for x in input().split()]
	if A < B or B > D:
		print(N)
	elif B <= C:
		print(Y)
	else:
		if A > C:
			A -= ((A-C)//B)*B
			if A > C:
				A -= B
		if A < 0:
			print(N)
			continue
		x = D-B
		if x == 0:
			print(Y)
			continue
		B-=A
		C-=A
		if B%x==0:
			if B-x>C:
				print(N)
			else:
				print(Y)
		elif (B//x)*x>C:
			print(N)
		else:
			print(Y)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
def LI(): return list(map(int, input().split()))
t = int(input())
q = []
for i in range(t):
    a, b, c, d = LI()
    if a < b or b > d:
        print("No")
        continue
    if c >= b:
        print("Yes")
        continue
    k = math.ceil((a-c)/b)
    k = (a-c)//b
    first = a - k*b
    if first > c:
        first -= b
    if first < 0:
        print("No")
        continue
    sub = d%b
    if sub == 0:
        print("Yes")
        continue
    first = first % sub
    s = set([first])
    while True:
        n = int(((c-first)/sub)) + 1
        next_first = (first + n*sub - b)
        if next_first < 0:
            print("No")
            break
        next_first = next_first % sub
        if next_first in s:
            print("Yes")
            break
        s.add(next_first)
        first = next_first

Submission status: Wrong Answer

Solution code:
N = int(input())
x = []
for i in range(N):
    a1,b1,c1,d1=[int(i) for i in input().split()]
    x.append([a1,b1,c1,d1])
for i in range(N):
  y = x[i]
  if y[0] < y[1]:
    print("No")
  elif y[1] > y[3]:
    print("No")
  elif y[1] > y[2]:
    ama = y[0] % y[1]
    mita = set()
    mo = y[3] %  y[1]
    if mo > y[1]-y[2]:
      print("No")
    else:
      print("Yes")
  else:
    print("Yes")

Submission status: Wrong Answer

Solution code:

N = int(input())

for i in range(N):
    a,b,c,d = map(int,input().split( ))
    if a < b:
        print("No")
    elif b == 1:
        print("Yes")
    else:
        a = a % b
        while a <= c:
            a += b
#        d = d % b
#        while d <= c:
#            d += b
        ok = False
        store = a
        for i in range(a):
            store += -b
            if store < 0:
                break
            if store <= c:
                store += d
            if store == a:
                ok = True
                break
        if ok :
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
t = int(input())

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

Submission status: Wrong Answer

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)
    i += 1
    if(i == 1000):
      print("Yes")
  #print(A,B,C,D)

Submission status: Wrong Answer

Solution code:
t = int(input())

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

for i in range(t):
  a, b, c, d = list(map(int, input().split()))
  if a<b or b>d:
    print("No")
  elif a%b>c:
    print("No")
  elif gcd(c, d)>=b%c:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
import math

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:
        if (b - c) > (d - b):
            cond = False
        else:
            tmp = math.ceil(((c - (a % b)) / (d - b))) * (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:
def gcd (a,b):
	if a < b:
		a,b = b,a
	return a if b == 0 else gcd(b,a%b)

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

	if (A % B) > C:
		print("No")
		continue

	if C >= (B-1):
		print("Yes")
		continue

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

	c = (C // dif)
	#print(B//dif,C // dif)
	if (C % dif) == 0:
		if (B - C) <= dif:
			print("Yes")
		else:
			print("No")
	else:
		if ((B-1)//dif) - (C//dif) >= 1:
			print("No")
		else:
			print("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])

    
NoFlag=0

for i in range(T):
    if a[i] < b[i]:
        print("No")

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

    elif b[i] <= c[i]+1:
        print("Yes")
        
    else:
        a[i] = a[i]%b[i] +b[i]
        for ii in range(b[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]
            
        if NoFlag ==0:
            print("Yes")