#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>

#include <stdio.h>

using namespace std;

pair<int, int> Get2And5(int x)
{
	pair<int, int> ret = {};
	while (x && x % 2 == 0)
	{
		ret.first++;
		x /= 2;
	}
	while (x && x % 5 == 0)
	{
		ret.second++;
		x /= 5;
	}

	return ret;
}

struct Node
{
	int x, y;
	int value;
	pair<int, int> twofives[2];
	int previous[2];

	Node()
	{
		previous[0] = previous[1] = -1;
	}
};

pair<int, int> operator+(const pair<int, int> &lhs, const pair<int, int> &rhs)
{
	return { lhs.first + rhs.first, lhs.second + rhs.second };
}

pair<int, int>& operator+=(pair<int, int> &lhs, const pair<int, int> &rhs)
{
	lhs.first += rhs.first;
	lhs.second += rhs.second;
	return lhs;
}

int main()
{
	int n;
	cin >> n;

	Node *pZero = nullptr;

	Node *mat = new Node[n*n];
	for (int i = 0; i<n*n; i++)
	{
		mat[i].x = i % n;
		mat[i].y = i / n;
		cin >> mat[i].value;
		if (mat[i].value == 0)
		{
			mat[i].value = 10;
			if (!pZero) pZero = &mat[i];
		}
	}

	for (int i = 0; i<n*n; i++)
	{
		Node &cur = mat[i];

		// calaulate 2/5
		auto tf = Get2And5(cur.value);

		// choose a previous step
		bool x_avail = cur.x != 0;
		bool y_avail = cur.y != 0;

		if (x_avail && y_avail)
		{
			Node &prev_x = mat[i-1];
			Node &prev_y = mat[i-n];

			// accumulate based on twos
			if (prev_x.twofives[0].first < prev_y.twofives[0].first)
			{
				cur.twofives[0] = prev_x.twofives[0] + tf;
				cur.previous[0] = i-1;
			}
			else
			{
				cur.twofives[0] = prev_y.twofives[0] + tf;
				cur.previous[0] = i-n;
			}

			// accumulate based on fives
			if (prev_x.twofives[1].second < prev_y.twofives[1].second)
			{
				cur.twofives[1] = prev_x.twofives[1] + tf;
				cur.previous[1] = i-1;
			}
			else
			{
				cur.twofives[1] = prev_y.twofives[1] + tf;
				cur.previous[1] = i-n;
			}
		}
		else if (x_avail)
		{
			Node &prev_x = mat[i-1];

			// accumulate (only one choice)
			auto tft = prev_x.twofives[0] + tf;
			cur.twofives[0] = tft;
			cur.previous[0] = i-1;
			auto tff = prev_x.twofives[1] + tf;
			cur.twofives[1] = tff;
			cur.previous[1] = i-1;
		}
		else if (y_avail)
		{
			Node &prev_y = mat[i-n];

			// accumulate (only one choice)
			auto tft = prev_y.twofives[0] + tf;
			cur.twofives[0] = tft;
			cur.previous[0] = i-n;
			auto tff = prev_y.twofives[1] + tf;
			cur.twofives[1] = tff;
			cur.previous[1] = i-n;
		}
		else
		{
			// we are at the starting point
			cur.twofives[0] = cur.twofives[1] = tf;
		}
/*
		printf("self=(%d, %d)\n", cur.x, cur.y);
		printf("two: take (%d, %d) zeros=%d\n", cur.previous[0] % n, cur.previous[0] / n,
			min(cur.twofives[0].first, cur.twofives[0].second));
		printf("five: take (%d, %d) zeros=%d\n", cur.previous[1] % n, cur.previous[1] / n,
			min(cur.twofives[1].first, cur.twofives[1].second));
*/	}

	Node *node = &mat[n*n-1];
	int myindex = n*n-1;
	int winner_2 = node->twofives[0].first;
	int winner = min(node->twofives[0].first, node->twofives[1].second);
	if (winner > 1 && pZero)
	{
		// use any path with pZero
		cout << "1" << endl;

		for (int i = 0; i<pZero->x; i++)
			cout << "R";
		for (int i = 0; i<pZero->y; i++)
			cout << "D";
		for (int i = pZero->x; i<n-1; i++)
			cout << "R";
		for (int i = pZero->y; i<n-1; i++)
			cout << "D";

		cout << endl;
	}
	else
	{
		cout << winner << endl;

		string result;
		while (node != &mat[0])
		{
			int prev = (winner == winner_2) ? node->previous[0] : node->previous[1];
			if (prev == myindex -1)
			{
				result += "R";
			}
			else
			{
				result += "D";
			}

			node = &mat[prev];
			myindex = prev;
		}

		reverse(result.begin(), result.end());
		cout << result << endl;
	}

	delete[] mat;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>

#include <stdio.h>

using namespace std;

pair<int, int> Get2And5(int x)
{
	pair<int, int> ret = {};
	while (x && x % 2 == 0)
	{
		ret.first++;
		x /= 2;
	}
	while (x && x % 5 == 0)
	{
		ret.second++;
		x /= 5;
	}

	return ret;
}

struct Node
{
	int x, y;
	int value;
	pair<int, int> twofives[2];
	int previous[2];

	Node()
	{
		previous[0] = previous[1] = -1;
	}
};

pair<int, int> operator+(const pair<int, int> &lhs, const pair<int, int> &rhs)
{
	return { lhs.first + rhs.first, lhs.second + rhs.second };
}

pair<int, int>& operator+=(pair<int, int> &lhs, const pair<int, int> &rhs)
{
	lhs.first += rhs.first;
	lhs.second += rhs.second;
	return lhs;
}

int main()
{
	int n;
	cin >> n;

	Node *pZero = nullptr;

	Node *mat = new Node[n*n];
	for (int i = 0; i<n*n; i++)
	{
		mat[i].x = i % n;
		mat[i].y = i / n;
		cin >> mat[i].value;
		if (mat[i].value == 0)
		{
			mat[i].value = 10;
			if (!pZero) pZero = &mat[i];
		}
	}

	for (int i = 0; i<n*n; i++)
	{
		Node &cur = mat[i];

		// calaulate 2/5
		auto tf = Get2And5(cur.value);

		// choose a previous step
		bool x_avail = cur.x != 0;
		bool y_avail = cur.y != 0;

		if (x_avail && y_avail)
		{
			Node &prev_x = mat[i-1];
			Node &prev_y = mat[i-n];

			// accumulate based on twos
			if (prev_x.twofives[0].first < prev_y.twofives[0].first)
			{
				cur.twofives[0] = prev_x.twofives[0] + tf;
				cur.previous[0] = i-1;
			}
			else
			{
				cur.twofives[0] = prev_y.twofives[0] + tf;
				cur.previous[0] = i-n;
			}

			// accumulate based on fives
			if (prev_x.twofives[1].second < prev_y.twofives[1].second)
			{
				cur.twofives[1] = prev_x.twofives[1] + tf;
				cur.previous[1] = i-1;
			}
			else
			{
				cur.twofives[1] = prev_y.twofives[1] + tf;
				cur.previous[1] = i-n;
			}
		}
		else if (x_avail)
		{
			Node &prev_x = mat[i-1];

			// accumulate (only one choice)
			auto tft = prev_x.twofives[0] + tf;
			cur.twofives[0] = tft;
			cur.previous[0] = i-1;
			auto tff = prev_x.twofives[1] + tf;
			cur.twofives[1] = tff;
			cur.previous[1] = i-1;
		}
		else if (y_avail)
		{
			Node &prev_y = mat[i-n];

			// accumulate (only one choice)
			auto tft = prev_y.twofives[0] + tf;
			cur.twofives[0] = tft;
			cur.previous[0] = i-n;
			auto tff = prev_y.twofives[1] + tf;
			cur.twofives[1] = tff;
			cur.previous[1] = i-n;
		}
		else
		{
			// we are at the starting point
			cur.twofives[0] = cur.twofives[1] = tf;
		}

		printf("self=(%d, %d)\n", cur.x, cur.y);
		printf("two: take (%d, %d) zeros=%d\n", cur.previous[0] % n, cur.previous[0] / n,
			min(cur.twofives[0].first, cur.twofives[0].second));
		printf("five: take (%d, %d) zeros=%d\n", cur.previous[1] % n, cur.previous[1] / n,
			min(cur.twofives[1].first, cur.twofives[1].second));
	}

	Node *node = &mat[n*n-1];
	int myindex = n*n-1;
	int winner_2 = node->twofives[0].first;
	int winner = min(node->twofives[0].first, node->twofives[1].second);
	if (winner > 1 && pZero)
	{
		// use any path with pZero
		cout << "1" << endl;

		for (int i = 0; i<pZero->x; i++)
			cout << "R";
		for (int i = 0; i<pZero->y; i++)
			cout << "D";
		for (int i = pZero->x; i<n-1; i++)
			cout << "R";
		for (int i = pZero->y; i<n-1; i++)
			cout << "D";

		cout << endl;
	}
	else
	{
		cout << winner << endl;

		string result;
		while (node != &mat[0])
		{
			int prev = (winner == winner_2) ? node->previous[0] : node->previous[1];
			if (prev == myindex -1)
			{
				result += "R";
			}
			else
			{
				result += "D";
			}

			node = &mat[prev];
			myindex = prev;
		}

		reverse(result.begin(), result.end());
		cout << result << endl;
	}

	delete[] mat;
	return 0;
}


#include <iostream>
#include <queue>
#include <utility>

using namespace std;

pair<int, int> Get2And5(int x)
{
	pair<int, int> ret = {};
	while (x % 2 == 0)
	{
		ret.first++;
		x /= 2;
	}
	while (x % 5 == 0)
	{
		ret.second++;
		x /= 5;
	}

	return ret;
}

struct Node
{
	int x, y;
	int previous;
	int value;
	int twos;
	int fives;
	int zeros;
	int steps;

	Node()
	{
		x = y = 0;
		previous = -1;
		value = 0;
		twos = fives = zeros = 0;
		steps = 0;
	}
};

struct NextNode
{
	Node *n;

	bool operator<(const NextNode &rhs) const
	{
		// choose the block with lower score
		if (n->zeros < rhs.n->zeros)
			return true;
		if (n->zeros > rhs.n->zeros)
			return false;

		// choose the block which goes further
		if (n->steps > rhs.n->steps)
			return true;
		if (n->steps < rhs.n->steps)
			return false;

		// finally choose the lower (larger y) block
		return n->y < rhs.n->y;
	}
};

int main()
{
	int n;
	cin >> n;

	Node *mat = new Node[n*n];
	for (int i = 0; i<n*n; i++)
	{
		mat[i].x = i % n;
		mat[i].y = i / n;
		mat[i].steps = mat[i].x + mat[i].y;
		cin >> mat[i].value;
	}

	auto matGet = [mat](int index) -> Node& { return mat[index]; };
	auto matGetIndx = [mat, n](const Node &node) { return node.x + node.y * n; };

	priority_queue<NextNode> q;
	q.push({ &matGet(0) });

	while (!q.empty())
	{
		Node &cur = *q.top().n;
		q.pop();

		// calaulate 2/5/0
		auto tf = Get2And5(cur.value);
		cur.twos = tf.first;
		cur.fives = tf.second;
		cur.zeros = min(tf.first, tf.second);

		// choose a previous step
		bool x_avail = cur.x != 0;
		bool y_avail = cur.y != 0;
		if (x_avail && y_avail)
		{
			Node &prev_x = matGet(matGetIndx(cur) -1);
			Node &prev_y = matGet(matGetIndx(cur) -n);

			// accumulate 2/5/0
			int x_twos = cur.twos + prev_x.twos;
			int x_fives = cur.fives + prev_x.fives;
			int x_zeros = min(x_twos, x_fives);

			int y_twos = cur.twos + prev_y.twos;
			int y_fives = cur.fives + prev_y.fives;
			int y_zeros = min(y_twos, y_fives);

			if (x_zeros < y_zeros)
			{
				cur.twos = x_twos;
				cur.fives = x_fives;
				cur.zeros = x_zeros;
				cur.previous = matGetIndx(prev_x);
			}
			else
			{
				cur.twos = y_twos;
				cur.fives = y_fives;
				cur.zeros = y_zeros;
				cur.previous = matGetIndx(prev_y);
			}
		}
		else if (x_avail)
		{
			Node &prev_x = matGet(matGetIndx(cur) -1);

			// accumulate 2/5/0
			int x_twos = cur.twos + prev_x.twos;
			int x_fives = cur.fives + prev_x.fives;
			int x_zeros = min(x_twos, x_fives);

			cur.twos = x_twos;
			cur.fives = x_fives;
			cur.zeros = x_zeros;
			cur.previous = matGetIndx(prev_x);
		}
		else if (y_avail)
		{
			Node &prev_y = matGet(matGetIndx(cur) -n);

			// accumulate 2/5/0
			int y_twos = cur.twos + prev_y.twos;
			int y_fives = cur.fives + prev_y.fives;
			int y_zeros = min(y_twos, y_fives);

			cur.twos = y_twos;
			cur.fives = y_fives;
			cur.zeros = y_zeros;
			cur.previous = matGetIndx(prev_y);
		}
		else
		{
			// we are at the starting point
		}

		// push new blocks
		if (cur.x != n-1)
		{
			Node &next = matGet(matGetIndx(cur) +1);
			q.push({ &next });
		}
		if (cur.y != n-1)
		{
			Node &next = matGet(matGetIndx(cur) +n);
			q.push({ &next });
		}
	}

	Node *node = &matGet(n*n-1);
	cout << node->zeros << endl;

	string result;
	while (node != &matGet(0))
	{
		if (node->previous == matGetIndx(*node) -1)
		{
			result += "R";
		}
		else
		{
			result += "D";
		}

		node = &matGet(node->previous);
	}

	reverse(result.begin(), result.end());
	cout << result << endl;

	/*do
	{
		cout << "(" << node->x << ", " << node->y << ")" << endl;
		node = &matGet(node->previous);
	}
	while (node != &matGet(0));
*/
	delete[] mat;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>

#include <stdio.h>

using namespace std;

pair<int, int> Get2And5(int x)
{
	pair<int, int> ret = {};
	while (x && x % 2 == 0)
	{
		ret.first++;
		x /= 2;
	}
	while (x && x % 5 == 0)
	{
		ret.second++;
		x /= 5;
	}

	return ret;
}

struct Node
{
	int x, y;
	int value;
	pair<int, int> twofives;
	int previous[2];

	Node()
	{
		previous[0] = previous[1] = -1;
	}
};

pair<int, int> operator+(const pair<int, int> &lhs, const pair<int, int> &rhs)
{
	return { lhs.first + rhs.first, lhs.second + rhs.second };
}

pair<int, int>& operator+=(pair<int, int> &lhs, const pair<int, int> &rhs)
{
	lhs.first += rhs.first;
	lhs.second += rhs.second;
	return lhs;
}

int main()
{
	int n;
	cin >> n;

	Node *pZero = nullptr;

	Node *mat = new Node[n*n];
	for (int i = 0; i<n*n; i++)
	{
		mat[i].x = i % n;
		mat[i].y = i / n;
		cin >> mat[i].value;
		if (mat[i].value == 0)
		{
			mat[i].value = 10;
			if (!pZero) pZero = &mat[i];
		}
	}

	for (int i = 0; i<n*n; i++)
	{
		Node &cur = mat[i];

		// calaulate 2/5
		auto tf = Get2And5(cur.value);

		// choose a previous step
		bool x_avail = cur.x != 0;
		bool y_avail = cur.y != 0;

		if (x_avail && y_avail)
		{
			Node &prev_x = mat[i-1];
			Node &prev_y = mat[i-n];

			// accumulate based on twos
			if (prev_x.twofives.first < prev_y.twofives.first)
			{
				cur.twofives.first = prev_x.twofives.first + tf.first;
				cur.previous[0] = i-1;
			}
			else
			{
				cur.twofives.first = prev_y.twofives.first + tf.first;
				cur.previous[0] = i-n;
			}

			// accumulate based on fives
			if (prev_x.twofives.second < prev_y.twofives.second)
			{
				cur.twofives.second = prev_x.twofives.second + tf.second;
				cur.previous[1] = i-1;
			}
			else
			{
				cur.twofives.second = prev_y.twofives.second + tf.second;
				cur.previous[1] = i-n;
			}
		}
		else if (x_avail)
		{
			Node &prev_x = mat[i-1];

			// accumulate (only one choice)
			cur.twofives = tf + prev_x.twofives;
			cur.previous[0] = i-1;
			cur.previous[1] = i-1;
		}
		else if (y_avail)
		{
			Node &prev_y = mat[i-n];

			// accumulate (only one choice)
			cur.twofives = tf + prev_y.twofives;
			cur.previous[0] = i-n;
			cur.previous[1] = i-n;
		}
		else
		{
			// we are at the starting point
			cur.twofives = tf;
		}
/*
		printf("self=(%d, %d)\n", cur.x, cur.y);
		printf("two: take (%d, %d) zeros=%d\n", cur.previous[0] % n, cur.previous[0] / n,
			cur.twofives.first);
		printf("five: take (%d, %d) zeros=%d\n", cur.previous[1] % n, cur.previous[1] / n,
			cur.twofives.second);
*/	}

	Node *node = &mat[n*n-1];
	int myindex = n*n-1;
	int winner_2 = node->twofives.first;
	int winner = min(node->twofives.first, node->twofives.second);
	if (winner > 1 && pZero)
	{
		// use any path with pZero
		cout << "1" << endl;

		for (int i = 0; i<pZero->x; i++)
			cout << "R";
		for (int i = 0; i<pZero->y; i++)
			cout << "D";
		for (int i = pZero->x; i<n-1; i++)
			cout << "R";
		for (int i = pZero->y; i<n-1; i++)
			cout << "D";

		cout << endl;
	}
	else
	{
		cout << winner << endl;

		string result;
		while (node != &mat[0])
		{
			int prev = (winner == winner_2) ? node->previous[0] : node->previous[1];
			if (prev == myindex -1)
			{
				result += "R";
			}
			else
			{
				result += "D";
			}

			node = &mat[prev];
			myindex = prev;
		}

		reverse(result.begin(), result.end());
		cout << result << endl;
	}

	delete[] mat;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>

using namespace std;

pair<int, int> Get2And5(int x)
{
	pair<int, int> ret = {};
	while (x % 2 == 0)
	{
		ret.first++;
		x /= 2;
	}
	while (x % 5 == 0)
	{
		ret.second++;
		x /= 5;
	}

	return ret;
}

struct Node
{
	int x, y;
	int previous;
	int value;
	int twos;
	int fives;
	int zeros;
	int steps;
	bool queued;

	Node()
	{
		x = y = 0;
		previous = -1;
		value = 0;
		twos = fives = zeros = 0;
		steps = 0;
		queued = false;
	}
};

struct NextNode
{
	Node *n;

	bool operator<(const NextNode &rhs) const
	{
		// choose the block with lower score
		if (n->zeros < rhs.n->zeros)
			return true;
		if (n->zeros > rhs.n->zeros)
			return false;

		// choose the block which goes further
		if (n->steps > rhs.n->steps)
			return true;
		if (n->steps < rhs.n->steps)
			return false;

		// finally choose the lower (larger y) block
		return n->y < rhs.n->y;
	}
};

int main()
{
	int n;
	cin >> n;

	Node *mat = new Node[n*n];
	for (int i = 0; i<n*n; i++)
	{
		mat[i].x = i % n;
		mat[i].y = i / n;
		mat[i].steps = mat[i].x + mat[i].y;
		cin >> mat[i].value;
	}

	auto matGet = [mat](int index) -> Node& { return mat[index]; };
	auto matGetIndx = [mat, n](const Node &node) { return node.x + node.y * n; };

	priority_queue<NextNode> q;
	q.push({ &matGet(0) });
	matGet(0).queued = true;

	while (!q.empty())
	{
		Node &cur = *q.top().n;
		q.pop();

		// calaulate 2/5/0
		auto tf = Get2And5(cur.value);
		cur.twos = tf.first;
		cur.fives = tf.second;
		cur.zeros = min(tf.first, tf.second);

		// choose a previous step
		bool x_avail = cur.x != 0;
		bool y_avail = cur.y != 0;
		if (x_avail && y_avail)
		{
			Node &prev_x = matGet(matGetIndx(cur) -1);
			Node &prev_y = matGet(matGetIndx(cur) -n);

			// accumulate 2/5/0
			int x_twos = cur.twos + prev_x.twos;
			int x_fives = cur.fives + prev_x.fives;
			int x_zeros = min(x_twos, x_fives);

			int y_twos = cur.twos + prev_y.twos;
			int y_fives = cur.fives + prev_y.fives;
			int y_zeros = min(y_twos, y_fives);

			if (x_zeros < y_zeros)
			{
				cur.twos = x_twos;
				cur.fives = x_fives;
				cur.zeros = x_zeros;
				cur.previous = matGetIndx(prev_x);
			}
			else
			{
				cur.twos = y_twos;
				cur.fives = y_fives;
				cur.zeros = y_zeros;
				cur.previous = matGetIndx(prev_y);
			}
		}
		else if (x_avail)
		{
			Node &prev_x = matGet(matGetIndx(cur) -1);

			// accumulate 2/5/0
			int x_twos = cur.twos + prev_x.twos;
			int x_fives = cur.fives + prev_x.fives;
			int x_zeros = min(x_twos, x_fives);

			cur.twos = x_twos;
			cur.fives = x_fives;
			cur.zeros = x_zeros;
			cur.previous = matGetIndx(prev_x);
		}
		else if (y_avail)
		{
			Node &prev_y = matGet(matGetIndx(cur) -n);

			// accumulate 2/5/0
			int y_twos = cur.twos + prev_y.twos;
			int y_fives = cur.fives + prev_y.fives;
			int y_zeros = min(y_twos, y_fives);

			cur.twos = y_twos;
			cur.fives = y_fives;
			cur.zeros = y_zeros;
			cur.previous = matGetIndx(prev_y);
		}
		else
		{
			// we are at the starting point
		}

		// push new blocks
		if (cur.x != n-1)
		{
			Node &next = matGet(matGetIndx(cur) +1);
			if (!next.queued)
			{
				q.push({ &next });
				next.queued = true;
			}
		}
		if (cur.y != n-1)
		{
			Node &next = matGet(matGetIndx(cur) +n);
			if (!next.queued)
			{
				q.push({ &next });
				next.queued = true;
			}
		}
	}

	Node *node = &matGet(n*n-1);
	cout << node->zeros << endl;

	string result;
	while (node != &matGet(0))
	{
		if (node->previous == matGetIndx(*node) -1)
		{
			result += "R";
		}
		else
		{
			result += "D";
		}

		node = &matGet(node->previous);
	}

	reverse(result.begin(), result.end());
	cout << result << endl;

	/*do
	{
		cout << "(" << node->x << ", " << node->y << ")" << endl;
		node = &matGet(node->previous);
	}
	while (node != &matGet(0));
*/
	delete[] mat;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>

using namespace std;

pair<int, int> Get2And5(int x)
{
	pair<int, int> ret = {};
	while (x % 2 == 0)
	{
		ret.first++;
		x /= 2;
	}
	while (x % 5 == 0)
	{
		ret.second++;
		x /= 5;
	}

	return ret;
}

struct Node
{
	int x, y;
	int previous;
	int value;
	int twos;
	int fives;
	int zeros;
	int steps;
	bool queued;

	Node()
	{
		x = y = 0;
		previous = -1;
		value = 0;
		twos = fives = zeros = 0;
		steps = 0;
		queued = false;
	}
};

struct NextNode
{
	Node *n;

	bool operator<(const NextNode &rhs) const
	{
		// choose the block with lower score
		if (n->zeros < rhs.n->zeros)
			return true;
		if (n->zeros > rhs.n->zeros)
			return false;

		// choose the block which goes further
		if (n->steps > rhs.n->steps)
			return true;
		if (n->steps < rhs.n->steps)
			return false;

		// finally choose the lower (larger y) block
		return n->y < rhs.n->y;
	}
};

int main()
{
	int n;
	cin >> n;

	Node *mat = new Node[n*n];
	for (int i = 0; i<n*n; i++)
	{
		mat[i].x = i % n;
		mat[i].y = i / n;
		mat[i].steps = mat[i].x + mat[i].y;
		cin >> mat[i].value;
	}

	auto matGet = [mat](int index) -> Node& { return mat[index]; };
	auto matGetIndx = [mat, n](const Node &node) { return node.x + node.y * n; };

	for (int i = 0; i<n*n; i++)
	{
		Node &cur = mat[i];

		// calaulate 2/5/0
		auto tf = Get2And5(cur.value);
		cur.twos = tf.first;
		cur.fives = tf.second;
		cur.zeros = min(tf.first, tf.second);

		// choose a previous step
		bool x_avail = cur.x != 0;
		bool y_avail = cur.y != 0;
		if (x_avail && y_avail)
		{
			Node &prev_x = matGet(matGetIndx(cur) -1);
			Node &prev_y = matGet(matGetIndx(cur) -n);

			// accumulate 2/5/0
			int x_twos = cur.twos + prev_x.twos;
			int x_fives = cur.fives + prev_x.fives;
			int x_zeros = min(x_twos, x_fives);

			int y_twos = cur.twos + prev_y.twos;
			int y_fives = cur.fives + prev_y.fives;
			int y_zeros = min(y_twos, y_fives);

			if (x_zeros < y_zeros)
			{
				cur.twos = x_twos;
				cur.fives = x_fives;
				cur.zeros = x_zeros;
				cur.previous = matGetIndx(prev_x);
			}
			else
			{
				cur.twos = y_twos;
				cur.fives = y_fives;
				cur.zeros = y_zeros;
				cur.previous = matGetIndx(prev_y);
			}
		}
		else if (x_avail)
		{
			Node &prev_x = matGet(matGetIndx(cur) -1);

			// accumulate 2/5/0
			int x_twos = cur.twos + prev_x.twos;
			int x_fives = cur.fives + prev_x.fives;
			int x_zeros = min(x_twos, x_fives);

			cur.twos = x_twos;
			cur.fives = x_fives;
			cur.zeros = x_zeros;
			cur.previous = matGetIndx(prev_x);
		}
		else if (y_avail)
		{
			Node &prev_y = matGet(matGetIndx(cur) -n);

			// accumulate 2/5/0
			int y_twos = cur.twos + prev_y.twos;
			int y_fives = cur.fives + prev_y.fives;
			int y_zeros = min(y_twos, y_fives);

			cur.twos = y_twos;
			cur.fives = y_fives;
			cur.zeros = y_zeros;
			cur.previous = matGetIndx(prev_y);
		}
		else
		{
			// we are at the starting point
		}
	}

	Node *node = &matGet(n*n-1);
	cout << node->zeros << endl;

	string result;
	while (node != &matGet(0))
	{
		if (node->previous == matGetIndx(*node) -1)
		{
			result += "R";
		}
		else
		{
			result += "D";
		}

		node = &matGet(node->previous);
	}

	reverse(result.begin(), result.end());
	cout << result << endl;

	/*do
	{
		cout << "(" << node->x << ", " << node->y << ")" << endl;
		node = &matGet(node->previous);
	}
	while (node != &matGet(0));
*/
	delete[] mat;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>

#include <stdio.h>

using namespace std;

pair<int, int> Get2And5(int x)
{
	pair<int, int> ret = {};
	while (x && x % 2 == 0)
	{
		ret.first++;
		x /= 2;
	}
	while (x && x % 5 == 0)
	{
		ret.second++;
		x /= 5;
	}

	return ret;
}

struct Node
{
	int x, y;
	int value;
	pair<int, int> twofives[2];
	int previous[2];

	Node()
	{
		previous[0] = previous[1] = -1;
	}
};

pair<int, int> operator+(const pair<int, int> &lhs, const pair<int, int> &rhs)
{
	return { lhs.first + rhs.first, lhs.second + rhs.second };
}

int main()
{
	int n;
	cin >> n;

	Node *pZero = nullptr;

	Node *mat = new Node[n*n];
	for (int i = 0; i<n*n; i++)
	{
		mat[i].x = i % n;
		mat[i].y = i / n;
		cin >> mat[i].value;
		if (mat[i].value == 0)
		{
			mat[i].value = 10;
			if (!pZero) pZero = &mat[i];
		}
	}

	auto matGet = [mat](int index) -> Node& { return mat[index]; };

	for (int i = 0; i<n*n; i++)
	{
		Node &cur = mat[i];

		// calaulate 2/5
		auto tf = Get2And5(cur.value);

		// choose a previous step
		bool x_avail = cur.x != 0;
		bool y_avail = cur.y != 0;

		if (x_avail && y_avail)
		{
			Node &prev_x = matGet(i -1);
			Node &prev_y = matGet(i -n);

			// accumulate based on twos
			auto x_tft = prev_x.twofives[0] + tf;
			auto y_tft = prev_y.twofives[0] + tf;
			if (x_tft.first < y_tft.first)
			{
				cur.twofives[0] = x_tft;
				cur.previous[0] = i-1;
			}
			else
			{
				cur.twofives[0] = y_tft;
				cur.previous[0] = i-n;
			}

			// accumulate based on fives
			auto x_tff = prev_x.twofives[1] + tf;
			auto y_tff = prev_y.twofives[1] + tf;
			if (x_tff.second < y_tff.second)
			{
				cur.twofives[1] = x_tff;
				cur.previous[1] = i-1;
			}
			else
			{
				cur.twofives[1] = y_tff;
				cur.previous[1] = i-n;
			}
		}
		else if (x_avail)
		{
			Node &prev_x = matGet(i -1);

			// accumulate (only one choice)
			auto tft = prev_x.twofives[0] + tf;
			cur.twofives[0] = tft;
			cur.previous[0] = i-1;
			auto tff = prev_x.twofives[1] + tf;
			cur.twofives[1] = tff;
			cur.previous[1] = i-1;
		}
		else if (y_avail)
		{
			Node &prev_y = matGet(i -n);

			// accumulate (only one choice)
			auto tft = prev_y.twofives[0] + tf;
			cur.twofives[0] = tft;
			cur.previous[0] = i-n;
			auto tff = prev_y.twofives[1] + tf;
			cur.twofives[1] = tff;
			cur.previous[1] = i-n;
		}
		else
		{
			// we are at the starting point
			cur.twofives[0] = cur.twofives[1] = tf;
		}
/*
		printf("self=(%d, %d)\n", cur.x, cur.y);
		printf("two: take (%d, %d) zeros=%d\n", cur.previous[0] % n, cur.previous[0] / n,
			min(cur.twofives[0].first, cur.twofives[0].second));
		printf("five: take (%d, %d) zeros=%d\n", cur.previous[1] % n, cur.previous[1] / n,
			min(cur.twofives[1].first, cur.twofives[1].second));
*/	}

	Node *node = &matGet(n*n-1);
	int myindex = n*n-1;
	int zeros_t = min(node->twofives[0].first, node->twofives[0].second);
	int zeros_f = min(node->twofives[1].first, node->twofives[1].second);
	int winner = min(zeros_t, zeros_f);
	if (winner > 1 && pZero)
	{
		// use any path with pZero
		cout << "1" << endl;

		for (int i = 0; i<pZero->x; i++)
			cout << "R";
		for (int i = 0; i<pZero->y; i++)
			cout << "D";
		for (int i = pZero->x; i<n-1; i++)
			cout << "R";
		for (int i = pZero->y; i<n-1; i++)
			cout << "D";

		cout << endl;
	}
	else
	{
		cout << winner << endl;

		string result;
		while (node != &matGet(0))
		{
			int prev = (winner == zeros_t) ? node->previous[0] : node->previous[1];
			if (prev == myindex -1)
			{
				result += "R";
			}
			else
			{
				result += "D";
			}

			node = &matGet(prev);
			myindex = prev;
		}

		reverse(result.begin(), result.end());
		cout << result << endl;
	}

	delete[] mat;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>

#include <stdio.h>

using namespace std;

pair<int, int> Get2And5(int x)
{
	pair<int, int> ret = {};
	while (x && x % 2 == 0)
	{
		ret.first++;
		x /= 2;
	}
	while (x && x % 5 == 0)
	{
		ret.second++;
		x /= 5;
	}

	return ret;
}

struct Node
{
	int x, y;
	int value;
	pair<int, int> twofives[2];
	int previous[2];

	Node()
	{
		previous[0] = previous[1] = -1;
	}
};

pair<int, int> operator+(const pair<int, int> &lhs, const pair<int, int> &rhs)
{
	return { lhs.first + rhs.first, lhs.second + rhs.second };
}

pair<int, int>& operator+=(pair<int, int> &lhs, const pair<int, int> &rhs)
{
	lhs.first += rhs.first;
	lhs.second += rhs.second;
	return lhs;
}

int main()
{
	int n;
	cin >> n;

	Node *pZero = nullptr;

	Node *mat = new Node[n*n];
	for (int i = 0; i<n*n; i++)
	{
		mat[i].x = i % n;
		mat[i].y = i / n;
		cin >> mat[i].value;
		if (mat[i].value == 0)
		{
			mat[i].value = 10;
			if (!pZero) pZero = &mat[i];
		}
	}

	for (int i = 0; i<n*n; i++)
	{
		Node &cur = mat[i];

		// calaulate 2/5
		auto tf = Get2And5(cur.value);

		// choose a previous step
		bool x_avail = cur.x != 0;
		bool y_avail = cur.y != 0;

		if (x_avail && y_avail)
		{
			Node &prev_x = mat[i-1];
			Node &prev_y = mat[i-n];

			// accumulate based on twos
			if (prev_x.twofives[0].first < prev_y.twofives[0].first)
			{
				cur.twofives[0] += tf;
				cur.previous[0] = i-1;
			}
			else
			{
				cur.twofives[0] += tf;
				cur.previous[0] = i-n;
			}

			// accumulate based on fives
			if (prev_x.twofives[1].second < prev_y.twofives[1].second)
			{
				cur.twofives[1] += tf;
				cur.previous[1] = i-1;
			}
			else
			{
				cur.twofives[1] += tf;
				cur.previous[1] = i-n;
			}
		}
		else if (x_avail)
		{
			Node &prev_x = mat[i-1];

			// accumulate (only one choice)
			auto tft = prev_x.twofives[0] + tf;
			cur.twofives[0] = tft;
			cur.previous[0] = i-1;
			auto tff = prev_x.twofives[1] + tf;
			cur.twofives[1] = tff;
			cur.previous[1] = i-1;
		}
		else if (y_avail)
		{
			Node &prev_y = mat[i-n];

			// accumulate (only one choice)
			auto tft = prev_y.twofives[0] + tf;
			cur.twofives[0] = tft;
			cur.previous[0] = i-n;
			auto tff = prev_y.twofives[1] + tf;
			cur.twofives[1] = tff;
			cur.previous[1] = i-n;
		}
		else
		{
			// we are at the starting point
			cur.twofives[0] = cur.twofives[1] = tf;
		}
/*
		printf("self=(%d, %d)\n", cur.x, cur.y);
		printf("two: take (%d, %d) zeros=%d\n", cur.previous[0] % n, cur.previous[0] / n,
			min(cur.twofives[0].first, cur.twofives[0].second));
		printf("five: take (%d, %d) zeros=%d\n", cur.previous[1] % n, cur.previous[1] / n,
			min(cur.twofives[1].first, cur.twofives[1].second));
*/	}

	Node *node = &mat[n*n-1];
	int myindex = n*n-1;
	int zeros_t = min(node->twofives[0].first, node->twofives[0].second);
	int zeros_f = min(node->twofives[1].first, node->twofives[1].second);
	int winner = min(zeros_t, zeros_f);
	if (winner > 1 && pZero)
	{
		// use any path with pZero
		cout << "1" << endl;

		for (int i = 0; i<pZero->x; i++)
			cout << "R";
		for (int i = 0; i<pZero->y; i++)
			cout << "D";
		for (int i = pZero->x; i<n-1; i++)
			cout << "R";
		for (int i = pZero->y; i<n-1; i++)
			cout << "D";

		cout << endl;
	}
	else
	{
		cout << winner << endl;

		string result;
		while (node != &mat[0])
		{
			int prev = (winner == zeros_t) ? node->previous[0] : node->previous[1];
			if (prev == myindex -1)
			{
				result += "R";
			}
			else
			{
				result += "D";
			}

			node = &mat[prev];
			myindex = prev;
		}

		reverse(result.begin(), result.end());
		cout << result << endl;
	}

	delete[] mat;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>

using namespace std;

pair<int, int> Get2And5(int x)
{
	pair<int, int> ret = {};

	while (x && x % 2 == 0)
	{
		ret.first++;
		x /= 2;
	}
	while (x && x % 5 == 0)
	{
		ret.second++;
		x /= 5;
	}

	return ret;
}

struct Node
{
	int x, y;
	int previous;
	int value;
	int twos;
	int fives;
	int zeros;
	int steps;
	bool zeroed;

	Node()
	{
		x = y = 0;
		previous = -1;
		value = 0;
		twos = fives = zeros = 0;
		steps = 0;
		zeroed = false;
	}
};

int main()
{
	int n;
	cin >> n;

	Node *mat = new Node[n*n];
	for (int i = 0; i<n*n; i++)
	{
		mat[i].x = i % n;
		mat[i].y = i / n;
		mat[i].steps = mat[i].x + mat[i].y;
		cin >> mat[i].value;
	}

	auto matGet = [mat](int index) -> Node& { return mat[index]; };
	auto matGetIndx = [mat, n](const Node &node) { return node.x + node.y * n; };

	for (int i = 0; i<n*n; i++)
	{
		Node &cur = mat[i];

		// choose a previous step
		bool x_avail = cur.x != 0;
		bool y_avail = cur.y != 0;

		if (!cur.value)
		{
			// this path is zeroed
			// so zero count always == 1
			cur.zeros = 1;
			cur.zeroed = true;
			if (x_avail)
			{
				cur.previous = i -1;
			}
			else if (y_avail)
			{
				cur.previous = i -n;
			}

			continue;
		}

		// calaulate 2/5
		auto tf = Get2And5(cur.value);
		cur.twos = tf.first;
		cur.fives = tf.second;

		if (x_avail && y_avail)
		{
			Node &prev_x = matGet(matGetIndx(cur) -1);
			Node &prev_y = matGet(matGetIndx(cur) -n);

			// accumulate 2/5/0
			int x_twos = cur.twos + prev_x.twos;
			int x_fives = cur.fives + prev_x.fives;
			int x_zeros = prev_x.zeroed ? 1 : min(x_twos, x_fives);

			int y_twos = cur.twos + prev_y.twos;
			int y_fives = cur.fives + prev_y.fives;
			int y_zeros = prev_y.zeroed ? 1 : min(y_twos, y_fives);

			if (x_zeros < y_zeros)
			{
				cur.twos = x_twos;
				cur.fives = x_fives;
				cur.zeros = x_zeros;
				cur.zeroed = prev_x.zeroed;
				cur.previous = matGetIndx(prev_x);
			}
			else
			{
				cur.twos = y_twos;
				cur.fives = y_fives;
				cur.zeros = y_zeros;
				cur.zeroed = prev_y.zeroed;
				cur.previous = matGetIndx(prev_y);
			}
		}
		else if (x_avail)
		{
			Node &prev_x = matGet(matGetIndx(cur) -1);

			// accumulate 2/5/0
			int x_twos = cur.twos + prev_x.twos;
			int x_fives = cur.fives + prev_x.fives;
			int x_zeros = prev_x.zeroed ? 1 : min(x_twos, x_fives);

			cur.twos = x_twos;
			cur.fives = x_fives;
			cur.zeros = x_zeros;
			cur.zeroed = prev_x.zeroed;
			cur.previous = matGetIndx(prev_x);
		}
		else if (y_avail)
		{
			Node &prev_y = matGet(matGetIndx(cur) -n);

			// accumulate 2/5/0
			int y_twos = cur.twos + prev_y.twos;
			int y_fives = cur.fives + prev_y.fives;
			int y_zeros = prev_y.zeroed ? 1 : min(y_twos, y_fives);

			cur.twos = y_twos;
			cur.fives = y_fives;
			cur.zeros = y_zeros;
			cur.zeroed = prev_y.zeroed;
			cur.previous = matGetIndx(prev_y);
		}
		else
		{
			// we are at the starting point
		}
	}

	Node *node = &matGet(n*n-1);
	cout << node->zeros << endl;

	string result;
	while (node != &matGet(0))
	{
		if (node->previous == matGetIndx(*node) -1)
		{
			result += "R";
		}
		else
		{
			result += "D";
		}

		node = &matGet(node->previous);
	}

	reverse(result.begin(), result.end());
	cout << result << endl;

	/*do
	{
		cout << "(" << node->x << ", " << node->y << ")" << endl;
		node = &matGet(node->previous);
	}
	while (node != &matGet(0));
*/
	delete[] mat;
	return 0;
}


#include <iostream>
#include <queue>
#include <utility>

using namespace std;

pair<int, int> Get2And5(int x)
{
	pair<int, int> ret = {};
	while (x % 2 == 0)
	{
		ret.first++;
		x /= 2;
	}
	while (x % 5 == 0)
	{
		ret.second++;
		x /= 5;
	}

	return ret;
}

struct Node
{
	int x, y;
	int previous;
	int value;
	int twos;
	int fives;
	int zeros;
	int steps;

	Node()
	{
		x = y = 0;
		previous = -1;
		value = 0;
		twos = fives = zeros = 0;
		steps = 0;
	}
};

struct NextNode
{
	Node *n;

	bool operator<(const NextNode &rhs) const
	{
		// choose the block with lower score
		if (n->zeros < rhs.n->zeros)
			return true;
		if (n->zeros > rhs.n->zeros)
			return false;

		// choose the block which goes further
		if (n->steps > rhs.n->steps)
			return true;
		if (n->steps < rhs.n->steps)
			return false;

		// finally choose the lower (larger y) block
		return n->y < rhs.n->y;
	}
};

int main()
{
	int n;
	cin >> n;

	Node *mat = new Node[n*n];
	for (int i = 0; i<n*n; i++)
	{
		mat[i].x = i % n;
		mat[i].y = i / n;
		mat[i].steps = mat[i].x + mat[i].y;
		cin >> mat[i].value;
	}

	auto matGet = [mat](int index) -> Node& { return mat[index]; };
	auto matGetIndx = [mat, n](const Node &node) { return node.x + node.y * n; };

	priority_queue<NextNode> q;
	q.push({ &matGet(0) });

	while (!q.empty())
	{
		Node &cur = *q.top().n;
		q.pop();

		// calaulate 2/5/0
		auto tf = Get2And5(cur.value);
		cur.twos = tf.first;
		cur.fives = tf.second;
		cur.zeros = min(tf.first, tf.second);

		// choose a previous step
		bool x_avail = cur.x != 0;
		bool y_avail = cur.y != 0;
		if (x_avail && y_avail)
		{
			Node &prev_x = matGet(matGetIndx(cur) -1);
			Node &prev_y = matGet(matGetIndx(cur) -n);

			// accumulate 2/5/0
			int x_twos = cur.twos + prev_x.twos;
			int x_fives = cur.fives + prev_x.fives;
			int x_zeros = min(x_twos, x_fives);

			int y_twos = cur.twos + prev_y.twos;
			int y_fives = cur.fives + prev_y.fives;
			int y_zeros = min(y_twos, y_fives);

			if (x_zeros < y_zeros)
			{
				cur.twos = x_twos;
				cur.fives = x_fives;
				cur.zeros = x_zeros;
				cur.previous = matGetIndx(prev_x);
			}
			else
			{
				cur.twos = y_twos;
				cur.fives = y_fives;
				cur.zeros = y_zeros;
				cur.previous = matGetIndx(prev_y);
			}
		}
		else if (x_avail)
		{
			Node &prev_x = matGet(matGetIndx(cur) -1);

			// accumulate 2/5/0
			int x_twos = cur.twos + prev_x.twos;
			int x_fives = cur.fives + prev_x.fives;
			int x_zeros = min(x_twos, x_fives);

			cur.twos = x_twos;
			cur.fives = x_fives;
			cur.zeros = x_zeros;
			cur.previous = matGetIndx(prev_x);
		}
		else if (y_avail)
		{
			Node &prev_y = matGet(matGetIndx(cur) -n);

			// accumulate 2/5/0
			int y_twos = cur.twos + prev_y.twos;
			int y_fives = cur.fives + prev_y.fives;
			int y_zeros = min(y_twos, y_fives);

			cur.twos = y_twos;
			cur.fives = y_fives;
			cur.zeros = y_zeros;
			cur.previous = matGetIndx(prev_y);
		}
		else
		{
			// we are at the starting point
		}

		// push new blocks
		if (cur.x != n-1)
		{
			Node &next = matGet(matGetIndx(cur) +1);
			q.push({ &next });
		}
		if (cur.y != n-1)
		{
			Node &next = matGet(matGetIndx(cur) +n);
			q.push({ &next });
		}
	}

	Node *node = &matGet(n*n-1);
	cout << node->zeros << endl;

	string result;
	while (node != &matGet(0))
	{
		if (node->previous == matGetIndx(*node) -1)
		{
			string tmp = "R";
			result = tmp + result;
		}
		else
		{
			string tmp = "D";
			result = tmp + result;
		}

		node = &matGet(node->previous);
	}

	cout << result << endl;

	/*do
	{
		cout << "(" << node->x << ", " << node->y << ")" << endl;
		node = &matGet(node->previous);
	}
	while (node != &matGet(0));
*/
	delete[] mat;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>

#include <stdio.h>

using namespace std;

pair<int, int> Get2And5(int x)
{
	pair<int, int> ret = {};
	while (x && x % 2 == 0)
	{
		ret.first++;
		x /= 2;
	}
	while (x && x % 5 == 0)
	{
		ret.second++;
		x /= 5;
	}

	return ret;
}

struct Node
{
	int x, y;
	int value;
	pair<int, int> twofives[2];
	int previous[2];

	Node()
	{
		previous[0] = previous[1] = -1;
	}
};

pair<int, int> operator+(const pair<int, int> &lhs, const pair<int, int> &rhs)
{
	return { lhs.first + rhs.first, lhs.second + rhs.second };
}

int main()
{
	int n;
	cin >> n;

	Node *pZero = nullptr;

	Node *mat = new Node[n*n];
	for (int i = 0; i<n*n; i++)
	{
		mat[i].x = i % n;
		mat[i].y = i / n;
		cin >> mat[i].value;
		if (mat[i].value == 0)
		{
			mat[i].value = 10;
			if (!pZero) pZero = &mat[i];
		}
	}

	//auto matGet = [mat](int index) -> Node& { return mat[index]; };

	for (int i = 0; i<n*n; i++)
	{
		Node &cur = mat[i];

		// calaulate 2/5
		auto tf = Get2And5(cur.value);

		// choose a previous step
		bool x_avail = cur.x != 0;
		bool y_avail = cur.y != 0;

		if (x_avail && y_avail)
		{
			Node &prev_x = mat[i-1];//matGet(i -1);
			Node &prev_y = mat[i-n];//matGet(i -n);

			// accumulate based on twos
			auto x_tft = prev_x.twofives[0] + tf;
			auto y_tft = prev_y.twofives[0] + tf;
			if (x_tft.first < y_tft.first)
			{
				cur.twofives[0] = x_tft;
				cur.previous[0] = i-1;
			}
			else
			{
				cur.twofives[0] = y_tft;
				cur.previous[0] = i-n;
			}

			// accumulate based on fives
			auto x_tff = prev_x.twofives[1] + tf;
			auto y_tff = prev_y.twofives[1] + tf;
			if (x_tff.second < y_tff.second)
			{
				cur.twofives[1] = x_tff;
				cur.previous[1] = i-1;
			}
			else
			{
				cur.twofives[1] = y_tff;
				cur.previous[1] = i-n;
			}
		}
		else if (x_avail)
		{
			Node &prev_x = mat[i-1];//matGet(i -1);

			// accumulate (only one choice)
			auto tft = prev_x.twofives[0] + tf;
			cur.twofives[0] = tft;
			cur.previous[0] = i-1;
			auto tff = prev_x.twofives[1] + tf;
			cur.twofives[1] = tff;
			cur.previous[1] = i-1;
		}
		else if (y_avail)
		{
			Node &prev_y = mat[i-n];//matGet(i -n);

			// accumulate (only one choice)
			auto tft = prev_y.twofives[0] + tf;
			cur.twofives[0] = tft;
			cur.previous[0] = i-n;
			auto tff = prev_y.twofives[1] + tf;
			cur.twofives[1] = tff;
			cur.previous[1] = i-n;
		}
		else
		{
			// we are at the starting point
			cur.twofives[0] = cur.twofives[1] = tf;
		}
/*
		printf("self=(%d, %d)\n", cur.x, cur.y);
		printf("two: take (%d, %d) zeros=%d\n", cur.previous[0] % n, cur.previous[0] / n,
			min(cur.twofives[0].first, cur.twofives[0].second));
		printf("five: take (%d, %d) zeros=%d\n", cur.previous[1] % n, cur.previous[1] / n,
			min(cur.twofives[1].first, cur.twofives[1].second));
*/	}

	Node *node = &mat[n*n-1];//&matGet(n*n-1);
	int myindex = n*n-1;
	int zeros_t = min(node->twofives[0].first, node->twofives[0].second);
	int zeros_f = min(node->twofives[1].first, node->twofives[1].second);
	int winner = min(zeros_t, zeros_f);
	if (winner > 1 && pZero)
	{
		// use any path with pZero
		cout << "1" << endl;

		for (int i = 0; i<pZero->x; i++)
			cout << "R";
		for (int i = 0; i<pZero->y; i++)
			cout << "D";
		for (int i = pZero->x; i<n-1; i++)
			cout << "R";
		for (int i = pZero->y; i<n-1; i++)
			cout << "D";

		cout << endl;
	}
	else
	{
		cout << winner << endl;

		string result;
		while (node != &mat[0])
		{
			int prev = (winner == zeros_t) ? node->previous[0] : node->previous[1];
			if (prev == myindex -1)
			{
				result += "R";
			}
			else
			{
				result += "D";
			}

			node = &mat[prev];//&matGet(prev);
			myindex = prev;
		}

		reverse(result.begin(), result.end());
		cout << result << endl;
	}

	delete[] mat;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>

using namespace std;

pair<int, int> Get2And5(int x)
{
	pair<int, int> ret = {};
	while (x % 2 == 0)
	{
		ret.first++;
		x /= 2;
	}
	while (x % 5 == 0)
	{
		ret.second++;
		x /= 5;
	}

	return ret;
}

struct Node
{
	int x, y;
	int previous;
	int value;
	int twos;
	int fives;
	int zeros;
	int steps;

	Node()
	{
		x = y = 0;
		previous = -1;
		value = 0;
		twos = fives = zeros = 0;
		steps = 0;
	}
};

struct NextNode
{
	Node *n;

	bool operator<(const NextNode &rhs) const
	{
		// choose the block with lower score
		if (n->zeros < rhs.n->zeros)
			return true;
		if (n->zeros > rhs.n->zeros)
			return false;

		// choose the block which goes further
		if (n->steps > rhs.n->steps)
			return true;
		if (n->steps < rhs.n->steps)
			return false;

		// finally choose the lower (larger y) block
		return n->y < rhs.n->y;
	}
};

int main()
{
	int n;
	cin >> n;

	Node *mat = new Node[n*n];
	for (int i = 0; i<n*n; i++)
	{
		mat[i].x = i % n;
		mat[i].y = i / n;
		mat[i].steps = mat[i].x + mat[i].y;
		cin >> mat[i].value;
	}

	auto matGet = [mat](int index) -> Node& { return mat[index]; };
	auto matGetIndx = [mat, n](const Node &node) { return node.x + node.y * n; };

	priority_queue<NextNode> q;
	q.push({ &matGet(0) });

	while (!q.empty())
	{
		Node &cur = *q.top().n;
		q.pop();

		// calaulate 2/5/0
		auto tf = Get2And5(cur.value);
		cur.twos = tf.first;
		cur.fives = tf.second;
		cur.zeros = min(tf.first, tf.second);

		// choose a previous step
		bool x_avail = cur.x != 0;
		bool y_avail = cur.y != 0;
		if (x_avail && y_avail)
		{
			Node &prev_x = matGet(matGetIndx(cur) -1);
			Node &prev_y = matGet(matGetIndx(cur) -n);

			// accumulate 2/5/0
			int x_twos = cur.twos + prev_x.twos;
			int x_fives = cur.fives + prev_x.fives;
			int x_zeros = min(x_twos, x_fives);

			int y_twos = cur.twos + prev_y.twos;
			int y_fives = cur.fives + prev_y.fives;
			int y_zeros = min(y_twos, y_fives);

			if (x_zeros < y_zeros)
			{
				cur.twos = x_twos;
				cur.fives = x_fives;
				cur.zeros = x_zeros;
				cur.previous = matGetIndx(prev_x);
			}
			else
			{
				cur.twos = y_twos;
				cur.fives = y_fives;
				cur.zeros = y_zeros;
				cur.previous = matGetIndx(prev_y);
			}
		}
		else if (x_avail)
		{
			Node &prev_x = matGet(matGetIndx(cur) -1);

			// accumulate 2/5/0
			int x_twos = cur.twos + prev_x.twos;
			int x_fives = cur.fives + prev_x.fives;
			int x_zeros = min(x_twos, x_fives);

			cur.twos = x_twos;
			cur.fives = x_fives;
			cur.zeros = x_zeros;
			cur.previous = matGetIndx(prev_x);
		}
		else if (y_avail)
		{
			Node &prev_y = matGet(matGetIndx(cur) -n);

			// accumulate 2/5/0
			int y_twos = cur.twos + prev_y.twos;
			int y_fives = cur.fives + prev_y.fives;
			int y_zeros = min(y_twos, y_fives);

			cur.twos = y_twos;
			cur.fives = y_fives;
			cur.zeros = y_zeros;
			cur.previous = matGetIndx(prev_y);
		}
		else
		{
			// we are at the starting point
		}

		// push new blocks
		if (cur.x != n-1)
		{
			Node &next = matGet(matGetIndx(cur) +1);
			q.push({ &next });
		}
		if (cur.y != n-1)
		{
			Node &next = matGet(matGetIndx(cur) +n);
			q.push({ &next });
		}
	}

	Node *node = &matGet(n*n-1);
	cout << node->zeros << endl;

	string result;
	while (node != &matGet(0))
	{
		if (node->previous == matGetIndx(*node) -1)
		{
			result += "R";
		}
		else
		{
			result += "D";
		}

		node = &matGet(node->previous);
	}

	reverse(result.begin(), result.end());
	cout << result << endl;

	/*do
	{
		cout << "(" << node->x << ", " << node->y << ")" << endl;
		node = &matGet(node->previous);
	}
	while (node != &matGet(0));
*/
	delete[] mat;
	return 0;
}


#include <sstream>
#include <iomanip>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <deque>
#include <complex>

#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define FORN(i,a,b) for(int i=(a),_b=(b);i<_b;i++)
#define DOWN(i,a,b) for(int i=a,_b=(b);i>=_b;i--)
#define SET(a,v) memset(a,v,sizeof(a))
#define sqr(x) ((x)*(x))
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair

#define DEBUG(x) cout << #x << " = "; cout << x << endl;
#define PR(a,n) cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl;
#define PR0(a,n) cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl;
using namespace std;

//Buffer reading
int INP,AM,REACHEOF;
const int BUFSIZE = (1<<12) + 17;
char BUF[BUFSIZE+1], *inp=BUF;
#define GETCHAR(INP) { \
    if(!*inp && !REACHEOF) { \
        memset(BUF,0,sizeof BUF);\
        int inpzzz = fread(BUF,1,BUFSIZE,stdin);\
        if (inpzzz != BUFSIZE) REACHEOF = true;\
        inp=BUF; \
    } \
    INP=*inp++; \
}
#define DIG(a) (((a)>='0')&&((a)<='9'))
#define GN(j) { \
    AM=0;\
    GETCHAR(INP); while(!DIG(INP) && INP!='-') GETCHAR(INP);\
    if (INP=='-') {AM=1;GETCHAR(INP);} \
    j=INP-'0'; GETCHAR(INP); \
    while(DIG(INP)){j=10*j+(INP-'0');GETCHAR(INP);} \
    if (AM) j=-j;\
}
//End of buffer reading

const long double PI = acos((long double) -1.0);
const int MN = 1011;

int a[MN][MN], f2[MN][MN], f5[MN][MN], p2[MN][MN], p5[MN][MN];
int n;

inline int min(const int &a, const int &b) {
    return (a < b) ? a : b;
}

void solve() {
    FOR(x,1,n) f2[0][x] = f2[x][0] = f5[0][x] = f5[x][0] = 1000111000;
    f2[1][0] = f5[1][0] = 0;

    FOR(i,1,n) FOR(j,1,n) {
        p2[i][j] = p5[i][j] = 0;
        int u;
        u = a[i][j]; while (!(u&1)) u >>= 1, p2[i][j]++;
        u = a[i][j]; while (u % 5 == 0) u /= 5, p5[i][j]++;

        f2[i][j] = min(f2[i-1][j], f2[i][j-1]) + p2[i][j];
        f5[i][j] = min(f5[i-1][j], f5[i][j-1]) + p5[i][j];
    }
}

void printPath(int i, int j) {
    FOR(t,1,i-1) putchar('D');
    FOR(t,1,j-1) putchar('R');

    FOR(t,i,n-1) putchar('D');
    FOR(t,j,n-1) putchar('R');
}

void trace2(int i, int j) {
    if (i == 1 && j == 1) return ;
    if (f2[i][j] == f2[i-1][j] + p2[i][j]) {
        trace2(i-1, j);
        putchar('D');
    }
    else {
        trace2(i, j-1);
        putchar('R');
    }
}

void trace5(int i, int j) {
    if (i == 1 && j == 1) return ;
    if (f5[i][j] == f5[i-1][j] + p5[i][j]) {
        trace5(i-1, j);
        putchar('D');
    }
    else {
        trace5(i, j-1);
        putchar('R');
    }
}

int main() {
    while (scanf("%d", &n) == 1) {
        bool has0 = false;
        int zeroi = -1, zeroj = -1;
        FOR(i,1,n) FOR(j,1,n) {
            scanf("%d", &a[i][j]);
            if (a[i][j] == 0) has0 = true, zeroi = i, zeroj = j, a[i][j] = 10;
        }
        solve();
        if (has0 && f2[n][n] > 1 && f5[n][n] > 1) {
            puts("1");
            printPath(zeroi, zeroj);
        }
        else if (f2[n][n] < f5[n][n]) {
            printf("%d\n", f2[n][n]);
            trace2(n, n);
        }
        else {
            printf("%d\n", f5[n][n]);
            trace5(n, n);
        }
        puts("");
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <assert.h>
#include <algorithm>

using namespace std;

int tdiv(int n)
{
    int cnt=0;
    while (n && n%2==0) n/=2, cnt++;

    return cnt;
}

int fdiv(int n)
{
    int cnt=0;
    while (n && n%5==0) n/=5, cnt++;

    return cnt;
}

void printv(vector<vector<int> > t, vector<vector<int> > f)
{
    for (int i=0; i<t.size(); i++)
    {
        for (int j=0; j<t.size(); j++) cout<<t[i][j]<<","<<f[i][j]<<"\t"; cout<<endl;
    }
    cout<<endl;
}

string toString(vector<vector<bool> > &dir)
{
    const int left  = false;
    const int up    = true;

    vector<char> dirStr = {'R','D'};
    string ans;
    int n = dir.size();
    int i=n-1, j=n-1;
    while (i>0 || j>0)
    {
        ans.push_back(dirStr[dir[i][j]]);
        if (i==0) j--;
        else if (j==0) i--;
        else
        {
            if (dir[i][j]==up) i--;
            else j--;
        }
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

int main()
{
    int n;
    cin>>n;
    vector<vector<int> > t(n, vector<int> (n)), f(n, vector<int> (n));
    int x=-1, y=-1;
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            int a;
            cin>>a;
            f[i][j] = fdiv(a);
            t[i][j] = tdiv(a);

            if (a==0)
            {
                x=i;
                y=j;
            }
        }
    }

    const int left  = false;
    const int up    = true;

    //printv(t,f);

    vector<vector<bool> > tdir(n, vector<bool> (n,false)),fdir(n, vector<bool> (n,false));
    for (int i=1; i<n; i++) tdir[i][0]=up, fdir[i][0]=up;
    for (int i=1; i<n; i++)
    {
        t[i][0]+=t[i-1][0];
        f[i][0]+=f[i-1][0];

        t[0][i]+=t[0][i-1];
        f[0][i]+=f[0][i-1];
    }

    //printv(t,f);

    for (int i=1; i<n; i++)
    {
        for (int j=1; j<n; j++)
        {
            if (t[i-1][j]<t[i][j-1])
            {
                t[i][j]+=t[i-1][j];
                tdir[i][j]=up;
            }
            else
            {
                t[i][j]+=t[i][j-1];
                tdir[i][j]=left;
            }

            if (f[i-1][j]<f[i][j-1])
            {
                f[i][j]+=f[i-1][j];
                fdir[i][j]=up;
            }
            else
            {
                f[i][j]+=f[i][j-1];
                fdir[i][j]=left;
            }
        }
        //cout<<"-------------"<<endl;
        //printv(t,f);
    }

    int mn = min(t[n-1][n-1], t[n-1][n-1]);
    if (x!=-1)
    {
        string ans;
        for (int i=1; i<=x; i++) ans.push_back('R');
        for (int i=1; i<=y; i++) ans.push_back('D');
        for (int i=x+1; i<n; i++) ans.push_back('R');
        for (int i=y+1; i<n; i++) ans.push_back('D');
        cout<<"1"<<endl;
        cout<<ans<<endl;
        assert(ans.size()==2*n-1);
    }
    else
    {
        if (t[n-1][n-1]<f[n-1][n-1])
        {
            cout<<t[n-1][n-1]<<endl;
            cout<<toString(tdir)<<endl;
        }
        else
        {
            cout<<f[n-1][n-1]<<endl;
            cout<<toString(fdir)<<endl;
        }
    }
    return 0;
}


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

using namespace std;

int tdiv(int n)
{
    int cnt=0;
    while (n%2==0) n/=2, cnt++;

    return cnt;
}

int fdiv(int n)
{
    int cnt=0;
    while (n%5==0) n/=5, cnt++;

    return cnt;
}

string toString(vector<vector<bool> > &dir)
{
    const int left  = false;
    const int up    = true;

    vector<char> dirStr = {'R','D'};
    string ans;
    int n = dir.size();
    int i=n-1, j=n-1;
    while (i>0 || j>0)
    {
        ans.push_back(dirStr[dir[i][j]]);
        if (i==0) j--;
        else if (j==0) i--;
        else
        {
            if (dir[i][j]==up) i--;
            else j--;
        }
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

int main()
{
    int n;
    scanf("%d",&n);
    vector<vector<int> > t(n, vector<int> (n)), f(n, vector<int> (n));
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            int a;
            scanf("%d",&a);
            f[i][j] = fdiv(a);
            t[i][j] = tdiv(a);
        }
    }

    const int left  = false;
    const int up    = true;

    //printv(t,f);

    vector<vector<bool> > tdir(n, vector<bool> (n,false)),fdir(n, vector<bool> (n,false));
    for (int i=1; i<n; i++) tdir[i][0]=up, fdir[i][0]=up;
    for (int i=1; i<n; i++)
    {
        t[i][0]+=t[i-1][0];
        f[i][0]+=f[i-1][0];

        t[0][i]+=t[0][i-1];
        f[0][i]+=f[0][i-1];
    }

    //printv(t,f);

    for (int i=1; i<n; i++)
    {
        for (int j=1; j<n; j++)
        {
            if (t[i-1][j]<t[i][j-1])
            {
                t[i][j]+=t[i-1][j];
                tdir[i][j]=up;
            }
            else
            {
                t[i][j]+=t[i][j-1];
                tdir[i][j]=left;
            }

            if (f[i-1][j]<f[i][j-1])
            {
                f[i][j]+=f[i-1][j];
                fdir[i][j]=up;
            }
            else
            {
                f[i][j]+=f[i][j-1];
                fdir[i][j]=left;
            }
        }
        //cout<<"-------------"<<endl;
        //printv(t,f);
    }

    if (t[n-1][n-1]<f[n-1][n-1])
    {
        cout<<t[n-1][n-1]<<endl;
        cout<<toString(tdir)<<endl;
    }
    else
    {
        cout<<f[n-1][n-1]<<endl;
        cout<<toString(fdir)<<endl;
    }
    return 0;
}
/*
6
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

*/


#include <iostream>
#include <string>
#include <vector>
#include <assert.h>
#include <algorithm>

using namespace std;

int tdiv(int n)
{
    int cnt=0;
    while (n && n%2==0) n/=2, cnt++;

    return cnt;
}

int fdiv(int n)
{
    int cnt=0;
    while (n && n%5==0) n/=5, cnt++;

    return cnt;
}

void printv(vector<vector<int> > t, vector<vector<int> > f)
{
    for (int i=0; i<t.size(); i++)
    {
        for (int j=0; j<t.size(); j++) cout<<t[i][j]<<","<<f[i][j]<<"\t"; cout<<endl;
    }
    cout<<endl;
}

bool checkPath(vector<vector<bool> > &dir, int x, int y)
{
    const int left  = false;
    const int up    = true;

    int n = dir.size();
    int i=n-1, j=n-1;
    while (i>0 || j>0)
    {
        if (x==i && y==j) return true;
        if (i==0) j--;
        else if (j==0) i--;
        else
        {
            if (dir[i][j]==up) i--;
            else j--;
        }
    }
    return false;
}

string toString(vector<vector<bool> > &dir)
{
    const int left  = false;
    const int up    = true;

    vector<char> dirStr = {'R','D'};
    string ans;
    int n = dir.size();
    int i=n-1, j=n-1;
    while (i>0 || j>0)
    {
        ans.push_back(dirStr[dir[i][j]]);
        if (i==0) j--;
        else if (j==0) i--;
        else
        {
            if (dir[i][j]==up) i--;
            else j--;
        }
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

int main()
{
    int n;
    cin>>n;
    vector<vector<int> > t(n, vector<int> (n)), f(n, vector<int> (n));
    int x=-1, y=-1;
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            int a;
            cin>>a;
            f[i][j] = fdiv(a);
            t[i][j] = tdiv(a);

            if (a==0)
            {
                x=i;
                y=j;
            }
        }
    }

    const int left  = false;
    const int up    = true;

    //printv(t,f);

    vector<vector<bool> > tdir(n, vector<bool> (n,false)),fdir(n, vector<bool> (n,false));
    for (int i=1; i<n; i++) tdir[i][0]=up, fdir[i][0]=up;
    for (int i=1; i<n; i++)
    {
        t[i][0]+=t[i-1][0];
        f[i][0]+=f[i-1][0];

        t[0][i]+=t[0][i-1];
        f[0][i]+=f[0][i-1];
    }

    //printv(t,f);

    for (int i=1; i<n; i++)
    {
        for (int j=1; j<n; j++)
        {
            if (t[i-1][j]<t[i][j-1])
            {
                t[i][j]+=t[i-1][j];
                tdir[i][j]=up;
            }
            else
            {
                t[i][j]+=t[i][j-1];
                tdir[i][j]=left;
            }

            if (f[i-1][j]<f[i][j-1])
            {
                f[i][j]+=f[i-1][j];
                fdir[i][j]=up;
            }
            else
            {
                f[i][j]+=f[i][j-1];
                fdir[i][j]=left;
            }
        }
        //cout<<"-------------"<<endl;
        //printv(t,f);
    }

    bool printZero=x!=-1;
    int mn = min(t[n-1][n-1], f[n-1][n-1]);
    if (mn==0 && printZero)
    {
        if (t[n-1][n-1]<f[n-1][n-1] && checkPath(tdir,x,y)) printZero=true;
        else if (checkPath(fdir,x,y)) printZero=true;
        else printZero=false;
    }

    if (printZero)
    {
        string ans;
        for (int i=1; i<=y; i++) ans.push_back('R');
        for (int i=1; i<=x; i++) ans.push_back('D');
        for (int i=y+1; i<n; i++) ans.push_back('R');
        for (int i=x+1; i<n; i++) ans.push_back('D');
        cout<<"1"<<endl;
        cout<<ans<<endl;
        //cout<<ans.size()<<endl;
        assert(ans.size()==2*n-2);
    }
    else
    {
        if (t[n-1][n-1]<f[n-1][n-1])
        {
            cout<<t[n-1][n-1]<<endl;
            cout<<toString(tdir)<<endl;
        }
        else
        {
            cout<<f[n-1][n-1]<<endl;
            cout<<toString(fdir)<<endl;
        }
    }
    return 0;
}


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

using namespace std;

int getDiv(int n, int d)
{
    int cnt=0;
    while (n && n%d==0) n/=d, cnt++;

    return cnt;
}

const int dirLeft  = false;
const int dirUp    = true;
vector<char> dirStr = {'R','D'};

void print(vector<vector<bool> > &dir, int i, int j)
{
    if (i>0 || j>0)
    {
        if (i==0) print(dir, i, j-1);
        else if (j==0) print(dir, i-1, j);
        else
        {
            if (dir[i][j]==dirUp) print(dir, i-1, j);
            else print(dir, i, j-1);
        }
        printf("%c",dirStr[dir[i][j]]);
    }
}

int main()
{
    int n;
    scanf("%d",&n);
    vector<vector<int> > t(n, vector<int> (n)), f(n, vector<int> (n));
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            int a;
            scanf("%d",&a);
            f[i][j] = getDiv(a,5);
            t[i][j] = getDiv(a,2);
        }
    }

    vector<vector<bool> > tdir(n, vector<bool> (n,dirLeft)),fdir(n, vector<bool> (n,dirLeft));
    for (int i=1; i<n; i++) tdir[i][0]=dirUp, fdir[i][0]=dirUp;
    for (int i=1; i<n; i++)
    {
        t[i][0]+=t[i-1][0];
        f[i][0]+=f[i-1][0];

        t[0][i]+=t[0][i-1];
        f[0][i]+=f[0][i-1];
    }

    //printv(t,f);

    for (int i=1; i<n; i++)
    {
        for (int j=1; j<n; j++)
        {
            if (t[i-1][j]<t[i][j-1])
            {
                t[i][j]+=t[i-1][j];
                tdir[i][j]=dirUp;
            }
            else
            {
                t[i][j]+=t[i][j-1];
                tdir[i][j]=dirLeft;
            }

            if (f[i-1][j]<f[i][j-1])
            {
                f[i][j]+=f[i-1][j];
                fdir[i][j]=dirUp;
            }
            else
            {
                f[i][j]+=f[i][j-1];
                fdir[i][j]=dirLeft;
            }
        }
        //cout<<"-------------"<<endl;
        //printv(t,f);
    }

    if (t[n-1][n-1]<f[n-1][n-1])
    {
        printf("%d\n",t[n-1][n-1]);
        print(tdir, n-1, n-1);
        printf("\n");
    }
    else
    {
        printf("%d\n",f[n-1][n-1]);
        print(fdir, n-1, n-1);
        printf("\n");
    }
    return 0;
}
/*
6
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

*/


#include <iostream>
#include <string>
#include <vector>
#include <assert.h>
#include <algorithm>

using namespace std;

int tdiv(int n)
{
    int cnt=0;
    while (n && n%2==0) n/=2, cnt++;

    return cnt;
}

int fdiv(int n)
{
    int cnt=0;
    while (n && n%5==0) n/=5, cnt++;

    return cnt;
}

void printv(vector<vector<int> > t, vector<vector<int> > f)
{
    for (int i=0; i<t.size(); i++)
    {
        for (int j=0; j<t.size(); j++) cout<<t[i][j]<<","<<f[i][j]<<"\t"; cout<<endl;
    }
    cout<<endl;
}

string toString(vector<vector<bool> > &dir)
{
    const int left  = false;
    const int up    = true;

    vector<char> dirStr = {'R','D'};
    string ans;
    int n = dir.size();
    int i=n-1, j=n-1;
    while (i>0 || j>0)
    {
        ans.push_back(dirStr[dir[i][j]]);
        if (i==0) j--;
        else if (j==0) i--;
        else
        {
            if (dir[i][j]==up) i--;
            else j--;
        }
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

int main()
{
    int n;
    cin>>n;
    vector<vector<int> > t(n, vector<int> (n)), f(n, vector<int> (n));
    int x=-1, y=-1;
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            int a;
            cin>>a;
            f[i][j] = fdiv(a);
            t[i][j] = tdiv(a);

            if (a==0)
            {
                x=i;
                y=j;
            }
        }
    }

    const int left  = false;
    const int up    = true;

    //printv(t,f);

    vector<vector<bool> > tdir(n, vector<bool> (n,false)),fdir(n, vector<bool> (n,false));
    for (int i=1; i<n; i++) tdir[i][0]=up, fdir[i][0]=up;
    for (int i=1; i<n; i++)
    {
        t[i][0]+=t[i-1][0];
        f[i][0]+=f[i-1][0];

        t[0][i]+=t[0][i-1];
        f[0][i]+=f[0][i-1];
    }

    //printv(t,f);

    for (int i=1; i<n; i++)
    {
        for (int j=1; j<n; j++)
        {
            if (t[i-1][j]<t[i][j-1])
            {
                t[i][j]+=t[i-1][j];
                tdir[i][j]=up;
            }
            else
            {
                t[i][j]+=t[i][j-1];
                tdir[i][j]=left;
            }

            if (f[i-1][j]<f[i][j-1])
            {
                f[i][j]+=f[i-1][j];
                fdir[i][j]=up;
            }
            else
            {
                f[i][j]+=f[i][j-1];
                fdir[i][j]=left;
            }
        }
        //cout<<"-------------"<<endl;
        //printv(t,f);
    }

    int mn = min(t[n-1][n-1], t[n-1][n-1]);
    if (x!=-1)
    {
        string ans;
        for (int i=1; i<=y; i++) ans.push_back('R');
        for (int i=1; i<=x; i++) ans.push_back('D');
        for (int i=y+1; i<n; i++) ans.push_back('R');
        for (int i=x+1; i<n; i++) ans.push_back('D');
        cout<<"1"<<endl;
        cout<<ans<<endl;
        //cout<<ans.size()<<endl;
        assert(ans.size()==2*n-2);
    }
    else
    {
        if (t[n-1][n-1]<f[n-1][n-1])
        {
            cout<<t[n-1][n-1]<<endl;
            cout<<toString(tdir)<<endl;
        }
        else
        {
            cout<<f[n-1][n-1]<<endl;
            cout<<toString(fdir)<<endl;
        }
    }
    return 0;
}


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

using namespace std;

int tdiv(int n)
{
    int cnt=0;
    while (n && n%2==0) n/=2, cnt++;

    return cnt;
}

int fdiv(int n)
{
    int cnt=0;
    while (n && n%5==0) n/=5, cnt++;

    return cnt;
}

void printv(vector<vector<int> > t, vector<vector<int> > f)
{
    for (int i=0; i<t.size(); i++)
    {
        for (int j=0; j<t.size(); j++) cout<<t[i][j]<<","<<f[i][j]<<"\t"; cout<<endl;
    }
    cout<<endl;
}

string toString(vector<vector<bool> > &dir)
{
    const int left  = false;
    const int up    = true;

    vector<char> dirStr = {'R','D'};
    string ans;
    int n = dir.size();
    int i=n-1, j=n-1;
    while (i>0 || j>0)
    {
        ans.push_back(dirStr[dir[i][j]]);
        if (i==0) j--;
        else if (j==0) i--;
        else
        {
            if (dir[i][j]==up) i--;
            else j--;
        }
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

int main()
{
    int n;
    cin>>n;
    vector<vector<int> > t(n, vector<int> (n)), f(n, vector<int> (n));
    int x=-1, y=-1;
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            int a;
            cin>>a;
            f[i][j] = fdiv(a);
            t[i][j] = tdiv(a);

            if (a==0)
            {
                x=i;
                y=j;
            }
        }
    }

    const int left  = false;
    const int up    = true;

    //printv(t,f);

    vector<vector<bool> > tdir(n, vector<bool> (n,false)),fdir(n, vector<bool> (n,false));
    for (int i=1; i<n; i++) tdir[i][0]=up, fdir[i][0]=up;
    for (int i=1; i<n; i++)
    {
        t[i][0]+=t[i-1][0];
        f[i][0]+=f[i-1][0];

        t[0][i]+=t[0][i-1];
        f[0][i]+=f[0][i-1];
    }

    //printv(t,f);

    for (int i=1; i<n; i++)
    {
        for (int j=1; j<n; j++)
        {
            if (t[i-1][j]<t[i][j-1])
            {
                t[i][j]+=t[i-1][j];
                tdir[i][j]=up;
            }
            else
            {
                t[i][j]+=t[i][j-1];
                tdir[i][j]=left;
            }

            if (f[i-1][j]<f[i][j-1])
            {
                f[i][j]+=f[i-1][j];
                fdir[i][j]=up;
            }
            else
            {
                f[i][j]+=f[i][j-1];
                fdir[i][j]=left;
            }
        }
        //cout<<"-------------"<<endl;
        //printv(t,f);
    }

    if (x!=-1)
    {
        string ans;
        for (int i=1; i<=x; i++) ans.push_back('R');
        for (int i=1; i<=y; i++) ans.push_back('D');
        for (int i=x+1; i<n; i++) ans.push_back('R');
        for (int i=y+1; i<n; i++) ans.push_back('D');
        cout<<"1"<<endl;
        cout<<ans<<endl;
    }
    else
    {
        if (t[n-1][n-1]<f[n-1][n-1])
        {
            cout<<t[n-1][n-1]<<endl;
            cout<<toString(tdir)<<endl;
        }
        else
        {
            cout<<f[n-1][n-1]<<endl;
            cout<<toString(fdir)<<endl;
        }
    }
    return 0;
}


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

using namespace std;

int div(int n)
{
    int fcnt=0;
    while (n%5==0) n/=5, fcnt++;

    int tcnt=0;
    while (n%2==0) n/=2, tcnt++;

    return min(tcnt,fcnt);
}

int main()
{
    int n;
    cin>>n;
    vector<vector<int> > d(n, vector<int> (n));
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            int a;
            cin>>a;
            d[i][j] = div(a);
        }
    }

    const int left  = false;
    const int up    = true;

    vector<vector<bool> > dir(n, vector<bool> (n,false));
    for (int i=1; i<n; i++) dir[i][0]=up;

    for (int i=1; i<n; i++)
    {
        for (int j=1; j<n; j++)
        {
            if (d[i-1][j]>d[i][j-1])
            {
                d[i][j]=d[i-1][j];
                dir[i][j]=up;
            }
            else
            {
                d[i][j]=d[i][j-1];
                dir[i][j]=left;
            }
        }
    }

    vector<char> dirStr = {'R','D'};
    string ans;
    int i=n-1, j=n-1;
    while (i>0 || j>0)
    {
        ans.push_back(dirStr[dir[i][j]]);
        if (i==0) j--;
        else if (j==0) i--;
        else
        {
            if (dir[i][j]==up) i--;
            else j--;
        }
    }

    reverse(ans.begin(), ans.end());
    cout<<d[n-1][n-1]<<endl;
    cout<<ans<<endl;

    return 0;
}


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

using namespace std;

int tdiv(int n)
{
    int cnt=0;
    while (n%2==0) n/=2, cnt++;

    return cnt;
}

int fdiv(int n)
{
    int cnt=0;
    while (n%5==0) n/=5, cnt++;

    return cnt;
}

string toString(vector<vector<bool> > &dir)
{
    const int left  = false;
    const int up    = true;

    vector<char> dirStr = {'R','D'};
    string ans;
    int n = dir.size();
    int i=n-1, j=n-1;
    int cnt=0;
    while (i>0 || j>0)
    {
        assert(cnt<2*n+10);
        cnt++;
        ans.push_back(dirStr[dir[i][j]]);
        if (i==0) j--;
        else if (j==0) i--;
        else
        {
            if (dir[i][j]==up) i--;
            else j--;
        }
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

int main()
{
    int n;
    scanf("%d",&n);
    vector<vector<int> > t(n, vector<int> (n)), f(n, vector<int> (n));
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            int a;
            scanf("%d",&a);
            f[i][j] = fdiv(a);
            t[i][j] = tdiv(a);
        }
    }

    const int left  = false;
    const int up    = true;

    //printv(t,f);

    vector<vector<bool> > tdir(n, vector<bool> (n,false)),fdir(n, vector<bool> (n,false));
    for (int i=1; i<n; i++) tdir[i][0]=up, fdir[i][0]=up;
    for (int i=1; i<n; i++)
    {
        t[i][0]+=t[i-1][0];
        f[i][0]+=f[i-1][0];

        t[0][i]+=t[0][i-1];
        f[0][i]+=f[0][i-1];
    }

    //printv(t,f);

    for (int i=1; i<n; i++)
    {
        for (int j=1; j<n; j++)
        {
            if (t[i-1][j]<t[i][j-1])
            {
                t[i][j]+=t[i-1][j];
                tdir[i][j]=up;
            }
            else
            {
                t[i][j]+=t[i][j-1];
                tdir[i][j]=left;
            }

            if (f[i-1][j]<f[i][j-1])
            {
                f[i][j]+=f[i-1][j];
                fdir[i][j]=up;
            }
            else
            {
                f[i][j]+=f[i][j-1];
                fdir[i][j]=left;
            }
        }
        //cout<<"-------------"<<endl;
        //printv(t,f);
    }

    if (t[n-1][n-1]<f[n-1][n-1])
    {
        cout<<t[n-1][n-1]<<endl;
        cout<<toString(tdir)<<endl;
    }
    else
    {
        cout<<f[n-1][n-1]<<endl;
        cout<<toString(fdir)<<endl;
    }
    return 0;
}
/*
6
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

*/


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

using namespace std;

int tdiv(int n)
{
    int cnt=0;
    while (n%2==0) n/=2, cnt++;

    return cnt;
}

int fdiv(int n)
{
    int cnt=0;
    while (n%5==0) n/=5, cnt++;

    return cnt;
}

const int dirLeft  = false;
const int dirUp    = true;
vector<char> dirStr = {'R','D'};

void print(vector<vector<bool> > &dir, int i, int j)
{
    if (i>0 || j>0)
    {
        if (i==0) print(dir, i, j-1);
        else if (j==0) print(dir, i-1, j);
        else
        {
            if (dir[i][j]==dirUp) print(dir, i-1, j);
            else print(dir, i, j-1);
        }
        printf("%c",dirStr[dir[i][j]]);
    }
}

int main()
{
    int n;
    scanf("%d",&n);
    vector<vector<int> > t(n, vector<int> (n)), f(n, vector<int> (n));
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            int a;
            scanf("%d",&a);
            f[i][j] = fdiv(a);
            t[i][j] = tdiv(a);
        }
    }

    vector<vector<bool> > tdir(n, vector<bool> (n,dirLeft)),fdir(n, vector<bool> (n,dirLeft));
    for (int i=1; i<n; i++) tdir[i][0]=dirUp, fdir[i][0]=dirUp;
    for (int i=1; i<n; i++)
    {
        t[i][0]+=t[i-1][0];
        f[i][0]+=f[i-1][0];

        t[0][i]+=t[0][i-1];
        f[0][i]+=f[0][i-1];
    }

    //printv(t,f);

    for (int i=1; i<n; i++)
    {
        for (int j=1; j<n; j++)
        {
            if (t[i-1][j]<t[i][j-1])
            {
                t[i][j]+=t[i-1][j];
                tdir[i][j]=dirUp;
            }
            else
            {
                t[i][j]+=t[i][j-1];
                tdir[i][j]=dirLeft;
            }

            if (f[i-1][j]<f[i][j-1])
            {
                f[i][j]+=f[i-1][j];
                fdir[i][j]=dirUp;
            }
            else
            {
                f[i][j]+=f[i][j-1];
                fdir[i][j]=dirLeft;
            }
        }
        //cout<<"-------------"<<endl;
        //printv(t,f);
    }

    if (t[n-1][n-1]<f[n-1][n-1])
    {
        printf("%d\n",t[n-1][n-1]);
        print(tdir, n-1, n-1);
        printf("\n");
    }
    else
    {
        printf("%d\n",f[n-1][n-1]);
        print(fdir, n-1, n-1);
        printf("\n");
    }
    return 0;
}
/*
6
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

*/


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

using namespace std;

int tdiv(int n)
{
    int cnt=0;
    while (n%2==0) n/=2, cnt++;

    return cnt;
}

int fdiv(int n)
{
    int cnt=0;
    while (n%5==0) n/=5, cnt++;

    return cnt;
}

string toString(vector<vector<bool> > &dir)
{
    const int left  = false;
    const int up    = true;

    vector<char> dirStr = {'R','D'};
    string ans;
    int n = dir.size();
    int i=n-1, j=n-1;
    int cnt=0;
    while (i>0 || j>0)
    {
        assert(cnt<2*n+10);
        cnt++;
        ans.push_back(dirStr[dir[i][j]]);
        if (i==0) j--;
        else if (j==0) i--;
        else
        {
            if (dir[i][j]==up) i--;
            else j--;
        }
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

int main()
{
    int n;
    scanf("%d",&n);
    vector<vector<int> > t(n, vector<int> (n)), f(n, vector<int> (n));
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            int a;
            scanf("%d",&a);
            f[i][j] = fdiv(a);
            t[i][j] = tdiv(a);
        }
    }

    const int left  = false;
    const int up    = true;

    //printv(t,f);

    vector<vector<bool> > tdir(n, vector<bool> (n,false)),fdir(n, vector<bool> (n,false));
    for (int i=1; i<n; i++) tdir[i][0]=up, fdir[i][0]=up;
    for (int i=1; i<n; i++)
    {
        t[i][0]+=t[i-1][0];
        f[i][0]+=f[i-1][0];

        t[0][i]+=t[0][i-1];
        f[0][i]+=f[0][i-1];
    }

    //printv(t,f);

    for (int i=1; i<n; i++)
    {
        for (int j=1; j<n; j++)
        {
            if (t[i-1][j]<t[i][j-1])
            {
                t[i][j]+=t[i-1][j];
                tdir[i][j]=up;
            }
            else
            {
                t[i][j]+=t[i][j-1];
                tdir[i][j]=left;
            }

            if (f[i-1][j]<f[i][j-1])
            {
                f[i][j]+=f[i-1][j];
                fdir[i][j]=up;
            }
            else
            {
                f[i][j]+=f[i][j-1];
                fdir[i][j]=left;
            }
        }
        //cout<<"-------------"<<endl;
        //printv(t,f);
    }

    if (t[n-1][n-1]<f[n-1][n-1])
    {
        printf("%d\n",t[n-1][n-1]);
        printf("%s\n",toString(tdir).c_str());
    }
    else
    {
        printf("%d\n",f[n-1][n-1]);
        printf("%s\n",toString(fdir).c_str());
    }
    return 0;
}
/*
6
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

*/


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

using namespace std;

int tdiv(int n)
{
    int cnt=0;
    while (n%2==0) n/=2, cnt++;

    return cnt;
}

int fdiv(int n)
{
    int cnt=0;
    while (n%5==0) n/=5, cnt++;

    return cnt;
}

void printv(vector<vector<int> > t, vector<vector<int> > f)
{
    for (int i=0; i<t.size(); i++)
    {
        for (int j=0; j<t.size(); j++) cout<<t[i][j]<<","<<f[i][j]<<"\t"; cout<<endl;
    }
    cout<<endl;
}

int main()
{
    int n;
    cin>>n;
    vector<vector<int> > t(n, vector<int> (n)), f(n, vector<int> (n));
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            int a;
            cin>>a;
            f[i][j] = fdiv(a);
            t[i][j] = tdiv(a);
        }
    }

    const int left  = false;
    const int up    = true;

    //printv(t,f);

    vector<vector<bool> > dir(n, vector<bool> (n,false));
    for (int i=1; i<n; i++) dir[i][0]=up;
    for (int i=1; i<n; i++)
    {
        t[i][0]+=t[i-1][0];
        f[i][0]+=f[i-1][0];

        t[0][i]+=t[0][i-1];
        f[0][i]+=f[0][i-1];
    }

    //printv(t,f);

    for (int i=1; i<n; i++)
    {
        for (int j=1; j<n; j++)
        {
            //cout<<t[i][j]<<","<<f[i][j]<<" "<<t[i-1][j]
            if (min(t[i-1][j]+t[i][j],f[i-1][j]+f[i][j])<min(t[i][j-1]+t[i][j],f[i][j-1]+f[i][j]))
            {
                t[i][j]+=t[i-1][j];
                f[i][j]+=f[i-1][j];
                dir[i][j]=up;
            }
            else
            {
                t[i][j]+=t[i][j-1];
                f[i][j]+=f[i][j-1];
                dir[i][j]=left;
            }
            //cout<<"----------------"<<endl;
            //printv(t,f);
        }
        //cout<<"-------------"<<endl;
        //printv(t,f);
    }

    vector<char> dirStr = {'R','D'};
    string ans;
    int i=n-1, j=n-1;
    while (i>0 || j>0)
    {
        ans.push_back(dirStr[dir[i][j]]);
        if (i==0) j--;
        else if (j==0) i--;
        else
        {
            if (dir[i][j]==up) i--;
            else j--;
        }
    }

    //printv(t,f);
    reverse(ans.begin(), ans.end());
    cout<<min(t[n-1][n-1],f[n-1][n-1])<<endl;
    cout<<ans<<endl;

    return 0;
}
/*
3
4 10 5
10 9 4
6 5 3

2 1 0
1 0 2
1 0 0

0 1 1
1 0 0
0 1 0

*/


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

using namespace std;

int tdiv(int n)
{
    int cnt=0;
    while (n%2==0) n/=2, cnt++;

    return cnt;
}

int fdiv(int n)
{
    int cnt=0;
    while (n%5==0) n/=5, cnt++;

    return cnt;
}

string toString(vector<vector<bool> > &dir)
{
    const int left  = false;
    const int up    = true;

    vector<char> dirStr = {'R','D'};
    string ans;
    int n = dir.size();
    int i=n-1, j=n-1;
    int cnt=0;
    while (i>0 || j>0)
    {
        assert(cnt<n+10);
        cnt++;
        ans.push_back(dirStr[dir[i][j]]);
        if (i==0) j--;
        else if (j==0) i--;
        else
        {
            if (dir[i][j]==up) i--;
            else j--;
        }
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

int main()
{
    int n;
    scanf("%d",&n);
    vector<vector<int> > t(n, vector<int> (n)), f(n, vector<int> (n));
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            int a;
            scanf("%d",&a);
            f[i][j] = fdiv(a);
            t[i][j] = tdiv(a);
        }
    }

    const int left  = false;
    const int up    = true;

    //printv(t,f);

    vector<vector<bool> > tdir(n, vector<bool> (n,false)),fdir(n, vector<bool> (n,false));
    for (int i=1; i<n; i++) tdir[i][0]=up, fdir[i][0]=up;
    for (int i=1; i<n; i++)
    {
        t[i][0]+=t[i-1][0];
        f[i][0]+=f[i-1][0];

        t[0][i]+=t[0][i-1];
        f[0][i]+=f[0][i-1];
    }

    //printv(t,f);

    for (int i=1; i<n; i++)
    {
        for (int j=1; j<n; j++)
        {
            if (t[i-1][j]<t[i][j-1])
            {
                t[i][j]+=t[i-1][j];
                tdir[i][j]=up;
            }
            else
            {
                t[i][j]+=t[i][j-1];
                tdir[i][j]=left;
            }

            if (f[i-1][j]<f[i][j-1])
            {
                f[i][j]+=f[i-1][j];
                fdir[i][j]=up;
            }
            else
            {
                f[i][j]+=f[i][j-1];
                fdir[i][j]=left;
            }
        }
        //cout<<"-------------"<<endl;
        //printv(t,f);
    }

    if (t[n-1][n-1]<f[n-1][n-1])
    {
        cout<<t[n-1][n-1]<<endl;
        cout<<toString(tdir)<<endl;
    }
    else
    {
        cout<<f[n-1][n-1]<<endl;
        cout<<toString(fdir)<<endl;
    }
    return 0;
}
/*
6
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

*/


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

using namespace std;

int tdiv(int n)
{
    int cnt=0;
    while (n%2==0) n/=2, cnt++;

    return cnt;
}

int fdiv(int n)
{
    int cnt=0;
    while (n%5==0) n/=5, cnt++;

    return cnt;
}

void printv(vector<vector<int> > t, vector<vector<int> > f)
{
    for (int i=0; i<t.size(); i++)
    {
        for (int j=0; j<t.size(); j++) cout<<t[i][j]<<","<<f[i][j]<<"\t"; cout<<endl;
    }
    cout<<endl;
}

string toString(vector<vector<bool> > &dir)
{
    const int left  = false;
    const int up    = true;

    vector<char> dirStr = {'R','D'};
    string ans;
    int n = dir.size();
    int i=n-1, j=n-1;
    while (i>0 || j>0)
    {
        ans.push_back(dirStr[dir[i][j]]);
        if (i==0) j--;
        else if (j==0) i--;
        else
        {
            if (dir[i][j]==up) i--;
            else j--;
        }
    }
    reverse(ans.begin(), ans.end());
    return ans;
}

int main()
{
    int n;
    cin>>n;
    vector<vector<int> > t(n, vector<int> (n)), f(n, vector<int> (n));
    for (int i=0; i<n; i++)
    {
        for (int j=0; j<n; j++)
        {
            int a;
            cin>>a;
            f[i][j] = fdiv(a);
            t[i][j] = tdiv(a);
        }
    }

    const int left  = false;
    const int up    = true;

    //printv(t,f);

    vector<vector<bool> > tdir(n, vector<bool> (n,false)),fdir(n, vector<bool> (n,false));
    for (int i=1; i<n; i++) tdir[i][0]=up, fdir[i][0]=up;
    for (int i=1; i<n; i++)
    {
        t[i][0]+=t[i-1][0];
        f[i][0]+=f[i-1][0];

        t[0][i]+=t[0][i-1];
        f[0][i]+=f[0][i-1];
    }

    //printv(t,f);

    for (int i=1; i<n; i++)
    {
        for (int j=1; j<n; j++)
        {
            if (t[i-1][j]<t[i][j-1])
            {
                t[i][j]+=t[i-1][j];
                tdir[i][j]=up;
            }
            else
            {
                t[i][j]+=t[i][j-1];
                tdir[i][j]=left;
            }

            if (f[i-1][j]<f[i][j-1])
            {
                f[i][j]+=f[i-1][j];
                fdir[i][j]=up;
            }
            else
            {
                f[i][j]+=f[i][j-1];
                fdir[i][j]=left;
            }
        }
        //cout<<"-------------"<<endl;
        //printv(t,f);
    }

    if (t[n-1][n-1]<f[n-1][n-1])
    {
        cout<<t[n-1][n-1]<<endl;
        cout<<toString(tdir)<<endl;
    }
    else
    {
        cout<<f[n-1][n-1]<<endl;
        cout<<toString(fdir)<<endl;
    }
    return 0;
}
/*
6
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

*/


// C header files
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>

// C++ header files
#include <map>
#include <set>
#include <deque>
#include <limits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

// input / output
#include <fstream>
#include <iomanip>
#include <iostream>

using namespace std;

// C++ types
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned short int usi;

// pairs
typedef pair <ll, ll> pll;
typedef pair <int, int> pi;
typedef pair <double, double> pd;

// single vectors
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <char> vc;
typedef vector <double> vd;
typedef vector <string> vs;
typedef vector <long long> vll;

// double vectors
typedef vector < vector <int> > vvi;
typedef vector < vector <bool> > vvb;
typedef vector < vector <char> > vvc;
typedef vector < vector <double> > vvd;
typedef vector < vector <string> > vvs;
typedef vector < pair <int, int> > vpi;
typedef vector < pair <double, double> > vpd;

// macroses
#define ft first
#define sc second
#define len(s) s.length()
#define left(i) 2*(i) + 1
#define right(i) 2*(i) + 2
#define prt(i) ((i)-1) / 2
#define maxV(type) numeric_limits<type>::max()
#define minV(type) numeric_limits<type>::min()
#define sf(a, b, i) for(size_t (i)=(a); (i) < (b); (i)++)

int main()
{
    //freopen("qsort.in", "r", stdin);
    //freopen("qsort.out", "w", stdout);
    int n, x;
    scanf("%d", &n);
    bool p[1000][1000];
    int a[1000][1000][2];
    int ans[1000][1000][2];
    for(int i=0; i < n; i++)
        for(int j=0; j < n; j++) {
            scanf("%d", &x);
            a[i][j][0] = 0;
            a[i][j][1] = 0;
            while(x % 2 == 0) {
                a[i][j][0]++;
                x /= 2;
            }
            while(x % 5 == 0) {
                a[i][j][1]++;
                x /= 5;
            }
        }
    ans[0][0][0] = a[0][0][0];
    ans[0][0][1] = a[0][0][1];
    for(int i=0; i < n; i++)
        for(int j=0; j < n; j++)
            if(i || j) {
            int c = 1000000000, d = 1000000000;
            if(i) {
                    p[i][j] = 0;
                    c = ans[i-1][j][0];
                    d = ans[i-1][j][1];
                    }
            if(j)
                if(min((a[i][j][0]+c), (a[i][j][1]+d)) > min((a[i][j][0]+ans[i][j-1][0]), (a[i][j][1]+ans[i][j-1][1]))) {
                    p[i][j] = 1;
                    c = ans[i][j-1][0];
                    d = ans[i][j-1][1];
                    }
            ans[i][j][0] = a[i][j][0] + c;
            ans[i][j][1] = a[i][j][1] + d;
        }
    int i=n-1, j=n-1;
    vector <bool> way;
    while(i || j) {
        way.push_back(p[i][j]);
        if(p[i][j])
            j--;
        else
            i--;
    }
    reverse(way.begin(), way.end());
    printf("%d\n", min(ans[n-1][n-1][0], ans[n-1][n-1][1]));
    for(int i=0; i < way.size(); i++)
        cout << (way[i] ? "R" : "D");
    //system("pause");
    return 0;
}


// C header files
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>

// C++ header files
#include <map>
#include <set>
#include <deque>
#include <limits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

// input / output
#include <fstream>
#include <iomanip>
#include <iostream>

using namespace std;

// C++ types
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned short int usi;

// pairs
typedef pair <ll, ll> pll;
typedef pair <int, int> pi;
typedef pair <double, double> pd;

// single vectors
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <char> vc;
typedef vector <double> vd;
typedef vector <string> vs;
typedef vector <long long> vll;

// double vectors
typedef vector < vector <int> > vvi;
typedef vector < vector <bool> > vvb;
typedef vector < vector <char> > vvc;
typedef vector < vector <double> > vvd;
typedef vector < vector <string> > vvs;
typedef vector < pair <int, int> > vpi;
typedef vector < pair <double, double> > vpd;

// macroses
#define ft first
#define sc second
#define len(s) s.length()
#define left(i) 2*(i) + 1
#define right(i) 2*(i) + 2
#define prt(i) ((i)-1) / 2
#define maxV(type) numeric_limits<type>::max()
#define minV(type) numeric_limits<type>::min()
#define sf(a, b, i) for(size_t (i)=(a); (i) < (b); (i)++)

int main()
{
    //freopen("qsort.in", "r", stdin);
    //freopen("qsort.out", "w", stdout);
    int n, x;
    scanf("%d", &n);
    bool p[1000][1000];
    ll a[1000][1000][2];
    ll ans[1000][1000][2];
    for(int i=0; i < n; i++)
        for(int j=0; j < n; j++) {
            scanf("%d", &x);
            a[i][j][0] = 0;
            a[i][j][1] = 0;
            if(x != 0) {
            while(x % 2 == 0) {
                a[i][j][0]++;
                x /= 2;
            }
            while(x % 5 == 0) {
                a[i][j][1]++;
                x /= 5;
            }
            }
        }
    ans[0][0][0] = a[0][0][0];
    ans[0][0][1] = a[0][0][1];
    for(int i=0; i < n; i++)
        for(int j=0; j < n; j++)
            if(i || j) {
            ll q = a[i][j][0];
            ll w = a[i][j][1];
            ll c = 1000000, d = 1000000;
            if(i) {
                    p[i][j] = 0;
                    c = ans[i-1][j][0];
                    d = ans[i-1][j][1];
                    }
            if(j)
                if(min((q+c), (w+d)) > min((q+ans[i][j-1][0]), (w+ans[i][j-1][1]))) {
                    p[i][j] = 1;
                    c = ans[i][j-1][0];
                    d = ans[i][j-1][1];
                    }
            ans[i][j][0] = q + c;
            ans[i][j][1] = w + d;
        }
    int i=n-1, j=n-1;
    vector <bool> way;
    while(i || j) {
        way.push_back(p[i][j]);
        if(p[i][j])
            j--;
        else
            i--;
    }
    reverse(way.begin(), way.end());
    printf("%d\n", min(ans[n-1][n-1][0], ans[n-1][n-1][1]));
    for(int i=0; i < way.size(); i++)
        cout << (way[i] ? "R" : "D");
    //system("pause");
    return 0;
}


// C header files
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>

// C++ header files
#include <map>
#include <set>
#include <deque>
#include <limits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

// input / output
#include <fstream>
#include <iomanip>
#include <iostream>

using namespace std;

// C++ types
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned short int usi;

// pairs
typedef pair <ll, ll> pll;
typedef pair <int, int> pi;
typedef pair <double, double> pd;

// single vectors
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <char> vc;
typedef vector <double> vd;
typedef vector <string> vs;
typedef vector <long long> vll;

// double vectors
typedef vector < vector <int> > vvi;
typedef vector < vector <bool> > vvb;
typedef vector < vector <char> > vvc;
typedef vector < vector <double> > vvd;
typedef vector < vector <string> > vvs;
typedef vector < pair <int, int> > vpi;
typedef vector < pair <double, double> > vpd;

// macroses
#define ft first
#define sc second
#define len(s) s.length()
#define left(i) 2*(i) + 1
#define right(i) 2*(i) + 2
#define prt(i) ((i)-1) / 2
#define maxV(type) numeric_limits<type>::max()
#define minV(type) numeric_limits<type>::min()
#define sf(a, b, i) for(size_t (i)=(a); (i) < (b); (i)++)

int main()
{
    //freopen("qsort.in", "r", stdin);
    //freopen("qsort.out", "w", stdout);
    int n, x;
    scanf("%d", &n);
    bool p[1000][1000];
    int a[1000][1000][2];
    int ans[1000][1000][2];
    for(int i=0; i < n; i++)
        for(int j=0; j < n; j++) {
            scanf("%d", &x);
            a[i][j][0] = 0;
            a[i][j][1] = 0;
            while(x % 2 == 0) {
                a[i][j][0]++;
                x /= 2;
            }
            while(x % 5 == 0) {
                a[i][j][1]++;
                x /= 5;
            }
        }
    ans[0][0][0] = a[0][0][0];
    ans[0][0][1] = a[0][0][1];
    for(int i=0; i < n; i++)
        for(int j=0; j < n; j++)
            if(i || j) {
            int q = a[i][j][0];
            int w = a[i][j][1];
            int c = 1000000, d = 1000000;
            if(i) {
                    p[i][j] = 0;
                    c = ans[i-1][j][0];
                    d = ans[i-1][j][1];
                    }
            if(j)
                if(min((q+c), (w+d)) > min((q+ans[i][j-1][0]), (w+ans[i][j-1][1]))) {
                    p[i][j] = 1;
                    c = ans[i][j-1][0];
                    d = ans[i][j-1][1];
                    }
            ans[i][j][0] = q + c;
            ans[i][j][1] = w + d;
        }
    int i=n-1, j=n-1;
    vector <bool> way;
    while(i || j) {
        way.push_back(p[i][j]);
        if(p[i][j])
            j--;
        else
            i--;
    }
    //reverse(way.begin(), way.end());
    printf("%d\n", min(ans[n-1][n-1][0], ans[n-1][n-1][1]));
        cout << (way[i] ? "R" : "D");
    //system("pause");
    return 0;
}


// C header files
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>

// C++ header files
#include <map>
#include <set>
#include <deque>
#include <limits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

// input / output
#include <fstream>
#include <iomanip>
#include <iostream>

using namespace std;

// C++ types
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned short int usi;

// pairs
typedef pair <ll, ll> pll;
typedef pair <int, int> pi;
typedef pair <double, double> pd;

// single vectors
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <char> vc;
typedef vector <double> vd;
typedef vector <string> vs;
typedef vector <long long> vll;

// double vectors
typedef vector < vector <int> > vvi;
typedef vector < vector <bool> > vvb;
typedef vector < vector <char> > vvc;
typedef vector < vector <double> > vvd;
typedef vector < vector <string> > vvs;
typedef vector < pair <int, int> > vpi;
typedef vector < pair <double, double> > vpd;

// macroses
#define ft first
#define sc second
#define len(s) s.length()
#define left(i) 2*(i) + 1
#define right(i) 2*(i) + 2
#define prt(i) ((i)-1) / 2
#define maxV(type) numeric_limits<type>::max()
#define minV(type) numeric_limits<type>::min()
#define sf(a, b, i) for(size_t (i)=(a); (i) < (b); (i)++)

int main()
{
    //freopen("qsort.in", "r", stdin);
    //freopen("qsort.out", "w", stdout);
    int n, x;
    scanf("%d", &n);
    bool p[1000][1000];
    int a[1000][1000][2];
    int ans[1000][1000][2];
    for(int i=0; i < n; i++)
        for(int j=0; j < n; j++) {
            scanf("%d", &x);
            a[i][j][0] = 0;
            a[i][j][1] = 0;
            while(x % 2 == 0) {
                a[i][j][0]++;
                x /= 2;
            }
            while(x % 5 == 0) {
                a[i][j][1]++;
                x /= 5;
            }
        }
    ans[0][0][0] = a[0][0][0];
    ans[0][0][1] = a[0][0][1];
    for(int i=0; i < n; i++)
        for(int j=0; j < n; j++)
            if(i || j) {
            int q = a[i][j][0];
            int w = a[i][j][1];
            int c = 1000000, d = 1000000;
            if(i) {
                    p[i][j] = 0;
                    c = ans[i-1][j][0];
                    d = ans[i-1][j][1];
                    }
            if(j)
                if(min((q+c), (w+d)) > min((q+ans[i][j-1][0]), (w+ans[i][j-1][1]))) {
                    p[i][j] = 1;
                    c = ans[i][j-1][0];
                    d = ans[i][j-1][1];
                    }
            ans[i][j][0] = q + c;
            ans[i][j][1] = w + d;
        }
    int i=n-1, j=n-1;
    vector <bool> way;
    while(i || j) {
        way.push_back(p[i][j]);
        if(p[i][j])
            j--;
        else
            i--;
    }
    reverse(way.begin(), way.end());
    printf("%d\n", min(ans[n-1][n-1][0], ans[n-1][n-1][1]));
    for(int i=0; i < way.size(); i++)
        cout << (way[i] ? "R" : "D");
    //system("pause");
    return 0;
}


// C header files
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>

// C++ header files
#include <map>
#include <set>
#include <deque>
#include <limits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

// input / output
#include <fstream>
#include <iomanip>
#include <iostream>

using namespace std;

// C++ types
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned short int usi;

// pairs
typedef pair <ll, ll> pll;
typedef pair <int, int> pi;
typedef pair <double, double> pd;

// single vectors
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <char> vc;
typedef vector <double> vd;
typedef vector <string> vs;
typedef vector <long long> vll;

// double vectors
typedef vector < vector <int> > vvi;
typedef vector < vector <bool> > vvb;
typedef vector < vector <char> > vvc;
typedef vector < vector <double> > vvd;
typedef vector < vector <string> > vvs;
typedef vector < pair <int, int> > vpi;
typedef vector < pair <double, double> > vpd;

// macroses
#define ft first
#define sc second
#define len(s) s.length()
#define left(i) 2*(i) + 1
#define right(i) 2*(i) + 2
#define prt(i) ((i)-1) / 2
#define maxV(type) numeric_limits<type>::max()
#define minV(type) numeric_limits<type>::min()
#define sf(a, b, i) for(size_t (i)=(a); (i) < (b); (i)++)

int main()
{
    //freopen("qsort.in", "r", stdin);
    //freopen("qsort.out", "w", stdout);
    int n, x;
    scanf("%d", &n);
    bool p[1000][1000];
    int a[1000][1000][2];
    int ans[1000][1000][2];
    for(int i=0; i < n; i++)
        for(int j=0; j < n; j++) {
            scanf("%d", &x);
            a[i][j][0] = 0;
            a[i][j][1] = 0;
            if(x) {
            while(x % 2 == 0) {
                a[i][j][0]++;
                x /= 2;
            }
            while(x % 5 == 0) {
                a[i][j][1]++;
                x /= 5;
            }
            }
        }
    ans[0][0][0] = a[0][0][0];
    ans[0][0][1] = a[0][0][1];
    for(int i=0; i < n; i++)
        for(int j=0; j < n; j++)
            if(i || j) {
            int c = 1000000, d = 1000000;
            if(i) {
                    p[i][j] = 0;
                    c = ans[i-1][j][0];
                    d = ans[i-1][j][1];
                    }
            if(j)
                if(min((a[i][j][0]+c), (a[i][j][1]+d)) > min((a[i][j][0]+ans[i][j-1][0]), (a[i][j][1]+ans[i][j-1][1]))) {
                    p[i][j] = 1;
                    c = ans[i][j-1][0];
                    d = ans[i][j-1][1];
                    }
            ans[i][j][0] = a[i][j][0] + c;
            ans[i][j][1] = a[i][j][1] + d;
        }
    int i=n-1, j=n-1;
    vector <bool> way;
    while(i || j) {
        way.push_back(p[i][j]);
        if(p[i][j])
            j--;
        else
            i--;
    }
    reverse(way.begin(), way.end());
    cout << min(ans[n-1][n-1][0], ans[n-1][n-1][1]) << endl;
    for(int i=0; i < way.size(); i++)
        cout << (way[i] ? "R" : "D");
    //system("pause");
    return 0;
}