Problem:
Score : 200 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters.
We will cut this string at one position into two strings X and Y.
Here, we would like to maximize the number of different letters contained in both X and Y.
Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.

Constraints

2 \leq N \leq 100

|S| = N

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the largest possible number of different letters contained in both X and Y.

Sample Input 1

6
aabbca

Sample Output 1

2

If we cut the string between the third and fourth letters into X = aab and Y = bca, the letters contained in both X and Y are a and b.
There will never be three or more different letters contained in both X and Y, so the answer is 2.

Sample Input 2

10
aaaaaaaaaa

Sample Output 2

1

However we divide S, only a will be contained in both X and Y.

Sample Input 3

45
tgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir

Sample Output 3

9

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

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

public class Prog
{
    public void run()
    {
        int N = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();
        List<char> bef = new List<char>();
        List<char> aft = new List<char>();
        int count = 0;
        int ans = 0;
        for(int i = 1; i < S.Length - 1; i++)
        {
            for(int j=0;j<i;j++)
            {
                if( !bef.Contains(S[j]))
                {
                    bef.Add(S[j]);
                }
            }
            for(int j=i;j<S.Length;j++)
            {
                if( !aft.Contains(S[j]))
                {
                    aft.Add(S[j]);
                }
            }
            for(int j=0;j<bef.Count;j++)
            {
                if(aft.Contains(bef[j]))
                {
                    count++;
                }
            }
            ans = Math.Max(ans, count);
            bef.Clear();
            aft.Clear();
            count = 0;
        }
        Console.WriteLine(ans);
    }
    public static void Main()
    {
        var prog = new Prog();
        prog.run();
    }

    /*
    最小公倍数
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }

    // ユークリッドの互除法 
    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
    */
    //a<=c, b<=d;
}

//Split().Select(int.Parse).ToArray()
//Array.ConvertAll(int.Parse)
//str.IndexOf("Stage",System.StringComparison.CurrentCulture)