This page is still under construction.

Parts of this page are still being built. What you see may change.

Nice Pairs

Time limit2sMemory limit512 MB

Summary
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.
Level

Medium5 of 10

Topics
String, Math, Hash map, Brute force
Solved
No attempts yet

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 A≤x<y≤BA \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. 1≤A≤B≤2,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.

Examples3

  1. Example 1

    Input
    1 9
    
    Expected output
    0
    
  2. Example 2

    Input
    10 40
    
    Expected output
    3
    
  3. Example 3

    Input
    100 500
    
    Expected output
    156