def some(i, j, count): j = str(j) + "0" j1, j2 = int(j[0]), int(j[1]) if i == j1+j2: count +=1 return count def aaa(count): r = 0 for i in range(1, 12+1): if i in (1, 3, 5, 7, 8, 10, 12): for j in range(1, 32): r += some(i, j, count) elif i == 2: for j in range(1, 29): r += some(i, j, count) else: for j in range(1, 31): r += some(i, j, count) return r print(aaa(0))