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:
from fractions import gcd
T = int(input())
for i in range(T):
    A, B, C, D = map(int, input().split())

    # 初日でケーキが買えない
    if B > A:
        print("No")
        continue

    # 毎日補充できても足りなくなる
    if B > D:
        print("No")
        continue

    # 買切る前に必ず入荷が発生する
    if C >= B:
        print("Yes")

    if B - gcd(B, D) + (A % gcd(B, D)) <= C:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
def findGCD(a,b):
    if a%b == 0:
        return b
    else:
        return findGCD(b,a%b)


def judge(a,b,c,d):
    if a<b or d<b:
        return False
    elif c >= b:
        return True
    else:
        g = findGCD(b,d)
        thr = b-g+a%g
        if thr > c:
            return False
        else:
            return True
        
T = int(input())
ABCD = []
for i in range(T):
    ABCD.append(list(map(int, input().split())))
        
for a,b,c,d in ABCD:
    if judge(a,b,c,d):
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

Solution code:
# coding:utf-8

def _gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a


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

  delta = d - b

  if delta < 0:
    print("No")
    continue

  b2 = b - c

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

  if b2 <= 1:
    print("Yes")
    continue

  pos = ((a-c)%b)

  if delta == 0:
    if pos > 0 and pos < b2:
      print("No")
      continue
    else:
      print("Yes")
      continue

  gcd = _gcd(b, delta)

  if gcd == 1:
    print("No")
    continue

  pos_mod = pos%gcd
  if pos_mod > 0 and pos_mod < b2:
    print("No")
    continue
  print("Yes")

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
	while y:
		x, y = x, x % y
	return x

t = int(input())
a = []
d = 0
for i in range(t):
  a.append(list(map(int,input().split())))
for j in a:
  if j[0] < j[1] or j[1] > j[3]:
    print("No")
  else:
    b = j[0] % j[1]
    k = gcd(j[1],j[3])
    c = j[2] % k
    if b > c:
      d = j[2] + k + c - b
    else:
      d = j[2] + c - b
    if b > d:
      print("No")
    else:
      print("Yes")

Submission status: Wrong Answer

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

def solve():
    a, b, c, d = map(int, input().split())
    if c >= b:return "Yes"
    g = gcd(d, b)
    a %= b
    if((c-a) // g != (b-a-1) // g):return "No"
    else: return "Yes"


for _ in range(int(input())):
    print (solve())

Submission status: Wrong Answer

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

def solve():
    a, b, c, d = map(int, input().split())
    if c >= b:return "Yes"
    g = gcd(d, b)
    a %= b
    if((c-a+1) // g != (b-a-1) // g):return "Yes"
    else: return "No"


for _ in range(int(input())):
    print (solve())

Submission status: Wrong Answer

Solution code:
def gcd(m, n):
    if m < n:
        m, n = n, m
    return m if n == 0 else gcd(n, m % n)


def judge(a, b, c, d):
    if a < b or b > d:
        return False

    else:
        m = a - (a // b) * b

        if m > c:
            return False

        else:
            if b == d:
                return True
            else:
                i = m % gcd(d - b, b)
                m = (d - b) * (1 + c // (d - b))
                if m + i < b:
                    return False
                else:
                    return True




def run():
    T = int(input())

    for _ in range(T):
        A, B, C, D = (int(x) for x in input().split())

        if judge(A, B, C, D):
            print("Yes")
        else:
            print("No")

if __name__ == '__main__':
    run()

Submission status: Wrong Answer

Solution code:
def judge(a, b, c, d):
    if a < b or b > d:
        return False

    else:
        m = a - (a // b) * b

        if m > c:
            return False

        else:
            if b == d:
                return True
            else:
                m = (d - b) * (1 + c // (d - b))
                if m < b:
                    return False
                else:
                    return True




def run():
    T = int(input())

    for _ in range(T):
        A, B, C, D = (int(x) for x in input().split())

        if judge(A, B, C, D):
            print("Yes")
        else:
            print("No")

if __name__ == '__main__':
    run()

Submission status: Wrong Answer

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

from math import ceil

def solve(A, B, C, D):
    if A < B or D < B: return False
    if A % B > C: return False

    if D % B == 0: return True
    x = (C - (A % B)) // (D % B) + 1
    if (A + x * (D % B)) % B > C: return False
    return True


T = int(input())
for i in range(T):
    A, B, C, D = [int(t) for t in input().split()]
    print('Yes' if solve(A, B, C, D) else 'No')

Submission status: Wrong Answer

Solution code:
# 最小公倍数
def gcd(a, b):
    while a % b:
        a, b = b, a % b
    return b

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 = gcd(c[i][3],c[i][1])
    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 :
            if c[i][1] - c[i][2] > 1 and c[i][2] < mem1 < c[i][1]:
                print("No")    
                break;
            else :
                print("Yes")
                break;
        elif c[i][1] - c[i][2] == 1 :
            print("Yes")
            break;
        elif  mem3 < (mem1 % mem3) + c[i][1] - c[i][2]:
            print("No")
            break;
        elif mem2 % 2 == 1 and c[i][1] - c[i][2] > 1:
            print("No")  
            break;          
        else :
            print("Yes")
            break;

Submission status: Wrong Answer

Solution code:
T=int(input())
A=[]
B=[]
C=[]
D=[]
for i in range(T):
  AA,BB,CC,DD=list(map(int,input().split()))
  A.append(AA)
  B.append(BB)
  C.append(CC)
  D.append(DD)
for i in range(T):
  if B[i]<=D[i]:
    if A[i]-B[i]>=0:
      if A[i]%B[i]<=C[i]:
        print("Yes")
        continue
  print("No")

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 d % b == 0:
        print('Yes')
        continue
    if c < ((a % b) + (d % b)) % b:
        print('No')
        continue
    if d % b - ((c - (a%b))%(d%b)) + c < b:
        print('No')
        continue
    if ((d % b - ((c - (a%b))%(d%b)) + c)) % b == 0 or \
    ((d % b - ((c - (a%b))%(d%b)) + c)) % b % (d%b) == 0:
        print('Yes')
        continue
    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()))
	if A < B:
		print("No")
	else:
		if D < B:
			print("No")
		else:
			if C >= B:
				print("Yes")
			else:
				x = A % B
				y = D % B
				z = B
				if y == 0:
					if x > C:
						print("No")
					else:
						print("Yes")
				else:
					if x > C:
						print("No")
					else:
						if ((C - x) // y + 1) * y < z - x:
							print("No")
						else:
							print("Yes")

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[1] > query[0]:
        res[cnt] = 'No'
    elif query[1] > query[3]:
        res[cnt] = 'No'
    elif query[2] >= query[1]:
        pass
    elif 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:
# -*- coding: utf-8 -*-
from itertools import combinations
def inpl(): return map(int, input().split())

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

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

Submission status: Wrong Answer

Solution code:


import math

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


def gcd(a, b):

	while b:

		a, b = b, a % b

	return a


#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=gcd(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
      if ss==b:
        ss-=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:
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 or c>=b:
            res.append('Yes')
        else:
            m = (c-a%b)//(d-b)+1
            k = a%b+m*(d-b)
            if c<k<b:
                res.append('No')
            else:
                res.append('Yes')
for j in range(t):
    print(res[j])

Submission status: Wrong Answer

Solution code:
from math import floor
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
T = int(input())
for i in range(T):
    A,B,C,D = map(int,input().split())
    if B > D or B > A:
        print("No")
    else:
        if A%B>C:
            print("No")
        else:
            d = gcd(B,D%B)
            r = A%B
            if r%d == 0:
                if B-d > C:
                    print("No")
                else:
                    print("Yes")
            else:
                if r+floor((B-r)/d) > C:
                    print("No")
                else:
                    print("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

        if B > A:
            print('No')
            continue
        if B > D:
            print('No')
        if C > D:
            print('Yes')


        while True:
            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 += D
        if flag:
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
from math import floor
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
T = int(input())
for i in range(T):
    A,B,C,D = map(int,input().split())
    if B > D:
        print("No")
    else:
        if A%B>C:
            print("No")
        else:
            d = gcd(B,D%B)
            r = A%B
            if r%d == 0:
                if B-D > C:
                    print("No")
                else:
                    print("Yes")
            else:
                if r+floor((B-r)/d) > C:
                    print("No")
                else:
                    print("Yes")

Submission status: Wrong Answer

Solution code:
t = int(input())
a = []
b = []
c = []
d = []
for i in range(t):
    tmp = list(map(int, input().split(" ")))
    a.append(tmp[0])
    b.append(tmp[1])
    c.append(tmp[2])
    d.append(tmp[3])

for i in range(t):
    if(a[i] < b[i]): print("No")
    elif(b[i] > d[i]): print("No")
    elif(b[i] <= c[i]): print("Yes")
    else:
        remain = a[i] - (a[i] // b[i]) * b[i]
        increase = d[i] - b[i]
        if(increase == 0):
            if(c[i] >= remain): print("Yes")
            elif(b[i] > remain): print("No")
            else: print("Yes")
        else:
            if(c[i] >= remain): remain += ((c[i] - remain) // increase) * increase
            if(c[i] >= remain): remain += increase
            if(remain < b[i]):
                print("No")
                continue

            history = [remain]
            remain -= b[i]
            if(c[i] >= remain): remain += ((c[i] - remain) // increase) * increase
            if(c[i] >= remain): remain += increase
            if(remain < b[i]):
                print("No")
                continue
            
            history.append(remain)
            sa = history[1] - history[0]
            if(sa <= 0):
                print("Yes")
                continue
            remain -= ((remain - c[i]) // sa) * sa
            if(c[i] >= remain): remain += sa
            if(remain < b[i]):
                print("No")
            else: print("Yes")

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 d % b == 0:
        print('Yes')
        continue
    if c < ((a % b) + (d % b)) % b:
        print('No')
        continue
    if d % b - ((c - (a%b))%(d%b)) + c < b:
        print('No')
        continue
    if (d % b - ((c - (a%b))%(d%b)) + c) % b != a % b:
        print('No')
        continue
    print('Yes')

Submission status: Wrong Answer

Solution code:
import math
t = int(input())
for i in range(t):
  a,b,c,d = [int(x) for x in input().split()]
  if a < b or b > d:
    print("No")
    continue
  elif b == d:
    if a%b <= c:
      print("Yes")
    else:
      print("No")
    continue
  else:
    if b <= c:
      print("Yes")
      continue
    else:
      l =[]
      tmp = a
      buf = math.ceil(c/b)*b-b
      first = tmp % b + buf
      second = first % b + buf
      if first > c or second > c:
        print("No")
      if first == second:
        print("Yes")
      else:
        dif = second -first
        if (c - first)%dif == 0:
          print("YES")
        else:
          print("No")

Submission status: Wrong Answer

Solution code:
T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    s, b, c, d = r[0], r[1], r[2], r[3]
    s_list = []
    while True:
        if (s < b) or (b>d):
            print('No')
            break
        if (c>s):
            print('Yes')
        s = s%b
        s_list.append(s)
        if c < s < b:
            print('No')
            break

        s = s+d
        if s in s_list:
            print('Yes')
            break
        s_list.append(s)

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 - A % b + 2 * 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:
a = int(input())
c = []
for i in range(a):
	b = list(map(int,input().split()))
	if ((b[0] % b[1] == 0 and b[1] <= b[2]) and b[1] != 1 )or b[0] < b[1] or b[1] > b[3]:
		print("No")
	else:
		if b[0] - b[1] != 0:
			ab = b[0] - b[1]
		'''
		pp = b[0] % b[1]
		while(1):
			if pp  < 0:
				print("No")
				break
			elif pp in c:
				print("Yes")
				break
			else:
				c.append(pp)
			if pp <= b[2]:
				pp += b[3]
			if pp // b[1] <= 0:
				pp -= b[1]
			else:
				pp %= b[1]
			'''
		pp = b[1] // ab

		if pp*ab in c:
			print("Yes")
			break
		elif pp*ab <= b[2]:
			c.append(pp*ab)
			b[0] = b[2] - pp*ab
		elif pp*ab > b[2]:
			print("No")
			break


	c = []

Submission status: Wrong Answer

Solution code:
T = int(input())

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

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

    if b <= c:
        if b <= d:
            print("Yes")
            continue
        else:
            if a % b + b < c:
                print("Yes")
                continue
            else:
                print("No")
                continue
    else:
        if b == d:
            if a%b <= c:
                print("Yes")
                continue
            else:
                print("No")
                continue
        elif b > d:
            print("No")
            continue
        parity_buy = (b % 2 == 0)
        parity_charge = (d % 2 == 0)

        cand = [i for i in range(c+1, b)]

        if parity_buy and parity_charge:
            a_even = (a % 2) == 0
            if a_even:
                cand = list(filter(lambda x: x % 2 == 0, cand))
            else:
                cand = list(filter(lambda x: x % 2 == 1, cand))

        if len(cand) != 0 and a%b > c:
            print("No")
            continue
        else:
            print("Yes")
            continue

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 c<k<b:
                res.append('No')
            else:
                res.append('Yes')
for j in range(t):
    print(res[j])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
t = int(input())
a=[]
b=[]
c=[]
d=[]
for i in range(t):
	e,f,g,h = map(int,input().split())
	a.append(e)
	b.append(f)
	c.append(g)
	d.append(h)

for i in range(t):
	if(b[i] == c[i] +1):
		print("Yes")

	elif(a[i] < b[i] or  (d[i] % b[i]) != 0):
		print("No")
	else:
		print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000)

T = int(input())
A = []
B = []
C = []
D = []

def bin_search(n,lst):
    l=0
    r=len(lst)

    while r-1>=l:
        i=(l+r)//2
        if lst[i]==n: return True,i
        elif lst[i]<n: l=i+1
        else: r=i
    return False,-1

def dfs(a,b,c,d):
    if a < b: return False
    else:
        memo.append(a)
        memo.sort()
        a -= b
        flg, idx = bin_search(a,memo)
        memo.append(a)
        if flg:
            return True
        elif a <= c:
            a += d
            memo.append(a)
            dfs(a,b,c,d)
        else:
            dfs(a,b,c,d)

memo = []
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)

for i in range(T):
    if A[i] < C[i]:
        if dfs(A[i],B[i],C[i],D[i]): print("Yes")
        else: print("No")

    else:
        a = A[i] - int((A[i] - C[i])/B[i])*B[i]
        if dfs(a,B[i],C[i],D[i]): print("Yes")
        else: print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def slv3(A, B, C, D):
    # error_print(A, B, C, D)
    if A < B:
        # error_print('A')
        return 'No'

    if D < B:
        # error_print('D')
        return 'No'

    if C >= B:
        return 'Yes'

    s = set([])
    while True:
        # error_print(A)
        if A in s:
            error_print('Yes')
            return 'Yes'
        s.add(A)
        if A < B:
            error_print('No')
            return 'No'

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

    return 'Yes'


def slv2(A, B, C, D):
        # error_print(A, B, C, D)
    if A < B:
        # error_print('A')
        return 'No'

    if D < B:
        # error_print('D')
        return 'No'

    if C >= B:
        return 'Yes'

    s = set([])
    m = D % B
    if m == 0:
        m = B
    while True:
        # error_print(A)
        if A in s:
            # error_print('Yes')
            return 'Yes'
        s.add(A)
        if A < B:
            # error_print('+No', A, B)
            return 'No'

        A %= B
        A += int(math.floor((C-A) / m)) * m + m
    return 'Yes'


@mt
def slv(T, Q):
    a = []
    for q in Q:
        a.append(slv2(*q))

    return '\n'.join(a)


def main():

    T = read_int()
    Q = [read_int_n() for _ in range(T)]
    print(slv(T, Q))


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

Submission status: Wrong Answer

Solution code:
T = int(input())

ABCD=[]
for _ in range(T):
    ABCD.append([int(x) for x in input().split()])


for A,B,C,D in ABCD:
    
    if A < B:
        print("No")
        continue
    
    if C > B:
        print("Yes")
        continue

    a = A - ((A - C)//B+1)*B

    dif = (D-B)%B

    if dif == 0:
        print("Yes")
        continue

    if dif>0:
        l=[]
        while True:
            
            a+=dif
            if C<a and a<B:
                print("No")
                break
            if a in l:
                print("Yes")
                break
            while a > C:
                a -= B
            l.append(a)
    else:
        a += B
        l=[]
        while True:
            a-=dif
            if C<a and a<B:
                print("No")
                break
            if a in l:
                print("Yes")
                break
            while a > C:
                a -= B
            l.append(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
li=[]
re=[]
for i in range(n):
	li.append(list(map(int,input().split())))
	if li[i][0] < li[i][1]:
		re.append("No")
	elif li[i][1] > li[i][3]:
		re.append("No")
	elif li[i][2] >=li[i][1]:
		re.append("Yes")
	else:
		Lim=li[i][0]%li[i][1]
		a=li[i][3]-li[i][1]
		if a == 0:
			pass
		elif (li[i][1]-Lim)%a == 0:
			m=(li[i][1]-Lim)//a-1
			Lim=Lim+m*a
		else:
			m=(li[i][1]-Lim)//a
			Lim=Lim+m*a
		if li[i][2] >= Lim:
			re.append("Yes")
		else:
			re.append("No")
for value in re:
 print(value)

Submission status: Wrong Answer

Solution code:
t = int(input())

for i in range(t):
  ai = list(map(int, input().split(" ")))
  stock = ai[0]
  while stock > ai[1]:
    stock -= ai[1]
    if stock < ai[2]:
      if stock + ai[3] < ai[1]:
          stock += ai[3]
      else:
        print("No")
        break
  print("Yes")

Submission status: Wrong Answer

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

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

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


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

    if A<B:
        print("No")
        return
    elif B>D:
        print("No")
        return
    elif B-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-1)%z or ( (C+1)%z>B%z and ((C+1)%z<=x%z or x%z<B%z) ):
            print("No")
            return

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python


def min_an(_, b, c, d):
    a = 0

    if b % (d - b) == 0:
        return (a % (d - b)) + (int(b / (d - b)) - 1) * (d - b)
    else:
        return (a % (d - b)) + int(b / (d - b)) * (d - b)


n = int(input().strip())

an = []
bn = []
cn = []
dn = []

for _ in range(n):
    a, b, c, d = map(int, input().strip().split(' '))
    an.append(a)
    bn.append(b)
    cn.append(c)
    dn.append(d)

for i in range(n):
    a, b, c, d = an[i], bn[i], cn[i], dn[i]

    if b == d:
        if a == b:
            print('Yes')
        else:
            print('No')
    else:
        if min_an(a, b, c, d) + b <= (b + c):
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
T = int(input())

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