modded venn algorithm