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:
import numpy as np

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

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

Submission status: Accepted

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

ans = 0
for i in range(1, N):
    temp = 0
    X = list(set(S[:i]))
    for j in X:
        if S[i:].count(j):
            temp += 1
    ans = max(ans, temp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
rs = []
for i in range(1, N):
  X = S[:i]
  Y = S[i:]
  r = len(set(X)&set(Y))
  rs.append(r)
r = max(rs)
print(r)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1,n):
  s1 = list(set(s[:i]))
  s2 = list(set(s[i:]))
  for j in s1:
    if j in s2:
      tmp += 1
  if tmp > c:
    c = tmp
  tmp = 0
  
print(c)

Submission status: Accepted

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

import collections
c = 0
m = 0
for i in range(N):
  S1 = S[:i]
  S2 = S[i:]
  C1 = collections.Counter(S1)
  C2 = collections.Counter(S2)
  c = 0
  for c1 in C1.keys():
    if c1 in C2.keys():
      c += 1
  m = max(m,c)
print(m)

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

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

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

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque
from collections import  Counter
import statistics
import math

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
s = input()
c = Counter(s)
li = list(c.keys())
ans = -1
for i in range(n-1):
    ct = 0
    for c in li:
        if c in s[:i+1] and c in s[i+1:]:
            ct += 1
    ans = max(ans, ct)
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
s = input()
d = defaultdict(int)
for i in range(n):
    d[s[i]] += 1
dd = defaultdict(int)
ret = - float('inf')
for i in range(n):
    dd[s[i]] += 1
    cnt = 0
    for key in dd.keys():
        if d[key] - dd[key] > 0:
            cnt += 1
    ret = max(ret, cnt)
print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
a = 'qwertyuiopasdfghjklzxcvbnm'

ans = 0
for i in range(n):
    cnt = 0
    for ai in a:
        if ai in s[:i] and ai in s[i:]:
            cnt += 1
    ans = max(ans, cnt)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
S=list(input())
r=0
for i in range(n):
    c=0
    for s in set(S[:i]):
        if s in S[i:]:
            c+=1
    r=max(r,c)
print(r)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1, n-1):
    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(1,N-1):
    l = S[:i]
    r = S[i:]
    ans = max(len(set(l) & set(r)),ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
count = 0
 
for i in range(N):
  attributeNum = len(set(S[0:i]) & set(S[i:]))
        
  if attributeNum > count and count<= N//2:
    count = attributeNum
 
print(count)

Submission status: Accepted

Solution code:
def test():
    n = int(input())
    s = input()
    ans = 0
    for i in range(n):
        set1 = set(s[:i])
        set2 = set(s[i:])
        ans = max(ans,len(set1 & set2))
    print(ans)


if __name__ == "__main__":
    test()

Submission status: Accepted

Solution code:


def main():

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

    for i in range(N):
        attributeNum = len(set(S[0:i]) & set(S[i:]))
        
        if attributeNum > count and count<= N//2:
            count = attributeNum

    print(count)


if __name__== "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    m_cnt = 0
    for i in range(n):
        t_s = s[:i + 1]
        t_t = s[i + 1:]
        import collections
        t_s = collections.Counter(t_s)
        t_t = collections.Counter(t_t)
        cnt = 0
        for k, v in t_s.items():
            if k in t_t.keys():
                cnt += 1
        m_cnt = max(m_cnt, cnt)
    print(m_cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = input()
s = input()
ans = 0
for i in range(len(s)):
  l = s[:i]
  r = s[i:]
  cnt = 0
  cl = Counter(l)
  for i in cl.keys():
    if i in r:
      cnt += 1
  if ans < cnt:
    ans = cnt
print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
alpha = ["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"]

Max = 0
for i in range(n+1):
    x = s[:i]
    y = s[i:]
    count = []
    ans = 0
    for i in alpha:
        if i in x and i in y and not i in count:
           ans += 1
           count.append(i)
    Max = max(Max,ans)
print(Max)

Submission status: Accepted

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

nums = []
for i in range(1, len(s)):
  x = s[:i]
  y = s[i:]
  x_letters = set(x)
  y_letters = set(y)
  num = 0
  for letter in x_letters:
    if letter in y_letters:
      num += 1
  nums.append(num)

print(max(nums))

Submission status: Accepted

Solution code:
N=int(input())
S=list(str(input()))
ans=[]
for i in range(N-1):
  num=0
  l=[]
  s1=S[0:i+1]
  s2=S[i+1:N]
  if len(s1)<=len(s2):
    s1,s2=s1,s2
  else:
    s1,s2=s2,s1
  for j in range(len(s1)):
    if s1[j] not in l:
      l.append(s1[j])
  for j in range(len(l)):
    if (l[j] in s2)==True:
      num+=1
  ans.append(num)
print(max(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
ans=0
for i in range(1,n-1):
  sum=0
  s1=set(s[:i])
  s2=set(s[i:])
  for j in s1:
    for k in s2:
      if j==k:
        sum+=1
        break
  if sum>ans:
    ans=sum
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    max_count = 0
    for i in range(N-1):
        Aset = set(list(S[:i+1]))
        Bset = set(list(S[i+1:]))
        max_count = max(max_count, len(Aset & Bset))
    return max_count



if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

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

Submission status: Accepted

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

max_cnt = 0
for i in range(1, n - 1):
    left = s[:i]
    right = s[i:]
    cnt = 0
    found = set()
    for c in left:
        if c not in found and right.find(c) != -1:
            cnt += 1
            found.add(c)
    max_cnt = max(max_cnt, cnt)

print(max_cnt)

Submission status: Accepted

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

count = 0

for i in range(N):
  X = S[:i]
  Y = S[i:]
  # print(X, Y)
  # print(set(X) & set(Y))
  count = max(count, len(set(X) & set(Y)))
  
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

max_count = 0

for i in range(N):
    a = S[:i]
    b = S[i:]

    a_2 = collections.Counter(a)
    b_2 = collections.Counter(b)

    dst = {}

    for k,v in b_2.items():
        if k in a_2:
            dst[k] = v

    max_count = max(max_count,len(dst))

print(max_count)

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    s = input()
    max_common = 0
    for i in range(n):
        s1, s2 = s[:i + 1], s[i + 1:]
        common = len(set(set(s1) & set(s2)))
        if common > max_common:
            max_common = common
    print(max_common)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1,n-1):
    cnt = 0
    seen = []
    for char in s[:i]:
        if char in s[i:] and char not in seen:
            seen.append(char)
            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):
  h = set(s[:i])
  t = set(s[i:])
  ans = max(ans,len(h&t))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
count = 0
for i in range(1,n):
  count = 0
  h = list(set(s[:i]))
  t = list(set(s[i:]))
  if len(h)>len(t):
    for j in range(len(h)):
      if h[j] in t:count+=1
  else:
    for j in range(len(t)):
      if t[j] in h:count+=1
  ans = max(ans,count)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N = int(input())
S = input()
ans = 0
for i in range(1, len(S)+1):
    left = set(S[:i])
    right = set(S[i:])

    x = len(left & right)
    ans = max(ans, x)

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(1, N)]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

abc='abcdefghijklmnopqrstuvwxyz'
res=[]

for i in range(1,n):
	l=s[:i]
	r=s[i:]
	n_l=len(l)
	n_r=len(r)
	cnt=0
	for j in range(26):
		x=abc[j]
		for k in range(n_l):
			if l[k]==x:
				for m in range(n_r):
					if r[m]==x:
						cnt+=1
						break
				break
	res.append(cnt)

print(max(res))

Submission status: Accepted

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

Submission status: Accepted

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

right = {}
for s in S:
    right[s] = right.get(s, 0) + 1

answer = 0
left = {}
for s in S:
    left[s] = left.get(s, 0) + 1
    right[s] -= 1
    if right[s] == 0:
        del right[s]
    shared = len(set(left.keys()) & set(right.keys()))
    if shared > answer:
        answer = shared
print(answer)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = input()
def char_kinds(s1,s2):
    set1 = set(Counter(s1).keys())
    set2 = set(Counter(s2).keys())
    return len(set1 & set2)

# s1 = "aaasdd"
# s2 = "aaaasa"
# print(char_kinds(s1,s
ans = 0
for i in range(len(S)):
    if char_kinds(S[:i],S[i:]) >= ans:
        ans = char_kinds(S[:i],S[i:])
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1, len(S)):
    ans = max(ans, len(set(S[:i]).intersection(S[i:])))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
mx=0
for i in range(n-1):
    L=set(s[:i+1])
    R=set(s[i+1:])
    tmp=len(L&R)
    if tmp>mx:
        mx=tmp
print(mx)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def check_list_element(list):
    a = []
    for i in list:
        if i not in a:
            a.append(i)
    return a


for i in range(n):
    count = 0
    a = s[:i]
    b = s[i:]
    a = check_list_element(a)
    for j in range(len(a)):
        if a[j] in b:
            count += 1
    if count >= max_num:
        max_num = count


print(max_num)

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()
max = 0
for i in range(1, n):
    b = []
    count = 0
    x = s[:i]
    y = s[i:]
    for c in x:
        if c in y:
            if c not in b:
                b.append(c)
                count += 1
    if count > max:
        max = count
print(max)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
dic={}
for i in set(list(s)):
    if s.count(i)>1:
        dic[i]=s.count(i)
#print(dic)

d=0
for i in range(n-1):
    c=0
    x=s[:i+1]
    y=s[i+1:]
    if len(y)>len(x):
        for j in dic:
            if x.count(j)!=dic[j] and x.count(j)>0:
                c+=1
    else:
        for j in dic:
            if y.count(j)!=dic[j] and y.count(j)>0:
                c+=1
    if c>d:
        d=c
        #print(i)

print(d)

Submission status: Accepted

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

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

main()

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

ans = 0
for i in range(1, len(S)):
  right = collections.Counter(S[:i])
  left = collections.Counter(S[i:])
  n = right.keys() & left.keys()
  if (len(n) > ans):
    ans = len(n)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
s = input()
num_list = []
for i in range(N):
  l_s = s[:i]
  r_s = s[i:]
  num = len(set(l_s).intersection(set(r_s)))
  num_list.append(num)
print(max(num_list))

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

Submission status: Accepted

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

count_max = 0

for i in range(1,N):
    count = 0
    S_tmp = []
    for j in range(0,i):
        count_S = S_tmp.count(S[j])
        if count_S == 0:
            S_tmp.append(S[j])
            for k in range(i,N):
                if S[j] == S[k]:
                    count += 1
                    break
    if count_max < count:
        count_max = count

print(count_max)

Submission status: Accepted

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

Submission status: Accepted

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

ans=0
sset=set()
for i in range(1,N):
    sset.clear()
    num=0
    s1=S[:i]
    s2=S[i:]
    for j in range(i):
        sset.add(s1[j])
    for c in list(sset):
        if c in s2:
            num+=1
    if ans<num:
        ans=num

print(ans)

Submission status: Accepted

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

m = 0
for i in range(1,len(s)):
    x = s[0:i]
    y = s[i:len(s)]
    a = []
    count = 0
    for j in range(0,i):
        if x[j] in y and not(x[j] in a):
            a.append(x[j])
            count += 1
    m = max(m,count)
print(m)

Submission status: Accepted

Solution code:
n=int(input());s=input()
l=[[0]*26 for i in range(n-1)]
r=[[0]*26 for i in range(n-1)]

for i in range(n-1):
  l[i][ord(s[i])-ord('a')]=1
  if i!=n-2:
    for j in range(26):
      l[i+1][j]=l[i][j]

for i in range(n-2,-1,-1):
  r[i][ord(s[i+1])-ord('a')]=1
  if i!=0:
    for j in range(26):
      r[i-1][j]=r[i][j]

lr=[[0]*26 for i in range(n-1)]
for i in range(n-1):
  for j in range(26):
    lr[i][j]=l[i][j]*r[i][j]
x=0
for i in range(n-1):
  x=max(x,sum(lr[i]))
print(x)

Submission status: Accepted

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

for i in range(1,n):
    a = set(s[:i])
    b = set(s[i:])
    cnt = 0
    for a_ in a:
        cnt += 1 if a_ in b else 0
    max_cnt = max(cnt,max_cnt)

print(max_cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
can = []
for cut in range(n):
  p = []
  for i in range(cut+1):
    now = s[i]
    if now in p:
      pass
    else:
      p.append(now)
  pp = []
  for i in range(cut+1,n):
    now = s[i]
    if now in p:
      if now in pp:
        pass
      else:
        pp.append(now)
    else:
      pass
  can.append(len(pp))
print(max(can))

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = list(input())
ans = 0
for i in range(N):
    L = list(Counter(S[:i]).keys())
    R = list(Counter(S[i:]).keys())
    c = 0
    for l in L:
        if l in R:
            c += 1
    ans = max(ans, c)
print(ans)

Submission status: Accepted

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

ans = 0
a = 0
n = 0
for i in range(1,N):
    X = S[:i]
    Y = S[i:]
    lis = list(set(X))
    for j in range(len(lis)):
        if Y.count(lis[j]) != 0:
            a += 1

    if a > ans:
        ans = a
    a = 0

print(ans)

Submission status: Accepted

Solution code:
b = int(input())
a = input()
mc = 0
for i in range(1, len(a)):
    b = a[:i]
    c = a[i:]
    d = {}
    e = []
    cnt = 0
    for j in range(len(b)):
        d[b[j]] = 1
    for j in range(len(c)):
        if c[j] in d and c[j] not in e:
            cnt += 1
            e.append(c[j])
    mc = max(mc, cnt)
print(mc)

Submission status: Accepted

Solution code:
n = int(input())
s = [c for c in 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()
a = 0

for L in range(N):
  left = S[:L]
  right = S[L:]
  both = set(left)&set(right)
  a = max(a,len(both))

print(a)

Submission status: Accepted

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

ans = []
for i in range(1, n):
    set_a = set(s[:i])
    set_b = set(s[i:n+1])
    ans.append(len(set_a & set_b))

print(max(ans))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1,N):
    count = 0
    X = ""
    Y = ""
    for j in S[:i]:
        X += j

    for k in S[i:]:
        if X.find(k) != -1 and Y.find(k) == -1:
            Y += k
            count += 1
 
    ans = max(count, ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
cnt=0
ans=[]
for i in range(n):
	a=s[:i]
	b=s[i:]
	l=[]
	cnt=0
	for j in range(len(a)):
		if b.count(a[j])>=1\
		and a[j] not in l:
			cnt+=1
			l.append(a[j])
	ans.append(cnt)
print(max(ans))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans_list = []
for i in range(1, N):
    tmp = 0
    A = list(set(S[0:i]))
    B = list(set(S[i:N]))
    for k in A:
        if k in B:
            tmp += 1   
    ans_list.append(tmp)
print(max(ans_list))

Submission status: Accepted

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


print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
intersec = [] 
for i in range(n):
  w = set(s[0:1+i])
  x = set(s[1+i:])
  intersec.append(len(w & x))


print(max(intersec))

Submission status: Accepted

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

Submission status: Accepted

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

max_score = 0
for cut in range(1, n-2):
    bh = set(s[:cut])
    lh = set(s[cut:])
    cscore = len(bh.intersection(lh))
    if max_score < cscore:
        max_score = cscore

print(max_score)

Submission status: Accepted

Solution code:
from collections import Counter

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

solver = []
for i in range(N-1):
  X = S[:i+1]
  Y = S[i+1:]
  lst_X = list(Counter(X).keys())
  lst_Y = list(Counter(Y).keys())
  lst_and = set(lst_X) & set(lst_Y)
  solver.append(len(lst_and))
  
print(max(solver))

Submission status: Accepted

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

ans = []

for i in range(len(s)-1):
    dic = {}
    for j in range(i+1):
        if s[j] in s[i+1:] and s[j] not in dic:
            dic[s[j]] = 1
    ans.append(len(dic))

print(max(ans))

Submission status: Accepted

Solution code:
n=int(input());l=list(input());c=0
for i in range(1,n):c=max(c,len(set(l[:i])&set(l[i:])))
print(c)

Submission status: Accepted

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

ans = 0
for i in range(1, N):
    sj = set()
    sk = set()
    for j in range(i):
        sj.add(S[j])
    for k in range(i, N):
        sk.add(S[k])
    ans = max(len(sj & sk), ans)
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
li = []
for i in range(1,n-1):
    li.append(len(set(s[:i+1]) & set(s[i+1:])))
print(0 if len(li) == 0 else max(li))

Submission status: Accepted

Solution code:
# 単純に真ん中でよくない？ -> ダメです 愚直にやりましょう
n = int(input())
s = input()

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

Submission status: Accepted

Solution code:
# ABC 98 B - cut and count
n = int(input())
s = input()

max_t = 0
for i in range(1, n):
    s1 = set(s[:i])
    s2 = set(s[i:])
    t = len(s1.intersection(s2))
    max_t = max(max_t, t)
print(max_t)

Submission status: Accepted

Solution code:
# N, S = map(int, input().split())  # 入力
N = int(input())
S = input()
S = [c for c in S]

# print(N, S)
ans = 0
for i in range(N - 1):
    first = set(S[0:i+1])
    second = set(S[i+1:])
    # print(S[0:i+1], S[i+1:])
    # print(first, second)
    tmpans = 0
    for index, n in enumerate(range(len(first))):
        if list(first)[index] in list(second):
            tmpans += 1
            ans = max(ans, tmpans)


print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(n+1):
    str1 = set(s[:i])
    str2 = set(s[i:])
    length =len(str1 & str2)
    if ans < length :
        ans = length
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans_lsit = []
for i in range(N):
    count = 0
    tmp = list(set(S[:i]))
    for j in range(len(tmp)):
        if tmp[j] in S[i:]:
            count += 1
    ans_lsit.append(count)

ans = max(ans_lsit)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = list((x.encode()[0] - "a".encode()[0] for x in input()))
alb = [-1] * 26
ala = [-1] * 26
Sc = [0] * (len(S)+1)
for i, c in enumerate(S):
    if alb[c] == -1:
        alb[c] = i+1
        Sc[alb[c]] += 1
    else:
        if ala[c] >= 0:
            Sc[ala[c]] += 1
        ala[c] = i+1
        Sc[ala[c]] -= 1

for i, v in enumerate(ala):
    if v == -1 and alb[i] >= 0:
        Sc[alb[i]] -= 1

x = 0
m = 0
for c in Sc[:N]:
    x += c
    m = max(x, m)

print(m)

Submission status: Accepted

Solution code:

n = input()
s = input()
res = 0
for pos in range(len(s)):
    s1 = set(s[0:pos])
    s2 = set(s[pos:])
    s3 = s1 & s2
    res = max(res, len(s3))

print(res)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
mx = 0
for i in range(n-1):
  a = [ord(aa) for aa in s[:i+1]]
  b = [ord(bb) for bb in s[i+1:]]
  counter = 0
  for c in range(ord('a'), ord('z')+1):
    if (c in a) and (c in b):
      counter += 1
  if mx < counter:
    mx = counter

print(mx)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

# a-z
az = [chr(i) for i in range(97, 97 + 26)]

ans = 0
for i in range(1, n):
    count = 0
    for j in az:
        if s[i:n].count(j) != 0 and s[:i].count(j) != 0:
            count += 1
    ans = max(ans, count)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
if N == 2:
    print(len(set(S[0]).intersection(set(S[1]))))
else:
    ans = []
    for i in range(1, N-1):
        a = set(S[:i])
        b = set(S[i:])
        ans.append(len(a.intersection(b)))
    print(max(ans))