from enum import Enum, auto def accum_dp(xs: list, f, op, e, init: dict): dp = init.copy() for x in xs: pp = {} dp, pp = pp, dp for fm_key, fm_val in pp.items(): for to_key, to_val in f(fm_key, fm_val, x): dp[to_key] = op(dp.get(to_key, e), to_val) return dp class E(Enum): S = auto() C = auto() W1 = auto() W2 = auto() def f(k, v, x): yield k, v+1 match (k, x): case (E.S, 'c'): yield E.C, 1 case (E.C, 'w'): yield E.W1, v+1 case (E.W1, 'w'): yield E.W2, v+1 case (E.W2, _): # goal yield E.W2, v INF = 1 << 62 S = input() init = {E.S: 0} dp = accum_dp(S, f, min, INF, init) ans = INF for st, v in dp.items(): if st == E.W2: ans = min(ans, v) if ans == INF: print(-1) else: print(ans)