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

lchrs = [0]*26
rchrs = [0]*26
flag = [False]*26
for c in s:
    lchrs[ord(c)-ord("a")] += 1

for c in s:
    i = ord(c)-ord("a")
    lchrs[i] -= 1
    rchrs[i] += 1
    if lchrs[i] and rchrs[i]:
        flag[i] = True
    else:
        flag[i] = False
    ans = max(ans, len([_ for _ in flag if _]))
print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
s = readline().decode().rstrip()
ans = 0
for i in range(1, n):
    cnt = 0
    for j in set(s[:i:]):
        if j in set(s[i::]):
            cnt += 1
    ans = max(ans, cnt)
print(ans)

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

ans = 0
for i in range(1, n):
    x = s[0:i]
    y = s[i:]

    uniq_x = set(x)
    uniq_y = set(y)

    cnt = 0
    for c in uniq_y:
        if c in uniq_x:
            cnt += 1

    ans = max(ans, cnt)

print(ans)

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

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

def countSameChar(x,y):
  cnt = 0
  for char in [chr(ord("a")+i) for i in range(26)]:
    if char in x and char in y:
      cnt += 1
  return cnt

def solve(n,s):
  ans = 0
  for i in range(n-2):
    x = s[:i+1]
    y = s[i+1:]
    ans = max(ans,countSameChar(x,y))
  return ans

print(solve(N,s))

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

lst = [0]*N

for i in range(N):
    X = list(set(list(S[0:i])))
    Y = list(set(list(S[i:N])))
    ans = 0
    for j in range(len(X)):
        if X[j] in Y:
            ans += 1
    lst[i] = ans

print(max(lst))

Solution (Python):
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    S = input()
    ans = 0
    for i in range(n-1):
        l = S[:i+1]
        r = S[i+1:]
        cnt = 0
        for s in set(l):
            if r.find(s) >= 0:
                cnt += 1
        ans = max(ans, cnt)
    print(ans)

if __name__ == '__main__':
    main()

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

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

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

ans = 0
for i in range(1,n):
    set_l = set(s[0:i])
    set_r = set(s[i::])
    set_both = set_l & set_r
    if ans < len(set_both):
        ans = len(set_both)
print (ans)

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 = input()
C = [[-1, -1] for _ in range(26)]
for i in range(N):
    c = ord(S[i]) - ord('a')
    if C[c][0] == -1:
        C[c][0] = i
    else:
        C[c][1] = i
print(max([len(tuple(filter(lambda x: x[0] <= i < x[1], C))) for i in range(N)]))

Solution (Python):
N = int(input())
S = input()
MAX = 0
for T in range(0,N+1):
    X = S[:T]
    Y = S[T:]
    Com = len(set(X)&set(Y))
    if Com>MAX:
        MAX = Com
print(MAX)

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

lst = [None]*(N-1)
for i in range(N-1):
    X = S[:i]
    Y = S[i:]
    lst[i] = len(set(X) & set(Y))
print(max(lst))

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:])
    intrsect_x_y = x & y
    ans = max(ans, len(intrsect_x_y))

print(ans)

Solution (Python):
def solve():
    N = int(input())
    S = input()
    ans = 0
    for i in range(1, N):
        cnt = 0
        for c in list(set(S[:i])):
            if c in list(set(S[i:])):
                cnt += 1
        ans = max(ans, cnt)
    print(ans)


if __name__ == "__main__":
    solve()

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

ans = 0
for i in range(len(s)):
    l = [s[j] for j in range(i + 1)]
    m = []
    for j in range(i + 1, len(s)):
        if s[j] in l and s[j] not in m:
            m.append(s[j])
    ans = max(ans, len(m))

print(ans)

Solution (Python):
import collections

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




ans = 0
for i in range(1, n):
    a = s[:i]
    b = s[i:]
    ca = list(collections.Counter(a).keys())
    cb = list(collections.Counter(b).keys())
    c = 0
    for cai in ca:
        if cai in cb:
            c += 1
    if ans < c:
        ans = c

print(ans)

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

for n in range(N-1):
  c = 0
  A = list(set(S[:n+1]))
  B = list(set(S[n+1:]))
  for a in A:
    if a in B:
      c+=1
  ans = max(ans,c)
  
print(ans)

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

Solution (Python):
from collections import Counter
N, = list(map(int,input().split()))
S = input()
cx = Counter(S)
cy = Counter()
cm = 0
r = 0
for c in S:
    cx[c] -= 1
    cy[c] += 1
    if cy[c]==1 and cx[c]>=1:
        cm += 1
    elif cy[c]>=2 and cx[c]==0:
        cm -= 1
    r = max(r, cm)
print(r)

Solution (Python):
N=int(input())
S=input()
L=[chr(i) for i in range(97, 97+26)]
ans0 = 0

for i in range(N-1):
  s1=S[0:i+1]
  s2=S[i+1:N]
  ans = 0
  for j in L:
    if ((j in s1) & (j in s2)):
      ans = ans + 1
    
  if ans0 < ans:
    ans0 = ans
print(ans0)

Solution (Python):
ans=0
N=int(input())
l=list(input())
for i in range(1,N):
   tmp1=set(l[0:i])
   tmp2=set(l[i:])
   tmp3=[]
   tmp3.append(list(tmp1))
   tmp3.append(list(tmp2))
   tmp3=sum(tmp3,[])
   tmp3=set(tmp3)
   ans=max(ans,-len(tmp3)+len(tmp2)+len(tmp1))
print(ans)

Solution (Python):

import sys
from collections import defaultdict, deque




def solve():
    n = int(input())
    s = [x for x in input()]
    ans = 0
    for i in range(n - 1):
        a = set(s[:i+1])
        b = set(s[i+1:])
        ans = max(ans, len(a & b))
    print(ans)


t = 1

for case in range(1,t+1):
    ans = solve()

"""

"""

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

ans=0
for i in range(len(S)):
    tmp=0
    a=set(S[:i:])
    b=set(S[i::])
    for i in a:
        if i in b:
            tmp+=1
    ans=max(ans,tmp)
print(ans)

Solution (Python):
import math
def main():
  n = int(input())
  s = input()
  ans=0
  for i in range(0,n):
    sum=0
    x=s[:i+1]
    y=s[i+1:]
    while len(x)>0:
      if x[0] in y :
        sum+=1
      x=x.replace(x[0],'')
    if sum>ans:
      ans=sum
  print(ans)
main()

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

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

print(ans)

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

ans = 0
for i in range(1, N):
    tmp = 0
    X = set(S[:i])
    Y = set(S[i:])
    for x in X:
        if x in Y:
            tmp += 1
    ans = max(ans, tmp)

print(ans)

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

for i in range(1,n):
    a = list(s[0:i])
    a = list(set(a))
    b = list(s[i:])
    t = 0
    for j in range(len(a)):
        if a[j] in b:
            t += 1
    p = max(t,p)

print(p)

Solution (Python):
n = int(input())
l = list(map(str,input()))

ans = 0
for i in range(n):
    a = l[:i]
    b = l[i:]
    tmp = []
    for j in a:
        if j in b:
            tmp.append(j)
    tmp = set(tmp)
    ans = (max(ans,len(tmp)))

print(ans)

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

ans = 0
for i in range(1,n-1):
    mae = s[:i]
    ato = s[i:]
    temp = []
    for j in mae:
        if j in ato:
            temp.append(j)
    temp = set(temp)
    ans = max(ans,len(temp))

print(ans)

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

ans = 0
for i in range(1,n-1):
    mae = s[:i]
    ato = s[i:]
    temp = []
    for j in mae:
        if j in ato:
            temp.append(j)
    temp = set(temp)
    ans = max(ans,len(temp))

print(ans)

Solution (Python):
import string

n = int(input())
s = input()
alp = list(string.ascii_lowercase)
ans = 0

for i in range(n):
    s1 = s[:i]
    s2 = s[i:]
    cnt = 0
    for c in alp:
        if c in s1 and c in s2:
            cnt += 1
    ans = max(ans, cnt)

print(ans)

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


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

print(ans)

Solution (Python):
n, s = open(0).read().split()

n = int(n)

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

print(ans)

Solution (Python):
import sys
N = int(input())
S = input()
unique_S = list(set(list(S)))

sys.exit() if not (2 <= N <= 100) else ''
sys.exit() if len(S) != N else ''
sys.exit() if not S.islower() else ''

result = 0
for I in range(len(S)):
    count = 0
    for J in range(len(unique_S)):
        if ( unique_S[J] in S[0:I] ) and ( unique_S[J] in S[I:] ):
            count += 1
        if result < count:
            result = count

print(result)

Solution (Python):
N = int(input())
S = input()
cnt = 0
alpha = []
ans = []

for i in range(1, N):
    alpha = []
    cnt = 0
    X = S[:i]
    Y = S[i:]
    for j in X:
        if j in alpha: continue
        if Y.count(j) > 0:
            cnt += 1
            alpha.append(j)

    ans.append(cnt)

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

Solution (Python):
N,S,z=int(input()),input(),0
for i in range(1,N):a,b=S[:i],S[i:];z=max(z,len([0 for j in range(97,123)if chr(j)in a and chr(j)in b]))
print(z)

Solution (Python):
N,S=int(input()),input()
ans=0
for i in range(1,N):
    a,b,c=S[:i],S[i:],0
    for j in range(97,123):
        if chr(j)in a and chr(j)in b:c+=1
    ans=max(ans,c)
print(ans)

Solution (Python):
n=int(input())
s=input()
alphabet=[chr(i) for i in range(97,97+26)]
ans=0

for i in range(1,n):
    s1=s[:i]
    s2=s[i:]
    cnt=0
    for j in range(len(alphabet)):
        if s1.count(alphabet[j])>=1 and s2.count(alphabet[j])>=1:
            cnt+=1
    if cnt>ans:
        ans=cnt
print(ans)

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

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

ans = 0
for i in range(1,n-1):
  w1,w2 = s[:i],s[i:]
  ans = max(ans, len(set(w1)&set(w2)))
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):
n = int(input());
s = input();
max = 0;
set = [chr(i) for i in range(97,123)];
for i in range(1,n) :
    x = s[:i];
    y = s[i:];
    cnt = 0;
    
    for ch in set :
        
        if x.find(ch) >= 0 and y.find(ch) >= 0 :
            cnt += 1;
    if cnt > max :
        max = cnt;

print(max);

Solution (Python):
def main():
    import collections

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

    cnt_s = []

    for i in range(n):
        cnt_l = collections.Counter(s[:i])
        cnt_r = collections.Counter(s[i:])
        cnt = 0
        for key in dict(collections.Counter(cnt_l)):
            if key in dict(collections.Counter(cnt_r)):
                cnt += 1
        cnt_s.append(cnt)

    print(max(cnt_s))


if __name__ == '__main__':
    main()

Solution (Python):




import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy














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

ans = 0

for i in range(1,N):
    Cfirst = collections.Counter(S[:i])
    Cend = collections.Counter(S[i:])
    ans = max(ans, len(Cfirst.keys() & Cend.keys()))

print(ans)

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

ans = 0

for i in range(n-1):
    left = s[0:i]
    right = s[i:n]

    sleft = set([x for x in left])
    sright = set([x for x in right])

    tmp = len(sleft & sright)
    if tmp > ans:
        ans = tmp

print(ans)

Solution (Python):
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

def f(a,b):
    a = list(set(a))
    b = list(set(b))
    cnt = 0
    for i in a:
        for j in b:
            if i == j:cnt += 1
    return cnt

if __name__ == "__main__":
    n = I()
    s = L()
    ans = 0
    for i in range(n):
        
        ans = max(ans,f(s[:n-i],s[n-i:]))
    print(ans)

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



ans=0

for i in range(1,N):
    X=S[:i]
    Y=S[i:]
    setX=set(X)
    setY=set(Y)
    intersectionXY=setX & setY
    _temp=len(intersectionXY)
    if _temp>ans:
        ans=_temp
    else:
        pass
print(ans)

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

ans = []

for i in range(1, N):
    l = set(S[:i])
    r = set(S[i:])
    ans.append(len(l & r))
print(max(ans))

Solution (Python):
N = int(input())
S = list(input())
ans = 0
for i in range(N):
    X = set(S[:i])
    Y = set(S[i:])
    tmp = len(X & Y)
    ans = max(ans, tmp)

print(ans)

Solution (Python):
import sys

N = int(input())
S = input()
num = len(S)
ans, count = 0, 0
for i in range(1, num):
    a = set(S[:i])
    b = set(S[i:])
    for j in a:
        if j in b: count += 1
    ans = max(ans, count)
    count = 0
    
print(ans)

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

for i in range(1,n):
    cnt = 0
    x = s[:i]
    y = s[i:]

    x = set(x)
    y = set(y)
    for j in x:
        if j in y: cnt+= 1
    ans = max(ans,cnt)
print(ans)

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

Solution (Python):
from collections import defaultdict

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

ans = -1

n = readInt()
s = input()

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

print(ans)

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

Solution (Python):


import sys

DEBUG = False

def read(t):
    return t(sys.stdin.readline().rstrip())


def read_list(t, sep = " "):
    return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return


def main():
    n = read(int)
    s = read(str)

    ans = 0
    for i in range(1, len(s) - 1):
        x = s[0:i]
        y = s[i:]

        x_chrs = set(list(x))
        y_chrs = set(list(y))

        nr_dup_chrs = x_chrs & y_chrs
        if ans < len(nr_dup_chrs):
            ans = len(nr_dup_chrs)

    print(ans)

if __name__ == "__main__":
    main()

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

print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    ans = 0
    for n in range(N):
        S1 = set(S[:n])
        S2 = set(S[n:])
        I = S1 & S2
        ans = max(ans, len(I))
    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
s=list(input())
mx=0
for i in range(1,n):

  m=len(set(s[:i])&set(s[i:]))
  if m>mx:
    mx=m

print(mx)

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

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

Solution (Python):
def actual(N, S):
    count = 0

    for i in range(1, N):
        left_chars = set(S[:i])
        right_chars = set(S[i:])

        and_chars = left_chars & right_chars
        unique_chars = len(and_chars)

        if unique_chars > count:
            count = unique_chars

    return count

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

print(actual(N, S))

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

Solution (Python):
n = int(input())
s = str(input())
ans = 0
count = 0
ch = []
for i in range(1,n):
    a = s[:i]
    b = s[i:]
    for j in range(i):
        if a[j] in b and a[j] not in ch:
            count += 1
        ch.append(a[j])
    ans = max(count,ans)
    count = 0
    ch = []
print(ans)

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()
res = 0
for i in range(n):
  res = max(res, len(set(s[:i]) & set(s[i:])))
print(res)

Solution (Python):









import os
import sys




def main():
    n = int(input())
    s = input()
    total = 0
    for i in range(1,n):
        cnt = 0
        left = s[:i]
        right = s[i:]
        left = list(set(left))
        right = list(set(right))
        for l in left:
            if l in right:
                cnt += 1
        if total < cnt:
            total = cnt
    print(total)


if __name__ == "__main__":
    main()

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

Solution (Python):

import sys


def solve(N: int, S: str):
    h = [set()]
    for c in S:
        h.append(h[-1] | set(c))
    t = [set()]
    for c in reversed(S):
        t.append(t[-1] | set(c))
    return max(len(hh & tt) for hh, tt in zip(h, reversed(t)))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    S = next(tokens)  
    print(solve(N, S))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

Solution (Python):

import sys


def solve(N: int, S: str):
    h = [frozenset()]
    for c in S:
        h.append(h[-1] | frozenset(c))
    t = [frozenset()]
    for c in reversed(S):
        t.append(t[-1] | frozenset(c))
    return max(len(hh & tt) for hh, tt in zip(h, reversed(t)))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    S = next(tokens)  
    print(solve(N, S))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

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

ans = 0
for i in range(1, n):
    left = list(s[:i])
    right = list(s[i:])
    
    t = 0
    for j in set(left):
        if j in right:
            t += 1
    
        ans = max(ans, t)
        
print(ans)

Solution (Python):
from fractions import gcd

from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

n = int(input())
s = input()
ans = 0
for i in range(1,n):
    cnt = 0
    c1 = Counter(s[:i])
    c2 = Counter(s[i:])
    for x in c1.keys():
        if c2[x]: cnt+=1
    ans = max(cnt, ans)
print(ans)

Solution (Python):
import collections
n = int(input())
s = input()
ans = 0
for i in range(1,n):
    cnt = 0
    c1 = collections.Counter(s[:i])
    c2 = collections.Counter(s[i:])
    for x in c1.keys():
        if c2[x]: cnt+=1
    ans = max(cnt, ans)
print(ans)

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

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

Solution (Python):
n = int(input())
s = input()
M = 0
for i in range(1, n):
    cnt = 0
    s1 = s[:i]
    s2 = s[i:]
    t = {}
    for x in s1:
        if x not in t: t[x]=1
    for k in s2:
        if k not in t: t[k]=0
        if t[k] == 1: t[k]+=1
    for x, y in t.items():
        if y==2: cnt+=1
    M = max(cnt, M)
print(M)

Solution (Python):
n = int(input())
s = input()
M = 0
for i in range(1, n):
    cnt = 0
    s1 = s[0:i]
    s2 = s[i:len(s)]
    t = {}
    for x in s1:
        if x not in t: t[x]=1
    for k in s2:
        if k not in t: t[k]=0
        if t[k] == 1: t[k]+=1
    for x, y in t.items():
        if y==2: cnt+=1
    M = max(cnt, M)
print(M)

Solution (Python):
N=int(input())
S=input()
ans=0
for i in range(N+1):
  bns=0
  dp=[0]*26
  bp=[0]*26
  a=S[:i]
  b=S[i:]
  a=sorted(a)
  b=sorted(b)
  for j in range(len(a)):
    dp[ord(a[j])-97]+=1
  for k in range(len(b)):
    bp[ord(b[k])-97]+=1
  for l in range(26):
    if min(dp[l],bp[l])>0:
      bns+=1
  ans=max(ans,bns)
print(ans)

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

ans = [None] * (n-1)

for i in range(1,n):
  a = s[0:i]
  b = s[i:n]

  ans[i-1] = len(set(b))-len((set(b)-set(a)))

ans.sort(reverse = True)

print(ans[0])

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

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

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

ans = 0

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

print(ans)

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


ans = 0
alphabet = [chr(i) for i in range(97, 97+26)]
def count(i):
    num = 0
    a=list(set(list(s[:i])))
    b=list(set(list(s[i:])))
    for i in alphabet:
        if (i in a) & (i in b):
            num += 1
    return num
for j in range(1,len(s)-1):
    if ans < count(j): ans = count(j)
print(ans)

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

for i in range(1,n):
    count = 0
    s1 = s[:i]
    s2 = s[i:]
    for i in t:
        if s1.count(i) > 0 and s2.count(i) > 0:
            count += 1
            
    if ans < count:
        ans = count
print(ans)

Solution (Python):


from fractions import gcd

from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

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

c = Counter(S)

mcount = len(c)

mct = 0
for i in range(N):
    ta = Counter(S[:i])
    tb = Counter(S[i:])
    
    ct = 0
    for st in ta:
        if tb[st]:
           ct += 1
           
    mct = max(mct, ct)
print(mct)

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

for i in range(1,n-1):
  cnt=0
  x=list(set(s[:i]))
  y=list(set(s[i:]))
  for j in x:
    if j in y:
      cnt+=1
  if ans<cnt:
    ans=cnt
print(ans)

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

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

def count_alphabets(s):
    alphabets = list("abcdefghijklmnopqrstuvwxyz")
    cnt = dict(zip(alphabets, [0 for _ in range(26)]))
    for c in s: cnt[c] += 1
    return cnt

ans = 0
for div in range(1, N):
    left_str, right_str = S[:div], S[div:]
    left_cnt, right_cnt = count_alphabets(left_str), count_alphabets(right_str)

    count = 0
    alphabets = list("abcdefghijklmnopqrstuvwxyz")
    for c in alphabets:
        if left_cnt[c] > 0 and right_cnt[c] > 0:
            count += 1
    ans = max(ans, count)
print(ans)

Solution (Python):
def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N = ii()
    S = input()
    m = max(len(set(S[:i]) & set(S[i:])) for i in range(N))
    print(m)

if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(input())
s = input()
ans = -1*float('inf')
for i in range(n):
  ans = max(ans, len(set(s[:i])&set(s[i:])))
print(ans)

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

res = 0
for i in range(1, N):
    res = max(len(set(S[:i])&set(S[i:])), res)

print(res)

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
s=input()
tmp=Counter(s)
ans=0
for i in range(n+1):
    l,r=s[:i],s[i:]
    dic={}
    tmp=Counter(r)
    for j in range(i):
        if tmp[l[j]]>0:
            dic[l[j]]=1
    ans=max(len(dic),ans)
    
print(ans)

Solution (Python):

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


max = 0
for i in range(N):
    A, B = set(S[:i + 1]), set(S[i + 1:])
    union_cnt = len(A & B)
    
    if max < union_cnt:
        max = union_cnt

print(max)

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

ans = 0
for i in range(1,N-1):
    S1,S2 = set(S[:i]),set(S[i:])
    ans = max(ans,len(S1 & S2))

print(ans)

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

Solution (Python):
N=int(input())
S=input()
ans=0
for i in range(1,N):
  temp=0
  check1=set(S[:i])
  check2=set(S[i:])
  for s in check1:
    if s in check2:
      temp+=1
  ans=max(ans,temp)
print(ans)

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

Solution (Python):
n = int(input())
S = input()
ans = 0
for i in range(0,n-1):
  A = set(S[0:i+1])
  B = set(S[i+1:n])
  ans = max(ans,len(list(A&B)))
  
print(ans)

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

Solution (Python):
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N=II()
S=input()
s1 = set()
s2 = set()
res = 0
for i in range(1, N):
    for c in S[:i]:
        s1.add(c)
    for c in S[i:]:
        s2.add(c)
    res = max(len(s1.intersection(s2)), res)
    s1.clear()
    s2.clear()
print(res)

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

ans = 0
for div in range(n):
    left = set(s[:div])
    right = set(s[div:])
    tmp = 0
    for i in left:
        if i in right:
           tmp += 1
    ans = max(ans, tmp)
print(ans)

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

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

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

for i in range(1,N):
    dicl = {}
    dicr = {}
    for j in range(i):
        dicl[S[j]] = j
    for j in range(i,N):
        if(S[j] in dicl.keys()):
            dicr[S[j]] = j
    if len(dicr.keys()) > max:
        max = len(dicr.keys())
print(max)

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

ans=0
for i in range(s_l):
  set1=set(s[:i])
  set2=set(s[i:])
  t_ans=len(set1&set2)
  ans=max(ans,t_ans)
print(ans)

Solution (Python):

if __name__ == '__main__':
    n =int(input())
    s=input()
    max =0
    for i in range(n):
        a= set(s[:i])
        b= set(s[i:])
        count = len(a &b)
        if max <count:
            max=count

    print(max)

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

l=[]

for i in range(n):
    h=set(s[0:i])
    t=set(s[i:])
    x=len(h&t)
    l.append(x)

print(max(l))

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

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    temp = 0
    X, Y = S[:i], S[i:]
    for c in set(S):
        if c in X and c in Y:
            temp += 1
    ans = max(ans, temp)
print(ans)

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

Solution (Python):

if __name__ == "__main__":
    N = int(input())
    S = input()
    unique_nums = [-1] * N
    for i in range(N):
        left = S[:i]
        
        right = S[i:]
        
        unique_nums[i] = len(set(left) & set(right))
    print(max(unique_nums))

Solution (Python):
import collections

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


def count_variation(s):
    c = collections.Counter(s)
    return c.keys()


ans = []

for i in range(1, N):
    s1 = S[:i]
    s2 = S[i:]
    mojis = len(count_variation(s1) & count_variation(s2))
    ans.append(mojis)

print(max(ans))

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