package fixjava;

public class StringUtils {

	/** Repeat the given string the requested number of times. */
	public static String repeat(String str, int numTimes) {
		StringBuilder buf = new StringBuilder(Math.max(0, str.length() * numTimes));
		for (int i = 0; i < numTimes; i++)
			buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the left hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padLeft(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(padChar);
		for (int i = 1, mi = bufSize - str.length(); i < mi; i++)
			buf.append(padChar);
		buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the right hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padRight(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(str);
		buf.append(padChar);
		while (buf.length() < bufSize)
			buf.append(padChar);
		return buf.toString();
	}

	/** Intern all strings in an array, skipping null elements. */
	public static String[] intern(String[] arr) {
		for (int i = 0; i < arr.length; i++)
			arr[i] = arr[i].intern();
		return arr;
	}

	/** Intern a string, ignoring null */
	public static String intern(String str) {
		return str == null ? null : str.intern();
	}

}

package com.codejam.practice;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Recycled {
	public static void main(String[] args) {
		//File read & write variables
		File inputFile = new File("C:/Users/SNALLAMA/Desktop/C-large.in");
		File outputFile = new File("C:/Users/SNALLAMA/Desktop/C-large.out");
		String line = null;
		int t, a, b, noOfDigits, divider, localnumber;
		//long outNumber=0;
		Set<String> finalOP = new HashSet<String>();		
		
		try {
			BufferedReader bReader =  new BufferedReader(new FileReader(inputFile));
			BufferedWriter bWriter = new BufferedWriter(new FileWriter(outputFile));
			try {
				t = Integer.parseInt(bReader.readLine().trim());
				//System.out.println("No. Of Cases"+t);
				for(int index=0;index<t;index++) {
					line = bReader.readLine().trim();
					StringTokenizer st = new StringTokenizer(line, " ");
					a=Integer.parseInt(st.nextElement().toString());
					b=Integer.parseInt(st.nextElement().toString());
					noOfDigits=String.valueOf(a).length();
					finalOP=new HashSet<String>(); 
					if(noOfDigits!=1){						
						for(int i=a;i<=b;i++){
							for(int localIndex=1;localIndex<noOfDigits;localIndex++){
								divider=Integer.parseInt(String.valueOf((int)Math.pow(10, localIndex)));
								localnumber=Integer.parseInt(String.valueOf(i%divider)+String.valueOf(i/divider));
								if((String.valueOf(localnumber).length()==String.valueOf(i).length())&&(a<=i)&&(i<localnumber)&&(localnumber<=b)){
									if(!finalOP.contains(localnumber+" "+i))
										finalOP.add(i+" "+localnumber);
									//System.out.println(divider+" "+i);
								}
							}
						}
					}
					
					bWriter.write("Case #"+(index+1)+": "+finalOP.size());
					bWriter.write("\n");					
				}
			} catch(Exception e) {
				System.out.println("Exception Message: "+ e.getMessage());
				e.printStackTrace();
			}finally{
				bReader.close();
				bWriter.close();
			}
			
		} catch(Exception e) {
			System.out.println("Exception Message: "+ e.getMessage());
			e.printStackTrace();
		} 				
	}

}
