  For every algebraically closed field and natural number $r$, we construct an
algebraic variety (over the field) whose birational automorphism group contains
every finite nilpotent group of class at most $2$ whose rank is at most $r$ and
whose order is coprime to the characteristic of the field. This construction is
sharp in characteristic $0$, i.e. up to bounded extension, the set of groups
from the statement cannot be replaced by a larger one.
  Using similar main steps, for every $r$, we construct several compact
manifolds whose diffeomorphism groups contain every finite nilpotent group of
class at most $2$ whose rank is at most $r$. This result answers a question of
Mundet i Riera affirmatively and is conjecturally sharp up to bounded
extension.
