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+1):
    cnt = 0
    x = s[0:i]
    y = s[i:n+1]
    for j in range(97, 123):
        if chr(j) in x and chr(j) in y:
            cnt += 1
    ans = max(cnt, ans)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
data=[]
ans=0
for i in range(n-1):
  if s[i] not in data:
    data.append(s[i])
  res=0
  for j in data:
    if j in s[i+1:n]:
      res+=1
  ans=max(ans,res)
print(ans)

Submission status: Accepted

Solution code:
# ABC098

N = int(input())
S = input()
ans = 0
for i in range(len(S)):
    left = set(S[0:i])
    right = set(S[i:len(S)])

    ans = max(ans, len(left & right))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
dic = {}

for i in range(N):
  if S[i] not in dic.keys():
    dic[S[i]] = [i]
  else:
    dic[S[i]].append(i)
    
ans = 0
for j in range(1,N):
  cnt = 0
  for k in dic.values():
    check1 = False
    check2 = False
    for l in k:
      if l < j:
        check1 = True
      if j <= l:
        check2 = True
    if check1 and check2:
      cnt += 1
  ans = max(ans, cnt)
  
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(N):
	s1,s2=set(S[:i]),set(S[i:])
	tmp = len(s1.intersection(s2))
	if tmp > ans:ans=tmp


print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ma=0
for i in range(1,N):
    leftS = S[0:i]
    rightS = S[i:]
    setLeftS = set(leftS)
    setRightS = set(rightS)
    m = 0
    for r in setRightS:
        if r in setLeftS:
            m+=1
    ma = max(ma,m)
print(ma)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    S = input()
    ans = 0
    for i in range(1, N):
        first = set(S[:i])
        second = set(S[i:])
        score = len(first & second)
        ans = max(ans, score)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
_sum = 0
visited = set()
_sum_visited = set()
max_size = len(set(S))


for n in range(N-1):
  if S[n] in S[n+1:] and (S[n] not in visited):
    _sum += 1
  
  elif S[n] in visited and (S[n] not in S[n+1:]):
    _sum -= 1
  
  visited.add(S[n])
  _sum_visited.add(_sum)
  last_size = len(set(S[n+1]))
  ans = max(_sum_visited)
  if ans == max_size:
    break
    
print(max(_sum_visited))

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0
for i in range(N):
    s1 = set(S[:i])
    s2 = set(S[i:])
    l: int = len(s1 & s2)
    if l > cnt:
        cnt = l

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    s = s_input()
    ans = 0
    for i in range(n):
        l = set(s[:i])
        r = set(s[i:])
        trial = 0
        for k in l:
            if k in r:
                trial += 1
        ans = max(ans,trial)
    print(ans)



if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
a = []
for i in range(1, len(s)):
    s1 = list(s[:i])
    s2 = list(s[i:])
    b = []
    for j in s1:
        if j in s2 and j not in b:
            b.append(j)
    a.append(len(b))
print(max(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
match = []
for i in range(1,len(s)):
    s1 = list(s[:i])
    s2 = list(s[i:])
    cnts = []
    for j in s1:
        if j in s2:
            if j not in cnts:
                cnts.append(j)
    match.append(len(cnts))
print(max(match))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
tmp=0
ans=0
for i in range(N):
    A=set(S[:i])
    B=set(S[i:N])
    AB=A & B
    tmp=len(AB)
    if tmp > ans:
        ans=tmp
print(ans)

Submission status: Accepted

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

ans=0
for i in range(N):
    X=S[0:i]
    Y=S[i:N] 
    XY=set(X) & set(Y)
    cnt=len(XY)
    ans=max(ans,cnt)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
ans = 0
c = 0
fh = []
lh = s
for i in range(n):
  tmp = lh.pop(0)
  if tmp not in fh:
    if tmp in lh:
      c += 1
  elif tmp not in lh:
    c -= 1
  fh.append(tmp)
  ans = max(ans, c)
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(1, N + 1):
    a = list(set(S[:i]))
    b = list(set(S[i:]))
    ans_ = sum([b.count(x) for x in a])
    # print(ans_)
    ans = max(ans, ans_)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
tmp = 0
for i in range(N):
  S1 = set(S[:i])
  S2 = set(S[i:])
  Sintcnt = len(S1 & S2)
  tmp = max(tmp, Sintcnt)
print(tmp)

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = input()
ans = 0
for l in range(1,n):
  s1 = s[:l]
  s2 = s[l:]
  s1 = collections.Counter(s1)
  s2 = collections.Counter(s2)
  num = 0
  for i in s1:
    if i in s2:
      num += 1
      ans = max(ans,num)
print(ans)

Submission status: Accepted

Solution code:
#7 B - Cut and Count
N = int(input())
S = list(input())

mcnt = 0
for i in range(N-1):
    count = 0
    l = S[:i]
    r = S[i:]
    l = set(l)
    r = set(r)
    for j in l:
        if j in r:
            count += 1
    mcnt = max(mcnt,count)
print(mcnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    s = S()
    ans = 0
    
    for i in range(1,n):
        left = s[:i]
        right = s[i:]
        leftset = set(left)
        rightset = set(right)
        share = len(leftset & rightset)
        ans = max(ans, share)

    print(ans)
main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
res = 0
for i in range(1, n - 1):
    l = set(s[:i])
    r = set(s[i:])
    tmp = 0
    for j in range(26):
        if chr(ord("a") + j) in l and chr(ord("a") + j) in r:
            tmp += 1
    res = max(res, tmp)
print(res)

Submission status: Accepted

Solution code:
N = int (input ())
S = input ()
x = 0
for i in range (N-1):
  L = S[:i+1]
  R = S[i+1:]
  X = 0
  for i in range (len(L)):
    if R.count(L[i]) != 0 and L[:i].count(L[i]) == 0:
      X += 1
  if X > x:
    x = X
print (x)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
ma=0
for i in range(n):
  c=[]
  count=0
  a=s[:i+1]
  b=s[i+1:]
  for j in range(len(a)):
    if a[j] not in c:
      if a[j] in b:
        c.append(a[j])
        count+=1
    if count>ma:
      ma=count
print(ma)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding:utf-8
n = int(input())
s = input()
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
S = S()
ans = 0
for i in range(N):
    a = collections.Counter(S[:i])
    b = collections.Counter(S[i:])
    ans = max(len(set(a.keys()) & set(b.keys())), ans)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
a = [0] * 26
for i in range(N):
    a[ord(S[i])-ord('a')] += 1

b = [0] * 26
for i in range(N):
    a[ord(S[i])-ord('a')] -= 1
    b[ord(S[i])-ord('a')] += 1
    cnt = 0
    for j in range(26):
        if a[j]*b[j]>0:
            cnt += 1
    ans = max(ans,cnt)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for i in range(N-1):
    set1 = set(S[:i+1])
    set2 = set(S[i+1:])
    
    ans = max(ans, len(set1&set2))
    
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(N-1):
    l1 = [0]*26
    l2 = [0]*26
    for j in S[:i+1]:
        if l1[(ord(j)-ord("a"))]==0:
            l1[(ord(j)-ord("a"))]=1
    for k in S[i+1:]:
        if l2[(ord(k)-ord("a"))]==0:
            l2[(ord(k)-ord("a"))]=1
    cnt = 0
    for i in range(26):
        if l1[i]*l2[i] == 1:
            cnt += 1
    ans = max(ans, cnt)

print(ans)

Submission status: Accepted

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

ans_list = []
for i in range(n):
    ans = 0
    x = list(set(s[:i]))
    y = list(set(s[i:]))
    for j in range(len(x)):
        if x[j] in y:
            ans += 1
    ans_list.append(ans)

a = max(ans_list)
print(a)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans=0
for i in range(1,n):
    be=s[:i]
    af=s[i:]

    tmp = len(set(be)&set(af))
    ans=max(ans,tmp)

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(N-1):
    a = [0]*26
    b = [0]*26
    for j in S[0:i+1]:
        if a[ord(j)-ord('a')]==0:
            a[ord(j)-ord('a')]=1
    for j in S[i+1:N]:
        if b[ord(j)-ord('a')]==0:
            b[ord(j)-ord('a')]=1
    subans = 0    
    for i in range(26):
        if a[i]*b[i]==1:
            subans+=1
    ans = max(ans,subans)
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
ans=[]
count=0
num=[]

for i in range(1,n+1):
  l=s[:i]
  r=s[i:]
  
  l=sorted(l)
  r=sorted(r)
  
  for j in l:
    if j in r:
      if j not in num:
        count+=1
        num.append(j)
        
  ans.append(count)
  num.clear()
  count=0
  
print(max(ans))

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
m = 0
w = []
for j in s:
    w.append(j)
w = list(set(w))
for i in range(1,n):
    t = 0
    for h in w:
        if 1 <= s[:i].count(h) and 1 <= s[i:].count(h):
            t += 1
    if m < t:
        m = t
print(m)

Submission status: Accepted

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

m = 0

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

print(m)

Submission status: Accepted

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

print(nax)

Submission status: Accepted

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

for i in range(1,n):
    s1 = s[:i]
    s2 = s[i:]
    cnt = max(cnt, len(list(set(s1) & set(s2))))
    
print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
S=str(input())
m=0
for i in range(N):
    a=[]
    x=S[:i]
    y=S[i:]
    for j in range(len(x)):
        if x[j] in y:
            if x[j] not in a:
                a.append(x[j])
    if len(a)>m:
        m=len(a)
                
print(m)

Submission status: Accepted

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

Submission status: Accepted

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


ans = []
for i in range(1, n):
  a = s[0:i]
  b = s[i:n]
  res = []
  for j in a:
    if j in b and j not in res:
      res.append(j)
    ans.append(len(res))
    
print(max(ans))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
chars = list("abcdefghijklmnopqrstuvwxyz")
ans_lst = []
for cut in range(1, N):
    left = S[:cut]
    right = S[cut:]
    count = 0
    for char in chars:
        if char in left and char in right:
            count += 1
    ans_lst.append(count)
print(max(ans_lst))

Submission status: Accepted

Solution code:
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    S = ns()
    ans = 0
    for i in range(1, n - 1):
        X = S[:i]
        Y = S[i:]
        tmp = len(set(X) & set(Y))
        ans = max(ans, tmp)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1,n):
    s_1 = set(s[:i])
    s_2 = set(s[i:])
    lis = [len(set(s[:i])&set(s[i:])) for i in range(1,n) ]
print(max(lis))

Submission status: Accepted

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

for i in range(1,n):
  count=0
  #print(a[:i],a[i:])
  l=set(a[:i])
  g=set(a[i:])
  #print(l,g)
  for j in l:
    if j in g: count+=1
  if max < count: max=count
print(max)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
dic = {}
for i in s:
    dic.setdefault(i,0)
    dic[i] += 1
#print(dic)
move = {}
ans = []
cnt = 0
for i in s:
    dic[i] -= 1
    move.setdefault(i,0)
    move[i] += 1
    if dic[i]>0 and move[i]>0:
        if i not in ans:
            ans.append(i)
    elif dic[i]==0:
        if i in ans:
            ans.remove(i)
    cnt = max(cnt,len(ans))
print(cnt)

Submission status: Accepted

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

result =[]

for i in range(N):
    left = []
    right= []
    for l in range(0,i):
        if S[l] not in left:
            left.append(S[l])
        else:
            continue

    
     
    for r in range(i,N):
        if S[r] not in right:
             right.append(S[r])
        else:
            continue


    count =0
    for i in left:
        for  s in right:
            if i == s :
                count +=1
    result.append(count)
    

print(max(result))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans = 0
for i in range(N):
    a = S[:i]
    b = S[i:]
    aset = set(a)
    bset = set(b)
    count = 0
    for i in aset:
        if i in bset:
            count += 1
    ans = max(ans,count)
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:]))
    kaburi = 0
    for j in range(len(X)):
        for k in range(len(Y)):
            if X[j] == Y[k]:
                kaburi += 1
    if kaburi > ans:
        ans = kaburi

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
L=list(input())
maxa=-10
for i in range(N-1):
  a=set(L[:i+1])
  b=set(L[i+1:])
  maxa=max(maxa,len(a&b))
print(maxa)

Submission status: Accepted

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

li1 = [0] * 26
li2 = [0] * 26

ans = 0

for s in S:
    si = ord(s) - 97
    li1[si] += 1

for s in S:
    si = ord(s) - 97
    li2[si] += 1
    li1[si] -= 1

    t = 0
    for i in range(26):
        if li1[i] > 0 and li2[i] > 0:
            t += 1

    ans = max(ans, t)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(N - 1):
    a = S[:i + 1]
    b = S[i + 1:]
    count = 0
    for j in range(97, 123):
        if chr(j) in a and chr(j) in b:
            count += 1
    if count > ans:
        ans = count
print(ans)

Submission status: Accepted

Solution code:
import collections

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

ans=0
X=collections.Counter()
Y=collections.Counter(S)
for c in S:
    X[c]+=1
    Y[c]-=1
    ans=max(ans,len(X&Y))
       
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

ans=0
X=Counter()
Y=Counter(S)
for c in S:
    X[c]+=1
    Y[c]-=1
    ans=max(ans,len(X&Y))
       
print(ans)

Submission status: Accepted

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

ans=0
for i in range(1,N-1):
    a=[0]*26
    for j in range(i):
        a[ord(S[j])-97]|=1
    for j in range(i,N):
        a[ord(S[j])-97]|=2
    ans=max(ans,a.count(3))

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

ans=0
X=Counter()
Y=Counter(S)
for c in S:
    Y[c]-=1
    if Y[c]==0:
        del X[c]
    else:
        X[c]+=1
    ans=max(ans,len(X))
       

print(ans)

Submission status: Accepted

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

ans=0
l=Counter()
r=Counter(S)
for c in S:
    l[c]+=1
    r[c]-=1
    ans=max(ans,len(l&r))

print(ans)

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

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

ans = 0
for i in range(n-1):
    cnt = 0
    f = set(s[:i+1])
    b = set(s[i+1:])
    tmp = []
    if (len(f) >= len(b)):
        tmp = list(set(s[:i+1]))
        tmp2 = list(s[i+1:])
    else:
        tmp = list(set(s[i+1:]))
        tmp2 = list(s[:i+1])
    for i in range(len(tmp)):
        if tmp[i] in tmp2:
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(N):
  ans = 0
  for j in range(N):
    f = {}
    b = {}
    for k in range(j):
      if S[k] in f.keys():
        f[S[k]] += 1
      else:
        f[S[k]] = 1
        
    for k in range(N-j):
      if S[N-k-1] in b.keys():
        b[S[N-k-1]] += 1
      else:
        b[S[N-k-1]] = 1

    for k in range(N):
      common = 0
      for l in f.keys():
        if l in b.keys():
          common += 1
     
      if common > ans:
        ans = common
        
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
answer = 0
for i in range(1,N-1):
  X = S[:i]
  Y = S[i:]
  Z = 0
  for c in 'abcdefghijklmnopqrstuvwxyz':
    if c in X and c in Y:
      Z += 1
  answer = max(answer,Z)
print(answer)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = list(input())
print(max([len(Counter(s[:i]).keys() & Counter(s[i:]).keys()) for i in range(1,n+1)]))

Submission status: Accepted

Solution code:
from collections import Counter

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

ans = 0

for i in range(1, n - 1):
    ans = max(ans, len(Counter(s[:i]).keys() & Counter(s[i:]).keys()))

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = 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:
def main():
    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)
main()

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:
N = int(input())
S = input()

ans = 0
for i in range(1, len(S)):
    tmp = 0
    X = set(S[:i])
    Y = set(S[i:])
    for x in X:
        if x in Y:
            tmp += 1
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
s = rr()
max_cnt = 0
for i in range(1, n-1):
  x = set(s[:i])
  y = set(s[i:])
  max_cnt = max(len(x & y), max_cnt)
print(max_cnt)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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 = list(input())
a = []
for i in range(1, N):
  a.append(len(list(set(s[0:i]) & set(s[i:]))))
print(max(a))

Submission status: Accepted

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

ans = 0
for i in range(n):
    d1, d2 = {}, {}
    for j in range(i):
        d1[s[j]] = 0
    for j in range(i, n):
        if s[j] in d1 and s[j] not in d2:
            d2[s[j]] = 0
    ans = max(ans, len(d2))

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(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(n-1):
    ls=set(s[0:i+1])
    rs=set(s[i+1:n])
    cnt=0
    for l in ls:
        if l in rs:
            cnt+=1
    ans=max(cnt,ans)
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(n):
    one = s[0:i]
    other = s[i:]
    now = 0
    one = set(one)

    for j in one:
        for k in other:
            if j == k:
                now += 1
                break

    ans = max(now, ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    S = input()
    ans = []
    abc = "abcdefghijklmnopqrstuvwxyz"
    for i in range(N-1):
        X = S[:i+1]
        Y = S[i+1:]
        count = 0
        for j in abc:
            if j in X and j in Y:
                count += 1
        ans.append(count)
    print(max(ans))
resolve()

Submission status: Accepted

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

a = [0]*N

for i in range(1, N):
    b = []
    for s in S[:i]:
        if s in S[i:] and s not in b:
            a[i] += 1
            b.append(s)

print(max(a))

Submission status: Accepted

Solution code:
import string

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

result = 0
for i in range(1, N+1):
    S_forward = S[:i]
    S_backward = S[i:]
    is_same = 0
    for j in string.ascii_lowercase:
        if j in S_forward and j in S_backward:
            is_same += 1
    result = max(result, is_same)

print(result)

Submission status: Accepted

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

result = 0
for i in range(1, N+1):
    S_forward = S[:i]
    S_backward = S[i:]
    is_same = []
    for j in S_forward:
        if j in S_backward:
            if j not in is_same:
                is_same.append(j)
    result = max(result, len(is_same))

print(result)

Submission status: Accepted

Solution code:

n=int(input())
s=input()
a=list("abcdefghijklmnopqrstuvwxyz")
x=[]
y=[]
m=0
for i in range(n-1):
    x=[s[j] for j in range(i)]
    y=[s[j] for j in range(i,n)]
    ans=0
    for j in range(26):
        if a[j] in x and a[j] in y:
            ans+=1
    m=max(ans,m)
print(m)

Submission status: Accepted

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

for i in range(1, len(s)):
    u = len(set(s[:i]).intersection(set(s[i:])))
    if u > max:
        max = u

print(max)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

MAX=0
for i in range(1,N-1):
  s1,s2=set(S[:i]),set(S[i:])
  tmp = len(s1.intersection(s2))
  if tmp > MAX:MAX=tmp

print(MAX)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

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