/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package recyclednumbers;

import java.util.HashSet;

/**
 *
 * @author vandit
 */
public class RecycleNumbers {

    private HashSet<String> numbers = new HashSet<String>();
    private HashSet<String> initialTempNumbers = new HashSet<String>();
    private HashSet<String> finalTempNumbers = new HashSet<String>();

    HashSet<Pair> numberPairs = new HashSet<Pair>();


    private void findRecycledNumbers(int start, int end, int places) {


        for (int i = start; i <= end; i++) {
            String initialNumber = Integer.toString(i);
            //if (!(numbers.contains(initialNumber) || finalTempNumbers.contains(initialNumber))) {

                StringBuffer tempNumber = new StringBuffer(initialNumber);
                int len = tempNumber.length();
                int startIndexToMove = len - places;
                String tempString = tempNumber.substring(startIndexToMove);
                if ((places == 1 && tempString.equals("0")) || tempString.charAt(0) == '0') {
                    continue;
                }
                tempNumber.delete(startIndexToMove, len);
                String finalTempNumber = tempString + tempNumber.toString();

                if (! (finalTempNumber.equals(initialNumber) || Integer.parseInt(finalTempNumber) > end || Integer.parseInt(finalTempNumber) < Integer.parseInt(initialNumber))) {
                    numbers.add(initialNumber);
                    finalTempNumbers.add(finalTempNumber);
                    Pair pair = new Pair(finalTempNumber,initialNumber);
                    numberPairs.add(pair);
                }
            }

        

    }

    public HashSet<Pair> findAllRecycledNumbers(int start, int end) {
        int length = Integer.toString(start).length();
        for (int i = 1; i < length; i++) {
            findRecycledNumbers(start, end, i);
        }
        return numberPairs;
    }
}


public class Case {
	
	//Atrib
	public int ind;
	public double a;
	public double b;

	public String resolver() {
		StringBuilder s_out = new StringBuilder("Case #" + ind + ": ");
		
		int cont = 0;
		
		for(int n = (int) a;n<b+1;n++)
			for(int m = n+1;m<=b;m++){
				
				String nn = String.valueOf(n);
				String mm = String.valueOf(m);
//				nn = nn.replace("0", "");
//				mm = mm.replace("0", "");
				if(nn.length() == mm.length() 
						&& Double.parseDouble(nn) < Double.parseDouble(mm)){
					
//					System.out.println("---" + nn + " " + mm);
					
					for(int i=1;i<nn.length();i++){
						
						String aux = nn.substring(i, nn.length()) + nn.substring(0, i);
						if(aux.equals(mm)){
//							System.out.println("---" + nn + " " + mm);
//							System.out.println( aux);
							cont++;
							i = nn.length();
						}
					}
					
				}
			}
		
//		System.out.println(cont);
		s_out.append(cont);
		
		s_out.append("\n");
		return s_out.toString();
	}

}//endClass
