The incircle of a scalene triangle $ABC$ touches the sides $BC, CA$, and $AB$ at points $D, E$, and $F$, respectively. Triangles $APE$ and $AQF$ are constructed outside the triangle so that \[AP =PE, AQ=QF, \angle APE=\angle ACB,\text{ and }\angle AQF =\angle ABC.\]Let $M$ be the midpoint of $BC$. Find $\angle QMP$ in terms of the angles of the triangle $ABC$.

[i]Iran, Shayan Talaei[/i]

1. **Identify the given conditions and setup:**
   - The incircle of triangle \(ABC\) touches sides \(BC\), \(CA\), and \(AB\) at points \(D\), \(E\), and \(F\) respectively.
   - Triangles \(APE\) and \(AQF\) are constructed outside triangle \(ABC\) such that:
     \[
     AP = PE, \quad AQ = QF, \quad \angle APE = \angle ACB, \quad \text{and} \quad \angle AQF = \angle ABC.
     \]
   - \(M\) is the midpoint of \(BC\).

2. **Establish concurrency and cyclic quadrilaterals:**
   - By the problem conditions, \(QF\), \(PE\), and \(BC\) are concurrent at \(D\).
   - Quadrilaterals \(AQBD\) and \(APCD\) are cyclic because:
     \[
     \angle AQB = \angle ABC \quad \text{and} \quad \angle APD = \angle ACB.
     \]

3. **Define intersection points and cyclic properties:**
   - Let \(EF \cap BC = G\).
   - Let \(EF\) intersect the circumcircle of \(\triangle ABC\) at points \(X\) and \(Y\) such that the points are in the order \(G, X, F, E, Y\).

4. **Apply cross-ratio and cyclic properties:**
   - The cross-ratio \((-1) = (G, D; B, C)\) implies that:
     \[
     GX \cdot GY = GB \cdot GC = GD \cdot GM.
     \]
   - This shows that \(DXYM\) is cyclic.

5. **Use Power of a Point (PoP):**
   - By PoP, we have:
     \[
     QF \cdot FD = AF \cdot FB = XF \cdot FY \quad \text{and} \quad PF \cdot FB = AF \cdot FC = XF \cdot FY.
     \]
   - This implies that \(QXDMYP\) is cyclic.

6. **Determine the angle \(\angle QMP\):**
   - Since \(DXYM\) is cyclic, we have:
     \[
     \angle QMP = \angle FDE.
     \]
   - Given that \(\angle FDE = 90^\circ - \frac{\angle BAC}{2}\), we conclude:
     \[
     \angle QMP = 90^\circ - \frac{\angle BAC}{2}.
     \]

The final answer is \(\boxed{90^\circ - \frac{\angle BAC}{2}}\).