Java and Python implementations