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 (Clang 3.8.0) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int string(char *front,char *buck,int num,int N);

int main(void){
  int N,i,j,k,l[2],count,max;
  char str[105],s[105],*p,front[105],buck[105];
  
  fgets(str,sizeof(str),stdin);
  N=atoi(str);
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  strcpy(s,p);
  
  for(i=0,max=0;i<N;i++){
    strcpy(front,s);
    p=&s[i+1];
    front[i+1]='\0';
    strcpy(buck,p);
    
    string(front,buck,i,N);
    
    l[0]=strlen(front);
    l[1]=strlen(buck);
    
    if(l[0]<=l[1]){
      for(j=0,count=0;j<l[0];j++){
        for(k=0;k<l[1];k++){
          if(front[j]==buck[k]){
            count++;
          }
        }
      }
    }
    if(max<count){
      max=count;
    }
  }
  
  printf("%d\n",max);
  
  return 0;
}

int string(char *front,char *buck,int num,int N){
  int i,j;
  char buff;
  
  for(i=0;i<=num;i++){
    for(j=num;j>i;j--){
      if(front[j-1]>front[j]){
        buff=front[j-1],front[j-1]=front[j],front[j]=buff;
      }
    }
  }
  i=0;
  while(front[i]!='\0'){
    if(front[i]==front[i+1]){
      for(j=i;front[j]!='\0';j++){
        front[j]=front[j+1];
      }
    }else{
      i++;
    }
  }
  
  for(i=0;i<N-num-1;i++){
    for(j=N-num-2;j>i;j--){
      if(buck[j-1]>buck[j]){
        buff=buck[j-1],buck[j-1]=buck[j],buck[j]=buff;
      }
    }
  }
  
  i=0;
  while(buck[i]!='\0'){
    if(buck[i]==buck[i+1]){
      for(j=i;buck[j]!='\0';j++){
        buck[j]=buck[j+1];
      }
    }else{
      i++;
    }
  }
  
  return 0;
}