Alisha has a string of length n. Each character is either 'a', 'b' or 'c'. She has to select two characters s[i] and s[j] such that s[i] != s[j] and i,j are valid indexes. She has to find the maximum value of the absolute difference between i and j i.e abs(i-j) .
Since Alisha is busy with her Semester exams help her find the maximum distance where distance is the maximum value of absolute difference between i and j  i.e abs(i-j) .

-----Input:-----
- The first and the only line contains the string s with each character either 'a', 'b', or 'c'. 

-----Output:-----
Print a single integer the maximum absolute difference between i and j. 

-----Constraints-----
- $1 \leq n \leq 10^5$
- s[i] can either be 'a', 'b' or 'c'.

-----Subtasks-----
- 40 points : $1 \leq n \leq 100$
- 60 points : $1 \leq n \leq 10^5$

-----Sample Input1:-----
aabcaaa

-----Sample Output1:-----
4

-----Sample Input2:-----
aba

-----Sample Output2:-----
1

Difficulty: UNKNOWN_DIFFICULTY

Solutions:
st = input().strip()
b = []
for i in range(len(st)):
	for j in range(i + 1, len(st)):
		if st[i] != st[j]:
			z = abs(i - j)
			b.append(z)
print(max(b))


s = input()
p1 = [i for i in range(len(s)) if s[i] == 'a']
p2 = [i for i in range(len(s)) if s[i] == 'b']
p3 = [i for i in range(len(s)) if s[i] == 'c']
xs = [abs(i - j) for i in p1 for j in p2]
ys = [abs(i - j) for i in p1 for j in p3]
zs = [abs(i - j) for i in p3 for j in p2]
rs = xs + ys + zs
print(max(rs))


try:
	s = input()
	l_a = []
	l_b = []
	l_c = []
	for i in range(len(s)):
		if s[i] == 'a':
			l_a.append(i)
	for i in range(len(s)):
		if s[i] == 'b':
			l_b.append(i)
	for i in range(len(s)):
		if s[i] == 'c':
			l_c.append(i)
	maxi = 0
	for i in l_a:
		for j in l_c:
			maxi = max(maxi, abs(i - j))
	for i in l_b:
		for j in l_c:
			maxi = max(maxi, abs(i - j))
	for i in l_a:
		for j in l_b:
			maxi = max(maxi, abs(i - j))
	print(maxi)
except:
	pass


s = str(input().strip())
d = {}
d['a'] = []
d['b'] = []
d['c'] = []
for i in range(len(s)):
	d[s[i]].append(i)
ans = [0]
try:
	ans.append(abs(d['a'][0] - d['b'][-1]))
	ans.append(abs(d['b'][0] - d['a'][-1]))
except:
	pass
try:
	ans.append(abs(d['a'][0] - d['c'][-1]))
	ans.append(abs(d['c'][0] - d['a'][-1]))
except:
	pass
try:
	ans.append(abs(d['c'][0] - d['b'][-1]))
	ans.append(abs(d['b'][0] - d['c'][-1]))
except:
	pass
print(max(ans))


s = input()
ln = len(s)
ai = 100000
bi = 100000
ci = 100000
bj = -100000
aj = -100000
cj = -1000000
for i in range(ln):
	if s[i] == 'a':
		if ai > i:
			ai = i
		if aj < i:
			aj = i
	if s[i] == 'b':
		if bi > i:
			bi = i
		if bj < i:
			bj = i
	if s[i] == 'c':
		if ci > i:
			ci = i
		if cj < i:
			cj = i
lst = [abs(ai - bj), abs(ai - cj), abs(bi - aj), abs(ci - aj), abs(bi - cj), abs(ci - bj)]
mxm = -1
for i in lst:
	if i < ln:
		if mxm < i:
			mxm = i
print(mxm)


string = input().strip()
(letter_first_position, letter_last_position) = ({}, {})
for (position, letter) in enumerate(string):
	if letter not in letter_first_position:
		letter_first_position[letter] = position
	letter_last_position[letter] = position
maximum_distance = max((abs(first_position - last_position) for (first_letter, first_position) in list(letter_first_position.items()) for (last_letter, last_position) in list(letter_last_position.items()) if first_letter != last_letter))
print(maximum_distance)


a = input()
a1 = 'abc'
lower = []
upper = []
for i in range(len(a1)):
	for j in range(len(a)):
		if a1[i] == a[j]:
			lower.append(j)
			break
for i in range(len(a1)):
	for j in range(len(a)):
		if a1[i] == a[j]:
			t = j
	upper.append(t)
ans = 1
for i in range(len(lower)):
	for j in range(len(lower)):
		if i != j:
			ans = max(abs(upper[j] - lower[i]), ans)
print(ans)


l = input()
a = []
b = []
c = []
j = 0
while j < len(l):
	if l[j] == 'a':
		a.append(j)
	if l[j] == 'b':
		b.append(j)
	if l[j] == 'c':
		c.append(j)
	j += 1
a.sort()
b.sort()
c.sort()
if len(a) != 0 and len(b) != 0 and (len(c) != 0):
	d = min(a[0], b[0], c[0])
	e = max(a[-1], b[-1], c[-1])
elif len(a) != 0 and len(b) != 0:
	d = min(a[0], b[0])
	e = max(a[-1], b[-1])
elif len(a) != 0 and len(c) != 0:
	d = min(a[0], c[0])
	e = max(a[-1], c[-1])
elif len(b) != 0 and len(c) != 0:
	d = min(b[0], c[0])
	e = max(b[-1], c[-1])
if e in a and d in a:
	if len(b) != 0 and len(c) != 0:
		d = min(b[0], c[0])
	elif len(b) != 0:
		d = b[0]
	else:
		d = c[0]
elif e in b and d in b:
	if len(a) != 0 and len(b) != 0:
		d = min(a[0], b[0])
	elif len(a) != 0:
		d = a[0]
	else:
		d = c[0]
elif e in c and d in c:
	if len(a) != 0 and len(b) != 0:
		d = min(a[0], b[0])
	elif len(a) != 0:
		d = a[0]
	else:
		d = b[0]
print(abs(d - e))


s = input()
n = len(s)
la = []
lb = []
lc = []
if len(set(s)) == 1:
	print('0')
elif 'a' and 'b' and ('c' in s):
	for i in range(n):
		if s[i] == 'a':
			la.append(i)
		elif s[i] == 'b':
			lb.append(i)
		elif s[i] == 'c':
			lc.append(i)
	(a1, a0) = (max(la), min(la))
	(b1, b0) = (max(lb), min(lb))
	(c1, c0) = (max(lc), min(lc))
	print(max(abs(a0 - b1), abs(a0 - c1), abs(a1 - b0), abs(a1 - c0), abs(b0 - c1), abs(b1 - c0)))
else:
	r = list(set(s))
	for i in range(n):
		if s[i] == r[0]:
			la.append(i)
		elif s[i] == r[1]:
			lb.append(i)
	(a1, a0) = (max(la), min(la))
	(b1, b0) = (max(lb), min(lb))
	print(max(abs(a0 - b1), abs(a1 - b0)))


word = input().strip()
max_val = 0
for i in range(len(word) - 1):
	for j in range(i + 1, len(word)):
		if word[i] != word[j] and abs(i - j) > max_val:
			max_val = abs(i - j)
print(max_val)


str = input()
m = 0
for i in ['a', 'b', 'c']:
	if str.find(i) != -1:
		for j in ['a', 'b', 'c']:
			if i != j and str.find(j) != -1:
				m = max(m, str.rindex(j) - str.find(i))
print(m)


s = input().strip()
d = 0
cur = 0
for i in range(len(s) - 1):
	for j in range(i + 1, len(s)):
		if s[i] != s[j]:
			cur = j - i
	d = max(d, cur)
print(d)


def __starting_point():
	s = input()
	(sa, ea, sb, eb, sc, ec) = (0, 0, 0, 0, 0, 0)
	for i in range(len(s)):
		if s[i] == 'a':
			if sa == 0:
				(sa, ea) = (i + 1, i + 1)
			else:
				ea = i + 1
		if s[i] == 'b':
			if sb == 0:
				(sb, eb) = (i + 1, i + 1)
			else:
				eb = i + 1
		if s[i] == 'c':
			if sc == 0:
				(sc, ec) = (i + 1, i + 1)
			else:
				ec = i + 1
	max_diff = 0
	if sa != 0:
		if sb != 0:
			max_diff = max(max_diff, abs(eb - sa), abs(ea - sb))
		if sc != 0:
			max_diff = max(max_diff, abs(ec - sa), abs(ea - sc))
	if sb != 0:
		if sc != 0:
			max_diff = max(max_diff, abs(ec - sb), abs(eb - sc))
	print(max_diff)
__starting_point()