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:
_ = input()
s = input()

max_chars = 0
for i in range(1, len(s)):
    x = s[:i]
    y = s[i:]
    # print(x, y)

    cnt = 0
    for char in set(x):

        if char in y:
            cnt += 1
        max_chars = max(max_chars, cnt)

print(max_chars)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
m = 0
for n in range(N-1):
    S1 = set(S[0:n+1])
    S2 = set(S[n+1:])
    S3 = S1 & S2
    m = max(m, len(S3))

print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, S = int(input()), input()
res = 0
def cmn_chars(A, B):
    a_set, b_set = set(A), set(B)
    return len(a_set.intersection(b_set))

res = cmn_chars(S[:len(S)//2], S[len(S)//2:])

for idx in range(res, len(S) - res):
    res = max(cmn_chars(S[:idx], S[idx:]), res)

print(res)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = list(input())
r = 0
for i in range(n):
  s1 = set(s[:i+1])
  s2 = set(s[i+1:])
  r = max(r, len(s1.intersection(s2)))
print(r)

Submission status: Accepted

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

R = -1
for n in range(1, N):
    R = max(len(set(S[:n]) & set(S[n:])), R)

print(R)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
cnt = 0
for i in range(N):
    temp = 0
    a = set(S[:i])
    b = set(S[i:])
    for j in a:
        if j in b:
            temp += 1
    if temp > cnt:
        cnt = temp
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
maxans = 0
for i in range(1, N):
    Xs = set([c for c in S[:i]])
    Ys = set([c for c in S[i:]])
    maxans = max(len(Xs.intersection(Ys)), maxans)

print(maxans)

Submission status: Accepted

Solution code:
# your code goes here
N = int(input())

text = input()

ans = -1
for i in range(N-1):
	X = text[0:i+1]
	Y = text[i+1:N]
	X_alpha = [0]*27
	Y_alpha = [0]*27
	for x in X:
		X_alpha[ord(x)-ord("a")] = 1
	for y in Y:
		Y_alpha[ord(y)-ord("a")] = 1
		
	for j in range(27):
		X_alpha[j] = X_alpha[j] * Y_alpha[j]
	
	ans = max(ans,sum(X_alpha))
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

S = list(input())

result = 0
for i in range(1, N - 1):
    left_S = list(set(S[:i]))
    right_S = list(set(S[i:]))
    tmp = 0
    for j in left_S:
        if j in right_S:
            tmp += 1

    result = max(result, tmp)

print(result)

Submission status: Accepted

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

b = 0

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

Submission status: Accepted

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

ans = 0

for i in range(N):
    X = S[:i]
    Y = S[i:]
    res = 0
    
    X = set(X)
    Y = set(Y)
    
    for j in X:
        if j in Y:
            res += 1
            
    ans = max(ans, res)
    
print(ans)

Submission status: Accepted

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

strMap = {}
for i in range(0,N):
    if S[i] not in strMap.keys():
        strMap[S[i]] = [i]
    else:
        if len(strMap[S[i]]) == 1:
            strMap[S[i]].append(i)
        else:
            strMap[S[i]][1] = i

max = -10

for i in range(len(S)):
    thisSum = 0
    for key in strMap.keys():
        if len(strMap[key]) > 1:
            if strMap[key][0] <= i and i <= strMap[key][1]:
                thisSum += 1
    if thisSum > max:
        max = thisSum

print(max)

Submission status: Accepted

Solution code:
def abc098_b():
    import numpy as np
    n = int(input())
    s = input()
    counts = []
    if len(s) == 2:
        return [0,1][s[0] == s[1]]
    for i in range(1, n - 1):
        x = s[:i]
        y = s[i:]
        count = 0
        for let in set(x):
            if let in set(y):
                count += 1
        counts.append(count)
    return np.max(counts)


print(abc098_b())

Submission status: Accepted

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

max_char = 0
for k in range(1, N):
    num_of_char = len(set(S[:k]) & set(S[k:]))
    if max_char < num_of_char:
        max_char = num_of_char
print(max_char)

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)

Submission status: Accepted

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

Submission status: Accepted

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

alphabet = "abcdefghijklmnopqrstuvwxyz"

ans = 0
for i in range(N):
        ans_tmp = 0
        for c in alphabet:
                if (c in S[:i]) and (c in S[i:]):
                        ans_tmp += 1
        if ans < ans_tmp:
                ans = ans_tmp

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(n):
    a = list(set(s[:i]))
    b = list(set(s[i:]))
    sum = 0
    dict = {}
    for j in a:
        if j in dict:
            dict[j] += 1
        else:
            dict[j] = 1
    for j in b:
        if j in dict:
            dict[j] += 1
        else:
            dict[j] = 1
    for j in dict.values():
        if j >= 2:
            sum += 1
    ans = max(ans,sum)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
out=0
for i in range(n-1):
    num=len(set(list(s)[:i+1]).intersection(set(list(s)[i+1:])))
    if num>out:
        out=num
print(out)

Submission status: Accepted

Solution code:
def count(a, b):
    c = 0
    for i in range(26):
        t = chr(ord('a') + i)
        if t in a and t in b:
            c += 1
    return c

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

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
max_num = 0
for i in range(N):
    s1 = S[:i]
    s2 = S[i:]
    num = len(set(s1) & set(s2))
    max_num = num if max_num < num else max_num
print(max_num)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    count = [0 for _ in range(N)]

    for i in range(1,N):
        s1 = S[:i]
        s2 = S[i:]
        a = ""
        for s in s1:
            if (s in a)==False:
                a += s
                if s in s2:
                    count[i] += 1
    return max(count)

if __name__ == "__main__":
    print(main())

Submission status: Accepted

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


count_list = []
for index in range(1, len(s)):
    a = s[:index]
    b = s[index:]

    kind_a = set(a)
    kind_b = set(b)

    count = 0
    for c in kind_a:
        if c in kind_b:
            count+=1
    count_list.append(count)

print(max(count_list))

Submission status: Accepted

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

ans = 0
for i in range(N):
    count = 0
    closed = []
    for j in range(i):
        if S[j] not in closed and S[j] in S[i:N]:
            count += 1
            closed.append(S[j])

    # print(i, count, S[:i], S[i:N])
    ans = max(ans, count)

print(ans)

Submission status: Accepted

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

max_num = 0
for i in range(N):
    # print(i)
    count = 0
    left = S[:i]
    right = S[i:]
    # print(left)
    # print(right)

    left_uni = list(set(left))
    right_uni = list(set(right))
    # print(left_uni)
    # print(right_uni)

    for l in left_uni:
        if l in right_uni:
            count += 1

    # print(count)

    if count > max_num:
        max_num = count

# print("===")
print(max_num)

Submission status: Accepted

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

m = 0

for i in range(1, n):
    s1 = s[:i]
    s2 = s[i:]

    inter = set(s1).intersection(set(s2))

    m = max(len(inter), m)

print(m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:]
    tmp = 0
    subset = set()
    for string in x:
        if string in y and string not in subset:
            tmp += 1
            subset.add(string)
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
r=0
for i in range(n):
    a=set(s[:i])
    b=s[i:]
    m=0
    for k in a:
        if b.find(k)>=0: 
            m+=1
    r=r if r>m else m
print(r)

Submission status: Accepted

Solution code:
n = input()
s = list(input())
res = 0
for i in range(1, len(s)):
    tmp = 0
    x = s[:i]
    y = s[i:]
    mita = []
    for k in x:
        if k in y and k not in mita:
            tmp += 1
        mita.append(k)
    res = max([res, tmp])
print(res)

Submission status: Accepted

Solution code:
n = input()
n = input()
ans = 0
for i in range(len(n)):
    a = n[0:i+1]
    b = n[i+1:len(n)]
    al = sorted(list(set(list(a))))
    bl = sorted(list(set(list(b))))
    temp = 0
    for j in range(len(al)):
        if al[j] in bl:
            temp += 1
    if ans < temp:
        ans = temp
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
count=0
maxcount=0

for i in range(1,len(S)):
    F=S[:i]
    G=S[i:]

    X=set(F)

    count=0

    for j in X:
        if j in G:
            count=count+1

    maxcount=max(count,maxcount)

print(maxcount)

Submission status: Accepted

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

def solve(s,s2):
  cnt=set(s.strip())
  cnt2=set(s2.strip())
  return len(cnt&cnt2)
  
ans=0
for i in range(1,N-1):
  ans=max(ans,solve(S[:i],S[i:]))

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N-1):  # 切り取る場所
    n = 0
    right = S[i+1:]
    for c in list(set(S[:i+1])):
        if c in right:
            n += 1
    ans = max(ans, n)


print(ans)

Submission status: Accepted

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

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

print ans

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

import collections
import string
ans = 0
for i in range(N):
  X = S[:i]
  Y = S[i:]
  cntX = collections.Counter(X)
  cntY = collections.Counter(Y)
  
  tmp = 0
  for c in string.ascii_lowercase:
    tmp += 0 if min(cntX[c], cntY[c]) == 0 else 1
  ans = max(ans, tmp)
print(ans)

Submission status: Accepted

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

max_num = 0

for i in range(1, N):
    common = set()
    X = S[:i]
    Y = S[i:]
    for c in X:
        if c in Y:
            common.add(c)
    if len(common) > max_num:
        max_num = len(common)

print(max_num)

Submission status: Accepted

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

output = 0
for i, pivot in enumerate(s):
    x = s[:i]
    y = s[i:]
    dic = {}
    out = 0
    for c in x:
        if not c in dic:
            dic[c] = 1
    for c in y:
        if c in dic:
            out += 1
            del dic[c]
    if out > output:
        output = out

print (output)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
count = 0
for i in range(N+1):
    s1 = set(S[:i])
    s2 = set(S[i:])
    count = max(count,len(s1.intersection(s2)))
print(count)

Submission status: Accepted

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

print(c)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
top = 0
for i in range(len(S)):
  a = S[:i]
  b = S[i:]
  a = set(a)
  b = set(b)
  a = list(a)
  b = list(b)
  c = len(a) + len(b) - len(set(a+b))
  top =  max(c,top)
print(top)

Submission status: Accepted

Solution code:
n = int(input())
s = list(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)

Submission status: Accepted

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

Submission status: Accepted

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

ans=0

for i in range(0,n-1):
    s1=set([])
    s2=set([])
    for j in range(0,i+1):
        s1.add(s[j])
    for j in range(i+1,n):
        s2.add(s[j])
    
    s1=s1.intersection(s2)
    ans=max(ans,len(s1))

print(ans)

Submission status: Accepted

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

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

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(n):
    A = set(list(s[:i]))
    B = set(list(s[i:]))
    current = list(A & B)
    
    if len(current) > ans:
        ans = len(current)
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = list(map(int, input().split()))
S = input()
result = 0
maxnum = len(set(S))
for i in range(len(S)):
    X = set(S[:i])
    Y = set(S[i:])
    Z = X & Y
    if result < len(Z):
        result = len(Z)
    if result == maxnum:
        break

print(result)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(n):
  s1 = s[:i]
  s2 = s[i:]
  lst = []
  for k in s1:
    if k in s2:
      lst.append(k)
  ans = max(ans, len(list(set(lst))))

print(ans)

Submission status: Accepted

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

result = 0

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

print(result)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    S = stdin.readline()
    result = 0
    for i in range(1, N):
        s1 = S[:i]
        s2 = S[i:]
        result = max(result, len(set(s1) & set(s2)))
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
num = 0
for i in range(len(s)):
    t1 = s[:i]
    t2 = s[i:]
    rec = 0
    rec1 = []
    for j in range(len(s)):
        if s[j] in t1 and s[j] in t2 and s[j] not in rec1:
            rec += 1
            rec1.append(s[j])

    num = max(num, rec)
print(num)

Submission status: Accepted

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

max_s = 0
for i in range(1, N):
    X = set(S[:i])
    Y = set(S[i:])
    if len(X & Y) > max_s:
        max_s = len(X & Y)
print(max_s)

Submission status: Accepted

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

    r = []
    for i in range(n):
        ls = set(list(s[0:i+1]))
        rs = set(list(s[i+1:]))
        r.append(len(ls.intersection(rs)))
    print(max(r))

main()

Submission status: Accepted

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

score_list = []
for i in range(N):
	score_list.append(len(set(S[:i])&set(S[i:])))

print max(score_list)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(n):
    a = s[:i]
    b = s[i:]
    c = []
    count = 0
    for j in a:
        if j in b and j not in c:
            count += 1
            c.append(j)
            ans = max(ans,count)
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    x, y = s[:i], s[i:]
    setX = set()
    setY = set()
    for a in x:
        setX.add(a)
    for b in y:
        setY.add(b)
    z = setX & setY
    ans = max(ans, len(z))

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
out = []
for i in range(N):
    dic = {}
    for j in range(N):
        if (j <= i):
            dic[S[j]] = 0
        else:
            if S[j] in dic:
                dic[S[j]] = 1
        a = 0
        for it in dic.values():
            a+=it
        out.append(a)

print(max(out))

Submission status: Accepted

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

for i in range(1, N):
    S1 = set(S[:i])
    S2 = set(S[i:])
    count = len(S1 & S2)
    if maximum < count:
        maximum = count

print(maximum)

Submission status: Accepted

Solution code:
N = int(input())
s = input()
d = 0
for i in range(N):
    a = set(s[:i])
    b = set(s[i:])
    c = len(a.intersection(b))
    if c >= d:
        d = c
print(d)

Submission status: Accepted

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

print(max([len(set(s[:n]).intersection(s[n:])) for n in range(1, N)]))

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(raw_input())
S = raw_input()

ans = 0
for i in range(N):
    count = 0
    s1 = S[:i]
    s2 = S[i:]
    s1 = list(s1)
    s1 = list(set(s1))
    for j in range(len(s1)):
        if s2.find(s1[j]) > -1:
            count += 1
    ans = max(ans, count)

print(ans)

Submission status: Accepted

Solution code:

N = int(input())

S = list(input())

A = 0
for i in range(N):
    X = S[:i]
    Y = S[i:]
    b = len(set(X) & set(Y))
    A = max(A,b)
print(A)

Submission status: Accepted

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

commons_len = 0

for i in range(n):
    left = set(s[:i])
    right = set(s[i:])
    commons_len = max(len(left.intersection(right)),commons_len)

print(commons_len)

Submission status: Accepted

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

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

print(ma)

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.intersection(y)))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
from collections import Counter
from pprint import pprint as pp

YN = {True: 'Yes', False: 'No'}
ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))
rian = lambda n: [ria() for _ in range(n)]
rs = lambda: input()
rsa = lambda: input().split()
rsn = lambda n: [rs() for _ in range(n)]

N = ri()
S = input()
ret = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
for i in range(n):
    tmp_res = 0
    tmp1 = set(s[:i])
    tmp2 = set(s[i:])
    for j in tmp2:
        if j in tmp1:
            tmp_res += 1
    if tmp_res > res:
        res = tmp_res
print(res)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
w = set(s)
t = 0
for i in range(n):
  if s.count(w[i]) >= 2:
    t += 1
print(t)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
A=[]
for i in range(1,N):
    A.append([list(S[:i]),list(S[i:])])
for i in range(N-1):
    for j in range(1,len(A[i][0])):
        for k in range(1,len(A[i][0])):
            if j<k and A[i][0][j-1]==A[i][0][k-1]:
                A[i][0].remove(A[i][0][k-1])
B=[]
for i in range(N-1):
    B.append(0)
for i in range(N-1):
    for j in range(len(A[i][0])):
        B[i]+=A[i][1].count(A[i][0][j])
print(max(B))

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
A=[]
for i in range(1,N):
    A.append([list(S[:i]),list(S[i:])])
for i in range(N-1):
    for j in range(len(A[i][0])):
        for k in range(len(A[i][0])):
            if j<k and A[i][0][j]==A[i][0][k]:
                A[i][0].remove(A[i][0][k-1])
print(A)
B=[]
for i in range(N-1):
    B.append(0)
for i in range(N-1):
    for j in range(len(A[i][0])):
        B[i]+=A[i][1].count(A[i][0][j])
print(max(B))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

lst = []
for i in range(1,n-1):
    left = s[:i]
    right = s[i:]

    cnt = 0
    for j in set(left):
        if j in set(right):
            cnt += 1
    lst.append(cnt)
    
print(max(lst))

Submission status: Runtime Error

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

ans=1

for i in range(1,N):
    X=S[:i]
    Y=S[i:]
    setX=set(X)
    setY=set(Y)
    intersectionXY=setX & setY
    _temp=len(intersectionXY)
    if _temp>ans:
        ans=_temp
    else:
        pass
print(ans)

Submission status: Runtime Error

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

ans = []

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(input())
cnt_list=[]
from collections import Counter
for i in range(1,n-1):
  t=s[:i]
  del s[:i]
  s_set=set(s)
  t_set=set(t)
  cnt=0
  for k in s_set:
    if k in t_set:
      cnt+=1
  cnt_list.append(cnt)
print(max(cnt_list))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
ams=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: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
t=""
k=""
ans=0
l=[]
for i in range(1,n):
    ans1=0
    t=sorted(set(s[:i]))
    k=sorted(set(s[i:]))
    for i in t:
        for j in k:
            if i==j:
                ans1+=1
                l.append(ans1)
print(max(l))

Submission status: Runtime Error

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

cnt = []
cnt_tmp = {}
for Si in S:
  cnt_tmp.setdefault(Si, 0)

cnt.append(cnt_tmp)
for i, Si in enumerate(S):
  cnt_tmp[Si] += 1
  cnt.append(cnt_tmp)
  
ans = 0
for i in range(N):
  	ans_tmp = 0
    for key in cnt_tmp.keys():
      	if cnt[i][key] > 0 and cnt[-1][key] - cnt[i][key] > 0: ans_tmp += 1
    ans = max(ans, ans_tmp)
    
print(ans)

Submission status: Runtime Error

Solution code:
def count_bomb(y,x):
    ans=0
    for i in range(y-1,y+2):
        for j in range(x-1,x+2):
            if i>=0 and i<h and j>=0 and j<w:
                if s[i][j]=="#":
                    ans+=1
    return ans
h,w=map(int,input().split())
s = [list(input()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            s[i][j]=count_bomb(i,j)
for i in range(h):
    print(*s[i],sep="")

Submission status: Runtime Error

Solution code:
def count_bomb(y,x,h,w):
    ans=0
    for i in range(y-1,y+2):
        for j in range(x-1,x+2):
            if i>=0 and i<h and j>=0 and j<w:
                if s[i][j]=="#":
                    ans+=1
    return ans

h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            s[i][j]=count_bomb(i,j,h,w)
for i in range(h):
    print(*s[i],sep="")

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
ans=0
 
for i in range(1, n):
    a=s[:i]
    b=s[i:]
    dic=[]
    dic2=[]
    for j in range(len(a)):
        if a[j] not in dic:
            dic.append(a[j])
    for k in range(len(b)):
        if b[k] not in dic2:
            dic2.append(b[k])
 
    for i in range(len(dic)):
        if dic[i] in dic2:
            cnt+=1
    ans=max(ans, cnt)
    
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
    cnt = 0
    for i in range(1, N):
        # スライスで部分文字列をつくって、set型に変換し、積集合で共通する英小文字を取得
        dup_cnt = set(S[:i]) & set(S[i:])
        # 共通する英小文字の数が現時点での最大値より大きいなら最大値を更新
        if cnt < len(dup_cnt):
            cnt = len(dup_cnt)
    print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
N=int(input())
S=str(input())
s_list = "abcdefghijklmnopqrstuvwxyz"
count_list = np.zeros(26)
max_count = 0
for i in range(N-1): # N字目で切った場合
  for k in range(i):
    if S[k] in S[N:len(S)]:
      count_list[s_list.index(S[k])] = count_list[s_list.index(S[k])] + 1
  if max_count < n = len([1 for x in count_list if x>0])
print(max_count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def main():
    N = int(input())
    S = input()
    
    for i in range(1, N-1):
        left = set(S[:i])
        right = set(S[i:])

        yield len(left & right)


print(max(main()))

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
alp=list("abcdefghijklmnopqrstuvwxyz")
ans_set=[]
for i in range(N):
    X=S[:i]
    Y=S[i:]
    X_set=set(X)
    Y_set=set(Y)
    ans=0
    for w in alp:
        if w in X_set and w in Y_set:
            ans+=1
            ans_set.append(ans)
print(max(ans_set))

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
alp=list("abcdefghijklmnopqrstuvwxy")
ans_set=[]
for i in range(N):
    X=S[:i]
    Y=S[i:]
    X_set=set(X)
    Y_set=set(Y)
    ans=0
    for w in alp:
        if w in X_set and w in Y_set:
            ans+=1
            ans_set.append(ans)
print(max(ans_set))