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:
def examB():
    N = I()
    S = SI()
    cur = 0
    for i in range(N-1):
        d1 = set()
        d2 = set()
        for j in S[:i]:
            d1.add(j)
        for j in S[i:]:
            d2.add(j)
        curS = d1&d2
        cur = max(cur,len(curS))
    print(cur)


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

Submission status: Accepted

Solution code:
A = int(input())
B = input()
m = 0
for i in range(A):
  c = set(B[:i])
  a = set(B[i:])
  l = a & c
  m = max(m,len(l))
print(m)

Submission status: Accepted

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

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:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n=int(input())
s=input()
for i in range(1,n):
    A=set(s[:i])
    B=set(s[i:])
    for ai in A:
        if ai in B:
            count+=1
    ans=max(ans,count)
    count=0
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f(s, t):
    return len(set(s) & set(t))

N = int(input())
S = input()
ans = 0
for i in range(N):
    ans = max(ans, f(S[:i], S[i:]))
print(ans)

Submission status: Accepted

Solution code:
def f(s, t):
    res = 0
    for i in set(s):
        for j in set(t):
            if i == j:
                res += 1
    return res

N = int(input())
S = input()
ans = 0
for i in range(N):
    ans = max(ans, f(S[:i], S[i:]))
print(ans)

Submission status: Accepted

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

x=[0]*n
for c in "abcdefghijklmnopqrstuvwxyz":
  b,e=s.find(c),s.rfind(c)
  if b!=e:
    for i in range(b,e+1):
      x[i]+=1

print(max(x))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
max_num = 0
for i in range(1, n):
  s_1 = s[:i]
  s_2 = s[i:]
  temp = len(set(s_1) & set(s_2))
  if temp > max_num:
    max_num = temp
print(max_num)

Submission status: Accepted

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

ans = 0
for i in range(n):
    a = s[:i]
    b = s[i:]
    tmp = len(set(a) & set(b))
    if ans < tmp:
        ans = tmp

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N = int(input())
    S = input()
    max_score = 0
    for i in range(N):
        left = "".join(set(S[:i]))
        right = "".join(set(S[i:]))
        score = 0
        for i in range(len(left)):
            if left[i] in right:
                score += 1
        max_score = max(max_score,score)
    print(max_score)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(1,n-1):
    a = Counter(s[:i])
    b = Counter(s[i:])
    cnt = 0
    for k in a.keys():
        if k in b:
            cnt += 1
    if cnt > ans:
        ans = cnt
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
S = input()

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 = input()
ans = 0
for i in range(1,len(S)):
    X = S[:i]
    Y = S[i:]
    dic = {}
    for j in X:
        if( (j in Y) == True):
            dic[j] = 0
        ans = max(ans,len(dic))
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
s = [str(i) for i in s]

ma = 0
for i in range(len(s)):
    point = 0
    fi = list(set(s[:i]))
    la = list(set(s[i:]))
    for j in fi:
        if j in la:
            point += 1
    ma =  max(ma,point)

print(ma)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
k = len(set(S))

count = 0
for i in range(1, N-k+1):
    X = set(S[:i])
    Y = set(S[i:])
    c = sum([1 if x in Y else 0 for x in X])
    count = c if c > count else count

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

set_s = set(s)
the_number = 0

for i in range(1, n):
    the_number_of_this_cut = 0

    x = set(list(s[:i]))
    y = set(list(s[i:]))

    for letter in set_s:
        if letter in x and letter in y:
            the_number_of_this_cut += 1
    
    the_number = max(the_number, the_number_of_this_cut)

print(the_number)

Submission status: Accepted

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

ans = 0
for i in range(N):
    left = []
    right = []
    for j in range(N):
        if j <= i:
            if S[j] not in left:
                left.append(S[j])
        else:
            if S[j] not in right:
                right.append(S[j])
    tmp_ans = 0
    for j in range(len(left)):
        if left[j] in right:
            tmp_ans += 1
    ans = max(ans, tmp_ans)
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

value=0
ord("a")
for i in range(1,N):
    data1=[0 for i in range(ord("z")-ord("a")+1)]
    data2=[0 for i in range(ord("z")-ord("a")+1)]
    for s in S[:i]:
        data1[ord(s)-ord("a")]+=1
    for s in S[i:]:
        data2[ord(s)-ord("a")]+=1

    value=max(len([1 for i,m in zip(data1,data2) if i and m]),value)
print(value)

Submission status: Accepted

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

for i in range(n-1):
  temp = len(set(list(S[0:i+1]))&set(list(S[i+1:n])))
  if temp > counter:
    counter = temp

print(counter)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
res= 0
for i in range(n-1):
    tres= 0
    x = s[:i+1]
    y = s[i+1:]
    l=[]
    for c in x:
        if not (c in l) and (c in y):
            l.append(c)
            tres += 1
    res = max(res,tres)

print(res)

Submission status: Accepted

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

max_count = 0  
for i in range(N):
  l = S_list[i:]
  cs = set(S_list[0:i])
  
  count = 0
  for s in cs:
    if s in l:
      count += 1
    if count > max_count:
      max_count = count
print(max_count)

Submission status: Accepted

Solution code:
n=int(input())
a=input()
cnt=0
for i in range(n-1):
    seta=set(a[:i+1])
    setb=set(a[i+1:])
    tmp=len(seta&setb)
    cnt=max(cnt,tmp)
print(cnt)

Submission status: Accepted

Solution code:
import collections
n = int(input())
S = 0
s = input()
maximum = 0
for i in range(n):
  l = s[:i]
  r = s[i:]
  c = collections.Counter(l)
  c = c.most_common()
  for j in range(len(c)):
    if c[j][0] in r:
      S += 1
  maximum = max(maximum,S)
  S = 0
print(maximum)

Submission status: Accepted

Solution code:
import string

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

ans = 0

for i in range(1, N):
    cnt = 0
    for j in string.ascii_lowercase:
        if j in S[:i] and j in S[i:]:
            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(n):
    ctn = 0
    x = set(s[:i])
    y = set(s[i:])
    for j in x:
        if j in y:
            ctn += 1
    if ans < ctn:
        ans = ctn
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
counter = 0
for i in range(N):
    syu = len(set(S[:i]) & set(S[i:]))
    counter = syu if syu > counter else counter

print(counter)

Submission status: Accepted

Solution code:
n = int(input())
line = input()
a = []
b = []
max = 0

for i in range(0, n):
  a.clear()
  b.clear()
  for j in range(0, i):
  	a.append(line[j])
  for k in range(i, n):
    b.append(line[k])
    
  if (len(set(a) & set(b)) > max):
    max = len(set(a) & set(b))

print(max)

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
S=one_str()

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

print(maxs)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

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

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-07 23:33:56(JST)
## internal modules
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## external modules
# import scipy.special   # if use comb function on AtCoder, 
# import scipy.misc      # select scipy.misc.comb (old version) 

def main():
    n = int(sys.stdin.readline().rstrip())
    s = sys.stdin.readline().rstrip()

    max_count = 0
    for i in range(1, n):
        s1, s2 = s[:i], s[i:]
        count = 0
        for l in set(s1):
            if l in s2:
                count += 1
        max_count = max(count, max_count)
    
    print(max_count)





if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    S = input().strip()
    ma = 0
    for i in range(1, len(S)-1):
        ma = max(ma, len(set(S[:i]) & set(S[i:])))
    print(ma)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = input()
res = 0
for i in range(n):
    cnt = 0
    d1 = defaultdict(int)
    d2 = defaultdict(int)
    for j in range(0,i):
        d1[s[j]] += 1
    for j in range(i,n):
        d2[s[j]] += 1
    for key in d1.keys():
        if d2[key] > 0:
            cnt += 1
    res = max(res, cnt)
print(res)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
hsh1,hsh2 = [0]*26,[0]*26

hsh1[ord(s[0])-97]+=1
for i in range(1,n):
    hsh2[ord(s[i])-97]+=1
ans=0
ct=0
for i in range(26):
    if(hsh1[i]!=0 and hsh2[i]!=0):
        ct+=1
ans = max(ans,ct)

for i in range(1,n-1):
    ct=0
    cur = ord(s[i])-97
    hsh2[cur]-=1
    hsh1[cur]+=1
    for j in range(26):
        if(hsh1[j]!=0 and hsh2[j]!=0):
            ct+=1
    ans = max(ans,ct)
print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
Y = list(input())
X = []
ans = 0
for n in range(N):
    X.append(Y.pop(0))
    X_and_Y = set(X) & set(Y)
    ans = max(ans,len(X_and_Y))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
S=str(input())
result = 0
for i in range(N-1):
    S_1=set(S[:i+1])
    S_2=set(S[i+1:])
    result =max(result,len(S_1&S_2))
print(result)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    S = list(input()[:-1])

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
s1 = ''
s2 = ''

for i in range(1, n):
    s1 = set(s[:i])
    s2 = set(s[i:])
    tmp = 0
    for c in s1:
        if(c in s2):
            tmp += 1
    if(ans < tmp):
        ans = tmp

print(ans)

Submission status: Accepted

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

cnt_max = 0
for i in range(N):
    cnt = len(set(S[:i])&set(S[i:]))
    if cnt > cnt_max:
        cnt_max = cnt

print(cnt_max)

Submission status: Accepted

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

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

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(S[:i+1]) & set(S[i+1:]))))
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

for i in range(N):
    sl = set()
    sr = set()

    for j, char in enumerate(S):
        if j <= i:
            sl.add(char)
        else:
            sr.add(char)
    
    if len(sl & sr) > max_kind:
        max_kind = len(sl & sr)

print(max_kind)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from string import ascii_lowercase

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import string

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

ans = 0
for n in range(1, N):
  counts = 0
  for c in string.ascii_lowercase:
    if c in S[:n] and c in S[n:]:
      counts += 1
  ans = max(counts, ans)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
s = [str(si) for si in s]
ans = [0 for _ in range(n)]
for i in range(1, n):
    sp = s[:i]
    sp.sort()
    ss = s[i:]
    tmp = ""
    for j in sp:
        if j == tmp: continue
        else:
            if j in ss:
                ans[i] += 1
                tmp = j
print(max(ans))

Submission status: Accepted

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

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

print(m)

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:
import sys

#+++++

def cc(sa, sb):
	aa=set(list(sa))
	bb=list(set(list(sb)))
	count=0
	for c in bb:
		if c in aa:
			count+=1
	return count


def main():
	n=int(input())
	s=input()
	ans=0
	for i, _ in enumerate(s):
		ans=max(ans, cc(s[:i], s[i:]))
	
	print(ans)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
count = 0
for i in range(N):
    tmpcount = 0
    tmp1 = list(set(S[:i]))
    tmp2 = list(set(S[i:]))
    for j in range(len(tmp1)):
        if tmp1[j] in tmp2:
            tmpcount += 1
    if tmpcount >= count:
        count = tmpcount
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#2019/10/25
N, S = open(0).readlines()
S = list(S)
# print(N,S)
# print(S[:2], S[2:], set(S[:2]) & set(S[2:]))
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()

max_kinds = 0
for i in range(N):
  kinds = len(set(S[:i]) & set(S[i:]))
  if kinds > max_kinds:
    max_kinds = kinds
    
print(max_kinds)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

minind={}
maxind={}

for i,c in enumerate(S):
    if c not in minind:
        minind[c]=i
    maxind[c]=i

cnt=[0 for i in range(N+1)]

for c in [chr(i) for i in range(97,97+26)]:
    if c in minind and minind[c]<maxind[c]:
        for j in range(minind[c]+1,maxind[c]+1):
            cnt[j]+=1

print(max(cnt))

Submission status: Accepted

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

Submission status: Accepted

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

def f(x, y):
  a = 0
  for i in range(97, 97+26):
    k = chr(i)
    if k in x and k in y:
      a += 1
  return a

a = 0
for i in range(1, n-1):
  a = max(a, f(s[:i], s[i:]))
print(a)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

def mojisu(s1, s2):
    c = collections.Counter(s1)
    cnt = 0
    for c in c.keys():
        if c in s2:
            cnt += 1
    return cnt

m = 0
for i in range(1,N):
    _ = mojisu(S[:i], S[i:])
    if m < _:
        m = _
print(m)

Submission status: Accepted

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

for s in range(1,t):
    a=set(S[0:s])
    b=set(S[s:])
    cnt=0
    for chr in a:
        if chr in b:cnt+=1
    if cnt>ans: ans=cnt
print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = [i for i in input()]
m = 0
for i in range(1,n):
    x = s[0:i]
    y = s[i:n]
    c1 = collections.Counter(x)
    c2 = collections.Counter(y)
    d1 = set(c1.keys())
    d2 = set(c2.keys())
    e = list(d1 & d2)
    m = max(m,len(e))
print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def retNumOfCommonCharacters(left: str, right: str) -> int:
    cnt = 0
    for l in left:
        if l in right:
            cnt += 1

    return cnt

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

ans = 0
for i in range(1, n):
    num = retNumOfCommonCharacters(set(s[0:i]), set(s[i:]))
    if ans <= num:
        ans = num

print(ans)

Submission status: Accepted

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

    ans = 0
    for i in range(1, n):
        count = 0
        left = s[:i]
        right = s[-(n - i):]
        left_set = list(set(left))
        right_set = list(set(right))

        if left_set >= right_set:
            for j in range(len(right_set)):
                if right_set[j] in left_set:
                    count += 1
        else:
            for k in range(len(left_set)):
                if left_set[k] in right_set:
                    count += 1

        ans = max(count, ans)

    print(ans)


if __name__ == '__main__':
    cut_and_count()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import string

N = int(input())
S = input()
cnt = 0
for i in range(1, N):
  s1 = S[:i]
  s2 = S[i:]
  tmp = 0
  for j in string.ascii_lowercase:
    if j in s1 and j in s2:
      tmp += 1
  cnt = max(cnt, tmp)
print(cnt)

Submission status: Accepted

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

cnt = 0

for i in range(1, len(s) - 1):
    int_cnt = len(set(s[:i]) & set(s[i:]))
    if int_cnt > cnt:
        cnt = int_cnt

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

tmp_list = []
for i in range(1,N):
    S1 = S[:i]
    S2 = S[i:]
    tmp_list.append(len(set(S1)&set(S2)))

print(max(tmp_list))

Submission status: Accepted

Solution code:


def resolve():
    input()
    s=[i for i in input()]

    mx=0
    for i in range(len(s)):
        A=set(s[:i])
        B=set(s[i:])
        AB=list(A & B)

        mx=max(mx,len(AB))
    print(mx)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N = int(input())
s = list(input())
result = 0

for i in range(N):
  result = max(result, len(set(s[:i]) & set(s[i:])))

print(result)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
max_count = 0
for i in range(1, N-1):
    ans = []
    cnt = 0
    for j in S[:i]:
        if j not in ans and j in S[i:]:
            ans.append(j)
            cnt += 1
    if cnt > max_count:
        max_count = cnt

print(max_count)

Submission status: Accepted

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

max_len = 0

for i in range(1, n+1):
  l = set(s[:i])
  r = set(s[i:])
  
  if max_len < len(l&r): max_len = len(l&r)
    
print(max_len)

Submission status: Accepted

Solution code:
len = int(input())
ret = input()
count_max = 0
for i in range(1, len):#全ての場所での分割を試す
  count = 0
  for k in range(97, 123):#それぞれのアルファベットがそれぞれの部分に含まれるか検証(アスキーコードを用いる）
    if ((chr(k) in ret[:i]) and (chr(k) in ret[i:])):
      count += 1
  if count > count_max:
    count_max = count
print(count_max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
k = list(x for x in input())
ans = [0] * n
for i in range(n):
  l = []
  for j in range(0,i):
    if l.count(k[j]) == 0:
      l.append(k[j])
      if k[i:n].count(k[j]) > 0:
        ans[i] += 1
print(max(ans))

Submission status: Accepted

Solution code:
import copy
n=int(input())
s=list(input())
x=[]
y=copy.copy(s)
num=0
for i in range(n):
    x+=[s[i]]
    y.pop(0)
    if len(set(x)&set(y))>num:
        num=len(set(x)&set(y))
    
print(num)

Submission status: Accepted

Solution code:
import collections
n=int(input())
s=input()
max=0
for i in range(1,n):
    cnt=0
    x = set(s[:i])
    y = set(s[i:])
    for item in x:
        if item in y:
            cnt += 1
    if cnt > max:
        max = cnt
print(max)

Submission status: Accepted

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

for i in range(1, n):
    x = set(s[0:i:])
    y = set(s[i::])
    count = 0
    for k in x:
        for l in y:
            if k == l:
                count += 1

    if count > output:
        output = count

print(output)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for i in range(n-2):
  ans=max(ans,len(set(s[:i+1])&set(s[i+1:])))
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:
import collections
N=int(input())
S =input()
def countchar(s1,s2):
  ret=0
  table=collections.defaultdict(int)
  for x in s1:
    table[x]+=1
  for x in s2:
    if x in table and table[x]>0:
      ret+=1
      table[x]=0
  return(ret)
ans=0
for i in range(1,N):
  X=S[:i]
  Y=S[i:]
  ans=max(ans,countchar(X,Y))
print(ans)

Submission status: Accepted

Solution code:
import string
n=int(input())
s=list(input())
cnt=[0 for i in range(n-1)]
for i in range(n-1):
    for j in string.ascii_lowercase:
        if (j in s[:i+1] and j in s[i+1:]): cnt[i]+=1
print('{0}'.format(max(cnt)))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ans=0
for i in range(n-1):
    left=set([])
    right=set([])
    for x in range(n):
        if x <= i :
            left.add(s[x])
        else:
            right.add(s[x])
    ans=max(ans,len(left & right))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1,n - 1):
    cnt = 0
    for j in range(0,26):
        a = b = False
        for k in range(0,n):
            if ord(s[k]) == j + ord('a'):
                if k < i:
                    a = True
                else:
                    b = True
        if a and b:
            cnt += 1
    ans = max(ans,cnt)
print(ans)