Fermion masses and cosmology in multidimensional unified theories