Problem:


Score : 600 points

Problem Statement

Ringo Mart, a convenience store, sells apple juice.

On the opening day of Ringo Mart, there were A cans of juice in stock in the morning.
Snuke buys B cans of juice here every day in the daytime.
Then, the manager checks the number of cans of juice remaining in stock every night.
If there are C or less cans, D new cans will be added to the stock by the next morning.

Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them.
Nobody besides Snuke buy juice at this store.

Note that each test case in this problem consists of T queries.

Constraints

1 \leq T \leq 300

1 \leq A, B, C, D \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T

In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.

Output

Print T lines. The i-th line should contain Yes if Snuke can buy apple juice indefinitely in the i-th query; No otherwise.

Sample Input 1

14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985

Sample Output 1

No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes

In the first query, the number of cans of juice in stock changes as follows: (D represents daytime and N represents night.)

9
→D 2
→N 11
→D 4
→N 13
→D 6
→N 6
→D x

In the second query, the number of cans of juice in stock changes as follows:

9
→D 2
→N 11
→D 4
→N 13
→D 6
→N 15
→D 8
→N 8
→D 1
→N 10
→D 3
→N 12
→D 5
→N 14
→D 7
→N 7
→D 0
→N 9
→D 2
→N 11
→D …

and so on, thus Snuke can buy juice indefinitely.

Sample Input 2

24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1

Sample Output 2

No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No



Sample input:
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985


Sample output:
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes

Submission status: Wrong Answer

Solution code:
T = int(input())
A = 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 A[i]%B[i] < C[i]:
        print("Yes")
    else:
        print("No")

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 )) // (d - b) != (c - ( a % b ) + 1) // (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())
for _ in range(T):
    a,b,c,d=map(int, input().split())
    if a<b or b>d: print("No")
    elif b<=c+1: print("Yes")
    elif a%b>c: print("No")
    elif 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:
aa=int(input())
N=[0 for i in range(aa)]
for i in range(aa):
  bb=input()
  #print(b)
  N[i]=bb.split()


for i in range(aa):
  for j in range(4):
    N[i][j]=int(N[i][j])


for i in range(aa):

  a=N[i][0]
  b=N[i][1]
  c=N[i][2]
  d=N[i][3]

  e=a-a//b*b
  f=d-d//b*b
  

  h=0 #YES=0 NO=1
  if f!=0 :
    while e<b:
      if e>c :
        h=1
      e+=f
      #print(e)
      #print(f)
#print("while")
  else:
    if e>c :
      h=1
      e+=f

  if a<b:
    h=1

  if h==1:
    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[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(100):
            if yoru[-1] <= query[2]:
                hiru.append(yoru[-1] + query[3])
                yoru.append(hiru[-1]%query[1])
            else:
                hiru.append(yoru[-1])
                yoru.append(hiru[-1] - query[1])
                
        if min(yoru) < 0:
            res[cnt] = 'No'
for i in range(T):
    print(res[i])

Submission status: Wrong Answer

Solution code:

def main():
    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)


    for i in range(t):

        if A[i] < B[i] or B[i] > D[i]:
            print("No")
            continue

        if B[i]-1 <= C[i]:
            print("Yes")
            continue

        lst = []
        for j in range(B[i]):
            tmp = (A[i] + (j*D[i])) % B[i]

            if tmp > C[i]:
                print("No")
                break

            if tmp in lst:
                break

            lst.append(tmp)

        print("Yes")


if __name__ == "__main__":
        main()

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:
        done = False
        start = (c-min_n) // dif
        for i in range(min_n + start*dif, b, dif):
            if b > i > c:
                no()
                done = True
                break
        if done:
            continue
    yes()

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:
        return 'No'

    if D < B:
        return 'No'

    if C >= B:

        return 'Yes'

    if D % B == 0 and A % B <= C:

        return 'Yes'
    elif D % B == 0:
        return 'No'

    if A % B <= C:
        pass
    else:
        return 'No'

    if C % (D % B) == 0:
        return 'Yes'
    else:
        return 'No'


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

    return '\n'.join(a)


def main():

    # for i in range(10000):
    #     print(i)
    #     a = random.randint(1, 1000)
    #     b = random.randint(1, 1000)
    #     c = random.randint(1, 1000)
    #     d = random.randint(1, 1000)
    #     # a = 686
    #     # b = 387
    #     # c = 286
    #     # d = 388
    #     a = 732
    #     b = 582
    #     c = 213
    #     d = 781

    #     if slv2(a, b, c, d) != slv3(a, b, c, d):
    #         print(a, b, c, d)
    #         return

    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())
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(100):
            if yoru[-1] <= query[2]:
                hiru.append(yoru[-1] + query[3])
                yoru.append(hiru[-1]%query[1])
            else:
                hiru.append(yoru[-1])
                yoru.append(hiru[-1] - query[1])
                
        if min(yoru) < 0:
            res[cnt] = '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:
        done = False
        start = (c-min_n) // dif
        for i in range(min_n + start*dif, b, dif):
            if b > i > c:
                no()
                done = True
                break
        if done:
            continue
    yes()

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:
			if A <= C:
				print(Y)
			else:
				print(N)
		elif 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:

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

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:
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"
        if self.a % self.b > 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"
        if self.d % self.b == 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:
T = int(input())
ABCD = [ list(map(int,input().split())) for _ in range(T)]
import fractions

def check(a,b,c,d):
    if b > d or a < b:
        print("No")
        return
    elif c >= b:
        print("Yes")
        return
    def_a = a % b
    a = def_a
    while True:
        a = (a + d) % b
        if a > c:
            print("No")
            return
        g = fractions.gcd(b,d)
        f = (b -a) // g
        if (b - a) % g == 0:
            f -= 1
        if g == 0 or c <= a + f * g:
            print("Yes")
            return
        print("No")
        return

for abcd in ABCD:
    check(abcd[0],abcd[1],abcd[2],abcd[3])

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

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout

t = int(stdin.readline())
for i in range(t):
    a, b, c, d = map(int, stdin.readline().split())
    
    if d < b:
        stdout.write('No\n')
        continue
    
    l, r = 0, a + 1
    while r - l > 1:
        m = (l + r) >> 1
        
        if a - m * b > c:
            l = m
        else:
            r = m
    
    if a - r * b < 0:
        stdout.write('No\n')
        continue
    
    cur = a - r * b
    
    if d == b:
        stdout.write('Yes\n')
        continue
    
    for j in range(10000):
        cur = cur + (d - b) * ((c + 1 - cur + (d - b - 1)) // (d - b))
        cur -= b
        
        if cur < 0:
            stdout.write('No\n')
            break
    else:
        stdout.write('Yes\n')

Submission status: Wrong Answer

Solution code:
def judge(a,b,c,d):
    if a >= b:
        if   ( b<= c+1 and b<= d)  \
          or ( b>c and (d%b ==0 or (b%2==0 and d%2==0 and b-c <=2 ) ) 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:
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]<0:
      print('No') #買えてない
      break;
    if Query[i][0]<=Query[i][2]: #夜
      Query[i][0]+=Query[i][3]
    count+=1
    if count==200:
      print('Yes')
      break;

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 B%2 == 0 and D%2 == 0: #補充される数と買う数がともに偶数の時、剰余は偶数増える
                    if C+2 < B:
                        print("No")
                    else:
                        print("Yes")
                else:
                    if C+1 < B:
                        print("No")
                    else:
                        print("Yes")

Submission status: Wrong Answer

Solution code:
import fractions 
n=int(input())
for _ in range(n):
    a,b,c,d=map(int,input().split())
    if d<b:
        print("No")
        continue
    elif a<b:
        print("No")
        continue
    elif c<=b:
        print("Yes")
        continue
    g=fractions.gcd(b,d)
    h=((b-1-a%b)//g)*g
    if a%b+h>c:
        print("No")
        continue
    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])
    asa = A

    if (A - 3*B + 2*D) == C:
        print("Yes")
    else:
        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]:
      print('No')
      break;
    Query[i][0]=Query[i][0]-Query[i][1] #昼
    if Query[i][0]<0:
      print('No') #買えてない
      break;
    if Query[i][0]<=Query[i][2]: #夜
      Query[i][0]+=Query[i][3]
    count+=1
    if count==40:
      print('Yes')
      break;

Submission status: Wrong Answer

Solution code:
def judge(a,b,c,d):
    if a >= b:
        if   ( b<= c+1 and b<= d)  \
          or ( b>c and (d%b ==0 or (b%2==0 and d%2==0 and b-c <=2 ) ) 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:
T = int(input())
A = list()
B = list()
C = list()
D = list()
for i in range(T):
    K = list(map(int, input().split()))
    A,B,C,D = K

for i in range(T):
    if D >= B and A%B < C:
        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 (d-c)%2 == 1 or a%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())
abcd=[list(map(int, input().split())) for _ in range(t)]
a=[abcd[i][0] for i in range(t)]
b=[abcd[i][1] for i in range(t)]
c=[abcd[i][2] for i in range(t)]
d=[abcd[i][3] for i in range(t)]
for i in range(t):
    if b[i]>d[i] or b[i]>a[i]:
        j='No'
    elif b[i]==d[i]:
        if ((a[i]-b[i])%d[i])>c[i] and ((a[i]-b[i])%d[i])<b[i]:
            j='No'
        else:
            j='Yes'
    else:
        if (2*b[i]-a[i])%(d[i]-b[i])==0:
            t=b[i]-(2*b[i]-a[i])%(d[i]-b[i])-(d[i]-b[i])
        else:
            t=b[i]-(2*b[i]-a[i])%(d[i]-b[i])
        if t>c[i]:
            j='No'
        else:
            j='Yes'    
    print(j)

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=b*(a//b)
        sabun=d-b*(d//b)
        if sabun==0:
            print('Yes')
            continue
        z=sabun*(b//sabun+1)-b
        if z!=0 and z<b-c:
            print('No')
        else:
            print('Yes')

Submission status: Wrong Answer

Solution code:
import fractions 
n=int(input())
for _ in range(n):
    a,b,c,d=map(int,input().split())
    if d<b:
        print("No")
        continue
    elif a<b:
        print("No")
        continue
    g=fractions.gcd(b,d)
    h=int((b-1-a%b)/g)*g
    if a%b+h>c:
        print("No")
        continue
    print("Yes")

Submission status: Wrong Answer

Solution code:
t = int(input())

for _ in range(t):
    a, b, c, d = map(int, input().split())
    cond = True
    
    if a < b or b > d or (a % b) > c:
        cond = False
    
    
    if b != d:
        if (b - c) > (d - b):
            cond = False
            
        tmp = (((c - (a % b)) // (d - b)) + 1) * (d - b) +  (a % b)
        if tmp > c and tmp < b:
            cond = False
    
        
    if cond:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
#B
import math
T=int(input())
for i in range(T):
    A,B,C,D=map(int,input().split())
    A_list=[]
    while True:
        k=math.ceil((A-C)/B) if A>=C else 1
        A-=k*B
        if A<0:
            print('No')
            break
        elif A<=C:
            A+=D
            if A in A_list:
                print('Yes')
                break
            A_list.append(A)

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]:
		print("No")
	else:
		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]
			pp %= b[1]
			if pp < b[1] and b[2] < pp:
				print("No")
				break

		
	c = []

Submission status: Wrong Answer

Solution code:
#B
import math
T=int(input())
for i in range(T):
    A,B,C,D=map(int,input().split())
    A_list=[]
    while True:
        k=math.ceil((A-C)/B) if A>=C else 1
        print(A,B,C,D)
        A-=k*B
        print(A)
        if A<0:
            print('No')
            break
        elif A<=C:
            A+=D
            if A in A_list:
                print('Yes')
                break
            A_list.append(A)

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    result = 0
    line = input().split()
    if int(line[0])//int(line[1])>=1 and int(line[0])%int(line[1])<=int(line[2]) and (int(line[0])%int(line[1])+int(line[3]))-int(line[1])>=0:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
        return a
T = int(input())
for _ in range(T):
    A,B,C,D = map(int,input().split())
    if A < B or D < B:
        print('No')
    else:
        g = gcd(B,D)
        k = B//g
        r = (A-C)%B
        if r == 0:
            sm = C
        else:
            sm = C+r-B
        if sm < 0:
            print('No')
        else:
            s = sm%g
            if s + (k-1)*g <= C:
                print('Yes')
            else:
                print('No')

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
for _ in range(n):
    a,b,c,d=map(int,input().split())
    if d<b:
        print("No")
        continue
    elif a<b:
        print("No")
        continue
    g=1
    h=1
    if 1+h>c:
        print("No")
        continue
    print("Yes")

Submission status: Wrong Answer

Solution code:
t = int(input())
for i in range(t):
    a, b, c, d = map(int, input().split())
    rec = [a]
    flag = False
    num = 0
    while True and num < 1000:
        if a < b:
            break
        else:
            a = a % b
        if a <= c:
            a += d
        if a in rec:
            flag = True
            break
        num += 1
        rec.append(a)
    if flag:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
for _ in range(n):
    a,b,c,d=map(int,input().split())
    if d<b:
        print("No")
        continue
    elif a<b:
        print("No")
        continue
   
    print("Yes")

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(10000):
        if d < b:
            is_ok = False
            break
        
        if _a - b > c:
            _a = _a - (((_a - c) // b) - 1) * b
        _a = _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:
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"
        if self.a % self.b > 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"
        if self.a % self.b + self.d == self.a:
            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:
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:
        if (b - c) > (d - b):
            cond = False
            
        if (b - 1) > c and ((b - 1) - (a % b)) % (d - b) == 0:
                cond = False
    
        
    if cond:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import numpy as np

def check(a,b,c,d,z_list):
    z = a
    ans = 'Yes'
    if a < b:
        ans = 'No'
        return ans,z_list
    z_list = [z] + z_list
    for k in range(10000000):
        x = (z - c)//b
        if x <= 0:
            x = 1
        z = z - b * x
        if z < 0:
            ans = 'No'
            break
        if z <= c:
            z += d
        
        if z in z_list:
            ans = 'Yes'
            break
        z_list.append(z)
#         print(z)
    return ans,z_list
def check_rec(rec,cd):
    z_list = []
    c = cd[0]
    d = cd[1]
    for k,cd in enumerate(rec[0][::-1]):
        if [c,d] == cd:
            z_list += (rec[1][k])
            break
    return z_list


t = int(input())
a = []
b = []
c = []
d = []
for k in range(t):
    aa,bb,cc,dd = list(map(int,input().split()))
    a.append(aa)
    b.append(bb)
    c.append(cc)
    d.append(dd)

aa = a
bb = b
cc = c
dd = d

cd_rec = []
z_rec  = []
ans_rec = []
rec = [[],[]]
for a,b,c,d in zip(aa,bb,cc,dd):
    
    z_list = check_rec(rec, [c,d])
    ans,z_list = check(a,b,c,d,z_list)
    rec[0].append([c,d])
    rec[1].append(z_list)

    print(ans)

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:
import numpy as np

def check(a,b,c,d,z_list):
    z = a
    ans = 'Yes'
    if a < b:
        ans = 'No'
        return ans,z_list
    z_list = [z] + z_list
    for k in range(100):
        x = (z - c)//b
        if x <= 0:
            x = 1
        z = z - b * x
        if z < 0:
            ans = 'No'
            break
        if z <= c:
            z += d
        
        if z in z_list:
            ans = 'Yes'
            break
        z_list.append(z)
#         print(z)
    return ans,z_list
def check_rec(rec,cd):
    z_list = []
    c = cd[0]
    d = cd[1]
    for k,cd in enumerate(rec[0][::-1]):
        if [c,d] == cd:
            z_list += (rec[1][k])
            break
    return z_list


t = int(input())
a = []
b = []
c = []
d = []
for k in range(t):
    aa,bb,cc,dd = list(map(int,input().split()))
    a.append(aa)
    b.append(bb)
    c.append(cc)
    d.append(dd)

aa = a
bb = b
cc = c
dd = d

cd_rec = []
z_rec  = []
ans_rec = []
rec = [[],[]]
for a,b,c,d in zip(aa,bb,cc,dd):
    
    z_list = check_rec(rec, [c,d])
    ans,z_list = check(a,b,c,d,z_list)
    rec[0].append([c,d])
    rec[1].append(z_list)

    print(ans)

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
  
  A = A % B + B
  Zaiko = A
  lista = []
  ZaikoMin = 10 ** 18
  i = 0
  while(i < 100):
    Zaiko = Zaiko - B
    #print(Zaiko)
    if(Zaiko < 0):
      print("No")
      break
    if(Zaiko <= C):
      Zaiko += D
      Zaiko = Zaiko % B + B
    if(Zaiko in lista or Zaiko > ZaikoMin):
      print("Yes")
      break
    lista.append(Zaiko)
    ZaikoMin = min(Zaiko, ZaikoMin)
    i += 1
    if(i == 100):
      print("Yes")
  #print(A,B,C,D)

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


@mt
def slv(T, Q):

    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'

        if D % B == 0 and A % B <= C:
            return 'Yes'
        elif D % B == 0:
            return 'No'

        if C % (D % B) == 0:
            return 'Yes'
        else:
            return 'No'

    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:
n = int(input())
for i in range(n):
    result = 0
    line = input().split()
    if int(line[0])%int(line[1])<=int(line[2]) and (int(line[0])%int(line[1])+int(line[3]))-int(line[1])>=0:
        print("Yes")
    else:
        print("No")