Problem p03017 (python)

Fixed submission:
# 2019/06/02
# AtCoder Grand Contest 034 - A

# For the answer:
# 1-1. Search min(ac) and max(abcd)
# 1-2. Search ## between min and max
# 2. Case:B<C, Left of B is . and (. or C), or exist .. -> Yes

# Def 1 : True is "Case No"
def searchRock(in_l, in_r, in_str, in_tg):
    rcflg = False
    for i in range(in_l - 1, in_r - 1): # Change -2 -> -1
        if in_str[i] == in_tg and in_str[i+1] == in_tg:
            rcflg = True
            break
    return rcflg

def searchPlain(in_l, in_r, in_str, in_tg):
    rcflg = False
    for i in range(in_l - 1, in_r - 1): # Change -2 -> -1
        if in_str[i] == in_tg and in_str[i+1] == in_tg and in_str[i+2] == in_tg:
            rcflg = True
            break
    return rcflg

# Input
n, a, b, c, d = map(int, input().split())
s = input()
ans = ""

# 1. Search ##
if c < b:
    # Search between a and c, b and d
    rflg = searchRock(a, c+1, s, "#")
    if rflg == True:
        ans = "No"
    else:
        rflg = searchRock(b, d+1, s, "#")
        if rflg == True:
            ans = "No"

else:
    # Search between a and max(c, d)
    rflg = searchRock(a, max(c, d)+1, s, "#")
    if rflg == True:
        ans = "No"
    
# 2. Check around b
if ans != "No":
    if (b < c and d < c):
        # Case: B < D < C 
        pflg = searchPlain(b-1, d, s, ".")
        if pflg == False:
            ans = "No"
#            if s[b-2] == "." and s[b] == ".":
#                ans = "Yes"
#            else:
#                ans = "No"
        else:
            ans = "Yes"
    else:
        ans = "Yes"

# Output
print(ans)

Buggy submission (verdict: Runtime Error):
# 2019/06/02
# AtCoder Grand Contest 034 - A

# For the answer:
# 1-1. Search min(ac) and max(abcd)
# 1-2. Search ## between min and max
# 2. Case:B<C, Left of B is . and (. or C), or exist .. -> Yes

# Def 1 : True is "Case No"
def searchRock(in_l, in_r, in_str, in_tg):
    rcflg = False
    for i in range(in_l - 1, in_r - 1): # Change -2 -> -1
        if in_str[i] == in_tg and in_str[i+1] == in_tg:
            rcflg = True
            break
    return rcflg

def searchPlain(in_l, in_r, in_str, in_tg):
    rcflg = False
    for i in range(in_l - 1, in_r - 2): # Change -2 -> -1
        if in_str[i] == in_tg and in_str[i+1] == in_tg and in_str[i+2] == in_tg:
            rcflg = True
            break
    return rcflg

# Input
n, a, b, c, d = map(int, input().split())
s = input()
ans = ""

# 1. Search ##
if c < b:
    # Search between a and c, b and d
    rflg = searchRock(a, c+1, s, "#")
    if rflg == True:
        ans = "No"
    else:
        rflg = searchRock(b, d+1, s, "#")
        if rflg == True:
            ans = "No"

else:
    # Search between a and max(c, d)
    rflg = searchRock(a, max(c, d)+1, s, "#")
    if rflg == True:
        ans = "No"
    
# 2. Check around b
if ans != "No":
    if (b < c and d < c):
        # Case: B < D < C 
        pflg = searchPlain(b-1, d, s, ".")
#        if pflg == False:
#            if s[b-2] == "." and s[b] == ".":
#                ans = "Yes"
#            else:
#                ans = "No"
        else:
            ans = "Yes"
    else:
        ans = "Yes"

# Output
print(ans)