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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=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:
'''
「文字列」S を「文字列」X と 「文字列」Y に分割、X と Y 両方に含む文字種類数最大化

「文字列」S を 各位置 で 分割して、「集合」X と 「集合」Y に格納する。
「集合」X と 「集合」Y の 論理積(AND) の 要素数 を 最大化することで求めることができる。
「集合」X と 「集合」Y の 論理積(AND) は X & Y で求めることができる。
'''

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

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

print(answer)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
d=set(list(s))
def counter(s1,s2):
    count=0
    for d1 in d:
        if d1 in list(s1) and d1 in list(s2):
            count+=1 
    return count
m=0
for i in range(1,n):
    m=max(counter(s[0:i],s[i:n]),m)
print(m)

Submission status: Accepted

Solution code:
#abc096 b
n=int(input())
s=input()
ans=0
for i in range(1,n):
    left=set(s[:i])
    right=set(s[i:])
    cnt=0
    for j in left:
        if j in right:
            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):
  l = set(S[:i]); r = set(S[i:]);
  ans = max(ans, len(l & r))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1, N):
  l = list(set(S[:i])); r = list(set(S[i:]));
  cnt = 0
  for s in l:
    cnt += r.count(s)
  ans = max(ans, cnt)
print(ans)

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

max_common_char = 0
for idx in range(N):
    p, v = S[:idx], S[idx:]
    commons = len(set(list(p)) & set(list(v)))
    if max_common_char <= commons:
        max_common_char = commons
print(max_common_char)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import os
import re
import datetime

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

maxCount = 0
for i in range(1, len(S) - 1):
	sl = S[:i] #// 左文字列
	sr = S[i:] #// 右文字列
	
	setl = set(sl)
	setr = set(sr)
	setAnd = setl & setr
	
	maxCount = max(len(setAnd), maxCount)

print(maxCount)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    s = input()

    if n == 2:
        if s[0] == s[1]:
            print(1)
            exit()
        else:
            print(0)
            exit()

    ans = 0
    for i in range(1, n):
        front = set(s[0:i])
        back = set(s[i:n])

        tmp = len(front.intersection(back))
        if ans < tmp:
            ans = tmp

    print(ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    s = input()

    if n == 2:
        if s[0] == s[1]:
            print(1)
            exit()
        else:
            print(0)
            exit()

    ans = 0
    for i in range(1, n):
        front = set(s[0:i])
        back = set(s[i:n])

        tmp = 0
        for f in front:
            if f in back:
                tmp += 1
        if ans < tmp:
            ans = tmp

    print(ans)

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():

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

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

resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def count(s1,s2):
    st1,st2=set([c for c in s1]),set([c for c in s2])
    return len(st1&st2)

N=int(input())
S=input()
print(max([count(S[:i],S[i:]) for i in range(N)]))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
 
for i in range(N):
    A=S[:i]
    B=S[i:]
    sum=0
    l=[]
    for j in A:
        if (j in B) and (j not in l):
            sum+=1
            l.append(j)
    ans=max(sum,ans)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans = 0
for i in range(1,N-1):
  X = [0] * 26
  cnt = 0
  for x in range(i):
    X[ord(S[x])-ord('a')] = 1
  for y in range(i,N):
    if ( X[ord(S[y])-ord('a')] == 1 ):
      cnt += 1
      X[ord(S[y])-ord('a')] = 0
  ans = max(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
a = int(input())
c = list(input())
ans = 0
for i in range(1,a):
  b = c[:]
  h = len(set(b[:i]) & set(b[i:]))
  if h > ans:
    ans = h
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[ord(i)-97 for i in input()]
maxx=0
for i in range(n):
    st1=set(a[:i])
    st2=set(a[i:])
    maxx=max(maxx,len(st1&st2))
print(maxx)

Submission status: Accepted

Solution code:
#ABC098
n = int(input())
s = input()
l = [0] * n
for i in range(n-1):
    count = 0
    a = s[:i+1]
    b = s[i+1:]
    
    for j in set(a):
        if j in set(b):
            count += 1
    
    l[i] = count
    
print(max(l))

Submission status: Accepted

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

max_set = 0
for i in range(1, N+1):
    front = set(S[:i])
    back = set(S[i:])
    tmp_set = len(front & back)
    if tmp_set > max_set:
        max_set = tmp_set

print(max_set)

Submission status: Accepted

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

ans = 0
for i in range(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()
ans = []

for i in range(n-1):
    left = set(s[:i+1])
    right = set(s[i+1:])
    cnt = 0
    for j in left:
        if j in right:
            cnt += 1
    ans.append(cnt)

print(max(ans))

Submission status: Accepted

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

ans = [0] * (n - 1)
cnt = 0
for i in range(n - 1):
    s_1 = set(s[:i + 1])
    s_2 = list(set(s[i + 1:]))

    for j in s_1:
        if j in s_2:
            cnt += 1

    ans[i] = cnt
    cnt = 0

print(max(ans))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
res=0
for i in range(1,len(S)):
    t=set(S[:i])
    m=set(S[i:])
    res=max(res,len(t.intersection(m)))
print(res)

Submission status: Accepted

Solution code:
import string

n = int(input())
strs = input()

ans = 0

for i in range(n):
    left = strs[:i]
    right = strs[i:]
    score = 0
    for a in string.ascii_lowercase:
        if a in left and a in right:
            score += 1
    
    if score > ans:
        ans = score
    
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(n-1):
  x = s[:i+1]
  y = s[i+1:]
  count = 0
  
  for j in range(len(x)):
    if (x[j] in y) and not(x[j] in x[:j]) :
      count += 1
  
  
  if ans < count:
    ans = count
  

print(ans)

Submission status: Accepted

Solution code:
#098_B
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:
# -*- coding: utf-8 -*-

N = int(input().strip())
S = input().strip()
#-----

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

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[0:i]) & set(s[i:])))
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
S = []
for i in s:
    S.append(i
    )

ans = 0
for i in range(1, n):
    x = S[0:i]
    y = S[i:n]
    a = 0
    for j in range(len(x)):
        if x[j] in y:
            a += 1
            while x[j] in y:
                y[y.index(x[j])] = 0
    ans = max(ans, a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
for i in range(N):
    X=list(S[:i])
    Y=list(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):
    x = list(set(s[:i]))
    y = list(set(s[i:]))
    cnt = 0
    for j in range(len(x)):
        for k in range(len(y)):
            if x[j] ==  y[k]:
                cnt += 1

    ans = max(cnt ,ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    a=set(s[:i])
    b=set(s[i:])
    c=list(a & b)
    l=max(len(c),l)
print(l)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N):
    X = S[0 : i]
    Y = S[i : N]
    X_and_Y_li = list(set(X) & set(Y))
    if len(X_and_Y_li) > ans :
        ans = len(X_and_Y_li)
print(ans)

Submission status: Accepted

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

count = 0
for i in range(1, n):
    temp = set()
    for j in range(i):
        if s[j] in set(s[i:]):
            temp.add(s[j])
    count = max(len(temp), count)

print(count)

Submission status: Accepted

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

count = 0
for i in range(1, n):
    temp = set()
    for j in range(i):
        if s[j] in s[i:]:
            temp.add(s[j])
    count = max(len(temp), count)

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import string


def readints():
    return list(map(int, input().split()))


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


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

a = []

for i in range(n+1):
    a.append(len(set(s[:i]) & set(s[i:])))
print(max(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1,n):
    buf=0
    for j in range(97,97+26):
        if chr(j) in s[:i] and chr(j) in s[i:]:
            buf+=1
    if buf>ans:
        ans=buf
print(ans)

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda x: [ni() for _ in range(x)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

from collections import defaultdict, Counter

n = ni()
s = ns()

ans = 0
for i in range(n - 1):
    d = defaultdict(int)
    b = defaultdict(int)
    cnt = 0
    for j in range(i + 1):
        d[s[j]] += 1
    for j in range(i + 1, n):
        b[s[j]] += 1
    for k, j in d.items():
        if b[k] >= 1:
            cnt += 1
    ans = max(ans, cnt)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    s=STR()
    ct=0
    for i in range(n):
        seta=set(s[0:i])
        setb=set(s[i:])
        ct=max(ct,len(seta&setb))
    print(ct)
if __name__ == '__main__':
    do()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
#%%
ans= 0
for i in range(1,N):
    set1 = set()
    set2 = set()
    
    for s in S[:i]:
        set1.add(s)
    for s in S[i:]:
        set2.add(s)
    
    sets = set1 & set2
    ans = max(ans,len(list(sets)))

print(ans)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

m = 0
for i in range(1, N - 1):
    a = set(S[:i])
    b = set(S[i:])
    if m < len(a & b):
        m = len(a & b)

print(m)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
answer = 0
for i in range(1, N):
    # print(S[:i], S[i:])
    x = list(set(S[:i]))
    y = list(set(S[i:]))
    # print(x)
    # print(y)
    count = 0
    for j in range(len(x)):
        if x[j] in y:
            count += 1
    if answer <= count:
        answer = count

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

s = input()
t = 0
m = 0
for i in range(n):
    a = s[:i]
    b = s[i:]
    A = list(set(a))
    B = list(set(b))
    for i in A:
        if i in B:
            t += 1
    if m < t:
        m = t
    t = 0
print(m)

Submission status: Accepted

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

print(m)

Submission status: Accepted

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

ans = 0
for i in range(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()
maxi = 0
for i in range(n):
  left  = s[:i+1]
  right = s[i+1:]
  left = set(list(left))
  right = set(list(right))
  cnt = len(left & right)
  if maxi < cnt:
    maxi = cnt
print(maxi)

Submission status: Accepted

Solution code:
n=int(input())
s=str(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)

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
import copy
A=["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"]
L=[[0 for i in range(26)]]
for i in range(N):
    l=copy.deepcopy(L[-1])
    for j in range(26):
        if S[i]==A[j]:
            l[j]+=1
    L.append(l)
#print(L)
ans=0
for i in range(N):
    cnt=0
    for j in range(26):
        if L[i][j]>0 and L[-1][j]-L[i][j]>0:
            cnt+=1
    if ans<cnt:
        ans=cnt
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
lis = []

for i in range(1, n):
  a = set(s[:i])
  b = set(s[i:])
  count = 0
  for c in a:
    if c in b:
      count += 1
  lis.append(count)
print(max(lis))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
for i in range(1,N):
  X=set(S[i:])
  Y=set(S[:i])
  ans=len(X & Y) if ans<len(X & Y) else ans
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:]
    ans = max(ans, len(set(x).intersection(set(y))))
print(ans)

Submission status: Accepted

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

ans=0
for i in range(N):
    X=S[:i]
    Y=S[i:]
    temp=0
    for j in range(26):
        if chr(ord("a")+j) in X and chr(ord("a")+j) in Y:
            temp+=1
    ans=max(ans,temp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
input()
S = input()
X = np.zeros((26, ), dtype=np.int64)
Y = np.zeros((26, ), dtype=np.int64)

for c in S:
    Y[ord(c) - ord("a")] += 1

ans = 0
for c in S:
    X[ord(c) - ord("a")] += 1
    Y[ord(c) - ord("a")] -= 1
    ans = max(ans, (X.astype(bool) * Y.astype(bool)).sum())

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
for i in range(n):
    prev = s[:i]
    subseq = s[i:]
    inner_cnt = 0
    for j in alph:
        if j in prev and j in subseq:
            inner_cnt += 1
    if inner_cnt > cnt:
        cnt = inner_cnt
print(cnt)

Submission status: Accepted

Solution code:
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = sys.stdin.readline

def eprint(s):
    if type(s) != type('str'):
        s=str(s)

    sys.stderr.write(s+'\n')
    return

def check(s, idx):
    s1 = set(s[:idx])
    s2 = set(s[idx:])

    return len(s1 & s2)

def main():
    n = int(input())
    s = input()[:-1]

    ma = -1 * 10**9
    
    for i in range(1, n):
        c = check(s, i)
        if c > ma:
            ma = c

    print(ma)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter


def main():
    N = int(input())
    S = input()
    answer = 0
    for i in range(1, N):
        first_half = Counter(S[:i])
        second_hald = Counter(S[i:])
        answer = max(answer, len(first_half & second_hald))
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
sn = len(set(s))
r = 0
for i in range(n+1):
    t = len(set(s[:i])) + len(set(s[i:])) - sn
    r = r if r>t else t
print(r)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    S = input()
    result = []
    for i in range(N + 1):
        result.append(len(set(S[:i]) & set(S[i:])))
    print(max(result))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 15

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

l = []
for i in range(1, n):
    a = s[0:i]
    b = s[i:]
    x = []
    for j in range(len(a)):
        if a[j] in b:
            x.append(a[j])
    else:
        l.append(len(set(x)))

print(max(l))

Submission status: Accepted

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

l = []
for i in range(1, n):
    a = s[0:i]
    b = s[i:]
#    print(a,b)
    x = []
    for j in range(len(a)):
        if a[j] in b:
            x.append(a[j])
    else:
        l.append(len(set(x)))
print(max(l))

Submission status: Accepted

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

cnt = []

for l in range(1, len(S)):
    cnt.append(len(set(S[:l]) & set(S[l:])))
    
print(max(cnt))

Submission status: Accepted

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

arr = []

for i in range(1,n):
    l = set(s[:i])
    r = set(s[i:])
    arr.append(len(l & r))

print(max(arr))

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1,n):
  s1=s[:i]
  s2=s[i:]
  li1=set([s1[j] for j in range(len(s1))])
  li2=set([s2[j] for j in range(len(s2))])
  ans = max(ans,len(li1 & li2))
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[0: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):
  count = 0
  a = s[:i]
  b = s[i:]
  c = set()
  for j in a:
    if b.count(j) >= 1 and not j in c:
      count += 1
      c.add(j)
  ans = max(ans, count)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

max=0
count=0

for i in range(1,len(s)):
    str1=set(list(s[0:i]))
    str2=set(list(s[i:n]))
    for c in str1:
        if c in str2:
            count+=1
            if max<=count:
                max=count
    count=0

print(max)

Submission status: Accepted

Solution code:
import collections
N=int(input())
S=input()
count=0
for i in range(1,N):
  A=S[:i]
  B=S[i:]
  a=collections.Counter([j for j in A if j in B])
  if count<len(a):
    count=len(a)
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, n):
    x = s[:i]
    y = s[i:]
    cnt = 0
    for j in range(i):
        if(y.count(x[j])):
            y = y.replace(x[j], '')
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
moji=[0]*26
for i in range(n):
    moji[ord(s[i])-97]+=1
ans=0
for rightcut in range(n):
    k=0
    temp=moji[:]
    for i in range(rightcut):
        if temp[ord(s[i])-97]>0:
            temp[ord(s[i])-97]-=1
    for j in range(26):
        k+=1 if (temp[j]!=0 and temp[j]!=moji[j] ) else 0
    ans = k if k>ans else ans
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:]
  cnt=0
  for j in range(i):
    if y.count(x[j]):
      y=y.replace(x[j],'')
      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(1, n):
    x = set(s[0:i])
    y = set(s[i:])
    ans = max(ans, len(x & y))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N):
    X = dict()
    Y = dict()
    p = []
    count = 0
    for j in range(N):
        if j <= i:
            if S[j] in X:
                X[S[j]] += 1
            else:
                X[S[j]] = 0
        else:
            if S[j] in Y:
                Y[S[j]] += 1
            else:
                Y[S[j]] = 0
        if S[j] in X and S[j] in Y:
            if S[j] not in p:
                count += 1
                p.append(S[j])
    ans = max(ans,count)
print(ans)

Submission status: Accepted

Solution code:
import sys

n=int(input())
s=str(input())
list=[]
for i in range(1,n):
	a=s[0:i]
	b=s[i:]
	count=0
	for j in range(97,97+26):
		if (chr(j) in a)and(chr(j) in b):
			count+=1
	list.append(count)
print(max(list))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

apls = list(set(n))
count = 0

for i in range(1, s+1):
    tmp = 0
    for apl in apls:
        if n[:i].count(apl) != 0 and n[i:].count(apl) != 0:
            tmp += 1
    if count < tmp:
        count = tmp

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

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

print(m)

Submission status: Accepted

Solution code:
import collections

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

m = 0
index = 0
for i in range(N):
    a = set(S[:i])
    b = set(S[i:])
    
    common_char = a & b
    if len(common_char) > m:
        m = len(common_char)
        index = i
print(m)

Submission status: Accepted

Solution code:
import collections

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

m = 0
index = 0
for i in range(N):
    a = set(S[:i])
    b = set(S[i:])
    d = 0
    for c in a:
        if c in b:
            d += 1
    if d > m:
        m = d
        index = i
print(m)

Submission status: Accepted

Solution code:
from collections import Counter

def solve(n, s):
    c = Counter(s)
    ret, tmp = 0, 0
    d = set()
    for l in s:
        c[l] -= 1
        if c[l] == 0:
            tmp -= 1

        if l not in d:
            tmp += 1
        d.add(l)

        if ret < tmp:
            ret = tmp
    return ret

_n = int(input())
_s = input()
print(solve(_n, _s))

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 solve():
    N = int(input())
    S = input()
    max_spieces = 0
    for i in range(1, N):
        pre = set(S[:i])
        post = set(S[i:])
        intersection_num = len(pre&post)
        if intersection_num > max_spieces:
            max_spieces = intersection_num
            
    print(max_spieces)
    
solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(input())
ans = 0
for i in range(n):
  l1 = l[i+1:]
  
  count = set()
  for j in range(i+1):
    if l[j] in l1:
      count.add(l[j])
  ans = max(ans,len(count))
  
print(ans)

Submission status: Accepted

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

mx=0

for i in range(1,N):
    str1=S[i:]
    str2=S[:i]

    same=[]

    for c1 in str1:
        for c2 in str2:
            if c1==c2:
                same.append(c1)

    if mx < len(set(same)):
        mx= len(set(same))

print(mx)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
s = input()
ans = 0
for i in range(1,n):
    num = 0
    for j in range(i):
        if s[j] not in s[:j] and s[j] in s[i:]: num += 1
    if num > ans: ans = num
print(ans)