Latex how to write symbol average: \overline

Latex how to write symbol average: \overline

$\overline{X}$
\[\overline{X}\]

Examples

$$\overline{X}$$

$$\overline{X_n}$$

$$\overline{XY}$$

$$\overline{x}=\frac{1}{n} \sum_{i=1}^{n} x_{i}=\frac{1}{n}\left(x_{1}+\cdots+x_{n}\right)$$
\[\overline{X}\] \[\overline{X_n}\] \[\overline{XY}\] \[\overline{x}=\frac{1}{n} \sum_{i=1}^{n} x_{i}=\frac{1}{n}\left(x_{1}+\cdots+x_{n}\right)\]