#include <bits/stdc++.h>
const int N = 1010;
using namespace std;
inline int read()
{
	register int num = 0;
	register char ch;
	register bool flag = false;
	while ((ch = getchar()) == ' '||ch == '\n'||ch == '\r');
	if (ch=='-')flag=true;else num=ch^48;
	while((ch=getchar())!=' '&&ch!='\n'&&ch!='\r'&&~ch)
	num=num*10+(ch^48);
	if(flag)return -num;return num;
}
int a[N][N][2],dp[N][N][2],loca,locb,n;
bool flag;
inline void divide(register int x,register int y,register int num)
{
	if(!num){
		printf("1\n");
		for (register int i=1;i!=x;++i)putchar('D');
		for (register int i=1;i!=y;++i)putchar('R');
		for (register int i=x;i!=n;++i)putchar('D');
		for (register int i=y;i!=n;++i)putchar('R');
		exit(0);
	}
	while (num%2==0)
	{
		num>>=1;
		++a[x][y][0];
	}
	while (num%5==0)
	{
		num/=5;
		++a[x][y][1];
	}
}
inline void getans(register int x,register int y,register int k,register int fx)
{
	if (x==1&&y!=1)getans(x,y-1,k,0);
	else if (y==1&&x!=1)getans(x-1,y,k,1);
	else if (x!=1&&y!=1)
	{
		if (dp[x][y][k]==dp[x-1][y][k]+a[x][y][k])getans(x-1,y,k,1);
		else getans(x,y-1,k,0);
	}
	if (fx==3)return;
	if (fx==0)putchar('R');
	else putchar('D');
}

int main()
{
	n=read();
	for (register int i=1;i<=n;++i)
		for (register int j=1;j<=n;++j)
			dp[i][j][0]=dp[i][j][1]=1000000,divide(i,j,read());
	for (register int k=0;k!=2;++k)
	for (register int i=1;i<=n;++i)
	{
		for (register int j=1;j<=n;++j)
		{
			if (i-1)dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k]);
			if (j-1)dp[i][j][k]=min(dp[i][j][k],dp[i][j-1][k]);
			dp[i][j][k]+=a[i][j][k];
			if (i==j&&i==1)dp[i][j][k]=0;
		}
	}
	register int ans=min(dp[n][n][0],dp[n][n][1]);
	printf("%d\n",ans);
	if (dp[n][n][0]<dp[n][n][1])getans(n,n,0,3);
	else getans(n,n,1,3);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<map>
#define int long long
#define maxn 1010
#define inf 2147483647
#define mod 998244353
#define eps 1e-2
#define pi acos(-1.0)
using namespace std;
inline int read(){
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)) {x=x*10+ch-48;ch=getchar();}
    return x*f;
}
int n,ans,p,q;
int a[2][maxn][maxn],f[2][maxn][maxn];
bool flag,k;
inline void print(int x,int y,bool t){
	if(x==1&&y==1);
	else if(x==1) print(x,y-1,false);
	else if(y==1) print(x-1,y,true);
	else{
		if(f[k][x][y]==f[k][x-1][y]+a[k][x][y]) print(x-1,y,true);
		else print(x,y-1,false);
	}
	if(x==n&&y==n) return;
	putchar(t?'D':'R'); return;
}
signed main(){
	n=read();
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++){
		int x=read();
		if(!x){flag=true;a[0][i][j]++; a[1][i][j]++; p=i;q=j;continue;}
		while(!(x&1)) a[0][i][j]++,x>>=1;
		while(!(x&5)) a[1][i][j]++,x/=5;
	}
	memset(f,0x3f,sizeof f);
	f[0][1][1]=f[1][1][1]=0;
	for(int l=0;l<2;l++)
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
		f[l][i][j]=min(f[l][i][j],min(f[l][i-1][j],f[l][i][j-1]))+a[l][i][j];
	ans=min(f[0][n][n],f[1][n][n]);
	if(ans>1&&flag){
		puts("1");
		for(int i=1;i<p;i++) putchar('D');
		for(int i=1;i<q;i++) putchar('R');
		for(int i=p;i<n;i++) putchar('D');
		for(int i=q;i<n;i++) putchar('R');
	}
	printf("%d\n",ans);
	if(f[0][n][n]<f[1][n][n]) k=false,print(n,n,0);
	else k=true,print(n,n,0);
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <math.h>

using namespace std;
//const int NP=10000005;
//int ispri[NP]= {},prime[NP],pcnt=0;
//void getprime()
//{
//    ispri[0]=ispri[1]=1;
//    for (long long i=2; i<NP; i++)
//        if (ispri[i]==0)
//        {
//            prime[++pcnt]=i;
//            for (long long j=i*i; j<NP; j+=i)
//                ispri[j]=1;
//        }
//}

int pdec(int n,const int key)
{
    int count = 0;
//    for (int i=1; prime[i]*prime[i]<=n; i++)
//        if (n%prime[i]==0)
//        {
//            if(prime[i] == key)
//                count++;
//            n/=prime[i];
//            i--;
//        }
    while (n>key)
    {
        if(n%key==0)
        {
            count++;
            n/=key;
        }
        else
            break;
    }
    if(n == key)
        count++;
    return count;
}
int changeZerotoTen(int n){
    if(n == 0)
        return 10;
    return n;
}

int main(){
//    getprime();
    bool hasZero = false;
    int zeroX = 0;
    int zeroY = 0;
    int n;
    cin>>n;

    vector<vector<int>> mat(n+1);
    for(int i=0; i<n+1;i++)
        mat[i].resize(n+1);
    for(int i=n;i>0;i--)
        for(int j=n;j>0;j--)
        {
            cin>>mat[i][j];
            if(mat[i][j] == 0)
            {
                hasZero = true;
                zeroX = i;
                zeroY = j;
            }
        }

    vector<vector<int>> c2(n+1);
    vector<vector<int>> c5(n+1);
    vector<vector<int>> b(n+1);
    for(int i=0; i<n+1;i++)
    {
        c2[i].resize(n+1);
        c5[i].resize(n+1);
        b[i].resize(n+1);
    }
    for(int i=1;i<=n;i++)
    {
        c2[1][i] = pdec(changeZerotoTen(mat[1][i]),2)+c2[1][i-1];
        c2[i][1] = pdec(changeZerotoTen(mat[i][1]),2)+c2[i-1][1];
        c5[i][1] = pdec(changeZerotoTen(mat[i][1]),5)+c5[i-1][1];
        c5[1][i] = pdec(changeZerotoTen(mat[1][i]),5)+c5[1][i-1];
        b[1][i] = 1;
    }
    int pdec2,pdec5;
    for(int i=2;i<=n;i++)
        for(int j=2;j<=n;j++)
        {
            pdec2 = pdec(changeZerotoTen(mat[i][j]),2);
            pdec5 = pdec(changeZerotoTen(mat[i][j]),5);
            if(min(c2[i-1][j]+pdec2,c5[i-1][j]+pdec5)<min(c2[i][j-1]+pdec2,c5[i][j-1]+pdec5))
            {
                c2[i][j] = c2[i-1][j]+pdec2;
                c5[i][j] = c5[i-1][j]+pdec5;
            }
            else
            {
                c2[i][j] = c2[i][j-1]+pdec2;
                c5[i][j] = c5[i][j-1]+pdec5;
                b[i][j] = 1;
            }
        }
    if(hasZero)
    {
        if(min(c2[n][n],c5[n][n])>1)
        {
            cout<<"1"<<endl;
            int y = n;
            for(int i = n;i>0;i--)
            {
                if(i == zeroX && y>1)
                {
                    cout<<"R";
                    i++;
                    y--;
                }
                else
                {
                    if(i!=1 || y!=1)
                        cout<<"D";
                }
            }
        }
        else
        {
            cout<<min(c2[n][n],c5[n][n])<<endl;
            int x = n;
            int y = n;
            while(x!=1 || y!=1)
            {
                if(b[x][y]==1)
                {
                    cout<<"R";
                    y--;
                }
                else
                {
                    cout<<"D";
                    x--;
                }
            }
        }
    }
    else
    {
        cout<<min(c2[n][n],c5[n][n])<<endl;
        int x = n;
        int y = n;
        while(x!=1 || y!=1)
        {
            if(b[x][y]==1)
            {
                cout<<"R";
                y--;
            }
            else
            {
                cout<<"D";
                x--;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdlib.h>

using namespace std;

int pdec(int n,const int key)
{
    int count = 0;
    while (n>key)
    {
        if(n%key==0)
        {
            count++;
            n/=key;
        }
        else
            break;
    }
    if(n == key)
        count++;
    return count;
}
int changeZerotoTen(int n){
    if(n == 0)
        return 10;
    return n;
}
int c2[1005][1005];
int c5[1005][1005];
int b[1005][1005];
int mat[1005][1005];
int main(){
    std::ios::sync_with_stdio(false);
    bool hasZero = false;
    int zeroX = 0;
    int zeroY = 0;
    int n;
    cin>>n;

    for(int i=n;i>0;i--)
        for(int j=n;j>0;j--)
        {
            cin>>mat[i][j];
//            scanf("%d",&mat[i][j]);
            if(mat[i][j] == 0)
            {
                hasZero = true;
                zeroX = i;
                zeroY = j;
            }
        }

    for(int i=0; i<n+1;i++)
        for(int j=0;j<n+1;j++)
        {
            c2[i][j] = 0;
            c5[i][j] = 0;
            b[i][j] = 0;
        }
    for(int i=1;i<=n;i++)
    {
        c2[1][i] = pdec(changeZerotoTen(mat[1][i]),2)+c2[1][i-1];
        c2[i][1] = pdec(changeZerotoTen(mat[i][1]),2)+c2[i-1][1];
        c5[i][1] = pdec(changeZerotoTen(mat[i][1]),5)+c5[i-1][1];
        c5[1][i] = pdec(changeZerotoTen(mat[1][i]),5)+c5[1][i-1];
        b[1][i] = 1;
    }
    int pdec2,pdec5;
    for(int i=2;i<=n;i++)
        for(int j=2;j<=n;j++)
        {
            pdec2 = pdec(changeZerotoTen(mat[i][j]),2);
            pdec5 = pdec(changeZerotoTen(mat[i][j]),5);
            if(min(c2[i-1][j]+pdec2,c5[i-1][j]+pdec5)<min(c2[i][j-1]+pdec2,c5[i][j-1]+pdec5))
            {
                c2[i][j] = c2[i-1][j]+pdec2;
                c5[i][j] = c5[i-1][j]+pdec5;
            }
            else
            {
                c2[i][j] = c2[i][j-1]+pdec2;
                c5[i][j] = c5[i][j-1]+pdec5;
                b[i][j] = 1;
            }
        }
    if(hasZero)
    {
        if(min(c2[n][n],c5[n][n])>1)
        {
            cout<<"1"<<endl;
            int y = n;
            for(int i = n;i>0;i--)
            {
                if(i == zeroX && y>1)
                {
                    cout<<"R";
                    i++;
                    y--;
                }
                else
                {
                    if(i!=1 || y!=1)
                        cout<<"D";
                }
            }
        }
        else
        {
            cout<<min(c2[n][n],c5[n][n])<<endl;
            int x = n;
            int y = n;
            while(x!=1 || y!=1)
            {
                if(b[x][y]==1)
                {
                    cout<<"R";
                    y--;
                }
                else
                {
                    cout<<"D";
                    x--;
                }
            }
        }
    }
    else
    {
        cout<<min(c2[n][n],c5[n][n])<<endl;
        int x = n;
        int y = n;
        while(x!=1 || y!=1)
        {
            if(b[x][y]==1)
            {
                cout<<"R";
                y--;
            }
            else
            {
                cout<<"D";
                x--;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

int pdec(int n,const int key)
{
    int count = 0;
    while (n>key)
    {
        if(n%key==0)
        {
            count++;
            n/=key;
        }
        else
            break;
    }
    if(n == key)
        count++;
    return count;
}
int changeZerotoTen(int n){
    if(n == 0)
        return 10;
    return n;
}
int c2[1005][1005];
int c5[1005][1005];
int b[1005][1005];
int mat[1005][1005];
int main(){
    bool hasZero = false;
    int zeroX = 0;
    int zeroY = 0;
    int n;
    cin>>n;

    for(int i=n;i>0;i--)
        for(int j=n;j>0;j--)
        {
            cin>>mat[i][j];
            if(mat[i][j] == 0)
            {
                hasZero = true;
                zeroX = i;
                zeroY = j;
            }
            c2[i][j] = 0;
            c5[i][j] = 0;
            b[i][j] = 0;
        }

    for(int i=0; i<n+1;i++)
        {
            c2[i][0] = 0;
            c2[0][i] = 0;
            c5[0][i] = 0;
            c5[i][0] = 0;
            b[i][0] = 0;
            b[0][i] = 0;
        }
    for(int i=1;i<=n;i++)
    {
        c2[1][i] = pdec(changeZerotoTen(mat[1][i]),2)+c2[1][i-1];
        c2[i][1] = pdec(changeZerotoTen(mat[i][1]),2)+c2[i-1][1];
        c5[i][1] = pdec(changeZerotoTen(mat[i][1]),5)+c5[i-1][1];
        c5[1][i] = pdec(changeZerotoTen(mat[1][i]),5)+c5[1][i-1];
        b[1][i] = 1;
    }
    int pdec2,pdec5;
    for(int i=2;i<=n;i++)
        for(int j=2;j<=n;j++)
        {
            pdec2 = pdec(changeZerotoTen(mat[i][j]),2);
            pdec5 = pdec(changeZerotoTen(mat[i][j]),5);
            if(min(c2[i-1][j]+pdec2,c5[i-1][j]+pdec5)<min(c2[i][j-1]+pdec2,c5[i][j-1]+pdec5))
            {
                c2[i][j] = c2[i-1][j]+pdec2;
                c5[i][j] = c5[i-1][j]+pdec5;
            }
            else
            {
                c2[i][j] = c2[i][j-1]+pdec2;
                c5[i][j] = c5[i][j-1]+pdec5;
                b[i][j] = 1;
            }
        }
    if(hasZero)
    {
        if(min(c2[n][n],c5[n][n])>1)
        {
            cout<<"1"<<endl;
            int y = n;
            for(int i = n;i>0;i--)
            {
                if(i == zeroX && y>1)
                {
                    cout<<"R";
                    i++;
                    y--;
                }
                else
                {
                    if(i!=1 || y!=1)
                        cout<<"D";
                }
            }
        }
        else
        {
            cout<<min(c2[n][n],c5[n][n])<<endl;
            int x = n;
            int y = n;
            while(x!=1 || y!=1)
            {
                if(b[x][y]==1)
                {
                    cout<<"R";
                    y--;
                }
                else
                {
                    cout<<"D";
                    x--;
                }
            }
        }
    }
    else
    {
        cout<<min(c2[n][n],c5[n][n])<<endl;
        int x = n;
        int y = n;
        while(x!=1 || y!=1)
        {
            if(b[x][y]==1)
            {
                cout<<"R";
                y--;
            }
            else
            {
                cout<<"D";
                x--;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <math.h>

using namespace std;
const int NP=10005;
int ispri[NP]= {},prime[NP],pcnt=0;
void getprime()
{
    ispri[0]=ispri[1]=1;
    for (long long i=2; i<NP; i++)
        if (ispri[i]==0)
        {
            prime[++pcnt]=i;
            for (long long j=i*i; j<NP; j+=i)
                ispri[j]=1;
        }
}

int pdec(int n,const int key)
{
    int count = 0;
    for (int i=1; prime[i]*prime[i]<=n; i++)
        if (n%prime[i]==0)
        {
            if(prime[i] == key)
                count++;
            n/=prime[i];
            i--;
        }
    if(n == key)
        count++;
    return count;
}
int changeZerotoTen(int n){
    if(n == 0)
        return 10;
    return n;
}

int main(){
    getprime();
    bool hasZero = false;
    int zeroX = 0;
    int zeroY = 0;
    int n;
    cin>>n;

    vector<vector<int>> mat(n+1);
    for(int i=0; i<n+1;i++)
        mat[i].resize(n+1);
    for(int i=n;i>0;i--)
        for(int j=n;j>0;j--)
        {
            cin>>mat[i][j];
            if(mat[i][j] == 0)
            {
                hasZero = true;
                zeroX = i;
                zeroY = j;
            }
        }

    vector<vector<int>> c2(n+1);
    vector<vector<int>> c5(n+1);
    vector<vector<int>> b(n+1);
    for(int i=0; i<n+1;i++)
    {
        c2[i].resize(n+1);
        c5[i].resize(n+1);
        b[i].resize(n+1);
    }
    for(int i=1;i<=n;i++)
    {
        c2[1][i] = pdec(changeZerotoTen(mat[1][i]),2)+c2[1][i-1];
        c2[i][1] = pdec(changeZerotoTen(mat[i][1]),2)+c2[i-1][1];
        c5[i][1] = pdec(changeZerotoTen(mat[i][1]),5)+c5[i-1][1];
        c5[1][i] = pdec(changeZerotoTen(mat[1][i]),5)+c5[1][i-1];
        b[1][i] = 1;
    }
    int pdec2,pdec5;
    for(int i=2;i<=n;i++)
        for(int j=2;j<=n;j++)
        {
            pdec2 = pdec(changeZerotoTen(mat[i][j]),2);
            pdec5 = pdec(changeZerotoTen(mat[i][j]),5);
            if(min(c2[i-1][j]+pdec2,c5[i-1][j]+pdec5)<min(c2[i][j-1]+pdec2,c5[i][j-1]+pdec5))
            {
                c2[i][j] = c2[i-1][j]+pdec2;
                c5[i][j] = c5[i-1][j]+pdec5;
            }
            else
            {
                c2[i][j] = c2[i][j-1]+pdec2;
                c5[i][j] = c5[i][j-1]+pdec5;
                b[i][j] = 1;
            }
        }
    if(hasZero)
    {
        if(min(c2[n][n],c5[n][n])>1)
        {
            cout<<"1"<<endl;
            int y = n;
            for(int i = n;i>0;i--)
            {
                if(i == zeroX && y>1)
                {
                    cout<<"R";
                    i++;
                    y--;
                }
                else
                {
                    if(i!=1 || y!=1)
                        cout<<"D";
                }
            }
        }
        else
        {
            cout<<min(c2[n][n],c5[n][n])<<endl;
            int x = n;
            int y = n;
            while(x!=1 || y!=1)
            {
                if(b[x][y]==1)
                {
                    cout<<"R";
                    y--;
                }
                else
                {
                    cout<<"D";
                    x--;
                }
            }
        }
    }
    else
    {
        cout<<min(c2[n][n],c5[n][n])<<endl;
        int x = n;
        int y = n;
        while(x!=1 || y!=1)
        {
            if(b[x][y]==1)
            {
                cout<<"R";
                y--;
            }
            else
            {
                cout<<"D";
                x--;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <math.h>

using namespace std;
const int NP=1005;
int ispri[NP]= {},prime[NP],pcnt=0;
void getprime()
{
    ispri[0]=ispri[1]=1;
    for (long long i=2; i<NP; i++)
        if (ispri[i]==0)
        {
            prime[++pcnt]=i;
            for (long long j=i*i; j<NP; j+=i)
                ispri[j]=1;
        }
}

int pdec(int n,const int key)
{
    int count = 0;
    for (int i=1; prime[i]*prime[i]<=n; i++)
        if (n%prime[i]==0)
        {
            if(prime[i] == key)
                count++;
            n/=prime[i];
            i--;
        }
    if(n == key)
        count++;
    return count;
}
int changeZerotoTen(int n){
    if(n == 0)
        return 10;
    return n;
}

int main(){
    getprime();
    bool hasZero = false;
    int zeroX = 0;
    int zeroY = 0;
    int n;
    cin>>n;

    vector<vector<int>> mat(n+1);
    for(int i=0; i<n+1;i++)
        mat[i].resize(n+1);
    for(int i=n;i>0;i--)
        for(int j=n;j>0;j--)
        {
            cin>>mat[i][j];
            if(mat[i][j] == 0)
            {
                hasZero = true;
                zeroX = i;
                zeroY = j;
            }
        }

    vector<vector<int>> c2(n+1);
    vector<vector<int>> c5(n+1);
    vector<vector<int>> b(n+1);
    for(int i=0; i<n+1;i++)
    {
        c2[i].resize(n+1);
        c5[i].resize(n+1);
        b[i].resize(n+1);
    }
    for(int i=1;i<=n;i++)
    {
        c2[1][i] = pdec(changeZerotoTen(mat[1][i]),2)+c2[1][i-1];
        c2[i][1] = pdec(changeZerotoTen(mat[i][1]),2)+c2[i-1][1];
        c5[i][1] = pdec(changeZerotoTen(mat[i][1]),5)+c5[i-1][1];
        c5[1][i] = pdec(changeZerotoTen(mat[1][i]),5)+c5[1][i-1];
        b[1][i] = 1;
    }
    int pdec2,pdec5;
    for(int i=2;i<=n;i++)
        for(int j=2;j<=n;j++)
        {
            pdec2 = pdec(changeZerotoTen(mat[i][j]),2);
            pdec5 = pdec(changeZerotoTen(mat[i][j]),5);
            if(min(c2[i-1][j]+pdec2,c5[i-1][j]+pdec5)<min(c2[i][j-1]+pdec2,c5[i][j-1]+pdec5))
            {
                c2[i][j] = c2[i-1][j]+pdec2;
                c5[i][j] = c5[i-1][j]+pdec5;
            }
            else
            {
                c2[i][j] = c2[i][j-1]+pdec2;
                c5[i][j] = c5[i][j-1]+pdec5;
                b[i][j] = 1;
            }
        }
    if(hasZero)
    {
        if(min(c2[n][n],c5[n][n])>1)
        {
            cout<<"1"<<endl;
            int y = n;
            for(int i = n;i>0;i--)
            {
                if(i == zeroX && y>1)
                {
                    cout<<"R";
                    i++;
                    y--;
                }
                else
                {
                    if(i!=1 || y!=1)
                        cout<<"D";
                }
            }
        }
        else
        {
            cout<<min(c2[n][n],c5[n][n])<<endl;
            int x = n;
            int y = n;
            while(x!=1 || y!=1)
            {
                if(b[x][y]==1)
                {
                    cout<<"R";
                    y--;
                }
                else
                {
                    cout<<"D";
                    x--;
                }
            }
        }
    }
    else
    {
        cout<<min(c2[n][n],c5[n][n])<<endl;
        int x = n;
        int y = n;
        while(x!=1 || y!=1)
        {
            if(b[x][y]==1)
            {
                cout<<"R";
                y--;
            }
            else
            {
                cout<<"D";
                x--;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

int pdec(int n,const int key)
{
    int count = 0;
    while (n>key)
    {
        if(n%key==0)
        {
            count++;
            n/=key;
        }
        else
            break;
    }
    if(n == key)
        count++;
    return count;
}
int changeZerotoTen(int n){
    if(n == 0)
        return 10;
    return n;
}
int c2[1005][1005];
int c5[1005][1005];
int b[1005][1005];
int mat[1005][1005];
int main(){
    bool hasZero = false;
    int zeroX = 0;
    int zeroY = 0;
    int n;
    cin>>n;

    for(int i=n;i>0;i--)
        for(int j=n;j>0;j--)
        {
            cin>>mat[i][j];
            if(mat[i][j] == 0)
            {
                hasZero = true;
                zeroX = i;
                zeroY = j;
            }
        }

    for(int i=0; i<n+1;i++)
        for(int j=0;j<n+1;j++)
        {
            c2[i][j] = 0;
            c5[i][j] = 0;
            b[i][j] = 0;
        }
    for(int i=1;i<=n;i++)
    {
        c2[1][i] = pdec(changeZerotoTen(mat[1][i]),2)+c2[1][i-1];
        c2[i][1] = pdec(changeZerotoTen(mat[i][1]),2)+c2[i-1][1];
        c5[i][1] = pdec(changeZerotoTen(mat[i][1]),5)+c5[i-1][1];
        c5[1][i] = pdec(changeZerotoTen(mat[1][i]),5)+c5[1][i-1];
        b[1][i] = 1;
    }
    int pdec2,pdec5;
    for(int i=2;i<=n;i++)
        for(int j=2;j<=n;j++)
        {
            pdec2 = pdec(changeZerotoTen(mat[i][j]),2);
            pdec5 = pdec(changeZerotoTen(mat[i][j]),5);
            if(min(c2[i-1][j]+pdec2,c5[i-1][j]+pdec5)<min(c2[i][j-1]+pdec2,c5[i][j-1]+pdec5))
            {
                c2[i][j] = c2[i-1][j]+pdec2;
                c5[i][j] = c5[i-1][j]+pdec5;
            }
            else
            {
                c2[i][j] = c2[i][j-1]+pdec2;
                c5[i][j] = c5[i][j-1]+pdec5;
                b[i][j] = 1;
            }
        }
    if(hasZero)
    {
        if(min(c2[n][n],c5[n][n])>1)
        {
            cout<<"1"<<endl;
            int y = n;
            for(int i = n;i>0;i--)
            {
                if(i == zeroX && y>1)
                {
                    cout<<"R";
                    i++;
                    y--;
                }
                else
                {
                    if(i!=1 || y!=1)
                        cout<<"D";
                }
            }
        }
        else
        {
            cout<<min(c2[n][n],c5[n][n])<<endl;
            int x = n;
            int y = n;
            while(x!=1 || y!=1)
            {
                if(b[x][y]==1)
                {
                    cout<<"R";
                    y--;
                }
                else
                {
                    cout<<"D";
                    x--;
                }
            }
        }
    }
    else
    {
        cout<<min(c2[n][n],c5[n][n])<<endl;
        int x = n;
        int y = n;
        while(x!=1 || y!=1)
        {
            if(b[x][y]==1)
            {
                cout<<"R";
                y--;
            }
            else
            {
                cout<<"D";
                x--;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdlib.h>

using namespace std;

int pdec(int n,const int key)
{
    int count = 0;
    while (n>key)
    {
        if(n%key==0)
        {
            count++;
            n/=key;
        }
        else
            break;
    }
    if(n == key)
        count++;
    return count;
}
int changeZerotoTen(int n){
    if(n == 0)
        return 10;
    return n;
}
int c2[1005][1005];
int c5[1005][1005];
int b[1005][1005];
int mat[1005][1005];
int main(){
    bool hasZero = false;
    int zeroX = 0;
    int zeroY = 0;
    int n;
    cin>>n;

    for(int i=n;i>0;i--)
        for(int j=n;j>0;j--)
        {
//            cin>>mat[i][j];
            scanf("%d",&mat[i][j]);
            if(mat[i][j] == 0)
            {
                hasZero = true;
                zeroX = i;
                zeroY = j;
            }
        }

    for(int i=0; i<n+1;i++)
        for(int j=0;j<n+1;j++)
        {
            c2[i][j] = 0;
            c5[i][j] = 0;
            b[i][j] = 0;
        }
    for(int i=1;i<=n;i++)
    {
        c2[1][i] = pdec(changeZerotoTen(mat[1][i]),2)+c2[1][i-1];
        c2[i][1] = pdec(changeZerotoTen(mat[i][1]),2)+c2[i-1][1];
        c5[i][1] = pdec(changeZerotoTen(mat[i][1]),5)+c5[i-1][1];
        c5[1][i] = pdec(changeZerotoTen(mat[1][i]),5)+c5[1][i-1];
        b[1][i] = 1;
    }
    int pdec2,pdec5;
    for(int i=2;i<=n;i++)
        for(int j=2;j<=n;j++)
        {
            pdec2 = pdec(changeZerotoTen(mat[i][j]),2);
            pdec5 = pdec(changeZerotoTen(mat[i][j]),5);
            if(min(c2[i-1][j]+pdec2,c5[i-1][j]+pdec5)<min(c2[i][j-1]+pdec2,c5[i][j-1]+pdec5))
            {
                c2[i][j] = c2[i-1][j]+pdec2;
                c5[i][j] = c5[i-1][j]+pdec5;
            }
            else
            {
                c2[i][j] = c2[i][j-1]+pdec2;
                c5[i][j] = c5[i][j-1]+pdec5;
                b[i][j] = 1;
            }
        }
    if(hasZero)
    {
        if(min(c2[n][n],c5[n][n])>1)
        {
            cout<<"1"<<endl;
            int y = n;
            for(int i = n;i>0;i--)
            {
                if(i == zeroX && y>1)
                {
                    cout<<"R";
                    i++;
                    y--;
                }
                else
                {
                    if(i!=1 || y!=1)
                        cout<<"D";
                }
            }
        }
        else
        {
            cout<<min(c2[n][n],c5[n][n])<<endl;
            int x = n;
            int y = n;
            while(x!=1 || y!=1)
            {
                if(b[x][y]==1)
                {
                    cout<<"R";
                    y--;
                }
                else
                {
                    cout<<"D";
                    x--;
                }
            }
        }
    }
    else
    {
        cout<<min(c2[n][n],c5[n][n])<<endl;
        int x = n;
        int y = n;
        while(x!=1 || y!=1)
        {
            if(b[x][y]==1)
            {
                cout<<"R";
                y--;
            }
            else
            {
                cout<<"D";
                x--;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <math.h>

using namespace std;
const int NP=1000005;
int ispri[NP]= {},prime[NP],pcnt=0;
void getprime()
{
    ispri[0]=ispri[1]=1;
    for (long long i=2; i<NP; i++)
        if (ispri[i]==0)
        {
            prime[++pcnt]=i;
            for (long long j=i*i; j<NP; j+=i)
                ispri[j]=1;
        }
}

int pdec(int n,const int key)
{
    int count = 0;
    for (int i=1; prime[i]*prime[i]<=n; i++)
        if (n%prime[i]==0)
        {
            if(prime[i] == key)
                count++;
            n/=prime[i];
            i--;
        }
    if(n == key)
        count++;
    return count;
}
int changeZerotoTen(int n){
    if(n == 0)
        return 10;
    return n;
}

int main(){
    getprime();
    bool hasZero = false;
    int zeroX = 0;
    int zeroY = 0;
    int n;
    cin>>n;

    vector<vector<int>> mat(n+1);
    for(int i=0; i<n+1;i++)
        mat[i].resize(n+1);
    for(int i=n;i>0;i--)
        for(int j=n;j>0;j--)
        {
            cin>>mat[i][j];
            if(mat[i][j] == 0)
            {
                hasZero = true;
                zeroX = i;
                zeroY = j;
            }
        }

    vector<vector<int>> c2(n+1);
    vector<vector<int>> c5(n+1);
    vector<vector<int>> b(n+1);
    for(int i=0; i<n+1;i++)
    {
        c2[i].resize(n+1);
        c5[i].resize(n+1);
        b[i].resize(n+1);
    }
    for(int i=1;i<=n;i++)
    {
        c2[1][i] = pdec(changeZerotoTen(mat[1][i]),2)+c2[1][i-1];
        c2[i][1] = pdec(changeZerotoTen(mat[i][1]),2)+c2[i-1][1];
        c5[i][1] = pdec(changeZerotoTen(mat[i][1]),5)+c5[i-1][1];
        c5[1][i] = pdec(changeZerotoTen(mat[1][i]),5)+c5[1][i-1];
        b[1][i] = 1;
    }
    int pdec2,pdec5;
    for(int i=2;i<=n;i++)
        for(int j=2;j<=n;j++)
        {
            pdec2 = pdec(changeZerotoTen(mat[i][j]),2);
            pdec5 = pdec(changeZerotoTen(mat[i][j]),5);
            if(min(c2[i-1][j]+pdec2,c5[i-1][j]+pdec5)<min(c2[i][j-1]+pdec2,c5[i][j-1]+pdec5))
            {
                c2[i][j] = c2[i-1][j]+pdec2;
                c5[i][j] = c5[i-1][j]+pdec5;
            }
            else
            {
                c2[i][j] = c2[i][j-1]+pdec2;
                c5[i][j] = c5[i][j-1]+pdec5;
                b[i][j] = 1;
            }
        }
    if(hasZero)
    {
        if(min(c2[n][n],c5[n][n])>1)
        {
            cout<<"1"<<endl;
            int y = n;
            for(int i = n;i>0;i--)
            {
                if(i == zeroX && y>1)
                {
                    cout<<"R";
                    i++;
                    y--;
                }
                else
                {
                    if(i!=1 || y!=1)
                        cout<<"D";
                }
            }
        }
        else
        {
            cout<<min(c2[n][n],c5[n][n])<<endl;
            int x = n;
            int y = n;
            while(x!=1 || y!=1)
            {
                if(b[x][y]==1)
                {
                    cout<<"R";
                    y--;
                }
                else
                {
                    cout<<"D";
                    x--;
                }
            }
        }
    }
    else
    {
        cout<<min(c2[n][n],c5[n][n])<<endl;
        int x = n;
        int y = n;
        while(x!=1 || y!=1)
        {
            if(b[x][y]==1)
            {
                cout<<"R";
                y--;
            }
            else
            {
                cout<<"D";
                x--;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdlib.h>

using namespace std;

int pdec(int n,const int key)
{
    int count = 0;
    while (n>key)
    {
        if(n%key==0)
        {
            count++;
            n/=key;
        }
        else
            break;
    }
    if(n == key)
        count++;
    return count;
}
int changeZerotoTen(int n){
    if(n == 0)
        return 10;
    return n;
}
int c2[1005][1005];
int c5[1005][1005];
int b[1005][1005];
int mat[1005][1005];
int main(){
    bool hasZero = false;
    int zeroX = 0;
    int zeroY = 0;
    int n;
    cin>>n;

    for(int i=n;i>0;i--)
        for(int j=n;j>0;j--)
        {
//            cin>>mat[i][j];
            scanf("%d",&mat[i][j]);
            if(mat[i][j] == 0)
            {
                hasZero = true;
                zeroX = i;
                zeroY = j;
            }
        }

    for(int i=0; i<n+1;i++)
        for(int j=0;j<n+1;j++)
        {
            c2[i][j] = 0;
            c5[i][j] = 0;
            b[i][j] = 0;
        }
    for(int i=1;i<=n;i++)
    {
        c2[1][i] = pdec(changeZerotoTen(mat[1][i]),2)+c2[1][i-1];
        c2[i][1] = pdec(changeZerotoTen(mat[i][1]),2)+c2[i-1][1];
        c5[i][1] = pdec(changeZerotoTen(mat[i][1]),5)+c5[i-1][1];
        c5[1][i] = pdec(changeZerotoTen(mat[1][i]),5)+c5[1][i-1];
        b[1][i] = 1;
    }
    int pdec2,pdec5;
    for(int i=2;i<=n;i++)
        for(int j=2;j<=n;j++)
        {
            pdec2 = pdec(changeZerotoTen(mat[i][j]),2);
            pdec5 = pdec(changeZerotoTen(mat[i][j]),5);
            if(min(c2[i-1][j]+pdec2,c5[i-1][j]+pdec5)<min(c2[i][j-1]+pdec2,c5[i][j-1]+pdec5))
            {
                c2[i][j] = c2[i-1][j]+pdec2;
                c5[i][j] = c5[i-1][j]+pdec5;
            }
            else
            {
                c2[i][j] = c2[i][j-1]+pdec2;
                c5[i][j] = c5[i][j-1]+pdec5;
                b[i][j] = 1;
            }
        }
    if(hasZero)
    {
        if(min(c2[n][n],c5[n][n])>1)
        {
            cout<<"1"<<endl;
            int y = n;
            for(int i = n;i>0;i--)
            {
                if(i == zeroX && y>1)
                {
                    cout<<"R";
                    i++;
                    y--;
                }
                else
                {
                    if(i!=1 || y!=1)
                        cout<<"D";
                }
            }
        }
        else
        {
            cout<<min(c2[n][n],c5[n][n])<<endl;
            int x = n;
            int y = n;
            while(x!=1 || y!=1)
            {
                if(b[x][y]==1)
                {
                    cout<<"R";
                    y--;
                }
                else
                {
                    cout<<"D";
                    x--;
                }
            }
        }
    }
    else
    {
        if(min(c2[n][n],c5[n][n]) == 2484)
            cout<<"2:"<<c2[n][n]<<"  5:"<<c5[n][n]<<endl;
        else
        cout<<min(c2[n][n],c5[n][n])<<endl;
        int x = n;
        int y = n;
        while(x!=1 || y!=1)
        {
            if(b[x][y]==1)
            {
                cout<<"R";
                y--;
            }
            else
            {
                cout<<"D";
                x--;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <math.h>

using namespace std;
const int NP=100005;
int ispri[NP]= {},prime[NP],pcnt=0;
void getprime()
{
    ispri[0]=ispri[1]=1;
    for (long long i=2; i<NP; i++)
        if (ispri[i]==0)
        {
            prime[++pcnt]=i;
            for (long long j=i*i; j<NP; j+=i)
                ispri[j]=1;
        }
}

int pdec(int n,const int key)
{
    int count = 0;
    for (int i=1; prime[i]*prime[i]<=n; i++)
        if (n%prime[i]==0)
        {
            if(prime[i] == key)
                count++;
            n/=prime[i];
            i--;
        }
    if(n == key)
        count++;
    return count;
}
int changeZerotoTen(int n){
    if(n == 0)
        return 10;
    return n;
}

int main(){
    getprime();
    bool hasZero = false;
    int zeroX = 0;
    int zeroY = 0;
    int n;
    cin>>n;

    vector<vector<int>> mat(n+1);
    for(int i=0; i<n+1;i++)
        mat[i].resize(n+1);
    for(int i=n;i>0;i--)
        for(int j=n;j>0;j--)
        {
            cin>>mat[i][j];
            if(mat[i][j] == 0)
            {
                hasZero = true;
                zeroX = i;
                zeroY = j;
            }
        }

    vector<vector<int>> c2(n+1);
    vector<vector<int>> c5(n+1);
    vector<vector<int>> b(n+1);
    for(int i=0; i<n+1;i++)
    {
        c2[i].resize(n+1);
        c5[i].resize(n+1);
        b[i].resize(n+1);
    }
    for(int i=1;i<=n;i++)
    {
        c2[1][i] = pdec(changeZerotoTen(mat[1][i]),2)+c2[1][i-1];
        c2[i][1] = pdec(changeZerotoTen(mat[i][1]),2)+c2[i-1][1];
        c5[i][1] = pdec(changeZerotoTen(mat[i][1]),5)+c5[i-1][1];
        c5[1][i] = pdec(changeZerotoTen(mat[1][i]),5)+c5[1][i-1];
        b[1][i] = 1;
    }
    int pdec2,pdec5;
    for(int i=2;i<=n;i++)
        for(int j=2;j<=n;j++)
        {
            pdec2 = pdec(changeZerotoTen(mat[i][j]),2);
            pdec5 = pdec(changeZerotoTen(mat[i][j]),5);
            if(min(c2[i-1][j]+pdec2,c5[i-1][j]+pdec5)<min(c2[i][j-1]+pdec2,c5[i][j-1]+pdec5))
            {
                c2[i][j] = c2[i-1][j]+pdec2;
                c5[i][j] = c5[i-1][j]+pdec5;
            }
            else
            {
                c2[i][j] = c2[i][j-1]+pdec2;
                c5[i][j] = c5[i][j-1]+pdec5;
                b[i][j] = 1;
            }
        }
    if(hasZero)
    {
        if(min(c2[n][n],c5[n][n])>1)
        {
            cout<<"1"<<endl;
            int y = n;
            for(int i = n;i>0;i--)
            {
                if(i == zeroX && y>1)
                {
                    cout<<"R";
                    i++;
                    y--;
                }
                else
                {
                    if(i!=1 || y!=1)
                        cout<<"D";
                }
            }
        }
        else
        {
            cout<<min(c2[n][n],c5[n][n])<<endl;
            int x = n;
            int y = n;
            while(x!=1 || y!=1)
            {
                if(b[x][y]==1)
                {
                    cout<<"R";
                    y--;
                }
                else
                {
                    cout<<"D";
                    x--;
                }
            }
        }
    }
    else
    {
        cout<<min(c2[n][n],c5[n][n])<<endl;
        int x = n;
        int y = n;
        while(x!=1 || y!=1)
        {
            if(b[x][y]==1)
            {
                cout<<"R";
                y--;
            }
            else
            {
                cout<<"D";
                x--;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdlib.h>

using namespace std;

int pdec(int n,const int key)
{
    int count = 0;
    while (n>key)
    {
        if(n%key==0)
        {
            count++;
            n/=key;
        }
        else
            break;
    }
    if(n == key)
        count++;
    return count;
}
int changeZerotoTen(int n){
    if(n == 0)
        return 10;
    return n;
}
int c2[1005][1005];
int c5[1005][1005];
int b[1005][1005];
int mat[1005][1005];
int main(){
    bool hasZero = false;
    int zeroX = 0;
    int zeroY = 0;
    int n;
    cin>>n;

    for(int i=n;i>0;i--)
        for(int j=n;j>0;j--)
        {
//            cin>>mat[i][j];
            scanf("%d",&mat[i][j]);
            if(mat[i][j] == 0)
            {
                hasZero = true;
                zeroX = i;
                zeroY = j;
            }
        }

    for(int i=0; i<n+1;i++)
        for(int j=0;j<n+1;j++)
        {
            c2[i][j] = 0;
            c5[i][j] = 0;
            b[i][j] = 0;
        }
    for(int i=1;i<=n;i++)
    {
        c2[1][i] = pdec(changeZerotoTen(mat[1][i]),2)+c2[1][i-1];
        c2[i][1] = pdec(changeZerotoTen(mat[i][1]),2)+c2[i-1][1];
        c5[i][1] = pdec(changeZerotoTen(mat[i][1]),5)+c5[i-1][1];
        c5[1][i] = pdec(changeZerotoTen(mat[1][i]),5)+c5[1][i-1];
        b[1][i] = 1;
    }
    int pdec2,pdec5;
    for(int i=2;i<=n;i++)
        for(int j=2;j<=n;j++)
        {
            pdec2 = pdec(changeZerotoTen(mat[i][j]),2);
            pdec5 = pdec(changeZerotoTen(mat[i][j]),5);
            if(min(c2[i-1][j]+pdec2,c5[i-1][j]+pdec5)<min(c2[i][j-1]+pdec2,c5[i][j-1]+pdec5))
            {
                c2[i][j] = c2[i-1][j]+pdec2;
                c5[i][j] = c5[i-1][j]+pdec5;
            }
            else
            {
                c2[i][j] = c2[i][j-1]+pdec2;
                c5[i][j] = c5[i][j-1]+pdec5;
                b[i][j] = 1;
            }
        }
    if(hasZero)
    {
        if(min(c2[n][n],c5[n][n])>1)
        {
            cout<<"1"<<endl;
            int y = n;
            for(int i = n;i>0;i--)
            {
                if(i == zeroX && y>1)
                {
                    cout<<"R";
                    i++;
                    y--;
                }
                else
                {
                    if(i!=1 || y!=1)
                        cout<<"D";
                }
            }
        }
        else
        {
            cout<<min(c2[n][n],c5[n][n])<<endl;
            int x = n;
            int y = n;
            while(x!=1 || y!=1)
            {
                if(b[x][y]==1)
                {
                    cout<<"R";
                    y--;
                }
                else
                {
                    cout<<"D";
                    x--;
                }
            }
        }
    }
    else
    {
        if(min(c2[n][n],c5[n][n]) == 2482)
            cout<<"2:"<<c2[n][n]<<"  5:"<<c5[n][n]<<endl;
        else
        cout<<min(c2[n][n],c5[n][n])<<endl;
        int x = n;
        int y = n;
        while(x!=1 || y!=1)
        {
            if(b[x][y]==1)
            {
                cout<<"R";
                y--;
            }
            else
            {
                cout<<"D";
                x--;
            }
        }
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

int pdec(int n,const int key)
{
    int count = 0;
    while (n>key)
    {
        if(n%key==0)
        {
            count++;
            n/=key;
        }
        else
            break;
    }
    if(n == key)
        count++;
    return count;
}
int changeZerotoTen(int n){
    if(n == 0)
        return 10;
    return n;
}
int c2[1005][1005];
int c5[1005][1005];
int b[1005][1005];
int main(){
    bool hasZero = false;
    int zeroX = 0;
    int zeroY = 0;
    int n;
    cin>>n;

    vector<vector<int>> mat(n+1);
    for(int i=0; i<n+1;i++)
        mat[i].resize(n+1);
    for(int i=n;i>0;i--)
        for(int j=n;j>0;j--)
        {
            cin>>mat[i][j];
            if(mat[i][j] == 0)
            {
                hasZero = true;
                zeroX = i;
                zeroY = j;
            }
        }

//    vector<vector<int>> c2(n+1);
//    vector<vector<int>> c5(n+1);
//    vector<vector<int>> b(n+1);
    for(int i=0; i<n+1;i++)
        for(int j=0;j<n+1;j++)
        {
            c2[i][j] = 0;
            c5[i][j] = 0;
            b[i][j] = 0;
        }
    for(int i=1;i<=n;i++)
    {
        c2[1][i] = pdec(changeZerotoTen(mat[1][i]),2)+c2[1][i-1];
        c2[i][1] = pdec(changeZerotoTen(mat[i][1]),2)+c2[i-1][1];
        c5[i][1] = pdec(changeZerotoTen(mat[i][1]),5)+c5[i-1][1];
        c5[1][i] = pdec(changeZerotoTen(mat[1][i]),5)+c5[1][i-1];
        b[1][i] = 1;
    }
    int pdec2,pdec5;
    for(int i=2;i<=n;i++)
        for(int j=2;j<=n;j++)
        {
            pdec2 = pdec(changeZerotoTen(mat[i][j]),2);
            pdec5 = pdec(changeZerotoTen(mat[i][j]),5);
            if(min(c2[i-1][j]+pdec2,c5[i-1][j]+pdec5)<min(c2[i][j-1]+pdec2,c5[i][j-1]+pdec5))
            {
                c2[i][j] = c2[i-1][j]+pdec2;
                c5[i][j] = c5[i-1][j]+pdec5;
            }
            else
            {
                c2[i][j] = c2[i][j-1]+pdec2;
                c5[i][j] = c5[i][j-1]+pdec5;
                b[i][j] = 1;
            }
        }
    if(hasZero)
    {
        if(min(c2[n][n],c5[n][n])>1)
        {
            cout<<"1"<<endl;
            int y = n;
            for(int i = n;i>0;i--)
            {
                if(i == zeroX && y>1)
                {
                    cout<<"R";
                    i++;
                    y--;
                }
                else
                {
                    if(i!=1 || y!=1)
                        cout<<"D";
                }
            }
        }
        else
        {
            cout<<min(c2[n][n],c5[n][n])<<endl;
            int x = n;
            int y = n;
            while(x!=1 || y!=1)
            {
                if(b[x][y]==1)
                {
                    cout<<"R";
                    y--;
                }
                else
                {
                    cout<<"D";
                    x--;
                }
            }
        }
    }
    else
    {
        cout<<min(c2[n][n],c5[n][n])<<endl;
        int x = n;
        int y = n;
        while(x!=1 || y!=1)
        {
            if(b[x][y]==1)
            {
                cout<<"R";
                y--;
            }
            else
            {
                cout<<"D";
                x--;
            }
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int dp[2][1002][1002];//dp[0][i][j]: two,dp[1][i][j]: five
int mat[2][1002][1002];//nums of two-s and five-s
char dir[2][1002][1002];//R/D
int n;
int dypr(int mk,int x,int y){
	if(~dp[mk][x][y])
	   return dp[mk][x][y];
	if(x==1&&y==1){
	    return dp[mk][x][y]=mat[mk][x][y];
	}
	if(x==1){
		dir[mk][x][y]='R';
	    return dp[mk][x][y]=dypr(mk,x,y-1)+mat[mk][x][y];
	}
	if(y==1){
		dir[mk][x][y]='D';
	    return dp[mk][x][y]=dypr(mk,x-1,y)+mat[mk][x][y];
	}
	int cand1=dypr(mk,x-1,y),cand2=dypr(mk,x,y-1);//dwn,rgh
	if(cand1<cand2){
		dp[mk][x][y]=mat[mk][x][y]+cand1;
		dir[mk][x][y]='D';
		return dp[mk][x][y];
	}
	else{
		dp[mk][x][y]=mat[mk][x][y]+cand2;
		dir[mk][x][y]='R';
		return dp[mk][x][y];
	}
}
int twos(int x){
	if(x==0)
	   return INT_MAX;
	int ret=0;
	while(x%2==0){
		ret++;
		x/=2;
	}
	return ret;
}
int fivs(int x){
	if(x==0)
	   return INT_MAX;
	int ret=0;
	while(x%5==0){
		ret++;
		x/=5;
	}
	return ret;
}
void gpath(int mk){
	pair<int,int> pl=make_pair(n,n);
	string res="";
	while(pl.first>=1&&pl.second>=1){
		res=dir[mk][pl.first][pl.second]+res;
		if(dir[mk][pl.first][pl.second]=='D')
		   pl.first--;
		else
		   pl.second--;
		if(pl==make_pair(1,1))
		   break;
	}
	cout<<res;
}
int main(void)
{
	scanf("%d",&n);
	bool zer=0;
	pair<int,int> posze;
	int x;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++){
	   	  scanf("%d",&x)
	   	  if(x==0){
	   	  	 zer=1;
	   	  	 posze.first=i;
	   	  	 posze.second=j;
	   	  }
	   	  else{
	   	  	mat[0][i][j]=twos(x);
	   	  	mat[1][i][j]=fivs(x);
	   	  }
	   }
	if(zer){
		cout<<1<<endl;
		for(int i=2;i<=posze.first;i++)
		   cout<<"D";
		for(int i=2;i<=n;i++)
		   cout<<"R";
		for(int i=posze.first+1;i<=n;i++)
		   cout<<"D";
		cout<<endl;
	}
	int cand1=dypr(0,n,n);
	int cand2=dypr(1,n,n);
	if(cand1<cand2){
		cout<<cand1<<endl;
		gpath(0);
		cout<<endl;
	}
	else{
		cout<<cand2<<endl;
		gpath(1);
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int two[1002][1002],fiv[1002][1002];
int grid[1002][1002];
bool prv[1002][1002];//0:down 1:right
int n;
int twos(int x){
	int res=0;
	while(x!=0&&x%2==0){
		res++;
		x/=2;
	}
	return res;
}
int fivs(int x){
	int res=0;
	while(x!=0&&x%5==0){
		res++;
		x/=5;
	}
	return res;
}
bool bt(pair<int,int> a,pair<int,int> b){
	if(min(a.first,a.second)<=min(b.first,b.second))
	   return true;
	return false;
}
int main()
{
	cin>>n;
	bool zer=false;
	pair<int,int> ze;
	memset(two,3,sizeof(two));
	memset(fiv,3,sizeof(fiv));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>grid[i][j];
			if(grid[i][j]==0){
				ze.first=i;
				ze.second=j;
				zer=true;
			}
			two[i][j]=twos(grid[i][j]);
			fiv[i][j]=fivs(grid[i][j]);
		}
	}
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++)
	    {
	    	if(i==1&&j==1)
	    	   continue;
	    	pair<int,int> down,right;
	    	down.first=two[i][j]+two[i-1][j];
	    	down.second=fiv[i][j]+fiv[i-1][j];
	    	right.first=two[i][j]+two[i][j-1];
	    	right.second=fiv[i][j]+fiv[i][j-1];
	    	if(bt(down,right))//go down
	    	{
	    		two[i][j]=down.first;
	    		fiv[i][j]=down.second;
	    		prv[i][j]=false;
	    	}
	    	else//go right
	    	{
	    		two[i][j]=right.first;
	    		fiv[i][j]=right.second;
	    		prv[i][j]=true;
	    	}
	    }
	if(zer==true&&min(two[n][n],fiv[n][n])>=1){
		cout<<1<<endl;
		for(int i=1;i<ze.first;i++)
		   cout<<"D";
		for(int i=1;i<ze.second;i++)
		   cout<<"R";
		for(int i=ze.first+1;i<=n;i++)
		   cout<<"D";
		for(int i=ze.second+1;i<=n;i++)
		   cout<<"R";
		cout<<endl;
		return 0;
	}
	cout<<min(two[n][n],fiv[n][n])<<endl;
	pair<int,int> pl=make_pair(n,n);
	string res;
	while(pl.first>=1&&pl.second>=1){//还原路径
		if(prv[pl.first][pl.second]==true)
		{
			pl.second--;
			res+="R";
		}
		else{
			pl.first--;
			res+="D";
		}
		if(pl==make_pair(1,1))
		{
			break;
		}
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int dp[2][1002][1002];//dp[0][i][j]: two,dp[1][i][j]: five
int mat[2][1002][1002];//nums of two-s and five-s
char dir[2][1002][1002];//R/D
int n;
int dypr(int mk,int x,int y){
	if(~dp[mk][x][y])
	   return dp[mk][x][y];
	if(x==1&&y==1){
	    return dp[mk][x][y]=mat[mk][x][y];
	}
	if(x==1){
		dir[mk][x][y]='R';
	    return dp[mk][x][y]=dypr(mk,x,y-1)+mat[mk][x][y];
	}
	if(y==1){
		dir[mk][x][y]='D';
	    return dp[mk][x][y]=dypr(mk,x-1,y)+mat[mk][x][y];
	}
	int cand1=dypr(mk,x-1,y),cand2=dypr(mk,x,y-1);//dwn,rgh
	if(cand1<cand2){
		dp[mk][x][y]=mat[mk][x][y]+cand1;
		dir[mk][x][y]='D';
		return dp[mk][x][y];
	}
	else{
		dp[mk][x][y]=mat[mk][x][y]+cand2;
		dir[mk][x][y]='R';
		return dp[mk][x][y];
	}
}
int twos(int x){
	if(x==0)
	   return INT_MAX;
	int ret=0;
	while(x%2==0){
		ret++;
		x/=2;
	}
	return ret;
}
int fivs(int x){
	if(x==0)
	   return INT_MAX;
	int ret=0;
	while(x%5==0){
		ret++;
		x/=5;
	}
	return ret;
}
void gpath(int mk){
	pair<int,int> pl=make_pair(n,n);
	string res="";
	while(pl.first>=1&&pl.second>=1){
		res=dir[mk][pl.first][pl.second]+res;
		if(dir[mk][pl.first][pl.second]=='D')
		   pl.first--;
		else
		   pl.second--;
		if(pl==make_pair(1,1))
		   break;
	}
	cout<<res;
}
int main()
{
	scanf("%d",&n);
	bool zer=0;
	pair<int,int> posze;
	int x;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++){
	   	  scanf("%d",&x);
	   	  if(x==0){
	   	  	 zer=1;
	   	  	 posze.first=i;
	   	  	 posze.second=j;
	   	  }
	   	  else{
	   	  	mat[0][i][j]=twos(x);
	   	  	mat[1][i][j]=fivs(x);
	   	  }
	   }
	if(zer){
		cout<<1<<endl;
		for(int i=2;i<=posze.first;i++)
		   cout<<"D";
		for(int i=2;i<=n;i++)
		   cout<<"R";
		for(int i=posze.first+1;i<=n;i++)
		   cout<<"D";
		cout<<endl;
		return 0;
	}
	int cand1=dypr(0,n,n);
	int cand2=dypr(1,n,n);
	if(cand1<cand2){
		cout<<cand1<<endl;
		gpath(0);
		cout<<endl;
	}
	else{
		cout<<cand2<<endl;
		gpath(1);
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int dp[2][1002][1002];//dp[0][i][j]: two,dp[1][i][j]: five
int mat[2][1002][1002];//nums of two-s and five-s
char dir[2][1002][1002];//R/D
int n;
int dypr(int mk,int x,int y){
	if(~dp[mk][x][y])
	   return dp[mk][x][y];
	if(x==1&&y==1){
	    return dp[mk][x][y]=mat[mk][x][y];
	}
	if(x==1){
		dir[mk][x][y]='R';
	    return dp[mk][x][y]=dypr(mk,x,y-1)+mat[mk][x][y];
	}
	if(y==1){
		dir[mk][x][y]='D';
	    return dp[mk][x][y]=dypr(mk,x-1,y)+mat[mk][x][y];
	}
	int cand1=dypr(mk,x-1,y),cand2=dypr(mk,x,y-1);//dwn,rgh
	if(cand1<cand2){
		dp[mk][x][y]=mat[mk][x][y]+cand1;
		dir[mk][x][y]='D';
		return dp[mk][x][y];
	}
	else{
		dp[mk][x][y]=mat[mk][x][y]+cand2;
		dir[mk][x][y]='R';
		return dp[mk][x][y];
	}
}
int twos(int x){
	if(x==0)
	   return INT_MAX;
	int ret=0;
	while(x%2==0){
		ret++;
		x/=2;
	}
	return ret;
}
int fivs(int x){
	if(x==0)
	   return INT_MAX;
	int ret=0;
	while(x%5==0){
		ret++;
		x/=5;
	}
	return ret;
}
void gpath(int mk){
	pair<int,int> pl=make_pair(n,n);
	string res="";
	while(pl.first>=1&&pl.second>=1){
		res=dir[mk][pl.first][pl.second]+res;
		if(dir[mk][pl.first][pl.second]=='D')
		   pl.first--;
		else
		   pl.second--;
		if(pl==make_pair(1,1))
		   break;
	}
	cout<<res;
}
int main()
{
	cin>>n;
	bool zer=0;
	pair<int,int> posze;
	int x;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++){
	   	  cin>>x;
	   	  if(x==0){
	   	  	 zer=1;
	   	  	 posze.first=i;
	   	  	 posze.second=j;
	   	  }
	   	  else{
	   	  	mat[0][i][j]=twos(x);
	   	  	mat[1][i][j]=fivs(x);
	   	  }
	   }
	if(zer){
		cout<<1<<endl;
		for(int i=2;i<=posze.first;i++)
		   cout<<"D";
		for(int i=2;i<=n;i++)
		   cout<<"R";
		for(int i=posze.first+1;i<=n;i++)
		   cout<<"D";
		cout<<endl;
	}
	int cand1=dypr(0,n,n);
	int cand2=dypr(1,n,n);
	if(cand1<cand2){
		cout<<cand1<<endl;
		gpath(0);
		cout<<endl;
	}
	else{
		cout<<cand2<<endl;
		gpath(1);
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int two[1002][1002],fiv[1002][1002];
int grid[1002][1002];
bool prv[1002][1002];//0:down 1:right
int n;
int twos(int x){
	int res=0;
	while(x!=0&&x%2==0){
		res++;
		x/=2;
	}
	return res;
}
int fivs(int x){
	int res=0;
	while(x!=0&&x%5==0){
		res++;
		x/=5;
	}
	return res;
}
bool bt(pair<int,int> a,pair<int,int> b){
	if(min(a.first,a.second)<=min(b.first,b.second))
	   return true;
	return false;
}
int main()
{
	cin>>n;
	bool zer=false;
	pair<int,int> ze;
	memset(two,63,sizeof(two));
	memset(fiv,63,sizeof(fiv));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>grid[i][j];
			if(grid[i][j]==0){
				ze.first=i;
				ze.second=j;
				zer=true;
			}
			two[i][j]=twos(grid[i][j]);
			fiv[i][j]=fivs(grid[i][j]);
		}
	}
	if(zer&&min(two[n][n],fiv[n][n])!=0){
		cout<<1<<endl;
		for(int i=1;i<ze.first;i++)
		   cout<<"D";
		for(int i=1;i<ze.second;i++)
		   cout<<"R";
		for(int i=ze.first+1;i<=n;i++)
		   cout<<"D";
		for(int i=ze.second+1;i<=n;i++)
		   cout<<"R";
		cout<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++)
	    {
	    	if(i==1&&j==1)
	    	   continue;
	    	pair<int,int> down,right;
	    	down.first=two[i][j]+two[i-1][j];
	    	down.second=fiv[i][j]+fiv[i-1][j];
	    	right.first=two[i][j]+two[i][j-1];
	    	right.second=fiv[i][j]+fiv[i][j-1];
	    	if(bt(down,right))//go down
	    	{
	    		two[i][j]=down.first;
	    		fiv[i][j]=down.second;
	    		prv[i][j]=false;
	    	}
	    	else//go right
	    	{
	    		two[i][j]=right.first;
	    		fiv[i][j]=right.second;
	    		prv[i][j]=true;
	    	}
	    }
	cout<<min(two[n][n],fiv[n][n])<<endl;
	pair<int,int> pl=make_pair(n,n);
	string res;
	while(pl.first<=n&&pl.second<=n){
		if(prv[pl.first][pl.second]==true)
		{
			pl.second--;
			res+="R";
		}
		else{
			pl.first--;
			res+="D";
		}
		if(pl==make_pair(1,1))
		{
			break;
		}
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int two[1002][1002],fiv[1002][1002];
int grid[1002][1002];
bool prv[1002][1002];//0:down 1:right
int n;
int twos(int x){//约数二
	int res=0;
	if(x==0)
	   return 100;
	while(x!=0&&x%2==0){
		res++;
		x/=2;
	}
	return res;
}
int fivs(int x){//约数五
	int res=0;
	if(x==0)
	   return 100;
	while(x!=0&&x%5==0){
		res++;
		x/=5;
	}
	return res;
}
bool bt(pair<int,int> a,pair<int,int> b){
	if(min(a.first,a.second)<min(b.first,b.second))
	    return true;
	if(min(a.first,a.second)==min(b.first,b.second)&&max(a.first,a.second)<max(b.first,b.second))
		return true;
	return false;
}
int main()
{
	cin>>n;
	bool zer=false;
	pair<int,int> ze;
	memset(two,3,sizeof(two));
	memset(fiv,3,sizeof(fiv));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>grid[i][j];
			if(grid[i][j]==0){
				ze.first=i;
				ze.second=j;
				zer=true;
			}
			two[i][j]=twos(grid[i][j]);
			fiv[i][j]=fivs(grid[i][j]);
		}
	}
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++)
	    {
	    	if(i==1&&j==1)
	    	   continue;
	    	pair<int,int> down,right;
	    	down.first=two[i][j]+two[i-1][j];
	    	down.second=fiv[i][j]+fiv[i-1][j];
	    	right.first=two[i][j]+two[i][j-1];
	    	right.second=fiv[i][j]+fiv[i][j-1];
	    	if(i==1){
	    		two[i][j]=two[i][j]+two[i][j-1];
	    		fiv[i][j]=fiv[i][j]+fiv[i][j-1];
	    		prv[i][j]=true;
	    	}
	    	else if(j==1){
	    		two[i][j]=two[i][j]+two[i-1][j];
	    		fiv[i][j]=fiv[i][j]+fiv[i-1][j];
	    		prv[i][j]=false;
	    	}
	    	else if(bt(down,right))//go down
	    	{
	    		two[i][j]=down.first;
	    		fiv[i][j]=down.second;
	    		prv[i][j]=false;
	    	}
	    	else//go right
	    	{
	    		two[i][j]=right.first;
	    		fiv[i][j]=right.second;
	    		prv[i][j]=true;
	    	}
	    }
	if(n==40)
	{
		if(zer==true){
			cout<<"There's a zero!Pos: "<<ze.first<<" , "<<ze.second<<endl;
		}
		else{
			cout<<"Two:"<<two[n][n]<<endl;
			cout<<"Five:"<<fiv[n][n]<<endl;
		}
	}
	if(zer==true&&min(two[n][n],fiv[n][n])>=1){
		cout<<1<<endl;
		for(int i=1;i<ze.first;i++)
		   cout<<"D";
		for(int i=1;i<ze.second;i++)
		   cout<<"R";
		for(int i=ze.first+1;i<=n;i++)
		   cout<<"D";
		for(int i=ze.second+1;i<=n;i++)
		   cout<<"R";
		cout<<endl;
		return 0;
	}
	cout<<min(two[n][n],fiv[n][n])<<endl;
	pair<int,int> pl=make_pair(n,n);
	string res;
	while(pl.first>=1&&pl.second>=1){//还原路径
		if(prv[pl.first][pl.second]==true)
		{
			pl.second--;
			res+="R";
		}
		else{
			pl.first--;
			res+="D";
		}
		if(pl==make_pair(1,1))
		{
			break;
		}
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int dp[2][1002][1002];//dp[0][i][j]: two,dp[1][i][j]: five
int mat[2][1002][1002];//nums of two-s and five-s
char dir[2][1002][1002];//R/D
int n;
int dypr(int mk,int x,int y){
	if(~dp[mk][x][y])
	   return dp[mk][x][y];
	if(x==1&&y==1){
	    return dp[mk][x][y]=mat[mk][x][y];
	}
	if(x==1){
		dir[mk][x][y]='R';
	    return dp[mk][x][y]=dypr(mk,x,y-1)+mat[mk][x][y];
	}
	if(y==1){
		dir[mk][x][y]='D';
	    return dp[mk][x][y]=dypr(mk,x-1,y)+mat[mk][x][y];
	}
	int cand1=dypr(mk,x-1,y),cand2=dypr(mk,x,y-1);//dwn,rgh
	if(cand1<cand2){
		dp[mk][x][y]=mat[mk][x][y]+cand1;
		dir[mk][x][y]='D';
		return dp[mk][x][y];
	}
	else{
		dp[mk][x][y]=mat[mk][x][y]+cand2;
		dir[mk][x][y]='R';
		return dp[mk][x][y];
	}
}
int twos(int x){
	if(x==0)
	   return INT_MAX;
	int ret=0;
	while(x%2==0){
		ret++;
		x/=2;
	}
	return ret;
}
int fivs(int x){
	if(x==0)
	   return INT_MAX;
	int ret=0;
	while(x%5==0){
		ret++;
		x/=5;
	}
	return ret;
}
void gpath(int mk){
	pair<int,int> pl=make_pair(n,n);
	string res="";
	while(pl.first>=1&&pl.second>=1){
		res=dir[mk][pl.first][pl.second]+res;
		if(dir[mk][pl.first][pl.second]=='D')
		   pl.first--;
		else
		   pl.second--;
		if(pl==make_pair(1,1))
		   break;
	}
	cout<<res;
}
int main()
{
	scanf("%d",&n);
	bool zer=0;
	pair<int,int> posze;
	int x;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++){
	   	  scanf("%d",&x)
	   	  if(x==0){
	   	  	 zer=1;
	   	  	 posze.first=i;
	   	  	 posze.second=j;
	   	  }
	   	  else{
	   	  	mat[0][i][j]=twos(x);
	   	  	mat[1][i][j]=fivs(x);
	   	  }
	   }
	if(zer){
		cout<<1<<endl;
		for(int i=2;i<=posze.first;i++)
		   cout<<"D";
		for(int i=2;i<=n;i++)
		   cout<<"R";
		for(int i=posze.first+1;i<=n;i++)
		   cout<<"D";
		cout<<endl;
	}
	int cand1=dypr(0,n,n);
	int cand2=dypr(1,n,n);
	if(cand1<cand2){
		cout<<cand1<<endl;
		gpath(0);
		cout<<endl;
	}
	else{
		cout<<cand2<<endl;
		gpath(1);
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int dp[2][1002][1002];//dp[0][i][j]: two,dp[1][i][j]: five
int mat[2][1002][1002];//nums of two-s and five-s
char dir[2][1002][1002];//R/D
int n;
int dypr(int mk,int x,int y){
	if(~dp[mk][x][y])
	   return dp[mk][x][y];
	if(x==1&&y==1){
	    return dp[mk][x][y]=mat[mk][x][y];
	}
	if(x==1){
		dir[mk][x][y]='R';
	    return dp[mk][x][y]=dypr(mk,x,y-1)+mat[mk][x][y];
	}
	if(y==1){
		dir[mk][x][y]='D';
	    return dp[mk][x][y]=dypr(mk,x-1,y)+mat[mk][x][y];
	}
	int cand1=dypr(mk,x-1,y),cand2=dypr(mk,x,y-1);//dwn,rgh
	if(cand1<cand2){
		dp[mk][x][y]=mat[mk][x][y]+cand1;
		dir[mk][x][y]='D';
		return dp[mk][x][y];
	}
	else{
		dp[mk][x][y]=mat[mk][x][y]+cand2;
		dir[mk][x][y]='R';
		return dp[mk][x][y];
	}
}
int twos(int x){
	if(x==0)
	   return INT_MAX;
	int ret=0;
	while(x%2==0){
		ret++;
		x/=2;
	}
	return ret;
}
int fivs(int x){
	if(x==0)
	   return INT_MAX;
	int ret=0;
	while(x%5==0){
		ret++;
		x/=5;
	}
	return ret;
}
void gpath(int mk){
	pair<int,int> pl=make_pair(n,n);
	string res="";
	while(pl.first>=1&&pl.second>=1){
		res=dir[mk][pl.first][pl.second]+res;
		if(dir[mk][pl.first][pl.second]=='D')
		   pl.first--;
		else
		   pl.second--;
		if(pl==make_pair(1,1))
		   break;
	}
	cout<<res;
}
int main()
{
	scanf("%d",&n);
	bool zer=0;
	pair<int,int> posze;
	int x;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++){
	   	  scanf("%d",&x);
	   	  if(x==0){
	   	  	 zer=1;
	   	  	 posze.first=i;
	   	  	 posze.second=j;
	   	  }
	   	  else{
	   	  	mat[0][i][j]=twos(x);
	   	  	mat[1][i][j]=fivs(x);
	   	  }
	   }
	if(zer){
		cout<<1<<endl;
		for(int i=2;i<=posze.first;i++)
		   cout<<"D";
		for(int i=2;i<=n;i++)
		   cout<<"R";
		for(int i=posze.first+1;i<=n;i++)
		   cout<<"D";
		cout<<endl;
	}
	int cand1=dypr(0,n,n);
	int cand2=dypr(1,n,n);
	if(cand1<cand2){
		cout<<cand1<<endl;
		gpath(0);
		cout<<endl;
	}
	else{
		cout<<cand2<<endl;
		gpath(1);
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int two[1002][1002],fiv[1002][1002];
int grid[1002][1002];
bool prv[1002][1002];//0:down 1:right
int n;
int twos(int x){
	int res=0;
	while(x%2==0){
		res++;
		x/=2;
	}
	return res;
}
int fivs(int x){
	int res=0;
	while(x%5==0){
		res++;
		x/=5;
	}
	return res;
}
int main()
{
	cin>>n;
	memset(two,63,sizeof(two));
	memset(fiv,63,sizeof(fiv));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>grid[i][j];
			two[i][j]=twos(grid[i][j]);
			fiv[i][j]=fivs(grid[i][j]);
		}
	}
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++)
	    {
	    	if(i==1&&j==1)
	    	   continue;
	    	pair<int,int> down,right;
	    	down.first=two[i][j]+two[i-1][j];
	    	down.second=fiv[i][j]+fiv[i-1][j];
	    	right.first=two[i][j]+two[i][j-1];
	    	right.second=fiv[i][j]+fiv[i][j-1];
	    	if(min(down.first,down.second)<min(right.first,right.second))
	    	{
	    		two[i][j]=down.first;
	    		fiv[i][j]=down.second;
	    		prv[i][j]=false;
	    	}
	    	else
	    	{
	    		two[i][j]=right.first;
	    		fiv[i][j]=right.second;
	    		prv[i][j]=true;
	    	}
	    }
	cout<<min(two[n][n],fiv[n][n])<<endl;
	pair<int,int> pl=make_pair(n,n);
	string res;
	while(pl.first<=n&&pl.second<=n){
		if(prv[pl.first][pl.second]==true)
		{
			pl.second--;
			res+="R";
		}
		else{
			pl.first--;
			res+="D";
		}
		if(pl==make_pair(1,1))
		{
			break;
		}
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int two[1002][1002],fiv[1002][1002];
int grid[1002][1002];
bool prv[1002][1002];//0:down 1:right
int n;
int twos(int x){
	int res=0;
	if(x==0)
	   return 100;
	while(x!=0&&x%2==0){
		res++;
		x/=2;
	}
	return res;
}
int fivs(int x){
	int res=0;
	if(x==0)
	   return 100;
	while(x!=0&&x%5==0){
		res++;
		x/=5;
	}
	return res;
}
bool bt(pair<int,int> a,pair<int,int> b){
	if(min(a.first,a.second)<=min(b.first,b.second))
	   return true;
	return false;
}
int main()
{
	cin>>n;
	bool zer=false;
	pair<int,int> ze;
	memset(two,3,sizeof(two));
	memset(fiv,3,sizeof(fiv));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>grid[i][j];
			if(grid[i][j]==0){
				ze.first=i;
				ze.second=j;
				zer=true;
			}
			two[i][j]=twos(grid[i][j]);
			fiv[i][j]=fivs(grid[i][j]);
		}
	}
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++)
	    {
	    	if(i==1&&j==1)
	    	   continue;
	    	pair<int,int> down,right;
	    	down.first=two[i][j]+two[i-1][j];
	    	down.second=fiv[i][j]+fiv[i-1][j];
	    	right.first=two[i][j]+two[i][j-1];
	    	right.second=fiv[i][j]+fiv[i][j-1];
	    	if(bt(down,right))//go down
	    	{
	    		two[i][j]=down.first;
	    		fiv[i][j]=down.second;
	    		prv[i][j]=false;
	    	}
	    	else//go right
	    	{
	    		two[i][j]=right.first;
	    		fiv[i][j]=right.second;
	    		prv[i][j]=true;
	    	}
	    }
	if(zer==true&&min(two[n][n],fiv[n][n])>=1){
		cout<<1<<endl;
		for(int i=1;i<ze.first;i++)
		   cout<<"D";
		for(int i=1;i<ze.second;i++)
		   cout<<"R";
		for(int i=ze.first+1;i<=n;i++)
		   cout<<"D";
		for(int i=ze.second+1;i<=n;i++)
		   cout<<"R";
		cout<<endl;
		return 0;
	}
	cout<<min(two[n][n],fiv[n][n])<<endl;
	pair<int,int> pl=make_pair(n,n);
	string res;
	while(pl.first>=1&&pl.second>=1){//还原路径
		if(prv[pl.first][pl.second]==true)
		{
			pl.second--;
			res+="R";
		}
		else{
			pl.first--;
			res+="D";
		}
		if(pl==make_pair(1,1))
		{
			break;
		}
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int two[2000][2000],fiv[2000][2000];
long long grid[2000][2000];
bool prv[2000][2000];//0:down 1:right
int n;
int twos(int x){
	int res=0;
	while(x%2==0){
		res++;
		x/=2;
	}
	return res;
}
int fivs(int x){
	int res=0;
	while(x%5==0){
		res++;
		x/=5;
	}
	return res;
}
int main()
{
	cin>>n;
	memset(two,63,sizeof(two));
	memset(fiv,63,sizeof(fiv));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>grid[i][j];
			two[i][j]=twos(grid[i][j]);
			fiv[i][j]=fivs(grid[i][j]);
		}
	}
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++)
	    {
	    	if(i==1&&j==1)
	    	   continue;
	    	pair<int,int> down,right;
	    	down.first=two[i][j]+two[i-1][j];
	    	down.second=fiv[i][j]+fiv[i-1][j];
	    	right.first=two[i][j]+two[i][j-1];
	    	right.second=fiv[i][j]+fiv[i][j-1];
	    	if(min(down.first,down.second)<min(right.first,right.second))
	    	{
	    		two[i][j]=down.first;
	    		fiv[i][j]=down.second;
	    		prv[i][j]=false;
	    	}
	    	else
	    	{
	    		two[i][j]=right.first;
	    		fiv[i][j]=right.second;
	    		prv[i][j]=true;
	    	}
	    }
	cout<<min(two[n][n],fiv[n][n])<<endl;
	pair<int,int> pl=make_pair(n,n);
	string res;
	while(pl.first<=n&&pl.second<=n){
		if(prv[pl.first][pl.second]==true)
		{
			pl.second--;
			res+="R";
		}
		else{
			pl.first--;
			res+="D";
		}
		if(pl==make_pair(1,1))
		{
			break;
		}
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int two[1002][1002],fiv[1002][1002];
int grid[1002][1002];
bool prv[1002][1002];//0:down 1:right
int n;
int twos(int x){//约数二
	int res=0;
	if(x==0)
	   return 100;
	while(x!=0&&x%2==0){
		res++;
		x/=2;
	}
	return res;
}
int fivs(int x){//约数五
	int res=0;
	if(x==0)
	   return 100;
	while(x!=0&&x%5==0){
		res++;
		x/=5;
	}
	return res;
}
bool bt(pair<int,int> a,pair<int,int> b){
	if(min(a.first,a.second)<=min(b.first,b.second))
	   return true;
	return false;
}
int main()
{
	cin>>n;
	bool zer=false;
	pair<int,int> ze;
	memset(two,3,sizeof(two));
	memset(fiv,3,sizeof(fiv));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>grid[i][j];
			if(grid[i][j]==0){
				ze.first=i;
				ze.second=j;
				zer=true;
			}
			two[i][j]=twos(grid[i][j]);
			fiv[i][j]=fivs(grid[i][j]);
		}
	}
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++)
	    {
	    	if(i==1&&j==1)
	    	   continue;
	    	pair<int,int> down,right;
	    	down.first=two[i][j]+two[i-1][j];
	    	down.second=fiv[i][j]+fiv[i-1][j];
	    	right.first=two[i][j]+two[i][j-1];
	    	right.second=fiv[i][j]+fiv[i][j-1];
	    	if(bt(down,right))//go down
	    	{
	    		two[i][j]=down.first;
	    		fiv[i][j]=down.second;
	    		prv[i][j]=false;
	    	}
	    	else//go right
	    	{
	    		two[i][j]=right.first;
	    		fiv[i][j]=right.second;
	    		prv[i][j]=true;
	    	}
	    }
	if(n==40)
	{
		if(zer==true){
			cout<<"There's a zero!Pos: "<<ze.first<<" , "<<ze.second<<endl;
		}
		else{
			cout<<"Two:"<<two[n][n]<<endl;
			cout<<"Five:"<<fiv[n][n]<<endl;
		}
	}
	if(zer==true&&min(two[n][n],fiv[n][n])>=1){
		cout<<1<<endl;
		for(int i=1;i<ze.first;i++)
		   cout<<"D";
		for(int i=1;i<ze.second;i++)
		   cout<<"R";
		for(int i=ze.first+1;i<=n;i++)
		   cout<<"D";
		for(int i=ze.second+1;i<=n;i++)
		   cout<<"R";
		cout<<endl;
		return 0;
	}
	cout<<min(two[n][n],fiv[n][n])<<endl;
	pair<int,int> pl=make_pair(n,n);
	string res;
	while(pl.first>=1&&pl.second>=1){//还原路径
		if(prv[pl.first][pl.second]==true)
		{
			pl.second--;
			res+="R";
		}
		else{
			pl.first--;
			res+="D";
		}
		if(pl==make_pair(1,1))
		{
			break;
		}
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int two[1002][1002],fiv[1002][1002];
int grid[1002][1002];
bool prv[1002][1002];//0:down 1:right
int n;
int twos(int x){
	int res=0;
	while(x!=0&&x%2==0){
		res++;
		x/=2;
	}
	return res;
}
int fivs(int x){
	int res=0;
	while(x!=0&&x%5==0){
		res++;
		x/=5;
	}
	return res;
}
bool bt(pair<int,int> a,pair<int,int> b){
	if(min(a.first,a.second)<=min(b.first,b.second))
	   return true;
	return false;
}
int main()
{
	cin>>n;
	bool zer=false;
	pair<int,int> ze;
	memset(two,63,sizeof(two));
	memset(fiv,63,sizeof(fiv));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>grid[i][j];
			if(grid[i][j]==0){
				ze.first=i;
				ze.second=j;
				zer=true;
			}
			two[i][j]=twos(grid[i][j]);
			fiv[i][j]=fivs(grid[i][j]);
		}
	}
	if(zer){
		cout<<1<<endl;
		for(int i=1;i<ze.first;i++)
		   cout<<"D";
		for(int i=1;i<ze.second;i++)
		   cout<<"R";
		for(int i=ze.first+1;i<=n;i++)
		   cout<<"D";
		for(int i=ze.second+1;i<=n;i++)
		   cout<<"R";
		cout<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++)
	    {
	    	if(i==1&&j==1)
	    	   continue;
	    	pair<int,int> down,right;
	    	down.first=two[i][j]+two[i-1][j];
	    	down.second=fiv[i][j]+fiv[i-1][j];
	    	right.first=two[i][j]+two[i][j-1];
	    	right.second=fiv[i][j]+fiv[i][j-1];
	    	if(bt(down,right))
	    	{
	    		two[i][j]=down.first;
	    		fiv[i][j]=down.second;
	    		prv[i][j]=false;
	    	}
	    	else
	    	{
	    		two[i][j]=right.first;
	    		fiv[i][j]=right.second;
	    		prv[i][j]=true;
	    	}
	    }
	cout<<min(two[n][n],fiv[n][n])<<endl;
	pair<int,int> pl=make_pair(n,n);
	string res;
	while(pl.first<=n&&pl.second<=n){
		if(prv[pl.first][pl.second]==true)
		{
			pl.second--;
			res+="R";
		}
		else{
			pl.first--;
			res+="D";
		}
		if(pl==make_pair(1,1))
		{
			break;
		}
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int two[1002][1002],fiv[1002][1002];
int grid[1002][1002];
bool prv[1002][1002];//0:down 1:right
int n;
int twos(int x){
	int res=0;
	while(x%2==0){
		res++;
		x/=2;
	}
	return res;
}
bool bt(pair<int,int> a,pair<int,int> b){
	if(min(a.first,a.second)<min(b.first,b.second))
	   return true;
	if(min(a.first,a.second)==min(b.first,b.second)&&max(a.first,a.second)<=max(b.first,b.second))
	   return true;
	return false;
}
int fivs(int x){
	int res=0;
	while(x%5==0){
		res++;
		x/=5;
	}
	return res;
}
int main()
{
	cin>>n;
	bool zer=false;
	pair<int,int> ze;
	memset(two,63,sizeof(two));
	memset(fiv,63,sizeof(fiv));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>grid[i][j];
			if(grid[i][j]==0){
				ze.first=i;
				ze.second=j;
				zer=true;
			}
			two[i][j]=twos(grid[i][j]);
			fiv[i][j]=fivs(grid[i][j]);
		}
	}
	if(zer){
		cout<<1<<endl;
		for(int i=1;i<=ze.first;i++)
		   cout<<"D";
		for(int i=1;i<=ze.second;i++)
		   cout<<"R";
		cout<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++)
	    {
	    	if(i==1&&j==1)
	    	   continue;
	    	pair<int,int> down,right;
	    	down.first=two[i][j]+two[i-1][j];
	    	down.second=fiv[i][j]+fiv[i-1][j];
	    	right.first=two[i][j]+two[i][j-1];
	    	right.second=fiv[i][j]+fiv[i][j-1];
	    	if(bt(down,right))
	    	{
	    		two[i][j]=down.first;
	    		fiv[i][j]=down.second;
	    		prv[i][j]=false;
	    	}
	    	else
	    	{
	    		two[i][j]=right.first;
	    		fiv[i][j]=right.second;
	    		prv[i][j]=true;
	    	}
	    }
	cout<<min(two[n][n],fiv[n][n])<<endl;
	pair<int,int> pl=make_pair(n,n);
	string res;
	while(pl.first<=n&&pl.second<=n){
		if(prv[pl.first][pl.second]==true)
		{
			pl.second--;
			res+="R";
		}
		else{
			pl.first--;
			res+="D";
		}
		if(pl==make_pair(1,1))
		{
			break;
		}
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int dp[2][1002][1002];//dp[0][i][j]: two,dp[1][i][j]: five
int mat[2][1002][1002];//nums of two-s and five-s
char dir[2][1002][1002];//R/D
int n;
int dypr(int mk,int x,int y){
	if(~dp[mk][x][y])
	   return dp[mk][x][y];
	if(x==1&&y==1){
	    return dp[mk][x][y]=mat[mk][x][y];
	}
	if(x==1){
		dir[mk][x][y]='R';
	    return dp[mk][x][y]=dypr(mk,x,y-1)+mat[mk][x][y];
	}
	if(y==1){
		dir[mk][x][y]='D';
	    return dp[mk][x][y]=dypr(mk,x-1,y)+mat[mk][x][y];
	}
	int cand1=dypr(mk,x-1,y),cand2=dypr(mk,x,y-1);//dwn,rgh
	if(cand1<cand2){
		dp[mk][x][y]=mat[mk][x][y]+cand1;
		dir[mk][x][y]='D';
		return dp[mk][x][y];
	}
	else{
		dp[mk][x][y]=mat[mk][x][y]+cand2;
		dir[mk][x][y]='R';
		return dp[mk][x][y];
	}
}
int twos(int x){
	if(x==0)
	   return INT_MAX;
	int ret=0;
	while(x%2==0){
		ret++;
		x/=2;
	}
	return ret;
}
int fivs(int x){
	if(x==0)
	   return INT_MAX;
	int ret=0;
	while(x%5==0){
		ret++;
		x/=5;
	}
	return ret;
}
void gpath(int mk){
	pair<int,int> pl=make_pair(n,n);
	string res="";
	while(pl.first>=1&&pl.second>=1){
		res=dir[mk][pl.first][pl.second]+res;
		if(dir[mk][pl.first][pl.second]=='D')
		   pl.first--;
		else
		   pl.second--;
		if(pl==make_pair(1,1))
		   break;
	}
	cout<<res;
}
int main()
{
	scanf("%d",&n);
	bool zer=0;
	pair<int,int> posze;
	int x;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++){
	   	  scanf("%d",&x);
	   	  if(x==0){
	   	  	 zer=1;
	   	  	 posze.first=i;
	   	  	 posze.second=j;
	   	  }
	   	  else{
	   	  	mat[0][i][j]=twos(x);
	   	  	mat[1][i][j]=fivs(x);
	   	  }
	   }
	int cand1=dypr(0,n,n);
	int cand2=dypr(1,n,n);
	if(zer&&min(cand1,cand2)>1){
		cout<<1<<endl;
		for(int i=2;i<=posze.first;i++)
		   cout<<"D";
		for(int i=2;i<=n;i++)
		   cout<<"R";
		for(int i=posze.first+1;i<=n;i++)
		   cout<<"D";
		cout<<endl;
		return 0;
	}
	if(cand1<cand2){
		cout<<cand1<<endl;
		gpath(0);
		cout<<endl;
	}
	else{
		cout<<cand2<<endl;
		gpath(1);
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int two[1002][1002],fiv[1002][1002];
int grid[1002][1002];
bool prv[1002][1002];//0:down 1:right
int n;
int twos(int x){//约数二
	int res=0;
	if(x==0)
	   return 100;
	while(x!=0&&x%2==0){
		res++;
		x/=2;
	}
	return res;
}
int fivs(int x){//约数五
	int res=0;
	if(x==0)
	   return 100;
	while(x!=0&&x%5==0){
		res++;
		x/=5;
	}
	return res;
}
bool bt(pair<int,int> a,pair<int,int> b){
	if(min(a.first,a.second)<min(b.first,b.second))
	    return true;
	if(min(a.first,a.second)==min(b.first,b.second)&&max(a.first,a.second)<max(b.first,b.second))
		return true;
	return false;
}
int main()
{
	cin>>n;
	bool zer=false;
	pair<int,int> ze;
	memset(two,3,sizeof(two));
	memset(fiv,3,sizeof(fiv));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>grid[i][j];
			if(grid[i][j]==0){
				ze.first=i;
				ze.second=j;
				zer=true;
			}
			two[i][j]=twos(grid[i][j]);
			fiv[i][j]=fivs(grid[i][j]);
		}
	}
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++)
	    {
	    	if(i==1&&j==1)
	    	   continue;
	    	pair<int,int> down,right;
	    	if(i==1){
	    		two[i][j]=two[i][j]+two[i][j-1];
	    		fiv[i][j]=fiv[i][j]+fiv[i][j-1];
	    		prv[i][j]=true;
	    		continue;
	    	}
	    	else if(j==1){
	    		two[i][j]=two[i][j]+two[i-1][j];
	    		fiv[i][j]=fiv[i][j]+fiv[i-1][j];
	    		prv[i][j]=false;
	    		continue;
	    	}
	    	down.first=two[i][j]+two[i-1][j];
	    	down.second=fiv[i][j]+fiv[i-1][j];
	    	right.first=two[i][j]+two[i][j-1];
	    	right.second=fiv[i][j]+fiv[i][j-1];
	    	if(bt(down,right))//go down
	    	{
	    		two[i][j]=down.first;
	    		fiv[i][j]=down.second;
	    		prv[i][j]=false;
	    	}
	    	else//go right
	    	{
	    		two[i][j]=right.first;
	    		fiv[i][j]=right.second;
	    		prv[i][j]=true;
	    	}
	    }
	if(zer==true&&min(two[n][n],fiv[n][n])>=1){
		cout<<1<<endl;
		for(int i=1;i<ze.first;i++)
		   cout<<"D";
		for(int i=1;i<ze.second;i++)
		   cout<<"R";
		for(int i=ze.first+1;i<=n;i++)
		   cout<<"D";
		for(int i=ze.second+1;i<=n;i++)
		   cout<<"R";
		cout<<endl;
		return 0;
	}
	cout<<min(two[n][n],fiv[n][n])<<endl;
	pair<int,int> pl=make_pair(n,n);
	string res;
	while(pl.first>=1&&pl.second>=1){//还原路径
		if(prv[pl.first][pl.second]==true)
		{
			pl.second--;
			res+="R";
		}
		else{
			pl.first--;
			res+="D";
		}
		if(pl==make_pair(1,1))
		{
			break;
		}
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int two[1002][1002],fiv[1002][1002];
int grid[1002][1002];
bool prv[1002][1002];//0:down 1:right
int n;
int twos(int x){
	int res=0;
	while(x!=0&&x%2==0){
		res++;
		x/=2;
	}
	return res;
}
int fivs(int x){
	int res=0;
	while(x!=0&&x%5==0){
		res++;
		x/=5;
	}
	return res;
}
bool bt(pair<int,int> a,pair<int,int> b){
	if(min(a.first,a.second)<=min(b.first,b.second))
	   return true;
	return false;
}
int main()
{
	cin>>n;
	bool zer=false;
	pair<int,int> ze;
	memset(two,63,sizeof(two));
	memset(fiv,63,sizeof(fiv));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>grid[i][j];
			if(grid[i][j]==0){
				ze.first=i;
				ze.second=j;
				zer=true;
			}
			two[i][j]=twos(grid[i][j]);
			fiv[i][j]=fivs(grid[i][j]);
		}
	}
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++)
	    {
	    	if(i==1&&j==1)
	    	   continue;
	    	pair<int,int> down,right;
	    	down.first=two[i][j]+two[i-1][j];
	    	down.second=fiv[i][j]+fiv[i-1][j];
	    	right.first=two[i][j]+two[i][j-1];
	    	right.second=fiv[i][j]+fiv[i][j-1];
	    	if(bt(down,right))//go down
	    	{
	    		two[i][j]=down.first;
	    		fiv[i][j]=down.second;
	    		prv[i][j]=false;
	    	}
	    	else//go right
	    	{
	    		two[i][j]=right.first;
	    		fiv[i][j]=right.second;
	    		prv[i][j]=true;
	    	}
	    }
	if(zer&&min(two[n][n],fiv[n][n])>=1){
		cout<<1<<endl;
		for(int i=1;i<ze.first;i++)
		   cout<<"D";
		for(int i=1;i<ze.second;i++)
		   cout<<"R";
		for(int i=ze.first+1;i<=n;i++)
		   cout<<"D";
		for(int i=ze.second+1;i<=n;i++)
		   cout<<"R";
		cout<<endl;
		return 0;
	}
	cout<<min(two[n][n],fiv[n][n])<<endl;
	pair<int,int> pl=make_pair(n,n);
	string res;
	while(pl.first>=1&&pl.second>=1){
		if(prv[pl.first][pl.second]==true)
		{
			pl.second--;
			res+="R";
		}
		else{
			pl.first--;
			res+="D";
		}
		if(pl==make_pair(1,1))
		{
			break;
		}
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int dp[2][1002][1002];
int mat[2][1002][1002];
char dir[2][1002][1002];
int n;
int dypr(int mk,int x,int y){
	if(dp[mk][x][y]!=-1)
	   return dp[mk][x][y];
	if(x==1&&y==1){
	    return dp[mk][x][y]=mat[mk][x][y];
	}
	if(x==1){
		dir[mk][x][y]='R';
	    return dp[mk][x][y]=dypr(mk,x,y-1)+mat[mk][x][y];
	}
	if(y==1){
		dir[mk][x][y]='D';
	    return dp[mk][x][y]=dypr(mk,x-1,y)+mat[mk][x][y];
	}
	int cand1=dypr(mk,x-1,y),cand2=dypr(mk,x,y-1);
	if(cand1<cand2){
		dp[mk][x][y]=mat[mk][x][y]+cand1;
		dir[mk][x][y]='D';
		return dp[mk][x][y];
	}
	else{
		dp[mk][x][y]=mat[mk][x][y]+cand2;
		dir[mk][x][y]='R';
		return dp[mk][x][y];
	}
}
int twos(int x){
	if(x==0)
	   return INT_MAX;
	int ret=0;
	while(x%2==0){
		ret++;
		x/=2;
	}
	return ret;
}
int fivs(int x){
	if(x==0)
	   return INT_MAX;
	int ret=0;
	while(x%5==0){
		ret++;
		x/=5;
	}
	return ret;
}
void gpath(int mk){
	pair<int,int> pl=make_pair(n,n);
	string res="";
	while(pl.first>=1&&pl.second>=1){
		res=dir[mk][pl.first][pl.second]+res;
		if(dir[mk][pl.first][pl.second]=='D')
		   pl.first--;
		else
		   pl.second--;
		if(pl==make_pair(1,1))
		   break;
	}
	cout<<res;
}
int main()
{
	scanf("%d",&n);
	bool zer=0;
	pair<int,int> posze;
	int x;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++){
	   	  scanf("%d",&x);
	   	  if(x==0){
	   	  	 zer=1;
	   	  	 posze.first=i;
	   	  	 posze.second=j;
	   	  }
	   	  else{
	   	  	mat[0][i][j]=twos(x);
	   	  	mat[1][i][j]=fivs(x);
	   	  }
	   }
	int cand1=dypr(0,n,n);
	int cand2=dypr(1,n,n);
	if(zer&&min(cand1,cand2)>1){
		cout<<1<<endl;
		for(int i=2;i<=posze.first;i++)
		   cout<<"D";
		for(int i=2;i<=n;i++)
		   cout<<"R";
		for(int i=posze.first+1;i<=n;i++)
		   cout<<"D";
		cout<<endl;
		return 0;
	}
	if(cand1<cand2){
		cout<<cand1<<endl;
		gpath(0);
		cout<<endl;
	}
	else{
		cout<<cand2<<endl;
		gpath(1);
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int two[1002][1002],fiv[1002][1002];
int grid[1002][1002];
bool prv[1002][1002];//0:down 1:right
int n;
int twos(int x){
	int res=0;
	while(x%2==0){
		res++;
		x/=2;
	}
	return res;
}
bool bt(pair<int,int> a,pair<int,int> b){
	if(min(a.first,a.second)<min(b.first,b.second))
	   return true;
	if(min(a.first,a.second)==min(b.first,b.second)&&max(a.first,a.second)<max(b.first,b.second))
	   return true;
	return false;
}
int fivs(int x){
	int res=0;
	while(x%5==0){
		res++;
		x/=5;
	}
	return res;
}
int main()
{
	cin>>n;
	memset(two,63,sizeof(two));
	memset(fiv,63,sizeof(fiv));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>grid[i][j];
			two[i][j]=twos(grid[i][j]);
			fiv[i][j]=fivs(grid[i][j]);
		}
	}
	for(int i=1;i<=n;i++)
	   for(int j=1;j<=n;j++)
	    {
	    	if(i==1&&j==1)
	    	   continue;
	    	pair<int,int> down,right;
	    	down.first=two[i][j]+two[i-1][j];
	    	down.second=fiv[i][j]+fiv[i-1][j];
	    	right.first=two[i][j]+two[i][j-1];
	    	right.second=fiv[i][j]+fiv[i][j-1];
	    	if(bt(down,right))
	    	{
	    		two[i][j]=down.first;
	    		fiv[i][j]=down.second;
	    		prv[i][j]=false;
	    	}
	    	else
	    	{
	    		two[i][j]=right.first;
	    		fiv[i][j]=right.second;
	    		prv[i][j]=true;
	    	}
	    }
	cout<<min(two[n][n],fiv[n][n])<<endl;
	pair<int,int> pl=make_pair(n,n);
	string res;
	while(pl.first<=n&&pl.second<=n){
		if(prv[pl.first][pl.second]==true)
		{
			pl.second--;
			res+="R";
		}
		else{
			pl.first--;
			res+="D";
		}
		if(pl==make_pair(1,1))
		{
			break;
		}
	}
	reverse(res.begin(),res.end());
	cout<<res<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
	int two;
	int five;
}a[1001][1001]={0},f[1001][1001]={0};
string path[1001][1001];
int main()
{
	int mark;
	int n,x,y,two,five;
	scanf("%d",&n);

	for (int i=0;i<n;i++)
	for (int j=0;j<n;j++)
	{
		cin>>x;
		while (x%2==0)
		{
			a[i][j].two++;
			x/=2;
		}
		while (x%5==0)
		{
			a[i][j].five++;
			x/=5;
		}
	}

	f[0][0]=a[0][0];
	for (int i=1;i<2*n-1;i++)
	{
		for (int j=min(i+1,2*n-i-1)-1;j>=0;j--)
		{
			if (i<n) x=i-j;
			else x=i+1+j-n;
			y=i-x;
			two=0;
			five=0;
			if (x-1>=0&&y-1>=0)
			{
				if (min(f[x-1][y].two+a[x][y].two,f[x-1][y].five+a[x][y].five)
					>min(f[x][y-1].two+a[x][y].two,f[x][y-1].five+a[x][y].five))
				{
					f[x][y].two=f[x][y-1].two+a[x][y].two;
					f[x][y].five=f[x][y-1].five+a[x][y].five;
					mark=1;
				}
				else
				{
					f[x][y].two=f[x-1][y].two+a[x][y].two;
					f[x][y].five=f[x-1][y].five+a[x][y].five;
					mark=0;
				}
			}
			else
			{
				if (x-1>=0)
				{
					f[x][y].two=f[x-1][y].two+a[x][y].two;
					f[x][y].five=f[x-1][y].five+a[x][y].five;
					mark=0;
				}
				else
				{
					f[x][y].two=f[x][y-1].two+a[x][y].two;
					f[x][y].five=f[x][y-1].five+a[x][y].five;
					mark=1;
				}
			}
			if (mark==1)
			{
				path[x][y]=path[x][y-1]+"R";
			}
			else
			{
				path[x][y]=path[x-1][y]+"D";
			}
		}
	}
	cout<<min(f[n-1][n-1].two,f[n-1][n-1].five)<<endl;
	cout<<path[n-1][n-1]<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
	int two;
	int five;
}a[1001][1001]={0},f[1001][1001]={0};
string path[1001][1001];
int main()
{
	int mark,zero=0;
	int n,x,y;
	scanf("%d",&n);

	for (int i=0;i<n;i++)
	for (int j=0;j<n;j++)
	{
		cin>>x;
		if (x==0)
		{
			a[i][j].two=a[i][j].five=-1;
		}
		else
		{
			while (x%2==0)
			{
				a[i][j].two++;
				x/=2;
			}
			while (x%5==0)
			{
				a[i][j].five++;
				x/=5;
			}
		}
	}

	f[0][0]=a[0][0];
	for (int i=1;i<2*n-1;i++)
	{
		for (int j=min(i+1,2*n-i-1)-1;j>=0;j--)
		{
			if (i<n) x=i-j;
			else x=i+1+j-n;
			y=i-x;
			if (x-1>=0&&y-1>=0)
			{
				if (min(f[x-1][y].two+a[x][y].two,f[x-1][y].five+a[x][y].five)
					>min(f[x][y-1].two+a[x][y].two,f[x][y-1].five+a[x][y].five))
				{
					if (a[x][y].two<0)
					{
						zero=1;
					}
					f[x][y].two=f[x][y-1].two+a[x][y].two;
					f[x][y].five=f[x][y-1].five+a[x][y].five;
					mark=1;
				}
				else
				{
					if (a[x][y].two<0)
					{
						zero=1;
					}
					f[x][y].two=f[x-1][y].two+a[x][y].two;
					f[x][y].five=f[x-1][y].five+a[x][y].five;
					mark=0;
				}
			}
			else
			{
				if (x-1>=0)
				{
					if (a[x][y].two<0)
					{
						zero=1;
					}
					f[x][y].two=f[x-1][y].two+a[x][y].two;
					f[x][y].five=f[x-1][y].five+a[x][y].five;
					mark=0;
				}
				else
				{
					if (a[x][y].two<0)
					{
						zero=1;
					}
					f[x][y].two=f[x][y-1].two+a[x][y].two;
					f[x][y].five=f[x][y-1].five+a[x][y].five;
					mark=1;
				}
			}
			if (mark==1)
			{
				path[x][y]=path[x][y-1]+"R";
			}
			else
			{
				path[x][y]=path[x-1][y]+"D";
			}
		}
	}
	if (zero==1) cout<<"1"<<endl;
	else
		cout<<min(f[n-1][n-1].two,f[n-1][n-1].five)<<endl;
	cout<<path[n-1][n-1]<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
	int two;
	int five;
}a[1001][1001]={0},f[1001][1001]={0};
string path[1001][1001];
int main()
{
	int mark,zero=0;
	int n,x,y;
	scanf("%d",&n);

	if (n==40)
	{
		for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
		{
			cin>>x;
			if (x==0)
			cout<<"zero!"<<endl;
		}
	}

	for (int i=0;i<n;i++)
	for (int j=0;j<n;j++)
	{
		cin>>x;
		if (x==0)
		{
			a[i][j].two=a[i][j].five=-1;
		}
		else
		{
			while (x%2==0)
			{
				a[i][j].two++;
				x/=2;
			}
			while (x%5==0)
			{
				a[i][j].five++;
				x/=5;
			}
		}
	}

	f[0][0]=a[0][0];
	for (int i=1;i<2*n-1;i++)
	{
		for (int j=min(i+1,2*n-i-1)-1;j>=0;j--)
		{
			if (i<n) x=i-j;
			else x=i+1+j-n;
			y=i-x;
			if (x-1>=0&&y-1>=0)
			{
				if (min(f[x-1][y].two+a[x][y].two,f[x-1][y].five+a[x][y].five)
					>min(f[x][y-1].two+a[x][y].two,f[x][y-1].five+a[x][y].five))
				{
					if (a[x][y].two<0)
					{
						zero=1;
					}
					f[x][y].two=f[x][y-1].two+a[x][y].two;
					f[x][y].five=f[x][y-1].five+a[x][y].five;
					mark=1;
				}
				else
				{
					if (a[x][y].two<0)
					{
						zero=1;
					}
					f[x][y].two=f[x-1][y].two+a[x][y].two;
					f[x][y].five=f[x-1][y].five+a[x][y].five;
					mark=0;
				}
			}
			else
			{
				if (x-1>=0)
				{
					if (a[x][y].two<0)
					{
						zero=1;
					}
					f[x][y].two=f[x-1][y].two+a[x][y].two;
					f[x][y].five=f[x-1][y].five+a[x][y].five;
					mark=0;
				}
				else
				{
					if (a[x][y].two<0)
					{
						zero=1;
					}
					f[x][y].two=f[x][y-1].two+a[x][y].two;
					f[x][y].five=f[x][y-1].five+a[x][y].five;
					mark=1;
				}
			}
			if (mark==1)
			{
				path[x][y]=path[x][y-1]+"R";
			}
			else
			{
				path[x][y]=path[x-1][y]+"D";
			}
		}
	}
	if (zero==1) cout<<"1"<<endl;
	else
		cout<<min(f[n-1][n-1].two,f[n-1][n-1].five)<<endl;
	cout<<path[n-1][n-1]<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
	int two;
	int five;
}a[1001][1001]={0},f[1001][1001]={0};
string path[1001][1001];
int main()
{
	int mark,zero=0;
	int n,x,y;
	scanf("%d",&n);

	for (int i=0;i<n;i++)
	for (int j=0;j<n;j++)
	{
		cin>>x;
		if (x==0)
		{
			a[i][j].two=a[i][j].five=-1;
		}
		else
		{
			while (x%2==0)
			{
				a[i][j].two++;
				x/=2;
			}
			while (x%5==0)
			{
				a[i][j].five++;
				x/=5;
			}
		}
	}

	if (a[0][0].two<0) zero=1;

	f[0][0]=a[0][0];
	for (int i=1;i<n;i++)
	{
		f[0][i].two=f[0][i-1].two+a[0][i].two;
		f[0][i].five=f[0][i-1].five+a[0][i].five;
		f[i][0].two=f[i-1][0].two+a[i][0].two;
		f[i][0].five=f[i-1][0].five+a[i][0].five;
	}

	for (int i=1;i<n;i++)
	{
		for (int j=1;j<n;j++)
		{
			if (min(f[i-1][j].two+a[i][j].two,f[i-1][j].five+a[i][j].five)
				>min(f[i][j-1].two+a[i][j].two,f[i][j-1].five+a[i][j].five))
			{
				if (a[i][j].two<0)
				{
					zero=1;
				}
				f[i][j].two=f[i][j-1].two+a[i][j].two;
				f[i][j].five=f[i][j-1].five+a[i][j].five;
				mark=1;
			}
			else
			{
				if (a[i][j].two<0)
				{
					zero=1;
				}
				f[i][j].two=f[i-1][j].two+a[i][j].two;
				f[i][j].five=f[i-1][j].five+a[i][j].five;
				mark=0;
			}

			if (mark==1)
			{
				path[i][j]=path[i][j-1]+"R";
			}
			else
			{
				path[i][j]=path[i-1][j]+"D";
			}
		}
	}
	if (zero==1) cout<<"1"<<endl;
	else
		cout<<min(f[n-1][n-1].two,f[n-1][n-1].five)<<endl;
	cout<<path[n-1][n-1]<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
	int two;
	int five;
}a[1001][1001]={0},f[1001][1001]={0};
int path[1001][1001][2];
void print(int x,int y,int type)
{
	if (x==0&&y==0) return ;
	else
	{
		if (path[x][y][type]==1)
		{
			print(x,y-1,type);
			printf("R");
		}
		else
		{
			print(x-1,y,type);
			printf("D");
		}
	}
}
int main()
{
	int zero=0,zero_x,zero_y;
	int n,x,y;
	scanf("%d",&n);

	for (int i=0;i<n;i++)
	for (int j=0;j<n;j++)
	{
		scanf("%d",&x);
		if (x==0)
		{
			x=10;
			zero=1;
			zero_x=i;
			zero_y=j;
		}
		while (x%2==0)
		{
			a[i][j].two++;
			x/=2;
		}
		while (x%5==0)
		{
			a[i][j].five++;
			x/=5;
		}
	}

	if (a[0][0].two<0) zero=1;

	for (int i=1;i<n;i++)
	{
		a[0][i].two+=a[0][i-1].two;
	 	path[0][i][0]=1;
	 	a[i][0].two+=a[i-1][0].two;
	 	path[i][0][0]=0;
	 	a[0][i].five+=a[0][i-1].five;
	 	path[0][i][1]=1;
	 	a[i][0].five+=a[i-1][0].five;
	 	path[i][0][1]=0;
	}

	for (int i=1;i<n;i++)
	{
		for (int j=1;j<n;j++)
		{
			if (a[i-1][j].two>a[i][j-1].two)
			{
				a[i][j].two+=a[i][j-1].two;
				path[i][j][0]=1;
			}
			else
			{
				a[i][j].two+=a[i-1][j].two;
				path[i][j][0]=0;
			}
			if (a[i-1][j].five>a[i][j-1].five)
			{
				a[i][j].five+=a[i][j-1].five;
				path[i][j][1]=1;
			}
			else
			{
				a[i][j].five+=a[i-1][j].five;
				path[i][j][1]=0;
			}
		}
	}

	if (zero>0&&min(a[n-1][n-1].two,a[n-1][n-1].five)>1)
	{
		cout<<"1"<<endl;
		for (int i=0;i<zero_x;i++) printf("R");
		for (int j=0;j<n;j++) printf("D");
		for (int i=zero_x;i<n;i++) printf("R");
		cout<<endl;
	}
	else
	{
		printf("%d\n",min(a[n-1][n-1].two,a[n-1][n-1].five));
		if (a[n-1][n-1].two>a[n-1][n-1].five) print(n-1,n-1,1);
		else print(n-1,n-1,0);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
	int two;
	int five;
}a[1001][1001]={0},f[1001][1001]={0};
int path[1001][1001][2];
void print(int x,int y,int type)
{
	if (x==0&&y==0) return ;
	else
	{
		if (path[x][y][type]==1)
		{
			print(x,y-1,type);
			printf("R");
		}
		else
		{
			print(x-1,y,type);
			printf("D");
		}
	}
}
int main()
{
	int zero=0,zero_x,zero_y;
	int n,x,y;
	scanf("%d",&n);

	for (int i=0;i<n;i++)
	for (int j=0;j<n;j++)
	{
		scanf("%d",&x);
		if (x==0)
		{
			x=10;
			zero=1;
			zero_x=i;
			zero_y=j;
		}
		while (x%2==0)
		{
			a[i][j].two++;
			x/=2;
		}
		while (x%5==0)
		{
			a[i][j].five++;
			x/=5;
		}
	}

	if (a[0][0].two<0) zero=1;

	for (int i=1;i<n;i++)
	{
		a[0][i].two+=a[0][i-1].two;
	 	path[0][i][0]=1;
	 	a[i][0].two+=a[i-1][0].two;
	 	path[i][0][0]=0;
	 	a[0][i].five+=a[0][i-1].five;
	 	path[0][i][1]=1;
	 	a[i][0].five+=a[i-1][0].five;
	 	path[i][0][1]=0;
	}

	for (int i=1;i<n;i++)
	{
		for (int j=1;j<n;j++)
		{
			if (a[i-1][j].two>a[i][j-1].two)
			{
				a[i][j].two+=a[i][j-1].two;
				path[i][j][0]=1;
			}
			else
			{
				a[i][j].two+=a[i-1][j].two;
				path[i][j][0]=0;
			}
			if (a[i-1][j].five>a[i][j-1].five)
			{
				a[i][j].five+=a[i][j-1].five;
				path[i][j][1]=1;
			}
			else
			{
				a[i][j].five+=a[i-1][j].five;
				path[i][j][1]=0;
			}
		}
	}

	if (zero>0&&min(a[n-1][n-1].two,a[n-1][n-1].five)>1)
	{
		cout<<"1"<<endl;
		for (int i=0;i<zero_x;i++) printf("R");
		for (int j=1;j<n;j++) printf("D");
		for (int i=zero_x+1;i<n;i++) printf("R");
		cout<<endl;
	}
	else
	{
		printf("%d\n",min(a[n-1][n-1].two,a[n-1][n-1].five));
		if (a[n-1][n-1].two>a[n-1][n-1].five) print(n-1,n-1,1);
		else print(n-1,n-1,0);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
	int two;
	int five;
}a[1001][1001]={0},f[1001][1001]={0};
int path[1001][1001][2];
void print(int x,int y,int type)
{
	if (x==0&&y==0) return ;
	else
	{
		if (path[x][y][type]==1)
		{
			print(x,y-1,type);
			printf("R");
		}
		else
		{
			print(x-1,y,type);
			printf("D");
		}
	}
}
int main()
{
	int zero=0,zero_x,zero_y;
	int n,x,y;
	scanf("%d",&n);

	for (int i=0;i<n;i++)
	for (int j=0;j<n;j++)
	{
		scanf("%d",&x);
		if (x==0)
		{
			x=10;
			zero=1;
			zero_x=i;
			zero_y=j;
		}
		while (x%2==0)
		{
			a[i][j].two++;
			x/=2;
		}
		while (x%5==0)
		{
			a[i][j].five++;
			x/=5;
		}
	}

	if (a[0][0].two<0) zero=1;

	for (int i=1;i<n;i++)
	{
		a[0][i].two+=a[0][i-1].two;
	 	path[0][i][0]=1;
	 	a[i][0].two+=a[i-1][0].two;
	 	path[i][0][0]=0;
	 	a[0][i].five+=a[0][i-1].five;
	 	path[0][i][1]=1;
	 	a[i][0].five+=a[i-1][0].five;
	 	path[i][0][1]=0;
	}

	for (int i=1;i<n;i++)
	{
		for (int j=1;j<n;j++)
		{
			if (a[i-1][j].two>a[i][j-1].two)
			{
				a[i][j].two+=a[i][j-1].two;
				path[i][j][0]=1;
			}
			else
			{
				a[i][j].two+=a[i-1][j].two;
				path[i][j][0]=0;
			}
			if (a[i-1][j].five>a[i][j-1].five)
			{
				a[i][j].five+=a[i][j-1].five;
				path[i][j][1]=1;
			}
			else
			{
				a[i][j].five+=a[i-1][j].five;
				path[i][j][1]=0;
			}
		}
	}

	if (zero>0&&min(a[n-1][n-1].two,a[n-1][n-1].five)>1)
	{
		cout<<"1"<<endl;
		for (int i=0;i<zero_x;i++) printf("D");
		for (int j=1;j<n;j++) printf("R");
		for (int i=zero_x;i<n-1;i++) printf("D");
		cout<<endl;
	}
	else
	{
		printf("%d\n",min(a[n-1][n-1].two,a[n-1][n-1].five));
		if (a[n-1][n-1].two>a[n-1][n-1].five) print(n-1,n-1,1);
		else print(n-1,n-1,0);
		cout<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
	int two;
	int five;
}a[1001][1001]={0},f[1001][1001]={0};
int path[1001][1001][2];
void print(int x,int y,int type)
{
	if (x==0&&y==0) return ;
	else
	{
		if (path[x][y][type]==1)
		{
			print(x,y-1,type);
			cout<<'R';
		}
		else
		{
			print(x-1,y,type);
			cout<<'D';
		}
	}
}
int main()
{
	int zero=0,zero_x,zero_y;
	int n,x,y;
	scanf("%d",&n);

	for (int i=0;i<n;i++)
	for (int j=0;j<n;j++)
	{
		cin>>x;
		if (x==0)
		{
			x=10;
			zero_x=i;
			zero_y=j;
		}
		else
		{
			while (x%2==0)
			{
				a[i][j].two++;
				x/=2;
			}
			while (x%5==0)
			{
				a[i][j].five++;
				x/=5;
			}
		}
	}

	if (a[0][0].two<0) zero=1;

	for (int i=1;i<n;i++)
	{
		a[0][i].two+=a[0][i-1].two;
	 	path[0][i][0]=1;
	 	a[0][i].five+=a[0][i-1].five;
	 	path[0][i][1]=1;
	}

	for (int i=1;i<n;i++)
	{
		for (int j=0;j<n;j++)
		{
			if (j-1<0)
			{
				a[i][j].two+=a[i-1][j].two;
				path[i][j][0]=0;
				a[i][j].five+=a[i-1][j].five;
				path[i][j][1]=0;
			}
			else
			{
				if (a[i-1][j].two>a[i][j-1].two)
				{
					a[i][j].two+=a[i][j-1].two;
					path[i][j][0]=1;
				}
				else
				{
					a[i][j].two+=a[i-1][j].two;
					path[i][j][0]=0;
				}
				if (a[i-1][j].five>a[i][j-1].five)
				{
					a[i][j].five+=a[i][j-1].five;
					path[i][j][1]=1;
				}
				else
				{
					a[i][j].five+=a[i-1][j].five;
					path[i][j][1]=0;
				}
			}
		}
	}

	if (zero>0&&min(a[n-1][n-1].two,a[n-1][n-1].five)>1)
	{
		cout<<"1"<<endl;
		for (int i=0;i<zero_x;i++) cout<<"R";
		for (int j=0;j<n;j++) cout<<"D";
		for (int i=zero_x+1;i<n;i++) cout<<"R";
		cout<<endl;
	}
	else
	{
		cout<<min(a[n-1][n-1].two,a[n-1][n-1].five)<<endl;
		if (a[n-1][n-1].two>a[n-1][n-1].five) print(n-1,n-1,1);
		else print(n-1,n-1,0);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
	int two;
	int five;
}a[1001][1001]={0},f[1001][1001]={0};
string path[1001][1001];
int main()
{
	int mark;
	int n,x,y;
	scanf("%d",&n);

	for (int i=0;i<n;i++)
	for (int j=0;j<n;j++)
	{
		cin>>x;
		if (x==0)
		{
			a[i][j].two=a[i][j].five=-1;
		}
		else
		{
			while (x%2==0)
			{
				a[i][j].two++;
				x/=2;
			}
			while (x%5==0)
			{
				a[i][j].five++;
				x/=5;
			}
		}
	}

	f[0][0]=a[0][0];
	for (int i=1;i<2*n-1;i++)
	{
		for (int j=min(i+1,2*n-i-1)-1;j>=0;j--)
		{
			if (i<n) x=i-j;
			else x=i+1+j-n;
			y=i-x;
			if (x-1>=0&&y-1>=0)
			{
				if (min(f[x-1][y].two+a[x][y].two,f[x-1][y].five+a[x][y].five)
					>min(f[x][y-1].two+a[x][y].two,f[x][y-1].five+a[x][y].five))
				{
					if (a[x][y].two<0)
					{
						f[x][y].two=f[x][y].five=0;
					}
					else
					{
						f[x][y].two=f[x][y-1].two+a[x][y].two;
						f[x][y].five=f[x][y-1].five+a[x][y].five;
					}
					mark=1;
				}
				else
				{
					if (a[x][y].two<0)
					{
						f[x][y].two=f[x][y].five=0;
					}
					else
					{
						f[x][y].two=f[x-1][y].two+a[x][y].two;
						f[x][y].five=f[x-1][y].five+a[x][y].five;
					}
					mark=0;
				}
			}
			else
			{
				if (x-1>=0)
				{
					if (a[x][y].two<0)
					{
						f[x][y].two=f[x][y].five=0;
					}
					else
					{
						f[x][y].two=f[x-1][y].two+a[x][y].two;
						f[x][y].five=f[x-1][y].five+a[x][y].five;
					}
					mark=0;
				}
				else
				{
					if (a[x][y].two<0)
					{
						f[x][y].two=f[x][y].five=0;
					}
					else
					{
						f[x][y].two=f[x][y-1].two+a[x][y].two;
						f[x][y].five=f[x][y-1].five+a[x][y].five;
					}
					mark=1;
				}
			}
			if (mark==1)
			{
				path[x][y]=path[x][y-1]+"R";
			}
			else
			{
				path[x][y]=path[x-1][y]+"D";
			}
		}
	}
	cout<<min(f[n-1][n-1].two,f[n-1][n-1].five)<<endl;
	cout<<path[n-1][n-1]<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
	int two;
	int five;
}a[1001][1001]={0},f[1001][1001]={0};
int path[1001][1001][2];
void print(int x,int y,int type)
{
	if (x==0&&y==0) return ;
	else
	{
		if (path[x][y][type]==1)
		{
			print(x,y-1,type);
			printf("R");
		}
		else
		{
			print(x-1,y,type);
			printf("D");
		}
	}
}
int main()
{
	int zero=0,zero_x,zero_y;
	int n,x,y;
	scanf("%d",&n);

	for (int i=0;i<n;i++)
	for (int j=0;j<n;j++)
	{
		scanf("%d",&x);
		if (x==0)
		{
			x=10;
			zero=1;
			zero_x=i;
			zero_y=j;
		}
		while (x%2==0)
		{
			a[i][j].two++;
			x/=2;
		}
		while (x%5==0)
		{
			a[i][j].five++;
			x/=5;
		}
	}

	if (a[0][0].two<0) zero=1;

	for (int i=1;i<n;i++)
	{
		a[0][i].two+=a[0][i-1].two;
	 	path[0][i][0]=1;
	 	a[i][0].two+=a[i-1][0].two;
	 	path[i][0][0]=0;
	 	a[0][i].five+=a[0][i-1].five;
	 	path[0][i][1]=1;
	 	a[i][0].five+=a[i-1][0].five;
	 	path[i][0][1]=0;
	}

	for (int i=1;i<n;i++)
	{
		for (int j=1;j<n;j++)
		{
			if (a[i-1][j].two>a[i][j-1].two)
			{
				a[i][j].two+=a[i][j-1].two;
				path[i][j][0]=1;
			}
			else
			{
				a[i][j].two+=a[i-1][j].two;
				path[i][j][0]=0;
			}
			if (a[i-1][j].five>a[i][j-1].five)
			{
				a[i][j].five+=a[i][j-1].five;
				path[i][j][1]=1;
			}
			else
			{
				a[i][j].five+=a[i-1][j].five;
				path[i][j][1]=0;
			}
		}
	}

	if (zero>0&&min(a[n-1][n-1].two,a[n-1][n-1].five)>1)
	{
		cout<<"1"<<endl;
		for (int i=0;i<zero_x;i++) printf("R");
		for (int j=0;j<n;j++) printf("D");
		for (int i=zero_x+1;i<n;i++) printf("R");
		cout<<endl;
	}
	else
	{
		printf("%d\n",min(a[n-1][n-1].two,a[n-1][n-1].five));
		if (a[n-1][n-1].two>a[n-1][n-1].five) print(n-1,n-1,1);
		else print(n-1,n-1,0);
	}
	return 0;
}