#!/usr/bin/env tclsh8.6 set score 0 while {[gets stdin line] >= 0} { set stack {} foreach c [split $line {}] { switch -- $c { \[ - \{ - ( - < {lappend stack $c} \] - \} - ) - > { set pop [lindex $stack end] set stack [lreplace $stack end end] } } switch -- $c { \] { if {$pop ne "\["} {incr score 57; break} } \} { if {$pop ne "\{"} {incr score 1197; break} } ) { if {$pop ne "("} {incr score 3; break} } > { if {$pop ne "<"} {incr score 25137; break} } } } } puts $score