Given a string, determine if it can be represented as the concatenation of several centrally symmetric substrings.
Formally, a string SSS is centrally symmetric if and only if it satisfies one of the following conditions:
-
SSS is an empty string.
-
S=o∣s∣x∣zS = o|s|x|zS=o∣s∣x∣z, i.e., SSS is one of the four letters: o, s, x and z.
-
S=bSq∣dSp∣pSd∣qSb∣nSu∣uSn∣oSo∣sSs∣xSx∣zSzS = bSq|dSp|pSd|qSb|nSu|uSn|oSo|sSs|xSx|zSzS=bSq∣dSp∣pSd∣qSb∣nSu∣uSn∣oSo∣sSs∣xSx∣zSz, i.e., SSS starts and ends with a pair of centrally symmetric letters, and the middle part is also a centrally symmetric substring.
A string SSS is considered good if and only if there exists an integer n≥1n \geq 1n≥1 such that S=T1T2⋯TnS = T_1T_2 \cdots T_nS=T1T2⋯Tn, where TiT_iTi (1≤i≤n1 \le i \le n1≤i≤n) is a centrally symmetric substring.
Given a string
SSS, determine whether it is a good string.