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 = [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 < 1000:
        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 == 1000:
        print('Yes')

Submission status: Wrong Answer

Solution code:
def check(a,b,c,d):
	if a < b:
		print('No')
		return True
	if d < b:
		print('No')
		return True
	return False

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

for q in query:
	flg = True
	a = q[0]
	b = q[1]
	c = q[2]
	d = q[3]

	if check(a,b,c,d):
		continue

	if a % b > c % b:
		p = a % b + (c % b) * b
	else:
		p = a % b + (c % b - 1) * b

	if d % b > c % b:
		r = d % b + (c % b) * b
	else:
		r = d % b + (c % b - 1) * b

	for i in range(10):
		if (p + i*r) % b > c:
			print('No')
			flg = False
			break
	if flg:
		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 == 1 or a % 2 == 1 or d % 2 == 1 or c % 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:
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
        A_list = []
        flag = False
        
        if A < B:
            print('No')
            continue
        if B < C:
            print('Yes')
            continue
        while True:
            if A in A_list:
                flag = True
                break
            A_list.extend([A])
            if len(A_list) > 10000:
                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 _ 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:
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:
            tmp = remain
            if(c[i] >= remain): remain += ((c[i] - remain) // increase) * increase
            if(c[i] >= remain): remain += increase
            if(remain < b[i]): print("No")
            else:
                remain = tmp
                if(c[i] + b[i] >= remain): remain += ((c[i] + b[i] - remain) // increase) * increase
                if(c[i] + b[i] >= remain): remain += increase
                remain -= b[i]
                if(remain < b[i]): 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 == 1 or a % 2 == 1 or d % 2 == 1 or c % 2 == 1:
            if b - c > 1:
                return 'No'
        else:
            if d % (b - c) == 0:
                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:
import math

t = int(input())
q_list = []

for i in range(t):
  q_list.append(list(map(int, input().split())))

for a, b, c, d in q_list:
  rest = c - (a - b)
  delta = d - b

  if c + delta < b:
    print('No')
    continue
  else:
    print('Yes')

Submission status: Wrong Answer

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

for query in queries:
  stock, sunuke_num, threshold, add_num = query

  # そもそもダメなパターン
  if sunuke_num > add_num or stock < sunuke_num:
    print("No")
    continue

  # # 仕入直前まで在庫を減らす
  # stock %= sunuke_num

  # # これでもまだ閾値より高ければ、次のターンで確実に在庫不足に陥る
  # if stock > threshold:
  #   print("No")
  #   continue

  # # 仕入れ直前の購入後の値
  # preval = stock

  # # 在庫補充
  # stock += add_num

  # # 仕入後の購入後の値
  # postval = stock - sunuke_num

  # # 次ターン時点で在庫不足のパターン
  # if postval < 0:
  #   print("No")
  #   continue

  # # 仕入数と買ってく数が等しいパターン
  # if postval - preval == 0:
  #   print("Yes")
  #   continue

  # print("pre: {} post : {}".format(preval, postval))
  # tmp = postval - preval + threshold
  # if tmp >= sunuke_num:
  #   print("Yes")
  # else:
  #   print("No")

  is_zero = False
  for i in range(50):
    # 仕入直前まで在庫を減らす
    stock %= sunuke_num

    # これでもまだ閾値より高ければ、次のターンで確実に在庫不足に陥る
    if stock > threshold:
      break

    # 仕入れ直前の購入後の値
    preval = stock

    # 仕入後の購入後の値
    postval = stock + add_num - sunuke_num

    # 次ターン時点で在庫不足のパターン
    if postval < 0:
      break

    # 仕入数と買ってく数が等しいパターン
    if postval - preval == 0:
      is_zero = True
      break

    tmp = postval - preval + threshold
    if tmp >= sunuke_num:
      if stock == 0:
        is_zero = True
        break
      else:
        stock += add_num
    else:
      break

  if is_zero is True:
    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"
        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:
            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:
from math import ceil
T = int(input())
for i in range(T):
    A, B, C, D = map(int, input().split())
    if A < B:
        print("No")
        continue

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

    if D == B:
        if A <= B + C:
            print("Yes")
        else:
            print("No")
        continue

    X = ceil((B+C-A) / (D-B))
    Y = A + (D-B) * (X + (1 if X == (B+C-A) // (D-B) else 0))
    Z = Y - B
    #print(X, X == (B+C-A) // (D-B), Y)
    if Z > C:
        if Z < B:
            print("No")
        else:
            print("Yes")
    else:
        if X == (B+C-A) // (D-B):
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
T = int(input())						# 5



def solv(A, B, C, D):
	#b = (A<B)				#初回在庫が足りない
	#b = b or (D<B)			#補充が足りない
	#b = b or ((A % B) > C)	#補充前にアウト
	#if b: return False
	
	#力業で計算する
	if A>B : A = (A % B) + B			#初回量を適正化
	if D>B : D = (D % B) + B			#補充量を適正化
	
	z = A					#在庫数を初期化
	for i in range(100000):
		
		z -= B
		if (z<0): return False		#昼：在庫が足りなくてアウト
		
		
		if (z<=C): z+=D				#夜：在庫追加
	
	else:
		return True
	
	
	

for i in range (T):
	A, B, C, D = map(int, input().split())		# 5 7 2
	
	b = solv(A, B, C, D)
	
	ans = "Yes" if b else "No"
	print(ans)

Submission status: Wrong Answer

Solution code:
T = int(input())
for i in range(T):
    A, B, C, D = [int(i) for i in input().split()]

    memo = set()
    while True:
        if A in memo:
            print("Yes")
            break

        if A - B < 0:
            print("No")
            break

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

        if D - B < 0:
            print("No")
            break

        n = 1 + (C - A + B) // (D - B)
        r = (A - B) + n * (D - B)
        if r < B:
            print("No")
            break
        else:
            A = r % B
            memo.add(A)

    else:
        print("Yes")

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

    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:
from math import ceil
T = int(input())
for i in range(T):
    A, B, C, D = map(int, input().split())
    if A < B:
        print("No")
        continue

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

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

    if D == B:
        if A <= B + C:
            print("Yes")
        else:
            print("No")
        continue

    X = ceil((B+C-A) / (D-B))
    Y = A + (D-B) * (X + (1 if X == (B+C-A) // (D-B) else 0))
    Z = Y - B
    #print(X, X == (B+C-A) // (D-B), Y)
    if Z > C:
        if Z < B:
            print("No")
        else:
            print("Yes")
    else:
        if X == (B+C-A) // (D-B):
            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()))
  #print(a, b, c, d, b%c, gcd(c, d))
  if a<b or b>d or a%b>c:
    print("No")
  elif b==d:
    print("Yes")
  elif gcd(c, d)>=b%c:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
T = int(input())						# 5



def solv(A, B, C, D):
	#b = (A<B)				#初回在庫が足りない
	#b = b or (D<B)			#補充が足りない
	#b = b or ((A % B) > C)	#補充前にアウト
	#if b: return False
	
	#力業で計算する
	if A>B : A = (A % B) + B			#初回量を適正化
	if D>B : D = (D % B) + B			#補充量を適正化
	
	z = A					#在庫数を初期化
	for i in range(1000):
		
		z -= B
		if (z<0): return False		#昼：在庫が足りなくてアウト
		
		
		if (z<=C): z+=D				#夜：在庫追加
	
	else:
		return True
	
	
	

for i in range (T):
	A, B, C, D = map(int, input().split())		# 5 7 2
	
	b = solv(A, B, C, D)
	
	ans = "Yes" if b else "No"
	print(ans)

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

    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)
        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:
N=int(input())
for i in range(N):
    L=input()
    L=L.rstrip().split(" ")
    A=int(L[0])
    B=int(L[1])
    C=int(L[2])
    D=int(L[3])
    
    if  A-B<0:
        print("No")
    elif D<B:
        print("No")
    elif D%B==0:
        if A%B<=C:
            print("Yes")
        else:
            print("No")
    else:
        MIN=int((C-A%B)/(D%B)+1)
        if int((B-A%B)/(D%B))==(B-A%B)/(D%B):
            MAX=int((B-A%B)/(D%B)-1)
        else:
            MAX=int((B-A%B)/(D%B))
        if MIN<=MAX:
            print("No")
        else:
            print("Yes")

Submission status: Wrong Answer

Solution code:
T = int(input())						# 5



def solv(A, B, C, D):
	b = (A<B)				#初回在庫が足りない
	b = b or (D<B)			#補充が足りない
	b = b or ((A % B) > C)	#補充前にアウト
	if b: return False
	
	#力業で計算する
	if A>B : A = (A % B) + B			#初回量を適正化
	if D>B : D = (D % B) + B			#補充量を適正化
	
	z = A					#在庫数を初期化
	for i in range(1000):
		
		z -= B
		if (z<0): return False		#昼：在庫が足りなくてアウト
		
		
		if (z<=C): z+=D				#夜：在庫追加
	
	else:
		return True
	
	
	

for i in range (T):
	A, B, C, D = map(int, input().split())		# 5 7 2
	
	b = solv(A, B, C, D)
	
	ans = "Yes" if b else "No"
	print(ans)

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

    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)
        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())
ABCD = [list(map(int,input().split())) for _ in range(T)]

for a,b,c,d in ABCD:
    if a < b:
        print('No')
        continue
    if d < b:
        print('No')
        continue
    tmp = a % b
    if tmp > c:
        print('No')
        continue
    if d % b == 0:
        print('Yes')
        continue
    if c >= b-1:
        print('Yes')
        continue
    if a%2 == 0 and b%2 == 0 and d %2 == 0 and b-c == 2:
        print('Yes')
        continue
    #print('No')

    a /= c
    b /= c
    d /= c
    c = 1
    now = a
    dp = [a]
    for _ in range(c+2):
        if now < b:
            print('No')
            break
        now %= b
        if now in dp:
            print('Yes')
            break
        if now > c:
            print('No')
            break
        dp.append(now)
        now += d
    print('No')

Submission status: Wrong Answer

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

def judge(l):
    A = l[0]
    B = l[1]
    C = l[2]
    D = l[3]
    init = []
    while(1):
        if A-B < 0:
            return 'No'
        else:
            i=A%B
            if i > C:
                return 'No'
        j = C//B
        rest = B*(j)+i+D
        A = rest
        if A in set(init):
            break
        else:
            init.append(A)
    #         rest = A-B*(i+1)
    #         rest=rest+D
    #     A=rest
    return 'Yes'

ans = list(map(judge,a))
for a in ans:
    print(a)

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

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:
      C = (apple[2] - A) // B
      if A + (B * (C + 1)) < apple[1]:
        print("No")
      else:
        print("Yes")

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=B+A%B
		D=B+D%B
		#print A,B,C,D
		if A==B==D:
			print "Yes"
		elif abs(B-C)-1>=1:
			if abs(B-C)-1==1 and ((B+C)/2)%2==1 and ( A%2 or B%2 or D%2 )==0:
				print "Yes"
			elif A%B<=C and B==D:
				print "Yes"
			else:
				print "No"
		elif abs(B-C)-1==0:
			print "Yes"

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)//(d-b))
        while a<=c:
            a+=(d-b)
        if a<b:
            print('No')
            continue
        else:
            f=a-b
            ff=0
            for __ in range(50000):
                f+=(d-b)*((c-f)//(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:
#!/usr/bin/env python
import math
def solve():
    a, b, c, d = map(int, input().split())
    # 自明
    if d < b or a < b:
        return 'No'
    if c > b:
        return 'Yes'
    a %= b
    if a > c:
        return 'No'
    if d-b == 0:
        return 'Yes'

    # 最初の1回でアウトになる
    t = ((c-a)//(d-b)+1)*(d-b)+a
    if c < t < b:
        return 'No'

    # さんざんまわしたらアウトになる
    # if (b % abs(t%b - a)) < 
    return 'Yes' 
    # cache = set([a])
    # while True:
    #     t = ((c-a)//(d-b)+1)*(d-b)+a
    #     if c < t < b:
    #         return 'No'
    #     a = t % b
    #     if a in cache:
    #         return 'Yes'
    #     else:
    #         cache.add(a)

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

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

        z=gcd(B,D)

        if ((C+1)!=B) and (z==1 or (C+1)%z==B%z==x%z 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)

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

    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 += c
            
        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())
for i in range(t):
    able = "Yes"
    a,b,c,d = map(int, input().split())
    if a - b < 0:
        able = "No"
    elif b < c and d >= b:
        able = "Yes"
    else:
        x=a
        if a-c >= 0:
            x = c+(a-c)%b
        if x <= c:
            x+=d
        for i in range(15000):
            x-=b
            if x >= 0:
                if x <= c:
                    x+=d
            else:
                able = "No"
                break
    print(able)

Submission status: Wrong Answer

Solution code:
t = int(input())

for _ 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 > c and tmp < b:
                cond = False
    
    if cond:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
t = int(raw_input())
for _ in xrange(t):
    a,b,c,d = map(int, raw_input().strip().split())
    if (a<b):
        print "No"
    else:
        val = a-b
        x = c-val
        y = b-val
        #print x,y
        #if b==d:
            #if val >= 0 and val<=c:
                #print "Yes"
            #else:
                #print "No"
        # if >x and <y
        xx = d-b
        if xx<0:
            print "No"
        else:
            m = xx
            if xx==0:
                if val<=c:
                    print "Yes"
                else:
                    print "No"
            else:
                q = x / (xx)
                #print xx,q
                xx *= q
                xx+=m
                if xx < y:
                    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 == 1 or a % 2 == 1 or d % 2 == 1 or c % 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:
def canbuy(A,B,C,D):
    X=A
    if B>D:
        return False
    for i in range(2*10**5):
        X-=B*max([(X-C)//B,1])
        if i==0:
            Y=X
        if X<0:
            return False
        if X<=C:
            X+=D
        if X==A or (X==Y and i!=0):
            return True
    if (A-X)>100:
        return False
    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:
def canbuy(A,B,C,D):
    X=A
    if B>D:
        return False
    for i in range(10**5):
        X-=B*max([(X-C)//B,1])
        if i==0:
            Y=X
        if X<0:
            return False
        if X<=C:
            X+=D
        if X==A or (X==Y and i!=0):
            return True
    if (A-X)>100:
        return False
    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=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(10000):
                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:
def main():
    N = int(input())
    ABCD = [list(map(int, input().split())) for i in range(N)]
    for A,B,C,D in ABCD:
        # 在庫が買う本数以下 or 在庫追加が買う本数以下
        if A < B or D < B:
            print("No")
            continue

        A %= B
        # 在庫が買う本数以下になり、補給出来ない
        if C < A:
            print("No")
            continue
        if B == D:
            print("Yes")
            continue

        tmp = D-B
        flag = True
        if (B-A-1)%tmp <= (B-1)-(C+1):
            flag = False
        
        print("Yes" if flag else "No")


if __name__ == '__main__':
    main()