memoizing sid s and lids