Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		X, _ := strconv.Atoi(buf[0])
		Y, _ := strconv.Atoi(buf[1])
		if X == 0 && Y == 0 {
			break
		}
		tbl := make([][]int, Y+2)
		field := make([][]int, Y+2)
		for i := range field {
			field[i] = make([]int, X+2)
			tbl[i] = make([]int, X+2)
			for j := range field[i] {
				field[i][j] = 2
				tbl[i][j] = 0
			}
		}
		buf_ := make([][]string, Y)
		for i := range buf_ {
			scanner.Scan()
			buf_[i] = strings.Split(scanner.Text(), " ")
		}
		for i := 1; i <= Y; i++ {
			for j := 1; j <= X; j++ {
				field[i][j], _ = strconv.Atoi(buf_[i-1][j-1])
				switch field[i][j] {
				case 0:
					if i == 1 {
						tbl[i][j] = 1 // スタートy=1
					} else {
						if field[i-1][j-1] != 2 {
							tbl[i][j] += tbl[i-1][j-1] // 左上からやってくる
						}
						if field[i-1][j] != 2 {
							tbl[i][j] += tbl[i-1][j] // 真上からやってくる
						}
						if field[i-1][j+1] != 2 {
							tbl[i][j] += tbl[i-1][j+1] // 右上からやってくる
						}
						if field[i-2][j] == 2 {
							tbl[i][j] += tbl[i-2][j] // ジャンプしてくる
						}
					}
				case 1:
					tbl[i][j] = 0 // 障害物あり
				case 2:
					if field[i-1][j] != 2 {
						tbl[i][j] += tbl[i-1][j] // 真上からくる
					}
					if field[i-2][j] == 2 {
						tbl[i][j] += tbl[i-2][j] // ジャンプ台からジャンプしてくる
					}
				}
			}
		}
		sum := 0
		for i := 1; i <= X; i++ {
			sum += tbl[Y][i] // とびこさないでゴール
			if field[Y-1][i] == 2 {
				sum += tbl[Y-1][i] // 飛び越してゴール
			}
		}
		fmt.Println(sum)
	}
}

Python: def algorithm():
    def down_jump(x, y, times):
        if x == r:
            out_map[x - 1][y] += times
        elif x == r - 1:
            out_map[x][y] += times
        elif in_map[x][y] == 2:
            down_jump(x + 2, y, times)
        else:
            out_map[x][y] += times

    while True:
        c, r = map(int, input().split())
        if c == 0 and r == 0:
            break

        in_map = []
        out_map = [[0 for _ in range(c)] for _ in range(r)]
        for _ in range(r):
            in_map.append(list(map(int, input().split())))

        for i in range(c):
            if in_map[0][i] == 0 or in_map[0][i] == 2:
                out_map[0][i] = 1

        for i in range(r):
            for j in range(c):
                if in_map[i][j] == 0 or (i == 0 and in_map[i][j] == 2):
                    # ???.
                    if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0 and in_map[i][j] == 0:
                        out_map[i + 1][j - 1] += out_map[i][j]
                    # ???.
                    if in_map[i][j] == 2:
                        down_jump(i, j, out_map[i][j])
                    elif i + 1 < r and in_map[i + 1][j] == 0:
                        out_map[i + 1][j] += out_map[i][j]
                    elif i + 1 < r and in_map[i + 1][j] == 2:
                        down_jump(i + 1, j, out_map[i][j])
                    # ???.
                    if i + 1 < r and j + 1 < c and in_map[i + 1][j + 1] == 0 and in_map[i][j] == 0:
                        out_map[i + 1][j + 1] += out_map[i][j]

        for i in range(c):
            out_map[r - 1][i] = 0 if in_map[r - 1][i] and in_map[r - 2][i] != 2 else out_map[r - 1][i]
        print(sum(out_map[r - 1]))


def main():
    algorithm()


if __name__ == '__main__':
    main()

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0203

"""
import sys
from sys import stdin
from collections import deque, defaultdict
input = stdin.readline


def solve(field):
    # 0: ????????°, 1: ?????????, 2: ?????£????????°
    ans = 0                     #  ??????????????°???????????°

    dy = [1, 1, 1]  # ?????????????????????????????????????§???????
    dx = [0, -1, 1]
    x_limit = len(field[0])
    y_limit = len(field)

    path = defaultdict(int)     #  ??????????????????????????°???????????°????????????'x???_y???'???????????????
    Q = deque()
    for x, m in enumerate(field[0]):
        if m == 0:              #  ?????????????????°?????´?????????????????????????????????
            t = '{}_{}'.format(x, 0)
            Q.append((x, 0))
            path[t] = 1
    if y_limit < 2:
        return len(Q)


    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        t = '{}_{}'.format(cx, cy)
        num = path.pop(t)

        if cy >= y_limit - 1:
            continue

        if field[cy][cx] == 1:  #  ?????£????????§?????°?????????????????????
            continue
        elif field[cy][cx] == 2: #  ?????£????????§?????°?????????????????£????????°
            if cy+2 >= y_limit-1:
                ans += num
            else:
                t = '{}_{}'.format(cx, cy+2)
                if not path[t]:
                    Q.append((cx, cy+2))
                path[t] += num
            continue

        for i in range(len(dx)):
            nx = cx + dx[i]     #  ?????°????????§?¨?
            ny = cy + dy[i]

            if 0<= nx < x_limit:
                if (ny >= y_limit - 1) and field[ny][nx] != 1:
                    ans += num
                else:
                    if field[ny][nx] == 2 and dx[i] == 0: #  ?????£????????°????????£??????????????\????????´???
                        if ny+2 > y_limit - 1:
                            ans += num
                        else:
                            t = '{}_{}'.format(nx, ny+2)
                            if not path[t]:
                                Q.append((nx, ny+2))
                            path[t] += num
                    elif field[ny][nx] == 0:
                        t = '{}_{}'.format(nx, ny)
                        if not path[t]:
                            Q.append((nx, ny))
                        path[t] += num
    return ans


def main(args):
    while True:
        X, Y = map(int, input().strip().split())
        if X == 0 and Y == 0:
            break
        field = []
        for _ in range(Y):
            temp = [int(x) for x in input().strip().split()]
            field.append(temp)
        result = solve(field)
        print(result)


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