100981: [AtCoder]ABC098 B - Cut and Count

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

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

Input

题意翻译

## 题目描述 给定一个长度为 $N$ 的字符串 $S$。我们可以在任意一个位置将字符串分割,使它变成两个字符串 $X$ 和 $Y$。现在要求出可能的 $X$ 和 $Y$ 都包含的字符种数的最大值。 ## 输入格式 输入 $N$ 和 $S$,格式如下面所示。 > $N$ $S$ ## 输出格式 一行,输出可能的 $X$ 和 $Y$ 都包含的字符种数的最大值。 ## 提示 ### 数据范围 - $2\ \le N\ \le 100$ - $|S|\ =\ N$ - $S$ 里的字符均为小写字符。 ### 数据解释 1 在 $S$ 的第 $3$ 个字符后切割字符串,此时 $X\ =\ \texttt{aab}$,$Y\ =\ \texttt{bca}$。 它们共同包含的字符有 $\texttt{a}$ 和 $\texttt{b}$ 两种。所以答案为 $2$。 ### 数据解释 2 显然,无论怎么切割字符串, $X$ 和 $Y$ 都包含的字符只可能为 $\texttt{a}$。所以答案为 $1$。

加入题单

上一题 下一题 算法标签: