#include <bits/stdc++.h>

using namespace std;

//begin of def

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define endl '\n'

using lli = long long int;
using ulli = unsigned long long int;
using Ld = long double;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
using pld = pair<Ld, Ld>;
#define X first
#define Y second

#define rep(I, S, E) for(int I = (S); I < (E); I++)
#define repq(I, S, E) for(int I = (S); I <= (E); I++)

#define pb push_back
#define epb emplace_back

#define ALL(X) X.begin(), X.end()

//end of def

map<lli, int> st[2];

int main(){
    fastio;
    int n;
    cin >> n;
    vector<lli> a(n), b(n);
    rep(i, 0, n)
        cin >> a[i];
    st[0][a[0]]++;

    b[0] = a[0];
    rep(i, 1, n){
        b[i] = a[i] - b[i - 1];
        st[i & 1][b[i]]++;
    }

    lli m = 0, res = 0;
    rep(i, 0, n){

        int ct = 0;
        if(i & 1)
            ct = st[0][m] + st[1][-m];
        else
            ct = st[0][-m] + st[1][m];
        st[i & 1][b[i]]--;
        res += ct;
        m = b[i];
    }
    cout << res;
    return 0;
}

#include<bits/stdc++.h>
#include<vector>
#include<string>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
bool flag[2510];
int dx[4];
int dy[4];
int t[51][51];
int p[51][51];
string direction = "UDLR";
int nx,ny;
int mx;
int sm,maxsum;
bool is_legal_action(int nx,int ny,bool *flag){
	if(0<=nx&&nx<50&&0<=ny&&ny<50&&flag[t[nx][ny]]==0){
		return true;
	}else{
		return false;
	}
}
int legallistlength(int x,int y,bool *flag){
  	int k=0;
  	rep(i,4){
      	nx = x + dx[i];
		ny = y + dy[i];
      	if(is_legal_action(nx,ny,flag)){
          	k++;
        }
    }
    return k;
}
void dfs(int x,int y,bool *flag,int depth){
  	flag[t[x][y]]=1;
  	sm+=p[x][y];
  	//sm++;
  	rep(i,4){
		nx = x + dx[i];
		ny = y + dy[i];
		if(depth>=1&&is_legal_action(nx,ny,flag)){
          	//cout << x <<" " <<  y <<" " << i << endl;
          	dfs(nx,ny,flag,depth-1);
        }
    }
  	if(depth==0||legallistlength(x,y,flag)==0){
      	if(maxsum<sm){
          	maxsum=sm;
          	//cout << maxsum << endl;
        }
      	
    }
  	sm-=p[x][y];
  	//sm--;
  	flag[t[x][y]]=0;
  	return;
}
void func(int x,int y,bool *flag,vector<char>& route){
	flag[t[x][y]]=1;
	int s=-1;
	int nxt=-1;
	rep(i,4){
		nx = x + dx[i];
		ny = y + dy[i];
		if(is_legal_action(nx,ny,flag)){
			/*if(s<=p[nx][ny]){
				s=p[nx][ny];
				nxt=i;
			}*/
          	sm=0;
          	maxsum=-1;
          	dfs(nx,ny,flag,22);
          	if(maxsum>=s){
              	s=maxsum;
              	nxt=i;
            }
          	//cout << i << " " << maxsum <<endl;
          	
		}
      	//cout <<x<<" " << y <<direction[i]<< nxt << endl;
	}
  	flag[t[x][y]]=1;
	if(nxt==-1){
		for (auto i: route){
			cout << i;
		}
		cout << "\n";
	}else{
		route.push_back(direction[nxt]);
		func(x + dx[nxt],y + dy[nxt],flag,route);
		route.pop_back();
	}
	flag[t[x][y]]=0;
	return;
}
int main(){
	int si,sj;
	scanf("%d %d",&si,&sj);
	int M=0;
	rep(i,50)rep(j,50){
		cin >> t[i][j];
		if(M<t[i][j])M=t[i][j];
	}
	M++;
	rep(i,50)rep(j,50) scanf("%d", &p[i][j]);
	rep(i,2500)flag[i]=0;
	vector<char> route;
	dx[0] = -1;
	dx[1] = 1;
	dx[2]=0;
	dx[3]=0;
	dy[0]=0;
	dy[1]=0;
	dy[2]=-1;
	dy[3]=1;
	func(si,sj,flag,route);
	return 0;
}