Go: package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"fmt"
)

var points [5][5][4]bool

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for i := 0; i < 9; i++ {
		y := i/2
		if i%2 == 0 {
			scanner.Scan()
			info := strings.Split(scanner.Text(), "")
			for k := range info {
				e, _ := strconv.Atoi(info[k])
				if e != 0 {
					points[y][k][1], points[y][k+1][3] = true, true
				}
			}
		} else {
			scanner.Scan()
			info := strings.Split(scanner.Text(), "")
			for k := range info {
				e, _ := strconv.Atoi(info[k])
				if e != 0 {
					points[y][k][2], points[y+1][k][0] = true, true
				}
			}
		}
	}
	x := 1
	y := 0
	dir := 1
	dx := []int{0, 1, 0, -1}
	dy := []int{-1, 0, 1, 0}
	ds := "URDL"
	fmt.Printf("%s", string(ds[dir]))
	for !(x == 0 && y == 0) {
		if points[y][x][(dir+3)%4] {
			dir = (dir+3)%4
		} else if points[y][x][dir] {

		} else if points[y][x][(dir+1)%4] {
			dir = (dir+1)%4
		} else {
			dir = (dir+2)%4
		}
		x += dx[dir]
		y += dy[dir]
		fmt.Printf("%s", string(ds[dir]))
	}
	fmt.Println()
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;


int main(){

	while(1){
		char yoko[10][10];
		char tate[10][10];
		memset(yoko,0,sizeof(yoko));
		memset(tate,0,sizeof(tate));
		
		for(int i = 0; i < 5; i++){
			for(int j = 0; j < 4; j++){
				char c;
				cin>>c;
				yoko[i][j]=c;
			}
			if(i!=4){
				for(int j = 0; j < 5; j++){
					char c;
					cin>>c;
					tate[i][j]=c;
				}
			}
		}
	//	if(cin.eof())
	//		break;
		
		
		// 0,1,2,3ÅEAºA¶Aã
		int angle=0;
		int px,py;
		px=py=0;
		while(1){
			if(angle==0){
				if(px!=4&&yoko[py][px]=='1'){
					cout<<"R";
					px++;
				}
				else{
					// ãÖ
					if(py!=0&&tate[py-1][px]=='1'){
						py--;
						angle=3;
						cout<<"U";
					}
					// ºÉÇª êÎAºÖ
					else if(py!=4&&tate[py][px]=='1'){
						py++;
						angle=1;
						cout<<"D";
					}
					else{
						px--;
						angle=2;
						cout<<"L";
					}
				}
			}
			// º
			else if(angle==1){
				if(py!=4&&tate[py][px]=='1'){
					cout<<"D";
					py++;
				}
				else{
					// ºÉÇª³¯êÎA½]
					if(px!=4&&yoko[py][px]=='1'){
						cout<<"R";
						angle=0;
						px++;
					}
					else if(px!=0&&yoko[py][px-1]=='1'){
						cout<<"L";
						angle=2;
						px--;
					}
					else{
						py--;
						angle=3;
						cout<<"U";
					}
				}
			}
			// ¶
			else if(angle==2){
				if(px!=0&&yoko[py][px-1]=='1'){
					cout<<"L";
					px--;
				}
				else{
					// ºÉÇª êÎAºÖ
					if(py!=4&&tate[py][px]=='1'){
						py++;
						angle=1;
						cout<<"D";
					}
					// ãÖ
					else if(py!=0&&tate[py-1][px]=='1'){
						py--;
						angle=3;
						cout<<"U";
					}
					else{
						px++;
						angle=0;
						cout<<"R";
					}
				}
			}
			// ã
			else if(angle==3){
				if(py!=0&&tate[py-1][px]=='1'){
					cout<<"U";
					py--;
				}
				else{
					// ºÉÇª³¯êÎA½]
					if(px!=0&&yoko[py][px-1]=='1'){
						cout<<"L";
						angle=2;
						px--;
					}
					else if(px!=4&&yoko[py][px]=='1'){
						cout<<"R";
						angle=0;
						px++;
					}
					else{
						py++;
						angle=1;
						cout<<"D";
					}
				}
			}
			if(px==0&&py==0)
				break;
}
//cout<<endl;
break;

}
return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#define RIGHT 1
#define LEFT -1
#define UP 2
#define DOWN -2
using namespace std;

int main(){
	int i,j,state,sy=0,sx=1,t_state;
	char row[5][4],col[4][5];

	cin>>row[0];
	for(i=0;i<4;i++){
		cin>>col[i];
		cin>>row[i+1];
	}

	for(i=0;i<5;i++){
		for(j=0;j<4;j++){
			row[i][j]=row[i][j]-'0';
		}
	}
	for(i=0;i<5;i++){
		for(j=0;j<4;j++){
			col[j][i]=col[j][i]-'0';
		}
	}

	cout<<"R"<<flush;
	state=RIGHT;
	while(sy || sx){
		switch(state){
			case RIGHT:
				if(sy>0 && col[sy-1][sx]){
					cout<<"U"<<flush;
					t_state=UP;
					sy--;
				}else if(sx<4 && row[sy][sx]){
					cout<<"R"<<flush;
					t_state=RIGHT;
					sx++;
				}else if(sy<4 && col[sy][sx]){
					cout<<"D"<<flush;
					t_state=DOWN;
					sy++;
				}
				break;
			case LEFT:
				if(sy<4 && col[sy][sx]){
					cout<<"D"<<flush;
					t_state=DOWN;
					sy++;
				}else if(sx>0 && row[sy][sx-1]){
					cout<<"L"<<flush;
					t_state=LEFT;
					sx--;
				}else if(sy>0 && col[sy-1][sx]){
					cout<<"U"<<flush;
					t_state=UP;
					sy--;
				}
				break;
			case UP:
				if(sx>0 && row[sy][sx-1]){
					cout<<"L"<<flush;
					t_state=LEFT;
					sx--;
				}else if(sy>0 && col[sy-1][sx]){
					cout<<"U"<<flush;
					t_state=UP;
					sy--;
				}else if(sx<4 && row[sy][sx]){
					cout<<"R"<<flush;
					t_state=RIGHT;
					sx++;
				}
				break;
			case DOWN:
				if(sx<4 && row[sy][sx]){
					cout<<"R"<<flush;
					t_state=RIGHT;
					sx++;
				}else if(sy<4 && col[sy][sx]){
					cout<<"D"<<flush;
					t_state=DOWN;
					sy++;
				}else if(sx>0 && row[sy][sx-1]){
					cout<<"L"<<flush;
					t_state=LEFT;
					sx--;
				}
				break;
		}
		state=t_state;
	}

	cout<<endl;
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<string>

#define R 1
#define D 2
#define L 3
#define U 4

using namespace std;

int main(void){

	int tate[6][7]={0};
	char inp;
	int yoko[7][6]={0};
	int x,y;
	int now;

	for(int i=1;i<6;i++){
		for(int j=1;j<5;j++){
			inp=getchar();
			yoko[i][j]=(int)(inp-'0');
		}
		getchar();
		if(i!=5){
			for(int j=1;j<6;j++){
				inp=getchar();
				tate[i][j]=(int)(inp-'0');
			}
			getchar();
		}
	}
	now=R;
	bool f=false;
	x=1,y=1;
	while(1){
		if(now==R){
			now=D;
			if(tate[y-1][x]==1&&f==false) now=U,f=true;
			else if(yoko[y][x]==1){
				x++;
				cout<<"R";
				now=R;
				f=false;
			}
		}
		if(now==D){
			now=L;
			if(yoko[y][x]==1&&f==false) now=R,f=true;
			else if(tate[y][x]==1){
				y++;
				cout<<"D";
				now=D;
				f=false;
			}
		}
		if(now==L){
			now=U;
			if(tate[y][x]==1&&f==false) now=D,f=true;
			else if(yoko[y][x-1]==1){
				x--;
				cout<<"L";
				now=L;
				f=false;
			}
		}
		if(now==U){
			now=R;
			if(yoko[y][x-1]==1&&f==false) now=L,f=true;
			else if(tate[y-1][x]==1){
				y--;
				cout<<"U";
				now=U;
				f=false;
			}
		}
		if(x==1&&y==1) break;
	}
	cout<<endl;
	return 0;
}

C++: #include<iostream>
#include<string>
#include<string.h>
using namespace std;

int main(){
    char ma[11][11];
    memset(ma,'0',sizeof(ma));
    for(int i=1;i<10;i++){
        if(i%2==1)
            for(int j=2;j<9;j+=2)
                cin>>ma[i][j];
        else
            for(int j=1;j<10;j+=2)
                cin>>ma[i][j];
    }
    int x=1,y=1,dir=0;
    int mv[4][2]={{2,0},{0,2},{-2,0},{0,-2}};
    int ts[4][8]={{1,-1,1,0,0,-1,0,1},{1,1,0,1,1,0,-1,0},{-1,1,-1,0,0,1,0,-1},{-1,-1,0,-1,-1,0,1,0}};
    string str[4]={"R","D","L","U"};
    string path="";
    int ch=0;
    for(int k=0;k<40;k++){
        int wen=1;
        while(ma[y+ts[dir][3]][x+ts[dir][2]]=='1'){
            y+=mv[dir][1];
            x+=mv[dir][0];
            wen=0;
            path+=str[dir];
            wen++;
           // cout<<x<<" "<<y<<"    "<<dir<<endl;
            if(ma[y+ts[dir][5]][x+ts[dir][4]]=='1'){
               // cout<<"dir: "<<dir<<"    "<<x<<" "<<y<<"   "<<x+ts[dir][4]<<"    "<<y+ts[dir][5]<<"     "<<ma[y+ts[dir][5]][x+ts[dir][4]]<<endl;
                break;
            }
        }
        if(x==1&&y==1)
            break;
       // cout<<x<<" "<<y<<"    "<<dir<<endl;
        if(ma[y+ts[dir][5]][x+ts[dir][4]]=='1')dir=(dir+3)%4;
        else do{
            dir=(dir+1)%4;
        }while((y+ts[dir][3]>10||y+ts[dir][3]<0||x+ts[dir][2]>10||x+ts[dir][2]<0)||ma[y+ts[dir][1]][x+ts[dir][0]]=='1');
        
    }
    cout<<path<<endl;
}
//RRRRDDDDLLLUUURRDDLURULLDDDRRRUUUULLLL
//RRRRDDDDLLLUUURRDDLURULLDDDRRRUUUULLLL
//RRRRDDDDLLLUUURRDDLURULLDDDRRRUUUULLLL