human
What is a the Python code you requested given the following:
Balph is learning to play a game called Buma. In this game, he is given a row of colored balls. He has to choose the color of one new ball and the place to insert it (between two balls, or to the left of all the balls, or to the right of all the balls).

When the ball is inserted the following happens repeatedly: if some segment of balls of the same color became longer as a result of a previous action and its length became at least 3, then all the balls of this segment are eliminated. 

Consider, for example, a row of balls 'AAABBBWWBB'. Suppose Balph chooses a ball of color 'W' and the place to insert it after the sixth ball, i. e. to the left of the two 'W's. After Balph inserts this ball, the balls of color 'W' are eliminated, since this segment was made longer and has length 3 now, so the row becomes 'AAABBBBB'. The balls of color 'B' are eliminated now, because the segment of balls of color 'B' became longer and has length 5 now. Thus, the row becomes 'AAA'. However, none of the balls are eliminated now, because there is no elongated segment.

Help Balph count the number of possible ways to choose a color of a new ball and a place to insert it that leads to the elimination of all the balls.

Input

The only line contains a non-empty string of uppercase English letters of length at most 3 ⋅ 10^5. Each letter represents a ball with the corresponding color.

Output

Output the number of ways to choose a color and a position of a new ball in order to eliminate all the balls.

Examples

Input

BBWWBB

Output

3

Input

BWWB

Output

0

Input

BBWBB

Output

0

Input

OOOWWW

Output

0

Input

WWWOOOOOOWWW

Output

7
Using python3 can you solve the prior task?
assistant
#Here is the Python code you requested.

import os
import sys
from io import BytesIO, IOBase

def solution(s):
    n = len(s)
    l, r = 0, n - 1

    while True:
        if s[l] != s[r]:
            write(0)
            return

        ll = l
        while ll < n and s[ll] == s[l]:
            ll += 1

        rr = r
        while rr >= 0 and s[rr] == s[r]:
            rr -= 1

        if ll == l + 1 and rr == r - 1:
            write(0)
            return

        if ll > r:
            write(r - l + 2)
            return
        else:
            l, r = ll, rr

def main():
    s = input()
    solution(s)

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
       ...