package jp.funnything.competition.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;

import org.apache.commons.io.IOUtils;

public class QuestionReader {
    private final BufferedReader _reader;

    public QuestionReader( final File input ) {
        try {
            _reader = new BufferedReader( new FileReader( input ) );
        } catch ( final FileNotFoundException e ) {
            throw new RuntimeException( e );
        }
    }

    public void close() {
        IOUtils.closeQuietly( _reader );
    }

    public String read() {
        try {
            return _reader.readLine();
        } catch ( final IOException e ) {
            throw new RuntimeException( e );
        }
    }

    public BigDecimal[] readBigDecimals() {
        return readBigDecimals( " " );
    }

    public BigDecimal[] readBigDecimals( final String separator ) {
        final String[] tokens = readTokens( separator );

        final BigDecimal[] values = new BigDecimal[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = new BigDecimal( tokens[ index ] );
        }

        return values;
    }

    public BigInteger[] readBigInts() {
        return readBigInts( " " );
    }

    public BigInteger[] readBigInts( final String separator ) {
        final String[] tokens = readTokens( separator );

        final BigInteger[] values = new BigInteger[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = new BigInteger( tokens[ index ] );
        }

        return values;
    }

    public int readInt() {
        final int[] values = readInts();

        if ( values.length != 1 ) {
            throw new IllegalStateException( "Try to read single interger, but the line contains zero or multiple values" );
        }

        return values[ 0 ];
    }

    public int[] readInts() {
        return readInts( " " );
    }

    public int[] readInts( final String separator ) {
        final String[] tokens = readTokens( separator );

        final int[] values = new int[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = Integer.parseInt( tokens[ index ] );
        }

        return values;
    }

    public long readLong() {
        final long[] values = readLongs();

        if ( values.length != 1 ) {
            throw new IllegalStateException( "Try to read single interger, but the line contains zero or multiple values" );
        }

        return values[ 0 ];
    }

    public long[] readLongs() {
        return readLongs( " " );
    }

    public long[] readLongs( final String separator ) {
        final String[] tokens = readTokens( separator );

        final long[] values = new long[ tokens.length ];
        for ( int index = 0 ; index < tokens.length ; index++ ) {
            values[ index ] = Long.parseLong( tokens[ index ] );
        }

        return values;
    }

    public String[] readTokens() {
        return readTokens( " " );
    }

    public String[] readTokens( final String separator ) {
        return read().split( separator );
    }
}

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

import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author Ka
 */
public class Recy {
        private File file;
    private int aantal;
    private ArrayList<String> cases;
    private ArrayList<Integer> max;
    public Recy(File f) throws FileNotFoundException
    {
        file = f;
        Scanner scanner = new Scanner(new FileReader(file));
        aantal = scanner.nextInt();
        cases = new ArrayList<String>(aantal);
        max = new ArrayList<Integer>(aantal);
        scanner.nextLine();
        for(int i =0; i < aantal ; i++)
        {
            String s = scanner.nextLine();
            cases.add(s);
        }
        System.out.println(cases);
    }
    public void scores()
    {
        for(String s : cases)
        {
            int counter = 0;
            ArrayList<Integer> nb = new ArrayList<Integer>();
            String sb = "";
            while(counter < s.length())
            {
                if(s.charAt(counter)!= ' ')
                {
                    sb = sb + s.charAt(counter);
                }
                if(s.charAt(counter) == ' '&& counter != s.length()-1)
                {
                    int n = Integer.parseInt(sb);
                    nb.add(n);
                    sb = "";
                }
                counter++;
            }
            if(counter == s.length())
            {
                int n = Integer.parseInt(sb);
                nb.add(n);
                sb = "";
            }
            System.out.println(nb);
            options(nb);
        }
    }
    public void options(ArrayList<Integer>nr)
    {
        int n = nr.get(0), m = nr.get(1),amount=0;
        if(n < 10 && m < 10)
            amount = 0;
        else if(n >= 10 && n < 100&& n % 10 < 10)
        {
            for(int i = n ; i < m ; i++)
            {
                String s = Integer.toString(i);
                int g = Integer.parseInt(s);
                String s1 = s.charAt(1)+""+ s.charAt(0)+"";
                int r = Integer.parseInt(s1);
                if(g >= n && g <= m && r >= n && r <= m && g < r )
                    amount++;
            }
        }
        else if(n >= 100 && n < 1000)
        {
            for(int i = n ; i < m ; i++)
            {
                String s = Integer.toString(i);
                int g = Integer.parseInt(s);
                String s1 = s.charAt(2)+""+ s.charAt(0)+""+s.charAt(1);
                String s2 = s.charAt(1)+""+ s.charAt(2)+""+s.charAt(0);
                int r = Integer.parseInt(s1);
                int r1 = Integer.parseInt(s2);
                if(g >= n && g <= m && r >= n && r <= m && g < r )
                    amount++;
                if(r != r1)
                {
                    if(g >= n && g <= m && r1 >= n && r1 <= m && g < r1 )
                        amount++;
                }
            }
        }
        else if(n >= 1000 && n < 10000)
        {
            for(int i = n ; i < m ; i++)
            {
                String s = Integer.toString(i);
                int g = Integer.parseInt(s);
                String s1 = s.charAt(3)+""+s.charAt(0)+""+ s.charAt(1)+""+s.charAt(2);
                String s2 = s.charAt(2)+""+s.charAt(3)+""+ s.charAt(0)+""+s.charAt(1);
                String s3 = s.charAt(1)+""+s.charAt(2)+""+ s.charAt(3)+""+s.charAt(0);
                int r = Integer.parseInt(s1);
                int r1 = Integer.parseInt(s2);
                int r2 = Integer.parseInt(s3);
                if(g >= n && g <= m && r >= n && r <= m && g < r )
                    amount++;
                if(r != r1 && r1 != r2 && r != r2)
                {
                    if(g >= n && g <= m && r1 >= n && r1 <= m && g < r1 )
                        amount++;
                    if(g >= n && g <= m && r2 >= n && r2 <= m && g <= r2 )
                        amount++;
                }
            }
        }
        max.add(amount);
    }
        public void output(BufferedWriter out) throws FileNotFoundException, IOException
    {
        int counter = 1;
        for(Integer s : max )
        {
            out.write("Case #" + counter + ": ");
            out.write(s+"\n");
            counter++;
        }
        out.close();
    }
}
