import sys
def is_round(s):
    year =int( s)
    m =int( s[-1]+s[-2])
    d = int(s[1]+s[0])
    gap = bool ((year % 4==0 and year % 100!=0) or year % 400==0)
    li =[31,28+gap,31,30,31,30,31,31,30,31,30,31]
    if 1<= m <= 12 and li[m-1] >= d:
        return True       
    return False

a = input().strip()
b = input().strip()
star_year = int(a[:4])
end_year =int( b[:4])
count = 0

for yy in range(star_year,end_year+1):
    year_str = str(yy)
    reverse_year = year_str[::-1]

    test = year_str+reverse_year
    if int(a)<= int(test) <=int(b):
        if is_round(year_str):
            count +=1
print(count)


沿用官方题解思路,精进了一点后面的部分,只用对年份进行回文检查再看是否合法就行,注意开始和最后的日期检查,