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 <string>

using namespace std;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const char dir[] = "RDLU";

int main()
{
    string input;

    while (cin >> input) {
        bool map[5][5][4];

        // Initialization
        for (int i = 0; i < 5; i++)
            for (int j = 0; j < 5; j++)
                for (int k = 0; k < 4; k++)
                    map[i][j][k] = false;

        // Input (0,0) - (0,4)
        for (int i = 0; i < 4; i++) 
            if (input[i] == '1') {
                map[0][i][0] = true;
                map[0][i + 1][2] = true;
            }

        // Input Others
        for (int i = 0; i < 8; i++) {
            cin >> input;
            int lim;
            (i % 2) ? (lim = 4) : (lim = 5);

            for (int j = 0; j < lim; j++)
                if (input[j] == '1') {
                    if (i % 2) {
                        map[(i + 1) / 2][j][0] = true;
                        map[(i + 1) / 2][j + 1][2] = true;
                    }
                    else {
                        map[i / 2][j][1] = true;
                        map[(i / 2) + 1][j][3] = true;
                    }
                }
        }

        // algorithm
        int x, y, d;

        x = y = d = 0;
        do {
            int del = (d + 3) % 4;
            for (int i = 0; i < 4; i++) 
                if (map[y][x][(del + i) % 4]) {
                    d = (del + i) % 4;
                    break;
                }
            x += dx[d];
            y += dy[d];
            cout << dir[d];
        } while (x || y);

        cout << endl;
    }

    return 0;
}

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

using namespace std;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const char dir[] = "RDLU";

int main()
{
    string input;

    while (cin >> input) {
        bool map[5][5][4];

        // Initialization
        for (int i = 0; i < 5; i++)
            for (int j = 0; j < 5; j++)
                for (int k = 0; k < 4; k++)
                    map[i][j][k] = false;

        // Input (0,0) - (0,4)
        for (int i = 0; i < 4; i++) 
            if (input[i] == '1') {
                map[0][i][0] = true;
                map[0][i + 1][2] = true;
            }

        // Input Others
        for (int i = 0; i < 8; i++) {
            cin >> input;
            int lim;
            (i % 2) ? (lim = 4) : (lim = 5);

            for (int j = 0; j < lim; j++)
                if (input[j] == '1') {
                    if (i % 2) {
                        map[(i + 1) / 2][j][0] = true;
                        if (j)
                            map[(i + 1) / 2][j + 1][2] = true;
                    }
                    else {
                        map[i / 2][j][1] = true;
                        map[(i / 2) + 1][j][3] = true;
                    }
                }
        }

        // algorithm
        int x, y, d;

        x = y = d = 0;
        // do {
        //     if (map[y][x][d])
        //         ;
        //     else if (map[y][x][(d + 1) % 4]) 
        //         d = (d + 1) % 4;
        //     else if (map[y][x][(d + 3) % 4]) 
        //         d = (d + 3) % 4;

            // map[y][x][d] = false;
            // x += dx[d];
            // y += dy[d];
            // cout << dir[d];
        // } while (x || y);
        do {
            int del = (d + 3) % 4;
            for (int i = 0; i < 4; i++) 
                if (map[y][x][(del + i) % 4]) {
                    d = (del + i) % 4;
                    break;
                }

            x += dx[d];
            y += dy[d];
            cout << dir[d];
        } while (x || y);

        cout << endl;
    }

    return 0;
}

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

int main(){
  int f,xyf;
  char h[5][4],v[4][5];
  int x,y;
  cin>>h[0];
  for(int i=0;i<4;i++){
    cin>>v[i];
    cin>>h[i+1];
  }
  f=xyf=1;
  y=0;
  x=1;cout<<"R";
  while(x!=0||y!=0){
    if(f==1){
      if(xyf==1){
	if(y>0&&v[y-1][x]=='1'){
	  y--;cout<<"U";f*=-1;xyf*=-1;
	}
	else if(x<4&&h[y][x]=='1'){
	  x++;cout<<"R";
	}
	else if(v[y][x]=='0'||y==4) xyf*=-1;
	else{
	  y++;f*=-1;cout<<"D";
	}
      }
      else{
	if(y<4&&v[y][x]=='1'){
	  y++;cout<<"D";f*=-1;xyf*=-1;
	}
	else if(x>0&&h[y][x-1]=='1'){
	  x--;cout<<"L";
	}
	else if(v[y-1][x]=='0'||y==0) xyf*=-1;
	else{
	  y--;cout<<"U";f*=-1;
	}
      }
    }
    else{
      if(xyf==1){
	if(x<4&&h[y][x]=='1'){
	  x++;cout<<"R";f*=-1;
	}
	else if(y<4&&v[y][x]=='1'){
	  y++;cout<<"D";
	}
	else if(h[y][x-1]=='0'||x==0) xyf*=-1;
	else{
	  x--;cout<<"L";f*=-1;xyf*=-1;
	}
      }
      else{
	if(x>0&&h[y][x-1]=='1'){
	  x--;cout<<"L";f*=-1;
	}
	else if(y>0&&v[y-1][x]=='1'){
	  y--;cout<<"U";
	}
	else if(h[y][x]=='0'||x==4) xyf*=-1;
	else{
	  x++;cout<<"R";f*=-1;xyf*=-1;
	}
      }
    }
  }
  cout<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const char ch[] = {"ULDR"};

bool g[10][10][10][10];

int main()
{
	char c;
	
	for (int i = 1; i <= 5; i++){
		for (int j = 1; j <= 4; j++){
			scanf(" %c", &c);
			if (c == '0') continue;
			g[i][j][i][j + 1] = true;
			g[i][j + 1][i][j] = true;
		}
		if (i == 5) continue;
		for (int j = 1; j <= 5; j++){
			scanf(" %c", &c);
			if (c == '0') continue;
			g[i][j][i + 1][j] = true;
			g[i + 1][j][i][j] = true;
		}
	}
	
	int dir = 3;
	int x = 1, y = 2;
	while (true){
		printf("%c", ch[dir]);
		if (x == 1 && y == 1) break;
		for (int t = -1; t <= 2; t++){
			int nd = (dir + t + 4) % 4;
			int nx = x + dx[nd];
			int ny = y + dy[nd];
			if (g[x][y][nx][ny]){
				x = nx;
				y = ny;
				dir = nd;
				break;
			}
		}
	}
	puts("");
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;



int main()
{
	bool points[5][5][4];
	for (int i = 0; i < 5; ++i)
		for (int j = 0; j < 5; ++j)
			for (int k = 0; k < 4; ++k)
				points[i][j][k] = false;

	for (int i = 0; i < 9; ++i)
	{
		int y = i/2;
		if (i%2 == 0)
		{
			for (int j = 0; j < 4; ++j)
			{
				int e;
				scanf("%1d", &e);
				if (e)
					points[y][j][1] = points[y][j+1][3] = true;
			}
		}
		else
		{
			for (int j = 0; j < 5; ++j)
			{
				int e;
				scanf("%1d", &e);
				if (e)
					points[y][j][2] = points[y+1][j][0] = true;
			}
		}
	}

	int x, y;
	x = 1;
	y = 0;
	int dir = 1;
	int dx[] = { 0, 1, 0, -1 };
	int dy[] = { -1, 0, 1, 0 };
	char* ds = "URDL";
	putchar(ds[dir]);
	while (!(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];
		putchar(ds[dir]);
	}

	return 0;
}