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:
#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)

#出力
if N == 2:
	if S[0] == S[1]:
		print("1")
	else:
		print("0")
	exit()
print(max(ans))

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
x_sum=[]
y_sum=[]
for i in range(n):
    x = s[0:i]
    y = s[i:n]
    x_sum.append(x)
    y_sum.append(y)
m = []
for i in range(1,n):
    x_list = list(x_sum[i])
    x_unique = list(set(x_list))
    l = 0
    for j in x_unique:
        if y_sum[i].find(j) > -1:
            l += 1
    m.append(l)
print(max(m))

Submission status: Accepted

Solution code:

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


S1 = []
S2 = []
score = 0
ans = 0
scorelist = []
alphabet = [chr(i) for i in range(97, 97+26)]
for i in range(N-1):
    S1 = S[0:i+1]
    S2 = S[i+1:N]
    score = 0
    for n in range(26):
        if alphabet[n] in S1:
            if alphabet[n] in S2:
                score += 1
        scorelist.append(score)
ans = max(scorelist)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
s = s[:n]
words = []

for i in range(n):
	a = list(s[:i])
	b = list(s[i:])
	aset = set(a)
	bset = set(b)
	c = len(aset & bset)
	words.append(c)

print(max(words))

Submission status: Accepted

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

saidai = 0

for i in range(1,N):
    cnt = 0
    search = []
    tmp1 = S[0:i]
    tmp2 = S[i:N]
    for k in range(len(tmp1)):
        if tmp1[k] not in search:
            search.append(tmp1[k])
    for j in range(len(search)):
        if search[j] in tmp2:
            cnt += 1
    if saidai < cnt:
        saidai = cnt

print(saidai)

Submission status: Accepted

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

# numは1からn-1まで
def mozisu(text, num):
    ans = 0
    wc = {}
    for i in text[:num]:
        wc[i] = True
    for i in text[num:]:
        if i in wc:
            if wc[i]:
                wc[i] = False
                ans += 1
    return ans

max = 0
for i in range(len(S)-1):
    x = mozisu(S, i+1)
    if x > max:
        max = x
print(max)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1, n-1):
	s1 = set(list(s[:i]))
	s2 = set(list(s[i:]))
	c = len(list(s1 & s2))
	if c > ans:
		ans = c
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

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

alphabet = ["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"]

max_count = 0

for i in range(1, n):
    left = s[0:i]
    right = s[i:n]
    count = 0
    for x in alphabet:
        if left.find(x) != -1 and right.find(x) != -1:
            count += 1
    if max_count < count:
        max_count = count
        
print(max_count)

Submission status: Accepted

Solution code:
import string

N = int(input())
s = str(input())

alphabet = string.ascii_lowercase
num_list = []

for i in range(N):
    count_alphabet = [0 for k in range(len(alphabet))]
    first = s[i:]
    end = s[:i]
    for j in first:
        if j in end:
            count_alphabet[alphabet.index(j)] = 1
    num_list.append(count_alphabet.count(1))

print(max(num_list))

Submission status: Accepted

Solution code:
from sys import stdin

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

str = []
for i in range(N):
    str.append(S[i])

result = 0

for i in range(N-1):
    front = str[:i+1]
    tail = str[i+1:]
    tmp = len(set(front) & set(tail))
    if tmp > result:
        result = tmp

print(result)

Submission status: Accepted

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)

if (len(n_list) > 0):
    print(max(n_list))
else:
    print(0)

Submission status: Accepted

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

for i in range(len(S)-1):
    #print(S[i+1:])
    #print(S[:i+1])
    Foward=set(S[i+1:])
    Rear=set(S[:i+1])
    count_prev=res
    count=0

    for j in Foward:
        #print(Foward[i+1:])
        #print(Rear)
        #print(j)
        if(j in Rear):
            #print("out")
            count+=1
            #print(count)
    res=max(count,count_prev)
    #print(count,count_prev)
print(res)

Submission status: Accepted

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

Ans = 0

for i in range(len(S)):
	X = set(S[:i])
	Y=set(S[i:])
	numAND = len(X & Y)
	if numAND >= Ans:
		Ans = numAND
print(Ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#入力
N = int(input())
S = input()
#s1,s2は分割した文字列,kはどちらにもある文字,rはkの要素数（どちらにもある文字の種類）
k = []
r = []

for i in range(len(S)):
    #分割
    s1 = S[0:i]
    s2 = S[i:len(S)]
    #s1の各文字がs2にあるか
    for j in range(len(s1)):
        if s2.find(s1[j:j+1]) != -1:
            #kに既に入っていなければ追加
            if (s1[j:j+1] in k) == False:
                k.append(s1[j:j+1])
                
    r.append(len(k))
    k.clear()

#rの最大の要素を返す
r.sort()
r.reverse()
print(r[0])

Submission status: Accepted

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

r_count = 0

for x in range(N - 1):   
    a = list(S[0:x + 1])
    b = list(S[x + 1: N])
    a_u_l = list(set(a))
    b_u_l = list(set(b))
    count = 0
    for a_u in a_u_l:
        if a_u in b_u_l:
            count = count + 1
    if count >= r_count:
        r_count = count
        
print(r_count)

Submission status: Accepted

Solution code:
N = int(input())
a = list(input())
 
l = [] #個数リスト
alphabet = 'abcdefghijklmnopqrstuvwxyz'

for i in range(N):
    count = 0
    x = a[:i]
    y = a[i:]
    for letter in alphabet:
        if letter in x and letter in y:
            count += 1
    l.append(count)
    
print(max(l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
counted = []
for i in range(1, n):
    c = 0
    counted_char = []
    for j in s[:i]:
        if j in s[i:] and j not in counted_char:
            c += 1
            counted_char.append(j)
    counted.append(c)

print(max(counted))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
mx = 0
for i in range(n):
    fw = set(s[:i+1])
    df = set(s[i+1:])
    if mx < len(fw&df):
        mx = len(fw&df)
print(mx)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
S=input()

list1=["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"]
list2=[]
for i in range(1,N):
    
    count=0
    for j in range(26):
        if S[:i].count(list1[j])>=1 and S[i:].count(list1[j])>=1:
            count=count+1
    list2.append(count)
#print(S[:3])
#print(S[4:])
#print(list2)
print(max(list2))

Submission status: Accepted

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

for i in range(n):
    a = set(s[:i+1])    
    b = set(s[i+1:])
    l = len(a & b)
    if l > max:
        max = l
print(max)

Submission status: Accepted

Solution code:
import copy

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

count = 0


#それぞれの文字数をカウントする
for i in range(len(S)):#どこで区切るか
    left = S[0:i]
    right = S[i:]
    left = set(left)
    right = set(right)
    sumsum = left & right
    sumsum = len(sumsum)
    if sumsum > count:
        count = copy.deepcopy(sumsum)

print(count)

Submission status: Accepted

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

ans = 0
for i in range(n):
    x = s[0:i]
    y = s[i:n]
    temp = 0
    for ch in range(ord('a'), ord('z')+1):
        ch = chr(ch)
        if ch in x and ch in y:
            temp += 1
    ans = max(ans, temp)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=str(input())
a=[]
Slist=list(S)
for i in range(0,N):
    slice=S[0:i]
    slice=S[i:N]
    S1list=list(S[0:i])
    S2list=list(S[i:N])
    set1=set(S1list)
    set2=set(S2list)
    match=list(set1 & set2)
    a.append(len(match))
print(max(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
l = {}
r = {}
ans = 0
nagasa = len(s)
for i in range(1, nagasa):
    l = set(s[0:i])
    r = set(s[i:nagasa+1])
    tmp = len(l&r)
    if ans < tmp:
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
s= input()

M = 0

for i in range(N):
    temp = 0
    l1,l2 = s[:i],s[i:]
    n1 , n2 = Counter(l1), Counter(l2)
    for c in n1.keys():
        if c in n2.keys():
            temp += 1
    if temp >= M:
        M = temp

print (M)

Submission status: Accepted

Solution code:
input()
target = list(input())
ret = 0
for i in range(len(target)):
    bSet = set(target[:i])
    aSet = set(target[i:])
    inter = bSet & aSet
    if ret < len(inter):
        ret = len(inter)
print(ret)

Submission status: Accepted

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

lst = []
for i in range(1,len(s)):
    s1 = s[:i]
    s2 = s[i:]
    #print(s1,s2)
    
    sls1 = []
    sls2 = []
    for j in range(len(s1)):
        sls1.append(s1[j])
    for j in range(len(s2)):
        sls2.append(s2[j])
    s1 = sls1
    s2 = sls2
    s1.sort()
    s2.sort()
    #print(s1,s2)
    
    sls1 = [s1[0]]
    for j in range(1,len(s1)):
        if s1[j] != s1[j-1]:
            sls1.append(s1[j])
    sls2 = [s2[0]]
    for j in range(1,len(s2)):
        if s2[j] != s2[j-1]:
            sls2.append(s2[j])
    s1 = sls1
    s2 = sls2
    #print(s1,s2)
    
    cnt = 0
    for j in range(len(s1)):
        for k in range(len(s2)):
            if s1[j] == s2[k]:
                cnt += 1
    lst.append(cnt)
lst.sort()
#print(lst)
print(lst[-1])

Submission status: Accepted

Solution code:
n = int(input())
s = input()
max = 0
for i in range(n-1):
    be = s[:i+1]
    af = s[i+1:n]
    c = []
    d = []
    count = 0
    for j in range(len(be)):
        if not be[j] in c:
            c.append(be[j])
    for k in range(len(af)):
        if not af[k] in d:
            d.append(af[k])
    for l in c:
        if l in d:
            count += 1
    if count > max:
        max = count

print(max)

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(input())
S = input()
maxd = 0
for a in range(1,N-1):
    X = set([])
    Y = set([])
    for x in range(0,a):
        X.add(S[x])
    for y in range(a,N):
        Y.add(S[y])
    diffnum = len(X&Y)
    maxd = max(diffnum,maxd)
print(maxd)

Submission status: Accepted

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

res = 0
for i in range(N):
    s1 = set(S[:i])
    s2 = set(S[i:])
    res = max(res,len(s1&s2))
print(res)

Submission status: Accepted

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

# 閾値nで数号を分割
def cal(n):
    result = 0
    former = set()
    latter = set()
    for i in range(N):
        if i <= n:
            former.add(S[i])
        else:
            latter.add(S[i])
    union = former & latter
    if result < len(union):
        result = len(union)
    return result

for i in range(N):
    a.append(cal(i))
print(max(a))

Submission status: Accepted

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

cnt_MAX = 0
for i,s in enumerate(S):
    X = S[:i]
    Y = S[i:]
    cnt = 0
    for x in set(list(X)):
        if x in Y:
            cnt += 1
    if cnt > cnt_MAX:
        cnt_MAX = cnt
print(cnt_MAX)

Submission status: Accepted

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

nummax = 0
for i in range(1, len(s)):
    s1 = s[0:i]
    s2 = s[i:]
    s1s = set()
    for j in s1:
        s1s.add(j)
    num = 0
    for j in s1s:
        if s2.count(j):
            num += 1
    nummax = max(nummax, num)

print(nummax)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
o_s = list(set(s))
counter = 0
max = 0
for i in range(1,n):
    left = set(s[0:i])
    right = set(s[i:n])
    for j in left:
        if(j in right):
            counter += 1
    if max < counter :
        max = counter
    counter = 0
print(max)

Submission status: Accepted

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

max = 0
for i in range(N):
 cnt = 0
 common = []
 X = S[0:i]
 Y = S[i:N]
 for k in X:
  if k in Y and k not in common:
   common.append(k)
   cnt += 1
 if cnt > max:
  max = cnt

print(max)

Submission status: Accepted

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

Submission status: Accepted

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

num_type_max = 0

for i in range(1, N-1):
    s1 = set(S[:i])
    s2 = set(S[i:])

    num_type = 0
    for s in s1:
        if s in s2:
            num_type += 1
    if num_type > num_type_max:
        num_type_max = num_type

print(num_type_max)

Submission status: Accepted

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

s = list(S)

max = 0
for i in range(1,N-1):
    count = 0
    X = s[0:i]
    Y = s[i:N]
    x = list(set(X))
    y = list(set(Y))
    for j in x:
        if j in y:
            count += 1

    if count > max:
        max = count

print(max)

Submission status: Accepted

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

Submission status: Accepted

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

alpha="abcdefghijklmnopqrstuvwxyz"

count=0
max=0

for i in range(1,n):
    x=s[:i]
    y=s[i:]
    for j in range(len(alpha)):
        if alpha[j] in x and alpha[j] in y:
            count+=1
    if count>max:
        max=count
    count=0

print(max)

Submission status: Accepted

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

mx = 0

# print(s)

for i in range(0, n):
    f = s[:i]
    b = s[i:]

    # print(i)
    res = 0
    l = []
    # print(i)
    for fi in f:
        # print(fi)
        if fi in b:
            # print('!')
            if not fi in l:
                l.append(fi)
                res += 1
    # print(res)

    if res > mx:
        # print(mx)
        mx = res

print(mx)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

n =int(input())

s = list(input())
num =[]
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
for i in range(1,n,1):
    x = []
    y = []
    for j in range(0,i,1):
        x.append(s[j])
    for j in range(i,n,1):
        y.append(s[j])
    answer = 0
    for a in alphabet:
        if (a in x) and (a in y):
            answer += 1
    num.append(answer)
#    print(x,y)

print(max(num))
#print(num)

Submission status: Accepted

Solution code:
# ABC098_B
num = int(input())
str = input()
alphabets = [chr(ord('a') + i) for i in range(26)]

answer=0

for i in range(1, num):
    strLeft = str[0:i]
    strRight = str[i:num]
    common=0
    for j in alphabets:
        if ((j in strLeft) and (j in strRight)):
            common+=1
    if(answer < common):
        answer=common

print(answer)

Submission status: Accepted

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

c = 0
for a in range(0, N-1):
	left = set(S[0:a])
	right = set(S[a:N])
	unio = left & right
	c = max(c, len(unio))

print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re

if __name__ == '__main__':
	N = int(input())
	S = input()
	res = [0 for _ in range(N)]

	for i in range(N):
		a = S[:i]
		b = S[i:]
		count = set()

		for j in range(len(a)):
			for k in range(len(b)):
				if a[j] == b[k]:
					count.add(str(a[j]))
					break

		res[i] = len(count)

	print(max(res))

Submission status: Accepted

Solution code:
N = int(input())
s = input()
max = 0
for i in range(N):
    set_a = set(s[0:i])
    set_b = set(s[i:])
    num = set_a & set_b
    if len(num) > max:
        max = len(num)
print(max)

Submission status: Accepted

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

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

    print(maxlen)

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = input()
ans = []
if n != 2:
    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))
else:
    if s[0] == s[1]:
        print('1')
    else:
        print('0')

Submission status: Accepted

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

n = int(N)
tmp = ""
dic = {}
ans = 0

for i in range(n):
    tmp += S[i]
    dic_tmp = [False for i in range(123 - 97)]
    dic = [False for i in range(123 - 97)]

    for j in tmp:
        dic_tmp[ord(j) - 97] = True

    for j in range(i + 1, n):
        dic[ord(S[j]) - 97] = True

    ct = 0
    for k in range(len(dic)):
        if dic_tmp[k] == True and dic[k] == True:
            ct += 1

    ans = max(ans, ct)

print(ans)

Submission status: Accepted

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

both = 0
for i in range(1, n):
	a = list(set(s[0:i]))
	b = list(set(s[i:n]))
	botht = 0
	for al in a:
		if(al in b):
			botht += 1
	if(both < botht):
		both = botht
		
print(both)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
S=input()
ans = 0
for i in range(1,N):
    tmp1 = S[0:i]
    tmp2 = S[i:N+1]
    count=0
    for j in set(tmp1):
        if j in tmp2:
            count+=1
    ans = max(ans,count)

print(ans)

Submission status: Accepted

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


def create_map(s):
    m = {}
    for c in s:
        if c in m:
            m[c] += 1
        else:
            m[c] = 1
    return m


def common(m1, m2):
    c = 0
    # print(m1)
    # print(m2)
    for key in m1.keys():
        if key in m2:
            c += 1
    # print('commmon = ' + str(c))
    return c


m = 0
for i in range(1, len(S)):
    # print(S[:i])
    # print(S[i:])
    m1 = create_map(S[:i])
    m2 = create_map(S[i:])
    com = common(m1, m2)
    if com > m:
        m = com

print(m)

Submission status: Accepted

Solution code:
N = input()
S = list(input())
max_ = 0
alphabets = [chr(i) for i in range(97, 97+26)]
for i in range(1, len(S)-1):
    x = S[:i]
    y = S[i:]
    match = 0
    for a in alphabets:
        if a in x and a in y:
            match += 1
    if match > max_:
        max_ = match
print(max_)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
l = []
count = 0
r = count
for i in range(n):
  a = s.pop(0)
  if (a in s) and (a not in l):
    count += 1
    if count > r:
      r = count
  elif (a not in s) and (a in l):
    count -= 1
  l.append(a)
print(r)

Submission status: Accepted

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

max = 0
for k in range(n):
    alpha = ""
    for i in range(k):
        for j in range(k, n):
            if s[i] == s[j]:
                if alpha.find(s[i]) < 0:
                    alpha += s[i]
    if len(alpha) > max:
        max = len(alpha)
print(max)

Submission status: Accepted

Solution code:
N = int(input())
s = list(input())
count = [0] * N

for i in range(1,N):
    # print(s[0:i], s[i:N])
    left = set(s[0:i])
    right = set(s[i:N])
    count[i] = len(left & right)
print(max(count))

Submission status: Accepted

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

# スペース区切りの整数の入力
a = int(input())
s = input()

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

# 出力
print("{}".format(max(temp)))

Submission status: Accepted

Solution code:
import math
import numpy as np


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

count = 0

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

print(count)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = input()
ans = 0 
for i in range(1,N):
    temp = list(set(S[0:i]))
    temp2 = list(set(S[i:N]))
    temp_ans =0
    for j in range(len(temp)):
        if temp[j] in temp2:
            temp_ans += 1
    if temp_ans>ans:
        # print(temp)
        # print(temp2)
        ans = temp_ans
        # ans2 = i
        # print(i)
print(ans)

Submission status: Accepted

Solution code:
import sys
if __name__ == "__main__":
    N = int(input())
    S = input()
    max = 0
    for i in range(1, N):
        s1 = S[0:i]
        s2 = S[i:N+1]
        buf = list(set(s1))
        buf2 = list(set(s2))
#        print(s1)
#        print(buf)
#        print(buf2)
        cnt = 0
        for i in range(len(buf)):
            if buf[i] in buf2:
                cnt += 1
#        print(cnt)
        if cnt > max:
            max = cnt
    print(max)

Submission status: Accepted

Solution code:
def m():
    n = int(input())
    s = str(input())
    ans = 0
    for i in range(1, n):
        cnt = 0
        left = set(s[i:])
        right = set(s[:i])
        for j in left:
            if j in right:
                cnt +=1
        ans = max(cnt, ans)
    return ans

print(m())

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    x = s[:i]#最初のi文字
    y = s[i:]

    setX = set(x)
    setY = set(y)
    
    ans = max(ans, len(setX & setY))#積

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
ans = 0
for i in range(n):
	a = set(s[:i])
	b = set(s[i:])
	count = 0
	for j in b:
		if j in a:
			count += 1
			if ans <= count:
				ans = count
print(ans)

Submission status: Accepted

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

res = [None] * n

for i in range(n):
    l = s[:i]
    r = s[i:]
    cnt = 0
    chk_s = ""

    for j in range(i):
        if not l[j] in chk_s:
            chk_s += l[j]
            if l[j] in r:
                cnt += 1

    else:
        res[i] = cnt

print(max(res))

Submission status: Accepted

Solution code:
N = int(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+1:]
  answer = len(list(set(str_first) & set(str_second)))
  ans_list.append(answer)
  
print(max(ans_list))

Submission status: Accepted

Solution code:
import collections

n = int(input())
s = input()
max_number = 0

for i in range(n-1):
  front = collections.Counter(s[:i+1])
  back = collections.Counter(s[i+1:])
  number = len(front.keys() & back.keys())
  if number > max_number:
    max_number = number

print(max_number)

Submission status: Accepted

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

chars = list(S)
ans = 0
for i in range(N-1):
  set_a = set(chars[0:i+1])
  set_b = set(chars[i+1:])
  ans = max(ans, len(set_a & set_b))
print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())
s = [c for c in raw_input()]

r = 0
for i in range(1, n):
    x = set(s[:i])
    y = set(s[i:])
    r = max(r, len(x.intersection(y)))

print r

Submission status: Accepted

Solution code:
N = int(input())
S = input()
# N = 6
# S = 'aabbca'

max = 0
for i in range(1, N):
    sum = 0
    # print(S[:i])
    # print(S[i:N])
    forward = list(set(S[:i]))
    back = list(set(S[i:N]))
    for j in range(len(forward)):
        if forward[j] in back:
            sum += 1
    if sum > max: max = sum

print(max)

Submission status: Accepted

Solution code:
n = int(input())

s = input()

result = 0
for i in range(1, len(s)):
    f_s = s[:i]
    b_s = s[i:]
#    print(f_s)
#    print(b_s)
    
    f_s_set = set(f_s)
    b_s_set = set(b_s)
    
    matched_s = list(f_s_set & b_s_set)
    if(len(matched_s) > result):
        result = len(matched_s)

print(result)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
c = []
for i in range(1,N):
    a = S[:i]
    b = 0
    d = S[i:]
    for j in set(a):
        if j in d:
            b += 1
    c.append(b)

print(max(c))

Submission status: Accepted

Solution code:

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

    m = 0
    for i in range(1, len(s)):
        s1 = set()
        s2 = set()
        for x in s[0:i]:
            s1.add(x)
        for x in s[i:]:
            s2.add(x)
                
        m = max(m, len(s1 & s2))

    print(m)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
a = 0
for i in range(1, n-1):
    cc = 0
    for c in set(s[:i]):
        if c in set(s[i:]):
            cc += 1
    a = max(a, cc)
print(a)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
max = 0
lis = []
for i in range(N):
    X = S[0:i]
    Y=S[i:N]
    X = list(set(X))
    Y = list(set(Y))
    lis = list(set(X) & set(Y))
    l = len(lis)
    if(l>max):max=l

print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(raw_input())
q = raw_input()

m = -1

for a in range(len(q)):
  dic1 = {}
  dic2 = {}
  buf = 0
  for b in range(len(q)):
    if a > b: dic1[ q[b] ] = 1
    else: dic2[ q[b] ] = 1

  for z in dic1:
    if z in dic2:
      buf += 1
  if m < buf:
    m = buf
print m

Submission status: Accepted

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

result = 0
for i in range(n-1):
  pre = set()
  suf = set()
  for j in range(i+1):
    pre.add(s[j])
  for k in range(i+1,n):
    suf.add(s[k])
  result = max(result,len(pre&suf))
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

maxCount = 0

if N == 2:
    print(len(set(S[0])&set(S[-1])))
else:
    for i in range(N):
        commonCount = len(set(S[0:i+1])&set(S[i+1:]))
        if maxCount < commonCount:
            maxCount = commonCount
    print(maxCount)

Submission status: Accepted

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

@author: maezawa
"""

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

ans = 0
for i in range(1,n):
    s1 = set(s[:i])
    s2 = set(s[i:])
    #print(s1)
    #print(s2)
    cnt = len(s1.intersection(s2))
    if ans < cnt:
        ans = cnt

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

import os
import sys

def main():
    result = 0
    list_length = int(input())
    data = list(input())
    for i in range(list_length):
        c = and_count(data[:i], data[i:])
        if result < c:
            result = c
    print(result)

def and_count(l1, l2):
    s1 = set(l1)
    s2 = set(l2)
    return len(list(s1 & s2))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

m = 0
for i in range(1, n):
    s1 = set(s[0:i])
    s2 = set(s[i:])
    common = len(s1 & s2)
    if m < common:
        m = common

print(m)

Submission status: Accepted

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

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

        s1_dic = {chr(j):0 for j in range(ord('a'), ord('a')+26)}
        for j in range(len(s1)):
            s1_dic[s1[j]] = s1_dic.get(s1[j], 0) + 1

        s2_dic = {chr(j): 0 for j in range(ord('a'), ord('a') + 26)}
        for j in range(len(s2)):
            s2_dic[s2[j]] = s2_dic.get(s2[j], 0) + 1

        cnt = 0
        for k in s1_dic:
            if s1_dic[k] != 0 and s2_dic[k] != 0:
                cnt += 1

        c_lst.append(cnt)

    print(max(c_lst))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
max_word = 0
for i in range(1, n):
    set_s1 = set(s[:i])
    set_s2 = set(s[i:])

    sorted(set_s1)
    sorted(set_s2)
    
    cnt = 0
    for r in set_s1:
        for t in set_s2:
            if r == t:
                cnt += 1
                max_word = max(cnt, max_word)
    
print(max_word)

Submission status: Accepted

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