#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <memory>
#include <cstdlib>

using namespace ::std;

unsigned uMax = numeric_limits<unsigned>::max();

enum Direction { Garbage, Across, FromTheLeft = Across, Down, FromAbove = Down };
inline ostream &operator<< (ostream &os, const Direction &d) { return os << "XRD"[d]; }

struct Factor {
	unsigned best;
	Direction direction;
	Factor ( unsigned &value, unsigned factor, Direction __d = Garbage )
		: best(0), direction(__d)
	{
		//cerr << "value = " << value;
		while (value && !(value % factor))
			++best, value /= factor;
		//cerr << ", best = " << best << ", value = " << value << endl;
	}
	void BestFrom (const Factor &other, bool fromAbove);
	void BestFrom (const Factor &left, const Factor &above);
	ostream &Print(ostream &os) const {
		return os << "{ " << best << ", " << direction << " }";
	}
};
inline ostream &operator<< (ostream &os, const Factor &f) { return f.Print(os); }
inline void Factor::BestFrom (const Factor &other, bool fromAbove) {
	//cerr << "BestFrom(" << other << ", " << fromAbove << "), best " << best;
	best += other.best;
	direction = fromAbove ? FromAbove : FromTheLeft;
	//cerr << " -> " << best << endl;
}
inline void Factor::BestFrom (const Factor &left, const Factor &above) {
	//cerr << "BestFrom(" << left << ", " << above << ")";
	bool fromAbove = above.best < left.best;
	//cerr << ": fromAbove = " << fromAbove << endl;
	BestFrom ((fromAbove ? above : left), fromAbove);
}
template<unsigned N> struct FactorMaker : public Factor {
	inline FactorMaker (unsigned &value) : Factor(value, N, Garbage) { }
};

struct State {
	unsigned size, best;
	vector<unsigned> cells;
	vector<Factor> twos, fives;
	string path;
	State () : size(0), best(uMax) { }
	istream &Read (istream &is) {
		is >> size;
		cells.reserve(size * size);
		for (unsigned value, r = 0; r < size; ++r) {
			for (unsigned c = 0; c < size; ++c) {
				is >> value;
				cells.emplace_back(value);
				twos.emplace_back( FactorMaker<2> { value } );
				fives.emplace_back( FactorMaker<5> { value } );
			}
		}
		Fill (twos);
		Fill (fives);
		path.resize(2 * (size - 1));
		vector<Factor> &bestFactor = fives.back().best < twos.back().best ? fives : twos;
		best = bestFactor.back().best;
		if ( best > 1 && FindZeroPath() )
			best = 1;
		else
			MakePath(bestFactor);
		return is;
	}
	void Fill (vector<Factor> &factors) {
		//Print (cerr, factors);
		Factor *fi = factors.data(), *prevRow = fi, *prevCol = fi;
		//cerr << "top row, fill from the left" << endl;
		for ( unsigned c = 1 ; c < size; ++c )
			(++fi)->BestFrom(*prevCol++, false);
		//cerr << "then the rest of the rows, ..." << endl;
		for ( unsigned r = 1; r < size; ++r ) {
			//cerr << "row " << r << endl;
			//cerr << "first column" << endl;
			(++fi)->BestFrom(*prevRow++, true);
			++prevCol;
			//cerr << "then the rest of the columns" << endl;
			for ( unsigned c = 0; ++c < size; ) {
				//cerr << "column " << c << endl;
				(++fi)->BestFrom(*prevCol++, *prevRow++);
			}
		}
		//Print (cerr, factors);
	}
	void Print (ostream &os, vector<Factor> &f) {
		auto fi = f.data();
		for (unsigned x = 0; x < size; ++x) {
			for (unsigned y = 0; y < size; ++y) {
				os << '\t' << *fi++;
			}
			os << endl;
		}
	}
	void MakePath (vector<Factor> &bestFactor) {
		auto fi = bestFactor.end() - 1;
		auto sp = path.end();
		while (fi != bestFactor.begin()) {
			*--sp = "XRD"[fi->direction];
			fi -= ( fi->direction == FromAbove ? size : 1 );
		}
	}
	bool FindZeroPath () {
		for ( unsigned n = 0; n < cells.size(); ++n ) {
			if ( cells[n] == 0 ) {
				unsigned /* x = n % size, */ y = n / size;
				fill_n( fill_n( fill_n( path.begin(), y, 'D' ), size, 'R' ), size - y, 'D' );
				return true;
			}
		}
		return false;
	}
	ostream &Write (ostream &os) {
		return os << best << endl << path << endl;
	}
};
inline istream &operator>> (istream &is, State &s) { return s.Read(is); }
inline ostream &operator<< (ostream &os, State &s) { return s.Write(os); }

int
main ()
{
	// apparently this may speed it up
	ios::sync_with_stdio(false);
	cout.setf(ios::boolalpha);
	cerr.setf(ios::boolalpha);

	State state;
	cin >> state;
	cout << state;

	return EXIT_SUCCESS;
}


#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdlib>

using namespace ::std;

typedef vector<bool> Path;
ostream &operator<< (ostream &os, Path &p) {
	for (auto direction : p)
		os << "DR"[direction];
	return os;
}

struct Cell {
	unsigned n, twos, fives;
	Cell (int _n) : n(_n), twos(0), fives(0) {
//		cerr << "Cell(" << _n << ")" << endl;
		while (_n && !(_n & 1))
			++twos, _n /= 2;
		while (_n & !(_n % 5))
			++fives, _n /= 5;
//		cerr << "Cell { " << n << ", " << twos << ", " << fives << "}" << endl;
	}
};

typedef vector<Cell> Row;
typedef vector<Row> Grid;

struct SearchState { unsigned x, y, twos, fives; };
ostream &operator<< (ostream &os, const SearchState &ss) {
	return os << "{ " << ss.x << ", " << ss.y << ", " << ss.twos << ", " << ss.fives << " }";
}

struct State {
	unsigned size, lwm;
	Grid cells;
	Path path, bestPath;
	State () : size(0), lwm(0) { }
	istream &Read (istream &is) {
		is >> size;
		cells.reserve(size);
		for (unsigned value, r = 0; r < size; ++r) {
			cells.emplace_back();
			Row &row = cells.back();
			row.reserve(size);
			for (unsigned c = 0; c < size; ++c) {
				is >> value, row.emplace_back(value);
			}
		}
		return is;
	}
	void Search (SearchState s, bool direction) {
		cerr << "state = " << s << ", direction = " << "DR"[direction] << endl;
		if ( ( direction ? ++s.x : ++s.y ) >= size )
			return;
		path.push_back(direction);
		Search (s);
		path.pop_back();
	}
	void Search (SearchState &s) {
		Cell &cell = cells[s.y][s.x];
		unsigned tens = min( (s.twos += cell.twos), (s.fives += cell.fives) );
		cerr << "state = " << s << ", tens = " << tens << ", path = " << path << endl;
		if ( tens >= lwm )
			return;
		else if ( s.x == size - 1 && s.x == s.y ) {
			lwm = tens;
			bestPath = path;
			cerr << "lwm = " << lwm << ", path = " << path << endl;
		} else {
//			bool acrossFirst = s.y >= s.x;
//			Search(s, acrossFirst);
//			Search(s, !acrossFirst);
			Search(s, false);
			Search(s, true);
		}
	}
	void Search () {
		lwm = numeric_limits<unsigned>::max();
		bestPath.clear();
		path.clear();
		path.reserve( 2 * (size - 1) );
		SearchState state { 0, 0, 0, 0 };
		Search(state);
		cout << lwm << endl << bestPath << endl;
	}
};
inline istream &operator>> (istream &is, State &s) { return s.Read(is); }

int
main ()
{
	// apparently this may speed it up
	ios_base::sync_with_stdio(false);

	State state;
	cin >> state;
	state.Search();

	return EXIT_SUCCESS;
}


#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <memory>
#include <cstdlib>

using namespace ::std;

unsigned uMax = numeric_limits<unsigned>::max();

enum Direction { Garbage, Across, FromTheLeft = Across, Down, FromAbove = Down };
inline ostream &operator<< (ostream &os, const Direction &d) { return os << "XRD"[d]; }

struct Factor {
	unsigned best;
	Direction direction;
	Factor ( unsigned &value, unsigned factor, Direction __d = Garbage )
		: best(0), direction(__d)
	{
		//cerr << "value = " << value;
		while (value && !(value % factor))
			++best, value /= factor;
		//cerr << ", best = " << best << ", value = " << value << endl;
	}
	void BestFrom (const Factor &other, bool fromAbove);
	void BestFrom (const Factor &left, const Factor &above);
	ostream &Print(ostream &os) const {
		return os << "{ " << best << ", " << direction << " }";
	}
};
ostream &operator<< (ostream &os, const Factor &f) { return f.Print(os); }
void Factor::BestFrom (const Factor &other, bool fromAbove) {
	//cerr << "BestFrom(" << other << ", " << fromAbove << "), best " << best;
	best += other.best;
	direction = fromAbove ? FromAbove : FromTheLeft;
	//cerr << " -> " << best << endl;
}
void Factor::BestFrom (const Factor &left, const Factor &above) {
	//cerr << "BestFrom(" << left << ", " << above << ")";
	bool fromAbove = above.best < left.best;
	//cerr << ": fromAbove = " << fromAbove << endl;
	BestFrom ((fromAbove ? above : left), fromAbove);
}
template<unsigned N> struct FactorMaker : public Factor {
	FactorMaker (unsigned &value) : Factor(value, N, Garbage) { }
};

struct State {
	unsigned size, best;
	vector<unsigned> cells;
	vector<Factor> twos, fives;
	string path;
	State () : size(0), best(uMax) { }
	istream &Read (istream &is) {
		is >> size;
		cells.reserve(size * size);
		for (unsigned value, r = 0; r < size; ++r) {
			for (unsigned c = 0; c < size; ++c) {
				is >> value;
				cells.emplace_back(value);
				twos.emplace_back( FactorMaker<2> { value } );
				fives.emplace_back( FactorMaker<5> { value } );
			}
		}
		Fill (twos);
		Fill (fives);
		path.resize(2 * (size - 1));
		vector<Factor> &bestFactor = fives.back().best < twos.back().best ? fives : twos;
		best = bestFactor.back().best;
		if ( best > 1 && FindZeroPath() )
			best = 1;
		else
			MakePath(bestFactor);
		return is;
	}
	void Fill (vector<Factor> &factors) {
		//Print (cerr, factors);
		Factor *fi = factors.data(), *prevRow = fi, *prevCol = fi;
		//cerr << "top row, fill from the left" << endl;
		for ( unsigned c = 1 ; c < size; ++c )
			(++fi)->BestFrom(*prevCol++, false);
		//cerr << "then the rest of the rows, ..." << endl;
		for ( unsigned r = 1; r < size; ++r ) {
			//cerr << "row " << r << endl;
			//cerr << "first column" << endl;
			(++fi)->BestFrom(*prevRow++, true);
			++prevCol;
			//cerr << "then the rest of the columns" << endl;
			for ( unsigned c = 0; ++c < size; ) {
				//cerr << "column " << c << endl;
				(++fi)->BestFrom(*prevCol++, *prevRow++);
			}
		}
		//Print (cerr, factors);
	}
	void Print (ostream &os, vector<Factor> &f) {
		auto fi = f.data();
		for (unsigned x = 0; x < size; ++x) {
			for (unsigned y = 0; y < size; ++y) {
				os << '\t' << *fi++;
			}
			os << endl;
		}
	}
	void MakePath (vector<Factor> &bestFactor) {
		auto fi = bestFactor.end() - 1;
		auto sp = path.end();
		while (fi != bestFactor.begin()) {
			*--sp = "XRD"[fi->direction];
			fi -= ( fi->direction == FromAbove ? size : 1 );
		}
	}
	bool FindZeroPath () {
		for ( unsigned n = 0; n < cells.size(); ++n ) {
			if ( cells[n] == 0 ) {
				unsigned /* x = n % size, */ y = n / size;
				fill_n( fill_n( fill_n( path.begin(), y, 'D' ), size, 'R' ), size - y, 'D' );
				return true;
			}
		}
		return false;
	}
	ostream &Write (ostream &os) {
		return os << best << endl << path << endl;
	}
};
inline istream &operator>> (istream &is, State &s) { return s.Read(is); }
inline ostream &operator<< (ostream &os, State &s) { return s.Write(os); }

int
main ()
{
	// apparently this may speed it up
	ios::sync_with_stdio(false);
	cout.setf(ios::boolalpha);
	cerr.setf(ios::boolalpha);

	State state;
	cin >> state;
	cout << state;

	return EXIT_SUCCESS;
}


#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdlib>

using namespace ::std;

typedef vector<bool> Path;
ostream &operator<< (ostream &os, Path &p) {
	for (auto direction : p)
		os << "DR"[direction];
	return os;
}

struct Cell {
	unsigned n, twos, fives;
	Cell (int _n) : n(_n), twos(0), fives(0) {
//		cerr << "Cell(" << _n << ")" << endl;
		while (_n && !(_n & 1))
			++twos, _n /= 2;
		while (_n & !(_n % 5))
			++fives, _n /= 5;
//		cerr << "Cell { " << n << ", " << twos << ", " << fives << "}" << endl;
	}
};

typedef vector<Cell> Row;
typedef vector<Row> Grid;

struct SearchState { unsigned x, y, twos, fives; };
ostream &operator<< (ostream &os, const SearchState &ss) {
	return os << "{ " << ss.x << ", " << ss.y << ", " << ss.twos << ", " << ss.fives << " }";
}

struct State {
	unsigned size, lwm;
	Grid cells;
	Path path, bestPath;
	State () : size(0), lwm(0) { }
	istream &Read (istream &is) {
		is >> size;
		cells.reserve(size);
		for (unsigned value, r = 0; r < size; ++r) {
			cells.emplace_back();
			Row &row = cells.back();
			row.reserve(size);
			for (unsigned c = 0; c < size; ++c) {
				is >> value, row.emplace_back(value);
			}
		}
		return is;
	}
	void Search (SearchState s, bool direction) {
		//cerr << "state = " << s << ", direction = " << "DR"[direction] << endl;
		if ( ( direction ? ++s.x : ++s.y ) >= size )
			return;
		path.push_back(direction);
		Search (s);
		path.pop_back();
	}
	void Search (SearchState &s) {
		Cell &cell = cells[s.y][s.x];
		unsigned tens = min( (s.twos += cell.twos), (s.fives += cell.fives) );
		//cerr << "state = " << s << ", tens = " << tens << ", path = " << path << endl;
		if ( tens >= lwm )
			return;
		else if ( s.x == size - 1 && s.x == s.y ) {
			lwm = tens;
			bestPath = path;
			//cerr << "lwm = " << lwm << ", path = " << path << endl;
		} else {
//			bool acrossFirst = s.y >= s.x;
//			Search(s, acrossFirst);
//			Search(s, !acrossFirst);
			Search(s, false);
			Search(s, true);
		}
	}
	void Search () {
		lwm = numeric_limits<unsigned>::max();
		bestPath.clear();
		path.clear();
		path.reserve( 2 * (size - 1) );
		SearchState state { 0, 0, 0, 0 };
		Search(state);
		cout << lwm << endl << bestPath << endl;
	}
};
inline istream &operator>> (istream &is, State &s) { return s.Read(is); }

int
main ()
{
	// apparently this may speed it up
	ios_base::sync_with_stdio(false);

	State state;
	cin >> state;
	state.Search();

	return EXIT_SUCCESS;
}


#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdlib>

using namespace ::std;

typedef vector<bool> Path;
ostream &operator<< (ostream &os, Path &p) {
	for (auto direction : p)
		os << "DR"[direction];
	return os;
}

struct Cell {
	unsigned n, twos, fives;
	Cell (int _n) : n(_n), twos(0), fives(0) {
//		cerr << "Cell(" << _n << ")" << endl;
		while (_n && !(_n & 1))
			++twos, _n /= 2;
		while (_n & !(_n % 5))
			++fives, _n /= 5;
//		cerr << "Cell { " << n << ", " << twos << ", " << fives << "}" << endl;
	}
};

typedef vector<Cell> Row;
typedef vector<Row> Grid;

struct SearchState { unsigned x, y, twos, fives; };
ostream &operator<< (ostream &os, const SearchState &ss) {
	return os << "{ " << ss.x << ", " << ss.y << ", " << ss.twos << ", " << ss.fives << " }";
}

struct State {
	unsigned size, lwm;
	Grid cells;
	Path path, bestPath;
	State () : size(0), lwm(0) { }
	istream &Read (istream &is) {
		is >> size;
		cells.reserve(size);
		for (unsigned value, r = 0; r < size; ++r) {
			cells.emplace_back();
			Row &row = cells.back();
			row.reserve(size);
			for (unsigned c = 0; c < size; ++c) {
				is >> value, row.emplace_back(value);
			}
		}
		return is;
	}
	void Search (SearchState s, bool direction) {
		cerr << "state = " << s << ", direction = " << "DR"[direction] << endl;
		if ( ( direction ? ++s.x : ++s.y ) >= size )
			return;
		path.push_back(direction);
		Search (s);
		path.pop_back();
	}
	void Search (SearchState &s) {
		Cell &cell = cells[s.y][s.x];
		unsigned tens = min( (s.twos += cell.twos), (s.fives += cell.fives) );
		cerr << "state = " << s << ", tens = " << tens << ", path = " << path << endl;
		if ( tens >= lwm )
			return;
		else if ( s.x == size - 1 && s.x == s.y ) {
			lwm = tens;
			bestPath = path;
			cerr << "lwm = " << lwm << ", path = " << path << endl;
		} else {
			bool acrossFirst = s.y >= s.x;
			Search(s, acrossFirst);
			Search(s, !acrossFirst);
		}
	}
	void Search () {
		lwm = numeric_limits<unsigned>::max();
		bestPath.clear();
		path.clear();
		path.reserve( 2 * (size - 1) );
		SearchState state { 0, 0, 0, 0 };
		Search(state);
		cout << lwm << endl << bestPath << endl;
	}
};
inline istream &operator>> (istream &is, State &s) { return s.Read(is); }

int
main ()
{
	// apparently this may speed it up
	ios_base::sync_with_stdio(false);

	State state;
	cin >> state;
	state.Search();

	return EXIT_SUCCESS;
}


#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <memory>
#include <cstdlib>

using namespace ::std;

unsigned uMax = numeric_limits<unsigned>::max();

struct Factor {
	unsigned best;
	bool direction;
	inline Factor ( unsigned &value, unsigned factor, bool __d = false )
		: best(0), direction(__d)
	{
		while (value && !(value % factor))
			++best, value /= factor;
	}
	void BestFrom (const Factor &other, bool fromAbove) {
		best += other.best;
		direction = fromAbove;
	}
	void BestFrom (const Factor &left, const Factor &above) {
		bool fromAbove = above.best < left.best;
		BestFrom (fromAbove ? above : left, fromAbove);
	}
	ostream &Print(ostream &os) const {
		return os << "{ " << best << ", " << "DR"[direction] << " }";
	}
};
inline ostream &operator<< (ostream &os, const Factor &f) { return f.Print(os); }
template<unsigned N> struct FactorMaker : public Factor {
	FactorMaker (unsigned &value) : Factor(value, N, false) { }
};

struct State {
	unsigned size, best;
	vector<unsigned> cells;
	vector<Factor> twos, fives;
	string path;
	State () : size(0), best(uMax) { }
	istream &Read (istream &is) {
		is >> size;
		cells.reserve(size * size);
		for (unsigned value, r = 0; r < size; ++r) {
			for (unsigned c = 0; c < size; ++c) {
				is >> value;
				cells.emplace_back(value);
				twos.emplace_back( FactorMaker<2> { value } );
				fives.emplace_back( FactorMaker<5> { value } );
			}
		}
		Fill (twos);
		Fill (fives);
		path.resize(2 * (size - 1));
		vector<Factor> &bestFactor = fives.back().best < twos.back().best ? fives : twos;
		best = bestFactor.back().best;
		if ( best > 1 && FindZeroPath() )
			best = 1;
		else
			MakePath(bestFactor);
		return is;
	}
	void Fill (vector<Factor> &factors) {
		Factor *fi = factors.data(), *prevRow = fi, *prevCol = prevRow;
		// top row, resetting the iterator ...
		for ( unsigned c = 1 ; c < size; ++c )
			(++fi)->BestFrom(*prevCol++, false);
		for ( unsigned r = 1; r < size; ++r ) {
			(++fi)->BestFrom(*prevRow++, true);
			for ( unsigned c = 0; ++c < size; )
				(++fi)->BestFrom(*++prevCol, *prevRow++);
		}
	}
	void MakePath (vector<Factor> &bestFactor) {
		auto fi = bestFactor.end() - 1;
		auto sp = path.end();
		while (fi != bestFactor.begin()) {
			*--sp = "RD"[fi->direction];
			fi -= fi->direction ? size : 1;
		}
	}
	bool FindZeroPath () {
		for ( unsigned n = 0; n < cells.size(); ++n )
			if ( cells[n] == 0 ) {
				cerr << "zero path found" << endl;
				unsigned /* x = n % size, */ y = n / size;
				fill_n( fill_n( fill_n( path.begin(), y, 'D' ), size, 'R' ), size - y, 'D' );
				return true;
			}
		return false;
	}
	ostream &Write (ostream &os) {
		return os << best << endl << path << endl;
	}
};
inline istream &operator>> (istream &is, State &s) { return s.Read(is); }
inline ostream &operator<< (ostream &os, State &s) { return s.Write(os); }

int
main ()
{
	// apparently this may speed it up
	ios::sync_with_stdio(false);

	State state;
	cin >> state;
	cout << state;

	return EXIT_SUCCESS;
}


#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <memory>
#include <cstdlib>

using namespace ::std;

unsigned uMax = numeric_limits<unsigned>::max();

struct Factor {
	unsigned best;
	bool direction;
	inline Factor ( unsigned &value, unsigned factor, bool __d = false )
		: best(0), direction(__d)
	{
		while (value && !(value % factor))
			++best, value /= factor;
	}
	void BestFrom (const Factor &other, bool fromAbove) {
		best += other.best;
		direction = fromAbove;
	}
	void BestFrom (const Factor &left, const Factor &above) {
		bool fromAbove = above.best < left.best;
		BestFrom (fromAbove ? above : left, fromAbove);
	}
	ostream &Print(ostream &os) const {
		return os << "{ " << best << ", " << "DR"[direction] << " }";
	}
};
inline ostream &operator<< (ostream &os, const Factor &f) { return f.Print(os); }
template<unsigned N> struct FactorMaker : public Factor {
	FactorMaker (unsigned &value) : Factor(value, N, false) { }
};

struct State {
	unsigned size, best;
	vector<unsigned> cells;
	vector<Factor> twos, fives;
	string path;
	State () : size(0), best(uMax) { }
	istream &Read (istream &is) {
		is >> size;
		cells.reserve(size * size);
		for (unsigned value, r = 0; r < size; ++r) {
			for (unsigned c = 0; c < size; ++c) {
				is >> value;
				cells.emplace_back(value);
				twos.emplace_back( FactorMaker<2> { value } );
				fives.emplace_back( FactorMaker<5> { value } );
			}
		}
		Fill (twos);
		Fill (fives);
		path.resize(2 * (size - 1));
		vector<Factor> &bestFactor = twos.back().best < fives.back().best ? twos : fives;
		best = bestFactor.back().best;
		if ( best > 1 && FindZeroPath() )
			best = 1;
		else
			MakePath(bestFactor);
		return is;
	}
	void Fill (vector<Factor> &factors) {
		Factor *fi = factors.data(), *prevRow = fi, *prevCol = prevRow;
		// top row, resetting the iterator ...
		for ( unsigned c = 1 ; c < size; ++c )
			(++fi)->BestFrom(*prevCol++, false);
		for ( unsigned r = 1; r < size; ++r ) {
			(++fi)->BestFrom(*prevRow++, true);
			for ( unsigned c = 0; ++c < size; )
				(++fi)->BestFrom(*++prevCol, *prevRow++);
		}
	}
	void MakePath (vector<Factor> &bestFactor) {
		auto fi = bestFactor.end() - 1;
		auto sp = path.end();
		while (fi != bestFactor.begin()) {
			*--sp = "RD"[fi->direction];
			fi -= fi->direction ? size : 1;
		}
	}
	bool FindZeroPath () {
		for ( unsigned n = 0; n < cells.size(); ++n )
			if ( !cells[n] ) {
				unsigned /* x = n % size, */ y = n / size;
				fill_n( fill_n( fill_n( path.begin(), y, 'D' ), size, 'R' ), size - y, 'D' );
				return true;
			}
		return false;
	}
	ostream &Write (ostream &os) {
		return os << best << endl << path << endl;
	}
};
inline istream &operator>> (istream &is, State &s) { return s.Read(is); }
inline ostream &operator<< (ostream &os, State &s) { return s.Write(os); }

int
main ()
{
	// apparently this may speed it up
	ios::sync_with_stdio(false);

	State state;
	cin >> state;
	cout << state;

	return EXIT_SUCCESS;
}


#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <memory>
#include <cstdlib>

using namespace ::std;

unsigned uMax = numeric_limits<unsigned>::max();

enum Direction { Garbage, Across, FromTheLeft = Across, Down, FromAbove = Down };
inline ostream &operator<< (ostream &os, const Direction &d) { return os << "XRD"[d]; }

struct Factor {
	unsigned best;
	Direction direction;
	inline Factor ( unsigned &value, unsigned factor, Direction __d = Garbage )
		: best(0), direction(__d)
	{
		//cerr << "value = " << value;
		while (value && !(value % factor))
			++best, value /= factor;
		//cerr << ", best = " << best << ", value = " << value << endl;
	}
	void BestFrom (const Factor &other, Direction fromAbove);
	void BestFrom (const Factor &left, const Factor &above);
	ostream &Print(ostream &os) const {
		return os << "{ " << best << ", " << direction << " }";
	}
};
inline ostream &operator<< (ostream &os, const Factor &f) { return f.Print(os); }
inline void Factor::BestFrom (const Factor &other, Direction fromAbove) {
	//cerr << "BestFrom(" << other << ", " << fromAbove << "), best " << best;
	best += other.best;
	direction = fromAbove;
	//cerr << " -> " << best << endl;
}
inline void Factor::BestFrom (const Factor &left, const Factor &above) {
	//cerr << "BestFrom(" << left << ", " << above << ")";
	Direction fromAbove = above.best < left.best ? FromAbove : FromTheLeft;
	//cerr << ": fromAbove = " << fromAbove << endl;
	BestFrom (fromAbove ? above : left, fromAbove);
}
template<unsigned N> struct FactorMaker : public Factor {
	FactorMaker (unsigned &value) : Factor(value, N, Garbage) { }
};

struct State {
	unsigned size, best;
	vector<unsigned> cells;
	vector<Factor> twos, fives;
	string path;
	State () : size(0), best(uMax) { }
	istream &Read (istream &is) {
		is >> size;
		cells.reserve(size * size);
		for (unsigned value, r = 0; r < size; ++r) {
			for (unsigned c = 0; c < size; ++c) {
				is >> value;
				cells.emplace_back(value);
				twos.emplace_back( FactorMaker<2> { value } );
				fives.emplace_back( FactorMaker<5> { value } );
			}
		}
		Fill (twos);
		Fill (fives);
		path.resize(2 * (size - 1));
		vector<Factor> &bestFactor = fives.back().best < twos.back().best ? fives : twos;
		best = bestFactor.back().best;
		if ( best > 1 && FindZeroPath() )
			best = 1;
		else
			MakePath(bestFactor);
		return is;
	}
	void Fill (vector<Factor> &factors) {
		Factor *fi = factors.data(), *prevRow = fi, *prevCol = prevRow;
		// top row, resetting the iterator ...
		//cerr << "top row, fill from the left" << endl;
		for ( unsigned c = 1 ; c < size; ++c )
			(++fi)->BestFrom(*prevCol++, FromTheLeft);
		//cerr << "then the rest of the rows, ..." << endl;
		for ( unsigned r = 1; r < size; ++r ) {
			//cerr << "row " << r << endl;
			//cerr << "first column" << endl;
			(++fi)->BestFrom(*prevRow++, FromAbove);
			++prevCol;
			//cerr << "then the rest of the columns" << endl;
			for ( unsigned c = 0; ++c < size; ) {
				//cerr << "column " << c << endl;
				(++fi)->BestFrom(*++prevCol, *prevRow++);
			}
		}
		//Print (cerr, factors);
	}
	void Print (ostream &os, vector<Factor> &f) {
		auto fi = f.data();
		for (unsigned x = 0; x < size; ++x) {
			for (unsigned y = 0; y < size; ++y) {
				os << '\t' << *fi++;
			}
			os << endl;
		}
	}
	void MakePath (vector<Factor> &bestFactor) {
		auto fi = bestFactor.end() - 1;
		auto sp = path.end();
		while (fi != bestFactor.begin()) {
			*--sp = "XRD"[fi->direction];
			fi -= ( fi->direction == FromAbove ? size : 1 );
		}
	}
	bool FindZeroPath () {
		for ( unsigned n = 0; n < cells.size(); ++n ) {
			if ( cells[n] == 0 ) {
				unsigned /* x = n % size, */ y = n / size;
				fill_n( fill_n( fill_n( path.begin(), y, 'D' ), size, 'R' ), size - y, 'D' );
				return true;
			}
		}
		return false;
	}
	ostream &Write (ostream &os) {
		return os << best << endl << path << endl;
	}
};
inline istream &operator>> (istream &is, State &s) { return s.Read(is); }
inline ostream &operator<< (ostream &os, State &s) { return s.Write(os); }

int
main ()
{
	// apparently this may speed it up
	ios::sync_with_stdio(false);
	cout.setf(ios::boolalpha);
	cerr.setf(ios::boolalpha);

	State state;
	cin >> state;
	cout << state;

	return EXIT_SUCCESS;
}


#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <memory>
#include <cstdlib>

using namespace ::std;

unsigned uMax = numeric_limits<unsigned>::max();

struct Factor {
	unsigned best;
	bool direction;
	inline Factor ( unsigned &value, unsigned factor, bool __d = false )
		: best(0), direction(__d)
	{
		while (value && !(value % factor))
			++best, value /= factor;
	}
	void BestFrom (const Factor &other, bool fromAbove) {
		best += other.best;
		direction = fromAbove;
	}
	void BestFrom (const Factor &left, const Factor &above) {
		bool fromAbove = above.best < left.best;
		BestFrom (fromAbove ? above : left, fromAbove);
	}
	ostream &Print(ostream &os) const {
		return os << "{ " << best << ", " << "DR"[direction] << " }";
	}
};
inline ostream &operator<< (ostream &os, const Factor &f) { return f.Print(os); }
template<unsigned N> struct FactorMaker : public Factor {
	FactorMaker (unsigned &value) : Factor(value, N, false) { }
};

struct State {
	unsigned size;
	vector<unsigned> cells;
	vector<Factor> twos, fives;
	State () : size(0) { }
	istream &Read (istream &is) {
		is >> size;
		cells.reserve(size * size);
		for (unsigned value, r = 0; r < size; ++r) {
			for (unsigned c = 0; c < size; ++c) {
				is >> value;
				cells.emplace_back(value);
				twos.emplace_back( FactorMaker<2> { value } );
				fives.emplace_back( FactorMaker<5> { value } );
			}
		}
		Fill (twos);
		Fill (fives);
		return is;
	}
	void Fill (vector<Factor> &factors) {
		Factor *fi = factors.data(), *prevRow = fi, *prevCol = prevRow;
		// top row, resetting the iterator ...
		for ( unsigned c = 1 ; c < size; ++c )
			(++fi)->BestFrom(*prevCol++, false);
		for ( unsigned r = 1; r < size; ++r ) {
			(++fi)->BestFrom(*prevRow++, true);
			for ( unsigned c = 0; ++c < size; )
				(++fi)->BestFrom(*++prevCol, *prevRow++);
		}
	}
	ostream &PrintResult (ostream &os, vector<Factor> &factors) {
		string s;
		auto fi = factors.end() - 1;
		while (fi != factors.begin()) {
			s += "RD"[fi->direction];
			fi -= fi->direction ? size : 1;
		}
		reverse (s.begin(), s.end());
		return os << s << endl;
	}
	ostream &Write (ostream &os) {
		return PrintResult (os, twos.back().best < fives.back().best ? twos : fives);
	}
};
inline istream &operator>> (istream &is, State &s) { return s.Read(is); }
inline ostream &operator<< (ostream &os, State &s) { return s.Write(os); }

int
main ()
{
	// apparently this may speed it up
	ios::sync_with_stdio(false);

	State state;
	cin >> state;
	cout << state;

	return EXIT_SUCCESS;
}


#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdlib>

using namespace ::std;

typedef vector<bool> Path;
ostream &operator<< (ostream &os, Path &p) {
	for (auto direction : p)
		os << "DR"[direction];
	return os;
}

struct Cell {
	unsigned n, twos, fives;
	Cell (int _n) : n(_n), twos(0), fives(0) {
//		cerr << "Cell(" << _n << ")" << endl;
		while (_n && !(_n & 1))
			++twos, _n /= 2;
		while (_n & !(_n % 5))
			++fives, _n /= 5;
//		cerr << "Cell { " << n << ", " << twos << ", " << fives << "}" << endl;
	}
};

typedef vector<Cell> Row;
typedef vector<Row> Grid;

struct SearchState { unsigned x, y, twos, fives; };
ostream &operator<< (ostream &os, const SearchState &ss) {
	return os << "{ " << ss.x << ", " << ss.y << ", " << ss.twos << ", " << ss.fives << " }";
}

struct State {
	unsigned size, lwm;
	Grid cells;
	Path path, bestPath;
	State () : size(0), lwm(0) { }
	istream &Read (istream &is) {
		is >> size;
		cells.reserve(size);
		for (unsigned value, r = 0; r < size; ++r) {
			cells.emplace_back();
			Row &row = cells.back();
			row.reserve(size);
			for (unsigned c = 0; c < size; ++c) {
				is >> value, row.emplace_back(value);
			}
		}
		return is;
	}
	void Search (SearchState s, bool direction) {
		cerr << "state = " << s << ", direction = " << "DR"[direction] << endl;
		if ( ( direction ? ++s.x : ++s.y ) >= size )
			return;
		path.push_back(direction);
		Search (s);
		path.pop_back();
	}
	void Search (SearchState &s) {
		Cell &cell = cells[s.x][s.y];
		unsigned tens = min( (s.twos += cell.twos), (s.fives += cell.fives) );
		cerr << "state = " << s << ", tens = " << tens << ", path = " << path << endl;
		if ( tens >= lwm )
			return;
		else if ( s.x == size - 1 && s.x == s.y ) {
			lwm = tens;
			bestPath = path;
			cerr << "lwm = " << lwm << ", path = " << path << endl;
		} else {
			bool acrossFirst = s.y >= s.x;
			Search(s, acrossFirst);
			Search(s, !acrossFirst);
		}
	}
	void Search () {
		lwm = numeric_limits<unsigned>::max();
		bestPath.clear();
		path.clear();
		path.reserve( 2 * (size - 1) );
		SearchState state { 0, 0, 0, 0 };
		Search(state);
		cout << bestPath << endl;
	}
};
inline istream &operator>> (istream &is, State &s) { return s.Read(is); }

int
main ()
{
	// apparently this may speed it up
	ios_base::sync_with_stdio(false);

	State state;
	cin >> state;
	state.Search();

	return EXIT_SUCCESS;
}


#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 == 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>

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

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][2];
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;
    }

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

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

    // printf(" is %d\n", 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[x][y]);
        }
        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");
    }
}

bool lessWeight(int weightFromTop[2], int weightFromLeft[2], int weight2, int weight5) {
    int weight2FromTop  = weight2 + weightFromTop[WEIGHT2];
    int weight5FromTop  = weight5 + weightFromTop[WEIGHT5];
    int weight2FromLeft = weight2 + weightFromLeft[WEIGHT2];
    int weight5FromLeft = weight5 + weightFromLeft[WEIGHT5];
    int minWeightFromTop  = std::min(weight2FromTop, weight5FromTop);
    int minWeightFromLeft = std::min(weight2FromLeft, weight5FromLeft);

    if (minWeightFromTop == minWeightFromLeft) {
        return std::max(weight2FromTop, weight5FromTop) < std::max(weight2FromLeft, weight5FromLeft);
    }

    return minWeightFromTop < minWeightFromLeft;
}

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

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

            int weight2 = getDividersCount(matrix[x][y], 2);
            int weight5 = getDividersCount(matrix[x][y], 5);
            char direction = ' ';
            if (x == 0) {
                weight2 += matrixWeight[x][y-1][WEIGHT2];
                weight5 += matrixWeight[x][y-1][WEIGHT5];
                direction = 'D';
            } else if (y == 0) {
                weight2 += matrixWeight[x-1][y][WEIGHT2];
                weight5 += matrixWeight[x-1][y][WEIGHT5];
                direction = 'R';
            } else {
                int weight2FromTop  = weight2 + matrixWeight[x][y-1][WEIGHT2];
                int weight5FromTop  = weight5 + matrixWeight[x][y-1][WEIGHT5];
                int weight2FromLeft = weight2 + matrixWeight[x-1][y][WEIGHT2];
                int weight5FromLeft = weight5 + matrixWeight[x-1][y][WEIGHT5];
                // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                if (lessWeight(matrixWeight[x][y-1], matrixWeight[x-1][y], weight2, weight5)) {
                    weight2 = weight2FromTop;
                    weight5 = weight5FromTop;
                    direction = 'D';
                } else {
                    weight2 = weight2FromLeft;
                    weight5 = weight5FromLeft;
                    direction = 'R';
                }
            }

            matrixWeight[x][y][WEIGHT2] = weight2;
            matrixWeight[x][y][WEIGHT5] = weight5;
            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);
    std::string path = getPath(matrixSize, matrixSize);

    // printMatrixWeight(matrixWeight, matrixSize, matrixSize);

    printf("%d\n", std::min(matrixWeight[matrixSize-1][matrixSize-1][WEIGHT2],
                            matrixWeight[matrixSize-1][matrixSize-1][WEIGHT5]));
    printf("%s\n", path.c_str());

}


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

#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];
bool matrixZero[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");
}

template<typename T>
void printCumulativeMatrixWeight(T 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]);
            std::cout << std::setw(3) << 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) {

            bool isZero = matrix[x][y] == 0;

            if (isZero) {
                matrixWeight[x][y][WEIGHT2] = 1;
                matrixWeight[x][y][WEIGHT5] = 1;
            } else {
                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];
                matrixZero[x][y][WEIGHT2] = isZero;
                matrixZero[x][y][WEIGHT5] = isZero;
                matrixDir[x][y][WEIGHT2] = ' ';
                matrixDir[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) {
                    if (isZero || matrixZero[x][y-1][i]) {
                        weight = 1;
                        matrixZero[x][y][i] = 1;
                    } else {
                        weight += matrixCumulativeWeight[x][y-1][i];
                    }
                    direction = 'D';
                } else if (y == 0) {
                    if (isZero || matrixZero[x-1][y][i]){
                        weight = 1;
                        matrixZero[x][y][i] = 1;
                    } else {
                        weight += matrixCumulativeWeight[x-1][y][i];
                    }
                    direction = 'R';
                } else {
                    int weightFromTop = 0;
                    if (isZero || matrixZero[x][y-1][i]){
                        weightFromTop = 1;
                    } else {
                        weightFromTop = weight + matrixCumulativeWeight[x][y-1][i];
                    }

                    int weightFromLeft = 0;
                    if (isZero || matrixZero[x-1][y][i]) {
                        weightFromLeft = 1;
                    } else {
                        weightFromLeft = weight + matrixCumulativeWeight[x-1][y][i];
                    }
                    // printf("weight: %d, weightFromLeft: %d, weightFromTop: %d\n", weight, weightFromLeft, weightFromTop);
                    if (weightFromTop < weightFromLeft) {
                        weight = weightFromTop;
                        matrixZero[x][y][i] = isZero || matrixZero[x][y-1][i];
                        direction = 'D';
                    } else {
                        weight = weightFromLeft;
                        matrixZero[x][y][i] = isZero || matrixZero[x-1][y][i];
                        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;
    bool zero = false;
    while (x != 0 || y != 0) {
        // printf("%d, %d, %c\n", x,y,matrixDir[x][y][type]);
        path = matrixDir[x][y][type] + path;
        zero |= matrix[x][y] == 0;
        if (zero) {
            minWeight = 1;
        } else {
            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;
// }

// std::string buildPathVia(int viaX, int viaY, int width, int height) {
//     int x = 0;
//     int y = 0;
//     std::string path;
//     while (y++ < viaY) {
//         path += 'D';
//     }
//     while (x++ < viaX) {
//         path += 'R';
//     }
//     while (y++ < height) {
//         path += 'D';
//     }
//     while (x++ < width) {
//         path += 'R';
//     }
//     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]);
            // 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);
    // printCumulativeMatrixWeight(matrixDir, matrixSize, matrixSize, WEIGHT2);
    // printCumulativeMatrixWeight(matrixDir, 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] = {{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}};

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[y][x] = getDividersCount(matrix[y][x], divider);
                continue;
            }

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

            matrixWeight[y][x] = weight;
            matrixDir[y][x] = 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[y][x] + path;
        if (matrixDir[y][x] == 'D') {
            y -= 1;
        } else {
            x -= 1;
        }
    }
    return path;
}

int main(int, char**){

    int matrixSize;
    std::cin >> matrixSize;

    // std::cout << "size: " << matrixSize << std::endl;

    // int matrixSize = 6;

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

    // 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] =
// {{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] =
// {{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>

#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]);
        }
    }

    // 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);

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

    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& weight10) {
    int x = width - 1;
    int y = height - 1;

    std::string path;
    weight10 = 0;

    while (x != 0 || y != 0) {
        path = matrixDir[x][y] + path;
        weight10 += getDividersCount(matrixDir[x][y], 10);
        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_10;
    std::string path2 = getPath(matrixSize, matrixSize, weight2_10);

    // printMatrix(matrixWeight, matrixSize, matrixSize);

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

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

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

    printf("%d\n", weight_10);
    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>
#include <initializer_list>

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;
}

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);

    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 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);

    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);

    std::string path;
    int weight;
    if (weight2*weight2_5 < weight5*weight5_2) {
        path = path2;
        weight = weight2*weight2_5;
    } else {
        path = path5;
        weight = 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;
            }

            if (matrix[0][0] == 515762700 &&
                matrix[1][0] == 600998816 && y == 75) {
                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());

}