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, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(input())
ans = 0
for i in range(N):
  A = S[:i]
  B = S[i:]
  C = list(set(A) & set(B))
  c = len(C)
  if c > ans:
    ans += 1



print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1 << 32


def solve(N: int, S: str):
    m = 0
    for i in range(1, N - 1):
        m = max(m, len(set(list(S[:i])) & set(list(S[i:]))))
    print(m)
    return


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().strip()
cmax = 0
for n in range(1,N-1):
    X = S[:n]
    Y = S[n:]
    Cx = {}
    Cy = {}
    for i in range(n):
        a = X[i]
        if a not in Cx:
            Cx[a] = 0
        Cx[a] += 1
    for i in range(N-n):
        a = Y[i]
        if a not in Cy:
            Cy[a]=0
        Cy[a] += 1
    cnt = 0
    for a in Cx:
        if a in Cy:
            cnt += 1
    cmax = max(cmax,cnt)
print(cmax)

Submission status: Accepted

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

ans = 0

for i in range(1,N-1):
    l = set()
    count = 0
    for j, s in enumerate(S):
        if j < i:
            l.add(s)
        else:
            if s in l:
                count += 1
                l.discard(s)
    ans = max(ans, count)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
S = input()
from collections import Counter
ans = 0
for i in range(1,n):
    f = S[:i]
    b = S[i:]
    f = set(f)
    #print(f)
    #print(S[:i],S[i:])
    cnt = 0
    for v in f:
        #print(v)
        if v in b:
            cnt += 1
    ans = max(ans,cnt)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
ans = -1
for i in range(1, n):
    x = s[0:i]
    y = s[i:]
    temp = 0
    for j in range(26):
        c = chr(ord('a')+j)
        if c in x and c in y:
            temp += 1
    ans = max(ans, temp)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
S = input()[:-1]
ans = 0

for i in range(N+1):
    sx = set()
    
    for j in range(i):
        sx.add(S[j])
    
    sy = set()
    
    for j in range(i, N):
        sy.add(S[j])
    
    ans = max(ans, len(sx&sy))

print(ans)

Submission status: Accepted

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

n = int(input())
s = input().rstrip()

ans = -1

for i in range(n):
    x = s[:i]
    y = s[i:]
    z = set()
    res = 0
    for j in range(len(x)):
        if y.count(x[j]) >= 1 and x[j] not in z:
            res += 1
            z.add(x[j])
    ans = max(ans, res)
print(ans)

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

cnt = 0
for i in range(1,n):
  x = s[:i]
  y = s[i:]
  xy = set(x)&set(y)
  if cnt < len(xy): cnt = len(xy)
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
ans = 0
for i in range(1, n-1):
    x = set(s[:i])
    y = set(s[i:])
    cnt = 0
    for c in x:
        if c in y:
            cnt += 1
    if cnt > ans:
        ans = cnt

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cs = [0]*(n-1)

for i in range(n-1):
    cnt = 0
    memo = []
    for j in s[0:i+1]:
        if j in s[i+1:n] and j not in memo:
            cnt += 1
        memo.append(j)
        
    cs[i] = cnt

print(max(cs))

Submission status: Accepted

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

mx = 0
for i in range(len(s)):
    first = set(list(s[:i + 1]))
    second = set(list(s[i + 1:]))

    intersection = first & second
    mx = max(len(intersection), mx)

print(mx)

Submission status: Accepted

Solution code:

def main():
    N = int(input()) 
    S = input() 
    maxv = 0
    for i in range(1,N-1):
        x = S[0:i]
        y = S[i:N]
        xl = list(set(x))
        yl = list(set(y))
        cnt = 0
        for xx in xl:
            cnt += yl.count(xx)
        maxv = max(maxv,cnt)
    
    print(maxv)






if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

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

print(ans)

Submission status: Accepted

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

max_match=0
for i in range(1,N):
  match=0
  left=set(S[:i])
  right=set(S[i:])
  for j in left:
    if j in right:
      match+=1
  if match > max_match:
    max_match=match
print(max_match)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():
        n=int(input())
        s=input()
        sset=set(s)
        ans=0
        for i in range(1,n):
            x=s[:i]
            y=s[i:]
            cnt=0
            for j in sset:
                if j in x and j in y:
                    cnt+=1
                    if cnt==len(sset):
                        return cnt
            ans=max(ans,cnt)
        return ans
    print(main())
resolve()

Submission status: Accepted

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    def calc_common_char_nums(a, b):
        set_a, set_b = set(list(a)), set(list(b))    # O(n)
        cnt = 0
        for char in string.ascii_lowercase:
            if char in set_a and char in set_b:
                cnt += 1
        return cnt



    n = ii()
    s = input()
    ans = -1
    for i in range(1, n):
        a, b = s[:i], s[i:]
        ans = max(ans, calc_common_char_nums(a, b))
    
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N  = int(input())
S = list(input())
D = [0]*(N-1)
for i in range(1, N):
  A = S[:i]
  B = S[i:]
  A1 = set(A)
  B1 = set(B)
  C = A1 & B1
  D[i-1] = len(C)
print(max(D))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, N):
    count = 0
    front = list(set(S[:i]))
    back = list(set(S[i:]))
    F = len(front)
    for j in range(F):
        count += back.count(front[j])
    if count>answer:
        answer = count
print(answer)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = input()
ma = 0
for i in range(1,n):
    s1=s[:i]
    s2=s[i:]
    common = set(s1) & set(s2)
    ma = max(ma,len(common))
print(ma)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
count = 0
ans = 0
x,y = '',''

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

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
arr = []
cnt = 0

for i in range(1,N):

  for ch in range (97,123):
    if S[:i].count(chr(ch)) != 0 and S[i:].count(chr(ch)) != 0:
      cnt=cnt+1
  arr.append(cnt)
  cnt=0

print(max(arr))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ans=0
for i in range(n):
    sl=set()
    sr=set()
    for j in range(n):
        if j<=i:
            sl.add(s[j])
        else:
            sr.add(s[j])
    ans=max(ans,len(sl & sr))
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1, n):
    cur = 0
    a = set(s[:i])
    b = set(s[i:])
    for A in a:
        if A in b:
            cur += 1
    ans = max(ans, cur)
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()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n = int(input())
s = input()
ans = 0
for i in range(1,n):
    a = 0
    sx = set(s[i:])
    sy = set(s[:i])
    for sxi in sx:
        if sxi in sy:
            a+=1
    ans = max(ans,a)
print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N = int(readline().rstrip().decode("utf-8"))
S = readline().rstrip().decode("utf-8")

ans = 0
for i in range(N-1):
    left = S[:i+1] 
    right = S[i+1:]
    # print("left: {} right: {}".format(left, right))

    tmp = len(set(left) & set(right))
    ans = max(tmp, ans)
print(ans)

Submission status: Accepted

Solution code:
#愚直で
n=int(input())
s=input()
ans=0
for i in range(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()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
t=""
k=""
l=[]
for i in range(1,n):
    ans1=0
    t=sorted(set(s[:i]))
    k=sorted(set(s[i:]))
    for i in t:
        for j in k:
            if i==j:
                ans1+=1
    l.append(ans1)
print(max(l))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
t=""
k=""
ans=0
l=[]
for i in range(1,n):
    ans1=0
    t=sorted(set(s[:i]))
    k=sorted(set(s[i:]))
    for i in t:
        for j in k:
            if i==j:
                ans1+=1
    l.append(ans1)
print(max(l))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
t=""
k=""
ans=0
l=[]
for i in range(1,n):
    ans1=0
    t=sorted(set(s[:i]))
    k=sorted(set(s[i:]))
    for i in t:
        for j in k:
            if i==j:
                ans1+=1
            l.append(ans1)
print(max(l))

Submission status: Accepted

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

a=set(s)
ans=0
for i in range(len(s)-1):
    l=set(s[:i+1])
    r=set(s[i+1:])
    d=len(l)+len(r)-len(a)
    if d>ans:
        ans=d
print(ans)

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
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

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n), n)+[X%n]
  return [X%n]


#############
# Main Code #
#############

N = inputI()
S = inputS()

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

Submission status: Accepted

Solution code:
def resolve():
	n = int(input())
	s = input()
	ans = 0
	for i in range(1, n-1):
		c = 0
		a, b = set(s[:i]), set(s[i:])
		for j in a:
			for k in b:
				if j == k:
					c += 1

		ans = max(ans, c)
	print(ans)
resolve()

Submission status: Accepted

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

num = 0
for i in range(n-1):
    x = s[:i+1]
    y = s[i+1:]

    setx = {i for i in x}
    sety = {i for i in y}
    common = setx & sety

    num = max(num, len(common))

print(num)

Submission status: Accepted

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

Submission status: Accepted

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

lans = list()
for i in range(1, N):
    sa = S[:i]
    sb = S[i:]
    l = list()
    cnt = 0
    for j in range(i):
        if S[j] in sb and S[j] not in l:
            l.append(S[j])
            cnt += 1
    lans.append(cnt)

print(max(lans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

    ans = 0
    for i in range(N):
        s1 = S[:i]
        s2 = S[i:]

        tmp = set()
        for s in s1:
            if s in s2:
                tmp.add(s)
        tmp_len = len(tmp)
        if tmp_len > ans:
            ans = tmp_len
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
s=input()
x=""
y=""
saidai=0
for i in range(n):
    x=s[:i+1]
    y=s[i+1:]
    #print(x,y)
    x_y_and=set(x)&set(y)
    if len(x_y_and)>saidai:
        saidai=len(x_y_and)
    x=""
    y=""
    x_y_and=""
print(saidai)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    ans = 0
    for i in range(1, N):
        X, Y = S[:i], S[i:]
        x = set(X)
        y = set(Y)
        num = len(x & y)
        if num > ans:
            ans = num

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
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"]

ans = 0
for i in range(n):
  a, b = s[:i], s[i:]
  sub = 0
  for j in range(26):
    if alphabet[j] in a and alphabet[j] in b:
      sub += 1
  if ans < sub:
    ans = sub
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
s=str(input())
s=list(s)
ans=0
for i in range(1,n-1):
  temp1=s[:-i]
  temp2=s[-i:]
  temp1=list(set(temp1))
  temp2=list(set(temp2))
  count=0
  for j in range(0,len(temp1)):
    if temp2.count(temp1[j])>=1:
      count=count+1
  ans=max(ans,count)
print(ans)

Submission status: Accepted

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

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:
# ABC098
# B
# Cut and Count

n = int(input())
s = input()
ans = 0
for i in range(n):
    s_f = set(s[:i])
    s_b = set(s[i:])
    _l =len(s_f & s_b)
    if ans < _l:
        ans = _l

print(ans)

Submission status: Accepted

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

ans = 0

for i in range(N - 1):
    tmp = set()
    for j in S[: i + 1]:
        if j in S[i + 1 :]:
            tmp.add(j)
    ans = max(ans, len(tmp))

print(ans)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import bisect

def solve(s):
    n = len(s)
    max_val = 0
    for i in range(1, n):
        s1 = set(list(s[0:i]))
        s2 = set(list(s[i:]))
        val = len(s1 & s2)
        max_val = max(max_val, val)
    return max_val

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = input()
a = [0]*26
al = 'abcdefghijklmnopqrstuvwxyz'
for i in range(n):
  a[al.index(s[i])] += 1
b = [0]*26
res = 0
for i in range(n):
  b[al.index(s[i])] += 1
  tmp = 0
  for j in range(26):
    if b[j] >= 1 and a[j] - b[j] >= 1:
      tmp += 1
  res = max(res, tmp)
print(res)

Submission status: Accepted

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

ans = 0
for i in range(N):
    same = 0
    S_a = S[0:i+1]
    S_b = S[i+1:N]
    for alphabet in "abcdefghijklmnopqrstuvwxyz":
        if S_a.count(alphabet) >0 and S_b.count(alphabet):
            same +=1
    if same > ans:
        ans = same
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

S = input()

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

print(res)

Submission status: Accepted

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    s = s_input()

    al=[chr(ord('a') + i) for i in range(26)]

    max_kind = 0
    for i in range(1,n):
        before_s = s[:i]
        after_s = s[i:]
        tmp_count = 0
        for check_s in al:
            if check_s in before_s and check_s in after_s:
                tmp_count += 1
        max_kind = max(max_kind, tmp_count)

    print(max_kind)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed May 13 17:11:47 2020

@author: shinba
"""

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
ans = 0
for i in range(1, n):
    k = 0
    used = []
    a = s[0:i]
    b = s[i:n]
    l, r = len(a), len(b)
    if l <= r:
        for j in range(l):
            if not a[j] in used:
                used.append(a[j])
                if a[j] in b:
                    k += 1
    else:
        for j in range(r):
            if not b[j] in used:
                used.append(b[j])
                if b[j] in a:
                    k += 1
    ans = max(ans, k)

print(ans)

Submission status: Accepted

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

# In[10]:


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


# In[11]:


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


# In[ ]:

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    head = set(S[:i])
    tail = set(S[i:])
    tmp_sum = 0
    for c in head:
        if c in tail:
            tmp_sum += 1

    ans = max(ans, tmp_sum)

print(ans)