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:
# ABC098B - Cut and Count
import collections

n = int(input())
s = input().rstrip()
count = 0
answer = 0
lst = [i for i in s]

if collections.Counter(lst) == 1:
    print(1)
else:
    for i in range(1, n):
        count = 0
        lst_sub1 = lst[:i]
        lst_sub2 = lst[i:]

        set_sub1 = set(lst_sub1)
        set_sub2 = set(lst_sub2)

        for j in set_sub1:
            if j in set_sub2:
                count += 1
        answer = max(answer, count)

    print(answer)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
	N = int(input())
	S = input()
	ans = 0
	for i in range(1, N-1):
		this_ans = 0
		appear = set()
		for j in range(i):
			appear.add(S[j])
		
		already = set()
		for j in range(i, N):
			if S[j] in appear and not S[j] in already:
				this_ans += 1
				already.add(S[j])
		ans = max(ans, this_ans)

	print(ans)


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
N = int(input())
S = input()
m = 0
for i in range(N-1):
  a = S[:i+1]
  b = S[i+1:]
  c = 0
  for j in list(set(a)):
    if j in b:
      c += 1
  if c > m:
    m = c
print(m)

Submission status: Accepted

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

#区切り位置は文字数-1（スライサーは1～N-1）
max = 0
for i in range(1, N, 1):
  a = len( set(S[:i]) & set(S[i:]) )
  if max < a: max = a
    
print(max)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

for i in range(N):
    S1=S[:i]
    S2=S[i:]
    se=set()
    t=0
    for j in S2:
        if j in S1 and not(j in se):
            se.add(j)
            t+=1
    res=max(res,t)
print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


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

    m = -INF
    for i in range(1, N):          # S[:i]とS[i:]
        kind = 0
        for c in set(S[:i]):
            if S[i:].count(c) > 0:
                kind += 1
        if kind > m:
            m = kind
        # print(S[:i], S[i:], kind)
    print(m)
    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:
N = int(input())
S = list(input())
ans = 0

for i in range(N):
    T = S[:i]
    U = S[i:]
    commonTU = set(T) & set(U)
    cnt = len(commonTU)
    ans = max(cnt,ans)
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(len(s) - 2):
    s1 = list(set(s[:i + 1]))
    s2 = list(set(s[i + 1:]))

    j = 0
    for x in s1:
        if x in s2:
            j += 1
    ans = max(ans, j)

print(ans)

Submission status: Accepted

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

answer = 0

for i in range(N):
    x = set(S[:i])
    y = set(S[i:])
    a = len(x&y)
    answer = max(a, answer)

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
s = IS()
ans = 0
cuts = [[s[:i],s[i:]] for i in range(1,len(s))]
for cut in cuts:
    count = 0 
    for char in set(cut[0]):
        if char in set(cut[1]):
            count += 1
            ans = max(ans, count)
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(N):
   Sa = S[:i]
   Sb = S[i:]
   A = set(Sa)
   B = set(Sb)
   score = len(A&B)
   ans = max(ans, score)

print(ans)

Submission status: Accepted

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

max = 0
for i in range(N-1):
    s1 = S[:i+1]
    s2 = S[i+1:]
    s1 = list(set(s1))
    s2 = list(set(s2))
    count = 0
    for e in s1:
        if e in s2:
            count += 1
    if count > max:
        max = count

print(max)

Submission status: Accepted

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

for i in range(1,n-1):
    a = set(s[:i])
    b = set(s[i:])
    cnt = len(a) + len(b) - len(set(s))
    c = max(c,cnt)

print(c)

Submission status: Accepted

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

for i in range(1,n-1):
    a = set(s[:i])
    b = set(s[i:])
    cnt = len(a) + len(b) - len(a|b)
    c = max(c,cnt)

print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans =0
for i in range(N+1):
    tmp=len(set(S[0:i])&set(S[i:]))
    if tmp>ans:
        ans=tmp
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
ans = 0
for i in range(n):
    s = set()
    t = set()
    for a in S[0:i]:
        s.add(a)
    for b in S[i:n]:
        t.add(b)
    ans = max(ans,len(s&t))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
import string
abcs = string.ascii_lowercase

ans = 0
for sakaime in range(N):
    cnt = 0
    left = S[:sakaime]
    right = S[sakaime:]
    for alpha in abcs:
        if alpha in left and alpha in right:
            cnt += 1
    ans = max(ans, cnt)
    
print(ans)

Submission status: Accepted

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

ans = 0
for sakaime in range(N):
    left = set(S[:sakaime])
    right = set(S[sakaime:])
 
    cnt = len(left.intersection(right))
    ans = max(ans, cnt)

print(ans)

Submission status: Accepted

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

def f(s,t):
    a=set(s)
    b=set(t)
    c=a&b
    return len(c)

x=0
for i in range(1,n-1):
    str1=s[0:i]
    str2=s[i:n]
    x=max(x,f(str1,str2))
print(x)

Submission status: Accepted

Solution code:
n=int(input())
s=str(input())
s1=''
s2=''
max=0
for i in range(1,n-1):
  count={}
  s1=s[:i]
  s2=s[i:]
  for j in range(len(s1)):
    if s2.count(s1[j]) >= 1:
      count[s1[j]]=1
  data=list(count.keys())
  if len(data) > max:
    max=len(data)
print(max)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
l = len(S)
ans = []
for i in range(l-1):
    ans.append(len(set(S[0:i+1]) & set(S[i+1:l])))
print(max(ans))

Submission status: Accepted

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

def countCommonLetter(X, Y):
    return len(set([x for x in X if x in Y]))

def solve():
    return max ( [countCommonLetter( s[:i], s[i:] ) for i in range(1, N)] )

print( solve() )

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
max_cnt = 0
for i in range(N):
  li1 = [0]*26
  li2 = [0]*26
  cnt = 0
  for j in S[i:]:
    li1[ord(j)-97]+=1
  for j in S[:i]:
    li2[ord(j)-97]+=1
  for j in range(26):
    if(li1[j]>0 and li2[j]>0):
      cnt += 1
  max_cnt = max(max_cnt,cnt)
print(max_cnt)

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 = str(input())
max = 0
list_S = list(S)
for i in range(N-1):
    X = list_S[:i]
    Y = list_S[-(len(list_S)-i):]
    result = set(X) & set(Y)
    if max < len(result):
        max = len(result)
print(max)

Submission status: Accepted

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

ans = -1
for i in range(N):
    x = len(set(list(S[:i]))&set(list(S[i:])))
    if x > ans:
        ans = x

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
ori=input()
max=0
for i in range(n-1):
    former=ori[:i+1]
    latter=ori[i+1:n]
    common=0
    for j in range(26):
        if chr(j+97) in former and chr(j+97) in latter:
            common+=1
        if max<=common:
            max=common
    
print(max)

Submission status: Accepted

Solution code:
N = int(input())
s = input()
ans = 0
for i in range(1, N-1):
    cnt = 0
    X = s[:i]
    Y = s[i:]
    alpX = [0 for j in range(26)]
    alpY = [0 for j in range(26)]
    lenX = i
    lenY = N-i
    for j in range(lenX):
        alpX[ord(X[j])-97] += 1
    for j in range(lenY):
        alpY[ord(Y[j])-97] += 1
    for j in range(26):
        if alpX[j] != 0 and alpY[j] != 0:
            cnt += 1 
    if ans < cnt:
        ans = cnt
print(str(ans))

Submission status: Accepted

Solution code:
_,a=open(0);print(max(len(set(a[:s])&set(a[s:]))for s in range(99)))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1,n-1):
    s1 = s[:i]
    s2 = s[i:]
    cnt =0 
    for x in 'abcdefghijklmnopqrstuvwxyz':
        if x in s1 and x in s2:
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())
s = str(raw_input())
count = 0
for i in range(1,n):
	x = list(s[:i])
	y = list(s[i:])
	com = set(x) & set(y)
	count = max(count, len(com))
print count

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
oristr=input()
max=0
for i in range(n-1):
  former=oristr[0:i+1]
  latter=oristr[i+1:n]
  common=0
  for j in range(26):
    if chr(j+97) in former and chr(j+97) in latter:
      common+=1
  if max<=common:
    max=common
print(max)

Submission status: Accepted

Solution code:
N = input()
S = input().strip()

res = []

for i in range(0,len(S)):
    res.append(len(set(S[i:]) & set(S[:i])))

print(max(res))

Submission status: Accepted

Solution code:
n,s=int(input()),input()
maxcount=0
for i in range(1,n+1):
  count=0
  x,y=s[:i],s[i:]
  for t in set(s):
    if t in x and t in y:
      count+=1
  if maxcount<count:
    maxcount=count
print(maxcount)

Submission status: Accepted

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

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

def list_intersection(a,b):
    c = []
    for i in range(len(a)):
        for j in range(len(b)):
            if a[i] == b[j]:
                c.append(a[i])
                a[i] = "_"
                b[j] = "&"
    return c

ans = 0
for i in range(1,n):
    inter = list_intersection(s[:i],s[i:])
    inter = set(inter)
    inter = list(inter)
    ans = max(ans,len(inter))

print(ans)

Submission status: Accepted

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

m = 0

for i in range(1, N):
    ans = 0
    X = S[:i]
    Xu = list(set(X))
    Y = S[i:]
    for a in Xu:
        if(Y.count(a)>0):
            ans+=1
    m = max(m, ans)

print(m)

Submission status: Accepted

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

def cnt(s,t):
	ret = 0
	for c in al:
		if c in s and c in t:ret+=1
	return ret

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

Submission status: Accepted

Solution code:
import collections as col
N = int(input())
S = input()
SMae, SAto = '', ''
SCol = col.Counter(S).most_common()
Ans = [0]*(N-1)

for i in range(N-1):
    SMae, SAto = S[:i+1], S[i+1:]
    for j in SCol:
        if j[0] in SMae and j[0] in SAto:
            Ans[i] += 1

print(max(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:
from sys import stdin
N=int(stdin.readline().rstrip())
S=(stdin.readline().rstrip())
ans=0
for i in range(N):
    if ans < len(set(S[:i]) & set(S[i:])):
        ans = len(set(S[:i]) & set(S[i:]))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = []
for i in range(1, N):
    X = S[: i + 1]
    Y = S[i + 1 :]
    setlist = list(set(X)) + list(set(Y))
    ans.append(len(setlist) - len(set(setlist)))
print(max(ans))

Submission status: Accepted

Solution code:
#coding: utf-8
from collections import Counter
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    cnt = 0
    left, right = S[:i], S[i:]
    longer, shorter = max(left, right), min(left, right)
    for j in range(len(longer)):
        if longer[j] in shorter and longer[j] not in longer[:j]:
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
max_ntypes = 0
for i in range(N):
    left = set(S[0:i+1])
    right = set(S[i+1:N])
    n = len(list(left & right))
    if n > max_ntypes:
        max_ntypes = n
print(max_ntypes)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
count_list = []
for i in range(1,n):
    count = 0
    left_list = set(s[:i])
    right_list = set(s[i:])
    for moji in left_list:
        if moji in right_list:
            count += 1
    count_list.append(count)
print(max(count_list))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1,n):
  a=0
  for j in range(97,123):
    if chr(j) in s[:i] and chr(j) in s[i:]:
      a+=1
  ans=max(ans,a)
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(list(S[:i]))&set(list(S[i:]))))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(n):
    d = {}
    for j in s[:i]:
        if d.get(j, 0) == 0:
            d[j] = 1
    for j in s[i:]:
        if d.get(j, 0) == 1:
            d[j] = 2
    t = 0
    for j in d:
        if d[j] == 2:
            t += 1
    ans = max(ans, t)

print (ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1,n):
    x,y=set(s[:i]),set(s[i:])
    #print(x,y)
    tmp=0
    for j in x:
        if j in y:
            #print(j,y)
            tmp+=1
            #print("tmp",tmp)
    if ans<tmp:
        ans=tmp
print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
S = list(input())
m = 0
for i in range(1, N):
    A = S[:i]
    B = S[i:]
    m = max(m, len(collections.Counter(A))+len(collections.Counter(B)))
print(m - len(collections.Counter(S)))

Submission status: Accepted

Solution code:
def skind(x,y):
  ans,s=0,[]
  for i in range(len(x)):
    if x[i] in y and not x[i] in s:
      ans+=1
      s.append(x[i])
  return ans
n,s,ans=int(input()),input(),0
for i in range(n-1):ans=max(ans,skind(s[:i+1],s[i+1:]))
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(n):
  count = 0
  checked = []
  for item in s[:i]:
    if item not in checked:
      if item in s[i:]:
        count += 1
      checked.append(item)
  ans = max(ans, count)
  
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
types=[]
for i in range(1,len(s)+1):
    types.append(len(set(s[:i]) & set(s[i:])))
print(max(types))

Submission status: Accepted

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

answer =0
for i in range(1,N-1):
  X = S[:i]
  Y = S[i:]
  count=0
  for l in 'abcdefghijklmnopqrstuvwxyz':
    if l in X and l in Y:
      count +=1
  answer =max(answer, count)
  
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

#分ける、xとyで文字の種類リストを作る、数える

def word_count(word):
    member = []
    for w in word:
        if not(w in member):
            member.append(w)
    return member

max_word = 0
for i in range(1,n):
    cut_place = i #i = 1なら0が左
    x = s[:i]
    y = s[i:]
    curr_word = 0
    x_s = word_count(x)
    y_s = word_count(y)
    for j in x_s:
        if j in y_s:
            curr_word += 1
    if max_word < curr_word:
        max_word = curr_word

print(max_word)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
result=[]
for i in range(1,N):
  result.append(sum([1 for s in set(list(S[:i])) if s in S[i:]]))
print(max(result))

Submission status: Accepted

Solution code:
n = int(input())
sli = list(input())

ans = 0
for i in range(1, n-1):
    x = len(set(sli[:i]) & set(sli[i:]))
    if ans < x:
        ans = x

print(ans)

Submission status: Accepted

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

kind = []

for i in range(N - 1):
    left = set(S[:i + 1])
    right = set(S[i + 1:])
    kind.append(len(left & right))

print(max(kind))

Submission status: Accepted

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

for i in range(1, N):
    X = S[:i]
    Y = S[i:]
    tmp = len(set(X) & set(Y))
    if tmp > ResMax:
        ResMax = tmp

print(ResMax)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

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

    s1 = set()
    s2 = set()
    for l in left:
        s1.add(l)
    for r in right:
        s2.add(r)
    s3 = s1 & s2
    count = len(s3)
    if max_chars < count:
        max_chars = count
print(max_chars)

Submission status: Accepted

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

vmax = 0
for i in range(n):
    s0 = s[:i]
    s1 = s[i:]

    v = len(set(set(s0) & set(s1)))
    vmax = max(vmax, v)

print(vmax)

Submission status: Accepted

Solution code:
import collections
n=int(input())
s=list(str(input()))
l=[]

c=collections.Counter(s)
#print(len(c.values()))

for i in range(1,n):
    x=s[:i]
    y=s[i:]
    xc=collections.Counter(x)
    yc=collections.Counter(y)
    l.append(len(xc.values())+len(yc.values())-len(c.values()))
    
print(max(l))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ss = list(set(s))
answer = 0


for i in range(n):
	kari = 0
	x = s[:i]
	y = s[i:]
	for j in ss:
		if j in x:
			if j in y:
				kari += 1
	answer = max(answer, kari)
	
print(answer)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    X = S[:i]
    Y = S[i:]
    count = 0
    for j in range(26):
        if chr(ord("a") + j) in X and chr(ord("a") + j) in Y:
            count += 1
    if count > ans:
        ans = count
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
maxcnt = 0
for i in range(n-1):
    cnt = 0
    for p in set(s[:i+1]):
        if p in s[i+1:]:
            cnt += 1
    if cnt > maxcnt:
        maxcnt = cnt
print(maxcnt)

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:])
    ans = max(ans, len(s1 & s2))

print(ans)

Submission status: Accepted

Solution code:
def solve(string):
    n, s = string.split()
    return str(max([len(set(s[:i]) & set(s[i:])) for i in range(1, int(n))]))


if __name__ == '__main__':
    print(solve("\n".join([input(), input()])))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ret = 0
for x in range(1, N):
    s1 = set(S[0:x])
    s2 = set(S[x:])
    ret = max(ret, len(s1 & s2))
print(ret)

Submission status: Accepted

Solution code:
n = int(input())
b = input()
 
largest = -1
for i in range(n):
  l = len(set(b[:i]) & set(b[i:]))
  largest = l if largest < l else largest
 
print(largest)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
maximum = 0
for i in range(n):
    kind = len(set(s[0:i]) & set(s[i:]))
    if kind > maximum :
        maximum = kind
print(maximum)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
maximum = 0
for i in range(n):
    x = s[0:i]
    y = s[i:]
    kind = len(set(x) & set(y))
    if kind > maximum :
        maximum = kind

print(maximum)

Submission status: Accepted

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

max_score = 0
for i in range(1,n-1):
    s1 = s[:i]
    s2 = s[i:]
    dic = []

    for x in s1:
        if x in s2 and x not in dic:
            dic.append(x)

    if max_score < len(dic):
        max_score = len(dic)

print(max_score)

Submission status: Accepted

Solution code:
# /user/bin/python
# -*- coding: utf-8 -*-


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

ans = 0
for i in range(1,N):
  dct = {}
  for c in S[:i]:
    if c in S[i:]:
      if c not in dct:
        dct[c] = 1
      else:
        dct[c] += 1
  ans = max(ans, len(dct))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
ans_li = []
for i in range(1,N,1):
  tmp_1 = list(set(S[i:]))
  tmp_2 = list(set(S[:i]))
  tmp_3 = set(tmp_1)&set(tmp_2)
  ans_li.append(len(tmp_3))
print(max(ans_li))

Submission status: Accepted

Solution code:
n = int(input())

s = input()

ans = 0

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

Submission status: Accepted

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

def main():
	N = int(input())
	tmp = input()
	S = list(tmp)
	
	ans_max = 0
	for i, val in enumerate(S):
		ans = 0
		S1 = []
		S2 = []
		if i == N-1:
			continue
			
		for j, vol in enumerate(S):
			if i < j:
				S2.append(vol)
			else:
				S1.append(vol)
			
		strings = []
		for i in S1:
			for j in S2:
				if i == j:
					strings.append(i)
		l_unique = list(set(strings))
		ans = len(l_unique)
		if ans_max < ans:
			ans_max = ans
				
	print(ans_max)
		
if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N):
    x = S[:i]
    y = S[i:]
    x_y = set(x) & set(y)
    ans = len(x_y) if len(x_y) > ans else ans
print(ans)

Submission status: Accepted

Solution code:
def cut_and_count(N: int, S: str) -> int:
    l, r = {}, {}
    for c in S:
        if c not in r:
            r[c] = 1
        else:
            r[c] += 1

    max_len = 0
    for c in S:
        if c not in l:
            l[c] = 1
        else:
            l[c] += 1
        r[c] -= 1

        ls = set(k for k, v in l.items() if v > 0)
        rs = set(k for k, v in r.items() if v > 0)

        temp = len(ls & rs)
        max_len = max(max_len, temp)

    return max_len


if __name__ == "__main__":
    N = int(input())
    S = input()
    ans = cut_and_count(N, S)
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
S0 = list(S)
max_S3 = 0

for i in range(N):
  dic1 = {}
  dic2 = {}
  S1 = S0[:i+1]
  S1 = set(S1)
  S2 = S0[i+1:]
  S2 = set(S2)
  S3 = list(S1 & S2)
  if(max_S3 < len(S3)):
   max_S3 = len(S3)
  
print(max_S3)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N):
  cnt = 0
  l = set(S[:i])
  r = set(S[i:])
  for ll in l:
    if(ll in r):
      cnt += 1
  ans = max(ans, cnt)
print(ans)

Submission status: Accepted

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

def f(l,r):
    li=[]
    re=0
    for i in range(len(l)):
        if l[i] in r and l[i] not in li:
            re+=1
            li.append(l[i])
    return re
            
ans=0

for i in range(1,n):
    sl=s[:i]
    sr=s[i:]
    ans=max(ans,f(sl,sr))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
S = [i for i in input()]
anslist = []
for i in range(N):
    ans = 0
    left =set(S[:i])
    rigth=set(S[i:])
    for j in left:
        for r in rigth:
            if j==r:
                ans+=1
    anslist.append(ans)
print(max(anslist))

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
count_L = [0] * 26
count_R = [0] * 26
ans = []
for i in range(n-1):
    count_L = [0] * 26
    count_R = [0] * 26
    c = 0
    for j in range(0,i+1):
        count_L[ord(s[j])-97] += 1
    for j in range(i+1,n):
        count_R[ord(s[j])-97] += 1
    #print(count_L,count_R)

    for j in range(26):
        if count_L[j] > 0 and count_R[j] > 0:
            c += 1
    ans.append(c)
print(max(ans))

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
S = input()
ans = 0
for i in range(N):
    n = 0
    X, Y = set(S[:i + 1]), set(S[i + 1:])
    for x in X:
        if x in Y:
            n += 1
    if ans < n:
        ans = n
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N):
    d1 = {}
    d2 = {}
    S1 = S[:i]
    S2 = S[i:]
    subans = 0
    for s in S1:
        d1[s] = True
    for s in S2:
        d2[s] = True
    for key in d1:
        if key in d2:
            subans += 1
    ans = max(ans, subans)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
for i in range(N):
  cnt = 0
  l = list(set(S[:i]))
  r = list(set(S[i:]))
  for ls in l:
    if(ls in r):
      cnt += 1
  ans = max(ans, cnt)
print(ans)

Submission status: Accepted

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

result = 0
for i in range(N-1):
    X = S[:i+1]
    Y = S[i+1:]
    setX = set(X)
    setY = set(Y)
    if setX & setY:
        result = max(len(list(setX & setY)), result)
print(result)

Submission status: Accepted

Solution code:
N = int(input())
s = input()
ans = 0
for i in range(N):
    l = set()
    r = set()
    tmp = 0
    x = s[0:i]
    y = s[i:]
    for j in x:
        l.add(j)
    for j in y:
        r.add(j)
    for j in l:
        if j in r:
            tmp += 1
    ans = max(ans,tmp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
maxcount = 0
for i in range(1, n):
	count = 0
	marked = []
	for j in range(i):
		if s[j] in marked:
			continue
		if s[i:].count(s[j]) > 0:
			count += 1
			marked.append(s[j])
	maxcount = max(count, maxcount)
print(maxcount)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N):
    t = len(set(S[:i]) & set(S[i:]))
    if ans<t:
        ans=t
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for i in range(N):
    a = S[0:i]
    b = S[i:]
    cache = 0
    obj = []
    for j in range(len(a)):
        if a[j] not in obj:
            if a[j] in b:
                obj.append(a[j])
                cache += 1

    if cache > count:
        count = cache

print(count)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
al="abcdefghijklmnopqrstuvwxyz"
candidate=[]
count=0
for i in range(n-1):
    for j in al:
        if j in s[:i+1] and j in s[i+1:]:
            count+=1
    candidate.append(count)
    count=0
candidate.sort()
print(candidate[-1])