/*{{{ #include */
#include <iostream>
#include <cstdio>
#include <istream>
#include <ostream>
#include <string>
#include <type_traits>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <tuple>
#include <algorithm>
#include <utility>
#include <cmath>/*}}}*/
/*{{{ namespace R2357 */
namespace R2357 {
    inline void IN(void){return;}
    template<class F,class... R>inline void IN(F& f,R&... r){std::cin>>f;IN(r...);}
    template <class T>inline void OUT(T x){std::cout<<x<<'\n';}
    template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
    template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
    template<class T=int>T read(){
        T x=0; char c;
        while(((c=getchar())>'9'||c<'0')&&c!='-');
        const bool f=(c=='-')&&(c=getchar());
        while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
        return f?-x:x;
    }
    template<class T>std::istream& operator>>(std::istream& input,std::vector<T>& V){
        for(auto& v:V)input>>v; return input;
    }
    namespace debug {
        using namespace std;
        void Write(void){cout<<endl;}
        template<class F,class...R>void Write(F& f,R&...r){cout<<' '<<f;Write(r...);}
        template<class T>void Write(vector<T>& V,int n=-1){
            if(n==-1) n = V.size();
            for(int i=0;i<n;i++)cout<<' '<<V[i]; cout<<endl;
        }
        #include <cxxabi.h>
        template<class T>string TypeName(T x){
            return string(abi::__cxa_demangle(typeid(T).name(), 0, 0, 0));
        }
    }
}
/*}}}*/
/*{{{ using */
using namespace std; using namespace R2357;
using ll=long long; using ld=long double;
using pint=pair<int,int>;/*}}}*/
/*{{{ #define */
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define each(x,v) for(auto& x:v)
#define el '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define Unique(x) sort(x.begin(),x.end());x.erase(unique(x.begin(),x.end()),x.end())
#define Fill(v,n) fill(v,v+sizeof(v)/sizeof(*v),n)
#define ceil_div(a,b) ((a+(b-1))/b)
#define max_element(x) *max_element(x.begin(),x.end())
#define INF 1234567890
#define INFL 1122334455667788990ll/*}}}*/

// using namespace debug;
int main(){
    int n = read();
    vector<ll> a(n); cin>>a;
    vector<ll> sum(n+1);{
        rep(i, 0, n) sum[i+1] = sum[i] + a[i];
        rep(i, 0, n) sum[i] = sum[i+1];
    }
    // Write("sum");
    // Write(sum, n);
    vector<ll> start(n);{
        rep(i, 0, n-1) start[i+1] = start[i] + sum[i];
    }
    // Write("start");
    // Write(start);
    vector<ll> sumMax(n);{
        sumMax[0] = sum[0];
        rep(i, 1, n) sumMax[i] = max(sumMax[i-1], sum[i]);
    }
    // Write("sumMax");
    // Write(sumMax);
    vector<ll> list(n);{
        rep(i, 0, n) list[i] = sumMax[i] + start[i];
    }
    // Write("list");
    // Write(list);
    OUT(max(0ll, max_element(list)));
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,b) for(int i=0;i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} else return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} else return false;}
struct Edge {int to; ll w; Edge(int to, ll w) : to(to), w(w) {}; };
using Graph = vector<vector<Edge>>;
const int INF = 1<<30;
const ll INFL = 1LL<<60;

/* A_012 */

const int h = 30;
const int w = 30;
const int n = h*w;

// 左 上 右 下
vector<int> dx = {-1,  0, 1, 0};
vector<int> dy = { 0, -1, 0, 1};


ll combination(ll n, ll k) {
  ll r = 1;
  for (ll d = 1; d <= k; ++d) {
    r *= n--;
    r /= d;
  }
  return r;
}


int main () {
  vector<vector<int>> cost(n, vector<int>(n, INF));
  random_device seed_gen;
  mt19937 engine(seed_gen());
  rep(i, n) {
    if (i % h == h-1) continue;
    cost[i][i+1] = 4500;
    cost[i+1][i] = 4500;
  }
  rep(i, n-h) {
    cost[i][i+h] = 4500;
    cost[i+h][i] = 4500;
  }

  rep(ik, 1000) {
    int b;
    int sx, sy, gx, gy;
    cin >> sy >> sx >> gy >> gx;

    string ans;
    string str = "";
    int x = sx;
    int y = sy;
    while (x != gx) {
      if (x < gx) {
        str += "R";
        x++;
      } else if (x > gx) {
        str += "L";
        x--;
      } 
    }
    while (y != gy) {
      if (y < gy) {
        str += "D";
        y++;
      } else if (y > gy) {
        str += "U";
        y--;
      } 
    }

    if (ik >= 200) {

      ll combi = combination((ll)abs(gy-sy)+abs(gx-sx), (ll)abs(gx-sx));
      int m;
      if (combi > 1000) m = 1000;
      else m = (int)combi;

      /* シャッフルして文字列生成 */
      set<string> cand;
      cand.insert(str);

      rep(ij, m) {
        shuffle(str.begin(), str.end(), engine);
        cand.insert(str);
      }

      /*  コスト計算 */
      int min_cost = INF;
      for (auto v : cand) {
        int nowx = sx, nowy = sy;
        int now = nowy*h + nowx;
        int c = 0;
        rep(j, v.size()) {
          if (v[j] == 'L') {
            c += cost[now][now-1];
            now--;
          }
          else if (v[j] == 'R') {
            c += cost[now][now+1];
            now++;
          }
          if (v[j] == 'U') {
            c += cost[now][now-h];
            now -= h;
          }
          if (v[j] == 'D') {
            c += cost[now][now+h];
            now += h;
          }
        }
        if (min_cost > c) {
          min_cost = c;
          ans = v;
        }
      }
    } else {
      ans = str;
    }

    cout << ans << endl;
    cin >> b;

    /* コストを再計算（単純分配） */
    int nowx = sx, nowy = sy;
    int now = nowy*h + nowx;
    int ave = b/(int)ans.size();
    rep(i, (int)ans.size()) {
      if (ans[i] == 'L') {
        cost[now][now-1] = ave;
        now--;
      }
      else if (ans[i] == 'R') {
        cost[now][now+1] = ave;
        now++;
      }
      else if (ans[i] == 'U') {
        cost[now][now-h] = ave;
        now -= h;
      }
      else if (ans[i] == 'D') {
        cost[now][now+h] = ave;
        now += h;
      }
    }
  }
  return 0;
}