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



Sample input:
0 0 1 2


Sample output:
UURDDLLUUURRDRDDDLLU

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
dx = tx - sx
dy = ty - sy
print("R" * dx + "U" * dy + "L" * dx + "D" * dy + "L" + "U" * (dy + 1) + "R" * (dx + 1) + "DR" + "D" * (dy + 1) + "L" * (dx + 1) + "U")

Submission status: Accepted

Solution code:
sx,sy,tx,ty=map(int,input().split())
print('R'*(tx-sx)+'U'*(ty-sy)+'L'*(tx-sx)+'D'*(ty-sy+1)+'R'*(tx-sx+1)+'U'*(ty-sy+1)+'L'+'U'+'L'*(tx-sx+1)+'D'*(ty-sy+1)+'R')

Submission status: Accepted

Solution code:
import numpy as np


def main():
    sx, sy, tx, ty = map(int, input().split())

    w = tx - sx
    h = ty - sy

    out = ''
    # s
    for _ in range(h):
        out += 'U'
    for _ in range(w):
        out += 'R'
    # t
    for _ in range(h):
        out += 'D'
    for _ in range(w):
        out += 'L'
    # s
    out += 'L'
    for _ in range(h+1):
        out += 'U'
    for _ in range(w+1):
        out += 'R'
    out += 'D'
    # t
    out += 'R'
    for _ in range(h+1):
        out += 'D'
    for _ in range(w+1):
        out += 'L'
    out += 'U'

    print(out)
 



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

sx, sy, tx, ty = nl()

path = ''

for i in range(ty-sy):
    path += 'U'
for i in range(tx-sx):
    path += 'R'
for i in range(ty-sy):
    path += 'D'
for i in range(tx-sx):
    path += 'L'

path += 'L'
for i in range(ty-sy+1):
    path += 'U'
for i in range(tx-sx+1):
    path += 'R'
path += 'DR'
for i in range(ty-sy+1):
    path += 'D'
for i in range(tx-sx+1):
    path += 'L'
path += 'U'
print(path)

Submission status: Accepted

Solution code:
sx,sy,tx,ty = map(int,input().split())

ans = ""
X = tx - sx
Y = ty - sy

for i in range(Y):
    ans += "U"
for i in range(X):
    ans += "R"
for i in range(Y):
    ans += "D"
for i in range(X):
    ans += "L"
ans += "L"

for i in range(Y+1):
    ans += "U"
for i in range(X+1):
    ans += "R"
ans += "D"
ans += "R"

for i in range(Y+1):
    ans += "D"
for i in range(X+1):
    ans += "L"
ans += "U"

print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = list(map(int, input().split()))
ans = "U"*(ty-sy)+"R"*(tx-sx)+"D"*(ty-sy)+"L"*(tx-sx)
ans += "L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"
ans += "R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U"
print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty=map(int, input().split())

dif_x=tx-sx
dif_y=ty-sy

cmd1 = 'R'*(dif_x) + 'U'*(dif_y)
cmd2 = 'L'*(dif_x) + 'D'*(dif_y)
cmd3 = 'D' + 'R'*(dif_x + 1) + 'U'*(dif_y+1) + 'L'
cmd4 = 'U' + 'L'*(dif_x + 1) + 'D'*(dif_y+1) + 'R'

ans = cmd1 + cmd2 + cmd3 + cmd4
print(ans)

Submission status: Accepted

Solution code:
import sys

sx, sy, tx, ty = map(int, sys.stdin.readline().split())


dif_x = tx - sx
dif_y = ty - sy


ans_s = ''
route_1 = 'RU'
route_2 = 'LD'
route_3 = 'DRUL'
route_4 = 'ULDR'

for i in range(dif_x):
    ans_s += 'R'
for i in range(dif_y):
    ans_s += 'U'
for i in range(dif_x):
    ans_s += 'L'
for i in range(dif_y):
    ans_s += 'D'

ans_s += 'D'
for i in range(dif_x + 1):
    ans_s += 'R'

for i in range(dif_y + 1):
    ans_s += 'U'
ans_s += 'L'

ans_s += 'U'
for i in range(dif_x + 1):
    ans_s += 'L'
for i in range(dif_y + 1):
    ans_s += 'D'
ans_s += 'R'


print(ans_s)

Submission status: Accepted

Solution code:
sx,sy,tx,ty = map(int,input().split())
dx,dy = tx-sx, ty-sy

cmd1 = 'R' * dx + 'U' * dy
cmd2 = 'L' * dx + 'D' * dy
cmd3 = 'D' + 'R' * (dx+1) + 'U' * (dy+1) + 'L'
cmd4 = 'U' + 'L' * (dx+1) + 'D' * (dy+1) + 'R'

answer = cmd1 + cmd2 + cmd3 + cmd4
print(answer)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = [int(i) for i in input().split()]
dx = tx - sx
dy = ty - sy

ans = "U" * dy + "R" * dx + "D" * dy + "L" * dx
ans += "L" + "U" * (dy + 1) + "R" * (dx + 1) + "D"
ans += "R" + "D" * (dy + 1) + "L" * (dx + 1) + "U"

print(ans)

Submission status: Accepted

Solution code:

sx, sy, tx, ty = map(int, input().split())

lst_A = []

if (sx < tx) and (sy < ty):
    for i in range(tx - sx):
        lst_A.append("R")
    for i in range(ty - sy):
        lst_A.append("U")
    for i in range(tx - sx):
        lst_A.append("L")
    for i in range(ty - sy):
        lst_A.append("D")
    lst_A.append("D")
    for i in range(tx - sx + 1):
        lst_A.append("R")
    for i in range(ty - sy + 1):
        lst_A.append("U")
    lst_A.append("L")
    lst_A.append("U")
    for i in range(tx - sx + 1):
        lst_A.append("L")
    for i in range(ty - sy + 1):
        lst_A.append("D")
    lst_A.append("R")


print("".join(lst_A))

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
dire = ["", "U", "L", "R", "D"]
dire_f = []
dire_s = [2]
a = []
b = []
c = []
d = []
for i in range(abs(ty-sy)):
    dire_f.append((ty-sy)//abs(ty-sy))
for i in range(abs(sx-tx)):
    dire_f.append(((sx-tx)//abs(sx-tx))*2)
for i in range(abs(ty-sy)+1):
    dire_s.append((ty-sy)//abs(ty-sy))
for i in range(abs(sx-tx)+1):
    dire_s.append(((sx-tx)//abs(sx-tx))*2)
dire_s.append(-1)
for i in range(len(dire_f)):
    a.append(dire[dire_f[i]])
    b.append(dire[dire_f[i]*(-1)])
for i in range(len(dire_s)):
    c.append(dire[dire_s[i]])
    d.append(dire[dire_s[i]*(-1)])
print("".join(a+b+c+d))

Submission status: Accepted

Solution code:
def change_U_D_R_L(changelst):
    changelst = changelst.replace("U", "上")
    changelst = changelst.replace("D", "下")
    changelst = changelst.replace("R", "右")
    changelst = changelst.replace("L", "左")
    re_lst = changelst.replace("上", "D").replace("下", "U").replace("右", "L").replace("左", "L")
    return re_lst


sx, sy, tx, ty = map(int, input().split())
go1 = []

for i in range(abs(ty - sy)):
    go1.append("U")
for i in range(abs(tx - sx)):
    go1.append("R")
go1 = "".join(go1)
back1 = change_U_D_R_L(go1)

print(go1 + back1 + "LU" + go1 + "RDRD" + back1 + "LU")

Submission status: Accepted

Solution code:
# 最短距離は当然abs(sx-tx)回x方向とabs(sy-ty)回y方向
# 同じ座標の周囲4マスすべてを使うことになるのでそうする
# 位置関係が判明しているのを利用

sx, sy, tx, ty = map(int, input().split())
difx, dify = abs(tx - sx), abs(ty - sy)
ans = "R" * difx + "U" * dify + "R" + "D" * (dify + 1) + "L" * (difx + 1) + "U"
ans += "U" * dify + "R" * difx + "U" + \
    "L" * (difx + 1) + "D" * (dify + 1) + "R"
print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())


diff_x = tx - sx
diff_y = ty - sy

if diff_y > 0:
    base_v = [abs(diff_y) * 'U', abs(diff_y) * 'D']
    add_v = ['U', 'D']
else:
    base_v = [abs(diff_y) * 'D', abs(diff_y) * 'U']
    add_v = ['D', 'U']
if diff_x > 0:
    base_h = [abs(diff_x) * 'R', abs(diff_x) * 'L']
    add_h = ['L', 'R']
else:
    base_h = [abs(diff_x) * 'L', abs(diff_x) * 'R']
    add_h = ['R', 'L']

ans = []
for i in range(2):
    if i == 1:
        ans.append(add_h[0])
    ans.append(base_v[0])
    if i == 1:
        ans.append(add_v[0])
    ans.append(base_h[0])
    if i == 1:
        ans.append(add_h[1])
        ans.append(add_v[1])
        ans.append(add_h[1])
    ans.append(base_v[1])
    if i == 1:
        ans.append(add_v[1])
        ans.append(add_h[0])
    ans.append(base_h[1])
    if i == 1:
        ans.append(add_v[0])

print(''.join(ans))

Submission status: Accepted

Solution code:
sx,sy,tx,ty=map(int,input().split())
dx=tx-sx
dy=ty-sy
r1="R"*dx+"U"*dy
r2="L"*dx+"D"*dy
r3="D"+"R"*(dx+1)+"U"*(dy+1)+"L"
r4="U"+"L"*(dx+1)+"D"*(dy+1)+"R"
print(r1+r2+r3+r4)

Submission status: Accepted

Solution code:
a=list(map(int, input().split()))

dx=-(a[0]-a[2])
dy=-(a[1]-a[3])

result=''
x=[]
y=[]
for i in range(dx):
    result=result+'R'

for i in range(dy):
    result=result+'U'

for i in range(dx):
    result=result+'L'

for i in range(dy):
    result=result+'D'

result=result+'D'

for i in range(dx+1):
    result=result+'R'

for i in range(dy+1):
    result=result+'U'

result=result+'L'

result=result+'U'

for i in range(dx+1):
    result=result+'L'

for i in range(dy+1):
    result=result+'D'

result=result+'R'

print(result)

Submission status: Accepted

Solution code:
## まず反時計回りの四角形を描くように最短で一周する
## その後一周り大きい四角形を描くように一周する

sx, sy, tx, ty = map(int,input().split())

solver = []
solver.append('U'*(ty-sy))
solver.append('R'*(tx-sx))
solver.append('D'*(ty-sy))
solver.append('L'*(tx-sx))
solver.append('L')
solver.append('U'*(ty-sy+1))
solver.append('R'*(tx-sx+1))
solver.append('D')
solver.append('R')
solver.append('D'*(ty-sy+1))
solver.append('L'*(tx-sx+1))
solver.append('U')

ans = ''.join(solver)
print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
nx = ny = 0
dx = tx - sx
dy = ty - sy

ans = "R" * dx + "U" * dy + "L" * dx + "D" * dy  # 1回目
ans += "D" + "R" * (dx + 1) + "U" * (dy + 1) + "LU" + "L" * (dx + 1) + "D" * (dy + 1) + "R"  # 2回目
print(ans)

Submission status: Accepted

Solution code:
sx,sy,tx,ty = map(int,input().split())
x=tx-sx
y=ty-sy
ans = "R"*x + "U"*y + "L"*x + "D"*y\
        +"D" + "R"*(x+1) + "U"*(y+1) + "L"\
        +"U" + "L"*(x+1) + "D"*(y+1) + "R"
print(ans)

Submission status: Accepted

Solution code:
def vertical_move(move):
    if move >= 0:
        return "U" * move
    return "D" * (-move)

def horizontal_move(move):
    if move >= 0:
        return "R" * move
    return "L" * (- move)

def opposite_horizontal_to_vertical(sx, sy, tx, ty):
    ans = ""
    first_opposite = ""
    vertical = ""
    horizontal = ""
    last_opposite = ""
    if sx <= tx:
        first_opposite = "L"
        horizontal = horizontal_move(tx - sx + 1)
    else:
        first_opposite = "R"
        horizontal = horizontal_move(tx - sx - 1)
        
    if sy <= ty:
        last_opposite = "D"
        vertical = vertical_move(ty + 1 - sy)
    else:
        last_opposite = "U"
        vertical = vertical_move(ty - 1 - sy)
        
    return first_opposite + vertical + horizontal + last_opposite

sx, sy, tx, ty = map(int, input().split())

ans = ""
ans += vertical_move(ty - sy)
ans += horizontal_move(tx - sx)
ans += vertical_move(sy - ty)
ans += horizontal_move(sx - tx)

ans += opposite_horizontal_to_vertical(sx, sy, tx, ty)
ans += opposite_horizontal_to_vertical(tx, ty, sx, sy)

print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())

dx = tx - sx
dy = ty - sy

for _ in range(dx):
    print('R', end='')
for _ in range(dy):
    print('U', end='')
for _ in range(dx):
    print('L', end='')
for _ in range(dy):
    print('D', end='')

print('L', end='')
for _ in range(dy+1):
    print('U', end='')
for _ in range(dx+1):
    print('R', end='')
print('DR', end='')
for _ in range(dy+1):
    print('D', end='')
for _ in range(dx+1):
    print('L', end='')
print('U', end='')

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())

sx_list = [sx, sx+1, sx, sx-1]
sy_list = [sy+1, sy, sy-1, sy]
tx_list = [tx-1, tx, tx+1, tx]
ty_list = [ty, ty-1, ty, ty+1]


U1 = ty_list[0]-sy_list[0]+1
R1 = tx_list[0]-sx_list[0]+1
D1 = ty_list[1]-sy_list[1]+1
L1 = tx_list[1]-sx_list[1]+1

D2 = 1
R2 = tx_list[2]-sx_list[2]
U2 = ty_list[2]-sy_list[2]
L2 = 1

U3 = 1
L3 = tx_list[3]-sx_list[3]
D3 = ty_list[3]-sy_list[3]
R3 = 1

ans = str()

for i in range(U1):
    ans += 'U'
for i in range(R1):
    ans += 'R'
for i in range(D1):
    ans += 'D'
for i in range(L1):
    ans += 'L'
    
for i in range(D2):
    ans += 'D'
for i in range(R2):
    ans += 'R'
for i in range(U2):
    ans += 'U'
for i in range(L2):
    ans += 'L'
    
for i in range(U3):
    ans += 'U'
for i in range(L3):
    ans += 'L'
for i in range(D3):
    ans += 'D'
for i in range(R3):
    ans += 'R'

print(ans)

Submission status: Accepted

Solution code:
import itertools
sx,sy,tx,ty = list(map(int,input().split(" ")))
diffX = tx - sx
diffY = ty - sy
ans = ""
ans+=diffY*"U"
ans+=diffX*"R"
ans+=diffY*"D"
ans+=diffX*"L"
ans+="L"
ans+=(diffY+1)*"U"
ans+=(diffX+1)*"R"
ans+="D"

ans+="R"
ans+=(diffY+1)*"D"
ans+=(diffX+1)*"L"
ans+="U"
print(ans)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
"""考え方
1回目のt行きは、右行ったあと上
1回目のs行きは、左行ったあと下
2回目のt行きは、一回下行って、右行ったあと上、その後左
2回目のs行きは、一回上行って、左行ったあと下、その後右
"""
def solve():
    sx, sy, tx, ty = list(map(int, input().split()))
    ans = ""
    
    # 一回目のt行き
    ans += "R"*(tx-sx)
    ans += "U"*(ty-sy)

    # 一回目のs行き
    ans += "L"*(tx-sx)
    ans += "D"*(ty-sy)

    # 二回目のt行き
    ans += "D"
    ans += "R"*(tx-sx+1)
    ans += "U"*(ty-sy+1)
    ans += "L"

    # 二回目のs行き
    ans += "U"
    ans += "L"*(tx-sx+1)
    ans += "D"*(ty-sy+1)
    ans += "R"

    print(ans)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
sx,sy,tx,ty = list(map(int,input().split()))
print("R"*(tx-sx)+"U"*(ty-sy)+"L"*(tx-sx)+"D"*(ty-sy)+"D"+"R"*(tx-sx+1)+"U"*(ty-sy+1)+"L"+"U"+"L"*(tx-sx+1)+"D"*(ty-sy+1)+"R")

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
dif_x, dif_y = tx - sx, ty - sy
ans = 'R' * dif_x + 'U' * (dif_y + 1) + 'L' * (dif_x + 1) + 'D' * (dif_y + 1) + 'R'
ans += 'U' * dif_y + 'R' * (dif_x + 1) + 'D' * (dif_y + 1) + 'L' * (dif_x + 1) + 'U'
print(ans)

Submission status: Accepted

Solution code:
import itertools
sx,sy,tx,ty = map(int,input().split())
f = ""
f += abs(tx-sx)*"R" + abs(ty-sy)*"U"
f += abs(tx-sx)*"L" + abs(ty-sy)*"D"

f += "D"

f += (1+abs(tx-sx))*"R" + (1 + abs(ty-sy))*"U"
f += "LU"
f += (1+abs(tx-sx))*"L" + (1+abs(ty-sy))*"D"
f += "R"
print(f)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())

distx = tx - sx
disty = ty - sy

for k in range(2):
    if k:
        distx += 1
        disty += 1
        print('D',end='')
    for i in range(distx):
        print('R',end='')
    for i in range(disty):
        print('U',end='')
    if k:
        print('L',end='')
        print('U',end='')
    for i in range(distx):
        print('L',end='')
    for i in range(disty):
        print('D',end='')
    if k:
        print('R')

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
x = tx - sx
y = ty - sy
op = ""
for i in range(y):
    op += "U"
for i in range(x):
    op += "R"
for i in range(y):
    op += "D"
for i in range(x):
    op += "L"
op += "L"
for i in range(y + 1):
    op += "U"
for i in range(x + 1):
    op += "R"
op += "DR"
for i in range(y + 1):
    op += "D"
for i in range(x + 1):
    op += "L"
op += "U"
print(op)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  a,b,c,d=LI()

  s=''
  for i in range(c-a):
    s+='R'
  for i in range(d-b):
    s+='U'

  for i in range(c-a):
    s+='L'
  for i in range(d-b):
    s+='D'

  s+='D'
  for i in range(c-a):
    s+='R'
  s+='R'
  for i in range(d-b):
    s+='U'
  s+='UL'

  s+='U'
  for i in range(c-a):
    s+='L'
  s+='L'
  for i in range(d-b):
    s+='D'
  s+='DR'

  return s

print(main())

Submission status: Accepted

Solution code:
sx,sy,tx,ty=map(int,input().split())
disx=tx-sx
disy=ty-sy
answer='U'*disy+'R'*disx+'D'*disy+'L'*(disx+1)+'U'*(disy+1)+'R'*(disx+1)+'D'+'R'+'D'*(disy+1)+'L'*(disx+1)+'U'
print(answer)

Submission status: Accepted

Solution code:
l = input().split()
sx = int(l[0])
sy = int(l[1])
tx = int(l[2])
ty = int(l[3])

# print(sx, sy, tx, ty)

ans = ''

dx = tx - sx
dy = ty - sy

# 往路 1
ans += 'U'*dy
ans += 'R'*dx

# 復路 1
ans += 'D'*dy
ans += 'L'*dx

# 往路 2
ans += 'L'
ans += 'U'*(dy + 1)
ans += 'R'*(dx + 1)
ans += 'D'

# 復路 2
ans += 'R'
ans += 'D'*(dy + 1)
ans += 'L'*(dx + 1)
ans += 'U'

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-




sx,sy,tx,ty = map(int, input().split())

r = 'R'*(tx-sx)
l = 'L'*(tx-sx)
u = 'U'*(ty-sy)
d = 'D'*(ty-sy)

ans = r+u
ans += 'R'+d+'D'+l+'LU'
ans += u+r
ans += 'U'+l+'L'+d+'DR'
print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())

dx = tx - sx
dy = ty - sy
n = dx + dy
memo = ['' for i in range(n)]
memo2 = ['' for i in range(n)]
lmemo = ['' for i in range(n+2)]
lmemo2 = ['' for i in range(n+2)]

ans = ''

for i in range(dy):
    ans += 'U'

for i in range(dx):
    ans += 'R'

for i in range(dy):
    ans += 'D'

for i in range(dx):
    ans += 'L'

# 2回目
ans += 'L'
for i in range(dy+1):
    ans += 'U'

for i in range(dx+1):
    ans += 'R'

ans += 'D'
ans += 'R'
for i in range(dy+1):
    ans += 'D'

for i in range(dx+1):
    ans += 'L'

ans += 'U'

print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
dx = abs(sx - tx)
dy = abs(sy - ty)

print("R"*dx, end="")
print("U"*dy, end="")
print("L"*dx, end="")
print("D"*dy, end="")
print("D", end="")
print("R"*(dx + 1), end="")
print("U"*(dy + 1), end="")
print("L", end="")
print("U", end="")
print("L"*(dx + 1), end="")
print("D"*(dy + 1), end="")
print("R", end="")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Back and Forth
https://atcoder.jp/contests/abc051/tasks/abc051_c

"""
import sys


def solve(sx, sy, tx, ty):
    used = set()
    ans = []
    x, y = sx, sy
    gx, gy = tx, ty
    px, py = sx, sy
    while True:
        path = []
        for nx, ny, d in ((x, y+1, 'U'), (x, y-1, 'D'), (x-1, y, 'L'), (x+1, y, 'R')):
            if not (nx, ny) in used and (nx, ny) != (px, py):
                path.append([abs(nx-gx) + abs(ny-gy), d, (nx, ny)])
        if path == []:
            break
        o = ''
        if  x == gx or y == gy:
            if x == gx:
                o = 'RLUD'
            else:
                o = 'UDRL'
        elif x > gx:
            if y > gy:
                o = 'DLUR'
            else:
                o = 'ULDR'
        else:
            if y > gy:
                o = 'DRUL'
            else:
                o = 'URDL'
        path.sort(key=lambda x: [x[0], o.index(x[1])])
        ans.append(path[0][1])
        x, y = path[0][2]
        used.add((x, y))
        if x == gx and y == gy:
            used.discard((x, y))
            if gx == sx and gy == sy:
                gx, gy = tx, ty
                px, py = sx, sy
            else:
                gx, gy = sx, sy
                px, py = tx, ty
    return ans


def main(args):
    sx, sy, tx, ty = map(int, input().split())
    ans = solve(sx, sy, tx, ty)
    print(*ans, sep='')


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

sx,sy,gx,gy = map(int,input().split())

ans = []
# go
way1 = ["U"] * (gy-sy) + ["R"] * (gx-sx)
#return
way2 = ["D"] * (gy-sy) + ["L"] * (gx-sx)

way3 = ["L"] + ["U"] * (gy-sy+1) + ["R"] * (gx-sx+1) + ["D"]
way4 = ["R"] + ["D"] * (gy-sy+1) + ["L"] * (gx-sx+1) + ["U"]
ans += way1 + way2 + way3 + way4

print("".join(ans))
# print(len(ans))

Submission status: Accepted

Solution code:
sx,sy,tx,ty = map(int,input().split())
dx,dy = tx-sx, ty-sy

if dx != 0 and dy != 0:
    d = ['R','U','L','D']
    root = [d[0]]*dx + [d[1]]*dy + [d[2]]*dx + [d[3]]*dy
    root += [d[3]] + [d[0]]*(dx+1) + [d[1]]*(dy+1) + [d[2]]
    root += [d[1]] + [d[2]]*(dx+1) + [d[3]]*(dy+1) + [d[0]]

print(''.join(root))

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())

print('U' * (ty - sy) + 'R' * (tx - sx) \
          + 'D' * (ty - sy) + 'L' * (tx - sx) \
          + 'L' + 'U' * (ty - sy + 1) + 'R' * (tx - sx + 1) + 'D' \
          + 'R' + 'D' * (ty - sy + 1) + 'L' * (tx - sx + 1) + 'U' )

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
ans = ""
ans += "R" * (tx-sx)
ans += "U" * (ty-sy)
ans += "L" * (tx-sx)
ans += "D" * (ty-sy)

ans += "D"
ans += "R" * (tx-sx+1)
ans += "U" * (ty-sy+1)
ans += "L"
ans += "U"
ans += "L" * (tx-sx+1)
ans += "D" * (ty-sy+1)
ans += "R"
print(ans)

Submission status: Accepted

Solution code:
sx,sy,tx,ty=map(int,input().split())
s="U"*(ty-sy)
s+="R"*(tx-sx)
s+="D"*(ty-sy)
s+="L"*(tx-sx)
s+="L"+"U"*(ty-sy+1)
s+="R"*(tx-sx+1)+"D"
s+="R"+"D"*(ty-sy+1)
s+="L"*(tx-sx+1)+"U"
print(s)

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    sx, sy, tx, ty = f()

    xdiff = tx - sx
    ydiff = ty - sy

    for _ in range(xdiff):
        print('R', end = '')
    for _ in range(ydiff):
        print('U', end = '')

    for _ in range(xdiff):
        print('L', end = '')
    for _ in range(ydiff):
        print('D', end = '')

    print('L', end = '')
    for _ in range(ydiff+1):
        print('U', end = '')
    
    for _ in range(xdiff+1):
        print('R', end = '')
    
    print('D', end = '')

    print('R', end = '')

    for _ in range(ydiff+1):
        print('D', end = '')

    for _ in range(xdiff+1):
        print('L', end = '')
    
    print('U')
    

solve()

Submission status: Accepted

Solution code:
def solve(dx, dy):
    route = 'U'*dy + 'R'*dx + 'D'*dy + 'L'*(dx+1) \
        + 'U'*(dy+1) + 'R'*(dx+1) + 'DR' \
        + 'D'*(dy+1) + 'L'*(dx+1) + 'U'
    print(route)

def main():
    sx, sy, tx, ty = map(int, input().split())
    solve(tx-sx, ty-sy)

main()

Submission status: Accepted

Solution code:
a,b,x,y=map(int,input().split());r,c=y-b,x-a;R,L,U,D='RLUD';print(R*c+U*r+L*c+D*-~r+R*-~c+U*-~r+L+U+L*-~c+D*-~r+R)

Submission status: Accepted

Solution code:
a,b,x,y=map(int,input().split());r,c=y-b,x-a;print('R'*c+'U'*r+'L'*c+'D'*-~r+'R'*-~c+'U'*-~r+'LU'+'L'*-~c+'D'*-~r+'R')

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
print('R' * (tx - sx) + 'U' * (ty - sy), end='')
print('L' * (tx - sx) + 'D' * (ty - sy), end='')
print('D' + 'R' * (tx - sx + 1) + 'U' * (ty - sy + 1) + 'L', end='')
print('U' + 'L' * (tx - sx + 1) + 'D' * (ty - sy + 1) + 'R', end='')

Submission status: Accepted

Solution code:
sx,sy,tx,ty=map(int,input().split())
a=tx-sx
b=ty-sy
ans=""

ans="U"*b+"R"*a
ans+="D"*b+"L"*a

ans+="D"+"R"*(a+1)+"U"*(b+1)+"L"
ans+="U"+"L"*(a+1)+"D"*(b+1)+"R"

print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())

dx = tx - sx
dy = ty - sy

ans = ""

ans = "R" * dx + "U" * dy + "L" * dx
ans += "D" * (dy + 1) + "R" * (dx + 1) + "U" * (dy + 1) + "L" + "U"
ans += "L" * (dx + 1) + "D" * (dy + 1) + "R"

print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
x = tx- sx 
y = ty - sy
ans = 'R'*x+'U'*y+'L'*x+'D'*y+'L'+'U'*(y+1)+'R'*(x+1)+'D'+'R'+'D'*(y+1)+'L'*(x+1)+'U'
print(ans)

Submission status: Accepted

Solution code:
sx,sy,tx,ty = map(int, input().split())
u = 'U'
d = 'D'
l = 'L'
r = 'R'
ans = ''


# 1st
for i in range(1,abs(tx-sx)+1):
    if tx > sx:
        ans += r
    else:
        ans += l

for i in range(1,abs(ty-sy)+1):
    if ty > sy:
        ans += u
    else:
        ans += d


# 2nd
if tx > sx:
    ans += r
else:
    ans += l

for i in range(1,abs(ty-sy)+2):
    if ty < sy:
        ans += u
    else:
        ans += d

for i in range(1,abs(tx-sx)+2):
    if tx < sx:
        ans += r
    else:
        ans += l

if ty > sy:
    ans += u
else:
    ans += d


# 3rd
for i in range(1,abs(ty-sy)+1):
    if ty > sy:
        ans += u
    else:
        ans += d

for i in range(1,abs(tx-sx)+1):
    if tx > sx:
        ans += r
    else:
        ans += l


# 4th
if ty > sy:
    ans += u
else:
    ans += d

for i in range(1,abs(tx-sx)+2):
    if tx < sx:
        ans += r
    else:
        ans += l

for i in range(1,abs(ty-sy)+2):
    if ty < sy:
        ans += u
    else:
        ans += d
        
if tx > sx:
    ans += r
else:
    ans += l

print(ans)

Submission status: Accepted

Solution code:
a,b,c,d = map(int,input().split())
dx = c-a
dy = d-b
print('U'*dy+'R'*dx+'D'*dy+'L'*(dx+1)+'U'*(dy+1)+'R'*(dx+1)+'D'+'R'+'D'*(dy+1)+'L'*(dx+1)+'U')

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
dx = tx - sx
dy = ty - sy

s = ''
s += 'R' * dx
s += 'U' * dy
s += 'L' * dx
s += 'D' * dy
s += 'D'
s += 'R' * (dx + 1)
s += 'U' * (dy + 1)
s += 'L'
s += 'U'
s += 'L' * (dx + 1)
s += 'D' * (dy + 1)
s += 'R'

print(s)

Submission status: Accepted

Solution code:
a, b, c, d = (int(i) for i in input().split())  
x = c - a
y = d - b
ans = ""
ans += "R"*x + "U"*y + "L"*x + "D"*y
ans += "D" + "R"*(x+1) + "U"*(y+1) + "L"
ans += "U" + "L"*(x+1) + "D"*(y+1) + "R"
print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())

dx = tx - sx
dy = ty - sy

result = ""
def move(r, u, l, d):
    return r * abs(dx) + u * abs(dy) + l * abs(dx) + d * abs(dy) + d + r * (abs(dx)+1) + u * (abs(dy)+1) + l + u + l * (abs(dx)+1) + d *(abs(dy)+1) + r

def horizen_move(r, u, l, d):
    return r * abs(dx+dy) + u + l * abs(dx+dy) + d * 2 + r * abs(dx+dy) + u + r + u * 2 + l * (abs(dx+dy) + 2) + d*2 + r

if dx > 0:
    if dy > 0:
        result = move("R", "U", "L", "D")
        
    elif dy < 0:
        result = move("R", "D", "L", "U")
    elif dy == 0:
        result = horizen_move("R", "U", "L", "D")
        
elif dx < 0:
    if dy > 0:
        result = move("L", "U", "R", "D")
    elif dy < 0:
        result = move("L", "D", "R", "U")
    elif dy == 0:
        result = horizen_move("L", "U", "R", "D")

else:
    if dy > 0:
        result = horizen_move("U", "R", "D", "L")
    elif dy < 0:
        result = horizen_move("D", "R", "U", "L")
        
print(result)

Submission status: Accepted

Solution code:
input_data=input().split()
sx=int(input_data[0])
sy=int(input_data[1])
tx=int(input_data[2])
ty=int(input_data[3])

dy = ty - sy
dx = tx - sx

ans=""


ans += 'R' * dx + 'U' * dy + 'L' * dx + 'D' * dy
ans += 'D' + 'R' * (dx + 1) + 'U' * (dy + 1) + 'L'
ans += 'U' + 'L' * (dx + 1) + 'D' * (dy + 1) + 'R'
print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())

ans = ''

dx = tx - sx
dy = ty - sy

ans += 'R' * dx + 'U' * dy + 'L' * dx + 'D' * dy
ans += 'D' + 'R' * (dx + 1) + 'U' * (dy + 1) + 'L'
ans += 'U' + 'L' * (dx + 1) + 'D' * (dy + 1) + 'R'

print(ans)

Submission status: Accepted

Solution code:
def output_route(length, string):
    for _ in range(length):
        print(string, end = '')
sx, sy, tx, ty = map(int, input().split())
len_x = tx - sx
len_y = ty - sy
output_route(len_x, "R")
output_route(len_y, "U")
output_route(len_x, "L")
output_route(len_y + 1, "D")
output_route(len_x + 1, "R")
output_route(len_y + 1, "U")
output_route(1, "L")
output_route(1, "U")
output_route(len_x + 1, "L")
output_route(len_y + 1, "D")
output_route(1, "R")

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
ans = 'R' * (tx - sx) + 'U' * (ty - sy)
ans += 'L' * (tx - sx) + 'D' * (ty - sy)
ans += 'D' + 'R' * (tx - sx + 1) + 'U' * (ty - sy + 1) + 'L'
ans += 'U' + 'L' * (tx - sx + 1) + 'D' * (ty - sy + 1) + 'R'
print(ans)

Submission status: Accepted

Solution code:
sx,sy,tx,ty = map(int,input().split())

ans = ""
ans += "R"*(tx-sx)
ans += "U"*(ty-sy)
ans += "L"*(tx-sx)
ans += "D"*(ty-sy)
ans += "D"
ans += "R"*(tx-sx+1)
ans += "U"*(ty-sy+1)
ans += "L"
ans += "U"
ans += "L"*(tx-sx+1)
ans += "D"*(ty-sy+1)
ans += "R"

print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())

ans = ''

ans += 'R' * (tx-sx)
ans += 'U' * (ty-sy)
ans += 'L' * (tx-sx)
ans += 'D' * (ty-sy)
ans += 'D'
ans += 'R' * (tx-sx+1)
ans += 'U' * (ty-sy+1)
ans += 'L'
ans += 'U'
ans += 'L' * (tx-sx+1)
ans += 'D' * (ty-sy+1)
ans += 'R'

print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int,input().split())

Answer = []

firstgo = 'R'*(tx - sx) + 'U'*(ty - sy)
firstcome = 'L'*(tx-sx) + 'D'*(ty - sy)
secondgo = 'D'+'R'*(tx-sx+1) + 'U'*(ty-sy+1) + 'L'
secondcome = 'U' + 'L'*(tx-sx+1) + 'D'*(ty-sy+1) + 'R'
print(firstgo+firstcome+secondgo + secondcome)

Submission status: Accepted

Solution code:
sx,sy,tx,ty=map(int,input().split())
dx=tx-sx
dy=ty-sy
ans=["DU"[dy>0]*dy+"LR"[dx>0]*dx,"DU"[dy<0]*dy+"LR"[dx<0]*dx]
ans.append(ans[1][-1]+ans[0][0]+ans[0]+ans[0][-1]+ans[1][0])
ans+=[{"L":"R","R":"L","U":"D","D":"U"}[c]for c in ans[2]]
print("".join(ans))

Submission status: Accepted

Solution code:
sx,sy,tx,ty=map(int,input().split())
w=tx-sx
h=ty-sy
ans=''
ans+='U'*h
ans+='R'*w
ans+='D'*h
ans+='L'*w
ans+='L'
ans+='U'*(h+1)
ans+='R'*(w+1)
ans+='D'
ans+='R'
ans+='D'*(h+1)
ans+='L'*(w+1)
ans+='U'
print(ans)

Submission status: Accepted

Solution code:
sx, sy, tx, ty = map(int, input().split())
h = tx - sx # 横
v = ty - sy # 縦

ans = 'R' * h + 'U' * v + 'L' * h + 'D' * v + 'D' * 1 + 'R' * (h + 1) + 'U' * (v + 1) + 'L' * 1 + 'U' * 1 + 'L' * (h + 1) + 'D' * (v + 1) + 'R' * 1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def solve(sx, sy, tx, ty):
    first = "U"*(ty-sy)+"R"*(tx-sx)
    second = "D"*(ty-sy)+"L"*(tx-sx)
    third = "L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"
    forth = "R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U"
    
    print(first+second+third+forth)
    
if __name__ == '__main__': 
    sx, sy, tx, ty = map(int, input().split())
    
    solve(sx, sy, tx, ty)

Submission status: Accepted

Solution code:
sx,sy,tx,ty=map(int,input().split())
a=(tx-sx)*"R"+(ty-sy)*"U"
b=(tx-sx)*"L"+(ty-sy)*"D"
print(a+b+"DR"+a+"ULUL"+b+"DR")

Submission status: Accepted

Solution code:
import sys
def MI(): return map(int, sys.stdin.readline().split())
sx, sy, tx, ty = MI()
dx = tx - sx
dy = ty - sy
print('U'*dy+'R'*dx+'D'*dy+'L'*dx+'L'+'U'*(dy+1)+'R'*(dx+1)+'DR'+'D'*(dy+1)+'L'*(dx+1)+'U')