my solution from various onilne programming contests/practices