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

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Lance Chen
 */
public class CodeHelper {

    private static String FILE_ROOT = "D:/workspace/googlecodejam/meta";

    public static List<List<String>> loadInputsExcludes(String fileName) {
        List<List<String>> result = new ArrayList<List<String>>();
        List<String> lines = FileUtil.readLines(FILE_ROOT + fileName);
        int index = 0;
        for (String line : lines) {
            if (index == 0) {
                index++;
                continue;
            }
            if (index % 2 == 1) {
                index++;
                continue;
            }
            List<String> dataList = new ArrayList<String>();
            String[] dataArray = line.split("\\s+");
            for (String data : dataArray) {
                if (data.trim().length() > 0) {
                    dataList.add(data);
                }
            }
            result.add(dataList);
            index++;
        }
        return result;
    }

    public static List<List<String>> loadInputs(String fileName) {
        List<List<String>> result = new ArrayList<List<String>>();
        List<String> lines = FileUtil.readLines(FILE_ROOT + fileName);
        for (String line : lines) {
            List<String> dataList = new ArrayList<String>();
            String[] dataArray = line.split("\\s+");
            for (String data : dataArray) {
                if (data.trim().length() > 0) {
                    dataList.add(data);
                }
            }
            result.add(dataList);
        }
        return result;
    }

    public static List<String> loadInputLines(String fileName) {
        return FileUtil.readLines(FILE_ROOT + fileName);
    }

    public static void writeOutputs(String fileName, List<String> lines) {
        FileUtil.writeLines(FILE_ROOT + fileName, lines);
    }
}

package MyAllgoritmicLib;

public class Sort {
	public static int partition(int[] m, int a, int b) {
		int i = a;
		for (int j = a; j <= b; j++) // ïðîñìàòðèâàåì ñ a ïî b
		{
			if (m[j] >= m[b]) // åñëè ýëåìåíò a[j] íå ïðåâîñõîäèò
			// a[b],
			{
				int t = m[i]; // ìåíÿåì ìåñòàìè a[j] è a[a], a[a+1], a[a+2] è
				// òàê äàëåå...
				m[i] = m[j]; // òî åñòü ïåðåíîñèì ýëåìåíòû ìåíüøèå a[b] â
				// íà÷àëî,
				m[j] = t; // à çàòåì è ñàì a[b] «ñâåðõó»
				i++; // òàêèì îáðàçîì ïîñëåäíèé îáìåí: a[b] è a[i], ïîñëå ÷åãî
				// i++
			}
		}
		return i - 1; // â èíäåêñå i õðàíèòñÿ <íîâàÿ ïîçèöèÿ ýëåìåíòà a[b]> + 1
	}

	public static void quicksort(int[] m, int a, int b) // a - íà÷àëî ïîäìíîæåñòâà,
	// b -
	// êîíåö
	{ // äëÿ ïåðâîãî âûçîâà: a = 0, b = <ýëåìåíòîâ â ìàññèâå> - 1
		if (a >= b)
			return;
		int c = partition(m, a, b);
		quicksort(m, a, c - 1);
		quicksort(m, c + 1, b);
	}
}
