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 (Python):
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    ans = max(ans, len(set(S[:i]) & set(S[i:])))
print(ans)

Solution (Python):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
s = ns()

ans = [0]

for i in range(1, n-1):
    set_x = set(s[:i])
    set_y = set(s[i:])
    ans.append(len(set_x & set_y))

print(max(ans))

Solution (Python):
from collections import Counter
N = int(input())
S = input()
ans = 0
for i in range(1,N):
    cnt = 0
    count1 = Counter(S[:i])
    count2 = Counter(S[i:])
    for char in [chr(i) for i in range(97, 97+26)]:
        if char in count1.keys() and char in count2.keys():
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Solution (Python):
n=int(input())
s=str(input())

alp=['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']
l=[]
for i in range(n):
    x=s[:i]
    y=s[i:]
    c=0
    for j in alp:
        if (j in x) and (j in y):
            c+=1
    l.append(c)
print(max(l))

Solution (Python):
import sys  
import numpy as np

input = sys.stdin.readline
N = int(input())
S = list(input())

S = S[:-1]

temp = []
for i in range(1,N):
    a = S[:i]
    b = S[i:]
    a = list(set(a))
    b = list(set(b))

    j = list(set(a+b))
    
    temp.append(len(a) + len(b) - len(j))
    

print(max(temp))

Solution (Python):
n = int(input())
s = input()
result = []
for i in range(1,n):
  a = s[:i]
  b= s[i:]
  r = set(a) & set(b)
  result.append(len(r))
print(max(result))

Solution (Python):

import io

n,m = int(input()),input()
array=[]
for i in range(1,n):
    array.append(len(list(set(m[:i])&set(m[i:]))))
print(max(array))

Solution (Python):
n = int(input())
s = list(input())
ans = 0

for i in range(1,n):
    a = set(s[:i])
    b = set(s[i:])
    c = a & b
    if len(c) > ans:
        ans = len(c)

print(ans)

Solution (Python):
N=int(input())
S=input()
T=[]
for i in range(N):
    A=set(S[0:i])
    B=set(S[i:N+1])
    C=set(A&B)
    T.append(len(C))
print(max(T))

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1, n):
    l = set(s[:i])
    r = set(s[i:])
    ans = max(ans, len(l.intersection(r)))
print(ans)

Solution (Python):
def main():
    N = int(input())
    S = input()
    mcount = 0
    for i in range(N):
        l = S[:i]
        r = S[i:]
        c = len(set.intersection(set(l), set(r)))
        if mcount < c:
            mcount = c
    print(mcount)
main()

Solution (Python):
n = int(input())
s = list(input())
ans = 0

for i in range(1,n):
    a = set(s[:i])
    b = set(s[i:])
    c = a & b
    if len(c) > ans:
        ans = len(c)

print(ans)

Solution (Python):

n = int(input())
s = input()

kinds = 0

for k in range(1, len(s) - 1):
    kinds = max(kinds, len(set(s[0:k]) & set(s[k:])))

print(kinds)

Solution (Python):
n = int(input())
s = list(input())
l = []
for i in range(n):
    l.append(len(set(s[:i]) & set(s[i:])))
print(max(l))

Solution (Python):
from collections import Counter
N = int(input())
s = input()
mx = 0
for i in range(1,N):
    ans1 = dict(Counter(s[:i]))
    ans2 = dict(Counter(s[i:]))
    count = 0
    for j in ans1:
        if j in ans2:
            count += 1
    mx = max(mx,count)
    
print(mx)

Solution (Python):
n=int(input())
s=input()
ans=[]
for i in range(1,n):
    l=set(s[:i])
    r=set(s[i:])
    a=0
    for li in l:
        if li in r:
            a+=1
    ans.append(a)
print(max(ans))

Solution (Python):
N = int(input())
S = input()

ans = 0
for i in range(1, N):
    X = set([s for s in S[:i]])
    Y = set([s for s in S[i:]])
    ans = max(ans, len(X.intersection(Y)))

print(ans)

Solution (Python):
n = int(input())
s = input()
def kinds(x,y):
    cnt = {}
    res = 0
    for s in x:
        if s not in cnt:cnt[s] = 1
        else:cnt[s]+=1
    c = {}
    for s in y:
        if s not in c and s in cnt:
            res+=1
            c[s] = 1
    return res
ans = 0
for i in range(n-1):
    ans = max(ans,kinds(s[:i+1],s[i+1:]))
    
    
print(ans)

Solution (Python):
n = int(input())
S = input().strip()
print(max(len(set(S[:i+1]) & set(S[i+1:])) for i in range(n-1)))

Solution (Python):
n = int(input())
s = input()
ans = 0

for i in range(1,n):
    x = ''.join(set(s[:i]))
    y = ''.join(set(s[i:]))
    z = 0
    for j in y:
        if j in x:
            z += 1
    if z > ans:
        ans = z
        
print(ans)

Solution (Python):
n = int(input())
s = list(input())
print(max([len(set(s[:i])&set(s[i:])) for i in range(1,n)]))

Solution (Python):
n = int(input())
s = list(input())
ans = 0
for i in range(1,n):
  c = 0
  for j in set(s[:i]):
    if j in set(s[i:]):
      c += 1
  ans = max(ans,c)
print(ans)

Solution (Python):
N = int(input())
S = input()
res = 0

for i in range(1,N):
  count = 0
  S_f = set(S[:i])
  S_l = set(S[i:])
  for s in S_f:
    if s in S_l:
      count += 1
  if res < count: res = count
    
print(res)

Solution (Python):
n=int(input())
s = input()
b = list()
for i in range(n):
    a = set(s[:i]) & set(s[i:])
    
    b.append(len(a))
print(max(b))

Solution (Python):
n = int(input())
s = input()
maxV = 0

for i in range(n):
    se = set()
    s1 = s[0:i]
    s2 = s[i:n]
    count = 0
    for j in s1:
        for k in s2:
            if j == k and not j in se:
                se.add(j)
                count += 1
        maxV = max(count, maxV)
print(maxV)

Solution (Python):
n=int(input())
s=input()
M=0
for i in range(1,n):
  s1=s[0:i]
  s2=s[i:n]
  S1=set(s1)
  S2=set(s2)
  m=len(S1&S2)
  M=max(M,m)
print(M)

Solution (Python):
n, s, c = int(input()), input(), 0
for i in range(1, n):
  c = max(c, len(set(s[:i]) & set(s[i:])))
print(c)

Solution (Python):
n = int(input())
s = input()
l = []
for i in range(n):
    l.append(s[i])
ans = 0
for m in range(n):
    sx = set(l[0 : m])
    sy = set(l[m:])
    ans = max(ans, len(sx & sy))
print(ans)

Solution (Python):
input()
s = input()
a = 0
for i in range(1,len(s)-1):
  x = set(s[:i]) & set(s[i:])
  if a< len(x):
    a = len(x)
print(a)

Solution (Python):
N = int(input())
S = input()

left = {c: 0 for c in S}
right = {c: 0 for c in S}
for c in S:
    right[c] += 1

ans = 0
common = 0
for i in range(N):
    left[S[i]] += 1
    right[S[i]] -= 1
    if left[S[i]] == 1 and right[S[i]] >= 1:
        common += 1
    elif left[S[i]] > 1 and right[S[i]] == 0:
        common -= 1

    ans = max((ans, common))

print(ans)

Solution (Python):
n=int(input())
s=input()
y=[]
for i in range(1,n):
    x=0
    m=list(dict.fromkeys(s[0:i]))
    for j in range(len(m)):
        if m[j] in s[i:n]:
            x+=1
    y.append(x)

y=sorted(y)
print(y[-1])

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(1,N):
    a = set(S[:i])
    b = set(S[i:])
    ans = max(ans,len(a&b))
print(ans)

Solution (Python):
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    S = list(iss())
    ret = 0
    for n in range(N):
        ret = max(ret, len(set(S[:n]) & set(S[::-1][:-n])))
    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
S = list(str(input()))

ans = 0
for i in range(1, N):
    X = set(S[0:i])
    Y = set(S[i:N])
    if ans < len(X & Y):
        ans = len(X & Y)

print(ans)

Solution (Python):
n = int(input())
s = input()

ans = 0
for i in range(1,n):
    x = list(set(list(s[:i])))
    y = list(set(list(s[i:])))
    c, d = 0, 0
    for j in x:
        c += y.count(j)
    for j in y:
        d += x.count(j)
    ans = max(c,d,ans)
print(ans)

Solution (Python):
N = int(input())
S = input()

ans = -1
for i in range(N-1):
    
    
    set_str = set(S[0:i+1]) & set(S[i+1:N])

    if ans < len(set_str):
        ans = len(set_str)

print(ans)

Solution (Python):
N = int(input())
S = list(input())
cnt = [0]
for i in range(N):
    S1 = set(S[:i+1])
    S2 = set(S[i+1:])
    cnt.append(len(S1&S2))
max_cnt=max(cnt)
print(max_cnt)

Solution (Python):
int(input())
a=str(input())
b,c,d=set(),set(),set()
e=0
for i in range(len(a)):
    for j in range(i):
        b.add(a[j])
    for k in range(i,len(a)):
        c.add(a[k])
    for l in range(len(b)):
        b=list(b)
        if b[l] in c:
            e+=1
    d.add(e)
    b,c=set(),set()
    e=0
print(max(d))

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(1,n):
    unq=len(list(set(s[:i]) & set(s[i:])))
    if  unq>ans:
        ans=unq
print(ans)

Solution (Python):
def solve():
    N = int(input())
    S = input()

    mx = 0
    for i in range(1,N):
        former = set(S[:i])
        latter = set(S[i:])

        cnt = 0
        for elem in former:
            if elem in latter:
                cnt += 1
        
        mx = max(cnt,mx)
    
    print(mx)

if __name__ == '__main__':
    solve()

Solution (Python):
import collections

N,S = open(0).read().split()
max_d = 0
for i in range(int(N)):
  A = set(list(S[:i]))
  B = set(list(S[i:]))
  if max_d < len(A&B):
    max_d = len(A&B)
print(max_d)

Solution (Python):
N = int(input())
S = input()

M = 0
for i in range(1, N):
    
    temp = len(set(list(S[:i])) & set(list(S[i:])))
    M = max(M, temp)
print(M)

Solution (Python):
N=int(input())
S=input()

answer=0
for i in range(1,N):
  S1=S[:i]
  S2=S[i:]
  
  s1_set=set()
  for c1 in S1:
    s1_set.add(c1)
  s2_set=set()
  for c2 in S2:
    s2_set.add(c2)
    
  cnt=0
  for c1 in s1_set:
    if c1 in s2_set:
      cnt+=1
      
  answer=max(answer,cnt)
  
print(answer)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(n-1):
  cnt = 0
  for alp in range(ord('a'),ord('z')+1):
    if chr(alp) in s[:i+1] and chr(alp) in s[i+1:]:
      cnt += 1
  ans = max(ans, cnt)
print(ans)

Solution (Python):
n=int(input())
s=input()
total=0
for i in range(1,n):
    a=s[:i]
    b=s[i:]
    a=set(list(a))
    b=set(list(b))
    numa=len(a)
    numb=len(b)
    numc=len(a|b)
    shurui=numa+numb-numc
    total=max(total,shurui)
    
print(total)

Solution (Python):
import sys

def resolve():
    N = int(input())
    S = input()
    res = 0
    for i in range(1, N-1):
        cnt = 0
        left = S[:i]
        right = S[i:]
        counted = []
        for s in left:
            if s in right and s not in counted:
                counted.append(s)
                cnt += 1

        res = max(cnt, res)
    print(res)

if '__main__' == __name__:
    resolve()

Solution (Python):
n=int(input())
s=input()
ans,p=0,0
for i in range(n-1):
    sets=list(set(s[:i+1]))
    if ans>p:
        p=ans
    ans=0
    for j in range(len(sets)):
        if sets[j] in s[i+1:]:
            ans+=1
        
print(p)

Solution (Python):

import math




n = int(input())


s = input()
ans = 0
for i in range(1,len(s)):
    a = s[:i]
    b = s[i:]
    count = 0
    for j in range(len(a)):
        if a[j] in b:
            flag = True
            if j > 0:
                for k in range(j):
                    if a[j]==a[k]:
                        flag=False
            if flag:
                count += 1
                
    
    
    if ans < count:
        ans = count

print(ans)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(n-1):
    s1=s[:i+1]
    s2=s[i+1:]
    s3=set(s1)&set(s2)
    ans=max(ans,len(s3))
print(ans)

Solution (Python):
N = int(input())
S =input()

alpha = 'abcdefghijklmnopqrstuvwxyz'
ans = -1

for i in range(N-1):
    count = 0
    for j in range(26):
        if alpha[j] in S[0:i] and alpha[j] in S[i:N]:
            count += 1
    ans = max(ans,count)
    
print(ans)

Solution (Python):
n=int(input())
s=str(input())
l=[]
cnt=0
ans=[]

for i in range(1,n):
    for j in range(i):
        if s[j] not in l:
            l.append(s[j])
    
    for j in range(i, len(s)):
        if s[j] in l:
            del l[l.index(s[j])]
            cnt+=1

    ans.append(cnt)
    
    l=[]
    cnt=0

print(max(ans))

Solution (Python):
N=int(input())
S=input()
ans=0

for i in range(N):
    S1=S[:i]
    S2=S[i:]
    Count=len(set(S1) & set(S2))
    if Count>=ans:
        ans=Count

print(ans)

Solution (Python):
N = int(input())
S = input()
ans = 0

for i in range(1, N):
    tmp = 0
    check_char_list = set(list(S[:i]))
    for item in set(list(S[i:])):
        if item in check_char_list:
            tmp += 1
    ans = max(ans, tmp)

print(ans)

Solution (Python):
n = int(input())
s = str(input())

max = 0
for i in range(n):
  x = set(s[:i]) & set(s[i:])
  if max < len(x):
    max = len(x)
print(max)

Solution (Python):
n = int(input())
s = input()
a = [s[i] for i in range(n)]
ans = 0
for i in range(1, n):
    l = set(a[:i])
    r = set(a[i:])
    ans = max(ans, len(l & r))
print(ans)

Solution (Python):
n = int(input())
s = input()

max_ = 0
for i in range(n):
  cand = set(s[:i]) & set(s[i:])
  if max_ < len(cand):
    max_ = len(cand)
print(max_)

Solution (Python):
n = int(input())
s = input()

mxcnt = 0
for i in range(n):
    xy = set(s[:i]) & set(s[i:])
    mxcnt = max(mxcnt, len(xy))
print(mxcnt)

Solution (Python):
n = int(input())
s = str(input())
ans = 0
for k in range(1, n):
  s1 = set(c for c in s[:k])
  s2 = set(c for c in s[k:])
  ans = max(ans, len(s1 & s2))
print(ans)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(n):
    x=list(set(s[:i+1]))
    y=list(set(s[i+1:]))
    cnt=0
    for j in range(min(len(x),len(y))):
        if i<=n//2:
            if x[j] in y:
                cnt+=1
        else:
            if y[j] in x:
                cnt+=1
    ans=max(ans,cnt)
print(ans)

Solution (Python):
n = int(input())
s = input()

maxs = 0
for i in range(1, len(s)):
  maxs = max(maxs, len(set(s[:i]) & set(s[i:])))
  
print(maxs)

Solution (Python):
n = int(input())
s = input()
ch = []
for i in range(0, n):
    x = s[:i+1]
    y = s[i+1:len(s)]
    a = set(x)
    b = set(y)
    c = a.intersection(b)
    ch.append(len(c))
print(max(ch))

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1,n):
        s1 = s[:i]
        s2 = s[i:]
        a = set()
        b = set()
        c = set()
        for j in s1:
                a.add(j)
        for j in s2:
                b.add(j)
        c = a & b
        ans = max(ans,len(c))
print (ans)

Solution (Python):










"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n = int(input())
  s = list(input())
  
  mid = [len(set(s[:i]) & set(s[i:])) for i in range(0,n)]
  print(max(mid))
  
if __name__ == '__main__':
  main()

Solution (Python):
n = int(input())
s = list(input())
ans = 0
for i in range(n):
    l = list(set(s[:i]))
    r = list(set(s[i:]))
    cnt = 0
    for j in range(len(l)):
        if l[j] in r:
            cnt += 1
    ans = max(ans,cnt)
print(ans)

Solution (Python):
N = int(input())
S = input()
ans = -1
for i in range(N):
    S1 = S[0:i+1]
    S2 = S[i+1:]
    
    dic_S1 = {}
    for j in S1:
        if j not in dic_S1:
            dic_S1[j] = 1
    tmp = 0
    for j in S2:
        if j in dic_S1:
            tmp += 1
            del dic_S1[j]
    ans = max(tmp, ans)
print(ans)

Solution (Python):
n = int(input())
s = input() 

ans = 0
for i in range(1,n):
    x = list(set(s[:i]))
    y = list(set(s[i:]))
    if len(x) >= len(y):
        ans = max(ans, len(x) - len(list(set(x)- set(y))))
    else:
        ans = max(ans, len(y) - len(list(set(y)- set(x))))


print(ans)

Solution (Python):
def main():
    n = int(input())
    s = input()
    mx = 0

    for i in range(n):
        left = s[:i]
        right = s[i:]
        mx = max(mx,len(set(left) & set(right)))

    print(mx)



if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
s=input()
a=0
for i in range(n):
    b=sum(j in s[i:] for j in set(s[:i]))
    a=max(a,b)
print(a)

Solution (Python):
from collections import Counter

N = int(input())
S = str(input())
ans = 0

for slash in range(N - 1):
    ctr = 0
    S_r_dic = dict()
    S_l = S[: slash + 1]
    S_r = S[slash + 1 :]
    for s in S_r:
        if s not in S_r_dic and s in Counter(S_l):
            ctr += 1
            S_r_dic[s] = 1
    ans = max(ctr, ans)

print(ans)

Solution (Python):
n = int(input())
list_S = list(input())
ans = 0

for i in range(n):
    k = set(list_S[:i])
    l = set(list_S[i:])
    m = k & l
    ans = max(ans, len(m))

print(ans)

Solution (Python):
n=int(input())
s=list(input())
ab= [len(set(s[:i]) & set(s[i:])) for i in range(0,n)]
print(max(ab))

Solution (Python):
from collections import defaultdict

n = int(input())
s = input()

ans = 0
for i in range(n):
    dic = defaultdict(int)
    for j in range(i):
        for k in range(i, n):
            if s[j] == s[k]:
                dic[s[j]] += 1
                break
    ans = max(ans, len(dic))
    
print(ans)

Solution (Python):
n = int(input())
s = input()
max_v = 0

for i in range(1,n):
    tmp1 = s[:i]
    tmp2 = s[i:]
    tmp1 = set(tmp1)
    tmp1 = list(tmp1)
    tmp2 = set(tmp2)
    tmp2 = list(tmp2)
    ans = 0
    for j in range(len(tmp1)):
        if tmp1[j] in tmp2:
            ans += 1
    max_v = max(max_v,ans)
    
print(max_v)

Solution (Python):
import collections
n = int(input())
s = list(input())

ans = 0
for i in range(1, n):
    TF = [False] * 26
    x = s[0:i]
    y = s[i:]
    col = collections.Counter(x)
    sub = 0
    for one in y:
        if TF[ord(one) - 97] == False:
            if one in col:
                sub += 1
                TF[ord(one) - 97] = True
    ans = max(ans, sub)

print(ans)

Solution (Python):
n = int(input())
s = list(input())

res = 0
for i in range(1, n):
    s1 = set(s[:i])
    s2 = set(s[i: n])
    cnt = 0
    for i in s1:
        if i in s2:
            cnt += 1
    res = max(res, cnt)
print(res)

Solution (Python):
N = int(input())
S = input()
ans = 0

for i in range(1, N):
    S1 = S[:i]
    S2 = S[i:]
    list_S1 = list(S1)
    list_S2 = list(S2)
    _and = set(list_S1) & set(list_S2)
    and_num = len(_and)
    if ans < and_num:
        ans = and_num

print(ans)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(1,n):
    a=set(s[:i])
    b=set(s[i:])
    cnt = 0
    for i in a:
        for j in b:
            if i == j:
                cnt += 1
                break
        ans=max(cnt,ans)
print(ans)

Solution (Python):
N = int(input())
S = input()
A = [len(set(S[:i]) & set(S[i:])) for i in range(N)]
print(max(A))

Solution (Python):
n = int(input())
s = input()
ans = 0

for i in range(n-1):
    x = set(s[:i+1])
    y = set(s[i+1:])
    ans = max(ans,len(x&y))
    
print(ans)

Solution (Python):
n = int(input())
s = list(input())
ans = 0
for i in range(1,n-1):
    sa = set(s[:i])
    sb = set(s[i:])
    ans = max(ans,len(sa&sb))

print(ans)

Solution (Python):
N = int(input())
S = input()
res = 0
for i in range(N):
    S_A = set(S[:i])
    S_B = set(S[i:])
    res = max(res, len(S_A & S_B))
print(res)

Solution (Python):

n = int(input())
s = input()

ans = [0]*n
for i in range(n):
    l = sorted(list(set(s[:i])))
    r = sorted(list(set(s[i:])))
    for j in range(len(l)):
        for k in range(len(r)):
            if l[j] == r[k]:
                ans[i] += 1
                
print(max(ans))

Solution (Python):
n = int(input())
s = input()

ans = []
for i in range(n):
    x = s[0:i+1]
    y = s[i+1:]
    s1 = set()
    s2 = set()
    for j in x:
        s1.add(j)
    for k in y:
        s2.add(k)
    wa = s1 & s2
    ans.append(len(wa))
print(max(ans))

Solution (Python):
N = int(input())
S = list(input())
a = []
for i in range(N):
    f = S[0:i+1]
    l = S[i+1:N]
    a.append( len(set(f)) + len(set(l)) - len(set(S)) )

print(max(a))

Solution (Python):
n = int(input())
s = input()
l = []

for i in range(1, len(s)):
    
    f = s[:i]
    b = s[i:]
    fset = list(set(s[:i]))
    bset = list(set(s[i:]))
    cnt = 0
   
    for j in fset:
        if bset.count(j) != 0:
            cnt += 1
    l.append(cnt)
   
print(max(l))

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(1, N):
  left = set(S[:i])
  right = set(S[i:])
  ans = max(ans, len(left & right))

print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0

for i in range(n):
    s1 = list(s[: i + 1])
    s2 = list(s[i + 1 :])
    ss = [""] * n

    count = 0
    for j in range(len(s1)):
        if s1[j] in s2 and s1[j] not in ss:
            ss[j] = s1[j]
            count = count + 1

    ans = max(ans, count)

print(ans)

Solution (Python):
import collections
N = int(input())
S = input()

ans=0
for i in range(1, N):
    s = S[:i]
    t = S[i:]

    s1 = set(s)
    t1 = set(t)

    c = collections.Counter(s1&t1)
    ans = max(ans, len(c))
print(ans)

Solution (Python):
n = int(input())
s = list(input())
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"]
ans = 0
for i in range(1, n):
    x = s[0 : i]
    y = s[i : n]
    c = 0
    for j in alph:
        if j in x and j in y:
            c += 1
    if ans < c:
        ans = c
print(ans)

Solution (Python):
n = int(input())
s = input()

ans = 0
for i in range(1, n):
    head = s[:i]
    tail = s[i:]
    cnt = 0
    for i in range(26):
        c = chr(ord('a') + i)
        if c in head and c in tail:
            cnt += 1

    ans = max(ans, cnt)

print(ans)

Solution (Python):
n = int(input())
s = input()

ans = 0
for i in range(1, n):
    head = s[:i]
    tail = s[i:]
    cnt = 0
    for i in range(26):
        c = chr(ord('a') + i)
        if c in head and c in tail:
            cnt += 1

    ans = max(ans, cnt)

print(ans)

Solution (Python):

def inputlist(): return [int(j) for j in input().split()]
from collections import Counter


N = int(input())
s = list(input())
ans = -1
for i in range(N):
    lif = s[:i]
    lib = s[i:]
    cf= list(Counter(lif).keys())
    cb= list(Counter(lib).keys())
    k = len(cf) + len(cb) - len(set(cf+cb))
    ans = max(ans,k)
print(ans)

Solution (Python):
N = int(input())
S = list(input())

count = {i:0 for i in range(N)}
for i in range(N):
    Pre = S[:i]
    Bak = S[i:]
    Pre_set = sorted(set(Pre))
    Bak_set = sorted(set(Bak))
    for j in Pre_set:
        for k in Bak_set:
            if j == k:
                count[i] += 1
max = max(count.values())

print(max)

Solution (Python):

N=int(input())
S=list(input())


s2=[S.pop(0)]
s1=S[:]
MAX=0
for i in range(N-1):
    n=len(set(s2) & set(s1))
    MAX=max(MAX,n)
    s2.append(s1.pop(0))
print(MAX)

Solution (Python):
N = int(input())
S = input()

S_list = list(S)

from collections import Counter
ans = 0
for i in range(1, N ):
    fas = S_list[ : i]
    sec = S_list[i : ]
    
    fas_dic = Counter(fas)
    sec_dic = Counter(sec)
    num = 0
    for j in fas_dic:
        if j in sec_dic:
            num += 1
    ans = max(ans, num)

print(ans)

Solution (Python):
from collections import Counter
def CaC(S,cp):
    s1 = S[:cp]
    s2 = S[cp:]
    
    c1 = Counter(s1)
    c2 = Counter(s2)
    
    count = 0
    if len(c1)<len(c2):
        for key in c1:
            if key in c2:
                count+=1
    else:
        for key in c2:
            if key in c1:
                count+=1
    return count
    
N = int(input())
S = input()

Max = 0
for i in range(1,N):
    m = CaC(S,i)
    if m>Max:
        Max=m
print(Max)

Solution (Python):

def compare(str1,str2):
    ans = 0
    str1=''.join(set(str1))
    str2=''.join(set(str2))
    for c in str1:
        ans += str2.count(c)

    return ans

N = int(input())
S = input()
m = 0
for i in range(N):

    tmp = compare(S[:i],S[i:])
    if m < tmp:
        m=tmp
print(m)

Solution (Python):
n = int(input())
s = input()

ans = 0

for i in range(n+1):
    li1 = [0]*26
    li2 = [0]*26
    s1 = s[:i]
    s2 = s[i:]
    for j in s1:
        li1[ord(j)-97] += 1
    for j in s2:
        li2[ord(j)-97] += 1
    tmp = 0
    for j in range(26):
        if li1[j] > 0 and li2[j] > 0:
            tmp += 1
    ans = max(ans, tmp)

print(ans)

Solution (Python):
def CutandCount(n , s):

    ans = 0

    for i in range(1 , n + 1):
        count = 0
        for w in range(ord('a'), ord('z') + 1):
            if chr(w) in s[:i] and chr(w) in s[i:]:
                count += 1

        ans = max(ans , count)

    return ans

def main():
    n = int(input())
    s = str(input())
    print(CutandCount(n , s))

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input());s=input();print(max([len(set(s[:i])&set(s[i:]))for i in range(n)]))

Solution (Python):
N = int(input())
S = list(input())
ans = []
for i in range(1,N):
    a = set(S[:i])
    b = set(S[i:])
    ans.append(len(a&b))
print(max(ans))

Solution (Python):
N = int(input())
S = list(input())

ans = []
if len(set(S)) == 1:
    ans.append(1)
elif len(set(S)) == len(S):
    ans.append(0)
else:
    pass
    
for i in range(N):
    if i == 0:
        pass
    elif S[i] == S[i-1]:
        pass
    else:
        S_f = S[:i+1]
        S_b = S[i+1:]
        F = set(S_b)
        B = set(S_f)
        ans.append(len(F&B))
        
print(max(ans))

Solution (Python):
n = int(input())
s = input()
res = 0
for i in range(1, n-1):
    s1 = set(s[:i])
    s2 = set(s[i:])
    res = max(res, len(s1&s2))
print(res)

Solution (Python):
n=int(input())
s=input()
l=[]
for i in range(1,n):
    l.append(len(set(s[:i]) & set(s[i:])))
print(max(l))

Solution (Python):
n = int(input())
s = input()
print(max([len(set(s[:i])&set(s[i:])) for i in range(1,n)]))

Solution (Python):
n=int(input())
s=input()
c=0
for i in range(1,len(s)):
    l=set(s[:i])
    r=set(s[i:])
    c=max(c,len(l&r))
print(c)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1,n):
    x = set(s[:i])
    y = set(s[i:])
    ans = max(ans,len(x&y))
print(ans)

Solution (Python):
def main():
    n = int(input())
    s = input()

    ans = -float("inf")
    for i in range(1, n):
        s_union = set(s[:i]) & set(s[i:])
        ans = max(ans, len(s_union))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
s=input()
ans=-1

for i in range(n):
    x=set(s[:i])
    y=set(s[i:])
    ans=(max(ans,len(x&y)))

print(ans)

Solution (Python):
n = int(input())
s = input()
dic_1 = {}
dic_2 = {}
ls = ["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"]
ans = 0
for j in range(26):
    dic_1[ls[j]] = 0
    dic_2[ls[j]] = 0
for i in range(1,n-1):
    s1 = s[:i]
    s2 = s[i:]
    tmp = 0
    for j in range(26):
        dic_1[ls[j]] = 0
        dic_2[ls[j]] = 0
    for j in range(len(s1)):
        dic_1[s1[j]] = 1
    for j in range(len(s2)):
        dic_2[s2[j]] = 1
    for j in range(26):
        tmp += dic_1[ls[j]] * dic_2[ls[j]]
    ans = max(ans,tmp)
print(ans)

Solution (Python):

n = int(input())
s = list(input())

ans = 0
for i in range(1, n):
    tmp1 = s[:i]
    tmp2 = s[i:]
    
    
    if len(set(tmp1) & set(tmp2)) > ans:
        ans = len(set(tmp1) & (set(tmp2)))
print(ans)

Solution (Python):
N = int(input())
S = input()

ans = 0
for i in range(N):
  a = S[:i]
  b = S[i:]
  ans = max(ans, len(set(a) & set(b)))
  
print(ans)

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(N):
    ans = max(ans,len(set(S[:i]).intersection(set(S[i:]))))
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
S = input()

R = Counter(list(S))
L = Counter()

ans = 0
for s in S:
    L[s] += 1
    R[s] -= 1
    ans = max(ans, len((L & R).keys()))

print(ans)

Solution (Python):
n = int(input())
s = input()
number = []
for i in range(n-1):
  before = s[:i+1]
  after = s[i+1:]
  before = list(before)
  after = list(after)
  number.append(len(set(before)&set(after)))
print(max(number))

Solution (Python):
n = int(input())
s = input()
max = 0

for i in range(n-1):
    x = set(list(s[:i]))
    y = set(list(s[i:]))
    l = len(x&y)
    if l > max:
        max=l

print(max)

Solution (Python):
n = int(input())
s = list(input())

maxi = 0

for i in range(n-1):
    left = set(s[:i+1])
    right = set(s[i+1:])
    g = len(left & right)
    if maxi<g:
        maxi = g

print(maxi)

Solution (Python):












n = int(input())
s = input()

lis = list(s)

ans = 0
for i in range(1,n):
    set1 = set(lis[0:i])
    set2 = set(lis[i:])
    checkset = set1 & set2
    ans = max(ans , len(checkset))

print(ans)

Solution (Python):
n=int(input())
s=input()
lis=list(s)
cnt=0
for i in range(1,n):
    left=set(lis[:i])
    right=set(lis[i:])
    char = left&right
    cnt=max(cnt,len(char))

print(cnt)

Solution (Python):
N=int(input())
S=input()
lis=list(S)
maxi=0

for i in range(1,N):
  left=set(lis[0:i])
  right=set(lis[i:])
  uni=left&right
  
  maxi=max(maxi,len(uni))
  
print(maxi)

Solution (Python):
n = int(input())
s = list(input())
ans = 0
for i in range(n):
         if ans < len(set(s[:i]) & set(s[i:])):
                  ans = len(set(s[:i]) & set(s[i:]))
print(ans)

Solution (Python):
n=int(input())
s=input()
ans=0
for i in range(n):
    left=s[:i]
    right=s[i:]
    both=set(left)&set(right)
    ans=max(ans,len(both))
print(ans)

Solution (Python):
'''
「文字列」S を「文字列」X と 「文字列」Y に分割、X と Y 両方に含む文字種類数最大化

「文字列」S を 各位置 で 分割して、「集合」X と 「集合」Y に格納する。
「集合」X と 「集合」Y の 論理積(AND) の 要素数 を 最大化することで求めることができる。
「集合」X と 「集合」Y の 論理積(AND) は X & Y で求めることができる。
'''

N = int(input())
S = input()

answer = 0
for L in range(N):
  left = S[:L]
  right = S[L:]
  both = set(left) & set(right)
  answer = max(answer, len(both))

print(answer)

Solution (Python):
n=int(input())
s=input()
d=set(list(s))
def counter(s1,s2):
    count=0
    for d1 in d:
        if d1 in list(s1) and d1 in list(s2):
            count+=1 
    return count
m=0
for i in range(1,n):
    m=max(counter(s[0:i],s[i:n]),m)
print(m)