Painful writing DP to fix the time limited exceed bug