I commit here solved problem at coding-test site.
These codes may not be the perfect answer!
If you have better answer and share that, I appreciated for.