Approximating CSPs on expanding structures, and applications to codes