#!/usr/bin/env tclsh8.6 namespace import ::tcl::mathop::* set card 1 while {[gets stdin line] >= 0} { set line [lindex [split $line :] 1] lassign [split $line |] win($card) has($card) set count($card) 1 incr card } for {set c 1} {$c < $card} {incr c} { array unset winhash foreach n $win($c) {set winhash($n) 1} set score 0 foreach n $has($c) { if {[info exists winhash($n)]} {incr score} } for {set i [+ $c 1]} {$i <= [+ $c $score]} {incr i} { incr count($i) $count($c) } } set total 0 for {set c 1} {$c < $card} {incr c} { incr total $count($c) } puts $total