Problem:


格子上の経路

上から見ると図 1 のような形の格子状の広場があります。この格子の各辺に「壁」があるかないかを 0 と 1 の並びで表します。点 A に立って壁に右手をつき、壁に右手をついたまま、矢印の方向に歩き続けて再び点 A に戻ってくるまでの経路を出力するプログラムを作成してください。

図1

Input

入力は９行からなり、以下の図 2 に示すように、壁がある場合を 1、ない場合を 0 として、以下の形式で与えられます。

1 行目は一番上の横線の壁の有無を左から 0 と 1 で表した文字列

2 行目はその下の縦線の壁の有無を左から0 と1 で表した文字列

3 行目は上から2 本目の横線の壁の有無を左から0 と1 で表した文字列

...

9 行目は一番下の横線の壁の有無を左から0 と1 で表した文字列

図2 (壁あるところを太線で表しています)　　(対応する数字のならび)

ただし、図１の太線に示すように、点 A から右に 1 区画分は必ず壁があるものとします。すなわち、1 行目の 1 文字目は常に 1 です。

Output

「図の左方向に一区画分進む」を 'L'、「図の右方向に一区画分進む」を 'R'、「図の上方向に一区画分進む」を 'U'、「図の下方向に一区画分進む」を 'D' で表わし、進む順に 'L', 'R', 'U', 'D' を１行に並べて出力します。

Sample Input

1111
00001
0110
01011
0010
01111
0010
01001
0111

Output for the Sample Input

RRRRDDDDLLLUUURRDDLURULLDDDRRRUUUULLLL



Sample input:
1111
00001
0110
01011
0010
01111
0010
01001
0111


Sample output:
RRRRDDDDLLLUUURRDDLURULLDDDRRRUUUULLLL

Submission status: Wrong Answer

Solution code:
#coding: utf-8

import sys

def xxx(position, direction):
    if direction == 'R' or direction == 'L':
        if not (0 <= position[tate] <= 8 and 0 <= position[yoko] <= 3):
            return 
    elif direction == 'U' or direction == 'D':
        if not (1 <= position[tate] <= 7 and 0 <= position[yoko] <= 4):
            return
    if (position[tate] == 0 and position[yoko] == 0) and direction == 'L' or \
       (position[tate] == 1 and position[yoko] == 0) and direction == 'U':
        result.append(direction)
        print_result()
    if mapp[position[tate]][position[yoko]] == 1:
        result.append(direction)
        kyoto(position, direction)
    elif mapp[position[tate]][position[yoko]] == 0:
        return

def kyoto(position, direction):
    if direction == 'R':
        #????????????????´¢
        check_position = position[tate], position[yoko]+1
        direction = 'R'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]+1
        direction = 'U'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]+1
        direction = 'D'
        xxx(check_position, direction)
    elif direction == 'U':
        #????????????????´¢
        check_position = position[tate]-2, position[yoko]
        direction = 'U'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]
        direction = 'R'
        xxx(check_position, direction)
    elif direction == 'L':
        #????????????????´¢
        check_position = position[tate], position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]
        direction = 'D'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]
        direction = 'U'
        xxx(check_position, direction)
    elif direction == 'D':
        #????????????????´¢
        check_position = position[tate]+2, position[yoko]
        direction = 'D'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]
        direction = 'R'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        
def print_result():
    print ''.join(result)
    sys.exit()

mapp = []
for i in range(9):
    mapp.append([int(char) for char in raw_input()])
    
tate = 0
yoko = 1
result = []
xxx((0,0), 'R')

Submission status: Wrong Answer

Solution code:
import sys

def xxx(position, direction):
    if direction == 'R' or direction == 'L':
        if not (0 <= position[tate] <= 8 and 0 <= position[yoko] <= 3):
            return 
    elif direction == 'U' or direction == 'D':
        if not (1 <= position[tate] <= 7 and 0 <= position[yoko] <= 4):
            return
    if (position[tate] == 0 and position[yoko] == 0) and direction == 'L' or \
       (position[tate] == 1 and position[yoko] == 0) and direction == 'U':
        result.append(direction)
        print_result()
    if mapp[position[tate]][position[yoko]] == 1:
        result.append(direction)
        kyoto(position, direction)
    elif mapp[position[tate]][position[yoko]] == 0:
        return

def kyoto(position, direction):
    if direction == 'R':
        check_position = position[tate], position[yoko]+1
        direction = 'R'
        xxx(check_position, direction)
        check_position = position[tate]-1, position[yoko]+1
        direction = 'U'
        xxx(check_position, direction)
        check_position = position[tate]+1, position[yoko]+1
        direction = 'D'
        xxx(check_position, direction)
    elif direction == 'U':
        check_position = position[tate]-2, position[yoko]
        direction = 'U'
        xxx(check_position, direction)
        check_position = position[tate]-1, position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        check_position = position[tate]-1, position[yoko]
        direction = 'R'
        xxx(check_position, direction)
    elif direction == 'L':
        check_position = position[tate], position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        check_position = position[tate]+1, position[yoko]
        direction = 'D'
        xxx(check_position, direction)
        check_position = position[tate]-1, position[yoko]
        direction = 'U'
        xxx(check_position, direction)
    elif direction == 'D':
        check_position = position[tate]+2, position[yoko]
        direction = 'D'
        xxx(check_position, direction)
        check_position = position[tate]+1, position[yoko]
        direction = 'R'
        xxx(check_position, direction)
        check_position = position[tate]+1, position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        
def print_result():
    print ''.join(result)
    sys.exit()

mapp = []
for i in range(9):
    mapp.append([int(char) for char in raw_input()])
    
tate = 0
yoko = 1
result = []
xxx((0,0), 'R')

Submission status: Wrong Answer

Solution code:
import sys

def xxx(position, direction):
    if direction == 'R' or direction == 'L':
        if not (0 <= position[tate] <= 8 and 0 <= position[yoko] <= 3):
            return 
    elif direction == 'U' or direction == 'D':
        if not (1 <= position[tate] <= 7 and 0 <= position[yoko] <= 4):
            return
    if (position[tate] == 0 and position[yoko] == 0) and direction == 'L' or \
       (position[tate] == 1 and position[yoko] == 0) and direction == 'U':
        result.append(direction)
        print_result()
    if mapp[position[tate]][position[yoko]] == 1:
        result.append(direction)
        kyoto(position, direction)
    elif mapp[position[tate]][position[yoko]] == 0:
        return

def kyoto(position, direction):
    if direction == 'R':
        check_position = position[tate], position[yoko]+1
        direction = 'R'
        xxx(check_position, direction)
        check_position = position[tate]-1, position[yoko]+1
        direction = 'U'
        xxx(check_position, direction)
        check_position = position[tate]+1, position[yoko]+1
        direction = 'D'
        xxx(check_position, direction)
    elif direction == 'U':
        check_position = position[tate]-2, position[yoko]
        direction = 'U'
        xxx(check_position, direction)
        check_position = position[tate]-1, position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        check_position = position[tate]-1, position[yoko]
        direction = 'R'
        xxx(check_position, direction)
    elif direction == 'L':
        check_position = position[tate], position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        check_position = position[tate]-1, position[yoko]
        direction = 'U'
        xxx(check_position, direction)
        check_position = position[tate]+1, position[yoko]
        direction = 'D'
        xxx(check_position, direction)
    elif direction == 'D':
        check_position = position[tate]+2, position[yoko]
        direction = 'D'
        xxx(check_position, direction)
        check_position = position[tate]+1, position[yoko]
        direction = 'R'
        xxx(check_position, direction)
        check_position = position[tate]+1, position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        
def print_result():
    print ''.join(result)
    sys.exit()

mapp = []
for i in range(9):
    mapp.append([int(char) for char in raw_input()])
    
tate = 0
yoko = 1
result = []
xxx((0,0), 'R')

Submission status: Wrong Answer

Solution code:
#coding: utf-8

import sys

def xxx(position, direction):
    if direction == 'R' or direction == 'L':
        if not (0 <= position[tate] <= 8 and 0 <= position[yoko] <= 3):
            return 
    elif direction == 'U' or direction == 'D':
        if not (1 <= position[tate] <= 7 and 0 <= position[yoko] <= 4):
            return
    if (position[tate] == 0 and position[yoko] == 0) and direction == 'L' or \
       (position[tate] == 1 and position[yoko] == 0) and direction == 'U':
        result.append(direction)
        print_result()
    if mapp[position[tate]][position[yoko]] == 1:
        result.append(direction)
        kyoto(position, direction)
    elif mapp[position[tate]][position[yoko]] == 0:
        return

def kyoto(position, direction):
    if direction == 'R':
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]+1
        direction = 'U'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate], position[yoko]+1
        direction = 'R'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]+1
        direction = 'D'
        xxx(check_position, direction)
    elif direction == 'U':
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]-2, position[yoko]
        direction = 'U'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]
        direction = 'R'
        xxx(check_position, direction)
    elif direction == 'L':
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]
        direction = 'D'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate], position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]
        direction = 'U'
        xxx(check_position, direction)
    elif direction == 'D':
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]
        direction = 'R'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]+2, position[yoko]
        direction = 'D'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        
def print_result():
    print ''.join(result)
    sys.exit()

mapp = []
for i in range(9):
    mapp.append([int(char) for char in raw_input()])
    
tate = 0
yoko = 1
result = []
xxx((0,0), 'R')

Submission status: Wrong Answer

Solution code:
#coding: utf-8

import sys

def xxx(position, direction):
    if direction == 'R' or direction == 'L':
        if not (0 <= position[tate] <= 8 and 0 <= position[yoko] <= 3):
            return 
    elif direction == 'U' or direction == 'D':
        if not (1 <= position[tate] <= 7 and 0 <= position[yoko] <= 4):
            return
    if (position[tate] == 0 and position[yoko] == 0) and direction == 'L' or \
       (position[tate] == 1 and position[yoko] == 0) and direction == 'U':
        result.append(direction)
        print_result()
    if mapp[position[tate]][position[yoko]] == 1:
        result.append(direction)
        kyoto(position, direction)
    elif mapp[position[tate]][position[yoko]] == 0:
        return

def kyoto(position, direction):
    if direction == 'R':
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]+1
        direction = 'U'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate], position[yoko]+1
        direction = 'R'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]+1
        direction = 'D'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'L'
        xxx(check_position, direction)
    elif direction == 'U':
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]-2, position[yoko]
        direction = 'U'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]
        direction = 'R'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'D'
        xxx(check_position, direction)
    elif direction == 'L':
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]
        direction = 'D'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate], position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]
        direction = 'U'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'R'
        xxx(check_position, direction)
    elif direction == 'D':
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]
        direction = 'R'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]+2, position[yoko]
        direction = 'D'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'U'
        xxx(check_position, direction)
        
def print_result():
    print ''.join(result)
    sys.exit()

mapp = []
for i in range(9):
    mapp.append([int(char) for char in raw_input()])
    
tate = 0
yoko = 1
result = []
xxx((0,0), 'R')

Submission status: Wrong Answer

Solution code:
import sys

def xxx(position, direction):
    if direction == 'R' or direction == 'L':
        if not (0 <= position[tate] <= 8 and 0 <= position[yoko] <= 3):
            return 
    elif direction == 'U' or direction == 'D':
        if not (1 <= position[tate] <= 7 and 0 <= position[yoko] <= 4):
            return
    if (position[tate] == 0 and position[yoko] == 0) and direction == 'L' or \
       (position[tate] == 1 and position[yoko] == 0) and direction == 'U':
        result.append(direction)
        print_result()
    if mapp[position[tate]][position[yoko]] == 1:
        result.append(direction)
        kyoto(position, direction)
    elif mapp[position[tate]][position[yoko]] == 0:
        return

def kyoto(position, direction):
    if direction == 'R':
        check_position = position[tate]-1, position[yoko]+1
        direction = 'U'
        xxx(check_position, direction)
        check_position = position[tate], position[yoko]+1
        direction = 'R'
        xxx(check_position, direction)
        check_position = position[tate]+1, position[yoko]+1
        direction = 'D'
        xxx(check_position, direction)
        check_position = position[tate], position[yoko]
        direction = 'L'
        xxx(check_position, direction)
    elif direction == 'U':
        check_position = position[tate]-1, position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        check_position = position[tate]-2, position[yoko]
        direction = 'U'
        xxx(check_position, direction)
        check_position = position[tate]-1, position[yoko]
        direction = 'R'
        xxx(check_position, direction)
        check_position = position[tate], position[yoko]
        direction = 'D'
        xxx(check_position, direction)
    elif direction == 'L':
        check_position = position[tate]+1, position[yoko]
        direction = 'D'
        xxx(check_position, direction)
        check_position = position[tate], position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        check_position = position[tate]-1, position[yoko]
        direction = 'U'
        xxx(check_position, direction)
        check_position = position[tate], position[yoko]
        direction = 'R'
        xxx(check_position, direction)
    elif direction == 'D':
        check_position = position[tate]+1, position[yoko]
        direction = 'R'
        xxx(check_position, direction)
        check_position = position[tate]+2, position[yoko]
        direction = 'D'
        xxx(check_position, direction)
        check_position = position[tate]+1, position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        check_position = position[tate], position[yoko]
        direction = 'U'
        xxx(check_position, direction)
        
def print_result():
    print ''.join(result)
    sys.exit()

mapp = []
for i in range(9):
    mapp.append([int(char) for char in raw_input()])
    
tate = 0
yoko = 1
result = []
xxx((0,0), 'R')

Submission status: Wrong Answer

Solution code:
#coding: utf-8

def xxx(position, direction):
    if direction == 'R' or direction == 'L':
        if not (0 <= position[tate] <= 8 and 0 <= position[yoko] <= 3):
            return 
    elif direction == 'U' or direction == 'D':
        if not (1 <= position[tate] <= 7 and 0 <= position[yoko] <= 4):
            return
    if (position[tate] == 0 and position[yoko] == 0) and direction == 'L' or \
       (position[tate] == 1 and position[yoko] == 0) and direction == 'U':
        result.append(direction)
        return print_result()
    if mapp[position[tate]][position[yoko]] == 1:
        result.append(direction)
        if kyoto(position, direction): return 1
    elif mapp[position[tate]][position[yoko]] == 0:
        return

def kyoto(position, direction):
    if direction == 'R':
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]+1
        direction = 'U'
        if xxx(check_position, direction): return 1
        #????????????????´¢
        check_position = position[tate], position[yoko]+1
        direction = 'R'
        if xxx(check_position, direction): return 1
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]+1
        direction = 'D'
        if xxx(check_position, direction): return 1
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'L'
        if xxx(check_position, direction): return 1
    elif direction == 'U':
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]-1
        direction = 'L'
        if xxx(check_position, direction): return 1
        #????????????????´¢
        check_position = position[tate]-2, position[yoko]
        direction = 'U'
        if xxx(check_position, direction): return 1
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]
        direction = 'R'
        if xxx(check_position, direction): return 1
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'D'
        if xxx(check_position, direction): return 1
    elif direction == 'L':
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]
        direction = 'D'
        if xxx(check_position, direction): return 1
        #????????????????´¢
        check_position = position[tate], position[yoko]-1
        direction = 'L'
        if xxx(check_position, direction): return 1
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]
        direction = 'U'
        if xxx(check_position, direction): return 1
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'R'
        if xxx(check_position, direction): return 1
    elif direction == 'D':
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]
        direction = 'R'
        if xxx(check_position, direction): return 1
        #????????????????´¢
        check_position = position[tate]+2, position[yoko]
        direction = 'D'
        if xxx(check_position, direction): return 1
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]-1
        direction = 'L'
        if xxx(check_position, direction): return 1
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'U'
        if xxx(check_position, direction): return 1
        
def print_result():
    print ''.join(result)
    return 1

mapp = []
for i in range(9):
    mapp.append([int(char) for char in raw_input()])

tate = 0
yoko = 1
result = []
xxx((0,0), 'R')

Submission status: Wrong Answer

Solution code:
#coding: utf-8

import sys

def xxx(position, direction):
    if direction == 'R' or direction == 'L':
        if not (0 <= position[tate] <= 8 and 0 <= position[yoko] <= 3):
            return 
    elif direction == 'U' or direction == 'D':
        if not (1 <= position[tate] <= 7 and 0 <= position[yoko] <= 4):
            return
    if (position[tate] == 0 and position[yoko] == 0) and direction == 'L' or \
       (position[tate] == 1 and position[yoko] == 0) and direction == 'U':
        result.append(direction)
        print_result()
    if mapp[position[tate]][position[yoko]] == 1:
        result.append(direction)
        kyoto(position, direction)
    elif mapp[position[tate]][position[yoko]] == 0:
        return

def kyoto(position, direction):
    if direction == 'R':
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]+1
        direction = 'U'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate], position[yoko]+1
        direction = 'R'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]+1
        direction = 'D'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'L'
        xxx(check_position, direction)
    elif direction == 'U':
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]-2, position[yoko]
        direction = 'U'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]
        direction = 'R'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'D'
        xxx(check_position, direction)
    elif direction == 'L':
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]
        direction = 'D'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate], position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]
        direction = 'U'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'R'
        xxx(check_position, direction)
    elif direction == 'D':
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]
        direction = 'R'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]+2, position[yoko]
        direction = 'D'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]-1
        direction = 'L'
        xxx(check_position, direction)
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'U'
        xxx(check_position, direction)
        
def print_result():
    print ''.join(result)
    sys.exit()

mapp = []
for i in range(9):
    mapp.append([int(char) for char in raw_input()])

tate = 0
yoko = 1
result = []
xxx((0,0), 'R')

Submission status: Wrong Answer

Solution code:
#coding: utf-8
def xxx(position, direction):
    if direction == 'R' or direction == 'L':
        if not (0 <= position[tate] <= 8 and 0 <= position[yoko] <= 3):
            return 
    elif direction == 'U' or direction == 'D':
        if not (1 <= position[tate] <= 7 and 0 <= position[yoko] <= 4):
            return
    if (position[tate] == 0 and position[yoko] == 0) and direction == 'L' or \
       (position[tate] == 1 and position[yoko] == 0) and direction == 'U':
        result.append(direction)
        print ''.join(result)
        return True
    if mapp[position[tate]][position[yoko]] == 1:
        result.append(direction)
        if kyoto(position, direction): return True
    elif mapp[position[tate]][position[yoko]] == 0:
        return

def kyoto(position, direction):
    if direction == 'R':
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]+1
        direction = 'U'
        if xxx(check_position, direction): return True
        #????????????????´¢
        check_position = position[tate], position[yoko]+1
        direction = 'R'
        if xxx(check_position, direction): return True
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]+1
        direction = 'D'
        if xxx(check_position, direction): return True
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'L'
        if xxx(check_position, direction): return True
    elif direction == 'U':
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]-1
        direction = 'L'
        if xxx(check_position, direction): return True
        #????????????????´¢
        check_position = position[tate]-2, position[yoko]
        direction = 'U'
        if xxx(check_position, direction): return True
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]
        direction = 'R'
        if xxx(check_position, direction): return True
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'D'
        if xxx(check_position, direction): return True
    elif direction == 'L':
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]
        direction = 'D'
        if xxx(check_position, direction): return True
        #????????????????´¢
        check_position = position[tate], position[yoko]-1
        direction = 'L'
        if xxx(check_position, direction): return True
        #????????????????´¢
        check_position = position[tate]-1, position[yoko]
        direction = 'U'
        if xxx(check_position, direction): return True
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'R'
        if xxx(check_position, direction): return True
    elif direction == 'D':
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]
        direction = 'R'
        if xxx(check_position, direction): return True
        #????????????????´¢
        check_position = position[tate]+2, position[yoko]
        direction = 'D'
        if xxx(check_position, direction): return True
        #????????????????´¢
        check_position = position[tate]+1, position[yoko]-1
        direction = 'L'
        if xxx(check_position, direction): return True
        #????????????????´¢
        check_position = position[tate], position[yoko]
        direction = 'U'
        if xxx(check_position, direction): return True

while True:
    try:      
        mapp = []
        for i in range(9):
            mapp.append([int(char) for char in raw_input()])
        tate = 0
        yoko = 1
        result = []
        xxx((0,0), 'R')
    except EOFError:
        break

Submission status: Wrong Answer

Solution code:
import sys

loc = [3, 1]

def print_dir(h):
	if h == 0:
		print('R', end='')
	elif h == 1:
		print('D', end='')
	elif h == 2:
		print('L', end='')
	elif h == 3:
		print('U', end='')

dir = [[1, 0], [0, 1], [-1, 0], [0, -1]]
hand = 3

board = [[0 for _ in range(11)] for _ in range(11)]
for i, line in enumerate(sys.stdin):
	for j, c in enumerate(line.strip()):
		board[i+1][1 + (i+1)%2 + j*2] = int(c)

print("R", end='')

while loc != [1, 1]:
	for i in range(4):
		if board[loc[1]+dir[(hand+i)%4][1]][loc[0]+dir[(hand+i)%4][0]] == 1:
			loc[0] += dir[(hand+i)%4][0]*2
			loc[1] += dir[(hand+i)%4][1]*2
			if i == 1:
				print_dir((hand+1)%4)
			elif i == 2:
				print_dir((hand+2)%4)
				hand = (hand+1)%4
			elif i == 3:
				print_dir((hand+1)%4)
				print_dir((hand+2)%4)
				print_dir((hand+2)%4)
				print_dir((hand+3)%4)
				hand = (hand+2)%4
			elif i == 0:
				print_dir(hand%4)
				hand = (hand+3)%4

			break

print()

Submission status: Wrong Answer

Solution code:
import sys
n = [input() for i in range(9)]
path = [[0 for i in range(5)] for j in range(5)]

for i, v in enumerate([a[1] for a in enumerate(n) if a[0] % 2 == 0]):
    for j in range(4):
        if v[j] == '1':
            path[i][j] += 1
            path[i][j+1] += 2


for i, v in enumerate([a[1] for a in enumerate(n) if a[0] % 2 != 0]):
    for j in range(5):
        if v[j] == '1':
            path[i][j] += 4
            path[i+1][j] += 8

dur = {'R':(1, 0, 1),
       'L':(2, 0, -1),
       'U':(8, -1, 0),
       'D':(4, 1, 0)}

dur_next = {'R':('U','R','D'),
            'L':('D','L','U'),
            'U':('L','U','R'),
            'D':('R','D','L')}
def walk():
    global cx, cy
    cx = dur[d][2] + cx
    cy = dur[d][1] + cy

def next_D():
    global cx,cy,d,dur
    for nd in dur_next[d]:
        if path[cy][cx] & dur[nd][0]:
            d = nd
            break

cx = cy = 0
d = 'R'

while 1:
    sys.stdout.write(d)
    walk()
    if cx == cy == 0:
        break

    next_D()