  Addressing a question of Cameron and Erd\Ho s, we show that, for infinitely
many values of $n$, the number of subsets of $\{1,2,\ldots, n\}$ that do not
contain a $k$-term arithmetic progression is at most $2^{O(r_k(n))}$, where
$r_k(n)$ is the maximum cardinality of a subset of $\{1,2,\ldots, n\}$ without
a $k$-term arithmetic progression. This bound is optimal up to a constant
factor in the exponent. For all values of $n$, we prove a weaker bound, which
is nevertheless sufficient to transfer the current best upper bound on $r_k(n)$
to the sparse random setting. To achieve these bounds, we establish a new
supersaturation result, which roughly states that sets of size $\Theta(r_k(n))$
contain superlinearly many $k$-term arithmetic progressions.
  For integers $r$ and $k$, Erd\Ho s asked whether there is a set of integers
$S$ with no $(k+1)$-term arithmetic progression, but such that any $r$-coloring
of $S$ yields a monochromatic $k$-term arithmetic progression. Ne\v{s}et\v{r}il
and R\"odl, and independently Spencer, answered this question affirmatively. We
show the following density version: for every $k\ge 3$ and $\delta>0$, there
exists a reasonably dense subset of primes $S$ with no $(k+1)$-term arithmetic
progression, yet every $U\subseteq S$ of size $|U|\ge\delta|S|$ contains a
$k$-term arithmetic progression.
  Our proof uses the hypergraph container method, which has proven to be a very
powerful tool in extremal combinatorics. The idea behind the container method
is to have a small certificate set to describe a large independent set. We give
two further applications in the appendix using this idea.
