package main

import (
  "os"
  "bufio"
  "strconv"
  "fmt"
)

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

var n int
var grid [][]int

func solveZero() string {
  for r := 0; r < n; r++ {
    for c := 0; c < n; c++ {
      if grid[r][c] == 0 {
        path := []byte{}
        for i := 0; i < r; i++ {
          path = append(path, 'D')
        }
        for i := 0; i < c; i++ {
          path = append(path, 'R')
        }
        for i := r; i != n-1; i++ {
          path = append(path, 'D')
        }
        for i := c; i != n-1; i++ {
          path = append(path, 'R')
        }
        return string(path)
      }
    }
  }
  return ""
}

func solve(factor int) (int, string) {
  cost := make([][]int, n)
  dir := make([][]byte, n)
  for r := 0; r < n; r++ {
    cost[r] = make([]int, n)
    dir[r] = make([]byte, n)
    for c := 0; c < n; c++ {
      x := grid[r][c]
      if x == 0 {
        cost[r][c] = 2*n
        continue
      }
      for x % factor == 0 {
        cost[r][c]++
        x /= factor
      }
    }
  }
  for t := 0; t < 2*n-1; t++ {
    r := t
    if r >= n {
      r = n-1
    }
    c := t-r
    for r >= 0 && c < n {
      left, up := -1, -1
      if c-1 >= 0 {
        left = cost[r][c-1]
      }
      if r-1 >= 0 {
        up = cost[r-1][c]
      }
      if left != -1 || up != -1 {
        if left != -1 && up != -1 {
          if left < up {
            cost[r][c] += left
            dir[r][c] = 'R'
          } else {
            cost[r][c] += up
            dir[r][c] = 'D'
          }
        } else if left != -1 {
          cost[r][c] += left
          dir[r][c] = 'R'
        } else {
          cost[r][c] += up
          dir[r][c] = 'D'
        }
      }
      r--
      c++
    }
  }
  path := make([]byte, 2*n-2)
  r, c := n-1, n-1
  for i := len(path)-1; i >= 0; i-- {
    path[i] = dir[r][c]
    if path[i] == 'D' {
      r--
    } else {
      c--
    }
  }
  return cost[n-1][n-1], string(path)
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n = getI()
  grid = make([][]int, n)
  for r := 0; r < n; r++ {
    grid[r] = make([]int, n)
    for c := 0; c < n; c++ {
      grid[r][c] = getI()
    }
  }
  cost, path := solve(2)
  cost5, path5 := solve(5)
  if cost5 < cost {
    cost, path = cost5, path5
  }
  path0 := solveZero()
  if path0 != "" && cost > 1 {
    cost, path = 1, path0
  }
  writer.WriteString(fmt.Sprintf("%d\n%s\n", cost, path))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

const N = 1000

var dp [N][N]int
var cnt [N][N]int

func main() {
	reader := bufio.NewReader(os.Stdin)

	n := readNum(reader)
	M := make([][]int, n)
	for i := 0; i < n; i++ {
		M[i] = readNNums(reader, n)
	}
	best, path := solve(n, M)
	fmt.Println(best)
	fmt.Println(path)
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const INF = 1 << 30

func solve(n int, M [][]int) (int, string) {
	var hasZero bool
	u, v := -1, -1
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if M[i][j] == 0 {
				hasZero = true
				u, v = i, j
				M[i][j] = 10
			}
		}
	}

	var limit = INF
	if hasZero {
		limit = 1
	}

	a, x := getMinCountPath(n, M, 2, limit)

	if a == 0 {
		return a, x
	}

	b, y := getMinCountPath(n, M, 5, a)

	if b == 0 {
		return b, y
	}

	if hasZero {
		// choose the 0, will give answer 1
		path := make([]byte, 0, 2*n-1)
		for i := 0; i < u; i++ {
			path = append(path, 'D')
		}
		for j := 0; j < v; j++ {
			path = append(path, 'R')
		}
		for i := u + 1; i < n; i++ {
			path = append(path, 'D')
		}
		for j := v + 1; j < n; j++ {
			path = append(path, 'R')
		}
		return 1, string(path)
	}

	if a <= b {
		return a, x
	}
	return b, y
}

func getMinCountPath(n int, M [][]int, div int, limit int) (int, string) {
	//dp := make([][]int, n)
	//cnt := make([][]int, n)
	for i := 0; i < n; i++ {
		//dp[i] = make([]int, n)
		//cnt[i] = make([]int, n)
		for j := 0; j < n; j++ {
			cnt[i][j] = count(M[i][j], div)
			//dp[i][j] = 0
		}
	}

	get := func(i, j int) int {
		if i < 0 || j < 0 {
			return INF
		}
		return dp[i][j]
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			dp[i][j] = cnt[i][j]
			if i > 0 || j > 0 {
				dp[i][j] += min(get(i-1, j), get(i, j-1))
			}
		}
	}

	best := dp[n-1][n-1]

	if best >= limit {
		return best, ""
	}

	res := make([]byte, 0, 2*n-1)

	x, y := n-1, n-1

	for x >= 0 && y >= 0 {
		cur := dp[x][y]
		if x > 0 && dp[x-1][y] == cur-cnt[x][y] {
			x--
			res = append(res, 'D')
		} else {
			y--
			res = append(res, 'R')
		}
		if x == 0 && y == 0 {
			break
		}
	}

	reverse(res)

	return best, string(res)
}

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func count(num int, div int) int {
	var res int
	for num%div == 0 {
		num /= div
		res++
	}
	return res
}

func reverse(buf []byte) {
	for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {
		buf[i], buf[j] = buf[j], buf[i]
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

const N = 1000
var dp [N][N]int
var cnt [N][N]int

func main() {
	reader := bufio.NewReader(os.Stdin)

	n := readNum(reader)
	M := make([][]int, n)
	for i := 0; i < n; i++ {
		M[i] = readNNums(reader, n)
	}
	best, path := solve(n, M)
	fmt.Println(best)
	fmt.Println(path)
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const INF = 1 << 30

func solve(n int, M [][]int) (int, string) {
	var hasZero bool
	u, v := -1, -1
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if M[i][j] == 0 {
				hasZero = true
				u, v = i, j
				M[i][j] = 10
			}
		}
	}
	a, x := getMinCountPath(n, M, 2, INF)

	if a == 0 {
		return a, x
	}

	b, y := getMinCountPath(n, M, 5, a)

	if b == 0 {
		return b, y
	}

	if hasZero {
		// choose the 0, will give answer 1
		path := make([]byte, 0, 2 * n - 1)
		for i := 0; i < u; i++ {
			path = append(path, 'D')
		}
		for j := 0; j < v; j++ {
			path = append(path, 'R')
		}
		for i := u+1; i < n; i++ {
			path = append(path, 'D')
		}
		for j := v+1; j < n; j++ {
			path = append(path, 'R')
		}
		return 1, string(path)
	}

	if a <= b {
		return a, x
	}
	return b, y
}

func getMinCountPath(n int, M [][]int, div int, limit int) (int, string) {
	//dp := make([][]int, n)
	//cnt := make([][]int, n)
	for i := 0; i < n; i++ {
		//dp[i] = make([]int, n)
		//cnt[i] = make([]int, n)
		for j := 0; j < n; j++ {
			cnt[i][j] = count(M[i][j], div)
			//dp[i][j] = 0
		}
	}

	get := func(i, j int) int {
		if i < 0 || j < 0 {
			return INF
		}
		return dp[i][j]
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			dp[i][j] = cnt[i][j]
			if i > 0 || j > 0 {
				dp[i][j] += min(get(i-1, j), get(i, j-1))
			}
		}
	}

	best := dp[n-1][n-1]

	if best >= limit {
		return best, ""
	}

	res := make([]byte, 0, 2*n-1)

	x, y := n-1, n-1

	for x >= 0 && y >= 0 {
		cur := dp[x][y]
		if x > 0 && dp[x-1][y] == cur-cnt[x][y] {
			x--
			res = append(res, 'D')
		} else {
			y--
			res = append(res, 'R')
		}
		if x == 0 && y == 0 {
			break
		}
	}

	reverse(res)

	return best, string(res)
}

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func count(num int, div int) int {
	if div == 2 {
		c := 32 // c will be the number of zero bits on the right
		num &= -num
		if num > 0 {
			c--
		}
		if num&0x0000FFFF > 0 {
			c -= 16
		}
		if num&0x00FF00FF > 0 {
			c -= 8
		}
		if num&0x0F0F0F0F > 0 {
			c -= 4
		}
		if num&0x33333333 > 0 {
			c -= 2
		}
		if num&0x55555555 > 0 {
			c -= 1
		}
		return c
	}
	var res int
	for num%div == 0 {
		num /= div
		res++
	}
	return res
}

func reverse(buf []byte) {
	for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {
		buf[i], buf[j] = buf[j], buf[i]
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

const N = 1000

var dp [N][N]int
var cnt [N][N]int

func main() {
	reader := bufio.NewReader(os.Stdin)

	n := readNum(reader)
	M := make([][]int, n)
	for i := 0; i < n; i++ {
		M[i] = readNNums(reader, n)
	}
	best, path := solve(n, M)
	fmt.Println(best)
	fmt.Println(path)
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const INF = 1 << 30

func solve(n int, M [][]int) (int, string) {
	var hasZero bool
	u, v := -1, -1
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if M[i][j] == 0 {
				hasZero = true
				u, v = i, j
				M[i][j] = 10
			}
		}
	}
	a, x := getMinCountPath(n, M, 2, INF)

	if a == 0 {
		return a, x
	}

	b, y := getMinCountPath(n, M, 5, a)

	if b == 0 {
		return b, y
	}

	if hasZero {
		// choose the 0, will give answer 1
		path := make([]byte, 0, 2*n-1)
		for i := 0; i < u; i++ {
			path = append(path, 'D')
		}
		for j := 0; j < v; j++ {
			path = append(path, 'R')
		}
		for i := u + 1; i < n; i++ {
			path = append(path, 'D')
		}
		for j := v + 1; j < n; j++ {
			path = append(path, 'R')
		}
		return 1, string(path)
	}

	if a <= b {
		return a, x
	}
	return b, y
}

func getMinCountPath(n int, M [][]int, div int, limit int) (int, string) {
	//dp := make([][]int, n)
	//cnt := make([][]int, n)
	for i := 0; i < n; i++ {
		//dp[i] = make([]int, n)
		//cnt[i] = make([]int, n)
		for j := 0; j < n; j++ {
			cnt[i][j] = count(M[i][j], div)
			//dp[i][j] = 0
		}
	}

	get := func(i, j int) int {
		if i < 0 || j < 0 {
			return INF
		}
		return dp[i][j]
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			dp[i][j] = cnt[i][j]
			if i > 0 || j > 0 {
				dp[i][j] += min(get(i-1, j), get(i, j-1))
			}
		}
	}

	best := dp[n-1][n-1]

	if best >= limit {
		return best, ""
	}

	res := make([]byte, 0, 2*n-1)

	x, y := n-1, n-1

	for x >= 0 && y >= 0 {
		cur := dp[x][y]
		if x > 0 && dp[x-1][y] == cur-cnt[x][y] {
			x--
			res = append(res, 'D')
		} else {
			y--
			res = append(res, 'R')
		}
		if x == 0 && y == 0 {
			break
		}
	}

	reverse(res)

	return best, string(res)
}

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func count(num int, div int) int {
	var res int
	for num%div == 0 {
		num /= div
		res++
	}
	return res
}

func reverse(buf []byte) {
	for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {
		buf[i], buf[j] = buf[j], buf[i]
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/2/problem/B

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

type Factor struct {
	Twos  int
	Fives int
}

type Path struct {
	Sum        int
	Directions string
}

func min(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

func countFactors(x int, twos int, fives int) Factor {
	if x == 0 {
		return Factor{Twos: 1, Fives: 1}
	} else if x%2 == 0 {
		return countFactors(x/2, twos+1, fives)
	} else if x%5 == 0 {
		return countFactors(x/5, twos, fives+1)
	}
	return Factor{Twos: twos, Fives: fives}
}

func hasZero(n int, m [][]int) (bool, int, int) {
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if m[i][j] == 0 {
				return true, i, j
			}
		}
	}
	return false, -1, -1
}

func createZeroPath(n int, i int, j int) Path {
	return Path{
		Sum:        1,
		Directions: strings.Repeat("D", i) + strings.Repeat("R", j) + strings.Repeat("D", n-1-i) + strings.Repeat("R", n-1-j),
	}
}

func createDirections(n int, m [][]int) string {
	directions := ""
	i, j := n-1, n-1
	for i > 0 || j > 0 {
		if i == 0 {
			directions = "R" + directions
			j -= 1
		} else if j == 0 {
			directions = "D" + directions
			i -= 1
		} else if m[i][j-1] < m[i-1][j] {
			directions = "R" + directions
			j -= 1
		} else {
			directions = "D" + directions
			i -= 1
		}
	}
	return directions
}

func createFactorMatrices(n int, m [][]int) ([][]int, [][]int) {
	twosMatrix := make([][]int, n)
	fivesMatrix := make([][]int, n)
	for i := 0; i < n; i++ {
		twosMatrix[i] = make([]int, n)
		fivesMatrix[i] = make([]int, n)
		for j := 0; j < n; j++ {
			factors := countFactors(m[i][j], 0, 0)
			twosMatrix[i][j] = factors.Twos
			fivesMatrix[i][j] = factors.Fives
		}
	}
	return twosMatrix, fivesMatrix
}

func computeMinPath(n int, matrix [][]int) {
	for i := 1; i < n; i++ {
		matrix[i][0] += matrix[i-1][0]
		matrix[0][i] += matrix[0][i-1]
	}
	for i := 1; i < n; i++ {
		for j := 1; j < n; j++ {
			if matrix[i][j-1] < matrix[i-1][j] {
				matrix[i][j] += matrix[i][j-1]
			} else {
				matrix[i][j] += matrix[i-1][j]
			}
		}
	}
}

func Solve(n int, m [][]int) Path {
	twosMatrix, fivesMatrix := createFactorMatrices(n, m)
	computeMinPath(n, twosMatrix)
	computeMinPath(n, fivesMatrix)
	twosSum, fivesSum := twosMatrix[n-1][n-1], fivesMatrix[n-1][n-1]
	if twosSum == 0 {
		return Path{Sum: twosSum, Directions: createDirections(n, twosMatrix)}
	} else if fivesSum == 0 {
		return Path{Sum: fivesSum, Directions: createDirections(n, fivesMatrix)}
	}
	hasZero, i, j := hasZero(n, m)
	if hasZero {
		return createZeroPath(n, i, j)
	} else if twosSum < fivesSum {
		return Path{Sum: twosSum, Directions: createDirections(n, twosMatrix)}
	}
	return Path{Sum: fivesSum, Directions: createDirections(n, fivesMatrix)}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	m := make([][]int, n)
	for i := 0; i < n; i++ {
		m[i] = make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(reader, "%d", &m[i][j])
		}
		fmt.Fscanf(reader, "%d\n")
	}

	solution := Solve(n, m)
	fmt.Fprintf(writer, "%d\n", solution.Sum)
	fmt.Fprintf(writer, "%s\n", solution.Directions)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var debug = false

type node struct {
	twos, fives int
	val         int
}

func solve() {
	n := readInt()

	a := make([][]node, n, n)
	for i, _ := range a {
		a[i] = make([]node, n, n)
	}

	zeroFound := false
	var zeroi, zeroj int

	for i, _ := range a {
		for j, _ := range a[i] {
			v := readInt()
			a[i][j].fives = fives(v)
			a[i][j].twos = twos(v)
			a[i][j].val = v
			if v == 0 {
				zeroFound = true
				zeroi = i
				zeroj = j
			}
		}
	}

	b := make([][]node, n, n)
	for i, _ := range b {
		b[i] = make([]node, n, n)
	}

	// Compute the minimum path to "this" point (it's the minimum
	// of the path cost of its 0, 1, or 2 predecessors plus its
	// own cost).
	for i := 0; i < 2*len(b); i++ {
		jj := 0
		ii := i
		if i >= n {
			ii = n - 1
			jj = i - n + 1
		}
		for {
			if ii < 0 || jj == n {
				break
			}

			if debug {
				fmt.Print("Set(", ii, jj, ")")
			}
			b[ii][jj] = a[ii][jj]
			v2 := math.MaxInt32
			v5 := math.MaxInt32
			if ii > 0 {
				v2 = min(v2, b[ii-1][jj].twos)
				v5 = min(v5, b[ii-1][jj].fives)
			}
			if jj > 0 {
				v2 = min(v2, b[ii][jj-1].twos)
				v5 = min(v5, b[ii][jj-1].fives)
			}

			if v2 != math.MaxInt32 {
				b[ii][jj].twos += v2
				b[ii][jj].fives += v5
			}

			ii--
			jj++
		}
		if debug {
			fmt.Println("")
		}
	}

	if zeroFound && min(b[n-1][n-1].twos, b[n-1][n-1].fives) >= 1 {
		fmt.Println("1")
		for i := 0; i < zeroi; i++ {
			fmt.Print("D")
		}
		for i := 0; i < zeroj; i++ {
			fmt.Print("R")
		}
		for i := zeroi; i < n-1; i++ {
			fmt.Print("D")
		}
		for i := zeroj; i < n-1; i++ {
			fmt.Print("R")
		}
		fmt.Println("")
		return
	}

	using2 := true
	if b[n-1][n-1].fives < b[n-1][n-1].twos {
		using2 = false
	}

	if debug {
		fmt.Println(a)
		fmt.Println(b)
	}

	// Now, find the path
	i := n - 1
	j := n - 1
	str := make([]rune, (n-1)*2, (n-1)*2)
	idx := len(str) - 1
	zeros := 0

	for {
		if using2 {
			zeros += a[i][j].twos
		} else {
			zeros += a[i][j].fives
		}

		if i == 0 && j == 0 {
			break
		}

		if i == 0 {
			str[idx] = 'R'
			idx--
			j--
			continue
		}
		if j == 0 {
			str[idx] = 'D'
			idx--
			i--
			continue
		}

		if using2 {
			if b[i-1][j].twos <= b[i][j-1].twos {
				str[idx] = 'D'
				idx--
				i--
			} else {
				str[idx] = 'R'
				idx--
				j--
			}
		} else {
			if b[i-1][j].fives <= b[i][j-1].fives {
				str[idx] = 'D'
				idx--
				i--
			} else {
				str[idx] = 'R'
				idx--
				j--
			}
		}
	}
	fmt.Println(zeros)
	fmt.Println(string(str))

	if debug {
		acc := a[n-1][n-1].val
		i = 0
		j = 0
		idx = 0
		for i != n-1 || j != n-1 {
			acc *= a[i][j].val
			fmt.Println("V(", i, j, a[i][j].val, ")")
			switch str[idx] {
			case 'R':
				j++
				break
			case 'D':
				i++
				break
			}
			idx++
		}
		fmt.Println("V(", n-1, n-1, a[n-1][n-1].val, ")")
		fmt.Println("Accum", acc)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func twos(i int) (n int) {
	n = 0
	for ; i > 0; i /= 2 {
		if i%2 != 0 {
			break
		}
		n++
	}
	return
}

func fives(i int) (n int) {
	n = 0
	for ; i > 0; i /= 5 {
		if i%5 != 0 {
			break
		}
		n++
	}
	return
}

func nzeros(i int) int {
	var cnt int
	for {
		if i%10 != 0 {
			break
		}
		i /= 10
		cnt++
		if i < 10 {
			break
		}
	}
	return cnt
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var debug = false

type node struct {
	twos, fives int
	val         int
}

func solve() {
	n := readInt()

	a := make([][]node, n, n)
	for i, _ := range a {
		a[i] = make([]node, n, n)
	}

	zeroFound := false
	var zeroi, zeroj int

	for i, _ := range a {
		for j, _ := range a[i] {
			v := readInt()
			a[i][j].fives = fives(v)
			a[i][j].twos = twos(v)
			a[i][j].val = v
			if v == 0 {
				zeroFound = true
				zeroi = i
				zeroj = j
			}
		}
	}

	b := make([][]node, n, n)
	for i, _ := range b {
		b[i] = make([]node, n, n)
	}

	// Compute the minimum path to "this" point (it's the minimum
	// of the path cost of its 0, 1, or 2 predecessors plus its
	// own cost).
	for i := 0; i < 2*len(b); i++ {
		jj := 0
		ii := i
		if i >= n {
			ii = n - 1
			jj = i - n + 1
		}
		for {
			if ii < 0 || jj == n {
				break
			}

			if debug {
				fmt.Print("Set(", ii, jj, ")")
			}
			b[ii][jj] = a[ii][jj]
			v2 := math.MaxInt32
			v5 := math.MaxInt32
			if ii > 0 {
				v2 = min(v2, b[ii-1][jj].twos)
				v5 = min(v5, b[ii-1][jj].fives)
			}
			if jj > 0 {
				v2 = min(v2, b[ii][jj-1].twos)
				v5 = min(v5, b[ii][jj-1].fives)
			}

			if v2 != math.MaxInt32 {
				b[ii][jj].twos += v2
				b[ii][jj].fives += v5
			}

			ii--
			jj++
		}
		if debug {
			fmt.Println("")
		}
	}

	if zeroFound && min(b[n-1][n-1].twos, b[n-1][n-1].fives) >= 1 {
		// There's a zero in the matrix, if we can't do better
		// with factors of 5 or 2, a path with a zero always has
		// a cost of 1.
		fmt.Println("1")
		for i := 0; i < zeroi; i++ {
			fmt.Print("D")
		}
		for i := 0; i < zeroj; i++ {
			fmt.Print("R")
		}
		for i := zeroi; i < n-1; i++ {
			fmt.Print("D")
		}
		for i := zeroj; i < n-1; i++ {
			fmt.Print("R")
		}
		fmt.Println("")
		return
	}

	var using2 bool
	if b[n-1][n-1].fives < b[n-1][n-1].twos {
		using2 = false
		fmt.Println(b[n-1][n-1].fives)
	} else {
		using2 = true
		fmt.Println(b[n-1][n-1].twos)
	}

	if debug {
		fmt.Println(a)
		fmt.Println(b)
	}

	// Now, find the path
	i := n - 1
	j := n - 1
	str := make([]rune, (n-1)*2, (n-1)*2)
	idx := len(str) - 1

	for {
		if i == 0 && j == 0 {
			break
		}

		if i == 0 {
			str[idx] = 'R'
			idx--
			j--
			continue
		}
		if j == 0 {
			str[idx] = 'D'
			idx--
			i--
			continue
		}

		if using2 {
			if b[i-1][j].twos <= b[i][j-1].twos {
				str[idx] = 'D'
				idx--
				i--
			} else {
				str[idx] = 'R'
				idx--
				j--
			}
		} else {
			if b[i-1][j].fives <= b[i][j-1].fives {
				str[idx] = 'D'
				idx--
				i--
			} else {
				str[idx] = 'R'
				idx--
				j--
			}
		}
	}
	fmt.Println(string(str))

	if debug {
		acc := a[n-1][n-1].val
		i = 0
		j = 0
		idx = 0
		for i != n-1 || j != n-1 {
			acc *= a[i][j].val
			fmt.Println("V(", i, j, a[i][j].val, ")")
			switch str[idx] {
			case 'R':
				j++
				break
			case 'D':
				i++
				break
			}
			idx++
		}
		fmt.Println("V(", n-1, n-1, a[n-1][n-1].val, ")")
		fmt.Println("Accum", acc)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func twos(i int) (n int) {
	n = 0
	for ; i > 0; i /= 2 {
		if i%2 != 0 {
			break
		}
		n++
	}
	return
}

func fives(i int) (n int) {
	n = 0
	for ; i > 0; i /= 5 {
		if i%5 != 0 {
			break
		}
		n++
	}
	return
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	mat := make([][]int64, n)
	s := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		s.Scan()
		mat[i] = toInts(s.Bytes(), n)
	}
	res, path := leastFactor(mat, 2)
	a, pa := leastFactor(mat, 5)
	if res > a {
		res = a
		path = pa
	}
	b, pb := hasZero(mat)
	if b && res > 1 {
		res = 1
		path = pb
	}
	fmt.Println(res)
	fmt.Println(path)
}

func toInts(s []byte, n int) []int64 {
	res := make([]int64, 0, n)
	var v int64
	for _, c := range s {
		if c == ' ' || c == '\n' {
			res = append(res, v)
			v = 0
		} else {
			v = v*10 + int64(c-'0')
		}
	}
	res = append(res, v)
	return res
}

type pair struct {
	v int64
	d byte
}

func (p *pair) String() string {
	return fmt.Sprintf("v: %d, d: %v", p.v, p.d)
}

func hasZero(mat [][]int64) (yes bool, res string) {
	n := len(mat)
	path := make([]byte, n+n-2)
	var t int
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if mat[i][j] == 0 {
				yes = true
				for k := 0; k < j; k++ {
					path[t] = 'R'
					t++
				}

				for k := 0; k < n-1; k++ {
					path[t] = 'D'
					t++
				}
				for ; t < len(path); t++ {
					path[t] = 'R'
				}
				return yes, string(path)
			}
		}
	}
	return
}

func leastFactor(mat [][]int64, n int64) (value int64, path string) {
	size := len(mat)
	mem := make([][]*pair, size)
	for i := 0; i < size; i++ {
		mem[i] = make([]*pair, size)
		for j := 0; j < size; j++ {
			fac := factors(mat[i][j], n)
			if i == 0 && j == 0 {
				mem[i][j] = &pair{v: fac, d: ' '}
			} else if i == 0 {
				mem[i][j] = &pair{v: mem[i][j-1].v + fac, d: 'R'}
			} else if j == 0 {
				mem[i][j] = &pair{v: mem[i-1][j].v + fac, d: 'D'}
			} else {
				var v int64
				var d byte
				if mem[i-1][j].v < mem[i][j-1].v {
					v = mem[i-1][j].v
					d = 'D'
				} else {
					v = mem[i][j-1].v
					d = 'R'
				}
				mem[i][j] = &pair{v: v + fac, d: d}
			}
		}
	}
	value = mem[size-1][size-1].v
	p := make([]byte, 2*size-2)
	i := size - 1
	j := size - 1
	for k := len(p) - 1; k >= 0; k-- {
		p[k] = mem[i][j].d
		if p[k] == 'D' {
			i = i - 1
		} else if p[k] == 'R' {
			j = j - 1
		} else {
			break
		}
	}
	return value, string(p)
}

func factors(n, p int64) (res int64) {
	if n == 0 {
		return 1
	}
	for n > 0 && n%p == 0 {
		n = n / p
		res++
	}
	return res
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

type node struct {
	twos, fives int
	val         int
}

func solve() {
	n := readInt()

	a := make([][]node, n, n)
	for i := 0; i < n; i++ {
		a[i] = make([]node, n, n)
	}

	zeroFound := false
	var zeroI, zeroJ int

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			v := readInt()
			a[i][j].fives = twoOrFives(v, 5)
			a[i][j].twos = twoOrFives(v, 2)
			a[i][j].val = v
			if v == 0 {
				zeroFound = true
				zeroI = i
				zeroJ = j
			}
		}
	}

	b := make([][]node, n, n)
	for i := 0; i < n; i++ {
		b[i] = make([]node, n, n)
	}

	for i := 0; i < 2*len(b); i++ {
		jj := 0
		ii := i
		if i >= n {
			ii = n - 1
			jj = i - n + 1
		}
		for {
			if ii < 0 || jj == n {
				break
			}
			b[ii][jj] = a[ii][jj]
			v2 := math.MaxInt32
			v5 := math.MaxInt32
			if ii > 0 {
				v2 = min(v2, b[ii-1][jj].twos)
				v5 = min(v5, b[ii-1][jj].fives)
			}
			if jj > 0 {
				v2 = min(v2, b[ii][jj-1].twos)
				v5 = min(v5, b[ii][jj-1].fives)
			}

			if v2 != math.MaxInt32 {
				b[ii][jj].twos += v2
				b[ii][jj].fives += v5
			}
			ii--
			jj++
		}
	}

	if zeroFound && min(b[n-1][n-1].twos, b[n-1][n-1].fives) >= 1 {
		fmt.Println("1")
		for i := 0; i < zeroI; i++ {
			fmt.Print("D")
		}
		for i := 0; i < zeroJ; i++ {
			fmt.Print("R")
		}
		for i := zeroI; i < n-1; i++ {
			fmt.Print("D")
		}
		for i := zeroJ; i < n-1; i++ {
			fmt.Print("R")
		}
		fmt.Println("")
		return
	}

	var using2 bool
	if b[n-1][n-1].fives < b[n-1][n-1].twos {
		using2 = false
		fmt.Println(b[n-1][n-1].fives)
	} else {
		using2 = true
		fmt.Println(b[n-1][n-1].twos)
	}

	i := n - 1
	j := n - 1
	str := make([]rune, (n-1)*2, (n-1)*2)
	idx := len(str) - 1
	for {
		if i == 0 && j == 0 {
			break
		}

		if i == 0 {
			str[idx] = 'R'
			idx--
			j--
			continue
		}
		if j == 0 {
			str[idx] = 'D'
			idx--
			i--
			continue
		}

		if using2 {
			if b[i-1][j].twos <= b[i][j-1].twos {
				str[idx] = 'D'
				idx--
				i--
			} else {
				str[idx] = 'R'
				idx--
				j--
			}
		} else {
			if b[i-1][j].fives <= b[i][j-1].fives {
				str[idx] = 'D'
				idx--
				i--
			} else {
				str[idx] = 'R'
				idx--
				j--
			}
		}
	}
	fmt.Println(string(str))
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func twoOrFives(num int, base int) (times int) {
	times = 0
	for num != 0 && num%base == 0 {
		times++
		num /= base
	}
	return
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func CF2B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	var n, v int
	Fscan(in, &n)
	zx := -1
	dp := make([][][2]int, n)
	for i := range dp {
		dp[i] = make([][2]int, n)
		for j := 0; j < n; j++ {
			Fscan(in, &v)
			if v == 0 {
				zx = i
			}
			for k, d := range []int{2, 5} {
				if i == 0 && j == 0 {
				} else if i == 0 {
					dp[i][j][k] = dp[i][j-1][k]
				} else if j == 0 {
					dp[i][j][k] = dp[i-1][j][k]
				} else {
					dp[i][j][k] = min(dp[i-1][j][k], dp[i][j-1][k])
				}
				if v > 0 {
					for ; v%d == 0; v /= d {
						dp[i][j][k]++
					}
				}
			}
		}
	}

	d := dp[n-1][n-1]
	k := 0
	if d[1] < d[0] {
		k = 1
	}
	if d[k] > 1 && zx != -1 {
		Fprint(out, "1\n", strings.Repeat("D", zx), strings.Repeat("R", n-1), strings.Repeat("D", n-1-zx))
		return
	}
	Fprintln(out, d[k])
	var f func(x, y int)
	f = func(x, y int) {
		if x == 0 && y == 0 {
			return
		}
		if x == 0 || y > 0 && dp[x][y-1][k] < dp[x-1][y][k] {
			f(x, y-1)
			Fprint(out, "R")
		} else {
			f(x-1, y)
			Fprint(out, "D")
		}
	}
	f(n-1, n-1)
}

func main() { CF2B(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func CF2B(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	n := r()
	zx := -1
	dp := make([][][2]int, n)
	for i := range dp {
		dp[i] = make([][2]int, n)
		for j := 0; j < n; j++ {
			v := r()
			if v == 0 {
				zx = i
			}
			for k, d := range []int{2, 5} {
				if i == 0 && j == 0 {
				} else if i == 0 {
					dp[i][j][k] = dp[i][j-1][k]
				} else if j == 0 {
					dp[i][j][k] = dp[i-1][j][k]
				} else {
					dp[i][j][k] = min(dp[i-1][j][k], dp[i][j-1][k])
				}
				if v > 0 {
					for ; v%d == 0; v /= d {
						dp[i][j][k]++
					}
				}
			}
		}
	}

	d := dp[n-1][n-1]
	k := 0
	if d[1] < d[0] {
		k = 1
	}
	if d[k] > 1 && zx != -1 {
		Fprint(out, "1\n", strings.Repeat("D", zx), strings.Repeat("R", n-1), strings.Repeat("D", n-1-zx))
		return
	}
	Fprintln(out, d[k])
	var f func(x, y int)
	f = func(x, y int) {
		if x == 0 && y == 0 {
			return
		}
		if x == 0 || y > 0 && dp[x][y-1][k] < dp[x-1][y][k] {
			f(x, y-1)
			Fprint(out, "R")
		} else {
			f(x-1, y)
			Fprint(out, "D")
		}
	}
	f(n-1, n-1)
}

func main() { CF2B(os.Stdin, os.Stdout) }

package main

import "fmt"
import "os"
import "bufio"
import "container/list"

var n = int(0)
var z = [1000][1000][2]int{}

func min(a int,b int) int{
    if a>b { return b }
    return a
}

func max(a int,b int) int {
    if a > b { return a }
    return b
}

func abs(a int) int{
    if a > 0 { return a }
    return -a
}

func p(a int) (int,int) {

    t := 0
    f := 0

    if a == 0 { return t,f }

    for ;a%5==0;a/=5 {
        f++
    }

    for ;a%2==0;a/=2 {
        t++
    }

    return t,f
}

func isDigit(b byte) bool{
    return b >= '0' && b <= '9'
}

func readLine() error{
    var err error
    _buf,err = _in.ReadBytes('\n')
    _lb = len(_buf)
    _pos = 0
    return err
}

func nextInt() (int,error){

    for digit:=false;!digit; {

        if _pos >= _lb {
            err := readLine()
            if err != nil {
                return -1,err
            }
        }

        for ; _pos < _lb && !digit ; _pos++ {

            digit = isDigit(_buf[_pos])

            if digit {
                break
            }
        }

    }

    r := 0

    for ; _pos < _lb && isDigit(_buf[_pos]) ; {
        r = r*10 + int(_buf[_pos]) - '0'
        _pos++
    }

    return r,nil
}

var (
    _in = bufio.NewReader(os.Stdin)
    _buf []byte
    _lb = int(-1)
    _pos = int(0)
)

func main(){

    n,_ := nextInt()

    v := 0
    zx := -1
    zy := -1

    for i:=0;i<n;i++ {
        for j:=0;j<n;j++ {

            v,_ = nextInt()

            z[i][j][0],z[i][j][1] = p(v)

            if(v == 0){
                zx = i
                zy = j
            }
        }
    }

    for i:=1;i<n;i++{
        z[i][0][0] += z[i-1][0][0]
        z[i][0][1] += z[i-1][0][1]
        z[0][i][0] += z[0][i-1][0]
        z[0][i][1] += z[0][i-1][1]
    }

    for i:=1;i<n;i++ {
        for j:=1;j<n;j++ {
            for k:=0;k<2;k++ {
                z[i][j][k] += min(z[i][j-1][k],z[i-1][j][k])
            }
        }
    }

    var ans = min(z[n-1][n-1][0],z[n-1][n-1][1])

    if zx!=-1 && zy!=-1 && ans > 1 {

        fmt.Println(1)

        x := 0
        y := 0

        for x < zx {
            fmt.Print("D")
            x++
        }

        for y < zy {
            fmt.Print("R")
            y++
        }

        for x < n-1 {
            fmt.Print("D")
            x++
        }

        for y < n-1 {
            fmt.Print("R")
            y++
        }

        fmt.Println()

    } else {

        fmt.Println(ans)

        var k int
        x := n-1
        y := n-1
        xs := list.New()

        if(z[n-1][n-1][0] < z[n-1][n-1][1]) {
            k = 0
        }else{
            k = 1
        }

        for !(x == 0 && y == 0 ) {

            if x==0 {
                xs.PushBack("R")
                y--
            }else if y==0 {
                xs.PushBack("D")
                x--
            }else {

                if z[x-1][y][k] < z[x][y-1][k]{
                    xs.PushBack("D")
                    x--
                }else{
                    xs.PushBack("R")
                    y--
                }
            }

        }

        for e:=xs.Back();e!=nil;e=e.Prev(){
            fmt.Print(e.Value.(string))
        }

        fmt.Println()
    }

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func countFactors(x int, y int) int {
	if x == 0 {
		return 1
	}
	count := 0
	for x > 0 {
		if x%y == 0 {
			count += 1
			x /= y
		} else {
			break
		}
	}
	return count
}

func solveDP(n int, matrix [][]int, k int) (int, string) {
    dp := make([][]int, n)
    for i := range dp {
        dp[i] = make([]int, n)
    }
	for x := 0; x < n; x++ {
		for y := 0; y < n; y++ {
			dp[x][y] = countFactors(matrix[x][y], k)
		}
	}
	for x := 1; x < n; x++ {
		dp[0][x] = dp[0][x] + dp[0][x-1]
		dp[x][0] = dp[x][0] + dp[x-1][0]
	}
	for x := 1; x < n; x++ {
		for y := 1; y < n; y++ {
			if dp[x][y-1] < dp[x-1][y] {
				dp[x][y] += dp[x][y-1]
			} else {
				dp[x][y] += dp[x-1][y]
			}
		}
	}
	i := n - 1
	j := n - 1
	path := ""
	for i != 0 || j != 0 {
		if j == 0 {
			path = "D" + path
			i -= 1
		} else if i == 0 {
			path = "R" + path
			j -= 1
		} else if dp[i][j-1] < dp[i-1][j] {
			path = "R" + path
			j -= 1
		} else {
			path = "D" + path
			i -= 1
		}
	}
	return dp[n-1][n-1], path
}

func min(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

func getZero(n int, matrix [][]int) (int, int) {
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if matrix[i][j] == 0 {
				return i, j
			}
		}
	}
	return -1, -1
}

func solve(n int, matrix [][]int) (int, string) {
	twosPathLength, twosPath := solveDP(n, matrix, 2)
	fivesPathLength, fivesPath := solveDP(n, matrix, 5)
	zeroI, zeroJ := getZero(n, matrix)
	if zeroI != -1 && zeroJ != -1 && min(twosPathLength, fivesPathLength) > 1 {
		return 1, strings.Repeat("D", zeroI) + strings.Repeat("R", zeroJ) + strings.Repeat("D", n-zeroI-1) + strings.Repeat("R", n-zeroJ-1)
	}
	if twosPathLength < fivesPathLength {
		return twosPathLength, twosPath
	}
	return fivesPathLength, fivesPath
}

func parseInput() (int, [][]int) {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	matrix := make([][]int, n)
	for i := range matrix {
		matrix[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Fscanf(reader, "%d", &matrix[i][j])
		}
		fmt.Fscanf(reader, "\n")
	}
	return n, matrix
}

func main() {
	n, matrix := parseInput()
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	pathLength, path := solve(n, matrix)
	fmt.Fprintf(writer, "%d\n%s\n", pathLength, path)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	mat := make([][]int, n)
	dp := make([][]int, n)
	path := make([][]byte, n)

	for i := 0; i < n; i++ {
		mat[i] = make([]int, n)
		dp[i] = make([]int, n)
		path[i] = make([]byte, n)
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &mat[i][j])
			dp[i][j] = 9999
		}
		fmt.Scanf("\n")
	}

	if mat[0][0] == 0 {
		dp[0][0] = 1
	} else {
		dp[0][0] = 0
	}

	for i := 1; i < 2*n-1; i++ {
		for j := 0; j < n; j++ {
			if i-j >= n || i-j < 0 {
				continue
			}
			if j != 0 {
				if dp[j-1][i-j] < dp[j][i-j] {
					dp[j][i-j] = dp[j-1][i-j]
					path[j][i-j] = 'D'
				}
			}
			if i-j != 0 {
				if dp[j][i-j-1] < dp[j][i-j] {
					dp[j][i-j] = dp[j][i-j-1]
					path[j][i-j] = 'R'
				}
			}
			if mat[j][i-j] == 0 {
				dp[j][i-j]++
			}
		}
	}
	fmt.Printf("%d\n", dp[n-1][n-1])

	bestPath := make([]byte, 2*(n-1))
	for y, x, pos := n-1, n-1, 2*(n-1)-1; y != 0 || x != 0; pos-- {
		bestPath[pos] = path[y][x]
		if path[y][x] == 'D' {
			y--
		} else {
			x--
		}
	}
	fmt.Printf("%s", string(bestPath))
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	mat := make([][]int, n)
	dp := make([][]int, n)
	path := make([][]byte, n)

	for i := 0; i < n; i++ {
		mat[i] = make([]int, n)
		dp[i] = make([]int, n)
		path[i] = make([]byte, n)
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &mat[i][j])
			dp[i][j] = 9999
		}
	}

	if mat[0][0] == 0 {
		dp[0][0] = 1
	} else {
		dp[0][0] = 0
	}

	for i := 1; i < 2*n-1; i++ {
		for j := 0; j < n; j++ {
			if i-j >= n || i-j < 0 {
				continue
			}
			if j != 0 {
				if dp[j-1][i-j] < dp[j][i-j] {
					dp[j][i-j] = dp[j-1][i-j]
					path[j][i-j] = 'D'
				}
			}
			if i-j != 0 {
				if dp[j][i-j-1] < dp[j][i-j] {
					dp[j][i-j] = dp[j][i-j-1]
					path[j][i-j] = 'R'
				}
			}
			if mat[j][i-j] == 0 {
				dp[j][i-j]++
			}
		}
	}
	fmt.Printf("%d\n", dp[n-1][n-1])

	bestPath := make([]byte, 2*(n-1))
	for y, x, pos := n-1, n-1, 2*(n-1)-1; y != 0 || x != 0; pos-- {
		bestPath[pos] = path[y][x]
		if path[y][x] == 'D' {
			y--
		} else {
			x--
		}
	}
	fmt.Printf("%s", string(bestPath))
}

package main

import (
	"fmt"
)

type Factor struct {
	Zero int
	Two  int
	Five int
}

func getFactor(n int) Factor {
	ret := Factor{}
	for ; n%10 == 0; n = n / 10 {
		ret.Zero++
	}
	for ; n%2 == 0; n = n / 2 {
		ret.Two++
	}
	for ; n%5 == 0; n = n / 5 {
		ret.Five++
	}
	return ret
}

type Status struct {
	Two     map[int]int
	TwoDir  map[int]string
	Five    map[int]int
	FiveDir map[int]string
}

func main() {
	var n int
	containZero := false
	var zy, zx int
	fmt.Scanf("%d\n", &n)
	mat := make([][]int, n)
	fac := make([][]Factor, n)
	dp := make([][]Status, n)
	path := make([][]string, n)

	for i := 0; i < n; i++ {
		mat[i] = make([]int, n)
		fac[i] = make([]Factor, n)
		dp[i] = make([]Status, n)
		path[i] = make([]string, n)
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &mat[i][j])
			if mat[i][j] == 0 {
				containZero = true
				zy = i
				zx = j
			}
			if mat[i][j] != 0 {
				fac[i][j] = getFactor(mat[i][j])
				dp[i][j] = Status{
					map[int]int{},
					map[int]string{},
					map[int]int{},
					map[int]string{},
				}
			}
		}
		fmt.Scanf("\n")
	}

	if mat[0][0] == 0 || mat[n-1][n-1] == 0 {
		fmt.Printf("0\n")
		for i := 0; i < n-1; i++ {
			fmt.Printf("DR")
		}
		return
	}
	if fac[0][0].Two == 0 {
		dp[0][0].Five[fac[0][0].Zero] = fac[0][0].Five
	}
	if fac[0][0].Five == 0 {
		dp[0][0].Two[fac[0][0].Zero] = fac[0][0].Two
	}
	for i := 0; i < 2*n-2; i++ {
		for j := 0; j < n; j++ {
			if i-j < 0 || i-j >= n {
				continue
			}
			if mat[j][i-j] == 0 {
				continue
			}

			for zero, two := range dp[j][i-j].Two {
				y := j
				x := i - j
				y1 := j + 1
				x1 := i - j + 1
				if x1 < n && mat[y][x1] != 0 {
					z := fac[y][x1].Zero
					five := fac[y][x1].Five
					if five > two {
						v, ok := dp[y][x1].Five[z+zero+two]
						if !ok || (ok && v > five-two) {
							dp[y][x1].Five[z+zero+two] = five - two
							dp[y][x1].FiveDir[z+zero+two] = dp[y][x].TwoDir[zero] + "R"
						}
					} else {
						v, ok := dp[y][x1].Two[z+zero+five]
						if !ok || (ok && v > two-five) {
							dp[y][x1].Two[z+zero+five] = two - five
							dp[y][x1].TwoDir[z+zero+five] = dp[y][x].TwoDir[zero] + "R"
						}
					}
				}
				if y1 < n && mat[y1][x] != 0 {
					z := fac[y1][x].Zero
					five := fac[y1][x].Five
					if five > two {
						v, ok := dp[y1][x].Five[z+zero+two]
						if !ok || (ok && v > five-two) {
							dp[y1][x].Five[z+zero+two] = five - two
							dp[y1][x].FiveDir[z+zero+two] = dp[y][x].TwoDir[zero] + "D"
						}
					} else {
						v, ok := dp[y1][x].Two[z+zero+five]
						if !ok || (ok && v > two-five) {
							dp[y1][x].Two[z+zero+five] = two - five
							dp[y1][x].TwoDir[z+zero+five] = dp[y][x].TwoDir[zero] + "D"
						}
					}
				}
			}
			for zero, five := range dp[j][i-j].Five {
				y := j
				x := i - j
				y1 := j + 1
				x1 := i - j + 1
				if x1 < n && mat[y][x1] != 0 {
					z := fac[y][x1].Zero
					two := fac[y][x1].Two
					if two > five {
						v, ok := dp[y][x1].Two[z+zero+five]
						if !ok || (ok && v > two-five) {
							dp[y][x1].Two[z+zero+five] = two - five
							dp[y][x1].TwoDir[z+zero+five] = dp[y][x].FiveDir[zero] + "R"
						}
					} else {
						v, ok := dp[y][x1].Two[z+zero+two]
						if !ok || (ok && v > five-two) {
							dp[y][x1].Five[z+zero+two] = five - two
							dp[y][x1].FiveDir[z+zero+two] = dp[y][x].FiveDir[zero] + "R"
						}
					}
				}
				if y1 < n && mat[y1][x] != 0 {
					z := fac[y1][x].Zero
					two := fac[y1][x].Two
					if two > five {
						v, ok := dp[y1][x].Two[z+zero+five]
						if !ok || (ok && v > two-five) {
							dp[y1][x].Two[z+zero+five] = two - five
							dp[y1][x].TwoDir[z+zero+five] = dp[y][x].FiveDir[zero] + "D"
						}
					} else {
						v, ok := dp[y1][x].Two[z+zero+two]
						if !ok || (ok && v > five-two) {
							dp[y1][x].Five[z+zero+two] = five - two
							dp[y1][x].FiveDir[z+zero+two] = dp[y][x].FiveDir[zero] + "D"
						}
					}
				}
			}
		}
	}

	min := 999999999
	solution := ""
	for zero, _ := range dp[n-1][n-1].Two {
		if min > zero {
			min = zero
			solution = dp[n-1][n-1].TwoDir[zero]
		}
	}
	for zero, _ := range dp[n-1][n-1].Five {
		if min > zero {
			min = zero
			solution = dp[n-1][n-1].FiveDir[zero]
		}
	}

	if containZero && min > 1 {
		fmt.Printf("1\n")
		for cx := 0; cx < zx; cx++ {
			fmt.Printf("R")
		}
		for cy := 0; cy < zy; cy++ {
			fmt.Printf("D")
		}
		for cx := zx; cx < n-1; cx++ {
			fmt.Printf("R")
		}
		for cy := zy; cy < n-1; cy++ {
			fmt.Printf("D")
		}
	} else {
		fmt.Printf("%d\n%s", min, solution)
	}
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	mat := make([][]int, n)
	dp := make([][]int, n)
	path := make([][]byte, n)

	for i := 0; i < n; i++ {
		mat[i] = make([]int, n)
		dp[i] = make([]int, n)
		path[i] = make([]byte, n)
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &mat[i][j])
			dp[i][j] = 9999
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Printf("%d ", mat[i][j])
		}
		fmt.Printf("\n")
	}

	if mat[0][0] == 0 {
		dp[0][0] = 1
	} else {
		dp[0][0] = 0
	}

	for i := 1; i < 2*n-1; i++ {
		for j := 0; j < n; j++ {
			if i-j >= n || i-j < 0 {
				continue
			}
			if j != 0 {
				if dp[j-1][i-j] < dp[j][i-j] {
					dp[j][i-j] = dp[j-1][i-j]
					path[j][i-j] = 'D'
				}
			}
			if i-j != 0 {
				if dp[j][i-j-1] < dp[j][i-j] {
					dp[j][i-j] = dp[j][i-j-1]
					path[j][i-j] = 'R'
				}
			}
			if mat[j][i-j] == 0 {
				dp[j][i-j]++
			}
		}
	}
	fmt.Printf("%d\n", dp[n-1][n-1])

	bestPath := make([]byte, 2*(n-1))
	for y, x, pos := n-1, n-1, 2*(n-1)-1; y != 0 || x != 0; pos-- {
		bestPath[pos] = path[y][x]
		if path[y][x] == 'D' {
			y--
		} else {
			x--
		}
	}
	fmt.Printf("%s", string(bestPath))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	n := readNum(reader)
	M := make([][]int, n)
	for i := 0; i < n; i++ {
		M[i] = readNNums(reader, n)
	}
	best, path := solve(n, M)
	fmt.Println(best)
	fmt.Println(path)
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const INF = 1 << 30
func solve(n int, M [][]int) (int, string) {
	a, x := getMinCountPath(n, M, 2, INF)
	b, y := getMinCountPath(n, M, 5, a)

	if a < b {
		return a, x
	}
	return b, y
}

func getMinCountPath(n int, M [][]int, div int, limit int) (int, string) {
	dp := make([][]int, n)
	cnt := make([][]int, n)
	for i := 0; i < n; i++ {
		dp[i] = make([]int, n)
		cnt[i] = make([]int, n)
		for j := 0; j < n; j++ {
			cnt[i][j] = count(M[i][j], div)
		}
	}

	get := func(i, j int) int {
		if i < 0 || j < 0 {
			return INF
		}
		return dp[i][j]
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == 0 && j == 0 {
				dp[i][j] = 0
			} else {
				dp[i][j] = min(get(i - 1, j), get(i, j - 1))
			}
			dp[i][j] += cnt[i][j]
		}
	}

	best := dp[n-1][n-1]

	if best >= limit {
		return best, ""
	}

	res := make([]byte, 0, 2 * n - 1)

	x, y := n - 1, n - 1

	for x >= 0 && y >= 0 {
		cur := dp[x][y]
		if x > 0 && dp[x-1][y] == cur - cnt[x][y] {
			x--
			res = append(res, 'D')
		} else {
			y--
			res = append(res, 'R')
		}
		if x == 0 && y == 0 {
			break
		}
	}

	reverse(res)

	return best, string(res)
}

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func count(num int, div int) int {
	var res int
	for num % div == 0 {
		num /= div
		res++
	}
	return res
}

func reverse(buf []byte) {
	for i, j := 0, len(buf) - 1; i < j; i, j = i + 1, j - 1 {
		buf[i], buf[j] = buf[j], buf[i]
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

const N = 1000
var dp [N][N]int
var cnt [N][N]int

func main() {
	reader := bufio.NewReader(os.Stdin)

	n := readNum(reader)
	M := make([][]int, n)
	for i := 0; i < n; i++ {
		M[i] = readNNums(reader, n)
	}
	best, path := solve(n, M)
	fmt.Println(best)
	fmt.Println(path)
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const INF = 1 << 30

func solve(n int, M [][]int) (int, string) {
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if M[i][j] == 0 {
				M[i][j] = 10
			}
		}
	}
	a, x := getMinCountPath(n, M, 2, INF)
	b, y := getMinCountPath(n, M, 5, a)

	if a <= b {
		return a, x
	}
	return b, y
}

func getMinCountPath(n int, M [][]int, div int, limit int) (int, string) {
	//dp := make([][]int, n)
	//cnt := make([][]int, n)
	for i := 0; i < n; i++ {
		//dp[i] = make([]int, n)
		//cnt[i] = make([]int, n)
		for j := 0; j < n; j++ {
			cnt[i][j] = count(M[i][j], div)
			//dp[i][j] = 0
		}
	}

	get := func(i, j int) int {
		if i < 0 || j < 0 {
			return INF
		}
		return dp[i][j]
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			dp[i][j] = cnt[i][j]
			if i > 0 || j > 0 {
				dp[i][j] += min(get(i-1, j), get(i, j-1))
			}
		}
	}

	best := dp[n-1][n-1]

	if best >= limit {
		return best, ""
	}

	res := make([]byte, 0, 2*n-1)

	x, y := n-1, n-1

	for x >= 0 && y >= 0 {
		cur := dp[x][y]
		if x > 0 && dp[x-1][y] == cur-cnt[x][y] {
			x--
			res = append(res, 'D')
		} else {
			y--
			res = append(res, 'R')
		}
		if x == 0 && y == 0 {
			break
		}
	}

	reverse(res)

	return best, string(res)
}

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func count(num int, div int) int {
	if div == 2 {
		c := 32 // c will be the number of zero bits on the right
		num &= -num
		if num > 0 {
			c--
		}
		if num&0x0000FFFF > 0 {
			c -= 16
		}
		if num&0x00FF00FF > 0 {
			c -= 8
		}
		if num&0x0F0F0F0F > 0 {
			c -= 4
		}
		if num&0x33333333 > 0 {
			c -= 2
		}
		if num&0x55555555 > 0 {
			c -= 1
		}
		return c
	}
	var res int
	for num%div == 0 {
		num /= div
		res++
	}
	return res
}

func reverse(buf []byte) {
	for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {
		buf[i], buf[j] = buf[j], buf[i]
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var debug = false

type node struct {
	twos, fives int
	val         int
}

func solve() {
	n := readInt()

	a := make([][]node, n, n)
	for i, _ := range a {
		a[i] = make([]node, n, n)
	}

	zeroFound := false
	var zeroi, zeroj int

	for i, _ := range a {
		for j, _ := range a[i] {
			v := readInt()
			a[i][j].fives = fives(v)
			a[i][j].twos = twos(v)
			a[i][j].val = v
			if v == 0 {
				zeroFound = true
				zeroi = i
				zeroj = j
			}
		}
	}

	if zeroFound {
		for i := 0; i < zeroi; i++ {
			fmt.Println("D")
		}
		for i := 0; i < zeroj; i++ {
			fmt.Println("R")
		}
		for i := zeroi; i < n; i++ {
			fmt.Println("D")
		}
		for i := zeroj; i < n; i++ {
			fmt.Println("R")
		}
		return
	}

	b := make([][]node, n, n)
	for i, _ := range b {
		b[i] = make([]node, n, n)
	}

	// Compute the minimum path to "this" point (it's the minimum
	// of the path cost of its 0, 1, or 2 predecessors plus its
	// own cost).
	for i := 0; i < 2*len(b); i++ {
		jj := 0
		ii := i
		if i >= n {
			ii = n - 1
			jj = i - n + 1
		}
		for {
			if ii < 0 || jj == n {
				break
			}

			if debug {
				fmt.Print("Set(", ii, jj, ")")
			}
			b[ii][jj] = a[ii][jj]
			v2 := math.MaxInt32
			v5 := math.MaxInt32
			if ii > 0 {
				v2 = min(v2, b[ii-1][jj].twos)
				v5 = min(v5, b[ii-1][jj].fives)
			}
			if jj > 0 {
				v2 = min(v2, b[ii][jj-1].twos)
				v5 = min(v5, b[ii][jj-1].fives)
			}

			if v2 != math.MaxInt32 {
				b[ii][jj].twos += v2
				b[ii][jj].fives += v5
			}

			ii--
			jj++
		}
		if debug {
			fmt.Println("")
		}
	}

	using2 := true
	if b[n-1][n-1].fives < b[n-1][n-1].twos {
		using2 = false
	}

	if debug {
		fmt.Println(a)
		fmt.Println(b)
	}

	// Now, find the path
	i := n - 1
	j := n - 1
	str := make([]rune, (n-1)*2, (n-1)*2)
	idx := len(str) - 1
	zeros := 0

	for {
		if using2 {
			zeros += a[i][j].twos
		} else {
			zeros += a[i][j].fives
		}

		if i == 0 && j == 0 {
			break
		}

		if i == 0 {
			str[idx] = 'R'
			idx--
			j--
			continue
		}
		if j == 0 {
			str[idx] = 'D'
			idx--
			i--
			continue
		}

		if using2 {
			if b[i-1][j].twos <= b[i][j-1].twos {
				str[idx] = 'D'
				idx--
				i--
			} else {
				str[idx] = 'R'
				idx--
				j--
			}
		} else {
			if b[i-1][j].fives <= b[i][j-1].fives {
				str[idx] = 'D'
				idx--
				i--
			} else {
				str[idx] = 'R'
				idx--
				j--
			}
		}
	}
	fmt.Println(zeros)
	fmt.Println(string(str))

	if debug {
		acc := a[n-1][n-1].val
		i = 0
		j = 0
		idx = 0
		for i != n-1 || j != n-1 {
			acc *= a[i][j].val
			fmt.Println("V(", i, j, a[i][j].val, ")")
			switch str[idx] {
			case 'R':
				j++
				break
			case 'D':
				i++
				break
			}
			idx++
		}
		fmt.Println("V(", n-1, n-1, a[n-1][n-1].val, ")")
		fmt.Println("Accum", acc)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func twos(i int) (n int) {
	n = 0
	for ; i > 0; i /= 2 {
		if i%2 != 0 {
			break
		}
		n++
	}
	return
}

func fives(i int) (n int) {
	n = 0
	for ; i > 0; i /= 5 {
		if i%5 != 0 {
			break
		}
		n++
	}
	return
}

func nzeros(i int) int {
	var cnt int
	for {
		if i%10 != 0 {
			break
		}
		i /= 10
		cnt++
		if i < 10 {
			break
		}
	}
	return cnt
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func solve() {
	n := readInt()

	a := make([][]int, n, n)
	for i, _ := range a {
		a[i] = make([]int, n, n)
	}

	for i, _ := range a {
		for j, _ := range a[i] {
			a[i][j] = nzeros(readInt())
		}
	}

	b := make([][]int, n, n)
	for i, _ := range b {
		b[i] = make([]int, n, n)
	}

	// Compute the minimum path to "this" point (it's the minimum
	// of the path cost of its 0, 1, or 2 predecessors plus its
	// own cost).
	for i, _ := range b {
		jj := 0
		for ii := i; ii >= 0; ii-- {
			b[ii][jj] = a[ii][jj]
			v := math.MaxInt32
			if ii > 0 {
				v = min(v, b[ii-1][jj])
			}
			if jj > 0 {
				v = min(v, b[ii][jj-1])
			}
			if v != math.MaxInt32 {
				b[ii][jj] += v
			}
			jj++
		}
	}

	fmt.Println(b[n-1][n-1])
	// Now, find the path
	i := 0
	j := 0
	for {
		if i == n-1 && j == n-1 {
			break
		}
		if i == n-1 {
			fmt.Print("R")
			j++
			continue
		}
		if j == n-1 {
			fmt.Print("D")
			i++
			continue
		}

		if b[i+1][j] <= b[i][j+1] {
			fmt.Print("D")
			i++
		} else {
			fmt.Print("R")
			j++
		}
	}
	fmt.Println("")
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func nzeros(i int) int {
	var cnt int
	for {
		if i%10 != 0 {
			break
		}
		i /= 10
		cnt++
		if i < 10 {
			break
		}
	}
	return cnt
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var debug = false

type node struct {
	twos, fives int
	val         int
}

func solve() {
	n := readInt()

	a := make([][]node, n, n)
	for i, _ := range a {
		a[i] = make([]node, n, n)
	}

	zeroFound := false
	var zeroi, zeroj int

	for i, _ := range a {
		for j, _ := range a[i] {
			v := readInt()
			a[i][j].fives = fives(v)
			a[i][j].twos = twos(v)
			a[i][j].val = v
			if v == 0 {
				zeroFound = true
				zeroi = i
				zeroj = j
			}
		}
	}

	if zeroFound {
		for i := 0; i < zeroi; i++ {
			fmt.Println("D")
		}
		for i := 0; i < zeroj; i++ {
			fmt.Println("R")
		}
		for i := zeroi; i < n; i++ {
			fmt.Println("D")
		}
		for i := zeroj; i < n; i++ {
			fmt.Println("R")
		}
		return
	}

	b := make([][]node, n, n)
	for i, _ := range b {
		b[i] = make([]node, n, n)
	}

	// Compute the minimum path to "this" point (it's the minimum
	// of the path cost of its 0, 1, or 2 predecessors plus its
	// own cost).
	for i := 0; i < 2*len(b); i++ {
		jj := 0
		ii := i
		if i >= n {
			ii = n - 1
			jj = i - n
		}
		for {
			if ii < 0 || jj == n {
				break
			}

			b[ii][jj] = a[ii][jj]
			v2 := math.MaxInt32
			v5 := math.MaxInt32
			if ii > 0 {
				v2 = min(v2, b[ii-1][jj].twos)
				v5 = min(v2, b[ii-1][jj].fives)
			}
			if jj > 0 {
				v2 = min(v2, b[ii][jj-1].twos)
				v5 = min(v5, b[ii][jj-1].fives)
			}

			if v2 != math.MaxInt32 {
				b[ii][jj].twos += v2
				b[ii][jj].fives += v5
			}

			ii--
			jj++
		}
	}

	using2 := true
	if b[n-1][n-1].fives < b[n-1][n-1].twos {
		using2 = false
	}

	if debug {
		fmt.Println(a)
		fmt.Println(b)
	}

	fmt.Println(min(b[n-1][n-1].twos, b[n-1][n-1].fives))

	// Now, find the path
	i := n - 1
	j := n - 1
	idx := n
	str := make([]rune, n+1, n+1)

	for {
		if i == 0 && j == 0 {
			break
		}

		if i == 0 {
			str[idx] = 'R'
			idx--
			j--
			continue
		}
		if j == 0 {
			str[idx] = 'D'
			idx--
			i--
			continue
		}

		if using2 {
			if b[i-1][j].twos <= b[i][j-1].twos {
				str[idx] = 'D'
				idx--
				i--
			} else {
				str[idx] = 'R'
				idx--
				j--
			}
		} else {
			if b[i-1][j].fives <= b[i][j-1].fives {
				str[idx] = 'D'
				idx--
				i--
			} else {
				str[idx] = 'R'
				idx--
				j--
			}
		}
	}
	fmt.Println(string(str))

	if debug {
		acc := a[n-1][n-1].val
		i = 0
		j = 0
		idx = 0
		for i != n-1 || j != n-1 {
			acc *= a[i][j].val
			fmt.Println("V(", i, j, a[i][j].val, ")")
			switch str[idx] {
			case 'R':
				j++
				break
			case 'D':
				i++
				break
			}
			idx++
		}

		fmt.Println("Accum", acc)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func twos(i int) (n int) {
	n = 0
	for ; i > 0; i /= 2 {
		if i%2 != 0 {
			break
		}
		n++
	}
	return
}

func fives(i int) (n int) {
	n = 0
	for ; i > 0; i /= 5 {
		if i%5 != 0 {
			break
		}
		n++
	}
	return
}

func nzeros(i int) int {
	var cnt int
	for {
		if i%10 != 0 {
			break
		}
		i /= 10
		cnt++
		if i < 10 {
			break
		}
	}
	return cnt
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func solve() {
	n := readInt()

	a := make([][]int, n, n)
	for i, _ := range a {
		a[i] = make([]int, n, n)
	}

	for i, _ := range a {
		for j, _ := range a[i] {
			a[i][j] = nzeros(readInt())
		}
	}

	b := make([][]int, n, n)
	for i, _ := range b {
		b[i] = make([]int, n, n)
	}

	// Compute the minimum path to "this" point (it's the minimum
	// of the path cost of its 0, 1, or 2 predecessors plus its
	// own cost).
	for i := 0; i < 2*len(b); i++ {
		jj := 0
		ii := i
		if i >= n {
			ii = n - 1
			jj = i - n
		}
		for {
			if ii < 0 || jj == n {
				break
			}

			b[ii][jj] = a[ii][jj]
			v := math.MaxInt32
			if ii > 0 {
				v = min(v, b[ii-1][jj])
			}
			if jj > 0 {
				v = min(v, b[ii][jj-1])
			}
			if v != math.MaxInt32 {
				b[ii][jj] += v
			}

			ii--
			jj++
		}
	}

	fmt.Println(b[n-1][n-1])
	// Now, find the path
	i := 0
	j := 0
	for {
		if i == n-1 && j == n-1 {
			break
		}
		if i == n-1 {
			fmt.Print("R")
			j++
			continue
		}
		if j == n-1 {
			fmt.Print("D")
			i++
			continue
		}

		if b[i+1][j] <= b[i][j+1] {
			fmt.Print("D")
			i++
		} else {
			fmt.Print("R")
			j++
		}
	}
	fmt.Println("")
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func nzeros(i int) int {
	var cnt int
	for {
		if i%10 != 0 {
			break
		}
		i /= 10
		cnt++
		if i < 10 {
			break
		}
	}
	return cnt
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var debug = false

type node struct {
	twos, fives int
	val         int
}

func solve() {
	n := readInt()

	a := make([][]node, n, n)
	for i, _ := range a {
		a[i] = make([]node, n, n)
	}

	zeroFound := false
	var zeroi, zeroj int

	for i, _ := range a {
		for j, _ := range a[i] {
			v := readInt()
			a[i][j].fives = fives(v)
			a[i][j].twos = twos(v)
			a[i][j].val = v
			if v == 0 {
				zeroFound = true
				zeroi = i
				zeroj = j
			}
		}
	}

	if zeroFound {
		for i := 0; i < zeroi; i++ {
			fmt.Println("D")
		}
		for i := 0; i < zeroj; i++ {
			fmt.Println("R")
		}
		for i := zeroi; i < n; i++ {
			fmt.Println("D")
		}
		for i := zeroj; i < n; i++ {
			fmt.Println("R")
		}
		return
	}

	b := make([][]node, n, n)
	for i, _ := range b {
		b[i] = make([]node, n, n)
	}

	// Compute the minimum path to "this" point (it's the minimum
	// of the path cost of its 0, 1, or 2 predecessors plus its
	// own cost).
	for i := 0; i < 2*len(b); i++ {
		jj := 0
		ii := i
		if i >= n {
			ii = n - 1
			jj = i - n
		}
		for {
			if ii < 0 || jj == n {
				break
			}

			b[ii][jj] = a[ii][jj]
			v2 := math.MaxInt32
			v5 := math.MaxInt32
			if ii > 0 {
				v2 = min(v2, b[ii-1][jj].twos)
				v5 = min(v2, b[ii-1][jj].fives)
			}
			if jj > 0 {
				v2 = min(v2, b[ii][jj-1].twos)
				v5 = min(v5, b[ii][jj-1].fives)
			}

			if v2 != math.MaxInt32 {
				b[ii][jj].twos += v2
				b[ii][jj].fives += v5
			}

			ii--
			jj++
		}
	}

	using2 := true
	if b[n-1][n-1].fives < b[n-1][n-1].twos {
		using2 = false
	}

	if debug {
		fmt.Println(a)
		fmt.Println(b)
	}

	// Now, find the path
	i := n - 1
	j := n - 1
	str := make([]rune, (n-1)*2, (n-1)*2)
	idx := len(str) - 1
	zeros := 0

	for {
		if using2 {
			zeros += a[i][j].twos
		} else {
			zeros += a[i][j].fives
		}

		if i == 0 && j == 0 {
			break
		}

		if i == 0 {
			str[idx] = 'R'
			idx--
			j--
			continue
		}
		if j == 0 {
			str[idx] = 'D'
			idx--
			i--
			continue
		}

		if using2 {
			if b[i-1][j].twos <= b[i][j-1].twos {
				str[idx] = 'D'
				idx--
				i--
			} else {
				str[idx] = 'R'
				idx--
				j--
			}
		} else {
			if b[i-1][j].fives <= b[i][j-1].fives {
				str[idx] = 'D'
				idx--
				i--
			} else {
				str[idx] = 'R'
				idx--
				j--
			}
		}
	}
	fmt.Println(zeros)
	fmt.Println(string(str))

	if debug {
		acc := a[n-1][n-1].val
		i = 0
		j = 0
		idx = 0
		for i != n-1 || j != n-1 {
			acc *= a[i][j].val
			fmt.Println("V(", i, j, a[i][j].val, ")")
			switch str[idx] {
			case 'R':
				j++
				break
			case 'D':
				i++
				break
			}
			idx++
		}
		fmt.Println("V(", n-1, n-1, a[n-1][n-1].val, ")")
		fmt.Println("Accum", acc)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func twos(i int) (n int) {
	n = 0
	for ; i > 0; i /= 2 {
		if i%2 != 0 {
			break
		}
		n++
	}
	return
}

func fives(i int) (n int) {
	n = 0
	for ; i > 0; i /= 5 {
		if i%5 != 0 {
			break
		}
		n++
	}
	return
}

func nzeros(i int) int {
	var cnt int
	for {
		if i%10 != 0 {
			break
		}
		i /= 10
		cnt++
		if i < 10 {
			break
		}
	}
	return cnt
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

type node struct {
	twos, fives int
}

func solve() {
	n := readInt()

	a := make([][]node, n, n)
	for i, _ := range a {
		a[i] = make([]node, n, n)
	}

	zeroFound := false
	var zeroi, zeroj int

	for i, _ := range a {
		for j, _ := range a[i] {
			v := readInt()
			a[i][j].fives = fives(v)
			a[i][j].twos = twos(v)
			if v == 0 {
				zeroFound = true
				zeroi = i
				zeroj = j
			}
		}
	}

	if zeroFound {
		for i := 0; i < zeroi; i++ {
			fmt.Println("D")
		}
		for i := 0; i < zeroj; i++ {
			fmt.Println("R")
		}
		for i := zeroi; i < n; i++ {
			fmt.Println("D")
		}
		for i := zeroj; i < n; i++ {
			fmt.Println("R")
		}
		return
	}

	b := make([][]node, n, n)
	for i, _ := range b {
		b[i] = make([]node, n, n)
	}

	// Compute the minimum path to "this" point (it's the minimum
	// of the path cost of its 0, 1, or 2 predecessors plus its
	// own cost).
	for i := 0; i < 2*len(b); i++ {
		jj := 0
		ii := i
		if i >= n {
			ii = n - 1
			jj = i - n
		}
		for {
			if ii < 0 || jj == n {
				break
			}

			b[ii][jj] = a[ii][jj]
			v2 := math.MaxInt32
			v5 := math.MaxInt32
			if ii > 0 {
				v2 = min(v2, b[ii-1][jj].twos)
				v5 = min(v2, b[ii-1][jj].fives)
			}
			if jj > 0 {
				v2 = min(v2, b[ii][jj-1].twos)
				v5 = min(v5, b[ii][jj-1].fives)
			}

			if v2 != math.MaxInt32 {
				b[ii][jj].twos += v2
				b[ii][jj].fives += v5
			}

			ii--
			jj++
		}
	}

	using2 := true
	if b[n-1][n-1].fives < b[n-1][n-1].twos {
		using2 = false
	}

	fmt.Println(min(b[n-1][n-1].twos, b[n-1][n-1].fives))

	// Now, find the path
	i := 0
	j := 0
	for {
		if i == n-1 && j == n-1 {
			break
		}
		if i == n-1 {
			fmt.Print("R")
			j++
			continue
		}
		if j == n-1 {
			fmt.Print("D")
			i++
			continue
		}

		if using2 {
			if b[i+1][j].twos <= b[i][j+1].twos {
				fmt.Print("D")
				i++
			} else {
				fmt.Print("R")
				j++
			}
		} else {
			if b[i+1][j].fives <= b[i][j+1].fives {
				fmt.Print("D")
				i++
			} else {
				fmt.Print("R")
				j++
			}
		}
	}
	fmt.Println("")
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func twos(i int) (n int) {
	n = 0
	for ; i > 0; i /= 2 {
		if i%2 != 0 {
			break
		}
		n++
	}
	return
}

func fives(i int) (n int) {
	n = 0
	for ; i > 0; i /= 5 {
		if i%5 != 0 {
			break
		}
		n++
	}
	return
}

func nzeros(i int) int {
	var cnt int
	for {
		if i%10 != 0 {
			break
		}
		i /= 10
		cnt++
		if i < 10 {
			break
		}
	}
	return cnt
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var debug = false

type node struct {
	twos, fives int
	val         int
}

func solve() {
	n := readInt()

	a := make([][]node, n, n)
	for i, _ := range a {
		a[i] = make([]node, n, n)
	}

	zeroFound := false
	var zeroi, zeroj int

	for i, _ := range a {
		for j, _ := range a[i] {
			v := readInt()
			a[i][j].fives = fives(v)
			a[i][j].twos = twos(v)
			a[i][j].val = v
			if v == 0 {
				zeroFound = true
				zeroi = i
				zeroj = j
			}
		}
	}

	if zeroFound {
		for i := 0; i < zeroi; i++ {
			fmt.Println("D")
		}
		for i := 0; i < zeroj; i++ {
			fmt.Println("R")
		}
		for i := zeroi; i < n; i++ {
			fmt.Println("D")
		}
		for i := zeroj; i < n; i++ {
			fmt.Println("R")
		}
		return
	}

	b := make([][]node, n, n)
	for i, _ := range b {
		b[i] = make([]node, n, n)
	}

	// Compute the minimum path to "this" point (it's the minimum
	// of the path cost of its 0, 1, or 2 predecessors plus its
	// own cost).
	for i := 0; i < 2*len(b); i++ {
		jj := 0
		ii := i
		if i >= n {
			ii = n - 1
			jj = i - n
		}
		for {
			if ii < 0 || jj == n {
				break
			}

			b[ii][jj] = a[ii][jj]
			v2 := math.MaxInt32
			v5 := math.MaxInt32
			if ii > 0 {
				v2 = min(v2, b[ii-1][jj].twos)
				v5 = min(v2, b[ii-1][jj].fives)
			}
			if jj > 0 {
				v2 = min(v2, b[ii][jj-1].twos)
				v5 = min(v5, b[ii][jj-1].fives)
			}

			if v2 != math.MaxInt32 {
				b[ii][jj].twos += v2
				b[ii][jj].fives += v5
			}

			ii--
			jj++
		}
	}

	using2 := true
	if b[n-1][n-1].fives < b[n-1][n-1].twos {
		using2 = false
	}

	if debug {
		fmt.Println(a)
		fmt.Println(b)
	}

	fmt.Println(min(b[n-1][n-1].twos, b[n-1][n-1].fives))

	// Now, find the path
	i := n - 1
	j := n - 1
	str := make([]rune, (n-1)*2, (n-1)*2)
	idx := len(str) - 1

	for {
		if i == 0 && j == 0 {
			break
		}

		if i == 0 {
			str[idx] = 'R'
			idx--
			j--
			continue
		}
		if j == 0 {
			str[idx] = 'D'
			idx--
			i--
			continue
		}

		if using2 {
			if b[i-1][j].twos <= b[i][j-1].twos {
				str[idx] = 'D'
				idx--
				i--
			} else {
				str[idx] = 'R'
				idx--
				j--
			}
		} else {
			if b[i-1][j].fives <= b[i][j-1].fives {
				str[idx] = 'D'
				idx--
				i--
			} else {
				str[idx] = 'R'
				idx--
				j--
			}
		}
	}
	fmt.Println(string(str))

	if debug {
		acc := a[n-1][n-1].val
		i = 0
		j = 0
		idx = 0
		for i != n-1 || j != n-1 {
			acc *= a[i][j].val
			fmt.Println("V(", i, j, a[i][j].val, ")")
			switch str[idx] {
			case 'R':
				j++
				break
			case 'D':
				i++
				break
			}
			idx++
		}

		fmt.Println("Accum", acc)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func twos(i int) (n int) {
	n = 0
	for ; i > 0; i /= 2 {
		if i%2 != 0 {
			break
		}
		n++
	}
	return
}

func fives(i int) (n int) {
	n = 0
	for ; i > 0; i /= 5 {
		if i%5 != 0 {
			break
		}
		n++
	}
	return
}

func nzeros(i int) int {
	var cnt int
	for {
		if i%10 != 0 {
			break
		}
		i /= 10
		cnt++
		if i < 10 {
			break
		}
	}
	return cnt
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	mat := make([][]int64, n)
	for i := 0; i < n; i++ {
		mat[i] = make([]int64, n)
		for j := 0; j < n-1; j++ {
			fmt.Scanf("%d", &mat[i][j])
		}
		fmt.Scanf("%d\n", &mat[i][n-1])
	}
	// fmt.Println(mat)
	res, path := leastFactor(mat, 2)
	a, pa := leastFactor(mat, 5)
	if res > a {
		res = a
		path = pa
	}
	fmt.Println(res)
	fmt.Println(path)
}

type pair struct {
	v int64
	d byte
}

func (p *pair) String() string {
	return fmt.Sprintf("v: %d, d: %v", p.v, p.d)
}

func leastFactor(mat [][]int64, n int64) (value int64, path string) {
	size := len(mat)
	mem := make([][]*pair, size)
	for i := 0; i < size; i++ {
		mem[i] = make([]*pair, size)
		for j := 0; j < size; j++ {
			if i == 0 && j == 0 {
				mem[i][j] = &pair{v: 0, d: ' '}
			} else if i == 0 {
				mem[i][j] = &pair{v: mem[i][j-1].v + factors(mat[i][j], n), d: 'R'}
			} else if j == 0 {
				mem[i][j] = &pair{v: mem[i-1][j].v + factors(mat[i][j], n), d: 'D'}
			} else {
				var v int64
				var d byte
				if mem[i-1][j].v < mem[i][j-1].v {
					v = mem[i-1][j].v
					d = 'D'
				} else {
					v = mem[i][j-1].v
					d = 'R'
				}
				mem[i][j] = &pair{v: v + factors(mat[i][j], n), d: d}
			}
		}
	}
	// fmt.Println(mem)
	value = mem[size-1][size-1].v
	p := make([]byte, 2*size-2)
	i := size - 1
	j := size - 1
	for k := len(p) - 1; k >= 0; k-- {
		// fmt.Println(i, j)

		p[k] = mem[i][j].d
		if p[k] == 'D' {
			i = i - 1
		} else if p[k] == 'R' {
			j = j - 1
		} else {
			break
		}
	}
	return value, string(p)
}

func factors(n, p int64) int64 {
	var res int64
	for n%p == 0 {
		n = n / p
		res++
	}
	return res
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	mat := make([][]int64, n)
	// now := time.Now()
	s := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		s.Scan()
		mat[i] = toInts(s.Bytes(), n)
	}
	// fmt.Println(mat)
	res, path := leastFactor(mat, 2)
	// fmt.Println("factor ", time.Since(now))

	a, pa := leastFactor(mat, 5)
	if res > a {
		res = a
		path = pa
	}
	fmt.Println(res)
	fmt.Println(path)
}

func toInts(s []byte, n int) []int64 {
	res := make([]int64, 0, n)
	var v int64
	for _, c := range s {
		if c == ' ' || c == '\n' {
			res = append(res, v)
			v = 0
		} else {
			v = v*10 + int64(c-'0')
		}
	}
	res = append(res, v)
	return res
}

type pair struct {
	v int64
	d byte
}

func (p *pair) String() string {
	return fmt.Sprintf("v: %d, d: %v", p.v, p.d)
}

func leastFactor(mat [][]int64, n int64) (value int64, path string) {
	size := len(mat)
	mem := make([][]*pair, size)
	for i := 0; i < size; i++ {
		mem[i] = make([]*pair, size)
		for j := 0; j < size; j++ {
			if i == 0 && j == 0 {
				mem[i][j] = &pair{v: factors(mat[i][j], n), d: ' '}
			} else if i == 0 {
				mem[i][j] = &pair{v: mem[i][j-1].v + factors(mat[i][j], n), d: 'R'}
			} else if j == 0 {
				mem[i][j] = &pair{v: mem[i-1][j].v + factors(mat[i][j], n), d: 'D'}
			} else {
				var v int64
				var d byte
				if mem[i-1][j].v < mem[i][j-1].v {
					v = mem[i-1][j].v
					d = 'D'
				} else {
					v = mem[i][j-1].v
					d = 'R'
				}
				mem[i][j] = &pair{v: v + factors(mat[i][j], n), d: d}
			}
		}
	}
	// fmt.Println(mem)
	value = mem[size-1][size-1].v
	p := make([]byte, 2*size-2)
	i := size - 1
	j := size - 1
	for k := len(p) - 1; k >= 0; k-- {
		// fmt.Println(i, j)

		p[k] = mem[i][j].d
		if p[k] == 'D' {
			i = i - 1
		} else if p[k] == 'R' {
			j = j - 1
		} else {
			break
		}
	}
	return value, string(p)
}

func factors(n, p int64) int64 {
	var res int64
	for n%p == 0 {
		p *= p
		res++
	}
	return res
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	mat := make([][]int64, n)
	s := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		s.Scan()
		mat[i] = toInts(s.Bytes(), n)
	}
	res, path := leastFactor(mat, 2)
	a, pa := leastFactor(mat, 5)
	if res > a {
		res = a
		path = pa
	}
	b, pb := hasZero(mat)
	if b && res > 1 {
		res = 1
		path = pb
	}
	fmt.Println(res)
	fmt.Println(path)
}

func toInts(s []byte, n int) []int64 {
	res := make([]int64, 0, n)
	var v int64
	for _, c := range s {
		if c == ' ' || c == '\n' {
			res = append(res, v)
			v = 0
		} else {
			v = v*10 + int64(c-'0')
		}
	}
	res = append(res, v)
	return res
}

type pair struct {
	v int64
	d byte
}

func (p *pair) String() string {
	return fmt.Sprintf("v: %d, d: %v", p.v, p.d)
}

func hasZero(mat [][]int64) (yes bool, res string) {
	n := len(mat)
	path := make([]byte, n+n-2)
	var t int
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if mat[i][j] == 0 {
				yes = true
				for k := 0; k < i; k++ {
					path[t] = 'R'
					t++
				}

				for k := 0; k < n-1; k++ {
					path[t] = 'D'
					t++
				}
				for ; t < len(path); t++ {
					path[t] = 'R'
				}
				return yes, string(path)
			}
		}
	}
	return
}

func leastFactor(mat [][]int64, n int64) (value int64, path string) {
	size := len(mat)
	mem := make([][]*pair, size)
	for i := 0; i < size; i++ {
		mem[i] = make([]*pair, size)
		for j := 0; j < size; j++ {
			fac := factors(mat[i][j], n)
			if i == 0 && j == 0 {
				mem[i][j] = &pair{v: fac, d: ' '}
			} else if i == 0 {
				mem[i][j] = &pair{v: mem[i][j-1].v + fac, d: 'R'}
			} else if j == 0 {
				mem[i][j] = &pair{v: mem[i-1][j].v + fac, d: 'D'}
			} else {
				var v int64
				var d byte
				if mem[i-1][j].v < mem[i][j-1].v {
					v = mem[i-1][j].v
					d = 'D'
				} else {
					v = mem[i][j-1].v
					d = 'R'
				}
				mem[i][j] = &pair{v: v + fac, d: d}
			}
		}
	}
	value = mem[size-1][size-1].v
	p := make([]byte, 2*size-2)
	i := size - 1
	j := size - 1
	for k := len(p) - 1; k >= 0; k-- {
		p[k] = mem[i][j].d
		if p[k] == 'D' {
			i = i - 1
		} else if p[k] == 'R' {
			j = j - 1
		} else {
			break
		}
	}
	return value, string(p)
}

func factors(n, p int64) (res int64) {
	for n > 0 && n%p == 0 {
		n = n / p
		res++
	}
	return res
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	mat := make([][]int64, n)
	s := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		s.Scan()
		mat[i] = toInts(s.Bytes(), n)
	}
	res, path := leastFactor(mat, 2)
	a, pa := leastFactor(mat, 5)
	if res > a {
		res = a
		path = pa
	}
	b, pb := hasZero(mat)
	if b && res > 1 {
		res = 1
		path = pb
	}
	fmt.Println(res)
	fmt.Println(path)
}

func toInts(s []byte, n int) []int64 {
	res := make([]int64, 0, n)
	var v int64
	for _, c := range s {
		if c == ' ' || c == '\n' {
			res = append(res, v)
			v = 0
		} else {
			v = v*10 + int64(c-'0')
		}
	}
	res = append(res, v)
	return res
}

type pair struct {
	v int64
	d byte
}

func (p *pair) String() string {
	return fmt.Sprintf("v: %d, d: %v", p.v, p.d)
}

func hasZero(mat [][]int64) (yes bool, res string) {
	n := len(mat)
	path := make([]byte, n+n-2)
	var t int
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if mat[i][j] == 0 {
				yes = true
				for k := 0; k < i; k++ {
					path[t] = 'R'
					t++
				}

				for k := 0; k < n-1; k++ {
					path[t] = 'D'
					t++
				}
				for ; t < len(path); t++ {
					path[t] = 'R'
				}
				return yes, string(path)
			}
		}
	}
	return
}

func leastFactor(mat [][]int64, n int64) (value int64, path string) {
	size := len(mat)
	mem := make([][]*pair, size)
	for i := 0; i < size; i++ {
		mem[i] = make([]*pair, size)
		for j := 0; j < size; j++ {
			fac := factors(mat[i][j], n)
			if i == 0 && j == 0 {
				mem[i][j] = &pair{v: fac, d: ' '}
			} else if i == 0 {
				mem[i][j] = &pair{v: mem[i][j-1].v + fac, d: 'R'}
			} else if j == 0 {
				mem[i][j] = &pair{v: mem[i-1][j].v + fac, d: 'D'}
			} else {
				var v int64
				var d byte
				if mem[i-1][j].v < mem[i][j-1].v {
					v = mem[i-1][j].v
					d = 'D'
				} else {
					v = mem[i][j-1].v
					d = 'R'
				}
				mem[i][j] = &pair{v: v + fac, d: d}
			}
		}
	}
	value = mem[size-1][size-1].v
	p := make([]byte, 2*size-2)
	i := size - 1
	j := size - 1
	for k := len(p) - 1; k >= 0; k-- {
		p[k] = mem[i][j].d
		if p[k] == 'D' {
			i = i - 1
		} else if p[k] == 'R' {
			j = j - 1
		} else {
			break
		}
	}
	return value, string(p)
}

func factors(n, p int64) (res int64) {
	if n == 0 {
		return 1
	}
	for n > 0 && n%p == 0 {
		n = n / p
		res++
	}
	return res
}

package main

import (
	"fmt"
	"math"
)

type XY struct {
	x int
	y int
}

func main() {
	times := 0
	fmt.Scanln(&times)
	point := make([][][]int, 2)
	pointXY := make([][][]XY, 2)
	dp := make([][][]int, 2)
	flag := false
	var zeroX, zeroY int
	for k := 0; k < 2; k++ {
		point[k] = make([][]int, times)
		pointXY[k] = make([][]XY, times)
		dp[k] = make([][]int, times)
		for i := 0; i < times; i++ {
			dp[k][i] = make([]int, times)
			point[k][i] = make([]int, times)
			pointXY[k][i] = make([]XY, times)
		}
	}
	for i := 0; i < times; i++ {
		for j := 0; j < times; j++ {
			dp[0][i][j] = math.MaxInt32
			dp[1][i][j] = math.MaxInt32
			var num int
			fmt.Scan(&num)
			if num == 0 {
				flag = true
				zeroX = i
				zeroY = j
				point[0][i][j]++
				point[1][i][j]++
				continue
			}
			point[0][i][j] += getNum(num, 2)
			point[1][i][j] += getNum(num, 5)
		}
	}
	for k := 0; k < 2; k++ {
		for i := 0; i < times; i++ {
			for j := 0; j < times; j++ {
				if i == 0 && j == 0 {
					dp[k][i][j] = 0
					pointXY[k][i][j] = XY{x: 0, y: 0}
				} else if i > 0 && j == 0 {
					dp[k][i][j] = dp[k][i-1][j]
					pointXY[k][i][j] = XY{x: i - 1, y: j}
				} else if i == 0 && j > 0 {
					dp[k][i][j] = dp[k][i][j-1]
					pointXY[k][i][j] = XY{x: i, y: j - 1}
				} else {
					if dp[k][i-1][j] < dp[k][i][j-1] {
						dp[k][i][j] = dp[k][i-1][j]
						pointXY[k][i][j] = XY{x: i - 1, y: j}
					} else {
						dp[k][i][j] = dp[k][i][j-1]
						pointXY[k][i][j] = XY{x: i, y: j - 1}
					}
				}

				dp[k][i][j] += point[k][i][j]
			}
		}
	}
	ans := min(dp[0][times-1][times-1], dp[1][times-1][times-1])

	if ans > 1 && flag {
		fmt.Println("1")
		for i := 0; i < zeroX; i++ {
			fmt.Print("D")
		}
		for j := 0; j < zeroY; j++ {
			fmt.Print("R")
		}
		for i := zeroX; i < times; i++ {
			fmt.Print("D")
		}
		for j := zeroY; j < times; j++ {
			fmt.Print("R")
		}
	} else {
		fmt.Println(ans)
		if dp[0][times-1][times-1] < dp[1][times-1][times-1] {
			show(&pointXY, times-1, times-1, 0, 3)
		} else {
			show(&pointXY, times-1, times-1, 1, 3)
		}
	}
	fmt.Println()
}

//获取数字num 质因子中 y 的个数
func getNum(num, y int) int {
	temp := 0
	for num != 0 && num%y == 0 {
		temp++
		num /= y
	}
	return temp
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func show(pointXY *[][][]XY, x, y, k, f int) {
	xy := (*pointXY)[k][x][y]
	fmt.Println(x, y, xy)
	if x == 0 && y == 0 {

	} else if xy.x == x - 1 {
		show(pointXY, xy.x, y, k, 1)
	} else if xy.y == y - 1 {
		show(pointXY, x, xy.y, k, 2)
	}
	if f == 1 {
		fmt.Print("D")
	} else if f == 2 {
		fmt.Print("R")
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	times := 0
	fmt.Scanln(&times)
	point := make([][][]int, 2, 2)
	pointXY := make([][]string, times, times)
	dp := make([][]int, times, times)

	for i := 0; i < times; i++ {
		dp[i] = make([]int, times)
		pointXY[i] = make([]string, times)
		for j := 0; j > times; j ++ {
			dp[i][j] = math.MaxInt32
		}
	}

	for k := 0; k < 2; k++ {
		point[k] = make([][]int, times)
		for i := 0; i < times; i++ {
			point[k][i] = make([]int, times)
		}
	}

	flag := false
	var zeroX, zeroY int
	for i := 0; i < times; i++ {
		for j := 0; j < times; j++ {
			var num int
			fmt.Scan(&num)
			if num == 0 {
				flag = true
				zeroX = i
				zeroY = j
				point[0][i][j]++
				point[1][i][j]++
				continue
			}
			point[0][i][j] += getNum(num, 2)
			point[1][i][j] += getNum(num, 5)
		}
	}
	for i := 0; i < times; i++ {
		for j := 0; j < times; j++ {
			if i == 0 && j == 0 {
				dp[i][j] = 0
				pointXY[i][j] = ""
			} else if i > 0 && j == 0 {
				dp[i][j] = dp[i-1][j]
				pointXY[i][j] += "D"
			} else if i == 0 && j > 0 {
				dp[i][j] = dp[i][j-1]
				pointXY[i][j] += "R"
			} else {
				if dp[i-1][j] < dp[i][j-1] {
					dp[i][j] = dp[i-1][j]
					pointXY[i][j] += "D"
				} else {
					dp[i][j] = dp[i][j-1]
					pointXY[i][j] += "R"
				}
			}
			dp[i][j] += point[0][i][j]
		}
	}
	ans1 := dp[times-1][times-1]
	result1 := pointXY[times-1][times-1]
	for i := 0; i < times; i++ {
		for j := 0; j > times; j ++ {
			dp[i][j] = math.MaxInt32
			pointXY[i][j] = ""
		}
	}
	for i := 0; i < times; i++ {
		for j := 0; j < times; j++ {
			if i == 0 && j == 0 {
				dp[i][j] = 0
				pointXY[i][j] = ""
			} else if i > 0 && j == 0 {
				dp[i][j] = dp[i-1][j]
				pointXY[i][j] = pointXY[i-1][j] + "D"
			} else if i == 0 && j > 0 {
				dp[i][j] = dp[i][j-1]
				pointXY[i][j] = pointXY[i][j-1] + "R"
			} else {
				if dp[i-1][j] < dp[i][j-1] {
					dp[i][j] = dp[i-1][j]
					pointXY[i][j] = pointXY[i-1][j] + "D"
				} else {
					dp[i][j] = dp[i][j-1]
					pointXY[i][j] = pointXY[i][j-1] + "R"
				}
			}
			dp[i][j] += point[1][i][j]
		}
	}
	ans2 := dp[times-1][times-1]
	result2 := pointXY[times-1][times-1]

	if ans1 > 1 && ans2 > 1 && flag {
		fmt.Println("1")
		for i := 0; i < zeroX; i++ {
			fmt.Print("D")
		}
		for j := 0; j < zeroY; j++ {
			fmt.Print("R")
		}
		for i := zeroX; i < times; i++ {
			fmt.Print("D")
		}
		for j := zeroY; j < times; j++ {
			fmt.Print("R")
		}
	} else {
		if ans1 < ans2 {
			fmt.Println(ans1)
			fmt.Println(result1)
		} else {
			fmt.Println(ans2)
			fmt.Println(result2)
		}
	}
}

//获取数字num 质因子中 y 的个数
func getNum(num, y int) int {
	temp := 0
	for num != 0 && num%y == 0 {
		temp++
		num /= y
	}
	return temp
}

package main

import "fmt"
import "container/list"

var n = int(0)
var v = [1000][1000]int{}
var z = [1000][1000][2]int{}

func min(a int,b int) int{
	if a>b { return b }
	return a
}

func max(a int,b int) int {
	if a > b { return a }
	return b
}

func abs(a int) int{
	if a > 0 { return a }
	return -a
}

func p(a int) (int,int) {

	t := 0
	f := 0

	if a == 0 { return t,f }

	for ;a%5==0;a/=5 {
		f++
	}

	for ;a%2==0;a/=2 {
		t++
	}

	return t,f
}

func main(){

	fmt.Scan(&n)

	zx := -1
	zy := -1

	for i:=0;i<n;i++ {
		for j:=0;j<n;j++ {
			fmt.Scan(&v[i][j])
			z[i][j][0],z[i][j][1] = p(v[i][j])

			if(v[i][j] == 0){
				zx = i
				zy = j
			}
		}
	}

	for i:=1;i<n;i++{
		z[i][0][0] += z[i-1][0][0]
		z[i][0][1] += z[i-1][0][1]
		z[0][i][0] += z[0][i-1][0]
		z[0][i][1] += z[0][i-1][1]
	}

	for i:=1;i<n;i++ {
		for j:=1;j<n;j++ {
			z[i][j][0] += min(z[i][j-1][0],z[i-1][j][0])
			z[i][j][1] += min(z[i][j-1][1],z[i-1][j][1])
		}
	}

	var ans = min(z[n-1][n-1][0],z[n-1][n-1][1])

	if zx!=-1&&zy!=-1 && ans > 1 {

		fmt.Println(1)

		x := 0
		y := 0

		for x < zx {
			fmt.Print("R")
			x++
		}

		for y < n {
			fmt.Print("D")
			y++
		}

		for x < n {
			fmt.Print("R")
		}

		fmt.Println()

	}else{

		fmt.Println(ans)

		x := n-1
		y := n-1
		var k int
		xs := list.New()

		if(z[n-1][n-1][0] < z[n-1][n-1][1]) {
			k = 0
		}else{
			k = 1
		}

		for x!=0 || y!=0 {

			if x==0 {
				xs.PushBack("D")
				y--
			}else if y==0 {
				xs.PushBack("R")
				x--
			}else {

				if z[x-1][y][k] < z[x][y][k] {
					xs.PushBack("R")
					x--
				}else{
					xs.PushBack("D")
					y--
				}
			}

		}

		for e:=xs.Back();e!=nil;e=e.Prev(){
			fmt.Print(e.Value.(string))
		}

		fmt.Println()
	}

}

package main

import "fmt"
import "container/list"

var n = int(0)
var z = [1000][1000][2]int{}

func min(a int,b int) int{
	if a>b { return b }
	return a
}

func max(a int,b int) int {
	if a > b { return a }
	return b
}

func abs(a int) int{
	if a > 0 { return a }
	return -a
}

func p(a int) (int,int) {

	t := 0
	f := 0

	if a == 0 { return t,f }

	for ;a%5==0;a/=5 {
		f++
	}

	for ;a%2==0;a/=2 {
		t++
	}

	return t,f
}

func main(){

	fmt.Scan(&n)

	v := 0
	zx := -1
	zy := -1

	for i:=0;i<n;i++ {
		for j:=0;j<n;j++ {

			fmt.Scan(&v)
			z[i][j][0],z[i][j][1] = p(v)

			if(v == 0){
				zx = i
				zy = j
			}
		}
	}

	for i:=1;i<n;i++{
		z[i][0][0] += z[i-1][0][0]
		z[i][0][1] += z[i-1][0][1]
		z[0][i][0] += z[0][i-1][0]
		z[0][i][1] += z[0][i-1][1]
	}

	for i:=1;i<n;i++ {
		for j:=1;j<n;j++ {
			for k:=0;k<2;k++ {
				z[i][j][k] += min(z[i][j-1][k],z[i-1][j][k])
			}
		}
	}

	var ans = min(z[n-1][n-1][0],z[n-1][n-1][1])

	if zx!=-1&&zy!=-1 && ans > 1 {

		fmt.Println(1)

		x := 0
		y := 0

		for x < zx {
			fmt.Print("R")
			x++
		}

		for y < n {
			fmt.Print("D")
			y++
		}

		for x < n {
			fmt.Print("R")
		}

		fmt.Println()

	}else{

		fmt.Println(ans)

		x := n-1
		y := n-1
		var k int
		xs := list.New()

		if(z[n-1][n-1][0] < z[n-1][n-1][1]) {
			k = 0
		}else{
			k = 1
		}
/*
		for i:=0;i<n;i++ {
			for j:=0;j<n;j++ {
				//fmt.Print("(",i,",",j,")"," ")
				fmt.Print(z[i][j][k])
				fmt.Print(" ")
			}
			fmt.Println()
		}
*/

		for x!=0 || y!=0 {

			if x==0 {
				xs.PushBack("R")
				y--
			}else if y==0 {
				xs.PushBack("D")
				x--
			}else {

				if(x == n-1 && y == n-1){
					fmt.Println(z[x-1][y][k])
					fmt.Println(z[x-1][y][k],z[x][y-1][k]);
				}
				if z[x-1][y][k] < z[x][y-1][k]{
					xs.PushBack("D")
					x--
				}else{
					xs.PushBack("R")
					y--
				}
			}

		}

		for e:=xs.Back();e!=nil;e=e.Prev(){
			fmt.Print(e.Value.(string))
		}

		fmt.Println()
	}

}

package main

import "fmt"
import "container/list"

var n = int(0)
var v = [1000][1000]int{}
var z = [1000][1000][2]int{}

func min(a int,b int) int{
	if a>b { return b }
	return a
}

func max(a int,b int) int {
	if a > b { return a }
	return b
}

func abs(a int) int{
	if a > 0 { return a }
	return -a
}

func p(a int) (int,int) {

	t := 0
	f := 0

	if a == 0 { return t,f }

	for ;a%5==0;a/=5 {
		f++
	}

	for ;a%2==0;a/=2 {
		t++
	}

	return t,f
}

func main(){

	fmt.Scan(&n)

	zx := -1
	zy := -1

	for i:=0;i<n;i++ {
		for j:=0;j<n;j++ {
			fmt.Scan(&v[i][j])
			z[i][j][0],z[i][j][1] = p(v[i][j])

			if(v[i][j] == 0){
				zx = i
				zy = j
			}
		}
	}

	for i:=1;i<n;i++{
		z[i][0][0] += z[i-1][0][0]
		z[i][0][1] += z[i-1][0][1]
		z[0][i][0] += z[0][i-1][0]
		z[0][i][1] += z[0][i-1][1]
	}

	for i:=1;i<n;i++ {
		for j:=1;j<n;j++ {
			z[i][j][0] += min(z[i][j-1][0],z[i-1][j][0])
			z[i][j][1] += min(z[i][j-1][1],z[i-1][j][1])
		}
	}

	var ans = min(z[n-1][n-1][0],z[n-1][n-1][1])

	if zx!=-1&&zy!=-1 && ans > 1 {

		fmt.Println(1)

		x := 0
		y := 0

		for x < zx {
			fmt.Print("R")
			x++
		}

		for y < n {
			fmt.Print("D")
			y++
		}

		for x < n {
			fmt.Print("R")
		}

		fmt.Println()

	}else{

		fmt.Println(ans)

		x := n-1
		y := n-1
		var k int
		xs := list.New()

		if(z[n-1][n-1][0] < z[n-1][n-1][1]) {
			k = 0
		}else{
			k = 1
		}

		for x!=0 || y!=0 {

			if x==0 {
				xs.PushFront("D")
				y--
			}else if y==0 {
				xs.PushFront("R")
				x--
			}else {

				if z[x-1][y][k] <= z[x][y][k] {
					xs.PushFront("R")
					x--
				}else{
					xs.PushFront("D")
					y--
				}
			}

		}

		for e:=xs.Front();e!=nil;e=e.Next(){
			fmt.Print(e.Value.(string))
		}

		fmt.Println()
	}

}

package main

import "fmt"
import "os"
import "bufio"
import "container/list"

var n = int(0)
var z = [1000][1000][2]int{}

func min(a int,b int) int{
	if a>b { return b }
	return a
}

func max(a int,b int) int {
	if a > b { return a }
	return b
}

func abs(a int) int{
	if a > 0 { return a }
	return -a
}

func p(a int) (int,int) {

	t := 0
	f := 0

	if a == 0 { return t,f }

	for ;a%5==0;a/=5 {
		f++
	}

	for ;a%2==0;a/=2 {
		t++
	}

	return t,f
}

func isDigit(b byte) bool{
	return b >= '0' && b <= '9'
}

func readLine() error{
	var err error
	_buf,err = _in.ReadBytes('\n')
	_lb = len(_buf)
	_pos = 0
	return err
}

func nextInt() (int,error){

	for digit:=false;!digit; {

		if _pos >= _lb {
			err := readLine()
			if err != nil {
				return -1,err
			}
		}

		for ; _pos < _lb && !digit ; _pos++ {

			digit = isDigit(_buf[_pos])

			if digit {
				break
			}
		}

	}

	r := 0

	for ; _pos < _lb && isDigit(_buf[_pos]) ; {
		r = r*10 + int(_buf[_pos]) - '0'
		_pos++
	}

	return r,nil
}

var (
	_in = bufio.NewReader(os.Stdin)
	_buf []byte
	_lb = int(-1)
	_pos = int(0)
)

func main(){

	n,_ := nextInt()

	v := 0
	zx := -1
	zy := -1

	for i:=0;i<n;i++ {
		for j:=0;j<n;j++ {

			v,_ = nextInt()

			z[i][j][0],z[i][j][1] = p(v)

			if(v == 0){
				zx = i
				zy = j
			}
		}
	}

	for i:=1;i<n;i++{
		z[i][0][0] += z[i-1][0][0]
		z[i][0][1] += z[i-1][0][1]
		z[0][i][0] += z[0][i-1][0]
		z[0][i][1] += z[0][i-1][1]
	}

	for i:=1;i<n;i++ {
		for j:=1;j<n;j++ {
			for k:=0;k<2;k++ {
				z[i][j][k] += min(z[i][j-1][k],z[i-1][j][k])
			}
		}
	}

	var ans = min(z[n-1][n-1][0],z[n-1][n-1][1])

	if zx!=-1 && zy!=-1 && ans > 1 {

		fmt.Println(1)

		x := 0
		y := 0

		for x < zx {
			fmt.Print("R")
			x++
		}

		for y < zy {
			fmt.Print("D")
			y++
		}

		for x < n {
			fmt.Print("R")
			x++
		}

		for y < n {
			fmt.Print("D")
			y++
		}

		fmt.Println()

	} else {

		fmt.Println(ans)

		x := n-1
		y := n-1
		var k int
		xs := list.New()

		if(z[n-1][n-1][0] < z[n-1][n-1][1]) {
			k = 0
		}else{
			k = 1
		}

		for x!=0 || y!=0 {

			if x==0 {
				xs.PushBack("R")
				y--
			}else if y==0 {
				xs.PushBack("D")
				x--
			}else {

				if z[x-1][y][k] < z[x][y-1][k]{
					xs.PushBack("D")
					x--
				}else{
					xs.PushBack("R")
					y--
				}
			}

		}

		for e:=xs.Back();e!=nil;e=e.Prev(){
			fmt.Print(e.Value.(string))
		}

		fmt.Println()
	}

}

package main

import "fmt"
import "os"
import "bufio"
import "container/list"

var n = int(0)
var z = [1000][1000][2]int{}

func min(a int,b int) int{
	if a>b { return b }
	return a
}

func max(a int,b int) int {
	if a > b { return a }
	return b
}

func abs(a int) int{
	if a > 0 { return a }
	return -a
}

func p(a int) (int,int) {

	t := 0
	f := 0

	if a == 0 { return t,f }

	for ;a%5==0;a/=5 {
		f++
	}

	for ;a%2==0;a/=2 {
		t++
	}

	return t,f
}

func isDigit(b byte) bool{
	return b >= '0' && b <= '9'
}

func readLine() error{
	var err error
	_buf,err = _in.ReadBytes('\n')
	_lb = len(_buf)
	_pos = 0
	return err
}

func nextInt() (int,error){

	for digit:=false;!digit; {

		if _pos >= _lb {
			err := readLine()
			if err != nil {
				return -1,err
			}
		}

		for ; _pos < _lb && !digit ; _pos++ {

			digit = isDigit(_buf[_pos])

			if digit {
				break
			}
		}

	}

	r := 0

	for ; _pos < _lb && isDigit(_buf[_pos]) ; {
		r = r*10 + int(_buf[_pos]) - '0'
		_pos++
	}

	return r,nil
}

var (
	_in = bufio.NewReader(os.Stdin)
	_buf []byte
	_lb = int(-1)
	_pos = int(0)
)

func main(){

	n,_ := nextInt()

	v := 0
	zx := -1
	zy := -1

	for i:=0;i<n;i++ {
		for j:=0;j<n;j++ {

			v,_ = nextInt()

			z[i][j][0],z[i][j][1] = p(v)

			if(v == 0){
				zx = i
				zy = j
			}
		}
	}

	for i:=1;i<n;i++{
		z[i][0][0] += z[i-1][0][0]
		z[i][0][1] += z[i-1][0][1]
		z[0][i][0] += z[0][i-1][0]
		z[0][i][1] += z[0][i-1][1]
	}

	for i:=1;i<n;i++ {
		for j:=1;j<n;j++ {
			for k:=0;k<2;k++ {
				z[i][j][k] += min(z[i][j-1][k],z[i-1][j][k])
			}
		}
	}

	var ans = min(z[n-1][n-1][0],z[n-1][n-1][1])

	if zx!=-1&&zy!=-1 && ans > 1 {

		fmt.Println(1)

		x := 0
		y := 0

		for x < zx {
			fmt.Print("R")
			x++
		}

		for y < n {
			fmt.Print("D")
			y++
		}

		for x < n {
			fmt.Print("R")
			x++
		}

		fmt.Println()

	}else{

		fmt.Println(ans)

		x := n-1
		y := n-1
		var k int
		xs := list.New()

		if(z[n-1][n-1][0] < z[n-1][n-1][1]) {
			k = 0
		}else{
			k = 1
		}
/*
		for i:=0;i<n;i++ {
			for j:=0;j<n;j++ {
				//fmt.Print("(",i,",",j,")"," ")
				fmt.Print(z[i][j][k])
				fmt.Print(" ")
			}
			fmt.Println()
		}
*/

		for x!=0 || y!=0 {

			if x==0 {
				xs.PushBack("R")
				y--
			}else if y==0 {
				xs.PushBack("D")
				x--
			}else {

				if z[x-1][y][k] < z[x][y-1][k]{
					xs.PushBack("D")
					x--
				}else{
					xs.PushBack("R")
					y--
				}
			}

		}

		for e:=xs.Back();e!=nil;e=e.Prev(){
			fmt.Print(e.Value.(string))
		}

		fmt.Println()
	}

}

package main

import "fmt"
import "container/list"

var n = int(0)
var z = [1000][1000][2]int{}

func min(a int,b int) int{
	if a>b { return b }
	return a
}

func max(a int,b int) int {
	if a > b { return a }
	return b
}

func abs(a int) int{
	if a > 0 { return a }
	return -a
}

func p(a int) (int,int) {

	t := 0
	f := 0

	if a == 0 { return t,f }

	for ;a%5==0;a/=5 {
		f++
	}

	for ;a%2==0;a/=2 {
		t++
	}

	return t,f
}

func main(){

	fmt.Scanf("%d",&n)

	v := 0
	zx := -1
	zy := -1

	for i:=0;i<n;i++ {
		for j:=0;j<n;j++ {

			fmt.Scanf("%d",&v)
			z[i][j][0],z[i][j][1] = p(v)

			if(v == 0){
				zx = i
				zy = j
			}
		}
	}

	for i:=1;i<n;i++{
		z[i][0][0] += z[i-1][0][0]
		z[i][0][1] += z[i-1][0][1]
		z[0][i][0] += z[0][i-1][0]
		z[0][i][1] += z[0][i-1][1]
	}

	for i:=1;i<n;i++ {
		for j:=1;j<n;j++ {
			for k:=0;k<2;k++ {
				z[i][j][k] += min(z[i][j-1][k],z[i-1][j][k])
			}
		}
	}

	var ans = min(z[n-1][n-1][0],z[n-1][n-1][1])

	if zx!=-1&&zy!=-1 && ans > 1 {

		fmt.Println(1)

		x := 0
		y := 0

		for x < zx {
			fmt.Print("R")
			x++
		}

		for y < n {
			fmt.Print("D")
			y++
		}

		for x < n {
			fmt.Print("R")
		}

		fmt.Println()

	}else{

		fmt.Println(ans)

		x := n-1
		y := n-1
		var k int
		xs := list.New()

		if(z[n-1][n-1][0] < z[n-1][n-1][1]) {
			k = 0
		}else{
			k = 1
		}
/*
		for i:=0;i<n;i++ {
			for j:=0;j<n;j++ {
				//fmt.Print("(",i,",",j,")"," ")
				fmt.Print(z[i][j][k])
				fmt.Print(" ")
			}
			fmt.Println()
		}
*/

		for x!=0 || y!=0 {

			if x==0 {
				xs.PushBack("R")
				y--
			}else if y==0 {
				xs.PushBack("D")
				x--
			}else {

				if z[x-1][y][k] < z[x][y-1][k]{
					xs.PushBack("D")
					x--
				}else{
					xs.PushBack("R")
					y--
				}
			}

		}

		for e:=xs.Back();e!=nil;e=e.Prev(){
			fmt.Print(e.Value.(string))
		}

		fmt.Println()
	}

}

package main

import "fmt"
import "os"
import "bufio"
import "container/list"

var n = int(0)
var z = [1000][1000][2]int{}

func min(a int,b int) int{
	if a>b { return b }
	return a
}

func max(a int,b int) int {
	if a > b { return a }
	return b
}

func abs(a int) int{
	if a > 0 { return a }
	return -a
}

func p(a int) (int,int) {

	t := 0
	f := 0

	if a == 0 { return t,f }

	for ;a%5==0;a/=5 {
		f++
	}

	for ;a%2==0;a/=2 {
		t++
	}

	return t,f
}

func isDigit(b byte) bool{
	return b >= '0' && b <= '9'
}

func readLine() error{
	var err error
	_buf,err = _in.ReadBytes('\n')
	_lb = len(_buf)
	_pos = 0
	return err
}

func nextInt() (int,error){

	for digit:=false;!digit; {

		if _pos >= _lb {
			err := readLine()
			if err != nil {
				return -1,err
			}
		}

		for ; _pos < _lb && !digit ; _pos++ {

			digit = isDigit(_buf[_pos])

			if digit {
				break
			}
		}

	}

	r := 0

	for ; _pos < _lb && isDigit(_buf[_pos]) ; {
		r = r*10 + int(_buf[_pos]) - '0'
		_pos++
	}

	return r,nil
}

var (
	_in = bufio.NewReader(os.Stdin)
	_buf []byte
	_lb = int(-1)
	_pos = int(0)
)

func main(){

	n,_ := nextInt()

	v := 0
	zx := -1
	zy := -1

	for i:=0;i<n;i++ {
		for j:=0;j<n;j++ {

			v,_ = nextInt()

			z[i][j][0],z[i][j][1] = p(v)

			if(v == 0){
				zx = i
				zy = j
			}
		}
	}

	for i:=1;i<n;i++{
		z[i][0][0] += z[i-1][0][0]
		z[i][0][1] += z[i-1][0][1]
		z[0][i][0] += z[0][i-1][0]
		z[0][i][1] += z[0][i-1][1]
	}

	for i:=1;i<n;i++ {
		for j:=1;j<n;j++ {
			for k:=0;k<2;k++ {
				z[i][j][k] += min(z[i][j-1][k],z[i-1][j][k])
			}
		}
	}

	var ans = min(z[n-1][n-1][0],z[n-1][n-1][1])

	if zx!=-1 && zy!=-1 && ans > 1 {

		fmt.Println(1)

		x := 0
		y := 0

		for x < zx {
			fmt.Print("R")
			x++
		}

		for y < zy {
			fmt.Print("D")
			y++
		}

		for x < n-1 {
			fmt.Print("R")
			x++
		}

		for y < n-1 {
			fmt.Print("D")
			y++
		}

		fmt.Println()

	} else {

		fmt.Println(ans)

		var k int
		x := n-1
		y := n-1
		xs := list.New()

		if(z[n-1][n-1][0] < z[n-1][n-1][1]) {
			k = 0
		}else{
			k = 1
		}

		for !(x == 0 && y == 0 ) {

			if x==0 {
				xs.PushBack("R")
				y--
			}else if y==0 {
				xs.PushBack("D")
				x--
			}else {

				if z[x-1][y][k] < z[x][y-1][k]{
					xs.PushBack("D")
					x--
				}else{
					xs.PushBack("R")
					y--
				}
			}

		}

		for e:=xs.Back();e!=nil;e=e.Prev(){
			fmt.Print(e.Value.(string))
		}

		fmt.Println()
	}

}

// Author: sighduck
// URL: https://codeforces.com/contest/2/problem/B

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

type Factor struct {
	Twos  int
	Fives int
}

type Path struct {
	Sum        int
	Directions string
}

func min(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

func countFactors(x int, twos int, fives int) Factor {
	if x == 0 {
		return Factor{Twos: 1, Fives: 1}
	} else if x%2 == 0 {
		return countFactors(x/2, twos+1, fives)
	} else if x%5 == 0 {
		return countFactors(x/5, twos, fives+1)
	}
	return Factor{Twos: twos, Fives: fives}
}

func hasZero(n int, m [][]int) (bool, int, int) {
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if m[i][j] == 0 {
				return true, i, j
			}
		}
	}
	return false, -1, -1
}

func createZeroPath(n int, i int, j int) Path {
	return Path{
		Sum:        1,
		Directions: strings.Repeat("D", i) + strings.Repeat("R", j) + strings.Repeat("D", n-1-i) + strings.Repeat("R", n-1-j),
	}
}

func createFactorMatrices(n int, m [][]int) ([][]int, [][]int) {
	twosMatrix := make([][]int, n)
	fivesMatrix := make([][]int, n)
	for i := 0; i < n; i++ {
		twosMatrix[i] = make([]int, n)
		fivesMatrix[i] = make([]int, n)
		for j := 0; j < n; j++ {
			factors := countFactors(m[i][j], 0, 0)
			twosMatrix[i][j] = factors.Twos
			fivesMatrix[i][j] = factors.Fives
		}
	}
	return twosMatrix, fivesMatrix
}

func computeMinPath(n int, matrix [][]int) Path {
	pathMatrix := make([][]Path, n)
	for i := 0; i < n; i++ {
		pathMatrix[i] = make([]Path, n)
		for j := 0; j < n; j++ {
			pathMatrix[i][j].Sum = matrix[i][j]
		}
	}
	for i := 1; i < n; i++ {
		pathMatrix[i][0].Sum += pathMatrix[i-1][0].Sum
		pathMatrix[i][0].Directions = pathMatrix[i-1][0].Directions + "D"
		pathMatrix[0][i].Sum += pathMatrix[0][i-1].Sum
		pathMatrix[0][i].Directions = pathMatrix[0][i-1].Directions + "R"
	}
	for i := 1; i < n; i++ {
		for j := 1; j < n; j++ {
			if pathMatrix[i][j-1].Sum < pathMatrix[i-1][j].Sum {
				pathMatrix[i][j].Sum += pathMatrix[i][j-1].Sum
				pathMatrix[i][j].Directions = pathMatrix[i][j-1].Directions + "R"
			} else {
				pathMatrix[i][j].Sum += pathMatrix[i-1][j].Sum
				pathMatrix[i][j].Directions = pathMatrix[i-1][j].Directions + "D"
			}
		}
	}
	return pathMatrix[n-1][n-1]
}

func Solve(n int, m [][]int) Path {
	twosMatrix, fivesMatrix := createFactorMatrices(n, m)
	minTwosPath := computeMinPath(n, twosMatrix)
	minFivesPath := computeMinPath(n, fivesMatrix)
	if minTwosPath.Sum == 0 {
		return minTwosPath
	} else if minFivesPath.Sum == 0 {
		return minFivesPath
	}
	hasZero, i, j := hasZero(n, m)
	if hasZero {
		return createZeroPath(n, i, j)
	} else if minTwosPath.Sum < minFivesPath.Sum {
		return minTwosPath
	}
	return minFivesPath
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	m := make([][]int, n)
	for i := 0; i < n; i++ {
		m[i] = make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(reader, "%d ", &m[i][j])
		}
	}

	solution := Solve(n, m)
	fmt.Fprintf(writer, "%d\n", solution.Sum)
	fmt.Fprintf(writer, "%s\n", solution.Directions)
}