Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside.

The text is a string $s$ of lowercase Latin letters. She considers a string $t$ as hidden in string $s$ if $t$ exists as a subsequence of $s$ whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices $1$, $3$, and $5$, which form an arithmetic progression with a common difference of $2$. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of $S$ are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!

For example, in the string aaabb, a is hidden $3$ times, b is hidden $2$ times, ab is hidden $6$ times, aa is hidden $3$ times, bb is hidden $1$ time, aab is hidden $2$ times, aaa is hidden $1$ time, abb is hidden $1$ time, aaab is hidden $1$ time, aabb is hidden $1$ time, and aaabb is hidden $1$ time. The number of occurrences of the secret message is $6$.


-----Input-----

The first line contains a string $s$ of lowercase Latin letters ($1 \le |s| \le 10^5$) — the text that Bessie intercepted.


-----Output-----

Output a single integer  — the number of occurrences of the secret message.


-----Examples-----
Input
aaabb

Output
6

Input
usaco

Output
1

Input
lol

Output
2



-----Note-----

In the first example, these are all the hidden strings and their indice sets:   a occurs at $(1)$, $(2)$, $(3)$  b occurs at $(4)$, $(5)$  ab occurs at $(1,4)$, $(1,5)$, $(2,4)$, $(2,5)$, $(3,4)$, $(3,5)$  aa occurs at $(1,2)$, $(1,3)$, $(2,3)$  bb occurs at $(4,5)$  aab occurs at $(1,3,5)$, $(2,3,4)$  aaa occurs at $(1,2,3)$  abb occurs at $(3,4,5)$  aaab occurs at $(1,2,3,4)$  aabb occurs at $(2,3,4,5)$  aaabb occurs at $(1,2,3,4,5)$  Note that all the sets of indices are arithmetic progressions.

In the second example, no hidden string occurs more than once.

In the third example, the hidden string is the letter l.

Source: codeforces | Difficulty: MEDIUM
Tags: Dynamic programming

Complete search

Mathematics

String algorithms


Solutions:
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(input())

def read_int_n():
	return list(map(int, input().split()))

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

def read_str():
	return input().strip()

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(S):
	ans = 0
	ci = defaultdict(list)
	for (i, c) in enumerate(S):
		ci[c].append(i)
	for v in ci.values():
		ans = max(ans, len(v))
	cs = list(ci.keys())
	for (a, b) in product(cs, repeat=2):
		t = 0
		for i in ci[a]:
			t += len(ci[b]) - bisect.bisect_right(ci[b], i)
		ans = max(ans, t)
	return ans

def main():
	S = read_str()
	print(slv(S))
main()


from collections import Counter

def main():
	s = input().strip()
	(cnt1, cnt2) = (Counter({'a': 0}), Counter({'aa': 0}))
	for c in s:
		for (k, v) in cnt1.items():
			cnt2[k + c] += v
		cnt1[c] += 1
	result = max(max(cnt1.values()), max(cnt2.values()))
	print(result)
main()


s = str(input())
alpha = [0] * 26
patt = [[0 for i in range(26)] for j in range(26)]
for i in range(len(s)):
	temp = ord(s[i]) - ord('a')
	for j in range(26):
		patt[j][temp] += alpha[j]
	alpha[temp] += 1
ans = 0
for i in alpha:
	ans = max(i, ans)
for i in range(26):
	for k in range(26):
		ans = max(ans, patt[i][k])
print(ans)


s = input()
dicti = {}
for i in range(ord('a'), ord('z') + 1):
	for j in range(i, ord('z') + 1):
		dicti[chr(i) + chr(j)] = 0
dp2 = [[0 for i in range(26)] for i in range(26)]
dp1 = [0 for i in range(26)]
for i in range(len(s)):
	for j in range(26):
		dp2[j][ord(s[i]) - ord('a')] += dp1[j]
	dp1[ord(s[i]) - ord('a')] += 1
maxi = 0
for i in dp2:
	maxi = max(max(i), maxi)
print(max(max(dp1), maxi))


(a, b) = ({}, {})
for x in input():
	for y in a:
		b[x, y] = b.get((x, y), 0) + a.get(y, 0)
	a[x] = a.get(x, 0) + 1
print(max(0, 0, *a.values(), *b.values()))


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def most_common(lst):
	return max(set(lst), key=lst.count)

def nCr(n, r):
	return math.factorial(n) / (math.factorial(r) * math.factorial(n - r))
t = 1
for tt in range(t):
	a = insr()
	s = list(a)
	n = len(a)
	b = list(a)
	c = list(b)
	c.reverse()
	s = list(set(a))
	s.sort()
	ss = []
	freq = [[0] * 26 for i in range(26)]
	dp = [[0] * n for i in range(26)]
	for i in range(len(dp)):
		c = 0
		for j in range(len(a)):
			if a[j] == chr(97 + i):
				c = c + 1
			dp[i][j] = c
	qwqw = 0
	for i in range(len(a) - 1, 0, -1):
		for j in range(len(dp)):
			freq[ord(a[i]) - 97][j] += dp[j][i - 1]
	for j in range(len(freq)):
		qwqw = max(qwqw, max(freq[j]))
	q = 0
	for i in range(len(ss)):
		q = max(count(a, ss[i]), q)
	qw = most_common(b)
	qq = b.count(qw)
	if qq == 1:
		print(1)
		sys.exit()
	print(max(int(qwqw), qq))


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
import collections as cc
import itertools as it
if 1:
	s = input()
	ans = 0
	arr = [[0] * 26 for i in range(26)]
	si = [0] * 26
	for i in s:
		k = ord(i) - ord('a')
		for j in range(26):
			arr[j][k] += si[j]
			ans = max(ans, arr[j][k], si[k])
		si[k] += 1
	print(max(ans, max(si)))


s = input()
t = [0] * 702
for a in s:
	a = ord(a) - 97
	for b in range(26):
		t[26 + b * 26 + a] += t[b]
	t[a] += 1
print(max(t))


s = input()
arr1 = [0] * 26
arr2 = [[0] * 26 for i in range(26)]
for i in range(len(s)):
	c = ord(s[i]) - ord('a')
	for j in range(26):
		arr2[j][c] += arr1[j]
	arr1[c] += 1
ans = 0
for i in range(26):
	ans = max(ans, arr1[i])
for i in range(26):
	for j in range(26):
		ans = max(ans, arr2[i][j])
print(ans)


s = str(input())
num = [0] * 30
a = [[0 for x in range(26)] for y in range(26)]
res = 0
for i in range(0, len(s)):
	val = ord(s[i]) - ord('a')
	for j in range(26):
		a[j][val] += num[j]
	num[val] += 1
for i in range(26):
	for j in range(26):
		res = max(res, a[i][j])
res = max(res, max(num))
print(int(res))


def msg_len(s):
	cnt_chars = {}
	cnts = {}
	for c1 in s:
		cnt_chars[c1] = cnt_chars.get(c1, 0) + 1
	max_single = max(cnt_chars.values())
	for c in s:
		cnt_chars[c] -= 1
		for (c2, cnt) in cnt_chars.items():
			cnts[c + c2] = cnts.get(c + c2, 0) + cnt
	return max(max_single, sorted(cnts.values())[-1])
print(msg_len(input()))
test_data = [('aaabb', 6), ('usaco', 1), ('lol', 2), ('qdpinbmcrfwxpdbfgozvvocemjructoadewegtvbvbfwwrpgyeaxgddrwvlqnygwmwhmrhaizpyxvgaflrsvzhhzrouvpxrkxfza', 37)]


s = input()
pref = [[0] * len(s) for _ in range(26)]
pref[ord(s[0]) - ord('a')][0] += 1
ans = [0] * (26 * 26)
cnt = [0] * 26
cnt[ord(s[0]) - ord('a')] += 1
for i in range(1, len(s)):
	code = ord(s[i]) - ord('a')
	cnt[code] += 1
	for c in range(26):
		ans[c * 26 + code] += pref[c][i - 1]
		pref[c][i] = pref[c][i - 1]
	pref[code][i] += 1
print(max(max(cnt), max(ans)))


import sys
input = sys.stdin.readline
s = input()
vals = {}
for l in s:
	if l in vals:
		vals[l] = vals[l] + 1
	elif l != '\n':
		vals[l] = 1
nums = []
max1 = 1
for g in vals:
	if vals[g] > max1:
		max1 = vals[g]
for j in vals:
	if vals[j] > 1:
		nums.append(j)
ans = max1
for o in nums:
	for j in nums:
		count = 0
		mult = 0
		for sad in s:
			if sad == j:
				count = count + mult
			if sad == o:
				mult = mult + 1
		if count > ans:
			ans = count
print(ans)


s = input()
se = set()
d = {}
d2 = {}
for i in range(len(s)):
	se.add(s[i])
	if s[i] not in d:
		d[s[i]] = {0: -1}
		d2[s[i]] = 0
	d2[s[i]] += 1
	d[s[i]][d2[s[i]]] = i
se = list(se)
ans = 1
for i in range(len(se)):
	for j in range(len(se)):
		a = se[i]
		b = se[j]
		ta = 0
		if a == b:
			ta = (d2[a] - 1) * d2[a] // 2
		else:
			for i2 in d[a].values():
				if i2 >= 0:
					lb = 0
					ub = len(d[b]) - 1
					while lb + 1 < ub:
						tt = (ub + lb) // 2
						tc = (ub - lb) // 2
						if d[b][tt] >= i2:
							ub -= tc
						else:
							lb += tc
					tt = (ub + lb) // 2
					for z in range(2):
						if tt < len(d[b]) - 1 and d[b][tt + 1] < i2:
							tt += 1
						elif tt > 0 and d[b][tt] > i2:
							tt -= 1
					ta += d2[b] - tt
		ans = max(ta, ans)
dm = max(d2.values())
print(max(ans, dm))


single = {}
double = {}
string = input()
for i in string:
	for j in single:
		x = j + i
		double[x] = double.get(x, 0) + single[j]
	single[i] = single.get(i, 0) + 1
max1 = -float('Inf')
for i in double:
	max1 = max(double[i], max1)
for i in single:
	max1 = max(single[i], max1)
print(max1)


s = str(input())
d = {'': 1}
d2 = {}
for i in range(len(s)):
	for (k, v) in d.items():
		temp = k + s[i]
		if temp not in d2:
			d2[temp] = v
		else:
			d2[temp] += v
	if s[i] not in d:
		d[s[i]] = 1
	else:
		d[s[i]] += 1
print(max(d2.values()))


import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest

def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def sortListWithIndex(listOfTuples, idx):
	return sorted(listOfTuples, key=lambda x: x[idx])

def sortDictWithVal(passedDic):
	temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1]
	toret = {}
	for tup in temp:
		toret[tup[0]] = tup[1]
	return toret

def sortDictWithKey(passedDic):
	return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
s = input()
len1 = [0] * 26
len2 = list2d(26, 26, 0)
for ch in s:
	for j in range(26):
		len2[j][ord(ch) - 97] += len1[j]
	len1[ord(ch) - 97] += 1
ans = max(len1)
for i in range(26):
	for j in range(26):
		ans = max(ans, len2[i][j])
print(ans)


import math

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	s = input()
	if len(s) == 1:
		print(1)
		return
	t = {}
	mx = 0
	alph = ''
	last = False
	gh = [1]
	gh_index = 0
	for i in s:
		if i in t:
			t[i] += 1
			if t[i] > mx:
				mx = t[i]
		else:
			t[i] = 1
			alph += i
		if last:
			if last == i:
				gh[gh_index] += 1
			else:
				gh_index += 1
				gh.append(1)
		last = i
	res = {}
	t2 = {}
	for i in s:
		if i in t2:
			t2[i] += 1
		else:
			t2[i] = 1
		for j in alph:
			k = str(i + j)
			if k not in res:
				res[k] = 0
			res[k] += t[j] - (t2[j] if j in t2 else 0)
	if len(res.values()) == 0:
		r = 0
		for i in range(1, mx):
			r += i
		print(r)
		return
	r = 0
	for i in range(1, max(gh)):
		r += i
	print(max(max(res.values()), mx, r))
query_count = 1
while query_count:
	query_count -= 1
	solve()


import string
a = input()
n = len(a)
c = [[0] * 26 for i in range(n)]
for i in range(n - 1, -1, -1):
	if i < n - 1:
		for j in range(26):
			c[i][j] = c[i + 1][j]
	c[i][ord(a[i]) - ord('a')] += 1
ans = 0
for ch in string.ascii_lowercase:
	cnt = a.count(ch)
	ans = max(ans, cnt)
dic = dict()
for i in range(n - 1):
	for j in range(26):
		ch = chr(j + ord('a'))
		word = a[i] + ch
		if word in dic:
			dic[word] += c[i + 1][j]
		else:
			dic[word] = c[i + 1][j]
if dic:
	ans = max(ans, max(dic.values()))
print(ans)


s = input()
a = [0] * 26
b = [[0] * 26 for i in range(26)]
for i in range(len(s)):
	c = ord(s[i]) - 97
	for j in range(26):
		b[j][c] += a[j]
	a[c] += 1
ans = 0
for i in range(26):
	ans = max(ans, a[i])
for i in range(26):
	for j in range(26):
		ans = max(ans, b[i][j])
print(ans)


(one, two) = ({}, {})
for c in input():
	for pc in one.keys():
		if pc + c in two:
			two[pc + c] += one[pc]
		else:
			two[pc + c] = one[pc]
	one[c] = one[c] + 1 if c in one else 1
print(max(max(two.values(), default=0), max(one.values(), default=0)))


s = input()
n = len(s)
dp = [[0 for i in range(26)] for j in range(n)]
table = [[0 for i in range(26)] for j in range(26)]
dp[n - 1][ord(s[n - 1]) - ord('a')] = 1
for i in range(n - 2, -1, -1):
	for j in range(26):
		dp[i][j] = dp[i + 1][j]
		table[ord(s[i]) - ord('a')][j] = table[ord(s[i]) - ord('a')][j] + dp[i][j]
	dp[i][ord(s[i]) - ord('a')] = dp[i][ord(s[i]) - ord('a')] + 1
m = 0
for i in range(26):
	m = max(m, max(table[i]))
d = {}
for i in s:
	if i not in d:
		d[i] = 1
	else:
		d[i] = d[i] + 1
for i in d:
	m = max(m, d[i])
print(m)


from collections import Counter
s = input().strip()
cnt = [0] * 26
rel = list()
for i in range(26):
	rel.append([0] * 26)
for si in s:
	cr = ord(si) - ord('a')
	for i in range(26):
		rel[i][cr] += cnt[i]
	cnt[cr] += 1
ans = 0
for i in range(26):
	ans = max(ans, cnt[i])
	for j in range(26):
		ans = max(ans, rel[i][j])
print(ans)


s = input()
arr1 = [0] * 26
arr2 = [[0 for k in range(26)] for i in range(26)]
for i in s:
	c = ord(i) - ord('a')
	for j in range(26):
		arr2[j][c] += arr1[j]
	arr1[c] += 1
maxi = 0
for i in arr1:
	maxi = max(maxi, i)
for i in arr2:
	maxi = max(maxi, max(i))
print(maxi)


s = input()
ar1 = [0] * 26
ar2 = [[0 for i in range(26)] for j in range(26)]
for i in range(len(s)):
	ch = ord(s[i]) - 97
	if i >= 1:
		for j in range(26):
			ar2[j][ch] += ar1[j]
	ar1[ch] += 1
m = max(ar1)
for t in range(26):
	m = max(m, max(ar2[t]))
print(m)


from collections import defaultdict
x = input()
mp = defaultdict(int)
norm_mp = defaultdict(int)
dp = []
for el in x:
	mp[el] += 1
	norm_mp[el] += 1
for i in range(len(x) - 1):
	mp[x[i]] -= 1
	for el in mp:
		norm_mp[f'{x[i]}{el}'] += mp[el]
print(sorted(norm_mp.items(), key=lambda item: item[1])[-1][-1])


s = input()
n = len(s)
d = {}
letters = 'abcdefghijklmnopqrstuvwxyz'
letters_len = len(letters)
letter_idx = {}
for i in range(len(letters)):
	letter_idx[letters[i]] = i
suffix = [] * n
for i in range(n):
	suffix.append([0] * letters_len)
for j in range(letters_len):
	suffix[n - 1][j] = 0
for i in range(n - 2, -1, -1):
	cur = s[i + 1]
	for j in range(letters_len):
		suffix[i][j] = suffix[i + 1][j]
	suffix[i][letter_idx[cur]] += 1
for i in range(n):
	sub = s[i]
	if sub in d:
		d[sub] += 1
	else:
		d[sub] = 1
	for j in letters:
		sub = s[i] + j
		if sub in d:
			d[sub] += suffix[i][letter_idx[j]]
		else:
			d[sub] = suffix[i][letter_idx[j]]
ans = 0
for v in d.values():
	ans = max(ans, v)
print(ans)


s = str(input())
cml = [[0 for i in range(len(s) + 1)] for j in range(26)]
c = 1
for i in s:
	k = ord(i) - ord('a')
	cml[k][c] = cml[k][c - 1] + 1
	for j in range(26):
		if j != k:
			cml[j][c] = cml[j][c - 1]
	c += 1
ab = [[0 for i in range(26)] for j in range(26)]
c = 1
for k in s:
	i = ord(k) - ord('a')
	for j in range(26):
		ab[i][j] += cml[j][-1] - cml[j][c]
	c += 1
ans = 0
res = 0
for i in range(26):
	res = max(res, cml[i][-1])
	for j in range(26):
		ans = max(ans, ab[i][j])
print(max(ans, res))


from sys import *
from math import *
from bisect import *
s = input()
m = []
ans = 0
for i in range(26):
	m.append([])
for i in range(len(s)):
	o = ord(s[i]) - 97
	m[o].append(i)
for i in range(26):
	for j in range(26):
		t = 0
		n = len(m[j])
		for k in m[i]:
			l = bisect_right(m[j], k)
			if l > n:
				l = n
			t += n - l
		ans = max(ans, t)
for i in range(26):
	if len(m[i]) > ans:
		ans = len(m[i])
print(ans)


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
import string

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
s = input()
res = dd()
c = dd()
for i in s:
	for j in c:
		res[f'{j}{i}'] += c[j]
	c[i] += 1
val = list(res.values())
val.append(0)
print(max(max(val), max(c.values())))


from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
import os
import sys
from io import BytesIO, IOBase
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')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def main():
	ar1 = [0] * 26
	ar2 = [[0] * 26 for _ in range(26)]
	oda = ord('a')
	sa = [ord(i) - oda for i in input()]
	for i in sa:
		for j in range(26):
			ar2[j][i] += ar1[j]
		ar1[i] += 1
	print(max(max(ar1), max([j for i in ar2 for j in i])))
main()


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 0 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
a = [[0 for i in range(26)] for i in range(26)]
val = [0] * 26
for i in S():
	v = ord(i) - 97
	for j in range(26):
		a[j][v] += val[j]
	val[v] += 1
print(max(max([max(i) for i in a]), max(val)))


s = list(input())
lis = [0] * 26
ans = [0] * (26 * 26)
for i in s:
	aa = ord(i) - ord('a')
	for j in range(26):
		code = j * 26 + aa
		ans[code] += lis[j]
	lis[aa] += 1
print(max(ans + lis))


s = input()
dict = {}
array = [0] * 26
for i in range(26):
	array[i] = [0] * 26
maxi1 = 0
for i in s:
	if i in dict:
		for j in dict:
			array[ord(j) - 97][ord(i) - 97] += dict[j]
		dict[i] += 1
	else:
		for j in dict:
			array[ord(j) - 97][ord(i) - 97] += dict[j]
		dict[i] = 1
for i in range(26):
	for j in range(26):
		maxi1 = max(maxi1, array[i][j])
maxi2 = max(dict.values())
print(max(maxi1, maxi2))


s = input()
count = [0] * 26
for i in s:
	count[ord(i) - 97] += 1
ans = max(count)
for i in range(26):
	letter = chr(i + 97)
	l = [0] * 26
	cnt = 0
	for k in s:
		if k == letter:
			cnt += 1
		else:
			l[ord(k) - 97] += cnt
	ans = max(ans, max(l))
for num in count:
	ans = max(ans, num * (num - 1) // 2)
print(ans)


from math import *

def binarySearch(arr, x, i):
	l = i
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def js(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] <= x:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def jg(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= x:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans

def ceil(a, b):
	if a % b == 0:
		return int(a / b)
	else:
		return a // b + 1
s = input()
h = [0] * 26
s = s[::-1]
dp = []
for i in range(26):
	dp.append([0] * 26)
for i in range(len(s)):
	h[ord(s[i]) - 97] += 1
	for j in range(26):
		if j != ord(s[i]) - 97:
			dp[ord(s[i]) - 97][j] += h[j]
		else:
			dp[ord(s[i]) - 97][j] = h[ord(s[i]) - 97]
			if h[ord(s[i]) - 97] > 3:
				dp[ord(s[i]) - 97][j] = h[ord(s[i]) - 97] * (h[ord(s[i]) - 97] - 1) // 2
ans = 1
for i in range(26):
	ans = max(ans, max(dp[i]))
print(ans)


def find_best_pair(string):
	l = list(set(string))
	if len(string) == 1:
		return 1
	max_occurrences = 0
	for i in l:
		for j in l:
			max_occurrences = max(max_occurrences, occurrences(string, (i, j)))
		max_occurrences = max(max_occurrences, _occurrences(string, i))
	return max_occurrences

def occurrences(string, pair):
	count = 0
	total = 0
	for letter in string:
		if letter == pair[0]:
			count += 1
		elif letter == pair[1]:
			total += count
	return total

def _occurrences(string, char):
	count = 0
	for letter in string:
		if letter == char:
			count += 1
	if count in (1, 2):
		return count
	return (count - 1) * count // 2
s = input()
print(find_best_pair(s))


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	z = []
	for i in range(26):
		for j in range(26):
			a = [chr(i + 97), chr(j + 97)]
			z.append(a)
	z = tuple(map(tuple, z))
	for _ in range(1):
		s = rs()
		d = Counter(s)
		f = max(d.values())
		ans = f
		for curr in z:
			a = curr[0]
			b = curr[1]
			if a not in d or b not in d:
				continue
			t = 0
			na = 0
			count = 0
			for i in range(len(s)):
				if s[i] == b:
					count += na
				if s[i] == a:
					na += 1
			ans = max(ans, count)
		print(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


s = input()
c = [0] * 26
cc = [[0] * 26 for _ in range(26)]
a = ord('a')
for _ in range(len(s)):
	c[ord(s[_]) - a] += 1
m = max(c)
for _ in range(len(s)):
	c[ord(s[_]) - a] -= 1
	for i in range(26):
		cc[ord(s[_]) - a][i] += c[i]
		m = max(cc[ord(s[_]) - a][i], m)
print(m)


from collections import defaultdict

def getIndex(a):
	return ord(a) - 97
s = input()
d = defaultdict(int)
dp = [[0 for i in range(26)] for i in range(26)]
alphabet = 'abcdefghijklmnopqrstuvwxyz'
for i in s:
	for char in alphabet:
		dp[getIndex(char)][getIndex(i)] += d[char]
	d[i] += 1
ans = max(d.values())
for i in dp:
	ans = max(ans, max(i))
print(ans)


s = input()
n = len(s)
count1 = [0 for _ in range(26)]
count2 = [[0 for _ in range(26)] for _ in range(26)]
for i in range(n):
	curr = ord(s[i]) - 97
	for j in range(26):
		count2[j][curr] += count1[j]
	count1[curr] += 1
ans = 0
for i in range(26):
	ans = max(ans, count1[i])
	for j in range(26):
		ans = max(ans, count2[i][j])
print(ans)


def nCr(n, r):
	(f, m) = (factorial, 1)
	for i in range(n, n - r, -1):
		m *= i
	return int(m // f(r))
from math import factorial
from collections import *
(s, cum, cum1, a, ans) = (input(), defaultdict(list), defaultdict(lambda : [0]), ord('a'), 0)
for (i, j) in enumerate(s):
	cum[j].append(i)
	for k in range(26):
		if j == chr(a + k):
			cum1[j].append(cum1[j][-1] + 1)
		else:
			cum1[chr(a + k)].append(cum1[chr(a + k)][-1])
if len(set(s)) == 1:
	print(max(nCr(len(s), 2), len(s)))
else:
	for i in range(26):
		for j in range(26):
			(ch1, ch2, tem) = (chr(a + i), chr(a + j), 0)
			if i == j:
				ans = max(ans, cum1[ch1][-1], nCr(cum1[ch1][-1], 2))
				continue
			for k in cum[ch1]:
				tem += cum1[ch2][-1] - cum1[ch2][k]
			ans = max(ans, tem)
	print(ans)


s = input()
cnt = [0] * 702
for i in range(len(s)):
	x = ord(s[i]) - 97
	for j in range(26):
		cnt[26 + 26 * j + x] += cnt[j]
	cnt[x] += 1
print(max(cnt))


alphabet = 'abcdefghijklmnopqrstuvwxyz'
n = input()
r = [0 for i in range(26)]
s = [[0 for i in range(26)] for j in range(26)]
if len(n) == 1:
	print(1)
else:
	for i in range(len(n)):
		t = alphabet.index(n[i])
		for j in range(26):
			s[t][j] += r[j]
		r[t] += 1
	l = [max(s[i]) for i in range(26)]
	print(max(max(r), max(l)))


import sys
from bisect import *
from collections import *
input = sys.stdin.readline
gb = [0 for i in range(26)]
ct = [[0 for i in range(26)] for j in range(26)]
dic = {chr(97 + i): i for i in range(26)}
a = input()
s = 0
a = a.rstrip('\n')
l = len(a)
for i in range(l):
	for j in range(26):
		ct[j][dic[a[i]]] += gb[j]
	gb[dic[a[i]]] += 1
for i in ct:
	for j in i:
		s = max(s, j)
for i in gb:
	s = max(s, i)
print(s)


def solve(s):
	count = [0] * 26
	count_pair = [[0] * 26 for _ in range(26)]
	res = -float('INF')
	for i in s:
		a = ord(i) - ord('a')
		for j in range(26):
			if count[j] == 0:
				continue
			count_pair[j][a] += count[j]
			res = max(count_pair[j][a], res)
		count[a] += 1
		res = max(res, count[a])
	print(res)

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


s = input()
s = list(s)
count1 = [0 for i in range(26)]
count2 = [[0 for i in range(26)] for j in range(26)]
for i in range(len(s)):
	c = ord(s[i]) - ord('a')
	for j in range(0, 26):
		count2[j][c] += count1[j]
	count1[c] += 1
maxe1 = max(count1)
maxe2 = maxe1
for i in range(26):
	for j in range(26):
		maxe2 = max(maxe2, count2[i][j])
print(maxe2)


a = [0] * 5 ** 6
for x in map(ord, input()):
	for y in range(123):
		a[123 * x + y] += a[y]
	a[x] += 1
print(max(a))


import sys
input = lambda : sys.stdin.readline().rstrip()
ans = [0] * 26
a = [ord(i) - 97 for i in input()]
cnt = [0] * 26
maxx = [0] * 26
ans = [0] * 26
for i in a:
	cnt[i] += 1
for i in range(len(ans)):
	z = cnt[i] * (cnt[i] + 1) // 2 - cnt[i]
	for j in range(len(a) - 1, -1, -1):
		if a[j] == i:
			ans[a[j]] += 1
			cnt[i] -= 1
		else:
			ans[a[j]] += cnt[i]
	maxx[i] = max(max(ans), z)
	ans = [0] * 26
print(max(maxx))


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
from collections import defaultdict
from bisect import bisect_left
s = inp()
n = len(s)
d = defaultdict(list)
for i in range(n):
	d[s[i]].append(i)
ans = 0
for key in d.keys():
	ans = max(ans, len(d[key]))
for k1 in d.keys():
	for k2 in d.keys():
		c = 0
		for idx in d[k1]:
			c += bisect_left(d[k2], idx)
		ans = max(ans, c)
print(ans)


from sys import exit

def iis():
	return map(int, input().split())

def ii():
	return int(input())

def liis():
	return list(map(int, input().split()))
s = input()
todos = {}
for i in range(len(s)):
	if s[i] not in todos:
		todos[s[i]] = 0
	todos[s[i]] += 1
ans = 1
maxi1 = 1
maxi2 = 1
maxi1c = s[0]
for k in todos:
	if todos[k] > maxi1:
		maxi1 = todos[k]
		maxi1c = k

def ans(s, c, d, n):
	at = 0
	ret = 0
	for i in s:
		if i == d:
			ret += at
		if i == c:
			at += 1
	return ret
a = []
answ = 0
for i in todos:
	a.append([todos[i], i])
	answ = max(answ, todos[i])
for i in range(len(a)):
	for j in range(len(a)):
		answ = max(answ, ans(s, a[i][1], a[j][1], a[j][0]))
print(answ)


st = input()
x = 'abcdefghijklmnopqrstuvwxyz'
dic = {}
for i in x:
	dic[i] = 0
main = {}
for i in x:
	for j in x:
		main[i + j] = 0
for xx in st:
	for jj in dic:
		main[jj + xx] += dic[jj]
	dic[xx] += 1
x1 = max(list(main.values()))
x2 = max(list(dic.values()))
print(max(x1, x2))


from collections import defaultdict as dd
s = input()
l = []
dc = dd(int)
cc = ord('a')
ccc = cc
d = dd(int)
for i in range(26):
	ll = [0]
	c = chr(cc + i)
	for i in range(len(s)):
		if s[i] == c:
			ll.append(ll[-1] + 1)
		else:
			ll.append(ll[-1])
	l.append(ll)
n = len(s)
for i in range(len(s)):
	c = s[i]
	dc[s[i]] += 1
	cc = ord(s[i])
	for j in range(26):
		d[s[i], chr(ccc + j)] += l[j][n] - l[j][i + 1]
mx = -1
for i in d:
	if d[i] > mx:
		mx = d[i]
for i in dc:
	mx = max(mx, dc[i])
print(mx)


s = input()
instant_count = {}
dict = {}
a = set(s)
a = ''.join(a)
for q in a:
	instant_count[q] = 0
for i in s:
	for j in a:
		x = j + i
		if x not in dict:
			dict[x] = instant_count[j]
		else:
			dict[x] += instant_count[j]
	instant_count[i] += 1
print(max(max(instant_count.values()), max(dict.values())))


def ii():
	return int(input())

def ai():
	return list(map(int, input().split()))

def mi():
	return map(int, input().split())
s = input()
freq = [0 for i in range(26)]
sub_string = [[0 for i in range(26)] for j in range(26)]
for i in range(len(s)):
	c = ord(s[i]) - 97
	for j in range(26):
		sub_string[j][c] += freq[j]
	freq[c] += 1
ans = max(freq)
for row in sub_string:
	ans = max(ans, max(row))
print(ans)


import math
d = {}
s = input()
l = list(s)
max1 = 0
arr = []
for i in range(0, 26):
	arr.append(0)
for i in range(0, len(s)):
	arr[ord(s[i]) - 97] += 1
	if max1 < arr[ord(s[i]) - 97]:
		max1 = arr[ord(s[i]) - 97]
count = 0
p = []
for i in range(1, 27):
	for j in range(1, 27):
		q = ''
		q = q + chr(96 + i) + chr(96 + j)
		p.append(q)
p = list(set(p))
for i in range(0, len(p)):
	count1 = 0
	ans = 0
	for j in s:
		if j == p[i][1]:
			ans += count1
		if j == p[i][0]:
			count1 += 1
	if max1 < ans:
		max1 = ans
print(max1)


d = {}
s = set()
for x in input():
	for y in s:
		d[x, y] = d.get((x, y), 0) + d[y]
	s |= {x}
	d[x] = d.get(x, 0) + 1
print(max(d.values()))
num_inp = lambda : int(input())
arr_inp = lambda : list(map(int, input().split()))
sp_inp = lambda : map(int, input().split())
str_inp = lambda : input()


import collections
s = str(input())
m = 1
d = collections.defaultdict(int)
v = collections.defaultdict(int)
ans = 0
for i in s:
	for j in range(26):
		d[chr(97 + j), i] += v[chr(97 + j)]
	v[i] += 1
	ans = max(ans, v[i])
for i in d:
	ans = max(ans, d[i])
print(ans)


from collections import defaultdict
s = input()
d = defaultdict(int)
for c in s:
	for a in range(97, 123):
		a = chr(a)
		d[a + c] += d[a]
	d[c] += 1
print(max(d.values()))


import math as mt
import bisect
import sys
import collections
import heapq
t = 1
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve():
	l = [0] * 27
	l2 = [[0 for j in range(27)] for i in range(27)]
	for i in range(len(s)):
		x = ord(s[i]) - ord('a')
		for j in range(27):
			l2[j][x] += l[j]
		l[x] += 1
	ans = max(l[:])
	for i in range(27):
		ans = max(max(l2[i]), ans)
	return ans
for _ in range(t):
	s = input()
	print(solve())


from collections import Counter
a = list(map(lambda c: ord(c) - 97, input()))
dp = [0] * 26
dp2 = Counter()
for c in a:
	for i in range(26):
		if i == c:
			continue
		dp2[i, c] += dp[i]
	dp[c] += 1
ans = max(max(dp), max(dp) * (max(dp) - 1) // 2, dp2.most_common(1)[0][1])
print(ans)


from collections import Counter
from math import inf
for i in range(1):
	s = input().strip()
	n = len(s)
	z = Counter(s)
	dp = [[0 for j in range(26)] for p in range(26)]
	x = [0 for j in range(26)]
	for j in s:
		if sum(x) == 0:
			x[ord(j) - 97] += 1
		else:
			for p in range(26):
				dp[ord(j) - 97][p] += x[p]
			x[ord(j) - 97] += 1
	m = -inf
	for p in range(26):
		for j in range(26):
			m = max(m, dp[p][j])
	print(max(m, max(z.values())))


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n').split(' ')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
s = st()
cnt = Counter(s)
ans = max(cnt.values())
curr = [0 for i in range(26)]
ansofchar = [[0 for i in range(26)] for j in range(26)]
for i in range(len(s) - 1, -1, -1):
	for j in 'abcdefghijklmnopqrstuvwxyz':
		ansofchar[ord(s[i]) - ord('a')][ord(j) - ord('a')] += curr[ord(j) - ord('a')]
	curr[ord(s[i]) - ord('a')] += 1
for i in ansofchar:
	ans = max(ans, max(i))
print(ans)


alph = 'abcdefghijklmnopqrstuvwxyz'

def to_arr(s):
	a = []
	for i in range(len(s)):
		a.append(alph.index(s[i]))
	return a
s = to_arr(input())
n = len(s)
a = [[0] * 26 for i in range(n)]
a[0][s[0]] = 1
ans = 0
for i in range(1, n):
	a[i][s[i]] = 1
	for j in range(26):
		a[i][j] += a[i - 1][j]
for i in range(26):
	ans = max(ans, a[-1][i])
b = [[0] * 26 for i in range(26)]
for i in range(1, n):
	for j in range(26):
		b[j][s[i]] += a[i - 1][j]
for i in range(26):
	for j in range(26):
		ans = max(ans, b[i][j])
print(ans)


from collections import defaultdict
s = list(input())
arr = [0 for j in range(26)]
index = defaultdict(int)
for j in range(len(s)):
	for k in range(26):
		v = chr(k + 97) + s[j]
		index[v] += arr[k]
	arr[ord(s[j]) - 97] += 1
maximum = max(arr)
for j in index:
	maximum = max(index[j], maximum)
print(maximum)


s = input()
n = len(s)
arr = [-1 for _ in range(n)]
for i in range(n):
	arr[i] = ord(s[i]) - ord('a')
ans = 0
cnt = [0 for _ in range(26)]
for i in range(n):
	cnt[arr[i]] += 1
ans = max(cnt)
cntPrev = [0 for _ in range(26)]
cnt2 = [[0 for _ in range(26)] for __ in range(26)]
for i in range(n):
	for j in range(26):
		cnt2[j][arr[i]] += cntPrev[j]
	cntPrev[arr[i]] += 1
for i in range(26):
	for j in range(26):
		ans = max(ans, cnt2[i][j])
print(ans)


import sys, os, io
from collections import defaultdict
input = sys.stdin.readline
s = input().strip()
s = [ord(i) - 97 for i in s]
a = [1]
b = [s[0]]
for i in range(1, len(s)):
	if s[i] == s[i - 1]:
		a[-1] += 1
	else:
		a.append(1)
		b.append(s[i])
dp = [[0] * 26 for i in range(26)]
cnt = [0] * 26
for i in range(len(a)):
	for j in range(26):
		dp[j][b[i]] += cnt[j] * a[i]
	cnt[b[i]] += a[i]
m = max(cnt)
ans = max(m * (m - 1) // 2, m)
for i in dp:
	ans = max(ans, max(i))
print(ans)


arr = list(input())
n = len(arr)
sufmax = []
for i in range(26):
	sufmax.append([0] * n)
sums = [0] * 26
for g in range(n - 1, -1, -1):
	sums[ord(arr[g]) - 97] += 1
	for i in range(26):
		sufmax[i][g] = sums[i]
ams = []
for i in range(26):
	ams.append([0] * 26)
for i in range(n - 1):
	for g in range(26):
		ams[ord(arr[i]) - 97][g] += sufmax[g][i + 1]
m = 0
for i in range(26):
	m = max(m, max(ams[i]))
c = [0] * 26
for i in range(n):
	c[ord(arr[i]) - 97] += 1
print(max(m, max(c)))


from collections import defaultdict
import string

def max_code(s):
	count = defaultdict(int)
	code = defaultdict(int)
	for c in s:
		for past in list(string.ascii_lowercase):
			code[past + c] += count[past]
		count[c] += 1
	return max(max(code.values()), max(count.values()))
s = input()
print(max_code(s))


import math, collections

def insr():
	return input()[:]

def inlt():
	return list(map(lambda x: int(x), input()))

def inp():
	return int(input())

def invr():
	return map(int, input().split())
str = insr()
count1 = [0] * 26
count2 = [[0] * 26 for i in range(26)]
for i in range(len(str)):
	e = ord(str[i]) - ord('a')
	for j in range(26):
		count2[j][e] += count1[j]
	count1[e] += 1
print(max(max(count1), max(map(max, count2))))


import math

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	s = input()
	s_dict = {}
	s_dict2 = {}
	res = {}
	alp = []
	for i in s:
		if i not in s_dict:
			alp.append(i)
			s_dict2[i] = 0
			s_dict[i] = 0
			res[i] = {}
		s_dict[i] += 1
	ans = max(s_dict.values())
	for i in s:
		for j in alp:
			if i not in res[j]:
				res[j][i] = 0
			res[j][i] += s_dict2[j]
		s_dict2[i] += 1
	for i in alp:
		for j in alp:
			ans = max(ans, res[i][j])
	print(ans)
query_count = 1
while query_count:
	query_count -= 1
	solve()


s = input()
arr1 = []
arr2 = []
for i in range(26):
	lst = []
	for j in range(26):
		lst.append(0)
	arr2.append(lst)
	arr1.append(0)
for ch in s:
	ind = ord(ch) - ord('a')
	for j in range(26):
		arr2[j][ind] += arr1[j]
	arr1[ind] += 1
ans = 0
for i in range(26):
	ans = max(ans, arr1[i])
for i in range(26):
	for j in range(26):
		ans = max(ans, arr2[i][j])
print(ans)


s = input()
letters = 'abcdefghijklmnopqrstuvwxyz'
mx = 0
for c in letters:
	mx = max(mx, s.count(c))
freq = {}
for let in letters:
	freq[let] = 0
dp = {}
for c1 in letters:
	for c2 in letters:
		dp[c1, c2] = 0
for c in s:
	for let in letters:
		dp[c, let] += freq[let]
	freq[c] += 1
for c1 in letters:
	for c2 in letters:
		mx = max(mx, dp[c1, c2])
print(mx)


def solve(s):
	A = 26
	ans = -float('INF')
	count = [0] * A
	count_pair = [[0] * A for _ in range(A)]
	for i in s:
		c = ord(i) - ord('a')
		for j in range(A):
			if count[j] != 0:
				count_pair[j][c] += count[j]
				ans = max(ans, count_pair[j][c])
		count[c] += 1
		ans = max(ans, count[c])
	print(ans)

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


from bisect import *
d = {}
i = 0
for c in input():
	l = d.setdefault(c, [])
	l += (i,)
	i += 1
m = len(max(d.values(), key=len))
print(max(m, m * (m - 1) // 2, *(sum((bisect(d[y], i) for i in d[x])) for x in d for y in d if y != x)))


def main():
	s = input()
	countFor1Letters = [0] * 26
	countFor2Letters = [[0 for x in range(26)] for j in range(26)]
	for i in range(len(s)):
		ind_i = ord(s[i]) - ord('a')
		for j in range(26):
			countFor2Letters[j][ind_i] += countFor1Letters[j]
		countFor1Letters[ind_i] += 1
	ans = 0
	for i in countFor2Letters:
		if max(i) > ans:
			ans = max(i)
	print(max(max(countFor1Letters), ans))
main()


import sys

def fast_input():
	return sys.stdin.readline().strip()

def data_input():
	return [int(x) for x in fast_input().split()]

def binary_search(array, x):
	(left, right) = (-1, len(array))
	while left + 1 != right:
		middle = (left + right) // 2
		if array[middle] >= x:
			right = middle
		elif array[middle] < x:
			left = middle
	return right

def solve_of_problem():
	alp = {}
	alp_2 = {}
	for i in range(26):
		alp[chr(i + 97)] = 0
	for i in range(26):
		for j in range(26):
			alp_2[chr(i + 97) + chr(j + 97)] = 0
	st = fast_input()
	for i in range(len(st)):
		for j in range(26):
			alp_2[chr(97 + j) + st[i]] += alp[chr(97 + j)]
		alp[st[i]] += 1
	print(max(max(alp.values()), max(alp_2.values())))
	return
for ______ in range(1):
	solve_of_problem()


d = {}
s = {0}
for x in input():
	for y in s:
		d[x, y] = d.get((x, y), 0) + d.get(y, 0)
	s |= {x}
	d[x] = d.get(x, 0) + 1
print(max(d.values()))


from collections import defaultdict
s = input()
foo = defaultdict(int)
char = [0] * 27
for i in s:
	for j in range(len(char)):
		foo[chr(j + 97), i] += char[j]
	char[ord(i) - 97] += 1
str_ = []
for j in foo:
	str_.append(foo[j])
print(max(max(char), max(str_)))


dp = {}
for c in input():
	num = ord(c) - ord('a') + 1
	for prev in range(1, 27):
		if prev in dp:
			dp[prev * 26 + num] = dp.get(prev * 26 + num, 0) + dp.get(prev)
	dp[num] = dp.get(num, 0) + 1
print(max(dp.values()))


s = list(input())
list1 = [0] * 26
list2 = list()
for i in range(26):
	p = [0] * 26
	list2.append(p)
for i in range(len(s)):
	t = ord(s[i]) - ord('a')
	for j in range(26):
		list2[j][t] += list1[j]
	list1[t] += 1
ans1 = 0
for i in range(26):
	ans1 = max(ans1, list1[i])
for i in range(26):
	for j in range(26):
		ans1 = max(ans1, list2[i][j])
print(ans1)


s = input()
n = len(s)
co = [0] * 26
dp = [[0 for _ in range(26)] for _ in range(26)]
for i in s:
	r = ord(i) - ord('a')
	for j in range(26):
		dp[r][j] += co[j]
	co[r] += 1
ans = 0
for i in range(26):
	ans = max(ans, max(dp[i]))
print(max(max(co), ans))


s = str(input())
a = len(s)
matrix = [[0] * a for i in range(26)]
lis = [0] * 26
for i in range(a):
	for j in range(26):
		matrix[j][a - i - 1] = lis[j]
	lis[ord(s[a - i - 1]) - 97] += 1
matrix1 = [[0] * 26 for i in range(26)]
for i in range(a):
	for j in range(26):
		matrix1[ord(s[i]) - 97][j] += matrix[j][i]
ans = max(lis)
for i in range(26):
	temp = max(matrix1[i])
	ans = max(ans, temp)
print(ans)


s = input()
l = [0] * 702
for i in s:
	a = ord(i) - 97
	for j in range(26):
		l[26 + 26 * j + a] += l[j]
	l[a] += 1
print(max(l))


s = input()
mam = 0
for i in range(0, 26):
	ch = chr(i + 97)
	a = [0] * 26
	maxi = 0
	k = 0
	ma = 0
	for i in range(0, len(s)):
		if s[i] == ch:
			a[ord(s[i]) - 97] = a[ord(s[i]) - 97] + 1 * k
			k = k + 1
		elif k > 0:
			a[ord(s[i]) - 97] = a[ord(s[i]) - 97] + 1 * k
	maxi = max(a)
	ma = max(k, maxi)
	mam = max(ma, mam)
print(mam)


import sys

def upper_bound(arr, index):
	l = 0
	r = len(arr)
	while r - l > 1:
		mid = (r + l) // 2
		if arr[mid] == index:
			l = mid
			break
		if arr[mid] < index:
			l = mid
		else:
			r = mid
	while l < len(arr) and arr[l] <= index:
		l += 1
	return l

def cal(char, second_char, chars):
	if char == second_char:
		l = len(chars[char])
		return l * (l - 1) / 2
	sum = 0
	first_char_indices = chars[char]
	second_char_indices = chars[second_char]
	for indice in first_char_indices:
		upb = upper_bound(second_char_indices, indice)
		if upb < len(second_char_indices):
			sum += len(second_char_indices) - upb
	return sum

def solve():
	s = sys.stdin.readline().strip()
	chars = dict()
	n = len(s)
	mx = 0
	for (index, char) in enumerate(s):
		count = chars.get(char)
		if count == None:
			count = chars[char] = []
		count.append(index)
	for (char, indices) in chars.items():
		mx = max(mx, len(indices))
		for second_char in chars.keys():
			mx = max(mx, cal(char, second_char, chars))
	print(int(mx))
solve()


def binsearch(a, x):
	if len(a) == 0:
		return 0
	if len(a) == 1:
		if a[0] > x:
			return 1
		else:
			return 0
	i = 0
	j = len(a) - 1
	while i < j:
		if x < a[i]:
			return len(a) - i
		if x > a[j]:
			return len(a) - j - 1
		mid = int((i + j) / 2)
		if mid == i:
			return len(a) - i - 1
		if mid == j:
			return len(a) - j
		if x > a[mid]:
			i = mid
		else:
			j = mid
	return len(a) - 1 - i
s = input()
f = []
for i in range(26):
	f.append([])
for i in range(len(s)):
	f[ord(s[i]) - ord('a')].append(i)
ans = []
for i in range(26):
	tm = 0
	for j in range(26):
		tm = 0
		l = len(f[i])
		if i == j and l > 1:
			ans.append(int(l * (l - 1) / 2))
		elif len(f[j]) > 0 and len(f[i]) > 0:
			for k in f[j]:
				tm = tm + binsearch(f[i], k)
		if tm > 0:
			ans.append(tm)
	if len(f[i]) > 0:
		ans.append(len(f[i]))
ans.sort()
print(ans[-1])


from collections import Counter
inp = input()
s = set()
dp = {}
c = Counter()
n = len(s)
for x in inp:
	dp[x] = dp.get(x, 0) + 1
	for y in s:
		dp[x, y] = dp.get((x, y), 0) + c[y]
	s.add(x)
	c[x] += 1
print(max(dp.values()))


import os
import sys
from io import BytesIO, IOBase
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')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
s = set()
dp = {}
c = Counter()
n = len(s)
for x in input():
	dp[x] = dp.get(x, 0) + 1
	for y in s:
		dp[x, y] = dp.get((x, y), 0) + c[y]
	s.add(x)
	c[x] = c.get(x, 0) + 1
print(max(dp.values()))


from collections import Counter

def main():
	s = input()
	counter = Counter(s)
	counts = counter.most_common()
	if len(counts) == 1:
		print(max(counts[0][1], counts[0][1] * (counts[0][1] - 1) // 2))
	else:
		nums = [[0 for i in range(26)] for i in range(26)]
		total = [[0 for i in range(len(s) + 1)] for i in range(26)]
		for i in range(1, len(s) + 1):
			idx = ord(s[-i]) % 26
			for j in range(26):
				nums[idx][j] += total[j][i - 1]
				if j == idx:
					total[j][i] = total[j][i - 1] + 1
				else:
					total[j][i] = total[j][i - 1]
		max_num = 0
		for i in range(26):
			for j in range(26):
				max_num = max(max_num, nums[i][j])
		print(max(counts[0][1], counts[0][1] * (counts[0][1] - 1) // 2, max_num))
main()


import os
import heapq as hp
import sys, threading
import math as mt
import operator
from copy import copy
from collections import defaultdict, deque
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def pw(a, b):
	result = 1
	while b > 0:
		if b % 2 == 1:
			result *= a
		a *= a
		b //= 2
	return result

def inpt():
	return [int(k) for k in input().split()]

def main():
	s = input()
	ar = [0] * 26
	d = defaultdict(int)
	mx = 0
	for i in s:
		for j in range(26):
			v = chr(ord('a') + j) + i
			d[v] += ar[j]
			mx = max(mx, d[v])
		ar[ord(i) - ord('a')] += 1
		mx = max(mx, ar[ord(i) - ord('a')])
	print(mx)
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')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import Counter, defaultdict
s = input()
n = len(s)
mx = 0
d = defaultdict(int)
dd = defaultdict(int)
st = list(set(s))
for i in range(len(s)):
	for j in range(len(st)):
		p = s[i] + st[j]
		d[p] += dd[st[j]]
	dd[s[i]] += 1
for (i, j) in d.items():
	mx = max(mx, j)
for (i, j) in dd.items():
	mx = max(mx, j)
print(mx)


from collections import Counter
from collections import defaultdict
best = [[0 for i in range(256)] for j in range(256)]
cnt = [0] * 256
s = input()
n = len(s)
count = Counter(s)
cnt[ord(s[0])] = 1
ans = max(list(count.values()))
for i in range(1, n):
	i1 = ord(s[i])
	for j in range(ord('a'), ord('z') + 1):
		best[j][i1] += cnt[j]
		if best[j][i1] > ans:
			ans = best[j][i1]
	cnt[i1] += 1
print(ans)


def solve():
	s = input()
	l = len(s)
	li1 = []
	for i in range(30):
		ltemp = []
		for j in range(30):
			ltemp.append(0)
		li1.append(ltemp)
	li3 = []
	for i in range(30):
		li3.append(0)
	li3[ord(s[0]) - ord('a')] = 1
	for i in range(1, l):
		for j in range(26):
			li1[j][ord(s[i]) - ord('a')] += li3[j]
		li3[ord(s[i]) - ord('a')] += 1
	ans = max(li3)
	for i in range(30):
		for j in range(30):
			if li1[i][j] > ans:
				ans = li1[i][j]
	print(ans)
solve()


import os
from io import BytesIO, IOBase
import sys
from collections import Counter

def main():
	dp = [[0] * 26 for i in range(26)]
	a = [0] * 26
	s = input().rstrip()
	for j in s:
		z = ord(j) - 97
		for i in range(26):
			dp[i][z] += a[i]
		a[z] += 1
	ma = 0
	for i in dp:
		for j in i:
			ma = max(ma, j)
	for i in a:
		ma = max(ma, i)
	print(ma)
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')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


s = list(input())
n = len(s)
t = [[0 for i in range(26)] for i in range(26)]
o = [0 for i in range(26)]
ans = 0
for i in range(n):
	for j in range(26):
		t[j][ord(s[i]) - 97] += o[j]
	o[ord(s[i]) - 97] += 1
ans = max(ans, max(o))
for i in range(26):
	for j in range(26):
		ans = max(ans, t[i][j])
print(ans)


s = input()
cnt = [0 for _ in range(26)]
for i in s:
	cnt[ord(i) - ord('a')] += 1
ans = max(cnt)
cntt = [[0 for _ in range(26)] for _ in range(26)]
for i in s:
	cnt[ord(i) - ord('a')] -= 1
	for j in range(26):
		cntt[ord(i) - ord('a')][j] += cnt[j]
for i in range(26):
	for j in range(26):
		ans = max(ans, cntt[i][j])
print(ans)


a = input()
s_map = {x: 0 for x in 'abcdefghijklmnopqrstuvwxyz'}
another_map = {}
for i in range(0, len(a)):
	for x in s_map:
		if x + a[i] not in another_map:
			another_map[x + a[i]] = 0
		another_map[x + a[i]] += s_map[x]
	s_map[a[i]] += 1
print(max(list(another_map.items()) + list(s_map.items()), key=lambda x: x[1])[1])


import math
d = {}
s = input()
l = list(s)
l = set(l)
s1 = ''
for i in l:
	s1 = s1 + i
max1 = 0
for i in range(0, len(s1)):
	k = 0
	k = s.count(s1[i])
	d[s1[i]] = s.count(s1[i])
	if max1 < k:
		max1 = k
count = 0
p = []
for i in range(1, 27):
	for j in range(1, 27):
		q = ''
		q = q + chr(96 + i) + chr(96 + j)
		p.append(q)
p = list(set(p))
for i in range(0, len(p)):
	count1 = 0
	ans = 0
	for j in s:
		if j == p[i][1]:
			ans += count1
		if j == p[i][0]:
			count1 += 1
	if max1 < ans:
		max1 = ans
print(max1)


s = input()
alph = 'abcdefghijklmnopqrstuvwxyz'
m = 0
ans1 = max((s.count(x) for x in alph))
for i in alph:
	for j in alph:
		c = s.count(j)
		ans = 0
		for k in s:
			if k == j:
				c -= 1
			if k == i:
				ans += c
		ans1 = max(ans, ans1)
print(ans1)


import bisect, collections

def solution():
	s = input().strip()
	d_char = collections.defaultdict(int)
	d = collections.defaultdict(int)
	for x in s:
		for (c, val) in d_char.items():
			d[x + c] += val
		d_char[x] += 1
	print(max(max(d.values()) if d else 0, max(d_char.values())))

def main():
	for _ in range(1):
		solution()
main()


A = [ord(a) - 97 for a in input()]
N = len(A)
X = [0] * 26
Y = [[0] * 26 for _ in range(26)]
for a in A:
	for k in range(26):
		Y[k][a] += X[k]
	X[a] += 1
print(max([max(y) for y in Y] + X))


s = input()
dp2 = [[0] * 26 for i in range(26)]
dp1 = [0] * 26

def ind(c: str):
	return ord(c) - ord('a')
n = len(s)
ans = 0
for i in range(len(s)):
	ch = s[i]
	for j in range(26):
		dp2[j][ind(ch)] += dp1[j]
	dp1[ind(ch)] += 1
ans = max(dp1)
for i in dp2:
	for j in i:
		ans = max(ans, j)
print(ans)


import sys
input = sys.stdin.readline
from collections import defaultdict
from bisect import *
s = input()[:-1]
d = defaultdict(list)
for i in range(len(s)):
	d[s[i]].append(i)
alpha = 'abcdefghijklmnopqrstuvwxyz'
ans = 0
for i in range(26):
	ans = max(ans, len(d[alpha[i]]))
for i in range(26):
	for j in range(26):
		n = len(d[alpha[j]])
		ans_cand = 0
		for idx in d[alpha[i]]:
			ans_cand += n - bisect_right(d[alpha[j]], idx)
		ans = max(ans, ans_cand)
print(ans)


s = input()
co = [0] * 26
co2 = [0] * (26 * 26)
for a in s:
	a = ord(a) - ord('a')
	for b in range(26):
		r = a + 26 * b
		co2[r] += co[b]
	co[a] += 1
print(max(max(co), max(co2)))


s = input().strip()
alph = 'abcdefghijklmnopqrstuvwxyz'
mx = max((s.count(i) for i in alph))
for first in alph:
	for second in alph:
		count = 0
		sc = s.count(second)
		for i in s:
			if i == second:
				sc -= 1
			if i == first:
				count += sc
		mx = max(mx, count)
print(mx)


def checker(s):
	(dict, lst, max1) = ({}, [0] * 26, 0)
	for i in range(26):
		lst[i] = [0] * 26
	for i in s:
		if i in dict:
			for j in dict:
				lst[ord(j) - 97][ord(i) - 97] += dict[j]
			dict[i] += 1
		else:
			for j in dict:
				lst[ord(j) - 97][ord(i) - 97] += dict[j]
			dict[i] = 1
	for i in range(26):
		for j in range(26):
			max1 = max(max1, lst[i][j])
	max2 = max(dict.values())
	return max(max1, max2)
print(checker(input()))


import os
import sys

def main():
	s = input()
	dp = [[0] * 27 for i in range(27)]
	d = [0] * 27
	for i in range(len(s)):
		k = ord(s[i]) - 97
		for j in range(27):
			dp[k][j] += d[j]
		d[k] += 1
	ans = 0
	for i in range(27):
		for j in range(27):
			ans = max(ans, dp[i][j])
	for i in d:
		ans = max(ans, i)
	print(ans)
main()


C = [[0 for j in range(26)] for i in range(26)]
count = [0] * 26
S = input()
ans = 0
for i in S:
	pos = ord(i) - 97
	for j in range(26):
		C[pos][j] += count[j]
		ans = max(ans, C[pos][j])
	count[pos] += 1
	ans = max(ans, count[pos])
print(ans)


s = input()
ans = [0] * 26
for i in range(26):
	ans[i] = [0] * 26
now = [0] * 26
for i in range(len(s)):
	n = ord(s[i]) - ord('a')
	for j in range(26):
		ans[n][j] += now[j]
	now[n] += 1
anss = max(now)
for i in range(26):
	for j in range(26):
		anss = max(anss, ans[i][j])
print(anss)


s = input()
one_symbol = {}
for num in range(97, 123):
	one_symbol[chr(num)] = s.count(chr(num))
two_symbols = {(chr(i), chr(j)): 0 for i in range(97, 123) for j in range(97, 123)}
ans = 0
for pair in two_symbols:
	first = 0
	last = 0
	total = 0
	for sym in s:
		if sym == pair[0] == pair[1]:
			last += 1
			total += first
			first += 1
		elif sym == pair[0]:
			first += 1
		elif sym == pair[1]:
			last += 1
			total += first
	ans = total if ans < total else ans
for sym in one_symbol:
	ans = one_symbol[sym] if ans < one_symbol[sym] else ans
print(ans)


s = input()
dp1 = [0] * 26
dp2 = [[0] * 26 for _ in range(26)]
for i in range(len(s)):
	c = ord(s[i]) - ord('a')
	for j in range(26):
		dp2[j][c] += dp1[j]
	dp1[c] += 1
print(max(max(dp1), max(map(max, dp2))))


s = list(input())
s = [ord(i) - 97 for i in s]
co = [[0 for i in range(26)] for j in range(26)]
pre = [0 for i in range(26)]
pre[s[0]] = 1
for i in range(1, len(s)):
	for j in range(26):
		co[s[i]][j] += pre[j]
	pre[s[i]] += 1
print(max(max([max(i) for i in co]), max(pre)))


def log(substr, dct, count=1):
	if substr in dct.keys():
		dct[substr] += count
	else:
		dct[substr] = count
string = input()
strlen = len(string)
len1 = {}
len2 = {}
for (n, c) in enumerate(string):
	for (c1, count) in len1.items():
		word = c1 + c
		log(word, len2, count)
	log(c, len1)
candidates = list(len1.values()) + list(len2.values())
print(max(candidates))


s = input()
Single = [0] * 26
Double = [[0] * 26 for _ in range(26)]
for i in range(len(s)):
	c = ord(s[i]) - ord('a')
	for j in range(26):
		Double[j][c] += Single[j]
	Single[c] += 1
res = 0
for x in Single:
	res = max(res, x)
for x in Double:
	for y in x:
		res = max(res, y)
print(res)


def solve(s, a, b):
	cnt = 0
	res = 0
	for ch in s:
		if ch == b:
			res += cnt
		if ch == a:
			cnt += 1
	return res
s = input()
res = 0
for i in range(26):
	res = max(res, len([x for x in s if x == chr(i + 97)]))
	for j in range(26):
		res = max(res, solve(s, chr(97 + i), chr(97 + j)))
print(res)


str_ = input()
l = [[0] * 26 for i in range(26)]
freq = [0] * 26
for i in str_:
	for j in range(26):
		if freq[j] > 0:
			l[ord(i) - 97][j] += freq[j]
	freq[ord(i) - 97] += 1
result = max(freq)
for i in range(26):
	for j in range(26):
		result = max(result, l[i][j])
print(result)


a = [0] * 5 ** 6
s = (*map(ord, input()),)
t = {*s}
for x in s:
	for y in t:
		a[123 * x + y] += a[y]
	a[x] += 1
print(max(a))


from collections import defaultdict
from itertools import combinations
text = input()
unq = defaultdict(int)
for i in list(text):
	unq[i] += 1
best = max(unq.values())
if best == 1:
	print(1)
	exit(0)
best = max(best, best * (best - 1) // 2)
for (a, b) in combinations(unq.keys(), 2):
	(cnt_ab, cnt_ba) = (0, 0)
	(a_enc, b_enc) = (0, 0)
	for x in list(text):
		if x == a:
			a_enc += 1
			cnt_ba += b_enc
		elif x == b:
			b_enc += 1
			cnt_ab += a_enc
	best = max(best, cnt_ab, cnt_ba)
print(best)


s = list(input())
lis = {}
d = {}
a = 'abcdefghijklmnopqrstuvwxyz'
for i in a:
	lis[i] = 0
for i in s:
	for j in lis:
		aa = j + i
		if aa not in d:
			d[aa] = lis[j]
		else:
			d[aa] += lis[j]
	lis[i] += 1
print(max(max(d.values()), max(lis.values())))


s = input()
arr = [[0 for i in range(26)] for i in range(len(s) + 2)]
n = len(s)
for i in range(n):
	for j in range(26):
		arr[i + 1][j] = arr[i][j]
	arr[i + 1][ord(s[i]) - 97] += 1
ans = [[0 for i in range(26)] for j in range(26)]
oans = 0
for i in range(26):
	arr[n + 1][i] = arr[n][i]
	oans = max(oans, arr[n + 1][i])
for i in range(26):
	for j in range(26):
		for k in range(1, n):
			if chr(97 + i) != s[k - 1]:
				continue
			ans[i][j] += arr[n + 1][j] - arr[k][j]
fans = 1
for i in range(26):
	for j in range(26):
		fans = max(fans, ans[i][j])
print(max(fans, oans))


s = input()
d = {}
l = []
m = 1
for i in s:
	if i not in d:
		l.append(i)
		d[i] = 1
	else:
		d[i] += 1
		if d[i] > m:
			m = d[i]
ans = m
a = m * (m - 1)
a >>= 1
if a > ans:
	ans = a
for i in l:
	for j in l:
		if i != j:
			x = 0
			t = 0
			for k in s:
				if k == i:
					t += 1
				if k == j:
					x += t
			if x > ans:
				ans = x
print(ans)


from bisect import *
d = {}
i = 0
for c in input():
	l = d.setdefault(c, [])
	l += (i,)
	i += 1
print(max(*map(len, d.values()), *(sum((bisect_left(d[y], i) for i in d[x])) for x in d for y in d)))


s = input()
n = len(s)
alpha = [[0 for _ in range(26)] for _ in range(26)]
beta = [0 for _ in range(26)]
for i in range(n):
	tmp = ord(s[i]) - 97
	for d in range(26):
		alpha[d][tmp] += beta[d]
	beta[tmp] += 1
maxi = max(beta)
for d in range(26):
	maxi = max(maxi, max(alpha[d]))
print(maxi)


import os
import operator
import sys
from _collections import defaultdict
import bisect
from io import BytesIO, IOBase

def inar():
	return [int(k) for k in input().split()]

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def main():
	string = input()
	n = len(string)
	ans = []
	for i in range(26):
		lis = [0] * 26
		ans.append(lis)
	temp = [0] * 26
	result = 0
	for i in range(0, n):
		temp[ord(string[i]) - 97] += 1
	for i in range(26):
		result = max(result, temp[i])
	temp = [0] * 26
	temp[ord(string[0]) - 97] += 1
	for i in range(1, n):
		val = ord(string[i]) - 97
		for j in range(26):
			ans[val][j] += temp[j]
		temp[val] += 1
	for i in range(26):
		for j in range(26):
			result = max(result, ans[i][j])
	print(result)
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')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
import string
from collections import defaultdict as dd
alph = string.ascii_lowercase
arr = list(map(str, input().strip()))
d = dict()
for i in range(len(arr)):
	d[i] = dict()
	for j in alph:
		d[i][j] = 0
for i in range(len(arr) - 2, -1, -1):
	d[i][arr[i + 1]] = 1 + d[i + 1][arr[i + 1]]
	for j in alph:
		if j != arr[i + 1]:
			d[i][j] = d[i + 1][j]
co = dd(int)
for i in arr:
	co[i] += 1
for i in range(len(arr)):
	for j in alph:
		co[arr[i] + j] += d[i][j]
maxi = 0
for k in co:
	maxi = max(maxi, co[k])
print(maxi)


s = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
dic = {}
for i in range(26):
	dic[alp[i]] = i
lis = [0] * 26
ans = [[0] * 26 for i in range(26)]
maxi = 0
for i in s:
	num = dic[i]
	for i in range(26):
		ans[i][num] += lis[i]
		maxi = max(maxi, ans[i][num])
	lis[num] += 1
	maxi = max(maxi, lis[num])
print(maxi)


import string
from collections import OrderedDict
s = input()
alphabet = OrderedDict(zip(string.ascii_lowercase, range(1, 27)))
dict_1 = {}
dict_2 = {}
for j in alphabet.keys():
	dict_1[j] = 0
	dict_2[j] = {}
	for i in alphabet.keys():
		dict_2[j][i] = 0
for i in range(len(s)):
	for j in alphabet.keys():
		dict_2[j][s[i]] += dict_1[j]
	dict_1[s[i]] += 1
ans = 0
for i in dict_1.keys():
	ans = max(ans, dict_1[i])
for i in dict_2.keys():
	for j in dict_2[i].keys():
		ans = max(ans, dict_2[i][j])
print(ans)


from collections import Counter
s = input()
s_arr = [ord(i) - ord('a') for i in s]
matrix = [[0 for _ in range(26)] for _ in range(26)]
cnt = [0 for i in range(26)]
for k in range(len(s)):
	for i in range(26):
		matrix[i][s_arr[k]] += cnt[i]
	cnt[s_arr[k]] += 1
max_pair = max([max(i) for i in matrix])
max_single = Counter(s).most_common()[0][1]
print(max(max_pair, max_single))


from collections import defaultdict
import string
a = list(string.ascii_lowercase)
s = input()
d = defaultdict(int)
d2 = defaultdict(int)
for si in s:
	for ai in a:
		t = (ai, si)
		d2[t] += d[ai]
	d[si] += 1
ans = max(max(d.values()), max(d2.values()))
print(ans)


s = input()
dp = [[0] * 27 for i in range(27)]
d = [0] * 27
for i in range(len(s)):
	k = ord(s[i]) - 97
	for j in range(27):
		dp[k][j] += d[j]
	d[k] += 1
ans = 0
for i in range(27):
	for j in range(27):
		ans = max(ans, dp[i][j])
for i in d:
	ans = max(ans, i)
print(ans)


s = input()
a = [0] * 26
for x in s:
	a[ord(x) - 97] += 1
maxa = max(a)
ans = max((maxa - 1) * maxa // 2, maxa)
for i in range(97, 123):
	for j in range(97, 123):
		if j != i:
			ni = 0
			tans = 0
			for x in s:
				if ord(x) == i:
					ni += 1
				if ord(x) == j:
					tans += ni
			ans = max(ans, tans)
print(ans)


import sys

def metod1(z, a):
	l = -1
	r = len(clovar[a])
	while r > 1 + l:
		answer = (r + l) // 2
		if clovar[a][answer] <= z:
			l = answer
		else:
			r = answer
	return r

def metod(b, a):
	(x, h) = (0, 0)
	d = a == b
	l = len(clovar[a])
	for i in clovar[b]:
		z = metod1(i, a)
		h += z - d
		x += l - z
	return max(h, x)
for _mind_control in range(1):
	s = list(input())
	if len(s) == len(set(s)):
		print(1)
		break
	clovar = {}
	arr = list(set(s))
	answer = 0
	for i in range(len(s)):
		if s[i] in clovar:
			clovar[s[i]].append(i)
		else:
			clovar[s[i]] = [i]
	for i in range(len(arr)):
		for o in arr[i:]:
			if len(clovar[o]) * len(clovar[arr[i]]) > answer:
				answer = max(max(answer, metod(arr[i], o)), len(clovar[o]), len(clovar[arr[i]]))
	print(answer)


s = input()
sto = {}
z = [0] * 26
for i in range(len(s)):
	if s[i] not in sto:
		sto[s[i]] = 0
	sto[s[i]] += 1
	for j in range(0, 26):
		comb = chr(j + ord('a')) + s[i]
		if comb not in sto:
			sto[comb] = 0
		sto[comb] += z[j]
	z[ord(s[i]) - ord('a')] += 1
print(max(sto.values()))


s = input()
dp = [[0 for j in range(27)] for i in range(26)]
for i in s:
	curr = ord(i) - ord('a')
	for j in range(26):
		dp[j][curr] += dp[j][26]
	dp[curr][26] += 1
ans = 0
for i in dp:
	for j in i:
		ans = max(ans, j)
print(ans)


import sys
import bisect
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque
from collections import Counter as c
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(var)

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
s = data()
dp = dd(list)
k = c(s)
for i in range(len(s)):
	dp[s[i]].append(i)
for i in dp.keys():
	dp[i].sort()
exist = list(dp.keys())
arr = sorted(k.items(), key=lambda x: x[1])
temp = arr[len(arr) - 1][1]
answer = max(temp, temp * (temp - 1) // 2)
res = 0
for i in range(len(exist)):
	for j in range(len(exist)):
		res = 0
		for k in dp[exist[i]]:
			temp = br(dp[exist[j]], k)
			res += len(dp[exist[j]]) - temp
		answer = max(res, answer)
out(str(answer) + '\n')


def solve(s):
	count = [0] * 26
	count_pair = [[0] * 26 for _ in range(26)]
	ans = 1
	for c in s:
		i = ord(c) - ord('a')
		for j in range(26):
			count_pair[j][i] += count[j]
			ans = max(count_pair[j][i], ans)
		count[i] += 1
		ans = max(count[i], ans)
	print(ans)

def main():
	solve(input())
main()


from collections import defaultdict
dic = defaultdict(int)
dic2 = defaultdict(list)
sl = list(input())
for (idx, s) in enumerate(sl):
	dic[s] += 1
ans_dic = defaultdict(int)
k = sorted(dic.values())
if len(k) == 1:
	print(max(k[-1] * (k[-1] - 1) // 2, k[-1]))
else:
	ans1 = max(k[-1], k[-1] * (k[-1] - 1) // 2)
	for s in sl:
		dic[s] -= 1
		for d in dic:
			ans_dic[s + d] += dic[d]
	print(max(ans1, max(ans_dic.values())))


def main():
	s = input()
	cnt = [s.count(chr(ord('a') + i)) for i in range(26)]
	an = max(cnt)
	for i in range(26):
		lol = [0] * 26
		kek = cnt[:]
		for c in s:
			kek[ord(c) - ord('a')] -= 1
			if ord(c) - ord('a') == i:
				for j in range(26):
					lol[j] += kek[j]
		an = max(an, max(lol))
	print(an)
main()


from collections import Counter
s = input().strip()
cnt = Counter()
cnt2 = Counter()
for c in s:
	cnt[c] += 1
mx = max(cnt.values())
for c in s:
	cnt[c] -= 1
	for (d, v) in cnt.items():
		cnt2[c + d] += v
print(max(mx, max(cnt2.values())))


import sys
input = lambda : sys.stdin.readline().strip()
s = list(input())
if len(s) == len(set(s)):
	print(1)
	exit(0)
lol = {}
for i in range(len(s)):
	if s[i] in lol:
		lol[s[i]].append(i)
	else:
		lol[s[i]] = [i]
su = list(set(s))
m = 0

def bin(x, a):
	l = -1
	r = len(lol[a])
	while r - l > 1:
		m = (r + l) // 2
		if lol[a][m] <= x:
			l = m
		else:
			r = m
	return r

def f(b, a):
	ans = 0
	ans1 = 0
	d = int(a == b)
	l = len(lol[a])
	for i in lol[b]:
		x = bin(i, a)
		ans1 += x - d
		ans += l - x
	return max(ans1, ans)
for i in range(len(su)):
	for j in su[i:]:
		if len(lol[j]) * len(lol[su[i]]) > m:
			m = max(m, f(su[i], j), len(lol[j]), len(lol[su[i]]))
print(m)


s = input()
n = len(s)
el = [0 for i in range(27)]
elem = [[0 for j in range(27)] for t in range(27)]
for i in range(n):
	k = ord(s[i]) - 97
	for p in range(27):
		elem[k][p] += el[p]
	el[k] += 1
m = 0
for i in range(27):
	for j in range(27):
		m = max(m, elem[i][j])
m_anof = 0
for i in range(27):
	m_anof = max(m_anof, el[i])
print(max(m, m_anof))


s = input()
M = [0 for i in range(30)]
ans = 0
for i in s:
	M[ord(i) - ord('a')] += 1
for i in s:
	ans = max(ans, M[ord(i) - ord('a')])
for i in range(26):
	for j in range(26):
		if i != j:
			res = 0
			cnt = 0
			for str in s:
				if ord(str) - ord('a') == i:
					cnt += 1
				if ord(str) - ord('a') == j:
					res += cnt
			ans = max(ans, res)
		else:
			res = 0
			cnt = 0
			for str in s:
				if ord(str) - ord('a') == j:
					res += cnt
				if ord(str) - ord('a') == i:
					cnt += 1
			ans = max(ans, res)
print(ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil, pi, sin, cos, acos, atan
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = 1
for _ in range(t):
	s = ips()
	n = len(s)
	dic = Counter(s)
	ans = -float('inf')
	for i in dic:
		ans = max(ans, dic[i])
	ch = list(dic.keys())
	nn = len(ch)
	for i in dic:
		ans = max(ans, dic[i])
	dp = Counter()
	dic = dd(int)
	for i in range(n - 1, -1, -1):
		ele = s[i]
		for j in dp:
			dic[ele + j] += dp[j]
		dp[s[i]] += 1
	for i in dic:
		ans = max(ans, dic[i])
	out(ans)


s = input()
ch = {}
c = 0
var = []
ans = 0
for i in range(len(s)):
	if s[i] in ch:
		ch[s[i]] += 1
	else:
		ch[s[i]] = 1
		var.append(s[i])
PAIR = {}
for i in var:
	ans = max(ans, ch[i])
	for j in var:
		PAIR[i, j] = 0
for i in range(len(s)):
	ch[s[i]] -= 1
	for j in var:
		PAIR[s[i], j] += ch[j]
		ans = max(ans, PAIR[s[i], j])
print(ans)


q = 1
for i in range(q):
	s = list(input())
	a = [0] * 26
	arr = [[0] * 26 for i in range(26)]
	for i in range(len(s)):
		for j in range(26):
			arr[j][ord(s[i]) - 97] += a[j]
		a[ord(s[i]) - 97] += 1
	ans = max(a)
	for i in range(26):
		for j in range(26):
			ans = max(ans, arr[i][j])
	print(ans)


from collections import Counter
import math
s = [i for i in input()]
c = Counter(s).most_common()
if len(c) == 1:
	print(max(len(s), c[0][1] * (c[0][1] - 1) // 2))
else:
	msf = 0
	for j in range(len(c)):
		for k in range(j + 1, len(c)):
			ct = 0
			m = 0
			for i in range(len(s)):
				if s[i] == c[j][0]:
					m += 1
				if s[i] == c[k][0]:
					ct += m
			msf = max(msf, ct)
			ct = 0
			m = 0
			for i in range(len(s)):
				if s[i] == c[k][0]:
					m += 1
				if s[i] == c[j][0]:
					ct += m
			msf = max(msf, ct)
	print(max(c[0][1], c[0][1] * (c[0][1] - 1) // 2, msf))


from collections import Counter, defaultdict
from bisect import bisect

def sol(s):
	sss = sorted(set(s))
	pos = defaultdict(list)
	cnt = defaultdict(int)
	for (i, x) in enumerate(s):
		pos[x].append(i)
	for (i, x) in enumerate(s):
		for a in sss:
			pa = pos[a]
			add = len(pa) - bisect(pa, i)
			cnt[f'{x}{a}'] += add
	return max(Counter(s).most_common(1)[0][1], max(cnt.values()))
print(sol(input()))


s = input()
one = [0] * 26
two = [[0] * 26 for _ in range(0, 26)]
for i in s:
	k = ord(i) - 97
	for ii in range(0, 26):
		two[ii][k] += one[ii]
	one[k] += 1
mx = max(one)
for i in two:
	mx = max(mx, max(i))
print(mx)


from collections import Counter
s = input()
c = Counter()
sets = set()
dp = dict()
for x in s:
	dp[x] = dp.get(x, 0) + 1
	for y in sets:
		dp[x, y] = dp.get((x, y), 0) + c[y]
	sets.add(x)
	c[x] += 1
print(max(dp.values()))


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input().strip()
mod = 1000000007
a = S()
ans = []
for i in range(26):
	ans.append([0] * 26)
c = [0] * 26
for i in a:
	k = ord(i) - 97
	for j in range(26):
		ans[j][k] += c[j]
	c[k] += 1
m = 0
m = max(m, max(c))
for i in ans:
	m = max(m, max(i))
print(m)


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
s = input()
ctr = [0] * 26
pairs = [[0] * 26 for _ in range(26)]
for c in s:
	i = ord(c) - 97
	for first in range(26):
		pairs[first][i] += ctr[first]
	ctr[i] += 1
maxSub = max(ctr)
for row in pairs:
	maxSub = max(maxSub, max(row))
print(maxSub)


s = input()
mp = {1: 0}
cnt = {1: 0}
for i in range(0, 26):
	for j in range(0, 26):
		mp[chr(i + ord('a')) + chr(j + ord('a'))] = 0
for i in range(0, 26):
	cnt[chr(i + ord('a'))] = 0
ans = 0
for i in s:
	for j in range(0, 26):
		c = chr(j + ord('a'))
		mp[i + c] += cnt[c]
		if mp[i + c] > ans:
			ans = mp[i + c]
	cnt[i] += 1
	if cnt[i] > ans:
		ans = cnt[i]
print(ans)


s = input()
d1 = {}
d2 = {}
for i in s:
	for key in d1:
		if key + i in d2:
			d2[key + i] += d1[key]
		else:
			d2[key + i] = d1[key]
	if i in d1:
		d1[i] += 1
	else:
		d1[i] = 1
ans = 0
for key in d1:
	ans = max(ans, d1[key])
for key in d2:
	ans = max(ans, d2[key])
print(ans)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	s = stdin.readline().strip()
	n = len(s)
	cnt = [{}]
	for c in s:
		newc = cnt[-1].copy()
		newc[c] = newc.get(c, 0) + 1
		cnt.append(newc)
	total = cnt[-1]
	res = max(total.values())
	for o in range(256):
		c = chr(o)
		if c < 'a' or 'z' < c or c not in total:
			continue
		for o2 in range(256):
			c2 = chr(o2)
			if c2 < 'a' or 'z' < c2 or c2 not in total:
				continue
			testres = 0
			for i in range(1, n):
				if s[i - 1] == c:
					testres += total.get(c2, 0) - cnt[i].get(c2, 0)
			res = max(res, testres)
	stdout.write('%d' % res)
	return 0
main()


from sys import stdin
s = stdin.readline().strip()
cnt = [[] for i in range(26)]
n = len(s)
for i in range(n):
	cnt[ord(s[i]) - 97].append(i)
ans = 0

def search(e, g):
	best = -1
	l = 0
	r = len(cnt[g]) - 1
	while l <= r:
		m = (l + r) // 2
		if cnt[g][m] > e:
			r = m - 1
			best = m
		else:
			l = m + 1
	return best
for i in range(26):
	if len(cnt[i]) == 0:
		continue
	for j in range(26):
		if len(cnt[j]) == 0:
			continue
		total = 0
		for k in cnt[i]:
			get = search(k, j)
			total += len(cnt[j]) - get if get >= 0 else 0
		ans = max(ans, total)
for i in range(26):
	ans = max(ans, len(cnt[i]))
print(ans)


bess = input()
n = len(bess)
target = {}
subseq = {}
for letter in bess:
	target[letter] = 0
for letter in bess:
	for l in target:
		try:
			subseq[l + letter] += target[l]
		except KeyError:
			subseq[l + letter] = target[l]
	target[letter] += 1
print(max(max(target.values()), max(subseq.values())))


from collections import Counter as c
s = input()
ans = max(c(s).values())
n = len(s)
pre = [[0 for _ in range(26)] for _ in range(n)]
v = ord(s[0]) - ord('a')
pre[0][v] = 1
for i in range(1, len(s)):
	v = ord(s[i]) - ord('a')
	for j in range(26):
		pre[i][j] += pre[i - 1][j]
	pre[i][v] += 1
d = {}
for i in range(n):
	v = ord(s[i]) - ord('a')
	pre[i][v] -= 1
	for j in range(26):
		ns = chr(j + ord('a')) + s[i]
		if ns not in d:
			d[ns] = 0
		d[ns] += pre[i][j]
	pre[i][v] += 1
ans = max(ans, max(d.values()))
print(ans)


a = input()
s = 0
b = []
for i in range(26):
	c = []
	for j in range(len(a) + 3):
		c.append(0)
	b.append(c)
d = []
for i in range(26):
	c = []
	for j in range(len(a) + 3):
		c.append(0)
	d.append(c)
for i in range(len(a)):
	x = ord(a[i]) - ord('a')
	b[x][i] = 1
	d[x][i] = 1
for i in range(26):
	for j in range(len(a)):
		b[i][j] += b[i][j - 1]
		s = max(s, b[i][j])
for i in range(26):
	for j in range(len(a), -1, -1):
		d[i][j] += d[i][j + 1]
		s = max(s, d[i][j])
for i in range(26):
	for j in range(26):
		r = 0
		for k in range(len(a)):
			x = ord(a[k]) - ord('a')
			if x == i:
				r = r + d[j][k + 1]
		s = max(r, s)
print(s)


from collections import defaultdict as dd
s = input()
n = len(s)
d = dd(int)
a = [ord(x) - 97 for x in s]
dic = [[0 for x in range(26)] for y in range(26)]
str = [0 for x in range(26)]
for i in range(n):
	for j in range(26):
		dic[a[i]][j] += str[j]
	str[a[i]] += 1
mx1 = max(str)
mx2 = 0
for i in dic:
	if mx2 < max(i):
		mx2 = max(i)
print(max(mx1, mx2))


import sys
s = sys.stdin.readline().rstrip()
cnt = {}
re = 0
for i in s:
	if i not in cnt:
		cnt[i] = 1
	else:
		cnt[i] += 1
	if re < cnt[i]:
		re = cnt[i]
if re < int(re * (re - 1) / 2):
	re = int(re * (re - 1) / 2)
chk = {}
cnt = {}
tar = []
for i in range(len(s)):
	idx = len(s) - i - 1
	if idx == len(s) - 1:
		cnt[s[idx]] = 1
		if cnt[s[idx]] == 1:
			tar.append(s[idx])
		continue
	for j in tar:
		if cnt[j] == 0 or s[idx] == j:
			continue
		if s[idx] + j not in chk:
			chk[s[idx] + j] = cnt[j]
		else:
			chk[s[idx] + j] += cnt[j]
		if chk[s[idx] + j] > re:
			re = chk[s[idx] + j]
	if s[idx] not in cnt:
		cnt[s[idx]] = 1
	else:
		cnt[s[idx]] += 1
	if cnt[s[idx]] == 1:
		tar.append(s[idx])
print(re)


s = input()
One = [0] * 26
Two = [[0] * 26 for i in range(26)]
for i in range(len(s)):
	c = ord(s[i]) - ord('a')
	for j in range(26):
		Two[j][c] += One[j]
	One[c] += 1
ans = max(One)
for i in range(26):
	r = max(Two[i])
	if r > ans:
		ans = r
print(ans)


import math
S = input()
D = dict()
E = dict()
for s in S:
	for d in D:
		if d + s in E:
			E[d + s] += D[d]
		else:
			E[d + s] = D[d]
	if s in D:
		D[s] += 1
	else:
		D[s] = 1
a = max(list(D.values()))
if len(list(E.values())) > 0:
	b = max(list(E.values()))
else:
	b = 0
print(max(a, b))


s = input()
ss = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'.split()
d1 = {}
d2 = {}
for ssi in ss:
	d1[ssi] = 0
for i in ss:
	for k in ss:
		d2[i + k] = 0
for si in s:
	for ki in d1.keys():
		d2[ki + si] += d1[ki]
	d1[si] += 1
print(max(max(d1.values()), max(d2.values())))


s = input()
c = {}
d = {}
for i in s:
	c[i] = c.get(i, 0) + 1
	for (j, k) in c.items():
		if i != j:
			d[i + j] = d.get(i + j, 0) + k
x = max(c.values())
y = max(d.values()) if d else 0
z = max((i * (i - 1) // 2 for i in c.values()))
print(max(x, y, z))


from collections import Counter
s = input()
n = len(s)
if len(s) == 1:
	print(1)
	exit()
if s.count(s[0]) == len(s):
	print(max(len(s), len(s) * (len(s) - 1) // 2))
	exit()
d = Counter(s)
l = []
for i in d:
	l.append(d[i])
ans = max(l)
c = {}
count = {}
for i in range(n - 1, -1, -1):
	if i == n - 1:
		if s[i] not in count:
			count[s[i]] = 1
		else:
			count[s[i]] += 1
	else:
		if s[i] not in count:
			count[s[i]] = 1
		else:
			count[s[i]] += 1
		for j in d:
			if j in count and j != s[i]:
				if s[i] + j not in c:
					c[s[i] + j] = count[j]
				else:
					c[s[i] + j] += count[j]
for i in c:
	if c[i] > ans:
		ans = c[i]
for i in d:
	if d[i] * (d[i] - 1) // 2 > ans:
		ans = d[i] * (d[i] - 1) // 2
print(ans)


import sys
import math
import operator as op
from functools import reduce
from bisect import *

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom
N = int(1000000.0) + 10
fenwick = [0] * N

def add(i, x, n):
	while i < n:
		fenwick[i] += x
		i = i | i + 1

def fsum(i, n):
	res = 0
	while i >= 0:
		res += fenwick[i]
		i = (i & i + 1) - 1
	return res

def fsum_range(i, j, n):
	return fsum(j, n) - fsum(i - 1, n)
mod = int(1000000000.0) + 7
t = 1
for i in range(t):
	s = read_line()
	dp = [[0 for i in range(26)] for j in range(26)]
	dp2 = [0] * 26
	n = len(s)
	for i in range(n):
		for j in range(26):
			dp[j][ord(s[i]) - ord('a')] += dp2[j]
		dp2[ord(s[i]) - ord('a')] += 1
	ans = max(dp2)
	for i in range(26):
		for j in range(26):
			ans = max(ans, dp[i][j])
	print(ans)


m = input()
from collections import defaultdict
cur_alphabet_count = defaultdict(int)
cur_pair_count = defaultdict(int)
for i in range(len(m)):
	cur_letter = m[len(m) - 1 - i]
	for (pair, count) in cur_alphabet_count.items():
		cur_pair_count[cur_letter + pair] += count
	cur_alphabet_count[cur_letter] += 1
print(max(max(cur_alphabet_count.values() or [0]), max(cur_pair_count.values() or [0])))


import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def solve():
	S = listStr()
	singles = [0 for i in range(26)]
	doubles = [[0 for j in range(26)] for i in range(26)]
	for s in S:
		num = ord(s) - ord('a')
		for j in range(26):
			doubles[j][num] += singles[j]
		singles[num] += 1
	ans = 0
	for i in range(26):
		ans = max(ans, singles[i])
		for j in range(26):
			ans = max(ans, doubles[i][j])
	return ans
print(solve())


S = input()
N = len(S)
Count = [0] * 26
New = [0] * 675
Ans = 0
for i in range(N):
	start = ord(S[i]) - 97
	for j in range(start, start + 26 * 25, 26):
		New[j] += Count[int(j // 26)]
	Count[start] += 1
X = max(Count)
P = X * (X - 1) >> 1
print(max(P, max(New), X))


from sys import stdin, exit
from typing import List, Tuple
CHAR_NUM = 26
line = [ord(v) - ord('a') for v in stdin.readline().rstrip()]
chars = [0] * CHAR_NUM
strings = [None] * CHAR_NUM
for i in range(CHAR_NUM):
	strings[i] = [0] * CHAR_NUM
for n in line:
	for i in range(CHAR_NUM):
		strings[i][n] += chars[i]
	chars[n] += 1
rez = max(chars)
for l in strings:
	rez = max(rez, max(l))
print(rez)


s = input()
oda = ord('a')
a = [ord(s[i]) - oda for i in range(len(s))]
c = [0] * 26
for i in a:
	c[i] += 1
ans = max(c)
r = [0] * 26 ** 2
c = [0] * 26
for i in range(len(a)):
	for j in range(26):
		r[a[i] * 26 + j] += c[j]
	c[a[i]] += 1
ans = max(ans, max(r))
print(ans)


import sys
import bisect
from collections import deque

def no():
	print('NO')

def dist(z, c):
	return (z[0] - c[0]) * (z[0] - c[0]) + (z[1] - c[1]) * (z[1] - c[1])

def vec(z, c):
	return z[0] * c[1] - z[1] * c[0]

def pro(z, c):
	return [z[0] - c[0], z[1] - c[1]]

def main():

	def pro1(z, a):
		l = -1
		r = len(w[a])
		while r > 1 + l:
			res = (r + l) // 2
			if w[a][res] <= z:
				l = res
			else:
				r = res
		return r

	def pro(b, a):
		(x, c) = (0, 0)
		(d, l) = (a == b, len(w[a]))
		for i in w[b]:
			z = pro1(i, a)
			c += z - d
			x += l - z
		return max(c, x)
	s = list(sys.stdin.readline())[:-1]
	if len(s) == len(set(s)):
		print(1)
		return 0
	w = {}
	q = list(set(s))
	res = 0
	for i in range(len(s)):
		if s[i] in w:
			w[s[i]].append(i)
		else:
			w[s[i]] = [i]
	for i in range(len(q)):
		for o in q[i:]:
			if len(w[o]) * len(w[q[i]]) > res:
				res = max(max(res, pro(q[i], o)), max(len(w[o]), len(w[q[i]])))
	print(res)
for i in range(1):
	main()


from math import *
from collections import *
from operator import itemgetter
import bisect
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
d = defaultdict(lambda : [])
s = input()
for i in range(len(s)):
	d[s[i]].append(i)
if len(d) == len(s):
	print(1)
elif len(d) == 1:
	print(max(len(s), len(s) * (len(s) - 1) // 2))
else:
	maxi = 0
	for i in range(26):
		n = len(d[chr(i + 97)])
		maxi = max(maxi, n * (n - 1) // 2)
		for j in range(26):
			c = 0
			for k in d[chr(i + 97)]:
				c += len(d[chr(j + 97)]) - bisect.bisect_right(d[chr(j + 97)], k)
			maxi = max(maxi, c, len(d[chr(i + 97)]))
	print(maxi)


c1 = [0] * 30
c2 = [[0] * 30 for _ in range(30)]
s = input()
for ch in s:
	j = ord(ch) - ord('a')
	for i in range(26):
		c2[i][j] += c1[i]
	c1[j] += 1
ans = 0
for i in range(26):
	ans = max(ans, c1[i])
for i in range(26):
	for j in range(26):
		ans = max(ans, c2[i][j])
print(ans)


s = input()
ard = {}
ard[s[0]] = 1
pair_max = 0
pairs = {}
for (i, c) in enumerate(s[1:], 1):
	for letter in ard.keys():
		temp = letter + c
		pairs[temp] = pairs.get(temp, 0) + ard[letter]
		if pairs[temp] > pair_max:
			pair_max = pairs[temp]
	ard[c] = ard.get(c, 0) + 1
print(max(list(ard.values()) + [pair_max]))


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
s = input()
n = len(s)
d = dd(int)
ans = 0
count = dd(int)
string = 'abcdefghijklmnopqrstuvwxyz'
for i in range(n):
	d[s[i]] += 1
	for j in string:
		ans = max(ans, d[j])
		if j == s[i]:
			count[j + s[i]] += d[j] - 1
			ans = max(ans, count[j + s[i]])
			continue
		count[j + s[i]] += d[j]
		ans = max(ans, count[j + s[i]])
print(ans)


s = input()
co = [0] * 26
dp = [[0 for _ in range(26)] for _ in range(26)]
for i in s:
	a = ord(i) - ord('a')
	for j in range(26):
		dp[a][j] += co[j]
	co[a] += 1
maxx = -1
for i in dp:
	maxx = max(maxx, max(i))
print(max(maxx, max(co)))


import collections, string
s = input()
d = collections.defaultdict(int)
for a in string.ascii_lowercase:
	d[a] = 0
	for b in string.ascii_lowercase:
		d[a + b] = 0
for c in s:
	for p in string.ascii_lowercase:
		d[p + c] += d[p]
	d[c] += 1
print(max(d.values()))


s = input()
arr = [0] * 26
Max = -1
Dict = {}
for i in range(len(s)):
	A = ord(s[i]) - ord('a')
	for j in range(26):
		seq = str(chr(j + 97)) + s[i]
		if Dict.get(seq) == None:
			Dict[seq] = arr[j]
		else:
			Dict[seq] = arr[j] + Dict[seq]
		Max = max(Max, Dict[seq])
	arr[A] += 1
	Max = max(Max, arr[A])
print(Max)


import sys
from collections import defaultdict
arr = [[0] * 26]
s = sys.stdin.readline()[:-1]
n = len(s)
for i in range(n - 2, -1, -1):
	tmp = [j for j in arr[-1]]
	tmp[ord(s[i + 1]) - 97] += 1
	arr.append(tmp)
ans = 0
arr.reverse()
dic = defaultdict(int)
for i in range(n):
	dic[s[i]] += 1
	ans = max(ans, dic[s[i]])
	for k in range(26):
		dic[s[i] + chr(k + 97)] += arr[i][k]
		ans = max(ans, dic[s[i] + chr(k + 97)])
print(ans)


import copy
S = input()
l = len(S)
tbl = [[0] * l for _ in range(26)]
for i in range(l):
	tbl[ord(S[i]) - 97][i] += 1
tbl_ = copy.deepcopy(tbl)
for i in range(26):
	for j in range(l - 1, 0, -1):
		tbl_[i][j - 1] += tbl_[i][j]
ans = 0
for i in range(26):
	ans = max(ans, tbl_[i][0])
for i in range(26):
	for j in range(26):
		ans_ = 0
		for k in range(l):
			ans_ += tbl[i][k] * tbl_[j][k]
		if i == j:
			ans_ -= tbl_[i][0]
		ans = max(ans, ans_)
print(ans)


def solve(S):
	S = [ord(ch) - ord('a') for ch in S]
	counts = [0] * 26
	pairs = [[0] * 26 for i in range(26)]
	for c in S:
		for j in range(26):
			pairs[c][j] += counts[j]
		counts[c] += 1
	best = max(counts)
	for i in range(26):
		for j in range(26):
			best = max(best, pairs[i][j])
	return best
S = input()
ans = solve(S)
print(ans)


from collections import Counter
import string
import bisect
import math
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
testcases = 1
for _ in range(testcases):
	s = input()
	characters = []
	for i in string.ascii_lowercase:
		characters.append(i)
	maxi = -1
	for i in characters:
		st = i
		maxi = max(maxi, s.count(st))
		for j in characters:
			pt = st + j
			if pt[0] == pt[1]:
				t = s.count(pt[0])
				maxi = max(maxi, t * (t - 1) // 2)
				continue
			count = 0
			countf = counts = 0
			for k in range(len(s)):
				if s[k] == pt[0]:
					countf += 1
				elif s[k] == pt[1]:
					count += countf
			maxi = max(maxi, count)
	print(maxi)


import sys
input = sys.stdin.readline
mii = lambda : map(int, input().split())
s = input().strip()
d = [0] * 1000
e = [0] * 1000
hist = [0] * 26
for i in s:
	j = ord(i) - ord('a')
	for k in range(26):
		e[k * 26 + j] += hist[k]
	hist[j] += 1
	d[j] += 1
print(max(d + e))


s = [s for s in input()]
d = {}
for i in s:
	d[i] = [0]
for i in range(len(s)):
	for j in d.keys():
		if j == s[i]:
			d[j].append(d[j][len(d[j]) - 1] + 1)
		else:
			d[j].append(d[j][len(d[j]) - 1])
ans = {}
for i in range(len(s)):
	l = s[i]
	id = i + 1
	try:
		ans[l] = ans[l] + 1
	except KeyError:
		ans[l] = 1
	for j in d.keys():
		if j == l:
			if d[j][id] - 1 > 0:
				new_str = j + l
				try:
					ans[new_str] = ans[new_str] + d[j][id] - 1
				except KeyError:
					ans[new_str] = d[j][id] - 1
		elif d[j][id] > 0:
			new_str = j + l
			try:
				ans[new_str] = ans[new_str] + d[j][id]
			except KeyError:
				ans[new_str] = d[j][id]
max_ele = 0
for i in ans:
	if ans[i] > max_ele:
		max_ele = ans[i]
print(max_ele)


from math import ceil, sqrt, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())
s = si()
a = []
for i in range(26):
	b = [0] * 26
	a.append(b)
c = [0] * 26
for i in range(len(s)):
	for j in range(26):
		a[j][ord(s[i]) - ord('a')] += c[j]
	c[ord(s[i]) - ord('a')] += 1
c1 = max(c)
for i in range(26):
	for j in range(26):
		c1 = max(c1, a[i][j])
print(c1)


import math
import sys
from collections import defaultdict, Counter, deque, OrderedDict
import bisect
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]
from itertools import accumulate, groupby
import sys
mod = 1000000007
S = input()
C = Counter(S)
(Ans1, Ans2, Ans3) = (0, 0, 0)
Ans1 = max(C.values())
N = C.most_common(1)[0][1]
Ans2 = N * (N - 1) // 2
count = {}
Ans = {}
for i in S:
	count[i] = count.get(i, 0) + 1
	for (j, k) in count.items():
		if j != i:
			Ans[i + j] = Ans.get(i + j, 0) + k
if Ans:
	Ans3 = max(Ans.values())
print(max(Ans1, Ans2, Ans3))


dp = [[0 for i in range(26)] for j in range(26)]
s = input()
ans = [0 for i in range(26)]
ans[ord(s[0]) - ord('a')] = 1
for i in range(1, len(s)):
	for j in range(26):
		dp[j][ord(s[i]) - ord('a')] += ans[j]
	ans[ord(s[i]) - ord('a')] += 1
an = 0
for i in range(26):
	for j in range(26):
		an = max(dp[i][j], an)
print(max(an, max(ans)))


F = [[0 for i in range(26)] for j in range(26)]
t = [0] * 26
s = input()
ans = 0
for k in s:
	number = ord(k) - 97
	for m in range(26):
		F[number][m] += t[m]
		ans = max(ans, F[number][m])
	t[number] += 1
	ans = max(ans, t[number])
print(ans)


def count(a, b):
	m = len(a)
	n = len(b)
	lookup = [[0 for i in range(n + 1)] for j in range(m + 1)]
	for i in range(n + 1):
		lookup[0][i] = 0
	for i in range(m + 1):
		lookup[i][0] = 1
	for i in range(1, m + 1):
		for j in range(1, n + 1):
			if a[i - 1] == b[j - 1]:
				lookup[i][j] = lookup[i - 1][j - 1] + lookup[i - 1][j]
			else:
				lookup[i][j] = lookup[i - 1][j]
	return lookup[m][n]
word = input()
arr = [0 for i in range(26)]
mat = [[0 for i in range(26)] for j in range(26)]
for i in range(len(word)):
	for j in range(26):
		mat[j][ord(word[i]) - 97] += arr[j]
	arr[ord(word[i]) - 97] += 1
m = -1
for i in arr:
	m = max(m, i)
for i in mat:
	for j in i:
		m = max(m, j)
print(m)


from collections import Counter
s = [i for i in input()]
mx = Counter(s).most_common()[0][1]
for i in range(26):
	for j in range(26):
		if i != j:
			m = 0
			ct = 0
			for k in range(len(s)):
				if s[k] == chr(97 + i):
					m += 1
				if s[k] == chr(97 + j):
					ct += m
			mx = max(mx, ct)
			m = 0
			ct = 0
			for k in range(len(s)):
				if s[k] == chr(97 + j):
					m += 1
				if s[k] == chr(97 + i):
					ct += m
			mx = max(mx, ct)
print(max(mx, Counter(s).most_common()[0][1] * (Counter(s).most_common()[0][1] - 1) // 2))


s = input()
n = len(s)
cnt = [0] * 30
dp = [[0 for i in range(30)] for j in range(30)]
for i in range(n):
	ch = ord(s[i]) - 97
	for j in range(26):
		dp[j][ch] += cnt[j]
	cnt[ch] += 1
res = max(cnt)
for i in range(26):
	res = max(res, max(dp[i]))
print(res)


from collections import Counter
from collections import defaultdict
import sys
input = sys.stdin.readline
s = input().rstrip()
n = len(s)
ans = 0
dc = defaultdict(lambda : defaultdict(int))
for i in range(n):
	x = s[i]
	if i == 0:
		dc[0][x] += 1
	else:
		for y in dc[0].keys():
			dc[x][y] += dc[0][y]
		dc[0][x] += 1
for i in dc:
	for j in dc[i]:
		ans = max(ans, dc[i][j])
print(ans)


s = input()
d1 = dict()
d2 = dict()
for c in s:
	for key in d1:
		if key + c in d2:
			d2[key + c] += d1[key]
		else:
			d2[key + c] = d1[key]
	if c in d1:
		d1[c] += 1
	else:
		d1[c] = 1
ans = 0
for key in d1:
	ans = max(ans, d1[key])
for key in d2:
	ans = max(ans, d2[key])
print(ans)


s = input()
import string
_ascii = string.ascii_lowercase
f1 = {c: 0 for c in _ascii}
f2 = {(c1, c2): 0 for c1 in _ascii for c2 in _ascii}
for c in s:
	for l in _ascii:
		f2[l, c] += f1[l]
	f1[c] += 1
print(max(max(f2.values()), max(f1.values())))


from sys import stdin
s = [ord(x) - ord('a') for x in input().rstrip()]
alphabet = [[0 for i in range(26)] for j in range(26)]
currSeen = [0] * 26
for i in s:
	for j in range(26):
		if currSeen[j] > 0:
			alphabet[j][i] += currSeen[j]
	currSeen[i] += 1
for i in range(26):
	alphabet[i] = max(alphabet[i])
print(max(max(alphabet), max(currSeen)))


s = input()
import collections
d = collections.defaultdict(list)
MAX = 0
for (i, x) in enumerate(s):
	d[x].append(i)
	MAX = max(len(d[x]), MAX)
for x in d:
	for y in d:
		j = 0
		count = 0
		y = d[y]
		for i in d[x]:
			while j != len(y) and y[j] <= i:
				j += 1
			if j == len(y):
				break
			count += len(y) - j
		MAX = max(MAX, count)
print(MAX)


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())
s = list(input())
n = len(s)
for i in range(n):
	s[i] = ord(s[i]) - 97
l = []
ll = [0] * 26
for i in range(26):
	l.append([0] * 26)
for i in range(n):
	for j in range(26):
		l[j][s[i]] += ll[j]
	ll[s[i]] += 1
t = 0
ans = max(ll)
for i in range(26):
	ans = max(ans, max(l[i]))
print(ans)


import sys
import collections
input = sys.stdin.readline

def main():
	S = input().strip()
	C = collections.Counter(S)
	C2 = collections.Counter()
	ans = C.most_common()[0][1]
	ruiseki = [0] * 26
	for a in S:
		ai = ord(a) - ord('a')
		ruiseki[ai] += 1
		for i in range(26):
			C2[ai, i] += C[chr(ord('a') + i)] - ruiseki[i]
	ans = max(ans, C2.most_common()[0][1])
	print(ans)
main()


from collections import Counter
s = input()
n = len(s)
c = Counter(s)
dp = [[0 for i in range(n)] for i in range(26)]
maxx2 = [0] * n
loc = {}
for i in range(n):
	if s[i] not in loc:
		loc[s[i]] = [i]
	else:
		loc[s[i]].append(i)
	for j in range(26):
		if ord(s[i]) == j + 97:
			dp[j][i] = dp[j][i - 1] + 1
		else:
			dp[j][i] = dp[j][i - 1]
for i in range(n):
	m = 0
	for j in range(26):
		m = max(m, dp[j][-1] - dp[j][i])
	maxx2[i] = m
ans = 0
for i in c:
	ans = max(ans, c[i])
for i in loc:
	for j in range(26):
		m = 0
		for k in loc[i]:
			m += dp[j][-1] - dp[j][k]
		ans = max(ans, m)
print(ans)


from collections import defaultdict
from bisect import bisect_right
import string
s = input()
d = defaultdict(list)
for (idx, c) in enumerate(s):
	d[c].append(idx)
ans = 0
for v in d:
	ans = max(ans, len(d[v]))
for start in string.ascii_lowercase:
	for end in string.ascii_lowercase:
		score = 0
		for v in d[start]:
			score += len(d[end]) - bisect_right(d[end], v)
		ans = max(ans, score)
print(ans)


import sys
s = input()
n = len(s)
d = dict()
k = 26
count1 = [0] * k
count2 = [[0] * k for i in range(k)]
for i in range(n):
	e = ord(s[i]) - ord('a')
	for j in range(k):
		count2[j][e] += count1[j]
	count1[e] += 1
answer = max(count1)
for i in range(k):
	answer = max(answer, max(count2[i]))
print(answer)


import sys
from math import *
d = {}

def bo(i):
	return ord(i) - ord('a')
t = 1
while t > 0:
	t -= 1
	s = list(input())
	d = {}
	n = len(s)
	maxi = [0 for i in range(27)]
	mini = [0 for i in range(27)]
	r = [[0 for i in range(27)] for j in range(n)]
	for i in range(26):
		d[i] = 0
	for i in range(n):
		if d[ord(s[i]) - ord('a')] == 0:
			d[ord(s[i]) - ord('a')] = 1
			mini[ord(s[i]) - ord('a')] = i
		else:
			d[ord(s[i]) - ord('a')] += 1
			maxi[ord(s[i]) - ord('a')] = i
		if i == 0:
			r[i][bo(s[i])] = 1
		else:
			r[i][bo(s[i])] = r[i - 1][bo(s[i])] + 1
			for ii in range(26):
				if ii != bo(s[i]):
					r[i][ii] = r[i - 1][ii]
	a = []
	for i in d:
		a.append(d[i])
	m = max(max(a), max(a) * (max(a) - 1) // 2)
	dis = [[0 for i in range(27)] for j in range(27)]
	if 1:
		for i in range(n):
			p = bo(s[i])
			for j in range(27):
				if p != j:
					dis[p][j] += r[i][j]
	b = -999
	for i in range(26):
		m = max(max(dis[i]), m)
	print(m)


from collections import defaultdict
s = input()
indices = defaultdict(list)
n = len(s)
for i in range(n):
	indices[s[i]].append(i)
ans = 0
k = list(indices.keys())
n = len(k)
for i in range(n):
	i1 = indices[k[i]]
	ans = max(ans, len(i1), len(i1) * (len(i1) - 1) // 2)
	for j in range(i + 1, n):
		i2 = indices[k[j]]
		(a, b) = (0, 0)
		count = 0
		while a < len(i1):
			while b < len(i2) and i2[b] < i1[a]:
				b += 1
			if b == len(i2):
				break
			count += len(i2) - b
			a += 1
		ans = max(ans, count, len(i1) * len(i2) - count)
print(ans)


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
s = input()
d = [0] * 26
l = [[0] * 26 for i in range(26)]
for j in s:
	a = ord(j) - 97
	for i in range(26):
		l[i][a] += d[i]
	d[a] += 1
ans = 0
for i in range(26):
	ans = max(ans, d[i])
	for j in range(26):
		ans = max(ans, l[i][j])
print(ans)


import sys
import string
s = input()
max_1_c = {}
for c in string.ascii_lowercase:
	max_1_c[c] = 0
max_2 = {}
for c in string.ascii_lowercase:
	max_2[c] = {}
	for c2 in string.ascii_lowercase:
		max_2[c][c2] = 0
for c in s:
	for c2 in string.ascii_lowercase:
		max_2[c2][c] += max_1_c[c2]
	max_1_c[c] += 1
total = 0
for c in string.ascii_lowercase:
	total = max(total, max_1_c[c])
for c in string.ascii_lowercase:
	for c2 in string.ascii_lowercase:
		total = max(total, max_2[c][c2])
print(total)


alpha = list(map(chr, [ord('a') + i for i in range(26)]))

def solve(s):
	cnt1 = {c: 0 for c in alpha}
	cnt2 = {c1 + c2: 0 for c1 in alpha for c2 in alpha}
	for c in s:
		for a in alpha:
			cnt2[a + c] += cnt1[a]
		cnt1[c] += 1
	return max(max(cnt1.values()), max(cnt2.values()))
s = input().strip()
print(solve(s))


import sys
LI = lambda : list(map(int, sys.stdin.readline().split()))
MI = lambda : map(int, sys.stdin.readline().split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline())
num = [[0 for i in range(26)] for j in range(26)]
cnt = {}
ans = 0
for c in SI()[::-1]:
	v = ord(c) - ord('a')
	for i in range(26):
		num[v][i] += cnt.get(i, 0)
		ans = max(ans, num[v][i])
	cnt[v] = cnt.get(v, 0) + 1
print(max(ans, *cnt.values()))


s = [ord(x) - 97 for x in input()]
n = len(s)
se = [0] * 26
se2 = [0] * 26 * 26
for i in range(n):
	for j in range(26):
		se2[s[i] + 26 * j] += se[j]
	se[s[i]] += 1
print(max(max(se), max(se2)))


from __future__ import division, print_function
from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
import math
import os
import sys

def binNumber(n, size=1):
	return bin(n)[2:].zfill(size)

def inar():
	return list(map(int, input().split()))

def ini():
	return int(input())

def insp():
	return map(int, input().split())

def instr():
	return str(input())

def main():
	s = instr()
	mp = {}
	ans = 0
	for c in s:
		if c not in mp:
			mp[c] = 1
		else:
			mp[c] += 1
		ans = max(ans, mp[c])
	newmp = {}
	for k in s:
		mp[k] -= 1
		for k2 in mp:
			if k + k2 not in newmp:
				newmp[k + k2] = mp[k2]
			else:
				newmp[k + k2] += mp[k2]
	for x in newmp:
		ans = max(ans, newmp[x])
	print(ans)
t = 1
while t > 0:
	t -= 1
	main()


s = input()
n = len(s)
dp = [[0 for i in range(26)] for j in range(n + 1)]
for i in range(n):
	for j in range(26):
		if ord(s[i]) - ord('a') == j:
			dp[i + 1][j] = dp[i][j] + 1
		else:
			dp[i + 1][j] = dp[i][j]
m1 = 0
for i in range(26):
	p = dp[n][i]
	m1 = max(m1, p * (p - 1) // 2)
m2 = 0
ma = [0] * (n + 1)
for i in range(n + 1):
	ma[i] = max(dp[i])
d = {}
m2 = ma[n]
for i in range(n, 1, -1):
	ind = i - 1
	c = s[ind]
	for j in range(26):
		d[chr(ord('a') + j) + c] = d.get(chr(ord('a') + j) + c, 0) + dp[i - 1][j]
for i in d:
	m2 = max(m2, d[i])
print(max(m1, m2))


from string import ascii_lowercase
s = input()
lc = {c: 0 for c in ascii_lowercase}
llc = dict()
for c in s:
	for v in lc:
		if v + c not in llc:
			llc[v + c] = lc[v]
		else:
			llc[v + c] += lc[v]
	lc[c] += 1
print(max(*lc.values(), *llc.values()))


import sys
import math, bisect, operator
(inf, m) = (float('inf'), 10 ** 9 + 7)
sys.setrecursionlimit(10 ** 6)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
I = lambda : int(sys.stdin.readline())
neo = lambda : map(int, sys.stdin.readline().split())
Neo = lambda : list(map(int, sys.stdin.readline().split()))
s = input()
c = Counter()
sets = set()
dp = dict()
for x in s:
	dp[x] = dp.get(x, 0) + 1
	for y in sets:
		dp[x, y] = dp.get((x, y), 0) + c[y]
	sets.add(x)
	c[x] += 1
print(max(dp.values()))


import bisect
s = input()
d = {}
for i in range(len(s)):
	if d.get(s[i]) == None:
		d[s[i]] = []
	d[s[i]].append(i)
ans = 0
for i in d:
	for j in d:
		m = 0
		for k in range(len(d[i])):
			b = bisect.bisect_right(d[j], d[i][k])
			m += len(d[j]) - b
		if ans < m:
			ans = m
	if ans < len(d[i]):
		ans = len(d[i])
print(ans)


from collections import *
l = list(input())
n = len(l)
arr = [[0] * 30 for i in range(30)]
array = [0] * 30
for i in range(n):
	val = ord(l[i]) - ord('a') + 1
	for j in range(1, 27):
		arr[j][val] += array[j]
	array[val] += 1
ans = 0
for i in range(1, 27):
	for j in range(1, 27):
		ans = max(ans, arr[i][j])
for i in range(1, 27):
	ans = max(ans, array[i])
print(ans)


import sys
import math
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
s = input()
n = len(s)
mark = [0] * 26
for i in range(n):
	mark[ord(s[i]) - 97] += 1
ans = 0
for num in mark:
	ans = max(ans, num)
	ans = max(ans, num * (num - 1) // 2)
for i in range(26):
	markk = [0] * 26
	anss = [0] * 26
	count = 0
	for j in range(n):
		if ord(s[j]) - 97 == i:
			count += 1
		else:
			anss[ord(s[j]) - 97] += count
	ans = max(ans, max(anss))
print(ans)


s = list(input())
ans = 0
from collections import Counter
d = dict(Counter(s))
ans = max(d.values())
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(26):
	for j in range(26):
		c = 0
		(x, y) = (alpha[i], alpha[j])
		counter = 0
		for some in s:
			if some == y:
				c += counter
			if some == x:
				counter += 1
		ans = max(ans, c)
print(ans)


import sys
from collections import Counter
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
S = [ord(a) - 97 for a in input()]
N = len(S)
acc = list2d(26, N, 0)
for (i, s) in enumerate(S):
	acc[s][i] += 1
for s in range(26):
	acc[s] = list(accumulate(acc[s]))
C = Counter(S)
mx = max(C.values())
for i in range(26):
	cnta = C[i]
	for j in range(26):
		cntb = C[j]
		if i == j:
			mx = max(mx, cnta * (cnta - 1) // 2)
		else:
			cnt = 0
			for k in range(N):
				if S[k] == j:
					cnt += acc[i][k]
			mx = max(mx, cnt)
print(mx)


import sys
input = sys.stdin.readline
from collections import Counter
S = input().strip()
C = Counter(S)
MAX = max(C.values())
if len(S) == 1:
	print(1)
	sys.exit()
C = Counter()
ANS = Counter()
for i in range(len(S) - 1):
	C[S[i]] += 1
	s = S[i + 1]
	for c in C:
		ANS[c + s] += C[c]
print(max(MAX, max(ANS.values())))


import os
import sys
from io import BytesIO, IOBase
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')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
vals = [ord(k) - 97 for k in input()]
n = len(vals)
dict1 = [0 for s in range(26)]
sufsum = []
occurences = 0
for s in range(n - 1, -1, -1):
	dict1[vals[s]] += 1
	if dict1[vals[s]] > occurences:
		occurences = dict1[vals[s]]
	sufsum.append(dict1.copy())
sufsum.reverse()
store = []
maxans = 0
for s in range(26):
	a1 = [0 for b in range(26)]
	store.append(a1)
for s in range(n):
	if s < n - 1:
		for b in range(26):
			store[vals[s]][b] += sufsum[s + 1][b]
			if store[vals[s]][b] > maxans:
				maxans = store[vals[s]][b]
print(max(occurences, maxans))


import bisect
s = input()
idx = {}
for i in range(len(s)):
	if s[i] not in idx:
		idx[s[i]] = []
	idx[s[i]].append(i)
ans = 0
for i in idx:
	ans = max(ans, len(idx[i]))
	for j in idx:
		ans = max(ans, len(idx[j]))
		cv = 0
		for fi in idx[i]:
			freq = len(idx[j]) - bisect.bisect_right(idx[j], fi)
			cv += freq
		ans = max(ans, cv)
print(ans)


import sys
a = ord('a')
s = input().strip()
n = len(s)
dp1 = [[0 for _ in range(26)] for _ in range(26)]
dp2 = [0] * 26
for i in range(n):
	c = ord(s[i]) - a
	for j in range(26):
		dp1[j][c] += dp2[j]
	dp2[c] += 1
ans = max(dp2)
for i in dp1:
	ans = max(ans, max(i))
print(ans)


s = list(input())
al = []
als = []
for i in s:
	if i in al:
		als[al.index(i)] += 1
	else:
		al.append(i)
		als.append(1)
ans1 = max(als)
for i in al:
	for j in al:
		if i != j:
			f = 0
			ans2 = 0
			for k in range(len(s)):
				if s[k] == i:
					f += 1
					continue
				if s[k] == j:
					ans2 += f
			ans1 = max(ans1, ans2)
for i in als:
	ans1 = max(ans1, i * (i - 1) // 2)
print(ans1)


import sys
import math
import itertools
import functools
import collections
import operator

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
arr = []
s = list(input())
ans = [[0] * 26 for _ in range(26)]
a = [0] * 26
orda = ord('a')
for c in s:
	ans[ord(c) - orda][ord(c) - orda] += 1
	for i in range(26):
		ans[ord(c) - orda][i] += ans[i][i] * (i != ord(c) - orda)
max_ = 0
for i in range(26):
	max_ = max(max_, ans[i][i] * (ans[i][i] - 1) // 2)
for r in ans:
	max_ = max(max_, max(r))
print(max_)


s = input()
pos = [0] * 26
ptr = []
for i in range(26):
	ee = []
	ptr.append(ee)
for i in range(0, len(s)):
	pos[ord(s[i]) - 97] += 1
	ptr[ord(s[i]) - 97].append(i)
ans = max(pos)
pre = []
p = [0] * 26
for i in range(len(s) - 1, -1, -1):
	h = []
	for j in range(0, 26):
		h.append(p[j])
	pre.append(h)
	p[ord(s[i]) - 97] += 1
pre = pre[::-1]
for i in range(0, 26):
	for j in range(0, 26):
		ch1 = chr(i + 97)
		ch2 = chr(j + 97)
		c = 0
		for k in range(0, len(ptr[i])):
			c = c + pre[ptr[i][k]][j]
		ans = max(ans, c)
print(ans)


s = input()
dp = []
n = len(s)
dp1 = {}
for _ in range(n):
	dp.append(list([0] * 26))
dp[0][ord(s[0]) - ord('a')] += 1
ans = 1
for i in range(1, len(s)):
	vl = ord(s[i]) - ord('a')
	for j in range(26):
		dp[i][j] = dp[i - 1][j]
		if dp[i - 1][j]:
			vl1 = chr(ord('a') + j) + s[i]
			if dp1.get(vl1) == None:
				dp1[vl1] = dp[i - 1][j]
			else:
				dp1[vl1] += dp[i - 1][j]
		if j == vl:
			dp[i][j] += 1
for i in range(26):
	ans = max(dp[n - 1][i], ans)
if len(dp1):
	ans = max(ans, max(dp1.values()))
print(ans)


from collections import Counter

def soln(s):
	subs = Counter()
	found = set()
	i = len(s) - 2
	subs[s[-1]] += 1
	found.update(s[-1])
	while i >= 0:
		buff = set()
		for sub in found:
			subs[s[i] + sub] += subs[sub]
			buff.update(s[i] + sub)
		subs[s[i]] += 1
		found.update(s[i])
		found.union(buff)
		i -= 1
	print(subs.most_common()[0][1])
soln(input())


s = str(input())
(count, ans) = ([0] * 26, 0)
count2 = [0] * 26
dp = [[0] * 26 for i in range(26)]
for i in range(len(s)):
	count[ord(s[i]) - 97] += 1
	ans = max(ans, count[ord(s[i]) - 97])
	if i < len(s) - 1:
		for i2 in range(26):
			dp[i2][ord(s[i + 1]) - 97] += count[i2]
			if dp[i2][ord(s[i + 1]) - 97] > ans:
				ans = dp[i2][ord(s[i + 1]) - 97]
print(ans)


import sys
message = sys.stdin.readline().strip()
positions = {}
for pos in range(len(message)):
	sym = message[pos]
	try:
		positions[sym].append(pos)
	except:
		positions[sym] = [pos]
answer = 0
for sym in positions:
	answer = max(answer, len(positions[sym]))
for sym1 in positions:
	for sym2 in positions:
		lenPositions1 = len(positions[sym1])
		lenPositions2 = len(positions[sym2])
		pos1 = 0
		pos2 = 0
		tmpAnswer = 0
		while pos1 < lenPositions1 and pos2 < lenPositions2:
			while pos1 < lenPositions1 and positions[sym1][pos1] < positions[sym2][pos2]:
				tmpAnswer += lenPositions2 - pos2
				pos1 += 1
			pos2 += 1
		answer = max(answer, tmpAnswer)
		pos1 = 0
		pos2 = 0
		tmpAnswer = 0
		while pos2 < lenPositions2 and pos1 < lenPositions1:
			while pos2 < lenPositions2 and positions[sym1][pos1] > positions[sym2][pos2]:
				tmpAnswer += lenPositions1 - pos1
				pos2 += 1
			pos1 += 1
		answer = max(answer, tmpAnswer)
print(answer)


from bisect import *
from math import *
s = input()
dic = {}
for i in range(26):
	for j in range(26):
		dic[i, j] = 0
arr = [0 for i in range(26)]
for i in s:
	for j in range(26):
		dic[j, ord(i) - 97] += arr[j]
	arr[ord(i) - 97] += 1
arr.sort(reverse=True)
val = max(dic.values())
print(max(val, arr[0]))


s = input()
d = {}
for i in s:
	if i not in d:
		d[i] = 1
	else:
		d[i] = d[i] + 1
dp = [[0 for i in range(26)] for j in range(len(s))]
for i in range(len(s) - 1, -1, -1):
	if i == len(s) - 1:
		temp = [0 for j in range(26)]
		temp[ord(s[i]) - ord('a')] = 1
		dp[i] = temp
	else:
		new = [j for j in dp[i + 1]]
		new[ord(s[i]) - ord('a')] = new[ord(s[i]) - ord('a')] + 1
		dp[i] = new
new = [[0 for i in range(26)] for j in range(26)]
for i in range(len(s)):
	for j in range(26):
		if ord(s[i]) - ord('a') != j:
			new[ord(s[i]) - ord('a')][j] = new[ord(s[i]) - ord('a')][j] + dp[i][j]
		else:
			new[ord(s[i]) - ord('a')][j] = new[ord(s[i]) - ord('a')][j] + dp[i][j] - 1
maxlen = 0
for i in range(26):
	for j in range(26):
		maxlen = max(maxlen, new[i][j])
d = {}
for i in s:
	if i in d:
		d[i] = d[i] + 1
	else:
		d[i] = 1
for i in d:
	maxlen = max(maxlen, d[i])
print(maxlen)


import sys
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
mod = 10 ** 7 + 1
st = ri()
cnt = [0] * 26
cnt2 = [[0 for i in range(26)] for j in range(26)]
ans = 0
for i in range(len(st)):
	c = ord(st[i]) - ord('a')
	for j in range(26):
		cnt2[j][c] += cnt[j]
		ans = max(ans, cnt2[j][c])
	cnt[c] += 1
	ans = max(ans, cnt[c])
print(ans)


s = input()
a = [0] * 26
dp = [[0] * 26 for _ in range(26)]
for x in s:
	t = ord(x) - 97
	for i in range(26):
		dp[i][t] += a[i]
	a[t] += 1
ans = 0
for i in range(26):
	ans = max(ans, a[i])
for i in range(26):
	for j in range(26):
		ans = max(ans, dp[i][j])
print(ans)


string = input().strip()
counts = [0] * 26
pairs = [[0 for _ in range(26)] for _ in range(26)]
for i in string:
	for j in range(26):
		pairs[j][ord(i) - ord('a')] += counts[j]
	counts[ord(i) - ord('a')] += 1
ans = -1
for i in counts:
	ans = max(ans, i)
for i in pairs:
	for j in i:
		ans = max(ans, j)
print(ans)


import math

def print_matrix(mat):
	print('---')
	for i in range(len(mat)):
		for j in range(len(mat[i])):
			print(mat[i][j], end=' ')
		print()
n_latin = 26
m2 = [[0 for i in range(n_latin)] for j in range(n_latin)]
m1 = [0 for i in range(n_latin)]
message = input()
n = len(message)
for i in range(n):
	c = ord(message[i]) - ord('a')
	for j in range(n_latin):
		m2[j][c] += m1[j]
	m1[c] += 1
r1 = max(m1)
for i in range(n_latin):
	for j in range(n_latin):
		if m2[i][j] > r1:
			r1 = m2[i][j]
print(r1)


s = input().strip()
from collections import defaultdict
d = defaultdict(int)
for c in s:
	for a in 'abcdefghijklmnopqrstuvwxyz':
		d[a + c] += d[a]
	d[c] += 1
mx = 0
for key in d:
	mx = max(mx, d[key])
print(mx)


s = input().strip()
prev = [[0 for i in range(len(s))] for i in range(26)]
prev[ord(s[0]) - ord('a')][0] = 1
for index in range(1, len(s)):
	cmp = ord(s[index]) - ord('a')
	for letter in range(26):
		prev[letter][index] = prev[letter][index - 1]
	prev[cmp][index] = prev[cmp][index - 1] + 1
dp1 = [[0 for i in range(26)] for i in range(26)]
dp2 = [[0 for i in range(len(s))] for i in range(26)]
for index in range(1, len(s)):
	cur = ord(s[index]) - ord('a')
	cmp = ord(s[index - 1]) - ord('a')
	for letter in range(26):
		dp1[letter][cur] += prev[letter][index - 1]
ans = max(max([max(i) for i in dp1]), max([prev[i][len(s) - 1] for i in range(26)]))
print(ans)


import sys
input = sys.stdin.readline
Alp = [chr(i) for i in range(97, 97 + 26)]
S = list(input().rstrip())
dic = {a: 0 for a in Alp}
ansdic = {}
for a in Alp:
	ansdic[a] = {}
	for b in Alp:
		ansdic[a][b] = 0
for s in S:
	for a in Alp:
		ansdic[a][s] += dic[a]
	dic[s] += 1
ans = 0
for a in Alp:
	for b in Alp:
		ans = max(ans, ansdic[a][b])
	ans = max(ans, dic[a])
print(ans)


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():
	ss = [ord(s) - ord('a') for s in list(input())]
	lcount = [0] * 26
	tlcount = [[0] * 26 for _ in range(26)]
	for s in ss:
		for i in range(26):
			tlcount[s][i] += lcount[i]
		lcount[s] += 1
	m1 = max(lcount)
	m2 = max(map(max, tlcount))
	print(max(m1, m2))
main()


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(x, y):
	return f(x) // (f(y) * f(x - y))
s = input()
maxi = 0
dp = []
for i in range(26):
	ka = [0, 0]
	dp.append(ka)
hash = defaultdict(int)
for i in range(len(s)):
	for j in range(26):
		hash[s[i] + chr(97 + j)] += dp[j][0]
	dp[ord(s[i]) - 97][0] += 1
	maxi = max(maxi, dp[ord(s[i]) - 97][0])
for i in hash:
	maxi = max(maxi, hash[i])
print(maxi)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input().rstrip()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
s = inputstringnum()
two = [[0 for i in range(26)] for j in range(26)]
one = [0] * 26
ans = 0
for i in s:
	for j in range(26):
		two[j][i] += one[j]
		ans = max(ans, two[j][i])
	one[i] += 1
	ans = max(ans, one[i])
print(ans)


import string
s = input()
alth = string.ascii_lowercase
althpr1 = [0] * 26
althpr2 = [0] * 676
n = len(s)
for i in range(n):
	ind = alth.find(s[i])
	for j in range(26):
		althpr2[ind + j * 26] += althpr1[j]
	althpr1[ind] += 1
print(max(max(althpr1), max(althpr2)))


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	S = input()
	singles = dd(int)
	doubles = dd(int)
	for c in S:
		for (k, v) in singles.items():
			doubles[k, c] += v
		singles[c] += 1
	ans = max(singles.values())
	if len(S) > 1:
		ans = max(ans, max(doubles.values()))
	print(ans)
mode = 's'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()