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):
def resolve():
	n = int(input())
	s = input()
	ans = 0
	for i in range(1, n-1):
		c = 0
		a, b = set(s[:i]), set(s[i:])
		for j in a:
			for k in b:
				if j == k:
					c += 1

		ans = max(ans, c)
	print(ans)
resolve()

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

num = 0
for i in range(n-1):
    x = s[:i+1]
    y = s[i+1:]

    setx = {i for i in x}
    sety = {i for i in y}
    common = setx & sety

    num = max(num, len(common))

print(num)

Solution (Python):
n = int(input())
s = input()
x = 0
for i in range(n):
    a = set(s[:i])
    b = set(s[i:])
    c = len(a & b)
    if c > x:
        x = c
print(x)

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

lans = list()
for i in range(1, N):
    sa = S[:i]
    sb = S[i:]
    l = list()
    cnt = 0
    for j in range(i):
        if S[j] in sb and S[j] not in l:
            l.append(S[j])
            cnt += 1
    lans.append(cnt)

print(max(lans))

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

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

def main():
    N = int(input())
    S = list(input())

    ans = 0
    for i in range(N):
        s1 = S[:i]
        s2 = S[i:]

        tmp = set()
        for s in s1:
            if s in s2:
                tmp.add(s)
        tmp_len = len(tmp)
        if tmp_len > ans:
            ans = tmp_len
    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):
n=int(input())
s=input()
x=""
y=""
saidai=0
for i in range(n):
    x=s[:i+1]
    y=s[i+1:]
    
    x_y_and=set(x)&set(y)
    if len(x_y_and)>saidai:
        saidai=len(x_y_and)
    x=""
    y=""
    x_y_and=""
print(saidai)

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

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    S = input().rstrip()

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
s = input()
alphabet = ["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(n):
  a, b = s[:i], s[i:]
  sub = 0
  for j in range(26):
    if alphabet[j] in a and alphabet[j] in b:
      sub += 1
  if ans < sub:
    ans = sub
print(ans)

Solution (Python):
n=int(input())
s=input()
k=0
for i in range(n-1):
    a=s[:i+1]
    b=s[i+1:]
    c={}
    count=0
    for j in range(len(a)):
        if a[j] in b and a[j] not in c:
            count+=1
            c[a[j]]=1
    if count>k:
        k=count
print(k)

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

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

Solution (Python):
n=int(input())
s=str(input())
s=list(s)
ans=0
for i in range(1,n-1):
  temp1=s[:-i]
  temp2=s[-i:]
  temp1=list(set(temp1))
  temp2=list(set(temp2))
  count=0
  for j in range(0,len(temp1)):
    if temp2.count(temp1[j])>=1:
      count=count+1
  ans=max(ans,count)
print(ans)

Solution (Python):
N = int(input())
S = list(map(str, input().rstrip()))

ans = 0

for i in range(1, N):
    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(n):
    s_f = set(s[:i])
    s_b = set(s[i:])
    _l =len(s_f & s_b)
    if ans < _l:
        ans = _l

print(ans)

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

ans = 0

for i in range(N - 1):
    tmp = set()
    for j in S[: i + 1]:
        if j in S[i + 1 :]:
            tmp.add(j)
    ans = max(ans, len(tmp))

print(ans)

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

ans = 0

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

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

Solution (Python):
import sys
import math
import bisect

def solve(s):
    n = len(s)
    max_val = 0
    for i in range(1, n):
        s1 = set(list(s[0:i]))
        s2 = set(list(s[i:]))
        val = len(s1 & s2)
        max_val = max(max_val, val)
    return max_val

def main():
    n = int(input())
    s = input()
    print(solve(s))

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
s = input()
a = [0]*26
al = 'abcdefghijklmnopqrstuvwxyz'
for i in range(n):
  a[al.index(s[i])] += 1
b = [0]*26
res = 0
for i in range(n):
  b[al.index(s[i])] += 1
  tmp = 0
  for j in range(26):
    if b[j] >= 1 and a[j] - b[j] >= 1:
      tmp += 1
  res = max(res, tmp)
print(res)

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

ans = 0
for i in range(N):
    same = 0
    S_a = S[0:i+1]
    S_b = S[i+1:N]
    for alphabet in "abcdefghijklmnopqrstuvwxyz":
        if S_a.count(alphabet) >0 and S_b.count(alphabet):
            same +=1
    if same > ans:
        ans = same
print(ans)

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

S = input()

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

print(res)

Solution (Python):
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    s = s_input()

    al=[chr(ord('a') + i) for i in range(26)]

    max_kind = 0
    for i in range(1,n):
        before_s = s[:i]
        after_s = s[i:]
        tmp_count = 0
        for check_s in al:
            if check_s in before_s and check_s in after_s:
                tmp_count += 1
        max_kind = max(max_kind, tmp_count)

    print(max_kind)

if __name__ == '__main__':
    main()

Solution (Python):

"""
Created on Wed May 13 17:11:47 2020

@author: shinba
"""

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

ans = 0

for i in range(1,n):
    s1 = set(s[:i])
    s2 = 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):
    k = 0
    used = []
    a = s[0:i]
    b = s[i:n]
    l, r = len(a), len(b)
    if l <= r:
        for j in range(l):
            if not a[j] in used:
                used.append(a[j])
                if a[j] in b:
                    k += 1
    else:
        for j in range(r):
            if not b[j] in used:
                used.append(b[j])
                if b[j] in a:
                    k += 1
    ans = max(ans, k)

print(ans)

Solution (Python):






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





count = []
for i in range(1,N):
    left = S[:i]
    right = S[i:]


    count.append(len(set(left)&set(right)))
print(max(count))

Solution (Python):
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    head = set(S[:i])
    tail = set(S[i:])
    tmp_sum = 0
    for c in head:
        if c in tail:
            tmp_sum += 1

    ans = max(ans, tmp_sum)

print(ans)

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

ans=0
for i in range(n-1):
    l=[left for left in s[:i+1]]
    r=[right for right in s[i+1:]]
    st = set(l) & set(r)
    ans = max(len(st),ans)
print(ans)

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

Solution (Python):
n,S = open(0);print(max([len(set(S[:c])&set(S[c:])) for c in range(len(S))]))

Solution (Python):
import copy
N = int(input())
S = input()
LAlphabet = [False] * 26
L = []
for s in S:
    LAlphabet[ord(s)-97] = True
    L.append(copy.deepcopy(LAlphabet))

RAlphabet = [False] * 26
R = []
for s in reversed(S):
    RAlphabet[ord(s)-97] = True
    R.append(copy.deepcopy(RAlphabet))
R.reverse()
ans = 0

print(max([sum([L[l][t] and R[l+1][t] for t in range(26)]) for l in range(N-1)]))

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


ans = 0
for i in range(n-1):
    x = s[:i+1];y = s[i+1:]
    xs = set();ys = set()
    for v in x:
        xs.add(v)
    for v in y:
        ys.add(v)
    ans = max(len(xs & ys),ans)
print(ans)

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

for i in range(1,N):
  A = 0
  X = S[:i]
  Y = S[i:]
  for j in C:
    if j in X and j in Y:
      A += 1
  ans = max(ans,A)
print(ans)

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

ans = 0

for i in range(1,N):
    left = S[:i]
    right = S[i:]
    tmp = 0
    for alpha in 'qwertyuiopasdfghjklzxcvbnm':
        if alpha in left and alpha in right:
            tmp += 1
    ans = max(ans,tmp)
    
print(ans)

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

score = 0
for i in range(n):
    left = s[:i]
    right = s[i:]
    left_c = list(collections.Counter(left).keys())
    right_c = list(collections.Counter(right).keys())
    tmp_score = 0
    for c in left_c:
        if c in right_c:
            tmp_score += 1
    if score < tmp_score:
        score = tmp_score
print(score)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1, n):
    tmp = 0
    for a in 'abcdefghijklmnopqrstuvwxyz':
        if a in s[:i] and a in s[i:]:
            tmp += 1
    ans = max(ans, tmp)
print(ans)

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

for i in range(n+1):
  l = len(set(s[i:]).intersection(set(s[:i])))
  ans = max(ans, l)
print(ans)

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

print(res)

Solution (Python):
N=int(input())
S=list(input())
cnt=0
maxcnt=0
for i in range(N):
    if i==0:
        if S[0] in S[1:N]:
            cnt+=1
        if maxcnt<cnt:
            maxcnt=cnt
    elif i == N-1:
        if S[N-1] in S[0:N]:
            cnt-=1
    else:
        if S[i] not in S[0:i] and S[i] in S[i+1:N]:
            cnt+=1
            if maxcnt<cnt:
                maxcnt=cnt
        elif S[i] in S[0:i] and S[i] not in S[i+1:N]:
            cnt-=1
        else:
            pass
print(maxcnt)

Solution (Python):
from string import ascii_lowercase 

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

  ans = 0

  for i in range(1, N-1):
    left = S[:i]
    right = S[i:]

    letters = []
    for c in ascii_lowercase:
      if(c in left):
        letters.append(c)

    count = 0
    for c in letters:
      if c in right:
        count += 1

    ans = max(ans, count)

  print(ans)

if __name__ == "__main__":
  main()

Solution (Python):
def main():
    N = int(input())
    S = list(input())
    ans = 0
    for i in range(1, N):
        tmpleft = S[:i]
        tmpright = S[i:]
        mrg = set(tmpleft)&set(tmpright)
        ans = max(ans, len(mrg))
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
S = list(input())
max_cnt = 0
for i in range(1,N-1):
    L = S[0:i]
    R = S[i:N]
    temp = len(set(L)&set(R))
    if temp > max_cnt:
        max_cnt = temp
print(max_cnt)

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(n):
    
    ans = max(ans, len(set(s[0:i])&set(s[i:n])))

print(ans)

Solution (Python):
from collections import Counter

n = int(input())
s = list(str(input()))
ans = 0


for i in range(n):
    count = 0
    cnt1 = Counter(s[0:i])
    cnt2 = Counter(s[i:n])
    l = []
    for k, j in cnt1.items():
        l.append(k)
    for k, j in cnt2.items():
        l.append(k)
    cnt3 = Counter(l)
    
    for k, j in cnt3.items():
        if j == 2:
            count += 1
    ans = max(ans, count)

print(ans)

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

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

print(ans)

Solution (Python):
from collections import defaultdict
n = int(input())
s = input()
l=1
tmp = 0
while(l<n):
    dd = set()
    dd2 = set()
    for i in range(0, l):
        dd.add(s[i])
    for i in range(l, n):
        dd2.add(s[i])
    tmp = max(tmp, len(dd&dd2))

    l+=1
print(tmp)

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

    acc = []
    t = [0] * 26
    for c in s:
        i = ord(c) - ord('a')
        t[i] += 1
        acc.append(t.copy())

    ans = 0
    for i in range(N - 1):
        left = acc[i]
        right = [cn - ci for ci, cn in zip(acc[i], acc[N - 1])]
        cnt = 0
        for ci in range(26):
            if left[ci] and right[ci]:
                cnt += 1
            ans = max(ans, cnt)
    print(ans)


if __name__ == '__main__':
    main()

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

ans = 0
for i in range(N):
  S_1 = set(S[:i+1])
  S_2 = set(S[i+1:])
  count = 0
  for s in S_1:
    if s in S_2:
      count += 1
  ans = max(ans, count)

print(ans)

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

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

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

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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


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

    print(ans)


if __name__ == "__main__":
    main()

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

max_c = 0
for i in range(1, N-1):
    S_f = S[:i]
    S_l = S[i:]
    count = 0
    memo = []
    for f in S_f:
        if f not in memo and f in S_l:
            count += 1
            memo.append(f)
    if count > max_c:
        max_c = count
print(max_c)

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

ans = 0
for i in range(1, N):
  l = len(list(set(S[:i]) & set(S[i:])))
  if l > ans:
    ans = l
print(ans)

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

for i in range(N):
  cnt = 0
  for _ in list(set(S[:i])):
    if S[i:].count(_) > 0:
      cnt += 1
  if ans < cnt:
    ans = cnt
print(ans)

Solution (Python):
n=int(input())
moji=str(input())
cnt=0
for i in range(n):
  count = 0
  temp=moji[:i+1]
  lst=[]
  for j in range(i+1):
    if temp[j] in moji[i+1:] and temp[j] not in lst:
      count+=1
      lst.append(temp[j])
  if count > cnt:
    cnt=count
print(cnt)

Solution (Python):
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
N = I()
S = S()
ans = 0
for i in range(N):
    ans = max(ans,len(set(S[:i])&set(S[i:])))
print(ans)

Solution (Python):
import collections,sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
N = I()
S = S()
ans = 0
for i in range(N):
    set_top = set()
    set_bottom = set()
    for s in collections.Counter(S[:i]):
        set_top.add(s)
    for s in collections.Counter(S[i:]):
        set_bottom.add(s)
    ans = max(ans,len(set_top&set_bottom))
print(ans)

Solution (Python):
import collections,sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
N = I()
S = S()
ans = 0
for i in range(1,N-1):
    set_top = set()
    set_bottom = set()
    for s in collections.Counter(S[:i]):
        set_top.add(s)
    for s in collections.Counter(S[i:]):
        set_bottom.add(s)
    ans = max(ans,len(set_top&set_bottom))
print(ans)

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

Solution (Python):
N = int(input())
A = input()
ans = 0
for i in range(N):
  now = 0
  a = A[0:i+1]
  b = A[i+1:N]
  k = list(set(list(a)))
  l = list(set(list(b)))
  if min(len(k),len(l)) == len(k):
    for j in range(len(k)):
      if k[j] in l:
        now += 1
    if now > ans:
      ans = now
  else:
    for j in range(len(l)):
      if l[j] in k:
        now += 1
    if now > ans:
      ans = now
print(ans)

Solution (Python):
n=int(input())
s=input()
ans=0
 
for i in range(1, n):
    a=s[:i]
    b=s[i:]
    dic=[]
    dic2=[]
    for j in range(len(a)):
        if a[j] not in dic:
            dic.append(a[j])
    for k in range(len(b)):
        if b[k] not in dic2:
            dic2.append(b[k])
    cnt=0
    for i in range(len(dic)):
        if dic[i] in dic2:
            cnt+=1
    ans=max(ans, cnt)
    
print(ans)

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

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

Solution (Python):
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
s = input()
maxx = 0
for i in range(n-1):
    x = s[:i+1]
    y = s[i+1:]
    ans = set(x) & set(y)
    ansans = len(ans)
    maxx = max(maxx, ansans)
print(maxx)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = list(input())
res = 0
for i in range(1,n):
    x = s[:i]
    y = s[i:]
    sx = set(x)
    sy = set(y)
    cnt = 0
    for i in list(sx):
        if i in sy:
            cnt += 1
    res = max(res, cnt)
print(res)

Solution (Python):
N=int(input())
S=input()
ans=0
for i in range(1,N):
    T1=S[:i]
    T2=S[i:]
    sub=0
    L=set(T1)
    for t in set(T2):
        if t in L:
            sub+=1
    ans=max(ans, sub)

print(ans)

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1,n):
    p = s[:i]
    q = s[i:]
    
    res = 0
    for i in range(26):
        c = chr(i+ord('a'))
        if c in p and c in q:res += 1
    ans = max(res,ans)
print(ans)

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

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

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

def judge(s,t):
    s = set(s)
    t = set(t)
    x = s & t
    return(len(x))


ans = 0
for i in range(1,N-1):
    ans = max(ans,judge(S[:i],S[i:]))
    
print(ans)

Solution (Python):
N = int(input())
S = input().strip()
cmax = 0
for i in range(N-1):
    S1 = S[:i+1]
    S2 = S[i+1:]
    hist = {chr(i):0 for i in range(97,123)}
    cnt = 0
    for j in range(i+1):
        a = S1[j]
        if hist[a]==1:continue
        hist[a] = 1
        flag = 0
        for k in range(len(S2)):
            if S2[k]==a:
                flag = 1
                break
        if flag==1:
            cnt += 1
    cmax = max(cmax,cnt)
print(cmax)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7


n=I()
u=[]
alphasm=[chr(i) for i in range(97, 97+26)]
s=input().rstrip()
for i in range(n):
    s1=list(s[0:i])
    s2=list(s[i:n])
    count=0
    for x in alphasm:
        if (x in s1) and (x in s2):
            count+=1
    u.append(count)
print(max(u))

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

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

ans = 0
for i in range(N):
    X = S[:i]
    Y = S[i:]
    cnt = 0
    for j in range(97,123):
        index = chr(j)
        if X.find(index) != -1 and Y.find(index) != -1:
            cnt += 1
        ans = max(ans,cnt)
print(ans)

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

max_char = 0

for i in range(1, n):
    s1 = set(s[0:i])
    s2 = set(s[i:])
    num = len(s1 & s2)
    if num > max_char:
        max_char = num
print(max_char)

Solution (Python):
from sys import stdin
def check(s,t):
    d=dict()
    for c in s:
        if c not in d:
            d[c]=1

    res=0
    for c in t:
        if c in d:
            if d[c]==1:
                res+=1
                d[c]=0

    return res

def main():
    
    readline=stdin.readline
    N=int(readline())
    S=readline().strip()

    res=0
    for i in range(1,N):
        X=S[:i]
        Y=S[i:]
        res=max(res,check(X,Y))

    print(res)
if __name__=="__main__":
    main()

Solution (Python):
n = int(input())
s = input()
ans = 0
for i in range(1, n):
    f1 = s[:i]
    f2 = s[i:]
    f1 = list(set(f1))
    cnt = 0

    for j in range(len(f1)):
        if f1[j] in f2:
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Solution (Python):
n = int(input())
s = input()
eng = list("abcdefghijklmnopqrstuvwxyz")
ans = 0
for i in range(1, n):
  count = 0
  t = list(s[:i:])
  u = list(s[i::])
  for j in range(26):
    if (eng[j] in t) and (eng[j] in u) :
      count += 1
  ans = max(count, ans)
print(ans)

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

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

ans = 0
left = set()
right = set(S)
for s in S:
    left.add(s)
    C[s] -= 1
    if not C[s]:
        right -= {s}
    ans = max(ans, len(left & right))

print(ans)

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

Solution (Python):
import sys, heapq, bisect, math, fractions
from collections import deque

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

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

print(res)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = list(read().rstrip().decode())
ans = 0
for i in range(n):
    ans = max(ans, len(set(s[:i]) & set(s[i:])))
print(ans)

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right


from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
S = input()

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

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):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()

    res = 0
    for i in range(n):
        X = set(s[:i])
        Y = set(s[i:])
        cnt = 0
        for x in X:
            if x in Y:
                cnt += 1
        res = max(res, cnt)

    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

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

ans = 0
for i in range(N):
    A = set(S[:i])
    B = set(S[i:])
    tmp = 0
    for a in A:
        if a in B:
            tmp += 1
    ans = max(ans, tmp)

print (ans)

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

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

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

    ans = 0
    for i in range(n):
        x = set()
        for j in range(i):
            x.add(s[j])
        y = set()
        for j in range(i, n):
            if s[j] in x:
                y.add(s[j])
        ans = max(ans, len(y))

    print(ans)

if __name__ == '__main__':
    main()

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

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

print(ans)

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

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

print(ans)

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

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

Solution (Python):

import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi

N = ri()
S = [i for i in rs()]
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 = input()
ans = 0
for i in range(1,n):
    dum = []
    check = 0
    for j in s[0:i]:
        dum.append(j)
    dum = set(dum)
    
    for k in dum:
        if s[i:n].count(k) >= 1:
            check += 1
    ans = max(check,ans)
print(ans)

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

maxMatch = 0

for x in range(N):
    first_half = set(S[:x])
    second_half = set(S[x:])
    intersection = first_half & second_half
    maxMatch = max(maxMatch, len(intersection))
print(maxMatch)