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

Submission status: Accepted

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

def match_num(A, B):
    m=[]
    for a in A:
        if a in B and a not in m:
            m.append(a)
    return m

match_nums=[]
for n in range(1, N):
    #print("{}\t{}".format(S[:n], S[n:]))
    #print(n)
    if n <= N//2:
        #print(S[:n])
        #print(match_num(S[:n], S[n:]))
        match_nums.append(len(match_num(S[:n], S[n:])))
        
    else:
        #print(S[n:])
        #print(match_num(S[:n], S[n:]))
        match_nums.append(len(match_num(S[n:], S[:n])))
print(max(match_nums))

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 = 0
for i in range(1, len(S)):
  L = set(S[:i])
  R = S[i:]
#  print(L, R)
  cnt = 0
  for j in L:
    if j in R:
      cnt += 1
  ans = max(ans, cnt)
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=list(input())
dic={}
count=0
for i in S:
    if not i in dic.keys():
        dic[i]=[count]
    else:
        dic[i].append(count)
    count+=1

max_count=0
for j in range(1,N+1):
    count=0
    for key,value in dic.items():
        if len(value)==1:
            continue
        else:
            if value[0]<=j and j<value[-1]:
                count+=1
    if max_count<count:
        max_count=count
print(max_count)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    s = input().strip()
    print(max([len(set(s[:i]) & set(s[i:])) for i in range(1, n)]))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

m = 0
for i in range(N):
    index = len(set(S[0:i]) & set(S[i:N]))
    if m < index: m = index

print(m)

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
cnt=0
n=int(input())
s=input()

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

max_cnt = 0
for i in range(2, N):
    first_half = set(S[0:i])
    latter_half = set(S[i:N+1])

    intersect = first_half & latter_half

    max_cnt = max(max_cnt, len(intersect))

print(max_cnt)

Submission status: Accepted

Solution code:
N = int(input())
x = input()
m = 0
sumy = 0
for i in range(N):
    sumx = 0
    a = []
    b = []
    c = []
    for j in range(N):
                
        if j<i:
            a.append(x[j])
        else:
            b.append(x[j])
    for k in range(len(b)):
        if any([l==b[k] for l in a]) and not any(b[k]==n for n in c):
            sumx+=1
            c.append(b[k])
    if sumy<sumx:
        sumy = sumx

print(sumy)

Submission status: Accepted

Solution code:
N = int(input())
S = input().strip()
cmax = 0
for i in range(1,N-1):
    A = set(list(S[:i]))
    B = set(list(S[i:]))
    C = A&B
    cmax = max(cmax,len(C))
print(cmax)

Submission status: Accepted

Solution code:
n=input()
m=input() 
s=[str(i) for i in m]
ans=[]
for h in range(1,len(s)):
    x=s[:h]
    y=s[h:]
    z=len(list(set(x)&set(y)))
    ans.append(z)
print(max(ans))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
Alphabet = ["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"]
h = 0
for j in range(1,n):
    StringL = s[0:j]
    StringR = s[j:n]
    r = 0
    for i in Alphabet:
        if StringL.count(i) == 0:
            pass
        else:
            if StringR.count(i) == 0:
                pass
            else: r = r + 1
        if r > h:
            h = r
print(h)

Submission status: Accepted

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

L = []
for i in range(N):
    L.append(S[i])
    
ans = 0
for i in range(1, N+1):
    c = 0
    temp1 = L[0:i]
    temp2 = L[i:N+1]
    temp1_set = set(temp1)
    temp2_set = set(temp2)
    temp1 = list(temp1_set)
    temp2 = list(temp2_set)
    for j in range(len(temp1)):
        for k in range(len(temp2)):
            if temp1[j] == temp2[k]:
                c += 1
                break
    if ans < c:
        ans = c
        
print(ans)

Submission status: Accepted

Solution code:
# 入力の受け取り
n = int(input())
s = input()

# 全種類用意しとく
alphabets_list = [c for c in "abcdefghijklmnopqrstuvwxyz"]

# 判定
result = []
for i in range(1, n):
    x = s[ :i]
    y = s[i: ]
    count = 0
    for alphabet in alphabets_list:
        if (alphabet in x) and (alphabet in y):
            count += 1
        else:
            count += 0
    result.append(count)

print(max(result))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
s = 0
for i in range(1,N-1):
    l = set(S[:i]) & set(S[i::])
    if len(l) > s :
        s = len(l)
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
a = set(S[:1])
b = set(S[1:])
M = len(a & b)

for i in range(2,N):
  a = set(S[:i])
  b = set(S[i:])
  if len(a & b) > M:
    M = len(a & b)

print(M)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
import copy
M = 0
for i in range(n):
    count = 0
    l1 = copy.copy(s[0 : i + 1])
    l2 = copy.copy(s[i + 1 : n])
    l1 = list(set(l1))
    l2 = list(set(l2))
    for j in range(len(l1)):
        if l1[j] in l2:
            count += 1
    if count > M:
        M = count
print(int(M))

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
l = []
for i in range(len(s)):
    x = set(s[:i])
    y = set(s[i:])
    li = list((x & y))
    for i in li:
        if li.count(i) >= 2:
            while True:
                if li.count(i) == 1:
                    break
                else :
                    li.remove(i)
    l.append(len(li))
print(max(l))

Submission status: Accepted

Solution code:
n = int(input())
S = input()
letters = list("abcdefghijklmnopqrstuvwxyz")
print(max([len([x for x in letters if (x in S[:i]) & (x in S[i:])]) for i in range(1, n)]))

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 = 0
for i in range(n):
    if len(set(s[:i])&set(s[i:])) > count:count = len(set(s[:i])&set(s[i:]))
print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
S_set = set(S)
dict_right = {}
dict_left = {}
num_list = [0]

for st in S_set:
    dict_right[st] = S.count(st)
    dict_left[st] = 0
for s in S:
    if dict_left[s] == 0 and dict_right[s] != 1:
        num_list.append(num_list[-1] + 1)
    elif dict_left[s] != 0 and dict_right[s] == 1:
        num_list.append(num_list[-1] - 1)
    dict_right[s] -= 1
    dict_left[s] += 1
print(max(num_list))

Submission status: Accepted

Solution code:
import copy
n=input()
n=int(n)
s=input()
l=[]
indexs=[]
for i in range(n):
  l.append(s[i])
lr=copy.deepcopy(l)
lr.reverse()
se=set(l)
for k in se:
  if l.index(k)+lr.index(k)!=n-1:
    indexs.append([l.index(k),n-1-lr.index(k)])
count=[0]*n
for j in range(len(indexs)):
  for t in range(indexs[j][0],indexs[j][1]):
    count[t]+=1
print(max(count))

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

Submission status: Accepted

Solution code:
# coding: utf-8
# NとSの入力
N = int(input())
S = list(input())
#解答の初期化
ans = 0
#Nが小さいので愚直に求めてもTLEにならないと判断
for i in range(N):
  #Sをi番目までとその後で分割しXとYに
  #文字種の重複がないsetを使用する
  X = list(set(S[0 : i + 1]))
  Y = list(set(S[i + 1 : N]))
  #i番目で分けた場合の値の初期化
  temp = 0
  #1文字ずつ見ていく
  for x in X:
    for y in Y:
      if x == y:
        temp += 1
        break
  #tempが今までの値よりも大きい場合上書き
  if temp > ans:
    ans = temp
#解答の出力
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

ans = 0
for i in range(N-1):
  X = S[:i+1]
  Y = S[i+1:]
  temp = 0
  for s in Counter(X).keys():
    if s in Y:
      temp += 1
  ans = max(ans, temp)
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# NとSの入力
N = int(input())
S = list(input())
#解答の初期化
ans = 0
#Nが小さいので全探索で十分
for i in range(N):
  #Sをi番目で分割しXとYに
  X = list(set(S[0 : i + 1]))
  Y = list(set(S[i + 1 : N]))
  #i番目で分けた場合の値の初期化
  temp = 0
  #1文字ずつ見ていく
  for x in X:
    for y in Y:
      if x == y:
        temp += 1
        break
  #ansをtempで上書きするかどうか
  if temp > ans:
    ans = temp
#解答の出力
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt_max = 0
for i in range(1,n):
  s_1 = set(s[:i])
  s_2 = set(s[i:])
  cnt = 0
  for p in s_1:
    if p in s_2:
      cnt += 1
  cnt_max = max(cnt ,cnt_max)
print(cnt_max)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1,n):
  k = 0
  for j in range(97,123):
    if s[:i].count(chr(j))*s[i:].count(chr(j)):
      k += 1
  ans = max(k,ans)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def count(strings):
    s = set()
    for c in strings:
        s.add(c)
    return s


N = int(input())
S = input()
ans = 0
for i in range(1, len(S)):
    left = count(S[:i])
    right = count(S[i:])
    ans = max(ans, len(left & right))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans1 = 0
for i in range(1,N):
  ans = 0
  a = S[:i]
  b = S[i:]
  a.sort()
  c = a[0]
  if c in b:
    ans +=1
  for j in range(1,len(a)):
    if a[j]!=c and a[j] in b:
      ans +=1
      c = a[j]
  ans1 = max(ans,ans1)
print(ans1)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
max_count = 0
for i in range(1,n):
    count = 0
    l = set(s[0:i])
    r = set(s[i:n])
    for j in r:
        if j in l:
            count = count + 1
    else:
        if count > max_count:
            max_count = count

print(max_count)

Submission status: Accepted

Solution code:
def bb098():
    n = int(input())
    s = input()
    t = list(s)

    u = list(set(t)) # uniq 重複を削除
    if len(u) == 1:
        print(1)
        import sys
        sys.exit()

    mx = 0
    for i in range(1, n-1):
        v = t[0:i]
        w = t[i:]
        vw = list(set(v) & set(w))
        if len(vw) > mx:
            mx = len(vw)

    print(mx)

bb098()

Submission status: Accepted

Solution code:
n=int(input())
s=[i for i in input()]
a=[]
for i in range(1,n):
    k=0
    x=list(set(s[:i]))
    y=list(set(s[i:]))
    for j in range(len(x)):
        if x[j] in y:
            k+=1
    a.append(k)
print(max(a))

Submission status: Accepted

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

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

Submission status: Accepted

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

ture_count_list = []
for i in range(1, N):
    count_list = []
    left_S_list = []
    for s in S[0:i]:
        if s not in left_S_list:
            left_S_list.append(s)
        else:
            pass
    for m in left_S_list:
        if m in S[i:]:
            count_list.append(True)
        else:
            count_list.append(False)
        ture_count_list.append(count_list.count(True))


print(max(ture_count_list))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
key = ["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"]
for i in range(1, n):
    anssub = 0
    a, b = s[0:i], s[i:]
    for value in key:
        if value in a and value in b:
            anssub += 1
    if anssub > ans:
        ans = anssub
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1,n):
    cnt=0
    a=s[:i]
    b=s[i:]
    for j in range(ord('a'),ord('z')+1):
        if a.count(chr(j)) and b.count(chr(j)): cnt+=1
    ans=max(ans,cnt)
print(ans)

Submission status: Accepted

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

for i in range(1, n):
#    print(s[:i] + '---' +s[i:])

    count = 0
    for c in set(s[:i]):
        if c in s[i:]:
            count += 1

    res = max(res, count)
    
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

for i in range(1, N+1):
    X = S[:i]
    Y = S[i:]
    c = Counter(X)

    count = 0
    for j in c:
        if j[0] in Y:
            count += 1

    ans = max(count, ans)

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
for i in range(1,N):
  l=[]
  r=[]
  for j in range(i):
    l.append(S[j])
  for j in range(i,N):
    r.append(S[j])
  count=0
  for item in set(l):
    if item in r:
      count+=1
  if ans<count:
    ans=count
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, N):
    dup_cnt = set(S[:i]) & set(S[i:])
    if cnt < len(dup_cnt):
        cnt = len(dup_cnt)
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1,len(S)):
    l = []
    r = []
    for k in range(0,i):
        l.append(S[k])
    for k in range(i,len(S)):
        r.append(S[k])
    count = 0
    for item in set(l):
        if item in r:
            count += 1
    if ans < count:
        ans = count
    count = 0
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
M=0
for i in range(n-1):
    L=s[:i+1]
    R=s[i+1:]
    check={}
    cnt=0
    for c in L:
        if c not in check:
            check[c]=1
    for c in check:
        if c in R:
            cnt+=1
    M=max(M,cnt)
print(M)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = str(input().rstrip('\n'))
    mc = 0
    for i in range(1, n):
        cnt = 0
        ts1 = dict(collections.Counter(s[:i]).most_common()).keys()
        ts2 = dict(collections.Counter(s[i:]).most_common()).keys()
        for k, in ts1:
            if k in ts2:
                cnt += 1
        mc = max(mc, cnt)
    print(mc)


if __name__ == '__main__':
    slove()

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:
_ = input()
S = input().strip()

ans = 0
for i in range(1,len(S)):
  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(1,N-1):
    s1 = set(list(S[:i]))
    s2 = set(list(S[i:]))
    n = len(s1 & s2)
    if ans < n:
        ans = n
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

m = 0
for i in range(1, n):
  a = s[:i]
  b = s[i:]
  c = len(set(a) & set(b))
  m = max(m, c)

print(m)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
count = 0
for x in range(1, n):
    s1= s[0:x]
    s2= s[x:]
    S = set(s1) & set(s2)
    if len(S) > count:
        count = len(S)
print(str(count))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# a = [2,3,4,7,5,7]

# b = a[0:1]
# print(b)


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

ls = list(S)
# print(ls)

# a = []

max = 0
# counter = 0

x = 1
# y = -1
for i in range(len(S)):
  a = ls[0:x]
  b = ls[x:]
  a_s = set(a)
  b_s = set(b)
  c = len(list(a_s & b_s))
  x +=1

  if c > max:
    max = c
    # print(a[-1])

print(max)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ss = [0]*N

if S.count(S[0]) == N:
  print(1)

else:
  for i in range(1, N):
    X = "".join(set(S[:i]))
    Y = "".join(set(S[i:]))
    for j in range(len(X)):
      if X[j] in Y:
        ss[i] += 1
  
  print(max(ss))

Submission status: Accepted

Solution code:
def count(s, t):
    hai=[]
    for i in range(len(s)):
        if not(s[i] in hai):
            hai.append(s[i])
    hai2=[]
    for i in range(len(t)):
        if not(t[i] in hai2):
            hai2.append(t[i])
    kotae=0
    for h in hai:
        if h in hai2:
            kotae+=1
    return kotae

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

for i in range(n):
    mae=s[:i]
    ato=s[i:]
    kazu=count(mae, ato)
    if kazu>=kotae:
        kotae=kazu

print(kotae)

Submission status: Accepted

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

maxi = 0
for i in range(1, n):
  x = []
  for c in s[:i]:
    if c not in x and c in s[i:]:
      x.append(c)
  maxi = max(maxi, len(x))
print(maxi)

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:]
  ans=max(ans,len(set(list(s1)))+len(set(list(s2)))-len(set(list(S))))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
kinds = []
for i in range(1,n):
    # print(s[0:i],s[i:])
    l = s[0:i]
    r = s[i:]
    dubles = []
    for i in list(l):
        for j in list(r):
            if i == j:
                dubles +=[i]
    # print(dubles)
    # print(set(dubles))
    kinds += [len(set(dubles))]
    
    
print(max(kinds))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
alphaList = "qwertyuiopasdfghjklzxcvbnm"
sMax = 0
for i in range(1, n):
    sSum = 0
    for j in range(26):
        if s[0:i].count(alphaList[j]) > 0 and s[i:n].count(alphaList[j]) > 0:
            sSum += 1
    sMax = max(sMax, sSum)
print(sMax)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC098b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = [0]*n
for i in range(n-1):
    cnt = 0
    x = list(set(s[0:i+1]))
    y = list(set(s[i+1:]))
    for j in range(len(x)):
        if x[j] in y:
            cnt += 1
    ans.append(cnt)
print(max(ans))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
record = 0
for position in range(n):
  x = s[:position + 1]
  y = s[position + 1:]
  if len(set(x) & set(y)) > record:
    record = len(set(x) & set(y))
print(record)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
count = 0
soFar = 0
for i in range(1, n):
    first = list(set(s[:i]))
    second = list(set(s[i:]))
    for j in range(len(first)):
        if first[j] in second:
            count += 1
    soFar = max(soFar, count)
    count = 0
print(soFar)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
s = [ n for n in s ]
ans = 0

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
sum = 0
ans = 0
for i in range(n-1):
  a = set(list(s[:i]))
  b = set(list(s[i:]))
  sum =len(a&b)
  if sum > ans:
    ans = sum
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

s = list(input())

res = 0
for i in range(1, n):
    temp = 0
    a = set(s[:i])
    b = set(s[i:])
    for j in a:
        if j in b:
            temp += 1
    if temp > res:
        res = temp

print(res)

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

count_list=[]
for i in range(1,N):
  X = S[0:i]
  Y = S[i:N]
  count=0
  temp = []
  for c in X:
    if c in Y:
      if c not in temp:
        count += 1
        temp.append(c)
  count_list.append(count)
print(max(count_list))

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

Submission status: Accepted

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

for i in range(N - 1):
    s1 = set(S[:i + 1])
    s2 = set(S[i + 1:])
    ans.append(len(s1 & s2))

print(max(ans))

Submission status: Accepted

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

count = [0] * n
last = -1

for c in range(26):
    c = chr(ord("a")+c)
    last = -1
    for i in range(n):
        if s[i] == c:
            if last == -1:
                count[i] += 1
            last = i
    count[last] -= 1
 
ans = count[0]
for i in range(1, n):
    count[i] += count[i-1]
    ans = max(ans, count[i])

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
rcount = [0] * 26
for i in range(n):
    rcount[ord(s[i])-ord("a")] += 1
lcount = [0] * 26

ans = 0
cur = 0
for i in range(n):
    j = ord(s[i])-ord("a")
    lcount[j] += 1
    rcount[j] -= 1
    if lcount[j] == 1 and rcount[j] >= 1:
        cur += 1
    if rcount[j] == 0 and lcount[j] >= 2:
        cur -= 1
    ans = max(ans, cur)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
from collections import defaultdict

ans = 0
L = "abcdefghijklmnopqrstuvwxyz"
for i in range(1,N):
    tmp = 0
    zen = S[:i]
    kou = S[i:]
    for j in L:
        if j in zen and j in kou:
            tmp += 1
    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans = 0
for i in range(1,N):
    a=0
    s1 = list(set(S[:i+1]))
    s2 = list(set(S[i+1:]))
    for j in range(len(s2)):
        a += list(set(s1)).count(s2[j])
    ans = max(ans, a)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# ABC098 B - Cut and Count
n = int(input())
s = input()

ans=0
for i in range(n-1):
    start = s[0:i+1]
    end = s[i+1:]
    start = ''.join(set(start))
    c = 0
    for j in range(len(start)):
        if start[j] in end:
            c += 1
            ans = max(ans,c)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
newlist = []
for ni in range(n):
    newlist.append([s[0:ni+1],s[ni+1:n]])
count = 0
for n in newlist:
    if len(set(n[0]) & set(n[1]))>count:
        count = len(set(n[0]) & set(n[1]))
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
text=input()
ans=0
for i in range(1,N):
  texta=text[:i]
  textb=text[i:]
  seta=set(list(texta))
  setb=set(list(textb))
  m=len(seta&setb)
  if ans<m:
    ans=m
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N = II()
S = IS()
max = 0
for i in range(1, N+1):
    cnt = 0
    a = set(S[:i])
    b = set(S[i:])
    for s in a:
        if s in b:
            cnt += 1
    if max < cnt:
        max = cnt
print(max)

Submission status: Accepted

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


max = 0

for half in range(N-1):

    X = S[0:half+1]
    Y = S[half+1:N] 

    set_X = set(X)
    set_Y = set(Y)
    tmp = len(set_X&set_Y)

    if tmp > max:
        max = tmp

print(max)

Submission status: Accepted

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

let = [chr(i) for i in range(97, 97 + 26)]

ans = 0
for i in range(1, n):
    l = s[:i]
    r = s[i:]
    cnt = 0
    for let_ele in let:
        if let_ele in l and let_ele in r:
            cnt += 1
    ans = max(ans, cnt)

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())
A = input()


## 分断する位置についてのループ
cnt = 0
for n in range(1,N):
  before = A[:n]
  after = A[n:]
  
  ## 一致する文字数のカウント

  _cnt = []
  for bef in before:
    if bef in after:
      _cnt.append(bef)
      
  cnt = max(cnt,len(set(_cnt)))

print(cnt)

Submission status: Accepted

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


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
import sys
from collections import deque
from functools import reduce
import copy
import math


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    s = inputs[0]
    max_count = 0
    for i in range(1, len(s)):
        front = s[0:i]
        tail = s[i:]
        front_kind = set()
        tail_kind = set()

        for f in front:
            front_kind.add(f)

        for t in tail:
            tail_kind.add(t)

        count = len(front_kind & tail_kind)
        max_count = max([count, max_count])
    return max_count


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

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

ans=0
for i in range(1,n+1):
  X=S[:i]
  Y=S[i:]
  tmp=[]
  for x in X:
    if x in Y:
      tmp.append(x)
  ans=max(ans,len(list(set(tmp))))
print(ans)

Submission status: Accepted

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