package codejam;

import fixjava.Pair;

public class Utils {

	public static long minLong(long firstVal, long... otherVals) {
		long minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	public static int minInt(int firstVal, int... otherVals) {
		int minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	public static float minFloat(float firstVal, float... otherVals) {
		float minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	/**
	 * ArgMin returned as a Pair<Integer, Integer>(index, value). Array must
	 * have at least one value.
	 */
	public static Pair<Integer, Integer> argMin(int[] arr) {
		int min = arr[0];
		int argMin = 0;
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] < min) {
				min = arr[i];
				argMin = i;
			}
		}
		return new Pair<Integer, Integer>(argMin, min);
	}

	/**
	 * ArgMax returned as a Pair<Integer, Integer>(index, value). Array must
	 * have at least one value.
	 */
	public static Pair<Integer, Integer> argMax(int[] arr) {
		int max = arr[0];
		int argMax = 0;
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] > max) {
				max = arr[i];
				argMax = i;
			}
		}
		return new Pair<Integer, Integer>(argMax, max);
	}

}

package codejam2012.qualification.b;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.ArrayListMultimap;

public final class Memory {

    private static Logger log = LoggerFactory.getLogger(Memory.class);

    public ArrayListMultimap<Integer, Triplet> data = ArrayListMultimap.create();

    private static int startFor(int a) {
        return a < 2 ? 0 : a - 2;
    }

    private static int endFor(int a) {
        return a > 8 ? 10 : a + 2;
    }

    public void init() {
        log.debug("init: start");
        for (int a = 0; a <= 10; ++a) {
            int bStart = startFor(a);
            int bEnd = endFor(a);
            for (int b = bStart; b <= bEnd; ++b) {
                int cStart = startFor(b);
                int cEnd = endFor(b);
                for (int c = cStart; c <= cEnd; ++c) {
                    int total = a + b + c;
                    data.put(total, Triplet.of(a, b, c, total));
                }
            }
        }
        log.debug("init: finished");
    }
}
