basic version
basic verison works, but exceed time limit