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:
# https://atcoder.jp/contests/abc098/tasks/abc098_b
n = int(input())
s = input()
r = []
for i in range(len(s) - 1):
    x = s[:i+1]
    y = s[-len(s) + 1 + i:]
    r.append(len(set(x) & set(y)))
print(max(r))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(1, N):
        s1 = set(S[:i])
        s2 = set(S[i:])
        tmp = 0
        for c in s1:
            if c in s2:
                tmp += 1
        ans = max(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

alphabets = 'abcdefghijklmnopqrstuvwxyz'

ans = 0

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
M = 0
for i in range(N):
    X = set(S[0:i])
    Y = set(S[i:N])
    count = 0
    for j in X:
        if j in Y:
            count += 1
    M = max(M, count)
print(M)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
L=[]
for i in range(0,N):
  L1=list(S[0:i]);L2=list(S[i:N])
  L.append(len(list(set(L1)&set(L2))))
print(max(L))

Submission status: Accepted

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

if n == 2:
    if s[0] == s[1]:
        print(1)
        exit()
    else:
        print(0)
        exit()

for i in s:
    S.append(i)

ans = []

for j in range(1, n-1):
    count = 0
    l, r = set(S[:j]), set(S[j:])
    for k in l:
        if k in r:
            count += 1
    ans.append(count)

print(max(ans))

Submission status: Accepted

Solution code:
n=int(input())
hoge=input()
ans=[]
for i in  range(n-1):
  ho1=hoge[:i+1]
  ho2=hoge[i+1:]

  kari=0
  
  if(ho1.count("a") and ho2.count("a")):
    kari+=1
  if(ho1.count("b") and ho2.count("b")):
    kari+=1
  if(ho1.count("c") and ho2.count("c")):
    kari+=1
  if(ho1.count("d") and ho2.count("d")):
    kari+=1
  if(ho1.count("e") and ho2.count("e")):
    kari+=1
  if(ho1.count("f") and ho2.count("f")):
    kari+=1
  if(ho1.count("g") and ho2.count("g")):
    kari+=1
  if(ho1.count("h") and ho2.count("h")):
    kari+=1
  if(ho1.count("i") and ho2.count("i")):
    kari+=1
  if(ho1.count("j") and ho2.count("j")):
    kari+=1
  if(ho1.count("k") and ho2.count("k")):
    kari+=1
  if(ho1.count("l") and ho2.count("l")):
    kari+=1
  if(ho1.count("m") and ho2.count("m")):
    kari+=1
  if(ho1.count("n") and ho2.count("n")):
    kari+=1
  if(ho1.count("o") and ho2.count("o")):
    kari+=1
  if(ho1.count("p") and ho2.count("p")):
    kari+=1
  if(ho1.count("q") and ho2.count("q")):
    kari+=1
  if(ho1.count("r") and ho2.count("r")):
    kari+=1
  if(ho1.count("s") and ho2.count("s")):
    kari+=1
  if(ho1.count("t") and ho2.count("t")):
    kari+=1
  if(ho1.count("u") and ho2.count("u")):
    kari+=1
  if(ho1.count("v") and ho2.count("v")):
    kari+=1
  if(ho1.count("w") and ho2.count("w")):
    kari+=1
  if(ho1.count("x") and ho2.count("x")):
    kari+=1
  if(ho1.count("y") and ho2.count("y")):
    kari+=1
  if(ho1.count("z") and ho2.count("z")):
    kari+=1
    
  ans.append(kari)
  
print(max(ans))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
m=0
for i in range(n):
    x=set(list(s[:i+1]))
    y=set(list(s[i+1:]))
    z=len(x&y)
    if z>m:
        m=z
print(m)

Submission status: Accepted

Solution code:
import sys

def main():
  input = sys.stdin.readline
  N = int(input())
  S = str(input().strip())
  cur = 0
  for i in range(N):
    a, b = S[:i], S[i:]
    cur = max(cur, len(set(a) & set(b)))
  print(cur)


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(1, N):
        X, Y = S[:i], S[i:]
        cnt = 0
        memo = []
        for letter in X:
            if letter not in memo:
                memo.append(letter)
                if letter in Y:
                    cnt += 1
        if cnt > ans:
            ans = cnt
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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:
input();a=input();print(max(len(set(a[:s])&set(a[s:]))for s in range(99)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,a=open(0).read().split();a,l=list(a),[]
for s in range(1,len(a)):l.append(len(set(a[:s])&set(a[s:])))
print(max(l))

Submission status: Accepted

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

ans = []

for i in range(N-1):
    x = 0
    for c in set(S[:i+1]):
        if c in set(S[i+1:]):
            x += 1
    ans.append(x)

print(max(ans))

Submission status: Accepted

Solution code:
def check(s1, s2):
    ss1 = set(s1)
    ss2 = set(s2)
    count = 0
    for si in ss1:
        if si in ss2:
            count += 1;
    return count


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

    mx = 0
    for i in range(1, len(s)):
        s1 = s[:i]
        s2 = s[i:]
        mx = max(check(s1, s2), mx)

    print(mx)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1,n-1):
    cnt = 0
    for j in set(s[:i]):
        if j in s[i:]:
            cnt += 1
    if cnt > ans:
        ans = cnt
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:
def main() -> None:
    N = int(input())
    S = input()
    m = 0
    for i in range(N):
        same_num = len(set(sorted(S[0:i])) & set(sorted(S[i:])))
        m = same_num if m < same_num else m
    
    print(m)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main() -> None:
    N = int(input())
    S = input()
    m = 0
    for i in range(N):
        l1 = S[0:i]
        l2 = S[i:]
        if m < len(set(sorted(l1)) & set(sorted(l2))):
            m = len(set(sorted(l1)) & set(sorted(l2)))
    
    print(m)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main() -> None:
    N = int(input())
    S = input()
    m = 0
    for i in range(len(S)):
        l1 = S[0:i]
        l2 = S[i:]
        if m < len(set(sorted(l1)) & set(sorted(l2))):
            m = len(set(sorted(l1)) & set(sorted(l2)))
    
    print(m)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

count_max = 0
for i in range(n-1):
    mae = s[:i+1]
    ato = s[i+1:]
    count = 0
    for i in range(ord("a"), ord("z") + 1):
        if chr(i) in mae and chr(i) in ato:
            count += 1
    if count > count_max:
        count_max = count    

print(count_max)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(1, n - 1):
  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):
    l = list(set(s[:i]))
    r = list(set(s[i:]))
    count=0
    for x in l:
        count+=r.count(x)
    if ans<count:
        ans=count
print(ans)

Submission status: Accepted

Solution code:
n=int(input())

s=input()

count=0

for i in range(n-1):
    s1=s[:i+1]
    s2=s[i+1:]  
    seki=set(s1) & set(s2)
    if len(seki)>count:
        count=len(seki)

print(count)

Submission status: Accepted

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

def count_c(str1, str2):
    s1 = [0] * 26
    s2 = [0] * 26
    count = 0
    for i in list(str1):
        s1[ord(i) - 97] += 1
    for i in list(str2):
        s2[ord(i) - 97] += 1
    for i in range(26):
        if s1[i] > 0 and s2[i] > 0:
            count += 1
    return count
max_c = 0
for i in range(1,n):
    max_c = max(max_c, count_c(s[:i], s[i:]))
print(max_c)

Submission status: Accepted

Solution code:
int_n = int(input())
str_s = input()

result_ar = []
for i in range(len(str_s)):
    # print(str_s[:i], str_s[i:])
    result_ar.append(len(set(str_s[:i]) & set(str_s[i:])))

print(max(result_ar))

Submission status: Accepted

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

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:])
  c=a&b
  ans=max(ans,len(c))
print(ans)

Submission status: Accepted

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

for i in range(1,len(s)):
    count=set()
    x=s[0:i]
    y=s[i::]
    #print(x)
    #print(y)
    for j in range(len(x)):
        if x[j] in y:
            count.add(x[j])
    if max<len(count):
        max=len(count)

print(max)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
group = set()
answer = 0

for x in range(0,N):
    number = 0
    for y in S[:x]:
        group.add(y)
    for y in S[x:]:
        if y in group:
            number += 1
            group.remove(y)
    answer = max(answer,number)
    group.clear 

print(answer)

Submission status: Accepted

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

ans = 0
num = len(S)

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
l = []
if n==2:
    if s[0]==s[1]:
        print(1)
    else:
        print(0)
else:
    for i in range(1,len(s)-1):
        a = set(list(s[:i]))
        b = set(list(s[i:]))
        l.append(len(a & b))
    print(max(l))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
a = []
for i in range(1,n):
    cnt = 0
    for j in set(s[:i]):
        if j in s[i:]:
            cnt += 1
    a.append(cnt)

print(max(a))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
result=0
for i in range(n):
    x=s[0:i+1]
    y=s[i+1:]
    kind=0
    for j in range(len(x)):
        if x[j] in y:
            if x[j] in x[0:j]:
                pass
            else:
                kind+=1
    if kind>result:
        result=kind
print(result)

Submission status: Accepted

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

ans = 0
for i in range(N):
  cnt = 0
  l = list(set(S[:i]))
  r = list(set(S[i:]))
  for ll in l:
    if(ll in r):
      cnt += 1
  ans = max(ans, cnt)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

S = input()

ma = 0
for i in range(1, N):
  a = S[i:]
  b = S[:i]
  cnt = 0
  a = list(set(a))
  for j in a:
    if j in b:
      cnt += 1
  if cnt > ma:
    ma = cnt

print(ma)

Submission status: Accepted

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

A = []

for i in range(1,N+1):
    ans = 0
    X = S[:i]
    Y = S[i:len(S)+1]
    L = []
    M = []
    for j in range(len(X)):
        L.append(X[j])
    for k in range(len(Y)):
        M.append(Y[k])
    LS = set(L)
    for l in LS:
         if l in M:
            ans += 1

    A.append(ans)

print(max(A))

Submission status: Accepted

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

count = []

if len(S) == 2:
    if S[0] == S[1]:
        count.append(1)
    else:
        count.append(0)
else:
    for i in range(1,N-1):
        sum = 0
        sita = S[0:i]
        usiro = S[i:N]

        #print(sita,usiro)
        sita = list(set(sita))
        usiro = list(set(usiro))

        #print(sita,usiro)
        for x in range(len(sita)):
            if sita[x] in usiro:
                sum += 1

        count.append(sum)

print(max(count))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
mx = 0
for i in range(1,n):
  cnt = 0
  for j in range(ord('a'), ord('z')+1):
    c = chr(j)
    if c in s[0:i] and c in s[i:n]:
      cnt += 1
  mx = max(cnt, mx)
print(mx)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 11 05:38:56 2019

@author: shinjisu
"""


# ABC 200点問題
import math


def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def dmp(x):
    global debug
    if debug:
        print(x)


debug = True


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


def prob096():  # Maximum Sum
    X = getIntList()
    K = getInt()
    dmp((X, K))
    total = sum(X) - max(X) + max(X)*2**K
    return total


def prob097():  # Exponential
    X = getInt()
    dmp(X)
    if X == 1:
        return 1
    for n in range(X, 0, -1):
        dmp(n)
        for b in range(2, int(math.sqrt(X))+1):
            a = n
            exp = True
            while a > 1:
                if a % b != 0:
                    exp = False
                    break
                a //= b
            if exp:
                break
        if exp:
            break
    return n


def prob098():  # Cut and Count
    N = getInt()
    S = input()
    dmp((N, S))
    maxChCount = 0
    for i in range(1, N):
        before = S[:i]
        after = S[i:]
        dmp((before, after))
        chCount = 0
        for j in range(26):
            ch = chr(ord('a')+j)
            if ch in before and ch in after:
                chCount += 1
        maxChCount = max(maxChCount, chCount)
    return maxChCount


debug = False  # True False
print(prob098())

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
ans = 0
for i in range(1,len(s)):
    A = s[:i]
    B = s[i:]
    a = 0
    for l in range(len(A)):
        if A.find(A[l], l+1, ) != -1:
            continue
        for k in range(len(B)):
            if A[l] == B[k]:
                a += 1
                break
    if a > ans:
        ans = a
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1, N):
    S1s = Ss[:i]
    S2s = Ss[i:]
    num = 0
    for ch in 'abcdefghijklmnopqrstuvwxyz':
        if ch in S1s and ch in S2s:
            num += 1
    ans = max(ans, num)
print(ans)

Submission status: Accepted

Solution code:
input()
s = input().rstrip()
ans = 0
for i in range(1, len(s)):
    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(1,N):
    L = S[:i]
    R = S[i:]
    cnt = 0
    for s in set(L):
        if s in R:
            cnt += 1
    ans =max(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
res = 0
for i in range(n):
    l1 = s[:i]
    l2 = s[i:]
    cnt = 0
    for j in set(l1):
        if j in l2:
            cnt += 1
    res = max(res,cnt)
print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from functools import reduce
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    def func(n, i):
        a = set(S[:i])
        b = set(S[i:])
        return max( n, len(a & b) )

    N = int(lines.pop(0))
    S = lines.pop(0)

    print( reduce( func, range(1,N), 0 ) )

#
# main
#
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
L = []
for i in range(N):
    S1 = S[0:i]
    S2 = S[i:]
    L.append(len(set(S1) & set(S2)))
print(max(L))

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
def inpl(): return list(map(int, input().split()))

#### START
N = int(input())
s = input()

ans = 0
for i in range(1, N):
  aset = set(list(s[0:i]))
  bset = set(list(s[i:]))
  ta = len(aset & bset)
  if ta>ans:
    ans=ta

print(ans)

Submission status: Accepted

Solution code:
N = input()

S = list(raw_input())

ans = 0
for i in range(1,N):
    counter = 0
    X = S[0:i]
    Y = S[i:N]
    data = []
    for j in X:
        if j in Y and j not in data:
            counter += 1
            data.append(j)
    if ans < counter:
        ans = counter

print ans

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    ans = 0
    for n in range(N + 1):
        c = 0
        for s in set(S[:n]):
            if S[n:].count(s) > 0:
                c += 1
        ans = max(ans, c)
    print(ans)


main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    ans = 0
    for n in range(N + 1):
        c = 0
        u = []
        for s in S[:n]:
            if s in u:
                continue
            if S[n:].count(s) > 0:
                c += 1
            u.append(s)
        ans = max(ans, c)
    print(ans)


main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
X=[]
Y=[]
max_len=0
for i in range(N-1):
  X=S[:i+1]
  Y=S[i+1:]
  #print(set(X),set(Y))
  same_ele_num = len(set(X) & set(Y))
  #print('X and Y:', same_ele_num)
  if(same_ele_num > max_len):
    max_len = same_ele_num
print(max_len)

Submission status: Accepted

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

num = len(set(S))

result = 0
for i in range(N-1):
  A = S[:i+1]
  B = S[i+1:]
  
  tmp = len(set(A) & set(B))
  if tmp > result:
    result = tmp
  
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

num = len(set(S))

result = 0
for i in range(N-1):
  A = S[0:i+1]
  B = S[i+1:N]
  
  tmp = len(list(set(A) & set(B)))
  if tmp > result:
    result = tmp
  elif tmp == num:
    result = num
    break
  
print(result)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:


n = int(input())

s = input()

alphabet = 'abcdefghijklmnopqrstuvxwyz'
A = [0] * len(alphabet)
B = A.copy()


for c in s:
    pos = alphabet.find(c)
    A[pos]+=1

#print(A)
#print(B)

ans = 0
for c in s:
    pos = alphabet.find(c)
    A[pos] -= 1
    B[pos] += 1
    
    #print(A)
    #print(B)

    t = sum(1 if ae>0 and be > 0 else 0 for ae, be in zip(A,B) )

    ans = max(t,ans)

    

print(ans)

Submission status: Accepted

Solution code:
""" AtCoder """

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

w = "abcdefghijklmnopqrstuvwxyz"

count_max = 0

for i in range(N):
    count = 0
    for j in range(len(w)):
        if w[j] in S[:i] and w[j] in S[i:]:
            count += 1
    if count_max < count:
        count_max = count

print(count_max)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ret = 0
for n in range(1, N):
    a = set(S[:n])
    b = set(S[n:])
    tmp_ret = len([x for x in a if x in b])
    if ret < tmp_ret:
        ret = tmp_ret

print(ret)

Submission status: Accepted

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

ans = 0
for i in range(N):
    s1 = set(list(S[:i+1]))
    s2 = set(list(S[i+1:]))
    ans = max(ans,len(s1&s2))

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

res = 0
for i in range(1, N):
    c1 = Counter(s[:i])
    c2 = Counter(s[i:])
    res = max(res, len(set(c1.keys()) & set(c2.keys())))

print(res)

Submission status: Accepted

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

for i in range(1, N):
    R.append(len(set(list(S[:i])) & set(list(S[i:]))))

print(max(R))

Submission status: Accepted

Solution code:
N = int(input())
s = input()
max = 0
for i in range(N):
    count = 0
    s1 = s[:i]
    s2 = s[i:]
    A = set(s1)
    B = set(s2)
    for c in A:
        if c in B:
            count += 1
    if count > max:
        max = count
print(max)

Submission status: Accepted

Solution code:
def func(s1, s2):
    set1 = set(s1)
    set2 = set(s2)

    cnt = 0
    for _ in range(len(set1)):
        s = set1.pop()
        if s in set2:
            cnt += 1
    return cnt


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

    mx = 0
    for i in range(len(s) - 1):
        s1 = s[:i + 1]
        s2 = s[i + 1:]
        ans = func(s1, s2)
        if ans > mx:
            mx = ans

    print(mx)


if __name__ == '__main__':
    main()
    # print(func([1, 2, 2, 3], [2, 3, 4, 4, 1]))

Submission status: Accepted

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

print(a)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
f = []
for i in range(n):
    a = []
    for j in range(i):
        if s[j] in s[i:]:
            a.append(s[j])
    f.append(len(set(a)))
print(max(f))

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()
ans = 0
for i in range(1, N):
    X = S[:i]
    Y = S[i:]
    Xstr = []
    Ystr = []
    for j in range(len(X)):
        Xstr.append(X[j])
    for j in range(len(Y)):
        Ystr.append(Y[j])
    Xstr = list(set(Xstr))
    Ystr = list(set(Ystr))
    anstemp = 0
    for x in Xstr:
        if x in Ystr:
            anstemp += 1
    if ans < anstemp:
        ans = anstemp
print(ans)

Submission status: Accepted

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

print(n)

Submission status: Accepted

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

ans=0

for i in range(1,n):
  count = 0
  memo={}
  for j in range(i):
    if s[0:i][j] not in memo:
      if s[0:i][j] in s[i:n]:
        count += 1 
        memo[s[0:i][j]] = 1
  ans = max(count,ans)
  
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    l= {}
    r= {}
    count = 0

    for c in range(0, i):
        l[s[c]] = True

    for c in range(i, n):
        r[s[c]] = True

    for c in l.keys():
        if r.get(c, False):
            count += 1
    ans = max(ans, count)

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(n - 1):
    x = set(S[: i + 1])
    y = set(S[i + 1 :])
    z = x & y
    ans = max(ans, len(z))
    
print(ans)

Submission status: Accepted

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

print(a)

Submission status: Accepted

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

print(a)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
res = []
for i in range(1,N):
    X=S[:i]
    Y=S[i:]
    count = 0
    o=set()
    for j in X:
        
        if (not j in o) and j in Y:
            count+=1
            o.add(j)
    res.append(count)
print(max(res))

Submission status: Accepted

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

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

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

    print(r)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
p=int(input())
a=input()
b=[]
for i in range(0,p):
    c=0
    t=list(set(a[:i]))
    k=a[i:]
    for j in range(len(t)):
        if t[j]in k:
            c+=1
    b.append(c)
print(max(b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans = []
for i in range(len(S)+1):
    num = 0
    X = S[:i]
    Y = S[i:]
    xd = {}
    yd = {}
    for j in X:
        if j in xd:
            continue
        else:
            xd[j] = 1

    for j in Y:
        if j in yd:
            continue
        else:
            yd[j] = 1


    for k in xd:
        if k in yd:
            num += 1

    ans.append(num)

print(max(ans))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
a=[]
l=[]
for i in range(n):
  kind=0
  l.append(s.pop(0))
  for j in list(set(l)):
    if j in list(set(s)):
      kind+=1
  a.append(kind)
print(max(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    a = set(S[:i])
    b = set(S[i:])
    c = (a & b)
    if num < len(c):
        num = len(c)
print(num)

Submission status: Accepted

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

for i in range(N):
    count = 0
    alp = []
    for s in S[:i+1]:
        if s in S[i+1:] and s not in alp:
            count += 1
            alp.append(s)
    if maxcount < count:
        maxcount = count
print(maxcount)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
# N,M = [int(n) for n in input().split()]
N = int(input())
S = list(input())
st = set(S)
# for s in S:
#     st.add(s)
kind = len(st)
maxi = 0
# print(kind)
for i in range(1,len(S)-1):
    # print(i)
    l = set(S[:i])
    r = set(S[i:])
    tmp = len(l&r)
    # print(tmp)
    maxi = max(tmp,maxi)

print(maxi)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
d=0
for i in range(1,n):
  S=[]
  for t in s[:i:]:
    if t in s[i::]:
      S.append(t)
  S=list(set(S))
  d=max(d,len(S))
print(d)

Submission status: Accepted

Solution code:
input()
s=input()
cnt=0
for i in range(len(s)):
    x=set(s[:i])
    y=set(s[i:])
    if cnt<len(x&y):
        cnt=len(x&y)
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
s = input()
A = []
count=0
for i in range(1, a):
    x = list(s[:i])
    y = list(s[i:])

    x = list(set(x))
    y = list(set(y))

    for i in y:
        if(i in x):
            count+=1
    A.append(count)
    count=0
print(max(A))

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
input = sys.stdin.readline

ans = 0
N, S = int(input()), input()
for i in range(1, N-1):
    set_X = set(S[:i])
    set_Y = set(S[i:])
    set_tmp = set_X & set_Y
    ans = max(ans, len(set_tmp))
print(ans)