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:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

n=I()
s=input().rstrip()
alphasm=[chr(i) for i in range(97, 97+26)]
num=[]
for i in range(n):
    count=0
    k=list(s[0:i])
    l=list(s[i:n])
    for char in alphasm:
        if (char in k) and (char in l):
            count+=1
    num.append(count)
print(max(num))

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()
print(max([len(set(s[:i + 1]) & set(s[i + 1:])) for i in range(n - 1)]))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
tmp = []
for i in range(1, n):
    tmp.append([s[0:i], s[i:n]])

m = 0
for i in range(len(tmp)):
    cnt = 0
    tmp2 = []
    for j in range(len(tmp[i][0])):
        if tmp[i][0][j] in tmp[i][1] and tmp[i][0][j] not in tmp2:
            cnt += 1
            tmp2.append(tmp[i][0][j])
    if cnt > m:
        m = cnt
print(m)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
al=list("abcdefghijklmnopqrstuvwxyz")
count=0
ans=0
for i in range(1,n):
  left=set(s[:i])
  right=set(s[i:])
  for j in al:
    if j in left and j in right:
      count+=1
  if ans<=count:
    ans=count
  count=0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
keep=-1
for i in range(0,n-1):
  left=s[:i+1]
  migi=s[i+1:]
  lis=[]
  count=0
  for j in range(0,len(left)):
    t=left[j]
    if not t in lis:
      if t in migi:
        count+=1
    lis.append(t)
  if count>keep:
    keep=count
print(keep)

Submission status: Accepted

Solution code:
from collections import OrderedDict

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

ans = 0
for i in range(N):
    if (i == N - 1):
        break
    L = ''.join(OrderedDict.fromkeys(S[0:i + 1]))
    R = ''.join(OrderedDict.fromkeys(S[i + 1:]))
    count = 0
    for j in range(len(L)):
        if (L[j] in R):
            count += 1
        else:
            continue
    ans = max(ans, count)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
S=input()
ans=0
for i in range(n-1):
    L=S[:i+1]
    R=S[i+1:]
    C=[]
    for l in L:
        if not l in C:
            if l in R:
                C.append(l)
    ans=max(len(C),ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
Max = 0
for i in range(1, len(s)): # i = 1
    length = len(set(s[:i]) & set(s[i:]))
    if length > Max:
        Max = length
print(Max)

Submission status: Accepted

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


def read():
    N = int(input().strip())
    S = input().strip()
    return N, S


def solve(N, S):
    Z = 26
    cl = [[0 for j in range(Z)] for i in range(N)]  # [0, l)
    cr = [[0 for j in range(Z)] for i in range(N)]  # [l, N)
    for i in range(N):
        if i > 0:
            for j in range(Z):
                cl[i][j] = cl[i-1][j]
        s = ord(S[i]) - ord('a')
        cl[i][s] += 1
    for i in range(N-1, -1, -1):
        if i < N-1:
            for j in range(Z):
                cr[i][j] = cr[i+1][j]
        s = ord(S[i]) - ord('a')
        cr[i][s] += 1

    max_chars = 0
    for i in range(1, N):
        chars = 0
        for j in range(Z):
            if cl[i-1][j] > 0 and cr[i][j] > 0:
                chars += 1
        max_chars = max(max_chars, chars)
    return max_chars


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

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

type_num = 0
for i in range(1,n):
    left_s = list(set(s[0:i]))
    right_s = list(set(s[i:n]))
    
    tmp = 0
    for j in left_s:
        if j in right_s:
            tmp += right_s.count(j)
            type_num = max(type_num, tmp)
print(type_num)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc098/tasks/abc098_b


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

    ans = 0
    for i in range(1, N):
        X = S[:i]
        Y = S[i:]
        tmp = 0
        for code in range(97, 97+26):
            c = chr(code)
            if c in X and c in Y:
                tmp += 1
        
        if tmp > ans:
            ans = tmp
        
    return ans


print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop

import collections

n = int(input())
s = input()
u = ""
v = ""
ans = 0
for i in range(n):
    u += s[i]
    v = ""
    for j in range(i+1,n):
        v += s[j]
    u2 = collections.Counter(u)
    v2 = collections.Counter(v)
    ukey = []
    vkey = []
    for key in u2.keys():
        ukey.append(key)
    for key in v2.keys():
        vkey.append(key)
    same = 0
    for i in ukey:
        for j in vkey:
            if i == j:
                same += 1
    ans = max(ans,same)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = str(input())

ans = 0
for i in range(1,n):
    tmp1 = Counter(s[:i]).keys()
    tmp2 = Counter(s[i:]).keys()

    same = set(tmp1) & set(tmp2)

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import time
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    S = input()
    ans = 0
    for i in range(N):
        X = set(S[:i])
        Y = set(S[i:])
        ans = max(ans, len(X&Y))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
cnts = []
for i in range(N-1):
    A = set(S[0:i+1])
    B = set(S[i+1:N])
    cnt = 0
    for a in A:
        if a in B:
            cnt += 1
    cnts.append(cnt)
print(max(cnts))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
m=0
for i in range(n):
  s1=s[:i]
  a1=set()
  for j in s1:
    a1.add(j)
  s2=s[i:]
  a2=set()
  for j in s2:
    a2.add(j)
  uni=a1 & a2
  if m<len(uni):
    m=len(uni)
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n = int(input())
s = input()
ans = 0
for i in range(1, n):
    left = set(s[: i])
    right = set(s[i : n])
    ans = max(ans, len(left & right))
print(ans)

Submission status: Accepted

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

import collections
ans = 0
for i in range(1, n):
    #print(s[:i], s[i:])
    c1 = collections.Counter(s[:i])
    c2 = collections.Counter(s[i:])
    p = c1.keys() & c2.keys()
    #print(p)
    if len(p) > ans:
        ans = len(p)
print(ans)

Submission status: Accepted

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

    count = 0
    max_count = 0
    for i in range(N - 1):
        if S[i] not in S[:i]:
            if S[i] in S[i + 1:]:
                count += 1
        elif S[i] not in S[i + 1:]:
            count -= 1
        max_count = max(count, max_count)

    print(max_count)

Submission status: Accepted

Solution code:
n=int(input())
slist=list(input())
saidai=0
for i in range(1,n):
    a=len(set(slist[0:i])&set(slist[i:n]))
    if a>saidai:
        saidai=a
print(saidai)

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    x = s[0:i] 
    y = s[i:n]
    xl = list(x)
    yl = list(y)
    cnt = 0
    pre = []
    for j in range(len(xl)):
        if xl[j] in yl and xl[j] not in pre:
            cnt += 1
            pre.append(xl[j])
    if ans < cnt:
        ans = cnt
print(ans)

Submission status: Accepted

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

max_chars = 0
for i in range(1, len(s)):
    s1, s2 = s[:i], s[i:]
    s1_chars = set(s1)
    s2_chars = set(s2)

    same_chars = s1_chars & s2_chars
    max_chars = max(max_chars, len(same_chars))

print(max_chars)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
a = []
ans = 0

for i in s:
    a.append(i)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
count = 0
for a in range(1,N-2):
    b = set(S[0:a])
    c = set(S[a:])
    d = len(b&c)
    if d > count:
        count = d

print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    S=list(input())
    ans=0
    for i in range(100):
        ans=max(ans,len(set(S[:i])&set(S[i:])))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(1, n):
    a,b = set(s[:i]), set(s[i:])
    if max(len(a),len(b))-max(len(a-b),len(b-a))>x:
        x = max(len(a),len(b))-max(len(a-b),len(b-a))

print(x)

Submission status: Accepted

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

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

        yield len(left & right)


print(max(main()))

Submission status: Accepted

Solution code:
#ABC098-B
n = int(input())
s = input()
cnt = 0
for i in range(n):
    s1 = s[:i]
    s2 = s[i:]
    tmp = len(set(s1)&set(s2))
    if cnt < tmp:
        cnt = tmp
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
s = set(S)
count = 0
maxx = 0
for i in range(N): #切断場所
    for k in range(i):
        if S[k] in S[:i] and S[k] in S[i:] and S[k] not in S[:k]:
            count += 1
    maxx = max(maxx, count)
    count = 0
print(maxx)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
s = set(S)
count = 0
maxx = 0
for i in range(N): #切断場所
    for k in range(i):
        if S[k] in S[:i] and S[k] in S[i:] and S[k] not in S[:k]:
            count += 1
    maxx = max(maxx, count)
    count = 0
print(maxx)

Submission status: Accepted

Solution code:
from collections import Counter

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

counter = Counter(S)
ans = 0
for i in range(1, N):
    left_counter = Counter(S[:i])
    right_counter = Counter(S[i:])
    left_set = set(left_counter.keys())
    right_set = set(right_counter.keys())
    common_set = left_set & right_set
    ans = max(ans, len(common_set))

print(ans)

Submission status: Accepted

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

for i in range(N):
  x = set(list(S[0:i]))
  y = set(list(S[i:len(S)]))
  if len(x & y) > max:
    max = len(x & y)

print(max)

Submission status: Accepted

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

ans = 0
for i in range(1,N):
    cnt = 0
    zenhan = list(set(S[:i]))
    kouhan = list(set(S[i:]))
    for j in zenhan:
        if kouhan.count(j) == 1:
            cnt += 1
    else:
        ans = max(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
counter=0
alpha=list(set(list(S)))
for i in range(1,N):
    st=S[:i]
    gr=S[i:]
    count=0
    for j in range(0,len(alpha)):
        if st.count(alpha[j])!=0 and gr.count(alpha[j])!=0:
            count+=1
    if counter<count:
        counter=count
print(counter)

Submission status: Accepted

Solution code:
n=int(input())
s=list(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()
ans = 0
for i in range(n - 1):
    cnt = 0
    x = set(s[:i + 1])
    y = set(s[i + 1:n])
    cnt = len(x & y)
    if cnt > ans:
        ans = cnt
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def myAnswer(N:int,S:list) -> int:
   ans = 0
   for i in range(1,N):
      left = set(S[:i])
      right = set(S[i:])
      counter = 0
      for l in left:
         if(l in right):
            counter += 1
      ans = max(ans,counter)

   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   S = list(input())
   print(myAnswer(N,S[:]))

if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
s = list(input())
ans = 0
for i in range(1,n):
    be = set(s[:i])
    en = set(s[i:])
    ans = max(ans,len(be&en))

print(ans)

Submission status: Accepted

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


def solve(N: int, S: str):
    print(max(len(set(S[:i]) & set(S[i:])) for i in range(1, N)))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = []
tmp = 0
for i in range(N):
    for j in range(97,123):
        A = S[:i]
        B = S[i:]
        if A.count(chr(j)) > 0 and B.count(chr(j)) > 0:
            tmp += 1
    ans.append(tmp)
    tmp = 0
print(max(ans))

Submission status: Accepted

Solution code:
n=int(input())
s1=list(input())
s2=set()
s3=set()
tmp_s2=[]
tmp_s3=[]
max=0
for i in range(n-1):
    for j in range(i+1):
        tmp_s2.append(s1[j])
    s2=set(tmp_s2)
    tmp_s2.clear()
    for j in range(i+1,n):
        tmp_s3.append(s1[j])
    s3=set(tmp_s3)
    tmp_s3.clear()
    if max<len(s2&s3):
        max=len(s2&s3)
    s2.clear()
    s3.clear()
print(max)

Submission status: Accepted

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

max=0

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

Submission status: Accepted

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

a=[]
b=[]
max=0

for i in range(1,(N)):
  a=[]
  b=[]
  for j in range(i):
    #print(i,j,S[j])
    a.append(S[j])
  #print(a,len(set(a)))
  for j in range(i,N):
    #print(i,j,S[j])
    b.append(S[j])
  #print(b,len(set(b)))
  if len(set(a)&set(b))>max:
    max=len(set(a)&set(b))
print(max)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    S = input()

    res = 0
    for i in range(1, N):
        A = set(S[:i])
        B = set(S[i:])

        res = max(res, len(A & B))

    print(res)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

res = 0
for i in range(N):
    l = S[:i]
    r = S[i:]
    cnt = 0
    for j in set(l):
        if r.count(j) > 0:
            cnt += 1
    res=max(res,cnt)
print(res)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
max_1=0
for i in range(1,N):
  count=0
  counted=[]
  A=S[:i]
  B=S[i:]
  for j in A:
    if j not in counted and j in B:
      count+=1
      counted.append(j)
  max_1=max(max_1,count)

print(max_1)

Submission status: Accepted

Solution code:
from collections import Counter

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

ans = 0
for i in range(1,N):
    temp = 0
    left = S[:i]
    right = S[i:]
    left_words = Counter(left)
    right_words = Counter(right)
    for key1 in left_words.keys():
        for key2 in right_words.keys():
            if key1 == key2:
                temp += 1
    if temp > ans:
        ans = temp
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1,n):
    s_1 = set(s[:i])
    s_2 = set(s[i:])
    ans = max(ans, len(s_1.intersection(s_2)))

print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc098/tasks/abc098_b
n = int(input())
s = input()

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

Submission status: Accepted

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

ans = 0
for i in range(1, N):
    left = S[:i]
    right = S[i:]
    common = set(left) & set(right)
    if ans < len(common):
        ans = len(common)

print(ans)

Submission status: Accepted

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

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

ans=0
for i in range(1,n):
    a=set(s[:i])
    b=set(s[i:])
    c=a&b
    if len(c)>ans:
        ans=len(c)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
cl = [0]*N
for i in range(1,N):
  Y = S[i:]
  X = S[:i]
  X = list(set(X))
  Y = list(set(Y))
  count = 0
  for j in range(len(X)):
    for k in range(len(Y)):
      if X[j] == Y[k]:
        count += 1
  cl[i] = count

print(max(cl))

Submission status: Accepted

Solution code:
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    S = iss()
    print(max(len(set(S[:n]) & set(S[n:])) for n in range(N)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1, n - 1):
    sf = set(s[:i])
    sb = set(s[i:])
    cnt = 0
    for j in sf:
        if j in sb:
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Submission status: Accepted

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

i=0
ans=[]
while i<N:
    A=set(S[:i])
    B=set(S[i:])
    j=0
    count=0
    while j<len(A):
        count+=1*(list(A)[j]in B)
        j+=1
    ans.append(count)
    i+=1

print(max(ans))

Submission status: Accepted

Solution code:
icase=0
if icase==0:
    n=int(input())
    s=list(input())
    icmax=0
    for i in range(n):
        si=set(s[0:i])
        ti=set(s[i:n])
        icnt=len(si&ti) 
        icmax=max(icmax,icnt)
    print(icmax)

Submission status: Accepted

Solution code:
def countboth(s1,s2): #len(s1)<len(s2)だと早い
    count = 0
    alph = 'abcdefghijklmnopqrstuvwxyz'
    if len(s1)*len(s2) == 0:
        return 0
    
    for a in alph:
        if a in s1 and a in s2:
            count += 1
    return count

n = int(input())
s = input()
cmax = 0
i = 1
while i < n-1:
    if i < (n/2):
        s1, s2 = s[:i],s[i:]
    else:
        s2, s1 = s[:i],s[i:]
    cmax = max(countboth(s1,s2), cmax)
    i += 1
print(cmax)

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:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
s = ns()

ans = [0]

for i in range(1, n-1):
    set_x = set(s[:i])
    set_y = set(s[i:])
    ans.append(len(set_x & set_y))

print(max(ans))

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = input()
ans = 0
for i in range(1,N):
    cnt = 0
    count1 = Counter(S[:i])
    count2 = Counter(S[i:])
    for char in [chr(i) for i in range(97, 97+26)]:
        if char in count1.keys() and char in count2.keys():
            cnt += 1
    ans = max(ans, cnt)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=str(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']
l=[]
for i in range(n):
    x=s[:i]
    y=s[i:]
    c=0
    for j in alp:
        if (j in x) and (j in y):
            c+=1
    l.append(c)
print(max(l))

Submission status: Accepted

Solution code:
import sys  
import numpy as np

input = sys.stdin.readline
N = int(input())
S = list(input())

S = S[:-1]

temp = []
for i in range(1,N):
    a = S[:i]
    b = S[i:]
    a = list(set(a))
    b = list(set(b))

    j = list(set(a+b))
    
    temp.append(len(a) + len(b) - len(j))
    

print(max(temp))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# solution
import io

n,m = int(input()),input()
array=[]
for i in range(1,n):
    array.append(len(list(set(m[:i])&set(m[i:]))))
print(max(array))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
T=[]
for i in range(N):
    A=set(S[0:i])
    B=set(S[i:N+1])
    C=set(A&B)
    T.append(len(C))
print(max(T))