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

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

Submission status: Wrong Answer

Solution code:
# cook your dish here
t =int(input())
 
for i in range(0,t):
    a,b,c,d = map(int,input().split())
    
    l = [a]
    if a < b:
        print('No')
    elif a-c <= 0:
        if a >= b and d >=b:
            print('Yes')
        else:
            print('No')
    else:
        
        for j in range(0,100001):
            if a-c <= 0:
                if a >= b and d >=b:
                    print('Yes')
                else:
                    print('No')
                break
            if (a-c)%b == 0:
                n = (a-c)//b
            else:
                n = (a-c)//b + 1
            if a- n*b < 0:
                print('No')
                break
            if  a-n*b+d in l:
                print('Yes')
                break
            l.append(a-n*b+d)
            a = a-n*b+d
            if j == 1000:
                print('Yes')
                break

Submission status: Wrong Answer

Solution code:
def canbuy(A,B,C,D):
    X=A
    S=set()
    N=0
    if B>D:
        return False
    for i in range(5*10**2):
        X-=B*max([(X-C)//B,1])
        if X<0:
            return False
        if X<=C:
            X+=D
        if X==A:
            return True
        S.add(X)
        N+=1
        if len(S)<N:
            return True
    return True
T=int(input())
a=[0 for i in range(T)]
b=[0 for i in range(T)]
c=[0 for i in range(T)]
d=[0 for i in range(T)]
for i in range(T):
    a[i],b[i],c[i],d[i]=map(int,input().split())

for i in range(T):
    if canbuy(a[i],b[i],c[i],d[i]):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

		while A<=B:
			if (D-B)%B==0:
				if A>C and A<B:
					print "No"
					break
				else:
					print "Yes"
					break
			elif (D-B)%B==1:
					print "No"
					break

			A+=(D-B)%B
			if A>C and A<B:
				print "No"
				break
		else:
			print "Yes"

Submission status: Wrong Answer

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

Submission status: 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)

    if (A % b > c):
        print("No")
        continue
    
    ddb = (A % b - a + b) % b
    
    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())
check = 0
while check < T:
    A, B, C, D = map(int, input().split())
    check += 1
    if A >= B and B * 2 < C + D:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
from sys import stdin

# stdin = open('sample.txt')

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

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


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
t = int(input())

def no():
    print("No")

def yes():
    print("Yes")

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

    dif = d - b
    min_n = a - b

    if (a < b or d < b or a % b > c):
        no()
        continue
    if dif != 0 and min_n != 0 and b > c:
        already = []
        start = a
        done = False
        previous = 10**19
        while True:
            count = start // b
            end = start - count * b
            if end > previous:
                dif = end - previous
                count = ((c-previous) // dif) + 1
                val = previous + dif*count
                if b > val and val > c:
                    no()
                    done = True
                    break
                start = val + b
                previous = 10 ** 19
            else:
                if end in already:
                    break
                already.append(end)
                start = end + d
                previous = end
        if done:
            continue

    yes()

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 = True
        for i in range(1000):
            if A in A_list:
                flag = True
                break
            A_list.extend([A])
            if A < B:
                flag = False
                break
            q, A = divmod(A, B)
            for i in range(q-1):
                if A + B > C:
                    break
                A += B
            A_list.extend([A + B])
            if A <= C:
                A = A + D
        if flag:
            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 = True
        for i in range(500):
            if A in A_list:
                flag = True
                break
            A_list.extend([A])
            if A < B:
                flag = False
                break
            q, A = divmod(A, B)
            for i in range(q-1):
                if A + B > C:
                    break
                A += B
            A_list.extend([A + B])
            if A <= C:
                A = A + D
        if flag:
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
class query:
    def __init__(self, a, b, c, d):
        self.a = a
        self.b = b
        self.c = c
        self.d = d
    def isEternal(self):
        if self.a < self.b:
            return "No"
        ab = self.a % self.b
        if ab > self.c:
            return "No"
        if self.d < self.b:
            return "No"
        d = self.b - self.c
        if d <= 0:
            return "Yes"
        if self.b % d == 0 and self.d % d == 0:
            return "Yes"
        db = self.d % self.b
        if db == 0:
            return "Yes"
        if (((self.c - ab) // db) + 1) * db >= self.b - ab and (self.b - ab) % db == 0:
            return "Yes"
        return "No"

if __name__ == "__main__":
    t = int(input())
    querys = [query(*[int(s) for s in input().split()]) for _ in range(t)]
    for q in querys:
        print(q.isEternal())

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 = True
        for i in range(100):
            if A in A_list:
                flag = True
                break
            A_list.extend([A])
            if A < B:
                flag = False
                break
            q, A = divmod(A, B)
            for i in range(q-1):
                if A + B > C:
                    break
                A += B
            A_list.extend([A + B])
            if A <= C:
                A = A + D
        if flag:
            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 > C:
		init = C + ((A - C) % B)
		if init != C:
			init -= B
		if init < 0:
			print("No")
			continue
	else:
		init = A

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

	dif = (D - B)
	if dif == 0:
		print("Yes")
		continue
	i = C - ((C - init) % dif)
	if i + dif < B:
		print("No")
	else:
		print("Yes")

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:
            return 'No'
        if d % b == 0:
            return 'Yes'
        if b % 2 == 0 and d % 2 == 0:
            if (d - b) % (b - c) == 0:
                return 'Yes'
            else:
                return 'No'
        else:
            if b - c > 1:
                return 'No'
#        if b % 2 == 1 or a % 2 == 1 or d % 2 == 1:
#            if b - c > 1:
#                return 'No'
#        else:
#            if (d - b) % (b - c) == 0:
#                return 'Yes'
#            else:
#                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:



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


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


#print(so(11,5))

def aaa(n):

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

  e=a-a//b*b
  f=d-d//b*b
  
  if e*f>0 :
    s=so(e,f)
  else :
    s=f


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

      if ss>c:
        return "No"
          
    

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

  return "Yes"

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

Submission status: 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

    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
    assert 0 <= (A + (B-1-A)//E*E)%B < B
    print("No" if (A + (B-1-A)//E*E)%B > C else "Yes")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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
    if A <= C and B == D:
        return 1

    count = 0

    while A  <  B:
        count += 1
        #print(A)
        if A > C and A < B:
            return 0
        if B==D:
            return 1
        #print(A,B,C,D)
        #print(int((C-A) / (D-B) + 1),count)
        if A <= C:
            A += int((C-A) / (D-B) + 1) *(D-B)
            if int((C-A) / (D-B)) == 1:
                A = A - (D-B)
        else:
            A += (D-B)        
    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())
query=[]
for i in range(t):
    query.append(list(map(int,input().split())))



def cal(a,b,c,d,cnt):
    if cnt%2==0:
        a=a-b
    else:
        if a<=c:
            a=a+d
    return a

yn=[]
cnt2=0
list_a=[[]for i in range(t)]
for i in range(t):
    a=query[i][0]
    list_a[i].append(a)
    cnt=0
    while 1:
        a=cal(a,query[i][1],query[i][2],query[i][3],cnt)
        if a<0:
            yn.append(0)
            break
        

        if cnt%2==0: 
            cnt2+=1
            list_a[i].append(a)
            if a in list_a[i][:cnt2]:
                yn.append(1)
                break
        cnt+=1
        
for i in range(t):
    if yn[i]==0:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
from sys import stdin

# stdin = open('sample.txt')

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

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


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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



def cal(a,b,c,d,cnt):
    if cnt%2==0:
        a=a-b
    else:
        if a<=c:
            a=a+d
    return a

yn=[]
cnt2=0
list_a=[[]for i in range(t)]
for i in range(t):
    a=query[i][0]
    list_a[i].append(a)
    cnt=0
    while 1:
        a=cal(a,query[i][1],query[i][2],query[i][3],cnt)
        if a<0:
            yn.append(0)
            break
        

        if cnt%2==0: 
            cnt2+=1
            list_a[i].append(a)
            if a in list_a[i][:cnt2]:
                yn.append(1)
                break
        cnt+=1
        
for i in range(t):
    if yn[i]==0:
        print('No')
    else:
        print('Yes')
print(yn,list_a)

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

    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:
T = int(input())
check = 0
while check < T:
    A, B, C, D = map(int, input().split())
    check += 1
    if A >= B and B * 2 == C + D:
        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:
            return 'No'
        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 (d - b) % (b - c) == 0:
                return 'Yes'
            else:
                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())

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 or a%b>c:
    print("No")
  elif b==d:
    print("Yes")
  elif gcd(b, d)>=b%c:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
T = int(input())
check = 0
while check < T:
    A, B, C, D = map(int, input().split())
    check += 1
    if A >= B or B * 2 == C + D:
        print('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])
        init_A = A
        init_D = D
        A_list = []
        flag = False
        while True:
            if A in A_list:
                flag = True
                break
            A_list.extend([A])
            if len(A_list) > init_A + init_D:
                flag = True
                break
            if A < B:
                break
            q, A = divmod(A, B)
            for i in range(q-1):
                if A + B > C:
                    break
                A += B
            A_list.extend([A + B])
            if A <= C:
                A = A + D
        if flag:
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
t=int(input())
for i in range(t):
    a,b,c,d = list(map(int,input().split()))
    st = []
    if a-b > 0 and c>=b and d >=b:
        print('Yes')
        break
        
    if a > c*100:    
        if a-b > c:
            a = a%b
            while a<=c:
                a+=b
    if d > c*100:
        if d-b>c:
            d = d%b
            while d<=c:
                d+=b

    while True:
        if a-b < 0:
            print('No')
            break
        
        a -= b
        if a <= c:
            a += d
        if a in st:
            print('Yes')
            break
        st.append(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

# stdin = open('sample.txt')

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

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


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


if __name__ == '__main__':
    main()

Submission status: 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:
        print("No") #そもそも買えないか、毎日補充したとしてもやがて足りなくなる
    else:
        if A%B > C: 
            print("No") #いつか、「補充基準以上だが買う数よりは少ない」状況となる
        else:
            if D%B == 0:
                print("Yes") #補充される前後で在庫の剰余は変わらないのでsustainable
            else:
                if A%B + (D%B)* (-(-(C-(A%B))//(D%B))) == C: #D%BずつA%Bに足していって、Cと等しくなってしまうとそこで止まってしまうからもう一回足す
                    if A%B + (D%B)* ((-(-(C-(A%B))//(D%B)))+1) >= B:
                        print("Yes")
                    else:
                        print("No")
                else:
                    if A%B + (D%B)* (-(-(C-(A%B))//(D%B))) >= B:
                        print("Yes")
                    else:
                        print("No")

Submission status: Wrong Answer

Solution code:
from sys import stdin

# stdin = open('sample.txt')

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

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


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


if __name__ == '__main__':
    main()

Submission status: 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:
            return 'No'
        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 d % (b - c) == 0:
                return 'Yes'
            else:
                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:
# Q_B
import math
T = int(input())
A, B, C, D = [0 for i in range(T)], [0 for i in range(T)], [0 for i in range(T)], [0 for i in range(T)]
for i in range(T):
    A[i], B[i], C[i], D[i] =  list(map(int, input().split()))

def judge(a, b, c, d):

    if a < b: # そもそも初日から買えない
        return "No"
    
    Seq = []
    n = (a - c)  //  b # 初期のあたりをつける
    z = a - n*b
    if z <= c:
        z += c
#    z = a　- n * b
    Seq.append(z)
#    print('in z=', z, " n=", n )
    cnt = 0
    re = "No"
    while z >= b:
        z -= b
        if z <= c:
            z += d
        cnt += 1
        if z in Seq:
            re = "Yes"
            break
        if z == a:
            re = "Yes"
            break
        # 大きい数対策
        n = (z - c) // b
        z = z - n * b
#        print('z=', z, " n=", n )
        if z <= c:
            z += d
            
        if z in Seq:
            re = "Yes"
            break
        else:
            Seq.append(z)
    return re

for i in range(T):
    print(judge(A[i], B[i], C[i], D[i]))

Submission status: Wrong Answer

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

Submission status: 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 > C:
		init = C + ((A - C) % B)
		if init != C:
			init -= B
		if init < 0:
			print("No")
			continue
	else:
		init = A

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

	dif = (D - B)
	if dif == 0:
		print("Yes")
		continue
	g = gcd(B,dif)
	if g == 1 or (C + dif < B):
		print("No")

	else:
		print("Yes")

Submission status: Wrong Answer

Solution code:
class query:
    def __init__(self, a, b, c, d):
        self.a = a
        self.b = b
        self.c = c
        self.d = d
    def isEternal(self):
        if self.a < self.b:
            return "No"
        ab = self.a % self.b
        if ab > self.c:
            return "No"
        if self.d < self.b:
            return "No"
        d = self.b - self.c
        if d <= 0:
            return "Yes"
        if self.b % d == 0 and self.d % d == 0:
            return "Yes"
        db = self.d % self.b
        if db == 0:
            return "Yes"
        q, r = divmod((self.c - ab), db)
        q += 1 if r != 0 else 0
        if q * db < self.b - ab:
            return "No"
        return "Yes"

if __name__ == "__main__":
    t = int(input())
    querys = [query(*[int(s) for s in input().split()]) for _ in range(t)]
    for q in querys:
        print(q.isEternal())

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-1<=C:
        print("Yes")
        return
    else:
        x=A%B
        y=D%B
        

        z=gcd(B,D)

        if z==1 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)