Determine cube efficiently