Problem:


Score : 200 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters.
We will cut this string at one position into two strings X and Y.
Here, we would like to maximize the number of different letters contained in both X and Y.
Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.

Constraints

2 \leq N \leq 100

|S| = N

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the largest possible number of different letters contained in both X and Y.

Sample Input 1

6
aabbca

Sample Output 1

2

If we cut the string between the third and fourth letters into X = aab and Y = bca, the letters contained in both X and Y are a and b.
There will never be three or more different letters contained in both X and Y, so the answer is 2.

Sample Input 2

10
aaaaaaaaaa

Sample Output 2

1

However we divide S, only a will be contained in both X and Y.

Sample Input 3

45
tgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir

Sample Output 3

9



Sample input:
6
aabbca


Sample output:
2

Submission status: Accepted

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

ans = 0

for i in range(1, N):
    x = S[:i]
    y = S[i:N]

    cnt = 0

    for j in range(ord('a'), ord('z') + 1):
        if chr(j) in x and chr(j) in y:
            cnt += 1
    ans = max(ans, cnt)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
maxC=0
index=0
while index<n:
    list1=[]
    list2=[]
    listForChar=[]
    index2=0
    sum=0
    while index2<index+1:
        list1.append(s[index2])
        index2+=1
    index3=index+1
    while index3<n:
        list2.append(s[index3])
        index3+=1
    for char in list1:
        if char in list2 and char not in listForChar:
            sum +=1
            listForChar.append(char)
    if sum>maxC:
        maxC=sum
    index+=1
print(maxC)

Submission status: Accepted

Solution code:
# coding:utf-8

INF = float('inf')


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

ans = 0
for i in range(1, N - 1):
    str_list = []
    score = 0

    for x in S[:i]:
        if x not in str_list: str_list.append(x)

    for xi in str_list:
        if xi in S[i:]: score += 1

    ans = max(ans, score)

print(ans)

Submission status: Accepted

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

def main():
    s = list(S)
    ans = 0
    for i in range(N):
        x = s[:i]
        y = s[i:]
        intersection = set(x) & set(y)
        ans = max(ans, len(intersection))
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())

S=str(input())
S1=""
S2=""
ans=0

for i in range(N):
    #同じ種類の単語を無視するため一度あったのはここで格納
    past=[]
    count=0
    S1="".join(S[0:i+1])
    #print(S1)
    S2="".join(S[i+1:len(S)])
    #print(S1+"と"+S2)
    for j in range(len(S2)):

        if S1.rfind(S2[j])!=-1 and not(S2[j] in past):
            
            count+=1
            past.append(S2[j])
            
    
    ans=max(ans,count)

print(ans)

Submission status: Accepted

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

maxco=0

for i in range(len(s)):
    co=0
    le=s[0:i]
    ri=s[i:len(s)]
    for j in range(i):
        if le[j] not in le[0:j] and le[j] in ri :
            co+=1
    maxco=max(maxco,co)

print(maxco)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
li_and=[]
for i in range(n):
    s_a=s[0:i+1]
    s_b=s[i+1:n]
    s_and = len(list(set(s_a) & set(s_b)))
    li_and+=[s_and]
print(max(li_and))

Submission status: Accepted

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)
  i += 1
print(max(li))

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()
A = input()
B =[i for i in A]
SUM = [0]*(len(B))
for i in range(len(B)):
    count=0
    C = B[:i]
    D = set(B[i:])
    for t in D:
        if C.count(t)>0:
            count+=1
            SUM[i] = count
print(max(SUM))

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())
atoz = [chr(i) for i in range(97,97+26)]

N = inp()
S = input()
ans = 0
for i in range(1,N):
	x = S[:i]
	y = S[i:]
	tmp = 0
	for s in atoz:
		if s in x and s in y:
			tmp += 1
	ans = max(tmp,ans)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=list(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, S = (input() for i in 'NS')
res = 0
for i in range(int(N)):
    s, t = set(S[:i]), set(S[i:])
    res = max(res, len(s.intersection(t)))
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(raw_input())
S = raw_input()
slist = []
for i in range(0, N):
	slist.append(S[i])
max = 0
for i in range(0, N):
	xlist = []
	for j in range(0, i):
		if slist[j] not in xlist:
			xlist.append(slist[j])
	ylist = []
	for j in range(i, N):
		if slist[j] not in  ylist:
			ylist.append(slist[j])
	cnt = 0
	for j in range(0, len(xlist)):
		if xlist[j] in ylist:
			cnt = cnt + 1
	if max < cnt:
		max = cnt

print max

Submission status: Accepted

Solution code:
N = int(input())
s = str(input())
types = []
for i in range(len(s)-1):
    x = list(s[:i+1])
    y = list(s[i+1:])
    x.sort()
    y.sort()
    x_str = []
    y_str = []
    count = 0
    for j in range(len(x)):
        if j == 0:
            x_str.append(x[0])
        else:
            if x[j-1] != x[j]:
                x_str.append(x[j])
    for j in range(len(y)):
        if j == 0:
            y_str.append(y[0])
        else:
            if y[j-1] != y[j]:
                y_str.append(y[j])
    for j in range(len(x_str)):
        if x_str[j] in y_str:
            count += 1
    types.append(count)
print(max(types))

Submission status: Accepted

Solution code:
def stringToCompare(x,y):
    r = []
    c = 0
    for i in range(len(y)):
        if x.count(y[i]):
            if y[i] not in r:
                c+=1
                r.append(y[i])
    return c

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

print(max([stringToCompare(S[0:i],S[i:N]) for i in range(0,N)]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#98b
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()

R = []

for i in range(N):
    s1 = list(set(list(S[:(i+1) ])))
    s2 = list(set(list(S[ (i+1):])))
    r = 0
    for s in s1:
        if (s in s2) == True:
            r += 1
    R.append(r)

print(max(R))

Submission status: Accepted

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

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

count_max=0
for i in range (N):
    left=S[:i]
    right=S[i:]
    count=0
    for j in range (len(alphabet)):
        if right.count(alphabet[j])>0 and left.count(alphabet[j])>0:
            count+=1
    if count>count_max:
        count_max=count
print(count_max)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
key = 0
Count = []
cnt = 0
for i in range(N - 1):
    for j in range(i + 1):
        for k in range(j):
            if j == 0:
                break
            if S[j] == S[k]:
                #print(j, k, end = " ")
                key = 1
                break
            
        if key == 0:
            for k in range(i + 1, N):
               if S[j] == S[k]:
                    cnt += 1
                    #print(S[j], end = " ")
                    break

        key = 0
            
    Count.append(cnt)
    #print()
    cnt = 0

print(max(Count))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
Q = []
for i in range(1,N) :
    A = S[0:i]
    B = S[i:N+1]
    A = list(set(A))
    q = 0
    for j in range(len(A)) :
        if A[j] in B :
            q += 1
        Q.append(q)
print(max(Q))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for x in range(N):
    X = S[:x]
    Y = S[x:]
    temp = len(set(X) & set(Y))
    if temp > ans:
        ans = temp
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for x in range(N):
    X = S[:x]
    Y = S[x:]
    temp = len(set(X) & set(Y))
    if temp > ans:
        ans = temp
print(ans)

Submission status: Accepted

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

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

    for j in range (i,n):
        right.add(s[j])
    
    both=right&left
    ans=max(ans,len(both))
    

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
LS = list(S)
count = 0
hantei = 0
alfabetto = [
"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):
    RLS = LS[0 : i]
    LLS = LS[i : N]

    for alfa in alfabetto:
        if (alfa in RLS) and (alfa in LLS):
            count += 1
    if hantei < count:
        hantei = count
    count = 0

print(hantei)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
ans=0
for i in range(1,N-1):
    X = S[:i]
    Y = S[i:]
    Z = set(X) & set(Y)
    if len(Z) > ans :
        ans = len(Z)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
ans=0
for i in range(N):
    X = S[:i]
    Y = S[i:]
    Z = set(X) & set(Y)
    if len(Z) > ans :
        ans = len(Z)
print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    left = S[:i]
    right = S[i:]
    count_left = collections.Counter(left)
    count_right = collections.Counter(right)
    count_left_unique = list(count_left.keys())
    count_right_unique = count_right.keys()
    cnt = 0
    for j in range(len(count_left_unique)):
        if(count_left_unique[j] in count_right_unique):
            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 = set(s[:i])
  y = set(s[i:])
  total = len(x & y)
  if total > ans:
    ans = total
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:])
    c = a & b
    ans = max(ans, len(c))
print(ans)

Submission status: Accepted

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


print(max(len(set(x).intersection(set(y))) for x,y in [(S[:i],S[i:]) for i in range(1, len(S))]))

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

l_dict = {}
r_dict = {}

for c in s:
	r_dict[c] = 0
	l_dict[c] = 0

for c in s:
	r_dict[c] += 1

ans = 0
for c in s:
	l_dict[c] += 1
	r_dict[c] -= 1

	count = 0
	for k, v in l_dict.items():
		if v > 0:
			if r_dict[k] > 0:
				count += 1

	ans = max(ans, count)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
c = 0
list_s = [sorted(list(set(s[:i]))) for i in range(1,n)]
list_l = [sorted(list(set(s[i:]))) for i in range(1,n)]
print(max([sum([1 if list_s[j][i] in list_l[j] else 0 for i in range(len(list_s[j]))]) for j in range(n-1)]))

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

Submission status: Accepted

Solution code:
res = -float('inf')
n=int(input())
s=input()
for i in range(1,n):
    tmp = 0
    x=s[:i]
    y=s[i:]
    for c in [chr(i) for i in range(97,97+26)]:
        tmp += (c in x) and (c in y)
    res = max(res,tmp)
print(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:
import sys

#a, b = map(int, input().split(" "))
N = int(input())
S = input()

ans = 0
for i in range(1, N):
	max_len = 0
	for asc in range(ord("a"), ord("z")+1):
		flag = False
		for j in range(i):
			if ord(S[j]) == asc:
				for k in range(i,N):
					if ord(S[k]) == asc:
						flag = True
						break
		if not(flag):
			continue
		max_len += 1
		#print(str(i)+" "+str(chr(asc))+str(max_len))
	ans = max(max_len, ans)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
ans_max = 0
for i in range(n):
    ans = 0
    s1 = s[0:i]
    s2 = s[i:n]
    for k in range(i):
        if s1[k] in s2:
             s1 = s1.replace(s1[k]," ")
             ans += 1
    if ans_max < ans:
        ans_max = ans
print(ans_max)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8
n = int(input())
alpha = dict.fromkeys(list("abcdefghijklmnopqrstuvwxyz"),0)
string = input()
for i in range(n):
    alpha[string[i]] += 1

keys = list(alpha.keys())
for key in keys:
    if alpha[key] == 0:
        del alpha[key]
Q = []
maxv = 0
for i in range(n):
    if string[i] not in Q:
        Q.append(string[i])
    alpha[string[i]] -= 1
    if alpha[string[i]] == 0:
        del alpha[string[i]]
    keys = list(alpha.keys())
    cnt = 0
    for ch in Q:
        if ch in keys:
            cnt += 1
    maxv = max(maxv, cnt)

print(maxv)

Submission status: Accepted

Solution code:
#標準入力
N = int(input())
S = input()

Max_count = 0
#処理
for i in range(1, N):
  temporary_count = len(set(S[i:]) & set(S[:i]))
  if temporary_count > Max_count:
    Max_count = temporary_count
    
print(Max_count)

Submission status: Accepted

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

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

print(max_same_count)

Submission status: Accepted

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

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

a = []

for i in range(1, N):
    f1 = set(S[0:i])
    f2 = set(S[i:N])
    a.append(len(f1 & f2))

print(max(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N=int(input())
S=input()
a=[]
for i in range(N):
    a.append(set(S[0:i])&set(S[i:N]))
b=[]
for j in range(N):
    b.append(len(a[j]))
print(max(b))

Submission status: Accepted

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

res=0
for i in range(N-1):
    SL = list(set(S[:(i+1)]))
    SR = list(set(S[(i+1):]))
    cnt = 0 
    for s1 in SL:
        for s2 in SR:
            if s1==s2 : cnt += 1
    res = max(res,cnt)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python

N = int(raw_input())
S = str(raw_input())

counter = 0
ans = 0

for i in range(N):
	X = list(S[:i])
	Y = (S[i:])

	sorted(X)
	sorted(Y)

	X = list(set(X))
	Y = list(set(Y))

	for j in range(len(X)):
		if(str(Y).find(X[j]) != -1):
			counter += 1
	if(counter > ans):
		ans = counter
	counter = 0

print ans

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

res = 0 
for i in range(n):
    temp = 0 
    c1 = Counter(s[:i])
    c2 = Counter(s[i:])
    for c in c1.keys():
        if c in c2.keys():
            temp += 1
    if temp > res:
        res = temp
print(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=list(input())
a=[]

for i in range(1,N):
    x=set(S[:i-1:])
    y=set(S[i-1::])
    a.append(len(list(x&y)))
    
print(max(a))

Submission status: Accepted

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

def main():
    N = int(input())
    S = input()

    str_list = list(set(S))
    max_cnt = 0
    
    for i in range(1, N):
        cnt = 0
        first_str = S[:i]
        last_str = S[i:]

        for j in str_list:
            if j in first_str and j in last_str:
                cnt += 1
        if cnt > max_cnt:
            max_cnt = cnt
    
    print(max_cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# --------------------------------------------

dp = None

def main():
    N = int(input())
    S = input()

    ans = 0

    div = 1
    while div < len(S) - 1:
        front, rear = set(list(S[:div])), set(list(S[div:]))
        kind = len(front & rear)

        ans = max(ans, kind)

        div += 1

    print(ans)

main()

Submission status: Accepted

Solution code:
N = int(input())
S = input()
output=[]
for i in range(1, N):
	L = list(S[0:i])
	R = list(S[i:N])
	temp=[]
	for j in L:
		if j in R and not j in temp:
			temp.append(j)
	output.append(len(temp))
print(max(output))

Submission status: Accepted

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

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

print(max)

Submission status: Accepted

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


max = 0
for i in range(1,n):
    xs = set(s[:i])
    ys = set(s[i:])
    l = len(xs&ys)
    if l > max:
        max = l

print(max)

Submission status: Accepted

Solution code:
# your code goes here
N=int(input())
s=list(input())
a = []

for i in range(1,N):
	x = set(s[0:i-1:])
	y = set(s[i-1::])
	a.append(len(list(x&y)))

print(max(a))

Submission status: Accepted

Solution code:
N = int(input())
*S, = list(input())
A = [chr(i) for i in range(97, 97+26)]
K = 0
for L in range(1,N):
    cnt = 0
    for alpha in A:
        if alpha in S[:L] and alpha in S[L:]:
            cnt += 1
    K = max(K,cnt)
print(K)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
abc = 'abcdefghijklmnopqrstuvwxyz'

ans = 0
for i in range(1,N):
    left = S[:i]
    righ = S[i:]
    tmp = 0
    for ch in abc:
        if ch in left and ch in righ:
            tmp += 1
    if tmp > ans:
        ans = tmp

print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())
s = raw_input()
same = 0
for i in range(1, n-1):
  left = set(s[:i])
  right = set(s[i:])
  union = left & right
  if len(union) > same:
    same = len(union)
print(same)

Submission status: Accepted

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

results = []
for i in range(n):
    cnt = 0
    for v in setn:
        if v in s[:i] and v in s[i:]:
            cnt += 1
    results.append(cnt)
print(max(results))

Submission status: Accepted

Solution code:
n = int(input())
st = input()
b = 0
for i in range(n):
    k = list(set(st[:i]))
    u = 0
    for j in range(len(k)):
        if k[j] in st[i:]:
            u += 1
    if u > b:
        b = u
print(str(b))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
count_max=0
for i in range(1,N):
    X=S[:i]
    Y=S[i:]
    count=0
    character_in_X=[]
    for character in X:
        if character not in character_in_X:
            character_in_X.append(character)
    for character in character_in_X:
        if character in Y:
            count+=1
    count_max=max(count, count_max)
print(count_max)

Submission status: Accepted

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

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

ans = 0
for i in range(1, N):

    str1 = S[:i]
    str2 = S[i:]
    list1 = list(set(str1))
    list2 = list(set(str2))

    tmp = 0
    for s in list1:
        if s in list2:
            tmp += 1
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
input()
s = input()
r = 0
for i in range(1,len(s)-1):
  r = max(r, len([k for k in list(set(s[:i])) if k in s[i:]]))
print(r)

Submission status: Accepted

Solution code:
def same_count(str_list):
    standard_str = min(str_list, key=lambda x: len(x))
    return [all([c in str_ for str_ in str_list]) for c in set(standard_str)].count(True)

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

print(max([same_count([s[:i+1], s[i+1:]]) for i in range(n)]+[0]))

Submission status: Accepted

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

for i in range(N+1):
    X = set(S[:i])
    Y = set(S[i:])
    Z = X & Y
    if len(Z) > ans:
        ans = len(Z)

print(ans)

Submission status: Accepted

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

j=0
for i in range(n-1):
	k=set([s[m] for m in range(i+1)])&set([s[n-1-m] for m in range(n-i-1)])
	if j<len(k):
		j=len(k)
print(j)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N):
	f = set(S[:i])
	b = set(S[i:])
	if ans < len(f & b):
		ans = len(f & b)
print(ans)

Submission status: Accepted

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

amax = 0
for i in range(1, N):
    count = 0
    for s in set(S[:i]):
        if s in S[i:]:
            count += 1
    amax = max(amax, count)
print(amax)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = input()
n = -1
for i in range(1,len(s)):
    a = s[:i]
    b = s[i:]
    n = max(n, len(set(Counter(a).keys() & Counter(b).keys())))

print(n)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N):
	f = set(S[:i])
	b = set(S[i:])
	if ans <= len(f & b):
		ans = len(f & b)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N):
	f = set(S[:i])
	b = set(S[i:])
	if ans <= len(set(f & b)):
		ans = len(set(f & b))
print(ans)

Submission status: Accepted

Solution code:
def solve(ls, rs, ans):
    if len(rs) == 0:
        return ans
    ans = max(ans, len(set(ls).intersection(set(rs))))
    return solve(ls + [rs[0]], rs[1:], ans)

if __name__ == "__main__":
    n = int(input())
    s = input()
    print(solve([], s, 0))

Submission status: Accepted

Solution code:
input()
str=input()
r=[]

for i in range(1,len(str)):
  s1=set(str[0:i])
  s2=set(str[i:])
  r.append(len(s1&s2))

print(max(r))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input()) 
result_list = [] 
for i in range(N): 
    X = S[:i] 
    Y = S[i:] 
    counter = 0 
    old_list = [] 
    for j in X: 
        if j in Y and not(j in old_list): 
            counter += 1 
            old_list.append(j) 
            result_list.append(counter) 
if result_list == []:
    print(0)
else:
    print (max(result_list))

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
Count = 0
for i in range(n):
    f = list(set(s[:(i+1)]))
    r = list(set(s[(i+1):]))
    count = 0
    for j in range(len(f)):
        for k in range(len(r)):
            if f[j] == r[k]:
                count += 1
    if Count < count:
        Count = count
print(Count)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
count_M=0
for i in range(N):
	SR=S[(i+1):]
	SL=S[:(i+1)]
	count = 0
	for j in range(len(SL)):
		for k in range(len(SR)):
			if(SL[j] == SR[k]):
				count+=1
				SR=SR.replace(SR[k],' ')
	
	if(count_M < count):
		count_M=count

print(count_M)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
x=[]
y=list(s)
k=0
for i in range(n):
    x.append(s[i])
    del y[0]
    xn=list(set(x))
    yn=list(set(y))
    t=0
    for a in xn:
        for b in yn:
            if a==b:
                t+=1
                k=max(k,t)
print(k)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0

for n in range(N):
    x = 0
    Sl = S[:n]
    Sr = S[n:]
    for a in set(S):
        if a in Sl and a in Sr:
            x += 1
    if count < x:
        count = x

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
max_found = 0
for i in range(1,N):
    found = 0
    s1 = S[:i]
    s2 = S[i:]
    for s in set(s1):
        if s in s2:
            found += 1
    if max_found < found:
        max_found = found
print(max_found)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    S = input()

    res = 0
    for i in range(N):
        sub1 = set(S[:i])
        sub2 = set(S[i:])

        if len(sub1 & sub2) > res:
            res = len(sub1 & sub2)

    print(res)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N):
	f = set(S[:i])
	b = set(S[i:])
	if ans < len(set(f & b)):
		ans = len(set(f & b))
print(ans)

Submission status: Accepted

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

common = 0
for i in range(1,len(s)+1):
    common = max(common, len(set(s[:i]).intersection(set(s[i:]))))

print(common)

Submission status: Accepted

Solution code:
N = int(input())
S = [x for x in input()]
ans = 0

#SL,SR = S[:3],S[3:]

#print(S,SL,SR)

for i in range(1,N+1):
    SL,SR = S[:i],S[i:]
    count = 0
 #   print(SL,SR,count)
    while SL != [] and SR != []:
        if SL[0] in SR:
            count += 1
            a = SL[0]
            while a in SL and a in SR:
                SL.remove(a)
                SR.remove(a)
 #               print(SL,SR)
        elif SL[0] not in SR:
            a = SL[0]
            while a in SL:
                SL.remove(a)

#    print(count)

    if count >= ans:
        ans = count


print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [x[:1] for x in input()]
ans = 0

#SL,SR = S[:3],S[3:]

#print(S,SL,SR)

for i in range(1,N+1):
    SL,SR = S[:i],S[i:]
    count = 0
 #   print(SL,SR,count)
    while SL != [] and SR != []:
        if SL[0] in SR:
            count += 1
            a = SL[0]
            while a in SL and a in SR:
                SL.remove(a)
                SR.remove(a)
 #               print(SL,SR)
        elif SL[0] not in SR:
            a = SL[0]
            while a in SL:
                SL.remove(a)

#    print(count)

    if count >= ans:
        ans = count


print(ans)