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



Sample input:
6
aabbca


Sample output:
2

Submission status: Accepted

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

for i in range(N - 1):
	# 文字列を2つに分割する
	S1 = S[:i + 1]
	S2 = S[i + 1:]
	s = []
	count = 0

	# S1に存在する文字がS2に存在する場合、その文字をlistに格納する
	for j in range(i + 1):
		if S2.count(S1[j]) != 0:
			s.append(S1[j])

 	# list内の文字種数を算出する
	count = len(set(s))

	# 文字種数がいままでの最大数より大きい場合は入れ替える
	ans = max(ans, count)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))
    #print(s[:i], s[i:])
    num.append(comm)

print(max(num))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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)

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
# 入力
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc098/submissions/5418660
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
###############################################################################

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()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:

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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

slist=list(s)
maxlist=[]
for i in range(1,n):
    maximum=0
    sr=slist[:i]
    sl=slist[i:]
    if sr.count("a")!=0 and sl.count("a")!=0:
        maximum+=1
    if sr.count("b")!=0 and sl.count("b")!=0:
        maximum+=1
    if sr.count("c")!=0 and sl.count("c")!=0:
        maximum+=1
    if sr.count("d")!=0 and sl.count("d")!=0:
        maximum+=1
    if sr.count("e")!=0 and sl.count("e")!=0:
        maximum+=1
    if sr.count("f")!=0 and sl.count("f")!=0:
        maximum+=1
    if sr.count("g")!=0 and sl.count("g")!=0:
        maximum+=1
    if sr.count("h")!=0 and sl.count("h")!=0:
        maximum+=1
    if sr.count("i")!=0 and sl.count("i")!=0:
        maximum+=1
    if sr.count("j")!=0 and sl.count("j")!=0:
        maximum+=1
    if sr.count("k")!=0 and sl.count("k")!=0:
        maximum+=1
    if sr.count("l")!=0 and sl.count("l")!=0:
        maximum+=1
    if sr.count("m")!=0 and sl.count("m")!=0:
        maximum+=1
    if sr.count("n")!=0 and sl.count("n")!=0:
        maximum+=1
    if sr.count("o")!=0 and sl.count("o")!=0:
        maximum+=1
    if sr.count("p")!=0 and sl.count("p")!=0:
        maximum+=1
    if sr.count("q")!=0 and sl.count("q")!=0:
        maximum+=1
    if sr.count("r")!=0 and sl.count("r")!=0:
        maximum+=1
    if sr.count("s")!=0 and sl.count("s")!=0:
        maximum+=1
    if sr.count("t")!=0 and sl.count("t")!=0:
        maximum+=1
    if sr.count("u")!=0 and sl.count("u")!=0:
        maximum+=1
    if sr.count("v")!=0 and sl.count("v")!=0:
        maximum+=1
    if sr.count("w")!=0 and sl.count("w")!=0:
        maximum+=1
    if sr.count("x")!=0 and sl.count("x")!=0:
        maximum+=1
    if sr.count("y")!=0 and sl.count("y")!=0:
        maximum+=1
    if sr.count("z")!=0 and sl.count("z")!=0:
        maximum+=1
    maxlist.append(maximum)

print(max(maxlist))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import sys
n = int(input())
s = input()
count_max = 0
for i in range(1,n):
    if len(set(s[:i]) & set(s[i:])) >count_max:
        count_max = len(set(s[:i]) & set(s[i:]))
print(count_max)

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  S = input()
  M = 0

  for i in range(1, N):
    s1 = set(list(S[:i]))
    s2 = set(list(S[i:]))

    M = max(M, len(s1.intersection(s2)))

  print(M)


if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
n=int(input())
s=input()
s_list=[]
for i in range(len(s)):
    s_list.append(s[i])

ans_list=[]
for j in range(len(s_list)):
    ans=len(set(s_list[:j])&set(s_list[j:]))
    ans_list.append(ans)

ans_list.sort()
print(ans_list[-1])

Submission status: Accepted

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

K = []
for i in range(1,N):
    X = set(S[:i])
    Y = set(S[i:])
    K.append(len(X & Y))

print(max(K))

Submission status: Accepted

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

K = []
for i in range(1,N):
    X = list(set(S[:i]))
    Y = list(set(S[i:]))
    cnt = 0
    for i in range(len(X)):
        if X[i] in Y:
            cnt += 1

    K.append(cnt)

print(max(K))

Submission status: Accepted

Solution code:

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

    return n, s

def submit():
    n, s = read_input()

    max_common = 0
    for i in range(1, n):
        f = s[:i]
        l = s[i:]

        fc = set([c for c in f])
        lc = set([c for c in l])

        common = fc.intersection(lc)
        if max_common < len(common):
            max_common = len(common)

    print(max_common)

if __name__ == '__main__':
    submit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
F=[]
B=[]
max=0

for i in range(1,N):
	F=S[0:i]
	B=S[i:N]
	tmp=set(F)&set(B)
	if tmp=='set()': tmp=0
	else: tmp=len(list(tmp))
	if max<tmp:
		max=tmp
print(max)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans = 0
for i in range(1, N):
    ans_tmp = 0
    S_unique = list(set(S[0:i]))
    for j in S_unique:
        if j in S[i:N]:
            ans_tmp += 1
    ans = max(ans, ans_tmp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
res = 0
for i in range(1,n):
    b,c =(s[:i], s[i:])
    cnt = 0
    for j in range(26):
        p = chr(ord('a') + j)
        cnt += (p in b) and (p in c)
    res = max(res, cnt)
print(res)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = [0]
for i in range(N):
    L = set(S[:i])
    R = set(S[i:])
    ans.append(len(list(L.intersection(R))))
print(max(ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import numpy as np
import math
import re

n = int(input())

x = input()
max = 0
for i in range(n):
    s = 0
    list1 = set(x[0:i])
    list2 = set(x[i:n])
    for j in list1:
        if j in list2:
            s += 1
    if s > max:
        max = s
print(max)

Submission status: Accepted

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

z = []
for i in range(1,N):
  x = S[:i]
  y = S[i:]
  if set(x) & set(y):
    z.append(len(set(x)&set(y)))
  else:
    continue

print(max(z) if len(z) != 0 else 0)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
z = 0

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

print(z)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = list(input())
ans = 0
for i in range(n):
    c1 = Counter(s[:i])
    c2 = Counter(s[i:])
    count = 0
    for k in c1.keys():
        if k in c2.keys():
            count += 1
    ans = max(ans, count)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = input()
n = list(input())
maxnum = -1
for i in range(len(n)):
    x = set(n[:i])
    y = set(n[i:])
    maxnum = max(maxnum, len(x & y))

print(maxnum)

Submission status: Accepted

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

for i in range(N):
    A=S[:i]
    B=S[i:]
    sum=0
    l=set()
    for j in A:
        if (j in B) and (j not in l):
            sum+=1
            l.add(j)
    ans=max(sum,ans)
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
alfabets = [chr(i) for i in range(97,97+26)]
numbers = []
for i in range(0,n-1) :
    cnt = 0
    a = s[0:i+1]
    b = s[i+1:n]
    for j in alfabets :
        if j in a and j in b :
            cnt += 1
    numbers.append(cnt)

print(max(numbers))

Submission status: Accepted

Solution code:
import sys

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

for i in range(1, len(s)):
    x_set = set(s[0:i])
    y_set = set(s[i::])
    xy_insect = x_set & y_set
    if len(xy_insect) and ans < len(xy_insect):
        ans = len(xy_insect)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = 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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    ret = 0
    for i in range(N):
        ret = max(ret, len(set(S[:i]).intersection(set(S[i:]))))
    print(ret)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
s = list(input())
cnt = 0
ans = 0
for i in range(1,n):
    a = s[:i]
    b = s[i:]

    a = list(set(a))
    b = list(set(b))

    a.sort()
    b.sort()

    for j in range(len(a)):
        if a[j] in b:
            cnt += 1
    
    if ans<cnt:
        ans = cnt

    cnt = 0

print(ans)

Submission status: Accepted

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

box = []
s = set()
for i in range(N):
    for j in range(0, i):
        if S[j] in S[i:]:
            s.add(S[j])
    box.append(len(s))
    s = set()
    
print(max(box))