Let $A$ be a finite set and let $\Bbb P$ be a probability measure on $A^{\Bbb N_0}$. Further, let $x_i:A^{\Bbb N_0}\to A$ be projection maps, so that $(x_i)_{i=0}^\infty$ can be treated as a stochastic process. Suppose that for some integer number $m\geq 1$ the measure $\Bbb P$ satisfies the following condition: $$ (x_i,\dots,x_{i+m})_*\Bbb P = (x_0,\dots,x_m)_*\Bbb P\quad \forall i\in \Bbb N,\tag{1} $$ that is any sequence of the length $m+1$ has equal probability of appearance anywhere along the trajectory of the process. For example, $\Bbb P$ is shift-invariant (stationary) if and only if it satisfies $(1)$ for any choice of $m$. In my case, the number $m$ is fixed though, so $\Bbb P$ does not have to be a stationary measure.
Let us denote $\Bbb P^m := (x_0,\dots,x_m)_*\Bbb P$ to be a measure on $A^{m+1}$, and let $F:A^{m+1}\to\Bbb R$ be some arbitrary function. Suppose, I need to maximize $$ \Bbb P^m[F]:=\sum_{s\in A^{m+1}}F(s)\cdot\Bbb P^m(\{s\}) \tag{2}. $$ where the optimization is done over all possible measures $\Bbb P$ that satisfy $(1)$. Have such problem been already studied, perhaps the solution is already known?
For a finite sequence $Y= (y_0,\dots,y_m)$ let $\left <Y\right>\subset A^{m+1}$ be the set of sequences $$\left<Y\right> = \{ (y_i, y_{i+1 \mod (m+1)}, \dots y_{i+1 \mod (m+1)}) : 0 \leq i \leq m \}$$ be the set of shifts of $Y$.
Now let $$\mathscr F = \left\{\left<Y\right> : Y\in A^{m+1}\right\}$$ be the shift invariant $\sigma$-algebra on $A^{m+1}$. As $\mathscr F$ is a partition $\sigma$-algebra we have $$\mathbb P^m\left[F \left| \mathscr F\right.\right](Y) = \frac 1{m+1} \sum_{\hat Y\in\left<Y\right>} F(\hat Y).$$
Therefore if $\bar Y$ is such that $\sum_{\hat Y\in\left<\bar Y\right>} F(\hat Y)\geq\sum_{\hat Y\in\left< Y\right>} F(\hat Y)$ for every $Y\in A^{m+1}$ we have
$$\begin{array}{rl} \mathbb P^m\left[F \right] &= \int_{A^{m+1}} \mathbb P^m\left[F \left| \mathscr F\right.\right](X) d \mathbb P^m(X) \\ &\leq \int_{A^{m+1}} \mathbb P^m\left[F \left| \mathscr F\right.\right](\bar Y) d \mathbb P^m(X) \\ &=\frac 1{m+1}\sum_{\hat Y\in\left<\bar Y\right>} F(\hat Y) \end{array}$$
So set $\mathbb P$ to be the measure constructed by choosing $(x_0,\dots,x_m)$ uniformly from $\left<\bar Y\right>$ and setting $x_k = x_{k \mod (m+1)}$ for $k> m$ then $\mathbb P$ is shift invariant by construction and $$\mathbb P^m\left[F \right] =\frac 1{m+1}\sum_{\hat Y\in\left<\bar Y\right>} F(\hat Y)$$ attains its maximal value.