Buggy python submission (verdict: Runtime Error):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        w,h = LI()
        if w == 0:
            break
        la = ["#" * (w+2)]
        ra = ["#" * (w+2)]
        for _ in range(h):
            l,r = LS()
            la.append("#{}#".format(l))
            ra.append("#{}#".format(r))
        la.append("#" * (w+2))
        ra.append("#" * (w+2))
        ls = None
        rs = None
        for i in range(1,h+2):
            for j in range(1,w+2):
                if la[i][j] == 'L':
                    ls = (i,j)
                if ra[i][j] == 'R':
                    rs = (i,j)

        def search(s):
            d = collections.defaultdict(lambda: inf)
            d[s] = 0
            q = []
            heapq.heappush(q, (0, s))
            v = collections.defaultdict(bool)
            while len(q):
                k, u = heapq.heappop(q)
                if v[u]:
                    continue
                v[u] = True

                for di, dj in dd:
                    li = u[0][0] + di
                    lj = u[0][1] + dj
                    if la[li][lj] == "#":
                        li -= di
                        lj -= dj
                    ri = u[1][0] + di
                    rj = u[1][1] - dj
                    if ra[ri][rj] == "#":
                        ri -= di
                        rj += dj
                    if la[li][lj] == '%' and ra[ri][rj] == '%':
                        return True
                    if la[li][lj] == '%':
                        continue
                    if ra[ri][rj] == '%':
                        continue
                    uv = ((li,lj), (ri,rj))

                    if v[uv]:
                        continue
                    vd = k + 1
                    if d[uv] > vd:
                        d[uv] = vd
                        heapq.heappush(q, (vd, uv))

            return False

        if search((ls,rs)):
            rr.append('Yes')
        else:
            rr.append('No')


    return '\n'.join(map(str,rr))


print(main())




Fixed submission:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(w, h):
        w2 = w+2
        la = ['#' * w2]
        ra = ['#' * w2]
        ls = rs = None
        for i in range(1,h+1):
            lt, rt = LS()
            if 'L' in lt:
                ls = (i, lt.index('L') + 1)
            if 'R' in rt:
                rs = (i, rt.index('R') + 1)
            la.append('#' + lt + '#')
            ra.append('#' + rt + '#')
        la.append('#' * w2)
        ra.append('#' * w2)

        q = collections.deque([(ls[0], ls[1], rs[0], rs[1])])
        v = collections.defaultdict(bool)
        v[(ls[0], ls[1], rs[0], rs[1])] = 1
        while q:
            ly,lx,ry,rx = q.pop()
            for dy, dx in dd:
                lty = ly + dy
                ltx = lx + dx
                rty = ry + dy
                rtx = rx - dx
                if la[lty][ltx] == '#':
                    lty = ly
                    ltx = lx
                if ra[rty][rtx] == '#':
                    rty = ry
                    rtx = rx
                if v[(lty,ltx,rty,rtx)]:
                    continue
                v[(lty,ltx,rty,rtx)] = 1
                if la[lty][ltx] == '%' and ra[rty][rtx] == '%':
                    return 'Yes'
                if la[lty][ltx] != '%' and ra[rty][rtx] != '%':
                    q.append((lty,ltx,rty,rtx))

        return 'No'

    while True:
        w,h = LI()
        if w == 0 and h == 0:
            break
        rr.append(f(w,h))

    return '\n'.join(rr)



print(main())

Buggy python submission (verdict: Runtime Error):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        w,h = LI()
        if w == 0:
            break
        print(w,h)
        la = ["#" * (w+2)]
        ra = ["#" * (w+2)]
        for _ in range(h):
            l,r = LS()
            la.append("#{}#".format(l))
            ra.append("#{}#".format(r))
        la.append("#" * (w+2))
        ra.append("#" * (w+2))
        ls = None
        rs = None
        lp = None
        rp = None
        for i in range(1,h+2):
            for j in range(1,w+2):
                if la[i][j] == 'L':
                    ls = (i,j)
                elif la[i][j] == '%':
                    lp = (i,j)
                if ra[i][j] == 'R':
                    rs = (i,j)
                elif ra[i][j] == '%':
                    rp = (i,j)
        lla = []
        rra = []
        for i in range(h+2):
            tl = []
            tr = []
            for j in range(w+2):
                if la[i][j] == '#':
                    tl.append(None)
                else:
                    tl.append(1)
                if ra[i][j] == '#':
                    tr.append(None)
                else:
                    tr.append(1)
            lla.append(tl)
            rra.append(tr)


        def search(s):
            q = []
            q.append(s)
            v = set()
            v.add(s)
            qi = 0
            while len(q) > qi:
                u = q[qi]
                qi += 1

                for di, dj in dd:
                    li = u[0][0]
                    lj = u[0][1]
                    if not lla[li+di][lj+dj] is None:
                        li += di
                        lj += dj
                    ri = u[1][0]
                    rj = u[1][1]
                    if not rra[ri+di][rj-dj] is None:
                        ri += di
                        rj -= dj

                    uv = ((li,lj), (ri,rj))
                    if uv in v:
                        continue
                    v.add(uv)
                    if (li,lj) == lp and (ri,rj) == rp:
                        # print(len(q))
                        return True
                    if (li,lj) == lp:
                        continue
                    if (ri,rj) == rp:
                        continue

                    q.append(uv)

            # print(len(q))
            return False

        if search((ls,rs)):
            rr.append('Yes')
        else:
            rr.append('No')
        # print(rr[-1])


    return '\n'.join(map(str,rr))


print(main())




Fixed submission:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(w, h):
        w2 = w+2
        la = ['#' * w2]
        ra = ['#' * w2]
        ls = rs = None
        for i in range(1,h+1):
            lt, rt = LS()
            if 'L' in lt:
                ls = (i, lt.index('L') + 1)
            if 'R' in rt:
                rs = (i, rt.index('R') + 1)
            la.append('#' + lt + '#')
            ra.append('#' + rt + '#')
        la.append('#' * w2)
        ra.append('#' * w2)

        q = collections.deque([(ls[0], ls[1], rs[0], rs[1])])
        v = collections.defaultdict(bool)
        v[(ls[0], ls[1], rs[0], rs[1])] = 1
        while q:
            ly,lx,ry,rx = q.pop()
            for dy, dx in dd:
                lty = ly + dy
                ltx = lx + dx
                rty = ry + dy
                rtx = rx - dx
                if la[lty][ltx] == '#':
                    lty = ly
                    ltx = lx
                if ra[rty][rtx] == '#':
                    rty = ry
                    rtx = rx
                if v[(lty,ltx,rty,rtx)]:
                    continue
                v[(lty,ltx,rty,rtx)] = 1
                if la[lty][ltx] == '%' and ra[rty][rtx] == '%':
                    return 'Yes'
                if la[lty][ltx] != '%' and ra[rty][rtx] != '%':
                    q.append((lty,ltx,rty,rtx))

        return 'No'

    while True:
        w,h = LI()
        if w == 0 and h == 0:
            break
        rr.append(f(w,h))

    return '\n'.join(rr)



print(main())

Buggy python submission (verdict: Runtime Error):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        w,h = LI()
        if w == 0:
            break
        # print(w,h)
        W = w+2
        dd = [(0,-1),(W,0),(0,1),(-W,0)]
        la = ["#" * W]
        ra = ["#" * W]
        for _ in range(h):
            l,r = LS()
            la.append("#{}#".format(l))
            ra.append("#{}#".format(r))
        la.append("#" * W)
        ra.append("#" * W)
        ls = None
        rs = None
        lp = None
        rp = None
        for i in range(1,h+2):
            for j in range(1,w+2):
                if la[i][j] == 'L':
                    ls = i*W+j
                elif la[i][j] == '%':
                    lp = i*W+j
                if ra[i][j] == 'R':
                    rs = i*W+j
                elif ra[i][j] == '%':
                    rp = i*W+j
        lla = []
        rra = []
        for i in range(h+2):
            for j in range(w+2):
                if la[i][j] == '#':
                    lla.append(None)
                else:
                    lla.append(1)
                if ra[i][j] == '#':
                    rra.append(None)
                else:
                    rra.append(1)


        def search(s):
            q = []
            q.append(s)
            v = set()
            v.add(s)
            qi = 0
            while len(q) > qi:
                u = q[qi]
                qi += 1

                for di, dj in dd:
                    lij = u[0]
                    if not lla[lij+di+dj] is None:
                        lij += di + dj
                    rij = u[1]
                    if not rra[rij+di-dj] is None:
                        rij += di - dj

                    uv = (lij,rij)
                    if uv in v:
                        continue
                    v.add(uv)
                    if lij == lp and rij == rp:
                        # print(len(q))
                        return True
                    if lij == lp:
                        continue
                    if rij == rp:
                        continue

                    q.append(uv)

            # print(len(q))
            return False

        if search((ls,rs)):
            rr.append('Yes')
        else:
            rr.append('No')
        # print(rr[-1])


    return '\n'.join(map(str,rr))


print(main())




Fixed submission:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(w, h):
        w2 = w+2
        la = ['#' * w2]
        ra = ['#' * w2]
        ls = rs = None
        for i in range(1,h+1):
            lt, rt = LS()
            if 'L' in lt:
                ls = (i, lt.index('L') + 1)
            if 'R' in rt:
                rs = (i, rt.index('R') + 1)
            la.append('#' + lt + '#')
            ra.append('#' + rt + '#')
        la.append('#' * w2)
        ra.append('#' * w2)

        q = collections.deque([(ls[0], ls[1], rs[0], rs[1])])
        v = collections.defaultdict(bool)
        v[(ls[0], ls[1], rs[0], rs[1])] = 1
        while q:
            ly,lx,ry,rx = q.pop()
            for dy, dx in dd:
                lty = ly + dy
                ltx = lx + dx
                rty = ry + dy
                rtx = rx - dx
                if la[lty][ltx] == '#':
                    lty = ly
                    ltx = lx
                if ra[rty][rtx] == '#':
                    rty = ry
                    rtx = rx
                if v[(lty,ltx,rty,rtx)]:
                    continue
                v[(lty,ltx,rty,rtx)] = 1
                if la[lty][ltx] == '%' and ra[rty][rtx] == '%':
                    return 'Yes'
                if la[lty][ltx] != '%' and ra[rty][rtx] != '%':
                    q.append((lty,ltx,rty,rtx))

        return 'No'

    while True:
        w,h = LI()
        if w == 0 and h == 0:
            break
        rr.append(f(w,h))

    return '\n'.join(rr)



print(main())