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 Scala (2.11.7) (judge verdict: Accepted)

object Main extends App {
	val ab = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	val a1 = List(1,2,3,4,5,6,7,8,9)
	val a2 = List(0,1,2,3,4,5,6,7,8,9)
	val a3 = List(0,1,2,3,4,5,6,7,8,9)

	var cnt = Set[Int]()

	for(x <- a1){
		val temp = x + 10*x + 100*x + 1000*x + 10000*x
		if(ab(0) <= temp && temp <= ab(1)){
			cnt = cnt + temp
		}
	}

	for(x <- a1){
		for(y <- a2){
			val t1 = 10000*x + 1000*x + 100*y + 10*x + x
			val t2 = 10000*x + 1000*y + 100*y + 10*y + x

			if(ab(0) <= t1 && t1 <= ab(1)){
				cnt = cnt + t1
			}
			if(ab(0) <= t2 && t2 <= ab(1)){
				cnt = cnt + t2
			}

			for(z <- a3){
				val t3 = 10000*x + 1000*y + 100*z + 10*y + x
				if(ab(0) <= t3 && t3 <= ab(1)){
					cnt = cnt + t3
				}
			}
		}
	}

	println(cnt.size)
}