%-----------------------------------------------------------------------------
% mdep.pl--
%
%    A program for the discovery of multivalued dependencies from 
%    relations. 
% 
% Authors: I. Savnik, P.A. Flach
%-----------------------------------------------------------------------------

% Last update: 3/3/00.

:- op( 250, xfy, -> ).
:- op( 250, xfy, ->> ).
:- op( 300, xfy, : ).
:- dynamic queue/2, cntr/1, remember/1, active_relation/2, work_mode/1, 
           method/1.

   
%-----------------------------------------------------------------------------
% Induction of mvds.

% mvds( Relation ).
%
%   Main routine which prepares complete environment for the 
%   discovery of mvds, activates the computation of negative and 
%   positive borders, and cleans the environment. 

mvds( Relation ) :- 
    tree_clear( negat, glb ),
    tree_clear( work, lub ),
    tree_clear( work1, lub ),
    activate( Relation ),
    init_work_tree,
    (  method( bottomup ),
       writel([ nl, 'Construction of negative border', nl, nl ]),
       induce_negative_border,
       writel([ nl, 'Filtering negative border', nl, nl ]),
       tree_remove_gener( negat, exact ),
       tree_print( 'Negative border: ', negat ),
       writel([ nl, 'Construction of positive border', nl, nl ]),
       bottomup_positive_border
    ;  method( topdown ),
       writel([ nl, 'Construction of positive border', nl, nl ]),
       topdown_positive_border ), 
    writel([ nl, 'Filtering positive border', nl, nl ]),
    tree_remove_spec( work, exact ),
    tree_print( 'Positive border: ', work ),
    clear_environment.



% init_work_tree.
% 
%   Initialize tree 'work'  to the most general sentence defined 
%   under the schema of active relation. 

init_work_tree :- 
    active_relation( _, NumOfAttr ),
    make_attr_list( 1, NumOfAttr, InitDEP, AttList ),
    assert( attributes( AttList )),
    tree_add( work, [0,[0]|InitDEP] ), !.
  


% make_attr_list( Attr, NumOfAttr, AttrSSet, AttrSet ).
%
%   Given the number of attributes in active relation construct
%   a list of attributes AttrSet including attributes from 
%   [Attr..NumOfAttr] and a list of lists including a single 
%   attribute from [Attr..NumOfAttr].

make_attr_list( Attr, NumOfAttr, [[Attr]|RestL1], [Attr|RestL2] ) :- 
    Attr =< NumOfAttr, 
    Attr1 is Attr + 1,
    make_attr_list( Attr1, NumOfAttr, RestL1, RestL2 ), !.
make_attr_list( Attr, NumOfAttr, [], [] ) :- 
    Attr > NumOfAttr.



% anti_unify_sets( +T1, +T2, -As, -Xs ).
%
%   Anti-unify tuples T1 and T2 and put variable attributes
%   in the set As and attributes with equal values in the Xs. 

anti_unify_sets( Args, T1, T2, As, Xs ) :- 
    find_anti_sets( 1, Args, T1, T2, As, Xs ), !.

find_anti_sets( N, Args, _, _, [], [] ) :- 
    N > Args, !.

find_anti_sets( N, Args, T1, T2, As, [ N|RestXs ]) :- 
    N =< Args,
    attr_val( N, T1, Val1 ),
    attr_val( N, T2, Val2 ),
    (  ( Val1 = ? ; Val2 = ? )
    ;  Val1 = Val2 ),
    N1 is N + 1,
    find_anti_sets( N1, Args, T1, T2, As, RestXs ).

find_anti_sets( N, Args, T1, T2, [ N|RestAs ], Xs ) :- 
  N =< Args,
  attr_val( N, T1, Val1 ),
  attr_val( N, T2, Val2 ),
  Val1 \== Val2,
  N1 is N + 1,
  find_anti_sets( N1, Args, T1, T2, RestAs, Xs ).



%-----------------------------------------------------------------------------
% Procedures for computing positive border

% bottomup_positive_border.
%
%   Bottom-up algorithm for computing positive border; incremental 
%   refinement of positive border with respect to invalid sentences. 
%   Initialy, tree 'work' contains sentence (0,R). 

bottomup_positive_border :- 
    tree_get( negat, [_|NS] ),
    writel([ '*** Processing invalid sentence ', NS, '.', nl ]),
    specialise_tree( work, NS ),
    fail. 
bottomup_positive_border :- 
    tree_empty( negat ), !.


% topdown_positive_border.
%
%   Top-down algorithm for computing positive border; top-down 
%   enumeration of sentences which are verified on the complete relation.
%   Initialy tree 'work' contains sentence (0,R). 

topdown_positive_border :- 
    tree_get( work, S ),             % single sentence 
    tree_clear( work, lub ),
    writel([ '*** Specialising sentence ', S, '.', nl ]),
    specialise_sntc( S ), !.


% specialise_sntc( Sx ).
%
%   Generates all specialisations of sentence S and checks them 
%   on complete relation.

specialise_sntc( [I|S] ) :- 
    sntc_invalid( S ),    
    debug_msg([ '     Sentence ', S, ' is not valid. ', nl ]),
    specialise_by_order( [I|S], _ ), !.

specialise_sntc( Sx ) :- 
    writel([ '*** Sentence ', Sx, ' is valid. ', nl ]),
    tree_add( work, Sx ), 
    debug_msg([ '     Sentence ', Sx, ' is added to PC. ', nl ]), !. 

%specialise_sntc( _ ) :- !.


% specialise_tree( NS ).  
%
%   Specialise all sentences from tree 'work' considering the
%   invalid sentence NS.

specialise_tree( Tree, NS ) :- 
    NS = [[0|X]|_],
    tree_gemember( Tree, [0], X, [_|NS], exact, Sx ),
    tree_del( Tree, Sx ),
    debug_msg([ '  Specialising sentence ', Sx, ' for ', NS, '.', nl ]),
    specialise_by_order( Sx, NS ), 
    fail.
specialise_tree( _, _ ) :- !.


% specialise_sntc( Sx, NS ).
%
%   Generates all specialisations of sentence S with respect to 
%   invalid sentence NS.

specialise_sntc( [I|S], NS ) :- 
    sntc_covers( S, NS ),                            % exact ordering
%   debug_msg([ '     Sentence ', S, ' >= ', NS, '.', nl ]),
    specialise_by_order( [I|S], NS ), !.

specialise_sntc( Sx, _ ) :- 
    tree_add( work, Sx ), 
    debug_msg([ '     Sentence ', Sx, ' is added to PC. ', nl ]), !. 

%specialise_sntc( _, _ ) :- !.


% specialise_by_order( Sx, NSx ).
%
%   Specialise Sx (with respect to NSx if bottom-up alg is used).

specialise_by_order( [Inx|S], NS ) :- 
    count( S, Num ),
    Up is Num - 1,
    Inx @< Up,
    create_range( Inx, Up, ILst ), 
    member( I, ILst ),
    pick( 0, I, S, El1, S1 ),
    create_range( I, Up, JLst ),
    member( J, JLst ),
    pick( 0, J, S1, El2, S2 ),
    get_from_end( El1, Last ),
    get_first( El2, First ),
    Last @< First,
    union( El1, El2, NewEl ),
    insert( 0, I, NewEl, S2, S3 ),
    \+ sntc_trivial( S3 ), 
    \+ tree_ge_member( work, [_|S3], sparse, _ ), 
    debug_msg([ '  Specialisation ', S3, ' of ', S, ' generated.', nl ]), 
    (  method( topdown ),
       specialise_sntc( [I|S3] ) 
    ;  method( bottomup ),
       specialise_sntc( [I|S3], NS )),
    fail.
specialise_by_order( S, _ ) :- 
    debug_msg([ '     No more specialisations of ', S, '.', nl ]), !.



%-----------------------------------------------------------------------------
% Procedures for computing negative border


% induce_negative_border.
%
%   Find all sentences that are refuted by active relation; 
%   sentences are stored in tree 'negat'.
 
induce_negative_border :- 
%   tree_clear( negat, glb ),
%   open( 'mvds.neg', write, S ), 
    induce_negative.
%   close( S ).

induce_negative :- 
    active_relation( _, Args ), 
    dummy_tuple( T1 ), 
    dummy_tuple( T2 ), 
    T1, T2, T1 @< T2,
%   debug_msg( [ 'T1: ', T1, ' T2: ', T2, nl ]),
    anti_unify_sets( Args, T1, T2, Ys, Xs1 ),
    Xs = [0|Xs1],    
    partition( Ys, Ya, Yb ), 
    Ya \== [], Yb \== [],
    Ya @< Yb,
%   debug_msg( [ 'Xs: ', Xs1, ' Ya: ', Ya, ' Yb: ', Yb, nl ]),
    \+ tree_se_member( negat, [0,Xs,Ya,Yb], exact, _ ),
    debug_msg( [ '  Candidate sentence: ', [Xs,Ya,Yb], nl ]),
    construct_mvd_tuples( T1, T2, Xs1, Ya, T3, T4 ),
%   debug_msg( [ T1, T2, T3, T4, nl ] ),
    missing_mvd_tuples( T3, T4 ), 
    writel( [ '*** Negative sentence ', [Xs,Ya,Yb], '.', nl ]),
    tree_add( negat, [0,Xs,Ya,Yb] ),
    fail.
induce_negative :- % read(_), !.
    !.


% counter.
% Simple counter used for testing.

cntr(1).
counter :- 
    clause( cntr(I), true, Ref ),
    erase( Ref ),
    I1 is I + 1,
    M is I1 mod 100,
    (  M == 0,
       writel([ 'Number=', I1 ])
    ;  M \== 0 ),
    assertz( cntr(I1) ), !.


% check_mvd_tuples( T3, T4 ).
%
%   Checks if tuples T3 and T4 exist in active relation. 
%   Predicate succeeds if one of tuples does not exist and 
%   fails otherwise. 

missing_mvd_tuples( T3, _ ) :- 
    \+ T3, !.
missing_mvd_tuples( _, T4 ) :- 
    \+ T4, !.
missing_mvd_tuples( _, _ ) :- 
    fail.


% construct_mvd_tuples( T1, T2, Xs, Ya, T3, T4 ).
%
%   Given tuples T1 and T2 construct two tuples that 
%   have to be in the relation so that Xs->>Ya holds. 

construct_mvd_tuples( T1, T2, Xs, Ya, T3, T4 ) :- 
    dummy_tuple( T3 ),
    dummy_tuple( T4 ),
    compose_tuples( 1, T1, T2, Xs, Ya, T3, T4 ), !. 

compose_tuples( N, T1, T2, Xs, Ya, T3, T4 ) :- 
    active_relation( _, Args ), 
    (  dmember( N, Xs ), 
       attr_val( N, T1, Val ),
       attr_val( N, T3, Val ),
       attr_val( N, T4, Val )
    ;  dmember( N, Ya ),
       attr_val( N, T1, Val1 ),
       attr_val( N, T2, Val2 ),
       attr_val( N, T3, Val1 ),
       attr_val( N, T4, Val2 )
    ;  attr_val( N, T1, Val1 ),
       attr_val( N, T2, Val2 ),
       attr_val( N, T3, Val2 ),
       attr_val( N, T4, Val1 ) ), 
    N1 is N+1,
    (  N == Args
    ;  compose_tuples( N1, T1, T2, Xs, Ya, T3, T4 )), !.



%-----------------------------------------------------------------------------
% Operations on sentences.

% sntc_trivial( S ).
% 
%    Tests if sentence S is trivial.

sntc_trivial( [_] ).
sntc_trivial( [_|[_]] ).


% sntc_covers_mvd( [Z|DepY], MVD ).         % not used !!
%
%   Check if sentence [Z|DepY] covers dependency X->>Y.

sntc_covers_mvd( [Z|DepY], X->>Y ) :-     
    sub_set_eq( Z, X ),                     % Z is subset of X
    diff( X, Z, RestX ),                    % RestX = X - Z 
    db_subtract_set( DepY, RestX, DepY1 ),  % DepY1 = { Y'i | Y'i = Yi-RestX }
    sort( DepY1, DepY2 ),                   % 
    db_covers_set( DepY2, Y ), !.           % Y is exact union of DepY2 elems


% sntc_covers( [Z|DepZ], [X|DepX] ).
%
%   Check if sentence [Z|DepZ] covers sentence [X|DepX] 
%   (ie. [Z|DepZ] is more general than [X|DepX] ).

sntc_covers( [Z|DepZ], [X|DepX] ) :- 
    sub_set_eq( Z, X ),
    diff( X, Z, RestX ),
    db_subtract_set( DepZ, RestX, DepZ1 ),
    sort( DepZ1, DepZ2 ), 
    db_covers( DepZ2, DepX ), !.


% sntc_covers_sparse( [Z|DepZ], [X|DepX] ).
%
%     Check if sentence [X|DepX] can be generated from [Z|DepZ] 
%     using sparse ordering of sentences.

sntc_covers_sparse( [Z,DepZ], [X|DepX] ) :- 
    sub_set_eq( Z, X ),
    diff( X, Z, RestX ),
    subunion_sets( RestX, DepZ, DepZ1 ),
    sort( DepZ1, DepZ2 ), 
    db_covers( DepZ2, DepX ), !.


% check if X is an union of elements of DepZ; 
% remove that elements from DepZ and return DepZ1.

subunion_sets( [], L, L ) :- !. 
subunion_sets( X, [Y|L], L1 ) :- 
    sub_set_eq( Y, X ), 
    diff( X, Y, Z ),
    subunion_sets( Z, L, L1 ), !. 
subunion_sets( X, [Y|L], [Y|L1] ) :-
    subunion_sets( X, L, L1 ), !. 


% sntc_mge( S1, S2, Ord ) & sntc_mgt( S1, S2, Ord ).
% sntc_mse( S1, S2, Ord ) & sntc_msp( S1, S2, Ord ).
%
%   Check if S1 is more general|specifc (or equal) to S2 
%   with regards to exact or sparse orderings.

sntc_mge( S1, S2, exact ) :- 
    sntc_covers( S1, S2 ).
sntc_mge( S1, S2, sparse ) :- 
    sntc_covers_sparse( S1, S2 ).

sntc_mgt( S1, S2, exact ) :- 
    sntc_covers( S1, S2 ),
    S1 \== S2.
sntc_mgt( S1, S2, sparse ) :- 
    sntc_covers_sparse( S1, S2 ),
    S1 \== S2.

sntc_mse( S1, S2, exact ) :- 
    sntc_covers( S2, S1 ).
sntc_mse( S1, S2, sparse ) :- 
    sntc_covers_sparse( S2, S1 ).

sntc_msp( S1, S2, exact ) :- 
    sntc_covers( S2, S1 ),
    S1 \== S2.
sntc_msp( S1, S2, sparse ) :- 
    sntc_covers_sparse( S2, S1 ),
    S1 \== S2.


% sntc_entails( S1, S2, Ord ). 
%
%   Check if S2 can be entailed from S1 (exact|sparse). 

sntc_entails( S1, S2, exact ) :- 
    sntc_covers( S1, S2 ).
sntc_entails( S1, S2, sparse ) :- 
    sntc_covers_sparse( S1, S2 ).


% sntc_lub( S1, S2, S3 ).
%
%   Calculate least upper bound of sentences S1 and S2, returning 
%   sentence S3. 

sntc_lub( [X|DepX], [Y|DepY], NewDepLub ) :-       % upper bound !!
  intsc( X, Y, Z ),                                
  diff( Y, Z, RestY ),
  diff( X, Z, RestX ),
  (  RestX == [], NewDepX1 = DepX
  ;  RestX \== [], NewDepX1 = [RestX|DepX] ),
  (  RestY == [], NewDepY1 = DepY
  ;  RestY \== [], NewDepY1 = [RestY|DepY] ),
  sort( NewDepX1, NewDepX ),
  sort( NewDepY1, NewDepY ),
  db_lub( NewDepX, NewDepY, DepLub ),
  sort( [Z|DepLub], NewDepLub ), !.


% sntc_glb( S1, S2, S3 ).
%
%   Calculate greatest lower bound of sentences S1 and S2, returning 
%   a sentence S3. 

sntc_glb( [X|DepX], [Y|DepY], [Z|DepLub] ) :-
    union( X, Y, Z ),
    db_subtract_set( DepX, Z, NewDepX ),
    db_subtract_set( DepY, Z, NewDepY ),
    db_glb( NewDepX, NewDepY, DepLub ).


% sntc_calc_G( S1, S2, Gty, S3 ).
%
%   Calculate greatest lower bound of sentences S1 and S2, returning
%   sentence S3. 

sntc_calc_G( S1, S2, Gty, G ) :- 
    Gty == lub,
    sntc_lub( S1, S2, G ), !.

sntc_calc_G( S1, S2, Gty, G ) :- 
    Gty == glb,
    sntc_glb( S1, S2, G ), !.


% sntc_calc_G_list( X, DEP, S1, Gty, G ).
%
%

sntc_calc_G_list( _, [], G, _, G ) :- !.
sntc_calc_G_list( X, [[_|Dep]|DEP], G, Gty, NewG ) :- 
    sntc_calc_G( [X|Dep], G, Gty, NewG1 ),
    sntc_calc_G_list( X, DEP, NewG1, Gty, NewG ). 


% sntc_equal( S1, S2 ).
%
%   Check if sentences S1 and S2 are equal. 

sntc_equal( S, S ).
%    Z == X, DepZ == DepX.
%    set_eq( Z, X ),
%    set_eq( DepZ, DepX ), !. 


% sntc_invalid( S ).
%
%   Checks if S is valid on the complete relation. 

sntc_invalid( [X1|DEP] ) :-
    X1 = [0|X],
    member( Y, DEP ),
    dummy_tuple( T1 ), 
    dummy_tuple( T2 ), 
    T1, 
    tuple_copyvals( T1, X, T2 ),
    T2, T1 \== T2,
    construct_mvd_tuples( T1, T2, X, Y, T3, T4 ),
    missing_mvd_tuples( T3, T4 ), !.


% tuple_copyvals( T1, X, T2 ).
%
%   Copy values of T1's attributes from X to T2.

tuple_copyvals( _, [], _ ) :- !.
tuple_copyvals( T1, [N|L], T2 ) :-
    attr_val( N, T1, Val ),
    attr_val( N, T2, Val ),
    tuple_copyvals( T1, L, T2 ). 


%-----------------------------------------------------------------------------
% Operations on dependency bases

% db_subtract_set( Dep, Z, NewDep ).
% 
%    Subtract Z from each set of Dep resulting NewDep. 

db_subtract_set( [], _, [] ) :- !.

db_subtract_set( [X|L], Y, [X1|L1] ) :-    % sorted ?!
    diff( X, Y, X1 ),
    X1 \== [],
    db_subtract_set( L, Y, L1 ).

db_subtract_set( [X|L], Y, L1 ) :- 
    diff( X, Y, X1 ), 
    X1 == [], 
    db_subtract_set( L, Y, L1 ). 


% db_covers_set( DEP, Y ).
%
%    Check if Y is exact union of sets from DEP.

db_covers_set( [X|L], Y ) :- 
  sub_set_eq( X, Y ),                     % X is subset of Y
  diff( Y, X, RestY ),
  db_covers_set( L, RestY ), !. 

db_covers_set( [X|L], Y ) :- 
  intsc( Y, X, Intsc ),              
  (  Intsc == [],                         % X and Y are disjunctive
     db_covers_set( L, Y )
  ;  !, fail ).                           % X and Y overlap     !!! check

db_covers_set( [], Y ) :-
  Y \== [],
  !, fail. 

db_covers_set( _, [] ) :- !.


% db_covers( DepX, DepY ).
%
%    Check if sets from dependency basis DepY are the exact union of 
%    sets from DepX.

db_covers( [Y|L], [Y1|L1] ) :- 
  Y == Y1, 
  db_covers( L, L1 ), !. 

db_covers( [Y|L], [Y1|L1] ) :- 
  sub_set_eq( Y, Y1 ), 
  diff( Y1, Y, RestY ),
  sort( [RestY|L1], L2 ),
  db_covers( L, L2 ), !. 

db_covers( [], [] ).


% db_add_units( Dep, X, NewDep ),
%
%    Add sets including single elements from X to Dep yielding 
%    NewDep.

db_add_units( Dep, X, NewDepS ) :- 
  add_units( Dep, X, NewDep ),
  sort( NewDep, NewDepS ).

add_units( Dep, [], Dep ).
add_units( Dep, [El|RestX], [[El]|RestNewDep] ) :- 
  add_units( Dep, RestX, RestNewDep ).


% db_lub( DepX, DepY, DepLub ).
% 
%    Compute least upper bound of DepX and DepY resulting
%    DepLub.

db_lub( [], Dep, Dep ).
db_lub( [X|RestDepX], DepY, DepLub ) :- 
  db_merge_lub( X, DepY, NewDepY ),
  db_lub( RestDepX, NewDepY, DepLub ).

db_merge_lub( X, [], [X] ). 

db_merge_lub( X, [Z|RestDep], NewDep ) :- 
  intsc( Z, X, ZX ),
  ZX == [],
  db_merge_lub( X, RestDep, NewDep1 ),
  sort( [Z|NewDep1], NewDep ).
  
db_merge_lub( X, [Z|RestDep], NewDep ) :- 
  intsc( Z, X, ZX ),
  ZX \== [],
  diff( Z, X, ZRest ),
  diff( X, Z, XRest ),
  (  ZRest \== [],
     XRest \== [],
     db_merge_lub( XRest, RestDep, NewDep1 ),
     sort( [ZRest,ZX|NewDep1], NewDep )
  ;  ZRest == [],
     XRest \== [],
     db_merge_lub( XRest, RestDep, NewDep1 ),
     sort( [ZX|NewDep1], NewDep )
  ;  ZRest \== [],
     XRest == [],
     sort( [ZX,ZRest|RestDep], NewDep )
  ;  ZRest == [], 
     XRest == [],
     sort( [ZX|RestDep], NewDep )).


% db_glb( DepX, DepY, DepLub ).
% 
%    Compute greatest lower bound of DepX and DepY yielding
%    DepLub.

db_glb( [], Dep, Dep ).
db_glb( [X|RestDepX], DepY, DepLub ) :- 
  db_merge_glb( X, DepY, NewDepY ),
  db_glb( RestDepX, NewDepY, DepLub ).

db_merge_glb( X, [], [X] ).

db_merge_glb( X, [Z|RestDep], NewDep ) :-
  intsc( Z, X, ZX ),
  ZX == [],
  db_merge_glb( X, RestDep, NewDep1 ),
  sort( [Z|NewDep1], NewDep ).
  
db_merge_glb( X, [Z|RestDep], NewDep ) :-
  intsc( Z, X, ZX ),
  ZX \== [],
  union( Z, X, ZuX ),
  db_merge_glb( ZuX, RestDep, NewDep1 ),
  sort( NewDep1, NewDep ).


% db_calc_E( Dep1, Dep2, Gty, Dep3 ).
% 

db_calc_E( Dep1, Dep2, Gty, Dep3 ) :- 
    Gty = lub,
    db_lub( Dep1, Dep2, Dep3 ), !.

db_calc_E( Dep1, Dep2, Gty, Dep3 ) :- 
    Gty = glb,
    db_glb( Dep1, Dep2, Dep3 ), !.



%-----------------------------------------------------------------------------
% Trees - filters

% tree_remove_spec( +Tree ).
%
%     Remove sentences that can be obtained by specializing some 
%     sentence from Tree. 

tree_remove_spec( Tree, Ord ) :- 
    tree_info( Tree, Gty ),
    tree_clear( work2, Gty ),
    Node =.. [ Tree, X, _, DEP ],
    clause( Node, true ),
%   DEP \== [],
    member( [I|Dep], DEP ),
    writel( [ '*** Checking sentence ', [X|Dep], '.', nl ]),
    (  \+ tree_gt_member( Tree, [_,X|Dep], Ord, _ ), 
       tree_add( work2, [I,X|Dep] )
    ;  true ),
    debug_msg( [ '  Generalisation of ', [X|Dep], ' exists.', nl ]),
%-  tree_del( Tree, [_,X|Dep] ),
    false.
tree_remove_spec( Tree, _ ) :- 
    tree_info( Tree, Gty ),
    tree_clear( Tree, Gty ),
    tree_copy( work2, Tree ), !.


% tree_remove_gener( +Tree ).
%
%    Filter tree by removing sentences which are more general than 
%    some sentence from tree Tree.

tree_remove_gener( Tree, Ord ) :- 
    tree_info( Tree, Gty ),
    tree_clear( work2, Gty ),
    Node =.. [ Tree, X, _, DEP ],
    clause( Node, true ),
%   DEP \== [],
    member( [I|Dep], DEP ),
    writel( [ '*** Checking sentence ', [X|Dep], '.', nl ]),
    (  \+ tree_sp_member( Tree, [_,X|Dep], Ord, _ ),
       tree_add( work2, [I,X|Dep] )
    ;  true ),
    debug_msg( [ '  Specialisation of ', [X|Dep], ' exists.', nl ]),
%-  tree_del( Tree, [_,X|Dep] ),
    false.
tree_remove_gener( _, _ ) :-
    tree_info( Tree, Gty ),
    tree_clear( Tree, Gty ),
    tree_copy( work2, Tree ), !.



%-----------------------------------------------------------------------------
% Trees - generalized member operations


% tree_semember( Tree, X1, X2, Sx, Ord, S1x ).     
%   
%    Check if Tree includes more specific sentence than 
%    (or equal) sentence Sx. G variables of Tree must include 
%    glb of sentences represented in subtrees. 

tree_semember( Tree, X1, [], [I|S], Ord, S1x ) :-        % end of X
  Node =.. [ Tree, X1, G, E ],
  clause( Node, true ),
  \+ sntc_msp( S, G, Ord ), 
  (  E \== [],                                      % end of sntc
     member( [Inx|Dep], E ),
     sntc_entails( S, [X1|Dep], Ord ),
     S1x = [Inx,X1|Dep]
  ;  get_from_end( X1, A1 ),                        % search subtrees
     active_relation( _, A2 ),
     A1p is A1 + 1,
     A2p is A2 + 1,
     create_range( A1p, A2p, Candidates ),
     member( A, Candidates ),
     add_to_end( A, X1, X1New ),
     tree_semember( Tree, X1New, [], [I|S], Ord, S1x )).

tree_semember( Tree, X1, X2, [I|S], Ord, S1x ) :-             
  Node =.. [ Tree, X1, G, E ],
  clause( Node, true ),
  \+ sntc_msp( S, G, Ord ),
  (  E \== [],                                          % end of sentence 
     member( [Inx|Dep], E ),
     sntc_entails( S, [X1|Dep], Ord ),
     S1x = [Inx,X1|Dep]
  ;  X2 = [A|X2New],                                    % try to use X2
     add_to_end( A, X1, X1New ),
     tree_semember( Tree, X1New, X2New, [I|S], Ord, S1x )     
  ;  get_from_end( X1, A1 ),                            % try attr btwn X1-X2
     X2 = [ A2|_ ],
     A1p is A1 + 1,
     create_range( A1p, A2, Candidates ),
     member( A, Candidates ),
     add_to_end( A, X1, X1New ), 
     tree_semember( Tree, X1New, X2, [I|S], Ord, S1x )). 

create_range( A, A, [] ) :- !.
create_range( A1, A2, [A1|L] ) :-
     A1p is A1 + 1,
     create_range( A1p, A2, L ).
 

% tree_se_member( Tree, Sx, Ord, S1x ).
%   
%    Check if Tree includes sentences more specific or equal to
%    (with regards to exact or sparse ordering) sentence Sx 
%    and return it as S1x. 

tree_se_member( Tree, Sx, Ord, S1x ) :-    
    Sx = [_,[0|X2]|_],
    tree_semember( Tree, [0], X2, Sx, Ord, S1x ), !.


% tree_sp_member( Tree, Sx, Ord, S1x ).
%

tree_sp_member( Tree, [I|S], Ord, [I1|S1] ) :- 
  S = [[0|X2]|_],
  tree_semember( Tree, [0], X2, [I|S], Ord, [I1|S1] ),
  \+ sntc_equal( S, S1 ), !. 


% tree_gemember( Tree, Path, Rest, Sx, Ord, S1x ).
%
%   Check if Tree includes more general sentence than S and return 
%   one using the variable S1 if such exists. G variables of Tree 
%   must include lub of sentences represented in subtrees.

tree_gemember( Tree, X1, X2, [I|S], Ord, S1x ) :-   
    Node =.. [ Tree, X1, G, E ],
    clause( Node, true ),
    \+ sntc_mgt( S, G, Ord ),  
    (  E \== [],                                         % sentence found? 
       member( [Inx|Dep], E ),
       sntc_entails( [X1|Dep], S, Ord ),
       S1x = [Inx,X1|Dep]
    ;  X2 = [A|X2New],                                   % try to use X2
       add_to_end( A, X1, X1New ),
       tree_gemember( Tree, X1New, X2New, [I|S], Ord, S1x )     
    ;  X2 = [ _|X2New ],                                 % skip atr from X2
       tree_gemember( Tree, X1, X2New, [I|S], Ord, S1x )). 


% tree_ge_member( Tree, Sx, Ord, S1x ).
%
%    Check if Tree includes sentences more general or equal to 
%    sentence Sx. 

tree_ge_member( Tree, Sx, Ord, S1x ) :-   
    Sx = [_,[0|X2]|_],
    tree_gemember( Tree, [0], X2, Sx, Ord, S1x ), !.


% tree_gt_member( Tree, Sx, Ord, S1x ).
%

tree_gt_member( Tree, [I|S], Ord, [I1|S1] ) :- 
    S = [[0|X2]|_],
    tree_gemember( Tree, [0], X2, [I|S], Ord, [I1|S1] ),
    \+ sntc_equal( S, S1 ), !. 



%-----------------------------------------------------------------------------
% Trees

:- dynamic work/1, work1/1, work2/1, negat/1, result/1, pair/1, 
           tree_info/1. 

% sentence representation: 
%     SSet =  [X0,X1,...,Xn]
%     X0  ==  left-hand side of sentence
%     X1,...,Xn == dependency basis
 
% sentence representation for the enumeration: 
%     Sx =  [Active,SSet]
%     Active == index of the active set
%     SSet   == sentence

% tree representation:  
%     each node is a clause: tree( X, G, E ).
%           X - left-hand side of sentence
%           G - lub of all DEP-s of sntncs that go thru node
%           E - DBs of sentences (X,DB) going thru node 


% tree_member( Tree, Sx ).
%
%   Checks if sentence Sx is an element of Tree. 
%   Repeated calls not allowed.

tree_member( Tree, [_,X|Dep] ) :- 
    Node =.. [ Tree, X, _, DEP ], 
    clause( Node, true ), 
    dmember( [_|Dep], DEP ), !.


% tree_add( Tree, Sx ).
%
%   Adds a new sentence S to Tree. Depending on the variable 
%   Gty routine calculates variables G using operation lub or glb.

tree_add( Tree, [I,X|Dep] ) :- 
    tree_info( Tree, Gty ), 
    conc( X1, X2, X ),
    X1 \== [],
    (  X2 \== [],                                         % inner node
       tree_add_node( Tree, X1, [X|Dep], [], Gty )
    ;  X2 == [],                                          % last node
       tree_add_node( Tree, X1, [X|Dep], [I|Dep], Gty )),
    fail.
tree_add( _, _ ) :- !.

tree_add_node( Tree, X1, S, IDep, Gty ) :-
    Node =.. [ Tree, X1, G, E ], 
    (  clause( Node, true, Ref ), 
       erase( Ref ),
       (  IDep == [],                                % inner node
          NewE = E
       ;  IDep \== [],
          IDep = [_|Dep],
          (  dmember( [_|Dep], E ),                  % last node, duplicate  
             NewE = E
          ;  \+ dmember( [_|Dep], E ),               % last node, new
             add( IDep, E, NewE ))),                 % ?? db_calc_E(E,E1)
       sntc_calc_G( S, G, Gty, NewG ),
       Node1 =.. [ Tree, X1, NewG, NewE ], 
       assertz( Node1 )
    ;  \+ clause( Node, true ),                      % new node
       (  IDep == [],                                % inner node of sntc
          Node1 =.. [ Tree, X1, S, [] ]
       ;  Dep \== [],                                % last node of sntc
          Node1 =.. [ Tree, X1, S, [IDep] ] ),
       assertz( Node1 )), !.


% tree_del( Tree, Sentence ).
%
%   Deletes Sentence from Tree.

tree_del( Tree, [_,X|Dep] ) :- 
    tree_info( Tree, Gty ),
    cut_end( X, X1 ),
    Node =.. [ Tree, X1, _, DEP ],
    clause( Node, true, Ref ),
    erase( Ref ),
    tree_calc_G( Tree, X1, Gty, G, Zero ),
    (  X == X1,                                      % last node
       del( [_|Dep], DEP, NewDEP )                       
    ;  X \== X1,                                     % inner node
       NewDEP = DEP ),
    sntc_calc_G_list( X1, NewDEP, G, Gty, NewG ),
    NewG \== Zero,
    Node1 =.. [ Tree, X1, NewG, NewDEP ],   
    assertz( Node1 ),
    fail.
tree_del( _, _ ) :- !.


% tree_calc_G( Tree, X, Gty, G ).
%
%   Calculate G variable from the children of X. 
  
tree_calc_G( Tree, X, Gty, G, Zero ) :- 
    get_from_end( X, A1 ),
    active_relation( _, A2 ),
    A1p is A1 + 1,
    A2p is A2 + 1,
    create_range( A1p, A2p, Candidates ),
    create_range( 0, A2p, Atts ),
    (  Gty == lub, Zero = [Atts]         
    ;  Gty == glb, Zero = [[]] ),
    calc_G( Tree, X, Candidates, Zero, Gty, G ), !.
  
calc_G( _, _, [], G, _, G ).                            % Gout=G for all Gty
calc_G( Tree, X, [A|Rest], G, Gty, Gout ) :- 
    add_to_end( A, X, X1 ),
    Node =.. [ Tree, X1, G1, _ ],
    (  clause( Node, true ),
       sntc_calc_G( G, G1, Gty, G2 ),
       calc_G( Tree, X, Rest, G2, Gty, Gout )
    ;  \+ clause( Node, true ),
       calc_G( Tree, X, Rest, G, Gty, Gout )), !.


% tree_get( Tree, S ).
%
%   Retrieve a sentence from the tree. Retrial is allowed. 

tree_get( Tree, [I,X|Dep] ) :- 
    Node =.. [ Tree, X, _, DEP ],
    clause( Node, true ),
%   DEP \== [],      
    member( [I|Dep], DEP ),
    tree_del( Tree, [I,X|Dep] ).
%tree_get( _, _ ) :- !.


% tree_empty( +Tree ).
%
%   Checks if Tree is empty.

tree_empty( Tree ) :- 
    Node =.. [ Tree, _, _, _ ], 
    \+ clause( Node, true ), !. 


% tree_clear( Tree, Gty ).
%
%   Erases complete Tree and sets variable Gty.

tree_clear( Tree, _ ) :- 
    Node =.. [ Tree, _, _, _ ],
    clause( Node, true, Ref ), 
    erase( Ref ),
%    writel( [ ' Sentence deleted: ', Node, nl ]),
    fail.

tree_clear( Tree, Gty ) :- 
    (  clause( tree_info( Tree, _ ), true, Ref ),
       erase( Ref )
    ;  true ),
    assert( tree_info( Tree, Gty )), !.
   

% tree_pairs_clear.
%

tree_pairs_clear :- 
    clause( pair(_), true, Ref ), 
    erase( Ref ),
    fail.
tree_pairs_clear :- !.


% tree_copy( +Tree1, +Tree2 ).
%
%   Copies Tree1 to Tree2. User takes care that Tree2 is empty
%   and that predicate 'tree_info' is set.

tree_copy( Tree1, Tree2 ):- 
    Node1 =.. [ Tree1, X, G, E ],
    clause( Node1, true ), 
    Node2 =.. [ Tree2, X, G, E ],
    assertz( Node2 ),
%    writel( [ ' Sentence copied: ', Node1, nl ]),
    fail.
tree_copy( _, _ ) :- !. 


% tree_print( Head, Tree ).
%
%   Prints the content of Tree to stdout. Variable Head stores
%   string to be displayed before the contents of tree is displayed.

tree_print( Head, Tree ) :- 
    writel( [ nl, Head, nl, nl ]),
    Node =.. [ Tree, [_|X], _, E ],
    clause( Node, true ), 
    E \== [],
    member( [_|Dep], E ),
    writel([ X, ' ->> ', Dep, nl ] ),
    fail. 
tree_print( _, _ ) :- !. 


% tree_dump( Tree, File ).
%
%   Writes the contents of Tree to File. 
%   [-- Store predicate predicate 'tree_info' ! --]

tree_dump( Tree, File ) :- 
    open( File, write, Stream ),
    tree_write( Tree, Stream ),
    close( Stream ), !. 

tree_write( Tree, Stream ) :- 
    Node =.. [ Tree, _, _, _ ], 
    clause( Node, true ), 
    write( Stream, Node ), 
    put( Stream, 46 ), 
    put( Stream, 10 ),
    fail.
tree_write( _, _ ) :- !.


% tree_load( Tree, File ).
%
%    Reads Tree from File. [-- Predicate 'tree_info'! --]

tree_load( Tree, File ) :- 
  open( File, read, Stream ),
  tree_read( Tree, Stream ),
  close( Stream ), !. 

tree_read( Tree, Stream ) :- 
  read( Stream, Line ), 
  (  Line == end_of_file
  ;  Line \== end_of_file,
     Line =.. [ _, X, G, DEP ],
     Node =.. [ Tree, X, G, DEP ],
     assertz( Node )), 
  fail.
tree_read( _, _ ) :- !.



%-----------------------------------------------------------------------------
% Environment, options, tools


% work_mode( Mode ).
% Mode can be: debug, normal.

work_mode( normal ).

set_mode( Mode ) :- 
  clause( work_mode( _ ), true, Ref ),
  erase( Ref ),
  assert( work_mode( Mode )),
  writel([ nl, 'Ok.', nl ]).


% set_method( Method ).
% Method: topdown, bottomup.

method( topdown ).

set_method( Method ) :- 
  clause( method( _ ), true, Ref ),
  erase( Ref ),
  assert( method( Method )),
  writel([ nl, 'Ok.', nl ]).


% activate( Relation ).
% use 'Relation'.

activate( Relation ) :- 
  num_of_attr( Relation, NumOfAttr ),
  (  clause( active_relation( _, _ ), true, Ref ),
     erase( Ref ), !
  ;  true ),
  assert( active_relation( Relation, NumOfAttr )).


% deactivate( Relation ).
% removes predicate 'active_relation'. 

deactivate :- 
    clause( active_relation( _, _ ), true, Ref ),
    erase( Ref ).


% list.
% list all relations included in mdep.

list :- 
    bagof0( R, N ^ num_of_attr( R, N ), L ),
    writel([ nl, L, nl ]).
    

% mdep_help. 
% displays help message. 

mdep_help :- 
    writel([ nl, 'mdep 1.0 <Mar 2000> ', nl, nl ]),
    writel([ 'list.', nl ]),
    writel([ '   List all relations included in the program.', nl ]),
    writel([ 'mdep_help.', nl ]),
    writel([ '   Lists available commands.', nl ]),
    writel([ 'mvds( Relation ).', nl ]),
    writel([ '   Run an algorithm for the discovery of mvds from Relation.', nl ]),
    writel([ 'set_method( Method ).', nl ]),
    writel([ '   Method can be: topdown (default) or bottomup.', nl ]), 
    writel([ 'set_mode( Mode ).', nl ]),
    writel([ '   Mode can be: normal (default), or debug.', nl ]), !.


% clear_environment.
% removes predicates 'active_relation' and 'attribute'. 

clear_environment :- 
    clause( active_relation( _, _ ), true, Ref ),
    erase( Ref ),
    clause( attributes( _ ), true, Ref1 ),
    erase( Ref1 ).


% attr_val( N, T, Val ).
% return the value of N-th attribute from tuple T.

attr_val( N, T, Val ) :- 
  arg( N, T, Val ).


% dummy_tuple( T ).
% constructs a dummy tuple to be used for reading active relation. 

dummy_tuple( T ) :- 
  active_relation( R, N ),
  functor( T, R, N ), !.


% tuple( T ).
% retrieve tuples from active relation. 

tuple( T ) :- 
  active_relation( R, N ),
  functor( T, R, N ), !, T. 



%-----------------------------------------------------------------------------
% Markers 
%
%   Boolean variables. 

is_marked( Mark ) :- 
  clause( remember( Mark ), true, _ ), !.

set_mark( Mark ):- 
  (  clause( remember( Mark ), true, _ )
  ;  assert( remember( Mark ))), !.

reset_mark( Mark ) :- 
  (  clause( remember( Mark ), true, Ref ), 
     erase( Ref )
  ;  true ), !.



%-----------------------------------------------------------------------------
% checking the type of values

% numeric( Term )
% checks if Term is integer or float

numeric( Term ) :- 
  integer( Term ) ; float( Term ).


% logic( Term )
% checks if Term has boolean value 

logic( true).
logic( false ).


% list( Term )
% checks if Term is list

list( Term ) :-
  nonvar( Term ),
  ( Term = [] ; Term = [ _|_ ] ), !.



%-----------------------------------------------------------------------------
% list manipulation 

% member( X, L )
% the element X is member of the list L.
% repeated calls allowed.

member( X, [ X|_ ] ).
member( X, [ _|L ] ) :-
  member( X, L ).


% dmember( X, L )
% element X is member of the list L.
% repeated calls not allowed.

dmember( X, [ X|_ ] ) :- !.
dmember( X, [ _|L ] ) :-
  dmember( X, L ).


% dappend( L1, L2, L3 )
% concatenates the lists L1 and L2 into the list L3.
% repeated calls not allowed.

dappend( [], L, L ) :- !.
dappend( [ X|L1 ], L2, [ X|L3 ] ) :-
  dappend( L1, L2, L3 ).


% del( X, L1, L2 )
% deletes element X from the list L1 resulting the list L2.
% predicate allows repeated calls.

del( X, [ X|L ], L ).
del( X, [ Y|L1 ], [ Y|L2 ] ) :-
  del( X, L1, L2 ).


% add( X, L1, L2 ).
% adds element X to the list L1 resulting the list L2

add( X, [], [X] ) :- !.
add( X, L, [X|L] ).


% add_to_end( X, L1, L2 ).
% adds an element X to the end of list L1 resulting list L2.

add_to_end( X, [ ], [ X ] ) :- !.
add_to_end( X, [ Y|L1 ], [ Y|L2 ] ) :-
  add_to_end( X, L1, L2 ).


% get_from_end( L, X )
% reads and element X from the end of L.

get_from_end( [X], X ) :- !.
get_from_end( [ _|L ], X ) :-
  get_from_end( L, X ).


% get_first( L, X ).
% reads first element X from L.

get_first( [X], X ) :- !.
get_first( [X|_], X ).


% pick( Inc, I, L, E, L1).
% picks I-th element E from L resulting L1.

pick( Inc, I, [E|Rest], E1, [E|Rest1] ) :- 
  Inc @< I, 
  Inc1 is Inc + 1, !,
  pick( Inc1, I, Rest, E1, Rest1 ).

pick( Inc, I, [E|Rest], E, Rest ) :- 
  Inc == I, !.
  
   
% insert( Inc, I, E, L, L1).
% inserts element E on the I-th place in L resulting L1. 

insert( Inc, I, E, [E1|Rest], [E1|Rest1] ) :- 
  Inc @< I, 
  Inc1 is Inc + 1, !,
  insert( Inc1, I, E, Rest, Rest1 ).

insert( Inc, I, E, L, [E|L] ) :- 
  Inc == I, !.


% count( L, N ).
% counts elements in list L.

count( [], 0 ) :- !.
count( [ _|R ], N ) :-
  count( R, N1 ),
  N is N1 + 1.


% conc( L1, L2, L ).
% concatenates lists L1 and L2 into list L.
% predicate allows repeated calls.

conc( [], L, L).
conc( [ X|R ], L2, [ X|L ] ) :- 
  conc( R, L2, L ).


% reverse( L1, L2 ).
% reverses the elements of L1 yielding L2.

reverse( [], []) :- !.
reverse( [X|L1], L ) :-
  reverse( L1, L2 ),
  add_to_end( X, L2, L ). 


% cut_end( L1, L2 ).
% cuts the elements from the end of L1 yielding L2.
% predicate allows repeated calls.

cut_end( [], []).
cut_end( L1, L ) :-
  bagof( Y, X^L1^conc(X,Y,L1), Cs ), 
  reverse( Cs, Es ), !,
  member( Cut, Es ),
  diff( L1, Cut, L ),
  L \== [].


% diff( L1, L2, L )
% calculates difference between lists L1 and L2 into list L.

diff( [], _, []) :- !.
diff( [ X|R ], L1, L2 ) :- 
  diff( R, L1, L), !,
  (  dmember( X, L1 ),
     L2 = L 
  ;  L2 = [ X|L ] ), !.


% intsc( L1, L2, L )
% calculates intersection between lists L1 and L2 into list L.

intsc( [], _, []) :- !.
intsc( [ X|R ], L1, L2 ) :- 
  intsc( R, L1, L),
  (  member( X, L1 ),
     L2 = [ X|L ]
  ;  L2 = L ), !.


% merge( L, S1, S2 )
% merges list L with set S1 yielding set S2.

merge( [], L, L ) :- !.
merge( [ X|L1 ], L2, L3 ) :-
  dmember( X, L2 ),
  merge( L1, L2, L3 ), !.
merge( [ X|L1 ], L2, L3 ) :-
  merge( L1, [ X|L2 ], L3 ), !.


% union( S1, S2, S3 )
% computes union of S1 and S2 yielding S3. 

union( [], L, L ) :- !.
union( L, [], L ) :- !.
union( [X|L1], [Y|L2], [X|L3] ) :-
  X == Y,
  union( L1, L2, L3 ), !.
union( [X|L1], [Y|L2], [X|L3] ) :-
  X @< Y,
  union( L1, [Y|L2], L3 ), !.
union( [X|L1], [Y|L2], [Y|L3] ) :-
  Y @< X,
  union( [X|L1], L2, L3 ), !.


% set_eq( Set1, Set2 )
% tests if set Set1 is equal to set Set2.

set_eq( [], [] ) :- !.
set_eq( [ X|L1 ], L2 ) :-
  del( X, L2, L3 ), !,
  set_eq( L1, L3 ).


% subset( Set1, Set2 )
% tests if Set1 is equal to Set2.

subset( [], _ ).
subset( [ X|L1 ], L2 ) :-
  del( X, L2, L3 ), 
  subset( L1, L3 ).


% partition( L1, L2, L3 )
% 

partition([],[],[]).
partition([X|Xs],[X|Ys],Zs):-
        partition(Xs,Ys,Zs).
partition([X|Xs],Ys,[X|Zs]):-
        partition(Xs,Ys,Zs).
 

% sub_set_eq( +Set1, +Set2 )
% tests if Set1 is a subset of or equal to Set2. 
% sets Set1 and Set2 are ordered. 

sub_set_eq( [], _ ) :- !.
sub_set_eq( [ X|Y ], [ X1|Y1 ] ) :- 
  X = X1, 
  sub_set_eq( Y, Y1 ), !. 
sub_set_eq( [ X|_ ], [ X1|_ ] ) :- 
  X < X1, fail.
sub_set_eq( [ X|Y ], [ X1|Y1 ] ) :- 
  X > X1, 
  sub_set_eq( [ X|Y ], Y1 ), !.

%sub_set_eq( [], _ ) :- !.
%sub_set_eq( [ X|L1 ], L2 ) :-
%  del( X, L2, L3 ), !,
%  sub_set_eq( L1, L3 ), !.



%-----------------------------------------------------------------------------
% miscellaneous

% bagof0( Var, Gs, SolL )
% like built in bagof/3, except that does not fail in the case
% of no solutions.

bagof0( Var, Gs, SolL ) :-
  bagof( Var, Gs, SolL ), !.
bagof0( _, _, [] ).


% setof0( Var, Gs, SolL )
% like built in setof/3, except that does not fail in the case
% of no solutions.

setof0( Var, Gs, SolL ) :-
  setof( Var, Gs, SolL ), !.
setof0( _, _, [] ).



%-----------------------------------------------------------------------------
% error handling and output routines

% error( Msg )
% writes the error message Msg and terminates program execution.

error( Msg ) :-
  writel( [ nl, '  *** Error: ' ] ),
  writel( Msg ),
  writel( [ ' ***', nl ] ),
  abort.


% debug_msg( Msg )
% writes Msg if program is in debug working mode.

debug_msg( Msg ) :-
  work_mode( debug ),
  writel( [ '###: ' ] ),
  writel( Msg ), !.
debug_msg( _ ) :-
  work_mode( normal ).


% writel( L )
% writes elements of L; atom 'nl' means new-line.

writel( L ) :-
  member( X, L ),
  ( X == nl, nl ; X \== nl, write( X )), fail.
writel( _ ).


% writeel( L )
% writes elements of L. Every element is in new line.

writeel( L ) :-
  member( X, L ),
  ( X == nl ; X \== nl, write( X )), nl, fail.
writeel( _ ).


% writel( S, L )
% writes elements of L to file S; atom 'nl' means new-line.

writel( S, L ) :-
  member( X, L ),
  ( X == nl, put( S, 10 ) ; X \== nl, write( S, X )), fail.
writel( _, _ ).



%-----------------------------------------------------------------------------

:- writel([ nl, 'mdep 1.0 <Mar 2000>', nl ]).
:- writel([ 'Run "mdep_help" to list available commands.', nl, nl ]).

%-----------------------------------------------------------------------------
%-----------------------------------------------------------------------------
% Relations

% r( A, B, C ).

num_of_attr( r, 3 ).
r( a1, b1, c1 ).
r( a2, b2, c1 ).
r( a3, b3, c2 ).
r( a4, b3, c2 ).

% r1( A, B, C, D ).

num_of_attr( r1, 4 ).
r1( a1, b1, c1, d1 ).
r1( a1, b2, c2, d2 ).
r1( a1, b1, c2, d2 ).
r1( a1, b2, c1, d1 ).
r1( a2, b2, c2, d1 ).

% r2( A, B, C, D, E ).

num_of_attr( r2, 5 ).
r2( a1, b1, c1, d1, e1 ).
r2( a1, b1, c1, d1, e2 ).
r2( a1, b1, c1, d2, e2 ).
r2( a1, b2, c2, d1, e1 ).
r2( a1, b2, c2, d1, e2 ).
r2( a1, b2, c2, d2, e2 ).


% train( Direction, Hour, Minutes, FirstStop ).

num_of_attr( train, 4 ).
train( utrecht, 8, 8, den_bosch ).
train( tilburg, 8, 10, tilburg ).
train( maastricht, 8, 10, weert ).
train( utrecht, 8, 13, eindhoven_bkln ).
train( tilburg, 8, 17, eindhoven_bkln ).
train( utrecht, 8, 25, den_bosch ).
train( utrecht, 8, 31, utrecht ).
train( utrecht, 8, 43, eindhoven_bkln ).
train( tilburg, 8, 47, eindhoven_bkln ).
train( utrecht, 9, 8, den_bosch ).
train( tilburg, 9, 10, tilburg ).
train( maastricht, 9, 10, weert ).
train( utrecht, 9, 13, eindhoven_bkln ).
train( tilburg, 9, 17, eindhoven_bkln ).
train( utrecht, 9, 25, den_bosch ).
train( utrecht, 9, 43, eindhoven_bkln ).
train( tilburg, 9, 47, eindhoven_bkln ).

% course( ).

num_of_attr( course, 6 ).
course( cs101, deadwood, m9, 222, weenie, b ).
course( cs101, deadwood, w9, 333, weenie, b ).
course( cs101, deadwood, f9, 222, weenie, b ).
course( cs101, deadwood, m9, 222, grind, c ).
course( cs101, deadwood, w9, 333, grind, c ).
course( cs101, deadwood, f9, 222, grind, c ).

num_of_attr( lenses, 6 ).

lenses(1,1,1,1,1,3).
lenses(2,1,1,1,2,2).
lenses(3,1,1,2,1,3).
lenses(4,1,1,2,2,1).
lenses(5,1,2,1,1,3).
lenses(6,1,2,1,2,2).
lenses(7,1,2,2,1,3).
lenses(8,1,2,2,2,1).
lenses(9,2,1,1,1,3).
lenses(10,2,1,1,2,2).
lenses(11,2,1,2,1,3).
lenses(12,2,1,2,2,1).
lenses(13,2,2,1,1,3).
lenses(14,2,2,1,2,2).
lenses(15,2,2,2,1,3).
lenses(16,2,2,2,2,3).
lenses(17,3,1,1,1,3).
lenses(18,3,1,1,2,3).
lenses(19,3,1,2,1,3).
lenses(20,3,1,2,2,1).
lenses(21,3,2,1,1,3).
lenses(22,3,2,1,2,2).
lenses(23,3,2,2,1,3).
lenses(24,3,2,2,2,3).


num_of_attr( bcw, 11 ).

bcw(1000025,5,1,1,1,2,1,3,1,1,2).
bcw(1002945,5,4,4,5,7,10,3,2,1,2).
bcw(1015425,3,1,1,1,2,2,3,1,1,2).
bcw(1016277,6,8,8,1,3,4,3,7,1,2).
bcw(1017023,4,1,1,3,2,1,3,1,1,2).
bcw(1017122,8,10,10,8,7,10,9,7,1,4).
bcw(1018099,1,1,1,1,2,10,3,1,1,2).
bcw(1018561,2,1,2,1,2,1,3,1,1,2).
bcw(1033078,2,1,1,1,2,1,1,1,5,2).
bcw(1033078,4,2,1,1,2,1,2,1,1,2).
bcw(1035283,1,1,1,1,1,1,3,1,1,2).
bcw(1036172,2,1,1,1,2,1,2,1,1,2).
bcw(1041801,5,3,3,3,2,3,4,4,1,4).
bcw(1043999,1,1,1,1,2,3,3,1,1,2).
bcw(1044572,8,7,5,10,7,9,5,5,4,4).
bcw(1047630,7,4,6,4,6,1,4,3,1,4).
bcw(1048672,4,1,1,1,2,1,2,1,1,2).
bcw(1049815,4,1,1,1,2,1,3,1,1,2).
bcw(1050670,10,7,7,6,4,10,4,1,2,4).
bcw(1050718,6,1,1,1,2,1,3,1,1,2).
bcw(1054590,7,3,2,10,5,10,5,4,4,4).
bcw(1054593,10,5,5,3,6,7,7,10,1,4).
bcw(1056784,3,1,1,1,2,1,2,1,1,2).
bcw(1057013,8,4,5,1,2,?,7,3,1,4).
bcw(1059552,1,1,1,1,2,1,3,1,1,2).
bcw(1065726,5,2,3,4,2,7,3,6,1,4).
bcw(1066373,3,2,1,1,1,1,2,1,1,2).
bcw(1066979,5,1,1,1,2,1,2,1,1,2).
bcw(1067444,2,1,1,1,2,1,2,1,1,2).
bcw(1070935,1,1,3,1,2,1,1,1,1,2).
bcw(1070935,3,1,1,1,1,1,2,1,1,2).
bcw(1071760,2,1,1,1,2,1,3,1,1,2).
bcw(1072179,10,7,7,3,8,5,7,4,3,4).
bcw(1074610,2,1,1,2,2,1,3,1,1,2).
bcw(1075123,3,1,2,1,2,1,2,1,1,2).
bcw(1079304,2,1,1,1,2,1,2,1,1,2).
bcw(1080185,10,10,10,8,6,1,8,9,1,4).
bcw(1081791,6,2,1,1,1,1,7,1,1,2).
bcw(1084584,5,4,4,9,2,10,5,6,1,4).
bcw(1091262,2,5,3,3,6,7,7,5,1,4).
bcw(1096800,6,6,6,9,6,?,7,8,1,2).
bcw(1099510,10,4,3,1,3,3,6,5,2,4).
bcw(1100524,6,10,10,2,8,10,7,3,3,4).
bcw(1102573,5,6,5,6,10,1,3,1,1,4).
bcw(1103608,10,10,10,4,8,1,8,10,1,4).
bcw(1103722,1,1,1,1,2,1,2,1,2,2).
bcw(1105257,3,7,7,4,4,9,4,8,1,4).
bcw(1105524,1,1,1,1,2,1,2,1,1,2).
bcw(1106095,4,1,1,3,2,1,3,1,1,2).
bcw(1106829,7,8,7,2,4,8,3,8,2,4).
bcw(1108370,9,5,8,1,2,3,2,1,5,4).
bcw(1108449,5,3,3,4,2,4,3,4,1,4).
bcw(1110102,10,3,6,2,3,5,4,10,2,4).
bcw(1110503,5,5,5,8,10,8,7,3,7,4).
bcw(1110524,10,5,5,6,8,8,7,1,1,4).
bcw(1111249,10,6,6,3,4,5,3,6,1,4).
bcw(1112209,8,10,10,1,3,6,3,9,1,4).
bcw(1113038,8,2,4,1,5,1,5,4,4,4).
bcw(1113483,5,2,3,1,6,10,5,1,1,4).
bcw(1113906,9,5,5,2,2,2,5,1,1,4).
bcw(1115282,5,3,5,5,3,3,4,10,1,4).
bcw(1115293,1,1,1,1,2,2,2,1,1,2).
bcw(1116116,9,10,10,1,10,8,3,3,1,4).
bcw(1116132,6,3,4,1,5,2,3,9,1,4).
bcw(1116192,1,1,1,1,2,1,2,1,1,2).
bcw(1116998,10,4,2,1,3,2,4,3,10,4).
bcw(1117152,4,1,1,1,2,1,3,1,1,2).
bcw(1118039,5,3,4,1,8,10,4,9,1,4).
bcw(1120559,8,3,8,3,4,9,8,9,8,4).
bcw(1121732,1,1,1,1,2,1,3,2,1,2).
bcw(1121919,5,1,3,1,2,1,2,1,1,2).
bcw(1123061,6,10,2,8,10,2,7,8,10,4).
bcw(1124651,1,3,3,2,2,1,7,2,1,2).
bcw(1125035,9,4,5,10,6,10,4,8,1,4).
bcw(1126417,10,6,4,1,3,4,3,2,3,4).
bcw(1131294,1,1,2,1,2,2,4,2,1,2).
bcw(1132347,1,1,4,1,2,1,2,1,1,2).
bcw(1133041,5,3,1,2,2,1,2,1,1,2).
bcw(1133136,3,1,1,1,2,3,3,1,1,2).
bcw(1136142,2,1,1,1,3,1,2,1,1,2).
bcw(1137156,2,2,2,1,1,1,7,1,1,2).
bcw(1143978,4,1,1,2,2,1,2,1,1,2).
bcw(1143978,5,2,1,1,2,1,3,1,1,2).
bcw(1147044,3,1,1,1,2,2,7,1,1,2).
bcw(1147699,3,5,7,8,8,9,7,10,7,4).
bcw(1147748,5,10,6,1,10,4,4,10,10,4).
bcw(1148278,3,3,6,4,5,8,4,4,1,4).
bcw(1148873,3,6,6,6,5,10,6,8,3,4).
bcw(1152331,4,1,1,1,2,1,3,1,1,2).
bcw(1155546,2,1,1,2,3,1,2,1,1,2).
bcw(1156272,1,1,1,1,2,1,3,1,1,2).
bcw(1156948,3,1,1,2,2,1,1,1,1,2).
bcw(1157734,4,1,1,1,2,1,3,1,1,2).
bcw(1158247,1,1,1,1,2,1,2,1,1,2).
bcw(1160476,2,1,1,1,2,1,3,1,1,2).
bcw(1164066,1,1,1,1,2,1,3,1,1,2).
bcw(1165297,2,1,1,2,2,1,1,1,1,2).
bcw(1165790,5,1,1,1,2,1,3,1,1,2).
bcw(1165926,9,6,9,2,10,6,2,9,10,4).
bcw(1166630,7,5,6,10,5,10,7,9,4,4).
bcw(1166654,10,3,5,1,10,5,3,10,2,4).
bcw(1167439,2,3,4,4,2,5,2,5,1,4).
bcw(1167471,4,1,2,1,2,1,3,1,1,2).
bcw(1168359,8,2,3,1,6,3,7,1,1,4).
bcw(1168736,10,10,10,10,10,1,8,8,8,4).
bcw(1169049,7,3,4,4,3,3,3,2,7,4).
bcw(1170419,10,10,10,8,2,10,4,1,1,4).
bcw(1170420,1,6,8,10,8,10,5,7,1,4).
bcw(1171710,1,1,1,1,2,1,2,3,1,2).
bcw(1171710,6,5,4,4,3,9,7,8,3,4).
bcw(1171795,1,3,1,2,2,2,5,3,2,2).
bcw(1171845,8,6,4,3,5,9,3,1,1,4).
bcw(1172152,10,3,3,10,2,10,7,3,3,4).
bcw(1173216,10,10,10,3,10,8,8,1,1,4).
bcw(1173235,3,3,2,1,2,3,3,1,1,2).
bcw(1173347,1,1,1,1,2,5,1,1,1,2).
bcw(1173347,8,3,3,1,2,2,3,2,1,2).
bcw(1173509,4,5,5,10,4,10,7,5,8,4).
bcw(1173514,1,1,1,1,4,3,1,1,1,2).
bcw(1173681,3,2,1,1,2,2,3,1,1,2).
bcw(1174057,1,1,2,2,2,1,3,1,1,2).
bcw(1174057,4,2,1,1,2,2,3,1,1,2).
bcw(1174131,10,10,10,2,10,10,5,3,3,4).
bcw(1174428,5,3,5,1,8,10,5,3,1,4).
bcw(1175937,5,4,6,7,9,7,8,10,1,4).
bcw(1176406,1,1,1,1,2,1,2,1,1,2).
bcw(1176881,7,5,3,7,4,10,7,5,5,4).
bcw(1177027,3,1,1,1,2,1,3,1,1,2).
bcw(1177399,8,3,5,4,5,10,1,6,2,4).
bcw(1177512,1,1,1,1,10,1,1,1,1,2).
bcw(1178580,5,1,3,1,2,1,2,1,1,2).
bcw(1179818,2,1,1,1,2,1,3,1,1,2).
bcw(1180194,5,10,8,10,8,10,3,6,3,4).
bcw(1180523,3,1,1,1,2,1,2,2,1,2).
bcw(1180831,3,1,1,1,3,1,2,1,1,2).
bcw(1181356,5,1,1,1,2,2,3,3,1,2).
bcw(1182404,4,1,1,1,2,1,2,1,1,2).
bcw(1182410,3,1,1,1,2,1,1,1,1,2).
bcw(1183240,4,1,2,1,2,1,2,1,1,2).
bcw(1183246,1,1,1,1,1,?,2,1,1,2).
bcw(1183516,3,1,1,1,2,1,1,1,1,2).
bcw(1183911,2,1,1,1,2,1,1,1,1,2).
bcw(1183983,9,5,5,4,4,5,4,3,3,4).
bcw(1184184,1,1,1,1,2,5,1,1,1,2).
bcw(1184241,2,1,1,1,2,1,2,1,1,2).
bcw(1184840,1,1,3,1,2,?,2,1,1,2).
bcw(1185609,3,4,5,2,6,8,4,1,1,4).
bcw(1185610,1,1,1,1,3,2,2,1,1,2).
bcw(1187457,3,1,1,3,8,1,5,8,1,2).
bcw(1187805,8,8,7,4,10,10,7,8,7,4).
bcw(1188472,1,1,1,1,1,1,3,1,1,2).
bcw(1189266,7,2,4,1,6,10,5,4,3,4).
bcw(1189286,10,10,8,6,4,5,8,10,1,4).
bcw(1190394,4,1,1,1,2,3,1,1,1,2).
bcw(1190485,1,1,1,1,2,1,1,1,1,2).
bcw(1192325,5,5,5,6,3,10,3,1,1,4).
bcw(1193091,1,2,2,1,2,1,2,1,1,2).
bcw(1193210,2,1,1,1,2,1,3,1,1,2).
bcw(1193683,1,1,2,1,3,?,1,1,1,2).
bcw(1196295,9,9,10,3,6,10,7,10,6,4).
bcw(1196915,10,7,7,4,5,10,5,7,2,4).
bcw(1197080,4,1,1,1,2,1,3,2,1,2).
bcw(1197270,3,1,1,1,2,1,3,1,1,2).
bcw(1197440,1,1,1,2,1,3,1,1,7,2).
bcw(1197510,5,1,1,1,2,?,3,1,1,2).
bcw(1197979,4,1,1,1,2,2,3,2,1,2).
bcw(1197993,5,6,7,8,8,10,3,10,3,4).
bcw(1198128,10,8,10,10,6,1,3,1,10,4).
bcw(1198641,3,1,1,1,2,1,3,1,1,2).
bcw(1199219,1,1,1,2,1,1,1,1,1,2).
bcw(1199731,3,1,1,1,2,1,1,1,1,2).
bcw(1199983,1,1,1,1,2,1,3,1,1,2).
bcw(1200772,1,1,1,1,2,1,2,1,1,2).
bcw(1200847,6,10,10,10,8,10,10,10,7,4).
bcw(1200892,8,6,5,4,3,10,6,1,1,4).
bcw(1200952,5,8,7,7,10,10,5,7,1,4).
bcw(1201834,2,1,1,1,2,1,3,1,1,2).
bcw(1201936,5,10,10,3,8,1,5,10,3,4).
bcw(1202125,4,1,1,1,2,1,3,1,1,2).
bcw(1202812,5,3,3,3,6,10,3,1,1,4).
bcw(1203096,1,1,1,1,1,1,3,1,1,2).
bcw(1204242,1,1,1,1,2,1,1,1,1,2).
bcw(1204898,6,1,1,1,2,1,3,1,1,2).
bcw(1205138,5,8,8,8,5,10,7,8,1,4).
bcw(1205579,8,7,6,4,4,10,5,1,1,4).
bcw(1206089,2,1,1,1,1,1,3,1,1,2).
bcw(1206695,1,5,8,6,5,8,7,10,1,4).
bcw(1206841,10,5,6,10,6,10,7,7,10,4).
bcw(1207986,5,8,4,10,5,8,9,10,1,4).
bcw(1208301,1,2,3,1,2,1,3,1,1,2).
bcw(1210963,10,10,10,8,6,8,7,10,1,4).
bcw(1211202,7,5,10,10,10,10,4,10,3,4).
bcw(1212232,5,1,1,1,2,1,2,1,1,2).
bcw(1212251,1,1,1,1,2,1,3,1,1,2).
bcw(1212422,3,1,1,1,2,1,3,1,1,2).
bcw(1212422,4,1,1,1,2,1,3,1,1,2).
bcw(1213375,8,4,4,5,4,7,7,8,2,2).
bcw(1213383,5,1,1,4,2,1,3,1,1,2).
bcw(1214092,1,1,1,1,2,1,1,1,1,2).
bcw(1214556,3,1,1,1,2,1,2,1,1,2).
bcw(1214966,9,7,7,5,5,10,7,8,3,4).
bcw(1216694,10,8,8,4,10,10,8,1,1,4).
bcw(1216947,1,1,1,1,2,1,3,1,1,2).
bcw(1217051,5,1,1,1,2,1,3,1,1,2).
bcw(1217264,1,1,1,1,2,1,3,1,1,2).
bcw(1218105,5,10,10,9,6,10,7,10,5,4).
bcw(1218741,10,10,9,3,7,5,3,5,1,4).
bcw(1218860,1,1,1,1,1,1,3,1,1,2).
bcw(1218860,1,1,1,1,1,1,3,1,1,2).
bcw(1219406,5,1,1,1,1,1,3,1,1,2).
bcw(1219525,8,10,10,10,5,10,8,10,6,4).
bcw(1219859,8,10,8,8,4,8,7,7,1,4).
bcw(1220330,1,1,1,1,2,1,3,1,1,2).
bcw(1221863,10,10,10,10,7,10,7,10,4,4).
bcw(1222047,10,10,10,10,3,10,10,6,1,4).
bcw(1222936,8,7,8,7,5,5,5,10,2,4).
bcw(1223282,1,1,1,1,2,1,2,1,1,2).
bcw(1223426,1,1,1,1,2,1,3,1,1,2).
bcw(1223793,6,10,7,7,6,4,8,10,2,4).
bcw(1223967,6,1,3,1,2,1,3,1,1,2).
bcw(1224329,1,1,1,2,2,1,3,1,1,2).
bcw(1225799,10,6,4,3,10,10,9,10,1,4).
bcw(1226012,4,1,1,3,1,5,2,1,1,4).
bcw(1226612,7,5,6,3,3,8,7,4,1,4).
bcw(1227210,10,5,5,6,3,10,7,9,2,4).
bcw(1227244,1,1,1,1,2,1,2,1,1,2).
bcw(1227481,10,5,7,4,4,10,8,9,1,4).
bcw(1228152,8,9,9,5,3,5,7,7,1,4).
bcw(1228311,1,1,1,1,1,1,3,1,1,2).
bcw(1230175,10,10,10,3,10,10,9,10,1,4).
bcw(1230688,7,4,7,4,3,7,7,6,1,4).
bcw(1231387,6,8,7,5,6,8,8,9,2,4).
bcw(1231706,8,4,6,3,3,1,4,3,1,2).
bcw(1232225,10,4,5,5,5,10,4,1,1,4).
bcw(1236043,3,3,2,1,3,1,3,6,1,2).
bcw(1241232,3,1,4,1,2,?,3,1,1,2).
bcw(1241559,10,8,8,2,8,10,4,8,10,4).
bcw(1241679,9,8,8,5,6,2,4,10,4,4).
bcw(1242364,8,10,10,8,6,9,3,10,10,4).
bcw(1243256,10,4,3,2,3,10,5,3,2,4).
bcw(1270479,5,1,3,3,2,2,2,3,1,2).
bcw(1276091,3,1,1,3,1,1,3,1,1,2).
bcw(1277018,2,1,1,1,2,1,3,1,1,2).
bcw(128059,1,1,1,1,2,5,5,1,1,2).
bcw(1285531,1,1,1,1,2,1,3,1,1,2).
bcw(1287775,5,1,1,2,2,2,3,1,1,2).
bcw(144888,8,10,10,8,5,10,7,8,1,4).
bcw(145447,8,4,4,1,2,9,3,3,1,4).
bcw(167528,4,1,1,1,2,1,3,6,1,2).
bcw(169356,3,1,1,1,2,?,3,1,1,2).
bcw(183913,1,2,2,1,2,1,1,1,1,2).
bcw(191250,10,4,4,10,2,10,5,3,3,4).
bcw(1017023,6,3,3,5,3,10,3,5,3,2).
bcw(1100524,6,10,10,2,8,10,7,3,3,4).
bcw(1116116,9,10,10,1,10,8,3,3,1,4).
bcw(1168736,5,6,6,2,4,10,3,6,1,4).
bcw(1182404,3,1,1,1,2,1,1,1,1,2).
bcw(1182404,3,1,1,1,2,1,2,1,1,2).
bcw(1198641,3,1,1,1,2,1,3,1,1,2).
bcw(242970,5,7,7,1,5,8,3,4,1,2).
bcw(255644,10,5,8,10,3,10,5,1,3,4).
bcw(263538,5,10,10,6,10,10,10,6,5,4).
bcw(274137,8,8,9,4,5,10,7,8,1,4).
bcw(303213,10,4,4,10,6,10,5,5,1,4).
bcw(314428,7,9,4,10,10,3,5,3,3,4).
bcw(1182404,5,1,4,1,2,1,3,2,1,2).
bcw(1198641,10,10,6,3,3,10,4,3,2,4).
bcw(320675,3,3,5,2,3,10,7,1,1,4).
bcw(324427,10,8,8,2,3,4,8,7,8,4).
bcw(385103,1,1,1,1,2,1,3,1,1,2).
bcw(390840,8,4,7,1,3,10,3,9,2,4).
bcw(411453,5,1,1,1,2,1,3,1,1,2).
bcw(320675,3,3,5,2,3,10,7,1,1,4).
bcw(428903,7,2,4,1,3,4,3,3,1,4).
bcw(431495,3,1,1,1,2,1,3,2,1,2).
bcw(432809,3,1,3,1,2,?,2,1,1,2).
bcw(434518,3,1,1,1,2,1,2,1,1,2).
bcw(452264,1,1,1,1,2,1,2,1,1,2).
bcw(456282,1,1,1,1,2,1,3,1,1,2).
bcw(476903,10,5,7,3,3,7,3,3,8,4).
bcw(486283,3,1,1,1,2,1,3,1,1,2).
bcw(486662,2,1,1,2,2,1,3,1,1,2).
bcw(488173,1,4,3,10,4,10,5,6,1,4).
bcw(492268,10,4,6,1,2,10,5,3,1,4).
bcw(508234,7,4,5,10,2,10,3,8,2,4).
bcw(527363,8,10,10,10,8,10,10,7,3,4).
bcw(529329,10,10,10,10,10,10,4,10,10,4).
bcw(535331,3,1,1,1,3,1,2,1,1,2).
bcw(543558,6,1,3,1,4,5,5,10,1,4).
bcw(555977,5,6,6,8,6,10,4,10,4,4).
bcw(560680,1,1,1,1,2,1,1,1,1,2).
bcw(561477,1,1,1,1,2,1,3,1,1,2).
bcw(563649,8,8,8,1,2,?,6,10,1,4).
bcw(601265,10,4,4,6,2,10,2,3,1,4).
bcw(606140,1,1,1,1,2,?,2,1,1,2).
bcw(606722,5,5,7,8,6,10,7,4,1,4).
bcw(616240,5,3,4,3,4,5,4,7,1,2).
bcw(61634,5,4,3,1,2,?,2,3,1,2).
bcw(625201,8,2,1,1,5,1,1,1,1,2).
bcw(63375,9,1,2,6,4,10,7,7,2,4).
bcw(635844,8,4,10,5,4,4,7,10,1,4).
bcw(636130,1,1,1,1,2,1,3,1,1,2).
bcw(640744,10,10,10,7,9,10,7,10,10,4).
bcw(646904,1,1,1,1,2,1,3,1,1,2).
bcw(653777,8,3,4,9,3,10,3,3,1,4).
bcw(659642,10,8,4,4,4,10,3,10,4,4).
bcw(666090,1,1,1,1,2,1,3,1,1,2).
bcw(666942,1,1,1,1,2,1,3,1,1,2).
bcw(667204,7,8,7,6,4,3,8,8,4,4).
bcw(673637,3,1,1,1,2,5,5,1,1,2).
bcw(684955,2,1,1,1,3,1,2,1,1,2).
bcw(688033,1,1,1,1,2,1,1,1,1,2).
bcw(691628,8,6,4,10,10,1,3,5,1,4).
bcw(693702,1,1,1,1,2,1,1,1,1,2).
bcw(704097,1,1,1,1,1,1,2,1,1,2).
bcw(704168,4,6,5,6,7,?,4,9,1,2).
bcw(706426,5,5,5,2,5,10,4,3,1,4).
bcw(709287,6,8,7,8,6,8,8,9,1,4).
bcw(718641,1,1,1,1,5,1,3,1,1,2).
bcw(721482,4,4,4,4,6,5,7,3,1,2).
bcw(730881,7,6,3,2,5,10,7,4,6,4).
bcw(733639,3,1,1,1,2,?,3,1,1,2).
bcw(733639,3,1,1,1,2,1,3,1,1,2).
bcw(733823,5,4,6,10,2,10,4,1,1,4).
bcw(740492,1,1,1,1,2,1,3,1,1,2).
bcw(743348,3,2,2,1,2,1,2,3,1,2).
bcw(752904,10,1,1,1,2,10,5,4,1,4).
bcw(756136,1,1,1,1,2,1,2,1,1,2).
bcw(760001,8,10,3,2,6,4,3,10,1,4).
bcw(760239,10,4,6,4,5,10,7,1,1,4).
bcw(76389,10,4,7,2,2,8,6,1,1,4).
bcw(764974,5,1,1,1,2,1,3,1,2,2).
bcw(770066,5,2,2,2,2,1,2,2,1,2).
bcw(785208,5,4,6,6,4,10,4,3,1,4).
bcw(785615,8,6,7,3,3,10,3,4,2,4).
bcw(792744,1,1,1,1,2,1,1,1,1,2).
bcw(797327,6,5,5,8,4,10,3,4,1,4).
bcw(798429,1,1,1,1,2,1,3,1,1,2).
bcw(704097,1,1,1,1,1,1,2,1,1,2).
bcw(806423,8,5,5,5,2,10,4,3,1,4).
bcw(809912,10,3,3,1,2,10,7,6,1,4).
bcw(810104,1,1,1,1,2,1,3,1,1,2).
bcw(814265,2,1,1,1,2,1,1,1,1,2).
bcw(814911,1,1,1,1,2,1,1,1,1,2).
bcw(822829,7,6,4,8,10,10,9,5,3,4).
bcw(826923,1,1,1,1,2,1,1,1,1,2).
bcw(830690,5,2,2,2,3,1,1,3,1,2).
bcw(831268,1,1,1,1,1,1,1,3,1,2).
bcw(832226,3,4,4,10,5,1,3,3,1,4).
bcw(832567,4,2,3,5,3,8,7,6,1,4).
bcw(836433,5,1,1,3,2,1,1,1,1,2).
bcw(837082,2,1,1,1,2,1,3,1,1,2).
bcw(846832,3,4,5,3,7,3,4,6,1,2).
bcw(850831,2,7,10,10,7,10,4,9,4,4).
bcw(855524,1,1,1,1,2,1,2,1,1,2).
bcw(857774,4,1,1,1,3,1,2,2,1,2).
bcw(859164,5,3,3,1,3,3,3,3,3,4).
bcw(859350,8,10,10,7,10,10,7,3,8,4).
bcw(866325,8,10,5,3,8,4,4,10,3,4).
bcw(873549,10,3,5,4,3,7,3,5,3,4).
bcw(877291,6,10,10,10,10,10,8,10,10,4).
bcw(877943,3,10,3,10,6,10,5,1,4,4).
bcw(888169,3,2,2,1,4,3,2,1,1,2).
bcw(888523,4,4,4,2,2,3,2,1,1,2).
bcw(896404,2,1,1,1,2,1,3,1,1,2).
bcw(897172,2,1,1,1,2,1,2,1,1,2).
bcw(95719,6,10,10,10,8,10,7,10,7,4).
bcw(160296,5,8,8,10,5,10,8,10,3,4).
bcw(342245,1,1,3,1,2,1,1,1,1,2).
bcw(428598,1,1,3,1,1,1,2,1,1,2).
bcw(492561,4,3,2,1,3,1,2,1,1,2).
bcw(493452,1,1,3,1,2,1,1,1,1,2).
bcw(493452,4,1,2,1,2,1,2,1,1,2).
bcw(521441,5,1,1,2,2,1,2,1,1,2).
bcw(560680,3,1,2,1,2,1,2,1,1,2).
bcw(636437,1,1,1,1,2,1,1,1,1,2).
bcw(640712,1,1,1,1,2,1,2,1,1,2).
bcw(654244,1,1,1,1,1,1,2,1,1,2).
bcw(657753,3,1,1,4,3,1,2,2,1,2).
bcw(685977,5,3,4,1,4,1,3,1,1,2).
bcw(805448,1,1,1,1,2,1,1,1,1,2).
bcw(846423,10,6,3,6,4,10,7,8,4,4).
bcw(1002504,3,2,2,2,2,1,3,2,1,2).
bcw(1022257,2,1,1,1,2,1,1,1,1,2).
bcw(1026122,2,1,1,1,2,1,1,1,1,2).
bcw(1071084,3,3,2,2,3,1,1,2,3,2).
bcw(1080233,7,6,6,3,2,10,7,1,1,4).
bcw(1114570,5,3,3,2,3,1,3,1,1,2).
bcw(1114570,2,1,1,1,2,1,2,2,1,2).
bcw(1116715,5,1,1,1,3,2,2,2,1,2).
bcw(1131411,1,1,1,2,2,1,2,1,1,2).
bcw(1151734,10,8,7,4,3,10,7,9,1,4).
bcw(1156017,3,1,1,1,2,1,2,1,1,2).
bcw(1158247,1,1,1,1,1,1,1,1,1,2).
bcw(1158405,1,2,3,1,2,1,2,1,1,2).
bcw(1168278,3,1,1,1,2,1,2,1,1,2).
bcw(1176187,3,1,1,1,2,1,3,1,1,2).
bcw(1196263,4,1,1,1,2,1,1,1,1,2).
bcw(1196475,3,2,1,1,2,1,2,2,1,2).
bcw(1206314,1,2,3,1,2,1,1,1,1,2).
bcw(1211265,3,10,8,7,6,9,9,3,8,4).
bcw(1213784,3,1,1,1,2,1,1,1,1,2).
bcw(1223003,5,3,3,1,2,1,2,1,1,2).
bcw(1223306,3,1,1,1,2,4,1,1,1,2).
bcw(1223543,1,2,1,3,2,1,1,2,1,2).
bcw(1229929,1,1,1,1,2,1,2,1,1,2).
bcw(1231853,4,2,2,1,2,1,2,1,1,2).
bcw(1234554,1,1,1,1,2,1,2,1,1,2).
bcw(1236837,2,3,2,2,2,2,3,1,1,2).
bcw(1237674,3,1,2,1,2,1,2,1,1,2).
bcw(1238021,1,1,1,1,2,1,2,1,1,2).
bcw(1238464,1,1,1,1,1,?,2,1,1,2).
bcw(1238633,10,10,10,6,8,4,8,5,1,4).
bcw(1238915,5,1,2,1,2,1,3,1,1,2).
bcw(1238948,8,5,6,2,3,10,6,6,1,4).
bcw(1239232,3,3,2,6,3,3,3,5,1,2).
bcw(1239347,8,7,8,5,10,10,7,2,1,4).
bcw(1239967,1,1,1,1,2,1,2,1,1,2).
bcw(1240337,5,2,2,2,2,2,3,2,2,2).
bcw(1253505,2,3,1,1,5,1,1,1,1,2).
bcw(1255384,3,2,2,3,2,3,3,1,1,2).
bcw(1257200,10,10,10,7,10,10,8,2,1,4).
bcw(1257648,4,3,3,1,2,1,3,3,1,2).
bcw(1257815,5,1,3,1,2,1,2,1,1,2).
bcw(1257938,3,1,1,1,2,1,1,1,1,2).
bcw(1258549,9,10,10,10,10,10,10,10,1,4).
bcw(1258556,5,3,6,1,2,1,1,1,1,2).
bcw(1266154,8,7,8,2,4,2,5,10,1,4).
bcw(1272039,1,1,1,1,2,1,2,1,1,2).
bcw(1276091,2,1,1,1,2,1,2,1,1,2).
bcw(1276091,1,3,1,1,2,1,2,2,1,2).
bcw(1276091,5,1,1,3,4,1,3,2,1,2).
bcw(1277629,5,1,1,1,2,1,2,2,1,2).
bcw(1293439,3,2,2,3,2,1,1,1,1,2).
bcw(1293439,6,9,7,5,5,8,4,2,1,2).
bcw(1294562,10,8,10,1,3,10,5,1,1,4).
bcw(1295186,10,10,10,1,6,1,2,8,1,4).
bcw(527337,4,1,1,1,2,1,1,1,1,2).
bcw(558538,4,1,3,3,2,1,1,1,1,2).
bcw(566509,5,1,1,1,2,1,1,1,1,2).
bcw(608157,10,4,3,10,4,10,10,1,1,4).
bcw(677910,5,2,2,4,2,4,1,1,1,2).
bcw(734111,1,1,1,3,2,3,1,1,1,2).
bcw(734111,1,1,1,1,2,2,1,1,1,2).
bcw(780555,5,1,1,6,3,1,2,1,1,2).
bcw(827627,2,1,1,1,2,1,1,1,1,2).
bcw(1049837,1,1,1,1,2,1,1,1,1,2).
bcw(1058849,5,1,1,1,2,1,1,1,1,2).
bcw(1182404,1,1,1,1,1,1,1,1,1,2).
bcw(1193544,5,7,9,8,6,10,8,10,1,4).
bcw(1201870,4,1,1,3,1,1,2,1,1,2).
bcw(1202253,5,1,1,1,2,1,1,1,1,2).
bcw(1227081,3,1,1,3,2,1,1,1,1,2).
bcw(1230994,4,5,5,8,6,10,10,7,1,4).
bcw(1238410,2,3,1,1,3,1,1,1,1,2).
bcw(1246562,10,2,2,1,2,6,1,1,2,4).
bcw(1257470,10,6,5,8,5,10,8,6,1,4).
bcw(1259008,8,8,9,6,6,3,10,10,1,4).
bcw(1266124,5,1,2,1,2,1,1,1,1,2).
bcw(1267898,5,1,3,1,2,1,1,1,1,2).
bcw(1268313,5,1,1,3,2,1,1,1,1,2).
bcw(1268804,3,1,1,1,2,5,1,1,1,2).
bcw(1276091,6,1,1,3,2,1,1,1,1,2).
bcw(1280258,4,1,1,1,2,1,1,2,1,2).
bcw(1293966,4,1,1,1,2,1,1,1,1,2).
bcw(1296572,10,9,8,7,6,4,7,10,3,4).
bcw(1298416,10,6,6,2,4,10,9,7,1,4).
bcw(1299596,6,6,6,5,4,10,7,6,2,4).
bcw(1105524,4,1,1,1,2,1,1,1,1,2).
bcw(1181685,1,1,2,1,2,1,2,1,1,2).
bcw(1211594,3,1,1,1,1,1,2,1,1,2).
bcw(1238777,6,1,1,3,2,1,1,1,1,2).
bcw(1257608,6,1,1,1,1,1,1,1,1,2).
bcw(1269574,4,1,1,1,2,1,1,1,1,2).
bcw(1277145,5,1,1,1,2,1,1,1,1,2).
bcw(1287282,3,1,1,1,2,1,1,1,1,2).
bcw(1296025,4,1,2,1,2,1,1,1,1,2).
bcw(1296263,4,1,1,1,2,1,1,1,1,2).
bcw(1296593,5,2,1,1,2,1,1,1,1,2).
bcw(1299161,4,8,7,10,4,10,7,5,1,4).
bcw(1301945,5,1,1,1,1,1,1,1,1,2).
bcw(1302428,5,3,2,4,2,1,1,1,1,2).
bcw(1318169,9,10,10,10,10,5,10,10,10,4).
bcw(474162,8,7,8,5,5,10,9,10,1,4).
bcw(787451,5,1,2,1,2,1,1,1,1,2).
bcw(1002025,1,1,1,3,1,3,1,1,1,2).
bcw(1070522,3,1,1,1,1,1,2,1,1,2).
bcw(1073960,10,10,10,10,6,10,8,1,5,4).
bcw(1076352,3,6,4,10,3,3,3,4,1,4).
bcw(1084139,6,3,2,1,3,4,4,1,1,4).
bcw(1115293,1,1,1,1,2,1,1,1,1,2).
bcw(1119189,5,8,9,4,3,10,7,1,1,4).
bcw(1133991,4,1,1,1,1,1,2,1,1,2).
bcw(1142706,5,10,10,10,6,10,6,5,2,4).
bcw(1155967,5,1,2,10,4,5,2,1,1,2).
bcw(1170945,3,1,1,1,1,1,2,1,1,2).
bcw(1181567,1,1,1,1,1,1,1,1,1,2).
bcw(1182404,4,2,1,1,2,1,1,1,1,2).
bcw(1204558,4,1,1,1,2,1,2,1,1,2).
bcw(1217952,4,1,1,1,2,1,2,1,1,2).
bcw(1224565,6,1,1,1,2,1,3,1,1,2).
bcw(1238186,4,1,1,1,2,1,2,1,1,2).
bcw(1253917,4,1,1,2,2,1,2,1,1,2).
bcw(1265899,4,1,1,1,2,1,3,1,1,2).
bcw(1268766,1,1,1,1,2,1,1,1,1,2).
bcw(1277268,3,3,1,1,2,1,1,1,1,2).
bcw(1286943,8,10,10,10,7,5,4,8,7,4).
bcw(1295508,1,1,1,1,2,4,1,1,1,2).
bcw(1297327,5,1,1,1,2,1,1,1,1,2).
bcw(1297522,2,1,1,1,2,1,1,1,1,2).
bcw(1298360,1,1,1,1,2,1,1,1,1,2).
bcw(1299924,5,1,1,1,2,1,2,1,1,2).
bcw(1299994,5,1,1,1,2,1,1,1,1,2).
bcw(1304595,3,1,1,1,1,1,2,1,1,2).
bcw(1306282,6,6,7,10,3,10,8,10,2,4).
bcw(1313325,4,10,4,7,3,10,9,10,1,4).
bcw(1320077,1,1,1,1,1,1,1,1,1,2).
bcw(1320077,1,1,1,1,1,1,2,1,1,2).
bcw(1320304,3,1,2,2,2,1,1,1,1,2).
bcw(1330439,4,7,8,3,4,10,9,1,1,4).
bcw(333093,1,1,1,1,3,1,1,1,1,2).
bcw(369565,4,1,1,1,3,1,1,1,1,2).
bcw(412300,10,4,5,4,3,5,7,3,1,4).
bcw(672113,7,5,6,10,4,10,5,3,1,4).
bcw(749653,3,1,1,1,2,1,2,1,1,2).
bcw(769612,3,1,1,2,2,1,1,1,1,2).
bcw(769612,4,1,1,1,2,1,1,1,1,2).
bcw(798429,4,1,1,1,2,1,3,1,1,2).
bcw(807657,6,1,3,2,2,1,1,1,1,2).
bcw(8233704,4,1,1,1,1,1,2,1,1,2).
bcw(837480,7,4,4,3,4,10,6,9,1,4).
bcw(867392,4,2,2,1,2,1,2,1,1,2).
bcw(869828,1,1,1,1,1,1,3,1,1,2).
bcw(1043068,3,1,1,1,2,1,2,1,1,2).
bcw(1056171,2,1,1,1,2,1,2,1,1,2).
bcw(1061990,1,1,3,2,2,1,3,1,1,2).
bcw(1113061,5,1,1,1,2,1,3,1,1,2).
bcw(1116192,5,1,2,1,2,1,3,1,1,2).
bcw(1135090,4,1,1,1,2,1,2,1,1,2).
bcw(1145420,6,1,1,1,2,1,2,1,1,2).
bcw(1158157,5,1,1,1,2,2,2,1,1,2).
bcw(1171578,3,1,1,1,2,1,1,1,1,2).
bcw(1174841,5,3,1,1,2,1,1,1,1,2).
bcw(1184586,4,1,1,1,2,1,2,1,1,2).
bcw(1186936,2,1,3,2,2,1,2,1,1,2).
bcw(1197527,5,1,1,1,2,1,2,1,1,2).
bcw(1222464,6,10,10,10,4,10,7,10,1,4).
bcw(1240603,2,1,1,1,1,1,1,1,1,2).
bcw(1240603,3,1,1,1,1,1,1,1,1,2).
bcw(1241035,7,8,3,7,4,5,7,8,2,4).
bcw(1287971,3,1,1,1,2,1,2,1,1,2).
bcw(1289391,1,1,1,1,2,1,3,1,1,2).
bcw(1299924,3,2,2,2,2,1,4,2,1,2).
bcw(1306339,4,4,2,1,2,5,2,1,2,2).
bcw(1313658,3,1,1,1,2,1,1,1,1,2).
bcw(1313982,4,3,1,1,2,1,4,8,1,2).
bcw(1321264,5,2,2,2,1,1,2,1,1,2).
bcw(1321321,5,1,1,3,2,1,1,1,1,2).
bcw(1321348,2,1,1,1,2,1,2,1,1,2).
bcw(1321931,5,1,1,1,2,1,2,1,1,2).
bcw(1321942,5,1,1,1,2,1,3,1,1,2).
bcw(1321942,5,1,1,1,2,1,3,1,1,2).
bcw(1328331,1,1,1,1,2,1,3,1,1,2).
bcw(1328755,3,1,1,1,2,1,2,1,1,2).
bcw(1331405,4,1,1,1,2,1,3,2,1,2).
bcw(1331412,5,7,10,10,5,10,10,10,1,4).
bcw(1333104,3,1,2,1,2,1,3,1,1,2).
bcw(1334071,4,1,1,1,2,3,2,1,1,2).
bcw(1343068,8,4,4,1,6,10,2,5,2,4).
bcw(1343374,10,10,8,10,6,5,10,3,1,4).
bcw(1344121,8,10,4,4,8,10,8,2,1,4).
bcw(142932,7,6,10,5,3,10,9,10,2,4).
bcw(183936,3,1,1,1,2,1,2,1,1,2).
bcw(324382,1,1,1,1,2,1,2,1,1,2).
bcw(378275,10,9,7,3,4,2,7,7,1,4).
bcw(385103,5,1,2,1,2,1,3,1,1,2).
bcw(690557,5,1,1,1,2,1,2,1,1,2).
bcw(695091,1,1,1,1,2,1,2,1,1,2).
bcw(695219,1,1,1,1,2,1,2,1,1,2).
bcw(824249,1,1,1,1,2,1,3,1,1,2).
bcw(871549,5,1,2,1,2,1,2,1,1,2).
bcw(878358,5,7,10,6,5,10,7,5,1,4).
bcw(1107684,6,10,5,5,4,10,6,10,1,4).
bcw(1115762,3,1,1,1,2,1,1,1,1,2).
bcw(1217717,5,1,1,6,3,1,1,1,1,2).
bcw(1239420,1,1,1,1,2,1,1,1,1,2).
bcw(1254538,8,10,10,10,6,10,10,10,1,4).
bcw(1261751,5,1,1,1,2,1,2,2,1,2).
bcw(1268275,9,8,8,9,6,3,4,1,1,4).
bcw(1272166,5,1,1,1,2,1,1,1,1,2).
bcw(1294261,4,10,8,5,4,1,10,1,1,4).
bcw(1295529,2,5,7,6,4,10,7,6,1,4).
bcw(1298484,10,3,4,5,3,10,4,1,1,4).
bcw(1311875,5,1,2,1,2,1,1,1,1,2).
bcw(1315506,4,8,6,3,4,10,7,1,1,4).
bcw(1320141,5,1,1,1,2,1,2,1,1,2).
bcw(1325309,4,1,2,1,2,1,2,1,1,2).
bcw(1333063,5,1,3,1,2,1,3,1,1,2).
bcw(1333495,3,1,1,1,2,1,2,1,1,2).
bcw(1334659,5,2,4,1,1,1,1,1,1,2).
bcw(1336798,3,1,1,1,2,1,2,1,1,2).
bcw(1344449,1,1,1,1,1,1,2,1,1,2).
bcw(1350568,4,1,1,1,2,1,2,1,1,2).
bcw(1352663,5,4,6,8,4,1,8,10,1,4).
bcw(188336,5,3,2,8,5,10,8,1,2,4).
bcw(352431,10,5,10,3,5,8,7,8,3,4).
bcw(353098,4,1,1,2,2,1,1,1,1,2).
bcw(411453,1,1,1,1,2,1,1,1,1,2).
bcw(557583,5,10,10,10,10,10,10,1,1,4).
bcw(636375,5,1,1,1,2,1,1,1,1,2).
bcw(736150,10,4,3,10,3,10,7,1,2,4).
bcw(803531,5,10,10,10,5,2,8,5,1,4).
bcw(822829,8,10,10,10,6,10,10,10,10,4).
bcw(1016634,2,3,1,1,2,1,2,1,1,2).
bcw(1031608,2,1,1,1,1,1,2,1,1,2).
bcw(1041043,4,1,3,1,2,1,2,1,1,2).
bcw(1042252,3,1,1,1,2,1,2,1,1,2).
bcw(1057067,1,1,1,1,1,?,1,1,1,2).
bcw(1061990,4,1,1,1,2,1,2,1,1,2).
bcw(1073836,5,1,1,1,2,1,2,1,1,2).
bcw(1083817,3,1,1,1,2,1,2,1,1,2).
bcw(1096352,6,3,3,3,3,2,6,1,1,2).
bcw(1140597,7,1,2,3,2,1,2,1,1,2).
bcw(1149548,1,1,1,1,2,1,1,1,1,2).
bcw(1174009,5,1,1,2,1,1,2,1,1,2).
bcw(1183596,3,1,3,1,3,4,1,1,1,2).
bcw(1190386,4,6,6,5,7,6,7,7,3,4).
bcw(1190546,2,1,1,1,2,5,1,1,1,2).
bcw(1213273,2,1,1,1,2,1,1,1,1,2).
bcw(1218982,4,1,1,1,2,1,1,1,1,2).
bcw(1225382,6,2,3,1,2,1,1,1,1,2).
bcw(1235807,5,1,1,1,2,1,2,1,1,2).
bcw(1238777,1,1,1,1,2,1,1,1,1,2).
bcw(1253955,8,7,4,4,5,3,5,10,1,4).
bcw(1257366,3,1,1,1,2,1,1,1,1,2).
bcw(1260659,3,1,4,1,2,1,1,1,1,2).
bcw(1268952,10,10,7,8,7,1,10,10,3,4).
bcw(1275807,4,2,4,3,2,2,2,1,1,2).
bcw(1277792,4,1,1,1,2,1,1,1,1,2).
bcw(1277792,5,1,1,3,2,1,1,1,1,2).
bcw(1285722,4,1,1,3,2,1,1,1,1,2).
bcw(1288608,3,1,1,1,2,1,2,1,1,2).
bcw(1290203,3,1,1,1,2,1,2,1,1,2).
bcw(1294413,1,1,1,1,2,1,1,1,1,2).
bcw(1299596,2,1,1,1,2,1,1,1,1,2).
bcw(1303489,3,1,1,1,2,1,2,1,1,2).
bcw(1311033,1,2,2,1,2,1,1,1,1,2).
bcw(1311108,1,1,1,3,2,1,1,1,1,2).
bcw(1315807,5,10,10,10,10,2,10,10,10,4).
bcw(1318671,3,1,1,1,2,1,2,1,1,2).
bcw(1319609,3,1,1,2,3,4,1,1,1,2).
bcw(1323477,1,2,1,3,2,1,2,1,1,2).
bcw(1324572,5,1,1,1,2,1,2,2,1,2).
bcw(1324681,4,1,1,1,2,1,2,1,1,2).
bcw(1325159,3,1,1,1,2,1,3,1,1,2).
bcw(1326892,3,1,1,1,2,1,2,1,1,2).
bcw(1330361,5,1,1,1,2,1,2,1,1,2).
bcw(1333877,5,4,5,1,8,1,3,6,1,2).
bcw(1334015,7,8,8,7,3,10,7,2,3,4).
bcw(1334667,1,1,1,1,2,1,1,1,1,2).
bcw(1339781,1,1,1,1,2,1,2,1,1,2).
bcw(1339781,4,1,1,1,2,1,3,1,1,2).
bcw(13454352,1,1,3,1,2,1,2,1,1,2).
bcw(1345452,1,1,3,1,2,1,2,1,1,2).
bcw(1345593,3,1,1,3,2,1,2,1,1,2).
bcw(1347749,1,1,1,1,2,1,1,1,1,2).
bcw(1347943,5,2,2,2,2,1,1,1,2,2).
bcw(1348851,3,1,1,1,2,1,3,1,1,2).
bcw(1350319,5,7,4,1,6,1,7,10,3,4).
bcw(1350423,5,10,10,8,5,5,7,10,1,4).
bcw(1352848,3,10,7,8,5,8,7,4,1,4).
bcw(1353092,3,2,1,2,2,1,3,1,1,2).
bcw(1354840,2,1,1,1,2,1,3,1,1,2).
bcw(1354840,5,3,2,1,3,1,1,1,1,2).
bcw(1355260,1,1,1,1,2,1,2,1,1,2).
bcw(1365075,4,1,4,1,2,1,1,1,1,2).
bcw(1365328,1,1,2,1,2,1,2,1,1,2).
bcw(1368267,5,1,1,1,2,1,1,1,1,2).
bcw(1368273,1,1,1,1,2,1,1,1,1,2).
bcw(1368882,2,1,1,1,2,1,1,1,1,2).
bcw(1369821,10,10,10,10,5,10,10,10,7,4).
bcw(1371026,5,10,10,10,4,10,5,6,3,4).
bcw(1371920,5,1,1,1,2,1,3,2,1,2).
bcw(466906,1,1,1,1,2,1,1,1,1,2).
bcw(466906,1,1,1,1,2,1,1,1,1,2).
bcw(534555,1,1,1,1,2,1,1,1,1,2).
bcw(536708,1,1,1,1,2,1,1,1,1,2).
bcw(566346,3,1,1,1,2,1,2,3,1,2).
bcw(603148,4,1,1,1,2,1,1,1,1,2).
bcw(654546,1,1,1,1,2,1,1,1,8,2).
bcw(654546,1,1,1,3,2,1,1,1,1,2).
bcw(695091,5,10,10,5,4,5,4,4,1,4).
bcw(714039,3,1,1,1,2,1,1,1,1,2).
bcw(763235,3,1,1,1,2,1,2,1,2,2).
bcw(776715,3,1,1,1,3,2,1,1,1,2).
bcw(841769,2,1,1,1,2,1,1,1,1,2).
bcw(888820,5,10,10,3,7,3,8,10,2,4).
bcw(897471,4,8,6,4,3,4,10,6,1,4).
bcw(897471,4,8,8,5,4,5,10,4,1,4).

num_of_attr( led, 8 ).

led(1,1,0,1,0,1,1,5).
led(1,1,1,1,1,1,1,8).
led(1,1,1,0,1,1,1,0).
led(1,1,0,1,1,1,1,6).
led(0,0,1,0,0,1,0,1).
led(1,1,1,0,1,1,1,0).
led(1,1,1,0,1,1,1,0).
led(1,1,1,1,0,1,1,9).
led(1,1,0,1,1,1,1,6).
led(1,1,0,1,1,1,1,6).
led(1,0,1,1,0,1,1,3).
led(0,1,1,1,0,1,0,4).
led(0,1,1,1,0,1,0,4).
led(0,0,1,0,0,1,0,1).
led(0,1,1,1,0,1,0,4).
led(1,1,1,0,1,1,1,0).
led(1,1,0,1,1,1,1,6).
led(0,1,1,1,0,1,0,4).
led(1,1,1,1,0,1,1,9).
led(1,1,1,0,1,1,1,0).
led(1,0,1,1,1,0,1,2).
led(0,0,1,0,0,1,0,1).
led(0,1,1,1,0,1,0,4).
led(0,0,1,0,0,1,0,1).
led(1,1,0,1,1,1,1,6).
led(1,1,1,1,1,1,1,8).
led(1,0,1,1,1,0,1,2).
led(1,1,1,1,1,1,1,8).
led(1,1,1,1,1,1,1,8).
led(1,0,1,0,0,1,0,7).
led(0,1,1,1,0,1,0,4).
led(0,1,1,1,0,1,0,4).
led(1,1,0,1,0,1,1,5).
led(1,1,0,1,1,1,1,6).
led(0,1,1,1,0,1,0,4).
led(0,1,1,1,0,1,0,4).
led(0,1,1,1,0,1,0,4).
led(0,1,1,1,0,1,0,4).
led(1,1,0,1,1,1,1,6).
led(1,0,1,1,0,1,1,3).
led(1,0,1,1,0,1,1,3).
led(1,1,1,1,1,1,1,8).
led(1,1,0,1,1,1,1,6).
led(0,1,1,1,0,1,0,4).
led(0,1,1,1,0,1,0,4).
led(1,1,1,1,0,1,1,9).
led(1,1,0,1,1,1,1,6).
led(1,1,1,0,1,1,1,0).
led(1,0,1,0,0,1,0,7).
led(1,1,0,1,0,1,1,5).
led(0,0,1,0,0,1,0,1).
led(1,0,1,0,0,1,0,7).
led(1,1,0,1,1,1,1,6).
led(1,1,1,1,0,1,1,9).
led(1,1,1,0,1,1,1,0).
led(1,0,1,0,0,1,0,7).
led(1,1,0,1,1,1,1,6).
led(1,0,1,1,0,1,1,3).
led(1,1,0,1,0,1,1,5).
led(1,1,0,1,0,1,1,5).
led(1,1,0,1,0,1,1,5).
led(1,1,0,1,1,1,1,6).
led(0,0,1,0,0,1,0,1).
led(1,0,1,1,0,1,1,3).
led(1,0,1,0,0,1,0,7).
led(1,1,0,1,0,1,1,5).
led(0,1,1,1,0,1,0,4).
led(1,0,1,1,0,1,1,3).
led(1,0,1,1,0,1,1,3).
led(1,0,1,1,0,1,1,3).
led(1,1,0,1,1,1,1,6).
led(1,1,1,1,0,1,1,9).
led(1,1,1,0,1,1,1,0).
led(1,1,1,1,1,1,1,8).
led(1,0,1,1,1,0,1,2).
led(1,0,1,0,0,1,0,7).
led(1,1,1,0,1,1,1,0).
led(1,1,1,1,1,1,1,8).
led(1,0,1,1,0,1,1,3).
led(1,0,1,1,1,0,1,2).
led(0,1,1,1,0,1,0,4).
led(1,1,0,1,1,1,1,6).
led(0,1,1,1,0,1,0,4).
led(0,0,1,0,0,1,0,1).
led(1,0,1,1,0,1,1,3).
led(1,1,1,1,0,1,1,9).
led(1,1,0,1,1,1,1,6).
led(1,1,1,0,1,1,1,0).
led(1,0,1,1,0,1,1,3).
led(1,1,1,1,1,1,1,8).
led(1,1,1,1,1,1,1,8).
led(1,1,1,1,1,1,1,8).
led(1,1,1,0,1,1,1,0).
led(1,0,1,0,0,1,0,7).
led(1,0,1,1,1,0,1,2).
led(1,0,1,1,0,1,1,3).
led(1,0,1,1,0,1,1,3).
led(1,1,0,1,0,1,1,5).
led(0,1,1,1,0,1,0,4).
led(1,1,1,1,1,1,1,8).


num_of_attr( iris, 5 ).

iris(5.1,3.5,1.4,0.2,iris-setosa).
iris(4.9,3.0,1.4,0.2,iris-setosa).
iris(4.7,3.2,1.3,0.2,iris-setosa).
iris(4.6,3.1,1.5,0.2,iris-setosa).
iris(5.0,3.6,1.4,0.2,iris-setosa).
iris(5.4,3.9,1.7,0.4,iris-setosa).
iris(4.6,3.4,1.4,0.3,iris-setosa).
iris(5.0,3.4,1.5,0.2,iris-setosa).
iris(4.4,2.9,1.4,0.2,iris-setosa).
iris(4.9,3.1,1.5,0.1,iris-setosa).
iris(5.4,3.7,1.5,0.2,iris-setosa).
iris(4.8,3.4,1.6,0.2,iris-setosa).
iris(4.8,3.0,1.4,0.1,iris-setosa).
iris(4.3,3.0,1.1,0.1,iris-setosa).
iris(5.8,4.0,1.2,0.2,iris-setosa).
iris(5.7,4.4,1.5,0.4,iris-setosa).
iris(5.4,3.9,1.3,0.4,iris-setosa).
iris(5.1,3.5,1.4,0.3,iris-setosa).
iris(5.7,3.8,1.7,0.3,iris-setosa).
iris(5.1,3.8,1.5,0.3,iris-setosa).
iris(5.4,3.4,1.7,0.2,iris-setosa).
iris(5.1,3.7,1.5,0.4,iris-setosa).
iris(4.6,3.6,1.0,0.2,iris-setosa).
iris(5.1,3.3,1.7,0.5,iris-setosa).
iris(4.8,3.4,1.9,0.2,iris-setosa).
iris(5.0,3.0,1.6,0.2,iris-setosa).
iris(5.0,3.4,1.6,0.4,iris-setosa).
iris(5.2,3.5,1.5,0.2,iris-setosa).
iris(5.2,3.4,1.4,0.2,iris-setosa).
iris(4.7,3.2,1.6,0.2,iris-setosa).
iris(4.8,3.1,1.6,0.2,iris-setosa).
iris(5.4,3.4,1.5,0.4,iris-setosa).
iris(5.2,4.1,1.5,0.1,iris-setosa).
iris(5.5,4.2,1.4,0.2,iris-setosa).
iris(4.9,3.1,1.5,0.1,iris-setosa).
iris(5.0,3.2,1.2,0.2,iris-setosa).
iris(5.5,3.5,1.3,0.2,iris-setosa).
iris(4.9,3.1,1.5,0.1,iris-setosa).
iris(4.4,3.0,1.3,0.2,iris-setosa).
iris(5.1,3.4,1.5,0.2,iris-setosa).
iris(5.0,3.5,1.3,0.3,iris-setosa).
iris(4.5,2.3,1.3,0.3,iris-setosa).
iris(4.4,3.2,1.3,0.2,iris-setosa).
iris(5.0,3.5,1.6,0.6,iris-setosa).
iris(5.1,3.8,1.9,0.4,iris-setosa).
iris(4.8,3.0,1.4,0.3,iris-setosa).
iris(5.1,3.8,1.6,0.2,iris-setosa).
iris(4.6,3.2,1.4,0.2,iris-setosa).
iris(5.3,3.7,1.5,0.2,iris-setosa).
iris(5.0,3.3,1.4,0.2,iris-setosa).
iris(7.0,3.2,4.7,1.4,iris-versicolor).
iris(6.4,3.2,4.5,1.5,iris-versicolor).
iris(6.9,3.1,4.9,1.5,iris-versicolor).
iris(5.5,2.3,4.0,1.3,iris-versicolor).
iris(6.5,2.8,4.6,1.5,iris-versicolor).
iris(5.7,2.8,4.5,1.3,iris-versicolor).
iris(6.3,3.3,4.7,1.6,iris-versicolor).
iris(4.9,2.4,3.3,1.0,iris-versicolor).
iris(6.6,2.9,4.6,1.3,iris-versicolor).
iris(5.2,2.7,3.9,1.4,iris-versicolor).
iris(5.0,2.0,3.5,1.0,iris-versicolor).
iris(5.9,3.0,4.2,1.5,iris-versicolor).
iris(6.0,2.2,4.0,1.0,iris-versicolor).
iris(6.1,2.9,4.7,1.4,iris-versicolor).
iris(5.6,2.9,3.6,1.3,iris-versicolor).
iris(6.7,3.1,4.4,1.4,iris-versicolor).
iris(5.6,3.0,4.5,1.5,iris-versicolor).
iris(5.8,2.7,4.1,1.0,iris-versicolor).
iris(6.2,2.2,4.5,1.5,iris-versicolor).
iris(5.6,2.5,3.9,1.1,iris-versicolor).
iris(5.9,3.2,4.8,1.8,iris-versicolor).
iris(6.1,2.8,4.0,1.3,iris-versicolor).
iris(6.3,2.5,4.9,1.5,iris-versicolor).
iris(6.1,2.8,4.7,1.2,iris-versicolor).
iris(6.4,2.9,4.3,1.3,iris-versicolor).
iris(6.6,3.0,4.4,1.4,iris-versicolor).
iris(6.8,2.8,4.8,1.4,iris-versicolor).
iris(6.7,3.0,5.0,1.7,iris-versicolor).
iris(6.0,2.9,4.5,1.5,iris-versicolor).
iris(5.7,2.6,3.5,1.0,iris-versicolor).
iris(5.5,2.4,3.8,1.1,iris-versicolor).
iris(5.5,2.4,3.7,1.0,iris-versicolor).
iris(5.8,2.7,3.9,1.2,iris-versicolor).
iris(6.0,2.7,5.1,1.6,iris-versicolor).
iris(5.4,3.0,4.5,1.5,iris-versicolor).
iris(6.0,3.4,4.5,1.6,iris-versicolor).
iris(6.7,3.1,4.7,1.5,iris-versicolor).
iris(6.3,2.3,4.4,1.3,iris-versicolor).
iris(5.6,3.0,4.1,1.3,iris-versicolor).
iris(5.5,2.5,4.0,1.3,iris-versicolor).
iris(5.5,2.6,4.4,1.2,iris-versicolor).
iris(6.1,3.0,4.6,1.4,iris-versicolor).
iris(5.8,2.6,4.0,1.2,iris-versicolor).
iris(5.0,2.3,3.3,1.0,iris-versicolor).
iris(5.6,2.7,4.2,1.3,iris-versicolor).
iris(5.7,3.0,4.2,1.2,iris-versicolor).
iris(5.7,2.9,4.2,1.3,iris-versicolor).
iris(6.2,2.9,4.3,1.3,iris-versicolor).
iris(5.1,2.5,3.0,1.1,iris-versicolor).
iris(5.7,2.8,4.1,1.3,iris-versicolor).
iris(6.3,3.3,6.0,2.5,iris-virginica).
iris(5.8,2.7,5.1,1.9,iris-virginica).
iris(7.1,3.0,5.9,2.1,iris-virginica).
iris(6.3,2.9,5.6,1.8,iris-virginica).
iris(6.5,3.0,5.8,2.2,iris-virginica).
iris(7.6,3.0,6.6,2.1,iris-virginica).
iris(4.9,2.5,4.5,1.7,iris-virginica).
iris(7.3,2.9,6.3,1.8,iris-virginica).
iris(6.7,2.5,5.8,1.8,iris-virginica).
iris(7.2,3.6,6.1,2.5,iris-virginica).
iris(6.5,3.2,5.1,2.0,iris-virginica).
iris(6.4,2.7,5.3,1.9,iris-virginica).
iris(6.8,3.0,5.5,2.1,iris-virginica).
iris(5.7,2.5,5.0,2.0,iris-virginica).
iris(5.8,2.8,5.1,2.4,iris-virginica).
iris(6.4,3.2,5.3,2.3,iris-virginica).
iris(6.5,3.0,5.5,1.8,iris-virginica).
iris(7.7,3.8,6.7,2.2,iris-virginica).
iris(7.7,2.6,6.9,2.3,iris-virginica).
iris(6.0,2.2,5.0,1.5,iris-virginica).
iris(6.9,3.2,5.7,2.3,iris-virginica).
iris(5.6,2.8,4.9,2.0,iris-virginica).
iris(7.7,2.8,6.7,2.0,iris-virginica).
iris(6.3,2.7,4.9,1.8,iris-virginica).
iris(6.7,3.3,5.7,2.1,iris-virginica).
iris(7.2,3.2,6.0,1.8,iris-virginica).
iris(6.2,2.8,4.8,1.8,iris-virginica).
iris(6.1,3.0,4.9,1.8,iris-virginica).
iris(6.4,2.8,5.6,2.1,iris-virginica).
iris(7.2,3.0,5.8,1.6,iris-virginica).
iris(7.4,2.8,6.1,1.9,iris-virginica).
iris(7.9,3.8,6.4,2.0,iris-virginica).
iris(6.4,2.8,5.6,2.2,iris-virginica).
iris(6.3,2.8,5.1,1.5,iris-virginica).
iris(6.1,2.6,5.6,1.4,iris-virginica).
iris(7.7,3.0,6.1,2.3,iris-virginica).
iris(6.3,3.4,5.6,2.4,iris-virginica).
iris(6.4,3.1,5.5,1.8,iris-virginica).
iris(6.0,3.0,4.8,1.8,iris-virginica).
iris(6.9,3.1,5.4,2.1,iris-virginica).
iris(6.7,3.1,5.6,2.4,iris-virginica).
iris(6.9,3.1,5.1,2.3,iris-virginica).
iris(5.8,2.7,5.1,1.9,iris-virginica).
iris(6.8,3.2,5.9,2.3,iris-virginica).
iris(6.7,3.3,5.7,2.5,iris-virginica).
iris(6.7,3.0,5.2,2.3,iris-virginica).
iris(6.3,2.5,5.0,1.9,iris-virginica).
iris(6.5,3.0,5.2,2.0,iris-virginica).
iris(6.2,3.4,5.4,2.3,iris-virginica).
iris(5.9,3.0,5.1,1.8,iris-virginica).


num_of_attr( bupa, 7 ).

bupa(85,92,45,27,31,0.0,1).
bupa(85,64,59,32,23,0.0,2).
bupa(86,54,33,16,54,0.0,2).
bupa(91,78,34,24,36,0.0,2).
bupa(87,70,12,28,10,0.0,2).
bupa(98,55,13,17,17,0.0,2).
bupa(88,62,20,17,9,0.5,1).
bupa(88,67,21,11,11,0.5,1).
bupa(92,54,22,20,7,0.5,1).
bupa(90,60,25,19,5,0.5,1).
bupa(89,52,13,24,15,0.5,1).
bupa(82,62,17,17,15,0.5,1).
bupa(90,64,61,32,13,0.5,1).
bupa(86,77,25,19,18,0.5,1).
bupa(96,67,29,20,11,0.5,1).
bupa(91,78,20,31,18,0.5,1).
bupa(89,67,23,16,10,0.5,1).
bupa(89,79,17,17,16,0.5,1).
bupa(91,107,20,20,56,0.5,1).
bupa(94,116,11,33,11,0.5,1).
bupa(92,59,35,13,19,0.5,1).
bupa(93,23,35,20,20,0.5,1).
bupa(90,60,23,27,5,0.5,1).
bupa(96,68,18,19,19,0.5,1).
bupa(84,80,47,33,97,0.5,1).
bupa(92,70,24,13,26,0.5,1).
bupa(90,47,28,15,18,0.5,1).
bupa(88,66,20,21,10,0.5,1).
bupa(91,102,17,13,19,0.5,1).
bupa(87,41,31,19,16,0.5,1).
bupa(86,79,28,16,17,0.5,1).
bupa(91,57,31,23,42,0.5,1).
bupa(93,77,32,18,29,0.5,1).
bupa(88,96,28,21,40,0.5,1).
bupa(94,65,22,18,11,0.5,1).
bupa(91,72,155,68,82,0.5,2).
bupa(85,54,47,33,22,0.5,2).
bupa(79,39,14,19,9,0.5,2).
bupa(85,85,25,26,30,0.5,2).
bupa(89,63,24,20,38,0.5,2).
bupa(84,92,68,37,44,0.5,2).
bupa(89,68,26,39,42,0.5,2).
bupa(89,101,18,25,13,0.5,2).
bupa(86,84,18,14,16,0.5,2).
bupa(85,65,25,14,18,0.5,2).
bupa(88,61,19,21,13,0.5,2).
bupa(92,56,14,16,10,0.5,2).
bupa(95,50,29,25,50,0.5,2).
bupa(91,75,24,22,11,0.5,2).
bupa(83,40,29,25,38,0.5,2).
bupa(89,74,19,23,16,0.5,2).
bupa(85,64,24,22,11,0.5,2).
bupa(92,57,64,36,90,0.5,2).
bupa(94,48,11,23,43,0.5,2).
bupa(87,52,21,19,30,0.5,2).
bupa(85,65,23,29,15,0.5,2).
bupa(84,82,21,21,19,0.5,2).
bupa(88,49,20,22,19,0.5,2).
bupa(96,67,26,26,36,0.5,2).
bupa(90,63,24,24,24,0.5,2).
bupa(90,45,33,34,27,0.5,2).
bupa(90,72,14,15,18,0.5,2).
bupa(91,55,4,8,13,0.5,2).
bupa(91,52,15,22,11,0.5,2).
bupa(87,71,32,19,27,1.0,1).
bupa(89,77,26,20,19,1.0,1).
bupa(89,67,5,17,14,1.0,2).
bupa(85,51,26,24,23,1.0,2).
bupa(103,75,19,30,13,1.0,2).
bupa(90,63,16,21,14,1.0,2).
bupa(90,63,29,23,57,2.0,1).
bupa(90,67,35,19,35,2.0,1).
bupa(87,66,27,22,9,2.0,1).
bupa(90,73,34,21,22,2.0,1).
bupa(86,54,20,21,16,2.0,1).
bupa(90,80,19,14,42,2.0,1).
bupa(87,90,43,28,156,2.0,2).
bupa(96,72,28,19,30,2.0,2).
bupa(91,55,9,25,16,2.0,2).
bupa(95,78,27,25,30,2.0,2).
bupa(92,101,34,30,64,2.0,2).
bupa(89,51,41,22,48,2.0,2).
bupa(91,99,42,33,16,2.0,2).
bupa(94,58,21,18,26,2.0,2).
bupa(92,60,30,27,297,2.0,2).
bupa(94,58,21,18,26,2.0,2).
bupa(88,47,33,26,29,2.0,2).
bupa(92,65,17,25,9,2.0,2).
bupa(92,79,22,20,11,3.0,1).
bupa(84,83,20,25,7,3.0,1).
bupa(88,68,27,21,26,3.0,1).
bupa(86,48,20,20,6,3.0,1).
bupa(99,69,45,32,30,3.0,1).
bupa(88,66,23,12,15,3.0,1).
bupa(89,62,42,30,20,3.0,1).
bupa(90,51,23,17,27,3.0,1).
bupa(81,61,32,37,53,3.0,2).
bupa(89,89,23,18,104,3.0,2).
bupa(89,65,26,18,36,3.0,2).
bupa(92,75,26,26,24,3.0,2).
bupa(85,59,25,20,25,3.0,2).
bupa(92,61,18,13,81,3.0,2).
bupa(89,63,22,27,10,4.0,1).
bupa(90,84,18,23,13,4.0,1).
bupa(88,95,25,19,14,4.0,1).
bupa(89,35,27,29,17,4.0,1).
bupa(91,80,37,23,27,4.0,1).
bupa(91,109,33,15,18,4.0,1).
bupa(91,65,17,5,7,4.0,1).
bupa(88,107,29,20,50,4.0,2).
bupa(87,76,22,55,9,4.0,2).
bupa(87,86,28,23,21,4.0,2).
bupa(87,42,26,23,17,4.0,2).
bupa(88,80,24,25,17,4.0,2).
bupa(90,96,34,49,169,4.0,2).
bupa(86,67,11,15,8,4.0,2).
bupa(92,40,19,20,21,4.0,2).
bupa(85,60,17,21,14,4.0,2).
bupa(89,90,15,17,25,4.0,2).
bupa(91,57,15,16,16,4.0,2).
bupa(96,55,48,39,42,4.0,2).
bupa(79,101,17,27,23,4.0,2).
bupa(90,134,14,20,14,4.0,2).
bupa(89,76,14,21,24,4.0,2).
bupa(88,93,29,27,31,4.0,2).
bupa(90,67,10,16,16,4.0,2).
bupa(92,73,24,21,48,4.0,2).
bupa(91,55,28,28,82,4.0,2).
bupa(83,45,19,21,13,4.0,2).
bupa(90,74,19,14,22,4.0,2).
bupa(92,66,21,16,33,5.0,1).
bupa(93,63,26,18,18,5.0,1).
bupa(86,78,47,39,107,5.0,2).
bupa(97,44,113,45,150,5.0,2).
bupa(87,59,15,19,12,5.0,2).
bupa(86,44,21,11,15,5.0,2).
bupa(87,64,16,20,24,5.0,2).
bupa(92,57,21,23,22,5.0,2).
bupa(90,70,25,23,112,5.0,2).
bupa(99,59,17,19,11,5.0,2).
bupa(92,80,10,26,20,6.0,1).
bupa(95,60,26,22,28,6.0,1).
bupa(91,63,25,26,15,6.0,1).
bupa(92,62,37,21,36,6.0,1).
bupa(95,50,13,14,15,6.0,1).
bupa(90,76,37,19,50,6.0,1).
bupa(96,70,70,26,36,6.0,1).
bupa(95,62,64,42,76,6.0,1).
bupa(92,62,20,23,20,6.0,1).
bupa(91,63,25,26,15,6.0,1).
bupa(82,56,67,38,92,6.0,2).
bupa(92,82,27,24,37,6.0,2).
bupa(90,63,12,26,21,6.0,2).
bupa(88,37,9,15,16,6.0,2).
bupa(100,60,29,23,76,6.0,2).
bupa(98,43,35,23,69,6.0,2).
bupa(91,74,87,50,67,6.0,2).
bupa(92,87,57,25,44,6.0,2).
bupa(93,99,36,34,48,6.0,2).
bupa(90,72,17,19,19,6.0,2).
bupa(97,93,21,20,68,6.0,2).
bupa(93,50,18,25,17,6.0,2).
bupa(90,57,20,26,33,6.0,2).
bupa(92,76,31,28,41,6.0,2).
bupa(88,55,19,17,14,6.0,2).
bupa(89,63,24,29,29,6.0,2).
bupa(92,79,70,32,84,7.0,1).
bupa(92,93,58,35,120,7.0,1).
bupa(93,84,58,47,62,7.0,2).
bupa(97,71,29,22,52,8.0,1).
bupa(84,99,33,19,26,8.0,1).
bupa(96,44,42,23,73,8.0,1).
bupa(90,62,22,21,21,8.0,1).
bupa(92,94,18,17,6,8.0,1).
bupa(90,67,77,39,114,8.0,1).
bupa(97,71,29,22,52,8.0,1).
bupa(91,69,25,25,66,8.0,2).
bupa(93,59,17,20,14,8.0,2).
bupa(92,95,85,48,200,8.0,2).
bupa(90,50,26,22,53,8.0,2).
bupa(91,62,59,47,60,8.0,2).
bupa(92,93,22,28,123,9.0,1).
bupa(92,77,86,41,31,10.0,1).
bupa(86,66,22,24,26,10.0,2).
bupa(98,57,31,34,73,10.0,2).
bupa(95,80,50,64,55,10.0,2).
bupa(92,108,53,33,94,12.0,2).
bupa(97,92,22,28,49,12.0,2).
bupa(93,77,39,37,108,16.0,1).
bupa(94,83,81,34,201,20.0,1).
bupa(87,75,25,21,14,0.0,1).
bupa(88,56,23,18,12,0.0,1).
bupa(84,97,41,20,32,0.0,2).
bupa(94,91,27,20,15,0.5,1).
bupa(97,62,17,13,5,0.5,1).
bupa(92,85,25,20,12,0.5,1).
bupa(82,48,27,15,12,0.5,1).
bupa(88,74,31,25,15,0.5,1).
bupa(95,77,30,14,21,0.5,1).
bupa(88,94,26,18,8,0.5,1).
bupa(91,70,19,19,22,0.5,1).
bupa(83,54,27,15,12,0.5,1).
bupa(91,105,40,26,56,0.5,1).
bupa(86,79,37,28,14,0.5,1).
bupa(91,96,35,22,135,0.5,1).
bupa(89,82,23,14,35,0.5,1).
bupa(90,73,24,23,11,0.5,1).
bupa(90,87,19,25,19,0.5,1).
bupa(89,82,33,32,18,0.5,1).
bupa(85,79,17,8,9,0.5,1).
bupa(85,119,30,26,17,0.5,1).
bupa(78,69,24,18,31,0.5,1).
bupa(88,107,34,21,27,0.5,1).
bupa(89,115,17,27,7,0.5,1).
bupa(92,67,23,15,12,0.5,1).
bupa(89,101,27,34,14,0.5,1).
bupa(91,84,11,12,10,0.5,1).
bupa(94,101,41,20,53,0.5,2).
bupa(88,46,29,22,18,0.5,2).
bupa(88,122,35,29,42,0.5,2).
bupa(84,88,28,25,35,0.5,2).
bupa(90,79,18,15,24,0.5,2).
bupa(87,69,22,26,11,0.5,2).
bupa(65,63,19,20,14,0.5,2).
bupa(90,64,12,17,14,0.5,2).
bupa(85,58,18,24,16,0.5,2).
bupa(88,81,41,27,36,0.5,2).
bupa(86,78,52,29,62,0.5,2).
bupa(82,74,38,28,48,0.5,2).
bupa(86,58,36,27,59,0.5,2).
bupa(94,56,30,18,27,0.5,2).
bupa(87,57,30,30,22,0.5,2).
bupa(98,74,148,75,159,0.5,2).
bupa(94,75,20,25,38,0.5,2).
bupa(83,68,17,20,71,0.5,2).
bupa(93,56,25,21,33,0.5,2).
bupa(101,65,18,21,22,0.5,2).
bupa(92,65,25,20,31,0.5,2).
bupa(92,58,14,16,13,0.5,2).
bupa(86,58,16,23,23,0.5,2).
bupa(85,62,15,13,22,0.5,2).
bupa(86,57,13,20,13,0.5,2).
bupa(86,54,26,30,13,0.5,2).
bupa(81,41,33,27,34,1.0,1).
bupa(91,67,32,26,13,1.0,1).
bupa(91,80,21,19,14,1.0,1).
bupa(92,60,23,15,19,1.0,1).
bupa(91,60,32,14,8,1.0,1).
bupa(93,65,28,22,10,1.0,1).
bupa(90,63,45,24,85,1.0,2).
bupa(87,92,21,22,37,1.0,2).
bupa(83,78,31,19,115,1.0,2).
bupa(95,62,24,23,14,1.0,2).
bupa(93,59,41,30,48,1.0,2).
bupa(84,82,43,32,38,2.0,1).
bupa(87,71,33,20,22,2.0,1).
bupa(86,44,24,15,18,2.0,1).
bupa(86,66,28,24,21,2.0,1).
bupa(88,58,31,17,17,2.0,1).
bupa(90,61,28,29,31,2.0,1).
bupa(88,69,70,24,64,2.0,1).
bupa(93,87,18,17,26,2.0,1).
bupa(98,58,33,21,28,2.0,1).
bupa(91,44,18,18,23,2.0,2).
bupa(87,75,37,19,70,2.0,2).
bupa(94,91,30,26,25,2.0,2).
bupa(88,85,14,15,10,2.0,2).
bupa(89,109,26,25,27,2.0,2).
bupa(87,59,37,27,34,2.0,2).
bupa(93,58,20,23,18,2.0,2).
bupa(88,57,9,15,16,2.0,2).
bupa(94,65,38,27,17,3.0,1).
bupa(91,71,12,22,11,3.0,1).
bupa(90,55,20,20,16,3.0,1).
bupa(91,64,21,17,26,3.0,2).
bupa(88,47,35,26,33,3.0,2).
bupa(82,72,31,20,84,3.0,2).
bupa(85,58,83,49,51,3.0,2).
bupa(91,54,25,22,35,4.0,1).
bupa(98,50,27,25,53,4.0,2).
bupa(86,62,29,21,26,4.0,2).
bupa(89,48,32,22,14,4.0,2).
bupa(82,68,20,22,9,4.0,2).
bupa(83,70,17,19,23,4.0,2).
bupa(96,70,21,26,21,4.0,2).
bupa(94,117,77,56,52,4.0,2).
bupa(93,45,11,14,21,4.0,2).
bupa(93,49,27,21,29,4.0,2).
bupa(84,73,46,32,39,4.0,2).
bupa(91,63,17,17,46,4.0,2).
bupa(90,57,31,18,37,4.0,2).
bupa(87,45,19,13,16,4.0,2).
bupa(91,68,14,20,19,4.0,2).
bupa(86,55,29,35,108,4.0,2).
bupa(91,86,52,47,52,4.0,2).
bupa(88,46,15,33,55,4.0,2).
bupa(85,52,22,23,34,4.0,2).
bupa(89,72,33,27,55,4.0,2).
bupa(95,59,23,18,19,4.0,2).
bupa(94,43,154,82,121,4.0,2).
bupa(96,56,38,26,23,5.0,2).
bupa(90,52,10,17,12,5.0,2).
bupa(94,45,20,16,12,5.0,2).
bupa(99,42,14,21,49,5.0,2).
bupa(93,102,47,23,37,5.0,2).
bupa(94,71,25,26,31,5.0,2).
bupa(92,73,33,34,115,5.0,2).
bupa(87,54,41,29,23,6.0,1).
bupa(92,67,15,14,14,6.0,1).
bupa(98,101,31,26,32,6.0,1).
bupa(92,53,51,33,92,6.0,1).
bupa(97,94,43,43,82,6.0,1).
bupa(93,43,11,16,54,6.0,1).
bupa(93,68,24,18,19,6.0,1).
bupa(95,36,38,19,15,6.0,1).
bupa(99,86,58,42,203,6.0,1).
bupa(98,66,103,57,114,6.0,1).
bupa(92,80,10,26,20,6.0,1).
bupa(96,74,27,25,43,6.0,2).
bupa(95,93,21,27,47,6.0,2).
bupa(86,109,16,22,28,6.0,2).
bupa(91,46,30,24,39,7.0,2).
bupa(102,82,34,78,203,7.0,2).
bupa(85,50,12,18,14,7.0,2).
bupa(91,57,33,23,12,8.0,1).
bupa(91,52,76,32,24,8.0,1).
bupa(93,70,46,30,33,8.0,1).
bupa(87,55,36,19,25,8.0,1).
bupa(98,123,28,24,31,8.0,1).
bupa(82,55,18,23,44,8.0,2).
bupa(95,73,20,25,225,8.0,2).
bupa(97,80,17,20,53,8.0,2).
bupa(100,83,25,24,28,8.0,2).
bupa(88,91,56,35,126,9.0,2).
bupa(91,138,45,21,48,10.0,1).
bupa(92,41,37,22,37,10.0,1).
bupa(86,123,20,25,23,10.0,2).
bupa(91,93,35,34,37,10.0,2).
bupa(87,87,15,23,11,10.0,2).
bupa(87,56,52,43,55,10.0,2).
bupa(99,75,26,24,41,12.0,1).
bupa(96,69,53,43,203,12.0,2).
bupa(98,77,55,35,89,15.0,1).
bupa(91,68,27,26,14,16.0,1).
bupa(98,99,57,45,65,20.0,1).

%-----------------------------------------------------------------------------
