def paths(i, j):
    if path[i][j]:
        return path[i][j]
    val = a[i][j]
    cnt = 1
    for (dy, dx) in dyx:
        y = (i + dy)
        x = (j + dx)
        if ((0 <= y < h) and (0 <= x < w) and (a[y][x] < val)):
            cnt += paths(y, x)
            cnt %= MOD
    path[i][j] = cnt
    return cnt
def paths(i, j):
    if path[i][j]:
        return path[i][j]
    val = a[i][j]
    cnt = 1
    for (dy, dx) in dyx:
        y = (i + dy)
        x = (j + dx)
        if ((0 <= y < h) and (0 <= x < w) and (a[y][x] < val)):
            cnt += paths(y, x)
            cnt %= MOD
    path[i][j] = cnt
    return cnt