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: Wrong Answer

Solution code:
n = int(input())
s = input()
mx = 0
for i in range(int(n/2)):
    fw = set(s[:i+1])
    df = set(s[i+1:])
    if mx <= len(fw&df):
        mx = len(fw&df)
print(mx)

Submission status: Wrong Answer

Solution code:
import string
import itertools

L = string.ascii_lowercase

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

    front = [set() for _ in range(n)]
    back  = [set() for _ in range(n)]

    for i, c in enumerate(s):
        if i > 0:
            front[i] = front[i - 1] | set([c])
    
    for i, c in zip(itertools.count(n - 1, -1), reversed(s)):
        if i == n - 1:
            back[i].add(c)

        if i != n - 1:
            back[i] = back[i + 1] | set([c])
    
    m = 0
    for i in range(n):
        x = len(front[i] & back[i])
        m = max(m, x)
    
    print(m)
    
        

main()

Submission status: Wrong Answer

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

both = 0
for i in range(1, n):
	a = list(set(s[0:i]))
	b = list(set(s[i:n]))
	print(a,b)
	botht = 0
	for al in a:
		if(al in b):
			botht += 1
	if(both < botht):
		both = botht
		
print(both)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = input()
mx = 0
for i in range(int(n/2)+1):
    fw = set(s[0:i+1])
    df = set(s[i+1:])
    if mx <= len(fw&df):
        mx = len(fw&df)
print(mx)

Submission status: Wrong Answer

Solution code:
N = int(input())
str = input()
str_list=list(str)
ans_list=[]
for i in range (N):
  str_first = str_list[0:i+1]
  str_second = str_list[i:]
  answer = len(list(set(str_first) & set(str_second)))
  ans_list.append(answer)
  
print(max(ans_list))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import copy

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

count = 0

#文字が一番多く入ってるものをカウントする
for i in range(len(S)):
    temp = S.count(S[i])
    temp_l = S[i]
    if temp > count:
        count = copy.deepcopy(temp)
        max_l = copy.deepcopy(temp_l)

print(int(count/2)+1)

Submission status: Wrong Answer

Solution code:
import sys
if __name__ == "__main__":
    N = int(input())
    S = input()
    max = 1
    for i in range(1, N):
        s1 = S[0:i]
        s2 = S[i:N+1]
        buf = list(set(s1))
        buf2 = list(set(s2))
#        print(s1)
#        print(buf)
#        print(buf2)
        cnt = 0
        for i in range(len(buf)):
            if buf[i] in buf2:
                cnt += 1
        if cnt > max:
            max = cnt
    print(max)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(input())
s = S
c = []
for i in range(1,N):
    a = S[:i]
    b = 0
    del S [:i]
    for j in set(a):
        if j in S:
            b += 1
    c.append(b)
    S = s

print(max(c))

Submission status: Wrong Answer

Solution code:
import sys
if __name__ == "__main__":
    N = int(input())
    S = input()
    max = 1
    for i in range(1, N+1):
        s1 = S[0:i]
        s2 = S[i:N+1]
        buf = list(set(s1))
        buf2 = list(set(s2))
#        print(buf)
#        print(buf2)
        cnt = 0
        for i in range(len(buf)):
            if buf[i] in buf2:
                cnt += 1
        if cnt > max:
            max = cnt
    print(max)

Submission status: Wrong Answer

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

maxCount = 0

for i in range(N-1):
    commonCount = len(set(S[0:i+1])&set(S[i+1:-1]))
    if maxCount < commonCount:
        maxCount = commonCount

print(maxCount)

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
N = int(input())
s = input()
i = 1
li = []
charas = 'abcdefghijklmnopqrstuvwxyz'
while i < N:
  m = 0
  s1 = s[0:i]
  s2 = s[i:]
  for chara in charas:
    if chara in s1 and chara in s2:
      m += 1
  li.append(m)
print(max(li))

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
half = int(n/2)

max1 = 0
for i in range(half):
  f = set(s[:half-i])
  b = set(s[half-i:])
  union = len(f&b)
  if max1 < union:
    max1 = union
  #else:
    #break

max2 = 0
for i in range(half):
  f = set(s[:half+i])
  b = set(s[half+i:])
  union = len(f&b)
  if max2 < union:
    max2 = union
  #else:
    #break
    
ans = max1 if max1>max2 else max2
print(ans)

Submission status: Accepted

Solution code:

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

ans = 0

for i in range(N-1):
    L = S[:i+1]
    R = S[i+1:]
    c = 0
    for l in set(L):
        if l in R:
            c += 1

    ans = max(ans, c)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
res = []

for i in range(1, N):
  res.append(len(set(S[:i]) & set(S[i:])))

print(max(res))

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

Submission status: Accepted

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

for i in range(1,n):
    l = list(s[0:i])
    r = list(s[i:n])
    dup = len(set(l)&set(r))

    if ans < dup:
        ans = dup
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.buffer.readline
in_n = lambda: int(input())
in_nn = lambda: map(int, input().split())
in_s = lambda: input().rstrip().decode('utf-8')
in_map = lambda: [s == ord('.') for s in input() if s != ord('\n')]

MOD = 10**9 + 7
INF = 8 * 10**18


def main():

    N = in_n()
    S = in_s()

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

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()
tmp,ans=0,0
for i in range(n+1):
    s0=[]
    for j in range(n):
        if j<i:
            t=True
            for x in s0:
                if x==s[j]:t=False
            if t:s0.append(s[j])
        else:
            for k in range(len(s0)):
                if s0[k]==s[j]:
                    tmp+=1
                    s0[k]=-1
    #print(i,tmp)
    tmp,ans=0,max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
count = 0
ans = 0
for i in range(0, n - 1):
    x = list(s[:i + 1])
    y = list(s[i + 1:])
    for c in range(ord('a'), ord('z') + 1):
        if chr(c) in x and chr(c) in y:
            count += 1
    if ans < count:
        ans = count
    count = 0
print(ans)

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()
alphabet = ["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-1):
    x = s[:i]
    y = s[i:]
    comp = 0
    for j in alphabet:
        if j in x and j in y:
            comp += 1
    if comp > ans:
        ans = comp
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = input()
ans = 0
for i in range(N):
    d1 = Counter(S[:i])
    d2 = Counter(S[i:])
    tmp = 0
    for alphabet in 'abcdefghijklmnopqrstuvwxyz':
        tmp += min(d1[alphabet], d2[alphabet], 1)
    print
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input().strip()
cmax = 0
for i in range(1,N-1):
    X = set(list(S[:i]))
    Y = set(list(S[i:]))
    Z = X&Y
    cmax = max(cmax,len(Z))
print(cmax)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

cnt = 0
for i in range(1, n-1):
    tmp = 0
    r, l = s[:i], s[i:]
    rs = list(set(r))
    for ri in rs:
        if l.count(ri) > 0:
            tmp += 1
    cnt = max(cnt, tmp)

print(cnt)

Submission status: Accepted

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

alps = 'abcdefghijklmnopqrstuvwxyz'
ans = 0
for i in range(1,n):
    s1 = s[:i]
    s2 = s[i:]
    cnt = 0
    for alp in alps:
        if alp in s1 and alp in s2:
            cnt += 1
    ans = max(ans,cnt)

print(ans)

Submission status: Accepted

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

n = inp()
s = input()
res = 0
for i in range(n):
    a = s[:i]
    b = s[i:]
    ss = set(b)
    ans = 0
    sss = set()
    for x in a:
        if x in ss and not x in sss:
            ans += 1
        sss.add(x)
    res = max(res, ans)
print(res)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
ans = []
for i in range(1, n):
    first_falf = set(s[:i])
    after_falf = set(s[i:])
    count = 0
    for word in first_falf:
        if word in after_falf:
            count += 1
    ans.append(count)
print(max(ans))

Submission status: Accepted

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

def count(x, y):
   l= []
   result = 0
   for i in range(len(x + y)):
      l.append((x + y)[i])
   for letter in set(l):
      if (letter in x) and (letter in y):
         result += 1
   return result

lst = []
for i in range(1, N):
   lst.append(count(s[:i], s[i:]))

print(max(lst))

Submission status: Accepted

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

for i in range(1,n):
    s1 = s[:i]
    s2 = s[i:]
    S1 = list(set(s1))
    cnt = 0
    for j in range(len(S1)):
        if S1[j] in s2:
            cnt += 1
            ans = max(ans, cnt)
            
print(ans)

Submission status: Accepted

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

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

    print(ans)


main()

Submission status: Accepted

Solution code:
def answer(n: int, s: str) -> int:
    result = 0
    for i in range(1, n):
        x = set(s[i:])
        y = set(s[:i])
        common_characters = x.intersection(y)
        result = max(result, len(common_characters))

    return result

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

result = 0
for i in range(1,n):
  x = s[:i]
  y = s[i:]
  x_set = set(x)
  y_set = set(y)
  num = x_set & y_set
  result = max(result, len(num))
print(result)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(str,input()))
ansl = []
for i in range(1,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
  ansl.append(ans)
print(max(ansl))

Submission status: Accepted

Solution code:
n=int(input())
s = list(input())
wd = list("abcdefghijklmnopqrstuvwxyz")
ans=0
for i in range(n):
  s1 = set(s[:i])
  s2=set(s[i:])
  tmp=0
  for w in wd:
    if w in s1 and w in s2:
      tmp+=1
  ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/local/bin/python3
# https://atcoder.jp/contests/abc098/tasks/abc098_b

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


def check(i):
    return len(set(S[:i]) & set(S[i:]))


ans = [0] * N
for i in range(N):
    ans[i] = check(i)

print(max(ans))

Submission status: Accepted

Solution code:
N = int(input())
N_List = list(map(str,input().strip()))
ans = 0
for i in range(1,N):
    c_ans = len(set(N_List[:i]) & set(N_List[i:]))
    if c_ans > ans:
        ans = c_ans
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(n):
    #複数のリストから共通する要素を抽出
    ans = max(ans, len(set(list(s[:i])) & set(list(s[i:]))))

print(ans)

Submission status: Accepted

Solution code:
def calc_intersection():
    n = int(input())
    s = input()
    list_intersection = []

    for i in range(1, n):
        a = set(s[:i])
        b = set(s[i:])
        intersection_a_b = a.intersection(b)
        list_intersection.append(len(intersection_a_b))
    return max(list_intersection)


if __name__ == '__main__':
    print(calc_intersection())

Submission status: Accepted

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

for i in range(1, n + 1):
    a = set(s[:i])
    b = set(s[i:])
    intersection_a_b = a.intersection(b)
    list_intersection.append(len(intersection_a_b))

print(max(list_intersection))

Submission status: Accepted

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

table = [0] * (len(S)+1)
wordDict = {}

for i in range(len(S)):
  if S[i] in wordDict :
    wordDict[S[i]] = [wordDict[S[i]][0], i]
  else:
    wordDict[S[i]] = [i+1, i]

for ran in wordDict.values():
  if ran[0] > ran[1]:
    continue
  for i in range(ran[0], ran[1]+1):
    table[i] += 1

maxNum = 0
for i in range(len(S)+1):
  maxNum = max(maxNum, table[i])

print(maxNum)

Submission status: Accepted

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

def check(a,b):
  c = [0] * 26
  d = [0] * 26
  for i in range(len(a)):
    c[ord(a[i])-97] = 1
  for i in range(len(b)):
    d[ord(b[i])-97] = 1
  ans = 0
  for i in range(26):
    if c[i] == 1 and d[i] == 1:
      ans += 1
  return ans

res = 0
for i in range(n):
  res = max(res,check(s[:i],s[i:]))
print(res)

Submission status: Accepted

Solution code:
def al_cnt(k,s):
    count = 0
    if 'a' in s[:k] and 'a' in s[k:]:
        count += 1
    if 'b' in s[:k] and 'b' in s[k:]:
        count += 1
    if 'c' in s[:k] and 'c' in s[k:]:
        count += 1
    if 'd' in s[:k] and 'd' in s[k:]:
        count += 1
    if 'e' in s[:k] and 'e' in s[k:]:
        count += 1
    if 'f' in s[:k] and'f' in s[k:]:
        count += 1
    if 'g' in s[:k] and 'g' in s[k:]:
        count += 1
    if 'h' in s[:k] and 'h' in s[k:]:
        count += 1
    if 'i' in s[:k] and 'i' in s[k:]:
        count += 1
    if 'j' in s[:k] and 'j' in s[k:]:
        count += 1
    if 'k' in s[:k] and 'k' in s[k:]:
        count += 1
    if 'l' in s[:k] and 'l' in s[k:]:
        count += 1
    if 'm' in s[:k] and 'm' in s[k:]:
        count += 1
    if 'n' in s[:k] and 'n' in s[k:]:
        count += 1
    if 'o' in s[:k] and 'o' in s[k:]:
        count += 1
    if 'p' in s[:k] and 'p' in s[k:]:
        count += 1
    if 'q' in s[:k] and 'q' in s[k:]:
        count += 1
    if 'r' in s[:k] and 'r' in s[k:]:
        count += 1
    if 's' in s[:k] and 's' in s[k:]:
        count += 1
    if 't' in s[:k] and 't' in s[k:]:
        count += 1
    if 'u' in s[:k] and 'u' in s[k:]:
        count += 1
    if 'v' in s[:k] and 'v' in s[k:]:
        count += 1
    if 'w' in s[:k] and 'w' in s[k:]:
        count += 1
    if 'x' in s[:k] and 'x' in s[k:]:
        count += 1
    if 'y' in s[:k] and 'y' in s[k:]:
        count += 1
    if 'z' in s[:k] and 'z' in s[k:]:
        count += 1
    return count
n = int(input())
s = input()
ans = 0
for i in range(1,n-1):
    temp = al_cnt(i,s)
    ans = max(ans,temp)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(n-1):
    s1 = s[:i+1]
    it = iter(s[i+1:])
    it2 = iter(s[i+1:])
    s2 = dict(zip(it,it2))
    visited = {}
    for i in s1:
        if i in visited:
            continue
        if i in s2:
            visited[i] = 1
    ans = max(ans,len(visited))
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
alh="abcdefghijklmnopqrstuvwxyz"
max=0
for i in range(n):
  front=s[:i]
  rear=s[i:]
  cnt=0
  for j in alh:
    if j in front and j in rear:
      cnt+=1
  if cnt>max:
    max=cnt
print(max)

Submission status: Accepted

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

n = int(input())
s = input().strip()

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
shurui=[]
for i in range(len(s)-1):
  zenhan=s[0:i+1]
  kouhan=s[i+1:len(s)]
  kaburu=[]
  kaburu.clear()
  a=0
  for j in range(len(zenhan)):
    if kouhan.count(zenhan[j]) != 0 and kaburu.count(zenhan[j])==0:
      a+=1
      kaburu.append(zenhan[j])
  shurui.append(a)
print(max(shurui))

Submission status: Accepted

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

res = 0

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = []
for n in range(1, N):
    x = sorted(S[:n])
    y = sorted(S[n:])
    cnt.append(len(set(x)&set(y)))
        
print(max(cnt))

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

for i in range(1,len(s)):
  s1 = s[:i]
  s2 = s[i:]
  cnt = set()
  for j in s1:
    if j in s2:
      cnt.add(j)
  ans = max(ans,len(cnt))
print(ans)

Submission status: Accepted

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

x=[]

for i in range(n):
    a=s[:i]
    b=s[i:]
    cnt=0
    c=set(a)
    d=set(b)
    c=list(c)
    d=list(d)
    for j in range(len(c)):
        for k in range(len(d)):
            if c[j]==d[k]:
                cnt+=1
                break
    x.append(cnt)

print(max(x))

Submission status: Accepted

Solution code:
n=int(input())
S=input()
ans=0
for i in range(1,len(S)):
  S1=S[:i]
  S2=S[i:]
  cnt = set()
  for s1 in S1:
    if s1 in S2:
      cnt.add(s1)
  ans = max(ans,len(cnt))
print(ans)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(N-1):
    S1=list(S[0:i+1])
    S2=list(S[i+1:N])

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

    for j in range(len(S1)):
        li1[alf.find(S1[j])]+=1
    for k in range(len(S2)):
        li2[alf.find(S2[k])]+=1
    
    for l in range(26):
        if min(li1[l],li2[l])!=0:
            temp+=1
    if temp>ans:
        ans=temp
print(ans)

Submission status: Accepted

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

max_cnt = 0
for i in range(1, N):
    x = set(S[0:i])
    y = set(S[i:N])
    x_y = len(x & y)
    
    if x_y > max_cnt:
        max_cnt = x_y
        
print(max_cnt)

Submission status: Accepted

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

max_count = 0
for i in range(0, N-1):
  X = S[0:i+1]
  Y = S[i+1:]

  X_set = set(X)
  Y_set = set(Y)

  count = len(X_set & Y_set)
  if max_count < count:
    max_count = count

print(max_count)

Submission status: Accepted

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

ss = []
for s in S:
    if s not in ss:
        ss.append(s)

max_count = 0
for i in range(1, N-1):
    count = 0
    for s in ss:
        x = S[0:i]
        y = S[i:N]
        if s in x and s in y:
            count += 1
    if count > max_count:
        max_count = count

print(max_count)

Submission status: Accepted

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

max_counter = 0
for i in range(1, N-1):
    x = set(S[0:i])
    y = set(S[i:N])
    if len(x & y) > max_counter:
        max_counter = len(x & y)

print(max_counter)

Submission status: Accepted

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

for i in range(1,n-1):
  L = S[:i]
  R = S[i:]
  UL = set(L)
  UR = set(R)
  ans = max(ans, len(UL & UR))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
lines = [s.rstrip("\n") for s in sys.stdin.readlines()]
n, = [int(num) for num in lines.pop(0).split(" ")]
s = lines.pop(0)

ans = 0
for i in range(n):
    intersection = set(s[:i]) & set(s[i:])
    num = len(intersection)
    if num > ans:
        ans = num
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [i for i in input()]
ANS = []

for i in range(1, N+1):
    ans = 0
    A = []
    B = []
    A = list(set(S[:i]))
    B = list(set(S[i:]))
    for a in A:
        for b in B:
            if a == b:
                ans += 1
    ANS.append(ans)
print(max(ANS))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
s="abcdefghijklmnopqrstuvwxyz"
for i in range(1,N):
    T1=S[0:i]
    T2=S[i:N]
    count=0
    for c in s:
        if c in T1 and c in T2:
            count+=1
    ans=max(ans,count)
print(ans)

Submission status: Accepted

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

max_count = 0

for i in range(1, n):
    s1 = ''.join(set(s[:i]))
    s2 = ''.join(set(s[i:]))
    count = 0
    for j in range(len(s1)):
        if s1[j] in s2:
            count += 1
    if count > max_count:
        max_count = count
print(max_count)

Submission status: Accepted

Solution code:
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    S = input()
    ans = 0
    for i in range(1, n):
        x = set(S[:i])
        y = set(S[i:])
        cnt = 0
        for c in x:
            if c in y:
                cnt += 1
        ans = max(cnt, ans)
    print(ans)

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

def f(s, t):
  set_s = set()
  set_t = set()
  for i in s:
    set_s.add(i)
  for i in t:
    set_t.add(i)
  return len( set_s & set_t )

ans = 0
for i in range(1,N):
  s = S[i:]
  t = S[:i]
  ans = max(ans, f(s ,t))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
list = [0]*N
for i in range(N):
    A = S[:i]
    B = S[i:]
    A = set(A)
    B = set(B)
    for j in A:
      if j in B:
        list[i] += 1
list = sorted(list)
print(list[-1])

Submission status: Accepted

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

al = "abcdefghijklmnopqrstuwvxyz"

_max = 0
for i in range(1, N-1):
    s_1 = S[:i]
    s_2 = S[i:]
    count = 0
    for a in al:
        if a in s_1 and a in s_2:
            count += 1
    if count > _max:
        _max = count

print(_max)

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()
C = [chr(i) for i in range(97, 123)]
ans = 0
for i in range(0, N - 1):
  count = 0
  a = S[:i + 1]
  b = S[i + 1:]
  for c in C:
    if c in a and c in b:
      count += 1
  ans = max(count, ans)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
alphabets = 'abcdefghijklmnopqrstuvwxyz'
max_chr = 0

for i in range(len(s)-1):
    cnt = 0
    for letter in alphabets:
        if (letter in s[:i+1]) and (letter in s[i+1:]):
            cnt += 1
    max_chr = max(max_chr, cnt)
print(max_chr)

Submission status: Accepted

Solution code:
input()
S = input()

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

Submission status: Accepted

Solution code:
_ = input()
S = input()

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

Submission status: Accepted

Solution code:
_ = input()
S = input()

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

Submission status: Accepted

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

print(max([len(set(S[:i]) & set(S[i:])) for i in range(N)]))

Submission status: Accepted

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

print(max([len(set(S[:i]) & set(S[i:])) for i in range(N)]))

Submission status: Accepted

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

print(max([len(set(list(S[:i])) & set(list(S[i:]))) for i in range(N)]))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
count = 0
for i in range(n-1):
  a=s[:i + 1]
  b=s[i+1:]
  temp = 0
  for j in range(27):
    if chr(96+j) in a and chr(96+j) in b:
      temp += 1
  count = max(temp, count)
print(count)

Submission status: Accepted

Solution code:
n = int(input())
a = input()
dic="abcdefghijklmnopqrstuvwxyz"
maxcount = 0
for i in range(n):
  count = 0
  for j in range(26):
    if str(dic[j]) in a[:i] and str(dic[j]) in a[i:]:
      count+=1
  maxcount = max(count,maxcount)
print(maxcount)

Submission status: Accepted

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

ans = 0
for i in range(1,N-1):
  set1 = set(S[:i])
  set2 = set(S[i:])
  z = set1.intersection(set2)
  ans = max(ans,len(z))

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from string import ascii_lowercase


def cut_and_count(s, n, i):
    x = set(s[:i])
    y = set(s[i:])
    cnt = 0

    for ch in ascii_lowercase:
        if ch in x and ch in y:
            cnt += 1
    return cnt


def main():
    n = int(input())
    s = list(input())
    ans = 0

    for i in range(1, n):
        res = cut_and_count(s, n, i)
        ans = max(ans, res)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush

sys.setrecursionlimit(10**6)
INF = 10**20

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])

N = int(input())
S = input()
X = [0]*26
Y = [0]*26

for i in range(N):
    k = ord(S[i])-ord('a')
    Y[k] += 1

ans = 0
for i in range(N):
    k = ord(S[i])-ord('a')
    X[k] += 1
    Y[k] -= 1
    tmp = 0
    for j in range(26):
        if X[j]>0 and Y[j]>0:
            tmp += 1
    ans = max(ans,tmp)
print(ans)

Submission status: Accepted

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

alphabets = [chr(i + 97) for i in range(26)]

# forward
l1 = [0] * (n-1)
now = [False] * 26
for i in range(n-1):
    now[ord(s[i]) - 97] = True
    l1[i] = now.copy()

# backward
l2 = [0] * (n-1)
now = [False] * 26
for i in range(n-1, 0, -1):
    now[ord(s[i]) - 97] = True
    l2[i-1] = now.copy()

ans = 0
for i in range(n-1):
    cnt = 0
    for j in range(26):
        if l1[i][j] and l2[i][j]:
            cnt += 1

    if ans < cnt:
        ans = cnt

print(ans)

Submission status: Accepted

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

list1 =  []
for i in range(N):
  x = set()
  
  for s in S[:i+1]:
    if s in S[i+1:]:
      x.add(s)
  list1.append(len(x))
print(max(list1))

Submission status: Accepted

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