//Generates very strong time-limit tests for both brute and quadratic solutions.
//One may rewrite this to write the tests to files.
//E.g. "java Tester018 0 1 99999 100 nobrute" weeps out any quadratic solution.

import java.io.*;
import java.util.*;
import java.math.*;

public class Tester018 {
    static boolean useBrute;

    static void test(int k, String test) {
        long t0 = System.currentTimeMillis();
        String brute = useBrute ? digits_mb_brute.solve(k, test) : null;
        long t1 = System.currentTimeMillis();
        String nkk = digits_mb_nkk.solve(k, test);
        long t2 = System.currentTimeMillis();
        String nk = digits_mb.solve(k, test);
        long t3 = System.currentTimeMillis();
        if (!useBrute) {
            brute = nk;
        }
        System.out.println("K = " + k);
        System.out.println("S = " + test);
        if (useBrute) {
            System.out.println("Time(brute) = " + (t1 - t0));
        }
        System.out.println("Time(nkk)   = " + (t2 - t1));
        System.out.println("Time(nk)    = " + (t3 - t2));
        if (!brute.equals(nkk) || !brute.equals(nk)) {
            System.out.println("WRONG ANSWER");
            if (useBrute) {
                System.out.println("Ans(brute) = " + brute);
            }
            System.out.println("Ans(nkk)   = " + nkk);
            System.out.println("Ans(nk)    = " + nk);
            System.exit(1);
        } else {
            System.out.println("A = " + nk);
        }
    }

    public static void main(String[] args) {
        if (args.length < 4 || args.length > 5) {
            System.out.println("Usage: Tester018 <#0> <#1> <#8> <k> [nobrute]");
            System.exit(-1);
        }
        useBrute = !(args.length > 4 && args[4].equals("nobrute"));
        int n0 = Integer.parseInt(args[0]);
        int n1 = Integer.parseInt(args[1]);
        int n8 = Integer.parseInt(args[2]);
        int k = Integer.parseInt(args[3]);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n0; ++i) {
            sb.append('0');
        }
        for (int i = 0; i < n1; ++i) {
            sb.append('1');
        }
        for (int i = 0; i < n8; ++i) {
            sb.append('8');
        }
        test(k, sb.toString());
    }
}
