書き換えた値は \([\min\{a_i\}, \max\{a_i\}]\) のどれかになるので, すべて試す.