#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef float flt;

#define for0(i, n) for(ll i=0; i<n; i++)
#define for1(i, n) for(ll i=1; i<=n; i++)
#define forab(i, a, b) for(ll i=a; i<=b; i++)
#define clr0(a) memset(a, 0, sizeof(a))

ll SubseqWidths(ll A[], ll n) {
    sort(A, A + n);
    ll pow2[n];
    pow2[0] = 1;
    for (ll i=1; i<n; ++i) {
        pow2[i] = (pow2[i - 1] * 2) % 998244353;
    }
    int ans = 0;
    for (ll i=0; i<n; ++i) {
        ans = (ans + (pow2[i] * pow2[n - 1 - i]) * A[i]) % 998244353;
    }
    for0(i, n) {
        ans += (A[i]*A[i]) % 998244353;
    }
    ans -= A[0];
    return ans;
}

void solve() {
    ll n;
    cin >> n;
    ll a[n+10];
    ll ans = 0;
    for0(i, n) {
        cin >> a[i];
        ans += (a[i]*a[i]) % 998244353;
    }
    //cout << SubseqWidths(a, n) << endl;;
    sort (a, a+n);
    ll mul[n+10];
    mul[0] = a[0];
    for1(i, n-1) {
        mul[i] = (2*mul[i-1] + a[i]) % 998244353;
    }
    //ll ans = 0;
    //for0(i, n) {
    //    cout << mul[i] << " ";
    //}
    //cout << endl;
    for0(i, n) {
        if (i>0) {
            ans += (a[i]*mul[i-1]) % 998244353;
        }
    }
    ans = ans % 998244353;
    cout << ans << endl;

}

void testcase() {
    ll t;
    cin >> t;
    while (t--) {
        solve();
    }
}

int main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //testcase();
    solve();

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
#include <list>
#include <type_traits>
#include<fstream>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()

int sy, sx;
uint32_t t[50][50];
int p[50][50];


struct State{
	char op;
	int prev_st;
	int y, x;
	int score;

	int sumy, sumx;
	int moment;

	long long vis[30];

	State(int sy, int sx, uint32_t t_id, int sc) {
		op = 'x';
		prev_st = -1;
		y = sy;
		x = sx;
		sumx = sumy = 0;
		score = sc;
		moment = 0;
		memset(vis, 0, sizeof(vis));
		vis[t_id / 64] |= 1LL << t_id % 64;
	}

	State(const State &st, int prev, char op, int dy,int dx) {
		*this = st;
		this->op = op;
		prev_st = prev;
		y += dy;
		x += dx;
		score += p[y][x];
		sumy += dy;
		sumx += dx;
		int a = min(sumx, sumy);
		int b = max(sumx, sumy);
		moment = b * b - a * a;
		uint32_t t_id = t[y][x];
		vis[t_id / 64] |= 1LL <<  t_id % 64;
	}
	State(const State& st, int prev) {
		*this = st;
		this->op = 'x';
		prev_st = prev;
		sumy = sumx = 0;
		moment = 0;
	}

	bool ok(int ny, int nx) const {
		if (0 <= ny && ny < 50 && 0 <= nx && nx < 50) {
			uint32_t t_id = t[ny][nx];
			return (vis[t_id / 64] >> t_id % 64 & 1) == 0;
		}
		return false;
	}

	bool operator<(const State& s) const { 
		int a = 10 * score + 2000 * moment;
		int b = 10 * s.score + 2000 * s.moment;
		return a > b;
	}
};


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);


#if defined(_MSC_VER)
	ifstream input("in.txt");
#else
	auto& input = cin;
#endif

	input >> sy >> sx;
	rep(i, 50)rep(j, 50)input >> t[i][j];
	rep(i, 50)rep(j, 50)input >> p[i][j];


	vector<vector<State>> sts;
	sts.emplace_back();
	sts.back().emplace_back(sy, sx, t[sy][sx], p[sy][sx]);

	rep(i, 1200) {
		if (sts.back().empty()) break;
		sts.emplace_back();
		//cerr << i << endl;

		sort(all(sts[i]), [](const State& a, const State& b) {return a.score > b.score; });
		sts[i].erase(unique(all(sts[i]), [](const State& a, const State& b) {return a.score == b.score; }), sts[i].end());
		int width = min<int>(1200, sts[i].size());
		nth_element(sts[i].begin(), sts[i].begin() + width, sts[i].end());
		

		rep(j, width) {
			const State& st = sts[i][j];
			if (st.ok(st.y - 1, st.x))
				sts.back().emplace_back(st, j, 'U', - 1, 0);
			if (st.ok(st.y + 1, st.x))
				sts.back().emplace_back(st, j, 'D', 1, 0);
			if (st.ok(st.y, st.x - 1))
				sts.back().emplace_back(st, j, 'L', 0, -1);
			if (st.ok(st.y, st.x + 1))
				sts.back().emplace_back(st, j, 'R', 0, 1);
			sts.back().emplace_back(st, j);

			//cerr << st.score << endl;
		}
	}

	int best_i = 0, best_j = 0, best_score = 0;
	rep(i, sts.size()){
		rep(j, sts[i].size()) {
			if (best_score < sts[i][j].score) {
				best_score = sts[i][j].score;
				best_i = i;
				best_j = j;
			}
		}
	}
	//cerr << best_i << endl;
	cerr << best_score << endl;

	string answer;
	while (best_i) {
		if (sts[best_i][best_j].op != 'x')answer += sts[best_i][best_j].op;
		best_j = sts[best_i][best_j].prev_st;
		best_i--;
	}
	reverse(all(answer));
	cout << answer << endl;



	return 0;
}
