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())
text = input()
result = []
for i in range(N-1):
      counter = 0
      text1 = text[0:i+1]
      text2 = text[i+1:]
      if  "a" in text1:
            if "a" in text2:
                  counter = counter + 1
      if  "b" in text1:
            if "b" in text2:
                  counter = counter + 1
      if  "c" in text1:
            if "c" in text2:
                  counter = counter + 1
      if  "d" in text1:
            if "d" in text2:
                  counter = counter + 1
      if  "e" in text1:
            if "e" in text2:
                  counter = counter + 1
      if  "f" in text1:
            if "f" in text2:
                  counter = counter + 1
      if  "g" in text1:
            if "g" in text2:
                  counter = counter + 1
      if  "h" in text1:
            if "h" in text2:
                  counter = counter + 1
      if  "i" in text1:
            if "i" in text2:
                  counter = counter + 1
      if  "j" in text1:
            if "j" in text2:
                  counter = counter + 1
      if  "k" in text1:
            if "k" in text2:
                  counter = counter + 1
      if  "l" in text1:
            if "l" in text2:
                  counter = counter + 1
      if  "m" in text1:
            if "m" in text2:
                  counter = counter + 1
      if  "n" in text1:
            if "n" in text2:
                  counter = counter + 1
      if  "o" in text1:
            if "o" in text2:
                  counter = counter + 1
      if  "p" in text1:
            if "p" in text2:
                  counter = counter + 1
      if  "q" in text1:
            if "q" in text2:
                  counter = counter + 1
      if  "r" in text1:
            if "r" in text2:
                  counter = counter + 1
      if  "s" in text1:
            if "s" in text2:
                  counter = counter + 1
      if  "t" in text1:
            if "t" in text2:
                  counter = counter + 1
      if  "u" in text1:
            if "u" in text2:
                  counter = counter + 1
      if  "v" in text1:
            if "v" in text2:
                  counter = counter + 1
      if  "w" in text1:
            if "w" in text2:
                  counter = counter + 1
      if  "x" in text1:
            if "x" in text2:
                  counter = counter + 1
      if  "y" in text1:
            if "y" in text2:
                  counter = counter + 1
      if  "z" in text1:
            if "z" in text2:
                      counter = counter + 1
      result = result + [counter]

print(max(result))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
alphabet='abcdefghijklmnopqrstuvwxyz'

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

st2 = Counter(S)
st1 = Counter()
best = 0
for i in range(N-1):
  st1.update(S[i])
  cnt = 0
  for k,v in st1.items():
    if st2[k] - v > 0:
      cnt += 1
  best = max(best, cnt)
print best

Submission status: Accepted

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

def count_common(a, b):
    min_char = set(min(a, b))
    max_char = set(max(a, b))
    return len(max_char) - len(max_char - min_char)

rtn = 0
for i in range(N):
    a = S[:i]
    b = S[i:]
    tmp = count_common(a, b)
    if rtn < tmp:
        rtn = tmp

print(rtn)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
sets = [(set(S[:i+1]),set(S[i+1:])) for i in range(len(S)-1)]
size_of_intersection = [len(s1.intersection(s2)) for s1, s2 in sets]
if size_of_intersection:
    print(max(size_of_intersection))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(N+1):
  left = set(S[:i])
  right = set(S[i:])

  tmp = 0
  for j in left:
    if j in right:
      tmp += 1

  if ans<tmp:
    ans = tmp

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(N+1):
  left = S[:i]
  right = S[i:]

  k=0
  for j in range(ord('a'),ord('z')+1):
    if left.count(chr(j))>0 and right.count(chr(j))>0:
      k += 1

  if ans<k:
    ans = k

print(ans)

Submission status: Accepted

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

    
print(ans)

Submission status: Accepted

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

ans=0
for i in range(n):
    cnt=0
    d={}
    for si in s[:i]:
        if si in s[i:] and si not in d:
            cnt+=1
            d[si]=True
    ans=max(ans, cnt)    
print(ans)

Submission status: Accepted

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

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 = list(input())

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
s=input()
res=0
for i in range(1,N):
    X=s[:i]
    Y=s[i:]
    n=0
    for j in range(97,123):
        if X.count(chr(j))!=0 and Y.count(chr(j))!=0:
            n+=1
    res=max(res,n)
print(res)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

max_n = 0

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

    if len(x&y) > max_n:
        max_n = len(x&y)

print(max_n)

Submission status: Accepted

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

x_max = 0

for i in range(1,N):
    A = set(S[0:i])
    B = set(S[i:])
    
    x = len(A&B)
    
    if x_max < x:
        x_max = x
        
print(x_max)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input()) 
S = input()

# n = 6
# S = "aabbca"
count = [0 for x in range(n)]

for i in range(n):
    S1 = S[0:i]
    S1c = Counter(S1)
    # print(S1c)
    # print(S1c.keys())

    S2 = S[i:n]
    S2c = Counter(S2)
    # print(S2c)

    for alphabet in S1c.keys():
        if alphabet in S2c.keys():
            count[i] += 1

# print(count)
print(max(count))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - Cut and Count

"""
import sys
from sys import stdin
input = stdin.readline


def solve(N, S):
    ans = 0
    for n in range(N):
        left = set(S[:n])
        right = set(S[n:])
        ans = max(ans, len(left & right))
    return ans


def main(args):
    N = int(input())
    S = input().strip()
    ans = solve(N, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
n1 = []
for i in range(n):
    s1 = set()
    for j in range(i+1):
        for k in range(i+1, n):
            # print(i, j, k, s[j], s[k])
            if s[j] == s[k] and set(s[j]).issubset(s1) is False:
                s1.add(s[j])
            # print('len', len(s1))
    n1.append(len(s1))
print(max(n1))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from string import ascii_lowercase
from collections import Counter
def inpl(): return map(int, input().split())

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

ans = 0

for i in range(N):
    tmp = 0
    A = Counter(S[:i])
    B = Counter(S[i:])
    for a in ascii_lowercase:
        tmp += (A[a] > 0)&(B[a] > 0)
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
alphabets = ['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(N + 1):
    former = S[:i + 1]
    latter = S[i + 1:]
    count = 0
    for j in alphabets:
        if (j in former) and (j in latter):
            count += 1
    if count > ans:
        ans = count
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
split_chars = ((set(s[:i]), set(s[i:])) for i in range(1, n))
common_chars = (set.intersection(*charsets) for charsets in split_chars)
print(max(len(chars) for chars in common_chars))

Submission status: Accepted

Solution code:
n = int(input())
word = input().strip()

print(max([len(set([s for s in word[:i] if s in word[i:]])) for i in range(1, n)]))

Submission status: Accepted

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

Submission status: Accepted

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

maxlen = 0

for i in range(N):
	a = S[0:i+1]
	b = S[i+1:N]
	aset = set(a)
	bset = set(b)

	ans = aset & bset

	if len(ans) >= maxlen:
		maxlen = len(ans)

print(maxlen)

Submission status: Accepted

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

ans = -1
for i in range(n-1):
    temp = 0
    s_1st = list(set(s[0:i+1]))
    s_2nd = list(set(s[i+1:n+1]))
    for j in range(len(s_1st)):
        if s_1st[j] in s_2nd:
            temp += 1
    if ans <= temp:
        ans = temp
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

n = int(input().rstrip())

line = input().rstrip()

max_count = 0
for i in range(n):
    a = set(line[0:i])
    b = set(line[i:])
    count = len(a.intersection(b))
    if max_count < count:
        max_count = count

print(max_count)

Submission status: Accepted

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

max_num=0
for i in range(N):
	X=S[:i:]
	Y=S[i::]
	num=0
	for char in [chr(i) for i in range(97,97+26)]:
		if (char in X) and (char in Y):
			num=num+1
	if max_num<num:
		max_num=num
print(max_num)

Submission status: Accepted

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

S = list(S)
res = 0
for i in range(1, N):
    S1 = set(S[:i])
    S2 = set(S[i:])
    if(len(S1.intersection(S2)) > res):
        res = len(S1.intersection(S2))

print(res)

Submission status: Accepted

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

for i in range(n+1):
	f = set(s[i:])
	b = set(s[:i])
	count = len(f & b)
	if c < count:
		c = count
print(c)

Submission status: Accepted

Solution code:
N=int(input())
s=input()
count=[]
for i in range (N):
    count.append(0)
    for k in range (i):
        if(s[k] in s[i:]):
            count[i]=count[i]+1
            if(s[k] in s[:k]):
                count[i]=count[i]-1
print(max(count))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
S_list=list(S)
S_max=0
for n in range(N):
    S_list_former=set(S_list[:n])
    S_list_latter=set(S_list[n:N])
    S_list_com=len(S_list_former & S_list_latter)
    if S_list_com>=S_max:
        S_max=S_list_com
print(S_max)

Submission status: Accepted

Solution code:
t=input()
s=input()
n=0
for i in range(len(s)):
  a=set(s[:i])
  b=set(s[i:])
  t=len(a&b)
  if t>n:
    n=t
print(n)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
x = 0
for i in range(n+1):
    f = set(s[i:])
    d = set(s[:i])
    count =len(f & d)
    if count > x:
        x = count
print(x)

Submission status: Accepted

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

ans = 0

for i in range(N):
    s1 = S[0 : i+1]
    s2 = S[i+1 : N]
    set1 = set(s1)
    set2 = set(s2)
    if ans <= len(set1 & set2):
        ans = len(set1 & set2)

print(ans)

Submission status: Accepted

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

ans = 0

for i in range(len(S)):
    s1 = S[0:i+1]
    s2 = S[i+1:len(S)]
    #print(s1,s2)
    set1 = set(s1)
    set2 = set(s2)
    #print(set1, set2)
    inse = set1.intersection(set2)
    #print(inse)
    ans = max(ans, len(inse))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
c = 0
for i in range(n+1):
    f = set(s[i:])
    d = set(s[:i])
    count =len(f & d)
    if count > c:
        c = count
print(c)

Submission status: Accepted

Solution code:
#b
num = int(input())
li = list(input())
ans = 0
for i in range(num):
    fi = set(li[:i])
    se = set(li[i:])
    hoge = len(list(fi & se))
    if hoge > ans:
        ans = hoge
    
print(ans)

Submission status: Accepted

Solution code:
N=int(input().strip())
S=input().strip()
maxnum=0
for i in range(1,N):
    if min(i, N-i) < maxnum:
        continue
    s1=set(i for i in S[:i])
    s2=set(i for i in S[i:])
    num=0
    for c in s1:
        if c in s2:
            num+=1
    if num > maxnum:
        maxnum=num
print(maxnum)

Submission status: Accepted

Solution code:
num = int(input())
li = list(input())
ans = 0
for i in range(num):
  fi = set(li[:i])
  se = set(li[i:])
  hoge = len(list(fi & se))
  if hoge > ans:
    ans = hoge
 
print(ans)

Submission status: Accepted

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

for i in range(n-1):
    s1 = s[0:i+1]
    s2 = s[i+1:n]
    res_1 = 0
    for alp in range(ord('a'),ord('z')+1):
        if s1.find(chr(alp)) > -1:
            if s2.find(chr(alp)) > -1:
                res_1 = res_1 + 1
    if res < res_1:
        res = res_1

print(res)

Submission status: Accepted

Solution code:
# ANSHUL GAUTAM
# IIIT-D

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

ans = 0

for i in range(1,N):
	curr = 0
	s = S[:i]
	r = S[i:]
	for j in range(97,123):
		char = chr(j)
		if(char in s and char in r):
			curr += 1
	ans = max(ans, curr)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
c=0
for i in range(1,n):
  x=set(s[:i])
  y=set(s[i:])
  a = len(x & y)
  if a > c:
    c = a
print(c)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    x, y = set(S[:i]), set(S[i:])
    cnt = 0
    for c in x:
        if c in y:
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
k = 0
for n in range(1,n):
    a =  set(s[:n]) & set(s[n:])
    if len(a) > k :
        k = len(a)
print('{}'.format(k))

Submission status: Accepted

Solution code:
n, s = [input() for i in range(2)]
n = int(n)

list(s)

count = 0
for i in range(1, n):
    x, y = set(s[:i]), set(s[i:])
    count = len(x & y) if count < len(x & y) else count

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(x)

Submission status: Accepted

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

maxx=0
for i in range(1,n):
    l={}
    r={}
    for j in range(i):
        if S[j] in l:
            l[S[j]]+=1
        else:
            l[S[j]]=1
    for j in range(i,n):
        if S[j] in r:
            r[S[j]]+=1
        else:
            r[S[j]]=1
    count=0
    for c in l:
        if c in r:
            count+=1
    maxx=max(maxx,count)

print(maxx)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = input()
cnt_l = []
for i in range(n - 1):
  str1_cnt = Counter(s[:i + 1])
  str2_cnt = Counter(s[i + 1:])
  cnt_l.append(len(set(list(str1_cnt)) & set(list(str2_cnt))))
print(max(cnt_l))

Submission status: Accepted

Solution code:
input()
s = input()

x = 0

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

print(x)

Submission status: Accepted

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

''' "効率の良い" アルゴリズム

各文字について「最初の出現と最後の出現の間の切断位置」に1を、
そのほかに0を割り当てる:
(s) a b r a c a d a b r a
a: 0 1 1 1 1 1 1 1 1 1 1 0
b: 0 0 1 1 1 1 1 1 1 0 0 0
c: 0 0 0 0 0 0 0 0 0 0 0 0
d: 0 0 0 0 0 0 0 0 0 0 0 0
r: 0 0 0 1 1 1 1 1 1 1 0 0

合計を計算する:
+: 0 1 2 3 3 3 3 3 3 2 1 0

最大をとる:
3

ただし、2次元の表を作るのはまだ効率が悪いので、実際には次のようにする。
各位置について「その位置の文字が最初であって最後でないなら+1,
最後であって最初でないなら-1, さもなければ0」を割り当てる:

(s) a b r a c a d a b r a
    + + +           - - -
これは前後から「もう見た文字」以外をたどればよい。

手前から順に足していき、最大をとる:
max(1,2,3,3,3,3,3,3,2,1,0)
'''
n = int(input())
s = input()
point = [0 for _ in range(n)]

seen_forward = set()
for i, letter in enumerate(s):
    if letter not in seen_forward:
        point[i] += 1
        seen_forward.add(letter)

seen_backward = set()
for i, letter in reversed(list(enumerate(s))):
    if letter not in seen_backward:
        point[i] -= 1
        seen_backward.add(letter)

current_score, max_score = 0, 0
for p in point:
    current_score += p
    max_score = max(max_score, current_score)

print(max_score)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
alphabets = 'abcdefghijklmnopqrstuvwxyz'
scores = []
for i in range(n):
    count = 0
    for alphabet in alphabets:
        if alphabet in s[:i] and alphabet in s[i:]:
            count += 1
    scores.append(count)
print(max(scores))

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
alp = ["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"]
X = []
Y = S
max=[]
for i in range(N):
    X.append(Y[0])
    del Y[0]
    count = 0
    for j in range(26):
        if X.count(alp[j]) > 0 and Y.count(alp[j]):
            count += 1
        max.append(count)
max.sort(reverse = True)
print(max[0])

Submission status: Accepted

Solution code:
N = int(input())
S = input()
temp=0
for i in range(N-1):
    S1=S[0:i+1]
    S2=S[i+1:N]
#    print(S1 + " " + S2)
    kaburi=[]
    for s in S1:
        if s in S2 and s not in kaburi:
            kaburi.append(s)
    if len(kaburi)>temp:
        temp = len(kaburi)
print(temp)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ss=[i for i in s]
w=0
for i in range(1,n):
    #print(i)
    a=set(ss[:i])
    b=set(ss[i:])

    v=0
    for aa in a:
        #print(a)
        #print(b)
        if aa in b:
            v+=1
            #a.remove(aa)
            #b.remove(aa)
            #aは更新されるの？ーy
            #ただ前のaaが消された時次にforで取り出されるのは何？
            #また同じ文字でもaaでない時は消されない
        #print(v)
    if v>w:
        w=v
print(w)

Submission status: Accepted

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

Submission status: Accepted

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

max = 0
count = 0
check = []

for i in range(1,N):
  count = 0
  check = []
  left = S[:i]
  right = S[i:]
  for j in left:
    if j in right and j not in check:
      count += 1
    check.append(j)
  if count >= max:
    max = count
    
print(max)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(N):
    x,y = S[0:i+1], S[i+1:]
    tmp = 0
    al = []
    for xi in x:
        if xi in y and not xi in al:
            al.append(xi)
            tmp += 1
    ans = max(ans,tmp)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

letters = []
for i in range(N):
    if S[i] not in letters:
        letters.append(S[i])

ans = 0
for i in range(N):
    kinds = 0
    left = S[:i]
    right = S[i:]
    for j in range(len(letters)):
        if((letters[j] in left) and (letters[j] in right)):
            kinds = kinds + 1
    ans = max(kinds,ans)

print(ans)

Submission status: Accepted

Solution code:
def cut_count(N, S):
    counter = [0]
    for i in range(1, N):
        x = list(set(S[:i]))
        y = ''.join(list(set(S[i:])))
        c = [y.count(x[j]) for j in range(len(x))]
        if sum(c) != 0:
            counter.append(sum(c))
        else:
            pass
    return max(counter)

def main():
    N = int(input())
    S = list(input())
    print(cut_count(N, S))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import string

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

count = 0
for i in range(n - 1):
  count1 = 0
  for j in string.ascii_lowercase:
    x = s[:i+1]
    y = s[i+1:]
    if j in x and j in y:
      count1 += 1
  if count1 > count:
    count = count1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(raw_input())
S = str(raw_input())
opt_num = 0
dict = {}
dict2 = {}
for i in range(N-1):
    first = S[:i+1]
    latter = S[i+1:]
    for l in S:
        dict[l] = 0
    dict2 = {}
    cnt = 0
    for f in first:
        dict[f] = 1
    for l in latter:
        if dict[l]:
            dict2[l] = 1
    if opt_num < len(dict2):
        opt_num = len(dict2)
print(opt_num)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
s = arr_data[1][0]

maxdata=0
for i in range(1,n):
    
    s1=set(s[:i])
    s2=set(s[i:])
    
    maxdata=max(maxdata,len(s1&s2))
    
print(maxdata)

Submission status: Accepted

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

posDevide = 1
maxMatchWordNum = 0

while posDevide <=  N - 1:
        arrayNum = 0
        matchWordNum = 0
        while arrayNum < posDevide:
                if arrayNum  == S.find( S[ arrayNum ], 0, posDevide):
                        matchWordNum = matchWordNum + 1 if  bool( S.count( S[ arrayNum ], posDevide, N )) else matchWordNum

                arrayNum += 1

        maxMatchWordNum = matchWordNum if matchWordNum > maxMatchWordNum else maxMatchWordNum
        posDevide += 1

print(maxMatchWordNum)

Submission status: Accepted

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

former = set(s[0])
latter = set(s[1:])
ans = len(former & latter)

for i in range(2, n):
	former = set(s[:i])
	latter = set(s[i:])
	if len(former & latter) > ans:
		ans = len(former & latter)
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
import collections
t=[]
for i in range(1,n):
    x=s[:i]
    y=s[i:]
    c = collections.Counter(x)
    d = collections.Counter(y)
    t.append(len(set(c)&set(d)))
print(max(t))

Submission status: Accepted

Solution code:
from sys import stdin


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ret = 0
for i in range(len(s)):
    sa = s[:i]
    sb = s[i:]
    bot = [0]*26
    for j in range(26):
        c = chr(j+ord('a'))
        if c in sa and c in sb:
            bot[j] += 1
    ret = max(ret,sum(bot))
print(ret)

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()
list=list(S)
x=0
for j in range(N+1):
    a=0
    for i in range(97,123):

        if (chr(i) in list[0:j]) and (chr(i) in list[j:N]):
            a+=1
    if a>x:
        x=a
print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=int(input())
b=input()
d=0

for i in range(a):
 c=0
 data=b[0:i]
 match=b[i:a]
 data_uniq=list(set(data))
 match_uniq=list(set(match))
 for x in range(len(data_uniq)):
  for y in range(len(match_uniq)):
   if data_uniq[x]==match_uniq[y]: 
    c+=1
    d=max(d,c)
                   

print (d)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    max = 0;
    for i in range(1, N):
        l = S[:i]
        r = S[i:]
        used = []
        for k in l:
            if k in r and k not in used:
                used.append(k)
        if len(used) > max: max = len(used)
    print(max)

if __name__ == '__main__':
  main()

Submission status: Accepted

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

max = -1

for i in range(1,n):
	syu = []
	x = s[0:i]
	y = s[i:]
	
	for moji in x:
		if moji not in syu and moji in y:
			syu.append(moji)
	
	if max < len(syu):
		max = len(syu)
	
print(max)

Submission status: Accepted

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

max_common = -1

for i in range(1,n):
    common = []
    x = s[0:i]
    y = s[i:]
    #print(x, y)
    
    for letter in x:
        if letter not in common and letter in y:
            common.append(letter)
    #print("common: ", common)
    
    max_common = max(len(common), max_common)
    #print()
    
print(max_common)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
raw_input()
str = raw_input()
nums = []
for i in range(1,len(str)):
    count = 0
    chars = []
    
    for c in str[0:i]:
        if not c in chars and c in str[i:len(str)]:
            chars.append(c)
            count +=1
    nums.append(count)
print max(nums)

Submission status: Accepted

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

ans = list()

for i in range(len(s)):
    cnt = 0
    x = sorted(set(s[:i]), key=s.index)
    y = sorted(set(s[i:]), key=s.index)
    for j in x:
        if j in y:
            cnt += 1
    ans.append(cnt)

print(max(ans))

Submission status: Accepted

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

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

alphabets = "abcdefghijklmnopqrstuvwxyz"

res = 0

for i in range(1, n):

    matches = 0

    s1 = s[:i]
    s2 = s[i:]

    for c in list(alphabets):
        if s1.find(c) != -1 and s2.find(c) != -1:
            matches += 1

    if matches > res: res = matches

print(res)

Submission status: Accepted

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

def main():
    N = int(input())
    S = input()
    q = set(S)
    ans = 0
    for i in range(1, N):
        a = set(S[:i])
        b = set(S[i:])
        cnt = 0
        for j in q:
            if j in a and j in b : cnt += 1
        ans = max(cnt, ans)
    print(ans)
main()

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding:utf-8 -*-

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

max = 0
for i in range(1, len(s)):
    left = s[:i]
    right = s[i:]
    buf = []
    for j in left:
        if j in right and j not in buf:
            buf.append(j)
    if max < len(buf):
        max = len(buf)
print(max)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
maxNum = 0
for i in range(1,N):
    X = set(S[:i])
    Y = set(S[i:])
    n = len(X & Y)
    if maxNum < n:
        maxNum = n
print(maxNum)

Submission status: Accepted

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

ans = 0
for i in range(N):
    X, Y = set(), set()
    for j in range(N):
        if j < i:
            X.add(S[j])
        else:
            Y.add(S[j])

    same = len(X & Y)
    if same > ans:
        ans = same
print(ans)