Two versions written in JAVA, and Python