  Let $\Omega \subset \mathbb{R}^n$, for $n \geq 2$, be a bounded $C^2$ domain.
Let $q \in L^1_{loc} (\Omega)$ with $q \geq 0$. We give necessary conditions
and matching sufficient conditions, which differ only in the constants
involved, for the existence of very weak solutions to the boundary value
problem $(-\triangle -q) u =0, \, \, u\ge 0 \, \, \text{on} \, \, \Omega, \,
u=1 \, \text{on} \, \, \partial \Omega$, and the related nonlinear problem with
quadratic growth in the gradient, $-\triangle u = |\nabla u|^2 + q \, \text{on}
\, \Omega, \, u=0 \, \, \text{on} \, \, \partial \Omega$. We also obtain
precise pointwise estimates of solutions up to the boundary.
  A crucial role is played by a new "boundary condition" on $q$ which is
expressed in terms of the exponential integrability on $\partial \Omega$ of the
balayage of the measure $\delta q \, dx$, where $\delta (x) = \text{dist} (x,
\partial \Omega)$. This condition is sharp, and appears in such a context for
the first time. It holds, for example, if $\delta q \, dx$ is a Carleson
measure in $\Omega$, or if its balayage is in $BMO(\partial \Omega)$, with
sufficiently small norm. This solves an open problem posed in the literature.
