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: Runtime Error

Solution code:
N=int(input())
S=str(input())
idx_list=[]
for idx in range(len(S)-1):
    if S[idx]==S[idx+1]:
        idx_list.append(idx)

idx=max(idx_list)+1
sub_X=S[:idx]
sub_Y=S[idx:]

import collections
count_list_X=list(collections.Counter(sub_X).keys())
count_list_Y=list(collections.Counter(sub_Y).keys())


count=0
for str1 in count_list_X:
    for str2 in count_list_Y:
        if str1==str2:
            count+=1
            
print(count)

Submission status: Runtime Error

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

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

print(max)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
ans = 0
ka = []
for x in range(N):
    a = set(S[0:x])
    b = set(S[x:N-1]
    for y in a:
        for z in b:
            if b[z] == a[y]:
            ans += 1
    ka.append(ans)
    ans = 0

print(max(ka))

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=Int(input())
S=input()
for i in range(N):
  SR=S[(i+1):]
  SL=S[:(i+1)]
  count=0
  for j in SL:
    for k in SR:
  	  if(SL[j]===SR[k]):
    	count++
        break

  if(count_M<count):
  		count_M=count

print(count)

Submission status: Runtime Error

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

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

print(common)

Submission status: Runtime Error

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

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

print(common)

Submission status: Runtime Error

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

print(max(result))

Submission status: Runtime Error

Solution code:
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: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
S = int(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: Runtime Error

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-1)]))

Submission status: Runtime Error

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)
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: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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)
  c=max(c,a)
print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
c=0
for i in range(1,N):
  x=s[0:i]
  y=s[i:N]
  for j in range('a','z'+1):
    if j in x and j in y:
      c+=1
print(c)

Submission status: Runtime Error

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

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:
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: Runtime Error

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

posDevide = 1
maxMatchWordNum = 0

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

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

print(maxMatchWordNum)

Submission status: Runtime Error

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

posDevide = 1
maxMatchWordNum = 0

while posDevide < N:
        arrayNum = 1
        mutchWordNum = 0
        while arrayNum <=  posDevide:
                matchWordNum = matchWordNum + 1 if  bool( s.count[ arrayNum - 1 ], posDevide, N-1 ) else matchWordNum
                arrayNum + 1
        end
        maxMatchWordNum = matchWordNum if matchWordNum > maxMatchWordNum else maxMatchWordNum
        posDevide + 1
end

print(maxMatchWordNum)

Submission status: Runtime Error

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

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: Runtime Error

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

ans = list()

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

print(max(ans))

Submission status: Runtime Error

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: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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):
        print(s[0:i], s[i: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()
return B(n, s)

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:
N = int(input())
S = list(str(input()))
countlist=[]
for i in range(1,N-1):
    s1 = set(S[0:i])
    s2 = set(S[i:])

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

ans = max(countlist)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(str(input()))
countlist=[]
if N % 2 == 0:
    split = N / 2
    odd = False
else:
    split = N / 2 + 1
    odd = True
for i in range(1,N-1):
    s1 = set(S[0:i])
    s2 = set(S[i:])
    
    matched_list=list(s1 & s2)
    countlist.append(len(matched_list))

ans = sorted(countlist,reverse=True)


print(ans[0])

Submission status: Runtime Error

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 and

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
t = 0
for i in range(len(s)-1):
  a = {s[:i]} 
  b = {s[i+1:]}
  c = a & b
  print(c)
  if c > t:
    t = c

print(c)

Submission status: Runtime Error

Solution code:
N = int(input())
S = list(str(input()))
countlist=[]
anslist =[]
if N % 2 == 0:
    split = N / 2
    odd = False
else:
    split = N / 2 + 1
    odd = True
for i in range(1,N-1):
    if i > split:
        check = 0
    else:
        check = 1
    s1 = list(set(S[0:i]))
    s2 = list(set(S[i:]))
   # print(s1)
   # print(s2)
    if check == 0:
        for j in s2:
            if j not in s1:
                s2.remove(j)
    else:
        for j in s1:
            if j not in s2:
                s1.remove(j)
    if(check == 0):
        countlist.append(len(s2))
    else:
        countlist.append(len(s1))

ans = sorted(countlist,reverse=True)


print(ans[0])

Submission status: Runtime Error

Solution code:
#Cut and Count

#ライブラリ
import copy

#入力
N = int(input())
S = list(input())
ans = []
#計算
for j in range(1,N-1,1):
	counter = 0
	S_hidari = []
	S_migi = []
	S_hidari = set(copy.copy(S[0:j]))
	S_migi = set(copy.copy(S[j:N]))
	for s_hidari in S_hidari:
		for s_migi in S_migi:
			if s_hidari == s_migi:
				counter += 1
	ans.append(counter)

#出力
print(max(ans))

Submission status: Runtime Error

Solution code:
a = int(input())
s = input()
x=[]
y=[]
count=[]
for i in range (a):
    for j in range (i):
        x[j]=s[j]
    for k in range (a-i):
        y[k]=s[i+k]
    for l in range (i):
        for m in range (a-i):
            if x[l] == y[m]:
                count[i]+=1
                break
print(max(count))

Submission status: Runtime Error

Solution code:
n=input()
x=input()
s=list(x)
list=[]

for i in range(n):
    a=0;
    for j in range(i):
        for k in range(n-i):
            if s[j]=s[k]:
                a+=1
    list.append(a)

f=max(list)
print(f)

Submission status: Runtime Error

Solution code:

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

s_list = list(set(S))
n_list = []

for i in range(1, N - 2):
    line1 = S[:i]
    line2 = S[i:]
    num = 0
    for c in s_list:
        _1 = line1.count(c)
        _2 = line2.count(c)
        if (_1 > 0 and  _2 > 0):
            num += 1
    n_list.append(num)
    
print(max(n_list))

Submission status: Runtime Error

Solution code:

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

s_list = list(set(S))
n_list = []

for i in range(1, N - 1):
    line1 = S[:i]
    line2 = S[i:]
    num = 0
    for c in s_list:
        _1 = line1.count(c)
        _2 = line2.count(c)
        if (_1 > 0 and  _2 > 0):
            num += 1
    n_list.append(num)
    
print(max(n_list))

Submission status: Runtime Error

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

s_list = list(set(S))
n_list = []

for i in range(1, N - 1):
    line1 = S[:i]
    line2 = S[i:]
    num = 0
    for c in s_list:
        _1 = line1.count(c)
        _2 = line2.count(c)
        num += min(_1, _2)
    n_list.append(num)
    
print(max(n_list))

Submission status: Runtime Error

Solution code:
N = input()
str = input()
str_list=list(str)
ans_list=[]
for i in range N:
  str_first = str_list[0:i+1]
  str_second = str_list[i:]
  answer = set(str_first) & set(str_second)
  ans_list.append(answer)
  
print(max(ans_list))

Submission status: Runtime Error

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

for i in range(1,len(s)):
    #print(t[:i], t[i:])
    left = list(t[:i])
    right = list(t[i:])
    kyoutuu = set(left) & set(right)
    ans = max(ans,len(list(kyoutuu)))
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

def abc098_b():
    import numpy as np
    n = int(input())
    s = input()
    counts = []
    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: Runtime Error

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


count_list = []
for index in range(1, len(s) - 1):
    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: Runtime Error

Solution code:
n = int(input())
s = str(input())
ans = 0
for i in range(1,len(s)):
    #print(t[:i], t[i:])
    left = set(list(t[:1]))
    right = set(list(t[i:]))
    kyoutuu = left & right
    ans = max(ans,kyoutuu)
print(y)

Submission status: Runtime Error

Solution code:
n = int(input())
s = str(input())
ans = 0
for i in range(1,len(s)):
    #print(t[:i], t[i:])
    left = set(list(t[:1]))
    right = set(list(t[i:]))
    kyoutuu = left & right
    y = len(list((1,2,3)))
    ans = max(ans,y)
print(y)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
s = input()
ans = []
for i in range(1,n-1):
    counter = 0
    seg = s[0:i]
    another = s[i:n]
    d = collections.Counter(seg)
    for k in d:
        if k in another:
            counter += 1
    ans.append(counter)
print(max(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
s = str(input())
ans = 0
for i in range(1,len(s)):
    print(t[:i], t[i:])
    left = set(list(t[:1]))
    right = set(list(t[i:]))
    kyoutuu = left & right
    y = len(list((1,2,3)))
    ans = max(ans,y)
print(y)