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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    mcount = 0
    for i in range(N):
        l = S[:i]
        r = S[i:]
        c = len(set.intersection(set(l), set(r)))
        if mcount < c:
            mcount = c
    print(mcount)
main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# ABC 098: B – Cut and Count
n = int(input())
s = input()

kinds = 0

for k in range(1, len(s) - 1):
    kinds = max(kinds, len(set(s[0:k]) & set(s[k:])))

print(kinds)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
s = input()
mx = 0
for i in range(1,N):
    ans1 = dict(Counter(s[:i]))
    ans2 = dict(Counter(s[i:]))
    count = 0
    for j in ans1:
        if j in ans2:
            count += 1
    mx = max(mx,count)
    
print(mx)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=[]
for i in range(1,n):
    l=set(s[:i])
    r=set(s[i:])
    a=0
    for li in l:
        if li in r:
            a+=1
    ans.append(a)
print(max(ans))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
def kinds(x,y):
    cnt = {}
    res = 0
    for s in x:
        if s not in cnt:cnt[s] = 1
        else:cnt[s]+=1
    c = {}
    for s in y:
        if s not in c and s in cnt:
            res+=1
            c[s] = 1
    return res
ans = 0
for i in range(n-1):
    ans = max(ans,kinds(s[:i+1],s[i+1:]))
    
    
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = input().strip()
print(max(len(set(S[:i+1]) & set(S[i+1:])) for i in range(n-1)))

Submission status: Accepted

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

for i in range(1,n):
    x = ''.join(set(s[:i]))
    y = ''.join(set(s[i:]))
    z = 0
    for j in y:
        if j in x:
            z += 1
    if z > ans:
        ans = z
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1,N):
  count = 0
  S_f = set(S[:i])
  S_l = set(S[i:])
  for s in S_f:
    if s in S_l:
      count += 1
  if res < count: res = count
    
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    se = set()
    s1 = s[0:i]
    s2 = s[i:n]
    count = 0
    for j in s1:
        for k in s2:
            if j == k and not j in se:
                se.add(j)
                count += 1
        maxV = max(count, maxV)
print(maxV)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
l = []
for i in range(n):
    l.append(s[i])
ans = 0
for m in range(n):
    sx = set(l[0 : m])
    sy = set(l[m:])
    ans = max(ans, len(sx & sy))
print(ans)

Submission status: Accepted

Solution code:
input()
s = input()
a = 0
for i in range(1,len(s)-1):
  x = set(s[:i]) & set(s[i:])
  if a< len(x):
    a = len(x)
print(a)

Submission status: Accepted

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

left = {c: 0 for c in S}
right = {c: 0 for c in S}
for c in S:
    right[c] += 1

ans = 0
common = 0
for i in range(N):
    left[S[i]] += 1
    right[S[i]] -= 1
    if left[S[i]] == 1 and right[S[i]] >= 1:
        common += 1
    elif left[S[i]] > 1 and right[S[i]] == 0:
        common -= 1

    ans = max((ans, common))

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
y=[]
for i in range(1,n):
    x=0
    m=list(dict.fromkeys(s[0:i]))
    for j in range(len(m)):
        if m[j] in s[i:n]:
            x+=1
    y.append(x)

y=sorted(y)
print(y[-1])

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

Submission status: Accepted

Solution code:
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    S = list(iss())
    ret = 0
    for n in range(N):
        ret = max(ret, len(set(S[:n]) & set(S[::-1][:-n])))
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1,n):
    x = list(set(list(s[:i])))
    y = list(set(list(s[i:])))
    c, d = 0, 0
    for j in x:
        c += y.count(j)
    for j in y:
        d += x.count(j)
    ans = max(c,d,ans)
print(ans)

Submission status: Accepted

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

ans = -1
for i in range(N-1):
    #print(S[0:i+1])
    #print(S[i+1:N])
    set_str = set(S[0:i+1]) & set(S[i+1:N])

    if ans < len(set_str):
        ans = len(set_str)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
cnt = [0]
for i in range(N):
    S1 = set(S[:i+1])
    S2 = set(S[i+1:])
    cnt.append(len(S1&S2))
max_cnt=max(cnt)
print(max_cnt)

Submission status: Accepted

Solution code:
int(input())
a=str(input())
b,c,d=set(),set(),set()
e=0
for i in range(len(a)):
    for j in range(i):
        b.add(a[j])
    for k in range(i,len(a)):
        c.add(a[k])
    for l in range(len(b)):
        b=list(b)
        if b[l] in c:
            e+=1
    d.add(e)
    b,c=set(),set()
    e=0
print(max(d))

Submission status: Accepted

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

Submission status: Accepted

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

    mx = 0
    for i in range(1,N):
        former = set(S[:i])
        latter = set(S[i:])

        cnt = 0
        for elem in former:
            if elem in latter:
                cnt += 1
        
        mx = max(cnt,mx)
    
    print(mx)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import collections

N,S = open(0).read().split()
max_d = 0
for i in range(int(N)):
  A = set(list(S[:i]))
  B = set(list(S[i:]))
  if max_d < len(A&B):
    max_d = len(A&B)
print(max_d)

Submission status: Accepted

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

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

Submission status: Accepted

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

answer=0
for i in range(1,N):
  S1=S[:i]
  S2=S[i:]
  
  s1_set=set()
  for c1 in S1:
    s1_set.add(c1)
  s2_set=set()
  for c2 in S2:
    s2_set.add(c2)
    
  cnt=0
  for c1 in s1_set:
    if c1 in s2_set:
      cnt+=1
      
  answer=max(answer,cnt)
  
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
total=0
for i in range(1,n):
    a=s[:i]
    b=s[i:]
    a=set(list(a))
    b=set(list(b))
    numa=len(a)
    numb=len(b)
    numc=len(a|b)
    shurui=numa+numb-numc
    total=max(total,shurui)
    
print(total)

Submission status: Accepted

Solution code:
import sys

def resolve():
    N = int(input())
    S = input()
    res = 0
    for i in range(1, N-1):
        cnt = 0
        left = S[:i]
        right = S[i:]
        counted = []
        for s in left:
            if s in right and s not in counted:
                counted.append(s)
                cnt += 1

        res = max(cnt, res)
    print(res)

if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import math
#import itertools
#import statistics
#import numpy as np
#import collections
n = int(input())
#a = list(map(int, input().split()))
#a = list(map(int, input().split()))
s = input()
ans = 0
for i in range(1,len(s)):
    a = s[:i]
    b = s[i:]
    count = 0
    for j in range(len(a)):
        if a[j] in b:
            flag = True
            if j > 0:
                for k in range(j):
                    if a[j]==a[k]:
                        flag=False
            if flag:
                count += 1
                #print(a[j]+" "+str(count), end="")
    #print(count)
    #print()
    if ans < count:
        ans = count

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

alpha = 'abcdefghijklmnopqrstuvwxyz'
ans = -1

for i in range(N-1):
    count = 0
    for j in range(26):
        if alpha[j] in S[0:i] and alpha[j] in S[i:N]:
            count += 1
    ans = max(ans,count)
    
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=str(input())
l=[]
cnt=0
ans=[]

for i in range(1,n):
    for j in range(i):
        if s[j] not in l:
            l.append(s[j])
    
    for j in range(i, len(s)):
        if s[j] in l:
            del l[l.index(s[j])]
            cnt+=1

    ans.append(cnt)
    
    l=[]
    cnt=0

print(max(ans))

Submission status: Accepted

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

for i in range(N):
    S1=S[:i]
    S2=S[i:]
    Count=len(set(S1) & set(S2))
    if Count>=ans:
        ans=Count

print(ans)

Submission status: Accepted

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

for i in range(1, N):
    tmp = 0
    check_char_list = set(list(S[:i]))
    for item in set(list(S[i:])):
        if item in check_char_list:
            tmp += 1
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

max_ = 0
for i in range(n):
  cand = set(s[:i]) & set(s[i:])
  if max_ < len(cand):
    max_ = len(cand)
print(max_)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
ans = 0
for k in range(1, n):
  s1 = set(c for c in s[:k])
  s2 = set(c for c in s[k:])
  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(set(s[:i+1]))
    y=list(set(s[i+1:]))
    cnt=0
    for j in range(min(len(x),len(y))):
        if i<=n//2:
            if x[j] in y:
                cnt+=1
        else:
            if y[j] in x:
                cnt+=1
    ans=max(ans,cnt)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ch = []
for i in range(0, n):
    x = s[:i+1]
    y = s[i+1:len(s)]
    a = set(x)
    b = set(y)
    c = a.intersection(b)
    ch.append(len(c))
print(max(ch))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n = int(input())
  s = list(input())
  
  mid = [len(set(s[:i]) & set(s[i:])) for i in range(0,n)]
  print(max(mid))
  
if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = -1
for i in range(N):
    S1 = S[0:i+1]
    S2 = S[i+1:]
    #print(S1, S2)
    dic_S1 = {}
    for j in S1:
        if j not in dic_S1:
            dic_S1[j] = 1
    tmp = 0
    for j in S2:
        if j in dic_S1:
            tmp += 1
            del dic_S1[j]
    ans = max(tmp, ans)
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:]))
    if len(x) >= len(y):
        ans = max(ans, len(x) - len(list(set(x)- set(y))))
    else:
        ans = max(ans, len(y) - len(list(set(y)- set(x))))


print(ans)

Submission status: Accepted

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

    for i in range(n):
        left = s[:i]
        right = s[i:]
        mx = max(mx,len(set(left) & set(right)))

    print(mx)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

for slash in range(N - 1):
    ctr = 0
    S_r_dic = dict()
    S_l = S[: slash + 1]
    S_r = S[slash + 1 :]
    for s in S_r:
        if s not in S_r_dic and s in Counter(S_l):
            ctr += 1
            S_r_dic[s] = 1
    ans = max(ctr, ans)

print(ans)

Submission status: Accepted

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

for i in range(n):
    k = set(list_S[:i])
    l = set(list_S[i:])
    m = k & l
    ans = max(ans, len(m))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

ans = 0
for i in range(n):
    dic = defaultdict(int)
    for j in range(i):
        for k in range(i, n):
            if s[j] == s[k]:
                dic[s[j]] += 1
                break
    ans = max(ans, len(dic))
    
print(ans)

Submission status: Accepted

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

for i in range(1,n):
    tmp1 = s[:i]
    tmp2 = s[i:]
    tmp1 = set(tmp1)
    tmp1 = list(tmp1)
    tmp2 = set(tmp2)
    tmp2 = list(tmp2)
    ans = 0
    for j in range(len(tmp1)):
        if tmp1[j] in tmp2:
            ans += 1
    max_v = max(max_v,ans)
    
print(max_v)

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    TF = [False] * 26
    x = s[0:i]
    y = s[i:]
    col = collections.Counter(x)
    sub = 0
    for one in y:
        if TF[ord(one) - 97] == False:
            if one in col:
                sub += 1
                TF[ord(one) - 97] = True
    ans = max(ans, sub)

print(ans)

Submission status: Accepted

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

res = 0
for i in range(1, n):
    s1 = set(s[:i])
    s2 = set(s[i: n])
    cnt = 0
    for i in s1:
        if i in s2:
            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):
    S1 = S[:i]
    S2 = S[i:]
    list_S1 = list(S1)
    list_S2 = list(S2)
    _and = set(list_S1) & set(list_S2)
    and_num = len(_and)
    if ans < and_num:
        ans = and_num

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 i in a:
        for j in b:
            if i == j:
                cnt += 1
                break
        ans=max(cnt,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = [0]*n
for i in range(n):
    l = sorted(list(set(s[:i])))
    r = sorted(list(set(s[i:])))
    for j in range(len(l)):
        for k in range(len(r)):
            if l[j] == r[k]:
                ans[i] += 1
                
print(max(ans))

Submission status: Accepted

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

ans = []
for i in range(n):
    x = s[0:i+1]
    y = s[i+1:]
    s1 = set()
    s2 = set()
    for j in x:
        s1.add(j)
    for k in y:
        s2.add(k)
    wa = s1 & s2
    ans.append(len(wa))
print(max(ans))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
a = []
for i in range(N):
    f = S[0:i+1]
    l = S[i+1:N]
    a.append( len(set(f)) + len(set(l)) - len(set(S)) )

print(max(a))

Submission status: Accepted

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

for i in range(1, len(s)):
    
    f = s[:i]
    b = s[i:]
    fset = list(set(s[:i]))
    bset = list(set(s[i:]))
    cnt = 0
   
    for j in fset:
        if bset.count(j) != 0:
            cnt += 1
    l.append(cnt)
   
print(max(l))

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:
n = int(input())
s = input()
ans = 0

for i in range(n):
    s1 = list(s[: i + 1])
    s2 = list(s[i + 1 :])
    ss = [""] * n

    count = 0
    for j in range(len(s1)):
        if s1[j] in s2 and s1[j] not in ss:
            ss[j] = s1[j]
            count = count + 1

    ans = max(ans, count)

print(ans)

Submission status: Accepted

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

ans=0
for i in range(1, N):
    s = S[:i]
    t = S[i:]
#     print(s, t)
    s1 = set(s)
    t1 = set(t)
#     print(s1, t1)
    c = collections.Counter(s1&t1)
    ans = max(ans, len(c))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(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"]
ans = 0
for i in range(1, n):
    x = s[0 : i]
    y = s[i : n]
    c = 0
    for j in alph:
        if j in x and j in y:
            c += 1
    if ans < c:
        ans = c
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    head = s[:i]
    tail = s[i:]
    cnt = 0
    for i in range(26):
        c = chr(ord('a') + i)
        if c in head and c in tail:
            cnt += 1

    ans = max(ans, cnt)

print(ans)

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
from collections import Counter
#template
#issueから始める
N = int(input())
s = list(input())
ans = -1
for i in range(N):
    lif = s[:i]
    lib = s[i:]
    cf= list(Counter(lif).keys())
    cb= list(Counter(lib).keys())
    k = len(cf) + len(cb) - len(set(cf+cb))
    ans = max(ans,k)
print(ans)

Submission status: Accepted

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

count = {i:0 for i in range(N)}
for i in range(N):
    Pre = S[:i]
    Bak = S[i:]
    Pre_set = sorted(set(Pre))
    Bak_set = sorted(set(Bak))
    for j in Pre_set:
        for k in Bak_set:
            if j == k:
                count[i] += 1
max = max(count.values())
# print(count)
print(max)

Submission status: Accepted

Solution code:

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


s2=[S.pop(0)]
s1=S[:]
MAX=0
for i in range(N-1):
    n=len(set(s2) & set(s1))
    MAX=max(MAX,n)
    s2.append(s1.pop(0))
print(MAX)

Submission status: Accepted

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

S_list = list(S)

from collections import Counter
ans = 0
for i in range(1, N ):
    fas = S_list[ : i]
    sec = S_list[i : ]
    #print(fas, sec)
    fas_dic = Counter(fas)
    sec_dic = Counter(sec)
    num = 0
    for j in fas_dic:
        if j in sec_dic:
            num += 1
    ans = max(ans, num)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
def CaC(S,cp):
    s1 = S[:cp]
    s2 = S[cp:]
    
    c1 = Counter(s1)
    c2 = Counter(s2)
    
    count = 0
    if len(c1)<len(c2):
        for key in c1:
            if key in c2:
                count+=1
    else:
        for key in c2:
            if key in c1:
                count+=1
    return count
    
N = int(input())
S = input()

Max = 0
for i in range(1,N):
    m = CaC(S,i)
    if m>Max:
        Max=m
print(Max)

Submission status: Accepted

Solution code:
#abc098_b
def compare(str1,str2):
    ans = 0
    str1=''.join(set(str1))
    str2=''.join(set(str2))
    for c in str1:
        ans += str2.count(c)

    return ans

N = int(input())
S = input()
m = 0
for i in range(N):
#    print(S[:i],S[i:])
    tmp = compare(S[:i],S[i:])
    if m < tmp:
        m=tmp
print(m)

Submission status: Accepted

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

ans = 0

for i in range(n+1):
    li1 = [0]*26
    li2 = [0]*26
    s1 = s[:i]
    s2 = s[i:]
    for j in s1:
        li1[ord(j)-97] += 1
    for j in s2:
        li2[ord(j)-97] += 1
    tmp = 0
    for j in range(26):
        if li1[j] > 0 and li2[j] > 0:
            tmp += 1
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
def CutandCount(n , s):

    ans = 0

    for i in range(1 , n + 1):
        count = 0
        for w in range(ord('a'), ord('z') + 1):
            if chr(w) in s[:i] and chr(w) in s[i:]:
                count += 1

        ans = max(ans , count)

    return ans

def main():
    n = int(input())
    s = str(input())
    print(CutandCount(n , s))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = []
if len(set(S)) == 1:
    ans.append(1)
elif len(set(S)) == len(S):
    ans.append(0)
else:
    pass
    
for i in range(N):
    if i == 0:
        pass
    elif S[i] == S[i-1]:
        pass
    else:
        S_f = S[:i+1]
        S_b = S[i+1:]
        F = set(S_b)
        B = set(S_f)
        ans.append(len(F&B))
        
print(max(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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 = max(ans,len(x&y))
print(ans)

Submission status: Accepted

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

    ans = -float("inf")
    for i in range(1, n):
        s_union = set(s[:i]) & set(s[i:])
        ans = max(ans, len(s_union))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=-1

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
dic_1 = {}
dic_2 = {}
ls = ["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"]
ans = 0
for j in range(26):
    dic_1[ls[j]] = 0
    dic_2[ls[j]] = 0
for i in range(1,n-1):
    s1 = s[:i]
    s2 = s[i:]
    tmp = 0
    for j in range(26):
        dic_1[ls[j]] = 0
        dic_2[ls[j]] = 0
    for j in range(len(s1)):
        dic_1[s1[j]] = 1
    for j in range(len(s2)):
        dic_2[s2[j]] = 1
    for j in range(26):
        tmp += dic_1[ls[j]] * dic_2[ls[j]]
    ans = max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
s = list(input())

ans = 0
for i in range(1, n):
    tmp1 = s[:i]
    tmp2 = s[i:]
    #print(tmp1, tmp2)
    #print(len(set(tmp1) & set(tmp2)))
    if len(set(tmp1) & set(tmp2)) > ans:
        ans = len(set(tmp1) & (set(tmp2)))
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:]
  ans = max(ans, len(set(a) & set(b)))
  
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]).intersection(set(S[i:]))))
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

R = Counter(list(S))
L = Counter()

ans = 0
for s in S:
    L[s] += 1
    R[s] -= 1
    ans = max(ans, len((L & R).keys()))

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
number = []
for i in range(n-1):
  before = s[:i+1]
  after = s[i+1:]
  before = list(before)
  after = list(after)
  number.append(len(set(before)&set(after)))
print(max(number))

Submission status: Accepted

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

for i in range(n-1):
    x = set(list(s[:i]))
    y = set(list(s[i:]))
    l = len(x&y)
    if l > max:
        max=l

print(max)

Submission status: Accepted

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

maxi = 0

for i in range(n-1):
    left = set(s[:i+1])
    right = set(s[i+1:])
    g = len(left & right)
    if maxi<g:
        maxi = g

print(maxi)

Submission status: Accepted

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

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

lis = list(s)

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

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
lis=list(S)
maxi=0

for i in range(1,N):
  left=set(lis[0:i])
  right=set(lis[i:])
  uni=left&right
  #print(left,right,uni)
  maxi=max(maxi,len(uni))
  
print(maxi)