triangle
 
% triangle.pi  (in Picat)
% Declaratively solving Google Code Jam problems with Picat, PADL'15
% Sergii Dymchenko and Mariia Mykhailova
% http://goo.gl/enHWlq 
% Round 2 2008
% Problem B. Triangle Areas
%
% to use: picat triangle < input_file > output_file
%

import cp.
import util.    % using the function join/1

main =>
    C = read_int(),
    foreach (Case_num in 1..C)
        N = read_int(), M = read_int(), A = read_int(),
        do_case(Case_num, N, M, A)
    end.

do_case(Case_num, N, M, A) =>
    printf("Case #%w: ", Case_num),
    if model(N, M, A, Points), solve(Points) then
        printf("0 0 %s\n", join([to_string(V) : V in Points]))
    else
        println("IMPOSSIBLE")
    end.

model(N, M, A, Points) =>
    [X2, X3] :: 0..N,
    [Y2, Y3] :: 0..M,
    A #= abs(X2 * Y3 - X3 * Y2),
    Points = [X2, Y2, X3, Y3].