Given a linear equation of the form a1x1 + a2x2 + a3x3 = 0 with integer coefficients ai, we are interested in maximising the number of solutions to this equation in a set S ⊆ Z, for sets S of a given size.We prove that, for any choice of constants a1, a2 and a3, the maximum number of solutions is at least ( 1 12 + o(1))|S| 2 . Furthermore, we show that this is optimal, in the following sense. For any ε > 0, there are choices of a1, a2 and a3, for which any large set S of integers has at most ( 1 12 + ε)|S| 2 solutions. For equations in k 3 variables, we also show an analogous result. Set σ k = ∞ −∞ ( sin πx πx ) k dx. Then, for any choice of constants a1, . . . , a k , there are sets S with at least ( σ k k k−1 + o(1))|S| k−1 solutions to a1x1 + · · · + a k x k = 0. Moreover, there are choices of coefficients a1, . . . , a k for which any large set S must have no more than ( σ k k k−1 + ε)|S| k−1 solutions, for any ε > 0.