#!/usr/bin/ruby require 'timeout' def dfs(a) return to_enum(:dfs,a) if !block_given? yield a[0] if a.size<2 (a.size-1).times{|i| dfs(a[0..i]){|l| dfs(a[i+1..-1]){|r| (puts :YES;exit) if l==r next if lb[-1] dfs(b).each{|e| } } } rescue Timeout::Error puts :NO end