My solution for AIZU ONLINE JUDGE