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(1,N):
    s1 = S[:i]
    s2 = S[i:]
    s1 = set(s1)
    s2 = set(s2)
    ans = max(ans,len(s1.intersection(s2)))

print(ans)

Submission status: Accepted

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



separater=1
while separater<N:
    former_list = []
    latter_list = []
    former_set = {}
    latter_set = {}
    former_string=S[:separater]
    latter_string=S[separater:N]
    former_set=set(list(former_string))
    latter_set=set(list(latter_string))
    intersection=former_set & latter_set
    if now_max<len(intersection):
        now_max=len(intersection)

    #print(former_string)
    #print(latter_string)
    #print(intersection)

    separater+=1
print(now_max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
count = []
for i in range(1, N):
    z = []
    x = list(set(S[:i]))
    y = list(set(S[i:]))
    for j in x:
        z += filter(lambda str: str == j, y)
    count.append(len(z))
print(max(count))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ls = [s[k:k+1] for k in range(n)]
#print(ls)

res = 0
for i in range(1,n):
  f = list(set(ls[0:i]))
  b = list(set(ls[i:n]))
  #print(f,b)
  tmp = 0
  for j in range(len(f)):
    if b.count(f[j]) > 0:
      tmp += 1
  if tmp > res:
    res = tmp

print(res)

Submission status: Accepted

Solution code:
N = int(input())
l = [i for i in input()]
ans = 0

for i in range(len(l)):
  a = len(set(l[:i]))
  b = len(set(l[i:]))
  ans = max(ans,a+b-len(set(l)))

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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


def main():
    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:
N = int(input())
S = input()
T = list(set(S))
i = 1
ans = 0
while i < N:
  S1 = S[0:i]
  S2 = S[i:N]
  con = 0
  for j in range (len(T)):
     if S1.find(T[j]) > -1 and S2.find(T[j]) > -1:
        con += 1
  if con > ans:
    ans = con
  i += 1
print(ans)

Submission status: Accepted

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


def main():
    """Function."""
    n = int(input())
    s = str(input())

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

        l_check, r_check = set(list(left)), set(list(right))
        temp = len(l_check & r_check)
        if temp > max_val:
            max_val = temp

    print(max_val)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for i in range(n-2):
  kr=0
  for j in [chr(k) for k in range(97,97+26)]:
    if s[0:i+1].count(j)>=1 and s[i+1:n].count(j)>=1:
      kr+=1
  if ans<kr:
    ans=kr
print(ans)

Submission status: Accepted

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

output=0

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

Submission status: Accepted

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

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

print(m)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

MAX = 0
for i in range(n-1):
    x = s[:i+1]
    y = s[i+1:]
    tmp = len(set(list(x)).intersection(set(list(y))))
    MAX = max(tmp, MAX)

print(MAX)

Submission status: Accepted

Solution code:
a =int(input())
s = input()
r = 0
m = 0
for i in range(1,a):
    tmp = s[0:i]
    temp = s[i:a]
    tm = set(tmp)
    tp = set(temp)
    for i in tm:
        for j in tp:
            if i == j:
                r +=1
    if m < r:
        m = r
    r = 0
    
print(m)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import sys
import math
import fractions
def j(a):
    if a==1: print("Yes")
    else :print("No")


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

x = ip()                              #入力整数1つ
#x,y = (int(i) for i in input().split())      #入力整数横2つ
#x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#a,b,c,k = (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
l = []
for i in range(len(a)):
    l.append(a[i])
x = l
max = 0
for i in range(1,len(x)):
    c = x[:i]
    d = x[i:]
    c.sort()
    d.sort()
    c = set(c)
    d = set(d)
    num = len(c & d)
    if num > max: max = num
print(max)

Submission status: Accepted

Solution code:
import collections as cl
N = int(input())
S = input()

max_count = -1
max_index = -1
for i in range(N) :
    c1 = cl.Counter(list(S[0:i]))
    c2 = cl.Counter(list(S[i:]))
    if (len(c1.keys() & c2.keys()) > max_count) :
        max_count = len(c1.keys() & c2.keys())
        max_index = i

print(max_count)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1,n):
  a = set([j for j in s[:i]])
  b = set([k for k in s[i:]])
  c = a & b
  d = len(c)
  if d > ans:
    ans = d    
print(ans)

Submission status: Accepted

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

left = {}
right = {}

for c in S[1:]:
    if c not in right:
        right[c] = 1
    else:
        right[c] += 1

left[S[0]] = 1

ans = len(left.keys() & right.keys())
for i in range(1, N-1):
    c = S[i]
    if c not in left:
        left[c] = 1
    
    if right[c] == 1:
        del(right[c])
    else:
        right[c] -= 1

    ans = max(ans, len(left.keys() & right.keys()))
    

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

for i in range(n):
    x = set(s[:i+1])
    y = set(s[i+1:])

    z = 0
    for w in x:
        if w in y:
            z +=1
    if z > ans:
        ans = z
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
S=input()
count1=0
m=0
for i in range(1,n):
    x=S[:i]
    y=S[i:]
    x1=list(x)
    x2=set(x1)
    for i in x2:
        if y.count(i)>=1:
            count1+=1
    m=max(count1,m)
    count1=0
    x=""
    y=""
    x1=[]
    x2=[]
print(m)

Submission status: Accepted

Solution code:
a = int(input())
b = list(input())
cr = []
for i in range(1,a):
    count = 0
    br = set(b[0:i])
    for r in br:
        if r in b[i:a]:
            count += 1
    cr.append(count)
print(max(cr))

Submission status: Accepted

Solution code:
N = int(input())
SList = list(input())
max = 0
i = 0
while i < N-1:
    left = SList[0:i+1]
    right = SList[i+1:N]
    common = list(set(left)&set(right))
    l = len(common)
    if max < l:
        max=l
    i += 1

print(max)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
slist = list(S)
max = 0
i = 0
while i < N:
  left = slist[0:i+1]
  right = slist[i+1:N]
  common = list(set(left) & set(right))
  l = len(common)
  if max <= l:
    max = l
  i+=1
print(max)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
S = input()
alphabet = "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".split(",")

ans = 0
max_num = 0
for n in range(N):
    s1 = S[:n]
    s2 = S[n:]

    h1 = np.zeros(26)
    h2 = np.zeros(26)

    for i in range(len(s1)):
          h1[alphabet.index(s1[i])] = 1
    for i in range(len(s2)):
          h2[alphabet.index(s2[i])] = 1

    h = h1 * h2
    num = np.sum(h)
    if num > max_num:
          max_num = num

print(int(max_num))

Submission status: Accepted

Solution code:
_ = input()
s = input()
ans = 0
for i in range(len(s)):
  s1 = set(s[:i])
  s2 = set(s[i:])
  c = 0
  for j in s1:
    if j in s2:
      c = c + 1
    ans = max(c, ans)
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import OrderedDict 

# Function to remove all duplicates from string 
# and order does not matter 
def removeDupWithoutOrder(str): 
   
    # set() --> A Set is an unordered collection  
    #            data type that is iterable, mutable,  
    #            and has no duplicate elements. 
    # "".join() --> It joins two adjacent elements in 
    #               iterable with any symbol defined in  
    #               "" ( double quotes ) and returns a  
    #               single string 
    return "".join(set(str)) 
  
# Function to remove all duplicates from string  
# and keep the order of characters same 
def removeDupWithOrder(str): 
    s = "".join(OrderedDict.fromkeys(str)) 
    return "".join(sorted(s))

n = int(input())
s = input()
maxcnt = 0
oset = set()
for i in range(1,n):
    s1 = removeDupWithOrder(s[0:i])
    s2 = removeDupWithOrder(s[i:n])
    oset.add(s1+' '+s2)
ls = list(oset)
for x in ls:
    s1,s2 = map(str,x.split())
    cnt = 0
    for i in range(len(s1)):
        if s1[i] in s2:
            cnt += 1
    if maxcnt < cnt:
        maxcnt = cnt
print(maxcnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=int(input())
b=list(input())
c=[]
h=[]
for k in range(0,a-1):
	d=[]
	c.append(b[k])
	for i in range(k+1,a):
		d.append(b[i])
#	print(c)
#	print(d)
	e=[]
	for i in c:
		if i not in e:
			e.append(i)
#	print(e)

	f=[]
	for i in d:
		if i not in f:
			f.append(i)
#	print(f)

	g=0
	for l in range(len(e)):
		for i in range(len(f)):
			if e[l]==f[i]:
				g=g+1
	h.append(g)
#print(h)
print(max(h))

Submission status: Accepted

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

ans=0
for i in range(1,a):
#print(s[:i],s[i:])
  seta=set(s[:i])
  setb=set(s[i:])
  setc=seta & setb
  if ans < len(setc):
    ans=len(setc)
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:
def ToSet(S):
    set_S = set()
    for s in S:
        set_S.add(s)
    return set_S

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

    m = 0
    for i in range(1, n):
        set1 = ToSet(s[0:i])
        set2 = ToSet(s[i:])
        l = len(set1 & set2)
        if m < l: 
            m = l
    print(m)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
al = [chr(ord('a') + i) for i in range(26)]
ans = 0
for i in range(n - 1):
    sh = 0
    for j in al:
        if j in s[0:i+1] and j in s[i+1:n]:
            sh += 1
    if sh > ans:
        ans = sh
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = input()
L = []
for i in range(N):
  A = set(s[:i])
  B = set(s[i:])
  L.append(len(A&B))
print(max(L))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N - 1):
    count = 0
    table = {}
    for s in S[:i]:
        if s in S[i:]:
            table[s] = 1
    ans = max(ans, sum([1 for _ in table.keys()]))
print(ans)

Submission status: Accepted

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

intger2 = 0
c = []

for i in range(N):
  intger1 = 0
  str1 = list(set(S[i + 1:]))
  str2 = list(set(S[:i + 1]))
  l = len(str2)
  
  for j in range(l):
    if( str2[j] in str1):
      intger1 += 1
      
    else:
      continue
  
  if( intger2 <= intger1):
    intger2 = intger1
    c.append(intger2)
    
  else:
    continue

print(max(c))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans = 0
for i in range(1,N+1):
    ANS = []
    ANSB = []
    b = 0
    for k in range(i):
        ANS.append(S[k])
    ANS = list(set(ANS))
    for k in range(i,N):
        ANSB.append(S[k])
    ANSB = list(set(ANSB))
    for k in ANSB:
        if k in ANS:
            b += 1
    ans = max(ans,b)
print(ans)

Submission status: Accepted

Solution code:
n = int(input()) - 1
s = input()
result_list = list()
for i in range(n):
    x = s[:i+1]
    y = s[i+1:]
    comon_set_len = len(set(ii for ii in x) & set(iii for iii in y))
    result_list.append(comon_set_len)
result_list.sort(reverse = True)
print(result_list[0])

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(n):
    a = list(set(s[:i]))
    b = list(set(s[i:]))
    l_a = len(a)
    l_b = len(b)
    c = list(set(a+b))
    l_c = len(c)
    ans = max(ans,l_a+l_b-l_c)
print(ans)

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

Solution code:
class CutAndCount:
    def __init__(self, n, s):
        self.n = n
        self.s = s

    def cut_and_count(self, i):
        chars_contained_both = 0

        x, y = s[0:i], s[i:]
        for c_in_x in set(x):
            for c_in_y in set(y):
                if c_in_x == c_in_y:
                    chars_contained_both += 1

        return chars_contained_both

    def solve(self):
        max_chars = 0

        for i in range(1, self.n):
            max_chars = max(self.cut_and_count(i), max_chars)

        print(max_chars)

n, s = int(input()), input()
cac = CutAndCount(n, s)
cac.solve()

Submission status: Accepted

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

result = max(sum(c in S[i:] for c in set(S[:i])) for i in range(N))

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

left = set()
right = set()
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()

ans_L = []
for i in range(1, len(S) + 1):
    A = S[0:i + 1]
    B = S[i + 1:]
    l = set()
    for j in A:
        if j in B:
            l.add(j)
    ans_L.append(l)

ans = []
for i in ans_L:
    ans.append(len(i))
print(max(ans))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(str,input()))
l = []
for i in range(N):
  S_2 = set(S[:i]) #最初からi文字目まで
  S_3 = set(S[i:]) #i+1文字目から最後まで
  l.append(len(list(S_2 & S_3)))
print(max(l))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1, n):
    s2 = set(s[:i])
    count = 0
    for j in s2:
        if j in s[i:n]:
            count += 1
    if count > ans:
        ans = count

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):
    count = 0
    x = s[0:i+1]
    y = s[i+1:]
    cx = Counter(x)
    cy = Counter(y)
    for key, value in cx.items():
        if cy[key] > 0:
            count += 1
    ans = max(ans, count)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
P = []
for i in range(0,N-1) :
    L1 = list(S[:i+1])
    L2 = list(S[i+1:])
    L1 = list(set(L1))
    L2 = list(set(L2))
    p = 0
    for j in range(len(L1)) :
        p += L2.count(L1[j])
    P.append(p)
print(max(P))

Submission status: Accepted

Solution code:
N=int(input())
S=list(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):
    a,b = S[:i],S[i:]
    ans = max(ans, len(set(a)&set(b)))
print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
s = lc()

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

Submission status: Accepted

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

ans=[]
for sikiri in range(n):
    l=list(set(s[:sikiri]))
    r=list(set(s[sikiri:]))
    ans.append(len(l) + len(r) - len(set(l+r)))

print(max(ans))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
a=[]
b=[]
c=0
for i in range(1,n):
	a=set(s[i:])
	b=set(s[:i])
	d=a&b
	if c<len(d):
		c=len(d)
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

s1 = []
s2 = []

for i in range(n):
  s1.append([])
  s2.append([])

for i in range(n):
  for j in range(n):
    if j < i:
      s1[i].append(t[j])
    else:
      s2[i].append(t[j])

count = 0
com = []
slv = []
      
for i in range(n):
  for j in range(i):
    if s1[i][j] in s2[i] and s1[i][j] not in com:
      count += 1
      com.append(s1[i][j])
  slv.append(count)
  count = 0
  com = []
  
print(max(slv))

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    x1 = set(s[:i])
    x2 = set(s[i:])
    ans_cur = 0
    for xx1 in x1:
        if xx1 in x2:
            ans_cur +=1
    ans = max(ans, ans_cur)
print(ans)

Submission status: Accepted

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

res = 0
for i in range(N):
	X = set(list(S[:i + 1]))
	Y = set(list(S[i + 1:]))
	c = 0
	for x in X:
		if x in Y:
			c += 1
	if res < c:
		res = c
print res

Submission status: Accepted

Solution code:
n=int(input())
s=input()
same=-1
for i in range(0,n):
  left=s[:i]
  right=s[i:]
  same_tmp=0
  while len(left)>0 and len(right)>0:
    char=left[0]
    if char in right:
      same_tmp+=1
      left=left.replace(char,'')
      right=right.replace(char,'')
    else:
      left=left.replace(char,'')
    left.replace(char,'')
  if same_tmp>same:
    same=same_tmp
print(same)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ctl=[]
ctr=[]
for i in range(26):
  ctl.append(0)
  ctr.append(0)
for i in range(n):
  ctr[ord(s[i])-ord('a')]+=1
ans=0
for i in range(n-1):
  ctr[ord(s[i])-ord('a')]-=1
  ctl[ord(s[i])-ord('a')]+=1
  ans1=0
  for j in range(26):
    if(ctl[j]>0 and ctr[j]>0):
      ans1+=1
  ans=max([ans, ans1])
print(ans)

Submission status: Accepted

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

for i in range(1, len(s)-1):
  a = set(s[:i])
  b = set(s[i:])
  c = a & b
  count = max(count, len(c))
print(count)

Submission status: Accepted

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

count = 0
for i in range(1, N-1):
    A = list(set(S[:i]))
    B = list(set(S[i:]))
    C = 0
    for a in A:
        if a in B:
            C += 1
    if count < C:
        count = C

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def run(N, S):
    ret = 0
    for i in range(1, N-1):
       ret = max([ret, num_dup(N, S, i)])
    return ret


def num_dup(N, S, x):
    '''
    0 < x < N-1
    '''
    s1 = list(set(S[:x]))
    s2 = list(set(S[x:]))
    cnt = 0
    for ss in s1:
        if ss in s2:
            cnt += 1
    return cnt

def main():
    N = int(input())
    S = input()
    print(run(N, S))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

X = 0

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

	for j in range(26):
		if al[j] in a and al[j] in b:
			x += 1
	if x >= X:
		X = x

print(X)

Submission status: Accepted

Solution code:
_=input ()
s=input ()
sr=[ss for ss in s if s.count (ss) >1 ]
a=0
for i in range(len(sr)):
  a=max(len(set(sr[:i+1]) & set(sr[i+1:])),a)
print (a)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
s = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
num = []
for i in range(n):
  a = set(s[:i])
  b = set(s[i:])
  num.append(len(a.intersection(b)))
print(max(num))

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
l = [0]*n
for i in range(n):
    s1 = set(s[:i:])
    s2 = set(s[i::])
    l[i] = len(s1&s2)
print(max(l))

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
a = {}
b = {}
c = []
for i in range(n):
  a = set(s[:i+1])
  b = set(s[i+1:])
  c.append(len((a&b)))
  a.clear()
  b.clear()
print(max(c))

Submission status: Accepted

Solution code:
import collections
N = int(input())
w = input()

max = 0
i = 1
while i < N:
    left = {c for c in w[:i]}
    right = {c for c in w[i:]}
    x = len(left & right)
    if x > max:
        max = x
    i += 1
print(max)

Submission status: Accepted

Solution code:
from collections import Counter as C
n = int(input())
s = input()

res = 0
for i in range(1,n):
    a = s[:i]
    b = s[i:]
    tmp = 0
    for k in C(a):
        if k in b:
            tmp += 1
    res = max(res,tmp)
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for _ in range(1, N):
  a = set(S[:_])
  b = set(S[_:])
  n = len(a & b)
  if ans < n:
    ans = n

print(ans)

Submission status: Accepted

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

print(maxnum)

Submission status: Accepted

Solution code:
def count_(X,Y):
    dic={}
    for a in X:
        if a in Y:
            dic[a]=1
    return len(dic)

N=input()
S=input()
max_=0
for i in range(1,len(S)):
    X=S[:i]
    Y=S[i:]
    tmp = count_(X,Y)
    if tmp>max_:
        max_=tmp
print(max_)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

#Tに含まれた文字の種類を数える
def countletter(T):
    S=[]
    for t in T:
        if t not in S:
            S.append(t)
    return len(S)

ans=0

for i in range(1,N):
    A=S[:i]
    B=S[i:]
    
    ans=max(ans,countletter(A)+countletter(B)-countletter(S))
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#encoding utf-8

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

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

print(maxcha)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
list_s = list(s)
cut = 0
ans = 0
while cut < n:
    if ans < len(set(list_s[:cut]) & set(list_s[cut:])):
        ans = len(set(list_s[:cut]) & set(list_s[cut:]))
    cut += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
x = 0
for i in range(1,n):
    count=0
    for j in "abcdefghijklmnopqrstuvwxyz":
        if j in s[0:i] and j in s[i:n]:
            count += 1
        if count > x:
            x = count
print(x)

Submission status: Accepted

Solution code:
from sys import stdin

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

cut = 1
ans = 0

for i in range(cut, len(S) - 1):
    left = []
    right = []

    for c in range(len(S)):
        if (c < i):
            left.append(S[c])
        else:
            right.append(S[c])

    all_len = len(set(left) & set(right))
    if (all_len > ans):
        ans = all_len

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
m = 0
for i in range(1,n):
  count = 0
  for j in "abcdefghijklmnopqrstuvwxyz":
    if j in s[0:i] and j in s[i:n]:
      count += 1
  if count > m:
    m = count
print(m)

Submission status: Accepted

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

alphabet = list("abcdefghijklmnopqrstuvwxyz")

def clear_dict(dict, keys):    
    for char in keys:
        dict[char] = 0

max_cnt = 0
for char_n in range(1, len(s)):
    cnt_left = dict()
    cnt_right = dict()
    clear_dict(cnt_left, alphabet)
    clear_dict(cnt_right, alphabet)

    str_left = s[:char_n]
    str_right = s[char_n:]
    for char in str_left:
        cnt_left[char] += 1
    for char in str_right:
        cnt_right[char] += 1
    
    cnt = 0
    for char in alphabet:
        if cnt_left[char] != 0 and cnt_right[char] != 0:
            cnt += 1
    
    max_cnt = max(cnt, max_cnt)

print(max_cnt)

Submission status: Accepted

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

S_rev = S[::-1]
for i in range(N):
    count = 0
    for c in set(S[:i]):
        if c in S_rev[:-i]:
            count += 1
    max_cnt = max(max_cnt, count)

print(max_cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
s = input()
L = []
for i in range(N):
  A = set(s[:i])
  B = set(s[i:])
  L.append(len(A&B))
print(max(L))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
num = 0
for i in range(1, n):
    q = s[:i]
    p = s[i:]
    tmp1 = set()
    for j in q:
        tmp1.add(j)
    tmp2 = set()
    for j in p:
        tmp2.add(j)

    num = max(num, len(tmp1 & tmp2))

print(num)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
l = []
for i in range(len(S)-1):
  X = S[:i+1] 
  Y = S[i+1:]
  X_and_Y_count = len(set(X) & set(Y))
  l.append(X_and_Y_count)
  if i == len(S)-2:
    print(max(l))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
s = input()
print(max([ len(set(s[: i]).intersection(set(s[i :]))) for i in range(n + 1) ]))

Submission status: Accepted

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


def get_common_chars(first_set, latter_set):
    common_chars = set([])
    for chara in first_set:
        if chara in latter_set:
            common_chars.add(chara)
    return common_chars


max_charlen = 0
for i in range(n - 1):
    first_set = set(s[:i + 1])
    latter_set = set(s[i + 1:])
    common_charlen = len(get_common_chars(first_set, latter_set))
    if max_charlen < common_charlen:
        max_charlen = common_charlen
print(max_charlen)

Submission status: Accepted

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

res = []

for i in range(1, len(S)):
    a = S[:i]
    b = S[i:]
    c = set(a) & set(b)
    res.append(len(c))

print(max(res))

Submission status: Accepted

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