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>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int table[100][100];
string s;

int dx[] = { 0, 1, 0, -1, 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0, -1, 0, 1, 0 };
char c[] = "URDLURDL";

int main(){
	REP(i, 9){
		cin >> s;
		REP(j, s.size()){
			if (i % 2 == 0)	table[i][2 * j + 1] = s[j] - '0';
			else table[i][2 * j] = s[j] - '0';
		}
	}
	bool f = 0;
	string ans = "";
	int x = 0, y = 0, muki = 0;
	while (1){
		if (f&&x == 0 && y == 0)break;
		int ny, nx;
		for (int i = muki; i < muki + 4; i++){
			nx = x + dx[i], ny = y + dy[i];
			if (nx >= 0 && nx <= 8 && ny >= 0 && ny <= 8){
				if (table[ny][nx] == 1){
					x += 2 * dx[i];
					y += 2 * dy[i];
					ans += c[i];
					if (c[i] == 'U')muki = 3;
					else if (c[i] == 'R')muki = 0;
					else if (c[i] == 'D')muki = 1;
					else muki = 2;
					break;
				}
			}
		}
		f = 1;
	}
	cout << ans << endl;
}

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

double eps = 1e-10;

int main() {
	string s[16], ans("R");
	for(int i = 0; i < 9; ++i){
		cin >> s[i];
	}
	int x = 0, y = 0;
	int d = 0; // 0:right, 1:down, 2:left, 3:up
	bool flag = false;
	while(1){
		if(d == 0){
			if(s[y][x + 1] == '1'){
				ans += 'R';
				x += 1;
			}
			else if(y >= 2 && s[y - 1][x + 1] == '1'){
				ans += 'U';
				y -= 1;
				x += 1;
				d = 3;
			}
			else if(s[y + 1][x + 1] == '1'){
				ans += 'D';
				x += 1;
				y += 1;
				d = 1;
			}
			else{
				ans += 'L';
				d = 2;
			}
		}
		else if(d == 1){
			if(s[y + 2][x] == '1'){
				ans += 'D';
				y += 2;
			}
			else if(s[y + 1][x] == '1'){
				ans += 'R';
				y += 1;
				d = 0;
			}
			else if(s[y + 1][x - 1] == '1'){
				ans += 'L';
				x -= 1;
				y += 1;
				d = 2;
			}
			else{
				ans += 'U';
				d = 3;
			}
		}
		else if(d == 2){
			if(s[y][x - 1] == '1'){
				ans += 'L';
				x -= 1;
			}
			else if(y >= 2 && s[y - 1][x] == '1'){
				ans += 'U';
				y -= 1;
				d = 3;
			}
			else if(s[y + 1][x] == '1'){
				ans += 'D';
				y += 1;
				d = 1;
			}
			else{
				ans += 'R';
				d = 0;
			}
		}
		else if(d == 3){
			if(y >= 3 && s[y - 2][x] == '1'){
				ans += 'U';
				y -= 2;
			}
			else if(s[y - 1][x] == '1'){
				y -= 1;
				if(x == 0 && y == 0)
					break;
				ans += 'R';
				d = 0;
			}
			else if(s[y - 1][x - 1] == '1'){
				ans += 'L';
				y -= 1;
				x -= 1;
				d = 2;
			}
			else{
				ans += 'D';
				d = 1;
			}
		}
		/*if(x == 1 && y == 8 && flag)
			break;
		if(x == 1 && y == 8){
			flag = true;
			//break;
		}*/
		if(x == 0 && y == 0)
			break;
	}
	/*cout << s[8][3] << endl;
	cout << d << endl;*/
	cout << ans << endl;
	return 0;
}

C++:       }
      else if(ex[vy][vx-1] == 1) {
        vx--;
        direction = 3;
        cout << "L";
      }
    }
  }
  cout << endl;
}

C++: #include<bits/stdc++.h>
using namespace std;
bool t[222][222][4];
int w,h,n,a[202][202];
int seach(int x,int y,int d){
 
  int turn =1,p=0;
   
  while(1){
    if(!p){
      if(d==3)cout<<'R';
      if(d==2)cout<<'U';
      if(d==1)cout<<'L';
      if(d==0)cout<<'D';
    }
    p=0;

    if(t[y][x][d])break;
    t[y][x][d]=1;
    if(d==0){
        if(a[y+1][x]==1)d=3;
    else if(a[y+2][x]==0){
      if(a[y+2][x-1]==1)y+=2;
      else d=1,y+=2,p++;
    }
 
    }
    else if(d==1){
        if(a[y][x-1]==1)d=0;
    else if(a[y][x-2]==0){
      if(a[y-1][x-2]==1)x-=2;
      else d=2,x-=2,p++;
    }
 
    }
    else if(d==2){
        if(a[y-1][x]==1)d=1;
    else if(a[y-2][x]==0){
      if(a[y-2][x+1]==1)y-=2;
      else d=3,y-=2,p++;
    }
 
    }
    else if(d==3){
        if(a[y][x+1]==1)d=2;
    else if(a[y][x+2]==0){
      if(a[y+1][x+2]==1)x+=2;
      else d=0,x+=2,p++;
    }
 
      }

  }
}
int main(){

    memset(a,0,sizeof(a));

    for(int i=0;i<9;i++){
      string x;
      cin>>x;
      if(i%2){
        for(int j=0;j<5;j++)if(x[j]=='1')
          a[i+3][j*2+3]=1;
      }
      else{
        for(int j=0;j<4;j++)if(x[j]=='1')
          a[i+3][j*2+1+3]=1;
      }
    }
    for(int i=0;i<20;i++){
      for(int j=0;j<20;j++)
        cout<<a[i][j];cout<<endl;
    }
    seach(4,2,3);
    cout<<endl;
}