Jordi Gali Markup Marginal Cost Relation Jordi Gali defined price, marginal cost and mark up relationship as 



Drago Bergholt tried to reach gali's representation from firm maximization problem.

I think that there is error in derivation.

Can you help me correcting derivation process and obtaining gali's representation ?



Now, is there any derivation error below (last part) ?



is this part ?



Here, in the left side need to be "-" negative  ?



Continue....



Nt and Nit are different?
The problem is the maximization of profit of a firm that produces a differentiated good $i$ using labor $N_i$ as unique input, under the demand function of the consumers (or final goods producers) and the production function.

The first three steps are computed by substituting the two constraints and the market clearing condition for goods market $Y_t=C_t$ into the objective function in order to have a free maximization problem in one unknown, $P_{it}$.

The FOC for $P_{it}$ is right and the same is true for the next step, where the left hand side is positive because he has divided for $-(1-\epsilon)$, i.e. $(\epsilon-1)$ that you see at the denominator of $\epsilon$. The highlighted part is correct too: this is the derivative of the function nested in the square brackets; he added $\frac{1}{P_t}$ because he kept $\frac{P_{it}}{P_t}$ all elevated at $-\epsilon-1$, this means that $P_t^{-1}$ and $P_t$ goes away. You could also have written
\begin{gather}
\epsilon\frac{\frac{P_{it}^{-\epsilon-1}}{P_t^{-\epsilon}}C_t}{A_t}=\epsilon\frac{\big(\frac{P_{it}}{P_t}\big)^{-\epsilon-1}C_t}{A_t}\frac{1}{P_t}
\end{gather}

After the "Continue...", he just sum the two expressions in square brackets because they are exponentials with the same base and in the second step he notice that 
\begin{gather}
\bigg[\frac{\frac{P_{it}}{P_t}^{-\epsilon}C_t}{A_t}\bigg]^{\frac{1}{1-\alpha}}=N_t
\end{gather}
using again the demand for $Y_{it}$, $Y_t=C_t$ and the production function. 

The last step is a rearrangement of the previous one (simple algebra) and it is still the FOC for $P_{it}$. If you rearrange it as in Gali, you obtain the optimal pricing condition for the monopolistic firm in flexible price setting.