#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define read(a) for(int i = 0; i < n; i++) cin >> a[i];
#define print(a) for(int i = 0; i < n; i++) cout << a[i] << " ";
#define pb push_back
#define pql priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define pqlv priority_queue<vi>
#define pqsv priority_queue<vi, vvi, greater<vi>>
#define endl '\n'
#define N 1234567
#define MOD 1000000007
vector<string> v;
int n, m;
int dist[101][101];
int d[101][101];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t--) {
memset(dist, -1, sizeof dist);
cin >> n >> m;
v.clear();
v.resize(n);
for(int i = 0; i < n; i++) {
cin >> v[i];
}
int x, y, c1, c2;
queue<vi> q;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(v[i][j] == 'M') {
q.push({ i, j, 0 });
}
if(v[i][j] == 'A') {
x = i; y = j;
}
}
}
c1 = x; c2 = y;
while(!q.empty()) {
auto f = q.front();
q.pop();
int x = f[0], y = f[1], steps = f[2];
if(x < 0 || x > n - 1 || y < 0 || y > m - 1 || v[x][y] == '#' || dist[x][y] != -1) {
continue;
}
dist[x][y] = steps;
vi dx = { 0, 0, -1, 1 };
vi dy = { -1, 1, 0, 0 };
for(int i = 0; i < 4; i++) {
int cx = x + dx[i], cy = y + dy[i];
q.push({ cx, cy, steps + 1 });
}
}
int cnt = 0;
string ret;
while(!q.empty()) q.pop();
q.push({ x, y, 0, 0 });
memset(d, -1, sizeof d);
bool ans = false;
// L => 0, R => 1, U => 2, D => 3
int p[n + 1][m + 1];
memset(p, 0, sizeof p);
while(!q.empty()) {
auto f = q.front();
q.pop();
int x = f[0], y = f[1], steps = f[2], dir = f[3];
if(x < 0 || x > n - 1 || y < 0 || y > m - 1 || v[x][y] == '#' || d[x][y] != -1 || (dist[x][y] >= 0 && dist[x][y] <= steps))
continue;
if(x == n - 1 || y == m - 1 || x == 0 || y == 0) {
p[x][y] = dir;
while(x != c1 || y != c2) {
cnt++;
if(p[x][y] == 0) ret += 'L', y++;
else if(p[x][y] == 1) ret += 'R', y--;
else if(p[x][y] == 2) ret += 'U', x++;
else ret += 'D', x--;
}
ans = true;
break;
}
d[x][y] = steps;
p[x][y] = dir;
vi dx = { 0, 0, -1, 1 };
vi dy = { -1, 1, 0, 0 };
for(int i = 0; i < 4; i++) {
int cx = x + dx[i], cy = y + dy[i];
q.push({ cx, cy, steps + 1, i });
}
}
if(ans) {
reverse(ret.begin(), ret.end());
cout << "YES" << endl << cnt << endl << ret;
}
else
cout << "NO";
cout << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAKI2RlZmluZSBpbnQgbG9uZyBsb25nIGludAojZGVmaW5lIHZpIHZlY3RvcjxpbnQ+CiNkZWZpbmUgdnZpIHZlY3Rvcjx2aT4KI2RlZmluZSByZWFkKGEpICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSBjaW4gPj4gYVtpXTsKI2RlZmluZSBwcmludChhKSAgZm9yKGludCBpID0gMDsgaSA8IG47IGkrKykgY291dCA8PCBhW2ldIDw8ICIgIjsKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBwcWwgcHJpb3JpdHlfcXVldWU8aW50PgojZGVmaW5lIHBxcyBwcmlvcml0eV9xdWV1ZTxpbnQsIHZpLCBncmVhdGVyPGludD4+CiNkZWZpbmUgcHFsdiBwcmlvcml0eV9xdWV1ZTx2aT4KI2RlZmluZSBwcXN2IHByaW9yaXR5X3F1ZXVlPHZpLCB2dmksIGdyZWF0ZXI8dmk+PgojZGVmaW5lIGVuZGwgJ1xuJwojZGVmaW5lIE4gMTIzNDU2NwojZGVmaW5lIE1PRCAxMDAwMDAwMDA3Cgp2ZWN0b3I8c3RyaW5nPiB2OwppbnQgbiwgbTsKCmludCBkaXN0WzEwMV1bMTAxXTsKaW50IGRbMTAxXVsxMDFdOwoKc2lnbmVkIG1haW4oKSB7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7IAogICAgY2luLnRpZSgwKTsgCiAgICBjb3V0LnRpZSgwKTsKICAgIGludCB0ID0gMTsKICAgIC8vIGNpbiA+PiB0OwogICAgd2hpbGUodC0tKSB7CiAgICAgICAgbWVtc2V0KGRpc3QsIC0xLCBzaXplb2YgZGlzdCk7CiAgICAgICAgY2luID4+IG4gPj4gbTsKICAgICAgICB2LmNsZWFyKCk7CiAgICAgICAgdi5yZXNpemUobik7CiAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgICAgICBjaW4gPj4gdltpXTsKICAgICAgICB9CiAgICAgICAgaW50IHgsIHksIGMxLCBjMjsKICAgICAgICBxdWV1ZTx2aT4gcTsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCBtOyBqKyspIHsKICAgICAgICAgICAgICAgIGlmKHZbaV1bal0gPT0gJ00nKSB7CiAgICAgICAgICAgICAgICAgICAgcS5wdXNoKHsgaSwgaiwgMCB9KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmKHZbaV1bal0gPT0gJ0EnKSB7CiAgICAgICAgICAgICAgICAgICAgeCA9IGk7IHkgPSBqOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGMxID0geDsgYzIgPSB5OwogICAgICAgIHdoaWxlKCFxLmVtcHR5KCkpIHsKICAgICAgICAgICAgYXV0byBmID0gcS5mcm9udCgpOwogICAgICAgICAgICBxLnBvcCgpOwogICAgICAgICAgICBpbnQgeCA9IGZbMF0sIHkgPSBmWzFdLCBzdGVwcyA9IGZbMl07CiAgICAgICAgICAgIGlmKHggPCAwIHx8IHggPiBuIC0gMSB8fCB5IDwgMCB8fCB5ID4gbSAtIDEgfHwgdlt4XVt5XSA9PSAnIycgfHwgZGlzdFt4XVt5XSAhPSAtMSkgewogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZGlzdFt4XVt5XSA9IHN0ZXBzOwogICAgICAgICAgICB2aSBkeCA9IHsgMCwgMCwgLTEsIDEgfTsKICAgICAgICAgICAgdmkgZHkgPSB7IC0xLCAxLCAwLCAwIH07CiAgICAgICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCA0OyBpKyspIHsKICAgICAgICAgICAgICAgIGludCBjeCA9IHggKyBkeFtpXSwgY3kgPSB5ICsgZHlbaV07CiAgICAgICAgICAgICAgICBxLnB1c2goeyBjeCwgY3ksIHN0ZXBzICsgMSB9KTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpbnQgY250ID0gMDsKICAgICAgICBzdHJpbmcgcmV0OwogICAgICAgIHdoaWxlKCFxLmVtcHR5KCkpICAgcS5wb3AoKTsKICAgICAgICBxLnB1c2goeyB4LCB5LCAwLCAwIH0pOwogICAgICAgIG1lbXNldChkLCAtMSwgc2l6ZW9mIGQpOwogICAgICAgIGJvb2wgYW5zID0gZmFsc2U7CiAgICAgICAgLy8gTCA9PiAwLCBSID0+IDEsIFUgPT4gMiwgRCA9PiAzCiAgICAgICAgaW50IHBbbiArIDFdW20gKyAxXTsKICAgICAgICBtZW1zZXQocCwgMCwgc2l6ZW9mIHApOwogICAgICAgIHdoaWxlKCFxLmVtcHR5KCkpIHsKICAgICAgICAgICAgYXV0byBmID0gcS5mcm9udCgpOwogICAgICAgICAgICBxLnBvcCgpOwogICAgICAgICAgICBpbnQgeCA9IGZbMF0sIHkgPSBmWzFdLCBzdGVwcyA9IGZbMl0sIGRpciA9IGZbM107CiAgICAgICAgICAgIGlmKHggPCAwIHx8IHggPiBuIC0gMSB8fCB5IDwgMCB8fCB5ID4gbSAtIDEgfHwgdlt4XVt5XSA9PSAnIycgfHwgZFt4XVt5XSAhPSAtMSB8fCAoZGlzdFt4XVt5XSA+PSAwICYmIGRpc3RbeF1beV0gPD0gc3RlcHMpKQogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIGlmKHggPT0gbiAtIDEgfHwgeSA9PSBtIC0gMSB8fCB4ID09IDAgfHwgeSA9PSAwKSB7CiAgICAgICAgICAgICAgICBwW3hdW3ldID0gZGlyOwogICAgICAgICAgICAgICAgd2hpbGUoeCAhPSBjMSB8fCB5ICE9IGMyKSB7CiAgICAgICAgICAgICAgICAgICAgY250Kys7CiAgICAgICAgICAgICAgICAgICAgaWYocFt4XVt5XSA9PSAwKSAgICByZXQgKz0gJ0wnLCB5Kys7CiAgICAgICAgICAgICAgICAgICAgZWxzZSBpZihwW3hdW3ldID09IDEpICAgcmV0ICs9ICdSJywgeS0tOwogICAgICAgICAgICAgICAgICAgIGVsc2UgaWYocFt4XVt5XSA9PSAyKSAgIHJldCArPSAnVScsIHgrKzsKICAgICAgICAgICAgICAgICAgICBlbHNlICAgIHJldCArPSAnRCcsIHgtLTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGFucyA9IHRydWU7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBkW3hdW3ldID0gc3RlcHM7CiAgICAgICAgICAgIHBbeF1beV0gPSBkaXI7CiAgICAgICAgICAgIHZpIGR4ID0geyAwLCAwLCAtMSwgMSB9OwogICAgICAgICAgICB2aSBkeSA9IHsgLTEsIDEsIDAsIDAgfTsKICAgICAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IDQ7IGkrKykgewogICAgICAgICAgICAgICAgaW50IGN4ID0geCArIGR4W2ldLCBjeSA9IHkgKyBkeVtpXTsKICAgICAgICAgICAgICAgIHEucHVzaCh7IGN4LCBjeSwgc3RlcHMgKyAxLCBpIH0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmKGFucykgewogICAgICAgICAgICByZXZlcnNlKHJldC5iZWdpbigpLCByZXQuZW5kKCkpOwogICAgICAgICAgICBjb3V0IDw8ICJZRVMiIDw8IGVuZGwgPDwgY250IDw8IGVuZGwgPDwgcmV0OwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgICAgIGNvdXQgPDwgIk5PIjsKICAgICAgICBjb3V0IDw8IGVuZGw7CiAgICB9CglyZXR1cm4gMDsKfQ==