ROM  algorithm