#!/usr/bin/ruby def solve(s) al=[] ar=[] ah=[0]*s.size ast=[] s.size.times{|i| if s[i]==?( al<=r hidx=(0...s.size).bsearch{|i|ah[i]>=ah[l]+2}||s.size #next if !hidx st=ast.bsearch{|e|e>=hidx}||s.size if st