Nonconvex functionals related to multiphase systems