#!/usr/bin/env tclsh if {[llength $argv]} { set pre [lindex $argv 0] } else { set pre 25 } while {[gets stdin line] >= 0} { if {$line eq ""} continue lappend list $line } proc check {list i} { global pre for {set j [expr {$i-$pre}]} {$j < $i-1} {incr j} { for {set k [expr {$j+1}]} {$k < $i} {incr k} { set a [lindex $list $j] set b [lindex $list $k] if {$a == $b} continue if {$a + $b == [lindex $list $i]} {return 1} } } return 0 } for {set i $pre} {$i < [llength $list]} {incr i} { if {! [check $list $i]} { set invalid [lindex $list $i] puts $invalid break } } for {set i 0} {$i < [llength $list] - 1} {incr i} { set total [lindex $list $i] set min $total set max $total for {set j [expr {$i+1}]} {$j < [llength $list]} {incr j} { set b [lindex $list $j] incr total $b if {$b < $min} {set min $b} if {$b > $max} {set max $b} if {$total == $invalid} { puts [expr {$min + $max}] exit } if {$total > $invalid} break } }