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

package recycled;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.TreeSet;

/**
 *
 * @author Alfred
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    try {
            FileInputStream fstream = new FileInputStream("C-small-attempt0.in");
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            FileWriter outFile = new FileWriter("out.txt");
            PrintWriter out = new PrintWriter(outFile);
            String line;
            line = br.readLine();
            int cases = Integer.parseInt(line);
            for (int i=1; i<=cases;i++){
                line = br.readLine();
                String[] values = line.split(" ");
                int A = Integer.parseInt(values[0]);
                int B = Integer.parseInt(values[1]);
                int total=0;
                for (int n=A; n<=B;n++){
                    TreeSet<String> solutions = new TreeSet<String>();
                    for (int k=1;k<values[1].length();k++){
                        String m = circshift(n,k);
                        int mVal = Integer.parseInt(m);
                        if(mVal<=B && mVal!=n  && mVal> n && !m.startsWith("0") && m.length()==Integer.toString(n).length() )
                        {
                            solutions.add(m);
                        }                   
                    }
                    total+=solutions.size();
                }
                out.println("Case #"+i+": "+total);
            }
            in.close();
            out.close();
        } catch (Exception e) {//Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }

}

    private static String circshift(int n, int k) {
        String nString=Integer.toString(n);
        int len=nString.length();
        String m =  nString.substring(len-k)+nString.subSequence(0, len-k);
        //System.out.println(n+" "+m);
        return m;
    }

}

package gcj.main;

import gcj.cases.competition.qualification_round_2012.CaseC;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class Main {

	
	public static final void main (String[] args) throws Exception{
//		doTask("taskTeszt0", "/home/dev/LetÃ¶ltÃ©sek/0-teszt-practice.in", "/home/dev/LetÃ¶ltÃ©sek/0-teszt-practice.out", new Case0());
//		doTask("taskSmall0", "/home/dev/LetÃ¶ltÃ©sek/A-small-attempt0.in", "/home/dev/LetÃ¶ltÃ©sek/A-small-attempt0.out", new Case0());
		
//		doTask("taskTesztB", "/home/dev/LetÃ¶ltÃ©sek/B-teszt-practice.in", "/home/dev/LetÃ¶ltÃ©sek/B-teszt-practice.out", new CaseB());
//		doTask("taskSmallB", "/home/dev/LetÃ¶ltÃ©sek/B-small-practice.in", "/home/dev/LetÃ¶ltÃ©sek/B-small-practice.out", new CaseB());
//		doTask("taskLargeB", "/home/dev/LetÃ¶ltÃ©sek/B-large-practice.in", "/home/dev/LetÃ¶ltÃ©sek/B-large-practice.out", new CaseB());
		
//		doTask("taskTesztC", "/home/dev/LetÃ¶ltÃ©sek/C-teszt-practice.in", "/home/dev/LetÃ¶ltÃ©sek/C-teszt-practice.out", new CaseC());
		doTask("taskSmallC", "/home/dev/LetÃ¶ltÃ©sek/C-small-attempt0.in", "/home/dev/LetÃ¶ltÃ©sek/C-small-attempt0.out", new CaseC());
//		doTask("taskLargeC", "/home/dev/LetÃ¶ltÃ©sek/C-large-practice.in", "/home/dev/LetÃ¶ltÃ©sek/C-large-practice.out", new CaseC());
		
		doTask(null, null, null, null); //because i hate the 'never used locally' warning... 
	}

	
	private static final void doTask(String taskID, String inpFilePath, String outFilePath, Case c) throws Exception {
		if(taskID == null) return;
		BufferedReader br = null;
		BufferedWriter bw = null;
		String strLine;
		int caseNum = 0;
		System.out.println(taskID + " strated...");
		try{
			{
				//open files
				br = new BufferedReader(new FileReader(new File(inpFilePath)));
				bw = new BufferedWriter(new FileWriter(new File(outFilePath)));
			}
			{
				//read caseNum value
				if ((strLine = br.readLine()) != null){
					caseNum = Integer.parseInt(strLine);	
				}
				System.out.println("CaseNum: "+caseNum);
			}
			for(int i=0; i<caseNum; i++){			
				System.out.println("\tprocessing Case #: "+(i+1));
				//load case
				c.init(i+1, br);
				//processing case
				c.solve();
				//write to file
				c.generateOutput(bw, i<caseNum-1);
			}
		}catch(Exception e){
			System.out.println(taskID + " failed!");
			e.printStackTrace();
		}finally{
			//end
			if(br!=null) br.close();
			if(bw!=null) bw.close();
			System.out.println(taskID + " finished.");
		}
	}
}
