  The main result of the present paper is about the solutions of the functional
equation \Eq{*}{ F\Big(\frac{x+y}2\Big)+f_1(x)+f_2(y)=G(g_1(x)+g_2(y)),\qquad
x,y\in I, } derived originally, in a natural way, from the invariance problem
of generalized weighted quasi-arithmetic means, where
$F,f_1,f_2,g_1,g_2:I\to\mathbb{R}$ and $G:g_1(I)+g_2(I)\to\mathbb{R}$ are the
unknown functions assumed to be continuously differentiable with $0\notin
g'_1(I)\cup g'_2(I)$, and the set $I$ stands for a nonempty open subinterval of
$\mathbb{R}$.
  In addition to these, we will also touch upon solutions not necessarily
regular. More precisely, we are going to solve the above equation assuming
first that $F$ is affine on $I$ and $g_1$ and $g_2$ are continuous functions
strictly monotone in the same sense, and secondly that $g_1$ and $g_2$ are
invertible affine functions with a common additive part.
