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:
#!/usr/bin/env python3
import sys 

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

def comp(str1, str2):
    s1 = set(list(str1))
    s2 = list(str2)
    ans = 0 
    for i in s1: 
        if i in s2: 
            ans += 1
    return ans 

ans = 0 
for i in range(n-1):
   ls = s[:i+1]
   rs = s[i+1:]
   tmp = comp(ls, rs) 
   ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
# 2020/01/26
# AtCoder Beginner Contest 098 - B

# Input
n = int(input())
s = input()

clist_d = [[0] * 27 for i in range(len(s) + 1)]

for i in range(len(s)):
    idx = ord(s[i]) - 97
    clist_d[i][idx] = clist_d[i][idx] + 1

    for j in range(26):
        clist_d[i+1][j] = clist_d[i][j]

maxcnt = 0
for i in range(len(s)):
    cnt = 0
    for j in range(26):
        if clist_d[i][j] > 0 and clist_d[i][j] < clist_d[len(s)-1][j]:
            cnt = cnt + 1
        
        if maxcnt < cnt:
            maxcnt = cnt
    
ans = maxcnt

# Output
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import string
n = int (input())
s = input()
az = string.ascii_lowercase

ans = []

for i in range(1,n):
     count = 0
     before = s[:i]
     after = s[i:]
     for j in az:
         if j in before and j in after:
              count +=1
     ans.append(count)
print(max(ans))

Submission status: Accepted

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

for i in range(1, n, 1):
    a = s[:i]
    b = s[i:]
    rep = 0
    for word in "abcdefghijklmnopqrstuvwxyz":
        if word in a and word in b:
            rep += 1
    ans = max(ans, rep)
print(ans)

Submission status: Accepted

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

count=0
max_count=0
for i in range(1,n):
    x=s[:i]
    y=s[i:]
    l=Counter(x)
    t=Counter(y)
    for j in l.keys():
        if(j in t.keys()):
            count+=1
    if(max_count < count):
        max_count=count
    count=0
print(max_count)

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
S = list(readline().decode('utf8').rstrip())

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

print(ans)

Submission status: Accepted

Solution code:
a = input()
b = raw_input()
x = 0
for i in range(1,a):
    z = b[0:i]
    y = b[i:a]
    arr = []
    for l in y:
        for m in z:
            if l == m and l not in arr:
                arr.append(l)
    if len(arr) > x:
        x = len(arr)
print x

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans=0
for i in range(N):
  A=set(S[:i])
  B=set(S[i:])
  cnt=0
  for j in A:
    if (j in B):
      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):
  A=len(set(S[:i+1])&set(S[i+1:]))
  ans=max(A,ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
s = raw_input()
ans = 0
for i in range(1,n):
    a = s[0:i]
    b = s[i:n]
    arr = []
    for l in a:
        for m in b:
            if l == m and l not in arr:
                arr.append(l)
    if len(arr) > ans:
        ans = len(arr)
print ans

Submission status: Accepted

Solution code:
n=int(input())
s=input()
l=[0 for i in range(26)]
for c in s:
    l[ord(c)-ord('a')]+=1
r=[0 for i in range(26)]
ans=0

for c in s:
    l[ord(c)-ord('a')]-=1
    r[ord(c)-ord('a')]+=1
    tmp=0
    for i in range(26):
        if l[i] and r[i]:
            tmp+=1
    if ans<tmp:
        ans=tmp
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(n)))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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()

resultMax = 0
for i in range(n):
  s1 = set(s[:i])
  s2 = set(s[i:])
  result = 0
  for j in s1:
    for k in s2:
      if j == k:
        result += 1
        break
  if resultMax < result:
    resultMax = result

print(resultMax)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(n):
    x, y = s[:i], s[i:]
    cnt = 0
    for j in range(26):
        if x.count(chr(ord('a') + j)) and y.count(chr(ord('a') + j)):
            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):
    ans = max(ans, len(set(x for x in s[:i]) & set(x for x in s[i:])))

print(ans)

Submission status: Accepted

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

f = ""
b = ""

L = [0] * N
con = 0

for i in range(N - 1):
  b = S[i + 1:]
  if S[i] in b and S[i] not in f:
    con += 1
    L[i] = con
  elif S[i] not in b and S[i] in f:
    con -= 1
    L[i] = con
  f += S[i]

  
print(max(L))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
maxx=-1
def got(a,al):
    for i in a:
        if i==al :
      	    return(True)
    return(False)
for i in range(n):
    a=s[:i]
    b=s[i:]
    cnt=0
    alp="abcdefghijklmnopqrstuvwxyz"
    for al in alp:
        if got(a,al) and got(b,al):
      	    cnt+=1
    maxx=max(maxx,cnt)
print(maxx)

Submission status: Accepted

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

ans=0
for i in range(n-1):
  cnt=0
  a=set(s[:i+1])
  b=set(s[i+1:])
  for j in a:
    if j in b:
      cnt+=1
  if ans<cnt:
    ans=cnt

print(ans)

Submission status: Accepted

Solution code:
alp='abcdefghijklmnopqrstuvwxyz'
N=int(input())
S=input()
out=0
for i in range(1, N):
  X=S[:i]
  Y=S[i:]
  xs=[0]*26
  ys=[0]*26
  tmp=0
  for j in range(len(X)):
    xs[alp.index(X[j])]=1
  for j in range(len(Y)):
    ys[alp.index(Y[j])]=1
    
  for j in range(26):
    if xs[j]==1 and ys[j]==1:
      tmp+=1
      
  if out<tmp:
    out=tmp
print(out)

Submission status: Accepted

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

m = 0
for i in range(1, N-1):
    a = set(S[:i])
    b = set(S[i:])
    m = max(m, len(a.intersection(b)))

print(m)

Submission status: Accepted

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

ans = 0
for i in range(2, N):
  fw = set(S[:i])
  bk = set(S[i:])
  len_S = len(fw & bk)
  ans = max(ans, len_S)
  
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if S == S[0] * N:
  print(1)
else:
  for i in range(1, N):
    count = 0
    X = list(set(S[0:i]))
    Y = list(set(S[i:]))
    for j in range(len(X)):
      if Y.count(X[j]) > 0:
        count += 1
    C.append(count)

  print(max(C))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1,N-1):
    lis1 = [0]*26
    lis2 = [0]*26
    for j,s in enumerate(S):
        if j<i:
            lis1[ord(s)-97] = 1
        else:
            lis2[ord(s)-97] = 1
    ans = max(ans,sum([lis1[i]*lis2[i] for i in range(26)]))
print(ans)

Submission status: Accepted

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

for i in range(1,n-1):
    
    mae = set(s[:i])
    ato = set(s[i:])
    cnt = mae & ato

    ans = max(ans,len(cnt))
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import collections
from collections import Counter
input = sys.stdin.readline
N = int(input())
S = list(input())
count = -1000
del S[-1]
for i in range(N) :
    a = 0
    Sa = S[:i]
    Sb = S[i:]
    ca = collections.Counter(Sa)
    cb = collections.Counter(Sb)
    ka = list(ca.keys())
    kb = list(cb.keys())
    for j in ka :
        for k in kb :
            if j == k :
                a +=1
    count = max(a,count)
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
#2<=n<=100だからやってみる

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

Submission status: Accepted

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

res = []

for i in range(n):
    x = set(s[:i])
    y = set(s[i:])
    res.append(len(x & y))
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(N)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
N = int(input())
S = str(input())

ans = 0
for i in range(1, N) :
  X = S[:i]
  Y = S[i:]
  #print ("X: " + X)
  #print ("Y: " + Y)
  Xlist = []
  Ylist = []
  cnt = 0
  for x in range(len(X)) :
    if X[x] not in Xlist :
      Xlist.append(X[x])
  for y in range(len(Y)) :
    if Y[y] not in Ylist :
      Ylist.append(Y[y])
  
  for xl in range(len(Xlist)) :
    if Xlist[xl] in Ylist :
      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):
    left = set(S[:i])
    right = set(S[i:])
    ans = max(ans, len(left&right))
print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = input()
    ma = 0
    for i in range(1, n):
        x = s[:i]
        y = s[i:]
        ma = max(ma, count_same(x, y))
    print(ma)


def count_same(x, y):
    return len(set(x) & set(y))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

num=0
for i in range(n):
    x=set(s[:i])
    y=set(s[i:])
    if len(x&y)>num:
        num=len(x&y)

print(num)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
ans = 0
for i in range(1, n):
    x = S[:i]
    y = S[i:]
    co = len(set(x) & set(y))
    if co > ans:
        ans = co

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    left = set(list(S[:i]))
    right = set(list(S[i:]))
    candidate = len(left&right)
    ans = max(ans, candidate)

print(ans)

Submission status: Accepted

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

#どんよくぅ
s= []
s.append(lst1.pop(0))
ans,res = 0,0
for i in range(n-1):
    res = 0
    for j in s:
        if j in lst1:
            res += 1
    if not lst1[0] in s:
        s.append(lst1.pop(0))
    else:
        del lst1[0]
    ans = max(ans,res)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for i in range(1,n-1):
    a=s[:i]
    b=s[i:]
    c=0
    for j in range(97,97+26):
        if a.count(chr(j))!=0 and b.count(chr(j))!=0:
            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):
  X = set(list(S[:i]))
  Y = set(list(S[i:]))
  ans = max(ans, len(X & Y))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
S = list(input())
ans = 0
for i in range(1, N-1):
    temp = []
    left = S[:i]
    right = S[i:]
    for i in left:
        if i in right and i not in temp:
            temp.append(i)
    ans = max(ans, len(temp))
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

n = int(sys.stdin.readline().rstrip())
s = sys.stdin.readline().rstrip()

def main():
    c = Counter(s)
    l = set()
    r = set(s)
    res = 0
    cnt = 0
    for letter in s:
        c[letter] -= 1
        if not c[letter]:
            r -= set([letter])
            if letter in l:
                cnt -= 1
        elif not letter in l:
            l.add(letter)
            cnt += 1
            res = max(res, cnt)
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

for i in range(n-1):
    x = list(s[:i+1])
    y = list(s[i+1:])
    x1 = list(set(x))
    y1 = list(set(y))
    z = x1 + y1
    z1 = list(set(z))

    lst.append(len(z)-len(z1))

print(max(lst))

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    left = set(s[:i])
    right = set(s[i:])

    cnt = 0
    for l in left:
        if l 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 = set(s[:i])
    y = set(s[i:])
    ans = max(len(x&y),ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

max_c = 0
for i in range(N):
    a = S[0:i]
    b = S[i:]
    c = len(set(a) & set(b))
    if c > max_c:
        max_c = c
print(max_c)

Submission status: Accepted

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

def count(left, right):
  return len(set(left) & set(right))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

lis_ans = []
for split in range(1,n):
    left = s[:split]
    right = s[split:]
    #print(left, right)
    
    s_left = set(left)
    s_right = set(right)

    ans = 0
    for wl in s_left:
        for wr in s_right:
            if wl == wr:
                ans += 1

    lis_ans.append(ans)

print(max(lis_ans))

Submission status: Accepted

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

ans = []


for i in range (1,N):
    mae = S[:i]
    usiro = S[i:]
    mae_usiro = set(mae) & set(usiro)
    ans.append(len(mae_usiro))
    

print(max(ans))

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = input()
s = input()
ans = 0
tmp = 0
old = []
for i in range(1, len(s)):
    tmp = 0
    old = []
    for j in range(i):
        if s[j] in s[i:] and not(s[j] in old):
            tmp += 1
            old.append(s[j])
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
a = set()
b = set()
ans = 0
for i in range(1,N):
    X = set(S[:i])
    Y = list(set(S[i:]))
    cnt = 0
    for s in Y:
        if s in X:
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N):
	cnt = 0
	type_flont= sorted(set(S[:i]),key=S.index)
	type_back= sorted(set(S[i:N]),key=S.index)
	for j in range(len(type_back)):
		if(type_back[j] in type_flont):
			cnt+=1
	if(ans < cnt):
		ans = cnt
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    left = set(s[:i])
    right = set(s[i:])

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

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    left = set(s[:i])
    right = set(s[i:])

    tmp = 0
    for j in left:
        if j in right:
            tmp += 1
    
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

answer = []
for i in range(1, N):
  answer.append(len(set(S[:i]) & set(S[i:])))
print(max(answer))

Submission status: Accepted

Solution code:
n=int(input())
s=str(input())
ans=[]
li=["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"]  
for i in range(1,n):
    cnt=0
    for j in range(26):
        if li[j] in s[:i]:
            if li[j] in s[i:]:
                cnt+=1
    ans.append(cnt)   
print(max(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 = input()

ans = 0
for i in range(1, N):
    S1 = S[i:]
    S2 = S[:i]
    
    A = [0] * 26
    for j in range(len(S1)):
        t = ord(S1[j]) - 97
        A[t] += 1

    B = [0] * 26
    for j in range(len(S2)):
        t = ord(S2[j]) - 97
        B[t] += 1
    
    c = 0
    for k in range(26):
        if A[k] > 0 and B[k] > 0:
            c += 1

    ans = max(ans, c)

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(N):
  cnt = 0
  X = set(S[:i])
  Y = set(S[i:])
  for j in X:
    if j in Y:
      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,n):
    left = set(s[:i])
    right= set(s[i:])
    c=0
    for i in left:
        if i in right:c += 1
    ans=max(c,ans)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = input()
array = []
for i in range(1,N):
    S1 = list(S[:i])
    S2 = list(S[i:])
    S1c = Counter(S1)
    S2c = Counter(S2)
    suma = 0
    for k in S1c:
        if k in S2c:
            suma += 1
    array.append(suma)
print(max(array))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(n - 1):
  cnt = 0
  X = s[0:i + 1]
  Y = s[i + 1:]
  X = set(X)
  Y = set(Y)
  for x in X:
    if x in Y:
      cnt += 1
  ans = max(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(input())
d = 0
for i in range(1,n):
    a1 = a[:i]
    a2 = a[i:]
    d = max(len(set(a1)&set(a2)),d)
print(d)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1, n - 1):
    cnt = 0
    left = set(s[:i])
    right = set(s[i:])
    for alphabet in left:
        if alphabet in right:
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

import random


def main():
    n = int(input().strip())
    s = input().strip()
    max_cnt=0
    for i in range(1,n):
        s1=set(s[0:i])
        s2=set(s[i:n])
        ss = s1 & s2
        cnt=len(ss)
        max_cnt=max(max_cnt,cnt)
    print(max_cnt)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
sset = set(s)
c = 0
for i in range(n):
    s1 = s[:i]
    s2 = s[i:]
    clst = [1 for i in sset if s1.count(i) > 0 and s2.count(i) > 0]
    tc = sum(clst)
    if tc > c:
        c = tc
print(c)

Submission status: Accepted

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


def solve(N: int, S: str):
    ans = 0
    for i in range(N):
        Z = set(S[:i]) & set(S[i:])
        ans = max(len(set(Z)), ans)
    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    solve(N, S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
x=[a for a in input()]
judge=list(set(x))
count=0
ans=[]


for j in range(N-1):
  for i in judge:
    X=x[0:j+1]
    Y=x[j+1::]
    if i in X and i in Y:
      count += 1
  else:
    ans.append(count)
    count=0
print(max(ans))

Submission status: Accepted

Solution code:
#098b
import collections
N = int(input())
S = str(input())
ans = 0
for i in range(1,N):
    Sa = S[0:i]
    Sb = S[i::]
    #print(Sa,Sb)
    Sa_counted = collections.Counter(Sa)
    Sb_counted = collections.Counter(Sb)
    common_char = set(Sa_counted.keys()) & set(Sb_counted.keys())
    #print(common_char)
    if len(common_char) > ans:
        ans = len(common_char)
        
print(ans)

Submission status: Accepted

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

ans = []
cnt = 0
for i in range(1,n):
    s1 = list(set(s[:i]))
    s2 = list(set(s[i:]))

    for j in range(len(s1)):
        for k in range(len(s2)):
            if s1[j] == s2[k]:
                cnt += 1
    ans.append(cnt)
    cnt = 0

print(max(ans))

Submission status: Accepted

Solution code:
alf = list(str('abcdefghijklmnopqrstuvwxyz'))
n = int(input())
s = str(input())
ans = 0
for i in range(len(s)):
    x = s[:i]
    y = s[i:]
    count = 0
    for j in alf:
        if j in x and j in y:
            count += 1
    if count > ans:
        ans = count
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(n):
    cnt = 0
    x = s[:i]
    y = s[i:]
    for j in range(i):
        if x[j] in y and x[j] not in x[:j]:
            cnt += 1
    if cnt >= ans:
        ans = cnt

print(ans)

Submission status: Accepted

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

ans = 0

for i in range(len(s)-1):
	k = s[0:i+1]
	t = s[i+1:len(s)]
	#print(k,t)
	maxstr = 0
	
	#文字列kの重複を削除
	k = ''.join(set(k))
	
	for j in range(len(k)):
		if t.count(k[j]) != 0:
			#print(k[j])
			maxstr = maxstr + 1
	if ans <= maxstr:
		ans = maxstr	

print(ans)

Submission status: Accepted

Solution code:
import collections

N = int(input())
S = input()
A = ''
B = S
ans = 0
for i in range(N):
  A += B[0]
  B = B[1:]
  C = collections.Counter(A)
  D = 0
  for w in C:
    if w in B:
      D += 1
  if D > ans:
    ans = D
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
X=[]
Y=[]
cnt=[]
for i in range(N-1):
    X=S[0:i+1]
    Y=S[i+1:N]
    cnt.append(len(set(X) & set(Y)))

print(max(cnt))

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

Submission status: Accepted

Solution code:
n = int(input())
s = input().strip()
ans = 0
for i in range(len(s)):
    s1 = list(set(s[:i]))
    s2 = list(set(s[i:]))
    count_inner = 0
    for c in s1:
        if c in s2:
            count_inner += 1
    ans = max(ans, count_inner)
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1,N):
    A = set(S[0:i])
    B = set(S[i:N])
    C = A & B    
    ans = max(ans,len(C))
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=str(input())
result=0

for i in range(1,N):
	valiation=0
	A=sorted(S[:i])
	B=sorted(S[i:])
	for j in range(i):
		if (j==0 or A[j]!=A[j-1]) and A[j] in B:
			valiation+=1
	result=max(result,valiation)
print(result)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = input()
ans = 0
for i in range(1,n):
    c1 = Counter(s[:i])
    c2 = Counter(s[-(n-i):])
    cnt = 0
    for c in c1:
        if c2[c] > 0:
            cnt += 1
    ans = max(ans,cnt)
print(ans)

Submission status: Accepted

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

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 = str(input())
S = []
for t in s:
    S.append(t)

ans = 0
for i in range(n):
    left = S[:i]
    right = S[i:]
    count = len(set(left) & set(right))
    if count >= ans:
        ans = count

print(ans)

Submission status: Accepted

Solution code:
##### 解けた #####

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

for sp in range(1,N):
    l=S[:sp]
    r=S[sp:]

    maxd=max(maxd,len(list(set(l)&set(r))))

print(maxd)

Submission status: Accepted

Solution code:
N = int(input())
S = list(map(str,input()))
target = len(set(S))
count = list()
for i in range(1,N):
	X = set(S[:i])
	Y = set(S[i:])
	# 対称差集合
	symmetric_difference = X ^ Y
	count.append(target - len(symmetric_difference))
	# print('X:',X,'Y:',Y)
	# print(len(symmetric_difference))
print(max(count))

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(set(x) & set(y)))

print(ans)