% by Neng-Fa Zhou, Jan. 2012

maxflow(M,Source,Sink):-
    N is M^length,
    new_array(X,[N,N]),
    foreach(I in 1..N, J in 1..N, 
        X[I,J] :: 0..M[I,J]
    ),
    term_variables(X,Vars),
    foreach(I in 1..N, 
        (I\==Source,I\==Sink->
             sum([X[J,I] : J in 1..N]) $= 
             sum([X[I,J] : J in 1..N]) 
        ;
             true
        )
    ),
    Total $= sum([X[Source,I] : I in 1..N]),
    Total $= sum([X[I,Sink] : I in 1..N]),
    ip_solve([max(Total)],[Total|Vars]),
    writeln(Total).

go :-
        A= []([](0,0,0,7,8,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,4,0,0,0,0,0,0,6,8,0,0,0,5,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,5,0),[](0,9,5,0,0,0,0,0,8,1,0,0,0,0,9,4,5,0,0,0,6,4,8,2,0,3,7,0,0,0,2,0,0,0,6,4,0,0,5,1,0,0,0,0,0,0,0,0,8,0,0,4,0,0,0,5,0,0,0,0),[](0,8,0,0,0,4,0,0,0,0,0,0,0,8,5,1,1,0,2,0,0,5,0,0,0,0,0,0,7,0,5,0,0,0,0,8,0,0,4,0,5,3,0,0,0,0,0,0,0,0,0,0,8,0,0,0,1,0,6,0),[](0,0,0,9,0,0,0,0,1,4,7,4,0,7,0,0,4,0,8,0,0,5,0,0,2,0,0,0,0,4,3,0,0,0,0,2,0,0,0,7,1,5,9,0,0,0,0,0,6,0,0,0,3,0,0,4,8,1,0,8),[](0,0,0,3,9,0,0,7,7,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,8,0,4,2,0,0,8,8,1,9,9,4,0,0,9,1,0,0,0,0,0,0,0,0,7,0,0,0,0),[](8,0,3,0,0,0,0,0,8,7,0,7,0,0,7,0,0,0,9,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,6,0,0,0,0,0,0,6,7,0,4,0,0,2,4,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