thanks to the OJ's discussion, wrote a awsome solution