TLE with HELP MARTHA problem of Code Ensemble

T=int(input())
for _ in range(T):
str1=input()
initial=list(map(int,input().split()))
n=int(input())
for _ in range(n):
str2=""
target=list(map(int,input().split()))
if target[0]>=initial[0]:
x=target[0]-initial[0]
str2+=x*“R”
if target[0]<=initial[0]:
x=initial[0]-target[0]
str2+=x*“L”
if target[1]>=initial[1]:
y=target[1]-initial[1]
str2+=y*“U”
if target[1]<=initial[1]:
y=initial[1]-target[1]
str2+=y*“D”
#print(str2)
res_str=""
for i in str1:
if i in str2:
res_str+=i
#print(res_str)
if str2 in res_str or str2[::-1] in res_str:
print(“YES”,len(str2))
else:
print(“NO”)

1 Like

did you use FAST IO ?

@I don’t know how to use fast IO in python. Can you please help me with any article or something ?

1 Like

Try reading this-
https://www.geeksforgeeks.org/python-input-methods-competitive-programming/
Also format your code.

3 Likes

Thanks a lot