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):
    bef = list(set(S[:i]))
    aft = list(set(S[i:]))
    cnt = 0
    for j in bef:
        if j in aft:
            cnt += 1
    else:
        ans = max(cnt, ans)

print(ans)

Solution (Python):
def types(st1, st2):
    ret = 0
    for i in range(26):
        j = chr(i + 97)
        if j in st1 and j in st2:
            ret += 1
    return ret

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

ans = 0
for i in range(n-1):
    ans = max(ans, types(s[:i], s[i:]))
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
S = input()
mx = 0
for i in range(1,N):
    pre = Counter(S[:i])
    back = Counter(S[i:])
    tmp = 0
    for k in pre.keys():
        if k in back:
            tmp += 1
    mx = max(mx, tmp)
print(mx)

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

Solution (Python):
def abc():
    n = int(input())
    s = input().rstrip()
    max_dup = 0
    for i in range(1, n+1):
        s1 = set(s[0:i])
        s2 = set(s[i:])
        max_dup = max(max_dup, len(s1 & s2))
    print(max_dup)


abc()

Solution (Python):
def resolve():
    n=int(input())
    s=input()
    mx=0
    alp=list('abcdefghijklmnopqrstuvwxyz')
    l=[0 for i in alp]
    for i in range(n):
        lt=s[:i+1]
        lb=s[i+1:]
        fuku=0
        for j in alp:
            if j in lt and j in lb:
                fuku+=1
        mx=max(mx,fuku)
    print(mx)
resolve()

Solution (Python):
N = int(input())
S = input()
left = ""
right = ""
ans = []
for i in range(N):
    left = S[:i+1]
    right = S[i+1:]
    left_n = set(list(left))
    right_n = set(list(right))
    count = 0
    for l in left_n:
        if l in right_n:
            count += 1
    ans.append(count)
print(max(ans))

Solution (Python):
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()
ans = []
for i in range(N-1):
    c=0
    
    for j in list(set(S[0:i+1])):
        if j in list(set(S[i+1:])):
            c+=1
    ans.append(c)
print(max(ans))

Solution (Python):


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

print(ans)

Solution (Python):
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

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

sys.setrecursionlimit(2147483647)
INF = float("inf")


N = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()

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

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

ans = 0

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

print(ans)

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

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

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

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

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

cnt = 0
for i in range(n):
  tmp = len(set(s[:i]).intersection(s[i:]))
  cnt = max(tmp,cnt)
print(cnt)

Solution (Python):
import numpy as np
n = int(input())
s = input()

cnt = 0
for i in range(1,n):
  tmp = 0
  for a in set(list(s[:i])):
    tmp += max(np.sign(s[i:].find(a)+0.5),0)
  cnt = max(cnt,tmp)
print(int(cnt))

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


def f(s1, s2):
    return len(set(s1).intersection(set(s2)))


print(max(map(lambda i: f(s[:i], s[i:]), range(1, n))))

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

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

Solution (Python):

n = int(input())
s = input()
ans = 0
for i in range(len(s)-1):
	s1 = list(set(s[i+1:]))
	s2 = list(set(s[:i+1]))

	tog = 0
	for i in s1:
		if i in s2:
			tog += 1

	ans = max(tog,ans)
print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1,n):
    cnt = 0
    s_b = s[:i]
    s_a = s[i:]
    for j in set(s_b):
        if j in s_a:
            cnt+=1
    if cnt > ans:
        ans = cnt
print(ans)

Solution (Python):
N = int(input())
S = input()
S_set = list(set(S))
mx_ans = 0
for n in range(N):
  X = S[:n]
  Y = S[n:]
  ans = 0
  for i in range(len(S_set)):
    if (X.count(S_set[i])>0) and (Y.count(S_set[i])>0):
      ans += 1
  if mx_ans < ans:
    mx_ans = ans
print(mx_ans)

Solution (Python):
import sys


if __name__ == '__main__':
    N = int(input())
    S = str(input())

    S_list = list(S)

    answer = - sys.maxsize
    for i in range(1,len(S)):
        left_S = S_list[:i:]
        right_S = S_list[i::]
        cnt_both_S = len(set(left_S) & set(right_S))
        answer = max(answer, cnt_both_S)

    print(answer)

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

Solution (Python):
n=int(input())
s=input()
st='abcdefghijklmnopqrstuvwxyz'
ans=0
for i in range(1,n-1):
    ll=[0]*26
    rl=[0]*26
    for j in range(i):
        ll[st.index(s[j])]+=1
    for j in range(i,n):
        rl[st.index(s[j])]+=1
    cnt=0
    for j in range(26):
        cnt+=1 if ll[j]>0 and rl[j]>0 else 0
    ans=max(ans,cnt)
print(ans)

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

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

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

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

ans = 0

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

print(ans)

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

cnt = 0

for i in range(n):
    li1 = s[:1+i]
    li2 = s[1+i:]
    ans = list(set(li1) & set(li2))
    cnt = max(cnt, len(ans))
    
print(cnt)

Solution (Python):

N = int(input())
s = input()
ans = 0
for n in range(N):
    s_and = len(set(s[:n]) & set(s[n:]))
    ans = max(ans, s_and)
print(ans)

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

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

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

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

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

cnt = 0
for i in range(n+2):
    c = set(s[0:i]) & set(s[i:n+1])
    if len(c) >= cnt:
        cnt = len(c)
print(cnt)

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

ans = 0

for i in range(1,N-1):
    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):
    x = s[:i+1]
    y = s[i+1:]
    ans = max(ans,len(set(x)&set(y)))

print(ans)

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

Solution (Python):
import sys
input = sys.stdin.readline

N, = map(int, input().split())
S = list(input().strip())

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

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

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

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

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

Solution (Python):
a=input()
n=input()
C=[]
dic={}
for i in n:
    if i not in dic:
        dic[i]=1
    else:
        dic[i]+=1
c=A=0;
for i in n:
    if dic[i]>1:
        dic[i]-=1
        if i not in C:
            C.append(i)
            c+=1
            if c>A:A=c
    else:
        if i in C:
            c-=1
print(A)

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

ans=[]
for i in range(n):
    l1=set(l[:i])
    l2=set(l[i:])
    ll=l1&l2
    ans.append(len(ll))
    
print(max(ans))

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

Solution (Python):
n = int(input())
s = input()
result = []
if len(set(s)) == 1:
  print(1)
else:
  for i in range(n):
    tmp = 0
    for k in set(s[:i]):
      if k in s[i:]:
        tmp += 1
    result.append(tmp)
  print(max(result))

Solution (Python):
if __name__ == '__main__':
  n = int(input())
  s = list(input())
  ans = 0
  for i in range(0, len(s)):
    x = set(s[:i+1])
    y = set(s[i+1:])
    num = len(x & y)
    if ans <= num:
      ans = num
  print(ans)

Solution (Python):
n=int(input())
s=list(input())
ans=0
for i in range(n):
    ans=max(ans,len(set(s[0:i+1])&set(s[i+1:n])))
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:]
	s = []
	count = 0

	
	for j in range(i + 1):
		if S2.count(S1[j]) != 0:
			s.append(S1[j])

 	
	count = len(set(s))

	
	ans = max(ans, count)

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()
ans=[]
for i in range(n):
    count=0
    for j in set(s[i:]):
        if j in s[:i]:
            count+=1
    ans.append(count)
print(max(ans))

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

m = 0
for i in range(1, len(S)):
    X, Y = S[:i], S[i:]
    m = max(m, len(set(X) & set(Y)))
print(m)

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

ans = 0

for i in range(1,n):
    s_left = [s[j] for j in range(i)]
    s_right = [s[j] for j in range(i,n)]
    ans = max(ans,len(set([c for c in s_left if c in s_right])))
print(ans)

Solution (Python):
n = int(input())
s = input()
num = []
for i in range(1,n):
    former = set(s[:i])
    latter = set(s[i:])
    comm = len(former.intersection(latter))
    
    num.append(comm)

print(max(num))

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

dicX={s[0]:1}
dicY={}
for i in range(1,N):
    if s[i] in dicY: dicY[s[i]]+=1
    else: dicY[s[i]]=1

ans=int(s[0] in dicY)

for i in range(1,N-1):
    if not s[i] in dicX: dicX[s[i]]=1
    
    if dicY[s[i]]>1: dicY[s[i]]-=1
    else: dicY.pop(s[i])
    
    tmp=0
    for j in dicX:
         if j in dicY: tmp+=1
    ans=max(tmp,ans)

print(ans)

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

dicX={s[0]:1}
dicY={}
for i in range(1,N):
    if s[i] in dicY: dicY[s[i]]+=1
    else: dicY[s[i]]=1

if s[0] in dicY: ans=1
else: ans=0

for i in range(1,N-1):
    if not s[i] in dicX: dicX[s[i]]=1
    
    if dicY[s[i]]>1: dicY[s[i]]-=1
    else: dicY.pop(s[i])
    
    tmp=0
    for j in dicX:
         if j in dicY: tmp+=1
    ans=max(tmp,ans)

print(ans)

Solution (Python):
N=int(input())
s=input()
 
dicX={s[0]:1}
dicY={}
for i in range(1,N):
    if s[i] in dicY: dicY[s[i]]+=1
    else: dicY[s[i]]=1
 
ans=0

for i in range(1,N-1):
    if not s[i] in dicX: dicX[s[i]]=1
    
    if dicY[s[i]]>1: dicY[s[i]]-=1
    else: dicY.pop(s[i])
    
    tmp=0
    for j in dicX:
         if j in dicY: tmp+=1
    ans=max(tmp,ans)
 
print(ans)

Solution (Python):
N=int(input())
s=input()
 
dicX={s[0]:1}
dicY={}
for i in range(1,N):
    if s[i] in dicY: dicY[s[i]]+=1
    else: dicY[s[i]]=1
 
ans=0
for i in range(1,N-1):
    if s[i] in dicX: dicX[s[i]]+=1
    else: dicX[s[i]]=1
    
    if dicY[s[i]]>1: dicY[s[i]]-=1
    else: dicY.pop(s[i])
    
    tmp=0
    for j in dicX:
         if j in dicY: tmp+=1
    ans=max(tmp,ans)
 
print(ans)

Solution (Python):
n = int(input())
s = input()
common = 0
for i in range(n):
    x = s[:i]
    y = s[i:]
    x_set = {i for i in x}
    y_set = {i for i in y}
    c = x_set.intersection(y_set)
    if len(c) > common:
        common = len(c)
print(common)

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

cnt = 0
for i in range(1, N):
  x = list(set(S[:i]))
  y = list(set(S[i:]))
  tmp = 0
  for c in x:
    if c in y:
      tmp = tmp +1
  
  if cnt < tmp:
    cnt = tmp

print(cnt)

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

for i in range(1, n):
    count = 0
    left = list(set(s[:i]))
    right = list(set(s[i:]))
    for i in left:
        if right.count(i) == 1:
            count += 1
    if count > ans:
        ans = count

print(ans)

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

sets = set(S)
ans = 0
for i in range(1,N):
    cnt = 0
    for s in sets:
        l = 0
        r = 0
        for j in S[:i]:
            if j ==s :
                l=1
                break
        for j in S[i:N]:    
            if j == s  :  
                r=1
                break
        if l*r == 1:
            cnt += 1
    ans = max(ans,cnt)
    
print(ans)

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

ans=0
for i in range(len(S)):
    a=set(S[:i])
    b=set(S[i:])
    if len(a&b)>ans:
    	ans=len(a&b)
print(ans)

Solution (Python):
n = int(input())
s = input()
maxc = 0
for i in range(1,n):
    cnt = 0
    sl = list(set(s[:i]))
    sr = list(set(s[i:]))
    for j in range(len(sl[:i])):
        if sl.count(sl[j])>0 and sr.count(sl[j]):
            cnt += 1
    maxc = max(maxc,cnt)
print(maxc)

Solution (Python):
N = int(raw_input())
S = raw_input()
left = []
right = []
for i in range(0, 26):
	left.append(0)
	right.append(0)
for i in range(0, N):
	left[ord(S[i])-97] += 1
max = 0
for i in range(0, N):
	left[ord(S[i])-97] -= 1
	right[ord(S[i])-97] += 1
	cnt = 0
	for j in range(0, 26):
		if left[j] != 0 and right[j] != 0: cnt += 1
	if max < cnt: max = cnt
print max

Solution (Python):
n=int(input())
s=input()
temp=0
for i in range(n):
    s_l=set(s[:i+1])
    s_r=set(s[i+1:])
    t=s_l&s_r
    if len(t)>temp:
        temp=len(t)
print(temp)

Solution (Python):

import sys


def solve(N: int, S: str):

    res = 0
    for i in range(len(S)):
        aset = set(list(S[0:i]))
        bset = set(list(S[i:]))
        res = max(len(aset&bset),res)

    print(res)


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)  
    solve(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())
X,Y = [0 for x in range(ord('z')-96)],[]
for i in range(ord('z')-96):
    Y += [S.count(chr(i+96+1))]

ans,temp = [],0
for i in range(0,N):
    s = ord(S[i])-97
    if X[s]==0 and Y[s]>=2:
        temp += 1
    elif X[s]>=1 and Y[s]==1:
        temp -= 1
    X[s] += 1
    Y[s] -= 1
    ans += [temp]

print(max(ans))

Solution (Python):

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

mx=0
for i in range(1,N):
  l1=list(set(S[:i]))
  l2=list(set(S[i:]))
  
  c=0
  for x in l1:
    if l2.count(x)>0:
      c+=1

  
  mx=max(mx,c)


print(mx)

Solution (Python):
N = int(input())
S = input()
com = 0
S_set = [set(S[_] for _ in range(N))]
for i in range(1, N - 1):
    S_com = set(S[:i]) & set(S[i:])
    if com < len(S_com):
        com = len(S_com)
print(com)

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

result = []

for i in range(N):
    a = set(list(S[:i]))
    b = set(list(S[i:]))
    result.append(len(a.intersection(b)))

print(max(result))

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

result = []

for i in range(n):
    a = set(list(s[0:i]))
    b = set(list(s[i:]))
    result.append(len(a.intersection(b)))

print(max(result))

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

ans = 0

for i in range(N - 1):
    A = S[:i + 1]
    B = S[i + 1:]
    C = set()
    for a in A:
        if a in list(B):
            C.add(a)
        ans = max(ans, len(C))

print(ans)

Solution (Python):
n = int(input())
s = input()
mc = 0
mindex = -1
for i in range(1, len(s)):
    a = {}
    b = {}
    sa = s[0:i]
    sb = s[i:]
    c = 0
    for x in range(len(sa)):
        a[sa[x]] = True
    for x in range(len(sb)):
        b[sb[x]] = True
    for j in a.keys():
        if j in b:
            c += 1
    if mc < c:
        mc = c
        mindex = i
print(mc)

Solution (Python):
N = int(input())
s = list(input())
g = 0
mg = -1
cs = set()
for i in range(N-1):
    if s[i] in s[i+1:]:
        if not s[i] in cs:
            g += 1
            cs.add(s[i])
    else:
        if s[i] in cs:    
            g -= 1
            cs.remove(s[i])
    mg = max(mg,g)
print(mg)

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

Solution (Python):
import string

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

for i in range(1,N):
  l, r = S[:i], S[i:]
  cnt = 0
  for j in string.ascii_letters:
    if j in l and j in r:
      cnt+=1
  ans = max(ans, cnt)
print(ans)

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

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

Solution (Python):

N = int(input())
S = input()
ans = 0
moji = 'abcdefghijklmnopqrstuvwxyz'
for i in range(1, N):
  l, r = S[:i], S[i:]
  cnt = 0
  for c in moji:
    if c in l and c in r:
      cnt += 1
  ans = max(ans, cnt)
  
print(ans)

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

max_number = 0

for i in range(1, N):

    pre = S[0:i]
    post = S[i:]

    pre_dic = {}
    post_dic = {}

    for c in pre:
        pre_dic[c] = True

    for c in post:
        post_dic[c] = True

    number = 0

    for c in post_dic:
        if c in pre_dic:
            number += 1

    max_number = max(max_number, number)

print(max_number)

Solution (Python):

import sys


def solve(N: int, S: str):
    ret = 0
    for i in range(1, N):
        l = set(S[:i])
        r = set(S[i:])
        count = 0
        for c in l:
            if c in r:
                count += 1
        ret = max(ret, count)
    print(ret)
    return


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)  
    solve(N, S)

if __name__ == '__main__':
    main()

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance





def main():
    n = intin()
    s = input()

    x = []
    y = [c for c in s]
    ans = 0

    while y:
        ans = max(ans, len(set(x) & set(y)))
        c = y.pop()
        x.append(c)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
S = input()
L = []
for i in range(1, N):
    a = set()
    b = set()
    for j in S[:i]:
        a.add(j)
    for k in S[i:]:
        b.add(k)
    count = len(a & b)
    L.append(count)

print(max(L))

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')




def solve():
    n = f()[0]
    s = input()

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

solve()

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

max_count=0
for i in range(1,n):
    left = s[:i]
    right = s[i:]
    count = 0
    for c in "abcdefghijklmnopqrstuvwxyz":
        if c in left and c in right:
            count += 1
    max_count = max(max_count, count)

print(max_count)

Solution (Python):
alpha = [chr(i) for i in range(97,97 + 26)]

def Count(s,t):
	ret = 0
	for i in alpha:
		if i in s and i in t:ret+=1
	return ret

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

ans = 0
for i in range(1,n):
	ans = max(ans,Count(s[:i],s[i:]))
print(ans)

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

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

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

Solution (Python):
N = int(input())
S = input().rstrip()
maximum = -10**9
for i in range(N-1):
    X = S[:i+1]
    Y = S[i+1:]
    X_char = set(X)
    Y_char = set(Y)
    count = 0
    for i in list(X_char):
        if i in Y_char:
            count += 1
    if count > maximum:
        maximum = count
print(maximum)

Solution (Python):
import sys
input = sys.stdin.readline

n = int(input())
s = input().rstrip()
count = 0
for i in range(1, n-1):
  left = s[:i]
  right = s[i:]
  c = len(set(left) & set(right))
  if count < c:
    count = c
print(count)

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

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

Solution (Python):
n=int(input())
s=input()
ma=0
for i in range(1,n):
    s1=s[:i]
    s2=s[i:]
    cnt=0
    for a in set(s1):
        if a in s2:
            cnt+=1
    if ma<cnt:
        ma=cnt
print(ma)

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = int(input())
S = input()
ans = -1
for i in range(1,N):
    a = S[:i]
    b = S[i:]
    seta = set(list(a))
    tmp = 0
    for sa in seta:
        if sa in b:
            tmp += 1
    ans = max(tmp,ans)
print(ans)

Solution (Python):
n=int(input())
s=list(str(input()))
al=[chr(ord("a")+i) for i in range(26)]
c=[0 for i in range(n)]
for i in range(n):
    sl=s[:i]
    sr=s[i:]
    for j in al:
        if j in sl and j in sr:
            c[i]+=1
print(max(c))

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()
count=[]
for i in range(len(S)):
    a=[]
    b=[]
    for k in range(i):
        a.append(S[k])
    for h in range(i,len(S)):
        b.append(S[h])
    A=set(a)
    B=set(b)
    count.append(len(A&B))

print(max(count))

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

max_stgy = (0, 0)
for sep in range(1, N):
    kinds = len(set(S[:sep]) & set(S[sep:]))
    if max_stgy[1] < kinds:
        max_stgy = (sep, kinds)

print(max_stgy[1])

Solution (Python):

def main():
    num = int(input())
    data = list(input())
    ans = 0
    for i in range(1, num - 1):
        pre = data[:i]
        aft = data[i:]
        kari = len(set(pre) & set(aft))
        if ans < kari:
            ans = kari

    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
s = input()
moji = [chr(i)for i in range(97,97+26)]
ans = 0
for i in range(n):
    count = 0
    for key in moji:
        if key in s[i:] and key in s[:i]:
            count +=1
    if count > ans:
        ans = count
print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(n):
    hidari = s[:i]
    migi = s[i:]
    count = 0
    alist = []
    for j in hidari:
        if (j in migi) and (j not in alist):
            count += 1
            alist.append(j)          
    if count > ans:
        ans = count
print(ans)

Solution (Python):
n = int(input())
s = input()
alph = [chr(i) for i in range(97,97+26)]
ans = 0
for i in range(n):
  cnt = 0
  for key in alph:
    if key in s[:i] and key in s[i:]:
      cnt += 1
  if cnt > ans:
    ans = cnt
print(ans)

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

for i in range(1,N-1):
  cnt=0
  A=set(S[:i])
  B=S[i:]
  for a in A:
    if a in list(B):
      cnt+=1
  if cnt_max<cnt:
    cnt_max=cnt

print(cnt_max)

Solution (Python):


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

    ans = 0
    for i in range(N):
        X = S[:i+1]
        Y = S[i+1:]
        syurui = 0
        onaji = {}
        for x in X:
            if (x in Y) and (not x in onaji):
                onaji[x] = True
                syurui += 1
        ans = max(ans, syurui)
    print(ans)


if __name__ == "__main__":
    solve()

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

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=len(a&b)
    if c>ans:
        ans=c
print(ans)

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

    count = 0
    max_ = 0

    for i in range(N):
        x = set(S[:i])
        y = set(S[i:])

        max_ = max(len(x&y), max_)

    print(max_)


if __name__=='__main__':
    main()

Solution (Python):
N = int(input())
S = input()
ans_list = []
abc_list = [chr(i) for i in range(97,97+26)]
for i in range(1,N):
    ans = 0
    S1 = list(S[:i])
    S2 = list(S[i:])
    for j in abc_list:
        if(j in S1 and j in S2):
            ans += 1
    ans_list.append(ans)
print(max(ans_list))

Solution (Python):
n=int(input())
t=input()
d=[len(list(set(list(t[:i]))&set(list(t[i:])))) for i in range(1,n-1)]
try:
  print(max(d))
except:
  print(0)

Solution (Python):
n=int(input())
s=input()
l=[]
for i in range(n-1):
    ans=0
    su=list(set(s[:i+1]))
    sd=list(set(s[i+1:]))
    for j in su:
        if j in sd:
            ans+=1
    l.append(ans)
print(max(l))

Solution (Python):
n=int(input())
l=list(input())
c=0
for i in range(1,n):
  c1=0
  l2=[]
  for j in range(0,i):
    if (l[j] in l[i:n]) and not (l[j] in l2):
      c1+=1
      l2.append(l[j])
  if c1>c:
    c=c1
print(c)