Problem:


Score : 200 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters.
We will cut this string at one position into two strings X and Y.
Here, we would like to maximize the number of different letters contained in both X and Y.
Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.

Constraints

2 \leq N \leq 100

|S| = N

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the largest possible number of different letters contained in both X and Y.

Sample Input 1

6
aabbca

Sample Output 1

2

If we cut the string between the third and fourth letters into X = aab and Y = bca, the letters contained in both X and Y are a and b.
There will never be three or more different letters contained in both X and Y, so the answer is 2.

Sample Input 2

10
aaaaaaaaaa

Sample Output 2

1

However we divide S, only a will be contained in both X and Y.

Sample Input 3

45
tgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir

Sample Output 3

9



Sample input:
6
aabbca


Sample output:
2

Submission status: Accepted

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

ans=0
for i in range(n-1):
    l=[left for left in s[:i+1]]
    r=[right for right in s[i+1:]]
    st = set(l) & set(r)
    ans = max(len(st),ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
N = int(input())
S = input()
LAlphabet = [False] * 26
L = []
for s in S:
    LAlphabet[ord(s)-97] = True
    L.append(copy.deepcopy(LAlphabet))

RAlphabet = [False] * 26
R = []
for s in reversed(S):
    RAlphabet[ord(s)-97] = True
    R.append(copy.deepcopy(RAlphabet))
R.reverse()
ans = 0

print(max([sum([L[l][t] and R[l+1][t] for t in range(26)]) for l in range(N-1)]))

Submission status: Accepted

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


ans = 0
for i in range(n-1):
    x = s[:i+1];y = s[i+1:]
    xs = set();ys = set()
    for v in x:
        xs.add(v)
    for v in y:
        ys.add(v)
    ans = max(len(xs & ys),ans)
print(ans)

Submission status: Accepted

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

for i in range(1,N):
  A = 0
  X = S[:i]
  Y = S[i:]
  for j in C:
    if j in X and j in Y:
      A += 1
  ans = max(ans,A)
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(1,N):
    left = S[:i]
    right = S[i:]
    tmp = 0
    for alpha in 'qwertyuiopasdfghjklzxcvbnm':
        if alpha in left and alpha in right:
            tmp += 1
    ans = max(ans,tmp)
    
print(ans)

Submission status: Accepted

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

score = 0
for i in range(n):
    left = s[:i]
    right = s[i:]
    left_c = list(collections.Counter(left).keys())
    right_c = list(collections.Counter(right).keys())
    tmp_score = 0
    for c in left_c:
        if c in right_c:
            tmp_score += 1
    if score < tmp_score:
        score = tmp_score
print(score)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1, n):
    tmp = 0
    for a in 'abcdefghijklmnopqrstuvwxyz':
        if a in s[:i] and a in s[i:]:
            tmp += 1
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

print(res)

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
cnt=0
maxcnt=0
for i in range(N):
    if i==0:
        if S[0] in S[1:N]:
            cnt+=1
        if maxcnt<cnt:
            maxcnt=cnt
    elif i == N-1:
        if S[N-1] in S[0:N]:
            cnt-=1
    else:
        if S[i] not in S[0:i] and S[i] in S[i+1:N]:
            cnt+=1
            if maxcnt<cnt:
                maxcnt=cnt
        elif S[i] in S[0:i] and S[i] not in S[i+1:N]:
            cnt-=1
        else:
            pass
print(maxcnt)

Submission status: Accepted

Solution code:
from string import ascii_lowercase 

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

  ans = 0

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

    letters = []
    for c in ascii_lowercase:
      if(c in left):
        letters.append(c)

    count = 0
    for c in letters:
      if c in right:
        count += 1

    ans = max(ans, count)

  print(ans)

if __name__ == "__main__":
  main()

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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


for i in range(n):
    count = 0
    cnt1 = Counter(s[0:i])
    cnt2 = Counter(s[i:n])
    l = []
    for k, j in cnt1.items():
        l.append(k)
    for k, j in cnt2.items():
        l.append(k)
    cnt3 = Counter(l)
    
    for k, j in cnt3.items():
        if j == 2:
            count += 1
    ans = max(ans, count)

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
s = input()
l=1
tmp = 0
while(l<n):
    dd = set()
    dd2 = set()
    for i in range(0, l):
        dd.add(s[i])
    for i in range(l, n):
        dd2.add(s[i])
    tmp = max(tmp, len(dd&dd2))

    l+=1
print(tmp)

Submission status: Accepted

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

    acc = []
    t = [0] * 26
    for c in s:
        i = ord(c) - ord('a')
        t[i] += 1
        acc.append(t.copy())

    ans = 0
    for i in range(N - 1):
        left = acc[i]
        right = [cn - ci for ci, cn in zip(acc[i], acc[N - 1])]
        cnt = 0
        for ci in range(26):
            if left[ci] and right[ci]:
                cnt += 1
            ans = max(ans, cnt)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
for i in range(N):
  S_1 = set(S[:i+1])
  S_2 = set(S[i+1:])
  count = 0
  for s in S_1:
    if s in S_2:
      count += 1
  ans = max(ans, count)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
sset = len(set(s))
ans = 0
for i in range(len(s)):
    x = set(s[:i])
    y = set(s[i:])
    ans = max(ans, len(x) + len(y) -sset)
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:])
  a = len(x&y)
  if ans < a:
    ans = a
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

max_c = 0
for i in range(1, N-1):
    S_f = S[:i]
    S_l = S[i:]
    count = 0
    memo = []
    for f in S_f:
        if f not in memo and f in S_l:
            count += 1
            memo.append(f)
    if count > max_c:
        max_c = count
print(max_c)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(N):
  cnt = 0
  for _ in list(set(S[:i])):
    if S[i:].count(_) > 0:
      cnt += 1
  if ans < cnt:
    ans = cnt
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
moji=str(input())
cnt=0
for i in range(n):
  count = 0
  temp=moji[:i+1]
  lst=[]
  for j in range(i+1):
    if temp[j] in moji[i+1:] and temp[j] not in lst:
      count+=1
      lst.append(temp[j])
  if count > cnt:
    cnt=count
print(cnt)

Submission status: Accepted

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
N = I()
S = S()
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 collections,sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
N = I()
S = S()
ans = 0
for i in range(N):
    set_top = set()
    set_bottom = set()
    for s in collections.Counter(S[:i]):
        set_top.add(s)
    for s in collections.Counter(S[i:]):
        set_bottom.add(s)
    ans = max(ans,len(set_top&set_bottom))
print(ans)

Submission status: Accepted

Solution code:
import collections,sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
N = I()
S = S()
ans = 0
for i in range(1,N-1):
    set_top = set()
    set_bottom = set()
    for s in collections.Counter(S[:i]):
        set_top.add(s)
    for s in collections.Counter(S[i:]):
        set_bottom.add(s)
    ans = max(ans,len(set_top&set_bottom))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = input()
ans = 0
for i in range(N):
  now = 0
  a = A[0:i+1]
  b = A[i+1:N]
  k = list(set(list(a)))
  l = list(set(list(b)))
  if min(len(k),len(l)) == len(k):
    for j in range(len(k)):
      if k[j] in l:
        now += 1
    if now > ans:
      ans = now
  else:
    for j in range(len(l)):
      if l[j] in k:
        now += 1
    if now > ans:
      ans = now
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
 
for i in range(1, n):
    a=s[:i]
    b=s[i:]
    dic=[]
    dic2=[]
    for j in range(len(a)):
        if a[j] not in dic:
            dic.append(a[j])
    for k in range(len(b)):
        if b[k] not in dic2:
            dic2.append(b[k])
    cnt=0
    for i in range(len(dic)):
        if dic[i] in dic2:
            cnt+=1
    ans=max(ans, cnt)
    
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


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


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
s = input()
maxx = 0
for i in range(n-1):
    x = s[:i+1]
    y = s[i+1:]
    ans = set(x) & set(y)
    ansans = len(ans)
    maxx = max(maxx, ansans)
print(maxx)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = list(input())
res = 0
for i in range(1,n):
    x = s[:i]
    y = s[i:]
    sx = set(x)
    sy = set(y)
    cnt = 0
    for i in list(sx):
        if i in sy:
            cnt += 1
    res = max(res, cnt)
print(res)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
for i in range(1,N):
    T1=S[:i]
    T2=S[i:]
    sub=0
    L=set(T1)
    for t in set(T2):
        if t in L:
            sub+=1
    ans=max(ans, sub)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1,len(s)-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 - 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 = str(input())

def judge(s,t):
    s = set(s)
    t = set(t)
    x = s & t
    return(len(x))


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

Submission status: Accepted

Solution code:
N = int(input())
S = input().strip()
cmax = 0
for i in range(N-1):
    S1 = S[:i+1]
    S2 = S[i+1:]
    hist = {chr(i):0 for i in range(97,123)}
    cnt = 0
    for j in range(i+1):
        a = S1[j]
        if hist[a]==1:continue
        hist[a] = 1
        flag = 0
        for k in range(len(S2)):
            if S2[k]==a:
                flag = 1
                break
        if flag==1:
            cnt += 1
    cmax = max(cmax,cnt)
print(cmax)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
u=[]
alphasm=[chr(i) for i in range(97, 97+26)]
s=input().rstrip()
for i in range(n):
    s1=list(s[0:i])
    s2=list(s[i:n])
    count=0
    for x in alphasm:
        if (x in s1) and (x in s2):
            count+=1
    u.append(count)
print(max(u))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(N):
    X = S[:i]
    Y = S[i:]
    cnt = 0
    for j in range(97,123):
        index = chr(j)
        if X.find(index) != -1 and Y.find(index) != -1:
            cnt += 1
        ans = max(ans,cnt)
print(ans)

Submission status: Accepted

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

max_char = 0

for i in range(1, n):
    s1 = set(s[0:i])
    s2 = set(s[i:])
    num = len(s1 & s2)
    if num > max_char:
        max_char = num
print(max_char)

Submission status: Accepted

Solution code:
from sys import stdin
def check(s,t):
    d=dict()
    for c in s:
        if c not in d:
            d[c]=1

    res=0
    for c in t:
        if c in d:
            if d[c]==1:
                res+=1
                d[c]=0

    return res

def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    S=readline().strip()

    res=0
    for i in range(1,N):
        X=S[:i]
        Y=S[i:]
        res=max(res,check(X,Y))

    print(res)
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1, n):
    f1 = s[:i]
    f2 = s[i:]
    f1 = list(set(f1))
    cnt = 0

    for j in range(len(f1)):
        if f1[j] in f2:
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
eng = list("abcdefghijklmnopqrstuvwxyz")
ans = 0
for i in range(1, n):
  count = 0
  t = list(s[:i:])
  u = list(s[i::])
  for j in range(26):
    if (eng[j] in t) and (eng[j] in u) :
      count += 1
  ans = max(count, ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
left = set()
right = set(S)
for s in S:
    left.add(s)
    C[s] -= 1
    if not C[s]:
        right -= {s}
    ans = max(ans, len(left & right))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, heapq, bisect, math, fractions
from collections import deque

N = int(input())
S = list(sys.stdin.readline())

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

print(res)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = list(read().rstrip().decode())
ans = 0
for i in range(n):
    ans = max(ans, len(set(s[:i]) & set(s[i:])))
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
S = input()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = 0
    for i in range(n):
        X = set(s[:i])
        Y = set(s[i:])
        cnt = 0
        for x in X:
            if x in Y:
                cnt += 1
        res = max(res, cnt)

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

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

ans = 0
for i in range(N):
    A = set(S[:i])
    B = set(S[i:])
    tmp = 0
    for a in A:
        if a in B:
            tmp += 1
    ans = max(ans, tmp)

print (ans)

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:])
  cnt = 0
  for j in x:
    if j in y: cnt += 1
    if ans < cnt: ans = cnt
print(ans)

Submission status: Accepted

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

    ans = 0
    for i in range(n):
        x = set()
        for j in range(i):
            x.add(s[j])
        y = set()
        for j in range(i, n):
            if s[j] in x:
                y.add(s[j])
        ans = max(ans, len(y))

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

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

Submission status: Accepted

Solution code:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
N = ri()
S = [i for i in rs()]
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):
    dum = []
    check = 0
    for j in s[0:i]:
        dum.append(j)
    dum = set(dum)
    #print(s[0:i])
    for k in dum:
        if s[i:n].count(k) >= 1:
            check += 1
    ans = max(check,ans)
print(ans)

Submission status: Accepted

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

maxMatch = 0

for x in range(N):
    first_half = set(S[:x])
    second_half = set(S[x:])
    intersection = first_half & second_half
    maxMatch = max(maxMatch, len(intersection))
print(maxMatch)

Submission status: Accepted

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

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

Submission status: Accepted

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

    
print(ans)

Submission status: Accepted

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

for i in range(1, n):
    a=s[:i]
    b=s[i:]
    dic=[]
    dic2=[]
    for j in range(len(a)):
        if a[j] not in dic:
            dic.append(a[j])
    for k in range(len(b)):
        if b[k] not in dic2:
            dic2.append(b[k])

    l=min(len(dic), len(dic2))
    cnt=0
    if l==len(dic):
        for j in range(len(dic)):
            if dic[j] in dic2:
                cnt+=1
    else:
        for k in range(len(dic2)):
            if dic2[k] in dic:
                cnt+=1
    
    ans=max(ans, cnt)
    
print(ans)

Submission status: Accepted

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

c = 0
for i in range(N):
    l = set(S[:i])
    r = set(S[i:])
    dp = len(l&r)
    if c < dp:
        c = dp

print(c)

Submission status: Accepted

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

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 s[i:]:
            cnt += 1
    ans = max(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
v = [0] * n
for c in range(ord('a'), ord('z') + 1):
  p = -1
  for i in range(n):
    if ord(s[i]) == c:
      if p >= 0:
        v[i] -= 1
        v[p] += 1
      p = i
ans = 0
vsum = 0
for i in v:
  vsum += i
  ans = max(ans, vsum)
print(ans)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

def resolve():
    n = int(input())
    s = list(input())

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

        tmp_ans = len(set(left) & set(right))

        # if ans < tmp_ans:
        #     ans = tmp_ans
        ans = max(ans, tmp_ans)

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """6
aabbca"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """10
aaaaaaaaaa"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """45
tgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir"""
        output = """9"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

def resolve():
    n = int(input())
    s = list(input())

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

        tmp_ans = len(set(left) & set(right))

        if ans < tmp_ans:
            ans = tmp_ans

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """6
aabbca"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """10
aaaaaaaaaa"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """45
tgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir"""
        output = """9"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

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

res = 0
for i in range(N):
    s1 = S[:i]
    s2 = S[i:]
    ss1, ss2 = set(s1), set(s2)
    s = ss1&ss2
    val = len(s)
    if res < val:
        res = val

print(res)

Submission status: Accepted

Solution code:

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

print(ans)