import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.net.StandardSocketOptions;
import java.security.cert.CollectionCertStoreParameters;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class Main {

	public static int lowerBound(ArrayList<Integer> array, int length, long value) {
		int low = 0;
		int high = length;
		while (low < high) {
			final int mid = (low + high) / 2;
			if (value <= array.get(mid)) {
				high = mid;
			} else {
				low = mid + 1;
			}
		}
		return low;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	static long lcm(long a, long b) {
		return (a * b) / gcd(a, b);
	}

	// public static void sortbyColumn(int arr[][], int col) {
	// // Using built-in sort function Arrays.sort
	// Arrays.sort(arr, new Comparator<int[]>() {
	//
	// @Override
	// // Compare values according to columns
	// public int compare(final int[] entry1, final int[] entry2) {
	//
	// // To sort in descending order revert
	// // the '>' Operator
	// // if (entry1[col] > entry2[col])
	// // return 1;
	// // else //(entry1[col] >= entry2[col])
	// // return -1;
	// return new Integer(entry1[col]).compareTo(entry2[col]);
	// // return entry1[col].
	// }
	// }); // End of function call sort().
	// }

	static class pair {
		int V, I;

		pair(int v, int i) {
			V = v;
			I = i;
		}
	}

	public static int[] swap(int data[], int left, int right) {
		int temp = data[left];
		data[left] = data[right];
		data[right] = temp;
		return data;
	}

	public static int[] reverse(int data[], int left, int right) {
		while (left < right) {
			int temp = data[left];
			data[left++] = data[right];
			data[right--] = temp;
		}
		return data;
	}

	public static boolean findNextPermutation(int data[]) {
		if (data.length <= 1)
			return false;

		int last = data.length - 2;
		while (last >= 0) {
			if (data[last] < data[last + 1]) {
				break;
			}
			last--;
		}
		if (last < 0)
			return false;

		int nextGreater = data.length - 1;
		for (int i = data.length - 1; i > last; i--) {
			if (data[i] > data[last]) {
				nextGreater = i;
				break;
			}
		}
		data = swap(data, nextGreater, last);
		data = reverse(data, last + 1, data.length - 1);
		return true;
	}

	static long nCr(long n, long r) {
		long x = 1;
		long yu = n - r;
		while (n > r) {
			x = x * n;
			n--;
		}
		while (yu > 0) {
			x /= yu;
			yu--;
		}
		return x;
	}

	/*
	 * static boolean prime[] = new boolean[1000007];
	 *
	 * public static void sieveOfEratosthenes(int n) {
	 *
	 * for (int i = 0; i < n; i++) prime[i] = true; * for (int p = 2; p * p <=
	 * n; p++) { // If prime[p] is not changed, then it is a prime if (prime[p]
	 * == true) { // Update all multiples of p for (int i = p * p; i <= n; i +=
	 * p) prime[i] = false; } }
	 *
	 * // Print all prime numbers // for(int i = 2; i <= n; i++) // { //
	 * if(prime[i] == true) // System.out.print(i + " "); // } }
	 */

	static long power(long fac2, int y, int p) {
		long res = 1;
		fac2 = fac2 % p;
		while (y > 0) {
			if (y % 2 == 1)
				res = (res * fac2) % p;
			fac2 = (fac2 * fac2) % p;
		}
		return res;
	}

	static long modInverse(long fac2, int p) {
		return power(fac2, p - 2, p);
	}

	static boolean isPrime(int n) {
		// Corner cases
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;

		// This is checked so that we can skip
		// middle five numbers in below loop
		if (n % 2 == 0 || n % 3 == 0)
			return false;

		for (int i = 5; i * i <= n; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}

	public static BigInteger lcmm(String a, String b) {
		BigInteger s = new BigInteger(a);
		BigInteger s1 = new BigInteger(b);
		BigInteger mul = s.multiply(s1);
		BigInteger gcd = s.gcd(s1);
		BigInteger lcm = mul.divide(gcd);
		return lcm;
	}

	static long setBitNumber(long n) {
		if (n == 0)
			return 0;

		long msb = 0;
		while (n != 0) {
			n = n / 2;
			msb++;
		}

		return msb;
	}

	public static void main(String[] args) throws NumberFormatException, IOException, ScriptException {
		FastReader sc = new FastReader();
		PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// Scanner scn = new Scanner(System.in);
		//
		String s = sc.next();
		HashMap<String, Integer> h = new HashMap<>();
		int arr[] = new int[26];
		HashMap<Character, Integer> f = new HashMap<>();
		int ma = 0;
		for (int i = 0; i < s.length(); i++) {
			arr[s.charAt(i) - 97]++;
			for (int j = 0; j < 26; j++) {
				String str = "" + (char) (j + 97) + s.charAt(i);
				if((char) (j + 97) != s.charAt(i)){
				if (h.containsKey(str) == true) {
					h.put(str, h.get(str) + arr[j]);
					if (h.get(str) > ma)
						ma = h.get(str);
				} else
					h.put(str, arr[j]);
				}
			}
			if (f.containsKey(s.charAt(i)) == true) {
				f.put(s.charAt(i), f.get(s.charAt(i)) + 1);
				if (f.get(s.charAt(i)) > ma)
					ma = f.get(s.charAt(i));
			} else {
				f.put(s.charAt(i), 1);
			}
		}
		//pr.println(h);
		pr.println(Math.max(1, ma));
		//
		// coded to perfection by Rohan Mukhija
		pr.flush();
		pr.close();
	}

	static HashMap<Integer, Integer> h = new HashMap<>();

	private static boolean possible(long[] arr, int[] f, long mid, long k) {
		long c = 0;

		for (int i = 0; i < arr.length; i++) {
			if ((arr[i] * f[f.length - i - 1]) > mid) {
				c += (arr[i] - (mid / f[f.length - i - 1]));
			}
		}
		// System.out.println(mid+" "+c);
		if (c <= k)
			return true;
		return false;
	}

}


import java.util.Scanner;

public class c {
	public static void main(String[] args) {
		Scanner s = new Scanner (System.in);
		String a = s.next();
		long[][] ans = new long[26][26];
		long[] arr= new long[26];
		for(int i = a.length() -1; i>=0  ; i--) {
			for(int j = 0 ; j < 26 ; j++) {
				ans[a.charAt(i)-'a'][j]+=arr[j];
			}
			arr[a.charAt(i)-'a']++;
		}
		long max = 0 ;
		for(int i = 0 ; i<26  ; i++) {
			max = Math.max(max,arr[i]);
			for(int j = 0 ; j < 26 ; j++) {
				max = Math.max(max , ans[i][j]);
				max = Math.max(max, ans[i][j]);
			}
		}
//		for(int i = 0 ; i<26  ; i++) {
//			for(int j = 0 ; j < 26 ; j++) {
//System.out.print(ans[i][j]+" ");
//			}
//			System.out.println();
//		}
		System.out.println(max);

	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;

public class Main {
	static ArrayList<Integer> adj[];
	static PrintWriter out = new PrintWriter(System.out);
	public static long mod;

	static int [][]notmemo;
	static int k;
	static long[] a;
	static long b[];
	static int m;
	static char c[];

	static class Pair  implements Comparable<Pair>{
    	long a;
    	int b;
    	int node;
    	public Pair(long level,int b1,int n) {
		a=level;
		b=b1;
		node=n;
    	}
		@Override
		public int compareTo(Pair o) {
		if(this.a==o.a)
			return b-o.b;

		return Long.compare(o.a,a);

		}
    }
    static Pair s1[];
    static long s[];
    static ArrayList<Pair> adjlist[];
	static int n1;
	static int n2;
	static int k1;
	static int k2;
	static int skip=0;
	public static void main(String args[]) throws IOException {
		Scanner sc = new Scanner(System.in);
	String s=sc.nextLine();
	char c[]=s.toCharArray();
	long count[]=new long[26];
	for (int i = 0; i < c.length; i++) {
		count[c[i]-'a']++;
	}
	long total=1;
	HashSet<Character> set=new HashSet<>();
	for (int i = 0; i < c.length; i++) {
		if(count[c[i]-'a']!=0&&!set.contains(c[i]))
		total*=(count[c[i]-'a']);
	set.add(c[i]);
	}
	System.out.println(total);
	out.flush();
	}

	private static long lcm(long a2, long b2) {
	return (a2*b2)/gcd(a2,b2);
	}

	static Boolean zero[][];
	static int small[];
	  static void dfs(int s, int e)
	    {
	        small[s] = 1;
	        for(int  u: adj[s])
	        {
	            if(u == e)
	                continue;

	            dfs(u ,s);

	            small[s] +=small[u];
	        }
	    }

	static int idx=0;

	static long dpdp[][][][];
	static int modd=(int) 1e8;

	static class Edge implements Comparable<Edge>
	{
		int node;long cost;

		Edge(int a, long b) { node = a;	cost = b; }

		public int compareTo(Edge e){ return Long.compare(cost,e.cost);	}
	}

        static void sieve(int N)	// O(N log log N)
	{
		isComposite = new int[N+1];
		isComposite[0] = isComposite[1] = 1;			// 0 indicates a prime number
		primes = new ArrayList<Integer>();

		for (int i = 2; i <= N; ++i) 					//can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))
			if (isComposite[i] == 0) 					//can loop in 2 and odd integers for slightly better performance
			{
				primes.add(i);
				if(1l * i * i <= N)
					for (int j = i * i; j <= N; j += i)	// j = i * 2 will not affect performance too much, may alter in modified sieve
						isComposite[j] = 1;
			}
	}
    static TreeSet<Integer> factors;
    static ArrayList<Integer> primeFactors(int N)		// O(sqrt(N) / ln sqrt(N))
	{
		ArrayList<Integer> factors = new ArrayList<Integer>();		//take abs(N) in case of -ve integers
		int idx = 0, p = primes.get(idx);

		while(1l*p * p <= N)
		{
			while(N % p == 0) { factors.add(p); N /= p; }
			p = primes.get(++idx);
		}

		if(N != 1)						// last prime factor may be > sqrt(N)
			factors.add(N);				// for integers whose largest prime factor has a power of 1
		return factors;
	}

    static String y;
    	static int nomnom[];
	static long fac[];

	static class book implements Comparable<book> {
		int idx;
		long score;

		public book(int i, long s) {
			idx = i;
			score = s;
		}

		public int compareTo(book o) {
			return (int) (o.score - score);
		}
	}

	static class library implements Comparable<library> {
		int numofbooks;
		int signup;
		int shiprate;
		int idx;

		public library(int a, int b, int c, int idx) {
			numofbooks = a;
			signup = b;
			shiprate = c;
			this.idx = idx;
		}

		@Override
		public int compareTo(library o) {
		if(signup==o.signup) {
			  return o.numofbooks-numofbooks;
		}
		return signup - o.signup;

		}
	}

	static boolean isOn(int S, int j) {
		return (S & 1 << j) != 0;
	}

	static boolean f = true;

	static class SegmentTree { // 1-based DS, OOP

		int N; // the number of elements in the array as a power of 2 (i.e. after padding)
		int[] array, sTree, lazy;

		SegmentTree(int[] in) {
			array = in;
			N = in.length - 1;
			sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
			lazy = new int[N << 1];
			//build(1, 1, N);
		}

		void build(int node, int b, int e) // O(n)
		{
			if (b == e)
				sTree[node] = array[b];
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}
		}

		void update_point(int index, int val) // O(log n)
		{
			index += N - 1;
			sTree[index] = val;
			while(index>1)
			{
				index >>= 1;
				sTree[index] = Math.max(sTree[index<<1] ,sTree[index<<1|1]);
			}
		}

		void update_range(int i, int j, int val) // O(log n)
		{
			update_range(1, 1, N, i, j, val);
		}

		void update_range(int node, int b, int e, int i, int j, int val) {
			if (i > e || j < b)
				return;
			if (b >= i && e <= j) {
				sTree[node] += (e - b + 1) * val;
				lazy[node] += val;
			} else {
				int mid = b + e >> 1;
				propagate(node, b, mid, e);
				update_range(node << 1, b, mid, i, j, val);
				update_range(node << 1 | 1, mid + 1, e, i, j, val);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}

		}

		void propagate(int node, int b, int mid, int e) {
			lazy[node << 1] += lazy[node];
			lazy[node << 1 | 1] += lazy[node];
			sTree[node << 1] += (mid - b + 1) * lazy[node];
			sTree[node << 1 | 1] += (e - mid) * lazy[node];
			lazy[node] = 0;
		}

		int query(int i, int j) {
			return query(1, 1, N, i, j);
		}

		int query(int node, int b, int e, int i, int j) // O(log n)
		{
			if (i > e || j < b)
				return 0;
			if (b >= i && e <= j)
				return sTree[node];
			int mid = b + e >> 1;
			// propagate(node, b, mid, e);
			int q1 = query(node << 1, b, mid, i, j);
			int q2 = query(node << 1 | 1, mid + 1, e, i, j);
			return Math.max(q1,q2);

		}
	}

	static long[][] memo;

	static class UnionFind {
		int[] p, rank, setSize;
		int numSets;
		int max[];

		public UnionFind(int N) {
			p = new int[numSets = N];
			rank = new int[N];
			setSize = new int[N];
			for (int i = 0; i < N; i++) {
				p[i] = i;
				setSize[i] = 1;
			}
		}

		public int findSet(int i) {
			return p[i] == i ? i : (p[i] = findSet(p[i]));
		}

		public boolean isSameSet(int i, int j) {
			return findSet(i) == findSet(j);
		}
		public int chunion(int i,int j, int x2) {
			if (isSameSet(i, j))
				return 0;
			numSets--;
			int x = findSet(i), y = findSet(j);
			int z=findSet(x2);
			p[x]=z;;
			p[y]=z;
		return x;
		}

		public void unionSet(int i, int j) {
			if (isSameSet(i, j))
				return;
			numSets--;
			int x = findSet(i), y = findSet(j);
			if (rank[x] > rank[y]) {
				p[y] = x;
				setSize[x] += setSize[y];

			} else {
				p[x] = y;
				setSize[y] += setSize[x];
				if (rank[x] == rank[y])
					rank[y]++;

			}
		}

		public int numDisjointSets() {
			return numSets;
		}

		public int sizeOfSet(int i) {
			return setSize[findSet(i)];
		}
	}

	/**
	 * private static void trace(int i, int time) { if(i==n) return;
	 *
	 *
	 * long ans=dp(i,time);
	 * if(time+a[i].t<a[i].burn&&(ans==dp(i+1,time+a[i].t)+a[i].cost)) {
	 *
	 * trace(i+1, time+a[i].t);
	 *
	 * l1.add(a[i].idx); return; } trace(i+1,time);
	 *
	 * }
	 **/

	static class incpair implements Comparable<incpair> {
		int a;
		long b;
		int idx;

		incpair(int a, long dirg, int i) {
			this.a = a;
			b = dirg;
			idx = i;
		}

		public int compareTo(incpair e) {
			return (int) (b - e.b);
		}
	}

	static class decpair implements Comparable<decpair> {
		int a;
		long b;
		int idx;

		decpair(int a, long dirg, int i) {
			this.a = a;
			b = dirg;
			idx = i;
		}

		public int compareTo(decpair e) {
			return (int) (e.b - b);
		}
	}

	static long allpowers[];

	static class Quad implements Comparable<Quad> {
		int u;
		int v;
		char state;
		int turns;

		public Quad(int i, int j, char c, int k) {
			u = i;
			v = j;
			state = c;
			turns = k;
		}

		public int compareTo(Quad e) {
			return (int) (turns - e.turns);
		}

	}

	static long dirg[][];
	static Edge[] driver;

	static int n;

	static long manhatandistance(long x, long x2, long y, long y2) {
		return Math.abs(x - x2) + Math.abs(y - y2);
	}

	static long fib[];

	static long fib(int n) {
		if (n == 1 || n == 0) {
			return 1;
		}
		if (fib[n] != -1) {
			return fib[n];
		} else
			return fib[n] = ((fib(n - 2) % mod + fib(n - 1) % mod) % mod);
	}

	static class Point  implements Comparable<Point>{
		long x, y;

		Point(long counth, long counts) {
			x = counth;
			y = counts;
		}

		@Override
		public int compareTo(Point p )
		{
			return Long.compare(p.y*1l*x, p.x*1l*y);
		}

	}

	static long[][] comb;

	static class Triple implements Comparable<Triple> {

		int l;
		int r;
		long cost;
		int idx;

		public Triple(int a, int b, long l1, int l2) {
			l = a;
			r = b;
			cost = l1;
			idx = l2;
		}

		public int compareTo(Triple x) {
			if (l != x.l || idx == x.idx)
				return l - x.l;
			return -idx;
		}

	}

	static TreeSet<Long> primeFactors(long N) // O(sqrt(N) / ln sqrt(N))
	{
		TreeSet<Long> factors = new TreeSet<Long>(); // take abs(N) in case of -ve integers
		int idx = 0, p = primes.get(idx);

		while (p * p <= N) {
			while (N % p == 0) {
				factors.add((long) p);
				N /= p;
			}
			if (primes.size() > idx + 1)
				p = primes.get(++idx);
			else
				break;
		}

		if (N != 1) // last prime factor may be > sqrt(N)
			factors.add(N); // for integers whose largest prime factor has a power of 1
		return factors;
	}

	static boolean visited[];

	/**
	 * static int bfs(int s) { Queue<Integer> q = new LinkedList<Integer>();
	 * q.add(s); int count=0; int maxcost=0; int dist[]=new int[n]; dist[s]=0;
	 * while(!q.isEmpty()) {
	 *
	 * int u = q.remove(); if(dist[u]==k) { break; } for(Pair v: adj[u]) {
	 * maxcost=Math.max(maxcost, v.cost);
	 *
	 *
	 *
	 * if(!visited[v.v]) {
	 *
	 * visited[v.v]=true; q.add(v.v); dist[v.v]=dist[u]+1; maxcost=Math.max(maxcost,
	 * v.cost); } }
	 *
	 * } return maxcost; }
	 **/
	public static boolean FindAllElements(int n, int k) {
		int sum = k;
		int[] A = new int[k];
		Arrays.fill(A, 0, k, 1);

		for (int i = k - 1; i >= 0; --i) {

			while (sum + A[i] <= n) {

				sum += A[i];
				A[i] *= 2;
			}
		}
		if (sum == n) {
			return true;
		} else
			return false;
	}

	static boolean[] vis2;

	static boolean f2 = false;

	static long[][] matMul(long[][] a2, long[][] b, int p, int q, int r) // C(p x r) = A(p x q) x (q x r) -- O(p x q x
																			// r)
	{
		long[][] C = new long[p][r];
		for (int i = 0; i < p; ++i) {
			for (int j = 0; j < r; ++j) {
				for (int k = 0; k < q; ++k) {
					C[i][j] = (C[i][j] + (a2[i][k] % mod * b[k][j] % mod)) % mod;
					C[i][j] %= mod;
				}

			}
		}
		return C;
	}
	public static int[] schuffle(int[] a2) {
		for (int i = 0; i < a2.length; i++) {
			int x =  (int) (Math.random() * a2.length);
			int temp = a2[x];
			a2[x] = a2[i];
			a2[i] = temp;
		}
		return a2;
	}

	static int memo1[];

	static boolean vis[];
	static TreeSet<Integer> set = new TreeSet<Integer>();

	static long modPow(long ways, long count, long mod) // O(log e)
	{
		ways %= mod;
		long res = 1;
		while (count > 0) {
			if ((count & 1) == 1)
				res = (res * ways) % mod;
			ways = (ways * ways) % mod;
			count >>= 1;
		}
		return res % mod;
	}

	static long gcd(long ans, long b) {
		if (b == 0) {
			return ans;
		}
		return gcd(b, ans % b);
	}

	static int[] isComposite;
	static int[] valid;

	static ArrayList<Integer> primes;
	static ArrayList<Integer> l1;

	static TreeSet<Integer> primus = new TreeSet<Integer>();

	static void sieveLinear(int N)
	{
		int[] lp = new int[N + 1];								//lp[i] = least prime divisor of i
		for(int i = 2; i <= N; ++i)
		{
			if(lp[i] == 0)
			{
				primus.add(i);
				lp[i] = i;
			}
			int curLP = lp[i];
			for(int p: primus)
				if(p > curLP || p * i > N)
					break;
				else
					lp[p * i] = i;
		}
	}

	public static long[] schuffle(long[] a2) {
		for (int i = 0; i < a2.length; i++) {
			int x =  (int) (Math.random() * a2.length);
			long temp = a2[x];
			a2[x] = a2[i];
			a2[i] = temp;
		}
		return a2;
	}

	static int V;
	static long INF = (long) 1E16;

	static class Edge2 {
		int node;
		long cost;
		long next;

		Edge2(int a, int c, Long long1) {
			node = a;
			cost = long1;
			next = c;
		}

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}

		public int[] nxtArr(int n) throws IOException {
			int[] ans = new int[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextInt();
			return ans;
		}

	}
	public static int[] sortarray(int a[]) {
		schuffle(a);
		Arrays.sort(a);
		return a;
		}
		public static long[] sortarray(long a[]) {
			schuffle(a);
			Arrays.sort(a);
			return a;
		}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;

public class Main {
	static ArrayList<Integer> adj[];
	static PrintWriter out = new PrintWriter(System.out);
	public static long mod;

	static int [][]notmemo;
	static int k;
	static long[] a;
	static long b[];
	static int m;
	static char c[];

	static class Pair  implements Comparable<Pair>{
    	long a;
    	int b;
    	int node;
    	public Pair(long level,int b1,int n) {
		a=level;
		b=b1;
		node=n;
    	}
		@Override
		public int compareTo(Pair o) {
		if(this.a==o.a)
			return b-o.b;

		return Long.compare(o.a,a);

		}
    }
    static Pair s1[];
    static long s[];
    static ArrayList<Pair> adjlist[];
	static int n1;
	static int n2;
	static int k1;
	static int k2;
	static int skip=0;
	public static void main(String args[]) throws IOException {
		Scanner sc = new Scanner(System.in);
	String s=sc.nextLine();
	int n=s.length();
	char c[]=s.toCharArray();
	long count[]=new long[26];
	long cc[][]=new long[26][26];
	for (int i = 0; i < c.length; i++) {
		for (int j = 0; j < cc.length; j++) {
			cc[i][j]+=count[j];
		}
		count[c[i]-'a']++;
	}
	long ans=0;

	for (int i = 0; i < count.length; i++) {
		ans=Math.max(ans,count[i]);
	}
	for (int i = 0; i < cc.length; i++) {
		for (int j = 0; j < cc.length; j++) {
			ans=Math.max(ans,(cc[i][j]*(cc[i][j]+1)/2));
		}
	}
	System.out.println(ans );
	}

	private static long lcm(long a2, long b2) {
	return (a2*b2)/gcd(a2,b2);
	}

	static Boolean zero[][];
	static int small[];
	  static void dfs(int s, int e)
	    {
	        small[s] = 1;
	        for(int  u: adj[s])
	        {
	            if(u == e)
	                continue;

	            dfs(u ,s);

	            small[s] +=small[u];
	        }
	    }

	static int idx=0;

	static long dpdp[][][][];
	static int modd=(int) 1e8;

	static class Edge implements Comparable<Edge>
	{
		int node;long cost;

		Edge(int a, long b) { node = a;	cost = b; }

		public int compareTo(Edge e){ return Long.compare(cost,e.cost);	}
	}

        static void sieve(int N)	// O(N log log N)
	{
		isComposite = new int[N+1];
		isComposite[0] = isComposite[1] = 1;			// 0 indicates a prime number
		primes = new ArrayList<Integer>();

		for (int i = 2; i <= N; ++i) 					//can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))
			if (isComposite[i] == 0) 					//can loop in 2 and odd integers for slightly better performance
			{
				primes.add(i);
				if(1l * i * i <= N)
					for (int j = i * i; j <= N; j += i)	// j = i * 2 will not affect performance too much, may alter in modified sieve
						isComposite[j] = 1;
			}
	}
    static TreeSet<Integer> factors;
    static ArrayList<Integer> primeFactors(int N)		// O(sqrt(N) / ln sqrt(N))
	{
		ArrayList<Integer> factors = new ArrayList<Integer>();		//take abs(N) in case of -ve integers
		int idx = 0, p = primes.get(idx);

		while(1l*p * p <= N)
		{
			while(N % p == 0) { factors.add(p); N /= p; }
			p = primes.get(++idx);
		}

		if(N != 1)						// last prime factor may be > sqrt(N)
			factors.add(N);				// for integers whose largest prime factor has a power of 1
		return factors;
	}

    static String y;
    	static int nomnom[];
	static long fac[];

	static class book implements Comparable<book> {
		int idx;
		long score;

		public book(int i, long s) {
			idx = i;
			score = s;
		}

		public int compareTo(book o) {
			return (int) (o.score - score);
		}
	}

	static class library implements Comparable<library> {
		int numofbooks;
		int signup;
		int shiprate;
		int idx;

		public library(int a, int b, int c, int idx) {
			numofbooks = a;
			signup = b;
			shiprate = c;
			this.idx = idx;
		}

		@Override
		public int compareTo(library o) {
		if(signup==o.signup) {
			  return o.numofbooks-numofbooks;
		}
		return signup - o.signup;

		}
	}

	static boolean isOn(int S, int j) {
		return (S & 1 << j) != 0;
	}

	static boolean f = true;

	static class SegmentTree { // 1-based DS, OOP

		int N; // the number of elements in the array as a power of 2 (i.e. after padding)
		int[] array, sTree, lazy;

		SegmentTree(int[] in) {
			array = in;
			N = in.length - 1;
			sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
			lazy = new int[N << 1];
			//build(1, 1, N);
		}

		void build(int node, int b, int e) // O(n)
		{
			if (b == e)
				sTree[node] = array[b];
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}
		}

		void update_point(int index, int val) // O(log n)
		{
			index += N - 1;
			sTree[index] = val;
			while(index>1)
			{
				index >>= 1;
				sTree[index] = Math.max(sTree[index<<1] ,sTree[index<<1|1]);
			}
		}

		void update_range(int i, int j, int val) // O(log n)
		{
			update_range(1, 1, N, i, j, val);
		}

		void update_range(int node, int b, int e, int i, int j, int val) {
			if (i > e || j < b)
				return;
			if (b >= i && e <= j) {
				sTree[node] += (e - b + 1) * val;
				lazy[node] += val;
			} else {
				int mid = b + e >> 1;
				propagate(node, b, mid, e);
				update_range(node << 1, b, mid, i, j, val);
				update_range(node << 1 | 1, mid + 1, e, i, j, val);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}

		}

		void propagate(int node, int b, int mid, int e) {
			lazy[node << 1] += lazy[node];
			lazy[node << 1 | 1] += lazy[node];
			sTree[node << 1] += (mid - b + 1) * lazy[node];
			sTree[node << 1 | 1] += (e - mid) * lazy[node];
			lazy[node] = 0;
		}

		int query(int i, int j) {
			return query(1, 1, N, i, j);
		}

		int query(int node, int b, int e, int i, int j) // O(log n)
		{
			if (i > e || j < b)
				return 0;
			if (b >= i && e <= j)
				return sTree[node];
			int mid = b + e >> 1;
			// propagate(node, b, mid, e);
			int q1 = query(node << 1, b, mid, i, j);
			int q2 = query(node << 1 | 1, mid + 1, e, i, j);
			return Math.max(q1,q2);

		}
	}

	static long[][] memo;

	static class UnionFind {
		int[] p, rank, setSize;
		int numSets;
		int max[];

		public UnionFind(int N) {
			p = new int[numSets = N];
			rank = new int[N];
			setSize = new int[N];
			for (int i = 0; i < N; i++) {
				p[i] = i;
				setSize[i] = 1;
			}
		}

		public int findSet(int i) {
			return p[i] == i ? i : (p[i] = findSet(p[i]));
		}

		public boolean isSameSet(int i, int j) {
			return findSet(i) == findSet(j);
		}
		public int chunion(int i,int j, int x2) {
			if (isSameSet(i, j))
				return 0;
			numSets--;
			int x = findSet(i), y = findSet(j);
			int z=findSet(x2);
			p[x]=z;;
			p[y]=z;
		return x;
		}

		public void unionSet(int i, int j) {
			if (isSameSet(i, j))
				return;
			numSets--;
			int x = findSet(i), y = findSet(j);
			if (rank[x] > rank[y]) {
				p[y] = x;
				setSize[x] += setSize[y];

			} else {
				p[x] = y;
				setSize[y] += setSize[x];
				if (rank[x] == rank[y])
					rank[y]++;

			}
		}

		public int numDisjointSets() {
			return numSets;
		}

		public int sizeOfSet(int i) {
			return setSize[findSet(i)];
		}
	}

	/**
	 * private static void trace(int i, int time) { if(i==n) return;
	 *
	 *
	 * long ans=dp(i,time);
	 * if(time+a[i].t<a[i].burn&&(ans==dp(i+1,time+a[i].t)+a[i].cost)) {
	 *
	 * trace(i+1, time+a[i].t);
	 *
	 * l1.add(a[i].idx); return; } trace(i+1,time);
	 *
	 * }
	 **/

	static class incpair implements Comparable<incpair> {
		int a;
		long b;
		int idx;

		incpair(int a, long dirg, int i) {
			this.a = a;
			b = dirg;
			idx = i;
		}

		public int compareTo(incpair e) {
			return (int) (b - e.b);
		}
	}

	static class decpair implements Comparable<decpair> {
		int a;
		long b;
		int idx;

		decpair(int a, long dirg, int i) {
			this.a = a;
			b = dirg;
			idx = i;
		}

		public int compareTo(decpair e) {
			return (int) (e.b - b);
		}
	}

	static long allpowers[];

	static class Quad implements Comparable<Quad> {
		int u;
		int v;
		char state;
		int turns;

		public Quad(int i, int j, char c, int k) {
			u = i;
			v = j;
			state = c;
			turns = k;
		}

		public int compareTo(Quad e) {
			return (int) (turns - e.turns);
		}

	}

	static long dirg[][];
	static Edge[] driver;

	static int n;

	static long manhatandistance(long x, long x2, long y, long y2) {
		return Math.abs(x - x2) + Math.abs(y - y2);
	}

	static long fib[];

	static long fib(int n) {
		if (n == 1 || n == 0) {
			return 1;
		}
		if (fib[n] != -1) {
			return fib[n];
		} else
			return fib[n] = ((fib(n - 2) % mod + fib(n - 1) % mod) % mod);
	}

	static class Point  implements Comparable<Point>{
		long x, y;

		Point(long counth, long counts) {
			x = counth;
			y = counts;
		}

		@Override
		public int compareTo(Point p )
		{
			return Long.compare(p.y*1l*x, p.x*1l*y);
		}

	}

	static long[][] comb;

	static class Triple implements Comparable<Triple> {

		int l;
		int r;
		long cost;
		int idx;

		public Triple(int a, int b, long l1, int l2) {
			l = a;
			r = b;
			cost = l1;
			idx = l2;
		}

		public int compareTo(Triple x) {
			if (l != x.l || idx == x.idx)
				return l - x.l;
			return -idx;
		}

	}

	static TreeSet<Long> primeFactors(long N) // O(sqrt(N) / ln sqrt(N))
	{
		TreeSet<Long> factors = new TreeSet<Long>(); // take abs(N) in case of -ve integers
		int idx = 0, p = primes.get(idx);

		while (p * p <= N) {
			while (N % p == 0) {
				factors.add((long) p);
				N /= p;
			}
			if (primes.size() > idx + 1)
				p = primes.get(++idx);
			else
				break;
		}

		if (N != 1) // last prime factor may be > sqrt(N)
			factors.add(N); // for integers whose largest prime factor has a power of 1
		return factors;
	}

	static boolean visited[];

	/**
	 * static int bfs(int s) { Queue<Integer> q = new LinkedList<Integer>();
	 * q.add(s); int count=0; int maxcost=0; int dist[]=new int[n]; dist[s]=0;
	 * while(!q.isEmpty()) {
	 *
	 * int u = q.remove(); if(dist[u]==k) { break; } for(Pair v: adj[u]) {
	 * maxcost=Math.max(maxcost, v.cost);
	 *
	 *
	 *
	 * if(!visited[v.v]) {
	 *
	 * visited[v.v]=true; q.add(v.v); dist[v.v]=dist[u]+1; maxcost=Math.max(maxcost,
	 * v.cost); } }
	 *
	 * } return maxcost; }
	 **/
	public static boolean FindAllElements(int n, int k) {
		int sum = k;
		int[] A = new int[k];
		Arrays.fill(A, 0, k, 1);

		for (int i = k - 1; i >= 0; --i) {

			while (sum + A[i] <= n) {

				sum += A[i];
				A[i] *= 2;
			}
		}
		if (sum == n) {
			return true;
		} else
			return false;
	}

	static boolean[] vis2;

	static boolean f2 = false;

	static long[][] matMul(long[][] a2, long[][] b, int p, int q, int r) // C(p x r) = A(p x q) x (q x r) -- O(p x q x
																			// r)
	{
		long[][] C = new long[p][r];
		for (int i = 0; i < p; ++i) {
			for (int j = 0; j < r; ++j) {
				for (int k = 0; k < q; ++k) {
					C[i][j] = (C[i][j] + (a2[i][k] % mod * b[k][j] % mod)) % mod;
					C[i][j] %= mod;
				}

			}
		}
		return C;
	}
	public static int[] schuffle(int[] a2) {
		for (int i = 0; i < a2.length; i++) {
			int x =  (int) (Math.random() * a2.length);
			int temp = a2[x];
			a2[x] = a2[i];
			a2[i] = temp;
		}
		return a2;
	}

	static int memo1[];

	static boolean vis[];
	static TreeSet<Integer> set = new TreeSet<Integer>();

	static long modPow(long ways, long count, long mod) // O(log e)
	{
		ways %= mod;
		long res = 1;
		while (count > 0) {
			if ((count & 1) == 1)
				res = (res * ways) % mod;
			ways = (ways * ways) % mod;
			count >>= 1;
		}
		return res % mod;
	}

	static long gcd(long ans, long b) {
		if (b == 0) {
			return ans;
		}
		return gcd(b, ans % b);
	}

	static int[] isComposite;
	static int[] valid;

	static ArrayList<Integer> primes;
	static ArrayList<Integer> l1;

	static TreeSet<Integer> primus = new TreeSet<Integer>();

	static void sieveLinear(int N)
	{
		int[] lp = new int[N + 1];								//lp[i] = least prime divisor of i
		for(int i = 2; i <= N; ++i)
		{
			if(lp[i] == 0)
			{
				primus.add(i);
				lp[i] = i;
			}
			int curLP = lp[i];
			for(int p: primus)
				if(p > curLP || p * i > N)
					break;
				else
					lp[p * i] = i;
		}
	}

	public static long[] schuffle(long[] a2) {
		for (int i = 0; i < a2.length; i++) {
			int x =  (int) (Math.random() * a2.length);
			long temp = a2[x];
			a2[x] = a2[i];
			a2[i] = temp;
		}
		return a2;
	}

	static int V;
	static long INF = (long) 1E16;

	static class Edge2 {
		int node;
		long cost;
		long next;

		Edge2(int a, int c, Long long1) {
			node = a;
			cost = long1;
			next = c;
		}

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}

		public int[] nxtArr(int n) throws IOException {
			int[] ans = new int[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextInt();
			return ans;
		}

	}
	public static int[] sortarray(int a[]) {
		schuffle(a);
		Arrays.sort(a);
		return a;
		}
		public static long[] sortarray(long a[]) {
			schuffle(a);
			Arrays.sort(a);
			return a;
		}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;

public class Main {
	static ArrayList<Integer> adj[];
	static PrintWriter out = new PrintWriter(System.out);
	public static long mod;

	static int [][]notmemo;
	static int k;
	static long[] a;
	static long b[];
	static int m;
	static char c[];

	static class Pair  implements Comparable<Pair>{
    	long a;
    	int b;
    	int node;
    	public Pair(long level,int b1,int n) {
		a=level;
		b=b1;
		node=n;
    	}
		@Override
		public int compareTo(Pair o) {
		if(this.a==o.a)
			return b-o.b;

		return Long.compare(o.a,a);

		}
    }
    static Pair s1[];
    static long s[];
    static ArrayList<Pair> adjlist[];
	static int n1;
	static int n2;
	static int k1;
	static int k2;
	static int skip=0;
	public static void main(String args[]) throws IOException {
		Scanner sc = new Scanner(System.in);
	String s=sc.nextLine();
	int n=s.length();
	char c[]=s.toCharArray();
	long count[]=new long[26];
	long cc[][]=new long[26][26];
	for (int i = 0; i < c.length; i++) {
		for (int j = 0; j < cc.length; j++) {
			cc[c[i]-'a'][j]+=count[j];
		}
		count[c[i]-'a']++;
	}
	long ans=0;

	for (int i = 0; i < count.length; i++) {
		ans=Math.max(ans,count[i]);
	}
	for (int i = 0; i < cc.length; i++) {
		for (int j = 0; j < cc.length; j++) {
			ans=Math.max(ans,cc[i][j]);
		}
	}
	System.out.println(ans );
	}

	private static long lcm(long a2, long b2) {
	return (a2*b2)/gcd(a2,b2);
	}

	static Boolean zero[][];
	static int small[];
	  static void dfs(int s, int e)
	    {
	        small[s] = 1;
	        for(int  u: adj[s])
	        {
	            if(u == e)
	                continue;

	            dfs(u ,s);

	            small[s] +=small[u];
	        }
	    }

	static int idx=0;

	static long dpdp[][][][];
	static int modd=(int) 1e8;

	static class Edge implements Comparable<Edge>
	{
		int node;long cost;

		Edge(int a, long b) { node = a;	cost = b; }

		public int compareTo(Edge e){ return Long.compare(cost,e.cost);	}
	}

        static void sieve(int N)	// O(N log log N)
	{
		isComposite = new int[N+1];
		isComposite[0] = isComposite[1] = 1;			// 0 indicates a prime number
		primes = new ArrayList<Integer>();

		for (int i = 2; i <= N; ++i) 					//can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))
			if (isComposite[i] == 0) 					//can loop in 2 and odd integers for slightly better performance
			{
				primes.add(i);
				if(1l * i * i <= N)
					for (int j = i * i; j <= N; j += i)	// j = i * 2 will not affect performance too much, may alter in modified sieve
						isComposite[j] = 1;
			}
	}
    static TreeSet<Integer> factors;
    static ArrayList<Integer> primeFactors(int N)		// O(sqrt(N) / ln sqrt(N))
	{
		ArrayList<Integer> factors = new ArrayList<Integer>();		//take abs(N) in case of -ve integers
		int idx = 0, p = primes.get(idx);

		while(1l*p * p <= N)
		{
			while(N % p == 0) { factors.add(p); N /= p; }
			p = primes.get(++idx);
		}

		if(N != 1)						// last prime factor may be > sqrt(N)
			factors.add(N);				// for integers whose largest prime factor has a power of 1
		return factors;
	}

    static String y;
    	static int nomnom[];
	static long fac[];

	static class book implements Comparable<book> {
		int idx;
		long score;

		public book(int i, long s) {
			idx = i;
			score = s;
		}

		public int compareTo(book o) {
			return (int) (o.score - score);
		}
	}

	static class library implements Comparable<library> {
		int numofbooks;
		int signup;
		int shiprate;
		int idx;

		public library(int a, int b, int c, int idx) {
			numofbooks = a;
			signup = b;
			shiprate = c;
			this.idx = idx;
		}

		@Override
		public int compareTo(library o) {
		if(signup==o.signup) {
			  return o.numofbooks-numofbooks;
		}
		return signup - o.signup;

		}
	}

	static boolean isOn(int S, int j) {
		return (S & 1 << j) != 0;
	}

	static boolean f = true;

	static class SegmentTree { // 1-based DS, OOP

		int N; // the number of elements in the array as a power of 2 (i.e. after padding)
		int[] array, sTree, lazy;

		SegmentTree(int[] in) {
			array = in;
			N = in.length - 1;
			sTree = new int[N << 1]; // no. of nodes = 2*N - 1, we add one to cross out index zero
			lazy = new int[N << 1];
			//build(1, 1, N);
		}

		void build(int node, int b, int e) // O(n)
		{
			if (b == e)
				sTree[node] = array[b];
			else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}
		}

		void update_point(int index, int val) // O(log n)
		{
			index += N - 1;
			sTree[index] = val;
			while(index>1)
			{
				index >>= 1;
				sTree[index] = Math.max(sTree[index<<1] ,sTree[index<<1|1]);
			}
		}

		void update_range(int i, int j, int val) // O(log n)
		{
			update_range(1, 1, N, i, j, val);
		}

		void update_range(int node, int b, int e, int i, int j, int val) {
			if (i > e || j < b)
				return;
			if (b >= i && e <= j) {
				sTree[node] += (e - b + 1) * val;
				lazy[node] += val;
			} else {
				int mid = b + e >> 1;
				propagate(node, b, mid, e);
				update_range(node << 1, b, mid, i, j, val);
				update_range(node << 1 | 1, mid + 1, e, i, j, val);
				sTree[node] = sTree[node << 1] + sTree[node << 1 | 1];
			}

		}

		void propagate(int node, int b, int mid, int e) {
			lazy[node << 1] += lazy[node];
			lazy[node << 1 | 1] += lazy[node];
			sTree[node << 1] += (mid - b + 1) * lazy[node];
			sTree[node << 1 | 1] += (e - mid) * lazy[node];
			lazy[node] = 0;
		}

		int query(int i, int j) {
			return query(1, 1, N, i, j);
		}

		int query(int node, int b, int e, int i, int j) // O(log n)
		{
			if (i > e || j < b)
				return 0;
			if (b >= i && e <= j)
				return sTree[node];
			int mid = b + e >> 1;
			// propagate(node, b, mid, e);
			int q1 = query(node << 1, b, mid, i, j);
			int q2 = query(node << 1 | 1, mid + 1, e, i, j);
			return Math.max(q1,q2);

		}
	}

	static long[][] memo;

	static class UnionFind {
		int[] p, rank, setSize;
		int numSets;
		int max[];

		public UnionFind(int N) {
			p = new int[numSets = N];
			rank = new int[N];
			setSize = new int[N];
			for (int i = 0; i < N; i++) {
				p[i] = i;
				setSize[i] = 1;
			}
		}

		public int findSet(int i) {
			return p[i] == i ? i : (p[i] = findSet(p[i]));
		}

		public boolean isSameSet(int i, int j) {
			return findSet(i) == findSet(j);
		}
		public int chunion(int i,int j, int x2) {
			if (isSameSet(i, j))
				return 0;
			numSets--;
			int x = findSet(i), y = findSet(j);
			int z=findSet(x2);
			p[x]=z;;
			p[y]=z;
		return x;
		}

		public void unionSet(int i, int j) {
			if (isSameSet(i, j))
				return;
			numSets--;
			int x = findSet(i), y = findSet(j);
			if (rank[x] > rank[y]) {
				p[y] = x;
				setSize[x] += setSize[y];

			} else {
				p[x] = y;
				setSize[y] += setSize[x];
				if (rank[x] == rank[y])
					rank[y]++;

			}
		}

		public int numDisjointSets() {
			return numSets;
		}

		public int sizeOfSet(int i) {
			return setSize[findSet(i)];
		}
	}

	/**
	 * private static void trace(int i, int time) { if(i==n) return;
	 *
	 *
	 * long ans=dp(i,time);
	 * if(time+a[i].t<a[i].burn&&(ans==dp(i+1,time+a[i].t)+a[i].cost)) {
	 *
	 * trace(i+1, time+a[i].t);
	 *
	 * l1.add(a[i].idx); return; } trace(i+1,time);
	 *
	 * }
	 **/

	static class incpair implements Comparable<incpair> {
		int a;
		long b;
		int idx;

		incpair(int a, long dirg, int i) {
			this.a = a;
			b = dirg;
			idx = i;
		}

		public int compareTo(incpair e) {
			return (int) (b - e.b);
		}
	}

	static class decpair implements Comparable<decpair> {
		int a;
		long b;
		int idx;

		decpair(int a, long dirg, int i) {
			this.a = a;
			b = dirg;
			idx = i;
		}

		public int compareTo(decpair e) {
			return (int) (e.b - b);
		}
	}

	static long allpowers[];

	static class Quad implements Comparable<Quad> {
		int u;
		int v;
		char state;
		int turns;

		public Quad(int i, int j, char c, int k) {
			u = i;
			v = j;
			state = c;
			turns = k;
		}

		public int compareTo(Quad e) {
			return (int) (turns - e.turns);
		}

	}

	static long dirg[][];
	static Edge[] driver;

	static int n;

	static long manhatandistance(long x, long x2, long y, long y2) {
		return Math.abs(x - x2) + Math.abs(y - y2);
	}

	static long fib[];

	static long fib(int n) {
		if (n == 1 || n == 0) {
			return 1;
		}
		if (fib[n] != -1) {
			return fib[n];
		} else
			return fib[n] = ((fib(n - 2) % mod + fib(n - 1) % mod) % mod);
	}

	static class Point  implements Comparable<Point>{
		long x, y;

		Point(long counth, long counts) {
			x = counth;
			y = counts;
		}

		@Override
		public int compareTo(Point p )
		{
			return Long.compare(p.y*1l*x, p.x*1l*y);
		}

	}

	static long[][] comb;

	static class Triple implements Comparable<Triple> {

		int l;
		int r;
		long cost;
		int idx;

		public Triple(int a, int b, long l1, int l2) {
			l = a;
			r = b;
			cost = l1;
			idx = l2;
		}

		public int compareTo(Triple x) {
			if (l != x.l || idx == x.idx)
				return l - x.l;
			return -idx;
		}

	}

	static TreeSet<Long> primeFactors(long N) // O(sqrt(N) / ln sqrt(N))
	{
		TreeSet<Long> factors = new TreeSet<Long>(); // take abs(N) in case of -ve integers
		int idx = 0, p = primes.get(idx);

		while (p * p <= N) {
			while (N % p == 0) {
				factors.add((long) p);
				N /= p;
			}
			if (primes.size() > idx + 1)
				p = primes.get(++idx);
			else
				break;
		}

		if (N != 1) // last prime factor may be > sqrt(N)
			factors.add(N); // for integers whose largest prime factor has a power of 1
		return factors;
	}

	static boolean visited[];

	/**
	 * static int bfs(int s) { Queue<Integer> q = new LinkedList<Integer>();
	 * q.add(s); int count=0; int maxcost=0; int dist[]=new int[n]; dist[s]=0;
	 * while(!q.isEmpty()) {
	 *
	 * int u = q.remove(); if(dist[u]==k) { break; } for(Pair v: adj[u]) {
	 * maxcost=Math.max(maxcost, v.cost);
	 *
	 *
	 *
	 * if(!visited[v.v]) {
	 *
	 * visited[v.v]=true; q.add(v.v); dist[v.v]=dist[u]+1; maxcost=Math.max(maxcost,
	 * v.cost); } }
	 *
	 * } return maxcost; }
	 **/
	public static boolean FindAllElements(int n, int k) {
		int sum = k;
		int[] A = new int[k];
		Arrays.fill(A, 0, k, 1);

		for (int i = k - 1; i >= 0; --i) {

			while (sum + A[i] <= n) {

				sum += A[i];
				A[i] *= 2;
			}
		}
		if (sum == n) {
			return true;
		} else
			return false;
	}

	static boolean[] vis2;

	static boolean f2 = false;

	static long[][] matMul(long[][] a2, long[][] b, int p, int q, int r) // C(p x r) = A(p x q) x (q x r) -- O(p x q x
																			// r)
	{
		long[][] C = new long[p][r];
		for (int i = 0; i < p; ++i) {
			for (int j = 0; j < r; ++j) {
				for (int k = 0; k < q; ++k) {
					C[i][j] = (C[i][j] + (a2[i][k] % mod * b[k][j] % mod)) % mod;
					C[i][j] %= mod;
				}

			}
		}
		return C;
	}
	public static int[] schuffle(int[] a2) {
		for (int i = 0; i < a2.length; i++) {
			int x =  (int) (Math.random() * a2.length);
			int temp = a2[x];
			a2[x] = a2[i];
			a2[i] = temp;
		}
		return a2;
	}

	static int memo1[];

	static boolean vis[];
	static TreeSet<Integer> set = new TreeSet<Integer>();

	static long modPow(long ways, long count, long mod) // O(log e)
	{
		ways %= mod;
		long res = 1;
		while (count > 0) {
			if ((count & 1) == 1)
				res = (res * ways) % mod;
			ways = (ways * ways) % mod;
			count >>= 1;
		}
		return res % mod;
	}

	static long gcd(long ans, long b) {
		if (b == 0) {
			return ans;
		}
		return gcd(b, ans % b);
	}

	static int[] isComposite;
	static int[] valid;

	static ArrayList<Integer> primes;
	static ArrayList<Integer> l1;

	static TreeSet<Integer> primus = new TreeSet<Integer>();

	static void sieveLinear(int N)
	{
		int[] lp = new int[N + 1];								//lp[i] = least prime divisor of i
		for(int i = 2; i <= N; ++i)
		{
			if(lp[i] == 0)
			{
				primus.add(i);
				lp[i] = i;
			}
			int curLP = lp[i];
			for(int p: primus)
				if(p > curLP || p * i > N)
					break;
				else
					lp[p * i] = i;
		}
	}

	public static long[] schuffle(long[] a2) {
		for (int i = 0; i < a2.length; i++) {
			int x =  (int) (Math.random() * a2.length);
			long temp = a2[x];
			a2[x] = a2[i];
			a2[i] = temp;
		}
		return a2;
	}

	static int V;
	static long INF = (long) 1E16;

	static class Edge2 {
		int node;
		long cost;
		long next;

		Edge2(int a, int c, Long long1) {
			node = a;
			cost = long1;
			next = c;
		}

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}

		public int[] nxtArr(int n) throws IOException {
			int[] ans = new int[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextInt();
			return ans;
		}

	}
	public static int[] sortarray(int a[]) {
		schuffle(a);
		Arrays.sort(a);
		return a;
		}
		public static long[] sortarray(long a[]) {
			schuffle(a);
			Arrays.sort(a);
			return a;
		}
}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class CowAndMessage1307C {
    public static int occurencesCount(char[] msg) {
        Map<String, Integer> freq = new HashMap<>();
        for (char c: msg) {
            String s = Character.toString(c);
            if (freq.containsKey(s)) {
                freq.put(s, freq.get(s) + 1);
            } else {
                freq.put(s, 1);
            }
        }
        for (int i = 0; i < msg.length; i++) {
            for (int step = 1; step < (msg.length - i); step++) {
                String res = String.valueOf(msg[i]) +
                        msg[i + step];
                if (freq.containsKey(res)) {
                    freq.put(res, freq.get(res) + 1);
                } else {
                    freq.put(res, 1);
                }
            }

        }
        int maxFreq = 0;
        for (int value: freq.values()) {
            if (value > maxFreq) {
                maxFreq = value;
            }
        }
        return maxFreq;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String msg = in.nextLine();
        System.out.println(occurencesCount(msg.toCharArray()));
    }
}


import java.util.Scanner;

public class CowAndMessage1307C {
    public static int occurencesCount(char[] msg) {
        int[] freq1 = new int[26];
        int[][] freq2 = new int[26][26];
        int pos;
        for (int i = 0; i < msg.length; i++) {
            pos = msg[i] - 'a';
            // буква является завершением для всех последовательностей длины 2, начала которых уже посчитаны в freq1
            for (int j = 0; j < 26; j++) {
                freq2[j][pos] += freq1[j];
            }
            freq1[pos]++;
        }
        int maxFreq = 0;
        for (int i = 0; i < 26; i++) {
            if (freq1[i] > maxFreq) {
                maxFreq = freq1[i];
            }
            for (int j = 0; j < 26; j++) {
                if (freq2[i][j] > maxFreq) {
                    maxFreq = freq2[i][j];
                }
            }
        }
        return maxFreq;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String msg = in.nextLine();
        System.out.println(occurencesCount(msg.toCharArray()));
    }
}


import java.util.Scanner;

public class CowAndMessage1307C {
    public static long occurencesCount(char[] msg) {
        long[] freq1 = new long[26];
        long[][] freq2 = new long[26][26];
        int pos;
        for (int i = 0; i < msg.length; i++) {
            pos = msg[i] - 'a';
            // буква является завершением для всех последовательностей длины 2, начала которых уже посчитаны в freq1
            for (int j = 0; j < 26; j++) {
                freq2[j][pos] += freq1[j];
            }
            freq1[pos]++;
        }
        long maxFreq = 0;
        for (int i = 0; i < 26; i++) {
            if (freq1[i] > maxFreq) {
                maxFreq = freq1[i];
            }
            for (int j = 0; j < 26; j++) {
                if (freq2[i][j] > maxFreq) {
                    maxFreq = freq2[i][j];
                }
            }
        }
        return maxFreq;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String msg = in.nextLine();
        System.out.println(occurencesCount(msg.toCharArray()));
    }
}


import java.util.Scanner;

public class CowAndMessage1307C {
    public static int occurencesCount(char[] msg) {
        int[] freq1 = new int[26];
        int[][] freq2 = new int[26][26];
        for (int i = 0; i < msg.length; i++) {
            freq1[msg[i] - 'a']++;
            for (int step = 1; step < (msg.length - i); step++) {
                freq2[msg[i] - 'a'][msg[i + step] - 'a']++;
            }

        }
        int maxFreq = 0;
        for (int count: freq1) {
            if (count > maxFreq) {
                maxFreq = count;
            }
        }
        for (int i = 0; i < 26; i++) {
            for (int j = 0; j < 26; j++) {
                if (freq2[i][j] > maxFreq) {
                    maxFreq = freq2[i][j];
                }
            }
        }
        return maxFreq;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String msg = in.nextLine();
        System.out.println(occurencesCount(msg.toCharArray()));
    }
}


// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    static int infi = Integer.MAX_VALUE / 2, mod = (int) (1e9 + 7), maxn = (int) 1e5;
    static long infl = Long.MAX_VALUE / 2;
    static char[] s;
    static int n;
    static int[][] suf;

    static long kol(int x, int y) {
        char a = (char) ('a' + x);
        char b = (char) ('a' + y);
        long ans = 0;
        for (int i = 0; i < n - 1; i++) {
            if (s[i] == a) {
                ans += suf[b - 'a'][i + 1];
            }
        }
        return ans;
    }

    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        s = next().toCharArray();
        n = s.length;
        suf = new int[26][n];
        suf[s[n - 1] - 'a'][n - 1] = 1;
        for (int i = n - 2; i >= 0; i--) {
            for (int j = 0; j < 26; j++) {
                suf[j][i] = suf[j][i + 1];
            }
            suf[s[i] - 'a'][i]++;
        }
        long ans = 0;
        for (int i = 0; i < 26; i++) {
            ans = max(ans, suf[i][0]);
        }
        for (int i = 0; i < 26; i++) {
            for (int j = 0; j < 26; j++) {
                ans = max(ans, max(kol(i, j), kol(j, i)));
            }
        }
        out.println(ans);
        out.close();
    }

    static BufferedReader br;
    static StringTokenizer st = new StringTokenizer("");
    static PrintWriter out;

    static String next() throws IOException {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

}

class f {
    int x, y;

    public f(int x, int y) {
        this.x = x;
        this.y = y;
    }
}


// coded from fivefourthreeone

import java.io.*;
import java.util.*;
public class Sol{
    public static void main(String[] args) throws IOException{
    	FastScanner sc = new FastScanner();
    	PrintWriter out = new PrintWriter(System.out);
    	String str = sc.nextToken();
    	long best[] = new long[26];
    	Arrays.fill(best, 0);
    	long ans[][] = new long[26][26];
    	for(int i=0; i<26; i++) {
    		for(int j=0; j<26; j++) {
    			ans[i][j] = 0;
    		}
    	}
    	for(int i= 0; i<str.length(); i++) {
    		int nxt = str.charAt(i)-'a';
    		for(int j=0; j<26; j++) {
    			ans[j][nxt]+=best[j];
    		}
    		best[nxt]++;
    	}
    	long max = 0;
    	for(int i=0; i<26; i++) {
    		max = Math.max(max, best[i]);
    		for(int j=0; j<26; j++) {
    			max = Math.max(max, ans[i][j]);
    		}
    	}
    	System.out.println(max);
    	out.close();
    }
	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
          return st.nextToken();
		}

		String nextLine() {
			st = null;
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return null;
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}
}


import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main implements Runnable
{
    boolean multiple = false;
    long MOD;

    @SuppressWarnings("Duplicates")
    void solve() throws Exception
    {
        String s = sc.nextToken();
        int n = s.length();
        long[][] pref = new long[26][n];
        long[][] count = new long[26][26];
        long[] smallcount = new long[26];
        pref[s.charAt(0) - 'a'][0]++;
        for (int i = 1; i < n; i++)
        {
            for (int j = 0; j < 26; j++)
                pref[j][i] = pref[j][i - 1];
            pref[s.charAt(i) - 'a'][i]++;
        }

        long ans = 0;

        for (int i = 0; i < n - 1; i++)
        {
            int first = s.charAt(i) - 'a';
            for (int second = 0; second < 26; second++)
                count[first][second] += pref[second][n - 1] - pref[second][i];
        }

        for (int i = 0; i < 26; i++)
            for (int j = 0; j < 26; j++)
                ans = max(ans, count[i][j]);

        for (int i = 0; i < n; i++)
            smallcount[s.charAt(i) - 'a']++;
        for (int i = 0; i < 26; i++)
            ans = max(ans, smallcount[i]);

        System.out.println(ans);
//        System.out.println(count[0][0]);
//        System.out.println(count[0][1]);
//        System.out.println(count[1][0]);
    }

    class Node implements Comparable<Node>
    {
        long t, u, v;
        Node(long T, long U, long V)
        {
            t = T;
            u = U;
            v = V;
        }

        @Override
        public int compareTo(Node o)
        {
            return (int)(t - o.t);
        }
    }

    long inv(long a, long b)
    {
        return 1 < a ? b - inv(b % a, a) * b / a : 1;
    }

    long gcd(long a, long b)
    {
        return a == 0 ? b : gcd(b % a, a);
    }

    long lcm(long a, long b) { return (a * b) / gcd(a , b); }

    class SegNode
    {
        int max;
        int L, R;
        SegNode left = null, right = null;

        int query(int queryL, int queryR)
        {
            if (queryL == L && queryR == R)
                return max;

            int leftAns = Integer.MIN_VALUE, rightAns = Integer.MIN_VALUE;
            if (left != null && queryL <= left.R)
                leftAns = left.query(queryL, min(queryR, left.R));
            if (right != null && queryR >= right.L)
                rightAns = right.query(max(queryL, right.L), queryR);

            return max(leftAns, rightAns);
        }

        SegNode(int[] arr, int l, int r)
        {
            L = l;
            R = r;
            max = arr[l];

            if (l == r) return;

            int mid = (l + r) / 2;
            left = new SegNode(arr, l, mid);
            right = new SegNode(arr, mid + 1, r);
            max = max(left.max, right.max);
        }
    }

    void print(long[] arr)
    {
        for (int i = 0; i < arr.length; i++)
            System.out.print(arr[i] + " ");
        System.out.println();
    }

    @Override
    public void run()
    {
        try
        {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            sc = new FastScanner(in);
            if (multiple)
            {
                int q = sc.nextInt();
                for (int i = 0; i < q; i++)
                    solve();
            }
            else
                solve();
        }
        catch (Throwable uncaught)
        {
            Main.uncaught = uncaught;
        }
        finally
        {
            out.close();
        }
    }

    public static void main(String[] args) throws Throwable
    {
        Thread thread = new Thread(null, new Main(), "", (1 << 26));
        thread.start();
        thread.join();
        if (Main.uncaught != null) {
            throw Main.uncaught;
        }
    }

    static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out;
}

class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in)
    {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main implements Runnable
{
    boolean multiple = false;
    long MOD;

    @SuppressWarnings("Duplicates")
    void solve() throws Exception
    {
        String s = sc.nextToken();
        int n = s.length();
        int[][] pref = new int[26][n];
        int[][] count = new int[26][26];
        int[] smallcount = new int[26];
        pref[s.charAt(0) - 'a'][0]++;
        for (int i = 1; i < n; i++)
        {
            for (int j = 0; j < 26; j++)
                pref[j][i] = pref[j][i - 1];
            pref[s.charAt(i) - 'a'][i]++;
        }

        long ans = 0;

        for (int i = 0; i < n - 1; i++)
        {
            int first = s.charAt(i) - 'a';
            for (int second = 0; second < 26; second++)
                count[first][second] += pref[second][n - 1] - pref[second][i];
        }

        for (int i = 0; i < 26; i++)
            for (int j = 0; j < 26; j++)
                ans = max(ans, count[i][j]);

        for (int i = 0; i < n; i++)
            ans = max(ans, ++smallcount[s.charAt(i) - 'a']);

        System.out.println(ans);
    }

    class Node implements Comparable<Node>
    {
        long t, u, v;
        Node(long T, long U, long V)
        {
            t = T;
            u = U;
            v = V;
        }

        @Override
        public int compareTo(Node o)
        {
            return (int)(t - o.t);
        }
    }

    long inv(long a, long b)
    {
        return 1 < a ? b - inv(b % a, a) * b / a : 1;
    }

    long gcd(long a, long b)
    {
        return a == 0 ? b : gcd(b % a, a);
    }

    long lcm(long a, long b) { return (a * b) / gcd(a , b); }

    class SegNode
    {
        int max;
        int L, R;
        SegNode left = null, right = null;

        int query(int queryL, int queryR)
        {
            if (queryL == L && queryR == R)
                return max;

            int leftAns = Integer.MIN_VALUE, rightAns = Integer.MIN_VALUE;
            if (left != null && queryL <= left.R)
                leftAns = left.query(queryL, min(queryR, left.R));
            if (right != null && queryR >= right.L)
                rightAns = right.query(max(queryL, right.L), queryR);

            return max(leftAns, rightAns);
        }

        SegNode(int[] arr, int l, int r)
        {
            L = l;
            R = r;
            max = arr[l];

            if (l == r) return;

            int mid = (l + r) / 2;
            left = new SegNode(arr, l, mid);
            right = new SegNode(arr, mid + 1, r);
            max = max(left.max, right.max);
        }
    }

    void print(long[] arr)
    {
        for (int i = 0; i < arr.length; i++)
            System.out.print(arr[i] + " ");
        System.out.println();
    }

    @Override
    public void run()
    {
        try
        {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            sc = new FastScanner(in);
            if (multiple)
            {
                int q = sc.nextInt();
                for (int i = 0; i < q; i++)
                    solve();
            }
            else
                solve();
        }
        catch (Throwable uncaught)
        {
            Main.uncaught = uncaught;
        }
        finally
        {
            out.close();
        }
    }

    public static void main(String[] args) throws Throwable
    {
        Thread thread = new Thread(null, new Main(), "", (1 << 26));
        thread.start();
        thread.join();
        if (Main.uncaught != null) {
            throw Main.uncaught;
        }
    }

    static Throwable uncaught; BufferedReader in; FastScanner sc; PrintWriter out;
}

class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in)
    {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.util.*;

public final class Solution {
    private static class Pair<S, T> {
        S first;
        T second;

        public Pair(S first, T second) {
            this.first = first;
            this.second = second;
        }

        public S getFirst() {
            return first;
        }

        public T getSecond() {
            return second;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int tests = 1;
        for(int t = 1; t <= tests; t++) {
            String s = in.next();

            long ans = solve(s);
            System.out.println(ans);

        }
    }

    private static long solve(String s) {
        int n = s.length();
        long ans = 0;
        long[] occs = new long[26];
        for(int i = 0; i < n; i++) {
            int c = s.charAt(i) - 'a';
            occs[c]++;
            ans = Math.max(ans, occs[c]);
        }

        for(int i = 0; i < 26; i++) {
            for(int j = 0; j < 26; j++) {
                if(occs[i] == 0 || occs[j] == 0) {
                    continue;
                } else {
                    long firstLetterOccs = 0;
                    long curr = 0;
                    for(int k = 0; k < n; k++) {
                        int c = s.charAt(k) - 'a';
                        if(c == i) {
                            firstLetterOccs++;
                        }
                        if(c == j) {
                            curr += firstLetterOccs;
                        }
                    }
                    ans = Math.max(curr, ans);
                }
            }
        }
        return ans;
    }
}


import java.util.*;

public final class Solution {
    private static class Pair<S, T> {
        S first;
        T second;

        public Pair(S first, T second) {
            this.first = first;
            this.second = second;
        }

        public S getFirst() {
            return first;
        }

        public T getSecond() {
            return second;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int tests = 1;
        for(int t = 1; t <= tests; t++) {
            String s = in.next();

            int ans = solve(s);
            System.out.println(ans);

        }
    }

    private static int solve(String s) {
        int n = s.length();
        int ans = 0;
        int[] occs = new int[26];
        for(int i = 0; i < n; i++) {
            int c = s.charAt(i) - 'a';
            occs[c]++;
            ans = Math.max(ans, occs[c]);
        }
        int[][] ct = new int[26][26];
        for(int i = 0; i < 26; i++) {
            for(int j = 0; j < 26; j++) {
                if(occs[i] == 0 || occs[j] == 0 || j == i) {
                    continue;
                } else {
                    int firstLetterOccs = 0;
                    int curr = 0;
                    for(int k = 0; k < n; k++) {
                        int c = s.charAt(k) - 'a';
                        if(c == i) {
                            firstLetterOccs++;
                        }
                        if(c == j) {
                            curr += firstLetterOccs;
                        }
                    }
                    ans = Math.max(curr, ans);
                }
            }
        }
        return ans;
    }
}


import java.util.*;

public final class Solution {
    private static class Pair<S, T> {
        S first;
        T second;

        public Pair(S first, T second) {
            this.first = first;
            this.second = second;
        }

        public S getFirst() {
            return first;
        }

        public T getSecond() {
            return second;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int tests = 1;
        for(int t = 1; t <= tests; t++) {
            String s = in.next();

            long ans = solve(s);
            System.out.println(ans);

        }
    }

    private static long solve(String s) {
        int n = s.length();
        long ans = 0;
        long[] occs = new long[26];
        for(int i = 0; i < n; i++) {
            int c = s.charAt(i) - 'a';
            occs[c]++;
            ans = Math.max(ans, occs[c]);
        }

        for(int i = 0; i < 26; i++) {
            for(int j = 0; j < 26; j++) {
                if(occs[i] == 0 || occs[j] == 0) {
                    continue;
                } else {
                    long firstLetterOccs = 0;
                    long curr = 0;
                    for(int k = 0; k < n; k++) {
                        int c = s.charAt(k) - 'a';
                        if(c == j) {
                            curr += firstLetterOccs;
                        }
                        if(c == i) {
                            firstLetterOccs++;
                        }

                    }
                    ans = Math.max(curr, ans);
                }
            }
        }
        return ans;
    }
}


import java.util.*;

public final class Solution {
    private static class Pair<S, T> {
        S first;
        T second;

        public Pair(S first, T second) {
            this.first = first;
            this.second = second;
        }

        public S getFirst() {
            return first;
        }

        public T getSecond() {
            return second;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int tests = 1;
        for(int t = 1; t <= tests; t++) {
            String s = in.next();

            long ans = solve(s);
            System.out.println(ans);

        }
    }

    private static long solve(String s) {
        int n = s.length();
        long ans = 0;
        long[] occs = new long[26];
        for(int i = 0; i < n; i++) {
            int c = s.charAt(i) - 'a';
            occs[c]++;
            ans = Math.max(ans, occs[c]);
        }

        for(int i = 0; i < 26; i++) {
            for(int j = 0; j < 26; j++) {
                if(occs[i] == 0 || occs[j] == 0 || j == i) {
                    continue;
                } else {
                    long firstLetterOccs = 0;
                    long curr = 0;
                    for(int k = 0; k < n; k++) {
                        int c = s.charAt(k) - 'a';
                        if(c == i) {
                            firstLetterOccs++;
                        }
                        if(c == j) {
                            curr += firstLetterOccs;
                        }
                    }
                    ans = Math.max(curr, ans);
                }
            }
        }
        return ans;
    }
}


import java.io.*;
import java.util.*;
import java.lang.Math;
public class pro{
    public static HashMap<Character, Integer> sortByValue(HashMap<Character, Integer> hm)
    {

        List<Map.Entry<Character, Integer> > list =
               new LinkedList<Map.Entry<Character, Integer> >(hm.entrySet());

        Collections.sort(list, new Comparator<Map.Entry<Character, Integer> >() {
            public int compare(Map.Entry<Character, Integer> o1,
                               Map.Entry<Character, Integer> o2)
            {
                return (o1.getValue()).compareTo(o2.getValue());
            }
        });
        HashMap<Character, Integer> temp = new LinkedHashMap<Character, Integer>();
        for (Map.Entry<Character, Integer> aa : list) {
            temp.put(aa.getKey(), aa.getValue());
        }
        return temp;
    }
public static void main(String[] arg)throws IOException{
        Scanner in=new Scanner(System.in);
        String s=in.next();
        HashMap<Character, Integer> hmap = new HashMap<Character, Integer>();
        for(int i=0;i<s.length();i++){
            if(hmap.get(s.charAt(i))==null){
                hmap.put(s.charAt(i),1);
            }else{
                int count= hmap.get(s.charAt(i));
                hmap.put(s.charAt(i),count+1);
            }
        }
        HashMap<Character, Integer> hm1 = sortByValue(hmap);
        /*for (Map.Entry<String, Integer> en : hm1.entrySet()) {
           out.println("Key = " + en.getKey() +  ", Value = " + en.getValue());
        }*/
        //checking if the hashmap has 1 value only
        if(hm1.size()==1){
            System.out.println(1);
        }else{
            int size=hm1.size();
            int[] arr=new int[size];
            int i=0;
            for (Map.Entry<Character, Integer> en : hm1.entrySet()) {
           arr[i]=en.getValue();
           i++;

        }
         System.out.println(arr[size-1]*arr[size-2]);

        }

}
}
class InputReader extends InputStream {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }


import java.io.*;
import java.util.*;
import java.lang.Math;
public class cowandmessage{
	public static void main(String[] arg)throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s=in.readLine();
        int n=s.length();

        //code goes here-->
        int[] arr2=new int[26];
        int[][] arr1=new int[26][26];
        for(int i=0;i<n-1;i++){
            arr2[(int)s.charAt(i)-97]++;
            for(int j=i+1;j<n;j++){
                arr1[(int)s.charAt(i)-97][(int)s.charAt(j)-97]++;
            }
        }
        arr2[(int)s.charAt(n-1)-97]++;
        int max=0;
        for(int i=0;i<26;i++){
            for(int j=0;j<26;j++){
                if(max<arr1[i][j]){
                    max=arr1[i][j];
                }
            }

        }
        for(int i=0;i<26;i++){
            if(max<arr2[i]){
                max=arr2[i];
            }

        }
        System.out.println(max);

	}
}
class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[100000]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }


import java.io.*;
import java.util.*;
import java.lang.Math;
public class cowandmessage{
	public static void main(String[] arg)throws IOException{
		Reader in=new Reader();
        String s=in.readLine();
        int n=s.length();

        //code goes here-->
        int[] arr2=new int[26];
        int[][] arr1=new int[26][26];
        for(int i=0;i<n-1;i++){
            arr2[(int)s.charAt(i)-97]++;
            for(int j=i+1;j<n;j++){
                arr1[(int)s.charAt(i)-97][(int)s.charAt(j)-97]++;
            }
        }
        arr2[(int)s.charAt(n-1)-97]++;
        int max=0;
        for(int i=0;i<26;i++){
            for(int j=0;j<26;j++){
                if(max<arr1[i][j]){
                    max=arr1[i][j];
                }
            }

        }
        for(int i=0;i<26;i++){
            if(max<arr2[i]){
                max=arr2[i];
            }

        }
        System.out.println(max);

	}
}
class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[100000]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }


import java.io.*;
import java.util.*;
import java.lang.Math;
public class cowandmessage{
	public static void main(String[] arg)throws IOException{
		Scanner in=new Scanner(System.in);
        String s=in.nextLine();
        int n=s.length();

        //code goes here-->
        int[][] arr1=new int[26][26];
        for(int i=0;i<n-1;i++){
            for(int j=i;j<n;j++){
                arr1[(int)s.charAt(i)-97][(int)s.charAt(j)-97]++;
            }
        }
        int max=0;
        for(int i=0;i<26;i++){
            for(int j=0;j<26;j++){
                if(max<arr1[i][j]){
                    max=arr1[i][j];
                }
            }

        }
        System.out.println(max);

	}
}


//experimental template for subs in java//
import java.io.*;
import java.util.*;
import java.lang.Math;
public class cowandmessage{
	public static void main(String[] arg)throws IOException{

        Reader in = new Reader();
        String s=in.readLine();
        int n=s.length();
        //code goes her-->
        int[][] arr1=new int[26][26];
        for(int i=0;i<n-1;i++){
            for(int j=i;j<n;j++){
                arr1[(int)s.charAt(i)-97][(int)s.charAt(j)-97]++;
            }
        }
        int max=0;
        for(int i=0;i<26;i++){
            for(int j=0;j<26;j++){
                if(max<arr1[i][j]){
                    max=arr1[i][j];
                }
            }

        }
        System.out.println(max);

	}
}
//fast IO

public class Reader
    {
        final public int BUFFER_SIZE = 1 << 16;
        public DataInputStream din;
        public byte[] buffer;
        public int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[100000]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        public void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        public byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }


import java.io.*;
import java.util.*;
import java.lang.Math;
public class cowandmessage{
	public static void main(String[] arg)throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s=in.readLine();
        int n=s.length();

        //code goes here-->
        int[] arr2=new int[26];
        int[][] arr1=new int[26][26];
        for(int i=0;i<n-1;i++){
            arr2[(int)s.charAt(i)-97]++;
            for(int j=0;j<26;j++){
                arr1[(int)s.charAt(i)-97][j]+=arr2[j];
            }

        }
        arr2[(int)s.charAt(n-1)-97]++;
        int max=0;
        for(int i=0;i<26;i++){
            for(int j=0;j<26;j++){
                if(max<arr1[i][j]){
                    max=arr1[i][j];
                }
            }

        }
        for(int i=0;i<26;i++){
            if(max<arr2[i]){
                max=arr2[i];
            }

        }
        System.out.println(max);

	}
}
class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[100000]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }


import java.io.*;
import java.util.*;
import java.lang.Math;
public class cowandmessage{
	public static void main(String[] arg)throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s=in.readLine();
        int n=s.length();

        //code goes here-->
        int[] arr2=new int[26];
        int[][] arr1=new int[26][26];
        for(int i=0;i<n;i++){

            for(int j=0;j<26;j++){
                arr1[j][(int)s.charAt(i)-97]+=arr2[j];
            }
            arr2[(int)s.charAt(i)-97]++;

        }

        int max=-1;
        for(int i=0;i<26;i++){
            for(int j=0;j<26;j++){
                if(max<arr1[i][j]){
                    max=arr1[i][j];
                }
            }

        }
        for(int i=0;i<26;i++){
            if(max<arr2[i]){
                max=arr2[i];
            }

        }
        System.out.println(max);

	}
}
class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[100000]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }