import java.io.*;

class code1
{
	public static void main(String args[]) throws Exception 
	{
		File ii = new File ("C-small-attempt1.in");
		FileInputStream fis = new FileInputStream(ii);
		BufferedReader  br = new BufferedReader(new InputStreamReader (fis));
		int cases = Integer.parseInt(br.readLine());
		FileOutputStream fout = new FileOutputStream ("output.txt");
		DataOutputStream dout = new DataOutputStream (fout);
		int total=0;
		for(int i=0;i<cases;i++){
		String temp = br.readLine();
		String parts [] = temp.split(" ");
		int lower = Integer.parseInt(parts[0]);
		int upper = Integer.parseInt(parts[1]);
		System.out.println(lower+" "+upper);
		
		for(int j=lower;j<=upper;j++)
		{
			int abc = j;int length=0;
			if(j<10)continue;
			while (abc!=0){abc/=10;length++;}
			abc=j;
			for(int m=0;m<length-1;m++){
				int shift = abc%10;
				abc=abc/10;
				System.out.println("hi "+j);
				abc=abc+shift*power(10,length-1);
				if(abc<=upper&&shift!=0&&abc>j)total++;
				System.out.println(total);
			}
		}
 		dout.writeBytes("Case #"+(i+1)+ ": "+total+"\n");
 		total=0;
		}//for close
		
	}

	private static int power(int i, int j) {
		int no=1;
		for(int a=0;a<j;a++){no=10*no;}
		return no;
	}
}
package com.codejam;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;

public class RecycledNumbers {
	
	private static int lowRange = 0, highRange = 0;
	private static ArrayList<Integer> list = null;
	private static ArrayList<Integer> newList = null; 
	
	
	public static void main(String[] args) {
		try {
			
			FileInputStream fstream = new FileInputStream(
					"D:\\Softwares\\C-small-attempt0.in");
			
			DataInputStream in = new DataInputStream(fstream);
			
			FileOutputStream out = new FileOutputStream("D:\\Softwares\\C-small-attempt0.out");
			PrintStream p = new PrintStream(out);



			int lineNo = 1;
			while (in.available() != 0) {
				if (lineNo == 1) {
					cases(in.readLine(), in, p);
				}
				lineNo++;
			}

			in.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	private static void cases(String firstLine, DataInputStream in, PrintStream p)
			throws IOException {
		int casesNo = Integer.parseInt(firstLine);
		for (int i = 0; i < casesNo; i++) {
			p.print("Case #" + (i + 1) + ": ");
			String line = in.readLine();
			numbers(line, p);
		}

	}

	private static void numbers(String line, PrintStream p) {
		String[] range = line.split(" ");
		lowRange = Integer.parseInt(range[0]);
		highRange = Integer.parseInt(range[1]);
		int[] numbers = new int[highRange - lowRange + 1];
		for (int i = 0; i < numbers.length; i++) {
			numbers[i] = lowRange + i;
		}
		list = new ArrayList<Integer>();
		newList = new ArrayList<Integer>();
		int total = recycled(numbers);
		p.println(total);
	}

	private static int recycled(int[] numbers) {
		int total = 0;
		int dupliTotal = 0;
		for (int i = 0; i < numbers.length; i++) {
			int num = numbers[i];
			int length = (int)(Math.log10(num)+1);
			int max = maxTen(length);
			int min = 10;
			while (num/min > 0){
				int rem = num%min;
				int remNum = num/min;
				max /= min;
				int newNum = rem*max + remNum;
				if(newNum>num){
					if (newNum <= highRange && newNum > lowRange) {

						if (list.contains(num))
							if (newList.get(list.indexOf(num))==newNum)
								dupliTotal++;
						list.add(num);
						newList.add(newNum);
						total++;
					}
				}
				min*=10;
				max = maxTen(length);
			}
		}
		return total-dupliTotal;
	}
	
	private static int maxTen(int length){
		int result = 1;
		int len = (int)(Math.log10(result)+1);
		while(len!=length){
			result*= 10;
			len = (int)(Math.log10(result)+1);
		}
		return result*10;
	}

}
