CodeForces - 82D Two out of Three (记忆化搜索+DP)*

NoSuchKey