Inclusion--Exclusion, Derangements & Pigeonhole

Study Sheet

Inclusion--Exclusion, Derangements & Pigeonhole

Competition counting & probability, Unit 5

Two-- and Three--Set Inclusion--Exclusion

Concept
Counting a Union Without Double--Counting

When two sets overlap, adding their sizes counts the overlap twice, so subtract it once:

AB=A+BAB\boxed{\,|A\cup B| = |A| + |B| - |A\cap B|\,}

For three sets, add the singles, subtract the pairs, add back the triple:

ABC=A+B+CABACBC+ABC.|A\cup B\cup C| = |A|+|B|+|C| - |A\cap B| - |A\cap C| - |B\cap C| + |A\cap B\cap C|.

To count elements in none of the sets, subtract the union from the universe U|U|:

AB=UAB.|\overline{A}\cap\overline{B}| = |U| - |A\cup B|.

Two overlapping sets: the middle region is counted once in A|A| and once in B|B|, so we subtract AB|A\cap B|.

Example
Example: A Survey

Of 5050 people, 3030 like coffee, 2525 like tea, and 1010 like both. How many like at least one drink? How many like neither?

CT=30+2510=45.Neither=5045=5.|C\cup T| = 30 + 25 - 10 = \mathbf{45}.\qquad \text{Neither} = 50 - 45 = \mathbf{5}.

Three sets: ++ singles - pairs ++ triple. Each atomic region ends up counted exactly once.

Example
Example: Divisibility

How many integers from 11 to 3030 are divisible by 22, 33, or 55?

302=15, 303=10, 305=6;306=5, 3010=3, 3015=2;3030=1.\left\lfloor\tfrac{30}{2}\right\rfloor=15,\ \left\lfloor\tfrac{30}{3}\right\rfloor=10,\ \left\lfloor\tfrac{30}{5}\right\rfloor=6;\quad \left\lfloor\tfrac{30}{6}\right\rfloor=5,\ \left\lfloor\tfrac{30}{10}\right\rfloor=3,\ \left\lfloor\tfrac{30}{15}\right\rfloor=2;\quad \left\lfloor\tfrac{30}{30}\right\rfloor=1.
15+10+6532+1=22.15+10+6 - 5-3-2 + 1 = \mathbf{22}.
Tip

Tip: The count divisible by both aa and bb is the count divisible by lcm(a,b)\operatorname{lcm}(a,b) --- not abab, unless aa and bb are coprime. For 66 and 1010, use lcm=30\operatorname{lcm}=30, not 6060.

General Inclusion--Exclusion

Concept
The Full Formula

For sets A1,,AnA_1,\dots,A_n, alternate sums over single sets, pairs, triples, and so on:

i=1nAi=iAii<jAiAj+i<j<kAiAjAk+(1)n+1A1An.\left|\,\bigcup_{i=1}^{n} A_i\,\right| = \sum_i |A_i| - \sum_{i<j}|A_i\cap A_j| + \sum_{i<j<k}|A_i\cap A_j\cap A_k| - \cdots + (-1)^{n+1}\bigl|A_1\cap\cdots\cap A_n\bigr|.

Equivalently, the number of elements in none of the sets is

A1An=S{1,,n}(1)SiSAi,\bigl|\overline{A_1}\cap\cdots\cap\overline{A_n}\bigr| = \sum_{S\subseteq\{1,\dots,n\}} (-1)^{|S|}\Bigl|\bigcap_{i\in S} A_i\Bigr|,

where the empty intersection is the whole universe U|U|.

Example
Example: Coprime--Style Count

How many integers from 11 to 100100 are divisible by none of 22, 33, 55?

U=100;50+33+20 (singles),16+10+6 (pairs: 6,10,15),3 (triple: 30).|U|=100;\quad 50+33+20 \ (\text{singles}),\quad 16+10+6 \ (\text{pairs: } 6,10,15),\quad 3 \ (\text{triple: }30).
100(50+33+20)+(16+10+6)3=100103+323=26.100 - (50+33+20) + (16+10+6) - 3 = 100 - 103 + 32 - 3 = \mathbf{26}.
Tip

Sign pattern: the term for an intersection of mm sets carries sign (1)m+1(-1)^{m+1} in the union formula (add odd, subtract even). In the “none” formula it is (1)m(-1)^{m}. Miscounting signs is the #1 error --- write the layers out explicitly.

Derangements

Concept
Permutations With No Fixed Point

A derangement is a permutation in which no element stays in its original position. Inclusion--exclusion over the “ii is fixed” events gives

Dn=n!k=0n(1)kk!=n!(111!+12!+(1)nn!).\boxed{\,D_n = n!\sum_{k=0}^{n}\frac{(-1)^k}{k!} = n!\left(1 - \frac{1}{1!} + \frac{1}{2!} - \cdots + \frac{(-1)^n}{n!}\right).}

Two handy recurrences:  Dn=(n1)(Dn1+Dn2)\ D_n = (n-1)\bigl(D_{n-1}+D_{n-2}\bigr) and  Dn=nDn1+(1)n.\ D_n = nD_{n-1} + (-1)^n.

n123456Dn012944265\begin{array}{c|cccccc} n & 1 & 2 & 3 & 4 & 5 & 6\\\hline D_n & 0 & 1 & 2 & 9 & 44 & 265 \end{array}

As nn grows, Dn/n!1/e0.3679D_n/n! \to 1/e \approx 0.3679, so a random permutation is a derangement about 37%37\% of the time.

Example
Example: The Hat--Check Problem

Four people check identical-looking hats; on the way out the hats are returned at random. In how many ways does nobody get their own hat?

D4=4!(11+1216+124)=24924=9.D_4 = 4!\left(1 - 1 + \tfrac12 - \tfrac16 + \tfrac{1}{24}\right) = 24\cdot\tfrac{9}{24} = \mathbf{9}.

Check with the recurrence: D4=3(D3+D2)=3(2+1)=9.D_4 = 3(D_3 + D_2) = 3(2+1) = 9.

Tip

Tip: “Exactly mm people get their own item” =(nm)Dnm= \binom{n}{m} D_{n-m}: choose who is fixed, then derange the rest. Summing over mm recovers n!n!, a useful sanity check.

Counting Surjections (Onto Functions)

Concept
Onto Functions via Inclusion--Exclusion

The number of surjections (onto functions) from an nn--element set onto a kk--element set is found by excluding the maps that miss at least one target value:

Surj(n,k)=i=0k(1)i(ki)(ki)n.\boxed{\,\operatorname{Surj}(n,k) = \sum_{i=0}^{k}(-1)^i\binom{k}{i}(k-i)^n.}

This also counts the ways to distribute nn distinct objects into kk distinct boxes with no box empty. It relates to Stirling numbers of the second kind by

Surj(n,k)=k!S(n,k),\operatorname{Surj}(n,k) = k!\,S(n,k),

where S(n,k)S(n,k) counts partitions of the objects into kk unlabeled nonempty groups.

Example
Example: Onto a 33--Set

How many functions from {1,2,3,4}\{1,2,3,4\} onto {a,b,c}\{a,b,c\} are there?

Surj(4,3)=34(31)24+(32)14(33)04=8148+30=36.\operatorname{Surj}(4,3) = 3^4 - \binom{3}{1}2^4 + \binom{3}{2}1^4 - \binom{3}{3}0^4 = 81 - 48 + 3 - 0 = \mathbf{36}.

Equivalently 3!S(4,3)=66=363!\,S(4,3) = 6\cdot 6 = 36.

Tip

Trap: knk^n counts all functions; only Surj(n,k)\operatorname{Surj}(n,k) are onto. If n<kn<k there are 00 surjections (too few inputs to hit every output), and the alternating sum indeed collapses to 00.

The Pigeonhole Principle

Concept
The Basic Principle

If nn objects are placed into kk boxes and n>kn > k, then some box contains at least two objects. More sharply: you cannot have every box with at most one object once the objects outnumber the boxes.

The art is choosing the right “boxes.” Common box constructions: remainders modulo mm, sign/parity classes, sub-regions of a shape, or pairs that sum to a target.

Five items in four boxes force at least one box to hold two.

Example
Example: Same Remainder

Show that among any 55 integers, two leave the same remainder when divided by 44. The possible remainders are {0,1,2,3}\{0,1,2,3\} --- four boxes. With 55 integers (five objects), two must share a remainder. Their difference is then divisible by 44.

Tip

Tip: “Two share a remainder mod mm” is the same as “their difference is a multiple of mm.” This turns many divisibility claims into a pigeonhole count with mm boxes.

Generalized Pigeonhole & Extremal Arguments

Concept
The Sharpened Count

If nn objects go into kk boxes, then some box contains at least

nk\boxed{\left\lceil \frac{n}{k} \right\rceil}

objects. (If every box had at most n/k1\lceil n/k\rceil - 1, the total would be under nn.) Turned around, to force some box to hold at least rr objects you need n>k(r1)n > k(r-1), i.e. n=k(r1)+1n = k(r-1)+1 objects.

Extremal principle: to find the largest “bad-free” set, group elements into forbidden pairs/blocks; you may take at most one representative per block, and the pigeonhole bound is tight when you take exactly one.

Example
Example: Guaranteeing a Color

A drawer holds socks in 55 colors. How many must you draw to be sure of 44 of one color?

Worst case: 3 of each color=35=15 socks, still no quartet.15+1=16.\text{Worst case: }3\text{ of each color}=3\cdot 5 = 15\text{ socks, still no quartet.}\quad 15+1 = \mathbf{16}.

Here k=5k=5, r=4r=4, so n=k(r1)+1=53+1=16n = k(r-1)+1 = 5\cdot 3 + 1 = 16.

Example
Example: Extremal Subset

What is the largest subset of {1,2,,20}\{1,2,\dots,20\} containing no two elements that sum to 2121? Pair them: (1,20),(2,19),,(10,11)(1,20),(2,19),\dots,(10,11) --- 1010 pairs. From each pair you may keep at most one number, so the largest safe subset has size 10\mathbf{10} (e.g. {1,2,,10}\{1,2,\dots,10\}).

Tip

Strategy: “How many to guarantee rr?” means build the worst case (r1r-1 per box) and add one. “Largest set avoiding a condition?” means group into forbidden blocks and take one per block. These are the same pigeonhole idea read in two directions.

Going Deeper: Connections & Advanced Tools

Concept
Inclusion--Exclusion and Euler's Totient

Euler's totient φ(n)\varphi(n) counts integers in {1,,n}\{1,\dots,n\} coprime to nn. Let p1,,prp_1,\dots,p_r be the distinct primes dividing nn; applying the “none of the divisibility events” form of PIE gives the product formula

φ(n)=ni=1r(11pi).\varphi(n) = n\prod_{i=1}^{r}\left(1 - \frac{1}{p_i}\right).

For example φ(12)=12(112)(113)=121223=4\varphi(12) = 12\left(1-\tfrac12\right)\left(1-\tfrac13\right) = 12\cdot\tfrac12\cdot\tfrac23 = 4 (namely 1,5,7,111,5,7,11). This is the surjection/derangement machinery in disguise: a signed sum over subsets of “forbidden” primes.

Example
Example: Surjections and Set Partitions

The number of ways to split 55 labeled tasks among 33 identical days with each day used at least once is a set partition count S(5,3)=25S(5,3)=25. Labeling the days (making them distinct) multiplies by 3!3!:

Surj(5,3)=3!S(5,3)=625=150=35325+315.\operatorname{Surj}(5,3) = 3!\,S(5,3) = 6\cdot 25 = 150 = 3^5 - 3\cdot 2^5 + 3\cdot 1^5.

The PIE formula and the Stirling--number viewpoint always agree.

Concept
Pigeonhole in Number Theory & Geometry

Number theory. Among any n+1n+1 integers, two are congruent modulo nn, so their difference is a multiple of nn. Among any n+1n+1 numbers chosen from {1,,2n}\{1,\dots,2n\}, two are consecutive-in-a-pair and one divides the other (write each as 2a(odd)2^a\cdot(\text{odd}); there are only nn odd parts --- the boxes).

Geometry. Partition a region into smaller cells; if you place more points than cells, two points share a cell and lie within its diameter. E.g. 55 points in a unit square: cut it into four 12×12\tfrac12\times\tfrac12 squares, so two points lie within distance 22\tfrac{\sqrt2}{2}.

Example
Example: Divisibility by a Difference

Prove that among any 1212 integers, two have a difference divisible by 1111. The residues modulo 1111 form 1111 boxes {0,1,,10}\{0,1,\dots,10\}. Twelve integers into eleven residue classes force two into the same class; their difference is then divisible by 1111. (This is exactly 12/11=2\lceil 12/11\rceil = 2.)

Concept
The Extremal Principle

Many existence problems yield to: consider the largest, smallest, or otherwise most extreme object and argue about it. Choose the configuration maximizing (or minimizing) some quantity; if the desired property failed, you could push the extreme further --- a contradiction. Paired with pigeonhole, the extremal principle proves that a structure must exist without constructing it explicitly.

Tip

Big picture. Inclusion--exclusion, derangements, surjection counts, and the totient are all one idea: count everything, then correct for over-counting with alternating signs over subsets of “bad” conditions. Pigeonhole and the extremal principle are the reverse temperament --- they prove existence by counting boxes rather than configurations. Together they let you both count exactly and guarantee structure. When a direct count stalls, ask: what is being over-counted (PIE), or what are the boxes (pigeonhole)?

Stirling Numbers of the Second Kind & Bell Numbers

Concept
Partitioning a Set into Blocks

The Stirling number of the second kind S(n,k)S(n,k) counts the ways to partition an nn--element set into exactly kk nonempty, unlabeled blocks. Building an element one at a time gives the recurrence

S(n,k)=kS(n1,k)+S(n1,k1)\boxed{\,S(n,k) = k\,S(n-1,k) + S(n-1,k-1)\,}

(the new element either joins one of the kk existing blocks, or starts a fresh block with the previous n1n-1 elements split into k1k-1 blocks). Boundary values: S(n,0)=[n=0]S(n,0)=[n=0], S(n,1)=S(n,n)=1S(n,1)=S(n,n)=1, S(n,2)=2n11S(n,2)=2^{n-1}-1.

Labeling the blocks turns each partition into a surjection, recovering the count from the previous section:

k!S(n,k)=Surj(n,k)=i=0k(1)i(ki)(ki)n.k!\,S(n,k) = \operatorname{Surj}(n,k) = \sum_{i=0}^{k}(-1)^i\binom{k}{i}(k-i)^n.

Summing over all block-counts gives the Bell number Bn=k=0nS(n,k)B_n=\sum_{k=0}^{n} S(n,k), the total number of partitions of an nn--set.

n0123456Bn11251552203\begin{array}{c|ccccccc} n & 0 & 1 & 2 & 3 & 4 & 5 & 6\\\hline B_n & 1 & 1 & 2 & 5 & 15 & 52 & 203 \end{array}

Each entry is kk times the entry directly above plus the entry up-and-left.

Example
Example: Distinct Prizes, Identical Teams (AIME flavor)

In how many ways can 66 distinct prizes be split among 33 indistinguishable nonempty groups? This is S(6,3)S(6,3). Build it from the recurrence, using S(5,3)=25S(5,3)=25 and S(5,2)=15S(5,2)=15:

S(6,3)=3S(5,3)+S(5,2)=325+15=90.S(6,3) = 3\,S(5,3) + S(5,2) = 3\cdot 25 + 15 = \mathbf{90}.

If the groups were instead labeled (say, Room 11, Room 22, Room 33), multiply by 3!3!: Surj(6,3)=690=540=36326+316.\operatorname{Surj}(6,3)=6\cdot 90 = 540 = 3^6 - 3\cdot 2^6 + 3\cdot 1^6.

Tip

Labeled vs. unlabeled: identical boxes/groups \Rightarrow use S(n,k)S(n,k); distinct boxes \Rightarrow use k!S(n,k)=Surj(n,k)k!\,S(n,k)=\operatorname{Surj}(n,k). If empty boxes are allowed, sum over the number of nonempty boxes: distinct boxes give knk^n, identical boxes give j=1kS(n,j)\sum_{j=1}^{k} S(n,j).

Derangement Asymptotics: The Nearest--Integer Rule

Concept
DnD_n Is the Nearest Integer to n!/en!/e

The Maclaurin series e1=k0(1)kk!e^{-1}=\sum_{k\ge 0}\tfrac{(-1)^k}{k!} truncated at k=nk=n is exactly Dn/n!D_n/n!. The leftover tail is tiny, so

Dn=n!e+12(n1),Dn=nearest integer to n!e.\boxed{\,D_n = \left\lfloor \frac{n!}{e} + \frac{1}{2} \right\rfloor \quad(n\ge 1),\qquad D_n = \text{nearest integer to } \frac{n!}{e}.}

Bounding the alternating tail gives Dnn!e=n!ek>n(1)kk!<1n+112\left|\,D_n - \tfrac{n!}{e}\,\right| = \tfrac{n!}{e}\left|\sum_{k>n}\tfrac{(-1)^k}{k!}\right| < \dfrac{1}{n+1} \le \tfrac12 for n1n\ge 1, which is why rounding is always correct. Consequently the probability that a random permutation of nn objects is a derangement,

Dnn!=k=0n(1)kk!1e0.367879,\frac{D_n}{n!} = \sum_{k=0}^{n}\frac{(-1)^k}{k!} \longrightarrow \frac{1}{e}\approx 0.367879,

converges extraordinarily fast --- already at n=6n=6 we have D6/6!=265/720=0.368055D_6/6! = 265/720 = 0.368055\ldots, agreeing with 1/e1/e to three decimals.

Example
Example: A Fast Derangement Count

Compute D7D_7 without the full alternating sum. Since 7!=50407! = 5040 and e2.718281828e\approx 2.718281828,

7!e=50402.7182818281854.11,D7=1854.11+0.5=1854.\frac{7!}{e} = \frac{5040}{2.718281828} \approx 1854.11,\qquad D_7 = \left\lfloor 1854.11 + 0.5\right\rfloor = \mathbf{1854}.

Cross-check with Dn=nDn1+(1)nD_n = nD_{n-1}+(-1)^n: D7=7D61=72651=18551=1854.D_7 = 7\,D_6 - 1 = 7\cdot 265 - 1 = 1855 - 1 = 1854.

Tip

Contest shortcut: to get DnD_n for larger nn, apply Dn=nDn1+(1)nD_n = nD_{n-1}+(-1)^n starting from D1=0D_1=0; the “±1\pm 1” alternates. The nearest-integer fact is the fast estimate, the recurrence is the exact check.

Exactly mm Sets: The Bonferroni Refinement

Concept
Counting Elements in Exactly (or At Least) mm Sets

Let Sj=T=jiTAiS_j = \sum_{|T|=j}\bigl|\bigcap_{i\in T}A_i\bigr| be the jj-th symmetric sum of intersection sizes (S0=US_0=|U|). The number of elements lying in exactly mm of the sets A1,,AnA_1,\dots,A_n is

Em=j=mn(1)jm(jm)Sj,\boxed{\,E_m = \sum_{j=m}^{n} (-1)^{\,j-m}\binom{j}{m} S_j,}

and the number in at least mm of the sets is

Lm=j=mn(1)jm(j1m1)Sj.L_m = \sum_{j=m}^{n} (-1)^{\,j-m}\binom{j-1}{m-1} S_j.

Setting m=0m=0 in EmE_m gives the “none” formula; m=1m=1 in LmL_m gives the ordinary union. Bonferroni inequalities: truncating the alternating series after an odd number of terms over-estimates A1An|A_1\cup\cdots\cup A_n| and after an even number under-estimates it, so partial sums bracket the true count.

Example
Example: Exactly One Own Hat

For the hat--check problem with n=5n=5 people, how many return arrangements give exactly 22 people their own hat? Using the “exactly mm” idea for fixed points (choose the fixed pair, derange the rest):

(52)D3=102=20.\binom{5}{2} D_3 = 10\cdot 2 = \mathbf{20}.

As a check that the counts partition 5!=1205!=120:  m=05(5m)D5m=44+59+102+101+50+1=44+45+20+10+0+1=120.\ \sum_{m=0}^{5}\binom{5}{m}D_{5-m} = 44 + 5\cdot 9 + 10\cdot 2 + 10\cdot 1 + 5\cdot 0 + 1 = 44+45+20+10+0+1 = 120.

Example
Example: In Exactly Two of Three (AIME flavor)

Of integers 11 to 100100, how many are divisible by exactly two of 2,3,52,3,5? Here S2=100/6+100/10+100/15=16+10+6=32S_2 = \lfloor 100/6\rfloor + \lfloor 100/10\rfloor + \lfloor 100/15\rfloor = 16+10+6 = 32 and S3=100/30=3S_3 = \lfloor 100/30\rfloor = 3. Then

E2=(22)S2(32)S3=3233=329=23.E_2 = \binom{2}{2}S_2 - \binom{3}{2}S_3 = 32 - 3\cdot 3 = 32 - 9 = \mathbf{23}.
Tip

Why the binomials appear: an element in exactly jj sets is counted (jm)\binom{j}{m} times inside SjS_j; the alternating (jm)\binom{j}{m}-weighted sum cancels all jmj\ne m and leaves each “exactly-mm” element counted once. Memorize the two coefficients: (jm)\binom{j}{m} for exactly, (j1m1)\binom{j-1}{m-1} for at least.

Ramsey Numbers & Probabilistic Pigeonhole

Concept
Order Forced by Size: R(3,3)=6R(3,3)=6

Color the edges of a complete graph on nn vertices with two colors (say, acquainted / stranger). A monochromatic triangle is three mutually-acquainted or three mutual strangers. The Ramsey number R(3,3)R(3,3) is the least nn forcing one to exist.

R(3,3)6R(3,3)\le 6: Fix a vertex vv among 66. Its 55 edges get 22 colors, so by pigeonhole (5/2=3\lceil 5/2\rceil = 3) at least 33 share a color --- say vv is acquainted with a,b,ca,b,c. If any edge among a,b,ca,b,c is “acquainted,” that edge with vv forms an acquainted triangle; otherwise a,b,ca,b,c are mutual strangers --- a stranger triangle. Either way a monochromatic triangle appears.

R(3,3)>5R(3,3)>5: color the 55-cycle's edges red and its “diagonals” blue; neither color contains a triangle. Hence R(3,3)=6\boxed{R(3,3)=6}: any party of 66 has 33 mutual acquaintances or 33 mutual strangers.

The pentagon (solid) and pentagram (dashed) each avoid a triangle, proving 55 vertices are not enough.

Example
Example: An Averaging (Probabilistic) Pigeonhole

100\mathbf{100} people each rate a film from 11 to 1010; the ratings sum to 620\mathbf{620}. Show some rating value was given by at least 62\mathbf{62} people is false in general, but the averaging principle still bites: the mean rating is 620/100=6.2620/100 = 6.2, so some person rated it at least 6.2=7\lceil 6.2\rceil = 7 and some rated it at most 66. More usefully, distributing 620620 “rating-points” among 1010 possible values, some value carries at least 620/10\lceil 620/10\rceil? No --- points are not people. The correct averaging statement: with 100100 people and 1010 scores, some score was chosen by at least 100/10=10\lceil 100/10\rceil = \mathbf{10} people.

Example
Example: Existence Beats the Average (Olympiad flavor)

Each of 1717 scientists corresponds with every other on one of 33 topics. Prove some three of them discuss a single common topic (i.e. R(3,3,3)17R(3,3,3)\le 17). Fix a scientist vv; its 1616 edges use 33 topics, so by pigeonhole 16/3=6\lceil 16/3\rceil = 6 edges share a topic TT --- say to the group GG of 6\ge 6 people. If any pair inside GG also uses topic TT, they and vv form a TT--triangle. Otherwise GG uses only the other 22 topics, and a 66-vertex 22-colored graph contains a monochromatic triangle by R(3,3)=6R(3,3)=6. Either way a monochromatic triangle exists.

Tip

The averaging principle: in any finite collection, some element is at least the average and some is at most the average. Combined with pigeonhole (n/k\lceil n/k\rceil per box) and Ramsey-style edge-coloring, this proves a desired structure must exist without exhibiting it. Ramsey's slogan: complete disorder is impossible --- enough size forces order.

Formulas, Proofs & Tips

Tip
Inclusion–exclusion and the pigeonhole principle
ABC=AAB+ABC;n/k in some hole|A\cup B\cup C|=\sum|A|-\sum|A\cap B|+|A\cap B\cap C|;\qquad \lceil n/k\rceil \text{ in some hole}

What it means. Add, subtract the overlaps, add back the triple overlap. With more items than boxes, some box repeats.

Example. Among 1313 people and 1212 months, two must share a birth month.

Why it works. An element in exactly two sets is counted twice by the singles and removed once by the pairs — net one. An element in all three is counted 33, removed 33, added 11 — again net one. Pigeonhole: if every one of kk boxes held fewer than n/k\lceil n/k\rceil, the total would fall short of nn.

Tip. Alternate the signs by set size: odd-sized intersections add, even-sized subtract.