Count Valid Paths in Grid with Restrictions