Problem:
Score : 300 points

Problem Statement

Dolphin resides in two-dimensional Cartesian plane, with the positive x-axis pointing right and the positive y-axis pointing up.

Currently, he is located at the point (sx,sy). In each second, he can move up, down, left or right by a distance of 1.

Here, both the x- and y-coordinates before and after each movement must be integers.

He will first visit the point (tx,ty) where sx < tx and sy < ty, then go back to the point (sx,sy), then visit the point (tx,ty) again, and lastly go back to the point (sx,sy).

Here, during the whole travel, he is not allowed to pass through the same point more than once, except the points (sx,sy) and (tx,ty).

Under this condition, find a shortest path for him.

Constraints

-1000 ≤ sx < tx ≤ 1000

-1000 ≤ sy < ty ≤ 1000

sx,sy,tx and ty are integers.

Input

The input is given from Standard Input in the following format:

sx sy tx ty

Output

Print a string S that represents a shortest path for Dolphin.

The i-th character in S should correspond to his i-th movement.

The directions of the movements should be indicated by the following characters:

U: Up

D: Down

L: Left

R: Right

If there exist multiple shortest paths under the condition, print any of them.

Sample Input 1

0 0 1 2

Sample Output 1

UURDDLLUUURRDRDDDLLU

One possible shortest path is:

Going from (sx,sy) to (tx,ty) for the first time: (0,0) → (0,1) → (0,2) → (1,2)

Going from (tx,ty) to (sx,sy) for the first time: (1,2) → (1,1) → (1,0) → (0,0)

Going from (sx,sy) to (tx,ty) for the second time: (0,0) → (-1,0) → (-1,1) → (-1,2) → (-1,3) → (0,3) → (1,3) → (1,2)

Going from (tx,ty) to (sx,sy) for the second time: (1,2) → (2,2) → (2,1) → (2,0) → (2,-1) → (1,-1) → (0,-1) → (0,0)

Sample Input 2

-2 -2 1 1

Sample Output 2

UURRURRDDDLLDLLULUUURRURRDDDLLDL

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;

  const int w = 2001;
  const int h = 2001;

  //訪問済みの座標を記録するvector
  vector<vector<int>> visited(h,vector<int>(w,0));

  //どの方向から移動してきたかを記録するvector
  vector<vector<char>> direction(h,vector<char>(w));

  //座標値を配列の添え字に変換する関数
  auto to_idx = [&](int c){
    return c + w / 2;
  };

  //与えられた2点の座標を配列の添え字に変換
  const int sx_ = to_idx(sx);
  const int sy_ = to_idx(sy);
  const int tx_ = to_idx(tx);
  const int ty_ = to_idx(ty);
  
  string ans;

  //4回の移動を行う
  rep(I,4){
    //出発地点の座標と対応する配列の添え字
    int nx,ny;

    //出発地点の座標と対応する配列の添え字
    int gx,gy;

    //出発地点と目標地点をセット
    if(I%2==0){
      nx = sx_;
      ny = sy_;
      gx = tx_;
      gy = ty_;
    }
    else{
      nx = tx_;
      ny = ty_;
      gx = sx_;
      gy = sy_;
    }

    //目標地点を未訪問にしておく
    visited[gy][gx] = 0;

    /*BFS（多分）する*/
    queue<P> q;
    const int dx[4] = { 0, 1,-1, 0};
    const int dy[4] = { 1, 0, 0,-1};
    const char di[4] = {'U','R','L','D'};

    //訪問済みの座標を記録するvector（最短経路上ではない座標も記録）
    vector<vector<int>> tmp_visited(h,vector<int>(w,0));

    //出発地点をキューに追加
    q.push(make_pair(nx,ny));

    while(!q.empty()){
      //目標地点に到達したかのフラグ
      bool reached = false;

      P p = q.front();
      q.pop();

      int X = p.first;
      int Y = p.second;

      rep(i,4){
        int to_x = X + dx[i];
        int to_y = Y + dy[i];

        //行先の座標が範囲外ならば
        if(0>to_x||to_x>=w) continue;
        if(0>to_y||to_y>=h) continue;

        //行先の座標が訪問済みならば
        if(visited[to_y][to_x]==1||tmp_visited[to_y][to_x]==1) continue;

        //訪問済みにしておく
        tmp_visited[to_y][to_x] = 1;

        //移動してきた方向を記す
        direction[to_y][to_x] = di[i];

        //目標地点に到達したら
        if(to_x==gx&&to_y==gy) reached = true;

        //キューに追加
        q.push(make_pair(to_x,to_y));
      }

      //目標地点に到着したときそれまでの経路を記録する
      if(reached){
        string tmp_ans;

        //出発地点に到達したかのフラグにする
        reached = false;

        int to_x = gx;
        int to_y = gy;

        while(!reached){
          //経路を記録
          tmp_ans = direction[to_y][to_x] + tmp_ans;

          //訪問済みにしておく
          visited[to_y][to_x] = 1;

          //経路を戻る
          if(direction[to_y][to_x]=='U') to_y--;
          else if(direction[to_y][to_x]=='D') to_y++;
          else if(direction[to_y][to_x]=='L') to_x++;
          else if(direction[to_y][to_x]=='R') to_x--;

          //出発地点に到着したら
          if(to_x==nx&&to_y==ny) reached = true;
        }

        ans += tmp_ans;

        break;
      }

    }

  }

  cout << ans << endl;

  return 0;
}