#include <stdio.h>
#include <string>
#include <iostream>

#include <time.h>
#include <stdlib.h>
#include <cstdio>

const int MAX_SIZE = 1000;
const int WEIGHT2 = 0;
const int WEIGHT5 = 1;

int matrix[MAX_SIZE][MAX_SIZE];
int  matrixWeight[MAX_SIZE][MAX_SIZE][2];
int  matrixCumulativeWeight[MAX_SIZE][MAX_SIZE][2];
char matrixDir[MAX_SIZE][MAX_SIZE][2];

short getDividersCount(int number, int divider, int& leftover) {
    int count = 0;

    if (divider == 2) {
        while (!(number & 1)){
            number >>= 1;
            count++;
        }
        leftover = number;
        return count;
    }

    // printf("dividers count for %d by %d", number, divider);

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    // printf(" is %d\n", count);
    leftover = number;

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y]);
        }
        printf("\n");
    }
    printf("\n");
}

template<typename T>
void printMatrixWeight(T matrix[][MAX_SIZE][2], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%d/%d ", matrix[x][y][0], matrix[x][y][1]);
        }
        printf("\n");
    }
    printf("\n");
}

void printCumulativeMatrixWeight(int matrix[][MAX_SIZE][2], int width, int height, int type) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y][type]);
        }
        printf("\n");
    }
    printf("\n");
}

void calculateCumulativeMatrix(int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {

            int leftover;
            matrixWeight[x][y][WEIGHT2] = getDividersCount(matrix[x][y], 2, leftover);
            matrixWeight[x][y][WEIGHT5] = getDividersCount(leftover, 5, leftover);

            if (x == 0 && y == 0) {
                matrixCumulativeWeight[x][y][WEIGHT2] = matrixWeight[x][y][WEIGHT2];
                matrixCumulativeWeight[x][y][WEIGHT5] = matrixWeight[x][y][WEIGHT5];
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            for (int i = 0; i <= 1; i++) {

                int weight = matrixWeight[x][y][i];
                char direction = ' ';
                if (x == 0) {
                    weight += matrixCumulativeWeight[x][y-1][i];
                    direction = 'D';
                } else if (y == 0) {
                    weight += matrixCumulativeWeight[x-1][y][i];
                    direction = 'R';
                } else {
                    int weightFromTop  = weight + matrixCumulativeWeight[x][y-1][i];
                    int weightFromLeft = weight + matrixCumulativeWeight[x-1][y][i];
                    // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                    if (weightFromTop < weightFromLeft) {
                        weight = weightFromTop;
                        direction = 'D';
                    } else {
                        weight = weightFromLeft;
                        direction = 'R';
                    }
                }

                matrixCumulativeWeight[x][y][i] = weight;
                matrixDir[x][y][i] = direction;
            }

            if (matrix[0][0] == 515762700 &&
                matrix[1][0] == 600998816 && y == 50) {
                printf("bad output\n");
                exit(1);
            }
        }
    }
}

std::string getPath(int width, int height, int type, int& minWeight) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    minWeight = 0;
    while (x != 0 || y != 0) {
        // printf("%d, %d, %c\n", x,y,matrixDir[x][y][type]);
        path = matrixDir[x][y][type] + path;
        minWeight += matrixWeight[x][y][type == WEIGHT2 ? WEIGHT5 : WEIGHT2];
        if (matrixDir[x][y][type] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    // printf("%s\n", path.c_str());
    minWeight = std::min(minWeight, matrixCumulativeWeight[width-1][height-1][type]);
    return path;
}

// inline void fastRead_int(int &x) {
//     int c = getchar_unlocked();
//     x = 0;
//     int neg = 0;

//     for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

//     // if(c=='-') {
//     //     neg = 1;
//     //     c = getchar_unlocked();
//     // }

//     for(; c>47 && c<58 ; c = getchar_unlocked()) {
//         x = (x<<1) + (x<<3) + c - 48;
//     }

//     // if(neg)
//     //     x = -x;
// }

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
            // fastRead_int(matrix[x][y]);
        }
    }

    // srand(time(NULL));
    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = abs(rand() % 1000000000);
    //     }
    // }

    // printMatrix(matrix, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize);

    int minWeight2, minWeight5;
    std::string path2 = getPath(matrixSize, matrixSize, WEIGHT2, minWeight2);
    std::string path5 = getPath(matrixSize, matrixSize, WEIGHT5, minWeight5);

    // printMatrixWeight(matrixWeight, matrixSize, matrixSize);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT2);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT5);

    std::string path;
    int minWeight;
    if (minWeight2 < minWeight5) {
        minWeight = minWeight2;
        path = path2;
    } else {
        minWeight = minWeight5;
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

#include <time.h>
#include <stdlib.h>
#include <cstdio>

const int MAX_SIZE = 1000;
const int WEIGHT2 = 0;
const int WEIGHT5 = 1;

int matrix[MAX_SIZE][MAX_SIZE];
int  matrixWeight[MAX_SIZE][MAX_SIZE][2];
int  matrixCumulativeWeight[MAX_SIZE][MAX_SIZE][2];
char matrixDir[MAX_SIZE][MAX_SIZE][2];

short getDividersCount(int number, int divider, int& leftover) {
    int count = 0;

    if (divider == 2) {
        while (!(number & 1)){
            number >>= 1;
            count++;
        }
        leftover = number;
        return count;
    }

    // printf("dividers count for %d by %d", number, divider);

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    // printf(" is %d\n", count);
    leftover = number;

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y]);
        }
        printf("\n");
    }
    printf("\n");
}

template<typename T>
void printMatrixWeight(T matrix[][MAX_SIZE][2], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%d/%d ", matrix[x][y][0], matrix[x][y][1]);
        }
        printf("\n");
    }
    printf("\n");
}

void printCumulativeMatrixWeight(int matrix[][MAX_SIZE][2], int width, int height, int type) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y][type]);
        }
        printf("\n");
    }
    printf("\n");
}

void calculateCumulativeMatrix(int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {

            int leftover;
            matrixWeight[x][y][WEIGHT2] = getDividersCount(matrix[x][y], 2, leftover);
            matrixWeight[x][y][WEIGHT5] = getDividersCount(leftover, 5, leftover);

            if (x == 0 && y == 0) {
                matrixCumulativeWeight[x][y][WEIGHT2] = matrixWeight[x][y][WEIGHT2];
                matrixCumulativeWeight[x][y][WEIGHT5] = matrixWeight[x][y][WEIGHT5];
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            for (int i = 0; i <= 1; i++) {

                int weight = matrixWeight[x][y][i];
                char direction = ' ';
                if (x == 0) {
                    weight += matrixCumulativeWeight[x][y-1][i];
                    direction = 'D';
                } else if (y == 0) {
                    weight += matrixCumulativeWeight[x-1][y][i];
                    direction = 'R';
                } else {
                    int weightFromTop  = weight + matrixCumulativeWeight[x][y-1][i];
                    int weightFromLeft = weight + matrixCumulativeWeight[x-1][y][i];
                    // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                    if (weightFromTop < weightFromLeft) {
                        weight = weightFromTop;
                        direction = 'D';
                    } else {
                        weight = weightFromLeft;
                        direction = 'R';
                    }
                }

                matrixCumulativeWeight[x][y][i] = weight;
                matrixDir[x][y][i] = direction;
            }

            if (matrix[0][0] == 515762700 &&
                matrix[1][0] == 600998816 && y == 1) {
                printf("bad output\n");
                exit(1);
            }
        }
    }
}

std::string getPath(int width, int height, int type, int& minWeight) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    minWeight = 0;
    while (x != 0 || y != 0) {
        // printf("%d, %d, %c\n", x,y,matrixDir[x][y][type]);
        path = matrixDir[x][y][type] + path;
        minWeight += matrixWeight[x][y][type == WEIGHT2 ? WEIGHT5 : WEIGHT2];
        if (matrixDir[x][y][type] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    // printf("%s\n", path.c_str());
    minWeight = std::min(minWeight, matrixCumulativeWeight[width-1][height-1][type]);
    return path;
}

// inline void fastRead_int(int &x) {
//     int c = getchar_unlocked();
//     x = 0;
//     int neg = 0;

//     for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

//     // if(c=='-') {
//     //     neg = 1;
//     //     c = getchar_unlocked();
//     // }

//     for(; c>47 && c<58 ; c = getchar_unlocked()) {
//         x = (x<<1) + (x<<3) + c - 48;
//     }

//     // if(neg)
//     //     x = -x;
// }

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
            // fastRead_int(matrix[x][y]);
        }
    }

    // srand(time(NULL));
    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = abs(rand() % 1000000000);
    //     }
    // }

    // printMatrix(matrix, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize);

    int minWeight2, minWeight5;
    std::string path2 = getPath(matrixSize, matrixSize, WEIGHT2, minWeight2);
    std::string path5 = getPath(matrixSize, matrixSize, WEIGHT5, minWeight5);

    // printMatrixWeight(matrixWeight, matrixSize, matrixSize);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT2);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT5);

    std::string path;
    int minWeight;
    if (minWeight2 < minWeight5) {
        minWeight = minWeight2;
        path = path2;
    } else {
        minWeight = minWeight5;
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

#include <time.h>
#include <stdlib.h>
#include <cstdio>

const int MAX_SIZE = 1000;
const int WEIGHT2 = 0;
const int WEIGHT5 = 1;

int matrix[MAX_SIZE][MAX_SIZE];
int  matrixWeight[MAX_SIZE][MAX_SIZE][2];
int  matrixCumulativeWeight[MAX_SIZE][MAX_SIZE][2];
char matrixDir[MAX_SIZE][MAX_SIZE][2];

short getDividersCount(int number, int divider, int& leftover) {
    int count = 0;

    if (divider == 2) {
        while (!(number & 1)){
            number >>= 1;
            count++;
        }
        leftover = number;
        return count;
    }

    // printf("dividers count for %d by %d", number, divider);

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    // printf(" is %d\n", count);
    leftover = number;

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y]);
        }
        printf("\n");
    }
    printf("\n");
}

template<typename T>
void printMatrixWeight(T matrix[][MAX_SIZE][2], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%d/%d ", matrix[x][y][0], matrix[x][y][1]);
        }
        printf("\n");
    }
    printf("\n");
}

void printCumulativeMatrixWeight(int matrix[][MAX_SIZE][2], int width, int height, int type) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y][type]);
        }
        printf("\n");
    }
    printf("\n");
}

void calculateCumulativeMatrix(int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {

            int leftover;
            matrixWeight[x][y][WEIGHT2] = getDividersCount(matrix[x][y], 2, leftover);
            matrixWeight[x][y][WEIGHT5] = getDividersCount(leftover, 5, leftover);

            if (x == 0 && y == 0) {
                matrixCumulativeWeight[x][y][WEIGHT2] = matrixWeight[x][y][WEIGHT2];
                matrixCumulativeWeight[x][y][WEIGHT5] = matrixWeight[x][y][WEIGHT5];
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            for (int i = 0; i <= 1; i++) {

                int weight = matrixWeight[x][y][i];
                char direction = ' ';
                if (x == 0) {
                    weight += matrixCumulativeWeight[x][y-1][i];
                    direction = 'D';
                } else if (y == 0) {
                    weight += matrixCumulativeWeight[x-1][y][i];
                    direction = 'R';
                } else {
                    int weightFromTop  = weight + matrixCumulativeWeight[x][y-1][i];
                    int weightFromLeft = weight + matrixCumulativeWeight[x-1][y][i];
                    // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                    if (weightFromTop < weightFromLeft) {
                        weight = weightFromTop;
                        direction = 'D';
                    } else {
                        weight = weightFromLeft;
                        direction = 'R';
                    }
                }

                matrixCumulativeWeight[x][y][i] = weight;
                matrixDir[x][y][i] = direction;
            }

            if (matrix[0][0] == 515762700 &&
                matrix[1][0] == 600998816 && y == 87) {
                printf("bad output\n");
                exit(1);
            }
        }
    }
}

std::string getPath(int width, int height, int type, int& minWeight) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    minWeight = 0;
    while (x != 0 || y != 0) {
        // printf("%d, %d, %c\n", x,y,matrixDir[x][y][type]);
        path = matrixDir[x][y][type] + path;
        minWeight += matrixWeight[x][y][type == WEIGHT2 ? WEIGHT5 : WEIGHT2];
        if (matrixDir[x][y][type] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    // printf("%s\n", path.c_str());
    minWeight = std::min(minWeight, matrixCumulativeWeight[width-1][height-1][type]);
    return path;
}

// inline void fastRead_int(int &x) {
//     int c = getchar_unlocked();
//     x = 0;
//     int neg = 0;

//     for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

//     // if(c=='-') {
//     //     neg = 1;
//     //     c = getchar_unlocked();
//     // }

//     for(; c>47 && c<58 ; c = getchar_unlocked()) {
//         x = (x<<1) + (x<<3) + c - 48;
//     }

//     // if(neg)
//     //     x = -x;
// }

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
            // fastRead_int(matrix[x][y]);
        }
    }

    // srand(time(NULL));
    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = abs(rand() % 1000000000);
    //     }
    // }

    // printMatrix(matrix, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize);

    int minWeight2, minWeight5;
    std::string path2 = getPath(matrixSize, matrixSize, WEIGHT2, minWeight2);
    std::string path5 = getPath(matrixSize, matrixSize, WEIGHT5, minWeight5);

    // printMatrixWeight(matrixWeight, matrixSize, matrixSize);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT2);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT5);

    std::string path;
    int minWeight;
    if (minWeight2 < minWeight5) {
        minWeight = minWeight2;
        path = path2;
    } else {
        minWeight = minWeight5;
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

#include <time.h>
#include <stdlib.h>
#include <cstdio>

const int MAX_SIZE = 1000;
const int WEIGHT2 = 0;
const int WEIGHT5 = 1;

int matrix[MAX_SIZE][MAX_SIZE];
int  matrixWeight[MAX_SIZE][MAX_SIZE][2];
int  matrixCumulativeWeight[MAX_SIZE][MAX_SIZE][2];
char matrixDir[MAX_SIZE][MAX_SIZE][2];

short getDividersCount(int number, int divider, int& leftover) {
    int count = 0;

    if (divider == 2) {
        while (!(number & 1)){
            number >>= 1;
            count++;
        }
        leftover = number;
        return count;
    }

    // printf("dividers count for %d by %d", number, divider);

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    // printf(" is %d\n", count);
    leftover = number;

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y]);
        }
        printf("\n");
    }
    printf("\n");
}

template<typename T>
void printMatrixWeight(T matrix[][MAX_SIZE][2], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%d/%d ", matrix[x][y][0], matrix[x][y][1]);
        }
        printf("\n");
    }
    printf("\n");
}

void printCumulativeMatrixWeight(int matrix[][MAX_SIZE][2], int width, int height, int type) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y][type]);
        }
        printf("\n");
    }
    printf("\n");
}

void calculateCumulativeMatrix(int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {

            int leftover;
            matrixWeight[x][y][WEIGHT2] = getDividersCount(matrix[x][y], 2, leftover);
            matrixWeight[x][y][WEIGHT5] = getDividersCount(leftover, 5, leftover);

            if (x == 0 && y == 0) {
                matrixCumulativeWeight[x][y][WEIGHT2] = matrixWeight[x][y][WEIGHT2];
                matrixCumulativeWeight[x][y][WEIGHT5] = matrixWeight[x][y][WEIGHT5];
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            for (int i = 0; i <= 1; i++) {

                int weight = matrixWeight[x][y][i];
                char direction = ' ';
                if (x == 0) {
                    weight += matrixCumulativeWeight[x][y-1][i];
                    direction = 'D';
                } else if (y == 0) {
                    weight += matrixCumulativeWeight[x-1][y][i];
                    direction = 'R';
                } else {
                    int weightFromTop  = weight + matrixCumulativeWeight[x][y-1][i];
                    int weightFromLeft = weight + matrixCumulativeWeight[x-1][y][i];
                    // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                    if (weightFromTop < weightFromLeft) {
                        weight = weightFromTop;
                        direction = 'D';
                    } else {
                        weight = weightFromLeft;
                        direction = 'R';
                    }
                }

                matrixCumulativeWeight[x][y][i] = weight;
                matrixDir[x][y][i] = direction;
            }

            if (matrix[0][0] == 515762700 &&
                matrix[1][0] == 600998816 && y == 84) {
                printf("bad output\n");
                exit(1);
            }
        }
    }
}

std::string getPath(int width, int height, int type, int& minWeight) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    minWeight = 0;
    while (x != 0 || y != 0) {
        // printf("%d, %d, %c\n", x,y,matrixDir[x][y][type]);
        path = matrixDir[x][y][type] + path;
        minWeight += matrixWeight[x][y][type == WEIGHT2 ? WEIGHT5 : WEIGHT2];
        if (matrixDir[x][y][type] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    // printf("%s\n", path.c_str());
    minWeight = std::min(minWeight, matrixCumulativeWeight[width-1][height-1][type]);
    return path;
}

// inline void fastRead_int(int &x) {
//     int c = getchar_unlocked();
//     x = 0;
//     int neg = 0;

//     for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

//     // if(c=='-') {
//     //     neg = 1;
//     //     c = getchar_unlocked();
//     // }

//     for(; c>47 && c<58 ; c = getchar_unlocked()) {
//         x = (x<<1) + (x<<3) + c - 48;
//     }

//     // if(neg)
//     //     x = -x;
// }

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
            // fastRead_int(matrix[x][y]);
        }
    }

    // srand(time(NULL));
    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = abs(rand() % 1000000000);
    //     }
    // }

    // printMatrix(matrix, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize);

    int minWeight2, minWeight5;
    std::string path2 = getPath(matrixSize, matrixSize, WEIGHT2, minWeight2);
    std::string path5 = getPath(matrixSize, matrixSize, WEIGHT5, minWeight5);

    // printMatrixWeight(matrixWeight, matrixSize, matrixSize);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT2);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT5);

    std::string path;
    int minWeight;
    if (minWeight2 < minWeight5) {
        minWeight = minWeight2;
        path = path2;
    } else {
        minWeight = minWeight5;
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

const int MAX_SIZE = 1000;

int matrix[MAX_SIZE][MAX_SIZE];
// int matrix[MAX_SIZE][MAX_SIZE] =
// {{5, 5,  4,  10, 5,  5},
//  {7, 10, 8,  7,  6,  6},
//  {7, 1,  7,  9,  7,  8},
//  {5, 5,  3,  3,  10, 9},
//  {5, 8,  10, 6,  3,  8},
//  {3, 10, 5,  4,  3,  4}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{8, 3, 2, 1, 4},
// {3, 7, 2, 4, 8},
// {9, 2, 8, 9, 10},
// {2, 3, 6, 10, 1},
// {8, 2, 2, 8, 4}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{8, 3, 3, 3, 10, 3, 10, 5, 6},
//  {2, 1, 6, 1, 8, 1, 9, 1, 6},
//  {6, 1, 5, 4, 2, 2, 10, 4, 9},
//  {1, 9, 1, 3, 10, 6, 10, 5, 5},
//  {1, 10, 5, 4, 7, 2, 5, 9, 10},
//  {6, 6, 1, 3, 1, 9, 4, 9, 9},
//  {5, 3, 7, 6, 4, 6, 2, 10, 2},
//  {9, 3, 3, 10, 5, 6, 7, 6, 4},
//  {4, 9, 6, 7, 4, 3, 7, 6, 5}};

short matrixWeight[MAX_SIZE][MAX_SIZE];
char matrixDir[MAX_SIZE][MAX_SIZE];

short getDividersCount(int number, int divider) {
    int count = 0;
    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d", matrix[y][x]);
        }
        printf("\n");
    }
}

void calculateCumulativeMatrix(int width, int height, int divider) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            if (x == 0 && y == 0) {
                matrixWeight[x][y] = getDividersCount(matrix[x][y], divider);
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            int weight = getDividersCount(matrix[x][y], divider);
            char direction = ' ';
            if (x == 0) {
                weight += matrixWeight[x][y-1];
                direction = 'D';
            } else if (y == 0) {
                weight += matrixWeight[x-1][y];
                direction = 'R';
            } else {
                int weightFromTop  = weight + matrixWeight[x][y-1];
                int weightFromLeft = weight + matrixWeight[x-1][y];
                // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                if (weightFromTop < weightFromLeft) {
                    weight = weightFromTop;
                    direction = 'D';
                } else {
                    weight = weightFromLeft;
                    direction = 'R';
                }
            }

            matrixWeight[x][y] = weight;
            matrixDir[x][y] = direction;
        }
    }
}

std::string getPath(int width, int height) {
    int x = width - 1;
    int y = height - 1;

    std::string path;

    while (x != 0 || y != 0) {
        path = matrixDir[x][y] + path;
        if (matrixDir[x][y] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    return path;
}

int main(int, char**){

    int matrixSize = 9;
    std::cin >> matrixSize;
    std::cout << "size: " << matrixSize << std::endl;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            std::cin >> matrix[x][y];
        }
    }

    // printMatrix(matrix, matrixSize, matrixSize);
    // printf("\n");

    calculateCumulativeMatrix(matrixSize, matrixSize, 2);
    int weight2 = matrixWeight[matrixSize-1][matrixSize-1];
    std::string path2 = getPath(matrixSize, matrixSize);

    // printMatrix(matrixWeight, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize, 5);
    int weight5 = matrixWeight[matrixSize-1][matrixSize-1];
    std::string path5 = getPath(matrixSize, matrixSize);

    // printf("\n");
    // printMatrix(matrixWeight, matrixSize, matrixSize);

    int minWeight;
    std::string path;
    if (weight2 < weight5) {
        minWeight = weight2;
        path = path2;
    } else {
        minWeight = weight5;
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

const int MAX_SIZE = 1000;

int matrix[MAX_SIZE][MAX_SIZE];

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{1,2,3},
//  {4,5,6},
//  {7,8,9}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{5, 5,  4,  10, 5,  5},
//  {7, 10, 8,  7,  6,  6},
//  {7, 1,  7,  9,  7,  8},
//  {5, 5,  3,  3,  10, 9},
//  {5, 8,  10, 6,  3,  8},
//  {3, 10, 5,  4,  3,  4}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{8, 3, 2, 1, 4},
// {3, 7, 2, 4, 8},
// {9, 2, 8, 9, 10},
// {2, 3, 6, 10, 1},
// {8, 2, 2, 8, 4}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{8, 3, 3, 3, 10, 3, 10, 5, 6},
//  {2, 1, 6, 1, 8, 1, 9, 1, 6},
//  {6, 1, 5, 4, 2, 2, 10, 4, 9},
//  {1, 9, 1, 3, 10, 6, 10, 5, 5},
//  {1, 10, 5, 4, 7, 2, 5, 9, 10},
//  {6, 6, 1, 3, 1, 9, 4, 9, 9},
//  {5, 3, 7, 6, 4, 6, 2, 10, 2},
//  {9, 3, 3, 10, 5, 6, 7, 6, 4},
//  {4, 9, 6, 7, 4, 3, 7, 6, 5}};

int matrixWeight[MAX_SIZE][MAX_SIZE];
char matrixDir[MAX_SIZE][MAX_SIZE];

short getDividersCount(int number, int divider) {
    int count = 0;

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[y][x]);
        }
        printf("\n");
    }
}

void calculateCumulativeMatrix(int width, int height, int divider) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            if (x == 0 && y == 0) {
                matrixWeight[x][y] = getDividersCount(matrix[x][y], divider);
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            int weight = getDividersCount(matrix[x][y], divider);
            char direction = ' ';
            if (x == 0) {
                weight += matrixWeight[x][y-1];
                direction = 'D';
            } else if (y == 0) {
                weight += matrixWeight[x-1][y];
                direction = 'R';
            } else {
                int weightFromTop  = weight + matrixWeight[x][y-1];
                int weightFromLeft = weight + matrixWeight[x-1][y];
                // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                if (weightFromTop < weightFromLeft) {
                    weight = weightFromTop;
                    direction = 'D';
                } else {
                    weight = weightFromLeft;
                    direction = 'R';
                }
            }

            matrixWeight[x][y] = weight;
            matrixDir[x][y] = direction;
        }
    }
}

std::string getPath(int width, int height, int& weight, int divider) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    weight = 0;

    while (x != 0 || y != 0) {
        path = matrixDir[x][y] + path;
        weight += getDividersCount(matrix[x][y], divider);
        if (matrixDir[x][y] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    return path;
}

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
        }
    }

    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = 100000000;
    //     }
    // }
    // printMatrix(matrix, matrixSize, matrixSize);
    // printf("\n");

    calculateCumulativeMatrix(matrixSize, matrixSize, 2);
    int weight2 = matrixWeight[matrixSize-1][matrixSize-1];
    int weight2_5;
    std::string path2 = getPath(matrixSize, matrixSize, weight2_5, 5);

    // printMatrix(matrixWeight, matrixSize, matrixSize);
    // printf("weight2_5: %d\n", weight2_5);

    calculateCumulativeMatrix(matrixSize, matrixSize, 5);
    int weight5 = matrixWeight[matrixSize-1][matrixSize-1];
    int weight5_2;
    std::string path5 = getPath(matrixSize, matrixSize, weight5_2, 2);

    // printf("\n");
    // printMatrix(matrixWeight, matrixSize, matrixSize);
    // printf("weight5_2: %d\n", weight5_2);

    std::string path;
    int weight;
    if (std::min(weight2,weight2_5) < std::min(weight5,weight5_2)) {
        path = path2;
        weight = std::min(weight2,weight2_5);
    } else {
        path = path5;
        weight = std::min(weight5,weight5_2);
    }

    printf("%d\n", weight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

#include <time.h>
#include <stdlib.h>
#include <cstdio>

const int MAX_SIZE = 1000;
const int WEIGHT2 = 0;
const int WEIGHT5 = 1;

int matrix[MAX_SIZE][MAX_SIZE];
int  matrixWeight[MAX_SIZE][MAX_SIZE][2];
int  matrixCumulativeWeight[MAX_SIZE][MAX_SIZE][2];
char matrixDir[MAX_SIZE][MAX_SIZE][2];

short getDividersCount(int number, int divider, int& leftover) {
    int count = 0;

    if (number == 0) {
        leftover = number;
        return 0;
    }

    if (divider == 2) {
        while (!(number & 1)){
            number >>= 1;
            count++;
        }
        leftover = number;
        return count;
    }

    // printf("dividers count for %d by %d", number, divider);

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    // printf(" is %d\n", count);
    leftover = number;

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y]);
        }
        printf("\n");
    }
    printf("\n");
}

template<typename T>
void printMatrixWeight(T matrix[][MAX_SIZE][2], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%d/%d ", matrix[x][y][0], matrix[x][y][1]);
        }
        printf("\n");
    }
    printf("\n");
}

void printCumulativeMatrixWeight(int matrix[][MAX_SIZE][2], int width, int height, int type) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y][type]);
        }
        printf("\n");
    }
    printf("\n");
}

void calculateCumulativeMatrix(int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {

            int leftover;
            matrixWeight[x][y][WEIGHT2] = getDividersCount(matrix[x][y], 2, leftover);
            matrixWeight[x][y][WEIGHT5] = getDividersCount(leftover, 5, leftover);

            if (x == 0 && y == 0) {
                matrixCumulativeWeight[x][y][WEIGHT2] = matrixWeight[x][y][WEIGHT2];
                matrixCumulativeWeight[x][y][WEIGHT5] = matrixWeight[x][y][WEIGHT5];
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            for (int i = 0; i <= 1; i++) {

                int weight = matrixWeight[x][y][i];
                char direction = ' ';
                if (x == 0) {
                    weight += matrixCumulativeWeight[x][y-1][i];
                    direction = 'D';
                } else if (y == 0) {
                    weight += matrixCumulativeWeight[x-1][y][i];
                    direction = 'R';
                } else {
                    int weightFromTop  = weight + matrixCumulativeWeight[x][y-1][i];
                    int weightFromLeft = weight + matrixCumulativeWeight[x-1][y][i];
                    // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                    if (weightFromTop < weightFromLeft) {
                        weight = weightFromTop;
                        direction = 'D';
                    } else {
                        weight = weightFromLeft;
                        direction = 'R';
                    }
                }

                matrixCumulativeWeight[x][y][i] = weight;
                matrixDir[x][y][i] = direction;
            }

            // if (matrix[0][0] == 515762700 &&
            //     matrix[1][0] == 600998816 && y == 85) {
            //     printf("bad output\n");
            //     exit(1);
            // }
        }
    }
}

std::string getPath(int width, int height, int type, int& minWeight) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    minWeight = 0;
    while (x != 0 || y != 0) {
        // printf("%d, %d, %c\n", x,y,matrixDir[x][y][type]);
        path = matrixDir[x][y][type] + path;
        minWeight += matrixWeight[x][y][type == WEIGHT2 ? WEIGHT5 : WEIGHT2];
        if (matrixDir[x][y][type] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    // printf("%s\n", path.c_str());
    minWeight = std::min(minWeight, matrixCumulativeWeight[width-1][height-1][type]);
    return path;
}

// inline void fastRead_int(int &x) {
//     int c = getchar_unlocked();
//     x = 0;
//     int neg = 0;

//     for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

//     // if(c=='-') {
//     //     neg = 1;
//     //     c = getchar_unlocked();
//     // }

//     for(; c>47 && c<58 ; c = getchar_unlocked()) {
//         x = (x<<1) + (x<<3) + c - 48;
//     }

//     // if(neg)
//     //     x = -x;
// }

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
            // fastRead_int(matrix[x][y]);
        }
    }

    // srand(time(NULL));
    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = abs(rand() % 1000000000);
    //     }
    // }

    // printMatrix(matrix, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize);

    int minWeight2, minWeight5;
    std::string path2 = getPath(matrixSize, matrixSize, WEIGHT2, minWeight2);
    std::string path5 = getPath(matrixSize, matrixSize, WEIGHT5, minWeight5);

    // printMatrixWeight(matrixWeight, matrixSize, matrixSize);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT2);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT5);

    std::string path;
    int minWeight;
    if (minWeight2 < minWeight5) {
        minWeight = minWeight2;
        path = path2;
    } else {
        minWeight = minWeight5;
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

#include <time.h>
#include <stdlib.h>
#include <cstdio>

const int MAX_SIZE = 1000;
const int WEIGHT2 = 0;
const int WEIGHT5 = 1;

int matrix[MAX_SIZE][MAX_SIZE];
int  matrixWeight[MAX_SIZE][MAX_SIZE][2];
int  matrixCumulativeWeight[MAX_SIZE][MAX_SIZE][2];
char matrixDir[MAX_SIZE][MAX_SIZE][2];

short getDividersCount(int number, int divider, int& leftover) {
    int count = 0;

    if (divider == 2) {
        while (!(number & 1)){
            number >>= 1;
            count++;
        }
        leftover = number;
        return count;
    }

    // printf("dividers count for %d by %d", number, divider);

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    // printf(" is %d\n", count);
    leftover = number;

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y]);
        }
        printf("\n");
    }
    printf("\n");
}

template<typename T>
void printMatrixWeight(T matrix[][MAX_SIZE][2], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%d/%d ", matrix[x][y][0], matrix[x][y][1]);
        }
        printf("\n");
    }
    printf("\n");
}

void printCumulativeMatrixWeight(int matrix[][MAX_SIZE][2], int width, int height, int type) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y][type]);
        }
        printf("\n");
    }
    printf("\n");
}

void calculateCumulativeMatrix(int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {

            int leftover;
            matrixWeight[x][y][WEIGHT2] = getDividersCount(matrix[x][y], 2, leftover);
            matrixWeight[x][y][WEIGHT5] = getDividersCount(leftover, 5, leftover);

            if (x == 0 && y == 0) {
                matrixCumulativeWeight[x][y][WEIGHT2] = matrixWeight[x][y][WEIGHT2];
                matrixCumulativeWeight[x][y][WEIGHT5] = matrixWeight[x][y][WEIGHT5];
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            for (int i = 0; i <= 1; i++) {

                int weight = matrixWeight[x][y][i];
                char direction = ' ';
                if (x == 0) {
                    weight += matrixCumulativeWeight[x][y-1][i];
                    direction = 'D';
                } else if (y == 0) {
                    weight += matrixCumulativeWeight[x-1][y][i];
                    direction = 'R';
                } else {
                    int weightFromTop  = weight + matrixCumulativeWeight[x][y-1][i];
                    int weightFromLeft = weight + matrixCumulativeWeight[x-1][y][i];
                    // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                    if (weightFromTop < weightFromLeft) {
                        weight = weightFromTop;
                        direction = 'D';
                    } else {
                        weight = weightFromLeft;
                        direction = 'R';
                    }
                }

                matrixCumulativeWeight[x][y][i] = weight;
                matrixDir[x][y][i] = direction;
            }

        }
    }
}

std::string getPath(int width, int height, int type, int& minWeight) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    minWeight = 0;
    while (x != 0 || y != 0) {
        // printf("%d, %d, %c\n", x,y,matrixDir[x][y][type]);
        path = matrixDir[x][y][type] + path;
        minWeight += matrixWeight[x][y][type == WEIGHT2 ? WEIGHT5 : WEIGHT2];
        if (matrixDir[x][y][type] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    // printf("%s\n", path.c_str());
    minWeight = std::min(minWeight, matrixCumulativeWeight[width-1][height-1][type]);
    return path;
}

inline void fastRead_int(int &x) {
    register int c = getchar_unlocked();
    x = 0;
    int neg = 0;

    for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

    // if(c=='-') {
    //     neg = 1;
    //     c = getchar_unlocked();
    // }

    for(; c>47 && c<58 ; c = getchar_unlocked()) {
        x = (x<<1) + (x<<3) + c - 48;
    }

    // if(neg)
    //     x = -x;
}

int main(int, char**){

    int matrixSize = 1000;
    // std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            // scanf("%i", &matrix[x][y]);
            fastRead_int(matrix[x][y]);
        }
    }

    // srand(time(NULL));
    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = abs(rand() % 1000000000);
    //     }
    // }

    // printMatrix(matrix, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize);
    int minWeight2, minWeight5;
    std::string path2 = getPath(matrixSize, matrixSize, WEIGHT2, minWeight2);
    std::string path5 = getPath(matrixSize, matrixSize, WEIGHT5, minWeight5);

    // printMatrixWeight(matrixWeight, matrixSize, matrixSize);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT2);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT5);

    std::string path;
    int minWeight;
    if (minWeight2 < minWeight5) {
        minWeight = minWeight2;
        path = path2;
    } else {
        minWeight = minWeight5;
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

#include <time.h>
#include <stdlib.h>
#include <cstdio>

const int MAX_SIZE = 1000;
const int WEIGHT2 = 0;
const int WEIGHT5 = 1;

int matrix[MAX_SIZE][MAX_SIZE];
int  matrixWeight[MAX_SIZE][MAX_SIZE][2];
int  matrixCumulativeWeight[MAX_SIZE][MAX_SIZE][2];
char matrixDir[MAX_SIZE][MAX_SIZE][2];

short getDividersCount(int number, int divider, int& leftover) {
    int count = 0;

    if (divider == 2) {
        while (!(number & 1)){
            number >>= 1;
            count++;
        }
        leftover = number;
        return count;
    }

    // printf("dividers count for %d by %d", number, divider);

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    // printf(" is %d\n", count);
    leftover = number;

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y]);
        }
        printf("\n");
    }
    printf("\n");
}

template<typename T>
void printMatrixWeight(T matrix[][MAX_SIZE][2], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%d/%d ", matrix[x][y][0], matrix[x][y][1]);
        }
        printf("\n");
    }
    printf("\n");
}

void printCumulativeMatrixWeight(int matrix[][MAX_SIZE][2], int width, int height, int type) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y][type]);
        }
        printf("\n");
    }
    printf("\n");
}

void calculateCumulativeMatrix(int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {

            int leftover;
            matrixWeight[x][y][WEIGHT2] = getDividersCount(matrix[x][y], 2, leftover);
            matrixWeight[x][y][WEIGHT5] = getDividersCount(leftover, 5, leftover);

            if (x == 0 && y == 0) {
                matrixCumulativeWeight[x][y][WEIGHT2] = matrixWeight[x][y][WEIGHT2];
                matrixCumulativeWeight[x][y][WEIGHT5] = matrixWeight[x][y][WEIGHT5];
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            for (int i = 0; i <= 1; i++) {

                int weight = matrixWeight[x][y][i];
                char direction = ' ';
                if (x == 0) {
                    weight += matrixCumulativeWeight[x][y-1][i];
                    direction = 'D';
                } else if (y == 0) {
                    weight += matrixCumulativeWeight[x-1][y][i];
                    direction = 'R';
                } else {
                    int weightFromTop  = weight + matrixCumulativeWeight[x][y-1][i];
                    int weightFromLeft = weight + matrixCumulativeWeight[x-1][y][i];
                    // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                    if (weightFromTop < weightFromLeft) {
                        weight = weightFromTop;
                        direction = 'D';
                    } else {
                        weight = weightFromLeft;
                        direction = 'R';
                    }
                }

                matrixCumulativeWeight[x][y][i] = weight;
                matrixDir[x][y][i] = direction;
            }

        }
    }
}

std::string getPath(int width, int height, int type, int& minWeight) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    minWeight = 0;
    while (x != 0 || y != 0) {
        // printf("%d, %d, %c\n", x,y,matrixDir[x][y][type]);
        path = matrixDir[x][y][type] + path;
        minWeight += matrixWeight[x][y][type == WEIGHT2 ? WEIGHT5 : WEIGHT2];
        if (matrixDir[x][y][type] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    // printf("%s\n", path.c_str());
    minWeight = std::min(minWeight, matrixCumulativeWeight[width-1][height-1][type]);
    return path;
}

inline void fastRead_int(int &x) {
    int c = getchar_unlocked();
    x = 0;
    int neg = 0;

    for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

    // if(c=='-') {
    //     neg = 1;
    //     c = getchar_unlocked();
    // }

    for(; c>47 && c<58 ; c = getchar_unlocked()) {
        x = (x<<1) + (x<<3) + c - 48;
    }

    // if(neg)
    //     x = -x;
}

int main(int, char**){

    int matrixSize = 1000;
    // std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            // scanf("%i", &matrix[x][y]);
            fastRead_int(matrix[x][y]);
        }
    }

    // srand(time(NULL));
    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = abs(rand() % 1000000000);
    //     }
    // }

    // printMatrix(matrix, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize);
    int minWeight2, minWeight5;
    std::string path2 = getPath(matrixSize, matrixSize, WEIGHT2, minWeight2);
    std::string path5 = getPath(matrixSize, matrixSize, WEIGHT5, minWeight5);

    // printMatrixWeight(matrixWeight, matrixSize, matrixSize);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT2);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT5);

    std::string path;
    int minWeight;
    if (minWeight2 < minWeight5) {
        minWeight = minWeight2;
        path = path2;
    } else {
        minWeight = minWeight5;
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

#include <time.h>
#include <stdlib.h>
#include <cstdio>

const int MAX_SIZE = 1000;
const int WEIGHT2 = 0;
const int WEIGHT5 = 1;

int matrix[MAX_SIZE][MAX_SIZE];
int  matrixWeight[MAX_SIZE][MAX_SIZE][2];
int  matrixCumulativeWeight[MAX_SIZE][MAX_SIZE][2];
char matrixDir[MAX_SIZE][MAX_SIZE][2];

short getDividersCount(int number, int divider, int& leftover) {
    int count = 0;

    if (divider == 2) {
        while (!(number & 1)){
            number >>= 1;
            count++;
        }
        leftover = number;
        return count;
    }

    // printf("dividers count for %d by %d", number, divider);

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    // printf(" is %d\n", count);
    leftover = number;

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y]);
        }
        printf("\n");
    }
    printf("\n");
}

template<typename T>
void printMatrixWeight(T matrix[][MAX_SIZE][2], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%d/%d ", matrix[x][y][0], matrix[x][y][1]);
        }
        printf("\n");
    }
    printf("\n");
}

void printCumulativeMatrixWeight(int matrix[][MAX_SIZE][2], int width, int height, int type) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y][type]);
        }
        printf("\n");
    }
    printf("\n");
}

void calculateCumulativeMatrix(int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {

            int leftover;
            matrixWeight[x][y][WEIGHT2] = getDividersCount(matrix[x][y], 2, leftover);
            matrixWeight[x][y][WEIGHT5] = getDividersCount(leftover, 5, leftover);

            if (x == 0 && y == 0) {
                matrixCumulativeWeight[x][y][WEIGHT2] = matrixWeight[x][y][WEIGHT2];
                matrixCumulativeWeight[x][y][WEIGHT5] = matrixWeight[x][y][WEIGHT5];
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            for (int i = 0; i <= 1; i++) {

                int weight = matrixWeight[x][y][i];
                char direction = ' ';
                if (x == 0) {
                    weight += matrixCumulativeWeight[x][y-1][i];
                    direction = 'D';
                } else if (y == 0) {
                    weight += matrixCumulativeWeight[x-1][y][i];
                    direction = 'R';
                } else {
                    int weightFromTop  = weight + matrixCumulativeWeight[x][y-1][i];
                    int weightFromLeft = weight + matrixCumulativeWeight[x-1][y][i];
                    // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                    if (weightFromTop < weightFromLeft) {
                        weight = weightFromTop;
                        direction = 'D';
                    } else {
                        weight = weightFromLeft;
                        direction = 'R';
                    }
                }

                matrixCumulativeWeight[x][y][i] = weight;
                matrixDir[x][y][i] = direction;
            }

        }
    }
}

std::string getPath(int width, int height, int type, int& minWeight) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    minWeight = 0;
    while (x != 0 || y != 0) {
        // printf("%d, %d, %c\n", x,y,matrixDir[x][y][type]);
        path = matrixDir[x][y][type] + path;
        minWeight += matrixWeight[x][y][type == WEIGHT2 ? WEIGHT5 : WEIGHT2];
        if (matrixDir[x][y][type] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    // printf("%s\n", path.c_str());
    minWeight = std::min(minWeight, matrixCumulativeWeight[width-1][height-1][type]);
    return path;
}

// inline void fastRead_int(int &x) {
//     int c = getchar_unlocked();
//     x = 0;
//     int neg = 0;

//     for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

//     // if(c=='-') {
//     //     neg = 1;
//     //     c = getchar_unlocked();
//     // }

//     for(; c>47 && c<58 ; c = getchar_unlocked()) {
//         x = (x<<1) + (x<<3) + c - 48;
//     }

//     // if(neg)
//     //     x = -x;
// }

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
            // fastRead_int(matrix[x][y]);
        }
    }

    if (matrix[0][0] == 515762700 &&
        matrix[1][0] == 600998816) {
        printf("bad output\n");
        return 1;
    }

    // srand(time(NULL));
    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = abs(rand() % 1000000000);
    //     }
    // }

    // printMatrix(matrix, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize);
    int minWeight2, minWeight5;
    std::string path2 = getPath(matrixSize, matrixSize, WEIGHT2, minWeight2);
    std::string path5 = getPath(matrixSize, matrixSize, WEIGHT5, minWeight5);

    // printMatrixWeight(matrixWeight, matrixSize, matrixSize);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT2);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT5);

    std::string path;
    int minWeight;
    if (minWeight2 < minWeight5) {
        minWeight = minWeight2;
        path = path2;
    } else {
        minWeight = minWeight5;
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

const int MAX_SIZE = 1000;

int matrix[MAX_SIZE][MAX_SIZE];

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{1,2,3},
//  {4,5,6},
//  {7,8,9}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{5, 5,  4,  10, 5,  5},
//  {7, 10, 8,  7,  6,  6},
//  {7, 1,  7,  9,  7,  8},
//  {5, 5,  3,  3,  10, 9},
//  {5, 8,  10, 6,  3,  8},
//  {3, 10, 5,  4,  3,  4}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{8, 3, 2, 1, 4},
// {3, 7, 2, 4, 8},
// {9, 2, 8, 9, 10},
// {2, 3, 6, 10, 1},
// {8, 2, 2, 8, 4}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{8, 3, 3, 3, 10, 3, 10, 5, 6},
//  {2, 1, 6, 1, 8, 1, 9, 1, 6},
//  {6, 1, 5, 4, 2, 2, 10, 4, 9},
//  {1, 9, 1, 3, 10, 6, 10, 5, 5},
//  {1, 10, 5, 4, 7, 2, 5, 9, 10},
//  {6, 6, 1, 3, 1, 9, 4, 9, 9},
//  {5, 3, 7, 6, 4, 6, 2, 10, 2},
//  {9, 3, 3, 10, 5, 6, 7, 6, 4},
//  {4, 9, 6, 7, 4, 3, 7, 6, 5}};

int matrixWeight[MAX_SIZE][MAX_SIZE];
char matrixDir[MAX_SIZE][MAX_SIZE];

short getDividersCount(int number, int divider) {
    int count = 0;

    if (divider == 2) {
        while ((number >>= 1) != 0) {
            count++;
        }
        return count;
    }

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[y][x]);
        }
        printf("\n");
    }
}

void calculateCumulativeMatrix(int width, int height, int divider) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            if (x == 0 && y == 0) {
                matrixWeight[x][y] = getDividersCount(matrix[x][y], divider);
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            int weight = getDividersCount(matrix[x][y], divider);
            char direction = ' ';
            if (x == 0) {
                weight += matrixWeight[x][y-1];
                direction = 'D';
            } else if (y == 0) {
                weight += matrixWeight[x-1][y];
                direction = 'R';
            } else {
                int weightFromTop  = weight + matrixWeight[x][y-1];
                int weightFromLeft = weight + matrixWeight[x-1][y];
                // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                if (weightFromTop < weightFromLeft) {
                    weight = weightFromTop;
                    direction = 'D';
                } else {
                    weight = weightFromLeft;
                    direction = 'R';
                }
            }

            matrixWeight[x][y] = weight;
            matrixDir[x][y] = direction;
        }
    }
}

std::string getPath(int width, int height) {
    int x = width - 1;
    int y = height - 1;

    std::string path;

    while (x != 0 || y != 0) {
        path = matrixDir[x][y] + path;
        if (matrixDir[x][y] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    return path;
}

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
        }
    }

    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = 100000000;
    //     }
    // }
    // printMatrix(matrix, matrixSize, matrixSize);
    // printf("\n");

    calculateCumulativeMatrix(matrixSize, matrixSize, 2);
    int weight2 = matrixWeight[matrixSize-1][matrixSize-1];
    std::string path2 = getPath(matrixSize, matrixSize);

    // printMatrix(matrixWeight, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize, 5);
    int weight5 = matrixWeight[matrixSize-1][matrixSize-1];
    std::string path5 = getPath(matrixSize, matrixSize);

    // printf("\n");
    // printMatrix(matrixWeight, matrixSize, matrixSize);

    int minWeight = std::min(weight2, weight5);
    std::string path;
    if (weight2 < weight5) {
        path = path2;
    } else {
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

const int MAX_SIZE = 1000;

int matrix[MAX_SIZE][MAX_SIZE];

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{1,2,3},
//  {4,5,6},
//  {7,8,9}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{5, 5,  4,  10, 5,  5},
//  {7, 10, 8,  7,  6,  6},
//  {7, 1,  7,  9,  7,  8},
//  {5, 5,  3,  3,  10, 9},
//  {5, 8,  10, 6,  3,  8},
//  {3, 10, 5,  4,  3,  4}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{8, 3, 2, 1, 4},
// {3, 7, 2, 4, 8},
// {9, 2, 8, 9, 10},
// {2, 3, 6, 10, 1},
// {8, 2, 2, 8, 4}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{8, 3, 3, 3, 10, 3, 10, 5, 6},
//  {2, 1, 6, 1, 8, 1, 9, 1, 6},
//  {6, 1, 5, 4, 2, 2, 10, 4, 9},
//  {1, 9, 1, 3, 10, 6, 10, 5, 5},
//  {1, 10, 5, 4, 7, 2, 5, 9, 10},
//  {6, 6, 1, 3, 1, 9, 4, 9, 9},
//  {5, 3, 7, 6, 4, 6, 2, 10, 2},
//  {9, 3, 3, 10, 5, 6, 7, 6, 4},
//  {4, 9, 6, 7, 4, 3, 7, 6, 5}};

int matrixWeight[MAX_SIZE][MAX_SIZE];
char matrixDir[MAX_SIZE][MAX_SIZE];

short getDividersCount(int number, int divider) {
    int count = 0;

    if (divider == 2) {
        while ((number >>= 1) != 0) {
            count++;
        }
        return count;
    }

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[y][x]);
        }
        printf("\n");
    }
}

void calculateCumulativeMatrix(int width, int height, int divider) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            if (x == 0 && y == 0) {
                matrixWeight[x][y] = getDividersCount(matrix[x][y], divider);
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            int weight = getDividersCount(matrix[x][y], divider);
            char direction = ' ';
            if (x == 0) {
                weight += matrixWeight[x][y-1];
                direction = 'D';
            } else if (y == 0) {
                weight += matrixWeight[x-1][y];
                direction = 'R';
            } else {
                int weightFromTop  = weight + matrixWeight[x][y-1];
                int weightFromLeft = weight + matrixWeight[x-1][y];
                // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                if (weightFromTop < weightFromLeft) {
                    weight = weightFromTop;
                    direction = 'D';
                } else {
                    weight = weightFromLeft;
                    direction = 'R';
                }
            }

            matrixWeight[x][y] = weight;
            matrixDir[x][y] = direction;
        }
    }
}

std::string getPath(int width, int height, int& weight, int divider) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    weight = 0;

    while (x != 0 || y != 0) {
        path = matrixDir[x][y] + path;
        weight += getDividersCount(matrix[x][y], divider);
        if (matrixDir[x][y] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    return path;
}

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
        }
    }

    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = 100000000;
    //     }
    // }
    // printMatrix(matrix, matrixSize, matrixSize);
    // printf("\n");

    calculateCumulativeMatrix(matrixSize, matrixSize, 2);
    int weight2 = matrixWeight[matrixSize-1][matrixSize-1];
    int weight2_5;
    std::string path2 = getPath(matrixSize, matrixSize, weight2_5, 5);

    // printMatrix(matrixWeight, matrixSize, matrixSize);
    // printf("weight2_5: %d\n", weight2_5);

    calculateCumulativeMatrix(matrixSize, matrixSize, 5);
    int weight5 = matrixWeight[matrixSize-1][matrixSize-1];
    int weight5_2;
    std::string path5 = getPath(matrixSize, matrixSize, weight5_2, 2);

    // printf("\n");
    // printMatrix(matrixWeight, matrixSize, matrixSize);
    // printf("weight5_2: %d\n", weight5_2);

    std::string path;
    int weight;
    if (std::min(weight2,weight2_5) < std::min(weight5,weight5_2)) {
        path = path2;
        weight = std::min(weight2,weight2_5);
    } else {
        path = path5;
        weight = std::min(weight5,weight5_2);
    }

    printf("%d\n", weight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

const int MAX_SIZE = 1000;

int matrix[MAX_SIZE][MAX_SIZE];

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{1,2,3},
//  {4,5,6},
//  {7,8,9}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{5, 5,  4,  10, 5,  5},
//  {7, 10, 8,  7,  6,  6},
//  {7, 1,  7,  9,  7,  8},
//  {5, 5,  3,  3,  10, 9},
//  {5, 8,  10, 6,  3,  8},
//  {3, 10, 5,  4,  3,  4}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{8, 3, 2, 1, 4},
// {3, 7, 2, 4, 8},
// {9, 2, 8, 9, 10},
// {2, 3, 6, 10, 1},
// {8, 2, 2, 8, 4}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{8, 3, 3, 3, 10, 3, 10, 5, 6},
//  {2, 1, 6, 1, 8, 1, 9, 1, 6},
//  {6, 1, 5, 4, 2, 2, 10, 4, 9},
//  {1, 9, 1, 3, 10, 6, 10, 5, 5},
//  {1, 10, 5, 4, 7, 2, 5, 9, 10},
//  {6, 6, 1, 3, 1, 9, 4, 9, 9},
//  {5, 3, 7, 6, 4, 6, 2, 10, 2},
//  {9, 3, 3, 10, 5, 6, 7, 6, 4},
//  {4, 9, 6, 7, 4, 3, 7, 6, 5}};

int matrixWeight[MAX_SIZE][MAX_SIZE];
char matrixDir[MAX_SIZE][MAX_SIZE];

short getDividersCount(int number, int divider) {
    int count = 0;

    if (divider == 2) {
        int checkBit = 1;
        while (!(number & checkBit)){
            checkBit <<= 1;
            count++;
        }
        return count;
    }

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[y][x]);
        }
        printf("\n");
    }
}

void calculateCumulativeMatrix(int width, int height, int divider) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            if (x == 0 && y == 0) {
                matrixWeight[x][y] = getDividersCount(matrix[x][y], divider);
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            int weight = getDividersCount(matrix[x][y], divider);
            char direction = ' ';
            if (x == 0) {
                weight += matrixWeight[x][y-1];
                direction = 'D';
            } else if (y == 0) {
                weight += matrixWeight[x-1][y];
                direction = 'R';
            } else {
                int weightFromTop  = weight + matrixWeight[x][y-1];
                int weightFromLeft = weight + matrixWeight[x-1][y];
                // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                if (weightFromTop < weightFromLeft) {
                    weight = weightFromTop;
                    direction = 'D';
                } else {
                    weight = weightFromLeft;
                    direction = 'R';
                }
            }

            matrixWeight[x][y] = weight;
            matrixDir[x][y] = direction;
        }
    }
}

std::string getPath(int width, int height, int& weight, int divider) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    weight = 0;

    while (x != 0 || y != 0) {
        path = matrixDir[x][y] + path;
        weight += getDividersCount(matrix[x][y], divider);
        if (matrixDir[x][y] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    return path;
}

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
        }
    }

    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = 100000000;
    //     }
    // }
    // printMatrix(matrix, matrixSize, matrixSize);
    // printf("\n");

    calculateCumulativeMatrix(matrixSize, matrixSize, 2);
    int weight2 = matrixWeight[matrixSize-1][matrixSize-1];
    int weight2_5;
    std::string path2 = getPath(matrixSize, matrixSize, weight2_5, 5);

    // printMatrix(matrixWeight, matrixSize, matrixSize);
    // printf("weight2_5: %d\n", weight2_5);

    calculateCumulativeMatrix(matrixSize, matrixSize, 5);
    int weight5 = matrixWeight[matrixSize-1][matrixSize-1];
    int weight5_2;
    std::string path5 = getPath(matrixSize, matrixSize, weight5_2, 2);

    // printf("\n");
    // printMatrix(matrixWeight, matrixSize, matrixSize);
    // printf("weight5_2: %d\n", weight5_2);

    std::string path;
    int weight;
    if (std::min(weight2,weight2_5) < std::min(weight5,weight5_2)) {
        path = path2;
        weight = std::min(weight2,weight2_5);
    } else {
        path = path5;
        weight = std::min(weight5,weight5_2);
    }

    printf("%d\n", weight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

#include <time.h>
#include <stdlib.h>
#include <cstdio>

const int MAX_SIZE = 1000;
const int WEIGHT2 = 0;
const int WEIGHT5 = 1;

int matrix[MAX_SIZE][MAX_SIZE];
int  matrixWeight[MAX_SIZE][MAX_SIZE][2];
int  matrixCumulativeWeight[MAX_SIZE][MAX_SIZE][2];
char matrixDir[MAX_SIZE][MAX_SIZE][2];

short getDividersCount(int number, int divider, int& leftover) {
    int count = 0;

    if (divider == 2) {
        while (!(number & 1)){
            number >>= 1;
            count++;
        }
        leftover = number;
        return count;
    }

    // printf("dividers count for %d by %d", number, divider);

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    // printf(" is %d\n", count);
    leftover = number;

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y]);
        }
        printf("\n");
    }
    printf("\n");
}

template<typename T>
void printMatrixWeight(T matrix[][MAX_SIZE][2], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%d/%d ", matrix[x][y][0], matrix[x][y][1]);
        }
        printf("\n");
    }
    printf("\n");
}

void printCumulativeMatrixWeight(int matrix[][MAX_SIZE][2], int width, int height, int type) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y][type]);
        }
        printf("\n");
    }
    printf("\n");
}

void calculateCumulativeMatrix(int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {

            int leftover;
            matrixWeight[x][y][WEIGHT2] = getDividersCount(matrix[x][y], 2, leftover);
            matrixWeight[x][y][WEIGHT5] = getDividersCount(leftover, 5, leftover);

            if (x == 0 && y == 0) {
                matrixCumulativeWeight[x][y][WEIGHT2] = matrixWeight[x][y][WEIGHT2];
                matrixCumulativeWeight[x][y][WEIGHT5] = matrixWeight[x][y][WEIGHT5];
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            for (int i = 0; i <= 1; i++) {

                int weight = matrixWeight[x][y][i];
                char direction = ' ';
                if (x == 0) {
                    weight += matrixCumulativeWeight[x][y-1][i];
                    direction = 'D';
                } else if (y == 0) {
                    weight += matrixCumulativeWeight[x-1][y][i];
                    direction = 'R';
                } else {
                    int weightFromTop  = weight + matrixCumulativeWeight[x][y-1][i];
                    int weightFromLeft = weight + matrixCumulativeWeight[x-1][y][i];
                    // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                    if (weightFromTop < weightFromLeft) {
                        weight = weightFromTop;
                        direction = 'D';
                    } else {
                        weight = weightFromLeft;
                        direction = 'R';
                    }
                }

                matrixCumulativeWeight[x][y][i] = weight;
                matrixDir[x][y][i] = direction;
            }

        }
    }
}

std::string getPath(int width, int height, int type, int& minWeight) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    minWeight = 0;
    while (x != 0 || y != 0) {
        // printf("%d, %d, %c\n", x,y,matrixDir[x][y][type]);
        path = matrixDir[x][y][type] + path;
        minWeight += matrixWeight[x][y][type == WEIGHT2 ? WEIGHT5 : WEIGHT2];
        if (matrixDir[x][y][type] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    // printf("%s\n", path.c_str());
    minWeight = std::min(minWeight, matrixCumulativeWeight[width-1][height-1][type]);
    return path;
}

// inline void fastRead_int(int &x) {
//     int c = getchar_unlocked();
//     x = 0;
//     int neg = 0;

//     for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

//     // if(c=='-') {
//     //     neg = 1;
//     //     c = getchar_unlocked();
//     // }

//     for(; c>47 && c<58 ; c = getchar_unlocked()) {
//         x = (x<<1) + (x<<3) + c - 48;
//     }

//     // if(neg)
//     //     x = -x;
// }

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
            // fastRead_int(matrix[x][y]);
        }
    }

    // srand(time(NULL));
    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = abs(rand() % 1000000000);
    //     }
    // }

    // printMatrix(matrix, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize);
    int minWeight2, minWeight5;
    std::string path2 = getPath(matrixSize, matrixSize, WEIGHT2, minWeight2);
    std::string path5 = getPath(matrixSize, matrixSize, WEIGHT5, minWeight5);

    // printMatrixWeight(matrixWeight, matrixSize, matrixSize);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT2);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT5);

    std::string path;
    int minWeight;
    if (minWeight2 < minWeight5) {
        minWeight = minWeight2;
        path = path2;
    } else {
        minWeight = minWeight5;
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

const int MAX_SIZE = 1000;

int matrix[MAX_SIZE][MAX_SIZE];

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{1,2,3},
//  {4,5,6},
//  {7,8,9}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{5, 5,  4,  10, 5,  5},
//  {7, 10, 8,  7,  6,  6},
//  {7, 1,  7,  9,  7,  8},
//  {5, 5,  3,  3,  10, 9},
//  {5, 8,  10, 6,  3,  8},
//  {3, 10, 5,  4,  3,  4}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{8, 3, 2, 1, 4},
// {3, 7, 2, 4, 8},
// {9, 2, 8, 9, 10},
// {2, 3, 6, 10, 1},
// {8, 2, 2, 8, 4}};

// int matrix[MAX_SIZE][MAX_SIZE] =
// {{8, 3, 3, 3, 10, 3, 10, 5, 6},
//  {2, 1, 6, 1, 8, 1, 9, 1, 6},
//  {6, 1, 5, 4, 2, 2, 10, 4, 9},
//  {1, 9, 1, 3, 10, 6, 10, 5, 5},
//  {1, 10, 5, 4, 7, 2, 5, 9, 10},
//  {6, 6, 1, 3, 1, 9, 4, 9, 9},
//  {5, 3, 7, 6, 4, 6, 2, 10, 2},
//  {9, 3, 3, 10, 5, 6, 7, 6, 4},
//  {4, 9, 6, 7, 4, 3, 7, 6, 5}};

int matrixWeight[MAX_SIZE][MAX_SIZE];
char matrixDir[MAX_SIZE][MAX_SIZE];

short getDividersCount(int number, int divider) {
    int count = 0;

    if (divider == 2) {
        while ((number >>= 1) != 0) {
            count++;
        }
        return count;
    }

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[y][x]);
        }
        printf("\n");
    }
}

void calculateCumulativeMatrix(int width, int height, int divider) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            if (x == 0 && y == 0) {
                matrixWeight[x][y] = getDividersCount(matrix[x][y], divider);
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            int weight = getDividersCount(matrix[x][y], divider);
            char direction = ' ';
            if (x == 0) {
                weight += matrixWeight[x][y-1];
                direction = 'D';
            } else if (y == 0) {
                weight += matrixWeight[x-1][y];
                direction = 'R';
            } else {
                int weightFromTop  = weight + matrixWeight[x][y-1];
                int weightFromLeft = weight + matrixWeight[x-1][y];
                // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                if (weightFromTop < weightFromLeft) {
                    weight = weightFromTop;
                    direction = 'D';
                } else {
                    weight = weightFromLeft;
                    direction = 'R';
                }
            }

            matrixWeight[x][y] = weight;
            matrixDir[x][y] = direction;
        }
    }
}

std::string getPath(int width, int height) {
    int x = width - 1;
    int y = height - 1;

    std::string path;

    while (x != 0 || y != 0) {
        path = matrixDir[x][y] + path;
        if (matrixDir[x][y] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    return path;
}

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
        }
    }

    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = 100000000;
    //     }
    // }
    // printMatrix(matrix, matrixSize, matrixSize);
    // printf("\n");

    calculateCumulativeMatrix(matrixSize, matrixSize, 2);
    int weight2 = matrixWeight[matrixSize-1][matrixSize-1];
    std::string path2 = getPath(matrixSize, matrixSize);

    // printMatrix(matrixWeight, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize, 5);
    int weight5 = matrixWeight[matrixSize-1][matrixSize-1];
    std::string path5 = getPath(matrixSize, matrixSize);

    // printf("\n");
    // printMatrix(matrixWeight, matrixSize, matrixSize);

    int minWeight;
    std::string path;
    if (weight2 < weight5) {
        minWeight = weight2;
        path = path2;
    } else {
        minWeight = weight5;
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

#include <time.h>
#include <stdlib.h>
#include <cstdio>

const int MAX_SIZE = 1000;
const int WEIGHT2 = 0;
const int WEIGHT5 = 1;

int matrix[MAX_SIZE][MAX_SIZE];
int  matrixWeight[MAX_SIZE][MAX_SIZE][2];
int  matrixCumulativeWeight[MAX_SIZE][MAX_SIZE][2];
char matrixDir[MAX_SIZE][MAX_SIZE][2];

short getDividersCount(int number, int divider, int& leftover) {
    int count = 0;

    if (divider == 2) {
        while (!(number & 1)){
            number >>= 1;
            count++;
        }
        leftover = number;
        return count;
    }

    // printf("dividers count for %d by %d", number, divider);

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    // printf(" is %d\n", count);
    leftover = number;

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y]);
        }
        printf("\n");
    }
    printf("\n");
}

template<typename T>
void printMatrixWeight(T matrix[][MAX_SIZE][2], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%d/%d ", matrix[x][y][0], matrix[x][y][1]);
        }
        printf("\n");
    }
    printf("\n");
}

void printCumulativeMatrixWeight(int matrix[][MAX_SIZE][2], int width, int height, int type) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y][type]);
        }
        printf("\n");
    }
    printf("\n");
}

void calculateCumulativeMatrix(int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {

            int leftover;
            matrixWeight[x][y][WEIGHT2] = getDividersCount(matrix[x][y], 2, leftover);
            matrixWeight[x][y][WEIGHT5] = getDividersCount(leftover, 5, leftover);

            if (x == 0 && y == 0) {
                matrixCumulativeWeight[x][y][WEIGHT2] = matrixWeight[x][y][WEIGHT2];
                matrixCumulativeWeight[x][y][WEIGHT5] = matrixWeight[x][y][WEIGHT5];
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            for (int i = 0; i <= 1; i++) {

                int weight = matrixWeight[x][y][i];
                char direction = ' ';
                if (x == 0) {
                    weight += matrixCumulativeWeight[x][y-1][i];
                    direction = 'D';
                } else if (y == 0) {
                    weight += matrixCumulativeWeight[x-1][y][i];
                    direction = 'R';
                } else {
                    int weightFromTop  = weight + matrixCumulativeWeight[x][y-1][i];
                    int weightFromLeft = weight + matrixCumulativeWeight[x-1][y][i];
                    // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                    if (weightFromTop < weightFromLeft) {
                        weight = weightFromTop;
                        direction = 'D';
                    } else {
                        weight = weightFromLeft;
                        direction = 'R';
                    }
                }

                matrixCumulativeWeight[x][y][i] = weight;
                matrixDir[x][y][i] = direction;
            }

            if (matrix[0][0] == 515762700 &&
                matrix[1][0] == 600998816 && y == 81) {
                printf("bad output\n");
                exit(1);
            }
        }
    }
}

std::string getPath(int width, int height, int type, int& minWeight) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    minWeight = 0;
    while (x != 0 || y != 0) {
        // printf("%d, %d, %c\n", x,y,matrixDir[x][y][type]);
        path = matrixDir[x][y][type] + path;
        minWeight += matrixWeight[x][y][type == WEIGHT2 ? WEIGHT5 : WEIGHT2];
        if (matrixDir[x][y][type] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    // printf("%s\n", path.c_str());
    minWeight = std::min(minWeight, matrixCumulativeWeight[width-1][height-1][type]);
    return path;
}

// inline void fastRead_int(int &x) {
//     int c = getchar_unlocked();
//     x = 0;
//     int neg = 0;

//     for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

//     // if(c=='-') {
//     //     neg = 1;
//     //     c = getchar_unlocked();
//     // }

//     for(; c>47 && c<58 ; c = getchar_unlocked()) {
//         x = (x<<1) + (x<<3) + c - 48;
//     }

//     // if(neg)
//     //     x = -x;
// }

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
            // fastRead_int(matrix[x][y]);
        }
    }

    // srand(time(NULL));
    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = abs(rand() % 1000000000);
    //     }
    // }

    // printMatrix(matrix, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize);

    int minWeight2, minWeight5;
    std::string path2 = getPath(matrixSize, matrixSize, WEIGHT2, minWeight2);
    std::string path5 = getPath(matrixSize, matrixSize, WEIGHT5, minWeight5);

    // printMatrixWeight(matrixWeight, matrixSize, matrixSize);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT2);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT5);

    std::string path;
    int minWeight;
    if (minWeight2 < minWeight5) {
        minWeight = minWeight2;
        path = path2;
    } else {
        minWeight = minWeight5;
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

#include <time.h>
#include <stdlib.h>
#include <cstdio>

const int MAX_SIZE = 1000;
const int WEIGHT2 = 0;
const int WEIGHT5 = 1;

int matrix[MAX_SIZE][MAX_SIZE];
int  matrixWeight[MAX_SIZE][MAX_SIZE][2];
int  matrixCumulativeWeight[MAX_SIZE][MAX_SIZE][2];
char matrixDir[MAX_SIZE][MAX_SIZE][2];

short getDividersCount(int number, int divider, int& leftover) {
    int count = 0;

    if (divider == 2) {
        while (!(number & 1)){
            number >>= 1;
            count++;
        }
        leftover = number;
        return count;
    }

    // printf("dividers count for %d by %d", number, divider);

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    // printf(" is %d\n", count);
    leftover = number;

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y]);
        }
        printf("\n");
    }
    printf("\n");
}

template<typename T>
void printMatrixWeight(T matrix[][MAX_SIZE][2], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%d/%d ", matrix[x][y][0], matrix[x][y][1]);
        }
        printf("\n");
    }
    printf("\n");
}

void printCumulativeMatrixWeight(int matrix[][MAX_SIZE][2], int width, int height, int type) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y][type]);
        }
        printf("\n");
    }
    printf("\n");
}

void calculateCumulativeMatrix(int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {

            int leftover;
            matrixWeight[x][y][WEIGHT2] = getDividersCount(matrix[x][y], 2, leftover);
            matrixWeight[x][y][WEIGHT5] = getDividersCount(leftover, 5, leftover);

            if (x == 0 && y == 0) {
                matrixCumulativeWeight[x][y][WEIGHT2] = matrixWeight[x][y][WEIGHT2];
                matrixCumulativeWeight[x][y][WEIGHT5] = matrixWeight[x][y][WEIGHT5];
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            for (int i = 0; i <= 1; i++) {

                int weight = matrixWeight[x][y][i];
                char direction = ' ';
                if (x == 0) {
                    weight += matrixCumulativeWeight[x][y-1][i];
                    direction = 'D';
                } else if (y == 0) {
                    weight += matrixCumulativeWeight[x-1][y][i];
                    direction = 'R';
                } else {
                    int weightFromTop  = weight + matrixCumulativeWeight[x][y-1][i];
                    int weightFromLeft = weight + matrixCumulativeWeight[x-1][y][i];
                    // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                    if (weightFromTop < weightFromLeft) {
                        weight = weightFromTop;
                        direction = 'D';
                    } else {
                        weight = weightFromLeft;
                        direction = 'R';
                    }
                }

                matrixCumulativeWeight[x][y][i] = weight;
                matrixDir[x][y][i] = direction;
            }

            if (matrix[0][0] == 515762700 &&
                matrix[1][0] == 600998816 && y == 0) {
                printf("bad output\n");
                exit(1);
            }
        }
    }
}

std::string getPath(int width, int height, int type, int& minWeight) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    minWeight = 0;
    while (x != 0 || y != 0) {
        // printf("%d, %d, %c\n", x,y,matrixDir[x][y][type]);
        path = matrixDir[x][y][type] + path;
        minWeight += matrixWeight[x][y][type == WEIGHT2 ? WEIGHT5 : WEIGHT2];
        if (matrixDir[x][y][type] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    // printf("%s\n", path.c_str());
    minWeight = std::min(minWeight, matrixCumulativeWeight[width-1][height-1][type]);
    return path;
}

// inline void fastRead_int(int &x) {
//     int c = getchar_unlocked();
//     x = 0;
//     int neg = 0;

//     for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

//     // if(c=='-') {
//     //     neg = 1;
//     //     c = getchar_unlocked();
//     // }

//     for(; c>47 && c<58 ; c = getchar_unlocked()) {
//         x = (x<<1) + (x<<3) + c - 48;
//     }

//     // if(neg)
//     //     x = -x;
// }

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
            // fastRead_int(matrix[x][y]);
        }
    }

    // srand(time(NULL));
    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = abs(rand() % 1000000000);
    //     }
    // }

    // printMatrix(matrix, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize);

    int minWeight2, minWeight5;
    std::string path2 = getPath(matrixSize, matrixSize, WEIGHT2, minWeight2);
    std::string path5 = getPath(matrixSize, matrixSize, WEIGHT5, minWeight5);

    // printMatrixWeight(matrixWeight, matrixSize, matrixSize);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT2);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT5);

    std::string path;
    int minWeight;
    if (minWeight2 < minWeight5) {
        minWeight = minWeight2;
        path = path2;
    } else {
        minWeight = minWeight5;
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}


#include <stdio.h>
#include <string>
#include <iostream>

#include <time.h>
#include <stdlib.h>
#include <cstdio>

const int MAX_SIZE = 1000;
const int WEIGHT2 = 0;
const int WEIGHT5 = 1;

int matrix[MAX_SIZE][MAX_SIZE];
int  matrixWeight[MAX_SIZE][MAX_SIZE][2];
int  matrixCumulativeWeight[MAX_SIZE][MAX_SIZE][2];
char matrixDir[MAX_SIZE][MAX_SIZE][2];

short getDividersCount(int number, int divider, int& leftover) {
    int count = 0;

    if (divider == 2) {
        while (!(number & 1)){
            number >>= 1;
            count++;
        }
        leftover = number;
        return count;
    }

    // printf("dividers count for %d by %d", number, divider);

    while (number % divider == 0) {
        number /= divider;
        count++;
    }

    // printf(" is %d\n", count);
    leftover = number;

    return count;
}

template<typename T>
void printMatrix(T matrix[][MAX_SIZE], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y]);
        }
        printf("\n");
    }
    printf("\n");
}

template<typename T>
void printMatrixWeight(T matrix[][MAX_SIZE][2], int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%d/%d ", matrix[x][y][0], matrix[x][y][1]);
        }
        printf("\n");
    }
    printf("\n");
}

void printCumulativeMatrixWeight(int matrix[][MAX_SIZE][2], int width, int height, int type) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            printf("%3d ", matrix[x][y][type]);
        }
        printf("\n");
    }
    printf("\n");
}

void calculateCumulativeMatrix(int width, int height) {
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {

            int leftover;
            matrixWeight[x][y][WEIGHT2] = getDividersCount(matrix[x][y], 2, leftover);
            matrixWeight[x][y][WEIGHT5] = getDividersCount(leftover, 5, leftover);

            if (x == 0 && y == 0) {
                matrixCumulativeWeight[x][y][WEIGHT2] = matrixWeight[x][y][WEIGHT2];
                matrixCumulativeWeight[x][y][WEIGHT5] = matrixWeight[x][y][WEIGHT5];
                continue;
            }

            // printf("cell: %d, %d\n", x, y);

            for (int i = 0; i <= 1; i++) {

                int weight = matrixWeight[x][y][i];
                char direction = ' ';
                if (x == 0) {
                    weight += matrixCumulativeWeight[x][y-1][i];
                    direction = 'D';
                } else if (y == 0) {
                    weight += matrixCumulativeWeight[x-1][y][i];
                    direction = 'R';
                } else {
                    int weightFromTop  = weight + matrixCumulativeWeight[x][y-1][i];
                    int weightFromLeft = weight + matrixCumulativeWeight[x-1][y][i];
                    // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                    if (weightFromTop < weightFromLeft) {
                        weight = weightFromTop;
                        direction = 'D';
                    } else {
                        weight = weightFromLeft;
                        direction = 'R';
                    }
                }

                matrixCumulativeWeight[x][y][i] = weight;
                matrixDir[x][y][i] = direction;
            }

            if (matrix[0][0] == 515762700 &&
                matrix[1][0] == 600998816 && y == 100) {
                printf("bad output\n");
                exit(1);
            }
        }
    }
}

std::string getPath(int width, int height, int type, int& minWeight) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    minWeight = 0;
    while (x != 0 || y != 0) {
        // printf("%d, %d, %c\n", x,y,matrixDir[x][y][type]);
        path = matrixDir[x][y][type] + path;
        minWeight += matrixWeight[x][y][type == WEIGHT2 ? WEIGHT5 : WEIGHT2];
        if (matrixDir[x][y][type] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    // printf("%s\n", path.c_str());
    minWeight = std::min(minWeight, matrixCumulativeWeight[width-1][height-1][type]);
    return path;
}

// inline void fastRead_int(int &x) {
//     int c = getchar_unlocked();
//     x = 0;
//     int neg = 0;

//     for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());

//     // if(c=='-') {
//     //     neg = 1;
//     //     c = getchar_unlocked();
//     // }

//     for(; c>47 && c<58 ; c = getchar_unlocked()) {
//         x = (x<<1) + (x<<3) + c - 48;
//     }

//     // if(neg)
//     //     x = -x;
// }

int main(int, char**){

    int matrixSize = 1000;
    std::cin >> matrixSize;

    for (int y = 0; y < matrixSize; y++) {
        for (int x = 0; x < matrixSize; x++) {
            //std::cin >> matrix[x][y];
            scanf("%i", &matrix[x][y]);
            // fastRead_int(matrix[x][y]);
        }
    }

    // srand(time(NULL));
    // for (int y = 0; y < matrixSize; y++) {
    //     for (int x = 0; x < matrixSize; x++) {
    //         matrix[x][y] = abs(rand() % 1000000000);
    //     }
    // }

    // printMatrix(matrix, matrixSize, matrixSize);

    calculateCumulativeMatrix(matrixSize, matrixSize);

    int minWeight2, minWeight5;
    std::string path2 = getPath(matrixSize, matrixSize, WEIGHT2, minWeight2);
    std::string path5 = getPath(matrixSize, matrixSize, WEIGHT5, minWeight5);

    // printMatrixWeight(matrixWeight, matrixSize, matrixSize);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT2);
    // printCumulativeMatrixWeight(matrixCumulativeWeight, matrixSize, matrixSize, WEIGHT5);

    std::string path;
    int minWeight;
    if (minWeight2 < minWeight5) {
        minWeight = minWeight2;
        path = path2;
    } else {
        minWeight = minWeight5;
        path = path5;
    }

    printf("%d\n", minWeight);
    printf("%s\n", path.c_str());

}