Scanf.scanf "%d %d %d %d %d %s %s" (fun h w n sr sc s t ->
    let check st m cs ct =
        let rec loop i p =
            if i = n then true else
                let p = if s.[i] = cs then p - 1 else p in
                if p < 1 then false else
                    let p = if t.[i] = ct then min (p + 1) m else p in
                    loop (i + 1) p
        in
        loop 0 st
    in
    print_endline @@
        if check sr           h 'U' 'D' &&
           check (h + 1 - sr) h 'D' 'U' &&
           check sc           w 'L' 'R' &&
           check (w + 1 - sc) w 'R' 'L' then "YES" else "NO"
)
