#!/usr/bin/env tclsh9.0 namespace import ::tcl::mathop::* proc check {value list} { # puts "check value=<$value> list=<$list>" if {[llength $list] == 1} { return [expr {$value == [lindex $list 0]}] } set a [lindex $list end] if {[check [- $value $a] [lrange $list 0 end-1]]} {return 1} if {[string match "*\[0-9\]$a" $value]} { set len [- [string length $value] [string length $a]] if {[check [string range $value 0 $len-1] [lrange $list 0 end-1]]} { return 1 } } if {[% $value $a] != 0} {return 0} if {[check [/ $value $a] [lrange $list 0 end-1]]} {return 1} return 0 } set total 0 while {[gets stdin line] >= 0} { if {$line eq ""} continue if {[scan $line {%lld: %[0-9 ]} value list] != 2} continue if {[check $value [split $list " "]]} {incr total $value} } puts $total