import ru.ifmo.testlib.Checker;
import ru.ifmo.testlib.InStream;
import ru.ifmo.testlib.Outcome;

public class Check implements Checker {

    public static int digitSum(int a) {
        int ans = 0;
        while (a > 0) {
            ans += a%10;
            a /= 10;
        }
        return ans;
    }

    @Override
    public Outcome test(InStream inf, InStream ouf, InStream ans) {
        int a = inf.nextInt();
        int b = inf.nextInt();
        int cAns = ouf.nextInt();
        if (cAns <= 0) {
            return new Outcome(Outcome.Type.WA, String.format("Invalid number: %d", cAns));
        }
        if (a % cAns != 0) {
            return new Outcome(Outcome.Type.WA, String.format("%d is not a divisor of %d", cAns, a));
        }
        if (b % cAns != 0) {
            return new Outcome(Outcome.Type.WA, String.format("%d is not a divisor of %d", cAns, b));
        }

        int jAns = ans.nextInt();
        int cSum = digitSum(cAns);
        int jSum = digitSum(jAns);
        if (cSum > jSum) {
            return new Outcome(Outcome.Type.FAIL, String.format("Contestant can better. Jury: %d, Contestant: %d", jAns, cAns));
        } else if (cSum < jSum) {
            return new Outcome(Outcome.Type.WA, String.format("expected digit sum: %d, found: %d", jSum, cSum));
        }
        return new Outcome(Outcome.Type.OK, String.format("%d", jAns));
    }
}
