深度优先遍历: def dfs(pb, i, j, n, res): if j == n-1: if i == 1: res[0] += 1 return for ne in get_neigh(i, j, n): if pb[ne[0]][ne[1]]: pb[ne[0]][ne[1]] == False dfs(pb, ne[0], ne[1], n, res) pb[ne[0]][ne[1]] == True def get_neigh(i, j, x): neigh = [] if j+1 < x: neigh.append([i, j+1]) if j+1 < x and i == 0: neigh.append([i+1, j+1]) if j+1 < x and i == 1: neigh.append([i-1, j+1]) return neigh if __name__ == '__main__': n = int(input()) p = [] p.append(list(input())) p.append(list(input())) pb = [[True for i in range(n)] for i in range(2)] for i in range(2): for j in range(n): if p[i][j] != '.': pb[i][j] = False pb[0][0] = False res = [0] dfs(pb, 0, 0, n, res) res = res[0] if res[0] > 0 else -1 print(res)