Nice Pairs

Count pairs (x, y) with A <= x < y <= B where y is a rotation of x's digits (a suffix moved to the front), counting duplicates only once.

Medium5StringMathHash mapBrute forceNo attempts yetTime limit2sMemory limit512 MB

Problem

Two natural numbers nn and mm form a nice pair when the following holds.

  • Cutting some digits off the back of nn and placing them, in the same order, in front of what is left gives mm.

For example, cutting 345345 off the back of 1234512345 and placing it in front gives 3451234512, so (12345,34512)(12345, 34512) is a nice pair.

You are given two natural numbers AA and BB with the same number of digits. Count the pairs (x,y)(x, y) with Ax<yBA \le x < y \le B such that (x,y)(x, y) is a nice pair.

Two different cut lengths can produce the same mm. In that case the pair (x,y)(x, y) is counted once.

Input

The first line contains two natural numbers AA and BB separated by a space. 1AB2,000,0001 \le A \le B \le 2{,}000{,}000, and AA and BB have the same number of digits.

Output

Print the number of nice pairs as a single integer.