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

count = 0
for i in range(N + 1):
    x_chars = set(list(S[:i]))
    y_chars = set(list(S[i:]))
    both = x_chars & y_chars
    if len(both) > count:
        count = len(both)

print(count)

Submission status: Accepted

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

max_diff = 0
for i in range(1, len(s)):
  s1 = s[:i]
  s2 = s[i:]
  diff = len(set(s1) & set(s2))
  if diff > max_diff:
    max_diff = diff
print(max_diff)

Submission status: Accepted

Solution code:
n=int(input())
s=str(input())
ans=0
for i in range(n):
    k=0
    arr=[]
    for j in range(i+1):
        if(s[j] in s[i+1:] and s[j] not in arr):
            k+=1
            arr.append(s[j])
    if(k>ans):
        ans=k
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

same_num = -1

for i in range(N):
    s1 = set(S[:i+1])
    s2 = set(S[i+1:])
    if len(s1 & s2) > same_num:
        same_num = len(s1 & s2)

print(same_num)

Submission status: Accepted

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

ans=0
for i in range(2,n):
	x=set(list(s[:i]))
	y=set(list(s[i:]))
	sum=x&y
	ans=max(ans,len(sum))

print(ans)

Submission status: Accepted

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

def div(x):
    s1,s2="",""
    for i in range(x):
        s1+=S[i]
    for i in range(N-x):
        s2+=S[x+i]
    return s1,s2

def count(s1,s2):
    cnt=0
    s1=list(set(s1))
    for i in range(len(s1)):
        if s1[i] in s2:
            cnt+=1
    return cnt

for i in range(1,N):
    s1,s2=div(i)
    cnt=count(s1,s2)
    lcnt.append(cnt)
    
print(max(lcnt))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
max_sep = 0
for i in range(n):
  s1 = s[:i]
  set1 = set(list(s1))
  s2 = s[i:]
  set2 = set(list(s2))
  set_all = set1 & set2
  max_sep = max(max_sep, len(set_all))

print(max_sep)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for n in range(2, N):
  X = set(list(S[:n]))
  Y = set(list(S[n:]))
  intersec = X & Y
  ans = max(ans, len(intersec))

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
maxn =0
alp = [chr(i) for i in range(97, 97+26)]
for i in range(N-1):
  A = S[:i+1:]
  B = S[i+1::]
  count = 0
  for j in alp:
    if A.find(j)!=-1 and B.find(j)!=-1:
      count+=1
  maxn = max(maxn,count)
print(maxn)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for k in range(N):
    t = 0
    T = set([x for x in S[:k]])
    U = set([x for x in S[k:]])
    for x in T:
        if x in U:
            t += 1
    ans = max(ans,t)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans = 0
for i in range(N):
  Sp = list(set(S[0 : i + 1]))
  Ss = list(set(S[i + 1 : N]))
  temp = 0
  for x in Sp:
    for y in Ss:
      if x == y:
        temp += 1
        break
  if temp > ans:
    ans = temp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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

print(result)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = input()


def calcCountUnion(X, Y):
    counter = 0
    for key in X.keys():
        if key in Y.keys():
            counter += 1
    return counter


def str2dict(S):
    X = {}
    Y = {}
    for a in S:
        X[a] = X[a] + 1 if (a in X.keys()) else 1
    return X, Y


def calcMaxCutCount(S):
    X, Y = str2dict(S)
    maxCutCount = 0
    for a in S:
        X[a] = X[a] - 1
        Y[a] = X[a] + 1 if (a in X.keys()) else 1
        if X[a] <= 0:
            X.pop(a)
        tmp = calcCountUnion(X, Y)
        maxCutCount = max((tmp, maxCutCount))
    return maxCutCount


print(calcMaxCutCount(S))

Submission status: Accepted

Solution code:
def alphabet_str(string):
    n = len(string)
    dict = ""
    for c in string:
        if dict.find(c) == -1:
            dict += c
    #print(dict)
    return dict


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

str = list(S)
str1 = ""
str2 = S

max = 0

for i in range(0,N-1):
    sum = 0
    str1 += str[i]
    str2 = str2[1:]
    dict1 = alphabet_str(str1)
    dict2 = alphabet_str(str2)
   # print("{0},{1}".format(dict1,dict2))
    for c in dict1:
        if dict2.find(c) >= 0:
            sum += 1
   # print(sum)
    if sum > max:
        max = sum
print(max)

Submission status: Accepted

Solution code:
def max_common(n, s):
    maximum = 0
    for i in range(1, n):
        set_left = set(s[:i])
        set_right = set(s[i:])
        maximum = max(maximum, len(set_left.intersection(set_right)))
    return maximum


if __name__ == '__main__':
    n = int(input())
    s = input()
    print(max_common(n, s))

Submission status: Accepted

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

print(max([len(set(text[:i]) & set(text[i:])) for i in range(1, n)]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    a = int(input())
    b = input()

    counts = []
    for i in range(1, a):
        count = 0
        b_1 = b[0:i]
        b_1 = list(set(list(b_1)))
        b_2 = b[i:a]
        b_2 = list(set(list(b_2)))
        for x in range(0, len(b_1)):
            for y in range(0, len(b_2)):
                if b_1[x] == b_2[y]:
                    count = count + 1

            counts.append(count)

    print(max(counts))

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
dp = [0 for i in range(n+1)]

for i in range(n):
    if (s[i] in s[i+1:]) and (s[i] not in s[:i]):
        dp[i+1] = dp[i]+1
    elif (s[i] not in s[i+1:]) and (s[i] in s[:i]):
        dp[i+1] = dp[i]-1
    else:
        dp[i+1] = dp[i]

print(max(dp))

Submission status: Accepted

Solution code:
import string

N = int(input())
S = input()
ret = 0
for i in range(1, N):
    k = 0
    for s in string.ascii_lowercase:
        if s in S[:i] and s in S[i:]:
            k += 1
    ret = max(ret, k)
print(ret)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
m=i=d=n//2
a=0
for _ in range(m):
    left=set(s[:i])
    right=set(s[i:])
    b=len(left&right)
    if a<b:
        a=b
    left=set(s[:d])
    right=set(s[d:])
    b=len(left&right)
    if a<b:
        a=b
    i=i+1
    d=d-1
print(a)

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

N = stdin.readline().rstrip()
S = stdin.readline().rstrip()


max = 0

N = int(N)

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


print(max)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    s = input()

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

    print(a)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

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

tmp = 0
ans = 0
for i in range(1,n):
    for j in set(s[0:i]):
        if j in set(s[i:]):
            tmp += 1
    ans = max(ans, tmp)
    tmp = 0
print(ans)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    n = int(input())
    s = input()
    ans = float('-inf')
    for end in range(1,n):
        ans = max(ans, len([tmp for tmp in list(set(s[0:end])) if list(set(s[end:n])).count(tmp) > 0]))
    else:
        print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

s = input()

mm = 0

for i in range(1,n):
    s1 = s[0:i]
    s2 = s[i:n]
    a = set(s1)
    b = set(s2)
    c = a & b
    mm = max(mm, len(c))

print(mm)

Submission status: Accepted

Solution code:
n=int(raw_input())
s=raw_input()
res=0
for i in xrange(len(s)):
 s1=s[:i]
 s2=s[i:]
 t1=set(list(s1))
 t2=set(list(s2))
 t3=t1 & t2
 res=max(res,len(t3))
print res

Submission status: Accepted

Solution code:
n = int(raw_input())
s = raw_input()
mx = 0
for i in range(n):
    s1 = set(list(s[:i]))
    s2 = set(list(s[i:]))
    mx = max(mx, len(s1.intersection(s2)))
print mx

Submission status: Accepted

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

result = 0
for i in range(1, n-1):
    x = list(set(s[:i]))
    y = list(set(s[i:]))
    temp = len(x+y) - len(set(x+y))
    if temp > result:
        result = temp

print(result)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input().strip())
ans=0
for i in range(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()
max_count = 0
for i in range(1, N):
    X = set(list(S[:i]))
    Y = S[i:]
    count = 0
    for c in X:
        if c in Y:
            count += 1
    max_count = max(max_count, count)
print(max_count)

Submission status: Accepted

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

for i in range(N):
    S1 = set(S[:i])
    S2 = set(S[i:])

    count = max(count, len(S1 & S2))

print(count)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
num=int(input())
word=str(input())
n_th = 0
for i in range(num):
    s1=word[:i]
    s2=word[i:]
    n=0
    for a in 'abcdefghijklmnopqrstuvwxyz':
        if (not s1.find(a) == -1) and (not s2.find(a) == -1):
            n += 1
    if n>n_th:
        n_th=n
print(n_th)

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    f = s[:i]
    b = s[i:]
    cnt = 0
    for c in [chr(j + ord('a')) for j in range(26)]:
        if c in f and c in b:
            cnt += 1
    ans = max(ans, cnt)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
count = 0
for i in range(1, N):
    pre_S = set(S[:i])
    post_S = set(S[i:])
    kyoutu_S = pre_S & post_S
    if count < len(kyoutu_S):
        count = len(kyoutu_S)

print(count)

Submission status: Accepted

Solution code:
def charToInt(c):
    return ord(c) - ord("a")
 
def stringToFlags(s):
    t = [False for i in range(26)]
    for i in range(len(s)):
        t[charToInt(s[i])] = True
    return t
 
def B(n, s):
    max = 0
    for i in range(1, n):
        xflags = stringToFlags(s[0:i])
        yflags = stringToFlags(s[i:n])
        
        count = 0
        for i in range(26):
            if xflags[i] and yflags[i]:
                count += 1
                if count > max:
                    max = count
    return max
 
n = int(input())
s = input()
print(B(n, s))

Submission status: Accepted

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

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

print(m)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    s = S()
    r = 0
    for i in range(n):
        a = set(collections.Counter(s[:i]).keys())
        b = set(collections.Counter(s[i:]).keys())
        r = max(r, len(a&b))

    return r




print(main())

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ma=0
for i in range(1,n):
  t=set(s[:i])
  tt=set(s[i:])
  c=0
  for x in t:
    if(x in tt):c+=1
    ma=max(ma,c)
print(ma)

Submission status: Accepted

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

A = [chr(i) for i in range(ord("a"), ord("a")+26)]

ans = 0
for i in range(N+1):
    S1 = S[:i]
    S2 = S[i:]
    cnt = 0
    for a in A:
        if a in S1 and a in S2:
            cnt += 1
    ans = max(ans, cnt)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

    c_lst = []
    for i in range(n):
        s1, s2 = set(s[:i]), set(s[i:])
        c_lst.append(len(s1&s2))

    print(max(c_lst))


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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
ss=s[::-1]
ans=0
front_bucket=[0 for i in range(26)]
back_bucket=[0 for i in range(26)]

for i in range(n):
  front_bucket[ord(s[i])-97]+=1
for i in range(n):
  back_bucket[ord(ss[i])-97]+=1
  front_bucket[ord(ss[i])-97]-=1
  a=0
  for j in range(26):
    if front_bucket[j]*back_bucket[j]>0:
      a+=1
  ans=max(ans,a)

print(ans)

Submission status: Accepted

Solution code:
N = int(raw_input())
S = raw_input()
ret = 0
for i in range(N):
  l = S[:i]
  r = S[i:]
  u = set(l) & set(r)
  ret = max(ret, len(u))
print ret

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    n = int(input())
    s = input()
    result = 0

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

    print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import string

def f(s, t):
    ret = 0
    for c in string.ascii_lowercase:
        found_s = False
        found_t = False
        for i in range(len(s)):
            if s[i] == c:
                found_s = True
                break
        for i in range(len(t)):
            if t[i] == c:
                found_t = True
                break
        if found_s and found_t:
            ret += 1
    return ret
    
if __name__ == '__main__':
    n = int(input())
    s = input()

    ans = 0
    for i in range(n + 1):
        #i文字目が壁になる
        #0文字目の手前まで:空文字列
        #n+1文字目の手前まで:全文字列
        tmp = f(s[:i], s[i:]) 
        ans = max(ans, tmp)
    print(ans)

Submission status: Accepted

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

A=[]

for i in range(N-1):
    left=set(S[:i+1])
    right=set(S[i+1:])
    C= left & right
    B=len(C)
    A.append(B)
    
        
print(max(A))

Submission status: Accepted

Solution code:
N = int(input())
S = list(str(input()))
countlist=[]
for i in range(0,N):
    s1 = set(S[:i])
    s2 = set(S[i:])

    matched_list=list(s1 & s2)
    countlist.append(len(matched_list))

ans = max(countlist)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import string

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

ans = 0
for i in range(n + 1):
    #i文字目が壁になる
    #0文字目の手前まで:空文字列
    #n+1文字目の手前まで:全文字列
    a, b = s[:i], s[i:]
    tmp = 0
    for c in string.ascii_lowercase:
        if (c in a) and (c in b):
            tmp += 1
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

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

num=[]
for i in range(0,N-1):
	icchi=[]
	p_list=[]
	q_list=[]
	for p in range(0,i+1):
		p_list.append(S[p])
	for q in range(i+1,N):
		q_list.append(S[q])
	for x in range(0,len(p_list)):
		for y in range(0,len(q_list)):
			if(p_list[x]==q_list[y]):
				icchi.append(p_list[x])
				break
	num.append(len(set(icchi)))
print(max(num))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans=[]
for i in range(N):
    x =S[:i]
    y=S[i:]
    a = 0
    xs = set()
    ys = set()
    for s in x:
        xs.add(s)
    for s in y:
        ys.add(s)  
    ans.append(len(xs&ys))
print(max(ans))

Submission status: Accepted

Solution code:
length = int(input())
chars = list(input())

maxOfKinds = 0

index = 0

while(index != len(chars)):
    numOfEquals = 0
    for i in range(0, index + 1):
        isExisted = False
        for k in range(0, i):
            if chars[i] == chars[k]:
                isExisted = True
        if isExisted == True:
            continue
        for j in range(index + 1, len(chars)):
            if chars[i] == chars[j]:
                numOfEquals += 1
                break
    if maxOfKinds < numOfEquals:
        maxOfKinds = numOfEquals
    index += 1

print(maxOfKinds)

Submission status: Accepted

Solution code:
def abc098_b():
    n = int(input())
    s = input()
    count_max = 0
    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
        count_max = max(count,count_max)
    return count_max

print(abc098_b())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
alp=[]
alp+="abcdefghijklmnopqrstuvwxyz"
li=[]
n = int(input())
li+=input()
saidai = 0
for i in range(n):
    count = 0
    lia = li.copy()
    lib = []
    for j in range(i):
        lib += lia.pop()
    for t in range(26):
        if alp[t] in lia and alp[t] in lib:
            count += 1
    if saidai < count:
        saidai = count
print(saidai)

Submission status: Accepted

Solution code:
n=int(input())
a=input()
l = []
for i in range(0, n):
    l.append(a[i])
t0=[]
for k in range(0, n):
    l1 = l[0:k]
    l2 = l[k: n]
    s1 = set(l1)
    s2 = set(l2)
    t = s1 & s2
    t0.append(len(t))
print(max(t0))

Submission status: Accepted

Solution code:
N = int(raw_input())
S = list(raw_input())
ans = 0
for n in range(N):
 B = set(S[:n])
 E = set(S[n:])
 c = 0
 for b in B:
  if b in E:
   c += 1
 if c > ans:
  ans = c
print ans

Submission status: Accepted

Solution code:
#coding: utf-8
n=int(input())
s=input()
origin=[]
origin=list(s)
s1=[]
s2=[]
i=0
j=0
k=0
a=0
an=0
while(i<=n-1):
    while(j<=i):
        s1.append(origin[j])
        j=j+1
    while(j<=n-1):
        s2.append(origin[j])
        j=j+1
    j=0
    s1=list(set(s1))
    s2=list(set(s2))

    while(j<=len(s1)-1):
        while(k<=len(s2)-1):
            if(s1[j]==s2[k]):
                a+=1
            k+=1
        k=0
        j+=1
    j=0
    i+=1
    s1=[]
    s2=[]
    if(an<a):
        an=a
    a=0
print(an)

Submission status: Accepted

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

input1 = raw_input()
input2 = raw_input()

N = int(input1)
S = input2


cutdic = {}
#切り方
for i in range(N):
    count = 0
    X = S[:i]
    Y = S[i:]
    setX = set(X)
    #print X, Y, setX
    for j in setX:
        if j in Y:
            count += 1
        cutdic[str(i) + "," + str(j)] = count

print (max(cutdic.values()))

Submission status: Accepted

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

N = int(input())
S = input().strip()

max_cnt = -1

for k in range(1,N):
    s1 = S[:k]
    s2 = S[k:]
    # print(s1, s2)

    cnt = len(set(s1) & set(s2))
    max_cnt = max(max_cnt, cnt)

print(max_cnt)

Submission status: Accepted

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

count = 0
temp = 0

for i in range(1,N):
    temp = 0
    s_tmp = S
    for j in range(i):
        if( s_tmp[i:].find(s_tmp[j]) >= 0 and s_tmp[j]!=','):
            temp = temp + 1;
            s_tmp = s_tmp.replace(s_tmp[j], ",")
            if(temp>count):
                count = temp
        
print(count)

Submission status: Accepted

Solution code:

N = input()
S = input()
N = int(N)
count = []

for i in range(N):
    times = 0
    left = S[:i]
    right = S[i:]
    for j in set(left):
        if j in set(right):
            times += 1
    count.append(times)
print(max(count))

Submission status: Accepted

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

for i in range(1,N):
    a = S[:i]
    b = S[i:]
    k = 0
    for j in range(len(a)):
        if a[j] not in a[:j]:
            if a[j] in b:
                k+=1
    if k>l:
        l = k
        
print(l)

Submission status: Accepted

Solution code:

N = input()
S = raw_input()

max_n = 0

for i in range(N-1):
    x = S[0:i+1]
    y = S[i+1:N]
    x1 = list(set(x))
    y1 = list(set(y))
    rx = len(x1)
    ry = len(y1)
    count = 0
    for j in range(rx):
        for k in range(ry):
            if y1[k] in x1[j]:
                count = count + 1
    if count > max_n:
        max_n = count

print(max_n)

Submission status: Accepted

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

counter = []
for i in range(1, N):
    temp = []
    temp.append(S[0:i])
    temp.append(S[i:N])
    matched_set = list(set(temp[0]) & set(temp[1]))
    counter.append(len(matched_set))

print(max(counter))

Submission status: Accepted

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

# preparation
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
max = 0
count = 0

# main
for i in range(len(s)):
  count = 0
  a = (s[i:n])
  b = (s[0:i])
  for j in range(len(ascii_lowercase)):
    if (a.count(ascii_lowercase[j]) > 0 and b.count(ascii_lowercase[j]) > 0):
      count += 1
  if (max < count):
    max = count
print (max)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat May 26 21:45:21 2018

@author: sakas
"""
N = int(input())
S = input()
arr = set()
ray = set()
s = list(S)
j = 0
for i in range(len(s)):
   arr = set(list(S[:int(i)]))
   ray = set(list(S[int(i):]))
   if j < int(len(arr & ray)):
       j = len(arr & ray)
print(j)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for x in range(1,n):
    u = [i for i in s[0:x] if i in s[x:(n+1)]]
    l = len(set(u))
    m = max(l, m)

print(m)

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline())
a = stdin.readline().strip()
ans = 0
b = "abcdefghijklmnopqrstuvwxyz"
for i in xrange(n):
 x = a[:i]
 y = a[i:]
 cur = 0
 for i in b:
  if i in x and i in y:
   cur += 1
 ans = max(ans,cur)
print ans

Submission status: Accepted

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

cnt = set()
for i in range(1, N):
    X = S[:i]
    Y = S[i:]
    x_set = set(X)
    y_set = set(Y)
    c = len(list(x_set & y_set))
    cnt.add(c)
print(max(cnt))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n = int(input())
s = input()
S = list(s)
max = 0
tmp = 0
for i in range(1,n+1):
    tmp = 0
    for j in range(i):
        if S[j] in s[i:n+1] and S[j] not in s[0:j]:
            tmp += 1
    if tmp > max:
        max = tmp
print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Q2

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

def sentenceCount(sx, sy):
    tmp = ''
    count = 0
    for char in sx:
        if sy.count(char) > 0 and not char in tmp:
            count = count + 1
            tmp = tmp + char
    
    return count

cnt = 0
for i in range(1, N):
    tmp = sentenceCount(S[:i], S[i:])
    if tmp > cnt:
        cnt = tmp

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
length = len(S)
M = 0
for i in range(length):
    fir = set(S[:i])
    las = set(S[i:])
    l = len(fir & las)
    if l > M:
        M = l
print(M)

Submission status: Accepted

Solution code:
a = int(input())
b = str(input())

res = []
def finder(A,B):
    goi = 0
    for k in range(97, 97+26):
        num = chr(k)
        if num in A and num in B:
            goi += 1
    else:
        return goi

for i in range(1,a):
    c = b[0:i]
    d = b[i:a]
    tyu = finder(c,d)
    
    res.append(tyu)
else:
    bigg = max(res)
    print(bigg)

Submission status: Accepted

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

M = 0
for n in range(1,N) :
    set1 = set([])
    set2 = set([])
    I = set([])
    for c in (S[:n]) :
        set1.add(c)
    for d in (S[n:]) :
        set2.add(d)
    I = set1 & set2
    if(len(I)>M) :
        M = len(I)
print(M)

Submission status: Accepted

Solution code:
n=int(input())
x=input()
s=list(x)
list=[]
 
for i in range(n):
    a=0
    moji=[]
    for j in range(i):
        for k in range(n-i):
            if s[j]==s[k+i]:
                if s[j] not in moji:
                    a+=1
                    moji.append(s[j])
    list.append(a)
 
f=max(list)
print(f)

Submission status: Accepted

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

def count(s, c):
    for i in range(0, len(s)):
        idx = ord(s[i]) - ord('a')
        if idx < 30:
            c[idx] += 1

max = 0
for i in range(1, n):
    a = s[0:i]
    b = s[i:]
    ca = [0 for i in range(30)]
    cb = [0 for i in range(30)]
    count(a, ca)
    count(b, cb)

    t = 0
    for j in range(0, 26):
        if ca[j] > 0 and cb[j] > 0:
            t += 1
    if t > max:
        max = t
print(max)

Submission status: Accepted

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

m = 0
for i in range(1, n):
    sub1 = set(s[:i])
    sub2 = set(s[i:])
    count = 0
    for c in sub1:
        if c in sub2:
            count += 1
    if m < count:
        m = count


print(m)

Submission status: Accepted

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

# 桁数
N = int(input())
# 文字列
S = input()

max_v = 0
for i in range(1,N):
    sXY = set(list(''.join(list(S[:i])))) & set(list(''.join(list(S[i:]))))
    if max_v < len(sXY):
    	max_v = len(sXY)

print(max_v)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
ans = 0
for i in range(1,n):
    cnt = 0
    flag = []
    for j in range(0,i):
        for k in range(i,n):
            if s[j]==s[k] and s[j] not in flag:
                cnt += 1
                flag.append(s[j])
                break

    ans = max(ans,cnt)

print(ans)

Submission status: Accepted

Solution code:
import sys

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

if n == 0 or n == 1:
    print(n)
    sys.exit()

ans = 0
for i in range(1, n):
    x = s[0:i]
    y = s[i:]

    x_set = set(x)
    y_set = set(y)
    x_and_y = x_set & y_set
    z = len(x_and_y)
    if ans < z:
        ans = z
print(ans)

Submission status: Accepted

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

c = 0
x = ""
for i in range(n):
    a = 0
    x = s[0:i]
    y = s[i:n]
    for j in x:
        if j in y:
            y = y.replace(j, "")
            a += 1

        if a > c:
            c = a

print(c)

Submission status: Accepted

Solution code:
import copy

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

maxcount = 0
for i in range(1,n):
    count = 0
    X = set(s[:i])
    Y = set(s[i:])
    
    for j in X:
        for k in Y:
            if j == k:
                count += 1
        
    if maxcount < count:
        maxcount = count
        
print(maxcount)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
lst = []
flag = True
for i in range(1,N):
    X = S[0:i]
    Y = S[i:N]
    xlst = list(X)
    ylst = list(Y)
    Zlst = list(set(xlst) & set(ylst))
    z = len(Zlst)
    lst.append(z)
    i=i+1
print(max(lst))

Submission status: Accepted

Solution code:
import string
import itertools


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

    front = [set()]
    for c in s:
        x = front[-1] | set([c])
        front.append(x)
        
    back = [set()]
    for c in reversed(s):
        x = back[0] | set([c])
        back.insert(0, x)
    
    m = 0
    for f, b in zip(front, back):
        x = f & b
        m = max(m, len(x))
    
    print(m)

main()

Submission status: Accepted

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

Submission status: Accepted

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

N = int(input())
S = list(map(str, input().split()))
s=list(S[0])
c=[]

for i in range(1,N):
    a_and_b = list(set(s[0:i]) & set(s[i:N]))
    c.append(int(len(a_and_b)))

print(max(c))