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 r == 1:
            return
        elif 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: def printF(field,w,h):
    for i in range(h):
        print(field[i])

def getp(f,p,y,x,h,w,v):
    if y<0 or x<0 or x>=w:
        return 0
    if y>=h:
        if v==True:
            return 1
        return 0

    
    k = f[y][x]
    r = 0
    if k==0:
        if p[y][x]>=0:
            return p[y][x]

        r = getp(f,p,y+1,x-1,h,w,False)+getp(f,p,y+1,x,h,w,True)+getp(f,p,y+1,x+1,h,w,False)
        p[y][x] = r
    elif k==1:
        r = 0
    elif k==2:
        if v == True:
            if p[y][x]>=0:
                return p[y][x]
            r = getp(f,p,y+2,x,h,w,True)
            p[y][x] = r
        else:
            r = 0

    #print("gp({},{},{}):({},{})".format(x,y,v,k,r))
    return r

w,h = map(int,input().split())
while w!=0 and h != 0:
    field = []

    for i in range(h):
        field.append(list(map(int,input().split())))
        

    #initialize
    p = []
    for i in range(h):
        p.append([-1]*w)

    #calc

    print(sum(map(lambda x:getp(field,p,0,x,h,w,True), range(w))))

    w,h = map(int,input().split())

Python: """ Created by Jieyi on 8/16/16. """


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(r):
            if in_map[0][i] == 0:
                out_map[0][i] = 1

        for i in range(r):
            for j in range(c):
                if in_map[i][j] == 0:
                    # ???.
                    if i + 1 < r and j > 0 and in_map[i + 1][j - 1] == 0:
                        out_map[i + 1][j - 1] += out_map[i][j]
                    # ???.
                    if 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:
                        out_map[i + 1][j + 1] += out_map[i][j]

        print(sum(out_map[c - 1]))


def main():
    algorithm()


if __name__ == '__main__':
    main()

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]

        print(sum(out_map[r - 1]))


def main():
    algorithm()


if __name__ == '__main__':
    main()