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()
res=0
for i in range(1,n):
    a=s[:i]
    b=s[i:]
    sum=0
    for j in range(97,123):
        x=chr(j)
        if x in a and x in b:
            sum+=1
    res=max(sum,res)
print(res)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
res=0
for i in range(1,n):
    a=s[:i]
    b=s[i:]
    sum=0
    for j in range(97,123):
        x=chr(j)
        if x in a and x in b:
            sum+=1
    res=max(sum,res)
print(res)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

def solve(x,y):

    sx = set(x)
    sy = set(y)
    s_com = sx & sy
    return len(s_com)

ans = 0
for i in range(n):
    x = s[:i]
    y = s[i:]
    ans = max(ans,solve(x,y))

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
final_cnt = 0
for i in range(n):
    cnt = 0
    x = set(s[:i])
    y = set(s[i:])
    cnt = len(x.intersection(y))
    final_cnt = max(final_cnt, cnt)
print(final_cnt)

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
s=list(input())
ans=0
for i in range(1,n):
    s1=set(s[:i])
    s2=set(s[i:])
    s1=s1.intersection(s2)
    ans=max(ans,len(s1))
print(ans)

Submission status: Accepted

Solution code:
#7
n = int(input())
s = input()
x,y = "",""
Max = 0

for i in range(1,n):
    x = list(set(list(s[:i])))
    y = list(set(list(s[i:])))
    cnt = 0
    for m in x:
        for n in y:
            if m == n:
                cnt +=1
                break
        if Max < cnt:
            Max = cnt
            
print(Max)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

res = 0

for i in range(1,n):
    temp =""
    x = s[:i]
    y = s[i:]
    for j in range(i):
        if s[j] in y:
            temp +=s[j]
    res = max(res,len(set(temp)))

print(res)

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()
ans = 0


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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import numpy as np

def int_mtx(N):
    x = []
    for _ in range(N):
        x.append(input())
    return x

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

ans = 0

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

print(ans)

Submission status: Accepted

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

answer = 0
for index in range(1,len(s)-1):
  x = list(set(s[:index]))
  y = list(set(s[index:]))
  count = 0
  if len(x) > len(y):
    for check in x:
      if check in y:
        count += 1
  else:
    for check in y:
      if check in x:
        count += 1
  if count > answer:
    answer = count
  
print(answer)

Submission status: Accepted

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

al = [chr(ord('a') + i) for i in range(26)]
left =[]
right = []
for i in S:
    right.append(i)

ans = 0

for i in range(len(S)):
    left.append(right[0])
    right.pop(0)
    aaa = 0
    for i in al:
        if i in left and i in right:
            aaa += 1
    ans = max(ans,aaa)

print(ans)

Submission status: Accepted

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

# print(s)
max_count = 0
for i in range(len(s)):
    ss = "abcdefghijklmnopqrstuvwxyz"
    x_dict = {}
    y_dict = {}
    for c in ss:
        x_dict[c] = 0
        y_dict[c] = 0
        
    # print(i)
    
    x = s[:i]
    y = s[i:]
    # print(f"{x} {y}")
    
    for xx in x:
        x_dict[xx] += 1
        
    for yy in y:
        y_dict[yy] += 1
    
    # print(x_dict)
    # print(y_dict)
    
    count = 0
    for c in ss:
        # print(f"{x_dict[c]} {y_dict[c]}")
        if x_dict[c] > 0 and y_dict[c] > 0:
            # print(f"{x_dict[c]} {y_dict[c]}")
            count += 1
    # print(count)
    max_count = max(max_count, count)
        
print(max_count)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import collections
a=int(input())
b=input()
result=[]
for i in range(1,a):
    n=b[:i]
    m=b[i:]
    n=collections.Counter(n)
    m=collections.Counter(m)
    n,o1=zip(*n.most_common())
    m,o2=zip(*m.most_common())
    n=set(n)
    m=set(m)
    s_i=n&m
    s_i=len(s_i)
    result.append(s_i)
print(max(result))

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = input()
ans = 0
for i in range(n-1):
    a, b = Counter(s[:i+1]), Counter(s[i+1:])
    inter = a.keys() & b.keys()
    ans = max(ans, len(inter))
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
s=""
m=""
ss=[]
mm=[]
s1=set()
m1=set()
res = 0
for i in range(N):
  s=S[0:i+1]
  m=S[i+1:N]
  ss=list(s)
  mm=list(m)
  s1=set(ss)
  m1=set(mm)
  s_intersection = s1 & m1
  res= max(res,len(s_intersection))
print(res)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
maxi = 0
for i in range(1,N):
  a = S[0:i]
  b = S[i:]
  aa = set(a)
  bb = set(b)
  ans = bb&aa
  if len(ans) > maxi:
    maxi = len(ans)
print(maxi)

Submission status: Accepted

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

for i in range(1, n):
    c = 0
    s1 = s[i:]
    s2 = s[:i]
    S = set(s1)

    for j in S:
        if j in s2:
            c += 1
    cnt = max(cnt, c)

print(cnt)

Submission status: Accepted

Solution code:
input()
s = input()
m = 0

for i in range(1,len(s)):
    f = s[:i]
    g = s[i:]
    
    x = set(f)
    count = 0
    
    for j in x:
        if j in g:
            count = count+1
    m = max(count,m)

print(m)

Submission status: Accepted

Solution code:
n = int(input())

s = list(input())

ans = 0

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

print(ans)

Submission status: Accepted

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

lst = []
for i in range(1,n-1):
    left = s[:i]
    right = s[i:]

    cnt = 0
    for j in set(left):
        if j in set(right):
            cnt += 1
    lst.append(cnt)

if not lst:
    print(0)
else:
    print(max(lst))

Submission status: Accepted

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

for i in range(1, n):
    a = s[:i]
    b = s[i:]
    a_al = []
    ans_t = 0

    for k in range(len(a)):
        for l in range(len(b)):
            if a[k] in a_al:
                continue
            if a[k] == b[l]:
                ans_t += 1
                a_al.append(a[k])
    if ans_t > ans:
        ans = ans_t

print(ans)

Submission status: Accepted

Solution code:

N = int(input())
S = list(input()) #１文字ずつ

ans=0
for i in range(1,N):
    X = S[0:i]
    Y = S[i:N]
    cnt=0
    # print('X.,Y:', X,Y)

    als=[chr(ord('a') + i) for i in range(26)]
    for al in als:
        if (al in X) and (al in Y):
            cnt+=1
    ans=max(ans,cnt)
print(ans)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    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)

            



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n=int(input())
s=input()
ans = 0
for i in range(1,n):
    a = {j for j in s[:i]}
    b = {j for j in s[i:]}
    ans = max(ans, len(a & b))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

lchrs = [0]*26
rchrs = [0]*26
flag = [False]*26
for c in s:
    lchrs[ord(c)-ord("a")] += 1

for c in s:
    i = ord(c)-ord("a")
    lchrs[i] -= 1
    rchrs[i] += 1
    if lchrs[i] and rchrs[i]:
        flag[i] = True
    else:
        flag[i] = False
    ans = max(ans, len([_ for _ in flag if _]))
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
s = readline().decode().rstrip()
ans = 0
for i in range(1, n):
    cnt = 0
    for j in set(s[:i:]):
        if j in set(s[i::]):
            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):
    x = s[0:i]
    y = s[i:]

    uniq_x = set(x)
    uniq_y = set(y)

    cnt = 0
    for c in uniq_y:
        if c in uniq_x:
            cnt += 1

    ans = max(ans, cnt)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def countSameChar(x,y):
  cnt = 0
  for char in [chr(ord("a")+i) for i in range(26)]:
    if char in x and char in y:
      cnt += 1
  return cnt

def solve(n,s):
  ans = 0
  for i in range(n-2):
    x = s[:i+1]
    y = s[i+1:]
    ans = max(ans,countSameChar(x,y))
  return ans

print(solve(N,s))

Submission status: Accepted

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

lst = [0]*N

for i in range(N):
    X = list(set(list(S[0:i])))
    Y = list(set(list(S[i:N])))
    ans = 0
    for j in range(len(X)):
        if X[j] in Y:
            ans += 1
    lst[i] = ans

print(max(lst))

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    S = input()
    ans = 0
    for i in range(n-1):
        l = S[:i+1]
        r = S[i+1:]
        cnt = 0
        for s in set(l):
            if r.find(s) >= 0:
                cnt += 1
        ans = max(ans, cnt)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
for i in range(1,n):
    set_l = set(s[0:i])
    set_r = set(s[i::])
    set_both = set_l & set_r
    if ans < len(set_both):
        ans = len(set_both)
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()
C = [[-1, -1] for _ in range(26)]
for i in range(N):
    c = ord(S[i]) - ord('a')
    if C[c][0] == -1:
        C[c][0] = i
    else:
        C[c][1] = i
print(max([len(tuple(filter(lambda x: x[0] <= i < x[1], C))) for i in range(N)]))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
MAX = 0
for T in range(0,N+1):
    X = S[:T]
    Y = S[T:]
    Com = len(set(X)&set(Y))
    if Com>MAX:
        MAX = Com
print(MAX)

Submission status: Accepted

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

lst = [None]*(N-1)
for i in range(N-1):
    X = S[:i]
    Y = S[i:]
    lst[i] = len(set(X) & set(Y))
print(max(lst))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    S = input()
    ans = 0
    for i in range(1, N):
        cnt = 0
        for c in list(set(S[:i])):
            if c in list(set(S[i:])):
                cnt += 1
        ans = max(ans, cnt)
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

ans = 0
for i in range(len(s)):
    l = [s[j] for j in range(i + 1)]
    m = []
    for j in range(i + 1, len(s)):
        if s[j] in l and s[j] not in m:
            m.append(s[j])
    ans = max(ans, len(m))

print(ans)

Submission status: Accepted

Solution code:
import collections

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

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

ans = 0
for i in range(1, n):
    a = s[:i]
    b = s[i:]
    ca = list(collections.Counter(a).keys())
    cb = list(collections.Counter(b).keys())
    c = 0
    for cai in ca:
        if cai in cb:
            c += 1
    if ans < c:
        ans = c

print(ans)

Submission status: Accepted

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

for n in range(N-1):
  c = 0
  A = list(set(S[:n+1]))
  B = list(set(S[n+1:]))
  for a in A:
    if a in B:
      c+=1
  ans = max(ans,c)
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N, = list(map(int,input().split()))
S = input()
cx = Counter(S)
cy = Counter()
cm = 0
r = 0
for c in S:
    cx[c] -= 1
    cy[c] += 1
    if cy[c]==1 and cx[c]>=1:
        cm += 1
    elif cy[c]>=2 and cx[c]==0:
        cm -= 1
    r = max(r, cm)
print(r)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
L=[chr(i) for i in range(97, 97+26)]
ans0 = 0

for i in range(N-1):
  s1=S[0:i+1]
  s2=S[i+1:N]
  ans = 0
  for j in L:
    if ((j in s1) & (j in s2)):
      ans = ans + 1
    #print(ans)
  if ans0 < ans:
    ans0 = ans
print(ans0)

Submission status: Accepted

Solution code:
ans=0
N=int(input())
l=list(input())
for i in range(1,N):
   tmp1=set(l[0:i])
   tmp2=set(l[i:])
   tmp3=[]
   tmp3.append(list(tmp1))
   tmp3.append(list(tmp2))
   tmp3=sum(tmp3,[])
   tmp3=set(tmp3)
   ans=max(ans,-len(tmp3)+len(tmp2)+len(tmp1))
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]


def solve():
    n = int(input())
    s = [x for x in input()]
    ans = 0
    for i in range(n - 1):
        a = set(s[:i+1])
        b = set(s[i+1:])
        ans = max(ans, len(a & b))
    print(ans)


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()

"""

"""

Submission status: Accepted

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

ans=0
for i in range(len(S)):
    tmp=0
    a=set(S[:i:])
    b=set(S[i::])
    for i in a:
        if i in b:
            tmp+=1
    ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
import math
def main():
  n = int(input())
  s = input()
  ans=0
  for i in range(0,n):
    sum=0
    x=s[:i+1]
    y=s[i+1:]
    while len(x)>0:
      if x[0] in y :
        sum+=1
      x=x.replace(x[0],'')
    if sum>ans:
      ans=sum
  print(ans)
main()

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

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

print(ans)

Submission status: Accepted

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

for i in range(1,n):
    a = list(s[0:i])
    a = list(set(a))
    b = list(s[i:])
    t = 0
    for j in range(len(a)):
        if a[j] in b:
            t += 1
    p = max(t,p)

print(p)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(str,input()))

ans = 0
for i in range(n):
    a = l[:i]
    b = l[i:]
    tmp = []
    for j in a:
        if j in b:
            tmp.append(j)
    tmp = set(tmp)
    ans = (max(ans,len(tmp)))

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1,n-1):
    mae = s[:i]
    ato = s[i:]
    temp = []
    for j in mae:
        if j in ato:
            temp.append(j)
    temp = set(temp)
    ans = max(ans,len(temp))

print(ans)

Submission status: Accepted

Solution code:
import string

n = int(input())
s = input()
alp = list(string.ascii_lowercase)
ans = 0

for i in range(n):
    s1 = s[:i]
    s2 = s[i:]
    cnt = 0
    for c in alp:
        if c in s1 and c in s2:
            cnt += 1
    ans = max(ans, cnt)

print(ans)

Submission status: Accepted

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

#%%
ans = 0
for i in range(n):
    left = set(s[i:])
    right = set(s[:i])
    ans = max(ans, len(left & right))

print(ans)

Submission status: Accepted

Solution code:
n, s = open(0).read().split()

n = int(n)

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

print(ans)

Submission status: Accepted

Solution code:
import sys
N = int(input())
S = input()
unique_S = list(set(list(S)))

sys.exit() if not (2 <= N <= 100) else ''
sys.exit() if len(S) != N else ''
sys.exit() if not S.islower() else ''

result = 0
for I in range(len(S)):
    count = 0
    for J in range(len(unique_S)):
        if ( unique_S[J] in S[0:I] ) and ( unique_S[J] in S[I:] ):
            count += 1
        if result < count:
            result = count

print(result)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
cnt = 0
alpha = []
ans = []

for i in range(1, N):
    alpha = []
    cnt = 0
    X = S[:i]
    Y = S[i:]
    for j in X:
        if j in alpha: continue
        if Y.count(j) > 0:
            cnt += 1
            alpha.append(j)

    ans.append(cnt)

print(max(ans))

Submission status: Accepted

Solution code:
N = int(input())
s = input()
ans = 0
for i in range(N):
    left = s[:i]
    right = s[i:]
    both = set(left)&set(right)
    ans = max(ans, len(both))
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(N)))

Submission status: Accepted

Solution code:
N,S,z=int(input()),input(),0
for i in range(1,N):a,b=S[:i],S[i:];z=max(z,len([0 for j in range(97,123)if chr(j)in a and chr(j)in b]))
print(z)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
alphabet=[chr(i) for i in range(97,97+26)]
ans=0

for i in range(1,n):
    s1=s[:i]
    s2=s[i:]
    cnt=0
    for j in range(len(alphabet)):
        if s1.count(alphabet[j])>=1 and s2.count(alphabet[j])>=1:
            cnt+=1
    if cnt>ans:
        ans=cnt
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 = list(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input());
s = input();
max = 0;
set = [chr(i) for i in range(97,123)];
for i in range(1,n) :
    x = s[:i];
    y = s[i:];
    cnt = 0;
    #print(x,y,max);
    for ch in set :
        #print(ch);
        if x.find(ch) >= 0 and y.find(ch) >= 0 :
            cnt += 1;
    if cnt > max :
        max = cnt;

print(max);

Submission status: Accepted

Solution code:
def main():
    import collections

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

    cnt_s = []

    for i in range(n):
        cnt_l = collections.Counter(s[:i])
        cnt_r = collections.Counter(s[i:])
        cnt = 0
        for key in dict(collections.Counter(cnt_l)):
            if key in dict(collections.Counter(cnt_r)):
                cnt += 1
        cnt_s.append(cnt)

    print(max(cnt_s))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input

# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))

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

ans = 0

for i in range(1,N):
    Cfirst = collections.Counter(S[:i])
    Cend = collections.Counter(S[i:])
    ans = max(ans, len(Cfirst.keys() & Cend.keys()))

print(ans)

Submission status: Accepted

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

ans = 0

for i in range(n-1):
    left = s[0:i]
    right = s[i:n]

    sleft = set([x for x in left])
    sright = set([x for x in right])

    tmp = len(sleft & sright)
    if tmp > ans:
        ans = tmp

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

def f(a,b):
    a = list(set(a))
    b = list(set(b))
    cnt = 0
    for i in a:
        for j in b:
            if i == j:cnt += 1
    return cnt

if __name__ == "__main__":
    n = I()
    s = L()
    ans = 0
    for i in range(n):
        #print(s[:n-i],s[n-i:])
        ans = max(ans,f(s[:n-i],s[n-i:]))
    print(ans)

Submission status: Accepted

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



ans=0

for i in range(1,N):
    X=S[:i]
    Y=S[i:]
    setX=set(X)
    setY=set(Y)
    intersectionXY=setX & setY
    _temp=len(intersectionXY)
    if _temp>ans:
        ans=_temp
    else:
        pass
print(ans)

Submission status: Accepted

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

ans = []

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys

N = int(input())
S = input()
num = len(S)
ans, count = 0, 0
for i in range(1, num):
    a = set(S[:i])
    b = set(S[i:])
    for j in a:
        if j in b: count += 1
    ans = max(ans, count)
    count = 0
    
print(ans)

Submission status: Accepted

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

for i in range(1,n):
    cnt = 0
    x = s[:i]
    y = s[i:]

    x = set(x)
    y = set(y)
    for j in x:
        if j in y: 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:
from collections import defaultdict

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

ans = -1

n = readInt()
s = input()

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:
N = int(input())
S = input()
print(max(len(set(S[:n])&set(S[n:])) for n in range(N)))

Submission status: Accepted

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

import sys

DEBUG = False

def read(t):
    return t(sys.stdin.readline().rstrip())


def read_list(t, sep = " "):
    return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return


def main():
    n = read(int)
    s = read(str)

    ans = 0
    for i in range(1, len(s) - 1):
        x = s[0:i]
        y = s[i:]

        x_chrs = set(list(x))
        y_chrs = set(list(y))

        nr_dup_chrs = x_chrs & y_chrs
        if ans < len(nr_dup_chrs):
            ans = len(nr_dup_chrs)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = input()
    ans = 0
    for n in range(N):
        S1 = set(S[:n])
        S2 = set(S[n:])
        I = S1 & S2
        ans = max(ans, len(I))
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
mx=0
for i in range(1,n):

  m=len(set(s[:i])&set(s[i:]))
  if m>mx:
    mx=m

print(mx)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def actual(N, S):
    count = 0

    for i in range(1, N):
        left_chars = set(S[:i])
        right_chars = set(S[i:])

        and_chars = left_chars & right_chars
        unique_chars = len(and_chars)

        if unique_chars > count:
            count = unique_chars

    return count

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

print(actual(N, S))

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:]))
    ans = max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
ans = 0
count = 0
ch = []
for i in range(1,n):
    a = s[:i]
    b = s[i:]
    for j in range(i):
        if a[j] in b and a[j] not in ch:
            count += 1
        ch.append(a[j])
    ans = max(count,ans)
    count = 0
    ch = []
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):
  res = max(res, len(set(s[:i]) & set(s[i:])))
print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-06-25 16:13:15 +0900
# LastModified: 2020-06-25 16:26:22 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n = int(input())
    s = input()
    total = 0
    for i in range(1,n):
        cnt = 0
        left = s[:i]
        right = s[i:]
        left = list(set(left))
        right = list(set(right))
        for l in left:
            if l in right:
                cnt += 1
        if total < cnt:
            total = cnt
    print(total)


if __name__ == "__main__":
    main()