Problem:
Score : 200 points

Problem Statement

Find the number of palindromic numbers among the integers between A and B (inclusive).
Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.

Constraints

10000 \leq A \leq B \leq 99999

All input values are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the number of palindromic numbers among the integers between A and B (inclusive).

Sample Input 1

11009 11332

Sample Output 1

4

There are four integers that satisfy the conditions: 11011, 11111, 11211 and 11311.

Sample Input 2

31415 92653

Sample Output 2

612

Solution in C# (.NET Core 3.1.201) (judge verdict: Wrong Answer)

using System;
using System.IO;
using System.Text;
using static Scanner;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Solve();
        Console.Out.Flush();
    }
    static void Solve() {
        string N = (ScanInt() - 1).ToString(), B = Scan();
        Console.WriteLine(Dp(B) - Dp(N));
    }
    static int Dp(string S) {
        var digits = S.Length;
        var dp = new int[digits + 1, 2];
        dp[0, 0] = 1;
        for (int d = 0; d < digits; d++) {
            var cur = S[d] - '0';
            for (int s = 0; s <= 1; s++) {
                for (var n = 0; n <= (s == 1 ? 9 : cur); n++) {
                    var isSmall = s == 1 || n < cur ? 1 : 0;
                    var a = d == 3 && n == S[1] - '0';
                    var b = d == 4 && n == S[0] - '0';
                    if (d >= 3 && !a && !b) continue;
                    dp[d + 1, isSmall] += dp[d, s];
                }
            }
        }
        return dp[digits, 0] + dp[digits, 1];
    }
}

public static class Scanner
{
    static readonly Stream stream = Console.OpenStandardInput();
    static readonly byte[] buffer = new byte[1024];
    static int length, p;
    static bool isEof;
    private static byte ConsoleIn() {
        if (isEof) return 0;
        if (p < length) return buffer[p++];
        p = 0;
        if ((length = stream.Read(buffer, 0, 1024)) > 0) return buffer[p++];
        isEof = true;
        return 0;
    }
    public static char GetChar() {
        var by = ConsoleIn();
        while ((by < '!' || '~' < by) && !isEof) by = ConsoleIn();
        return (char) by;
    }
    public static string Scan() {
        var sb = new StringBuilder();
        for (var ch = GetChar(); '!' <= ch && ch <= '~'; ch = (char) ConsoleIn()) {
            sb.Append(ch);
        }
        return sb.ToString();
    }
    public static int ScanInt() {
        var temp = 0;
        for (var ch = GetChar(); '0' <= ch && ch <= '9'; ch = (char) ConsoleIn()) {
            temp = temp * 10 + ch - '0';
        }
        return temp;
    }
}