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

Submission status: Accepted

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


def solve(N: int, S: str):
    h = [set()]
    for c in S:
        h.append(h[-1] | set(c))
    t = [set()]
    for c in reversed(S):
        t.append(t[-1] | set(c))
    return max(len(hh & tt) for hh, tt in zip(h, reversed(t)))

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    print(solve(N, S))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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


def solve(N: int, S: str):
    h = [frozenset()]
    for c in S:
        h.append(h[-1] | frozenset(c))
    t = [frozenset()]
    for c in reversed(S):
        t.append(t[-1] | frozenset(c))
    return max(len(hh & tt) for hh, tt in zip(h, reversed(t)))

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    print(solve(N, S))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    left = list(s[:i])
    right = list(s[i:])
    
    t = 0
    for j in set(left):
        if j in right:
            t += 1
    
        ans = max(ans, t)
        
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

n = int(input())
s = input()
ans = 0
for i in range(1,n):
    cnt = 0
    c1 = Counter(s[:i])
    c2 = Counter(s[i:])
    for x in c1.keys():
        if c2[x]: cnt+=1
    ans = max(cnt, ans)
print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = input()
ans = 0
for i in range(1,n):
    cnt = 0
    c1 = collections.Counter(s[:i])
    c2 = collections.Counter(s[i:])
    for x in c1.keys():
        if c2[x]: 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,len(s)):
    ans = max(ans, len(set(s[:i])&set(s[i:])))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1,len(s)):
    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()
M = 0
for i in range(1, n):
    cnt = 0
    s1 = s[:i]
    s2 = s[i:]
    t = {}
    for x in s1:
        if x not in t: t[x]=1
    for k in s2:
        if k not in t: t[k]=0
        if t[k] == 1: t[k]+=1
    for x, y in t.items():
        if y==2: cnt+=1
    M = max(cnt, M)
print(M)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
M = 0
for i in range(1, n):
    cnt = 0
    s1 = s[0:i]
    s2 = s[i:len(s)]
    t = {}
    for x in s1:
        if x not in t: t[x]=1
    for k in s2:
        if k not in t: t[k]=0
        if t[k] == 1: t[k]+=1
    for x, y in t.items():
        if y==2: cnt+=1
    M = max(cnt, M)
print(M)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
for i in range(N+1):
  bns=0
  dp=[0]*26
  bp=[0]*26
  a=S[:i]
  b=S[i:]
  a=sorted(a)
  b=sorted(b)
  for j in range(len(a)):
    dp[ord(a[j])-97]+=1
  for k in range(len(b)):
    bp[ord(b[k])-97]+=1
  for l in range(26):
    if min(dp[l],bp[l])>0:
      bns+=1
  ans=max(ans,bns)
print(ans)

Submission status: Accepted

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

ans = [None] * (n-1)

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

  ans[i-1] = len(set(b))-len((set(b)-set(a)))

ans.sort(reverse = True)

print(ans[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
#n = 45
#s = "tgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir"
ans = 0
alphabet = [chr(i) for i in range(97, 97+26)]
def count(i):
    num = 0
    a=list(set(list(s[:i])))
    b=list(set(list(s[i:])))
    for i in alphabet:
        if (i in a) & (i in b):
            num += 1
    return num
for j in range(1,len(s)-1):
    if ans < count(j): ans = count(j)
print(ans)

Submission status: Accepted

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

for i in range(1,n):
    count = 0
    s1 = s[:i]
    s2 = s[i:]
    for i in t:
        if s1.count(i) > 0 and s2.count(i) > 0:
            count += 1
            
    if ans < count:
        ans = count
print(ans)

Submission status: Accepted

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

from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

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

c = Counter(S)

mcount = len(c)

mct = 0
for i in range(N):
    ta = Counter(S[:i])
    tb = Counter(S[i:])
    
    ct = 0
    for st in ta:
        if tb[st]:
           ct += 1
           
    mct = max(mct, ct)
print(mct)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

def count_alphabets(s):
    alphabets = list("abcdefghijklmnopqrstuvwxyz")
    cnt = dict(zip(alphabets, [0 for _ in range(26)]))
    for c in s: cnt[c] += 1
    return cnt

ans = 0
for div in range(1, N):
    left_str, right_str = S[:div], S[div:]
    left_cnt, right_cnt = count_alphabets(left_str), count_alphabets(right_str)

    count = 0
    alphabets = list("abcdefghijklmnopqrstuvwxyz")
    for c in alphabets:
        if left_cnt[c] > 0 and right_cnt[c] > 0:
            count += 1
    ans = max(ans, count)
print(ans)

Submission status: Accepted

Solution code:
def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N = ii()
    S = input()
    m = max(len(set(S[:i]) & set(S[i:])) for i in range(N))
    print(m)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = -1*float('inf')
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()

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

print(res)

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
s=input()
tmp=Counter(s)
ans=0
for i in range(n+1):
    l,r=s[:i],s[i:]
    dic={}
    tmp=Counter(r)
    for j in range(i):
        if tmp[l[j]]>0:
            dic[l[j]]=1
    ans=max(len(dic),ans)
    # print(l,r)
print(ans)

Submission status: Accepted

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

# check
max = 0
for i in range(N):
    A, B = set(S[:i + 1]), set(S[i + 1:])
    union_cnt = len(A & B)
    
    if max < union_cnt:
        max = union_cnt

print(max)

Submission status: Accepted

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

ans = 0
for i in range(1,N-1):
    S1,S2 = set(S[:i]),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(1,n-1):
    tmp=0
    sa=list(s[:i])
    sa=set(sa)
    sa=list(sa)
    sb=list(s[i:])
    for j in range(len(sa)):
        if sa[j] in sb:
            tmp+=1
    if tmp>ans:
        ans=tmp
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
for i in range(1,N):
  temp=0
  check1=set(S[:i])
  check2=set(S[i:])
  for s in check1:
    if s in check2:
      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, b = s[:i], s[i:]
    a = set(a)
    b = set(b)
    ans = max(ans, len(a & b))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N=II()
S=input()
s1 = set()
s2 = set()
res = 0
for i in range(1, N):
    for c in S[:i]:
        s1.add(c)
    for c in S[i:]:
        s2.add(c)
    res = max(len(s1.intersection(s2)), res)
    s1.clear()
    s2.clear()
print(res)

Submission status: Accepted

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

ans = 0
for div in range(n):
    left = set(s[:div])
    right = set(s[div:])
    tmp = 0
    for i in left:
        if i in right:
           tmp += 1
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(1,N):
    dicl = {}
    dicr = {}
    for j in range(i):
        dicl[S[j]] = j
    for j in range(i,N):
        if(S[j] in dicl.keys()):
            dicr[S[j]] = j
    if len(dicr.keys()) > max:
        max = len(dicr.keys())
print(max)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

if __name__ == '__main__':
    n =int(input())
    s=input()
    max =0
    for i in range(n):
        a= set(s[:i])
        b= set(s[i:])
        count = len(a &b)
        if max <count:
            max=count

    print(max)

Submission status: Accepted

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

l=[]

for i in range(n):
    h=set(s[0:i])
    t=set(s[i:])
    x=len(h&t)
    l.append(x)

print(max(l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    temp = 0
    X, Y = S[:i], S[i:]
    for c in set(S):
        if c in X and c in Y:
            temp += 1
    ans = max(ans, temp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

if __name__ == "__main__":
    N = int(input())
    S = input()
    unique_nums = [-1] * N
    for i in range(N):
        left = S[:i]
        # print(left)
        right = S[i:]
        # print(right)
        unique_nums[i] = len(set(left) & set(right))
    print(max(unique_nums))

Submission status: Accepted

Solution code:
import collections

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


def count_variation(s):
    c = collections.Counter(s)
    return c.keys()


ans = []

for i in range(1, N):
    s1 = S[:i]
    s2 = S[i:]
    mojis = len(count_variation(s1) & count_variation(s2))
    ans.append(mojis)

print(max(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
find = []
for i in range(1, n):
    left  = s[:i]
    right = s[i:]
    cnt = 0
    find = []
    for c in left:
        if c in right and c not in find:
            cnt += 1
            find.append(c)
    if cnt > ans:
        ans = cnt
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1, n):
    tmp = 0
    dic = {}
    sl = list(set(s[:i]))
    sr = list(set(s[i:]))
    # print(sl, sr)

    for c in sl:
        if c not in dic:
            dic[c] = 0

    for c in sr:
        if c in dic:
            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):
    S1 = S[:i+1]
    S2 = S[i+1:]
#    print(S1, S2)
    ans = max(ans, len(set(list(S1)) & set(list(S2))))
print(ans)

Submission status: Accepted

Solution code:
def count(a,b):
  c = 0
  for i in set(a):
    if i in b:
      c += 1
  return c
n = int(input())
s = input()
lmax = 0
i = n-1
while i>=0:
  left = s[:i]
  right = s[i:]
  c = count(left,right)
  lmax = max(lmax,c)
  i-=1
print(lmax)

Submission status: Accepted

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

ANS = []
for i in range(n):
  p = 0
  A = set(s[0:i])
  B = set(s[i:n+1])
  for j in A:
    if j in B:
      p += 1
  ANS.append(p)
  
  
print(max(ANS))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
maxCommon = 0
for i in range(1, N):
    count = 0
    for j in range(ord('a'), ord('z')+1):
        left = False
        right = False
        for k in range(i):
            if ord(S[k]) == j:
                left = True
        for k in range(N - 1, i - 1, -1):
            if ord(S[k]) == j:
                right = True
        if right and left:
            count += 1
    if maxCommon < count:
        maxCommon = count
print(maxCommon)

Submission status: Accepted

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

Submission status: Accepted

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

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

maxx = 0

for i in range(N - 1):
    left = s[: i + 1]
    right = s[i + 1 :]
    
    and_LR = set(left) & set(right)
    cnt = len(and_LR)
    
    maxx = max(maxx, cnt)
    
print(maxx)

Submission status: Accepted

Solution code:
import collections

N = int(input())
s = input()

maxx = 0

for i in range(N - 1):
    left = s[: i + 1]
    right = s[i + 1 :]
    
    CNT_left = collections.Counter(left)
    CNT_right = collections.Counter(right)
    
    cnt = 0
    
    for k in CNT_left.keys():
        num = CNT_right[k]
        
        if (num >= 1):
            cnt += 1
    
    maxx = max(maxx, cnt)
    
print(maxx)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
l = 0
for i in range(1,n-1):
  p = list(set(s[:i]))
  q = list(set(s[i:]))
  pq = set(p) & set(q)
  k = len(pq)
  if k>l:
    l=k
print(l)

Submission status: Accepted

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

abc = 'abcdefghijklmnopqrstuvwxyz'

ans = 0
for i in range(1, N):
  abcdict = {c:0 for c in abc}
  A = S[:i]
  B = S[i:]
  for ai in A:
    if ai in B:
      abcdict[ai] = 1
  now = 0
  for c in abc:
    now += abcdict[c]
  ans = max(ans, now)
  
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = []
for i in range(1, n):
  x = set()
  y = set()
  for e in s[:i]:
    x.add(e)
  for e in s[i:]:
    y.add(e)
  ans.append(len(list(x & y)))
print(max(ans))

Submission status: Accepted

Solution code:
n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
s=list(input())
mx=0
for i in range(1,n):
    l1=s[0:i];l2=s[i:n]
    mx=max(mx,len(set(l1) & set(l2)))

print(mx)

Submission status: Accepted

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

re_ans = 0
for i in range(1, n):
    ans = 0
    lis = []
    t = s[:i]
    u = s[i:]
    for j in range(len(t)):
        if t[j] in u and t[j] not in lis:
            ans += 1
            lis.append(t[j])
        if re_ans < ans:
            re_ans = ans
print(re_ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
l = 0
for i in range(1,n-1):
    p = list(set(s[:i]))
    q = list(set(s[i:]))
    pq = set(p) & set(q)
    k = len(pq)
    if k > l:
        l = k
print(l)

Submission status: Accepted

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

for i in range(N-1):
    Sl = set(S[:i+1])
    Sr = set(S[i+1:])

    counter = 0
    for j in Sl:
        if j in Sr:
            counter += 1
    maxy = max(maxy, counter)
    
print(maxy)

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
s=[_ for _ in input()]


mx=0

for i in range(n):
  sr =s[:i]
  sl = s[i:]
  r=set(sr)
  l=set(sl)

  nn=len(r & l)
  mx = max(nn,mx)

print(mx)

Submission status: Accepted

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

ans = 0
for i in range(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 = list(input())
ans = 0
for i in range(1, n):
    x = s[:i]
    y = s[i:]
    temp = 0
    for ch in range(26):
        if chr(ch + 97) in x and chr(ch + 97) 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):
  ans=max(ans,len(set(list(s[0:i]))&set(list(s[i:n]))))
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
alp='abcdefghijklmnopqrstuvwxyz'

b=[]
for i in range(n):
  count=0
  s1=s[:i]
  s2=s[i:]
  for j in alp:
    if s1.count(j)*s2.count(j):
      count+=1
  b.append(count)
print(max(b))

Submission status: Accepted

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

max_c = 0

for i in range(1, n):
    part1 = s[:i]
    part2 = s[i:]

    intersection = set(part1) & set(part2)

    count_intersection = len(intersection)

    if count_intersection >= max_c:
        max_c = count_intersection

print(max_c)

Submission status: Accepted

Solution code:
N = int(input())
S = [i for i in 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 = list(s)
m = 0
for i in range(n - 1):
    l1 = l[:i+1]
    l2 = l[i+1:]
    l1 = list(set(l1))
    l2 = list(set(l2))
    l1.sort()
    l2.sort()
    x = 0
    for j in range(len(l1)):
        if l1[j] in l2:
            x += 1
    if x > m:
        m = x
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

s = list(s)
ans = 0
count = 0

for a in range(1, n):
    l1 = list(set(s[:a]))
    l2 = set(s[a:])

    length1 = len(l1)

    for x in range(length1):
        if l1[x] in l2:
            count += 1
    ans = max(ans, count)
    count = 0

print(ans)

Submission status: Accepted

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

s = list(s)
ans = 0
count = 0

for a in range(1, n):
    l1 = list(set(s[:a]))
    l2 = list(set(s[a:]))

    length1 = len(l1)

    for x in range(length1):
        if l1[x] in l2:
            count += 1
    ans = max(ans, count)
    count = 0

print(ans)

Submission status: Accepted

Solution code:
# For taking integer inputs.
import math


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


def coutDiffL(a1, a2):
    a1 = set(a1)
    a2 = set(a2)
    a3 = a1.intersection(a2)
    return len(a3)


n = inp()

s = input()
res = 0
for i in range(1, n-1):
    m1 = coutDiffL(s[:i], s[i:])
    if m1 > res:
        res = m1


print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
ans_index=0
for i in range(n):
  ans_index=0
  Left=s[0:i]
  Right=s[i:]
  #print(Left)
  #print(Right)
  if (Left.count("a")>0 and Right.count("a")>0):
    ans_index+=1
  if (Left.count("b")>0 and Right.count("b")>0):
    ans_index+=1
  if (Left.count("c")>0 and Right.count("c")>0):
    ans_index+=1
  if (Left.count("d")>0 and Right.count("d")>0):
    ans_index+=1
  if (Left.count("e")>0 and Right.count("e")>0):
    ans_index+=1
  if (Left.count("f")>0 and Right.count("f")>0):
    ans_index+=1
  if (Left.count("g")>0 and Right.count("g")>0):
    ans_index+=1
  if (Left.count("h")>0 and Right.count("h")>0):
    ans_index+=1
  if (Left.count("i")>0 and Right.count("i")>0):
    ans_index+=1
  if (Left.count("j")>0 and Right.count("j")>0):
    ans_index+=1
  if (Left.count("k")>0 and Right.count("k")>0):
    ans_index+=1
  if (Left.count("l")>0 and Right.count("l")>0):
    ans_index+=1
  if (Left.count("m")>0 and Right.count("m")>0):
    ans_index+=1
  if (Left.count("n")>0 and Right.count("n")>0):
    ans_index+=1
  if (Left.count("o")>0 and Right.count("o")>0):
    ans_index+=1
  if (Left.count("p")>0 and Right.count("p")>0):
    ans_index+=1
  if (Left.count("q")>0 and Right.count("q")>0):
    ans_index+=1
  if (Left.count("r")>0 and Right.count("r")>0):
    ans_index+=1
  if (Left.count("s")>0 and Right.count("s")>0):
    ans_index+=1
  if (Left.count("t")>0 and Right.count("t")>0):
    ans_index+=1
  if (Left.count("u")>0 and Right.count("u")>0):
    ans_index+=1
  if (Left.count("v")>0 and Right.count("v")>0):
    ans_index+=1
  if (Left.count("w")>0 and Right.count("w")>0):
    ans_index+=1
  if (Left.count("x")>0 and Right.count("x")>0):
    ans_index+=1
  if (Left.count("y")>0 and Right.count("y")>0):
    ans_index+=1
  if (Left.count("z")>0 and Right.count("z")>0):
    ans_index+=1
  
  ans=max(ans,ans_index)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
li=[]
for i in range(n):
    li.append(s[i])
num=[]
m=0
for i in range(1,n):
    l1=set(li[:i])
    l2=set(li[i:])
    for j in l1:
        if j in l2:
            m+=1
        else:
            pass
    num.append(m)
    m=0

ans=max(num)
print(ans)

Submission status: Accepted

Solution code:
import collections

n = int(input())
s = input()
l1 = []
l2 = []
ans = 0
for i in range(1,n):
  l1 = set(list(s[0:i:]))
  l2 = set(list(s[i::]))
  ans = max(ans,len(l1&l2))
#  print(l1,l2,ans)
  
print(ans)

Submission status: Accepted

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


def cnt(s, k):
    s1 = set(s[:k])
    s2 = set(s[k:])
    return len(s1.intersection(s2))

ans = 0
for i in range(n):
    ans = max(ans, cnt(s, i))
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
ltr = input()

res = 0
for i in range(n):
    s = Counter(ltr[:i]) & Counter(ltr[i:])
    res = max(res, len(s))
print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1,n):
    count=0
    str1=set(s[:i])
    str2=s[i:]
    for j in range(len(str1)):
        str3=(str1.pop()) in str2
        if str3==True:
            count+=1
    if ans<count:
        ans=count
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans = 0
for i in range(N):
  A = S[:i]
  B = S[i:]
  C = list(set(A) & set(B))
  #print(C)
  c = len(C)
  if c > ans:
    ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

idx = n//2
x = S[:idx]
y = S[idx:]
if x == y:
    print(1)
    exit()

cs = 0
for i in range(idx):
    x = S[:idx-i]
    y = S[idx-i:]
    cs = max(cs, len(set(x) & set(y)))

    x = S[:idx+i]
    y = S[idx+i:]
    cs = max(cs, len(set(x) & set(y)))

print(cs)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
S = input().rstrip()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from collections import deque
import math
import fractions
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


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