You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: 1753D.go
    path of file: ./repos/codeforces-go/main/1700-1799
    
    the code of the file until where you have to start completion: package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"io"
)

// 
    
func CF1753D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const inf int64 = 1e18
	dir4 := []struct{ x, y int }{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}
	match := []struct{ x, y int }{'L': {0, 1}, 'R': {0, -1}, 'U': {1, 0}, 'D': {-1, 0}}
	min := func(a, b int64) int64 {
		if a > b {
			return b
		}
		return a
	}

	var n, m int
	var p, q int64
	Fscan(in, &n, &m, &p, &q)
	g := make([]string, n)
	dis := make([][]int64, n)
	h := hp53{}
	for i := range g {
		Fscan(in, &g[i])
		dis[i] = make([]int64, m)
		for j, b := range g[i] {
			if b == '.' {
				dis[i][j] = 0
				h.push(pd53{i, j, 0})
			} else {
				dis[i][j] = inf
			}
		}
	}
	for len(h) > 0 {
		top := h.pop()
		i, j := top.x, top.y
		if top.dis > dis[i][j] {
			continue
		}
		for _, d := range dir4 {
			x, y := i+d.x, j+d.y
			if 0 <= x && x < n && 0 <= y && y < m && g[x][y] != '.' && g[x][y] != '#' {
				d := match[g[x][y]]
				x += d.x
				y += d.y
				newD := dis[i][j]
				if x != i && y != j {
					newD += p
				} else {
					newD += q
				}
				if newD < dis[x][y] {
					dis[x][y] = newD
					h.push(pd53{x, y, newD})
				}
			}
		}
	}
	ans := inf
	for i, r := range dis {
		for j, d := range r {
			if j < m-1 {
				ans = min(ans, d+r[j+1])
			}
			if i < n-1 {
				ans = min(ans, d+dis[i+1][j])
			}
		}
	}
	if ans == inf {
		ans = -1
	}
	Fprint(out, ans)
}