Format code
Use index starting from 0 in frequent item index; Implement triple counting.