using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Codeforces
{
    class MyComparer:IEqualityComparer<List<char>>
    {
        public bool Equals(List<char> x, List<char> y)
        {
            if (x.Count == y.Count)
            {
                var res = true;
                for (int i = 0; i < x.Count; ++i)
                {
                    if (x[i] != y[i])
                    {
                        res = false;
                        break;
                    }
                }
                return res;
            }
            return false;
        }

        public int GetHashCode(List<char> obj)
        {
            return base.GetHashCode();
        }
    }
    class Program : IDisposable
    {
        private static TextReader textReader = new StreamReader(Console.OpenStandardInput());
        private static TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

        void Solve()
        {
            var n = ReadInt();
            var singleLetStr = new List<string>();
            var dict = new Dictionary<List<char>, int>(new MyComparer());
            for (int i = 0; i < n; ++i)
            {
                var s = Console.ReadLine();
                var diffLetters = s.Distinct().ToList();
                diffLetters.Sort();
                if(diffLetters.Count() == 1)
                    singleLetStr.Add(s);
                else if (diffLetters.Count() == 2)
                {

                    if (dict.ContainsKey(diffLetters))
                    {
                        dict[diffLetters] += s.Length;
                    }
                    else
                    {
                        dict.Add(diffLetters,s.Length);
                    }
                }
            }
            foreach (var s in singleLetStr)
            {
                if (dict.Keys.Any(x => x.Contains(s.First())))
                {
                    var dictItems = dict.Where(x => x.Key.Contains(s.First())).ToList();
                    foreach (var keyValuePair in dictItems)
                    {
                        dict[keyValuePair.Key] += s.Length;
                    }
                }
                else
                {
                    dict.Add(new List<char>(){s.First()},s.Length);
                }
            }
            var res = dict.Values.Max();
            Console.WriteLine(res);
            //Console.ReadLine();
        }

        static void Main(string[] args)
        {
            var p = new Program();

            p.Solve();
            p.Dispose();
        }

        #region Helpers

        private static int ReadInt()
        {
            return int.Parse(textReader.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(textReader.ReadLine());
        }

        private static int[] ReadIntArray()
        {
            return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        #endregion

        public void Dispose()
        {
            textReader.Close();
            textWriter.Close();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Codeforces
{
    class MyComparer:IEqualityComparer<List<char>>
    {
        public bool Equals(List<char> x, List<char> y)
        {
            if (x.Count == y.Count)
            {
                var res = true;
                for (int i = 0; i < x.Count; ++i)
                {
                    if (x[i] != y[i])
                    {
                        res = false;
                        break;
                    }
                }
                return res;
            }
            return false;
        }

        public int GetHashCode(List<char> obj)
        {
            return base.GetHashCode();
        }
    }
    class Program : IDisposable
    {
        private static TextReader textReader = new StreamReader(Console.OpenStandardInput());
        private static TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

        void Solve()
        {
            var n = int.Parse(Console.ReadLine());//ReadInt();
            var singleLetStr = new List<string>();
            var dict = new Dictionary<List<char>, int>(new MyComparer());
            for (int i = 0; i < n; ++i)
            {
                var s = Console.ReadLine();
                var diffLetters = s.Distinct().ToList();
                diffLetters.Sort();
                if(diffLetters.Count() == 1)
                    singleLetStr.Add(s);
                else if (diffLetters.Count() == 2)
                {

                    if (dict.ContainsKey(diffLetters))
                    {
                        dict[diffLetters] += s.Length;
                    }
                    else
                    {
                        dict.Add(diffLetters,s.Length);
                    }
                }
            }
            foreach (var s in singleLetStr)
            {
                if (dict.Keys.Any(x => x.Contains(s.First())))
                {
                    var dictItems = dict.Where(x => x.Key.Contains(s.First())).ToList();
                    foreach (var keyValuePair in dictItems)
                    {
                        dict[keyValuePair.Key] += s.Length;
                    }
                }
                else
                {
                    dict.Add(new List<char>(){s.First()},s.Length);
                }
            }
            var res = dict.Values.Max();
            Console.WriteLine(res);
            //Console.ReadLine();
        }

        static void Main(string[] args)
        {
            var p = new Program();

            p.Solve();
            p.Dispose();
        }

        #region Helpers

        private static int ReadInt()
        {
            return int.Parse(textReader.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(textReader.ReadLine());
        }

        private static int[] ReadIntArray()
        {
            return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        #endregion

        public void Dispose()
        {
            textReader.Close();
            textWriter.Close();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var dict = new Dictionary<HashSet<char>, int>();
            for (int i = 0; i < n; ++i)
            {
                var s = Console.ReadLine().ToCharArray().ToList();
                var diffLetters = s.Distinct();
                if (diffLetters.Count() <= 2 && diffLetters.Count() > 0)
                {
                    var set = new HashSet<char>();
                    foreach (var letter in diffLetters)
                    {
                        set.Add(letter);
                    }
                    if (dict.ContainsKey(set))
                    {
                        dict[set] += s.Count;
                    }
                    else if(set.Count == 1 && dict.Keys.Any(x=>x.Contains(set.First()))){
                        var dictItems = dict.Where(x=>x.Key.Contains(set.First())).ToList();
                        foreach (var item in dictItems)
                        {
                            dict[item.Key] += s.Count;
                        }
                    }
                    else if(set.Count == 2 && dict.Any(x => x.Key.Count == 1 && set.Contains(x.Key.First())))
                    {
                        var dictItems = dict.Where(x => x.Key.Count == 1 && set.Contains(x.Key.First())).ToList();
                        foreach (var item in dictItems)
                        {
                            dict.Add(set, item.Value + s.Count);
                        }
                    }
                    else {
                        dict.Add(set, s.Count);
                    }
                }
            }
            var res = dict.Count!=0 ? dict.Values.Max() : 0;
            Console.WriteLine(res);
            //Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var dict = new Dictionary<HashSet<char>, int>();
            for (int i = 0; i < n; ++i)
            {
                var s = Console.ReadLine().ToCharArray().ToList();
                var diffLetters = s.Distinct();
                if (diffLetters.Count() <= 2 && diffLetters.Count() > 0)
                {
                    var set = new HashSet<char>();
                    foreach (var letter in diffLetters)
                    {
                        set.Add(letter);
                    }
                    if (dict.ContainsKey(set))
                    {
                        dict[set] += s.Count;
                    }
                    else if(set.Count == 1 && dict.Keys.Any(x=>x.Contains(set.First()))){
                        var dictItems = dict.Where(x=>x.Key.Contains(set.First())).ToList();
                        foreach (var item in dictItems)
                        {
                            dict[item.Key] += s.Count;
                        }
                    }
                    else if(set.Count == 2 && dict.Any(x => x.Key.Count == 1 && set.Contains(x.Key.First())))
                    {
                        var dictItems = dict.Where(x => x.Key.Count == 1 && set.Contains(x.Key.First())).ToList();
                        foreach (var item in dictItems)
                        {
                            if (!dict.ContainsKey(set))
                            {
                                dict.Add(set, item.Value + s.Count);
                            }
                            else
                            {
                                dict[set] += item.Value;
                            }
                        }
                    }
                    else {
                        dict.Add(set, s.Count);
                    }
                }
            }
            var res = dict.Count!=0 ? dict.Values.Max() : 0;
            Console.WriteLine(res);
            //Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Codeforces
{
    class MyComparer:IEqualityComparer<List<char>>
    {
        public bool Equals(List<char> x, List<char> y)
        {
            if (x.Count == y.Count)
            {
                var res = true;
                for (int i = 0; i < x.Count; ++i)
                {
                    if (x[i] != y[i])
                    {
                        res = false;
                        break;
                    }
                }
                return res;
            }
            return false;
        }

        public int GetHashCode(List<char> obj)
        {
            return base.GetHashCode();
        }
    }
    class Program : IDisposable
    {
        private static TextReader textReader = new StreamReader(Console.OpenStandardInput());
        private static TextWriter textWriter = new StreamWriter(Console.OpenStandardOutput());

        void Solve()
        {
            var n = int.Parse(Console.ReadLine());//ReadInt();
            var singleLetStr = new List<string>();
            var dict = new Dictionary<List<char>, int>(new MyComparer());
            for (int i = 0; i < n; ++i)
            {
                var s = Console.ReadLine();
                var diffLetters = s.Distinct().ToList();
                diffLetters.Sort();
                if(diffLetters.Count() == 1)
                    singleLetStr.Add(s);
                else if (diffLetters.Count() == 2)
                {

                    if (dict.ContainsKey(diffLetters))
                    {
                        dict[diffLetters] += s.Length;
                    }
                    else
                    {
                        dict.Add(diffLetters,s.Length);
                    }
                }
            }
            foreach (var s in singleLetStr)
            {
                if (dict.Keys.Any(x => x.Contains(s.First())))
                {
                    var dictItems = dict.Where(x => x.Key.Contains(s.First())).ToList();
                    foreach (var keyValuePair in dictItems)
                    {
                        dict[keyValuePair.Key] += s.Length;
                    }
                }
                else
                {
                    dict.Add(new List<char>(){s.First()},s.Length);
                }
            }
            for (int i=0;i<singleLetStr.Count;++i)
            {
                for (int j = i + 1; j < singleLetStr.Count; ++j)
                {
                    var list = new List<char> {singleLetStr[i][0], singleLetStr[j][0]};
                    if(dict.ContainsKey(list))
                        continue;
                    dict.Add(list,singleLetStr[i].Length+singleLetStr[j].Length );
                }
            }
            var res = dict.Count == 0 ? 0 : dict.Values.Max();
            Console.WriteLine(res);
            //Console.ReadLine();
        }

        static void Main(string[] args)
        {
            var p = new Program();

            p.Solve();
            p.Dispose();
        }

        #region Helpers

        private static int ReadInt()
        {
            return int.Parse(textReader.ReadLine());
        }

        private static long ReadLong()
        {
            return long.Parse(textReader.ReadLine());
        }

        private static int[] ReadIntArray()
        {
            return textReader.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        #endregion

        public void Dispose()
        {
            textReader.Close();
            textWriter.Close();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            //int max = 0;
            var dict = new Dictionary<HashSet<char>, int>();
            for (int i = 0; i < n; ++i)
            {
                var s = Console.ReadLine().ToCharArray().ToList();
                var diffLetters = s.Distinct();
                if (diffLetters.Count() <= 2)
                {
                    var set = new HashSet<char>();
                    foreach (var letter in diffLetters)
                    {
                        set.Add(letter);
                    }
                    if (dict.ContainsKey(set))
                    {
                        dict[set] += s.Count;
                    }
                    else if(set.Count == 1 && dict.Keys.Any(x=>x.Contains(set.First()))){
                        var dictItems = dict.Where(x=>x.Key.Contains(set.First())).ToList();
                        foreach (var item in dictItems)
                        {
                            dict[item.Key] += s.Count;
                        }
                    }
                    else {
                        dict.Add(set, s.Count);
                    }
                }
            }
            var res = dict.Count!=0 ? dict.Values.Max() : 0;
            Console.WriteLine(res);
            //Console.ReadLine();
        }
    }
}


using System;
using System.IO;
using System.Linq;

namespace Codeforces
{
	internal class Template
	{
		private void Solve()
		{
			var n = cin.NextInt();
			var words = new string[n];
			for (var i = 0; i < words.Length; i++)
			{
				words[i] = cin.NextString();
			}
			var best = int.MinValue;
			for (var i = 'a'; i <= 'z'; i++)
			{
				for (var j = i + 1; j <= 'z'; j++)
				{
					var cnt = 0;
					foreach (var w in words)
					{
						if (w.All(x => x == i || x == j))
						{
							cnt += w.Length;
						}
					}
					best = Math.Max(best, cnt);
				}
			}
			Console.WriteLine(best);
		}

		private static readonly Scanner cin = new Scanner();

		private static void Main()
		{
#if DEBUG
			Console.SetIn(new StreamReader(@"..\..\input.txt"));
#endif
			new Template().Solve();
			Console.ReadLine();
#if DEBUG
			Console.ReadKey();
#endif
		}
	}

	internal class Scanner
	{
		private string[] s = new string[0];
		private int i;
		private readonly char[] cs = { ' ' };

		public string NextString()
		{
			if (i < s.Length) return s[i++];
			var line = Console.ReadLine() ?? string.Empty;
			s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			i = 1;
			return s.First();
		}

		public double NextDouble()
		{
			return double.Parse(NextString());
		}

		public int NextInt()
		{
			return int.Parse(NextString());
		}

		public long NextLong()
		{
			return long.Parse(NextString());
		}
	}
}


using System;
using System.IO;
using System.Text;

namespace RM_329_A
{
    class RM_A
    {
        static void Main(string[] args)
        {
            //StreamReader f = new StreamReader("input_A.txt");
            TextReader f = Console.In;
            int n = int.Parse(f.ReadLine());
            string[] sl = new string[n], alph = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s" , "t", "u", "v" ,"w", "x", "y", "z" };
            for (int i = 0; i < n; i++)
            {
                sl[i] = f.ReadLine();
            }

            string[] let = new string[n];
            for (int i = 0; i < n; i++)
            {
                int let_count = 0;
                for (int j = 0; j < 26; j++)
                {
                    if (sl[i].Contains(alph[j]))
                    {
                        let[i] += alph[j];
                        let_count++;
                    }
                    if (let_count > 2) break;
                }
                if (let_count > 2) let[i] = "";
            }

            int max = 0;
            Array.Sort(let, sl);
            for (int i = 0; i < n; i++)
            {
                if (let[i] != "")
                {
                    int max_s = 0;
                    if (let[i].Length == 1)
                    {
                        int max1 = 0, max2 = 0, max0 = 0;
                        string max_l="";
                        for (int j = 0; j < n; j++)
                        {
                            if (let[j].Length == 1 && max_l == "")
                            {
                                max_l = let[j];
                                max0 = sl[j].Length;
                            }
                            else if (let[j].Length == 1 && max_l==let[j])
                            {
                                max0 += sl[j].Length;
                            }
                            else if (let[j].Length == 1 && max_l != let[j])
                            {
                                if (max0 > max1)
                                {
                                    max2 = max1;
                                    max1 = max0;
                                }
                                else if (max0 > max2) max2 = max0;
                                max_l = let[j];
                                max0 = sl[j].Length;
                            }
                        }
                        if (max0 > max1)
                        {
                            max2 = max1;
                            max1 = max0;
                        }
                        else if (max0 > max2) max2 = max0;
                        max_s = max1 + max2;
                    }
                    else
                        for (int j = 0; j < n; j++)
                        {
                            if (let[j].Length == 1 && let[i].Contains(let[j]))
                            {
                                max_s += sl[j].Length;
                            }
                            else if (let[j].Length == 2 && let[j].Equals(let[i]))
                            {
                                max_s += sl[j].Length;
                            }
                        }
                    if (max_s > max) max = max_s;
                }
            }
            Console.WriteLine(max);
            Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Olymp
{
  public class ProblemSolver
  {
    public void Solve()
    {
      int n = int.Parse(Console.ReadLine());
      string[] a = Enumerable.Range(0, n)
        .Select(i => Console.ReadLine())
        .ToArray();
      int m = 0;
      for (int i = 'a'; i < 'z'; i++)
      {
        for (int j = i + 1; j <= 'z'; j++)
        {
          int l = a
            .Where(w => Chars(w, (char)i) + Chars(w, (char)j) == w.Length)
            .Select(w => w.Length)
            .Sum();
          if(l > m)
            m = l;
        }
      }
      Console.Write(m);
    }

    private int Chars(string s, char c)
    {
      int count = 0;
      for (int i = 0; i < s.Length; i++)
      {
        if(s[i] == c)
          count++;
      }
      return count;
    }
  }

  class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver();
      solver.Solve();
    }
  }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static bool prov(string s)
        {
            List<char> a = new List<char>();
            bool f = true;
            for (int i = 0; i < s.Length; i++)
            {
                if (!(a.Contains(s[i])))
                    if (a.Count < 2)
                    {
                        a.Add(s[i]);
                    }
                    else
                    {
                        f = false;
                        break;
                    }
            }
            return f;

        }

        static bool prov2(string s, char a)
        {
            for (int i = 0; i < s.Length; i++)
                if (s[i] != a) return false;

            return true;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s;
            List<string> a = new List<string>();
            int max = 0;

            for (int i = 0; i < n; i++)
            {
                s = Console.ReadLine();
                if (prov(s))
                {
                    a.Add(s);
                }
            }

            char x, y;
            int r = 0;
            for (int i = 0; i < 26; i++)
            {
                x = Convert.ToChar(i + 97);
                for (int u = i+1; u < 25; u++)
                {
                    y = Convert.ToChar(u + 97);
                    r = 0;
                    for (int j = 0; j < a.Count; j++)
                    {
                        if ((a[j].Contains(x) && a[j].Contains(y)) || prov2(a[j], x) || prov2(a[j], y))
                            r += a[j].Length;
                    }
                    if (r > max) max = r;
                }
            }
            Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static bool prov(string s, ref char x, ref char y)
        {
            List<char> a = new List<char>();
            bool f = true;
            for (int i = 0; i < s.Length; i++)
            {
                if (!(a.Contains(s[i])))
                    if (a.Count < 2)
                    {
                        a.Add(s[i]);
                    }
                    else
                    {
                        f = false;
                        break;
                    }
            }
            a.Sort();
            x = a[0];
            if (a.Count == 1)
                y = a[0];
            else y = a[1];
            return f;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s;
            List<string> a = new List<string>();
            List<string> c = new List<string>();
            Dictionary<string, int> b = new Dictionary<string, int>();
            for (int i = 0; i < n; i++)
            {
                char x = 'a', y = 'a';
                s = Console.ReadLine();
                if (prov(s, ref x, ref y))
                {
                    if (x == y) c.Add(x + s.Count().ToString());
                    else
                    {
                        string t = Convert.ToString(x) + Convert.ToString(y);
                        a.Add(s);
                        if (b.ContainsKey(t))
                            b[t] += s.Length;
                        else
                            b.Add(t, s.Length);
                    }

                }
            }
            bool f;
            int max = -2;
            int q = 0;
            int r = 0;
            bool[] w = new bool[c.Count];
            w[0] = true;
            bool m = true;
            if (c.Count == n)
            {
                m = false;
                for (int i = 0; i < c.Count; i++)
                {
                    f = true;
                    for (int u = i + 1; u < c.Count-1; u++)
                        if (c[i][0] == c[u][0] && !w[u])
                        {
                            if (!b.ContainsKey((c[i][0]).ToString()))
                                b.Add(Convert.ToString(c[u][0]), Convert.ToInt32(c[i].Remove(0, 1)) + Convert.ToInt32(c[u].Remove(0, 1)));
                            else
                                b[Convert.ToString(c[i][0])] += Convert.ToInt32(c[u].Remove(0, 1));
                            f = false;
                            w[u] = true;
                        }
                    if (b.ContainsKey((c[i][0]).ToString())) { }
                    else
                        b.Add(Convert.ToString(c[i][0]), Convert.ToInt32(c[i].Remove(0, 1)));
                }
                if (b.ContainsKey((c[c.Count - 1][0]).ToString())) { }
                else
                    b.Add(Convert.ToString(c[c.Count - 1][0]), Convert.ToInt32(c[c.Count - 1].Remove(0, 1)));
            }
            else
            {
                for (int i = 0; i < c.Count; i++)
                {
                    f = true;
                    foreach (var item in b.Keys)
                    {
                        q = Convert.ToInt32(c[i].Remove(0, 1));
                        if (item.Contains(c[i][0]))
                        {
                            b[item] += q;
                            f = false;
                            break;
                        }
                    }
                    if (f) b.Add(Convert.ToString(c[i][0]), q);
                }
            }
            string j;
            int max2 = 0;
            int p = 0;
            int o;
            foreach (var i in b.Values)
            {

                if (i > max) { max = i; o = p; }
                p++;
            }
            p = 0;

            foreach (var i in b.Values)
            {
                if (i > max2 && p != 0) max2 = i;
                p++;
            }
            if (!m)
                Console.WriteLine(max + max2);
            else
                Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static bool prov(string s,ref char x,ref char y)
        {
            List<char> a = new List<char>();
            bool f=true;
            for (int i = 0; i < s.Length; i++)
            {
                if (!(a.Contains(s[i])))
                    if (a.Count < 2)
                    {
                        a.Add(s[i]);
                    }
                    else
                    {
                        f = false;
                        break;
                    }
            }
            a.Sort();
            x = a[0];
            if (a.Count == 1)
                y = a[0];
            else y = a[1];
            return f;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s;
            List<string> a = new List<string>();
            List<string> c=new List<string>();
            Dictionary <string, int> b = new Dictionary<string, int>();
            for (int i = 0; i < n; i++)
            {
                char x='a', y='a';
                s=Console.ReadLine();
                if (prov(s, ref x, ref y))
                {
                    if (x == y) c.Add(x+s.Count().ToString());
                    else
                    {
                        string t = Convert.ToString(x) + Convert.ToString(y);
                        a.Add(s);
                        if (b.ContainsKey(t))
                            b[t] += s.Length;
                        else
                            b.Add(t, s.Length);
                    }

                }
            }
            bool f;
            int q = 0;
            for (int i = 0; i < c.Count; i++)
            {
                f = true;
                foreach (var item in b.Keys)
                {
                    q =Convert.ToInt32(c[i].Remove(0, 1));
                    if (item.Contains(c[i][0]))
                    {
                        b[item] += q;
                        f = false;
                        break;
                    }
                }
                if (f) b.Add(Convert.ToString(c[i][0]), q);
            }

            int max = -2;
            foreach (var i in b.Values)
            {
                if ( i> max) max = i;
            }
            Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static bool prov(string s, ref char x, ref char y)
        {
            List<char> a = new List<char>();
            bool f = true;
            for (int i = 0; i < s.Length; i++)
            {
                if (!(a.Contains(s[i])))
                    if (a.Count < 2)
                    {
                        a.Add(s[i]);
                    }
                    else
                    {
                        f = false;
                        break;
                    }
            }
            a.Sort();
            x = a[0];
            if (a.Count == 1)
                y = a[0];
            else y = a[1];
            return f;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s;
            List<string> a = new List<string>();
            List<string> c = new List<string>();
            Dictionary<string, int> b = new Dictionary<string, int>();
            for (int i = 0; i < n; i++)
            {
                char x = 'a', y = 'a';
                s = Console.ReadLine();
                if (prov(s, ref x, ref y))
                {
                    if (x == y)
                    {
                        bool e = true;
                        for (int u=0;u<c.Count;u++)
                            if (x.ToString() == c[u].Remove(1, c[u].Length - 1))
                            {
                                c[u] = x + (int.Parse(c[u].Remove(0, 1)) + s.Length).ToString();
                                e = false;
                            }
                        if (e)
                        c.Add(x + s.Count().ToString());
                    }

                    else
                    {
                        string t = Convert.ToString(x) + Convert.ToString(y);
                        a.Add(s);
                        if (b.ContainsKey(t))
                            b[t] += s.Length;
                        else
                            b.Add(t, s.Length);
                    }

                }
            }
            bool f;
            int max = 0;
            int q = 0;

            bool m = true;
            if (b.Count == 0) m = false;
                for (int i = 0; i < c.Count; i++)
                {
                    f = true;
                    foreach (var item in b.Keys)
                    {
                        q = Convert.ToInt32(c[i].Remove(0, 1));
                        if (item.Contains(c[i][0]))
                        {
                            b[item] += q;
                            f = false;
                            break;
                        }
                    }
                    if (f) { q = Convert.ToInt32(c[i].Remove(0, 1)); b.Add(Convert.ToString(c[i][0]), q); }
                }

            int max2 = 0;
            int p = 0;
            int o=0;
            foreach (var i in b.Values)
            {

                if (i > max) { max = i; o = p; }
                p++;
            }
            p = 0;

            foreach (var i in b.Values)
            {
                if (i > max2 && p != o) max2 = i;
                p++;
            }
            if (!m)
                Console.WriteLine(max + max2);
            else
                Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static bool prov(string s,ref char x,ref char y)
        {
            List<char> a = new List<char>();
            bool f=true;
            for (int i = 0; i < s.Length; i++)
            {
                if (!(a.Contains(s[i])))
                    if (a.Count < 2)
                    {
                        a.Add(s[i]);
                    }
                    else
                    {
                        f = false;
                        break;
                    }
            }
            a.Sort();
            x = a[0];
            if (a.Count == 1)
                y = a[0];
            else y = a[1];
            return f;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s;
            List<string> a = new List<string>();
            List<string> c=new List<string>();
            Dictionary <string, int> b = new Dictionary<string, int>();
            for (int i = 0; i < n; i++)
            {
                char x='a', y='a';
                s=Console.ReadLine();
                if (prov(s, ref x, ref y))
                {
                    if (x == y) c.Add(x+s.Count().ToString());
                    else
                    {
                        string t = Convert.ToString(x) + Convert.ToString(y);
                        a.Add(s);
                        if (b.ContainsKey(t))
                            b[t] += s.Length;
                        else
                            b.Add(t, s.Length);
                    }

                }
            }
            bool f;
            int max = -2;
            int q = 0;
            int r=0;
            bool[] w = new bool[c.Count];
            w[0] = true;
            if (c.Count == n)
            {

                for (int i = 0; i < c.Count - 1; i++)
                {
                    f = true;
                    for (int u = i + 1; u < c.Count; u++)
                        if (c[i][0] == c[u][0] && !w[u])
                        {
                            if (!b.ContainsKey((c[i][0]).ToString()))
                                b.Add(Convert.ToString(c[u][0]), Convert.ToInt32(c[u].Remove(0, 1)) + Convert.ToInt32(c[u].Remove(0, 1)));
                            else
                                b[Convert.ToString(c[i][0])] += Convert.ToInt32(c[u].Remove(0, 1));
                            f = false;
                            w[u] = true;
                        }
                    if (b.ContainsKey((c[i][0]).ToString())) { }
                    else
                        b.Add(Convert.ToString(c[i][0]), Convert.ToInt32(c[i].Remove(0, 1)));
                }
            }
            else
            {
                for (int i = 0; i < c.Count; i++)
                {
                    f = true;
                    foreach (var item in b.Keys)
                    {
                        q = Convert.ToInt32(c[i].Remove(0, 1));
                        if (item.Contains(c[i][0]))
                        {
                            b[item] += q;
                            f = false;
                            break;
                        }
                    }
                    if (f) b.Add(Convert.ToString(c[i][0]), q);
                }
            }

                foreach (var i in b.Values)
                {
                    if (i > max) max = i;
                }

            Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static bool prov(string s,ref char x,ref char y)
        {
            List<char> a = new List<char>();
            bool f=true;
            for (int i = 0; i < s.Length; i++)
            {
                if (!(a.Contains(s[i])))
                    if (a.Count < 2)
                    {
                        a.Add(s[i]);
                    }
                    else
                    {
                        f = false;
                        break;
                    }
            }
            a.Sort();
            x = a[0];
            if (a.Count == 1)
                y = a[0];
            else y = a[1];
            return f;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s;
            List<string> a = new List<string>();
            List<string> c=new List<string>();
            Dictionary <string, int> b = new Dictionary<string, int>();
            for (int i = 0; i < n; i++)
            {
                char x='a', y='a';
                s=Console.ReadLine();
                if (prov(s, ref x, ref y))
                {
                    if (x == y) c.Add(x+s.Count().ToString());
                    else
                    {
                        string t = Convert.ToString(x) + Convert.ToString(y);
                        a.Add(s);
                        if (b.ContainsKey(t))
                            b[t] += s.Length;
                        else
                            b.Add(t, s.Length);
                    }

                }
            }
            bool f;
            int max = -2;
            int q = 0;
            int r=0;
            bool[] w = new bool[c.Count];
            w[0] = true;
            bool m = true;
            if (c.Count == n)
            {
                m = false;
                for (int i = 0; i < c.Count; i++)
                {
                    f = true;
                    for (int u = i+1; u < c.Count; u++)
                        if (c[i][0] == c[u][0] && !w[u])
                        {
                            if (!b.ContainsKey((c[i][0]).ToString()))
                                b.Add(Convert.ToString(c[u][0]), Convert.ToInt32(c[i].Remove(0, 1)) + Convert.ToInt32(c[u].Remove(0, 1)));
                            else
                                b[Convert.ToString(c[i][0])] += Convert.ToInt32(c[u].Remove(0, 1));
                            f = false;
                            w[u] = true;
                        }
                    if (b.ContainsKey((c[i][0]).ToString())) { }
                    else
                        b.Add(Convert.ToString(c[i][0]), Convert.ToInt32(c[i].Remove(0, 1)));
                }
                if (b.ContainsKey((c[c.Count-1][0]).ToString())) { }
                else
                    b.Add(Convert.ToString(c[c.Count-1][0]), Convert.ToInt32(c[c.Count-1].Remove(0, 1)));
            }
            else
            {
                for (int i = 0; i < c.Count; i++)
                {
                    f = true;
                    foreach (var item in b.Keys)
                    {
                        q = Convert.ToInt32(c[i].Remove(0, 1));
                        if (item.Contains(c[i][0]))
                        {
                            b[item] += q;
                            f = false;
                            break;
                        }
                    }
                    if (f) b.Add(Convert.ToString(c[i][0]), q);
                }
            }
            string j;
            int max2 =0;
            int p = 0;
            int o;
                foreach (var i in b.Values)
                {

                    if (i > max) { max = i; o = p; }
                    p++;
                }
                p = 0;

                foreach (var i in b.Values)
                {
                    if (i > max2 && p!=0) max2 = i;
                    p++;
                }
            if (!m)
            Console.WriteLine(max+max2);
            else
                Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static bool prov(string s)
        {
            List<char> a = new List<char>();
            bool f = true;
            for (int i = 0; i < s.Length; i++)
            {
                if (!(a.Contains(s[i])))
                    if (a.Count < 2)
                    {
                        a.Add(s[i]);
                    }
                    else
                    {
                        f = false;
                        break;
                    }
            }
            return f;

        }

        static bool prov2(string s, char a)
        {
            for (int i = 0; i < s.Length; i++)
                if (s[i] != a) return false;

            return true;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s;
            List<string> a = new List<string>();
            int max = 0;

            for (int i = 0; i < n; i++)
            {
                s = Console.ReadLine();
                if (prov(s))
                {
                    a.Add(s);
                }
            }

            char x, y;
            int r = 0;
            for (int i = 0; i < 26; i++)
            {
                x = Convert.ToChar(i + 97);
                for (int u = i+1; u < 26; u++)
                {
                    y = Convert.ToChar(u + 97);
                    r = 0;
                    for (int j = 0; j < a.Count; j++)
                    {
                        if ((a[j].Contains(x) && a[j].Contains(y)) || prov2(a[j], x) || prov2(a[j], y))
                            r += a[j].Length;
                    }
                    if (r > max) max = r;
                }
            }
            Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static bool prov(string s, ref char x, ref char y)
        {
            List<char> a = new List<char>();
            bool f = true;
            for (int i = 0; i < s.Length; i++)
            {
                if (!(a.Contains(s[i])))
                    if (a.Count < 2)
                    {
                        a.Add(s[i]);
                    }
                    else
                    {
                        f = false;
                        break;
                    }
            }
            a.Sort();
            x = a[0];
            if (a.Count == 1)
                y = a[0];
            else y = a[1];
            return f;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s;
            List<string> a = new List<string>();
            List<string> c = new List<string>();
            Dictionary<string, int> b = new Dictionary<string, int>();
            for (int i = 0; i < n; i++)
            {
                char x = 'a', y = 'a';
                s = Console.ReadLine();
                if (prov(s, ref x, ref y))
                {
                    if (x == y)
                    {
                        bool e = true;
                        for (int u=0;u<c.Count;u++)
                            if (x.ToString() == c[u].Remove(1, c[u].Length - 1))
                            {
                                c[u] = x + (int.Parse(c[u].Remove(0, 1)) + s.Length).ToString();
                                e = false;
                            }
                        if (e)
                        c.Add(x + s.Count().ToString());
                    }

                    else
                    {
                        string t = Convert.ToString(x) + Convert.ToString(y);
                        a.Add(s);
                        if (b.ContainsKey(t))
                            b[t] += s.Length;
                        else
                            b.Add(t, s.Length);
                    }

                }
            }
            bool f;
            int max = -2;
            int q = 0;
            int r = 0;
            bool[] w = new bool[c.Count];
            w[0] = true;
            bool m = true;
            if (b.Count == 0) m = false;
                for (int i = 0; i < c.Count; i++)
                {
                    f = true;
                    foreach (var item in b.Keys)
                    {
                        q = Convert.ToInt32(c[i].Remove(0, 1));
                        if (item.Contains(c[i][0]))
                        {
                            b[item] += q;
                            f = false;
                            break;
                        }
                    }
                    if (f) { q = Convert.ToInt32(c[i].Remove(0, 1)); b.Add(Convert.ToString(c[i][0]), q); }
                }
            string j;
            int max2 = 0;
            int p = 0;
            int o=0;
            foreach (var i in b.Values)
            {

                if (i > max) { max = i; o = p; }
                p++;
            }
            p = 0;

            foreach (var i in b.Values)
            {
                if (i > max2 && p != o) max2 = i;
                p++;
            }
            if (!m)
                Console.WriteLine(max + max2);
            else
                Console.WriteLine(max);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace first
{
    class Program
    {
        static void Main(string[] args)
        {
            HashSet<char> allSymbols = new HashSet<char>();
            List<Tuple<int, HashSet<char>>> words = new List<Tuple<int, HashSet<char>>>();
            int count = int.Parse(Console.ReadLine());
            for (int i = 0; i < count; i++)
            {
                int length = 0;
                HashSet<char> symbols = new HashSet<char>();
                while (true)
                {
                    char c = (char) Console.Read();
                    if (c.Equals('\r'))
                    {
                        Console.Read();
                        break;
                    }
                    symbols.Add(c);
                    length++;
                }
                if (symbols.Count <= 2)
                {
                    words.Add(new Tuple<int, HashSet<char>>(length, symbols));
                    allSymbols.UnionWith(symbols);
                }
            }

            int maxLength = 0;
            foreach (char c1 in allSymbols)
            {
                {
                    int sum = words.Where(x => x.Item2.Contains(c1) && x.Item2.Count == 1).Sum(x => x.Item1);
                    maxLength = Math.Max(maxLength, sum);
                }
                foreach (char c2 in allSymbols.Except(new[] {c1}))
                {
                    int sum = words.Where(x => (x.Item2.Contains(c1) && x.Item2.Contains(c2)) ||
                                               (x.Item2.Contains(c1) && x.Item2.Count == 1 ||
                                                x.Item2.Contains(c2) && x.Item2.Count == 1)).Sum(x => x.Item1);
                    maxLength = Math.Max(maxLength, sum);
                }
            }

            Console.WriteLine(maxLength);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace first
{
    class Program
    {
        static void Main(string[] args)
        {
            HashSet<char> allSymbols = new HashSet<char>();
            List<Tuple<int, HashSet<char>>> words = new List<Tuple<int, HashSet<char>>>();
            int count = int.Parse(Console.ReadLine());
            for (int i = 0; i < count; i++)
            {
                int length = 0;
                HashSet<char> symbols = new HashSet<char>();
                while (true)
                {
                    char c = (char) Console.Read();
                    if (c.Equals('\r'))
                    {
                        Console.Read();
                        break;
                    }
                    symbols.Add(c);
                    length++;
                }
                if (symbols.Count <= 2)
                {
                    words.Add(new Tuple<int, HashSet<char>>(length, symbols));
                    allSymbols.UnionWith(symbols);
                }
            }

            int maxLength = 0;
            foreach (char c1 in allSymbols)
            {
                foreach (char c2 in allSymbols.Except(new[] {c1}))
                {
                    int sum = words.Where(x => (x.Item2.Contains(c1) && x.Item2.Contains(c2)) ||
                       (x.Item2.Contains(c1) && x.Item2.Count == 1 || x.Item2.Contains(c2) && x.Item2.Count == 1)).Sum(x => x.Item1);
                    maxLength = Math.Max(maxLength, sum);
                }
            }

            Console.WriteLine(maxLength);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace codeforce593a
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = Convert.ToInt32(Console.ReadLine());
            Dictionary<char, List<string>> chars = new Dictionary<char, List<string>>();
            for (int i = 0; i < count; i++)
            {
                string line = Console.ReadLine();
                HashSet<char> set = new HashSet<char>();
                foreach (char let in line)
                {
                    set.Add(let);
                    if (set.Count > 2)
                        break;
                }
                if (set.Count < 3)
                {
                    foreach (char let in set)
                    {
                        if (chars.Keys.Contains(let))
                        {
                            chars[let].Add(line);
                        }
                        else
                        {
                            chars.Add(let, new List<string> { line });
                        }
                    }
                }
            }
            int ccount = chars.Count;

            HashSet<string> words = new HashSet<string>();
            int max = 0;
            foreach (var i in chars)
            {
                foreach (var j in chars)
                {
                  //  if (i.Key == j.Key) continue;
                    int counter = 0;

                    bool b = true;
                    foreach (var iv in i.Value)
                    {
                        foreach (var c in iv)
                        {
                            if (!(c == i.Key || c == j.Key))
                            {
                                b = false;
                                break;
                            }

                        }
                        if (b) counter += iv.Length;
                        words.Add(iv);
                        b = true;
                    }

                    foreach (var iv in j.Value)
                    {
                        if (words.Contains(iv)) continue;
                        foreach (var c in iv)
                        {
                            if (!(c == i.Key || c == j.Key))
                            {
                                b = false;
                                break;
                            }

                        }
                        if (b) counter += iv.Length;
                        b = true;
                    }

                    if (counter > max) max = counter;
                    words.Clear();
                }
            }
            if (chars.Count==1 && chars.FirstOrDefault().Value.Count==1)
            {
                Console.WriteLine(chars.FirstOrDefault().Value[0].Length); return;
            }
            Console.WriteLine(max);
            //Console.ReadKey();
        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace codeforce593a
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = Convert.ToInt32(Console.ReadLine());
            Dictionary<char, List<string>> chars = new Dictionary<char, List<string>>();
            for (int i = 0; i < count; i++)
            {
                string line = Console.ReadLine();
                HashSet<char> set = new HashSet<char>();
                foreach (char let in line)
                {
                    set.Add(let);
                    if (set.Count > 2)
                        break;
                }
                if (set.Count < 3)
                {
                    foreach (char let in set)
                    {
                        if (chars.Keys.Contains(let))
                        {
                            chars[let].Add(line);
                        }
                        else
                        {
                            chars.Add(let, new List<string> { line });
                        }
                    }
                }
            }
            int ccount = chars.Count;

            HashSet<string> words = new HashSet<string>();
            int max = 0;
            foreach (var i in chars)
            {
                foreach (var j in chars)
                {
                    if (i.Key == j.Key) continue;
                    int counter = 0;

                    bool b = true;
                    foreach (var iv in i.Value)
                    {
                        foreach (var c in iv)
                        {
                            if (!(c == i.Key || c == j.Key))
                            {
                                b = false;
                                break;
                            }

                        }
                        if (b) counter += iv.Length;
                        words.Add(iv);
                        b = true;
                    }

                    foreach (var iv in j.Value)
                    {
                        if (words.Contains(iv)) continue;
                        foreach (var c in iv)
                        {
                            if (!(c == i.Key || c == j.Key))
                            {
                                b = false;
                                break;
                            }

                        }
                        if (b) counter += iv.Length;
                        b = true;
                    }

                    if (counter > max) max = counter;
                    words.Clear();
                }
            }

            Console.WriteLine(max);
            //Console.ReadKey();
        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication17
{
    class Program
    {
        static void Main(string[] args)
        {
            int n,maxlen=0;
            n = int.Parse(Console.ReadLine());
            var a = new string[n];
            for (int i = 0; i < n; i++) a[i] = Console.ReadLine();
            for (char c1='a';c1<='z';c1++)
                for (char c2='a';c2<='z';c2++)
                {
                    int len = 0;
                    for (int i=0;i<n;i++)
                    {
                        bool p=true;
                        for (int j=0;j<a[i].Length;j++)
                             if (a[i][j]!=c1 && a[i][j]!=c2)
                             {
                                 p = false;
                                 break;
                             }
                        if (p) len += a[i].Length;
                    }
                    if (len > maxlen) maxlen = len;
                }
            Console.WriteLine(maxlen);

        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace _2Char
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = int.Parse(reader.ReadLine());

            var nn = new List<Tuple<char, char, int>>(n);
            for (int i = 0; i < n; i++)
            {
                string s = reader.ReadLine();
                char s1 = s[0], s2 = '0';
                bool ok = true;
                for (int j = 1; j < s.Length; j++)
                {
                    if (s[j] != s1)
                    {
                        if (s2 == '0')
                            s2 = s[j];
                        else if (s2 != s[j])
                        {
                            ok = false;
                            break;
                        }
                    }
                }
                if (ok)
                    nn.Add(new Tuple<char, char, int>(s1, s2, s.Length));
            }

            int max = 0;
            for (char i = 'a'; i <= 'z'; i++)
            {
                for (char j = i; j <= 'z'; j++)
                {
                    int count = 0;
                    foreach (var tuple in nn)
                    {
                        if ((tuple.Item1 == i && (tuple.Item2 == j || tuple.Item2 == '0'))
                            || (tuple.Item1 == j && (tuple.Item2 == i || tuple.Item2 == '0')))
                            count += tuple.Item3;
                    }
                    if (count > max)
                        max = count;
                }
            }

            writer.WriteLine(max);
            writer.Flush();
        }
    }
}


using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Data;

namespace ConsoleApplication1
{
    class Program : ProgramBase
    {
        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            var n = ReadInt();
            var letters = new Dictionary<char, int>();
            var pairs = new Dictionary<string, int>();
            for (int i = 0; i < n; i++)
            {
                var w = Read();
                var chars = new string(w.OrderBy(x => x).Distinct().ToArray());
                var distCount = chars.Length;
                if (distCount == 1)
                {
                    if (!letters.ContainsKey(w[0]))
                        letters.Add(w[0], 0);
                    letters[w[0]] += w.Length;
                }
                else if (distCount == 2)
                {
                    if (!pairs.ContainsKey(chars))
                        pairs.Add(chars, 0);
                    pairs[chars] += w.Length;
                }
            }
            var max = 0;
            foreach (var item in pairs)
            {
                var sum = item.Value;
                if (letters.ContainsKey(item.Key[0]))
                    sum += letters[item.Key[0]];
                if (letters.ContainsKey(item.Key[1]))
                    sum += letters[item.Key[1]];
                if (sum > max)
                    max = sum;
            }
            var lettersOnly = letters.OrderByDescending(kv => kv.Value).Take(2).Sum(x => x.Value);
            return Math.Max(lettersOnly, max);
        }

        public int[] GetPrimes(int n)
        {
            var sieve = new bool[n + 1];
            var result = new List<int>();
            for (int i = 2; i <= n; i++)
            {
                if (!sieve[i])
                    result.Add(i);
                for (int j = i; j <= n; j += i)
                    sieve[j] = true;
            }

            return result.ToArray();
        }

        public int[] ModifiedSieve(int n)
        {
            checked
            {
                var sieve = new int[n + 1];
                for (long i = 2; i <= n; i++)
                {
                    if (sieve[i] == 0)
                    {
                        for (long k = i; k <= n; k *= i)
                            for (long j = k; j <= n; j += k)
                                sieve[j]++;
                    }
                }
                return sieve;
            }
        }

        public IEnumerable<List<int>> GetAllSubsets(int n, int remaining, int current, List<int> prefix)
        {
            if (remaining == 0)
                return new [] { new List<int>(prefix) };
            if (current == n)
                return new List<int>[0];

            var result = GetAllSubsets(n, remaining, current + 1, prefix);
            prefix.Add(current);
            var res = GetAllSubsets(n, remaining - 1, current + 1, prefix);
            prefix.Remove(current);
            return result.Union(res);
        }

        public int DFS(List<int>[] edges, int[] cats, int catsCount, int currentV, int previousCats, int? parentV)
        {
            var es = edges[currentV];
            var currentCats = (cats[currentV] == 0) ? 0 : previousCats + 1;
            if (currentCats > catsCount)
                return 0;
            if (parentV.HasValue && es.Count == 1)
                return 1;

            var result = 0;
            for (int i = 0; i < es.Count; i++)
                if (!parentV.HasValue || parentV != es[i])
                    result += DFS(edges, cats, catsCount, es[i], currentCats, currentV);
            return result;
        }

        public long BinarySearch(Func<long, double> f, int P, long left, long right)
        {
            if (left == right || right - left == 1)
                return right;

            var centre = (right + left) / 2;

            if (f(centre) >= P)
                return BinarySearch(f, P, left, centre);
            else
                return BinarySearch(f, P, centre, right);
        }
    }
    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (string.IsNullOrEmpty(FileName))
                return Console.ReadLine();
            if (f == null)
                f = new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName + ".in");
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return Convert.ToInt32(Read());
        }
        protected int[] ReadInts()
        {
            return Read().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            return Read().Split(' ').Select(x => Convert.ToInt64(x)).ToArray();
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName + ".out", r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {
            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-NB-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
        public class DSU
        {
            public int[] arr;
            private Random rand = new Random();
            public DSU(int n)
            {
                arr = new int[n];
                for (int i = 0; i < n; i++)
                {
                    arr[i] = i;
                }
            }
            public void Union(int x, int y)
            {
                var x1 = Root(x);
                var y1 = Root(y);
                if (rand.NextDouble() > 0.5)
                    arr[x1] = y1;
                else
                    arr[y1] = x1;
            }

            public int Root(int x)
            {
                if (arr[x] == x)
                    return x;
                return Root(arr[x]);
            }
            public bool Find(int x, int y)
            { return Root(x) == Root(y); }
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func)
        {
            T result = default(T);
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int [] A=new int[1500];
            for (int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                int x=0;
                for (char c1 = 'a'; c1 <= 'z'; c1++)
                {
                    for (char c2 =c1; c2 <='z'; c2++)
                    {
                        int q=0;
                        for (int k = 0; k < s.Length; k++)
                            if (s[k] == c1 || s[k] == c2)
                                q++;
                        if (q==s.Length)
                            A[x] += s.Length;
                        x++;
                    }
                }
            }
            Console.WriteLine(A.Max());
           // Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TaskA
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] words = new string[n];
            char a = 'a';
            Dictionary<Tuple<char, char>, int> letters = new Dictionary<Tuple<char, char>, int>();
            Dictionary<char, int> singles = new Dictionary<char, int>();

            for (int i = 0; i < n; i++)
            {
                words[i] = Console.ReadLine();
                List<char> symbols = new List<char>();
                bool found = false;
                bool moreThanTwo = false;

                for (int j = 0; j < words[i].Length; j++)
                {
                    found = false;
                    foreach (var symbol in symbols)
                    {
                        if (symbol == words[i][j])
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        symbols.Add(words[i][j]);
                    }

                    if (symbols.Count > 2)
                    {
                        moreThanTwo = true;
                        break;
                    }
                }

                if (!moreThanTwo)
                {
                    bool two = false;
                    char prev = words[i][0];

                    for (int j = 1; j < words[i].Length; j++)
                    {
                        if (prev != words[i][j])
                        {
                            two = true;
                            Tuple<char, char> t = null;

                            if (words[i][j] > prev)
                                t = new Tuple<char,char>(prev, words[i][j]);
                            else
                                t = new Tuple<char,char>(words[i][j], prev);

                            if (letters.ContainsKey(t))
                                letters[t] += words[i].Length;
                            else
                                letters.Add(t, words[i].Length);

                            break;
                        }
                    }

                    if (!two)
                    {
                        Tuple<char, char> t = new Tuple<char, char>(words[i][0], '1');
                        if (singles.ContainsKey(words[i][0]))
                            singles[words[i][0]]+=words[i].Length;
                        else
                            singles.Add(words[i][0], words[i].Length);

                        if (letters.ContainsKey(t))
                            letters[t] += words[i].Length;
                        else
                            letters.Add(t, words[i].Length);
                    }
                }
            }

            var k = letters.Keys.ToList();

            for (int i = 0; i < letters.Count; i++)
            {
                if (k[i].Item2 == '1')
                {
                    for (int j = 0; j < letters.Count; j++)
                    {
                        if (i != j && (k[j].Item2 == k[i].Item1 || k[j].Item1 == k[i].Item1))
                        {
                            letters[k[j]] += letters[k[i]];
                        }
                    }
                }
            }

            var keys = singles.Keys.ToList();

            for (int i = 0; i < keys.Count; i++)
            {
                for (int j = i + 1; j < keys.Count; j++)
                {
                    if (i != j)
                    {
                        Tuple<char, char> t = null;
                        if (keys[i] < keys[j])
                            t = new Tuple<char, char>(keys[i], keys[j]);
                        else
                            t = new Tuple<char, char>(keys[j], keys[i]);

                        if (!letters.ContainsKey(t))
                            letters.Add(t, singles[keys[i]] + singles[keys[j]]);
                    }
                }
            }

            int max = 0;

            foreach (var pair in letters)
            {
                if(pair.Value > max)
                {
                    max = pair.Value;
                }
            }

            Console.WriteLine(max);
            //Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TaskA
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] words = new string[n];
            char a = 'a';
            Dictionary<Tuple<char, char>, int> letters = new Dictionary<Tuple<char, char>, int>();

            for (int i = 0; i < n; i++)
            {
                words[i] = Console.ReadLine();
                List<char> symbols = new List<char>();
                bool found = false;
                bool moreThanTwo = false;

                for (int j = 0; j < words[i].Length; j++)
                {
                    found = false;
                    foreach (var symbol in symbols)
                    {
                        if (symbol == words[i][j])
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        symbols.Add(words[i][j]);
                    }

                    if (symbols.Count > 2)
                    {
                        moreThanTwo = true;
                        break;
                    }
                }

                if (!moreThanTwo)
                {
                    bool two = false;
                    char prev = words[i][0];

                    for (int j = 1; j < words[i].Length; j++)
                    {
                        if (prev != words[i][j])
                        {
                            two = true;
                            Tuple<char, char> t = null;
                            if (words[i][j] > prev)
                                t = new Tuple<char,char>(prev, words[i][j]);
                            else
                                t = new Tuple<char,char>(words[i][j], prev);
                            if (letters.ContainsKey(t))
                                letters[t] += words[i].Length;
                            else
                                letters.Add(t, words[i].Length);

                            break;
                        }
                    }

                    if (!two)
                    {
                        Tuple<char, char> t = new Tuple<char, char>(words[i][0], '1');
                        if (letters.ContainsKey(t))
                            letters[t] += words[i].Length;
                        else
                            letters.Add(t, words[i].Length);
                    }
                }
            }

            var k = letters.Keys.ToList();

            for (int i = 0; i < letters.Count; i++)
            {
                if (k[i].Item2 == '1')
                {
                    for (int j = 0; j < letters.Count; j++)
                    {
                        if (i != j && (k[j].Item2 == k[i].Item1 || k[j].Item1 == k[i].Item1))
                        {
                            letters[k[j]] += letters[k[i]];
                        }
                    }
                }
            }
            int max = 0;

            foreach (var pair in letters)
            {
                if(pair.Value > max)
                {
                    max = pair.Value;
                }
            }

            Console.WriteLine(max);
            //Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
using System.Numerics;
using System.Globalization;
using System.Threading;

namespace probleme {
    class Program {
        static void Main(string[] args) {
            Console.SetIn(new StreamReader("file.txt"));
            int n = int.Parse(Console.ReadLine());
            int[,] m = new int['z' - 'a' + 1, 'z' - 'a' + 1];
            for (int i = 0; i < n; i++) {
                char[] aux = Console.ReadLine().ToCharArray();
                int[] ap = new int['z' - 'a' + 1];
                for (int j = 0; j < aux.Length; j++) {
                    ap[aux[j] - 'a']++;
                }
                int diff = 0, pr = 0, sc = 0;
                for (int j = 'a'; j <= 'z'; j++) {
                    if (ap[j - 'a'] > 0) {
                        diff++;
                        if (diff == 1) {
                            pr = j - 'a';
                        } else if (diff == 2) {
                            sc = j - 'a';
                        }
                    }
                }
                if (diff == 1) {
                    m[pr, pr] += aux.Length;
                } else if (diff == 2) {
                    m[pr, sc] += aux.Length;
                    m[sc, pr] += aux.Length;
                }
            }
            int ans = 0;
            int c1 = 0, c2 = 0;
            for (int i = 'a'; i <= 'z'; i++) {
                for (int j = 'a'; j <= 'z'; j++) {
                    if (j == i) {
                        continue;
                    }
                    int sum = m[i - 'a', i - 'a'] + m[j - 'a', j - 'a'] + m[i - 'a', j - 'a'];
                    if (sum > ans) {
                        ans = sum;
                        c1 = i - 'a';
                        c2 = j - 'a';
                    }
                }
            }
            Console.Write(ans);
            Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
using System.Numerics;
using System.Globalization;
using System.Threading;

namespace probleme {
    class Program {
        static void Main(string[] args) {
            //Console.SetIn(new StreamReader("file.txt"));
            int n = int.Parse(Console.ReadLine());
            int[,] m = new int['z' - 'a' + 1, 'z' - 'a' + 1];
            for (int i = 0; i < n; i++) {
                char[] aux = Console.ReadLine().ToCharArray();
                int[] ap = new int['z' - 'a' + 1];
                for (int j = 0; j < aux.Length; j++) {
                    ap[aux[j] - 'a']++;
                }
                int diff = 0, pr = 0, sc = 0;
                for (int j = 'a'; j <= 'z'; j++) {
                    if (ap[j - 'a'] > 0) {
                        diff++;
                        if (diff == 1) {
                            pr = j - 'a';
                        } else if (diff == 2) {
                            sc = j - 'a';
                        }
                    }
                }
                if (diff == 1) {
                    m[pr, pr] += aux.Length;
                } else if (diff == 2) {
                    m[pr, sc] += aux.Length;
                    m[sc, pr] += aux.Length;
                }
            }
            int ans = 0;
            for (int i = 'a'; i <= 'z'; i++) {
                for (int j = 'a'; j <= 'z'; j++) {
                    int sum = m[i - 'a', i - 'a'] + m[j - 'a', j - 'a'] + m[i - 'a', j - 'a'];
                    if (sum > ans) {
                        ans = sum;
                    }
                }
            }
            Console.Write(ans);
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
using System.Numerics;
using System.Globalization;
using System.Threading;

namespace probleme {
    class Program {
        static void Main(string[] args) {
            //Console.SetIn(new StreamReader("file.txt"));
            int n = int.Parse(Console.ReadLine());
            int[,] m = new int['z' - 'a' + 1, 'z' - 'a' + 1];
            for (int i = 0; i < n; i++) {
                char[] aux = Console.ReadLine().ToCharArray();
                int[] ap = new int['z' - 'a' + 1];
                for (int j = 0; j < aux.Length; j++) {
                    ap[aux[j] - 'a']++;
                }
                int diff = 0, pr = 0, sc = 0;
                for (int j = 'a'; j <= 'z'; j++) {
                    if (ap[j - 'a'] > 0) {
                        diff++;
                        if (diff == 1) {
                            pr = j - 'a';
                        } else if (diff == 2) {
                            sc = j - 'a';
                        }
                    }
                }
                if (diff == 1) {
                    m[pr, pr] += aux.Length;
                } else if (diff == 2) {
                    m[pr, sc] += aux.Length;
                    m[sc, pr] += aux.Length;
                }
            }
            int ans = 0;
            int c1 = 0, c2 = 0;
            for (int i = 'a'; i <= 'z'; i++) {
                for (int j = 'a'; j <= 'z'; j++) {
                    if (j == i) {
                        continue;
                    }
                    int sum = m[i - 'a', i - 'a'] + m[j - 'a', j - 'a'] + m[i - 'a', j - 'a'];
                    if (sum > ans) {
                        ans = sum;
                        c1 = i - 'a';
                        c2 = j - 'a';
                    }
                }
            }
            Console.Write(ans);
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
    class Program
    {
        static void Main(string[] args)
        {
            //var sr = new InputReader(new StreamReader(new FileStream("input.txt", FileMode.Open)));
            var sr = new InputReader(Console.In);
            var task = new Task();
            task.Solve(1, sr, Console.Out);
            //Console.ReadKey();
        }
    }

    class Task
    {
        public void Solve(int testNumber, InputReader sr, TextWriter sw)
        {
            var n = sr.NextInt32();
            var array = new string[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = sr.NextString();
            }
            var dicts = new string[n];
            for (var i = 0; i < n; i++)
            {
                var next = array[i];
                var str = "";
                var can = true;
                for (var j = 0; j < array[i].Length; j++)
                {
                    if (!str.Contains(array[i][j]))
                    {
                        str += array[i][j];
                        if (str.Length > 2)
                        {
                            can = false;
                            break;
                        }
                    }
                }
                if (can)
                {
                    dicts[i] = str;
                }
            }
            var max = 0;
            for (var i = 0; i < 26; i++)
            {
                for (var j = 0; j < 26; j++)
                {
                    var first = (char) (97 + i);
                    var second = (char) (97 + j);
                    var len = 0;
                    for (var k = 0; k < n; k++)
                    {
                        if (dicts[k] != null)
                        {
                            if (dicts[k].Length == 1)
                            {
                                if (dicts[k][0] == first || dicts[k][0] == second)
                                {
                                    len += array[k].Length;
                                }
                            }
                            else
                            {
                                if ((array[k][0] == first && array[k][1] == second) ||
                                    (array[k][0] == second && array[k][1] == first))
                                {
                                    len += array[k].Length;
                                }
                            }
                        }
                    }
                    if (max < len)
                    {
                        max = len;
                    }
                }
            }

            sw.WriteLine(max);
        }
    }

    class InputReader : IDisposable
    {
        private readonly TextReader sr;
        private bool isDispose = false;
        public InputReader(TextReader stream)
        {
            sr = stream;
        }

        public string NextString()
        {
            var result = sr.ReadLine();
            return result;
        }

        public int NextInt32()
        {
            return Int32.Parse(NextString());
        }

        public long NextInt64()
        {
            return Int64.Parse(NextString());
        }

        public string[] NextSplitStrings()
        {
            return NextString()
                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        }

        public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
        {
            return NextSplitStrings()
                    .Select(s => func(s, CultureInfo.InvariantCulture))
                    .ToArray();
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected void Dispose(bool dispose)
        {
            if (!isDispose)
            {
                if (dispose)
                {
                    sr.Close();
                }
                isDispose = true;
            }
        }

        ~InputReader()
        {
            Dispose(false);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
    class Program
    {
        static void Main(string[] args)
        {
            //var sr = new InputReader(new StreamReader(new FileStream("input.txt", FileMode.Open)));
            var sr = new InputReader(Console.In);
            var task = new Task();
            task.Solve(1, sr, Console.Out);
            //Console.ReadKey();
        }
    }

    class Task
    {
        public void Solve(int testNumber, InputReader sr, TextWriter sw)
        {
            var n = sr.NextInt32();
            var array = new string[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = sr.NextString();
            }
            var dicts = new string[n];
            for (var i = 0; i < n; i++)
            {
                var str = "";
                var can = true;
                for (var j = 0; j < array[i].Length; j++)
                {
                    if (!str.Contains(array[i][j]))
                    {
                        str += array[i][j];
                        if (str.Length > 2)
                        {
                            can = false;
                            break;
                        }
                    }
                }
                if (can)
                {
                    dicts[i] = str;
                }
            }
            var max = 0;
            for (var i = 0; i < 26; i++)
            {
                for (var j = 0; j < 26; j++)
                {
                    if (i != j)
                    {
                        var first = (char) (97 + i);
                        var second = (char) (97 + j);
                        var len = 0;
                        for (var k = 0; k < n; k++)
                        {
                            if (dicts[k] != null)
                            {
                                if (dicts[k].Length == 1)
                                {
                                    if (dicts[k][0] == first || dicts[k][0] == second)
                                    {
                                        len += array[k].Length;
                                    }
                                }
                                else
                                {
                                    if ((array[k][0] == first && array[k][1] == second) ||
                                        (array[k][0] == second && array[k][1] == first))
                                    {
                                        len += array[k].Length;
                                    }
                                }
                            }
                        }
                        if (max < len)
                        {
                            max = len;
                        }
                    }
                }
            }

            sw.WriteLine(max);
        }
    }

    class InputReader : IDisposable
    {
        private readonly TextReader sr;
        private bool isDispose = false;
        public InputReader(TextReader stream)
        {
            sr = stream;
        }

        public string NextString()
        {
            var result = sr.ReadLine();
            return result;
        }

        public int NextInt32()
        {
            return Int32.Parse(NextString());
        }

        public long NextInt64()
        {
            return Int64.Parse(NextString());
        }

        public string[] NextSplitStrings()
        {
            return NextString()
                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        }

        public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
        {
            return NextSplitStrings()
                    .Select(s => func(s, CultureInfo.InvariantCulture))
                    .ToArray();
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected void Dispose(bool dispose)
        {
            if (!isDispose)
            {
                if (dispose)
                {
                    sr.Close();
                }
                isDispose = true;
            }
        }

        ~InputReader()
        {
            Dispose(false);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF317
{
    class Program
    {
        static void Main(string[] args)
        {
            //var sr = new InputReader(new StreamReader(new FileStream("input.txt", FileMode.Open)));
            var sr = new InputReader(Console.In);
            var task = new Task();
            task.Solve(1, sr, Console.Out);
            //Console.ReadKey();
        }
    }

    class Task
    {
        public void Solve(int testNumber, InputReader sr, TextWriter sw)
        {
            var n = sr.NextInt32();
            var array = new string[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = sr.NextString();
            }
            var dicts = new string[n];
            for (var i = 0; i < n; i++)
            {
                var str = "";
                var can = true;
                for (var j = 0; j < array[i].Length; j++)
                {
                    if (!str.Contains(array[i][j]))
                    {
                        str += array[i][j];
                        if (str.Length > 2)
                        {
                            can = false;
                            break;
                        }
                    }
                }
                if (can)
                {
                    dicts[i] = str;
                }
            }
            var max = 0;
            for (var i = 0; i < 26; i++)
            {
                for (var j = 0; j < 26; j++)
                {
                    if (i != j)
                    {
                        var first = (char) (97 + i);
                        var second = (char) (97 + j);
                        var len = 0;
                        for (var k = 0; k < n; k++)
                        {
                            if (dicts[k] != null)
                            {
                                if (dicts[k].Length == 1)
                                {
                                    if (dicts[k][0] == first || dicts[k][0] == second)
                                    {
                                        len += array[k].Length;
                                    }
                                }
                                else
                                {
                                    if ((dicts[k][0] == first && dicts[k][1] == second) ||
                                        (dicts[k][0] == second && dicts[k][1] == first))
                                    {
                                        len += array[k].Length;
                                    }
                                }
                            }
                        }
                        if (max < len)
                        {
                            max = len;
                        }
                    }
                }
            }

            sw.WriteLine(max);
        }
    }

    class InputReader : IDisposable
    {
        private readonly TextReader sr;
        private bool isDispose = false;
        public InputReader(TextReader stream)
        {
            sr = stream;
        }

        public string NextString()
        {
            var result = sr.ReadLine();
            return result;
        }

        public int NextInt32()
        {
            return Int32.Parse(NextString());
        }

        public long NextInt64()
        {
            return Int64.Parse(NextString());
        }

        public string[] NextSplitStrings()
        {
            return NextString()
                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        }

        public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
        {
            return NextSplitStrings()
                    .Select(s => func(s, CultureInfo.InvariantCulture))
                    .ToArray();
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected void Dispose(bool dispose)
        {
            if (!isDispose)
            {
                if (dispose)
                {
                    sr.Close();
                }
                isDispose = true;
            }
        }

        ~InputReader()
        {
            Dispose(false);
        }
    }
}