Use this to learn the idea, then write your own version.
1package main2 3import (4 "bufio"5 . "fmt"6 "io"7)8 910func CF1301D(_r io.Reader, _w io.Writer) {11 in := bufio.NewReader(_r)12 out := bufio.NewWriter(_w)13 defer out.Flush()14 15 var n, m, k int16 Fscan(in, &n, &m, &k)17 if k > 4*n*m-2*n-2*m {18 Fprint(out, "NO")19 return20 }21 22 type pair struct {23 times int24 op string25 }26 ans := []pair{}27 makeAns := func(ops []string, maxTimes, left int) int {28 for _, op := range ops {29 if left <= len(op)*maxTimes {30 if left > 0 {31 if len(op) == 1 {32 ans = append(ans, pair{left, op})33 } else {34 a, b := left/len(op), left%len(op)35 if a > 0 {36 ans = append(ans, pair{a, op})37 }38 if b > 0 {39 ans = append(ans, pair{1, op[:b]})40 }41 }42 }43 return 044 }45 ans = append(ans, pair{maxTimes, op})46 left -= len(op) * maxTimes47 }48 return left49 }50 printAns := func() {51 Fprintln(out, "YES")52 Fprintln(out, len(ans))53 for _, a := range ans {54 Fprintln(out, a.times, a.op)55 }56 }57 58 if n == 1 {59 makeAns([]string{"R", "L"}, m-1, k)60 printAns()61 return62 }63 var cycleNum, left int64 if cycleSize := 4*(n-1) + 1; k <= cycleSize*(m-1) {65 cycleNum, left = k/cycleSize, k%cycleSize66 k = 067 } else {68 cycleNum, left = m-1, 069 k -= cycleSize * (m - 1)70 }71 for i := 0; i < cycleNum; i++ {72 ans = append(ans, pair{n - 1, "D"}, pair{n - 1, "RLU"}, pair{1, "R"})73 }74 makeAns([]string{"D", "RLU"}, n-1, left)75 k = makeAns([]string{"D", "U"}, n-1, k)76 if k > 0 {77 ans = append(ans, pair{k, "L"})78 }79 printAns()80}81 8283