#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int n,t,res,zx=-1,zy=-1;
int fct[2][1001][1001];
int dp[2][1001][1001];

void trace(int x,int y,int k)
{
    if(x==1 && y==1)return;
    if(x==1)
    {
        trace(x,y-1,k);
        printf("R");
    }
    else if(y==1)
    {
        trace(x-1,y,k);
        printf("D");
    }
    else if(dp[k][x][y]==dp[k][x-1][y]+fct[k][x][y])
    {
        trace(x-1,y,k);
        printf("D");
    }
    else
    {
        trace(x,y-1,k);
        printf("R");
    }
    if(x==n && y==n)return;
    return;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for (int j=1;j<=n; j++)
        {
            scanf("%d",&t);
            if(t==0)
            {
                zx=i;
                zy=j;
                //cout<<zx<<" "<<zy<<endl;
                break;
            }
            while(t%5==0)
            {
                fct[1][i][j]++;
                t/=5;
            }
            while(t%2==0)
            {
                fct[0][i][j]++;
                t/=2;
            }
        }
    }
    memset(dp, 0x3f, sizeof(dp));
    dp[0][1][1]=0;
    dp[1][1][1]=0;
    for(int k=0;k<2;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(i>1)
                {
                    dp[k][i][j]=min(dp[k][i][j],dp[k][i-1][j]);
                }
                if(j>1)
                {
                    dp[k][i][j]=min(dp[k][i][j],dp[k][i][j-1]);
                }
                dp[k][i][j]+=fct[k][i][j];
            }
        }
    }
    res=min(dp[0][n][n],dp[1][n][n]);
    //cout<<zx<<" "<<zy<<" "<<res<<endl;
        if(zx!=-1 && res>1)
        {
            printf("1\n");
            for(int i=1;i<zx;i++)
            {
                printf("D");
            }
            for(int i=1;i<zy;i++)
            {
                printf("R");
            }
            for(int i=zx;i<n;i++)
            {
                printf("D");
            }
            for(int i=zy;i<n;i++)
            {
                printf("R");
            }
        }
        else
        {

            printf("%d\n",res);
            if(res==dp[0][n][n])
            {
                trace(n,n,0);
            }
            else
            {
                trace(n,n,1);
            }
        }
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int n,t,res,zx=-1,zy=-1;
int fct[2][1001][1001];
int dp[2][1001][1001];

void trace(int x,int y,int k)
{
    if(x==1 && y==1)return;
    if(x==1)
    {
        trace(x,y-1,k);
        printf("R");
    }
    else if(y==1)
    {
        trace(x-1,y,k);
        printf("D");
    }
    else if(dp[k][x][y]==dp[k][x-1][y]+fct[k][x][y])
    {
        trace(x-1,y,k);
        printf("D");
    }
    else
    {
        trace(x,y-1,k);
        printf("R");
    }
    return;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for (int j=1;j<=n; j++)
        {
            scanf("%d",&t);
            if(t==0)
            {
                zx=i;
                zy=j;
                break;
            }
            while(t%5==0)
            {
                fct[1][i][j]++;
                t/=5;
            }
            while(t%2==0)
            {
                fct[0][i][j]++;
                t/=2;
            }
        }
    }
    memset(dp, 0x3f, sizeof(dp));
    dp[0][1][1]=0;
    dp[1][1][1]=0;
    for(int k=0;k<2;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(i>1)
                {
                    dp[k][i][j]=min(dp[k][i][j],dp[k][i-1][j]);
                }
                if(j>1)
                {
                    dp[k][i][j]=min(dp[k][i][j],dp[k][i][j-1]);
                }
                dp[k][i][j]+=fct[k][i][j];
            }
        }
    }
    res=min(dp[0][n][n],dp[1][n][n]);

        if(zx!=-1 && res>1)
        {
            printf("1\n");
            for(int i=1;i<zx;i++)
            {
                printf("D");
            }
            for(int i=1;i<zy;i++)
            {
                printf("R");
            }
            for(int i=zx;i<n;i++)
            {
                printf("D");
            }
            for(int i=zy;i<n;i++)
            {
                printf("R");
            }
        }
        else
        {

            printf("%d\n",res);
            if(res==dp[0][n][n])
            {
                trace(n,n,0);
            }
            else
            {
                trace(n,n,1);
            }
        }
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define MAX 1007

using namespace std;

int n,x;
int dp[2][MAX][MAX];
int p[2][MAX][MAX];

void print ( int x , int y , int k , int f  )
{
    if ( x == 1 && y == 1 );
    else if ( x == 1 ) print ( x , y-1 , k , 0);
    else if ( y == 1 ) print ( x-1 , y , k , 1);
    else
    {
        if ( dp[k][x][y] == dp[k][x-1][y] + p[k][x][y] )
            print ( x-1 , y , k , 1 );
        else print ( x , y-1 , k , 0);
    }
    if ( f == 3 ) return;
    printf ( "%c" , f?'D':'R' );
}

int main ( )
{
    while ( ~scanf ( "%d" , &n ) )
    {
        int flag = 0,a,b;
        for ( int i = 1 ; i <= n ; i++ )
            for ( int j = 1 ; j <= n ; j++ )
            {
                scanf ( "%d" , &x );
                if ( !x )
                {
                    flag = 1;
                    p[0][i][j]++;
                    p[1][i][j]++;
                    a = i , b = j;
                    continue;
                }
                while ( x%2 == 0 )
                {
                    p[0][i][j]++;
                    x /= 2;
                }
                while ( x%5 == 0 )
                {
                    p[1][i][j]++;
                    x /= 5;
                }
            }
        memset ( dp , 0x3f , sizeof ( dp ) );
        for ( int k = 0 ; k < 2 ; k++ )
            for ( int i = 1 ; i <= n ; i++ )
                for ( int j = 1 ; j <= n ; j++ )
                {
                    if ( i-1 )
                        dp[k][i][j] = min ( dp[k][i][j] , dp[k][i-1][j] );
                    if ( j-1 )
                        dp[k][i][j] = min ( dp[k][i][j] , dp[k][i][j-1] );
                    if ( i == j && i == 1 )
                        dp[k][i][j] = 0;
                    dp[k][i][j] +=  p[k][i][j];
                }
        int ans = min ( dp[0][n][n] , dp[1][n][n] );
        if ( ans > 1 && flag )
        {
            puts ( "1" );
            for ( int i = 1 ; i < a ; i++ )
                printf ( "%c" , 'D' );
            for ( int j = 1 ; j < b ; j++ )
                printf ( "%c" , 'R' );
            for ( int i = a ; i < n ; i++ )
                printf ( "%c" , 'D' );
            for ( int j = b ; j < n ; j++ )
                printf ( "%c" , 'R' );
            puts ( "" );
            continue;
        }
        printf ( "%d\n" , ans );
        if ( dp[0][n][n] < dp[1][n][n] )
            print ( n , n , 0 , 3 );
        else print ( n , n , 1 , 3 );
        puts ( "" );
    }
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int n,t,res,zx=-1,zy=-1;
int fct[2][1000][1000];
int dp[2][1000][1000];

void trace(int x,int y,int k)
{
    if(x==1 && y==1)return;
    if(dp[k][x][y]==dp[k][x-1][y]+fct[k][x][y])
    {
        trace(x-1,y,k);
        cout<<"D";
    }
    else
    {
        trace(x,y-1,k);
        cout<<"R";
    }
    return;
}

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for (int j=1;j<=n; j++)
        {
            cin>>t;
            if(t==0)
            {
                zx=i;
                zy=j;
            }
            while(t%5==0)
            {
                fct[1][i][j]++;
                t/=5;
            }
            while(t%2==0)
            {
                fct[0][i][j]++;
                t/=2;
            }
        }
    }
        memset(dp, 0x3f, sizeof(dp));
    dp[0][1][1]=0;
    dp[1][1][1]=0;
        for(int k=0;k<2;k++)
        {
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    if(i>1)
                    {
                        dp[k][i][j]=min(dp[k][i][j],dp[k][i-1][j]);
                    }
                    if(j>1)
                    {
                        dp[k][i][j]=min(dp[k][i][j],dp[k][i][j-1]);
                    }
                    dp[k][i][j]+=fct[k][i][j];
                }
            }
        }
        res=min(dp[0][n][n],dp[1][n][n]);

        if(zx!=-1)
        {
            cout<<"!";
            cout<<1<<endl;
            for(int i=0;i<zx;i++)
            {
                cout<<"D";
            }
            for(int i=0;i<zy;i++)
            {
                cout<<"R";
            }
            for(int i=zx;i<=n;i++)
            {
                cout<<"D";
            }
            for(int i=zy;i<=n;i++)
            {
                cout<<"R";
            }
        }
        else
        {
            cout<<res<<endl;
            if(res==dp[0][n][n])
            {
                trace(n,n,0);
            }
            else
            {
                trace(n,n,1);
            }
        }
    cout<<endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int n,t,res,zx=-1,zy=-1;
int fct[2][1001][1001];
int dp[2][1001][1001];

void trace(int x,int y,int k)
{
    if(x==1 && y==1)return;
    if(x==1)
    {
        trace(x,y-1,k);
        printf("R");
    }
    else if(y==1)
    {
        trace(x-1,y,k);
        printf("D");
    }
    else if(dp[k][x][y]==dp[k][x-1][y]+fct[k][x][y])
    {
        trace(x-1,y,k);
        printf("D");
    }
    else
    {
        trace(x,y-1,k);
        printf("R");
    }
    return;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for (int j=1;j<=n; j++)
        {
            scanf("%d",&t);
            if(t==0)
            {
                zx=i;
                zy=j;
                break;
            }
            while(t%5==0)
            {
                fct[1][i][j]++;
                t/=5;
            }
            while(t%2==0)
            {
                fct[0][i][j]++;
                t/=2;
            }
        }
    }
    memset(dp, 0x3f, sizeof(dp));
    dp[0][1][1]=0;
    dp[1][1][1]=0;
    for(int k=0;k<2;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(i>1)
                {
                    dp[k][i][j]=min(dp[k][i][j],dp[k][i-1][j]);
                }
                if(j>1)
                {
                    dp[k][i][j]=min(dp[k][i][j],dp[k][i][j-1]);
                }
                dp[k][i][j]+=fct[k][i][j];
            }
        }
    }
    res=min(dp[0][n][n],dp[1][n][n]);
    //cout<<zx<<" "<<zy<<" "<<res<<endl;
        if(zx!=-1 && res!=0)
        {
            printf("1\n");
            for(int i=1;i<zx;i++)
            {
                printf("D");
            }
            for(int i=1;i<zy;i++)
            {
                printf("R");
            }
            for(int i=zx;i<n;i++)
            {
                printf("D");
            }
            for(int i=zy;i<n;i++)
            {
                printf("R");
            }
        }
        else
        {

            printf("%d\n",res);
            if(res==dp[0][n][n])
            {
                trace(n,n,0);
            }
            else
            {
                trace(n,n,1);
            }
        }
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int n,t,res,zx=-1,zy=-1;
int fct[2][1001][1001];
int dp[2][1001][1001];

void trace(int x,int y,int k)
{
    if(x==1 && y==1)return;
    if(x==1)
    {
        trace(x,y-1,k);
        printf("R");
    }
    else if(y==1)
    {
        trace(x-1,y,k);
        printf("D");
    }
    else if(dp[k][x][y]==dp[k][x-1][y]+fct[k][x][y])
    {
        trace(x-1,y,k);
        printf("D");
    }
    else
    {
        trace(x,y-1,k);
        printf("R");
    }
    return;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for (int j=1;j<=n; j++)
        {
            scanf("%d",&t);
            if(t==0)
            {
                zx=i;
                zy=j;
                cout<<zx<<" "<<zy<<endl;
                break;
            }
            while(t%5==0)
            {
                fct[1][i][j]++;
                t/=5;
            }
            while(t%2==0)
            {
                fct[0][i][j]++;
                t/=2;
            }
        }
    }
    memset(dp, 0x3f, sizeof(dp));
    dp[0][1][1]=0;
    dp[1][1][1]=0;
    for(int k=0;k<2;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(i>1)
                {
                    dp[k][i][j]=min(dp[k][i][j],dp[k][i-1][j]);
                }
                if(j>1)
                {
                    dp[k][i][j]=min(dp[k][i][j],dp[k][i][j-1]);
                }
                dp[k][i][j]+=fct[k][i][j];
            }
        }
    }
    res=min(dp[0][n][n],dp[1][n][n]);
    //cout<<zx<<" "<<zy<<" "<<res<<endl;
        if(zx!=-1 && res!=0)
        {
            printf("1\n");
            for(int i=1;i<zx;i++)
            {
                printf("D");
            }
            for(int i=1;i<zy;i++)
            {
                printf("R");
            }
            for(int i=zx;i<n;i++)
            {
                printf("D");
            }
            for(int i=zy;i<n;i++)
            {
                printf("R");
            }
        }
        else
        {

            printf("%d\n",res);
            if(res==dp[0][n][n])
            {
                trace(n,n,0);
            }
            else
            {
                trace(n,n,1);
            }
        }
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int n,t,res,zx=-1,zy=-1;
int fct[2][1001][1001];
int dp[2][1001][1001];

void trace(int x,int y,int k)
{
    if(x==1 && y==1)return;
    if(x==1)
    {
        trace(x,y-1,k);
        printf("R");
    }
    else if(y==1)
    {
        trace(x-1,y,k);
        printf("D");
    }
    else if(dp[k][x][y]==dp[k][x-1][y]+fct[k][x][y])
    {
        trace(x-1,y,k);
        printf("D");
    }
    else
    {
        trace(x,y-1,k);
        printf("R");
    }
    return;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for (int j=1;j<=n; j++)
        {
            scanf("%d",&t);
            if(t==0)
            {
                zx=i;
                zy=j;
                break;
            }
            while(t%5==0)
            {
                fct[1][i][j]++;
                t/=5;
            }
            while(t%2==0)
            {
                fct[0][i][j]++;
                t/=2;
            }
        }
    }
    memset(dp, 0x3f, sizeof(dp));
    dp[0][1][1]=0;
    dp[1][1][1]=0;
    for(int k=0;k<2;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(i>1)
                {
                    dp[k][i][j]=min(dp[k][i][j],dp[k][i-1][j]);
                }
                if(j>1)
                {
                    dp[k][i][j]=min(dp[k][i][j],dp[k][i][j-1]);
                }
                dp[k][i][j]+=fct[k][i][j];
            }
        }
    }
    res=min(dp[0][n][n],dp[1][n][n]);
    //cout<<zx<<" "<<zy<<" "<<res<<endl;
        if(zx!=-1 && res!=0)
        {
            cout<<"!"<<endl;
            printf("1\n");
            for(int i=1;i<zx;i++)
            {
                printf("D");
            }
            for(int i=1;i<zy;i++)
            {
                printf("R");
            }
            for(int i=zx;i<n;i++)
            {
                printf("D");
            }
            for(int i=zy;i<n;i++)
            {
                printf("R");
            }
        }
        else
        {

            printf("%d\n",res);
            if(res==dp[0][n][n])
            {
                trace(n,n,0);
            }
            else
            {
                trace(n,n,1);
            }
        }
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int n,t,res,zx=-1,zy=-1;
int fct[2][1001][1001];
int dp[2][1001][1001];

void trace(int x,int y,int k)
{
    if(x==1 && y==1)return;
    if(x==1)
    {
        trace(x,y-1,k);
        printf("R");
    }
    else if(y==1)
    {
        trace(x-1,y,k);
        printf("D");
    }
    else if(dp[k][x][y]==dp[k][x-1][y]+fct[k][x][y])
    {
        trace(x-1,y,k);
        printf("D");
    }
    else
    {
        trace(x,y-1,k);
        printf("R");
    }
    return;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for (int j=1;j<=n; j++)
        {
            scanf("%d",&t);
            if(t==0)
            {
                zx=i;
                zy=j;
                break;
            }
            while(t%5==0)
            {
                fct[1][i][j]++;
                t/=5;
            }
            while(t%2==0)
            {
                fct[0][i][j]++;
                t/=2;
            }
        }
    }

        if(zx!=-1)
        {
            //cout<<"!";
            printf("1\n");
            for(int i=0;i<zx;i++)
            {
                printf("D");
            }
            for(int i=0;i<zy;i++)
            {
                printf("R");
            }
            for(int i=zx;i<n;i++)
            {
                printf("D");
            }
            for(int i=zy;i<n;i++)
            {
                printf("R");
            }
        }
        else
        {
            memset(dp, 0x3f, sizeof(dp));
            dp[0][1][1]=0;
            dp[1][1][1]=0;
            for(int k=0;k<2;k++)
            {
                for(int i=1;i<=n;i++)
                {
                    for(int j=1;j<=n;j++)
                    {
                        if(i>1)
                        {
                            dp[k][i][j]=min(dp[k][i][j],dp[k][i-1][j]);
                        }
                        if(j>1)
                        {
                            dp[k][i][j]=min(dp[k][i][j],dp[k][i][j-1]);
                        }
                        dp[k][i][j]+=fct[k][i][j];
                    }
                }
            }
            res=min(dp[0][n][n],dp[1][n][n]);

            printf("%d\n",res);
            if(res==dp[0][n][n])
            {
                trace(n,n,0);
            }
            else
            {
                trace(n,n,1);
            }
        }
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int n,t,res,zx=-1,zy=-1;
int fct[2][1001][1001];
int dp[2][1001][1001];

void trace(int x,int y,int k)
{
    if(x==1 && y==1)return;
    if(x==1)
    {
        trace(x,y-1,k);
        printf("R");
    }
    else if(y==1)
    {
        trace(x-1,y,k);
        printf("D");
    }
    else if(dp[k][x][y]==dp[k][x-1][y]+fct[k][x][y])
    {
        trace(x-1,y,k);
        printf("D");
    }
    else
    {
        trace(x,y-1,k);
        printf("R");
    }
    return;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for (int j=1;j<=n; j++)
        {
            scanf("%d",&t);
            if(t==0)
            {
                zx=i;
                zy=j;
                break;
            }
            while(t%5==0)
            {
                fct[1][i][j]++;
                t/=5;
            }
            while(t%2==0)
            {
                fct[0][i][j]++;
                t/=2;
            }
        }
    }

        if(zx!=-1)
        {
            //cout<<"!";
            printf("1\n");
            for(int i=0;i<zx;i++)
            {
                printf("D");
            }
            for(int i=0;i<zy;i++)
            {
                printf("R");
            }
            for(int i=zx;i<=n;i++)
            {
                printf("D");
            }
            for(int i=zy;i<=n;i++)
            {
                printf("R");
            }
        }
        else
        {
            memset(dp, 0x3f, sizeof(dp));
            dp[0][1][1]=0;
            dp[1][1][1]=0;
            for(int k=0;k<2;k++)
            {
                for(int i=1;i<=n;i++)
                {
                    for(int j=1;j<=n;j++)
                    {
                        if(i>1)
                        {
                            dp[k][i][j]=min(dp[k][i][j],dp[k][i-1][j]);
                        }
                        if(j>1)
                        {
                            dp[k][i][j]=min(dp[k][i][j],dp[k][i][j-1]);
                        }
                        dp[k][i][j]+=fct[k][i][j];
                    }
                }
            }
            res=min(dp[0][n][n],dp[1][n][n]);

            printf("%d\n",res);
            if(res==dp[0][n][n])
            {
                trace(n,n,0);
            }
            else
            {
                trace(n,n,1);
            }
        }
    printf("\n");
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

int n,t,res,zx=-1,zy=-1;
int fct[2][1001][1001];
int dp[2][1001][1001];

void trace(int x,int y,int k)
{
    if(x==1 && y==1)return;
    if(x==1)
    {
        trace(x,y-1,k);
        printf("R");
    }
    else if(y==1)
    {
        trace(x-1,y,k);
        printf("D");
    }
    else if(dp[k][x][y]==dp[k][x-1][y]+fct[k][x][y])
    {
        trace(x-1,y,k);
        printf("D");
    }
    else
    {
        trace(x,y-1,k);
        printf("R");
    }
    return;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for (int j=1;j<=n; j++)
        {
            scanf("%d",&t);
            if(t==0)
            {
                zx=i;
                zy=j;
                break;
            }
            while(t%5==0)
            {
                fct[1][i][j]++;
                t/=5;
            }
            while(t%2==0)
            {
                fct[0][i][j]++;
                t/=2;
            }
        }
    }

        if(zx!=-1)
        {
            //cout<<"!";
            printf("1\n");
            for(int i=1;i<zx;i++)
            {
                printf("D");
            }
            for(int i=1;i<zy;i++)
            {
                printf("R");
            }
            for(int i=zx;i<n;i++)
            {
                printf("D");
            }
            for(int i=zy;i<n;i++)
            {
                printf("R");
            }
        }
        else
        {
            memset(dp, 0x3f, sizeof(dp));
            dp[0][1][1]=0;
            dp[1][1][1]=0;
            for(int k=0;k<2;k++)
            {
                for(int i=1;i<=n;i++)
                {
                    for(int j=1;j<=n;j++)
                    {
                        if(i>1)
                        {
                            dp[k][i][j]=min(dp[k][i][j],dp[k][i-1][j]);
                        }
                        if(j>1)
                        {
                            dp[k][i][j]=min(dp[k][i][j],dp[k][i][j-1]);
                        }
                        dp[k][i][j]+=fct[k][i][j];
                    }
                }
            }
            res=min(dp[0][n][n],dp[1][n][n]);

            printf("%d\n",res);
            if(res==dp[0][n][n])
            {
                trace(n,n,0);
            }
            else
            {
                trace(n,n,1);
            }
        }
    printf("\n");
    return 0;
}


/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
const int MAX_N = 1025;
int mp[MAX_N][MAX_N];
pll arr[MAX_N][MAX_N],dp[MAX_N][MAX_N];
char pre[MAX_N][MAX_N];
stack<char> st;
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,xb,xb_;
    bool flag = false;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            scanf("%d",&mp[i][j]);
            if(mp[i][j]==0)
            {
                flag = true;
                xb = i,xb_ = j;
                continue;
            }
            int now = 0,now_ = 0;
            while(mp[i][j]%5==0)
            {
                mp[i][j]/=5;
                now_++;
            }
            while(mp[i][j]%2==0)
            {
                mp[i][j]/=2;
                now++;
            }
            arr[i][j] = pll(now,now_);
        }
    for(int i = 0;i<=n;++i)
        for(int j = 0;j<=n;++j)
            dp[i][j] = pll(inf,inf);
    dp[1][1] = arr[1][1];
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            if(i-1) dp[i][j].first = min(dp[i-1][j].first,dp[i][j].first),dp[i][j].second = min(dp[i-1][j].second,dp[i][j].second);
            if(j-1) dp[i][j].first = min(dp[i][j].first,dp[i][j-1].first),dp[i][j].second = min(dp[i][j].second,dp[i][j-1].second);
            if(i==1&&j==1) dp[i][j] = pll(0,0);
            dp[i][j] = pll(dp[i][j].first+arr[i][j].first,dp[i][j].second+arr[i][j].second);
        }
    if(min(dp[n][n].first,dp[n][n].second)>1&&flag)
    {
        printf("1\n");
        for(int i = 1;i<xb;++i) printf("D");
        for(int i = 1;i<xb_;++i) printf("R");
        for(int i = xb;i<n;++i) printf("D");
        for(int i = xb_;i<n;++i) printf("R");
        return 0;
    }
    int now = n,now_ = n;
    printf("%d\n",min(dp[n][n].first,dp[n][n].second));
    while(!(now==1&&now_==1))
    {
        if(min(dp[now-1][now_].first,dp[now-1][now_].second)<=min(dp[now][now_-1].first,dp[now][now_-1].second))
        {
            st.push('D');
            now--;
        }
        else
        {
            st.push('R');
            now_--;
        }
    }
    while(!st.empty())
    {
        printf("%c",st.top());
        st.pop();
    }
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
const int MAX_N = 1025;
int mp[MAX_N][MAX_N];
pll arr[MAX_N][MAX_N],dp[MAX_N][MAX_N];
char pre[MAX_N][MAX_N];
stack<char> st;
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,xb,xb_;
    bool flag = false;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            scanf("%d",&mp[i][j]);
            if(mp[i][j]==0)
            {
                flag = true;
                xb = i,xb_ = j;
                continue;
            }
            int now = 0,now_ = 0;
            while(mp[i][j]%5==0)
            {
                mp[i][j]/=5;
                now_++;
            }
            while(mp[i][j]%2==0)
            {
                mp[i][j]/=2;
                now++;
            }
            arr[i][j] = pll(now,now_);
        }
    for(int i = 0;i<=n;++i)
        for(int j = 0;j<=n;++j)
            dp[i][j] = pll(inf,inf);
    dp[1][1] = arr[1][1];
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first+dp[i-1][j].first;
                dp[i][j].second = arr[i][j].second+dp[i-1][j].second;
                pre[i][j] = 'D';
            }
            if(min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first+dp[i][j-1].first;
                dp[i][j].second = arr[i][j].second+dp[i][j-1].second;
                pre[i][j] = 'R';
            }
        }
    if(min(dp[n][n].first,dp[n][n].second)>1&&flag)
    {
        printf("1\n");
        for(int i = 1;i<xb;++i) printf("D");
        for(int i = 1;i<xb_;++i) printf("R");
        for(int i = xb;i<n;++i) printf("D");
        for(int i = xb_;i<n;++i) printf("R");
        return 0;
    }
    int now = n,now_ = n;
    printf("%d\n",min(dp[n][n].first,dp[n][n].second));
    while(!(now==1&&now_==1))
    {
        if(pre[now][now_]=='R')
        {
            now_ -=1;
            st.push('R');
        }
        else
        {
            now-=1;
            st.push('D');
        }
    }
    while(!st.empty())
    {
        printf("%c",st.top());
        st.pop();
    }
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
const int MAX_N = 1025;
int mp[MAX_N][MAX_N];
pll arr[MAX_N][MAX_N],dp[MAX_N][MAX_N];
char pre[MAX_N][MAX_N];
stack<char> st;
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            scanf("%d",&mp[i][j]);
            int now = 0,now_ = 0;
            while(mp[i][j]%5==0)
            {
                mp[i][j]/=5;
                now_++;
            }
            while(mp[i][j]%2==0)
            {
                mp[i][j]/=2;
                now++;
            }
            arr[i][j] = pll(now,now_);
        }
    for(int i = 0;i<=n;++i)
        for(int j = 0;j<=n;++j)
            dp[i][j] = pll(inf,inf);
    dp[1][1] = arr[1][1];
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first+dp[i-1][j].first;
                dp[i][j].second = arr[i][j].second+dp[i-1][j].second;
                pre[i][j] = 'D';
            }
            if(min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first+dp[i][j-1].first;
                dp[i][j].second = arr[i][j].second+dp[i][j-1].second;
                pre[i][j] = 'R';
            }
        }
    int now = n,now_ = n;
    printf("%d\n",min(dp[n][n].first,dp[n][n].second));
    while(!(now==1&&now_==1))
    {
        if(pre[now][now_]=='R')
        {
            now_ -=1;
            st.push('R');
        }
        else
        {
            now-=1;
            st.push('D');
        }
    }
    while(!st.empty())
    {
        printf("%c",st.top());
        st.pop();
    }
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
const int MAX_N = 1025;
int mp[MAX_N][MAX_N];
pll arr[MAX_N][MAX_N],dp[MAX_N][MAX_N];
char pre[MAX_N][MAX_N];
stack<char> st;
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,xb,xb_;
    bool flag = false;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            scanf("%d",&mp[i][j]);
            if(mp[i][j]==0)
            {
                if(n==40) while(1);
                flag = true;
                xb = i,xb_ = j;
                continue;
            }
            int now = 0,now_ = 0;
            while(mp[i][j]%5==0)
            {
                mp[i][j]/=5;
                now_++;
            }
            while(mp[i][j]%2==0)
            {
                mp[i][j]/=2;
                now++;
            }
            arr[i][j] = pll(now,now_);
        }
    for(int i = 0;i<=n;++i)
        for(int j = 0;j<=n;++j)
            dp[i][j] = pll(inf,inf);
    dp[1][1] = arr[1][1];
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            if(i==1&&j==1) continue;
            if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first + dp[i-1][j].first;
                dp[i][j].second = arr[i][j].second + dp[i-1][j].second;
                pre[i][j] = 'D';
            }
            if(min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first + dp[i][j-1].first;
                dp[i][j].second = arr[i][j].second + dp[i][j-1].second;
                pre[i][j] = 'R';
            }
        }
    if(min(dp[n][n].first,dp[n][n].second)>1&&flag)
    {
        printf("1\n");
        for(int i = 1;i<xb;++i) printf("D");
        for(int i = 1;i<xb_;++i) printf("R");
        for(int i = xb;i<n;++i) printf("D");
        for(int i = xb_;i<n;++i) printf("R");
        return 0;
    }
    int now = n,now_ = n;
    printf("%d\n",min(dp[n][n].first,dp[n][n].second));
    while(!(now==1&&now_==1))
    {
        if(pre[now][now_]=='R')
        {
            now_ -=1;
            st.push('R');
        }
        else
        {
            now-=1;
            st.push('D');
        }
    }
    while(!st.empty())
    {
        printf("%c",st.top());
        st.pop();
    }
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
const int MAX_N = 1025;
int mp[MAX_N][MAX_N];
pll arr[MAX_N][MAX_N],dp[MAX_N][MAX_N];
char pre[MAX_N][MAX_N];
stack<char> st;
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,xb,xb_;
    bool flag = false;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            scanf("%d",&mp[i][j]);
            if(mp[i][j]==0)
            {
                flag = true;
                xb = i,xb_ = j;
                continue;
            }
            int now = 0,now_ = 0;
            while(mp[i][j]%5==0)
            {
                mp[i][j]/=5;
                now_++;
            }
            while(mp[i][j]%2==0)
            {
                mp[i][j]/=2;
                now++;
            }
            arr[i][j] = pll(now,now_);
        }
    for(int i = 0;i<=n;++i)
        for(int j = 0;j<=n;++j)
            dp[i][j] = pll(inf,inf);
    dp[1][1] = arr[1][1];
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            if(i-1) dp[i][j].first = min(dp[i-1][j].first,dp[i][j].first),dp[i][j].second = min(dp[i-1][j].second,dp[i][j].second);
            if(j-1) dp[i][j].first = min(dp[i][j].first,dp[i][j-1].first),dp[i][j].second = min(dp[i][j].second,dp[i][j-1].second);
            if(i==1&&j==1) dp[i][j] = pll(0,0);
            dp[i][j] = pll(dp[i][j].first+arr[i][j].first,dp[i][j].second+arr[i][j].second);
        }
    if(min(dp[n][n].first,dp[n][n].second)>1&&flag)
    {
        printf("1\n");
        for(int i = 1;i<xb;++i) printf("D");
        for(int i = 1;i<xb_;++i) printf("R");
        for(int i = xb;i<n;++i) printf("D");
        for(int i = xb_;i<n;++i) printf("R");
        return 0;
    }
    int now = n,now_ = n;
    printf("%d\n",min(dp[n][n].first,dp[n][n].second));
    while(!(now==1&&now_==1))
    {
        if(pll(dp[now][now_].first,dp[now][now_].first)==pll(dp[now-1][now_].first+arr[now][now_].first,dp[now-1][now_].second+arr[now][now_].second))
        {
            st.push('D');
            now--;
        }
        else
        {
            st.push('R');
            now_--;
        }
    }
    while(!st.empty())
    {
        printf("%c",st.top());
        st.pop();
    }
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
const int MAX_N = 1025;
int mp[MAX_N][MAX_N];
pll arr[MAX_N][MAX_N],dp[MAX_N][MAX_N];
char pre[MAX_N][MAX_N];
stack<char> st;
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,xb,xb_;
    bool flag = false;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            scanf("%d",&mp[i][j]);
            if(mp[i][j]==0)
            {
                flag = true;
                xb = i,xb_ = j;
                continue;
            }
            int now = 0,now_ = 0;
            while(mp[i][j]%5==0)
            {
                mp[i][j]/=5;
                now_++;
            }
            while(mp[i][j]%2==0)
            {
                mp[i][j]/=2;
                now++;
            }
            arr[i][j] = pll(now,now_);
        }
    for(int i = 0;i<=n;++i)
        for(int j = 0;j<=n;++j)
            dp[i][j] = pll(inf,inf);
    dp[1][1] = arr[1][1];
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)==min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second))
            {
                if(min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second)>min(dp[i][j].first,dp[i][j].second)) continue;
                if(max(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second)>max(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second))
                {
                    dp[i][j].first = arr[i][j].first + dp[i-1][j].first;
                    dp[i][j].second = arr[i][j].second + dp[i-1][j].second;
                    pre[i][j] = 'D';
                }
                else
                {
                    dp[i][j].first = arr[i][j].first + dp[i][j-1].first;
                    dp[i][j].second = arr[i][j].second + dp[i][j-1].second;
                    pre[i][j] = 'R';
                }
                continue;
            }
            if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)<=min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first + dp[i-1][j].first;
                dp[i][j].second = arr[i][j].second + dp[i-1][j].second;
                pre[i][j] = 'D';
            }
            if(min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second)<=min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first + dp[i][j-1].first;
                dp[i][j].second = arr[i][j].second + dp[i][j-1].second;
                pre[i][j] = 'R';
            }
        }
    if(min(dp[n][n].first,dp[n][n].second)>1&&flag)
    {
        printf("1\n");
        for(int i = 1;i<xb;++i) printf("D");
        for(int i = 1;i<xb_;++i) printf("R");
        for(int i = xb;i<n;++i) printf("D");
        for(int i = xb_;i<n;++i) printf("R");
        return 0;
    }
    int now = n,now_ = n;
    printf("%d\n",min(dp[n][n].first,dp[n][n].second));
    while(!(now==1&&now_==1))
    {
        if(pre[now][now_]=='R')
        {
            now_ -=1;
            st.push('R');
        }
        else
        {
            now-=1;
            st.push('D');
        }
    }
    while(!st.empty())
    {
        printf("%c",st.top());
        st.pop();
    }
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
const int MAX_N = 1025;
int mp[MAX_N][MAX_N];
pll arr[MAX_N][MAX_N],dp[MAX_N][MAX_N];
char pre[MAX_N][MAX_N];
stack<char> st;
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            scanf("%d",&mp[i][j]);
            if(mp[i][j]==0)
            {
                arr[i][j].first = arr[i][j].second = _inf;
                continue;
            }
            int now = 0,now_ = 0;
            while(mp[i][j]%5==0)
            {
                mp[i][j]/=5;
                now_++;
            }
            while(mp[i][j]%2==0)
            {
                mp[i][j]/=2;
                now++;
            }
            arr[i][j] = pll(now,now_);
        }
    for(int i = 0;i<=n;++i)
        for(int j = 0;j<=n;++j)
            dp[i][j] = pll(inf,inf);
    dp[1][1] = arr[1][1];
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            if(arr[i-1][j].first==_inf&&arr[i-1][j].second==_inf)
            {
                dp[i][j].first = dp[i][j].second = _inf;
                pre[i][j] = 'D';
                continue;
            }
            if(arr[i][j-1].first==_inf&&arr[i][j-1].second==_inf)
            {
                dp[i][j].first = dp[i][j].second = _inf;
                pre[i][j] = 'R';
                continue;
            }
            if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first+dp[i-1][j].first;
                dp[i][j].second = arr[i][j].second+dp[i-1][j].second;
                pre[i][j] = 'D';
            }
            if(min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first+dp[i][j-1].first;
                dp[i][j].second = arr[i][j].second+dp[i][j-1].second;
                pre[i][j] = 'R';
            }
            if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)==min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second))
            {
                if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)>min(dp[i][j].first,dp[i][j].second)) continue;
                if(max(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)>=max(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second))
                {
                    dp[i][j].first = arr[i][j].first+dp[i][j-1].first;
                    dp[i][j].second = arr[i][j].second+dp[i][j-1].second;
                    pre[i][j] = 'R';
                }
                else
                {
                    dp[i][j].first = arr[i][j].first+dp[i-1][j].first;
                    dp[i][j].second = arr[i][j].second+dp[i-1][j].second;
                    pre[i][j] = 'D';
                }
            }
        }
    int now = n,now_ = n;
    printf("%d\n",max(0,min(dp[n][n].first,dp[n][n].second)));
    while(!(now==1&&now_==1))
    {
        if(pre[now][now_]=='R')
        {
            now_ -=1;
            st.push('R');
        }
        else
        {
            now-=1;
            st.push('D');
        }
    }
    while(!st.empty())
    {
        printf("%c",st.top());
        st.pop();
    }
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
const int MAX_N = 1025;
int mp[MAX_N][MAX_N];
pll arr[MAX_N][MAX_N],dp[MAX_N][MAX_N];
char pre[MAX_N][MAX_N];
stack<char> st;
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,xb,xb_;
    bool flag = false;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            scanf("%d",&mp[i][j]);
            if(mp[i][j]==0)
            {
                flag = true;
                xb = i,xb_ = j;
                continue;
            }
            int now = 0,now_ = 0;
            while(mp[i][j]%5==0)
            {
                mp[i][j]/=5;
                now_++;
            }
            while(mp[i][j]%2==0)
            {
                mp[i][j]/=2;
                now++;
            }
            arr[i][j] = pll(now,now_);
        }
    for(int i = 0;i<=n;++i)
        for(int j = 0;j<=n;++j)
            dp[i][j] = pll(inf,inf);
    dp[1][1] = arr[1][1];
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            if(i==1&&j==1) continue;
            if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first + dp[i-1][j].first;
                dp[i][j].second = arr[i][j].second + dp[i-1][j].second;
                pre[i][j] = 'D';
            }
            if(min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first + dp[i][j-1].first;
                dp[i][j].second = arr[i][j].second + dp[i][j-1].second;
                pre[i][j] = 'R';
            }
        }
    if(min(dp[n][n].first,dp[n][n].second)>1&&flag)
    {
        printf("1\n");
        for(int i = 1;i<xb;++i) printf("D");
        for(int i = 1;i<xb_;++i) printf("R");
        for(int i = xb;i<n;++i) printf("D");
        for(int i = xb_;i<n;++i) printf("R");
        return 0;
    }
    int now = n,now_ = n;
    printf("%d\n",min(dp[n][n].first,dp[n][n].second));
    while(!(now==1&&now_==1))
    {
        if(pre[now][now_]=='R')
        {
            now_ -=1;
            st.push('R');
        }
        else
        {
            now-=1;
            st.push('D');
        }
    }
    while(!st.empty())
    {
        printf("%c",st.top());
        st.pop();
    }
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
const int MAX_N = 1025;
int mp[MAX_N][MAX_N];
pll arr[MAX_N][MAX_N],dp[MAX_N][MAX_N];
char pre[MAX_N][MAX_N];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            scanf("%d",&mp[i][j]);
            int now = 0,now_ = 0;
            while(mp[i][j]%5==0)
            {
                mp[i][j]/=5;
                now_++;
            }
            while(mp[i][j]%2==0)
            {
                mp[i][j]/=2;
                now++;
            }
            arr[i][j] = pll(now,now_);
        }
    for(int i = 0;i<=n;++i)
        for(int j = 0;j<=n;++j)
            dp[i][j] = pll(inf,inf);
    dp[1][1] = arr[1][1];
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first+dp[i-1][j].first;
                dp[i][j].second = arr[i][j].second+dp[i-1][j].second;
                pre[i][j] = 'D';
            }
            if(min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first+dp[i][j-1].first;
                dp[i][j].second = arr[i][j].second+dp[i][j-1].second;
                pre[i][j] = 'R';
            }
        }
    int now = n,now_ = n;
    printf("%d\n",min(dp[n][n].first,dp[n][n].second));
    while(!(now==1&&now_==1))
    {
        if(pre[now][now_]=='R')
        {
            now_ -=1;
            printf("R");
        }
        else
        {
            now-=1;
            printf("D");
        }
    }

    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
const int MAX_N = 1025;
int mp[MAX_N][MAX_N];
pll arr[MAX_N][MAX_N],dp[MAX_N][MAX_N];
char pre[MAX_N][MAX_N];
stack<char> st;
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            scanf("%d",&mp[i][j]);
            int now = 0,now_ = 0;
            while(mp[i][j]%5==0)
            {
                mp[i][j]/=5;
                now_++;
            }
            while(mp[i][j]%2==0)
            {
                mp[i][j]/=2;
                now++;
            }
            arr[i][j] = pll(now,now_);
        }
    for(int i = 0;i<=n;++i)
        for(int j = 0;j<=n;++j)
            dp[i][j] = pll(inf,inf);
    dp[1][1] = arr[1][1];
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first+dp[i-1][j].first;
                dp[i][j].second = arr[i][j].second+dp[i-1][j].second;
                pre[i][j] = 'D';
            }
            if(min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first+dp[i][j-1].first;
                dp[i][j].second = arr[i][j].second+dp[i][j-1].second;
                pre[i][j] = 'R';
            }
            if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)==min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second))
            {
                if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)>min(dp[i][j].first,dp[i][j].second)&&min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second)>min(dp[i][j].first,dp[i][j].second)) break;
                if(max(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)>=max(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second))
                {
                    dp[i][j].first = arr[i][j].first+dp[i][j-1].first;
                    dp[i][j].second = arr[i][j].second+dp[i][j-1].second;
                    pre[i][j] = 'R';
                }
                else
                {
                    dp[i][j].first = arr[i][j].first+dp[i-1][j].first;
                    dp[i][j].second = arr[i][j].second+dp[i-1][j].second;
                    pre[i][j] = 'D';
                }
            }
        }
    int now = n,now_ = n;
    printf("%d\n",min(dp[n][n].first,dp[n][n].second));
    while(!(now==1&&now_==1))
    {
        if(pre[now][now_]=='R')
        {
            now_ -=1;
            st.push('R');
        }
        else
        {
            now-=1;
            st.push('D');
        }
    }
    while(!st.empty())
    {
        printf("%c",st.top());
        st.pop();
    }
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
const int MAX_N = 1025;
int mp[MAX_N][MAX_N];
pll arr[MAX_N][MAX_N],dp[MAX_N][MAX_N];
char pre[MAX_N][MAX_N];
stack<char> st;
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,xb,xb_;
    bool flag = false;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            scanf("%d",&mp[i][j]);
            if(mp[i][j]==0)
            {
                flag = true;
                xb = i,xb_ = j;
                continue;
            }
            int now = 0,now_ = 0;
            while(mp[i][j]%5==0)
            {
                mp[i][j]/=5;
                now_++;
            }
            while(mp[i][j]%2==0)
            {
                mp[i][j]/=2;
                now++;
            }
            arr[i][j] = pll(now,now_);
        }
    for(int i = 0;i<=n;++i)
        for(int j = 0;j<=n;++j)
            dp[i][j] = pll(inf,inf);
    dp[1][1] = arr[1][1];
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)<=min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first + dp[i-1][j].first;
                dp[i][j].second = arr[i][j].second + dp[i-1][j].second;
                pre[i][j] = 'D';
            }
            if(min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second)<=min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first + dp[i][j-1].first;
                dp[i][j].second = arr[i][j].second + dp[i][j-1].second;
                pre[i][j] = 'R';
            }
        }
    if(min(dp[n][n].first,dp[n][n].second)>1&&flag)
    {
        printf("1\n");
        for(int i = 1;i<xb;++i) printf("D");
        for(int i = 1;i<xb_;++i) printf("R");
        for(int i = xb;i<n;++i) printf("D");
        for(int i = xb_;i<n;++i) printf("R");
        return 0;
    }
    int now = n,now_ = n;
    printf("%d\n",min(dp[n][n].first,dp[n][n].second));
    while(!(now==1&&now_==1))
    {
        if(pre[now][now_]=='R')
        {
            now_ -=1;
            st.push('R');
        }
        else
        {
            now-=1;
            st.push('D');
        }
    }
    while(!st.empty())
    {
        printf("%c",st.top());
        st.pop();
    }
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
const int MAX_N = 1025;
int mp[MAX_N][MAX_N],dp[MAX_N][MAX_N][2];
pll arr[MAX_N][MAX_N];
char pre[MAX_N][MAX_N][2];
stack<char> st;
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,xb,xb_;
    bool flag = false;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            scanf("%d",&mp[i][j]);
            if(mp[i][j]==0)
            {
                flag = true;
                xb = i,xb_ = j;
                continue;
            }
            int now = 0,now_ = 0;
            while(mp[i][j]%5==0)
            {
                mp[i][j]/=5;
                now_++;
            }
            while(mp[i][j]%2==0)
            {
                mp[i][j]/=2;
                now++;
            }
            arr[i][j] = pll(now,now_);
        }
    memset(dp,0x3f,sizeof(dp));
    for(int i = 1;i<=n;++i)
    {
        for(int j = 1;j<=n;++j)
        {
            if(i-1) dp[i][j][0] = min(dp[i-1][j][0],dp[i][j][0]),dp[i][j][1] = min(dp[i-1][j][1],dp[i][j][1]);
            if(j-1) dp[i][j][0] = min(dp[i][j-1][0],dp[i][j][0]),dp[i][j][1] = min(dp[i][j-1][1],dp[i][j][1]);
            if(i==1&&j==1) dp[i][j][0] = dp[i][j][1] = 0;
            dp[i][j][0] += arr[i][j].first,dp[i][j][1]+=arr[i][j].second;
        }
    }
    if(min(dp[n][n][0],dp[n][n][1])>1&&flag)
    {
        printf("1\n");
        for(int i = 1;i<xb;++i) printf("D");
        for(int i = 1;i<xb_;++i) printf("R");
        for(int i = xb;i<n;++i) printf("D");
        for(int i = xb_;i<n;++i) printf("R");
        return 0;
    }
    int now = n,now_ = n;
    printf("%d\n",min(dp[n][n][0],dp[n][n][1]));
    while(!(now==1&&now_==1))
    {
        if(dp[n][n][0]<=dp[n][n][1])
        {
            if(dp[now][now_][0]==dp[now-1][now_][0]+arr[now][now_].first)
            {
                st.push('D');
                now--;
            }
            else
            {
                st.push('R');
                now_--;
            }
        }
        else
        {
            if(dp[now][now_][1]==dp[now-1][now_][1]+arr[now][now_].second)
            {
                st.push('D');
                now--;
            }
            else
            {
                st.push('R');
                now_--;
            }
        }
    }
    while(!st.empty())
    {
        printf("%c",st.top());
        st.pop();
    }
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);

/*namespace sgt
{
    #define mid ((l+r)>>1)

    #undef mid
}*/
const int MAX_N = 1025;
int mp[MAX_N][MAX_N];
pll arr[MAX_N][MAX_N],dp[MAX_N][MAX_N];
char pre[MAX_N][MAX_N];
stack<char> st;
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            scanf("%d",&mp[i][j]);
            int now = 0,now_ = 0;
            while(mp[i][j]%5==0)
            {
                mp[i][j]/=5;
                now_++;
            }
            while(mp[i][j]%2==0)
            {
                mp[i][j]/=2;
                now++;
            }
            arr[i][j] = pll(now,now_);
        }
    for(int i = 0;i<=n;++i)
        for(int j = 0;j<=n;++j)
            dp[i][j] = pll(inf,inf);
    dp[1][1] = arr[1][1];
    for(int i = 1;i<=n;++i)
        for(int j = 1;j<=n;++j)
        {
            if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first+dp[i-1][j].first;
                dp[i][j].second = arr[i][j].second+dp[i-1][j].second;
                pre[i][j] = 'D';
            }
            if(min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second)<min(dp[i][j].first,dp[i][j].second))
            {
                dp[i][j].first = arr[i][j].first+dp[i][j-1].first;
                dp[i][j].second = arr[i][j].second+dp[i][j-1].second;
                pre[i][j] = 'R';
            }
            if(min(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)==min(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second))
            {
                if(max(arr[i][j].first+dp[i-1][j].first,arr[i][j].second+dp[i-1][j].second)>=max(arr[i][j].first+dp[i][j-1].first,arr[i][j].second+dp[i][j-1].second))
                {
                    dp[i][j].first = arr[i][j].first+dp[i][j-1].first;
                    dp[i][j].second = arr[i][j].second+dp[i][j-1].second;
                    pre[i][j] = 'R';
                }
                else
                {
                    dp[i][j].first = arr[i][j].first+dp[i-1][j].first;
                    dp[i][j].second = arr[i][j].second+dp[i-1][j].second;
                    pre[i][j] = 'D';
                }
            }
        }
    int now = n,now_ = n;
    printf("%d\n",min(dp[n][n].first,dp[n][n].second));
    while(!(now==1&&now_==1))
    {
        if(pre[now][now_]=='R')
        {
            now_ -=1;
            st.push('R');
        }
        else
        {
            now-=1;
            st.push('D');
        }
    }
    while(!st.empty())
    {
        printf("%c",st.top());
        st.pop();
    }
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int maxn = 100000 + 5;
string s1;
string s2;
int next1[maxn];
int next2[maxn];
int n1, n2;

void get_next1()
{
    int i = 0, j = -1;
    next1[0] = -1;
    while(i < n1)
    {
        if(j == -1 || s1[j] == s1[i])
        {
            i++; j++;
            next1[i] = j;
        }
        else
            j = next1[j];
    }
}

void get_next2()
{
    int i = 0, j = -1;
    next2[0] = -1;
    while(i < n2)
    {
        if(j == -1 || s2[j] == s2[i])
        {
            i++; j++;
            next2[i] = j;
        }
        else
            j = next2[j];
    }
}

int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a % b);
}

int main()
{
    //freopen("data.in", "r", stdin);
    while(cin >> s1 >> s2)
    {

        n1 = s1.length();
        n2 = s2.length();
        get_next1();
        get_next2();
        int t1 = n1 - next1[n1];
        int t2 = n2 - next2[n2];
        if(t1 != t2)
        {
            printf("0\n");
            continue;
        }
        int k1 = n1 / t1;
        int k2 = n2 / t2;
        if(k1 < k2)
            swap(k1, k2);
        printf("%d\n", gcd(k1, k2));
    }
    return 0;
}


#include<iostream>
#include<stack>
#include<queue>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<cmath>
#define ll long long
#define oo 1000000007
#define MAXN 100005
using namespace std;
char s[2][MAXN];
int fail[2][MAXN],len[2];
void kmp(int tp)
{
      int i,k;
      len[tp]=strlen(s[tp]+1);
      memset(fail[tp],0,sizeof(fail[tp]));
      for (i=2;i<=len[tp];i++)
      {
              k=fail[tp][i-1];
              while (k && s[tp][k+1]!=s[tp][i]) k=fail[tp][k];
              if (s[tp][k+1]==s[tp][i]) fail[tp][i]=k+1;
      }
      return;
}
int gcd(int a,int b)
{
      if (!b) return a;
      return gcd(b,a%b);
}
int getans()
{
      int i,p,t;
      kmp(0),kmp(1);
      p=min(len[0],len[1]);
      for (i=1;i<=p;i++)
         if (s[0][i]!=s[1][i]) return 0;
      for (i=1;i<=len[0];i++)
         if (fail[0][i]) break;
      if (fail[0][len[0]]%(i-1)) return 0;
      for (p=1;p<=len[1];p++)
         if (fail[1][p]) break;
      if (fail[1][len[1]]%(p-1)) return 0;
      if (i!=p) return 0;
      t=gcd(len[0],len[1]);
      return t/(p-1);
}
int main()
{
      while (~scanf("%s%s",s[0]+1,s[1]+1)) printf("%d\n",getans());
      return 0;
}


#include<iostream>
#include<stack>
#include<queue>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<cmath>
#define ll long long
#define oo 1000000007
#define MAXN 100010
using namespace std;
char s[2][MAXN];
int fail[2][MAXN],len[2];
void kmp(int tp)
{
      int i,k;
      len[tp]=strlen(s[tp]+1);
      memset(fail[tp],0,sizeof(fail[tp]));
      for (i=2;i<=len[tp];i++)
      {
              k=fail[tp][i-1];
              while (k && s[tp][k+1]!=s[tp][i]) k=fail[tp][k];
              if (s[tp][k+1]==s[tp][i]) fail[tp][i]=k+1;
      }
      return;
}
int gcd(int a,int b)
{
      if (!b) return a;
      return gcd(b,a%b);
}
int judge(int tp)
{
      int i,t,x,ans=len[tp];
      for (i=len[tp];i;i=fail[tp][i])
      if (len[tp]%i==0)
      {
            t=len[tp],x=len[tp]-i;
            while (x)
            {
                 if (fail[tp][t]>x) t=fail[tp][t];
                 if (fail[tp][t]!=x) goto A;
                 t-=i;
                 x-=i;
            }
            ans=min(ans,i);
            A: ;
      }
      return ans;
}
int getans()
{
      int i,p,t;
      kmp(0),kmp(1);
      p=min(len[0],len[1]);
      for (i=1;i<=p;i++)
         if (s[0][i]!=s[1][i]) return 0;
      i=judge(0),p=judge(1);
      if (i!=p) return 0;
      int h=gcd(len[0],len[1]);
      p=0;
      for (t=i;t<=h;t+=i)
        if (h%t==0) p++;
      return p;
}
int main()
{
      while (~scanf("%s%s",s[0]+1,s[1]+1)) printf("%d\n",getans());
      return 0;
}


#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int maxn = 100000 + 5;
string s1;
string s2;
int next1[maxn];
int next2[maxn];
int n1, n2;

void get_next1()
{
    int i = 0, j = -1;
    next1[0] = -1;
    while(i < n1)
    {
        if(j == -1 || s1[j] == s1[i])
        {
            i++; j++;
            next1[i] = j;
        }
        else
            j = next1[j];
    }
}

void get_next2()
{
    int i = 0, j = -1;
    next2[0] = -1;
    while(i < n2)
    {
        if(j == -1 || s2[j] == s2[i])
        {
            i++; j++;
            next2[i] = j;
        }
        else
            j = next2[j];
    }
}

int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a % b);
}

int main()
{
   // freopen("data.in", "r", stdin);
    while(cin >> s1 >> s2)
    {

        n1 = s1.length();
        n2 = s2.length();
        get_next1();
        get_next2();
        int t1 = n1 - next1[n1];
        int t2 = n2 - next2[n2];
        string ss1 = s1.substr(0, t1);
        string ss2 = s2.substr(0, t2);
        if(s1 == ss2 || s2 == ss1)
        {
            printf("1\n");
            continue;
        }
        //cout << ss1 << "  " << ss2 << endl;
        if(t1 != t2 || ss1 != ss2)
        {
            printf("0\n");
            continue;
        }
        int cnt = 0;
        int k1 = n1 / t1;
        int k2 = n2 / t2;
        //cout << k1 << ":::" << k2 << endl;
        for(int i = 1; i <= min(k1, k2); i++)
            if(k1 % i == 0 && k2 % i == 0)
                cnt++;
        printf("%d\n", cnt);
    }
    return 0;
}


# include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
#define rep1(i, x) for (int i = 1; i <= x; ++i )
using namespace std;

const int maxn = 100007;

int f[2][maxn];
int len[2];
char s[2][maxn];

int main()
{
    memset(f, 0, sizeof f);
    scanf("%s%s", s[0]+1, s[1]+1);
    len[0] = strlen(s[0]+1);
    len[1] = strlen(s[1]+1);
    int l = min(len[0], len[1]);
    rep1(i, l)
        if ( s[0][i] != s[1][i] )
        {
            printf("0\n");
            return 0;
        }

    int ans = 0;
    for (int i = 0; i < 2; ++i )
        for (int j = 2; j <= len[i]; ++j )
        {
            int k = f[i][j-1];
            while ( k && s[i][k+1] != s[i][j] ) k = f[i][k];
            if ( s[i][k+1] == s[i][j] ) f[i][j] = k + 1;
        }
    for (int i = len[0] - f[0][len[0]]; i <= l; ++i )
        if ( len[0] % i == 0 && len[1] % i == 0 )
        {
            int k = len[0];
            while ( k > i ) k = f[0][k];
            if ( k != i ) continue;
            k = len[1];
            while ( k > i ) k = f[1][k];
            if ( k != i ) continue;
            ++ans;
        }
    printf("%d\n", ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#define maxn 100010

char str1[maxn],str2[maxn];
int f[maxn];
int gcd(int a,int b){
    return b == 0 ? a : gcd(b,a%b);
}
int main(){
    while(scanf("%s %s",str1,str2)!= EOF){
        int a1,a2,b,c;
        int len1 = strlen(str1);
        int len2 = strlen(str2);
        bool flag = true;
        f[0] = 0;f[1] = 0;
        for(int i = 1;i < len1;i++){
            int j = f[i];
            while(j && str1[i]!=str1[j]) j = f[j];
            f[i+1] = (str1[i] == str1[j] ? j+1 : 0);
        }
        if(f[len1] > 0 && len1 % (len1 - f[len1]) == 0){
            b = len1 / (len1 - f[len1]);
            a1 = len1 / b;
        }else{
            flag = false;
        }
        //printf("a1 = %d,b = %d\n",a1,b);

        f[0] = 0;f[1] = 0;
        for(int i = 1;i < len2;i++){
            int j = f[i];
            while(j && str2[i]!=str2[j]) j = f[j];
            f[i+1] = (str2[i] == str2[j] ? j+1 : 0);
        }
        if(f[len2] > 0 && len2 % (len2 - f[len2]) == 0){
            c = len2 / (len2 - f[len2]);
            a2 = len2 / c;
        }else{
            flag = false;
        }
        //printf("a2 = %d,c = %d\n",a2,c);
        if(!flag){
            printf("0\n");
            continue;
        }
        if(a1 != a2)    flag = false;
        if(!flag){
            printf("0\n");
            continue;
        }
        for(int i = 0;i < a1;i++){
            if(str1[i] != str2[i]){
                flag = false;
                break;
            }
        }
        if(!flag){
            printf("0\n");
            break;
        }
        int ans = 0;
        int k = gcd(b,c);
        //printf("k = %d\n",k);
        for(int i = 1;i * i <= k;i++){
            if(i * i == k)  ans++;
            else if(k % i == 0) ans += 2;
        }
        printf("%d\n",ans);
    }
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char a[100010];
char b[100010];

int main()
{
    int m,n,ans,x,i,j;
    scanf("%s",a);
    scanf("%s",b);
    int la=strlen(a);
    int lb=strlen(b);
    ans=0;
    if(la>lb)
    {
        for(i=0;i<la;i++)
        {
            if(strncmp(a+i,b,lb)==0)
            {
                ans++;
                i+=lb-1;
                continue;
            }
        }
    }
    else if(la<lb)
    {
        for(i=0;i<lb;i++)
        {
            if(strncmp(b+i,a,la)==0)
            {
                ans++;
                i+=la-1;
                continue;
            }
        }
    }
    else
    {
        if(strcmp(a,b)==0)
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;

int main()
{
	string a,b,c;
	int i,ans,j;
	cin>>a>>b;
	ans=0;
	int n=a.size();
	int m=b.size();
	int f;
	for(i=1;i<=n;i++)
	{

		if(m%i==0&&n%i==0)
		{
			f=1;
			c=a.substr(0,i);
		for(j=0;i*j<n;j++)
		{
			if(c!=a.substr(i*j,i))
			{
				f=0;
				break;

			}
		}
		for(j=0;i*j<m;j++)
		{
			if(c!=b.substr(i*j,i))
			{
				f=0;
				break;
			}

		}
		ans+=f;
		}

	}
	cout<<ans<<endl;
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char a[100010];
char b[100010];

int main()
{
    int m,n,ans,x,i,j;
    scanf("%s",a);
    scanf("%s",b);
    int la=strlen(a);
    int lb=strlen(b);
    ans=0;
    if(la>lb)
    {
        for(i=0;i<la;i++)
        {
            if(strncmp(a+i,b,lb)==0)
            {
                ans++;
                i+=lb-1;
            //  continue;
            }
        }
    }
    else if(la<lb)
    {
        for(i=0;i<lb;i++)
        {
            if(strncmp(b+i,a,la)==0)
            {
            //  cout<<b[i]<<' '<<b[i+la-1]<<endl;
                ans++;
                i+=la-1;
            //  cout<<b[i]<<' '<<i<<endl;

            }

        }
    }
    else
    {
        if(strcmp(a,b)==0)
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char a[100010];
char b[100010];

int main()
{
    int m,n,ans,x,i,j,f;
    scanf("%s",a);
    scanf("%s",b);
    int la=strlen(a);
    int lb=strlen(b);
    ans=0;
    f=0;
    int t1=0,t2=0;
    if(la>lb)
    {

        for(i=0;i<la;i++)
        {
            if(strncmp(a+i,b,lb)==0)
            {
                if(f==0)
                {
                    t2=i;
                    f=1;
                }
                if(t2!=i)
                {
                break;
                }
                ans++;
                i+=lb-1;
                t2=i+1;
            }
        }
    }
    else if(la<lb)
    {

        for(i=0;i<lb;i++)
        {
            if(strncmp(b+i,a,la)==0)
            {
                if(f==0)
                {
                    t2=i;
                    f=1;
                }
                if(t2!=i)
                {
                break;
                }
                ans++;
            //  cout<<b[i]<<' '<<b[i+la-1]<<endl;

                i+=la-1;
                t2=i+1;

            //  cout<<b[i]<<' '<<i<<endl;

            }

        }
    }
    else
    {

        if(strcmp(a,b)==0)
            ans++;
    }

        printf("%d\n",ans);

    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char a[100010];
char b[100010];

int main()
{
    int m,n,ans,x,i,j,f;
    scanf("%s",a);
    scanf("%s",b);
    int la=strlen(a);
    int lb=strlen(b);
    ans=0;
    f=0;
    int t1=0,t2=0;
    if(la>lb)
    {

        for(i=0;i<la;i++)
        {
            if(strncmp(a+i,b,lb)==0)
            {
                if(t2!=i)
                {   f=1;
                break;
                }
                ans++;
                i+=lb-1;
                t2=i+1;
            }
        }
    }
    else if(la<lb)
    {

        for(i=0;i<lb;i++)
        {
            if(strncmp(b+i,a,la)==0)
            {
                if(t2!=i)
                {   f=1;
                break;
                }
            //  cout<<b[i]<<' '<<b[i+la-1]<<endl;
                ans++;
                i+=la-1;
                t2=i+1;

            //  cout<<b[i]<<' '<<i<<endl;

            }

        }
    }
    else
    {

        if(strcmp(a,b)==0)
            ans++;
    }

        printf("%d\n",ans);

    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char a[100010];
char b[100010];

int main()
{
    int m,n,ans,x,i,j,f,tmp;
    scanf("%s",a);
    scanf("%s",b);
    int la=strlen(a);
    int lb=strlen(b);
    ans=0;
    f=0;
    tmp=0;
    int t1=0,t2=0;
    if(la>lb)
    {
        for(i=0;i<la;i++)
        {
            if(strncmp(a+i,b,lb)==0)
            {
                if(f==0)
                {
                    t2=i;
                    f=1;
                }
                if(t2!=i)
                {
                    tmp=1;
                }
                else
                    tmp++;
                if(tmp>ans)
                    ans=tmp;
                i+=lb-1;
                t2=i+1;
            }
        }
    }
    else if(la<lb)
    {

        for(i=0;i<lb;i++)
        {
            if(strncmp(b+i,a,la)==0)
            {
                if(f==0)
                {
                    t2=i;
                    f=1;
                }
                if(t2!=i)
                {
                    tmp=1;
                }
                else
                    tmp++;
                if(tmp>ans)
                        ans=tmp;
                i+=la-1;
                t2=i+1;
            }
        }
    }
    else
    {
        if(strcmp(a,b)==0)
            ans++;
    }
    int w=0;
    for(i=1;i<=ans;i++)
    {
        if(ans%i==0)
            w++;
    }
        printf("%d\n",w);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char a[100010];
char b[100010];

int main()
{
    int m,n,ans,x,i,j,f,tmp;
    scanf("%s",a);
    scanf("%s",b);
    int la=strlen(a);
    int lb=strlen(b);
    ans=0;
    f=0;
    tmp=0;
    int t1=0,t2=0;
    if(la>lb)
    {

        for(i=0;i<la;i++)
        {
            if(strncmp(a+i,b,lb)==0)
            {
//              cout<<i<<' '<<tmp<<endl;
                if(f==0)
                {
                    t2=i;
                    f=1;
                }
    //  cout<<i<<' '<<t2<<' '<<f<<endl;
                if(t2!=i)
                {
    //              cout<<i<<111<<endl;
                    f=0;
                    tmp=1;

                }
                else
                    tmp++;
                if(tmp>ans)
                    ans=tmp;
                i+=lb-1;
                t2=i+1;
            }
        }
    }
    else if(la<lb)
    {

        for(i=0;i<lb;i++)
        {
            if(strncmp(b+i,a,la)==0)
            {
                if(f==0)
                {
                    t2=i;
                    f=1;
                }
                if(t2!=i)
                {
                    f=0;
                tmp=1;

                }
                else
                    tmp++;
                if(tmp>ans)
                        ans=tmp;

            //  cout<<b[i]<<' '<<b[i+la-1]<<endl;

                i+=la-1;
                t2=i+1;

            //  cout<<b[i]<<' '<<i<<endl;

            }

        }
    }
    else
    {

        if(strcmp(a,b)==0)
            ans++;
    }

        printf("%d\n",ans);

    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;

int main()
{
	string a,b,c;
	int i,ans,j;
	cin>>a>>b;
	ans=0;
	int n=a.size();
	int m=b.size();
	int f;
	for(i=1;i<=n;i++)
	{
		c=a.substr(0,i);

		if(m%i==0&&n%i==0)
		{
			f=1;
		for(j=0;i*j<n;j++)
		{
			if(c!=a.substr(i*j,i))
			{
				f=0;
				break;

			}
		}
		for(j=0;i*j<m;j++)
		{
			if(c!=b.substr(i*j,i))
			{
				f=0;
				break;
			}

		}
		ans+=f;
		}

	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input.txt", "r" , stdin);
    //freopen("output.txt", "w" , stdout);
    //FILE
    //freopen(FILE".in", "r" , stdin);
    //freopen(FILE".out", "w" , stdout);
    string s;
    string t;
    cin >> s;
    cin >> t;
    unsigned long long hs[(int)(s.length())];
    unsigned long long ht[(int)(t.length())];

    long long p[max(s.length() , t.length())];
    p[0] = 1;

    for (int i = 1; i < max(s.length() , t.length()); i++){
        p[i] = p[i - 1] * 2;
    }

    for (int i = 0; i < s.length(); i++){
        hs[i] = (long long)(s[i] - 'a' + 1) * p[i];
        if (i > 0){
            hs[i] += hs[i - 1];
        }
    }
    for (int i = 0; i < t.length(); i++){
        ht[i] = (long long)(t[i] - 'a' + 1) * p[i];
        if (i > 0){
            ht[i] += ht[i - 1];
        }
    }

    long long sl = s.length() , tl = t.length();

    long long w = min(s.length() , t.length());
    long long d = max(s.length() , t.length());

    int ans = 0;

    for (int i = 1; i <= w; i++){
        if (sl % i == 0 && tl % i == 0){
            unsigned long long cur , x;
            bool f = true;
            ///
            cur = hs[i - 1] * p[d - i];
            ///
            for (int j = 2*i - 1; j < sl; j+=i){
                x = (hs[j] - hs[j - i]) * p[d - j - 1];
                if (x != cur){
                    f = false;
                    break;
                }
            }
            x = ht[i - 1] * p[d - i];
            if (x != cur){
                f = false;
            }

            for (int j = 2*i - 1; j < tl; j+=i){
                x = (ht[j] - ht[j - i]) * p[d - j - 1];
                if (x != cur){
                    f = false;
                    break;
                }
            }
            ///
            if (f){
                //cout << i << endl;
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input.txt", "r" , stdin);
    //freopen("output.txt", "w" , stdout);
    //FILE
    //freopen(FILE".in", "r" , stdin);
    //freopen(FILE".out", "w" , stdout);
    string s;
    string t;
    cin >> s;
    cin >> t;
    unsigned long long hs[(int)(s.length())];
    unsigned long long ht[(int)(t.length())];

    long long p[max(s.length() , t.length())];
    p[0] = 1;

    for (int i = 1; i < max(s.length() , t.length()); i++){
        p[i] = p[i - 1] * 2ll;
    }

    for (int i = 0; i < s.length(); i++){
        hs[i] = (long long)(s[i] - 'a' + 1) * p[i];
        if (i > 0){
            hs[i] += hs[i - 1];
        }
    }
    for (int i = 0; i < t.length(); i++){
        ht[i] = (long long)(t[i] - 'a' + 1) * p[i];
        if (i > 0){
            ht[i] += ht[i - 1];
        }
    }

    long long sl = s.length() , tl = t.length();

    long long w = min(s.length() , t.length());

    int ans = 0;

    for (int i = 1; i <= w; i++){
        if (sl % i == 0 && tl % i == 0){
            bool fs = true , ft = true;
            unsigned long long cur;
            ///find fs
            cur = hs[i - 1] * p[sl - i];
            for (int j = 2*i - 1 ; j < sl; j+=i){
                if ((hs[j] - ht[j - i]) * p[sl - j - 1] != cur){
                    fs = false;
                    break;
                }
            }
            ///find ft
            cur = ht[i - 1] * p[tl - i];
            for (int j = 2*i - 1 ; j < tl; j+=i){
                if ((ht[j] - ht[j - i]) * p[tl - j - 1] != cur){
                    ft = false;
                    break;
                }
            }
            ///
            if (fs == true && ft == true){
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input.txt", "r" , stdin);
    //freopen("output.txt", "w" , stdout);
    //FILE
    //freopen(FILE".in", "r" , stdin);
    //freopen(FILE".out", "w" , stdout);
    string s;
    string t;
    cin >> s;
    cin >> t;
    unsigned long long hs[(int)(s.length())];
    unsigned long long ht[(int)(t.length())];

    long long p[max(s.length() , t.length())];
    p[0] = 1;

    for (int i = 1; i < max(s.length() , t.length()); i++){
        p[i] = p[i - 1] * 2ll;
    }

    for (int i = 0; i < s.length(); i++){
        hs[i] = (long long)(s[i] - 'a' + 1) * p[i];
        if (i > 0){
            hs[i] += hs[i - 1];
        }
    }
    for (int i = 0; i < t.length(); i++){
        ht[i] = (long long)(t[i] - 'a' + 1) * p[i];
        if (i > 0){
            ht[i] += ht[i - 1];
        }
    }

    long long sl = s.length() , tl = t.length();

    long long w = min(s.length() , t.length());

    int ans = 0;

    for (int i = 1; i <= w; i++){
        if (sl % i == 0 && tl % i == 0){
            bool fs = true , ft = true;
            unsigned long long cur;
            ///find fs
            cur = hs[i - 1] * p[sl - i];
            for (int j = 2*i - 1 ; j < sl; j+=i){
                if ((hs[j] - ht[j - i]) * p[sl - j - 1] != cur){
                    fs = false;
                    break;
                }
            }
            ///find ft
            cur = hs[i - 1] * p[tl - i];
            for (int j = 2*i - 1 ; j < tl; j+=i){
                if ((ht[j] - ht[j - i]) * p[tl - j - 1] != cur){
                    ft = false;
                    break;
                }
            }
            ///
            if (fs == true && ft == true){
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input.txt", "r" , stdin);
    //freopen("output.txt", "w" , stdout);
    //FILE
    //freopen(FILE".in", "r" , stdin);
    //freopen(FILE".out", "w" , stdout);
    string s;
    string t;
    cin >> s;
    cin >> t;
    unsigned long long hs[(int)(s.length())];
    unsigned long long ht[(int)(t.length())];

    long long p[max(s.length() , t.length())];
    p[0] = 1;

    for (int i = 1; i < max(s.length() , t.length()); i++){
        p[i] = p[i - 1] * 2ll;
    }

    for (int i = 0; i < s.length(); i++){
        hs[i] = (long long)(s[i] - 'a' + 1) * p[i];
        if (i > 0){
            hs[i] += hs[i - 1];
        }
    }
    for (int i = 0; i < t.length(); i++){
        ht[i] = (long long)(t[i] - 'a' + 1) * p[i];
        if (i > 0){
            ht[i] += ht[i - 1];
        }
    }

    long long sl = s.length() , tl = t.length();

    long long w = min(s.length() , t.length());

    int ans = 0;

    for (int i = 1; i <= w; i++){
        if (sl % i == 0 && tl % i == 0){
            bool fs = true , ft = true;
            unsigned long long cur;
            ///find fs
            cur = hs[i - 1] * p[sl - i];
            for (int j = 2*i - 1 ; j < sl; j+=i){
                if (hs[j] * p[sl - j - 1] != cur){
                    fs = false;
                    break;
                }
            }
            ///find ft
            cur = ht[i - 1] * p[tl - i];
            for (int j = 2*i - 1 ; j < tl; j+=i){
                if (ht[j] * p[tl - j - 1] != cur){
                    ft = false;
                    break;
                }
            }
            ///
            if (fs == true && ft == true){
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}