def sumDigits(x): return sum(map(int, str(x))) def check(m, d): return sumDigits(m) == sumDigits(d) cnt = 0 for m in range(1, 12 + 1): dd = 31 if m == 2: dd = 28 elif m in [4,8,9,11]: dd = 30 for d in range(1, dd + 1): cnt += check(m, d) print(cnt)